summaryrefslogtreecommitdiffabout
path: root/libkdepim
Side-by-side diff
Diffstat (limited to 'libkdepim') (more/less context) (show whitespace changes)
-rw-r--r--libkdepim/ksyncmanager.cpp40
-rw-r--r--libkdepim/ksyncmanager.h1
2 files changed, 40 insertions, 1 deletions
diff --git a/libkdepim/ksyncmanager.cpp b/libkdepim/ksyncmanager.cpp
index 4390a06..feb184b 100644
--- a/libkdepim/ksyncmanager.cpp
+++ b/libkdepim/ksyncmanager.cpp
@@ -42,161 +42,193 @@
#include <qbuttongroup.h>
#include <qtimer.h>
#include <qmessagebox.h>
#include <qapplication.h>
#include <qlineedit.h>
#include <qdialog.h>
#include <qlayout.h>
#include <qtextcodec.h>
#include <qlabel.h>
#include <qcheckbox.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)
{
mServerSocket = 0;
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 );
if ( mPrefs->mPassiveSyncAutoStart )
enableQuick( false );
}
KSyncManager::~KSyncManager()
{
delete bar;
}
void KSyncManager::fillSyncMenu()
{
if ( mSyncMenu->count() )
mSyncMenu->clear();
mSyncMenu->insertItem( i18n("Configure..."), 0 );
mSyncMenu->insertSeparator();
+ QPopupMenu *clearMenu = new QPopupMenu ( mSyncMenu );
+ mSyncMenu->insertItem( i18n("Remove sync info"),clearMenu, 5000 );
+ clearMenu->insertItem( i18n("For all profiles"), 1 );
+ clearMenu->insertSeparator();
+ connect ( clearMenu, SIGNAL( activated ( int ) ), this, SLOT (slotClearMenu( int ) ) );
+ mSyncMenu->insertSeparator();
if ( mServerSocket == 0 ) {
mSyncMenu->insertItem( i18n("Enable Pi-Sync"), 2 );
} else {
mSyncMenu->insertItem( i18n("Disable Pi-Sync"), 3 );
}
mSyncMenu->insertSeparator();
mSyncMenu->insertItem( i18n("Multiple sync"), 1 );
mSyncMenu->insertSeparator();
-
KConfig config ( locateLocal( "config","ksyncprofilesrc" ) );
config.setGroup("General");
QStringList prof = config.readListEntry("SyncProfileNames");
mLocalMachineName = config.readEntry("LocalMachineName","undefined");
if ( prof.count() < 2 ) {
prof.clear();
QString externalName;
#ifdef DESKTOP_VERSION
#ifdef _WIN32_
externalName = "OutLook(not_implemented)";
#else
externalName = "KDE_Desktop";
#endif
#else
externalName = "Sharp_DTM";
#endif
prof << externalName;
prof << i18n("Local_file");
prof << i18n("Last_file");
KSyncProfile* temp = new KSyncProfile ();
temp->setName( prof[0] );
temp->writeConfig(&config);
temp->setName( prof[1] );
temp->writeConfig(&config);
temp->setName( prof[2] );
temp->writeConfig(&config);
config.setGroup("General");
config.writeEntry("SyncProfileNames",prof);
config.writeEntry("ExternSyncProfiles",externalName);
config.sync();
delete temp;
}
mExternSyncProfiles = config.readListEntry("ExternSyncProfiles");
mSyncProfileNames = prof;
unsigned int i;
for ( i = 0; i < prof.count(); ++i ) {
mSyncMenu->insertItem( prof[i], 1000+i );
+ clearMenu->insertItem( prof[i], 1000+i );
if ( i == 2 )
mSyncMenu->insertSeparator();
}
QDir app_dir;
//US do not display SharpDTM if app is pwmpi, or no sharpfiles available
if ( mTargetApp == PWMPI) {
mSyncMenu->removeItem( 1000 );
+ clearMenu->removeItem( 1000 );
}
#ifndef DESKTOP_VERSION
else if (!app_dir.exists(QDir::homeDirPath()+"/Applications/dtm" ) ) {
mSyncMenu->removeItem( 1000 );
+ clearMenu->removeItem( 1000 );
}
#endif
mSyncMenu->removeItem( 1002 );
+ clearMenu->removeItem( 1002 );
+}
+void KSyncManager::slotClearMenu( int action )
+{
+ QString syncDevice;
+ if ( action > 999 ) {
+ syncDevice = mSyncProfileNames[action - 1000] ;
}
+
+
+ int result = 0;
+ QString sd;
+ if ( syncDevice.isEmpty() )
+ sd = i18n("Do you want to\nclear all sync info\nof all profiles?");
+ else
+ sd = i18n("Do you want to\nclear the sync\ninfo of profile\n%1?\n"). arg( syncDevice );
+
+ result = QMessageBox::warning( mParent, i18n("Warning!"),sd,i18n("OK"), i18n("Cancel"), 0,
+ 0, 1 );
+ if ( result )
+ return;
+ mImplementation->removeSyncInfo( syncDevice );
+}
void KSyncManager::slotSyncMenu( int action )
{
qDebug("syncaction %d ", action);
+ if ( action == 5000 )
+ return;
if ( action == 0 ) {
// seems to be a Qt2 event handling bug
// syncmenu.clear causes a segfault at first time
// when we call it after the main event loop, it is ok
// same behaviour when calling OM/Pi via QCOP for the first time
QTimer::singleShot ( 1, this, SLOT ( confSync() ) );
//confSync();
return;
}
if ( action == 1 ) {
multiSync( true );
return;
}
if ( action == 2 ) {
enableQuick();
QTimer::singleShot ( 1, this, SLOT ( fillSyncMenu() ) );
return;
}
if ( action == 3 ) {
delete mServerSocket;
mServerSocket = 0;
QTimer::singleShot ( 1, this, SLOT ( fillSyncMenu() ) );
return;
}
if (blockSave())
return;
setBlockSave(true);
bool silent = false;
if ( action == 999 ) {
//special mode for silent syncing
action = 1000;
silent = true;
}
mCurrentSyncProfile = action - 1000 ;
mCurrentSyncDevice = mSyncProfileNames[mCurrentSyncProfile] ;
mCurrentSyncName = mLocalMachineName ;
KConfig config ( locateLocal( "config","ksyncprofilesrc" ) );
KSyncProfile* temp = new KSyncProfile ();
temp->setName(mSyncProfileNames[mCurrentSyncProfile]);
temp->readConfig(&config);
if (silent) {
mAskForPreferences = false;
mShowSyncSummary = false;
@@ -790,98 +822,104 @@ bool KSyncManager::edit_sync_options()
break;
}
if ( dia.exec() ) {
mSyncAlgoPrefs = rem.isChecked()*1+newest.isChecked()*2+ ask.isChecked()*3+ f_loc.isChecked()*4+ f_rem.isChecked()*5;//+ both.isChecked()*6 ;
return true;
}
return false;
}
QString KSyncManager::getPassword( )
{
QString retfile = "";
QDialog dia ( mParent, "input-dialog", true );
QLineEdit lab ( &dia );
lab.setEchoMode( QLineEdit::Password );
QVBoxLayout lay( &dia );
lay.setMargin(7);
lay.setSpacing(7);
lay.addWidget( &lab);
dia.setFixedSize( 230,50 );
dia.setCaption( i18n("Enter password") );
QPushButton pb ( "OK", &dia);
lay.addWidget( &pb );
connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) );
dia.show();
int res = dia.exec();
if ( res )
retfile = lab.text();
dia.hide();
qApp->processEvents();
return retfile;
}
void KSyncManager::confSync()
{
static KSyncPrefsDialog* sp = 0;
if ( ! sp ) {
sp = new KSyncPrefsDialog( mParent, "syncprefs", true );
}
sp->usrReadConfig();
#ifndef DESKTOP_VERSION
sp->showMaximized();
#else
sp->show();
#endif
sp->exec();
+ QStringList oldSyncProfileNames = mSyncProfileNames;
mSyncProfileNames = sp->getSyncProfileNames();
mLocalMachineName = sp->getLocalMachineName ();
+ int ii;
+ for ( ii = 0; ii < oldSyncProfileNames.count(); ++ii ) {
+ if ( ! mSyncProfileNames.contains( oldSyncProfileNames[ii] ) )
+ mImplementation->removeSyncInfo( oldSyncProfileNames[ii] );
+ }
QTimer::singleShot ( 1, this, SLOT ( fillSyncMenu() ) );
}
void KSyncManager::syncKDE()
{
emit save();
switch(mTargetApp)
{
case (KAPI):
break;
case (KOPI):
{
#ifdef DESKTOP_VERSION
QString command = qApp->applicationDirPath () + "/kdecaldump";
#else
QString command = "kdecaldump";
#endif
if ( ! QFile::exists ( command ) )
command = "kdecaldump";
QString fileName = QDir::homeDirPath ()+"/.kdecalendardump.ics";
system ( command.latin1());
if ( syncWithFile( fileName,true ) ) {
if ( mWriteBackFile ) {
command += " --read";
system ( command.latin1());
}
}
}
break;
case (PWMPI):
break;
default:
qDebug("KSyncManager::slotSyncMenu: invalid apptype selected");
break;
}
}
void KSyncManager::syncSharp()
{
if ( ! syncExternalApplication("sharp") )
qDebug("ERROR sync sharp ");
}
bool KSyncManager::syncExternalApplication(QString resource)
diff --git a/libkdepim/ksyncmanager.h b/libkdepim/ksyncmanager.h
index af4f1ab..aa32e28 100644
--- a/libkdepim/ksyncmanager.h
+++ b/libkdepim/ksyncmanager.h
@@ -109,96 +109,97 @@ class KSyncManager : public QObject
enum TargetApp {
KOPI = 0,
KAPI = 1,
PWMPI = 2 };
KSyncManager(QWidget* parent, KSyncInterface* implementation, TargetApp ta, KPimPrefs* prefs, QPopupMenu* syncmenu);
~KSyncManager() ;
void multiSync( bool askforPrefs );
bool blockSave() { return mBlockSaveFlag; }
void setBlockSave(bool sa) { mBlockSaveFlag = sa; }
void setDefaultFileName( QString s) { mDefFileName = s ;}
QString defaultFileName() { return mDefFileName ;}
QString syncFileName();
void enableQuick( bool ask = true);
QString getCurrentSyncDevice() { return mCurrentSyncDevice; }
QString getCurrentSyncName() { return mCurrentSyncName; }
void showProgressBar(int percentage, QString caption = QString::null, int total=100);
void hideProgressBar();
bool isProgressBarCanceled();
// sync stuff
QString mLocalMachineName;
QStringList mExternSyncProfiles;
QStringList mSyncProfileNames;
bool mAskForPreferences;
bool mShowSyncSummary;
bool mIsKapiFile;
bool mWriteBackExistingOnly;
int mSyncAlgoPrefs;
bool mWriteBackFile;
int mWriteBackInFuture;
QString mPhoneDevice;
QString mPhoneConnection;
QString mPhoneModel;
QString mPassWordPiSync;
QString mActiveSyncPort;
QString mActiveSyncIP ;
signals:
void save();
void request_file();
void getFile( bool );
public slots:
void slotSyncMenu( int );
+ void slotClearMenu( int action );
void deleteCommandSocket(KCommandSocket*s, int state);
void readFileFromSocket();
void fillSyncMenu();
private:
void syncPi();
KServerSocket * mServerSocket;
KPimPrefs* mPrefs;
QString mDefFileName;
QString mCurrentSyncDevice;
QString mCurrentSyncName;
void quickSyncLocalFile();
bool syncWithFile( QString fn , bool quick );
void syncLocalFile();
void syncPhone();
void syncSharp();
void syncKDE();
bool syncExternalApplication(QString);
int mCurrentSyncProfile ;
void syncRemote( KSyncProfile* prof, bool ask = true);
bool edit_sync_options();
bool edit_pisync_options();
int ringSync();
QString getPassword( );
bool mPisyncFinished;
bool mBlockSaveFlag;
QWidget* mParent;
KSyncInterface* mImplementation;
TargetApp mTargetApp;
QPopupMenu* mSyncMenu;
QProgressBar* bar;
private slots:
void confSync();
};
class KSyncInterface
{
public :
virtual void removeSyncInfo( QString syncProfile) = 0;
virtual bool sync(KSyncManager* manager, QString filename, int mode) = 0;
virtual bool syncExternal(KSyncManager* manager, QString resource)
{
// empty implementation, because some syncable applications do not
// have an external(sharpdtm) syncmode, like pwmanager.