summaryrefslogtreecommitdiffabout
Side-by-side diff
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
@@ -47,6 +47,7 @@ $Id$
#include <kmessagebox.h>
#include <kdebug.h>
#include <libkcal/syncdefines.h>
+#include <libkdepim/phoneaccess.h>
#include "addressbook.h"
#include "resource.h"
#include "vcardconverter.h"
@@ -459,6 +460,49 @@ void AddressBook::removeUntagged()
removeAddressee( todel );
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()
{
bool ok = true;
diff --git a/kabc/addressbook.h b/kabc/addressbook.h
index 532e05d..cc755d1 100644
--- a/kabc/addressbook.h
+++ b/kabc/addressbook.h
@@ -142,6 +142,9 @@ 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 );
void setUntagged();
diff --git a/kaddressbook/kabcore.cpp b/kaddressbook/kabcore.cpp
index 452f1bc..a7967cb 100644
--- a/kaddressbook/kabcore.cpp
+++ b/kaddressbook/kabcore.cpp
@@ -2823,29 +2823,15 @@ bool KABCore::sync(KSyncManager* manager, QString filename, int mode)
if ( syncOK )
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
}
//this is a overwritten callbackmethods from the syncinterface
bool KABCore::syncExternal(KSyncManager* manager, QString resource)
{
+ if ( resource == "phone" )
+ return syncPhone();
QString mCurrentSyncDevice = manager->getCurrentSyncDevice();
AddressBook abLocal( resource,"syncContact");
@@ -2868,16 +2854,55 @@ bool KABCore::syncExternal(KSyncManager* manager, QString resource)
return syncOK;
}
-
-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();
}
void KABCore::syncFileRequest()
diff --git a/kaddressbook/kabcore.h b/kaddressbook/kabcore.h
index 43c5f99..04ce33d 100644
--- a/kaddressbook/kabcore.h
+++ b/kaddressbook/kabcore.h
@@ -464,7 +464,8 @@ class KABCore : public QWidget, public KSyncInterface
//this are the overwritten callbackmethods from the syncinterface
virtual bool sync(KSyncManager* manager, QString filename, int mode);
virtual bool syncExternal(KSyncManager* manager, QString resource);
-
+ bool syncPhone();
+ void message( QString m );
// LR *******************************
// sync stuff!
diff --git a/libkcal/phoneformat.cpp b/libkcal/phoneformat.cpp
index c39413e..3555dc6 100644
--- a/libkcal/phoneformat.cpp
+++ b/libkcal/phoneformat.cpp
@@ -291,16 +291,12 @@ 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);
return false;
diff --git a/libkdepim/phoneaccess.cpp b/libkdepim/phoneaccess.cpp
index fe914dd..5fafa1f 100644
--- a/libkdepim/phoneaccess.cpp
+++ b/libkdepim/phoneaccess.cpp
@@ -143,7 +143,29 @@ bool PhoneAccess::writeToPhone( QString fileName)
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("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
@@ -22,6 +22,7 @@
#define PHONEACCESS_H
#include <qstring.h>
+#include <qobject.h>
@@ -34,6 +35,7 @@ class PhoneAccess : public QObject {
static void writeConfig( QString device,QString connection, QString model );
static bool writeToPhone( QString fileName );
+ static bool readFromPhone( QString fileName );
};