-rw-r--r-- | kaddressbook/kabcore.cpp | 130 |
1 files changed, 108 insertions, 22 deletions
diff --git a/kaddressbook/kabcore.cpp b/kaddressbook/kabcore.cpp index 7d8586a..ab2824c 100644 --- a/kaddressbook/kabcore.cpp +++ b/kaddressbook/kabcore.cpp @@ -158,6 +158,7 @@ $Id$ #ifdef _WIN32_ #ifdef _OL_IMPORT_ #include "kaimportoldialog.h" +#include <libkdepim/ol_access.h> #endif #else #include <unistd.h> @@ -1369,32 +1370,80 @@ void KABCore::importVCard( const KURL &url, bool showPreview ) void KABCore::importFromOL() { #ifdef _OL_IMPORT_ - KAImportOLdialog* idgl = new KAImportOLdialog( i18n("Import Contacts from OL"), mAddressBook, this ); - idgl->exec(); - KABC::Addressee::List list = idgl->getAddressList(); - if ( list.count() > 0 ) { - KABC::Addressee::List listNew; - KABC::Addressee::List listExisting; - KABC::Addressee::List::Iterator it; - KABC::AddressBook::Iterator iter; - for ( it = list.begin(); it != list.end(); ++it ) { - if ( mAddressBook->findByUid((*it).uid() ).isEmpty()) - listNew.append( (*it) ); - else - listExisting.append( (*it) ); - } - if ( listExisting.count() > 0 ) - KMessageBox::information( this, i18n("%1 contacts not added to addressbook\nbecause they were already in the addressbook!").arg( listExisting.count() )); - if ( listNew.count() > 0 ) { - pasteWithNewUid = false; - pasteContacts( listNew ); - pasteWithNewUid = true; + KABC::Addressee::List list = OL_access::instance()->importOLcontacts(); + if ( list.count() > 0 ) { + KABC::Addressee::List listNew; + KABC::Addressee::List listExisting; + KABC::Addressee::List::Iterator it; + KABC::AddressBook::Iterator iter; + for ( it = list.begin(); it != list.end(); ++it ) { + if ( mAddressBook->findByUid((*it).uid() ).isEmpty()) + listNew.append( (*it) ); + else + listExisting.append( (*it) ); + } + QString mess = i18n("%1 contacts read from OL.\n\n%2 contacts added to addressbook!").arg( list.count()).arg( listNew.count() ); + if ( listExisting.count() > 0 ) + mess += "\n\n"+ i18n("%1 contacts not added to addressbook\nbecause they were already in the addressbook!").arg( listExisting.count() ); + + KMessageBox::information( this, mess ); + if ( listNew.count() > 0 ) { + pasteWithNewUid = false; + pasteContacts( listNew ); + pasteWithNewUid = true; + } } - } - delete idgl; #endif } +bool KABCore::readOLdata( KABC::AddressBook* local ) +{ +#ifdef _OL_IMPORT_ + QStringList folderList = OL_access::instance()->getFolderSelection( OL_CONTACT_DATA , i18n("Select Folder to sync")); + KABC::Addressee::List list; + if ( folderList.count() ) { + OL_access::instance()->readContactData( OL_access::instance()->getFolderFromID( 0, folderList[1] ) , &list, true ); + KABC::Addressee::List::Iterator it; + for ( it = list.begin(); it != list.end(); ++it ) { + (*it).setExternalUID( (*it).uid() ); + (*it).setOriginalExternalUID( (*it).uid() ); + (*it).setTempSyncStat( SYNC_TEMPSTATE_NEW_EXTERNAL ); + local->insertAddressee( (*it) , false, false ); + } + mOLsyncFolderID = folderList[1]; + //KMessageBox::information( this, i18n("OLsync folder ID ") + mOLsyncFolderID ); + } + return list.count() > 0; +#else + return false; +#endif +} +bool KABCore::writeOLdata( KABC::AddressBook* aBook ) +{ +#ifdef _OL_IMPORT_ + if ( !OL_access::instance()->setSelectedFolder( mOLsyncFolderID ) ) + return false; + KABC::AddressBook::Iterator it; + for ( it = aBook->begin(); it != aBook->end(); ++it ) { + if ( (*it).tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL ) { + KABC::Addressee addressee = (*it); + if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_ADDED_EXTERNAL ) { + (*it) = OL_access::instance()->addAddressee( (*it) ); + (*it).setTempSyncStat( SYNC_TEMPSTATE_NEW_ID ); + } else if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_DELETE ) { + OL_access::instance()->deleteAddressee( (*it) ); + } else if ( (*it).tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL ) { + //changed + (*it) = OL_access::instance()->changeAddressee( (*it) ); + (*it).setTempSyncStat( SYNC_TEMPSTATE_NEW_CSUM ); + } + } + } + return true; +#else + return false; +#endif +} void KABCore::importVCard( const QString &vCard, bool showPreview ) { mXXPortManager->importVCard( vCard, showPreview ); @@ -3374,12 +3423,49 @@ void KABCore::removeSyncInfo( QString syncProfile) setModified(); } +bool KABCore::syncOL() +{ + disableBR( true ); + QString mCurrentSyncDevice = syncManager->getCurrentSyncDevice(); + AddressBook abLocal; + if ( ! readOLdata( &abLocal ) ) + return false; + bool syncOK = false; + message(i18n("Data from OL loaded..."), false); + mGlobalSyncMode = SYNC_MODE_EXTERNAL; + message(i18n("Sync preprocessing..."),false); + abLocal.preOLSync( mAddressBook ,mCurrentSyncDevice ); + message(i18n("Synchronizing..."),false); + syncOK = synchronizeAddressbooks( mAddressBook, &abLocal, syncManager->mSyncAlgoPrefs ); + syncManager->hideProgressBar(); + if ( syncOK ) { + if ( syncManager->mWriteBackFile ) { + abLocal.removeSyncAddressees( false ); + message(i18n("Saving address data to OL..."),false); + //abLocal.saveAB(); + writeOLdata( &abLocal ); + message(i18n("Sync postprocessing..."),false); + abLocal.postExternSync( mAddressBook,mCurrentSyncDevice, true ); + } + } else + message( i18n("Sync cancelled or failed.") ); + setModified(); + abLocal.removeResources(); + if ( syncOK ) { + mViewManager->refreshView(); + message(i18n("OL syncing finished.")); + } + disableBR( false ); + return syncOK; +} //this is a overwritten callbackmethods from the syncinterface bool KABCore::syncExternal(KSyncManager* manager, QString resource) { if ( resource == "phone" ) return syncPhone(); + if ( resource == "ol" ) + return syncOL(); disableBR( true ); if ( manager != syncManager ) qDebug("KABCore::syncExternal:: ERROR! :: manager != syncManager "); |