summaryrefslogtreecommitdiffabout
authorzautrix <zautrix>2004-10-09 21:35:22 (UTC)
committer zautrix <zautrix>2004-10-09 21:35:22 (UTC)
commit213a9d993e5a4751b64e18320cfbebb000681d13 (patch) (side-by-side diff)
tree995b465797464e689b73d3271ff4a3f8f0d3749b
parentd68435216e1ebc5a7fed391157197994e13992b3 (diff)
downloadkdepimpi-213a9d993e5a4751b64e18320cfbebb000681d13.zip
kdepimpi-213a9d993e5a4751b64e18320cfbebb000681d13.tar.gz
kdepimpi-213a9d993e5a4751b64e18320cfbebb000681d13.tar.bz2
ab phone sync implemented
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--kabc/addressbook.cpp44
-rw-r--r--kabc/addressbook.h3
-rw-r--r--kaddressbook/kabcore.cpp65
-rw-r--r--kaddressbook/kabcore.h3
-rw-r--r--libkcal/phoneformat.cpp12
-rw-r--r--libkdepim/phoneaccess.cpp24
-rw-r--r--libkdepim/phoneaccess.h2
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
@@ -48,4 +48,5 @@ $Id$
#include <kdebug.h>
#include <libkcal/syncdefines.h>
+#include <libkdepim/phoneaccess.h>
#include "addressbook.h"
#include "resource.h"
@@ -460,4 +461,47 @@ void AddressBook::removeUntagged()
deleteRemovedAddressees();
}
+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
@@ -143,4 +143,7 @@ class AddressBook : public QObject
bool save( Ticket *ticket );
bool saveAB( );
+ bool saveABphone( QString fileName );
+ void smplifyAddressees();
+ void preparePhoneSync( QString currentSyncDevice, bool isPreSync );
void export2File( QString fileName );
void importFromFile( QString fileName, bool replaceLabel = false, bool removeOld = false );
diff --git a/kaddressbook/kabcore.cpp b/kaddressbook/kabcore.cpp
index 452f1bc..a7967cb 100644
--- a/kaddressbook/kabcore.cpp
+++ b/kaddressbook/kabcore.cpp
@@ -2824,21 +2824,5 @@ bool KABCore::sync(KSyncManager* manager, QString filename, int mode)
mViewManager->refreshView();
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
}
@@ -2847,4 +2831,6 @@ bool KABCore::sync(KSyncManager* manager, QString filename, int mode)
bool KABCore::syncExternal(KSyncManager* manager, QString resource)
{
+ if ( resource == "phone" )
+ return syncPhone();
QString mCurrentSyncDevice = manager->getCurrentSyncDevice();
@@ -2869,14 +2855,53 @@ 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;
}
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
@@ -465,5 +465,6 @@ class KABCore : public QWidget, public KSyncInterface
virtual bool sync(KSyncManager* manager, QString filename, int mode);
virtual bool syncExternal(KSyncManager* manager, QString resource);
-
+ bool syncPhone();
+ void message( QString m );
// LR *******************************
diff --git a/libkcal/phoneformat.cpp b/libkcal/phoneformat.cpp
index c39413e..3555dc6 100644
--- a/libkcal/phoneformat.cpp
+++ b/libkcal/phoneformat.cpp
@@ -292,14 +292,10 @@ bool PhoneFormat::load( Calendar *calendar, Calendar *existingCal)
QString fileName;
#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 ) {
qDebug("Error::command returned %d", ret);
diff --git a/libkdepim/phoneaccess.cpp b/libkdepim/phoneaccess.cpp
index fe914dd..5fafa1f 100644
--- a/libkdepim/phoneaccess.cpp
+++ b/libkdepim/phoneaccess.cpp
@@ -144,5 +144,27 @@ bool PhoneAccess::writeToPhone( QString fileName)
qDebug("Error S::command returned %d.", ret);
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 )
return false;
diff --git a/libkdepim/phoneaccess.h b/libkdepim/phoneaccess.h
index b7c4732..80840e2 100644
--- a/libkdepim/phoneaccess.h
+++ b/libkdepim/phoneaccess.h
@@ -23,4 +23,5 @@
#include <qstring.h>
+#include <qobject.h>
@@ -35,4 +36,5 @@ class PhoneAccess : public QObject {
static void writeConfig( QString device,QString connection, QString model );
static bool writeToPhone( QString fileName );
+ static bool readFromPhone( QString fileName );
};