-rw-r--r-- | libkdepim/ksyncmanager.cpp | 7 | ||||
-rw-r--r-- | libkdepim/phoneaccess.cpp | 2 |
2 files changed, 4 insertions, 5 deletions
diff --git a/libkdepim/ksyncmanager.cpp b/libkdepim/ksyncmanager.cpp index 3adbf61..df5a0d9 100644 --- a/libkdepim/ksyncmanager.cpp +++ b/libkdepim/ksyncmanager.cpp @@ -1,254 +1,254 @@ /* This file is part of KDE-Pim/Pi. Copyright (c) 2004 Ulf Schenk This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ // $Id$ #include "ksyncmanager.h" #include <stdlib.h> #ifndef _WIN32_ #include <unistd.h> #endif #include "ksyncprofile.h" #include "ksyncprefsdialog.h" #include "kpimprefs.h" #include <kmessagebox.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 <qtextcodec.h> #include <qlabel.h> #include <qcheckbox.h> #include <klocale.h> #include <kglobal.h> #include <kconfig.h> #include <kfiledialog.h> QDateTime KSyncManager::mRequestedSyncEvent; KSyncManager::KSyncManager(QWidget* parent, KSyncInterface* implementation, TargetApp ta, KPimPrefs* prefs, QPopupMenu* syncmenu) - : QObject(), mParent(parent), mImplementation(implementation), mTargetApp(ta), mPrefs(prefs ),mSyncMenu(syncmenu) + : QObject(), mPrefs(prefs ), mParent(parent),mImplementation(implementation), mTargetApp(ta), mSyncMenu(syncmenu) { mServerSocket = 0; bar = new QProgressBar ( 1, 0 ); bar->setCaption (""); mWriteBackInPast = 2; 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("KSM::syncaction %d ", action); if ( action == 5000 ) return; mSyncWithDesktop = false; 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; mWriteBackFile = true; mSyncAlgoPrefs = 2;// take newest } else { mAskForPreferences = temp->getAskForPreferences(); mShowSyncSummary = temp->getShowSummaryAfterSync(); mWriteBackFile = temp->getWriteBackFile(); mSyncAlgoPrefs = temp->getSyncPrefs(); } mWriteBackExistingOnly = temp->getWriteBackExisting(); mIsKapiFile = temp->getIsKapiFile(); mWriteBackInFuture = 0; if ( temp->getWriteBackFuture() ) { mWriteBackInFuture = temp->getWriteBackFutureWeeks( ); mWriteBackInPast = temp->getWriteBackPastWeeks( ); } @@ -271,481 +271,480 @@ void KSyncManager::slotSyncMenu( int action ) } else if ( action == 1002 ) { mWriteBackFile = false; mAskForPreferences = false; mShowSyncSummary = false; mSyncAlgoPrefs = 3; 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("KSM::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(); while ( !mPisyncFinished ) { //qDebug("waiting "); qApp->processEvents(); } } else syncRemote( temp ); } } delete temp; setBlockSave(false); } void KSyncManager::enableQuick( bool ask ) { bool autoStart; bool changed = false; if ( ask ) { 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); QLineEdit lepw ( &dia ); lepw.setText( mPrefs->mPassiveSyncPw ); QLabel label2 ( i18n("Password to enable\naccess from remote:"), &dia ); lay.addWidget( &label2); lay.addWidget( &lepw); QCheckBox autostart(i18n("Automatically start\nat application startup"), &dia ); lay.addWidget( &autostart); autostart.setChecked( mPrefs->mPassiveSyncAutoStart ); #ifdef DESKTOP_VERSION #ifdef _WIN32_ QCheckBox syncdesktop( i18n("Automatically sync with Outlook\nwhen receiving sync request"),&dia ); syncdesktop.hide();// not implemented! #else QCheckBox syncdesktop( i18n("Automatically sync with KDE-Desktop\nwhen receiving sync request"),&dia ); #endif lay.addWidget( &syncdesktop); #else mPrefs->mPassiveSyncWithDesktop = false; QCheckBox syncdesktop( i18n("Automatically sync\nwith KDE-Desktop"),&dia ); syncdesktop.hide(); #endif syncdesktop.setChecked( mPrefs->mPassiveSyncWithDesktop ); dia.setFixedSize( 230,120 ); dia.setCaption( i18n("Enter port for Pi-Sync") ); QPushButton pb ( "OK", &dia); lay.addWidget( &pb ); connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) ); dia.show(); if ( ! dia.exec() ) return; dia.hide(); qApp->processEvents(); if ( mPrefs->mPassiveSyncPw != lepw.text() ) { changed = true; mPrefs->mPassiveSyncPw = lepw.text(); } if ( mPrefs->mPassiveSyncPort != lab.text() ) { mPrefs->mPassiveSyncPort = lab.text(); changed = true; } autoStart = autostart.isChecked(); if (mPrefs->mPassiveSyncWithDesktop != syncdesktop.isChecked() ) { changed = true; mPrefs->mPassiveSyncWithDesktop = syncdesktop.isChecked(); } } else autoStart = mPrefs->mPassiveSyncAutoStart; if ( autoStart != mPrefs->mPassiveSyncAutoStart ) changed = true; bool ok; mPrefs->mPassiveSyncAutoStart = false; Q_UINT16 port = mPrefs->mPassiveSyncPort.toUInt(&ok); if ( ! ok ) { KMessageBox::information( 0, i18n("No valid port")); return; } //qDebug("port %d ", port); mServerSocket = new KServerSocket ( mPrefs->mPassiveSyncPw, port ,1 ); mServerSocket->setFileName( defaultFileName() );//bbb //qDebug("connected "); if ( !mServerSocket->ok() ) { KMessageBox::information( 0, i18n("Failed to bind or\nlisten to the port!")); delete mServerSocket; mServerSocket = 0; return; } mPrefs->mPassiveSyncAutoStart = autoStart; if ( changed ) { mPrefs->writeConfig(); } connect( mServerSocket, SIGNAL ( request_file() ),this, SIGNAL ( request_file() ) ); connect( mServerSocket, SIGNAL ( file_received( bool ) ), this, SIGNAL ( getFile( bool ) ) ); } void KSyncManager::syncLocalFile() { QString fn =mPrefs->mLastSyncedLocalFile; QString ext; switch(mTargetApp) { case (KAPI): ext = "(*.vcf)"; break; case (KOPI): ext = "(*.ics/*.vcs)"; break; case (PWMPI): ext = "(*.pwm)"; break; default: qDebug("KSM::syncLocalFile: invalid apptype selected"); break; } fn =KFileDialog:: getOpenFileName( fn, i18n("Sync filename"+ext), mParent ); if ( fn == "" ) return; if ( syncWithFile( fn, false ) ) { qDebug("KSM::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!"), + QMessageBox::warning( mParent, i18n("Warning!"), mess ); return ret; } int result = 0; if ( !quick ) { mess = i18n("Sync with file \n...%1\nfrom:\n%2\n").arg(fn.right( 25)).arg(KGlobal::locale()->formatDateTime(info.lastModified (), true, false )); result = QMessageBox::warning( mParent, i18n("Warning!"), mess, i18n("Sync"), i18n("Cancel"), 0, 0, 1 ); if ( result ) return false; } if ( mAskForPreferences ) if ( !edit_sync_options()) { mParent->topLevelWidget()->setCaption( i18n("Syncing aborted. Nothing synced.") ); return false; } 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.") ); if ( ! quick ) mPrefs->mLastSyncedLocalFile = fn; } return ret; } void KSyncManager::quickSyncLocalFile() { if ( syncWithFile( mPrefs->mLastSyncedLocalFile, true ) ) { qDebug("KSM::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("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 = mPrefs->mRingSyncAlgoPrefs; if ( askforPrefs ) { if ( !edit_sync_options()) { mParent->topLevelWidget()->setCaption( i18n("Syncing aborted.") ); return; } mPrefs->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 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]); temp->readConfig(&config); - bool includeInRingSync; + bool includeInRingSync = false; switch(mTargetApp) { case (KAPI): includeInRingSync = temp->getIncludeInRingSyncAB(); break; case (KOPI): includeInRingSync = temp->getIncludeInRingSync(); break; case (PWMPI): includeInRingSync = temp->getIncludeInRingSyncPWM(); break; default: qDebug("KSM::ringSync: invalid apptype selected"); break; } if ( includeInRingSync && ( i < 1 || i > 2 )) { mParent->topLevelWidget()->setCaption(i18n("Profile ")+syncProfileNames[mCurrentSyncProfile]+ i18n(" is synced ... ")); ++syncedProfiles; mSyncWithDesktop = false; // mAskForPreferences = temp->getAskForPreferences(); mWriteBackFile = temp->getWriteBackFile(); mWriteBackExistingOnly = temp->getWriteBackExisting(); mIsKapiFile = temp->getIsKapiFile(); mWriteBackInFuture = 0; if ( temp->getWriteBackFuture() ) { mWriteBackInFuture = temp->getWriteBackFutureWeeks( ); mWriteBackInPast = temp->getWriteBackPastWeeks( ); } mFilterInCal = temp->getFilterInCal(); mFilterOutCal = temp->getFilterOutCal(); mFilterInAB = temp->getFilterInAB(); mFilterOutAB = temp->getFilterOutAB(); mShowSyncSummary = false; mCurrentSyncDevice = syncProfileNames[i] ; mCurrentSyncName = mLocalMachineName; if ( i == 0 ) { mIsKapiFile = false; #ifdef DESKTOP_VERSION syncKDE(); #else syncSharp(); #endif } else { 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("KSM: 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(); while ( !mPisyncFinished ) { //qDebug("waiting "); qApp->processEvents(); } timer.start(); while ( timer.elapsed () < 2000 ) { qApp->processEvents(); } } 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 } } } delete temp; return syncedProfiles; } 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 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("KSM::syncRemote: invalid apptype selected"); break; } int fi; if ( (fi = preCommand.find("$PWD$")) > 0 ) { QString pwd = getPassword(); preCommand = preCommand.left( fi )+ pwd + preCommand.mid( fi+5 ); } int maxlen = 30; if ( QApplication::desktop()->width() > 320 ) maxlen += 25; mParent->topLevelWidget()->setCaption ( i18n( "Copy remote file to local machine..." ) ); int fileSize = 0; int result = system ( preCommand ); // 0 : okay // 256: no such file or dir // qDebug("KSM::Sync: 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 ("KDE-Pim"); return; } mParent->topLevelWidget()->setCaption ( i18n( "Copying succeed." ) ); //qDebug(" file **%s** ",prof->getLocalTempFile().latin1() ); if ( syncWithFile( localTempFile, true ) ) { if ( mWriteBackFile ) { int fi; if ( (fi = postCommand.find("$PWD$")) > 0 ) { QString pwd = getPassword(); diff --git a/libkdepim/phoneaccess.cpp b/libkdepim/phoneaccess.cpp index e24ad9e..89db22b 100644 --- a/libkdepim/phoneaccess.cpp +++ b/libkdepim/phoneaccess.cpp @@ -1,216 +1,216 @@ /* This file is part of libkdepim. Copyright (c) 2004 Lutz Rogowski <rogowski@kde.org> This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include <qstring.h> #include <qapplication.h> #include <qptrlist.h> #include <qregexp.h> #include <qfile.h> #include <qlabel.h> #include <qtextstream.h> #include <qtextcodec.h> #include <qdir.h> #include <kmessagebox.h> #include <stdlib.h> #include "phoneaccess.h" void PhoneAccess::writeConfig( QString device, QString connection, QString model ) { #ifdef _WIN32_ QString fileName = qApp->applicationDirPath () +"\\gammurc"; #else QString fileName = QDir::homeDirPath() +"/.gammurc"; #endif //qDebug("save %d ", load ); QString content = "[gammu]\n";; bool write = false; bool addPort = true, addConnection = true, addModel = true; QFile file( fileName ); if ( QFile::exists( fileName) ) { if (!file.open( IO_ReadOnly ) ) { qDebug("Error: cannot open %s ", fileName.latin1() ); return; } QString line; while ( file.readLine( line, 1024 ) > 0 ) { //qDebug("*%s* ", line.latin1() ); if ( line.left(7 ) == "[gammu]" ) { ; } else if ( line.left(4 ) == "port" ) { if ( line == "port = " + device+"\n" ) { content += line ; addPort = false; //qDebug("port found" ); } } else if ( line.left(5 ) == "model" ) { if ( line == "model = " + model +"\n") { content += line ; addModel = false; //qDebug("model found" ); } } else if ( line.left( 10 ) == "connection" ) { if ( line == "connection = " + connection +"\n") { addConnection = false; content += line ; //qDebug("con found" ); } } else { content += line ; } } file.close(); } else { if ( ! connection.isEmpty() ) { addConnection = true; } if ( ! device.isEmpty() ) { addPort = true; } if ( ! model.isEmpty() ) { addModel = true; } } if ( addConnection ) { write = true; content += "connection = "; content += connection; content += "\n"; } if ( addPort ) { write = true; content += "port = "; content += device; content += "\n"; } if ( addModel ) { write = true; content += "model = "; content += model; content += "\n"; } if ( write ) { if (!file.open( IO_WriteOnly ) ) { qDebug("Error: cannot write file %s ", fileName.latin1() ); return; } qDebug("Writing file %s ", fileName.latin1() ); QTextStream ts( &file ); ts << content ; file.close(); } } bool PhoneAccess::writeToPhone( QString fileName) { #ifdef DESKTOP_VERSION #ifdef _WIN32_ QString command ="kammu --restore " + fileName ; #else QString command ="./kammu --restore " + fileName ; #endif #else QString command ="kammu --restore " + fileName ; #endif int ret = 1; while ( ret != 0 ) { QLabel* status = new QLabel( i18n(" This may take 1-3 minutes!"), 0 ); int w = 235; int h = status->sizeHint().height()+20 ; int dw = QApplication::desktop()->width(); int dh = QApplication::desktop()->height(); if ( dw > 310 ) w = 310; status->setCaption(i18n("Writing to phone...") ); status->setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); status->show(); status->raise(); status->update(); qApp->processEvents(); status->update(); qApp->processEvents(); ret = system ( command.latin1()); delete status; qApp->processEvents(); if ( ret ) { qDebug("Error S::command returned %d.", ret); int retval = KMessageBox::warningContinueCancel(0, i18n("Error accessing device!\nPlease turn on connection\nand retry!"),i18n("KDE/Pim phone access"),i18n("Retry"),i18n("Cancel")); if ( retval != KMessageBox::Continue ) return false; } } return true; } bool PhoneAccess::readFromPhone( QString fileName) { #ifdef DESKTOP_VERSION #ifdef _WIN32_ QString command ="kammu --backup " + fileName + " -yes" ; #else QString command ="./kammu --backup " + fileName + " -yes" ; #endif #else QString command ="kammu --backup " + fileName + " -yes" ; #endif - int ret; + int ret = 1; while ( ret != 0 ) { QLabel* status = new QLabel( i18n(" This may take 1-3 minutes!"), 0 ); int w = 235; int h = status->sizeHint().height()+20 ; int dw = QApplication::desktop()->width(); int dh = QApplication::desktop()->height(); if ( dw > 310 ) w = 310; status->setCaption(i18n("Reading from phone...") ); status->setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); status->show(); status->raise(); status->update(); qApp->processEvents(); status->update(); qApp->processEvents(); ret = system ( command.latin1() ); delete status; qApp->processEvents(); if ( ret ) { qDebug("Error reading from phone:Command returned %d", ret); int retval = KMessageBox::warningContinueCancel(0, i18n("Error accessing device!\nPlease turn on connection\nand retry!"),i18n("KDE/Pim phone access"),i18n("Retry"),i18n("Cancel")); if ( retval != KMessageBox::Continue ) return false; } } qApp->processEvents(); return true; } |