author | zautrix <zautrix> | 2004-10-09 21:35:22 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2004-10-09 21:35:22 (UTC) |
commit | 213a9d993e5a4751b64e18320cfbebb000681d13 (patch) (side-by-side diff) | |
tree | 995b465797464e689b73d3271ff4a3f8f0d3749b | |
parent | d68435216e1ebc5a7fed391157197994e13992b3 (diff) | |
download | kdepimpi-213a9d993e5a4751b64e18320cfbebb000681d13.zip kdepimpi-213a9d993e5a4751b64e18320cfbebb000681d13.tar.gz kdepimpi-213a9d993e5a4751b64e18320cfbebb000681d13.tar.bz2 |
ab phone sync implemented
-rw-r--r-- | kabc/addressbook.cpp | 44 | ||||
-rw-r--r-- | kabc/addressbook.h | 3 | ||||
-rw-r--r-- | kaddressbook/kabcore.cpp | 65 | ||||
-rw-r--r-- | kaddressbook/kabcore.h | 3 | ||||
-rw-r--r-- | libkcal/phoneformat.cpp | 12 | ||||
-rw-r--r-- | libkdepim/phoneaccess.cpp | 24 | ||||
-rw-r--r-- | libkdepim/phoneaccess.h | 2 |
7 files changed, 123 insertions, 30 deletions
diff --git a/kabc/addressbook.cpp b/kabc/addressbook.cpp index 16927e2..d037d2f 100644 --- a/kabc/addressbook.cpp +++ b/kabc/addressbook.cpp @@ -49,2 +49,3 @@ $Id$ #include <libkcal/syncdefines.h> +#include <libkdepim/phoneaccess.h> #include "addressbook.h" @@ -461,2 +462,45 @@ void AddressBook::removeUntagged() } +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() diff --git a/kabc/addressbook.h b/kabc/addressbook.h index 532e05d..cc755d1 100644 --- a/kabc/addressbook.h +++ b/kabc/addressbook.h @@ -144,2 +144,5 @@ class AddressBook : public QObject bool saveAB( ); + bool saveABphone( QString fileName ); + void smplifyAddressees(); + void preparePhoneSync( QString currentSyncDevice, bool isPreSync ); void export2File( QString fileName ); diff --git a/kaddressbook/kabcore.cpp b/kaddressbook/kabcore.cpp index 452f1bc..a7967cb 100644 --- a/kaddressbook/kabcore.cpp +++ b/kaddressbook/kabcore.cpp @@ -2825,19 +2825,3 @@ bool KABCore::sync(KSyncManager* manager, QString filename, int mode) return syncOK; -#if 0 - 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(); - } - -#endif } @@ -2848,2 +2832,4 @@ bool KABCore::syncExternal(KSyncManager* manager, QString resource) { + if ( resource == "phone" ) + return syncPhone(); QString mCurrentSyncDevice = manager->getCurrentSyncDevice(); @@ -2870,8 +2856,47 @@ bool KABCore::syncExternal(KSyncManager* manager, QString resource) } - -void KABCore::getFile( bool success ) +void KABCore::message( QString m ) { + + topLevelWidget()->setCaption( m ); QTimer::singleShot( 15000, this , SLOT ( setCaptionBack())); +} +bool KABCore::syncPhone() +{ + QString mCurrentSyncDevice = syncManager->getCurrentSyncDevice(); + QString fileName; +#ifdef _WIN32_ + fileName = locateLocal("tmp", "phonefile.vcf"); +#else + fileName = "/tmp/phonefile.vcf"; +#endif + if ( !PhoneAccess::readFromPhone( fileName) ) { + message(i18n("Phone access failed!")); + return false; + } + AddressBook abLocal( fileName,"syncContact"); + bool syncOK = false; + if ( abLocal.load() ) { + qDebug("AB phone loaded ,sync device %s",mCurrentSyncDevice.latin1()); + mGlobalSyncMode = SYNC_MODE_EXTERNAL; + abLocal.preparePhoneSync( mCurrentSyncDevice, true ); + abLocal.preExternSync( mAddressBook ,mCurrentSyncDevice ); + syncOK = synchronizeAddressbooks( mAddressBook, &abLocal, syncManager->mSyncAlgoPrefs ); + if ( syncOK ) { + if ( syncManager->mWriteBackFile ) { + abLocal.saveABphone( fileName ); + abLocal.preparePhoneSync( mCurrentSyncDevice, false ); + abLocal.preExternSync( mAddressBook ,mCurrentSyncDevice ); + abLocal.postExternSync( mAddressBook,mCurrentSyncDevice ); + } + } + setModified(); + } + if ( syncOK ) + mViewManager->refreshView(); + return syncOK; +} +void KABCore::getFile( bool success ) +{ if ( ! success ) { - setCaption( i18n("Error receiving file. Nothing changed!") ); + message( i18n("Error receiving file. Nothing changed!") ); return; @@ -2879,3 +2904,3 @@ void KABCore::getFile( bool success ) mAddressBook->importFromFile( sentSyncFile() , false, true ); - topLevelWidget()->setCaption( i18n("Pi-Sync successful!") ); + message( i18n("Pi-Sync successful!") ); mViewManager->refreshView(); diff --git a/kaddressbook/kabcore.h b/kaddressbook/kabcore.h index 43c5f99..04ce33d 100644 --- a/kaddressbook/kabcore.h +++ b/kaddressbook/kabcore.h @@ -466,3 +466,4 @@ class KABCore : public QWidget, public KSyncInterface virtual bool syncExternal(KSyncManager* manager, QString resource); - + bool syncPhone(); + void message( QString m ); diff --git a/libkcal/phoneformat.cpp b/libkcal/phoneformat.cpp index c39413e..3555dc6 100644 --- a/libkcal/phoneformat.cpp +++ b/libkcal/phoneformat.cpp @@ -293,12 +293,8 @@ bool PhoneFormat::load( Calendar *calendar, Calendar *existingCal) #ifdef _WIN32_ - fileName = locateLocal("tmp", "tempfile.vcs"); + fileName = locateLocal("tmp", "phonefile.vcs"); #else - fileName = "/tmp/kdepimtemp.vcs"; + fileName = "/tmp/phonefile.vcs"; #endif -#ifdef DESKTOP_VERSION - QString command ="./kammu --backup " + fileName + " -yes" ; -#else - QString command ="kammu --backup " + fileName + " -yes" ; -#endif - int ret = system ( command.latin1() ); + QString command; + int ret = PhoneAccess::readFromPhone( fileName ); if ( ret != 0 ) { diff --git a/libkdepim/phoneaccess.cpp b/libkdepim/phoneaccess.cpp index fe914dd..5fafa1f 100644 --- a/libkdepim/phoneaccess.cpp +++ b/libkdepim/phoneaccess.cpp @@ -145,3 +145,25 @@ bool PhoneAccess::writeToPhone( QString fileName) int retval = KMessageBox::warningContinueCancel(0, - i18n("Error accessing device!\nPlease turn on connection\nand retry!"),i18n("KO/Pi phone access"),i18n("Retry"),i18n("Cancel")); + i18n("Error accessing device!\nPlease turn on connection\nand retry!"),i18n("KDE/Pim phone access"),i18n("Retry"),i18n("Cancel")); + if ( retval != KMessageBox::Continue ) + return false; + } + return true; +} +bool PhoneAccess::readFromPhone( QString fileName) +{ + +#ifdef DESKTOP_VERSION +#ifdef _WIN32_ + QString command ="kammu --backup " + fileName + " -yes" ; +#else + QString command ="./kammu --backup " + fileName + " -yes" ; +#endif +#else + QString command ="kammu --backup " + fileName + " -yes" ; +#endif + int ret; + while ( (ret = system ( command.latin1())) != 0 ) { + qDebug("Error S::command returned %d.", ret); + int retval = KMessageBox::warningContinueCancel(0, + i18n("Error accessing device!\nPlease turn on connection\nand retry!"),i18n("KDE/Pim phone access"),i18n("Retry"),i18n("Cancel")); if ( retval != KMessageBox::Continue ) diff --git a/libkdepim/phoneaccess.h b/libkdepim/phoneaccess.h index b7c4732..80840e2 100644 --- a/libkdepim/phoneaccess.h +++ b/libkdepim/phoneaccess.h @@ -24,2 +24,3 @@ #include <qstring.h> +#include <qobject.h> @@ -36,2 +37,3 @@ class PhoneAccess : public QObject { static bool writeToPhone( QString fileName ); + static bool readFromPhone( QString fileName ); |