summaryrefslogtreecommitdiffabout
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--kaddressbook/kabcore.cpp33
-rw-r--r--libkdepim/ksyncmanager.cpp186
-rw-r--r--libkdepim/ksyncmanager.h14
-rw-r--r--pwmanager/pwmanager/pwm.cpp22
-rw-r--r--pwmanager/pwmanager/pwm.h1
-rw-r--r--pwmanager/pwmanager/pwmdoc.cpp92
-rw-r--r--pwmanager/pwmanager/pwmdoc.h25
7 files changed, 318 insertions, 55 deletions
diff --git a/kaddressbook/kabcore.cpp b/kaddressbook/kabcore.cpp
index f222234..f8359de 100644
--- a/kaddressbook/kabcore.cpp
+++ b/kaddressbook/kabcore.cpp
@@ -1080,5 +1080,6 @@ void KABCore::save()
1080 return; 1080 return;
1081 syncManager->setBlockSave(true);
1082 if ( !mModified ) 1081 if ( !mModified )
1083 return; 1082 return;
1083
1084 syncManager->setBlockSave(true);
1084 QString text = i18n( "There was an error while attempting to save\n the " 1085 QString text = i18n( "There was an error while attempting to save\n the "
@@ -2336,13 +2337,5 @@ bool KABCore::synchronizeAddressbooks( KABC::AddressBook* local, KABC::AddressBo
2336 Addressee inL; 2337 Addressee inL;
2337 QProgressBar bar( er.count(),0 ); 2338
2338 bar.setCaption (i18n("Syncing - close to abort!") ); 2339 syncManager->showProgressBar(0, i18n("Syncing - close to abort!"), er.count());
2339 2340
2340 int w = 300;
2341 if ( QApplication::desktop()->width() < 320 )
2342 w = 220;
2343 int h = bar.sizeHint().height() ;
2344 int dw = QApplication::desktop()->width();
2345 int dh = QApplication::desktop()->height();
2346 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
2347 bar.show();
2348 int modulo = (er.count()/10)+1; 2341 int modulo = (er.count()/10)+1;
@@ -2350,6 +2343,7 @@ bool KABCore::synchronizeAddressbooks( KABC::AddressBook* local, KABC::AddressBo
2350 while ( incCounter < er.count()) { 2343 while ( incCounter < er.count()) {
2351 if ( ! bar.isVisible() ) 2344 if (syncManager->isProgressBarCanceled())
2352 return false; 2345 return false;
2353 if ( incCounter % modulo == 0 ) 2346 if ( incCounter % modulo == 0 )
2354 bar.setProgress( incCounter ); 2347 syncManager->showProgressBar(incCounter);
2348
2355 uid = er[ incCounter ]; 2349 uid = er[ incCounter ];
@@ -2445,5 +2439,4 @@ bool KABCore::synchronizeAddressbooks( KABC::AddressBook* local, KABC::AddressBo
2445 modulo = (el.count()/10)+1; 2439 modulo = (el.count()/10)+1;
2446 bar.setCaption (i18n("Add / remove addressees") ); 2440
2447 bar.setTotalSteps ( el.count() ) ; 2441 syncManager->showProgressBar(0, i18n("Add / remove addressees"), el.count());
2448 bar.show();
2449 incCounter = 0; 2442 incCounter = 0;
@@ -2451,6 +2444,6 @@ bool KABCore::synchronizeAddressbooks( KABC::AddressBook* local, KABC::AddressBo
2451 qApp->processEvents(); 2444 qApp->processEvents();
2452 if ( ! bar.isVisible() ) 2445 if (syncManager->isProgressBarCanceled())
2453 return false; 2446 return false;
2454 if ( incCounter % modulo == 0 ) 2447 if ( incCounter % modulo == 0 )
2455 bar.setProgress( incCounter ); 2448 syncManager->showProgressBar(incCounter);
2456 uid = el[ incCounter ]; 2449 uid = el[ incCounter ];
@@ -2501,3 +2494,3 @@ bool KABCore::synchronizeAddressbooks( KABC::AddressBook* local, KABC::AddressBo
2501 el.clear(); 2494 el.clear();
2502 bar.hide(); 2495 syncManager->hideProgressBar();
2503 mLastAddressbookSync = QDateTime::currentDateTime().addSecs( 1 ); 2496 mLastAddressbookSync = QDateTime::currentDateTime().addSecs( 1 );
diff --git a/libkdepim/ksyncmanager.cpp b/libkdepim/ksyncmanager.cpp
index 87f200a..07e6761 100644
--- a/libkdepim/ksyncmanager.cpp
+++ b/libkdepim/ksyncmanager.cpp
@@ -36,2 +36,3 @@
36#include <qdir.h> 36#include <qdir.h>
37#include <qprogressbar.h>
37#include <qpopupmenu.h> 38#include <qpopupmenu.h>
@@ -55,2 +56,12 @@ KSyncManager::KSyncManager(QWidget* parent, KSyncInterface* implementation, Targ
55{ 56{
57 bar = new QProgressBar ( 1, 0 );
58 bar->setCaption ("");
59
60 int w = 300;
61 if ( QApplication::desktop()->width() < 320 )
62 w = 220;
63 int h = bar->sizeHint().height() ;
64 int dw = QApplication::desktop()->width();
65 int dh = QApplication::desktop()->height();
66 bar->setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
56 67
@@ -60,3 +71,3 @@ KSyncManager::~KSyncManager()
60{ 71{
61 72 delete bar;
62} 73}
@@ -80,4 +91,4 @@ void KSyncManager::fillSyncMenu()
80 prof.clear(); 91 prof.clear();
81 prof << i18n("Sharp_DTM"); 92 prof << i18n("Sharp_DTM");
82 prof << i18n("Local_file"); 93 prof << i18n("Local_file");
83 prof << i18n("Last_file"); 94 prof << i18n("Last_file");
@@ -100,3 +111,2 @@ void KSyncManager::fillSyncMenu()
100 for ( i = 0; i < prof.count(); ++i ) { 111 for ( i = 0; i < prof.count(); ++i ) {
101
102 mSyncMenu->insertItem( prof[i], 1000+i ); 112 mSyncMenu->insertItem( prof[i], 1000+i );
@@ -106,4 +116,8 @@ void KSyncManager::fillSyncMenu()
106 QDir app_dir; 116 QDir app_dir;
107 if ( !app_dir.exists(QDir::homeDirPath()+"/Applications/dtm" ) ) { 117 //US do not display SharpDTM if app is pwmpi, or no sharpfiles available
108 mSyncMenu->setItemEnabled( false , 1000 ); 118 if ( mTargetApp == PWMPI) {
119 mSyncMenu->removeItem( 1000 );
120 }
121 else if (!app_dir.exists(QDir::homeDirPath()+"/Applications/dtm" ) ) {
122 mSyncMenu->setItemEnabled( 1000, false );
109 } 123 }
@@ -163,5 +177,21 @@ void KSyncManager::slotSyncMenu( int action )
163 if ( temp->getIsLocalFileSync() ) { 177 if ( temp->getIsLocalFileSync() ) {
164 if ( syncWithFile( temp->getRemoteFileNameAB( ), false ) ) 178 switch(mTargetApp)
179 {
180 case (KAPI):
181 if ( syncWithFile( temp->getRemoteFileNameAB( ), false ) )
165 mPrefs->mLastSyncedLocalFile = temp->getRemoteFileNameAB(); 182 mPrefs->mLastSyncedLocalFile = temp->getRemoteFileNameAB();
166 183 break;
184 case (KOPI):
185 if ( syncWithFile( temp->getRemoteFileName( ), false ) )
186 mPrefs->mLastSyncedLocalFile = temp->getRemoteFileName();
187 break;
188 case (PWMPI):
189 if ( syncWithFile( temp->getRemoteFileNamePWM( ), false ) )
190 mPrefs->mLastSyncedLocalFile = temp->getRemoteFileNamePWM();
191 break;
192 default:
193 qDebug("KSyncManager::slotSyncMenu: invalid apptype selected");
194 break;
195
196 }
167 } else { 197 } else {
@@ -185,4 +215,22 @@ void KSyncManager::syncLocalFile()
185 QString fn =mPrefs->mLastSyncedLocalFile; 215 QString fn =mPrefs->mLastSyncedLocalFile;
186 216 QString ext;
187 fn =KFileDialog:: getOpenFileName( fn, i18n("Sync filename(*.ics/*.vcs)"), mParent ); 217
218 switch(mTargetApp)
219 {
220 case (KAPI):
221 ext = "(*.vcf)";
222 break;
223 case (KOPI):
224 ext = "(*.ics/*.vcs)";
225 break;
226 case (PWMPI):
227 ext = "(*.pwm)";
228 break;
229 default:
230 qDebug("KSyncManager::syncLocalFile: invalid apptype selected");
231 break;
232
233 }
234
235 fn =KFileDialog:: getOpenFileName( fn, i18n("Sync filename"+ext), mParent );
188 if ( fn == "" ) 236 if ( fn == "" )
@@ -286,3 +334,23 @@ int KSyncManager::ringSync()
286 temp->readConfig(&config); 334 temp->readConfig(&config);
287 if ( temp->getIncludeInRingSyncAB() && ( i < 1 || i > 2 )) { 335
336 QString includeInRingSync;
337 switch(mTargetApp)
338 {
339 case (KAPI):
340 includeInRingSync = temp->getIncludeInRingSyncAB();
341 break;
342 case (KOPI):
343 includeInRingSync = temp->getIncludeInRingSync();
344 break;
345 case (PWMPI):
346 includeInRingSync = temp->getIncludeInRingSyncPWM();
347 break;
348 default:
349 qDebug("KSyncManager::ringSync: invalid apptype selected");
350 break;
351
352 }
353
354
355 if ( includeInRingSync && ( i < 1 || i > 2 )) {
288 mParent->setCaption(i18n("Profile ")+syncProfileNames[mCurrentSyncProfile]+ i18n(" is synced ... ")); 356 mParent->setCaption(i18n("Profile ")+syncProfileNames[mCurrentSyncProfile]+ i18n(" is synced ... "));
@@ -302,4 +370,20 @@ int KSyncManager::ringSync()
302 if ( temp->getIsLocalFileSync() ) { 370 if ( temp->getIsLocalFileSync() ) {
303 if ( syncWithFile( temp->getRemoteFileNameAB( ), true ) ) 371 switch(mTargetApp)
304 mPrefs->mLastSyncedLocalFile = temp->getRemoteFileNameAB(); 372 {
373 case (KAPI):
374 if ( syncWithFile( temp->getRemoteFileNameAB( ), false ) )
375 mPrefs->mLastSyncedLocalFile = temp->getRemoteFileNameAB();
376 break;
377 case (KOPI):
378 if ( syncWithFile( temp->getRemoteFileName( ), false ) )
379 mPrefs->mLastSyncedLocalFile = temp->getRemoteFileName();
380 break;
381 case (PWMPI):
382 if ( syncWithFile( temp->getRemoteFileNamePWM( ), false ) )
383 mPrefs->mLastSyncedLocalFile = temp->getRemoteFileNamePWM();
384 break;
385 default:
386 qDebug("KSyncManager::slotSyncMenu: invalid apptype selected");
387 break;
388 }
305 } else { 389 } else {
@@ -342,7 +426,34 @@ void KSyncManager::syncRemote( KSyncProfile* prof, bool ask)
342 } 426 }
343 QString command = prof->getPreSyncCommandAB(); 427
428 QString preCommand;
429 QString localTempFile;
430 QString postCommand;
431
432 switch(mTargetApp)
433 {
434 case (KAPI):
435 preCommand = prof->getPreSyncCommandAB();
436 postCommand = prof->getPostSyncCommandAB();
437 localTempFile = prof->getLocalTempFileAB();
438 break;
439 case (KOPI):
440 preCommand = prof->getPreSyncCommand();
441 postCommand = prof->getPostSyncCommand();
442 localTempFile = prof->getLocalTempFile();
443 break;
444 case (PWMPI):
445 preCommand = prof->getPreSyncCommandPWM();
446 postCommand = prof->getPostSyncCommandPWM();
447 localTempFile = prof->getLocalTempFilePWM();
448 break;
449 default:
450 qDebug("KSyncManager::syncRemote: invalid apptype selected");
451 break;
452 }
453
454
344 int fi; 455 int fi;
345 if ( (fi = command.find("$PWD$")) > 0 ) { 456 if ( (fi = preCommand.find("$PWD$")) > 0 ) {
346 QString pwd = getPassword(); 457 QString pwd = getPassword();
347 command = command.left( fi )+ pwd + command.mid( fi+5 ); 458 preCommand = preCommand.left( fi )+ pwd + preCommand.mid( fi+5 );
348 459
@@ -354,3 +465,3 @@ void KSyncManager::syncRemote( KSyncProfile* prof, bool ask)
354 int fileSize = 0; 465 int fileSize = 0;
355 int result = system ( command ); 466 int result = system ( preCommand );
356 // 0 : okay 467 // 0 : okay
@@ -361,7 +472,7 @@ void KSyncManager::syncRemote( KSyncProfile* prof, bool ask)
361 unsigned int len = maxlen; 472 unsigned int len = maxlen;
362 while ( len < command.length() ) { 473 while ( len < preCommand.length() ) {
363 command.insert( len , "\n" ); 474 preCommand.insert( len , "\n" );
364 len += maxlen +2; 475 len += maxlen +2;
365 } 476 }
366 question = i18n("Sorry, the copy command failed!\nCommand was:\n%1\n \nTry command on console to get more\ndetailed info about the reason.\n").arg (command) ; 477 question = i18n("Sorry, the copy command failed!\nCommand was:\n%1\n \nTry command on console to get more\ndetailed info about the reason.\n").arg (preCommand) ;
367 QMessageBox::information( mParent, i18n("Sync - ERROR"), 478 QMessageBox::information( mParent, i18n("Sync - ERROR"),
@@ -374,3 +485,6 @@ void KSyncManager::syncRemote( KSyncProfile* prof, bool ask)
374 //qDebug(" file **%s** ",prof->getLocalTempFile().latin1() ); 485 //qDebug(" file **%s** ",prof->getLocalTempFile().latin1() );
375 if ( syncWithFile( prof->getLocalTempFileAB(), true ) ) { 486
487
488
489 if ( syncWithFile( localTempFile, true ) ) {
376// Event* e = mView->getLastSyncEvent(); 490// Event* e = mView->getLastSyncEvent();
@@ -380,7 +494,6 @@ void KSyncManager::syncRemote( KSyncProfile* prof, bool ask)
380 if ( mPrefs->mWriteBackFile ) { 494 if ( mPrefs->mWriteBackFile ) {
381 command = prof->getPostSyncCommandAB();
382 int fi; 495 int fi;
383 if ( (fi = command.find("$PWD$")) > 0 ) { 496 if ( (fi = postCommand.find("$PWD$")) > 0 ) {
384 QString pwd = getPassword(); 497 QString pwd = getPassword();
385 command = command.left( fi )+ pwd + command.mid( fi+5 ); 498 postCommand = postCommand.left( fi )+ pwd + postCommand.mid( fi+5 );
386 499
@@ -388,3 +501,3 @@ void KSyncManager::syncRemote( KSyncProfile* prof, bool ask)
388 mParent->setCaption ( i18n( "Writing back file ..." ) ); 501 mParent->setCaption ( i18n( "Writing back file ..." ) );
389 result = system ( command ); 502 result = system ( postCommand );
390 qDebug("Writing back file result: %d ", result); 503 qDebug("Writing back file result: %d ", result);
@@ -529 +642,24 @@ void KSyncManager::syncPhone()
529} 642}
643
644void KSyncManager::showProgressBar(int percentage, QString caption, int total)
645{
646 if (!bar->isVisible())
647 {
648 bar->setCaption (caption);
649 bar->setTotalSteps ( total ) ;
650
651 bar->show();
652 }
653
654 bar->setProgress( percentage );
655}
656
657void KSyncManager::hideProgressBar()
658{
659 bar->hide();
660}
661
662bool KSyncManager::isProgressBarCanceled()
663{
664 return !bar->isVisible();
665}
diff --git a/libkdepim/ksyncmanager.h b/libkdepim/ksyncmanager.h
index 389a005..9761107 100644
--- a/libkdepim/ksyncmanager.h
+++ b/libkdepim/ksyncmanager.h
@@ -33,2 +33,3 @@ class KSyncManager;
33class KSyncInterface; 33class KSyncInterface;
34class QProgressBar;
34 35
@@ -56,2 +57,7 @@ class KSyncManager : public QObject
56 57
58 void showProgressBar(int percentage, QString caption = QString::null, int total=100);
59 void hideProgressBar();
60 bool isProgressBarCanceled();
61
62
57 public slots: 63 public slots:
@@ -91,3 +97,3 @@ class KSyncManager : public QObject
91 97
92 98 QProgressBar* bar;
93 99
@@ -104,4 +110,8 @@ class KSyncInterface
104 virtual bool sync(KSyncManager* manager, QString filename, int mode) = 0; 110 virtual bool sync(KSyncManager* manager, QString filename, int mode) = 0;
105 virtual bool syncExternal(KSyncManager* manager, QString resource) = 0;
106 111
112 virtual bool syncExternal(KSyncManager* manager, QString resource)
113 {
114 // empty implementation, because some syncable applications do not have an external(sharpdtm) syncmode, like pwmanager.
115 return false;
116 }
107 117
diff --git a/pwmanager/pwmanager/pwm.cpp b/pwmanager/pwmanager/pwm.cpp
index ac2e66e..014e809 100644
--- a/pwmanager/pwmanager/pwm.cpp
+++ b/pwmanager/pwmanager/pwm.cpp
@@ -1324,13 +1324,19 @@ bool PwM::sync(KSyncManager* manager, QString filename, int mode)
1324{ 1324{
1325 return true; 1325 PWM_ASSERT(curDoc());
1326}
1327 1326
1328bool PwM::syncExternal(KSyncManager* manager, QString resource) 1327 bool ret = curDoc()->sync(manager, filename, mode);
1329{ 1328
1330 return true; 1329 if (ret == true) {
1330 //US BUG: what can we call here to update the view of the current doc?
1331 //mViewManager->refreshView();
1332 }
1333
1334 return ret;
1331} 1335}
1332 1336
1333//called by the syncmanager to indicate that the work has to marked as dirty. 1337//called by the syncmanager to indicate that the work has to be marked as dirty.
1334void PwM::sync_setModified() 1338void PwM::sync_setModified()
1335{ 1339{
1340 PWM_ASSERT(curDoc());
1341 curDoc()->sync_setModified();
1336} 1342}
@@ -1340,2 +1346,4 @@ bool PwM::sync_isModified()
1340{ 1346{
1347 PWM_ASSERT(curDoc());
1348 return curDoc()->sync_isModified();
1341} 1349}
@@ -1345,2 +1353,4 @@ void PwM::sync_save()
1345{ 1353{
1354 PWM_ASSERT(curDoc());
1355 return curDoc()->sync_save();
1346} 1356}
diff --git a/pwmanager/pwmanager/pwm.h b/pwmanager/pwmanager/pwm.h
index 2fe7352..7c6bf0d 100644
--- a/pwmanager/pwmanager/pwm.h
+++ b/pwmanager/pwmanager/pwm.h
@@ -273,3 +273,2 @@ protected:
273 virtual bool sync(KSyncManager* manager, QString filename, int mode); 273 virtual bool sync(KSyncManager* manager, QString filename, int mode);
274 virtual bool syncExternal(KSyncManager* manager, QString resource);
275 274
diff --git a/pwmanager/pwmanager/pwmdoc.cpp b/pwmanager/pwmanager/pwmdoc.cpp
index 1b6d36f..82fc746 100644
--- a/pwmanager/pwmanager/pwmdoc.cpp
+++ b/pwmanager/pwmanager/pwmdoc.cpp
@@ -2783,2 +2783,94 @@ out_ignore:
2783 2783
2784
2785
2786#ifdef PWM_EMBEDDED
2787//US ENH: this is the magic function that syncronizes the this doc with the remote doc
2788PwMerror PwMDoc::syncronize(KSyncManager* manager, PwMDoc* syncLocal , PwMDoc* syncRemote, int mode )
2789{
2790 bool syncOK = true;
2791 int addedPasswordsLocal = 0;
2792 int addedPasswordsRemote = 0;
2793 int deletedPasswordsRemote = 0;
2794 int deletedPasswordsLocal = 0;
2795 int changedLocal = 0;
2796 int changedRemote = 0;
2797
2798 QString mCurrentSyncName = manager->getCurrentSyncName();
2799 QString mCurrentSyncDevice = manager->getCurrentSyncDevice();
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809 return e_success;
2810}
2811
2812
2813
2814//this are the overwritten callbackmethods from the syncinterface
2815bool PwMDoc::sync(KSyncManager* manager, QString filename, int mode)
2816{
2817 QString mCurrentSyncDevice = manager->getCurrentSyncDevice();
2818
2819 // construct on the stack = automatic cleanup.
2820 PwMDoc syncTarget(this, "synctarget");
2821
2822 PwMerror err = syncTarget.openDoc(&filename, 2 /*== deeplocked*/);
2823
2824 if (err != e_success)
2825 return false;
2826
2827 qDebug("PWM file loaded %s,sync mode %d",filename.latin1(), mode );
2828
2829
2830 err = syncronize(manager, this, &syncTarget, mode );
2831
2832 if (err == e_success) {
2833 if ( PWMPrefs::instance()->mWriteBackFile ){
2834 qDebug("Saving remote PWManager file");
2835 err = syncTarget.saveDoc(conf()->confGlobCompression());
2836 if (err != e_success)
2837 return false;
2838
2839 }
2840
2841 flagDirty();
2842 return true;
2843 }
2844 else {
2845 return false;
2846 }
2847}
2848
2849//called by the syncmanager to indicate that the work has to marked as dirty.
2850void PwMDoc::sync_setModified()
2851{
2852 flagDirty();
2853}
2854
2855//called by the syncmanager to ask if the dirty flag is set.
2856bool PwMDoc::sync_isModified()
2857{
2858 return isDirty();
2859}
2860
2861//called by the syncmanager to indicate that the work has to be saved.
2862void PwMDoc::sync_save()
2863{
2864 PwMerror ret = saveDoc(conf()->confGlobCompression());
2865}
2866
2867#endif
2868
2869
2870
2871
2872
2873
2874
2875
2784#ifndef PWM_EMBEDDED 2876#ifndef PWM_EMBEDDED
diff --git a/pwmanager/pwmanager/pwmdoc.h b/pwmanager/pwmanager/pwmdoc.h
index 193247e..ea4d687 100644
--- a/pwmanager/pwmanager/pwmdoc.h
+++ b/pwmanager/pwmanager/pwmdoc.h
@@ -61,2 +61,3 @@
61#include <kapplication.h> 61#include <kapplication.h>
62#include <ksyncmanager.h>
62#endif 63#endif
@@ -337,3 +338,6 @@ protected:
337/** Document class for PwM */ 338/** Document class for PwM */
338class PwMDoc : public PwMDocUi 339//US ENH: derived from KSyncInterfaces, to get called by PwM when a sync is required.
340// But PwMDoc is handling the sync by itself.
341class PwMDoc : public PwMDocUi, public KSyncInterface
342
339{ 343{
@@ -698,2 +702,21 @@ protected:
698 bool copyFile(const QString &src, const QString &dst); 702 bool copyFile(const QString &src, const QString &dst);
703
704
705 public:
706#ifdef PWM_EMBEDDED
707 //US ENH: this is the magic function that syncronizes the local doc with the remote doc.
708 PwMerror syncronize(KSyncManager* manager, PwMDoc* syncLocal, PwMDoc* syncRemote, int mode );
709
710
711 //the following methods are the overwritten callbackmethods from the syncinterface
712 virtual bool sync(KSyncManager* manager, QString filename, int mode);
713
714 //called by the syncmanager to indicate that the work has to be marked as dirty.
715 virtual void sync_setModified();
716 //called by the syncmanager to ask if the dirty flag is set.
717 virtual bool sync_isModified();
718 //called by the syncmanager to indicate that the work has to be saved.
719 virtual void sync_save();
720#endif
721
699}; 722};