-rw-r--r-- | libkdepim/ksyncmanager.cpp | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/libkdepim/ksyncmanager.cpp b/libkdepim/ksyncmanager.cpp index f2ee0ab..2a75bfb 100644 --- a/libkdepim/ksyncmanager.cpp +++ b/libkdepim/ksyncmanager.cpp @@ -1441,261 +1441,267 @@ void KServerSocket::readBackFileFromSocket() piFileString = ""; 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 ); delete mSyncActionDialog; mSyncActionDialog = 0; blockRC = false; } KCommandSocket::KCommandSocket ( QString password, Q_UINT16 port, QString host, QObject * parent, QWidget * cap, const char * name ): QObject( parent, name ) { 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 <<"\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() )); } mFileString = ""; mFileName = fn; mFirst = true; if ( tlw ) tlw->setCaption( i18n("Trying to connect to remote...") ); mConnectCount = 30;mConnectMax = 30; mTimerSocket->start( 1000, true ); mSocket->connectToHost( mHost, mPort ); qDebug("KSS: Waiting for connection"); } void KCommandSocket::updateConnectDialog() { if ( mConnectCount == mConnectMax ) { //qDebug("MAXX %d", mConnectMax); mConnectProgress.setTotalSteps ( 30 ); 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";; + int byteCount = 0; + int byteMax = file2.size()/53; while ( ! ts2.atEnd() ) { qApp->processEvents(); - mConnectProgress.setProgress( count ); + 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( ) )); } void KCommandSocket::readFileFromSocket() { //qDebug("readBackFileFromSocket() %d ", mTime.elapsed ()); while ( mSocket->canReadLine () ) { mTime.restart(); QString line = mSocket->readLine (); if ( mFirstLine ) { mFirstLine = false; if ( line.left( 6 ) == "ERROR_" ) { mTimerSocket->stop(); mConnectCount = -1; if ( line.left( 8 ) == "ERROR_PW" ) { mRetVal = errorPW; deleteSocket(); return ; } if ( line.left( 8 ) == "ERROR_CA" ) { mRetVal = errorCA; deleteSocket(); return ; } if ( line.left( 8 ) == "ERROR_FI" ) { mRetVal = errorFI; deleteSocket(); return ; } if ( line.left( 8 ) == "ERROR_ED" ) { mRetVal = errorED; deleteSocket(); return ; } mRetVal = errorUN; deleteSocket(); return ; } } mFileString += line; //qDebug("readline: %s ", line.latin1()); } if ( mTime.elapsed () < 3000 ) { // wait for more //qDebug("waitformore "); QTimer::singleShot( 100, this , SLOT (readFileFromSocket( ) )); return; } mTimerSocket->stop(); mConnectCount = -1; mConnectProgress.hide(); QString fileName = mFileName; QFile file ( fileName ); if (!file.open( IO_WriteOnly ) ) { mFileString = ""; mRetVal = errorR; qDebug("KSS:Error open temp sync file for writing: %s",fileName.latin1() ); deleteSocket(); return ; } // mView->setLoadedFileVersion(QDateTime::currentDateTime().addSecs( -1)); QTextStream ts ( &file ); ts.setEncoding( QTextStream::Latin1 ); 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() { //qDebug("KCommandSocket::deleteSocket() "); mConnectProgress.hide(); if ( mConnectCount >= 0 ) { mTimerSocket->stop(); mRetVal = errorTO; qDebug("KCS::Connection to remote host timed out"); if ( mSocket ) { mSocket->close(); //if ( mSocket->state() == QSocket::Idle ) // deleteSocket(); delete mSocket; mSocket = 0; } if ( mConnectCount == 0 ) |