summaryrefslogtreecommitdiffabout
path: root/kaddressbook/kabcore.cpp
Side-by-side diff
Diffstat (limited to 'kaddressbook/kabcore.cpp') (more/less context) (show whitespace changes)
-rw-r--r--kaddressbook/kabcore.cpp96
1 files changed, 91 insertions, 5 deletions
diff --git a/kaddressbook/kabcore.cpp b/kaddressbook/kabcore.cpp
index 7d8586a..ab2824c 100644
--- a/kaddressbook/kabcore.cpp
+++ b/kaddressbook/kabcore.cpp
@@ -137,48 +137,49 @@ $Id$
#include <qbuttongroup.h>
#include <libkdepim/categoryselectdialog.h>
#include <libkdepim/categoryeditdialog.h>
#include <kabc/vcardconverter.h>
#include "addresseeutil.h"
#include "undocmds.h"
#include "addresseeeditordialog.h"
#include "viewmanager.h"
#include "details/detailsviewcontainer.h"
#include "kabprefs.h"
#include "xxportmanager.h"
#include "incsearchwidget.h"
#include "jumpbuttonbar.h"
#include "extensionmanager.h"
#include "addresseeconfig.h"
#include "nameeditdialog.h"
#include <kcmultidialog.h>
#ifdef _WIN32_
#ifdef _OL_IMPORT_
#include "kaimportoldialog.h"
+#include <libkdepim/ol_access.h>
#endif
#else
#include <unistd.h>
#endif
// sync includes
#include <libkdepim/ksyncprofile.h>
#include <libkdepim/ksyncprefsdialog.h>
class KABCatPrefs : public QDialog
{
public:
KABCatPrefs( QWidget *parent=0, const char *name=0 ) :
QDialog( parent, name, true )
{
setCaption( i18n("Manage new Categories") );
QVBoxLayout* lay = new QVBoxLayout( this );
lay->setSpacing( 3 );
lay->setMargin( 3 );
QLabel * lab = new QLabel( i18n("After importing/loading/syncing\nthere may be new categories in\naddressees\nwhich are not in the category list.\nPlease choose what to do:\n "), this );
lay->addWidget( lab );
QButtonGroup* format = new QButtonGroup( 1, Horizontal, i18n("New categories not in list:"), this );
lay->addWidget( format );
format->setExclusive ( true ) ;
@@ -1348,74 +1349,122 @@ void KABCore::addEmail( QString aStr )
}
}
if ( !found ) {
KABC::Addressee addr;
addr.setNameFromString( fullName );
addr.insertEmail( email, true );
mAddressBook->insertAddressee( addr );
mViewManager->refreshView( addr.uid() );
editContact( addr.uid() );
}
#else //KAB_EMBEDDED
qDebug("KABCore::addEmail finsih method");
#endif //KAB_EMBEDDED
}
void KABCore::importVCard( const KURL &url, bool showPreview )
{
mXXPortManager->importVCard( url, 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();
+ 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 )
- KMessageBox::information( this, i18n("%1 contacts not added to addressbook\nbecause they were already in the addressbook!").arg( listExisting.count() ));
+ 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 );
}
//US added a second method without defaultparameter
void KABCore::editContact2() {
editContact( QString::null );
}
void KABCore::editContact( const QString &uid )
{
if ( mExtensionManager->isQuickEditVisible() )
return;
// First, locate the contact entry
QString localUID = uid;
if ( localUID.isNull() ) {
QStringList uidList = mViewManager->selectedUids();
if ( uidList.count() > 0 )
localUID = *( uidList.at( 0 ) );
}
@@ -3353,54 +3402,91 @@ bool KABCore::sync(KSyncManager* manager, QString filename, int mode,QString res
if ( ! abLocal.saveAB())
qDebug("KA: sync::Error writing back AB to file ");
if ( external ) {
// afterwrite processing
abLocal.postExternSync( mAddressBook,mCurrentSyncDevice ,isXML);
}
}
}
setModified();
}
abLocal.removeResources();
if ( syncOK )
mViewManager->refreshView();
return syncOK;
}
void KABCore::removeSyncInfo( QString syncProfile)
{
qDebug("KA: AB:removeSyncInfo for profile %s ", syncProfile.latin1());
mAddressBook->removeSyncInfo( 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 ");
QString mCurrentSyncDevice = manager->getCurrentSyncDevice();
AddressBook abLocal( resource,"syncContact");
bool syncOK = false;
message(i18n("Loading DTM address data..."), false);
if ( abLocal.load() ) {
qDebug("KA: AB sharp loaded ,sync device %s",mCurrentSyncDevice.latin1());
mGlobalSyncMode = SYNC_MODE_EXTERNAL;
message(i18n("Sync preprocessing..."),false);
abLocal.preExternSync( mAddressBook ,mCurrentSyncDevice, false );
message(i18n("Synchronizing..."),false);
syncOK = synchronizeAddressbooks( mAddressBook, &abLocal, syncManager->mSyncAlgoPrefs );
syncManager->hideProgressBar();
if ( syncOK ) {
if ( syncManager->mWriteBackFile ) {
abLocal.removeSyncAddressees( false );
message(i18n("Saving DTM address data..."),false);
abLocal.saveAB();
message(i18n("Sync postprocessing..."),false);
abLocal.postExternSync( mAddressBook,mCurrentSyncDevice, true );
}