summaryrefslogtreecommitdiffabout
authorulf69 <ulf69>2004-10-03 23:29:56 (UTC)
committer ulf69 <ulf69>2004-10-03 23:29:56 (UTC)
commitaaea91151fe9a747e9eddfb8ba7d5896744faf30 (patch) (unidiff)
treeb2b064757d65bc83427e7a86692601364051b631
parenta5c204da5a2dba950fc5ad2c45861dbe56849c09 (diff)
downloadkdepimpi-aaea91151fe9a747e9eddfb8ba7d5896744faf30.zip
kdepimpi-aaea91151fe9a747e9eddfb8ba7d5896744faf30.tar.gz
kdepimpi-aaea91151fe9a747e9eddfb8ba7d5896744faf30.tar.bz2
moved sync related progressbar management to ksyncmanager, and proceeded with
the sync implementation of pwmanager
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
@@ -1057,51 +1057,52 @@ void KABCore::editContact( const QString &uid )
1057} 1057}
1058 1058
1059/** 1059/**
1060 Shows or edits the detail view for the given uid. If the uid is QString::null, 1060 Shows or edits the detail view for the given uid. If the uid is QString::null,
1061 the method will try to find a selected addressee in the view. 1061 the method will try to find a selected addressee in the view.
1062 */ 1062 */
1063void KABCore::executeContact( const QString &uid /*US = QString::null*/ ) 1063void KABCore::executeContact( const QString &uid /*US = QString::null*/ )
1064{ 1064{
1065 if ( mMultipleViewsAtOnce ) 1065 if ( mMultipleViewsAtOnce )
1066 { 1066 {
1067 editContact( uid ); 1067 editContact( uid );
1068 } 1068 }
1069 else 1069 else
1070 { 1070 {
1071 setDetailsVisible( true ); 1071 setDetailsVisible( true );
1072 mActionDetails->setChecked(true); 1072 mActionDetails->setChecked(true);
1073 } 1073 }
1074 1074
1075} 1075}
1076 1076
1077void KABCore::save() 1077void KABCore::save()
1078{ 1078{
1079 if (syncManager->blockSave()) 1079 if (syncManager->blockSave())
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 "
1085 "address book. Please check that some \nother application is " 1086 "address book. Please check that some \nother application is "
1086 "not using it. " ); 1087 "not using it. " );
1087 statusMessage(i18n("Saving addressbook ... ")); 1088 statusMessage(i18n("Saving addressbook ... "));
1088#ifndef KAB_EMBEDDED 1089#ifndef KAB_EMBEDDED
1089 KABC::StdAddressBook *b = dynamic_cast<KABC::StdAddressBook*>( mAddressBook ); 1090 KABC::StdAddressBook *b = dynamic_cast<KABC::StdAddressBook*>( mAddressBook );
1090 if ( !b || !b->save() ) { 1091 if ( !b || !b->save() ) {
1091 KMessageBox::error( this, text, i18n( "Unable to Save" ) ); 1092 KMessageBox::error( this, text, i18n( "Unable to Save" ) );
1092 } 1093 }
1093#else //KAB_EMBEDDED 1094#else //KAB_EMBEDDED
1094 KABC::StdAddressBook *b = (KABC::StdAddressBook*)( mAddressBook ); 1095 KABC::StdAddressBook *b = (KABC::StdAddressBook*)( mAddressBook );
1095 if ( !b || !b->save() ) { 1096 if ( !b || !b->save() ) {
1096 QMessageBox::critical( this, i18n( "Unable to Save" ), text, i18n("Ok")); 1097 QMessageBox::critical( this, i18n( "Unable to Save" ), text, i18n("Ok"));
1097 } 1098 }
1098#endif //KAB_EMBEDDED 1099#endif //KAB_EMBEDDED
1099 1100
1100 statusMessage(i18n("Addressbook saved!")); 1101 statusMessage(i18n("Addressbook saved!"));
1101 setModified( false ); 1102 setModified( false );
1102 syncManager->setBlockSave(false); 1103 syncManager->setBlockSave(false);
1103} 1104}
1104 1105
1105void KABCore::statusMessage(QString mess , int time ) 1106void KABCore::statusMessage(QString mess , int time )
1106{ 1107{
1107 //topLevelWidget()->setCaption( mess ); 1108 //topLevelWidget()->setCaption( mess );
@@ -2313,66 +2314,59 @@ bool KABCore::synchronizeAddressbooks( KABC::AddressBook* local, KABC::AddressBo
2313 //qDebug("%d %d %d %d ", addresseeLSync->dtStart().time().second(), addresseeLSync->dtStart().time().msec() , addresseeRSync->dtStart().time().second(), addresseeRSync->dtStart().time().msec()); 2314 //qDebug("%d %d %d %d ", addresseeLSync->dtStart().time().second(), addresseeLSync->dtStart().time().msec() , addresseeRSync->dtStart().time().second(), addresseeRSync->dtStart().time().msec());
2314 fullDateRange = true; 2315 fullDateRange = true;
2315 qDebug("FULLDATE 3 %s %s", addresseeLSync.revision().toString().latin1() , addresseeRSync.revision().toString().latin1() ); 2316 qDebug("FULLDATE 3 %s %s", addresseeLSync.revision().toString().latin1() , addresseeRSync.revision().toString().latin1() );
2316 } 2317 }
2317 } 2318 }
2318 // fullDateRange = true; // debug only! 2319 // fullDateRange = true; // debug only!
2319 if ( fullDateRange ) 2320 if ( fullDateRange )
2320 mLastAddressbookSync = QDateTime::currentDateTime().addDays( -100*365); 2321 mLastAddressbookSync = QDateTime::currentDateTime().addDays( -100*365);
2321 else 2322 else
2322 mLastAddressbookSync = addresseeLSync.revision(); 2323 mLastAddressbookSync = addresseeLSync.revision();
2323 // for resyncing if own file has changed 2324 // for resyncing if own file has changed
2324 // PENDING fixme later when implemented 2325 // PENDING fixme later when implemented
2325#if 0 2326#if 0
2326 if ( mCurrentSyncDevice == "deleteaftersync" ) { 2327 if ( mCurrentSyncDevice == "deleteaftersync" ) {
2327 mLastAddressbookSync = loadedFileVersion; 2328 mLastAddressbookSync = loadedFileVersion;
2328 qDebug("setting mLastAddressbookSync "); 2329 qDebug("setting mLastAddressbookSync ");
2329 } 2330 }
2330#endif 2331#endif
2331 2332
2332 //qDebug("*************************** "); 2333 //qDebug("*************************** ");
2333 // qDebug("mLastAddressbookSync %s ",mLastAddressbookSync.toString().latin1() ); 2334 // qDebug("mLastAddressbookSync %s ",mLastAddressbookSync.toString().latin1() );
2334 QStringList er = remote->uidList(); 2335 QStringList er = remote->uidList();
2335 Addressee inR ;//= er.first(); 2336 Addressee inR ;//= er.first();
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;
2349 int incCounter = 0; 2342 int incCounter = 0;
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 ];
2356 bool skipIncidence = false; 2350 bool skipIncidence = false;
2357 if ( uid.left(19) == QString("last-syncAddressee-") ) 2351 if ( uid.left(19) == QString("last-syncAddressee-") )
2358 skipIncidence = true; 2352 skipIncidence = true;
2359 QString idS,OidS; 2353 QString idS,OidS;
2360 qApp->processEvents(); 2354 qApp->processEvents();
2361 if ( !skipIncidence ) { 2355 if ( !skipIncidence ) {
2362 inL = local->findByUid( uid ); 2356 inL = local->findByUid( uid );
2363 inR = remote->findByUid( uid ); 2357 inR = remote->findByUid( uid );
2364 //inL.setResource( 0 ); 2358 //inL.setResource( 0 );
2365 //inR.setResource( 0 ); 2359 //inR.setResource( 0 );
2366 if ( !inL.isEmpty() ) { // maybe conflict - same uid in both calendars 2360 if ( !inL.isEmpty() ) { // maybe conflict - same uid in both calendars
2367 if ( take = takeAddressee( &inL, &inR, mode, fullDateRange ) ) { 2361 if ( take = takeAddressee( &inL, &inR, mode, fullDateRange ) ) {
2368 //qDebug("take %d %s ", take, inL.summary().latin1()); 2362 //qDebug("take %d %s ", take, inL.summary().latin1());
2369 if ( take == 3 ) 2363 if ( take == 3 )
2370 return false; 2364 return false;
2371 if ( take == 1 ) {// take local 2365 if ( take == 1 ) {// take local
2372 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 2366 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
2373 inL.setCsum( mCurrentSyncDevice, inR.getCsum(mCurrentSyncDevice) ); 2367 inL.setCsum( mCurrentSyncDevice, inR.getCsum(mCurrentSyncDevice) );
2374 inL.setID( mCurrentSyncDevice, inR.getID(mCurrentSyncDevice) ); 2368 inL.setID( mCurrentSyncDevice, inR.getID(mCurrentSyncDevice) );
2375 local->insertAddressee( inL, false ); 2369 local->insertAddressee( inL, false );
2376 idS = inR.externalUID(); 2370 idS = inR.externalUID();
2377 OidS = inR.originalExternalUID(); 2371 OidS = inR.originalExternalUID();
2378 } 2372 }
@@ -2422,105 +2416,104 @@ bool KABCore::synchronizeAddressbooks( KABC::AddressBook* local, KABC::AddressBo
2422 inL.setResource( 0 ); 2416 inL.setResource( 0 );
2423 local->insertAddressee( inL , false); 2417 local->insertAddressee( inL , false);
2424 ++addedAddressee; 2418 ++addedAddressee;
2425 } 2419 }
2426 } else { 2420 } else {
2427 if ( inR.revision() > mLastAddressbookSync || mode == 5 ) { 2421 if ( inR.revision() > mLastAddressbookSync || mode == 5 ) {
2428 inR.setRevision( modifiedCalendar ); 2422 inR.setRevision( modifiedCalendar );
2429 remote->insertAddressee( inR, false ); 2423 remote->insertAddressee( inR, false );
2430 inR.setResource( 0 ); 2424 inR.setResource( 0 );
2431 local->insertAddressee( inR, false ); 2425 local->insertAddressee( inR, false );
2432 ++addedAddressee; 2426 ++addedAddressee;
2433 } else { 2427 } else {
2434 // pending checkExternSyncAddressee(addresseeRSyncSharp, inR); 2428 // pending checkExternSyncAddressee(addresseeRSyncSharp, inR);
2435 remote->removeAddressee( inR ); 2429 remote->removeAddressee( inR );
2436 ++deletedAddresseeR; 2430 ++deletedAddresseeR;
2437 } 2431 }
2438 } 2432 }
2439 } 2433 }
2440 } 2434 }
2441 ++incCounter; 2435 ++incCounter;
2442 } 2436 }
2443 er.clear(); 2437 er.clear();
2444 QStringList el = local->uidList(); 2438 QStringList el = local->uidList();
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;
2450 while ( incCounter < el.count()) { 2443 while ( incCounter < el.count()) {
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 ];
2457 bool skipIncidence = false; 2450 bool skipIncidence = false;
2458 if ( uid.left(19) == QString("last-syncAddressee-") ) 2451 if ( uid.left(19) == QString("last-syncAddressee-") )
2459 skipIncidence = true; 2452 skipIncidence = true;
2460 if ( !skipIncidence ) { 2453 if ( !skipIncidence ) {
2461 inL = local->findByUid( uid ); 2454 inL = local->findByUid( uid );
2462 inR = remote->findByUid( uid ); 2455 inR = remote->findByUid( uid );
2463 if ( inR.isEmpty() ) { 2456 if ( inR.isEmpty() ) {
2464 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 2457 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
2465 if ( !inL.getID(mCurrentSyncDevice).isEmpty() && mode != 4 ) { 2458 if ( !inL.getID(mCurrentSyncDevice).isEmpty() && mode != 4 ) {
2466 // pending checkExternSyncAddressee(addresseeLSyncSharp, inL); 2459 // pending checkExternSyncAddressee(addresseeLSyncSharp, inL);
2467 local->removeAddressee( inL ); 2460 local->removeAddressee( inL );
2468 ++deletedAddresseeL; 2461 ++deletedAddresseeL;
2469 } else { 2462 } else {
2470 if ( ! KABPrefs::instance()->mWriteBackExistingOnly ) { 2463 if ( ! KABPrefs::instance()->mWriteBackExistingOnly ) {
2471 inL.removeID(mCurrentSyncDevice ); 2464 inL.removeID(mCurrentSyncDevice );
2472 ++addedAddresseeR; 2465 ++addedAddresseeR;
2473 inL.setRevision( modifiedCalendar ); 2466 inL.setRevision( modifiedCalendar );
2474 local->insertAddressee( inL, false ); 2467 local->insertAddressee( inL, false );
2475 inR = inL; 2468 inR = inL;
2476 inR.setTempSyncStat( SYNC_TEMPSTATE_ADDED_EXTERNAL ); 2469 inR.setTempSyncStat( SYNC_TEMPSTATE_ADDED_EXTERNAL );
2477 inR.setResource( 0 ); 2470 inR.setResource( 0 );
2478 remote->insertAddressee( inR, false ); 2471 remote->insertAddressee( inR, false );
2479 } 2472 }
2480 } 2473 }
2481 } else { 2474 } else {
2482 if ( inL.revision() < mLastAddressbookSync && mode != 4 ) { 2475 if ( inL.revision() < mLastAddressbookSync && mode != 4 ) {
2483 // pending checkExternSyncAddressee(addresseeLSyncSharp, inL); 2476 // pending checkExternSyncAddressee(addresseeLSyncSharp, inL);
2484 local->removeAddressee( inL ); 2477 local->removeAddressee( inL );
2485 ++deletedAddresseeL; 2478 ++deletedAddresseeL;
2486 } else { 2479 } else {
2487 if ( ! KABPrefs::instance()->mWriteBackExistingOnly ) { 2480 if ( ! KABPrefs::instance()->mWriteBackExistingOnly ) {
2488 ++addedAddresseeR; 2481 ++addedAddresseeR;
2489 inL.setRevision( modifiedCalendar ); 2482 inL.setRevision( modifiedCalendar );
2490 local->insertAddressee( inL, false ); 2483 local->insertAddressee( inL, false );
2491 inR = inL; 2484 inR = inL;
2492 inR.setResource( 0 ); 2485 inR.setResource( 0 );
2493 remote->insertAddressee( inR, false ); 2486 remote->insertAddressee( inR, false );
2494 } 2487 }
2495 } 2488 }
2496 } 2489 }
2497 } 2490 }
2498 } 2491 }
2499 ++incCounter; 2492 ++incCounter;
2500 } 2493 }
2501 el.clear(); 2494 el.clear();
2502 bar.hide(); 2495 syncManager->hideProgressBar();
2503 mLastAddressbookSync = QDateTime::currentDateTime().addSecs( 1 ); 2496 mLastAddressbookSync = QDateTime::currentDateTime().addSecs( 1 );
2504 // get rid of micro seconds 2497 // get rid of micro seconds
2505 QTime t = mLastAddressbookSync.time(); 2498 QTime t = mLastAddressbookSync.time();
2506 mLastAddressbookSync.setTime( QTime (t.hour (), t.minute (), t.second () ) ); 2499 mLastAddressbookSync.setTime( QTime (t.hour (), t.minute (), t.second () ) );
2507 addresseeLSync.setRevision( mLastAddressbookSync ); 2500 addresseeLSync.setRevision( mLastAddressbookSync );
2508 addresseeRSync.setRevision( mLastAddressbookSync ); 2501 addresseeRSync.setRevision( mLastAddressbookSync );
2509 addresseeRSync.setRole( i18n("!Remote from: ")+mCurrentSyncName ) ; 2502 addresseeRSync.setRole( i18n("!Remote from: ")+mCurrentSyncName ) ;
2510 addresseeLSync.setRole(i18n("!Local from: ") + mCurrentSyncName ); 2503 addresseeLSync.setRole(i18n("!Local from: ") + mCurrentSyncName );
2511 addresseeRSync.setGivenName( i18n("!DO NOT EDIT!") ) ; 2504 addresseeRSync.setGivenName( i18n("!DO NOT EDIT!") ) ;
2512 addresseeLSync.setGivenName(i18n("!DO NOT EDIT!") ); 2505 addresseeLSync.setGivenName(i18n("!DO NOT EDIT!") );
2513 addresseeRSync.setOrganization( "!"+mLastAddressbookSync.toString() ) ; 2506 addresseeRSync.setOrganization( "!"+mLastAddressbookSync.toString() ) ;
2514 addresseeLSync.setOrganization("!"+ mLastAddressbookSync.toString() ); 2507 addresseeLSync.setOrganization("!"+ mLastAddressbookSync.toString() );
2515 addresseeRSync.setNote( "" ) ; 2508 addresseeRSync.setNote( "" ) ;
2516 addresseeLSync.setNote( "" ); 2509 addresseeLSync.setNote( "" );
2517 2510
2518 if ( mGlobalSyncMode == SYNC_MODE_NORMAL) 2511 if ( mGlobalSyncMode == SYNC_MODE_NORMAL)
2519 remote->insertAddressee( addresseeRSync, false ); 2512 remote->insertAddressee( addresseeRSync, false );
2520 local->insertAddressee( addresseeLSync, false ); 2513 local->insertAddressee( addresseeLSync, false );
2521 QString mes; 2514 QString mes;
2522 mes .sprintf( i18n("Synchronization summary:\n\n %d items added to local\n %d items added to remote\n %d items updated on local\n %d items updated on remote\n %d items deleted on local\n %d items deleted on remote\n"),addedAddressee, addedAddresseeR, changedLocal, changedRemote, deletedAddresseeL, deletedAddresseeR ); 2515 mes .sprintf( i18n("Synchronization summary:\n\n %d items added to local\n %d items added to remote\n %d items updated on local\n %d items updated on remote\n %d items deleted on local\n %d items deleted on remote\n"),addedAddressee, addedAddresseeR, changedLocal, changedRemote, deletedAddresseeL, deletedAddresseeR );
2523 if ( KABPrefs::instance()->mShowSyncSummary ) { 2516 if ( KABPrefs::instance()->mShowSyncSummary ) {
2524 KMessageBox::information(this, mes, i18n("KA/Pi Synchronization") ); 2517 KMessageBox::information(this, mes, i18n("KA/Pi Synchronization") );
2525 } 2518 }
2526 qDebug( mes ); 2519 qDebug( mes );
diff --git a/libkdepim/ksyncmanager.cpp b/libkdepim/ksyncmanager.cpp
index 87f200a..07e6761 100644
--- a/libkdepim/ksyncmanager.cpp
+++ b/libkdepim/ksyncmanager.cpp
@@ -13,120 +13,134 @@
13 Library General Public License for more details. 13 Library General Public License for more details.
14 14
15 You should have received a copy of the GNU Library General Public License 15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to 16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. 18 Boston, MA 02111-1307, USA.
19*/ 19*/
20 20
21// $Id$ 21// $Id$
22 22
23#include "ksyncmanager.h" 23#include "ksyncmanager.h"
24 24
25#include <stdlib.h> 25#include <stdlib.h>
26 26
27#ifndef _WIN32_ 27#ifndef _WIN32_
28#include <unistd.h> 28#include <unistd.h>
29#endif 29#endif
30 30
31 31
32#include "ksyncprofile.h" 32#include "ksyncprofile.h"
33#include "ksyncprefsdialog.h" 33#include "ksyncprefsdialog.h"
34#include "kpimprefs.h" 34#include "kpimprefs.h"
35 35
36#include <qdir.h> 36#include <qdir.h>
37#include <qprogressbar.h>
37#include <qpopupmenu.h> 38#include <qpopupmenu.h>
38#include <qpushbutton.h> 39#include <qpushbutton.h>
39#include <qradiobutton.h> 40#include <qradiobutton.h>
40#include <qbuttongroup.h> 41#include <qbuttongroup.h>
41#include <qtimer.h> 42#include <qtimer.h>
42#include <qmessagebox.h> 43#include <qmessagebox.h>
43#include <qapplication.h> 44#include <qapplication.h>
44#include <qlineedit.h> 45#include <qlineedit.h>
45#include <qdialog.h> 46#include <qdialog.h>
46#include <qlayout.h> 47#include <qlayout.h>
47 48
48#include <klocale.h> 49#include <klocale.h>
49#include <kglobal.h> 50#include <kglobal.h>
50#include <kconfig.h> 51#include <kconfig.h>
51#include <kfiledialog.h> 52#include <kfiledialog.h>
52 53
53KSyncManager::KSyncManager(QWidget* parent, KSyncInterface* implementation, TargetApp ta, KPimPrefs* prefs, QPopupMenu* syncmenu) 54KSyncManager::KSyncManager(QWidget* parent, KSyncInterface* implementation, TargetApp ta, KPimPrefs* prefs, QPopupMenu* syncmenu)
54 : QObject(), mParent(parent), mImplementation(implementation), mTargetApp(ta), mPrefs(prefs), mSyncMenu(syncmenu) 55 : QObject(), mParent(parent), mImplementation(implementation), mTargetApp(ta), mPrefs(prefs), mSyncMenu(syncmenu)
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
57} 68}
58 69
59KSyncManager::~KSyncManager() 70KSyncManager::~KSyncManager()
60{ 71{
61 72 delete bar;
62} 73}
63 74
64 75
65void KSyncManager::fillSyncMenu() 76void KSyncManager::fillSyncMenu()
66{ 77{
67 if ( mSyncMenu->count() ) 78 if ( mSyncMenu->count() )
68 mSyncMenu->clear(); 79 mSyncMenu->clear();
69 80
70 mSyncMenu->insertItem( i18n("Configure..."), 0 ); 81 mSyncMenu->insertItem( i18n("Configure..."), 0 );
71 mSyncMenu->insertSeparator(); 82 mSyncMenu->insertSeparator();
72 mSyncMenu->insertItem( i18n("Multiple sync"), 1 ); 83 mSyncMenu->insertItem( i18n("Multiple sync"), 1 );
73 mSyncMenu->insertSeparator(); 84 mSyncMenu->insertSeparator();
74 85
75 KConfig config ( locateLocal( "config","ksyncprofilesrc" ) ); 86 KConfig config ( locateLocal( "config","ksyncprofilesrc" ) );
76 config.setGroup("General"); 87 config.setGroup("General");
77 QStringList prof = config.readListEntry("SyncProfileNames"); 88 QStringList prof = config.readListEntry("SyncProfileNames");
78 mPrefs->mLocalMachineName = config.readEntry("LocalMachineName","undefined"); 89 mPrefs->mLocalMachineName = config.readEntry("LocalMachineName","undefined");
79 if ( prof.count() < 3 ) { 90 if ( prof.count() < 3 ) {
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");
84 KSyncProfile* temp = new KSyncProfile (); 95 KSyncProfile* temp = new KSyncProfile ();
85 temp->setName( prof[0] ); 96 temp->setName( prof[0] );
86 temp->writeConfig(&config); 97 temp->writeConfig(&config);
87 temp->setName( prof[1] ); 98 temp->setName( prof[1] );
88 temp->writeConfig(&config); 99 temp->writeConfig(&config);
89 temp->setName( prof[2] ); 100 temp->setName( prof[2] );
90 temp->writeConfig(&config); 101 temp->writeConfig(&config);
91 config.setGroup("General"); 102 config.setGroup("General");
92 config.writeEntry("SyncProfileNames",prof); 103 config.writeEntry("SyncProfileNames",prof);
93 config.writeEntry("ExternSyncProfiles","Sharp_DTM"); 104 config.writeEntry("ExternSyncProfiles","Sharp_DTM");
94 config.sync(); 105 config.sync();
95 delete temp; 106 delete temp;
96 } 107 }
97 mPrefs->mExternSyncProfiles = config.readListEntry("ExternSyncProfiles"); 108 mPrefs->mExternSyncProfiles = config.readListEntry("ExternSyncProfiles");
98 mPrefs->mSyncProfileNames = prof; 109 mPrefs->mSyncProfileNames = prof;
99 unsigned int i; 110 unsigned int i;
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 );
103 if ( i == 2 ) 113 if ( i == 2 )
104 mSyncMenu->insertSeparator(); 114 mSyncMenu->insertSeparator();
105 } 115 }
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 }
110 //probaly useless 124 //probaly useless
111 //mView->setupExternSyncProfiles(); 125 //mView->setupExternSyncProfiles();
112} 126}
113 127
114void KSyncManager::slotSyncMenu( int action ) 128void KSyncManager::slotSyncMenu( int action )
115{ 129{
116 //qDebug("syncaction %d ", action); 130 //qDebug("syncaction %d ", action);
117 if ( action == 0 ) { 131 if ( action == 0 ) {
118 132
119 // seems to be a Qt2 event handling bug 133 // seems to be a Qt2 event handling bug
120 // syncmenu.clear causes a segfault at first time 134 // syncmenu.clear causes a segfault at first time
121 // when we call it after the main event loop, it is ok 135 // when we call it after the main event loop, it is ok
122 // same behaviour when calling OM/Pi via QCOP for the first time 136 // same behaviour when calling OM/Pi via QCOP for the first time
123 QTimer::singleShot ( 1, this, SLOT ( confSync() ) ); 137 QTimer::singleShot ( 1, this, SLOT ( confSync() ) );
124 //confSync(); 138 //confSync();
125 139
126 return; 140 return;
127 } 141 }
128 if ( action == 1 ) { 142 if ( action == 1 ) {
129 multiSync( true ); 143 multiSync( true );
130 return; 144 return;
131 } 145 }
132 146
@@ -140,72 +154,106 @@ void KSyncManager::slotSyncMenu( int action )
140 mCurrentSyncName = mPrefs->mLocalMachineName ; 154 mCurrentSyncName = mPrefs->mLocalMachineName ;
141 KConfig config ( locateLocal( "config","ksyncprofilesrc" ) ); 155 KConfig config ( locateLocal( "config","ksyncprofilesrc" ) );
142 KSyncProfile* temp = new KSyncProfile (); 156 KSyncProfile* temp = new KSyncProfile ();
143 temp->setName(mPrefs->mSyncProfileNames[mCurrentSyncProfile]); 157 temp->setName(mPrefs->mSyncProfileNames[mCurrentSyncProfile]);
144 temp->readConfig(&config); 158 temp->readConfig(&config);
145 mPrefs->mAskForPreferences = temp->getAskForPreferences(); 159 mPrefs->mAskForPreferences = temp->getAskForPreferences();
146 mPrefs->mSyncAlgoPrefs = temp->getSyncPrefs(); 160 mPrefs->mSyncAlgoPrefs = temp->getSyncPrefs();
147 mPrefs->mWriteBackFile = temp->getWriteBackFile(); 161 mPrefs->mWriteBackFile = temp->getWriteBackFile();
148 mPrefs->mWriteBackExistingOnly = temp->getWriteBackExisting(); 162 mPrefs->mWriteBackExistingOnly = temp->getWriteBackExisting();
149 mPrefs->mWriteBackInFuture = 0; 163 mPrefs->mWriteBackInFuture = 0;
150 if ( temp->getWriteBackFuture() ) 164 if ( temp->getWriteBackFuture() )
151 mPrefs->mWriteBackInFuture = temp->getWriteBackFutureWeeks( ); 165 mPrefs->mWriteBackInFuture = temp->getWriteBackFutureWeeks( );
152 mPrefs->mShowSyncSummary = temp->getShowSummaryAfterSync(); 166 mPrefs->mShowSyncSummary = temp->getShowSummaryAfterSync();
153 if ( action == 1000 ) { 167 if ( action == 1000 ) {
154 syncSharp(); 168 syncSharp();
155 169
156 } else if ( action == 1001 ) { 170 } else if ( action == 1001 ) {
157 syncLocalFile(); 171 syncLocalFile();
158 172
159 } else if ( action == 1002 ) { 173 } else if ( action == 1002 ) {
160 quickSyncLocalFile(); 174 quickSyncLocalFile();
161 175
162 } else if ( action >= 1003 ) { 176 } else if ( action >= 1003 ) {
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 {
168 if ( temp->getIsPhoneSync() ) { 198 if ( temp->getIsPhoneSync() ) {
169 mPrefs->mPhoneDevice = temp->getPhoneDevice( ) ; 199 mPrefs->mPhoneDevice = temp->getPhoneDevice( ) ;
170 mPrefs->mPhoneConnection = temp->getPhoneConnection( ); 200 mPrefs->mPhoneConnection = temp->getPhoneConnection( );
171 mPrefs->mPhoneModel = temp->getPhoneModel( ); 201 mPrefs->mPhoneModel = temp->getPhoneModel( );
172 syncPhone(); 202 syncPhone();
173 } else 203 } else
174 syncRemote( temp ); 204 syncRemote( temp );
175 205
176 } 206 }
177 } 207 }
178 delete temp; 208 delete temp;
179 setBlockSave(false); 209 setBlockSave(false);
180} 210}
181 211
182void KSyncManager::syncLocalFile() 212void KSyncManager::syncLocalFile()
183{ 213{
184 214
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 == "" )
189 return; 237 return;
190 if ( syncWithFile( fn, false ) ) { 238 if ( syncWithFile( fn, false ) ) {
191 qDebug("syncLocalFile() successful "); 239 qDebug("syncLocalFile() successful ");
192 } 240 }
193 241
194} 242}
195bool KSyncManager::syncWithFile( QString fn , bool quick ) 243bool KSyncManager::syncWithFile( QString fn , bool quick )
196{ 244{
197 bool ret = false; 245 bool ret = false;
198 QFileInfo info; 246 QFileInfo info;
199 info.setFile( fn ); 247 info.setFile( fn );
200 QString mess; 248 QString mess;
201 bool loadbup = true; 249 bool loadbup = true;
202 if ( !info. exists() ) { 250 if ( !info. exists() ) {
203 mess = i18n( "Sync file \n...%1\ndoes not exist!\nNothing synced!\n").arg(fn.right( 30) ); 251 mess = i18n( "Sync file \n...%1\ndoes not exist!\nNothing synced!\n").arg(fn.right( 30) );
204 int result = QMessageBox::warning( mParent, i18n("Warning!"), 252 int result = QMessageBox::warning( mParent, i18n("Warning!"),
205 mess ); 253 mess );
206 return ret; 254 return ret;
207 } 255 }
208 int result = 0; 256 int result = 0;
209 if ( !quick ) { 257 if ( !quick ) {
210 mess = i18n("Sync with file \n...%1\nfrom:\n%2\n").arg(fn.right( 25)).arg(KGlobal::locale()->formatDateTime(info.lastModified (), true, false )); 258 mess = i18n("Sync with file \n...%1\nfrom:\n%2\n").arg(fn.right( 25)).arg(KGlobal::locale()->formatDateTime(info.lastModified (), true, false ));
211 result = QMessageBox::warning( mParent, i18n("Warning!"), 259 result = QMessageBox::warning( mParent, i18n("Warning!"),
@@ -263,151 +311,216 @@ void KSyncManager::multiSync( bool askforPrefs )
263 if ( num > 1 ) 311 if ( num > 1 )
264 ringSync(); 312 ringSync();
265 setBlockSave(false); 313 setBlockSave(false);
266 if ( num ) 314 if ( num )
267 mImplementation->sync_save(); 315 mImplementation->sync_save();
268 if ( num ) 316 if ( num )
269 mParent->setCaption(i18n("%1 profiles synced. Multiple sync completed!").arg(num) ); 317 mParent->setCaption(i18n("%1 profiles synced. Multiple sync completed!").arg(num) );
270 else 318 else
271 mParent->setCaption(i18n("Nothing synced! No profiles defined for multisync!")); 319 mParent->setCaption(i18n("Nothing synced! No profiles defined for multisync!"));
272 return; 320 return;
273} 321}
274int KSyncManager::ringSync() 322int KSyncManager::ringSync()
275{ 323{
276 int syncedProfiles = 0; 324 int syncedProfiles = 0;
277 unsigned int i; 325 unsigned int i;
278 QTime timer; 326 QTime timer;
279 KConfig config ( locateLocal( "config","ksyncprofilesrc" ) ); 327 KConfig config ( locateLocal( "config","ksyncprofilesrc" ) );
280 QStringList syncProfileNames = mPrefs->mSyncProfileNames; 328 QStringList syncProfileNames = mPrefs->mSyncProfileNames;
281 KSyncProfile* temp = new KSyncProfile (); 329 KSyncProfile* temp = new KSyncProfile ();
282 mPrefs->mAskForPreferences = false; 330 mPrefs->mAskForPreferences = false;
283 for ( i = 0; i < syncProfileNames.count(); ++i ) { 331 for ( i = 0; i < syncProfileNames.count(); ++i ) {
284 mCurrentSyncProfile = i; 332 mCurrentSyncProfile = i;
285 temp->setName(syncProfileNames[mCurrentSyncProfile]); 333 temp->setName(syncProfileNames[mCurrentSyncProfile]);
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 ... "));
289 ++syncedProfiles; 357 ++syncedProfiles;
290 // mPrefs->mAskForPreferences = temp->getAskForPreferences(); 358 // mPrefs->mAskForPreferences = temp->getAskForPreferences();
291 mPrefs->mWriteBackFile = temp->getWriteBackFile(); 359 mPrefs->mWriteBackFile = temp->getWriteBackFile();
292 mPrefs->mWriteBackExistingOnly = temp->getWriteBackExisting(); 360 mPrefs->mWriteBackExistingOnly = temp->getWriteBackExisting();
293 mPrefs->mWriteBackInFuture = 0; 361 mPrefs->mWriteBackInFuture = 0;
294 if ( temp->getWriteBackFuture() ) 362 if ( temp->getWriteBackFuture() )
295 mPrefs->mWriteBackInFuture = temp->getWriteBackFutureWeeks( ); 363 mPrefs->mWriteBackInFuture = temp->getWriteBackFutureWeeks( );
296 mPrefs->mShowSyncSummary = false; 364 mPrefs->mShowSyncSummary = false;
297 mCurrentSyncDevice = syncProfileNames[i] ; 365 mCurrentSyncDevice = syncProfileNames[i] ;
298 mCurrentSyncName = mPrefs->mLocalMachineName; 366 mCurrentSyncName = mPrefs->mLocalMachineName;
299 if ( i == 0 ) { 367 if ( i == 0 ) {
300 syncSharp(); 368 syncSharp();
301 } else { 369 } else {
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 {
306 if ( temp->getIsPhoneSync() ) { 390 if ( temp->getIsPhoneSync() ) {
307 mPrefs->mPhoneDevice = temp->getPhoneDevice( ) ; 391 mPrefs->mPhoneDevice = temp->getPhoneDevice( ) ;
308 mPrefs->mPhoneConnection = temp->getPhoneConnection( ); 392 mPrefs->mPhoneConnection = temp->getPhoneConnection( );
309 mPrefs->mPhoneModel = temp->getPhoneModel( ); 393 mPrefs->mPhoneModel = temp->getPhoneModel( );
310 syncPhone(); 394 syncPhone();
311 } else 395 } else
312 syncRemote( temp, false ); 396 syncRemote( temp, false );
313 397
314 } 398 }
315 } 399 }
316 timer.start(); 400 timer.start();
317 mParent->setCaption(i18n("Multiple sync in progress ... please wait!") ); 401 mParent->setCaption(i18n("Multiple sync in progress ... please wait!") );
318 while ( timer.elapsed () < 2000 ) { 402 while ( timer.elapsed () < 2000 ) {
319 qApp->processEvents(); 403 qApp->processEvents();
320#ifndef _WIN32_ 404#ifndef _WIN32_
321 sleep (1); 405 sleep (1);
322#endif 406#endif
323 } 407 }
324 408
325 } 409 }
326 410
327 } 411 }
328 delete temp; 412 delete temp;
329 return syncedProfiles; 413 return syncedProfiles;
330} 414}
331 415
332void KSyncManager::syncRemote( KSyncProfile* prof, bool ask) 416void KSyncManager::syncRemote( KSyncProfile* prof, bool ask)
333{ 417{
334 QString question; 418 QString question;
335 if ( ask ) { 419 if ( ask ) {
336 question = i18n("Do you really want\nto remote sync\nwith profile \n")+ prof->getName()+" ?\n"; 420 question = i18n("Do you really want\nto remote sync\nwith profile \n")+ prof->getName()+" ?\n";
337 if ( QMessageBox::information( mParent, i18n("Sync"), 421 if ( QMessageBox::information( mParent, i18n("Sync"),
338 question, 422 question,
339 i18n("Yes"), i18n("No"), 423 i18n("Yes"), i18n("No"),
340 0, 0 ) != 0 ) 424 0, 0 ) != 0 )
341 return; 425 return;
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
349 } 460 }
350 int maxlen = 30; 461 int maxlen = 30;
351 if ( QApplication::desktop()->width() > 320 ) 462 if ( QApplication::desktop()->width() > 320 )
352 maxlen += 25; 463 maxlen += 25;
353 mParent->setCaption ( i18n( "Copy remote file to local machine..." ) ); 464 mParent->setCaption ( i18n( "Copy remote file to local machine..." ) );
354 int fileSize = 0; 465 int fileSize = 0;
355 int result = system ( command ); 466 int result = system ( preCommand );
356 // 0 : okay 467 // 0 : okay
357 // 256: no such file or dir 468 // 256: no such file or dir
358 // 469 //
359 qDebug("KO: Remote copy result(0 = okay): %d ",result ); 470 qDebug("KO: Remote copy result(0 = okay): %d ",result );
360 if ( result != 0 ) { 471 if ( result != 0 ) {
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"),
368 question, 479 question,
369 i18n("Okay!")) ; 480 i18n("Okay!")) ;
370 mParent->setCaption (""); 481 mParent->setCaption ("");
371 return; 482 return;
372 } 483 }
373 mParent->setCaption ( i18n( "Copying succeed." ) ); 484 mParent->setCaption ( i18n( "Copying succeed." ) );
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();
377// e->setReadOnly( false ); 491// e->setReadOnly( false );
378// e->setLocation( KOPrefs::instance()->mSyncProfileNames[mCurrentSyncProfile]); 492// e->setLocation( KOPrefs::instance()->mSyncProfileNames[mCurrentSyncProfile]);
379// e->setReadOnly( true ); 493// e->setReadOnly( true );
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
387 } 500 }
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);
391 if ( result != 0 ) { 504 if ( result != 0 ) {
392 mParent->setCaption ( i18n( "Writing back file result: " )+QString::number( result ) ); 505 mParent->setCaption ( i18n( "Writing back file result: " )+QString::number( result ) );
393 return; 506 return;
394 } else { 507 } else {
395 mParent->setCaption ( i18n( "Syncronization sucessfully completed" ) ); 508 mParent->setCaption ( i18n( "Syncronization sucessfully completed" ) );
396 } 509 }
397 } 510 }
398 } 511 }
399 return; 512 return;
400} 513}
401 514
402void KSyncManager::edit_sync_options() 515void KSyncManager::edit_sync_options()
403{ 516{
404 //mDialogManager->showSyncOptions(); 517 //mDialogManager->showSyncOptions();
405 //mPrefs->mSyncAlgoPrefs 518 //mPrefs->mSyncAlgoPrefs
406 QDialog dia( mParent, "dia", true ); 519 QDialog dia( mParent, "dia", true );
407 dia.setCaption( i18n("Device: " ) +mCurrentSyncDevice ); 520 dia.setCaption( i18n("Device: " ) +mCurrentSyncDevice );
408 QButtonGroup gr ( 1, Qt::Horizontal, i18n("Sync preferences"), &dia); 521 QButtonGroup gr ( 1, Qt::Horizontal, i18n("Sync preferences"), &dia);
409 QVBoxLayout lay ( &dia ); 522 QVBoxLayout lay ( &dia );
410 lay.setSpacing( 2 ); 523 lay.setSpacing( 2 );
411 lay.setMargin( 3 ); 524 lay.setMargin( 3 );
412 lay.addWidget(&gr); 525 lay.addWidget(&gr);
413 QRadioButton loc ( i18n("Take local entry on conflict"), &gr ); 526 QRadioButton loc ( i18n("Take local entry on conflict"), &gr );
@@ -506,24 +619,47 @@ bool KSyncManager::syncExternalApplication(QString resource)
506 if ( mImplementation->sync_isModified() ) 619 if ( mImplementation->sync_isModified() )
507 mImplementation->sync_save(); 620 mImplementation->sync_save();
508 621
509 if ( mPrefs->mAskForPreferences ) 622 if ( mPrefs->mAskForPreferences )
510 edit_sync_options(); 623 edit_sync_options();
511 624
512 qDebug("sync %s", resource.latin1()); 625 qDebug("sync %s", resource.latin1());
513 626
514 bool syncOK = mImplementation->syncExternal(this, resource); 627 bool syncOK = mImplementation->syncExternal(this, resource);
515 628
516 return syncOK; 629 return syncOK;
517 630
518} 631}
519 632
520void KSyncManager::syncPhone() 633void KSyncManager::syncPhone()
521{ 634{
522 if ( mImplementation->sync_isModified() ) 635 if ( mImplementation->sync_isModified() )
523 mImplementation->sync_save(); 636 mImplementation->sync_save();
524 637
525 qDebug("pending syncPhone(); "); 638 qDebug("pending syncPhone(); ");
526 //mView->syncPhone(); 639 //mView->syncPhone();
527 mImplementation->sync_setModified(); 640 mImplementation->sync_setModified();
528 641
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
@@ -10,110 +10,120 @@
10 This library is distributed in the hope that it will be useful, 10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details. 13 Library General Public License for more details.
14 14
15 You should have received a copy of the GNU Library General Public License 15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to 16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. 18 Boston, MA 02111-1307, USA.
19 19
20$Id$ 20$Id$
21*/ 21*/
22#ifndef _KSYNCMANAGER_H 22#ifndef _KSYNCMANAGER_H
23#define _KSYNCMANAGER_H 23#define _KSYNCMANAGER_H
24 24
25#include <qobject.h> 25#include <qobject.h>
26#include <qstring.h> 26#include <qstring.h>
27 27
28class QPopupMenu; 28class QPopupMenu;
29class KSyncProfile; 29class KSyncProfile;
30class KPimPrefs; 30class KPimPrefs;
31class QWidget; 31class QWidget;
32class KSyncManager; 32class KSyncManager;
33class KSyncInterface; 33class KSyncInterface;
34class QProgressBar;
34 35
35class KSyncManager : public QObject 36class KSyncManager : public QObject
36{ 37{
37 Q_OBJECT 38 Q_OBJECT
38 39
39 public: 40 public:
40 enum TargetApp { 41 enum TargetApp {
41 KOPI = 0, 42 KOPI = 0,
42 KAPI = 1, 43 KAPI = 1,
43 PWMPI = 2 }; 44 PWMPI = 2 };
44 45
45 46
46 KSyncManager(QWidget* parent, KSyncInterface* implementation, TargetApp ta, KPimPrefs* prefs, QPopupMenu* syncmenu); 47 KSyncManager(QWidget* parent, KSyncInterface* implementation, TargetApp ta, KPimPrefs* prefs, QPopupMenu* syncmenu);
47 ~KSyncManager() ; 48 ~KSyncManager() ;
48 49
49 bool blockSave() { return mBlockSaveFlag; } 50 bool blockSave() { return mBlockSaveFlag; }
50 void setBlockSave(bool sa) { mBlockSaveFlag = sa; } 51 void setBlockSave(bool sa) { mBlockSaveFlag = sa; }
51 52
52 void fillSyncMenu(); 53 void fillSyncMenu();
53 54
54 QString getCurrentSyncDevice() { return mCurrentSyncDevice; } 55 QString getCurrentSyncDevice() { return mCurrentSyncDevice; }
55 QString getCurrentSyncName() { return mCurrentSyncName; } 56 QString getCurrentSyncName() { return mCurrentSyncName; }
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:
58 void slotSyncMenu( int ); 64 void slotSyncMenu( int );
59 65
60 private: 66 private:
61 // LR ******************************* 67 // LR *******************************
62 // sync stuff! 68 // sync stuff!
63 QString mCurrentSyncDevice; 69 QString mCurrentSyncDevice;
64 QString mCurrentSyncName; 70 QString mCurrentSyncName;
65 void quickSyncLocalFile(); 71 void quickSyncLocalFile();
66 bool syncWithFile( QString fn , bool quick ); 72 bool syncWithFile( QString fn , bool quick );
67 void syncLocalFile(); 73 void syncLocalFile();
68 void syncPhone(); 74 void syncPhone();
69 void syncSharp(); 75 void syncSharp();
70 bool syncExternalApplication(QString); 76 bool syncExternalApplication(QString);
71 void multiSync( bool askforPrefs ); 77 void multiSync( bool askforPrefs );
72 int mCurrentSyncProfile ; 78 int mCurrentSyncProfile ;
73 void syncRemote( KSyncProfile* prof, bool ask = true); 79 void syncRemote( KSyncProfile* prof, bool ask = true);
74 void edit_sync_options(); 80 void edit_sync_options();
75 int ringSync(); 81 int ringSync();
76 QString getPassword( ); 82 QString getPassword( );
77 83
78 private slots: 84 private slots:
79 void confSync(); 85 void confSync();
80 // ********************* 86 // *********************
81 87
82 private: 88 private:
83 bool mBlockSaveFlag; 89 bool mBlockSaveFlag;
84 90
85 91
86 QWidget* mParent; 92 QWidget* mParent;
87 KSyncInterface* mImplementation; 93 KSyncInterface* mImplementation;
88 TargetApp mTargetApp; 94 TargetApp mTargetApp;
89 KPimPrefs* mPrefs; 95 KPimPrefs* mPrefs;
90 QPopupMenu* mSyncMenu; 96 QPopupMenu* mSyncMenu;
91 97
92 98 QProgressBar* bar;
93 99
94 100
95 101
96 102
97 103
98}; 104};
99 105
100 106
101class KSyncInterface 107class KSyncInterface
102{ 108{
103 public: 109 public:
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
108 //called by the syncmanager to indicate that the work has to be marked as dirty. 118 //called by the syncmanager to indicate that the work has to be marked as dirty.
109 virtual void sync_setModified() = 0; 119 virtual void sync_setModified() = 0;
110 120
111 //called by the syncmanager to ask if the dirty flag is set. 121 //called by the syncmanager to ask if the dirty flag is set.
112 virtual bool sync_isModified() = 0; 122 virtual bool sync_isModified() = 0;
113 123
114 //called by the syncmanager to indicate that the work has to be saved. 124 //called by the syncmanager to indicate that the work has to be saved.
115 virtual void sync_save() = 0; 125 virtual void sync_save() = 0;
116}; 126};
117 127
118 128
119#endif 129#endif
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
@@ -1301,55 +1301,65 @@ void PwM::createAboutData_slot()
1301 "for: Zaurus 5500 / 7x0 / 8x0\n" 1301 "for: Zaurus 5500 / 7x0 / 8x0\n"
1302#endif 1302#endif
1303 1303
1304 "(c) 2004 Ulf Schenk\n" 1304 "(c) 2004 Ulf Schenk\n"
1305 "(c) 2004 Lutz Rogowski\n" 1305 "(c) 2004 Lutz Rogowski\n"
1306 "(c) 1997-2004, The KDE PIM Team\n" 1306 "(c) 1997-2004, The KDE PIM Team\n"
1307 1307
1308 "(c) Michael Buesch - main programming\nand current maintainer\nmbuesch@freenet.de\n" 1308 "(c) Michael Buesch - main programming\nand current maintainer\nmbuesch@freenet.de\n"
1309 "Matt Scifo - mscifo@o1.com\n" 1309 "Matt Scifo - mscifo@o1.com\n"
1310 "Elias Probst - elias.probst@gmx.de\n" 1310 "Elias Probst - elias.probst@gmx.de\n"
1311 "George Staikos - staikos@kde.org\n" 1311 "George Staikos - staikos@kde.org\n"
1312 "Matthew Palmer - mjp16@uow.edu.au\n" 1312 "Matthew Palmer - mjp16@uow.edu.au\n"
1313 "Olivier Sessink - gpasman@nl.linux.org\n" 1313 "Olivier Sessink - gpasman@nl.linux.org\n"
1314 "The libgcrypt developers -\nBlowfish and SHA1 algorithms\nftp://ftp.gnupg.org/gcrypt/alpha/libgcrypt/\n" 1314 "The libgcrypt developers -\nBlowfish and SHA1 algorithms\nftp://ftp.gnupg.org/gcrypt/alpha/libgcrypt/\n"
1315 "Troy Engel - tengel@sonic.net\n" 1315 "Troy Engel - tengel@sonic.net\n"
1316 "Wickey - wickey@gmx.at\n" 1316 "Wickey - wickey@gmx.at\n"
1317 "Ian MacGregor - original documentation author.\n" 1317 "Ian MacGregor - original documentation author.\n"
1318 ); 1318 );
1319} 1319}
1320 1320
1321 1321
1322//this are the overwritten callbackmethods from the syncinterface 1322//this are the overwritten callbackmethods from the syncinterface
1323bool PwM::sync(KSyncManager* manager, QString filename, int mode) 1323bool 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}
1337 1343
1338//called by the syncmanager to ask if the dirty flag is set. 1344//called by the syncmanager to ask if the dirty flag is set.
1339bool PwM::sync_isModified() 1345bool PwM::sync_isModified()
1340{ 1346{
1347 PWM_ASSERT(curDoc());
1348 return curDoc()->sync_isModified();
1341} 1349}
1342 1350
1343//called by the syncmanager to indicate that the work has to be saved. 1351//called by the syncmanager to indicate that the work has to be saved.
1344void PwM::sync_save() 1352void PwM::sync_save()
1345{ 1353{
1354 PWM_ASSERT(curDoc());
1355 return curDoc()->sync_save();
1346} 1356}
1347 1357
1348 1358
1349 1359
1350#endif 1360#endif
1351 1361
1352 1362
1353#ifndef PWM_EMBEDDED 1363#ifndef PWM_EMBEDDED
1354#include "pwm.moc" 1364#include "pwm.moc"
1355#endif 1365#endif
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
@@ -250,49 +250,48 @@ protected:
250 KPopupMenu *chipcardPopup; 250 KPopupMenu *chipcardPopup;
251#endif // CONFIG_KEYCARD 251#endif // CONFIG_KEYCARD
252 /** "view" popup-menu */ 252 /** "view" popup-menu */
253 KPopupMenu *viewPopup; 253 KPopupMenu *viewPopup;
254 /** "options" popup-menu */ 254 /** "options" popup-menu */
255 KPopupMenu *optionsPopup; 255 KPopupMenu *optionsPopup;
256 /** "help" popup-menu */ 256 /** "help" popup-menu */
257 KPopupMenu *helpPopup; 257 KPopupMenu *helpPopup;
258 /** "export" popup-menu */ 258 /** "export" popup-menu */
259 KPopupMenu *exportPopup; 259 KPopupMenu *exportPopup;
260 /** "import" popup-menu */ 260 /** "import" popup-menu */
261 KPopupMenu *importPopup; 261 KPopupMenu *importPopup;
262 /** force quit this window? */ 262 /** force quit this window? */
263 bool forceQuit; 263 bool forceQuit;
264 /** force minimize this window to the tray */ 264 /** force minimize this window to the tray */
265 bool forceMinimizeToTray; 265 bool forceMinimizeToTray;
266 266
267 267
268 268
269 269
270 private: 270 private:
271#ifdef PWM_EMBEDDED 271#ifdef PWM_EMBEDDED
272 //this are the overwritten callbackmethods from the syncinterface 272 //this are the overwritten callbackmethods from the syncinterface
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
276 //called by the syncmanager to indicate that the work has to marked as dirty. 275 //called by the syncmanager to indicate that the work has to marked as dirty.
277 virtual void sync_setModified(); 276 virtual void sync_setModified();
278 //called by the syncmanager to ask if the dirty flag is set. 277 //called by the syncmanager to ask if the dirty flag is set.
279 virtual bool sync_isModified(); 278 virtual bool sync_isModified();
280 //called by the syncmanager to indicate that the work has to be saved. 279 //called by the syncmanager to indicate that the work has to be saved.
281 virtual void sync_save(); 280 virtual void sync_save();
282 281
283 // LR ******************************* 282 // LR *******************************
284 // sync stuff! 283 // sync stuff!
285 QPopupMenu *syncPopup; 284 QPopupMenu *syncPopup;
286 KSyncManager* syncManager; 285 KSyncManager* syncManager;
287#endif 286#endif
288 287
289 288
290 289
291 290
292 291
293 292
294 293
295 294
296}; 295};
297 296
298#endif 297#endif
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
@@ -2760,27 +2760,119 @@ QString PwMDoc::getTitle()
2760bool PwMDoc::tryDelete() 2760bool PwMDoc::tryDelete()
2761{ 2761{
2762 if (deleted) 2762 if (deleted)
2763 return true; 2763 return true;
2764 int ret; 2764 int ret;
2765 if (isDirty()) { 2765 if (isDirty()) {
2766 ret = dirtyAskSave(getTitle()); 2766 ret = dirtyAskSave(getTitle());
2767 if (ret == 0) { // save to disk 2767 if (ret == 0) { // save to disk
2768 if (!saveDocUi(this)) 2768 if (!saveDocUi(this))
2769 goto out_ignore; 2769 goto out_ignore;
2770 } else if (ret == 1) { // don't save and delete 2770 } else if (ret == 1) { // don't save and delete
2771 goto out_accept; 2771 goto out_accept;
2772 } else { // cancel operation 2772 } else { // cancel operation
2773 goto out_ignore; 2773 goto out_ignore;
2774 } 2774 }
2775 } 2775 }
2776out_accept: 2776out_accept:
2777 deleted = true; 2777 deleted = true;
2778 delete this; 2778 delete this;
2779 return true; 2779 return true;
2780out_ignore: 2780out_ignore:
2781 return false; 2781 return false;
2782} 2782}
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
2785#include "pwmdoc.moc" 2877#include "pwmdoc.moc"
2786#endif 2878#endif
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
@@ -38,48 +38,49 @@
38 #define PWM_CRYPT_TWOFISH(static_cast<char>(0x06)) 38 #define PWM_CRYPT_TWOFISH(static_cast<char>(0x06))
39 #define PWM_CRYPT_TWOFISH128(static_cast<char>(0x07)) 39 #define PWM_CRYPT_TWOFISH128(static_cast<char>(0x07))
40 40
41 #define PWM_COMPRESS_NONE(static_cast<char>(0x00)) 41 #define PWM_COMPRESS_NONE(static_cast<char>(0x00))
42 #define PWM_COMPRESS_GZIP(static_cast<char>(0x01)) 42 #define PWM_COMPRESS_GZIP(static_cast<char>(0x01))
43 #define PWM_COMPRESS_BZIP2(static_cast<char>(0x02)) 43 #define PWM_COMPRESS_BZIP2(static_cast<char>(0x02))
44 44
45 #define DEFAULT_MAX_ENTRIES(~(static_cast<unsigned int>(0))) 45 #define DEFAULT_MAX_ENTRIES(~(static_cast<unsigned int>(0)))
46 #define FILE_ID_HEADER "PWM_PASSWORD_FILE" 46 #define FILE_ID_HEADER "PWM_PASSWORD_FILE"
47 47
48 48
49#include "pwmexception.h" 49#include "pwmexception.h"
50#include "pwmdocui.h" 50#include "pwmdocui.h"
51 51
52#include <qobject.h> 52#include <qobject.h>
53#include <qtimer.h> 53#include <qtimer.h>
54#include <qdatetime.h> 54#include <qdatetime.h>
55 55
56#include <kprocess.h> 56#include <kprocess.h>
57 57
58#ifndef PWM_EMBEDDED 58#ifndef PWM_EMBEDDED
59#include "configuration.h" 59#include "configuration.h"
60#else 60#else
61#include <kapplication.h> 61#include <kapplication.h>
62#include <ksyncmanager.h>
62#endif 63#endif
63 64
64#include <string> 65#include <string>
65#include <vector> 66#include <vector>
66#include <utility> 67#include <utility>
67 68
68using std::vector; 69using std::vector;
69using std::string; 70using std::string;
70using std::pair; 71using std::pair;
71 72
72/* used in findEntry() function */ 73/* used in findEntry() function */
73 #define SEARCH_IN_DESC (1) 74 #define SEARCH_IN_DESC (1)
74 #define SEARCH_IN_NAME (1 << 1) 75 #define SEARCH_IN_NAME (1 << 1)
75 #define SEARCH_IN_PW (1 << 2) 76 #define SEARCH_IN_PW (1 << 2)
76 #define SEARCH_IN_COMMENT(1 << 3) 77 #define SEARCH_IN_COMMENT(1 << 3)
77 #define SEARCH_IN_URL (1 << 4) 78 #define SEARCH_IN_URL (1 << 4)
78 #define SEARCH_IN_LAUNCHER(1 << 5) 79 #define SEARCH_IN_LAUNCHER(1 << 5)
79 #define SEARCH_IN_ALL (SEARCH_IN_DESC | SEARCH_IN_NAME| \ 80 #define SEARCH_IN_ALL (SEARCH_IN_DESC | SEARCH_IN_NAME| \
80 SEARCH_IN_PW | SEARCH_IN_COMMENT| \ 81 SEARCH_IN_PW | SEARCH_IN_COMMENT| \
81 SEARCH_IN_URL| SEARCH_IN_LAUNCHER) 82 SEARCH_IN_URL| SEARCH_IN_LAUNCHER)
82 83
83/** document deeplocked. Data is out for lunch to disk */ 84/** document deeplocked. Data is out for lunch to disk */
84 #define DOC_STAT_DEEPLOCKED (1) 85 #define DOC_STAT_DEEPLOCKED (1)
85/** encrypted document on disk is dirty. data has to go to disk. */ 86/** encrypted document on disk is dirty. data has to go to disk. */
@@ -314,49 +315,52 @@ protected slots:
314 void mpwTimeout(); 315 void mpwTimeout();
315 /** timeout slot for the autoLock timer */ 316 /** timeout slot for the autoLock timer */
316 void autoLockTimeout(); 317 void autoLockTimeout();
317 /** timeout slot for the metaCheck timer */ 318 /** timeout slot for the metaCheck timer */
318 void metaCheckTimeout(); 319 void metaCheckTimeout();
319 320
320protected: 321protected:
321 /** pointer to the document associated with this timer. */ 322 /** pointer to the document associated with this timer. */
322 PwMDoc *doc; 323 PwMDoc *doc;
323 /** timer object for mpw timer */ 324 /** timer object for mpw timer */
324 QTimer *mpwTimer; 325 QTimer *mpwTimer;
325 /** timer object for the autoLock timer */ 326 /** timer object for the autoLock timer */
326 QTimer *autoLockTimer; 327 QTimer *autoLockTimer;
327 /** timer object for the metaCheck timer */ 328 /** timer object for the metaCheck timer */
328 QTimer *metaCheckTimer; 329 QTimer *metaCheckTimer;
329 /** lock counter for the mpw timer */ 330 /** lock counter for the mpw timer */
330 unsigned int mpwLock; 331 unsigned int mpwLock;
331 /** lock counter for the autoLock timer */ 332 /** lock counter for the autoLock timer */
332 unsigned int autoLockLock; 333 unsigned int autoLockLock;
333 /** lock counter for the metaCheck timer */ 334 /** lock counter for the metaCheck timer */
334 unsigned int metaCheckLock; 335 unsigned int metaCheckLock;
335}; 336};
336 337
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{
340 Q_OBJECT 344 Q_OBJECT
341 friend class DocTimer; 345 friend class DocTimer;
342 346
343public: 347public:
344 /** construtor */ 348 /** construtor */
345 PwMDoc(QObject* parent = 0, const char *name = 0); 349 PwMDoc(QObject* parent = 0, const char *name = 0);
346 /** destructor */ 350 /** destructor */
347 ~PwMDoc(); 351 ~PwMDoc();
348 352
349 /** returns a pointer to a list of all open documents */ 353 /** returns a pointer to a list of all open documents */
350 static PwMDocList* getOpenDocList() 354 static PwMDocList* getOpenDocList()
351 { return &openDocList; } 355 { return &openDocList; }
352 356
353 /** flag document dirty. dta changed */ 357 /** flag document dirty. dta changed */
354 void flagDirty() 358 void flagDirty()
355 { 359 {
356 setDocStatFlag(DOC_STAT_DISK_DIRTY); 360 setDocStatFlag(DOC_STAT_DISK_DIRTY);
357 emitDataChanged(this); 361 emitDataChanged(this);
358 } 362 }
359 /** modified? */ 363 /** modified? */
360 bool isDirty() 364 bool isDirty()
361 { return getDocStatFlag(DOC_STAT_DISK_DIRTY); } 365 { return getDocStatFlag(DOC_STAT_DISK_DIRTY); }
362 /** save document to disk */ 366 /** save document to disk */
@@ -675,27 +679,46 @@ protected:
675 bool exactWordMatch); 679 bool exactWordMatch);
676 /** clears all document-data */ 680 /** clears all document-data */
677 void clearDoc(); 681 void clearDoc();
678 /** delete all empty categories */ 682 /** delete all empty categories */
679 void delAllEmptyCat(bool dontFlagDirty); 683 void delAllEmptyCat(bool dontFlagDirty);
680 /** set a document status flag */ 684 /** set a document status flag */
681 void setDocStatFlag(unsigned int statFlag) 685 void setDocStatFlag(unsigned int statFlag)
682 { curDocStat |= statFlag; } 686 { curDocStat |= statFlag; }
683 /** unset a document status flag */ 687 /** unset a document status flag */
684 void unsetDocStatFlag(unsigned int statFlag) 688 void unsetDocStatFlag(unsigned int statFlag)
685 { curDocStat &= ~statFlag; } 689 { curDocStat &= ~statFlag; }
686 /** get a document status flag */ 690 /** get a document status flag */
687 bool getDocStatFlag(unsigned int statFlag) const 691 bool getDocStatFlag(unsigned int statFlag) const
688 { return (curDocStat & statFlag); } 692 { return (curDocStat & statFlag); }
689 /** set the "currentPassword" */ 693 /** set the "currentPassword" */
690 void setCurrentPw(const QString &pw) 694 void setCurrentPw(const QString &pw)
691 { 695 {
692 currentPw = pw; 696 currentPw = pw;
693 setDocStatFlag(DOC_STAT_DISK_DIRTY); 697 setDocStatFlag(DOC_STAT_DISK_DIRTY);
694 } 698 }
695 /** make a backup-copy of the given file */ 699 /** make a backup-copy of the given file */
696 bool backupFile(const QString &filePath); 700 bool backupFile(const QString &filePath);
697 /** copy a file from src to dst */ 701 /** copy a file from src to dst */
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};
700 723
701#endif 724#endif