summaryrefslogtreecommitdiffabout
authorulf69 <ulf69>2004-10-03 23:29:56 (UTC)
committer ulf69 <ulf69>2004-10-03 23:29:56 (UTC)
commitaaea91151fe9a747e9eddfb8ba7d5896744faf30 (patch) (side-by-side diff)
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
@@ -1080,5 +1080,6 @@ void KABCore::save()
return;
- syncManager->setBlockSave(true);
if ( !mModified )
return;
+
+ syncManager->setBlockSave(true);
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
Addressee inL;
- QProgressBar bar( er.count(),0 );
- bar.setCaption (i18n("Syncing - close to abort!") );
-
- int w = 300;
- if ( QApplication::desktop()->width() < 320 )
- w = 220;
- int h = bar.sizeHint().height() ;
- int dw = QApplication::desktop()->width();
- int dh = QApplication::desktop()->height();
- bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
- bar.show();
+
+ syncManager->showProgressBar(0, i18n("Syncing - close to abort!"), er.count());
+
int modulo = (er.count()/10)+1;
@@ -2350,6 +2343,7 @@ bool KABCore::synchronizeAddressbooks( KABC::AddressBook* local, KABC::AddressBo
while ( incCounter < er.count()) {
- if ( ! bar.isVisible() )
+ if (syncManager->isProgressBarCanceled())
return false;
if ( incCounter % modulo == 0 )
- bar.setProgress( incCounter );
+ syncManager->showProgressBar(incCounter);
+
uid = er[ incCounter ];
@@ -2445,5 +2439,4 @@ bool KABCore::synchronizeAddressbooks( KABC::AddressBook* local, KABC::AddressBo
modulo = (el.count()/10)+1;
- bar.setCaption (i18n("Add / remove addressees") );
- bar.setTotalSteps ( el.count() ) ;
- bar.show();
+
+ syncManager->showProgressBar(0, i18n("Add / remove addressees"), el.count());
incCounter = 0;
@@ -2451,6 +2444,6 @@ bool KABCore::synchronizeAddressbooks( KABC::AddressBook* local, KABC::AddressBo
qApp->processEvents();
- if ( ! bar.isVisible() )
+ if (syncManager->isProgressBarCanceled())
return false;
if ( incCounter % modulo == 0 )
- bar.setProgress( incCounter );
+ syncManager->showProgressBar(incCounter);
uid = el[ incCounter ];
@@ -2501,3 +2494,3 @@ bool KABCore::synchronizeAddressbooks( KABC::AddressBook* local, KABC::AddressBo
el.clear();
- bar.hide();
+ syncManager->hideProgressBar();
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 @@
#include <qdir.h>
+#include <qprogressbar.h>
#include <qpopupmenu.h>
@@ -55,2 +56,12 @@ KSyncManager::KSyncManager(QWidget* parent, KSyncInterface* implementation, Targ
{
+ bar = new QProgressBar ( 1, 0 );
+ bar->setCaption ("");
+
+ int w = 300;
+ if ( QApplication::desktop()->width() < 320 )
+ w = 220;
+ int h = bar->sizeHint().height() ;
+ int dw = QApplication::desktop()->width();
+ int dh = QApplication::desktop()->height();
+ bar->setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
@@ -60,3 +71,3 @@ KSyncManager::~KSyncManager()
{
-
+ delete bar;
}
@@ -80,4 +91,4 @@ void KSyncManager::fillSyncMenu()
prof.clear();
- prof << i18n("Sharp_DTM");
- prof << i18n("Local_file");
+ prof << i18n("Sharp_DTM");
+ prof << i18n("Local_file");
prof << i18n("Last_file");
@@ -100,3 +111,2 @@ void KSyncManager::fillSyncMenu()
for ( i = 0; i < prof.count(); ++i ) {
-
mSyncMenu->insertItem( prof[i], 1000+i );
@@ -106,4 +116,8 @@ void KSyncManager::fillSyncMenu()
QDir app_dir;
- if ( !app_dir.exists(QDir::homeDirPath()+"/Applications/dtm" ) ) {
- mSyncMenu->setItemEnabled( false , 1000 );
+ //US do not display SharpDTM if app is pwmpi, or no sharpfiles available
+ if ( mTargetApp == PWMPI) {
+ mSyncMenu->removeItem( 1000 );
+ }
+ else if (!app_dir.exists(QDir::homeDirPath()+"/Applications/dtm" ) ) {
+ mSyncMenu->setItemEnabled( 1000, false );
}
@@ -163,5 +177,21 @@ void KSyncManager::slotSyncMenu( int action )
if ( temp->getIsLocalFileSync() ) {
- if ( syncWithFile( temp->getRemoteFileNameAB( ), false ) )
+ switch(mTargetApp)
+ {
+ case (KAPI):
+ if ( syncWithFile( temp->getRemoteFileNameAB( ), false ) )
mPrefs->mLastSyncedLocalFile = temp->getRemoteFileNameAB();
-
+ break;
+ case (KOPI):
+ if ( syncWithFile( temp->getRemoteFileName( ), false ) )
+ mPrefs->mLastSyncedLocalFile = temp->getRemoteFileName();
+ break;
+ case (PWMPI):
+ if ( syncWithFile( temp->getRemoteFileNamePWM( ), false ) )
+ mPrefs->mLastSyncedLocalFile = temp->getRemoteFileNamePWM();
+ break;
+ default:
+ qDebug("KSyncManager::slotSyncMenu: invalid apptype selected");
+ break;
+
+ }
} else {
@@ -185,4 +215,22 @@ void KSyncManager::syncLocalFile()
QString fn =mPrefs->mLastSyncedLocalFile;
-
- fn =KFileDialog:: getOpenFileName( fn, i18n("Sync filename(*.ics/*.vcs)"), mParent );
+ QString ext;
+
+ switch(mTargetApp)
+ {
+ case (KAPI):
+ ext = "(*.vcf)";
+ break;
+ case (KOPI):
+ ext = "(*.ics/*.vcs)";
+ break;
+ case (PWMPI):
+ ext = "(*.pwm)";
+ break;
+ default:
+ qDebug("KSyncManager::syncLocalFile: invalid apptype selected");
+ break;
+
+ }
+
+ fn =KFileDialog:: getOpenFileName( fn, i18n("Sync filename"+ext), mParent );
if ( fn == "" )
@@ -286,3 +334,23 @@ int KSyncManager::ringSync()
temp->readConfig(&config);
- if ( temp->getIncludeInRingSyncAB() && ( i < 1 || i > 2 )) {
+
+ QString includeInRingSync;
+ switch(mTargetApp)
+ {
+ case (KAPI):
+ includeInRingSync = temp->getIncludeInRingSyncAB();
+ break;
+ case (KOPI):
+ includeInRingSync = temp->getIncludeInRingSync();
+ break;
+ case (PWMPI):
+ includeInRingSync = temp->getIncludeInRingSyncPWM();
+ break;
+ default:
+ qDebug("KSyncManager::ringSync: invalid apptype selected");
+ break;
+
+ }
+
+
+ if ( includeInRingSync && ( i < 1 || i > 2 )) {
mParent->setCaption(i18n("Profile ")+syncProfileNames[mCurrentSyncProfile]+ i18n(" is synced ... "));
@@ -302,4 +370,20 @@ int KSyncManager::ringSync()
if ( temp->getIsLocalFileSync() ) {
- if ( syncWithFile( temp->getRemoteFileNameAB( ), true ) )
- mPrefs->mLastSyncedLocalFile = temp->getRemoteFileNameAB();
+ switch(mTargetApp)
+ {
+ case (KAPI):
+ if ( syncWithFile( temp->getRemoteFileNameAB( ), false ) )
+ mPrefs->mLastSyncedLocalFile = temp->getRemoteFileNameAB();
+ break;
+ case (KOPI):
+ if ( syncWithFile( temp->getRemoteFileName( ), false ) )
+ mPrefs->mLastSyncedLocalFile = temp->getRemoteFileName();
+ break;
+ case (PWMPI):
+ if ( syncWithFile( temp->getRemoteFileNamePWM( ), false ) )
+ mPrefs->mLastSyncedLocalFile = temp->getRemoteFileNamePWM();
+ break;
+ default:
+ qDebug("KSyncManager::slotSyncMenu: invalid apptype selected");
+ break;
+ }
} else {
@@ -342,7 +426,34 @@ void KSyncManager::syncRemote( KSyncProfile* prof, bool ask)
}
- QString command = prof->getPreSyncCommandAB();
+
+ QString preCommand;
+ QString localTempFile;
+ QString postCommand;
+
+ switch(mTargetApp)
+ {
+ case (KAPI):
+ preCommand = prof->getPreSyncCommandAB();
+ postCommand = prof->getPostSyncCommandAB();
+ localTempFile = prof->getLocalTempFileAB();
+ break;
+ case (KOPI):
+ preCommand = prof->getPreSyncCommand();
+ postCommand = prof->getPostSyncCommand();
+ localTempFile = prof->getLocalTempFile();
+ break;
+ case (PWMPI):
+ preCommand = prof->getPreSyncCommandPWM();
+ postCommand = prof->getPostSyncCommandPWM();
+ localTempFile = prof->getLocalTempFilePWM();
+ break;
+ default:
+ qDebug("KSyncManager::syncRemote: invalid apptype selected");
+ break;
+ }
+
+
int fi;
- if ( (fi = command.find("$PWD$")) > 0 ) {
+ if ( (fi = preCommand.find("$PWD$")) > 0 ) {
QString pwd = getPassword();
- command = command.left( fi )+ pwd + command.mid( fi+5 );
+ preCommand = preCommand.left( fi )+ pwd + preCommand.mid( fi+5 );
@@ -354,3 +465,3 @@ void KSyncManager::syncRemote( KSyncProfile* prof, bool ask)
int fileSize = 0;
- int result = system ( command );
+ int result = system ( preCommand );
// 0 : okay
@@ -361,7 +472,7 @@ void KSyncManager::syncRemote( KSyncProfile* prof, bool ask)
unsigned int len = maxlen;
- while ( len < command.length() ) {
- command.insert( len , "\n" );
+ while ( len < preCommand.length() ) {
+ preCommand.insert( len , "\n" );
len += maxlen +2;
}
- 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) ;
+ 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) ;
QMessageBox::information( mParent, i18n("Sync - ERROR"),
@@ -374,3 +485,6 @@ void KSyncManager::syncRemote( KSyncProfile* prof, bool ask)
//qDebug(" file **%s** ",prof->getLocalTempFile().latin1() );
- if ( syncWithFile( prof->getLocalTempFileAB(), true ) ) {
+
+
+
+ if ( syncWithFile( localTempFile, true ) ) {
// Event* e = mView->getLastSyncEvent();
@@ -380,7 +494,6 @@ void KSyncManager::syncRemote( KSyncProfile* prof, bool ask)
if ( mPrefs->mWriteBackFile ) {
- command = prof->getPostSyncCommandAB();
int fi;
- if ( (fi = command.find("$PWD$")) > 0 ) {
+ if ( (fi = postCommand.find("$PWD$")) > 0 ) {
QString pwd = getPassword();
- command = command.left( fi )+ pwd + command.mid( fi+5 );
+ postCommand = postCommand.left( fi )+ pwd + postCommand.mid( fi+5 );
@@ -388,3 +501,3 @@ void KSyncManager::syncRemote( KSyncProfile* prof, bool ask)
mParent->setCaption ( i18n( "Writing back file ..." ) );
- result = system ( command );
+ result = system ( postCommand );
qDebug("Writing back file result: %d ", result);
@@ -529 +642,24 @@ void KSyncManager::syncPhone()
}
+
+void KSyncManager::showProgressBar(int percentage, QString caption, int total)
+{
+ if (!bar->isVisible())
+ {
+ bar->setCaption (caption);
+ bar->setTotalSteps ( total ) ;
+
+ bar->show();
+ }
+
+ bar->setProgress( percentage );
+}
+
+void KSyncManager::hideProgressBar()
+{
+ bar->hide();
+}
+
+bool KSyncManager::isProgressBarCanceled()
+{
+ return !bar->isVisible();
+}
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;
class KSyncInterface;
+class QProgressBar;
@@ -56,2 +57,7 @@ class KSyncManager : public QObject
+ void showProgressBar(int percentage, QString caption = QString::null, int total=100);
+ void hideProgressBar();
+ bool isProgressBarCanceled();
+
+
public slots:
@@ -91,3 +97,3 @@ class KSyncManager : public QObject
-
+ QProgressBar* bar;
@@ -104,4 +110,8 @@ class KSyncInterface
virtual bool sync(KSyncManager* manager, QString filename, int mode) = 0;
- virtual bool syncExternal(KSyncManager* manager, QString resource) = 0;
+ virtual bool syncExternal(KSyncManager* manager, QString resource)
+ {
+ // empty implementation, because some syncable applications do not have an external(sharpdtm) syncmode, like pwmanager.
+ return false;
+ }
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)
{
- return true;
-}
+ PWM_ASSERT(curDoc());
-bool PwM::syncExternal(KSyncManager* manager, QString resource)
-{
- return true;
+ bool ret = curDoc()->sync(manager, filename, mode);
+
+ if (ret == true) {
+ //US BUG: what can we call here to update the view of the current doc?
+ //mViewManager->refreshView();
+ }
+
+ return ret;
}
-//called by the syncmanager to indicate that the work has to marked as dirty.
+//called by the syncmanager to indicate that the work has to be marked as dirty.
void PwM::sync_setModified()
{
+ PWM_ASSERT(curDoc());
+ curDoc()->sync_setModified();
}
@@ -1340,2 +1346,4 @@ bool PwM::sync_isModified()
{
+ PWM_ASSERT(curDoc());
+ return curDoc()->sync_isModified();
}
@@ -1345,2 +1353,4 @@ void PwM::sync_save()
{
+ PWM_ASSERT(curDoc());
+ return curDoc()->sync_save();
}
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:
virtual bool sync(KSyncManager* manager, QString filename, int mode);
- virtual bool syncExternal(KSyncManager* manager, QString resource);
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:
+
+
+#ifdef PWM_EMBEDDED
+//US ENH: this is the magic function that syncronizes the this doc with the remote doc
+PwMerror PwMDoc::syncronize(KSyncManager* manager, PwMDoc* syncLocal , PwMDoc* syncRemote, int mode )
+{
+ bool syncOK = true;
+ int addedPasswordsLocal = 0;
+ int addedPasswordsRemote = 0;
+ int deletedPasswordsRemote = 0;
+ int deletedPasswordsLocal = 0;
+ int changedLocal = 0;
+ int changedRemote = 0;
+
+ QString mCurrentSyncName = manager->getCurrentSyncName();
+ QString mCurrentSyncDevice = manager->getCurrentSyncDevice();
+
+
+
+
+
+
+
+
+
+ return e_success;
+}
+
+
+
+//this are the overwritten callbackmethods from the syncinterface
+bool PwMDoc::sync(KSyncManager* manager, QString filename, int mode)
+{
+ QString mCurrentSyncDevice = manager->getCurrentSyncDevice();
+
+ // construct on the stack = automatic cleanup.
+ PwMDoc syncTarget(this, "synctarget");
+
+ PwMerror err = syncTarget.openDoc(&filename, 2 /*== deeplocked*/);
+
+ if (err != e_success)
+ return false;
+
+ qDebug("PWM file loaded %s,sync mode %d",filename.latin1(), mode );
+
+
+ err = syncronize(manager, this, &syncTarget, mode );
+
+ if (err == e_success) {
+ if ( PWMPrefs::instance()->mWriteBackFile ) {
+ qDebug("Saving remote PWManager file");
+ err = syncTarget.saveDoc(conf()->confGlobCompression());
+ if (err != e_success)
+ return false;
+
+ }
+
+ flagDirty();
+ return true;
+ }
+ else {
+ return false;
+ }
+}
+
+//called by the syncmanager to indicate that the work has to marked as dirty.
+void PwMDoc::sync_setModified()
+{
+ flagDirty();
+}
+
+//called by the syncmanager to ask if the dirty flag is set.
+bool PwMDoc::sync_isModified()
+{
+ return isDirty();
+}
+
+//called by the syncmanager to indicate that the work has to be saved.
+void PwMDoc::sync_save()
+{
+ PwMerror ret = saveDoc(conf()->confGlobCompression());
+}
+
+#endif
+
+
+
+
+
+
+
+
#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 @@
#include <kapplication.h>
+#include <ksyncmanager.h>
#endif
@@ -337,3 +338,6 @@ protected:
/** Document class for PwM */
-class PwMDoc : public PwMDocUi
+//US ENH: derived from KSyncInterfaces, to get called by PwM when a sync is required.
+// But PwMDoc is handling the sync by itself.
+class PwMDoc : public PwMDocUi, public KSyncInterface
+
{
@@ -698,2 +702,21 @@ protected:
bool copyFile(const QString &src, const QString &dst);
+
+
+ public:
+#ifdef PWM_EMBEDDED
+ //US ENH: this is the magic function that syncronizes the local doc with the remote doc.
+ PwMerror syncronize(KSyncManager* manager, PwMDoc* syncLocal, PwMDoc* syncRemote, int mode );
+
+
+ //the following methods are the overwritten callbackmethods from the syncinterface
+ virtual bool sync(KSyncManager* manager, QString filename, int mode);
+
+ //called by the syncmanager to indicate that the work has to be marked as dirty.
+ virtual void sync_setModified();
+ //called by the syncmanager to ask if the dirty flag is set.
+ virtual bool sync_isModified();
+ //called by the syncmanager to indicate that the work has to be saved.
+ virtual void sync_save();
+#endif
+
};