• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • tdeabc
 

tdeabc

  • tdeabc
vcardformatplugin.cpp
1 /*
2  This file is part of libtdeabc.
3  Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
4 
5  This library is free software; you can redistribute it and/or
6  modify it under the terms of the GNU Library General Public
7  License as published by the Free Software Foundation; either
8  version 2 of the License, or (at your option) any later version.
9 
10  This library is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  Library General Public License for more details.
14 
15  You should have received a copy of the GNU Library General Public License
16  along with this library; see the file COPYING.LIB. If not, write to
17  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18  Boston, MA 02110-1301, USA.
19 */
20 
21 #include <tqfile.h>
22 
23 #include "address.h"
24 #include "addressee.h"
25 #include "vcardconverter.h"
26 
27 #include "vcardformatplugin.h"
28 
29 using namespace TDEABC;
30 
31 VCardFormatPlugin::VCardFormatPlugin()
32 {
33 }
34 
35 VCardFormatPlugin::~VCardFormatPlugin()
36 {
37 }
38 
39 bool VCardFormatPlugin::load( Addressee &addressee, TQFile *file )
40 {
41  TQString data;
42 
43  TQTextStream t( file );
44  t.setEncoding( TQTextStream::UnicodeUTF8 );
45  data = t.read();
46 
47  VCardConverter converter;
48  Addressee::List l = converter.parseVCards( data );
49 
50  if ( ! l.first().isEmpty() ) {
51  addressee = l.first();
52  return true;
53  }
54 
55  return false;
56 }
57 
58 bool VCardFormatPlugin::loadAll( AddressBook*, Resource *resource, TQFile *file )
59 {
60  TQString data;
61 
62  TQTextStream t( file );
63  t.setEncoding( TQTextStream::UnicodeUTF8 );
64  data = t.read();
65 
66  VCardConverter converter;
67 
68  Addressee::List l = converter.parseVCards( data );
69 
70  Addressee::List::iterator itr;
71  for ( itr = l.begin(); itr != l.end(); ++itr) {
72  Addressee addressee = *itr;
73  addressee.setResource( resource );
74  addressee.setChanged( false );
75  resource->insertAddressee( addressee );
76  }
77 
78  return true;
79 }
80 
81 void VCardFormatPlugin::save( const Addressee &addressee, TQFile *file )
82 {
83  VCardConverter converter ;
84  Addressee::List vcardlist;
85 
86 
87  vcardlist.append( addressee );
88 
89  TQTextStream t( file );
90  t.setEncoding( TQTextStream::UnicodeUTF8 );
91  TQString text = converter.createVCards( vcardlist );
92 // kdDebug(5700)<< ">>>>>>>>> DEBUG <<<<<<<<<<" << endl;
93 // kdDebug(5700)<< text << endl;
94 // kdDebug(5700)<< ">>>>>>>>> DEBUG <<<<<<<<<<" << endl;
95  t << text;
96 }
97 
98 void VCardFormatPlugin::saveAll( AddressBook*, Resource *resource, TQFile *file )
99 {
100  VCardConverter converter;
101  Addressee::List vcardlist;
102 
103  Resource::Iterator it;
104  for ( it = resource->begin(); it != resource->end(); ++it ) {
105  (*it).setChanged( false );
106  vcardlist.append( *it );
107  }
108 
109  TQTextStream t( file );
110  t.setEncoding( TQTextStream::UnicodeUTF8 );
111  TQString text = converter.createVCards( vcardlist );
112 // kdDebug(5700)<< ">>>>>>>>> DEBUG <<<<<<<<<<" << endl;
113 // kdDebug(5700)<< text << endl;
114 // kdDebug(5700)<< ">>>>>>>>> DEBUG <<<<<<<<<<" << endl;
115  t << text;
116 }
117 
118 bool VCardFormatPlugin::checkFormat( TQFile *file ) const
119 {
120  TQString line;
121 
122  file->readLine( line, 1024 );
123  line = line.stripWhiteSpace();
124  if ( line == "BEGIN:VCARD" )
125  return true;
126  else
127  return false;
128 }
TDEABC::VCardFormatPlugin::loadAll
bool loadAll(AddressBook *, Resource *, TQFile *file)
Load whole addressbook from file.
Definition: vcardformatplugin.cpp:58
TDEABC::AddressBook
Address Book.
Definition: addressbook.h:43
TDEABC::VCardConverter::createVCards
TQString createVCards(Addressee::List list, Version version=v3_0)
Creates a string in vCard format which contains the given list of contact.
Definition: vcardconverter.cpp:54
TDEABC::VCardFormatPlugin::saveAll
void saveAll(AddressBook *, Resource *, TQFile *file)
Save whole addressbook to file.
Definition: vcardformatplugin.cpp:98
TDEABC
static data, shared by ALL addressee objects
Definition: address.h:48
TDEABC::VCardConverter::parseVCards
Addressee::List parseVCards(const TQString &vcard)
Parses a string in vCard format and returns a list of contact objects.
Definition: vcardconverter.cpp:68
TDEABC::Resource::Iterator
Resource Iterator.
Definition: resource.h:68
TDEABC::Addressee::setResource
void setResource(Resource *resource)
Set resource where the addressee is from.
Definition: addressee.src.cpp:1013
TDEABC::VCardFormatPlugin::checkFormat
bool checkFormat(TQFile *file) const
Checks if given file contains the right format.
Definition: vcardformatplugin.cpp:118
TDEABC::VCardFormatPlugin::save
void save(const Addressee &, TQFile *file)
Save a single Addressee to file.
Definition: vcardformatplugin.cpp:81
TDEABC::Addressee
address book entry
Definition: addressee.src.h:74
TDEABC::VCardFormatPlugin::load
bool load(Addressee &, TQFile *file)
Load single addressee from file.
Definition: vcardformatplugin.cpp:39
TDEABC::VCardConverter
Class to converting contact objects into vCard format and vice versa.
Definition: vcardconverter.h:53
TDEABC::Addressee::setChanged
void setChanged(bool value)
Mark addressee as changed.
Definition: addressee.src.cpp:1024

tdeabc

Skip menu "tdeabc"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

tdeabc

Skip menu "tdeabc"
  • arts
  • dcop
  • dnssd
  • interfaces
  •   kspeech
  •     interface
  •     library
  •   tdetexteditor
  • kate
  • kded
  • kdoctools
  • kimgio
  • kjs
  • libtdemid
  • libtdescreensaver
  •     tdecore
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  • tdeioslave
  •   http
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdemdi
  •   tdemdi
  • tdenewstuff
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for tdeabc by doxygen 1.8.8
This website is maintained by Timothy Pearson.