summaryrefslogtreecommitdiffabout
path: root/libkdepim
Side-by-side diff
Diffstat (limited to 'libkdepim') (more/less context) (ignore whitespace changes)
-rw-r--r--libkdepim/ksyncmanager.cpp186
-rw-r--r--libkdepim/ksyncmanager.h14
2 files changed, 173 insertions, 27 deletions
diff --git a/libkdepim/ksyncmanager.cpp b/libkdepim/ksyncmanager.cpp
index 87f200a..07e6761 100644
--- a/libkdepim/ksyncmanager.cpp
+++ b/libkdepim/ksyncmanager.cpp
@@ -34,6 +34,7 @@
#include "kpimprefs.h"
#include <qdir.h>
+#include <qprogressbar.h>
#include <qpopupmenu.h>
#include <qpushbutton.h>
#include <qradiobutton.h>
@@ -53,12 +54,22 @@
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;
}
@@ -78,8 +89,8 @@ void KSyncManager::fillSyncMenu()
mPrefs->mLocalMachineName = config.readEntry("LocalMachineName","undefined");
if ( prof.count() < 3 ) {
prof.clear();
- prof << i18n("Sharp_DTM");
- prof << i18n("Local_file");
+ prof << i18n("Sharp_DTM");
+ prof << i18n("Local_file");
prof << i18n("Last_file");
KSyncProfile* temp = new KSyncProfile ();
temp->setName( prof[0] );
@@ -98,14 +109,17 @@ void KSyncManager::fillSyncMenu()
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();
@@ -161,9 +175,25 @@ void KSyncManager::slotSyncMenu( int action )
} else if ( action >= 1003 ) {
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 {
if ( temp->getIsPhoneSync() ) {
mPrefs->mPhoneDevice = temp->getPhoneDevice( ) ;
@@ -183,8 +213,26 @@ 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 == "" )
return;
if ( syncWithFile( fn, false ) ) {
@@ -284,7 +332,27 @@ int KSyncManager::ringSync()
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();
@@ -300,8 +368,24 @@ int KSyncManager::ringSync()
syncSharp();
} else {
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 {
if ( temp->getIsPhoneSync() ) {
mPrefs->mPhoneDevice = temp->getPhoneDevice( ) ;
@@ -340,11 +424,38 @@ void KSyncManager::syncRemote( KSyncProfile* prof, bool ask)
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;
@@ -352,18 +463,18 @@ void KSyncManager::syncRemote( KSyncProfile* prof, bool ask)
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!")) ;
@@ -372,21 +483,23 @@ void KSyncManager::syncRemote( KSyncProfile* prof, bool ask)
}
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 ) );
@@ -527,3 +640,26 @@ void KSyncManager::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
@@ -31,6 +31,7 @@ class KPimPrefs;
class QWidget;
class KSyncManager;
class KSyncInterface;
+class QProgressBar;
class KSyncManager : public QObject
{
@@ -54,6 +55,11 @@ class KSyncManager : public QObject
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 );
@@ -89,7 +95,7 @@ class KSyncManager : public QObject
KPimPrefs* mPrefs;
QPopupMenu* mSyncMenu;
-
+ QProgressBar* bar;
@@ -102,8 +108,12 @@ 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;