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) (show whitespace changes)
-rw-r--r--kaddressbook/kabcore.cpp33
-rw-r--r--libkdepim/ksyncmanager.cpp174
-rw-r--r--libkdepim/ksyncmanager.h14
-rw-r--r--pwmanager/pwmanager/pwm.cpp20
-rw-r--r--pwmanager/pwmanager/pwm.h1
-rw-r--r--pwmanager/pwmanager/pwmdoc.cpp92
-rw-r--r--pwmanager/pwmanager/pwmdoc.h25
7 files changed, 311 insertions, 48 deletions
diff --git a/kaddressbook/kabcore.cpp b/kaddressbook/kabcore.cpp
index f222234..f8359de 100644
--- a/kaddressbook/kabcore.cpp
+++ b/kaddressbook/kabcore.cpp
@@ -1069,27 +1069,28 @@ void KABCore::executeContact( const QString &uid /*US = QString::null*/ )
else
{
setDetailsVisible( true );
mActionDetails->setChecked(true);
}
}
void KABCore::save()
{
if (syncManager->blockSave())
return;
- syncManager->setBlockSave(true);
if ( !mModified )
return;
+
+ syncManager->setBlockSave(true);
QString text = i18n( "There was an error while attempting to save\n the "
"address book. Please check that some \nother application is "
"not using it. " );
statusMessage(i18n("Saving addressbook ... "));
#ifndef KAB_EMBEDDED
KABC::StdAddressBook *b = dynamic_cast<KABC::StdAddressBook*>( mAddressBook );
if ( !b || !b->save() ) {
KMessageBox::error( this, text, i18n( "Unable to Save" ) );
}
#else //KAB_EMBEDDED
KABC::StdAddressBook *b = (KABC::StdAddressBook*)( mAddressBook );
if ( !b || !b->save() ) {
@@ -2325,42 +2326,35 @@ bool KABCore::synchronizeAddressbooks( KABC::AddressBook* local, KABC::AddressBo
#if 0
if ( mCurrentSyncDevice == "deleteaftersync" ) {
mLastAddressbookSync = loadedFileVersion;
qDebug("setting mLastAddressbookSync ");
}
#endif
//qDebug("*************************** ");
// qDebug("mLastAddressbookSync %s ",mLastAddressbookSync.toString().latin1() );
QStringList er = remote->uidList();
Addressee inR ;//= er.first();
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;
int incCounter = 0;
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 ];
bool skipIncidence = false;
if ( uid.left(19) == QString("last-syncAddressee-") )
skipIncidence = true;
QString idS,OidS;
qApp->processEvents();
if ( !skipIncidence ) {
inL = local->findByUid( uid );
inR = remote->findByUid( uid );
//inL.setResource( 0 );
//inR.setResource( 0 );
if ( !inL.isEmpty() ) { // maybe conflict - same uid in both calendars
@@ -2434,34 +2428,33 @@ bool KABCore::synchronizeAddressbooks( KABC::AddressBook* local, KABC::AddressBo
// pending checkExternSyncAddressee(addresseeRSyncSharp, inR);
remote->removeAddressee( inR );
++deletedAddresseeR;
}
}
}
}
++incCounter;
}
er.clear();
QStringList el = local->uidList();
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;
while ( incCounter < el.count()) {
qApp->processEvents();
- if ( ! bar.isVisible() )
+ if (syncManager->isProgressBarCanceled())
return false;
if ( incCounter % modulo == 0 )
- bar.setProgress( incCounter );
+ syncManager->showProgressBar(incCounter);
uid = el[ incCounter ];
bool skipIncidence = false;
if ( uid.left(19) == QString("last-syncAddressee-") )
skipIncidence = true;
if ( !skipIncidence ) {
inL = local->findByUid( uid );
inR = remote->findByUid( uid );
if ( inR.isEmpty() ) {
if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
if ( !inL.getID(mCurrentSyncDevice).isEmpty() && mode != 4 ) {
// pending checkExternSyncAddressee(addresseeLSyncSharp, inL);
local->removeAddressee( inL );
@@ -2490,25 +2483,25 @@ bool KABCore::synchronizeAddressbooks( KABC::AddressBook* local, KABC::AddressBo
local->insertAddressee( inL, false );
inR = inL;
inR.setResource( 0 );
remote->insertAddressee( inR, false );
}
}
}
}
}
++incCounter;
}
el.clear();
- bar.hide();
+ syncManager->hideProgressBar();
mLastAddressbookSync = QDateTime::currentDateTime().addSecs( 1 );
// get rid of micro seconds
QTime t = mLastAddressbookSync.time();
mLastAddressbookSync.setTime( QTime (t.hour (), t.minute (), t.second () ) );
addresseeLSync.setRevision( mLastAddressbookSync );
addresseeRSync.setRevision( mLastAddressbookSync );
addresseeRSync.setRole( i18n("!Remote from: ")+mCurrentSyncName ) ;
addresseeLSync.setRole(i18n("!Local from: ") + mCurrentSyncName );
addresseeRSync.setGivenName( i18n("!DO NOT EDIT!") ) ;
addresseeLSync.setGivenName(i18n("!DO NOT EDIT!") );
addresseeRSync.setOrganization( "!"+mLastAddressbookSync.toString() ) ;
addresseeLSync.setOrganization("!"+ mLastAddressbookSync.toString() );
diff --git a/libkdepim/ksyncmanager.cpp b/libkdepim/ksyncmanager.cpp
index 87f200a..07e6761 100644
--- a/libkdepim/ksyncmanager.cpp
+++ b/libkdepim/ksyncmanager.cpp
@@ -25,49 +25,60 @@
#include <stdlib.h>
#ifndef _WIN32_
#include <unistd.h>
#endif
#include "ksyncprofile.h"
#include "ksyncprefsdialog.h"
#include "kpimprefs.h"
#include <qdir.h>
+#include <qprogressbar.h>
#include <qpopupmenu.h>
#include <qpushbutton.h>
#include <qradiobutton.h>
#include <qbuttongroup.h>
#include <qtimer.h>
#include <qmessagebox.h>
#include <qapplication.h>
#include <qlineedit.h>
#include <qdialog.h>
#include <qlayout.h>
#include <klocale.h>
#include <kglobal.h>
#include <kconfig.h>
#include <kfiledialog.h>
KSyncManager::KSyncManager(QWidget* parent, KSyncInterface* implementation, TargetApp ta, KPimPrefs* prefs, QPopupMenu* syncmenu)
: QObject(), mParent(parent), mImplementation(implementation), mTargetApp(ta), mPrefs(prefs), mSyncMenu(syncmenu)
{
+ 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 );
}
KSyncManager::~KSyncManager()
{
-
+ delete bar;
}
void KSyncManager::fillSyncMenu()
{
if ( mSyncMenu->count() )
mSyncMenu->clear();
mSyncMenu->insertItem( i18n("Configure..."), 0 );
mSyncMenu->insertSeparator();
mSyncMenu->insertItem( i18n("Multiple sync"), 1 );
mSyncMenu->insertSeparator();
@@ -89,32 +100,35 @@ void KSyncManager::fillSyncMenu()
temp->setName( prof[2] );
temp->writeConfig(&config);
config.setGroup("General");
config.writeEntry("SyncProfileNames",prof);
config.writeEntry("ExternSyncProfiles","Sharp_DTM");
config.sync();
delete temp;
}
mPrefs->mExternSyncProfiles = config.readListEntry("ExternSyncProfiles");
mPrefs->mSyncProfileNames = prof;
unsigned int i;
for ( i = 0; i < prof.count(); ++i ) {
-
mSyncMenu->insertItem( prof[i], 1000+i );
if ( i == 2 )
mSyncMenu->insertSeparator();
}
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 );
}
//probaly useless
//mView->setupExternSyncProfiles();
}
void KSyncManager::slotSyncMenu( int action )
{
//qDebug("syncaction %d ", action);
if ( action == 0 ) {
// seems to be a Qt2 event handling bug
// syncmenu.clear causes a segfault at first time
@@ -152,48 +166,82 @@ void KSyncManager::slotSyncMenu( int action )
mPrefs->mShowSyncSummary = temp->getShowSummaryAfterSync();
if ( action == 1000 ) {
syncSharp();
} else if ( action == 1001 ) {
syncLocalFile();
} else if ( action == 1002 ) {
quickSyncLocalFile();
} else if ( action >= 1003 ) {
if ( temp->getIsLocalFileSync() ) {
+ 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 {
if ( temp->getIsPhoneSync() ) {
mPrefs->mPhoneDevice = temp->getPhoneDevice( ) ;
mPrefs->mPhoneConnection = temp->getPhoneConnection( );
mPrefs->mPhoneModel = temp->getPhoneModel( );
syncPhone();
} else
syncRemote( temp );
}
}
delete temp;
setBlockSave(false);
}
void KSyncManager::syncLocalFile()
{
QString fn =mPrefs->mLastSyncedLocalFile;
+ QString ext;
- fn =KFileDialog:: getOpenFileName( fn, i18n("Sync filename(*.ics/*.vcs)"), mParent );
+ 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 == "" )
return;
if ( syncWithFile( fn, false ) ) {
qDebug("syncLocalFile() successful ");
}
}
bool KSyncManager::syncWithFile( QString fn , bool quick )
{
bool ret = false;
QFileInfo info;
info.setFile( fn );
@@ -275,42 +323,78 @@ int KSyncManager::ringSync()
{
int syncedProfiles = 0;
unsigned int i;
QTime timer;
KConfig config ( locateLocal( "config","ksyncprofilesrc" ) );
QStringList syncProfileNames = mPrefs->mSyncProfileNames;
KSyncProfile* temp = new KSyncProfile ();
mPrefs->mAskForPreferences = false;
for ( i = 0; i < syncProfileNames.count(); ++i ) {
mCurrentSyncProfile = i;
temp->setName(syncProfileNames[mCurrentSyncProfile]);
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 ... "));
++syncedProfiles;
// mPrefs->mAskForPreferences = temp->getAskForPreferences();
mPrefs->mWriteBackFile = temp->getWriteBackFile();
mPrefs->mWriteBackExistingOnly = temp->getWriteBackExisting();
mPrefs->mWriteBackInFuture = 0;
if ( temp->getWriteBackFuture() )
mPrefs->mWriteBackInFuture = temp->getWriteBackFutureWeeks( );
mPrefs->mShowSyncSummary = false;
mCurrentSyncDevice = syncProfileNames[i] ;
mCurrentSyncName = mPrefs->mLocalMachineName;
if ( i == 0 ) {
syncSharp();
} else {
if ( temp->getIsLocalFileSync() ) {
- if ( syncWithFile( temp->getRemoteFileNameAB( ), true ) )
+ 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 {
if ( temp->getIsPhoneSync() ) {
mPrefs->mPhoneDevice = temp->getPhoneDevice( ) ;
mPrefs->mPhoneConnection = temp->getPhoneConnection( );
mPrefs->mPhoneModel = temp->getPhoneModel( );
syncPhone();
} else
syncRemote( temp, false );
}
}
timer.start();
@@ -331,71 +415,100 @@ int KSyncManager::ringSync()
void KSyncManager::syncRemote( KSyncProfile* prof, bool ask)
{
QString question;
if ( ask ) {
question = i18n("Do you really want\nto remote sync\nwith profile \n")+ prof->getName()+" ?\n";
if ( QMessageBox::information( mParent, i18n("Sync"),
question,
i18n("Yes"), i18n("No"),
0, 0 ) != 0 )
return;
}
- 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 );
}
int maxlen = 30;
if ( QApplication::desktop()->width() > 320 )
maxlen += 25;
mParent->setCaption ( i18n( "Copy remote file to local machine..." ) );
int fileSize = 0;
- int result = system ( command );
+ int result = system ( preCommand );
// 0 : okay
// 256: no such file or dir
//
qDebug("KO: Remote copy result(0 = okay): %d ",result );
if ( result != 0 ) {
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"),
question,
i18n("Okay!")) ;
mParent->setCaption ("");
return;
}
mParent->setCaption ( i18n( "Copying succeed." ) );
//qDebug(" file **%s** ",prof->getLocalTempFile().latin1() );
- if ( syncWithFile( prof->getLocalTempFileAB(), true ) ) {
+
+
+
+ if ( syncWithFile( localTempFile, true ) ) {
// Event* e = mView->getLastSyncEvent();
// e->setReadOnly( false );
// e->setLocation( KOPrefs::instance()->mSyncProfileNames[mCurrentSyncProfile]);
// e->setReadOnly( true );
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 );
}
mParent->setCaption ( i18n( "Writing back file ..." ) );
- result = system ( command );
+ result = system ( postCommand );
qDebug("Writing back file result: %d ", result);
if ( result != 0 ) {
mParent->setCaption ( i18n( "Writing back file result: " )+QString::number( result ) );
return;
} else {
mParent->setCaption ( i18n( "Syncronization sucessfully completed" ) );
}
}
}
return;
}
@@ -518,12 +631,35 @@ bool KSyncManager::syncExternalApplication(QString resource)
}
void KSyncManager::syncPhone()
{
if ( mImplementation->sync_isModified() )
mImplementation->sync_save();
qDebug("pending syncPhone(); ");
//mView->syncPhone();
mImplementation->sync_setModified();
}
+
+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
@@ -22,47 +22,53 @@ $Id$
#ifndef _KSYNCMANAGER_H
#define _KSYNCMANAGER_H
#include <qobject.h>
#include <qstring.h>
class QPopupMenu;
class KSyncProfile;
class KPimPrefs;
class QWidget;
class KSyncManager;
class KSyncInterface;
+class QProgressBar;
class KSyncManager : public QObject
{
Q_OBJECT
public:
enum TargetApp {
KOPI = 0,
KAPI = 1,
PWMPI = 2 };
KSyncManager(QWidget* parent, KSyncInterface* implementation, TargetApp ta, KPimPrefs* prefs, QPopupMenu* syncmenu);
~KSyncManager() ;
bool blockSave() { return mBlockSaveFlag; }
void setBlockSave(bool sa) { mBlockSaveFlag = sa; }
void fillSyncMenu();
QString getCurrentSyncDevice() { return mCurrentSyncDevice; }
QString getCurrentSyncName() { return mCurrentSyncName; }
+ void showProgressBar(int percentage, QString caption = QString::null, int total=100);
+ void hideProgressBar();
+ bool isProgressBarCanceled();
+
+
public slots:
void slotSyncMenu( int );
private:
// LR *******************************
// sync stuff!
QString mCurrentSyncDevice;
QString mCurrentSyncName;
void quickSyncLocalFile();
bool syncWithFile( QString fn , bool quick );
void syncLocalFile();
void syncPhone();
@@ -80,39 +86,43 @@ class KSyncManager : public QObject
// *********************
private:
bool mBlockSaveFlag;
QWidget* mParent;
KSyncInterface* mImplementation;
TargetApp mTargetApp;
KPimPrefs* mPrefs;
QPopupMenu* mSyncMenu;
-
+ QProgressBar* bar;
};
class KSyncInterface
{
public:
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;
+ }
//called by the syncmanager to indicate that the work has to be marked as dirty.
virtual void sync_setModified() = 0;
//called by the syncmanager to ask if the dirty flag is set.
virtual bool sync_isModified() = 0;
//called by the syncmanager to indicate that the work has to be saved.
virtual void sync_save() = 0;
};
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
@@ -1313,43 +1313,53 @@ void PwM::createAboutData_slot()
"Olivier Sessink - gpasman@nl.linux.org\n"
"The libgcrypt developers -\nBlowfish and SHA1 algorithms\nftp://ftp.gnupg.org/gcrypt/alpha/libgcrypt/\n"
"Troy Engel - tengel@sonic.net\n"
"Wickey - wickey@gmx.at\n"
"Ian MacGregor - original documentation author.\n"
);
}
//this are the overwritten callbackmethods from the syncinterface
bool PwM::sync(KSyncManager* manager, QString filename, int mode)
{
- return true;
+ PWM_ASSERT(curDoc());
+
+ 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();
}
-bool PwM::syncExternal(KSyncManager* manager, QString resource)
-{
- return true;
+ 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();
}
//called by the syncmanager to ask if the dirty flag is set.
bool PwM::sync_isModified()
{
+ PWM_ASSERT(curDoc());
+ return curDoc()->sync_isModified();
}
//called by the syncmanager to indicate that the work has to be saved.
void PwM::sync_save()
{
+ PWM_ASSERT(curDoc());
+ return curDoc()->sync_save();
}
#endif
#ifndef PWM_EMBEDDED
#include "pwm.moc"
#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
@@ -262,25 +262,24 @@ protected:
/** force quit this window? */
bool forceQuit;
/** force minimize this window to the tray */
bool forceMinimizeToTray;
private:
#ifdef PWM_EMBEDDED
//this are the overwritten callbackmethods from the syncinterface
virtual bool sync(KSyncManager* manager, QString filename, int mode);
- virtual bool syncExternal(KSyncManager* manager, QString resource);
//called by the syncmanager to indicate that the work has to 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();
// LR *******************************
// sync stuff!
QPopupMenu *syncPopup;
KSyncManager* syncManager;
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
@@ -2772,15 +2772,107 @@ bool PwMDoc::tryDelete()
} else { // cancel operation
goto out_ignore;
}
}
out_accept:
deleted = true;
delete this;
return true;
out_ignore:
return false;
}
+
+
+#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
#include "pwmdoc.moc"
#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
@@ -50,24 +50,25 @@
#include "pwmdocui.h"
#include <qobject.h>
#include <qtimer.h>
#include <qdatetime.h>
#include <kprocess.h>
#ifndef PWM_EMBEDDED
#include "configuration.h"
#else
#include <kapplication.h>
+#include <ksyncmanager.h>
#endif
#include <string>
#include <vector>
#include <utility>
using std::vector;
using std::string;
using std::pair;
/* used in findEntry() function */
#define SEARCH_IN_DESC (1)
@@ -326,25 +327,28 @@ protected:
QTimer *autoLockTimer;
/** timer object for the metaCheck timer */
QTimer *metaCheckTimer;
/** lock counter for the mpw timer */
unsigned int mpwLock;
/** lock counter for the autoLock timer */
unsigned int autoLockLock;
/** lock counter for the metaCheck timer */
unsigned int metaCheckLock;
};
/** 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
+
{
Q_OBJECT
friend class DocTimer;
public:
/** construtor */
PwMDoc(QObject* parent = 0, const char *name = 0);
/** destructor */
~PwMDoc();
/** returns a pointer to a list of all open documents */
static PwMDocList* getOpenDocList()
@@ -687,15 +691,34 @@ protected:
bool getDocStatFlag(unsigned int statFlag) const
{ return (curDocStat & statFlag); }
/** set the "currentPassword" */
void setCurrentPw(const QString &pw)
{
currentPw = pw;
setDocStatFlag(DOC_STAT_DISK_DIRTY);
}
/** make a backup-copy of the given file */
bool backupFile(const QString &filePath);
/** copy a file from src to dst */
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
+
};
#endif