simpleformat.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 <ksimpleconfig.h>
00024 #include <kdebug.h>
00025
00026 #include "addressbook.h"
00027
00028 #include "simpleformat.h"
00029
00030 using namespace KABC;
00031
00032 bool SimpleFormat::load( AddressBook *addressBook, const QString &fileName )
00033 {
00034 kdDebug(5700) << "SimpleFormat::load(): " << fileName << endl;
00035
00036 KSimpleConfig cfg( fileName );
00037
00038 QStringList uids = cfg.groupList();
00039 QStringList::ConstIterator it;
00040 for( it = uids.begin(); it != uids.end(); ++it ) {
00041 if ( (*it) == "<default>" ) continue;
00042 cfg.setGroup( *it );
00043 Addressee a;
00044 a.setUid( *it );
00045 a.setName( cfg.readEntry( "name" ) );
00046 a.setFormattedName( cfg.readEntry( "formattedName" ) );
00047 a.insertEmail( cfg.readEntry( "email" ) );
00048 #if 0
00049 QStringList phoneNumbers = cfg.readListEntry( "phonenumbers" );
00050 QStringList::ConstIterator it2;
00051 for( it2 = phoneNumbers.begin(); it2 != phoneNumbers.end(); ++it2 ) {
00052 PhoneNumber n;
00053 n.setNumber( cfg.readEntry( "phonenumber" + (*it2) ) );
00054 n.setType( PhoneNumber::Type((*it2).toInt()));
00055 a.insertPhoneNumber( n );
00056 }
00057 #endif
00058 addressBook->insertAddressee( a );
00059 }
00060
00061 return true;
00062 }
00063
00064 bool SimpleFormat::save( AddressBook *addressBook, const QString &fileName )
00065 {
00066 kdDebug(5700) << "SimpleFormat::save(): " << fileName << endl;
00067
00068 QFile::remove( fileName );
00069
00070 KSimpleConfig cfg( fileName );
00071
00072 AddressBook::Iterator it;
00073 for ( it = addressBook->begin(); it != addressBook->end(); ++it ) {
00074 cfg.setGroup( (*it).uid() );
00075 cfg.writeEntry( "name", (*it).name() );
00076 cfg.writeEntry( "formattedName", (*it).formattedName() );
00077 cfg.writeEntry( "email", (*it).preferredEmail() );
00078
00079 #if 0
00080 QStringList phoneNumberList;
00081 PhoneNumber::List phoneNumbers = (*it).phoneNumbers();
00082 PhoneNumber::List::ConstIterator it2;
00083 for( it2 = phoneNumbers.begin(); it2 != phoneNumbers.end(); ++it2 ) {
00084 cfg.writeEntry( "phonenumber" + QString::number( int((*it2).type()) ),
00085 (*it2).number() );
00086 phoneNumberList.append( QString::number( int((*it2).type()) ) );
00087 }
00088 cfg.writeEntry( "phonenumbers", phoneNumberList );
00089 #endif
00090 }
00091
00092 return true;
00093 }
This file is part of the documentation for kdelibs Version 3.1.5.