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

kabc

vcardformatplugin.cpp
00001 /*
00002     This file is part of libkabc.
00003     Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
00004 
00005     This library is free software; you can redistribute it and/or
00006     modify it under the terms of the GNU Library General Public
00007     License as published by the Free Software Foundation; either
00008     version 2 of the License, or (at your option) any later version.
00009 
00010     This library is distributed in the hope that it will be useful,
00011     but WITHOUT ANY WARRANTY; without even the implied warranty of
00012     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013     Library General Public License for more details.
00014 
00015     You should have received a copy of the GNU Library General Public License
00016     along with this library; see the file COPYING.LIB.  If not, write to
00017     the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00018     Boston, MA 02110-1301, USA.
00019 */
00020 
00021 #include <tqfile.h>
00022 
00023 #include "address.h"
00024 #include "addressee.h"
00025 #include "vcardconverter.h"
00026 
00027 #include "vcardformatplugin.h"
00028 
00029 using namespace KABC;
00030 
00031 VCardFormatPlugin::VCardFormatPlugin()
00032 {
00033 }
00034 
00035 VCardFormatPlugin::~VCardFormatPlugin()
00036 {
00037 }
00038 
00039 bool VCardFormatPlugin::load( Addressee &addressee, TQFile *file )
00040 {
00041   TQString data;
00042 
00043   TQTextStream t( file );
00044   t.setEncoding( TQTextStream::UnicodeUTF8 );
00045   data = t.read();
00046 
00047   VCardConverter converter;
00048   Addressee::List l = converter.parseVCards( data );
00049 
00050   if ( ! l.first().isEmpty() ) {
00051     addressee = l.first();
00052     return true;
00053   }
00054 
00055   return false;
00056 }
00057 
00058 bool VCardFormatPlugin::loadAll( AddressBook*, Resource *resource, TQFile *file )
00059 {
00060   TQString data;
00061 
00062   TQTextStream t( file );
00063   t.setEncoding( TQTextStream::UnicodeUTF8 );
00064   data = t.read();
00065 
00066   VCardConverter converter;
00067 
00068   Addressee::List l = converter.parseVCards( data );
00069 
00070   Addressee::List::iterator itr;
00071   for ( itr = l.begin(); itr != l.end(); ++itr) {
00072     Addressee addressee = *itr;
00073     addressee.setResource( resource );
00074     addressee.setChanged( false );
00075     resource->insertAddressee( addressee );
00076   }
00077 
00078   return true;
00079 }
00080 
00081 void VCardFormatPlugin::save( const Addressee &addressee, TQFile *file )
00082 {
00083   VCardConverter converter ;
00084   Addressee::List vcardlist;
00085 
00086 
00087   vcardlist.append( addressee );
00088 
00089   TQTextStream t( file );
00090   t.setEncoding( TQTextStream::UnicodeUTF8 );
00091   TQString text = converter.createVCards( vcardlist );
00092 //  kdDebug(5700)<< ">>>>>>>>> DEBUG <<<<<<<<<<" << endl;
00093 //  kdDebug(5700)<< text << endl;
00094 //  kdDebug(5700)<< ">>>>>>>>> DEBUG <<<<<<<<<<" << endl;
00095   t << text;
00096 }
00097 
00098 void VCardFormatPlugin::saveAll( AddressBook*, Resource *resource, TQFile *file )
00099 {
00100   VCardConverter converter;
00101   Addressee::List vcardlist;
00102 
00103   Resource::Iterator it;
00104   for ( it = resource->begin(); it != resource->end(); ++it ) {
00105     (*it).setChanged( false );
00106     vcardlist.append( *it );
00107   }
00108 
00109   TQTextStream t( file );
00110   t.setEncoding( TQTextStream::UnicodeUTF8 );
00111   TQString text = converter.createVCards( vcardlist );
00112 //  kdDebug(5700)<< ">>>>>>>>> DEBUG <<<<<<<<<<" << endl;
00113 //  kdDebug(5700)<< text << endl;
00114 //  kdDebug(5700)<< ">>>>>>>>> DEBUG <<<<<<<<<<" << endl;
00115   t << text;
00116 }
00117 
00118 bool VCardFormatPlugin::checkFormat( TQFile *file ) const
00119 {
00120   TQString line;
00121 
00122   file->readLine( line, 1024 );
00123   line = line.stripWhiteSpace();
00124   if ( line == "BEGIN:VCARD" )
00125     return true;
00126   else
00127     return false;
00128 }

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.7.6.1
This website is maintained by Timothy Pearson.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. |