-rw-r--r-- | kabc/addressbook.cpp | 44 | ||||
-rw-r--r-- | kabc/addressbook.h | 3 |
2 files changed, 47 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 @@ -26,48 +26,49 @@ $Id$ */ /*US #include <qfile.h> #include <qregexp.h> #include <qtimer.h> #include <kapplication.h> #include <kinstance.h> #include <kstandarddirs.h> #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; Addressee::List mRemovedAddressees; Field::List mAllFields; KConfig *mConfig; KRES::Manager<Resource> *mManager; //US ErrorHandler *mErrorHandler; }; struct AddressBook::Iterator::IteratorData { Addressee::List::Iterator mIt; }; @@ -438,48 +439,91 @@ void AddressBook::setUntagged() { Iterator ait; for ( ait = begin(); ait != end(); ++ait ) { (*ait).setTagged( false ); } } void AddressBook::removeUntagged() { Iterator ait; bool todelete = false; Iterator todel; for ( ait = begin(); ait != end(); ++ait ) { 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; KRES::Manager<Resource> *manager = d->mManager; for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) { if ( !(*it)->readOnly() && (*it)->isOpen() ) { Ticket *ticket = requestSaveTicket( *it ); // qDebug("StdAddressBook::save '%s'", (*it)->resourceName().latin1() ); if ( !ticket ) { error( i18n( "Unable to save to resource '%1'. It is locked." ) .arg( (*it)->resourceName() ) ); return false; } //if ( !save( ticket ) ) diff --git a/kabc/addressbook.h b/kabc/addressbook.h index 532e05d..cc755d1 100644 --- a/kabc/addressbook.h +++ b/kabc/addressbook.h @@ -121,48 +121,51 @@ class AddressBook : public QObject /** Requests a ticket for saving the addressbook. Calling this function locks the addressbook for all other processes. If the address book is already locked the function returns 0. You need the returned @ref Ticket object for calling the @ref save() function. @see save() */ Ticket *requestSaveTicket( Resource *resource=0 ); /** Load address book from file. */ bool load(); /** Save address book. The address book is saved to the file, the Ticket object has been requested for by @ref requestSaveTicket(). @param ticket a ticket object returned by @ref requestSaveTicket() */ bool save( Ticket *ticket ); bool saveAB( ); + bool saveABphone( QString fileName ); + void smplifyAddressees(); + void preparePhoneSync( QString currentSyncDevice, bool isPreSync ); void export2File( QString fileName ); void importFromFile( QString fileName, bool replaceLabel = false, bool removeOld = false ); void setUntagged(); void removeUntagged(); /** Returns a iterator for first entry of address book. */ Iterator begin(); /** Returns a const iterator for first entry of address book. */ ConstIterator begin() const; /** Returns a iterator for first entry of address book. */ Iterator end(); /** Returns a const iterator for first entry of address book. */ ConstIterator end() const; |