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 const QByteArray rawData = file->readAll();
00042 const QCString data( rawData.data(), rawData.size() );
00043
00044 VCardConverter converter;
00045 Addressee::List l = converter.parseVCardsRaw( data );
00046
00047 if ( ! l.first().isEmpty() ) {
00048 addressee = l.first();
00049 return true;
00050 }
00051
00052 return false;
00053 }
00054
00055 bool VCardFormatPlugin::loadAll( AddressBook*, Resource *resource, QFile *file )
00056 {
00057 const QByteArray rawData = file->readAll();
00058 const QCString data( rawData.data(), rawData.size() );
00059
00060 VCardConverter converter;
00061 Addressee::List l = converter.parseVCardsRaw( data );
00062
00063 Addressee::List::iterator itr;
00064 for ( itr = l.begin(); itr != l.end(); ++itr) {
00065 Addressee addressee = *itr;
00066 addressee.setResource( resource );
00067 addressee.setChanged( false );
00068 resource->insertAddressee( addressee );
00069 }
00070
00071 return true;
00072 }
00073
00074 void VCardFormatPlugin::save( const Addressee &addressee, QFile *file )
00075 {
00076 VCardConverter converter ;
00077 Addressee::List vcardlist;
00078
00079
00080 vcardlist.append( addressee );
00081
00082 const QCString data = converter.createVCardsRaw( vcardlist );
00083 file->writeBlock( data, data.length() );
00084 }
00085
00086 void VCardFormatPlugin::saveAll( AddressBook*, Resource *resource, QFile *file )
00087 {
00088 VCardConverter converter;
00089 Addressee::List vcardlist;
00090
00091 Resource::Iterator it;
00092 for ( it = resource->begin(); it != resource->end(); ++it ) {
00093 (*it).setChanged( false );
00094 vcardlist.append( *it );
00095 }
00096
00097 const QCString data = converter.createVCardsRaw( vcardlist );
00098 file->writeBlock( data, data.length() );
00099 }
00100
00101 bool VCardFormatPlugin::checkFormat( QFile *file ) const
00102 {
00103 QString line;
00104
00105 file->readLine( line, 1024 );
00106 line = line.stripWhiteSpace();
00107 if ( line == "BEGIN:VCARD" )
00108 return true;
00109 else
00110 return false;
00111 }