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

kabc

  • kabc
vcardformatplugin.cpp
1 /*
2  This file is part of libkabc.
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 KABC;
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 }
KABC::Resource::Iterator
Resource Iterator.
Definition: resource.h:68
KABC::Addressee::setResource
void setResource(Resource *resource)
Set resource where the addressee is from.
Definition: addressee.src.cpp:1013
KABC::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
KABC::VCardFormatPlugin::saveAll
void saveAll(AddressBook *, Resource *, TQFile *file)
Save whole addressbook to file.
Definition: vcardformatplugin.cpp:98
KABC::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
KABC::Addressee::setChanged
void setChanged(bool value)
Mark addressee as changed.
Definition: addressee.src.cpp:1024
KABC::VCardConverter
Class to converting contact objects into vCard format and vice versa.
Definition: vcardconverter.h:53
KABC::Addressee
address book entry
Definition: addressee.src.h:74
KABC::VCardFormatPlugin::loadAll
bool loadAll(AddressBook *, Resource *, TQFile *file)
Load whole addressbook from file.
Definition: vcardformatplugin.cpp:58
KABC::VCardFormatPlugin::load
bool load(Addressee &, TQFile *file)
Load single addressee from file.
Definition: vcardformatplugin.cpp:39
KABC::VCardFormatPlugin::save
void save(const Addressee &, TQFile *file)
Save a single Addressee to file.
Definition: vcardformatplugin.cpp:81
KABC::AddressBook
Address Book.
Definition: addressbook.h:43
KABC::VCardFormatPlugin::checkFormat
bool checkFormat(TQFile *file) const
Checks if given file contains the right format.
Definition: vcardformatplugin.cpp:118

kabc

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

kabc

Skip menu "kabc"
  • arts
  • dcop
  • dnssd
  • interfaces
  •     interface
  •     library
  •   kspeech
  •   ktexteditor
  • kabc
  • kate
  • kcmshell
  • kdecore
  • kded
  • kdefx
  • kdeprint
  • kdesu
  • kdeui
  • kdoctools
  • khtml
  • kimgio
  • kinit
  • kio
  •   bookmarks
  •   httpfilter
  •   kfile
  •   kio
  •   kioexec
  •   kpasswdserver
  •   kssl
  • kioslave
  •   http
  • kjs
  • kmdi
  •   kmdi
  • knewstuff
  • kparts
  • krandr
  • kresources
  • kspell2
  • kunittest
  • kutils
  • kwallet
  • libkmid
  • libkscreensaver
Generated for kabc by doxygen 1.8.6
This website is maintained by Timothy Pearson.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. |