-rw-r--r-- | kabc/addressbook.cpp | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/kabc/addressbook.cpp b/kabc/addressbook.cpp index 16927e2..d037d2f 100644 --- a/kabc/addressbook.cpp +++ b/kabc/addressbook.cpp @@ -38,24 +38,25 @@ $Id$ #include "errorhandler.h" */ #include <qptrlist.h> #include <qtextstream.h> #include <qfile.h> #include <qregexp.h> #include <kglobal.h> #include <klocale.h> #include <kmessagebox.h> #include <kdebug.h> #include <libkcal/syncdefines.h> +#include <libkdepim/phoneaccess.h> #include "addressbook.h" #include "resource.h" #include "vcardconverter.h" #include "vcardparser/vcardtool.h" //US #include "addressbook.moc" using namespace KABC; struct AddressBook::AddressBookData { Addressee::List mAddressees; @@ -450,24 +451,67 @@ void AddressBook::removeUntagged() if ( todelete ) removeAddressee( todel ); if (!(*ait).tagged()) { todelete = true; todel = ait; } else todelete = false; } if ( todelete ) removeAddressee( todel ); deleteRemovedAddressees(); } +void AddressBook::smplifyAddressees() +{ + Iterator ait; + for ( ait = begin(); ait != end(); ++ait ) { + (*ait).simplifyEmails(); + (*ait).simplifyPhoneNumbers(); + (*ait).simplifyPhoneNumberTypes(); + (*ait).simplifyAddresses(); + } +} +void AddressBook::preparePhoneSync( QString currentSyncDevice, bool isPreSync ) +{ + Iterator ait; + for ( ait = begin(); ait != end(); ++ait ) { + QString id = (*ait).IDStr(); + (*ait).setIDStr( ":"); + (*ait).setExternalUID( id ); + (*ait).setOriginalExternalUID( id ); + if ( isPreSync ) + (*ait).setTempSyncStat( SYNC_TEMPSTATE_NEW_EXTERNAL ); + else + (*ait).setTempSyncStat( SYNC_TEMPSTATE_NEW_ID ); + } +} +bool AddressBook::saveABphone( QString fileName ) +{ + smplifyAddressees(); + qDebug("saveABphone:: saving AB... "); + if ( ! saveAB() ) + return false; + qDebug("saveABphone:: writing to phone... "); + if ( !PhoneAccess::writeToPhone( fileName) ) { + return false; + } + qDebug("saveABphone:: re-reading from phone... "); + if ( !PhoneAccess::readFromPhone( fileName) ) { + return false; + } + qDebug("reloading phone book... "); + if ( !load() ) + return false; + return true; +} bool AddressBook::saveAB() { bool ok = true; deleteRemovedAddressees(); Iterator ait; for ( ait = begin(); ait != end(); ++ait ) { if ( !(*ait).IDStr().isEmpty() ) { (*ait).insertCustom( "KADDRESSBOOK", "X-ExternalID", (*ait).IDStr() ); } } KRES::Manager<Resource>::ActiveIterator it; |