summaryrefslogtreecommitdiffabout
path: root/kaddressbook/kabcore.cpp
Unidiff
Diffstat (limited to 'kaddressbook/kabcore.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--kaddressbook/kabcore.cpp130
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$
158#ifdef _WIN32_ 158#ifdef _WIN32_
159#ifdef _OL_IMPORT_ 159#ifdef _OL_IMPORT_
160#include "kaimportoldialog.h" 160#include "kaimportoldialog.h"
161#include <libkdepim/ol_access.h>
161#endif 162#endif
162#else 163#else
163#include <unistd.h> 164#include <unistd.h>
@@ -1369,32 +1370,80 @@ void KABCore::importVCard( const KURL &url, bool showPreview )
1369void KABCore::importFromOL() 1370void KABCore::importFromOL()
1370{ 1371{
1371#ifdef _OL_IMPORT_ 1372#ifdef _OL_IMPORT_
1372 KAImportOLdialog* idgl = new KAImportOLdialog( i18n("Import Contacts from OL"), mAddressBook, this ); 1373 KABC::Addressee::List list = OL_access::instance()->importOLcontacts();
1373 idgl->exec(); 1374 if ( list.count() > 0 ) {
1374 KABC::Addressee::List list = idgl->getAddressList(); 1375 KABC::Addressee::List listNew;
1375 if ( list.count() > 0 ) { 1376 KABC::Addressee::List listExisting;
1376 KABC::Addressee::List listNew; 1377 KABC::Addressee::List::Iterator it;
1377 KABC::Addressee::List listExisting; 1378 KABC::AddressBook::Iterator iter;
1378 KABC::Addressee::List::Iterator it; 1379 for ( it = list.begin(); it != list.end(); ++it ) {
1379 KABC::AddressBook::Iterator iter; 1380 if ( mAddressBook->findByUid((*it).uid() ).isEmpty())
1380 for ( it = list.begin(); it != list.end(); ++it ) { 1381 listNew.append( (*it) );
1381 if ( mAddressBook->findByUid((*it).uid() ).isEmpty()) 1382 else
1382 listNew.append( (*it) ); 1383 listExisting.append( (*it) );
1383 else 1384 }
1384 listExisting.append( (*it) ); 1385 QString mess = i18n("%1 contacts read from OL.\n\n%2 contacts added to addressbook!").arg( list.count()).arg( listNew.count() );
1385 } 1386 if ( listExisting.count() > 0 )
1386 if ( listExisting.count() > 0 ) 1387 mess += "\n\n"+ i18n("%1 contacts not added to addressbook\nbecause they were already in the addressbook!").arg( listExisting.count() );
1387 KMessageBox::information( this, i18n("%1 contacts not added to addressbook\nbecause they were already in the addressbook!").arg( listExisting.count() )); 1388
1388 if ( listNew.count() > 0 ) { 1389 KMessageBox::information( this, mess );
1389 pasteWithNewUid = false; 1390 if ( listNew.count() > 0 ) {
1390 pasteContacts( listNew ); 1391 pasteWithNewUid = false;
1391 pasteWithNewUid = true; 1392 pasteContacts( listNew );
1393 pasteWithNewUid = true;
1394 }
1392 } 1395 }
1393 }
1394 delete idgl;
1395#endif 1396#endif
1396} 1397}
1397 1398
1399bool KABCore::readOLdata( KABC::AddressBook* local )
1400{
1401#ifdef _OL_IMPORT_
1402 QStringList folderList = OL_access::instance()->getFolderSelection( OL_CONTACT_DATA , i18n("Select Folder to sync"));
1403 KABC::Addressee::List list;
1404 if ( folderList.count() ) {
1405 OL_access::instance()->readContactData( OL_access::instance()->getFolderFromID( 0, folderList[1] ) , &list, true );
1406 KABC::Addressee::List::Iterator it;
1407 for ( it = list.begin(); it != list.end(); ++it ) {
1408 (*it).setExternalUID( (*it).uid() );
1409 (*it).setOriginalExternalUID( (*it).uid() );
1410 (*it).setTempSyncStat( SYNC_TEMPSTATE_NEW_EXTERNAL );
1411 local->insertAddressee( (*it) , false, false );
1412 }
1413 mOLsyncFolderID = folderList[1];
1414 //KMessageBox::information( this, i18n("OLsync folder ID ") + mOLsyncFolderID );
1415 }
1416 return list.count() > 0;
1417#else
1418 return false;
1419#endif
1420}
1421bool KABCore::writeOLdata( KABC::AddressBook* aBook )
1422{
1423#ifdef _OL_IMPORT_
1424 if ( !OL_access::instance()->setSelectedFolder( mOLsyncFolderID ) )
1425 return false;
1426 KABC::AddressBook::Iterator it;
1427 for ( it = aBook->begin(); it != aBook->end(); ++it ) {
1428 if ( (*it).tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL ) {
1429 KABC::Addressee addressee = (*it);
1430 if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_ADDED_EXTERNAL ) {
1431 (*it) = OL_access::instance()->addAddressee( (*it) );
1432 (*it).setTempSyncStat( SYNC_TEMPSTATE_NEW_ID );
1433 } else if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_DELETE ) {
1434 OL_access::instance()->deleteAddressee( (*it) );
1435 } else if ( (*it).tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL ) {
1436 //changed
1437 (*it) = OL_access::instance()->changeAddressee( (*it) );
1438 (*it).setTempSyncStat( SYNC_TEMPSTATE_NEW_CSUM );
1439 }
1440 }
1441 }
1442 return true;
1443#else
1444 return false;
1445#endif
1446}
1398void KABCore::importVCard( const QString &vCard, bool showPreview ) 1447void KABCore::importVCard( const QString &vCard, bool showPreview )
1399{ 1448{
1400 mXXPortManager->importVCard( vCard, showPreview ); 1449 mXXPortManager->importVCard( vCard, showPreview );
@@ -3374,12 +3423,49 @@ void KABCore::removeSyncInfo( QString syncProfile)
3374 setModified(); 3423 setModified();
3375} 3424}
3376 3425
3426bool KABCore::syncOL()
3427{
3428 disableBR( true );
3429 QString mCurrentSyncDevice = syncManager->getCurrentSyncDevice();
3430 AddressBook abLocal;
3431 if ( ! readOLdata( &abLocal ) )
3432 return false;
3433 bool syncOK = false;
3434 message(i18n("Data from OL loaded..."), false);
3435 mGlobalSyncMode = SYNC_MODE_EXTERNAL;
3436 message(i18n("Sync preprocessing..."),false);
3437 abLocal.preOLSync( mAddressBook ,mCurrentSyncDevice );
3438 message(i18n("Synchronizing..."),false);
3439 syncOK = synchronizeAddressbooks( mAddressBook, &abLocal, syncManager->mSyncAlgoPrefs );
3440 syncManager->hideProgressBar();
3441 if ( syncOK ) {
3442 if ( syncManager->mWriteBackFile ) {
3443 abLocal.removeSyncAddressees( false );
3444 message(i18n("Saving address data to OL..."),false);
3445 //abLocal.saveAB();
3446 writeOLdata( &abLocal );
3447 message(i18n("Sync postprocessing..."),false);
3448 abLocal.postExternSync( mAddressBook,mCurrentSyncDevice, true );
3449 }
3450 } else
3451 message( i18n("Sync cancelled or failed.") );
3452 setModified();
3453 abLocal.removeResources();
3454 if ( syncOK ) {
3455 mViewManager->refreshView();
3456 message(i18n("OL syncing finished."));
3457 }
3458 disableBR( false );
3459 return syncOK;
3460}
3377 3461
3378//this is a overwritten callbackmethods from the syncinterface 3462//this is a overwritten callbackmethods from the syncinterface
3379bool KABCore::syncExternal(KSyncManager* manager, QString resource) 3463bool KABCore::syncExternal(KSyncManager* manager, QString resource)
3380{ 3464{
3381 if ( resource == "phone" ) 3465 if ( resource == "phone" )
3382 return syncPhone(); 3466 return syncPhone();
3467 if ( resource == "ol" )
3468 return syncOL();
3383 disableBR( true ); 3469 disableBR( true );
3384 if ( manager != syncManager ) 3470 if ( manager != syncManager )
3385 qDebug("KABCore::syncExternal:: ERROR! :: manager != syncManager "); 3471 qDebug("KABCore::syncExternal:: ERROR! :: manager != syncManager ");