author | zautrix <zautrix> | 2004-10-07 07:28:54 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2004-10-07 07:28:54 (UTC) |
commit | 77280f6a176a15b60004f312e6cacdfbbd3909c1 (patch) (side-by-side diff) | |
tree | e074d4abedc2f4cc575e5655575e038b9d460106 /libkdepim/ksyncmanager.cpp | |
parent | f1eb5b74c962909851607c4b4cb05ee18a347d37 (diff) | |
download | kdepimpi-77280f6a176a15b60004f312e6cacdfbbd3909c1.zip kdepimpi-77280f6a176a15b60004f312e6cacdfbbd3909c1.tar.gz kdepimpi-77280f6a176a15b60004f312e6cacdfbbd3909c1.tar.bz2 |
sync changes
-rw-r--r-- | libkdepim/ksyncmanager.cpp | 567 |
1 files changed, 531 insertions, 36 deletions
diff --git a/libkdepim/ksyncmanager.cpp b/libkdepim/ksyncmanager.cpp index c0cc840..5d48884 100644 --- a/libkdepim/ksyncmanager.cpp +++ b/libkdepim/ksyncmanager.cpp @@ -27,38 +27,42 @@ #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 <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), mSyncMenu(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(); @@ -67,43 +71,46 @@ KSyncManager::KSyncManager(QWidget* parent, KSyncInterface* implementation, Targ } 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() < 3 ) { + if ( prof.count() < 2 ) { prof.clear(); - prof << i18n("Sharp_DTM"); - prof << i18n("Local_file"); - prof << i18n("Last_file"); + prof << i18n("Sharp_DTM"); + prof << i18n("Local_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; @@ -136,16 +143,27 @@ void KSyncManager::slotSyncMenu( int action ) //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); mCurrentSyncProfile = action - 1000 ; mCurrentSyncDevice = mSyncProfileNames[mCurrentSyncProfile] ; @@ -193,24 +211,78 @@ void KSyncManager::slotSyncMenu( int action ) } } else { if ( temp->getIsPhoneSync() ) { mPhoneDevice = temp->getPhoneDevice( ) ; mPhoneConnection = temp->getPhoneConnection( ); mPhoneModel = temp->getPhoneModel( ); syncPhone(); - } else + } else if ( temp->getIsPiSync() ) { + mPassWordPiSync = temp->getRemotePw(); + mActiveSyncPort = temp->getRemotePort(); + mActiveSyncIP = temp->getRemoteIP(); + syncPi(); + } 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); + + QLineEdit lepw ( &dia ); + lepw.setText( mPrefs->mPassiveSyncPw ); + QLabel label2 ( i18n("Password to enable\naccess from remote:"), &dia ); + lay.addWidget( &label2); + lay.addWidget( &lepw); + dia.setFixedSize( 230,80 ); + 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(); + mPrefs->mPassiveSyncPw = lepw.text(); + mPrefs->mPassiveSyncPort = lab.text(); + bool ok; + 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() ); + //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 ( file_received( bool ) ), this, SIGNAL ( getFile( bool ) ) ); +} void KSyncManager::syncLocalFile() { QString fn =mLastSyncedLocalFile; QString ext; switch(mTargetApp) @@ -266,17 +338,16 @@ bool KSyncManager::syncWithFile( QString fn , bool quick ) if ( result == 0 ) { //qDebug("Now sycing ... "); if ( ret = mImplementation->sync( this, fn, mSyncAlgoPrefs ) ) mParent->setCaption( i18n("Synchronization successful") ); else mParent->setCaption( i18n("Sync cancelled or failed. Nothing synced.") ); if ( ! quick ) mLastSyncedLocalFile = fn; - mImplementation->sync_setModified(); } return ret; } void KSyncManager::quickSyncLocalFile() { if ( syncWithFile( mLastSyncedLocalFile, false ) ) { qDebug("quick syncLocalFile() successful "); @@ -305,17 +376,17 @@ void KSyncManager::multiSync( bool askforPrefs ) } mParent->setCaption(i18n("Multiple sync started.") ); qApp->processEvents(); int num = ringSync() ; if ( num > 1 ) ringSync(); setBlockSave(false); if ( num ) - mImplementation->sync_save(); + emit save(); if ( num ) mParent->setCaption(i18n("%1 profiles synced. Multiple sync completed!").arg(num) ); else mParent->setCaption(i18n("Nothing synced! No profiles defined for multisync!")); return; } int KSyncManager::ringSync() { @@ -423,36 +494,36 @@ void KSyncManager::syncRemote( KSyncProfile* prof, bool ask) 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("KSyncManager::syncRemote: invalid apptype selected"); - break; - } + { + 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 = preCommand.find("$PWD$")) > 0 ) { QString pwd = getPassword(); preCommand = preCommand.left( fi )+ pwd + preCommand.mid( fi+5 ); } @@ -609,38 +680,36 @@ void KSyncManager::confSync() void KSyncManager::syncSharp() { if ( ! syncExternalApplication("sharp") ) qDebug("ERROR sync sharp ");; } bool KSyncManager::syncExternalApplication(QString resource) { - if ( mImplementation->sync_isModified() ) - mImplementation->sync_save(); + + emit save(); if ( mAskForPreferences ) edit_sync_options(); qDebug("sync %s", resource.latin1()); bool syncOK = mImplementation->syncExternal(this, resource); return syncOK; } void KSyncManager::syncPhone() { - if ( mImplementation->sync_isModified() ) - mImplementation->sync_save(); + emit save(); qDebug("pending syncPhone(); "); //mView->syncPhone(); - mImplementation->sync_setModified(); } void KSyncManager::showProgressBar(int percentage, QString caption, int total) { if (!bar->isVisible()) { bar->setCaption (caption); @@ -656,8 +725,434 @@ void KSyncManager::hideProgressBar() { bar->hide(); } bool KSyncManager::isProgressBarCanceled() { return !bar->isVisible(); } + +QString KSyncManager::syncFileName() +{ + + QString fn = "tempfile"; + switch(mTargetApp) + { + case (KAPI): + fn = "addressbook.vcf"; + break; + case (KOPI): + fn = "synccalendar.ics"; + break; + case (PWMPI): + fn = "manager.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->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->setCaption( i18n("Sending request for remote file ...") ); + commandSocket->readFile( syncFileName() ); +} + +void KSyncManager::deleteCommandSocket(KCommandSocket*s, int state) +{ + qDebug("MainWindow::deleteCommandSocket %d", state); + + //enum { success, errorW, errorR, quiet }; + if ( state == KCommandSocket::errorR ) { + mParent->setCaption( i18n("ERROR: Receiving remote file failed.") ); + delete s; + KCommandSocket* commandSocket = new KCommandSocket( mPassWordPiSync, mActiveSyncPort.toUInt(), mActiveSyncIP, this ); + connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int)), this, SLOT(deleteCommandSocket(KCommandSocket*, int )) ); + commandSocket->sendStop(); + return; + + } else if ( state == KCommandSocket::errorW ) { + mParent->setCaption( i18n("ERROR:Writing back file failed.") ); + + } else if ( state == KCommandSocket::successR ) { + QTimer::singleShot( 1, this , SLOT ( readFileFromSocket())); + + } else if ( state == KCommandSocket::successW ) { + mParent->setCaption( i18n("Pi-Sync succesful!") ); + } + + delete s; +} + +void KSyncManager::readFileFromSocket() +{ + QString fileName = syncFileName(); + mParent->setCaption( i18n("Remote file saved to temp file.") ); + if ( ! syncWithFile( fileName , true ) ) { + mParent->setCaption( i18n("Syncing failed.") ); + qDebug("Syncing failed "); + return; + } + KCommandSocket* commandSocket = new KCommandSocket( mPassWordPiSync, mActiveSyncPort.toUInt(), mActiveSyncIP, this ); + connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int)), this, SLOT(deleteCommandSocket(KCommandSocket*, int )) ); + if ( mWriteBackFile ) + commandSocket->writeFile( fileName ); + else { + commandSocket->sendStop(); + mParent->setCaption( i18n("Pi-Sync succesful!") ); + } +} + + + + + + + + + + + + + + + + + + + + + + + +KServerSocket:: KServerSocket ( QString pw, Q_UINT16 port, int backlog, QObject * parent, const char * name ) : QServerSocket( port, backlog, parent, name ) +{ + mPassWord = pw; + mSocket = 0; + mSyncActionDialog = 0; + blockRC = false; +}; + +void KServerSocket::newConnection ( int socket ) +{ + // qDebug("KServerSocket:New connection %d ", socket); + if ( mSocket ) { + qDebug("KServerSocket::newConnection Socket deleted! "); + delete mSocket; + mSocket = 0; + } + mSocket = new QSocket( this ); + connect( mSocket , SIGNAL(readyRead()), this, SLOT(readClient()) ); + connect( mSocket , SIGNAL(delayedCloseFinished()), this, SLOT(discardClient()) ); + mSocket->setSocket( socket ); +} + +void KServerSocket::discardClient() +{ + //qDebug(" KServerSocket::discardClient()"); + if ( mSocket ) { + delete mSocket; + mSocket = 0; + } + //emit endConnect(); +} +void KServerSocket::readClient() +{ + if ( blockRC ) + return; + if ( mSocket == 0 ) { + qDebug("ERROR::KServerSocket::readClient(): mSocket == 0 "); + return; + } + qDebug("KServerSocket readClient()"); + if ( mSocket->canReadLine() ) { + QString line = mSocket->readLine(); + qDebug("KServerSocket readline: %s ", line.latin1()); + QStringList tokens = QStringList::split( QRegExp("[ \r\n][ \r\n]*"), line ); + if ( tokens[0] == "GET" ) { + if ( tokens[1] == mPassWord ) + //emit sendFile( mSocket ); + send_file(); + else { + KMessageBox::information( 0, i18n("ERROR:\nGot send file request\nwith invalid password")); + qDebug("password %s, invalid password %s ",mPassWord.latin1(), tokens[1].latin1() ); + } + } + if ( tokens[0] == "PUT" ) { + if ( tokens[1] == mPassWord ) { + //emit getFile( mSocket ); + blockRC = true; + get_file(); + } + else { + KMessageBox::information( 0, i18n("ERROR:\nGot receive file request\nwith invalid password")); + qDebug("password %s, invalid password %s ",mPassWord.latin1(), tokens[1].latin1() ); + } + } + if ( tokens[0] == "STOP" ) { + //emit endConnect(); + end_connect(); + } + } +} +void KServerSocket::end_connect() +{ + delete mSyncActionDialog; + mSyncActionDialog = 0; +} +void KServerSocket::send_file() +{ + //qDebug("MainWindow::sendFile(QSocket* s) "); + if ( mSyncActionDialog ) + delete mSyncActionDialog; + mSyncActionDialog = new QDialog ( 0, "input-dialog", true ); + mSyncActionDialog->setCaption(i18n("Received sync request")); + QLabel* label = new QLabel( i18n("Synchronizing from remote ...\n\nDo not use this application!\n\nIf syncing fails\nyou can close this dialog."), mSyncActionDialog ); + QVBoxLayout* lay = new QVBoxLayout( mSyncActionDialog ); + lay->addWidget( label); + lay->setMargin(7); + lay->setSpacing(7); + mSyncActionDialog->setFixedSize( 230, 120); + mSyncActionDialog->show(); + qDebug("KSS::saving ... "); + emit saveFile(); + qApp->processEvents(); + QString fileName = mFileName; + QFile file( fileName ); + if (!file.open( IO_ReadOnly ) ) { + delete mSyncActionDialog; + mSyncActionDialog = 0; + qDebug("KSS::error open file "); + mSocket->close(); + if ( mSocket->state() == QSocket::Idle ) + QTimer::singleShot( 10, this , SLOT ( discardClient())); + return ; + + } + mSyncActionDialog->setCaption( i18n("Sending file...") ); + QTextStream ts( &file ); + ts.setCodec( QTextCodec::codecForName("utf8") ); + QTextStream os( mSocket ); + os.setCodec( QTextCodec::codecForName("utf8") ); + //os.setEncoding( QTextStream::UnicodeUTF8 ); + while ( ! ts.atEnd() ) { + os << ts.readLine() << "\n"; + } + //os << ts.read(); + file.close(); + mSyncActionDialog->setCaption( i18n("Waiting for synced file...") ); + mSocket->close(); + if ( mSocket->state() == QSocket::Idle ) + QTimer::singleShot( 10, this , SLOT ( discardClient())); +} +void KServerSocket::get_file() +{ + mSyncActionDialog->setCaption( i18n("Receiving synced file...") ); + + piTime.start(); + piFileString = ""; + QTimer::singleShot( 1, this , SLOT (readBackFileFromSocket( ) )); +} + + +void KServerSocket::readBackFileFromSocket() +{ + //qDebug("readBackFileFromSocket() %d ", piTime.elapsed ()); + while ( mSocket->canReadLine () ) { + piTime.restart(); + QString line = mSocket->readLine (); + piFileString += line; + //qDebug("readline: %s ", line.latin1()); + mSyncActionDialog->setCaption( i18n("Received %1 bytes").arg( piFileString.length() ) ); + + } + if ( piTime.elapsed () < 3000 ) { + // wait for more + //qDebug("waitformore "); + QTimer::singleShot( 100, this , SLOT (readBackFileFromSocket( ) )); + return; + } + QString fileName = mFileName; + QFile file ( fileName ); + if (!file.open( IO_WriteOnly ) ) { + delete mSyncActionDialog; + mSyncActionDialog = 0; + qDebug("error open cal file "); + piFileString = ""; + emit file_received( false ); + blockRC = false; + return ; + + } + + // mView->setLoadedFileVersion(QDateTime::currentDateTime().addSecs( -1)); + QTextStream ts ( &file ); + ts.setCodec( QTextCodec::codecForName("utf8") ); + mSyncActionDialog->setCaption( i18n("Writing file to disk...") ); + ts << piFileString; + mSocket->close(); + if ( mSocket->state() == QSocket::Idle ) + QTimer::singleShot( 10, this , SLOT ( discardClient())); + file.close(); + delete mSyncActionDialog; + mSyncActionDialog = 0; + piFileString = ""; + blockRC = false; + emit file_received( true ); + +} + +KCommandSocket::KCommandSocket ( QString password, Q_UINT16 port, QString host, QObject * parent, const char * name ): QObject( parent, name ) +{ + mPassWord = password; + mSocket = 0; + mPort = port; + mHost = host; + + mRetVal = quiet; + mTimerSocket = new QTimer ( this ); + connect( mTimerSocket, SIGNAL ( timeout () ), this, SLOT ( deleteSocket() ) ); +} +void KCommandSocket::readFile( QString fn ) +{ + if ( !mSocket ) { + mSocket = new QSocket( this ); + connect( mSocket, SIGNAL(readyRead()), this, SLOT(startReadFileFromSocket()) ); + connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) ); + } + mFileString = ""; + mFileName = fn; + mFirst = true; + mSocket->connectToHost( mHost, mPort ); + QTextStream os( mSocket ); + os.setEncoding( QTextStream::UnicodeUTF8 ); + os << "GET " << mPassWord << "\r\n"; + mTimerSocket->start( 10000 ); +} + +void KCommandSocket::writeFile( QString fileName ) +{ + if ( !mSocket ) { + mSocket = new QSocket( this ); + connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) ); + connect( mSocket, SIGNAL(connected ()), this, SLOT(writeFileToSocket()) ); + } + mFileName = fileName ; + mSocket->connectToHost( mHost, mPort ); +} +void KCommandSocket::writeFileToSocket() +{ + QFile file2( mFileName ); + if (!file2.open( IO_ReadOnly ) ) { + mRetVal= errorW; + mSocket->close(); + if ( mSocket->state() == QSocket::Idle ) + QTimer::singleShot( 10, this , SLOT ( deleteSocket())); + return ; + } + QTextStream ts2( &file2 ); + ts2.setCodec( QTextCodec::codecForName("utf8") ); + QTextStream os2( mSocket ); + os2.setCodec( QTextCodec::codecForName("utf8") ); + os2 << "PUT " << mPassWord << "\r\n";; + while ( ! ts2.atEnd() ) { + os2 << ts2.readLine() << "\n"; + } + mRetVal= successW; + file2.close(); + mSocket->close(); + if ( mSocket->state() == QSocket::Idle ) + QTimer::singleShot( 10, this , SLOT ( deleteSocket())); +} +void KCommandSocket::sendStop() +{ + if ( !mSocket ) { + mSocket = new QSocket( this ); + connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) ); + } + mSocket->connectToHost( mHost, mPort ); + QTextStream os2( mSocket ); + os2.setCodec( QTextCodec::codecForName("utf8") ); + os2 << "STOP\r\n"; + mSocket->close(); + if ( mSocket->state() == QSocket::Idle ) + QTimer::singleShot( 10, this , SLOT ( deleteSocket())); +} + +void KCommandSocket::startReadFileFromSocket() +{ + if ( ! mFirst ) + return; + mFirst = false; + mTimerSocket->stop(); + mFileString = ""; + mTime.start(); + QTimer::singleShot( 1, this , SLOT (readFileFromSocket( ) )); + +} +void KCommandSocket::readFileFromSocket() +{ + //qDebug("readBackFileFromSocket() %d ", mTime.elapsed ()); + while ( mSocket->canReadLine () ) { + mTime.restart(); + QString line = mSocket->readLine (); + mFileString += line; + //qDebug("readline: %s ", line.latin1()); + } + if ( mTime.elapsed () < 3000 ) { + // wait for more + //qDebug("waitformore "); + QTimer::singleShot( 100, this , SLOT (readFileFromSocket( ) )); + return; + } + QString fileName = mFileName; + QFile file ( fileName ); + if (!file.open( IO_WriteOnly ) ) { + mFileString = ""; + mRetVal = errorR; + qDebug("Error open temp calender file for writing: %s",fileName.latin1() ); + deleteSocket(); + return ; + + } + // mView->setLoadedFileVersion(QDateTime::currentDateTime().addSecs( -1)); + QTextStream ts ( &file ); + ts.setCodec( QTextCodec::codecForName("utf8") ); + ts << mFileString; + file.close(); + mFileString = ""; + mRetVal = successR; + mSocket->close(); + // if state is not idle, deleteSocket(); is called via + // connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) ); + if ( mSocket->state() == QSocket::Idle ) + deleteSocket(); +} + +void KCommandSocket::deleteSocket() +{ + if ( mTimerSocket->isActive () ) { + mTimerSocket->stop(); + KMessageBox::information( 0, i18n("ERROR:\nConnection to remote host timed out!\nDid you forgot to enable\nsyncing on remote host? ")); + mRetVal = errorR; + } + //qDebug("KCommandSocket::deleteSocket() %d", mRetVal ); + if ( mSocket) + delete mSocket; + mSocket = 0; + emit commandFinished( this, mRetVal ); +} + |