author | zautrix <zautrix> | 2005-11-25 17:41:25 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2005-11-25 17:41:25 (UTC) |
commit | 279e183c0325cd9565605f60af0215bb9bfdc825 (patch) (side-by-side diff) | |
tree | 43ab776cd108874819e7c6e73070a7d989a9078f /libkdepim/ksyncmanager.cpp | |
parent | 794a5204686ad9bfc16172b01db35f1f3b7683e5 (diff) | |
download | kdepimpi-279e183c0325cd9565605f60af0215bb9bfdc825.zip kdepimpi-279e183c0325cd9565605f60af0215bb9bfdc825.tar.gz kdepimpi-279e183c0325cd9565605f60af0215bb9bfdc825.tar.bz2 |
sync
-rw-r--r-- | libkdepim/ksyncmanager.cpp | 24 |
1 files changed, 18 insertions, 6 deletions
diff --git a/libkdepim/ksyncmanager.cpp b/libkdepim/ksyncmanager.cpp index a64eb34..719d80b 100644 --- a/libkdepim/ksyncmanager.cpp +++ b/libkdepim/ksyncmanager.cpp @@ -151,97 +151,98 @@ void KSyncManager::fillSyncMenu() insertText = "Sharp_DTM"; #endif } mSyncMenu->insertItem( insertText, 1000+i ); clearMenu->insertItem( insertText, 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); - mCurrentResourceLocal = ""; + mCurrentResourceLocal = ""; + emit multiResourceSyncStart( false ); 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); @@ -396,96 +397,98 @@ void KSyncManager::enableQuick( bool ask ) dia.move( (dw-dia.width())/2, (dh - dia.height() )/2 ); #endif 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_UINT32 port_t = mPrefs->mPassiveSyncPort.toUInt(&ok); qDebug("%d ", port_t); if ( ! ok || port_t > 65535 ) { KMessageBox::information( 0, i18n("No valid port number:\n%1").arg ( mPrefs->mPassiveSyncPort ), i18n("Pi-Sync Port Error")); return; } Q_UINT16 port = port_t; //qDebug("port %d ", port); mServerSocket = new KServerSocket ( mPrefs->mPassiveSyncPw, port ,1 ); mServerSocket->setFileName( defaultFileName() );//bbb if ( !mServerSocket->ok() ) { QTimer::singleShot( 2000, this, SLOT ( displayErrorPort() ) ); 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 ) ) ); + connect( mServerSocket, SIGNAL ( request_file(const QString &) ),this, SIGNAL ( request_file(const QString &) ) ); + connect( mServerSocket, SIGNAL ( file_received( bool ,const QString &) ), this, SIGNAL ( getFile( bool,const QString & ) ) ); } void KSyncManager::displayErrorPort() { KMessageBox::information( 0, i18n("<b>Enabling Pi-Sync failed!</b> Failed to bind or listen to the port %1! Is another instance already listening to that port?").arg( mPrefs->mPassiveSyncPort) , i18n("Pi-Sync Port Error")); } 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; if ( !info. exists() ) { mess = i18n( "Sync file \n...%1\ndoes not exist!\nNothing synced!\n").arg(fn.right( 30) ); QMessageBox::warning( mParent, i18n("Warning!"), mess ); return ret; @@ -524,97 +527,97 @@ void KSyncManager::quickSyncLocalFile() qDebug("KSM::quick syncLocalFile() successful "); } } void KSyncManager::multiSync( bool askforPrefs ) { if (blockSave()) return; setBlockSave(true); mCurrentResourceLocal = ""; if ( askforPrefs ) { 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() { - + emit multiResourceSyncStart( false ); int syncedProfiles = 0; unsigned int i; QTime timer; KConfig config ( locateLocal( "config","ksyncprofilesrc" ) ); QStringList syncProfileNames = mSyncProfileNames; KSyncProfile* temp = new KSyncProfile (); mAskForPreferences = false; mCurrentResourceLocal = ""; for ( i = 0; i < syncProfileNames.count(); ++i ) { mCurrentSyncProfile = i; temp->setName(syncProfileNames[mCurrentSyncProfile]); temp->readConfig(&config); 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(); @@ -1095,440 +1098,449 @@ bool KSyncManager::isProgressBarCanceled() QString KSyncManager::syncFileName() { QString fn = "tempfile"; switch(mTargetApp) { case (KAPI): fn = "tempsyncab.vcf"; break; case (KOPI): fn = "tempsynccal.ics"; break; case (PWMPI): fn = "tempsyncpw.pwm"; break; default: break; } #ifdef DESKTOP_VERSION return locateLocal( "tmp", fn ); #else return (QString( "/tmp/" )+ fn ); #endif } void KSyncManager::syncPi() { mIsKapiFile = true; mPisyncFinished = false; qApp->processEvents(); if ( mAskForPreferences ) if ( !edit_pisync_options()) { mParent->topLevelWidget()->setCaption( i18n("Syncing aborted. Nothing synced.") ); mPisyncFinished = true; return; } bool ok; Q_UINT16 port = mActiveSyncPort.toUInt(&ok); if ( ! ok ) { mParent->topLevelWidget()->setCaption( i18n("Sorry, no valid port.Syncing cancelled.") ); mPisyncFinished = true; return; } mCurrentResourceLocal = ""; mCurrentResourceRemote = ""; if ( mSpecificResources.count() ) { int startLocal = 0; int startRemote = mSpecificResources.count()/2; + emit multiResourceSyncStart( true ); while ( startLocal < mSpecificResources.count()/2 ) { + if ( startLocal+1 >= mSpecificResources.count()/2 ) + emit multiResourceSyncStart( false ); mPisyncFinished = false; mCurrentResourceLocal = mSpecificResources[ startLocal ]; mCurrentResourceRemote = mSpecificResources[ startRemote ]; KCommandSocket* commandSocket = new KCommandSocket( mCurrentResourceRemote, mPassWordPiSync, port, mActiveSyncIP, this, mParent->topLevelWidget() ); connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int )), this, SLOT(deleteCommandSocket(KCommandSocket*, int)) ); commandSocket->readFile( syncFileName() ); while ( !mPisyncFinished ) { //qDebug("waiting "); qApp->processEvents(); } ++startLocal; } } else { KCommandSocket* commandSocket = new KCommandSocket( "", mPassWordPiSync, port, mActiveSyncIP, this, mParent->topLevelWidget() ); connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int )), this, SLOT(deleteCommandSocket(KCommandSocket*, int)) ); commandSocket->readFile( syncFileName() ); } } void KSyncManager::deleteCommandSocket(KCommandSocket*s, int state) { //enum { success, errorW, errorR, quiet }; if ( state == KCommandSocket::errorR ||state == KCommandSocket::errorTO ||state == KCommandSocket::errorPW || state == KCommandSocket::errorCA ||state == KCommandSocket::errorFI ||state == KCommandSocket::errorUN||state == KCommandSocket::errorED ) { if ( state == KCommandSocket::errorPW ) mParent->topLevelWidget()->setCaption( i18n("Wrong password: Receiving remote file failed.") ); else if ( state == KCommandSocket::errorR ||state == KCommandSocket::errorTO ) mParent->topLevelWidget()->setCaption( i18n("ERROR: Receiving remote file failed.") ); else if ( state == KCommandSocket::errorCA ) mParent->topLevelWidget()->setCaption( i18n("Sync cancelled from remote.") ); else if ( state == KCommandSocket::errorFI ) mParent->topLevelWidget()->setCaption( i18n("File error on remote.") ); else if ( state == KCommandSocket::errorED ) mParent->topLevelWidget()->setCaption( i18n("Please close error dialog on remote.") ); else if ( state == KCommandSocket::errorUN ) mParent->topLevelWidget()->setCaption( i18n("Unknown error on remote.") ); delete s; if ( state == KCommandSocket::errorR ) { KCommandSocket* commandSocket = new KCommandSocket( "",mPassWordPiSync, mActiveSyncPort.toUInt(), mActiveSyncIP, this, mParent->topLevelWidget()); connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int)), this, SLOT(deleteCommandSocket(KCommandSocket*, int )) ); commandSocket->sendStop(); } mPisyncFinished = true; return; } else if ( state == KCommandSocket::errorW ) { mParent->topLevelWidget()->setCaption( i18n("ERROR:Writing back file failed.") ); mPisyncFinished = true; } else if ( state == KCommandSocket::successR ) { QTimer::singleShot( 1, this , SLOT ( readFileFromSocket())); } else if ( state == KCommandSocket::successW ) { mParent->topLevelWidget()->setCaption( i18n("Pi-Sync successful!") ); mPisyncFinished = true; } else if ( state == KCommandSocket::quiet ){ qDebug("KSS: quiet "); mPisyncFinished = true; } else { qDebug("KSS: Error: unknown state: %d ", state); mPisyncFinished = true; } delete s; } void KSyncManager::readFileFromSocket() { QString fileName = syncFileName(); bool syncOK = true; mParent->topLevelWidget()->setCaption( i18n("Remote file saved to temp file.") ); if ( ! syncWithFile( fileName , true ) ) { mParent->topLevelWidget()->setCaption( i18n("Syncing failed.") ); syncOK = false; } - KCommandSocket* commandSocket = new KCommandSocket( "",mPassWordPiSync, mActiveSyncPort.toUInt(), mActiveSyncIP, this, mParent->topLevelWidget() ); + KCommandSocket* commandSocket = new KCommandSocket( mCurrentResourceRemote,mPassWordPiSync, mActiveSyncPort.toUInt(), mActiveSyncIP, this, mParent->topLevelWidget() ); connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int)), this, SLOT(deleteCommandSocket(KCommandSocket*, int )) ); if ( mWriteBackFile && syncOK ) { mParent->topLevelWidget()->setCaption( i18n("Sending back file ...") ); commandSocket->writeFile( fileName ); } else { commandSocket->sendStop(); if ( syncOK ) mParent->topLevelWidget()->setCaption( i18n("Pi-Sync succesful!") ); mPisyncFinished = true; } } 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; mErrorMessage = 0; } void KServerSocket::newConnection ( int socket ) { // qDebug("KServerSocket:New connection %d ", socket); if ( mSocket ) { qDebug("KSS::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() { QTimer::singleShot( 10, this , SLOT ( deleteSocket())); } void KServerSocket::deleteSocket() { qDebug("KSS::deleteSocket"); if ( mSocket ) { delete mSocket; mSocket = 0; } if ( mErrorMessage ) QTimer::singleShot( 10, this , SLOT ( displayErrorMessage())); } void KServerSocket::readClient() { if ( blockRC ) return; if ( mSocket == 0 ) { qDebug("ERROR::KSS::readClient(): mSocket == 0 "); return; } if ( mErrorMessage ) { mErrorMessage = 999; error_connect("ERROR_ED\r\n\r\n"); return; } + mResource = ""; mErrorMessage = 0; //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 ); bool ok = false; QDateTime dt = KGlobal::locale()->readDateTime( tokens[2], KLocale::ISODate, &ok); if ( ok ) { KSyncManager::mRequestedSyncEvent = dt; } else KSyncManager::mRequestedSyncEvent = QDateTime(); + mResource =tokens[3]; send_file(); } else { mErrorMessage = 1; error_connect("ERROR_PW\r\n\r\n"); } } if ( tokens[0] == "PUT" ) { if ( tokens[1] == mPassWord ) { //emit getFile( mSocket ); blockRC = true; + mResource =tokens[2]; get_file(); } else { mErrorMessage = 2; error_connect("ERROR_PW\r\n\r\n"); end_connect(); } } if ( tokens[0] == "STOP" ) { //emit endConnect(); end_connect(); } } } void KServerSocket::displayErrorMessage() { if ( mErrorMessage == 1 ) { KMessageBox::error( 0, i18n("Got send file request\nwith invalid password"), i18n("Pi-Sync Error")); mErrorMessage = 0; } else if ( mErrorMessage == 2 ) { KMessageBox::error( 0, i18n("Got receive file request\nwith invalid password"), i18n("Pi-Sync Error")); mErrorMessage = 0; } } void KServerSocket::error_connect( QString errmess ) { QTextStream os( mSocket ); os.setEncoding( QTextStream::Latin1 ); os << errmess ; mSocket->close(); if ( mSocket->state() == QSocket::Idle ) { QTimer::singleShot( 0, this , SLOT ( discardClient())); } } 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 ); label->setAlignment ( Qt::AlignHCenter ); QVBoxLayout* lay = new QVBoxLayout( mSyncActionDialog ); lay->addWidget( label); lay->setMargin(7); lay->setSpacing(7); if ( KSyncManager::mRequestedSyncEvent.isValid() ) { int secs = QDateTime::currentDateTime().secsTo( KSyncManager::mRequestedSyncEvent ); //secs = 333; if ( secs < 0 ) secs = secs * (-1); if ( secs > 30 ) //if ( true ) { QString warning = i18n("Clock skew of\nsyncing devices\nis %1 seconds!").arg( secs ); QLabel* label = new QLabel( warning, mSyncActionDialog ); label->setAlignment ( Qt::AlignHCenter ); lay->addWidget( label); if ( secs > 180 ) { if ( secs > 300 ) { if ( KMessageBox::Cancel == KMessageBox::warningContinueCancel(0, i18n("The clocks of the syncing\ndevices have a difference\nof more than 5 minutes.\nPlease adjust your clocks.\nYou may get wrong syncing results!\nPlease confirm synchronization!"), i18n("High clock skew!"),i18n("Synchronize!"))) { qDebug("KSS::Sync cancelled ,cs"); mErrorMessage = 0; end_connect(); error_connect("ERROR_CA\r\n\r\n"); return ; } } QFont f = label->font(); f.setPointSize ( f.pointSize() *2 ); f. setBold (true ); QLabel* label = new QLabel( warning, mSyncActionDialog ); label->setFont( f ); warning = i18n("ADJUST\nYOUR\nCLOCKS!"); label->setText( warning ); label->setAlignment ( Qt::AlignHCenter ); lay->addWidget( label); mSyncActionDialog->setFixedSize( 230, 300); } else { mSyncActionDialog->setFixedSize( 230, 200); } } else { mSyncActionDialog->setFixedSize( 230, 120); } } else mSyncActionDialog->setFixedSize( 230, 120); mSyncActionDialog->show(); mSyncActionDialog->raise(); + emit request_file(mResource); emit request_file(); qApp->processEvents(); QString fileName = mFileName; QFile file( fileName ); if (!file.open( IO_ReadOnly ) ) { mErrorMessage = 0; end_connect(); error_connect("ERROR_FI\r\n\r\n"); return ; } mSyncActionDialog->setCaption( i18n("Sending file...") ); QTextStream ts( &file ); ts.setEncoding( QTextStream::Latin1 ); QTextStream os( mSocket ); os.setEncoding( QTextStream::Latin1 ); while ( ! ts.atEnd() ) { os << ts.readLine() << "\r\n"; } os << "\r\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("KSS:Error open read back file "); piFileString = ""; - emit file_received( false ); + emit file_received( false, mResource); + emit file_received( false); blockRC = false; return ; } // mView->setLoadedFileVersion(QDateTime::currentDateTime().addSecs( -1)); QTextStream ts ( &file ); ts.setEncoding( QTextStream::Latin1 ); mSyncActionDialog->setCaption( i18n("Writing file to disk...") ); ts << piFileString; mSocket->close(); if ( mSocket->state() == QSocket::Idle ) QTimer::singleShot( 10, this , SLOT ( discardClient())); file.close(); piFileString = ""; - emit file_received( true ); + emit file_received( true, mResource ); + emit file_received( true); delete mSyncActionDialog; mSyncActionDialog = 0; blockRC = false; } KCommandSocket::KCommandSocket ( QString remres, QString password, Q_UINT16 port, QString host, QObject * parent, QWidget * cap, const char * name ): QObject( parent, name ) { mRemoteResource = remres; if ( mRemoteResource.isEmpty() ) mRemoteResource = "ALL"; mPassWord = password; mSocket = 0; mFirst = false; mFirstLine = true; mPort = port; mHost = host; tlw = cap; mRetVal = quiet; mTimerSocket = new QTimer ( this ); connect( mTimerSocket, SIGNAL ( timeout () ), this, SLOT ( updateConnectDialog() ) ); mConnectProgress.setCaption( i18n("Pi-Sync") ); connect( &mConnectProgress, SIGNAL ( cancelled () ), this, SLOT ( deleteSocket() ) ); mConnectCount = -1; } void KCommandSocket::sendFileRequest() { if ( tlw ) tlw->setCaption( i18n("Connected! Sending request for remote file ...") ); mConnectProgress.hide(); mConnectCount = 300;mConnectMax = 300; mConnectProgress.setCaption( i18n("Pi-Sync: Connected!") ); mTimerSocket->start( 100, true ); QTextStream os( mSocket ); os.setEncoding( QTextStream::Latin1 ); QString curDt = " " +KGlobal::locale()->formatDateTime(QDateTime::currentDateTime().addSecs(-1),true, true,KLocale::ISODate ); os << "GET " << mPassWord << curDt << mRemoteResource << "\r\n\r\n"; } 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()) ); connect( mSocket, SIGNAL(connected ()), this, SLOT(sendFileRequest() )); } @@ -1551,97 +1563,97 @@ void KCommandSocket::updateConnectDialog() mConnectProgress.show(); mConnectProgress.setLabelText( i18n("Trying to connect to remote...") ); } //qDebug("updateConnectDialog() %d", mConnectCount); mConnectProgress.raise(); mConnectProgress.setProgress( (mConnectMax - mConnectCount)%30 ); --mConnectCount; if ( mConnectCount > 0 ) mTimerSocket->start( 1000, true ); else deleteSocket(); } 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 ; mConnectCount = 30;mConnectMax = 30; mTimerSocket->start( 1000, true ); mSocket->connectToHost( mHost, mPort ); } void KCommandSocket::writeFileToSocket() { mTimerSocket->stop(); QFile file2( mFileName ); if (!file2.open( IO_ReadOnly ) ) { mConnectProgress.hide(); mConnectCount = -1; mRetVal= errorW; mSocket->close(); if ( mSocket->state() == QSocket::Idle ) QTimer::singleShot( 10, this , SLOT ( deleteSocket())); return ; } mConnectProgress.setTotalSteps ( file2.size() ); mConnectProgress.show(); int count = 0; mConnectProgress.setLabelText( i18n("Sending back synced file...") ); mConnectProgress.setProgress( count ); mConnectProgress.blockSignals( true ); QTextStream ts2( &file2 ); ts2.setEncoding( QTextStream::Latin1 ); QTextStream os2( mSocket ); os2.setEncoding( QTextStream::Latin1 ); - os2 << "PUT " << mPassWord << "\r\n\r\n";; + os2 << "PUT " << mPassWord << mRemoteResource << "\r\n\r\n";; int byteCount = 0; int byteMax = file2.size()/53; while ( ! ts2.atEnd() ) { qApp->processEvents(); if ( byteCount > byteMax ) { byteCount = 0; mConnectProgress.setProgress( count ); } QString temp = ts2.readLine(); count += temp.length(); byteCount += temp.length(); os2 << temp << "\r\n"; } file2.close(); mConnectProgress.hide(); mConnectCount = -1; os2 << "\r\n"; mRetVal= successW; mSocket->close(); if ( mSocket->state() == QSocket::Idle ) QTimer::singleShot( 10, this , SLOT ( deleteSocket())); mConnectProgress.blockSignals( false ); } void KCommandSocket::sendStop() { if ( !mSocket ) { mSocket = new QSocket( this ); connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) ); } mSocket->connectToHost( mHost, mPort ); QTextStream os2( mSocket ); os2.setEncoding( QTextStream::Latin1 ); os2 << "STOP\r\n\r\n"; mSocket->close(); if ( mSocket->state() == QSocket::Idle ) QTimer::singleShot( 10, this , SLOT ( deleteSocket())); } void KCommandSocket::startReadFileFromSocket() { if ( ! mFirst ) return; mConnectProgress.setLabelText( i18n("Receiving file from remote...") ); mFirst = false; mFileString = ""; mTime.start(); mFirstLine = true; QTimer::singleShot( 1, this , SLOT (readFileFromSocket( ) )); |