vcardformatplugin.cpp
00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 #include <qfile.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, QFile *file )
00040 {
00041   QString data;
00042 
00043   QTextStream t( file );
00044   t.setEncoding( QTextStream::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, QFile *file )
00059 {
00060   QString data;
00061 
00062   QTextStream t( file );
00063   t.setEncoding( QTextStream::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, QFile *file )
00082 {
00083   VCardConverter converter ;
00084   Addressee::List vcardlist;
00085 
00086 
00087   vcardlist.append( addressee );
00088 
00089   QTextStream t( file );
00090   t.setEncoding( QTextStream::UnicodeUTF8 );
00091   t << converter.createVCards( vcardlist );
00092 }
00093 
00094 void VCardFormatPlugin::saveAll( AddressBook*, Resource *resource, QFile *file )
00095 {
00096   VCardConverter converter;
00097   Addressee::List vcardlist;
00098 
00099   Resource::Iterator it;
00100   for ( it = resource->begin(); it != resource->end(); ++it ) {
00101     (*it).setChanged( false );
00102     vcardlist.append( *it );
00103   }
00104 
00105   QTextStream t( file );
00106   t.setEncoding( QTextStream::UnicodeUTF8 );
00107   t << converter.createVCards( vcardlist );
00108 }
00109 
00110 bool VCardFormatPlugin::checkFormat( QFile *file ) const
00111 {
00112   QString line;
00113 
00114   file->readLine( line, 1024 );
00115   line = line.stripWhiteSpace();
00116   if ( line == "BEGIN:VCARD" )
00117     return true;
00118   else
00119     return false;
00120 }
 
This file is part of the documentation for kabc Library Version 3.2.0.