author | zautrix <zautrix> | 2004-09-18 08:25:05 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2004-09-18 08:25:05 (UTC) |
commit | 983b010853dfadfec3638e2afd90e522985f67fb (patch) (side-by-side diff) | |
tree | b691b7664b9f6f23d0d92a0e05bf3e8cbcf2df67 /kaddressbook | |
parent | df03bd8c7ff6a738dd386001679542ae4b493a07 (diff) | |
download | kdepimpi-983b010853dfadfec3638e2afd90e522985f67fb.zip kdepimpi-983b010853dfadfec3638e2afd90e522985f67fb.tar.gz kdepimpi-983b010853dfadfec3638e2afd90e522985f67fb.tar.bz2 |
more AB syncing
-rw-r--r-- | kaddressbook/kabcore.cpp | 95 | ||||
-rw-r--r-- | kaddressbook/kabcore.h | 5 |
2 files changed, 86 insertions, 14 deletions
diff --git a/kaddressbook/kabcore.cpp b/kaddressbook/kabcore.cpp index 49c3b19..e912941 100644 --- a/kaddressbook/kabcore.cpp +++ b/kaddressbook/kabcore.cpp @@ -143,16 +143,17 @@ $Id$ #ifdef _WIN32_ #include "kaimportoldialog.h" #else #include <unistd.h> #endif // sync includes #include <libkdepim/ksyncprofile.h> +#include <libkdepim/ksyncprefsdialog.h> bool pasteWithNewUid = true; #ifdef KAB_EMBEDDED KABCore::KABCore( KAddressBookMain *client, bool readWrite, QWidget *parent, const char *name ) : QWidget( parent, name ), mGUIClient( client ), mViewManager( 0 ), mExtensionManager( 0 ),mConfigureDialog( 0 ),/*US mLdapSearchDialog( 0 ),*/ @@ -174,16 +175,18 @@ KABCore::KABCore( KXMLGUIClient *client, bool readWrite, QWidget *parent, const #ifndef KAB_EMBEDDED mAddressBook->setErrorHandler( new KABC::GUIErrorHandler ); #endif //KAB_EMBEDDED connect( mAddressBook, SIGNAL( addressBookChanged( AddressBook * ) ), SLOT( addressBookChanged() ) ); +#if 0 + // LP moved to addressbook init method mAddressBook->addCustomField( i18n( "Department" ), KABC::Field::Organization, "X-Department", "KADDRESSBOOK" ); mAddressBook->addCustomField( i18n( "Profession" ), KABC::Field::Organization, "X-Profession", "KADDRESSBOOK" ); mAddressBook->addCustomField( i18n( "Assistant's Name" ), KABC::Field::Organization, "X-AssistantsName", "KADDRESSBOOK" ); mAddressBook->addCustomField( i18n( "Manager's Name" ), KABC::Field::Organization, "X-ManagersName", "KADDRESSBOOK" ); @@ -199,17 +202,17 @@ KABCore::KABCore( KXMLGUIClient *client, bool readWrite, QWidget *parent, const //US added this field to become compatible with Opie/qtopia addressbook // values can be "female" or "male" or "". An empty field represents undefined. mAddressBook->addCustomField( i18n( "Gender" ), KABC::Field::Personal, "X-Gender", "KADDRESSBOOK" ); mAddressBook->addCustomField( i18n( "Children" ), KABC::Field::Personal, "X-Children", "KADDRESSBOOK" ); mAddressBook->addCustomField( i18n( "FreeBusyUrl" ), KABC::Field::Personal, "X-FreeBusyUrl", "KADDRESSBOOK" ); - +#endif initGUI(); mIncSearchWidget->setFocus(); connect( mViewManager, SIGNAL( selected( const QString& ) ), SLOT( setContactSelected( const QString& ) ) ); connect( mViewManager, SIGNAL( executed( const QString& ) ), @@ -2190,18 +2193,18 @@ void KABCore::slotSyncMenu( int action ) } else if ( action == 1001 ) { syncLocalFile(); } else if ( action == 1002 ) { quickSyncLocalFile(); } else if ( action >= 1003 ) { if ( temp->getIsLocalFileSync() ) { - if ( syncWithFile( temp->getRemoteFileName( ), false ) ) - KABPrefs::instance()->mLastSyncedLocalFile = temp->getRemoteFileName(); + if ( syncWithFile( temp->getRemoteFileNameAB( ), false ) ) + KABPrefs::instance()->mLastSyncedLocalFile = temp->getRemoteFileNameAB(); } else { if ( temp->getIsPhoneSync() ) { KABPrefs::instance()->mPhoneDevice = temp->getPhoneDevice( ) ; KABPrefs::instance()->mPhoneConnection = temp->getPhoneConnection( ); KABPrefs::instance()->mPhoneModel = temp->getPhoneModel( ); syncPhone(); } else syncRemote( temp ); @@ -2312,34 +2315,34 @@ int KABCore::ringSync() KConfig config ( locateLocal( "config","ksyncprofilesrc" ) ); QStringList syncProfileNames = KABPrefs::instance()->mSyncProfileNames; KSyncProfile* temp = new KSyncProfile (); KABPrefs::instance()->mAskForPreferences = false; for ( i = 0; i < syncProfileNames.count(); ++i ) { mCurrentSyncProfile = i; temp->setName(syncProfileNames[mCurrentSyncProfile]); temp->readConfig(&config); - if ( temp->getIncludeInRingSync() && ( i < 1 || i > 2 )) { + if ( temp->getIncludeInRingSyncAB() && ( i < 1 || i > 2 )) { setCaption(i18n("Profile ")+syncProfileNames[mCurrentSyncProfile]+ i18n(" is synced ... ")); ++syncedProfiles; // KABPrefs::instance()->mAskForPreferences = temp->getAskForPreferences(); KABPrefs::instance()->mWriteBackFile = temp->getWriteBackFile(); KABPrefs::instance()->mWriteBackExistingOnly = temp->getWriteBackExisting(); KABPrefs::instance()->mWriteBackInFuture = 0; if ( temp->getWriteBackFuture() ) KABPrefs::instance()->mWriteBackInFuture = temp->getWriteBackFutureWeeks( ); KABPrefs::instance()->mShowSyncSummary = false; mCurrentSyncDevice = syncProfileNames[i] ; mCurrentSyncName = KABPrefs::instance()->mLocalMachineName; if ( i == 0 ) { syncSharp(); } else { if ( temp->getIsLocalFileSync() ) { - if ( syncWithFile( temp->getRemoteFileName( ), true ) ) - KABPrefs::instance()->mLastSyncedLocalFile = temp->getRemoteFileName(); + if ( syncWithFile( temp->getRemoteFileNameAB( ), true ) ) + KABPrefs::instance()->mLastSyncedLocalFile = temp->getRemoteFileNameAB(); } else { if ( temp->getIsPhoneSync() ) { KABPrefs::instance()->mPhoneDevice = temp->getPhoneDevice( ) ; KABPrefs::instance()->mPhoneConnection = temp->getPhoneConnection( ); KABPrefs::instance()->mPhoneModel = temp->getPhoneModel( ); syncPhone(); } else syncRemote( temp, false ); @@ -2368,17 +2371,17 @@ void KABCore::syncRemote( KSyncProfile* prof, bool ask) if ( ask ) { question = i18n("Do you really want\nto remote sync\nwith profile \n")+ prof->getName()+" ?\n"; if ( QMessageBox::information( this, i18n("KO/Pi Sync"), question, i18n("Yes"), i18n("No"), 0, 0 ) != 0 ) return; } - QString command = prof->getPreSyncCommand(); + QString command = prof->getPreSyncCommandAB(); int fi; if ( (fi = command.find("$PWD$")) > 0 ) { QString pwd = getPassword(); command = command.left( fi )+ pwd + command.mid( fi+5 ); } int maxlen = 30; if ( QApplication::desktop()->width() > 320 ) @@ -2400,23 +2403,23 @@ void KABCore::syncRemote( KSyncProfile* prof, bool ask) QMessageBox::information( this, i18n("KO/Pi Sync - ERROR"), question, i18n("Okay!")) ; setCaption ("KO/Pi"); return; } setCaption ( i18n( "Copying succeed." ) ); //qDebug(" file **%s** ",prof->getLocalTempFile().latin1() ); - if ( syncWithFile( prof->getLocalTempFile(), true ) ) { + if ( syncWithFile( prof->getLocalTempFileAB(), true ) ) { // Event* e = mView->getLastSyncEvent(); // e->setReadOnly( false ); // e->setLocation( KOPrefs::instance()->mSyncProfileNames[mCurrentSyncProfile]); // e->setReadOnly( true ); if ( KABPrefs::instance()->mWriteBackFile ) { - command = prof->getPostSyncCommand(); + command = prof->getPostSyncCommandAB(); int fi; if ( (fi = command.find("$PWD$")) > 0 ) { QString pwd = getPassword(); command = command.left( fi )+ pwd + command.mid( fi+5 ); } setCaption ( i18n( "Writing back file ..." ) ); result = system ( command ); @@ -2505,36 +2508,102 @@ QString KABCore::getPassword( ) int res = dia.exec(); if ( res ) retfile = lab.text(); dia.hide(); qApp->processEvents(); return retfile; } +bool KABCore::synchronizeAddressbooks( KABC::AddressBook* local, KABC::AddressBook* remote,int mode) +{ +} bool KABCore::syncAB(QString filename, int mode) { + + + mGlobalSyncMode = SYNC_MODE_NORMAL; + AddressBook abLocal(filename,"syncContact"); + bool syncOK = false; + if ( abLocal.load() ) { + qDebug("AB loaded %s mode %d",filename.latin1(), mode ); + AddressBook::Iterator it; + QStringList vcards; + for ( it = abLocal.begin(); it != abLocal.end(); ++it ) { + qDebug("Name %s ", (*it).familyName().latin1()); + } + syncOK = synchronizeAddressbooks( mAddressBook, &abLocal, mode ); + if ( syncOK ) { + if ( KABPrefs::instance()->mWriteBackFile ) + { + abLocal.saveAB(); + } + } + setModified(); + + } + if ( syncOK ) + ;//updateView(); + return syncOK; +#if 0 + mGlobalSyncMode = SYNC_MODE_NORMAL; + CalendarLocal* calendar = new CalendarLocal(); + calendar->setTimeZoneId(KOPrefs::instance()->mTimeZoneId); + FileStorage* storage = new FileStorage( calendar ); + bool syncOK = false; + storage->setFileName( filename ); + // qDebug("loading ... "); + if ( storage->load(KOPrefs::instance()->mUseQuicksave) ) { + getEventViewerDialog()->setSyncMode( true ); + syncOK = synchronizeCalendar( mCalendar, calendar, mode ); + getEventViewerDialog()->setSyncMode( false ); + if ( syncOK ) { + if ( KOPrefs::instance()->mWriteBackFile ) + { + storage->setSaveFormat( new ICalFormat( KOPrefs::instance()->mUseQuicksave) ); + storage->save(); + } + } + setModified(); + } + delete storage; + delete calendar; + if ( syncOK ) + updateView(); + return syncOK; +#endif } void KABCore::confSync() -{ - //mView->confSync(); - qDebug("pending KABCore::confSync() "); +{ + static KSyncPrefsDialog* sp = 0; + if ( ! sp ) { + sp = new KSyncPrefsDialog( this, "syncprefs", true ); + } + sp->usrReadConfig(); +#ifndef DESKTOP_VERSION + sp->showMaximized(); +#else + sp->show(); +#endif + sp->exec(); + KABPrefs::instance()->mSyncProfileNames = sp->getSyncProfileNames(); + KABPrefs::instance()->mLocalMachineName = sp->getLocalMachineName (); fillSyncMenu(); } void KABCore::syncSharp() { if ( mModified ) save(); qDebug("pending syncSharp() "); //mView->syncSharp(); - mModified = true ; + setModified(); } void KABCore::syncPhone() { if ( mModified ) save(); qDebug("pending syncPhone(); "); //mView->syncPhone(); diff --git a/kaddressbook/kabcore.h b/kaddressbook/kabcore.h index 10ce8f4..4487a8a 100644 --- a/kaddressbook/kabcore.h +++ b/kaddressbook/kabcore.h @@ -451,28 +451,31 @@ class KABCore : public QWidget #ifdef KAB_EMBEDDED KAddressBookMain *mMainWindow; // should be the same like mGUIClient #endif //KAB_EMBEDDED // LR ******************************* // sync stuff! QPopupMenu *syncMenu; void fillSyncMenu(); - void confSync(); QString mCurrentSyncDevice; QString mCurrentSyncName; void quickSyncLocalFile(); bool syncWithFile( QString fn , bool quick ); void KABCore::syncLocalFile(); void KABCore::syncPhone(); void KABCore::syncSharp(); void multiSync( bool askforPrefs ); int mCurrentSyncProfile ; void syncRemote( KSyncProfile* prof, bool ask = true); void edit_sync_options(); bool syncAB(QString filename, int mode); int ringSync(); QString getPassword( ); + int mGlobalSyncMode; + bool synchronizeAddressbooks( KABC::AddressBook* local, KABC::AddressBook* remote,int mode); + public slots: + void confSync(); // ********************* }; #endif |