author | zautrix <zautrix> | 2004-10-07 17:51:17 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2004-10-07 17:51:17 (UTC) |
commit | 1f1538e5707b59bfcff2014901f29a65589229e3 (patch) (side-by-side diff) | |
tree | 0d91a303524e6ac9f7c954f01a0e1d09d0e305e7 /libkdepim | |
parent | bb8293c794d82a57bc93af85ccd89b601356d577 (diff) | |
download | kdepimpi-1f1538e5707b59bfcff2014901f29a65589229e3.zip kdepimpi-1f1538e5707b59bfcff2014901f29a65589229e3.tar.gz kdepimpi-1f1538e5707b59bfcff2014901f29a65589229e3.tar.bz2 |
many cleanups
-rw-r--r-- | libkdepim/kpimprefs.cpp | 9 | ||||
-rw-r--r-- | libkdepim/kpimprefs.h | 3 | ||||
-rw-r--r-- | libkdepim/ksyncmanager.cpp | 72 | ||||
-rw-r--r-- | libkdepim/ksyncmanager.h | 3 |
4 files changed, 56 insertions, 31 deletions
diff --git a/libkdepim/kpimprefs.cpp b/libkdepim/kpimprefs.cpp index 0a2f5f1..c21ebaa 100644 --- a/libkdepim/kpimprefs.cpp +++ b/libkdepim/kpimprefs.cpp @@ -29,27 +29,34 @@ $Id$ */ #include <kglobal.h> #include <kconfig.h> #include <klocale.h> #include <kdebug.h> #include "kpimprefs.h" KPimPrefs::KPimPrefs( const QString &name ) : KPrefs( name ) { - config()->setGroup("General"); +#ifdef _WIN32_ + QString hdp= locateLocal("data","korganizer")+"\\\\"; +#else + QString hdp= locateLocal("data","korganizer")+"/"; +#endif + config()->setGroup("SyncOptions"); addItemString("PassiveSyncPort",&mPassiveSyncPort,"9197" ); addItemString("PassiveSyncPw",&mPassiveSyncPw,"abc" ); + addItemString("LastSyncedLocalFile", &mLastSyncedLocalFile ,hdp +"lastsync.ics" ); + addItemInt("RingSyncAlgoPrefs",&mRingSyncAlgoPrefs,3); } KPimPrefs::~KPimPrefs() { } void KPimPrefs::usrSetDefaults() { setCategoryDefaults(); } void KPimPrefs::usrReadConfig() diff --git a/libkdepim/kpimprefs.h b/libkdepim/kpimprefs.h index fde8093..9346f7d 100644 --- a/libkdepim/kpimprefs.h +++ b/libkdepim/kpimprefs.h @@ -48,23 +48,24 @@ class KPimPrefs : public KPrefs /** Read preferences from config file */ void usrReadConfig(); /** Write preferences to config file */ void usrWriteConfig(); public: QStringList mCustomCategories; QString mPassiveSyncPort; QString mPassiveSyncPw; - + int mRingSyncAlgoPrefs; + QString mLastSyncedLocalFile; protected: virtual void setCategoryDefaults(); }; #endif diff --git a/libkdepim/ksyncmanager.cpp b/libkdepim/ksyncmanager.cpp index fad9a76..568c2a9 100644 --- a/libkdepim/ksyncmanager.cpp +++ b/libkdepim/ksyncmanager.cpp @@ -67,76 +67,80 @@ KSyncManager::KSyncManager(QWidget* parent, KSyncInterface* implementation, Targ 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; } -//LR ok + void KSyncManager::fillSyncMenu() { if ( mSyncMenu->count() ) mSyncMenu->clear(); mSyncMenu->insertItem( i18n("Configure..."), 0 ); 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(); prof << i18n("Sharp_DTM"); 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","Sharp_DTM"); 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 ); 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 ); } else if (!app_dir.exists(QDir::homeDirPath()+"/Applications/dtm" ) ) { - mSyncMenu->setItemEnabled( 1000, false ); + mSyncMenu->removeItem( 1000 ); } + mSyncMenu->removeItem( 1002 ); } 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 // 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() ) ); @@ -186,33 +190,33 @@ void KSyncManager::slotSyncMenu( int action ) } 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 ) ) - mLastSyncedLocalFile = temp->getRemoteFileNameAB(); + mPrefs->mLastSyncedLocalFile = temp->getRemoteFileNameAB(); break; case (KOPI): if ( syncWithFile( temp->getRemoteFileName( ), false ) ) - mLastSyncedLocalFile = temp->getRemoteFileName(); + mPrefs->mLastSyncedLocalFile = temp->getRemoteFileName(); break; case (PWMPI): if ( syncWithFile( temp->getRemoteFileNamePWM( ), false ) ) - mLastSyncedLocalFile = temp->getRemoteFileNamePWM(); + mPrefs->mLastSyncedLocalFile = temp->getRemoteFileNamePWM(); break; default: qDebug("KSyncManager::slotSyncMenu: invalid apptype selected"); break; } } else { if ( temp->getIsPhoneSync() ) { mPhoneDevice = temp->getPhoneDevice( ) ; mPhoneConnection = temp->getPhoneConnection( ); mPhoneModel = temp->getPhoneModel( ); syncPhone(); @@ -230,24 +234,25 @@ void KSyncManager::slotSyncMenu( int action ) mActiveSyncPort = temp->getRemotePortPWM(); mActiveSyncIP = temp->getRemoteIPPWM(); } syncPi(); } else syncRemote( temp ); } } delete temp; setBlockSave(false); } + void KSyncManager::enableQuick() { QDialog dia ( 0, "input-dialog", true ); QLineEdit lab ( &dia ); QVBoxLayout lay( &dia ); lab.setText( mPrefs->mPassiveSyncPort ); lay.setMargin(7); lay.setSpacing(7); int po = 9197+mTargetApp; QLabel label ( i18n("Port number (Default: %1)").arg(po), &dia ); lay.addWidget( &label); lay.addWidget( &lab); @@ -276,33 +281,32 @@ void KSyncManager::enableQuick() return; } //qDebug("port %d ", port); mServerSocket = new KServerSocket ( mPrefs->mPassiveSyncPw, port ,1 ); mServerSocket->setFileName( defaultFileName() ); //qDebug("connected "); if ( !mServerSocket->ok() ) { KMessageBox::information( 0, i18n("Failed to bind or\nlisten to the port!")); delete mServerSocket; mServerSocket = 0; return; } - //connect( mServerSocket, SIGNAL ( saveFile() ),this, SIGNAL ( save() ) ); connect( mServerSocket, SIGNAL ( request_file() ),this, SIGNAL ( request_file() ) ); connect( mServerSocket, SIGNAL ( file_received( bool ) ), this, SIGNAL ( getFile( bool ) ) ); } void KSyncManager::syncLocalFile() { - QString fn =mLastSyncedLocalFile; + QString fn =mPrefs->mLastSyncedLocalFile; QString ext; switch(mTargetApp) { case (KAPI): ext = "(*.vcf)"; break; case (KOPI): ext = "(*.ics/*.vcs)"; break; case (PWMPI): ext = "(*.pwm)"; @@ -312,24 +316,25 @@ void KSyncManager::syncLocalFile() 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 ); QString mess; bool loadbup = true; if ( !info. exists() ) { mess = i18n( "Sync file \n...%1\ndoes not exist!\nNothing synced!\n").arg(fn.right( 30) ); int result = QMessageBox::warning( mParent, i18n("Warning!"), mess ); return ret; @@ -344,70 +349,73 @@ bool KSyncManager::syncWithFile( QString fn , bool quick ) if ( result ) return false; } if ( mAskForPreferences ) edit_sync_options(); if ( result == 0 ) { //qDebug("Now sycing ... "); if ( ret = mImplementation->sync( this, fn, mSyncAlgoPrefs ) ) mParent->topLevelWidget()->setCaption( i18n("Synchronization successful") ); else mParent->topLevelWidget()->setCaption( i18n("Sync cancelled or failed. Nothing synced.") ); if ( ! quick ) - mLastSyncedLocalFile = fn; + mPrefs->mLastSyncedLocalFile = fn; } return ret; } + void KSyncManager::quickSyncLocalFile() { - if ( syncWithFile( mLastSyncedLocalFile, false ) ) { + if ( syncWithFile( mPrefs->mLastSyncedLocalFile, false ) ) { qDebug("quick syncLocalFile() successful "); } } + void KSyncManager::multiSync( bool askforPrefs ) { if (blockSave()) return; setBlockSave(true); QString question = i18n("Do you really want\nto multiple sync\nwith all checked profiles?\nSyncing takes some\ntime - all profiles\nare synced twice!"); - if ( QMessageBox::information( mParent, i18n("Sync"), + if ( QMessageBox::information( mParent, i18n("KDE-Pim Sync"), question, i18n("Yes"), i18n("No"), 0, 0 ) != 0 ) { setBlockSave(false); mParent->topLevelWidget()->setCaption(i18n("Aborted! Nothing synced!")); return; } mCurrentSyncDevice = i18n("Multiple profiles") ; - mSyncAlgoPrefs = mRingSyncAlgoPrefs; + mSyncAlgoPrefs = mPrefs->mRingSyncAlgoPrefs; if ( askforPrefs ) { edit_sync_options(); mRingSyncAlgoPrefs = mSyncAlgoPrefs; } mParent->topLevelWidget()->setCaption(i18n("Multiple sync started.") ); qApp->processEvents(); int num = ringSync() ; if ( num > 1 ) ringSync(); setBlockSave(false); if ( num ) emit save(); if ( num ) - mParent->topLevelWidget()->setCaption(i18n("%1 profiles synced. Multiple sync completed!").arg(num) ); + mParent->topLevelWidget()->setCaption(i18n("%1 profiles synced. Multiple sync complete!").arg(num) ); else mParent->topLevelWidget()->setCaption(i18n("Nothing synced! No profiles defined for multisync!")); return; } + int KSyncManager::ringSync() { int syncedProfiles = 0; unsigned int i; QTime timer; KConfig config ( locateLocal( "config","ksyncprofilesrc" ) ); QStringList syncProfileNames = mSyncProfileNames; KSyncProfile* temp = new KSyncProfile (); mAskForPreferences = false; for ( i = 0; i < syncProfileNames.count(); ++i ) { mCurrentSyncProfile = i; temp->setName(syncProfileNames[mCurrentSyncProfile]); @@ -443,44 +451,59 @@ int KSyncManager::ringSync() mWriteBackInFuture = temp->getWriteBackFutureWeeks( ); mShowSyncSummary = false; mCurrentSyncDevice = syncProfileNames[i] ; mCurrentSyncName = mLocalMachineName; if ( i == 0 ) { syncSharp(); } else { if ( temp->getIsLocalFileSync() ) { switch(mTargetApp) { case (KAPI): if ( syncWithFile( temp->getRemoteFileNameAB( ), false ) ) - mLastSyncedLocalFile = temp->getRemoteFileNameAB(); + mPrefs->mLastSyncedLocalFile = temp->getRemoteFileNameAB(); break; case (KOPI): if ( syncWithFile( temp->getRemoteFileName( ), false ) ) - mLastSyncedLocalFile = temp->getRemoteFileName(); + mPrefs->mLastSyncedLocalFile = temp->getRemoteFileName(); break; case (PWMPI): if ( syncWithFile( temp->getRemoteFileNamePWM( ), false ) ) - mLastSyncedLocalFile = temp->getRemoteFileNamePWM(); + mPrefs->mLastSyncedLocalFile = temp->getRemoteFileNamePWM(); break; default: qDebug("KSyncManager::slotSyncMenu: invalid apptype selected"); break; } } else { if ( temp->getIsPhoneSync() ) { mPhoneDevice = temp->getPhoneDevice( ) ; mPhoneConnection = temp->getPhoneConnection( ); mPhoneModel = temp->getPhoneModel( ); syncPhone(); + } else if ( temp->getIsPiSync() ) { + if ( mTargetApp == KAPI ) { + mPassWordPiSync = temp->getRemotePwAB(); + mActiveSyncPort = temp->getRemotePortAB(); + mActiveSyncIP = temp->getRemoteIPAB(); + } else if ( mTargetApp == KOPI ) { + mPassWordPiSync = temp->getRemotePw(); + mActiveSyncPort = temp->getRemotePort(); + mActiveSyncIP = temp->getRemoteIP(); + } else { + mPassWordPiSync = temp->getRemotePwPWM(); + mActiveSyncPort = temp->getRemotePortPWM(); + mActiveSyncIP = temp->getRemoteIPPWM(); + } + syncPi(); } else syncRemote( temp, false ); } } timer.start(); mParent->topLevelWidget()->setCaption(i18n("Multiple sync in progress ... please wait!") ); while ( timer.elapsed () < 2000 ) { qApp->processEvents(); #ifndef _WIN32_ sleep (1); #endif @@ -549,37 +572,32 @@ void KSyncManager::syncRemote( KSyncProfile* prof, bool ask) // qDebug("KO: Remote copy result(0 = okay): %d ",result ); if ( result != 0 ) { unsigned int len = maxlen; 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 (preCommand) ; QMessageBox::information( mParent, i18n("Sync - ERROR"), question, i18n("Okay!")) ; - mParent->topLevelWidget()->setCaption (""); + mParent->topLevelWidget()->setCaption ("KDE-Pim"); return; } mParent->topLevelWidget()->setCaption ( i18n( "Copying succeed." ) ); //qDebug(" file **%s** ",prof->getLocalTempFile().latin1() ); - - if ( syncWithFile( localTempFile, true ) ) { -// Event* e = mView->getLastSyncEvent(); -// e->setReadOnly( false ); -// e->setLocation( KOPrefs::instance()->mSyncProfileNames[mCurrentSyncProfile]); -// e->setReadOnly( true ); + if ( mWriteBackFile ) { int fi; if ( (fi = postCommand.find("$PWD$")) > 0 ) { QString pwd = getPassword(); postCommand = postCommand.left( fi )+ pwd + postCommand.mid( fi+5 ); } mParent->topLevelWidget()->setCaption ( i18n( "Writing back file ..." ) ); result = system ( postCommand ); qDebug("Writing back file result: %d ", result); if ( result != 0 ) { mParent->topLevelWidget()->setCaption ( i18n( "Writing back file result: " )+QString::number( result ) ); @@ -635,24 +653,25 @@ void KSyncManager::edit_sync_options() case 6: // both.setChecked( true); break; default: 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 ; } } + 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") ); @@ -676,55 +695,54 @@ void KSyncManager::confSync() if ( ! sp ) { sp = new KSyncPrefsDialog( mParent, "syncprefs", true ); } sp->usrReadConfig(); #ifndef DESKTOP_VERSION sp->showMaximized(); #else sp->show(); #endif sp->exec(); mSyncProfileNames = sp->getSyncProfileNames(); mLocalMachineName = sp->getLocalMachineName (); - fillSyncMenu(); + QTimer::singleShot ( 1, this, SLOT ( fillSyncMenu() ) ); } void KSyncManager::syncSharp() { + if ( ! syncExternalApplication("sharp") ) qDebug("ERROR sync sharp ");; } bool KSyncManager::syncExternalApplication(QString resource) { emit save(); if ( mAskForPreferences ) edit_sync_options(); qDebug("sync %s", resource.latin1()); bool syncOK = mImplementation->syncExternal(this, resource); return syncOK; } void KSyncManager::syncPhone() { - emit save(); - qDebug("pending syncPhone(); "); - //mView->syncPhone(); + syncExternalApplication("phone"); } void KSyncManager::showProgressBar(int percentage, QString caption, int total) { if (!bar->isVisible()) { bar->setCaption (caption); bar->setTotalSteps ( total ) ; bar->show(); } @@ -758,24 +776,25 @@ QString KSyncManager::syncFileName() fn = "tempsyncpw.pwm"; break; default: break; } #ifdef _WIN32_ return locateLocal( "tmp", fn ); #else return (QString( "/tmp/" )+ fn ); #endif } + void KSyncManager::syncPi() { qApp->processEvents(); bool ok; Q_UINT16 port = mActiveSyncPort.toUInt(&ok); if ( ! ok ) { mParent->topLevelWidget()->setCaption( i18n("Sorry, no valid port.Syncing cancelled.") ); return; } KCommandSocket* commandSocket = new KCommandSocket( mPassWordPiSync, port, mActiveSyncIP, this ); connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int )), this, SLOT(deleteCommandSocket(KCommandSocket*, int)) ); mParent->topLevelWidget()->setCaption( i18n("Sending request for remote file ...") ); @@ -1144,13 +1163,12 @@ void KCommandSocket::deleteSocket() mSocket->close(); if ( mSocket->state() == QSocket::Idle ) deleteSocket(); return; } } //qDebug("KCommandSocket::deleteSocket() %d", mRetVal ); if ( mSocket) delete mSocket; mSocket = 0; emit commandFinished( this, mRetVal ); } - diff --git a/libkdepim/ksyncmanager.h b/libkdepim/ksyncmanager.h index 25892d8..7027894 100644 --- a/libkdepim/ksyncmanager.h +++ b/libkdepim/ksyncmanager.h @@ -108,24 +108,25 @@ 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() ; + 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 fillSyncMenu(); QString getCurrentSyncDevice() { return mCurrentSyncDevice; } QString getCurrentSyncName() { return mCurrentSyncName; } void showProgressBar(int percentage, QString caption = QString::null, int total=100); void hideProgressBar(); @@ -138,25 +139,24 @@ class KSyncManager : public QObject bool mAskForPreferences; bool mShowSyncSummary; bool mShowSyncEvents; bool mShowTodoInAgenda; bool mWriteBackExistingOnly; int mSyncAlgoPrefs; int mRingSyncAlgoPrefs; bool mWriteBackFile; int mWriteBackInFuture; QString mPhoneDevice; QString mPhoneConnection; QString mPhoneModel; - QString mLastSyncedLocalFile; // save! QString mPassWordPiSync; QString mActiveSyncPort; QString mActiveSyncIP ; signals: void save(); void request_file(); void getFile( bool ); public slots: void slotSyncMenu( int ); void deleteCommandSocket(KCommandSocket*s, int state); @@ -169,25 +169,24 @@ class KSyncManager : public QObject KServerSocket * mServerSocket; void enableQuick(); KPimPrefs* mPrefs; QString mDefFileName; QString mCurrentSyncDevice; QString mCurrentSyncName; void quickSyncLocalFile(); bool syncWithFile( QString fn , bool quick ); void syncLocalFile(); void syncPhone(); void syncSharp(); bool syncExternalApplication(QString); - void multiSync( bool askforPrefs ); int mCurrentSyncProfile ; void syncRemote( KSyncProfile* prof, bool ask = true); void edit_sync_options(); int ringSync(); QString getPassword( ); private slots: void confSync(); // ********************* private: bool mBlockSaveFlag; |