author | zautrix <zautrix> | 2005-07-08 23:55:16 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2005-07-08 23:55:16 (UTC) |
commit | 1e11d41ecb6a912c4c0a2747eb1fa26626fdcca2 (patch) (side-by-side diff) | |
tree | 922c8080f9b9cc863e7d5637a5d9d775ee8c0355 /libkdepim/ksyncmanager.cpp | |
parent | 3e94cf2e8a14c7d40aea28a0fe5538abcd211746 (diff) | |
download | kdepimpi-1e11d41ecb6a912c4c0a2747eb1fa26626fdcca2.zip kdepimpi-1e11d41ecb6a912c4c0a2747eb1fa26626fdcca2.tar.gz kdepimpi-1e11d41ecb6a912c4c0a2747eb1fa26626fdcca2.tar.bz2 |
fixxx
-rw-r--r-- | libkdepim/ksyncmanager.cpp | 95 |
1 files changed, 77 insertions, 18 deletions
diff --git a/libkdepim/ksyncmanager.cpp b/libkdepim/ksyncmanager.cpp index fc0ac6b..f2ee0ab 100644 --- a/libkdepim/ksyncmanager.cpp +++ b/libkdepim/ksyncmanager.cpp @@ -350,13 +350,13 @@ void KSyncManager::enableQuick( bool ask ) 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 ); + QLabel label ( i18n("Port number (Default: %1)\nValid range from 1 to 65535").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 ); @@ -412,34 +412,39 @@ void KSyncManager::enableQuick( bool ask ) 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")); + 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() ) { - KMessageBox::information( 0, i18n("Failed to bind or\nlisten to the port!")); + 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 ) ) ); } - +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; @@ -793,13 +798,13 @@ bool KSyncManager::edit_pisync_options() QLineEdit le1 (&dia ); lay.addWidget( &le1 ); QLabel lab2 ( i18n("Remote IP address:"), &dia); lay.addWidget( &lab2 ); QLineEdit le2 (&dia ); lay.addWidget( &le2 ); - QLabel lab3 ( i18n("Remote port number:"), &dia); + QLabel lab3 ( i18n("Remote port number:\n(May be: 1 - 65535)"), &dia); lay.addWidget( &lab3 ); QLineEdit le3 (&dia ); lay.addWidget( &le3 ); QPushButton pb ( "OK", &dia); lay.addWidget( &pb ); connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) ); @@ -1185,14 +1190,16 @@ void KSyncManager::readFileFromSocket() if ( ! syncWithFile( fileName , true ) ) { mParent->topLevelWidget()->setCaption( i18n("Syncing failed.") ); syncOK = false; } KCommandSocket* commandSocket = new KCommandSocket( mPassWordPiSync, mActiveSyncPort.toUInt(), mActiveSyncIP, this, mParent->topLevelWidget() ); connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int)), this, SLOT(deleteCommandSocket(KCommandSocket*, int )) ); - if ( mWriteBackFile && syncOK ) + 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; } @@ -1289,17 +1296,17 @@ void KServerSocket::readClient() } } } void KServerSocket::displayErrorMessage() { if ( mErrorMessage == 1 ) { - KMessageBox::error( 0, i18n("Got send file request\nwith invalid password")); + 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")); + 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 ); @@ -1463,19 +1470,25 @@ KCommandSocket::KCommandSocket ( QString password, Q_UINT16 port, QString host, mFirstLine = true; mPort = port; mHost = host; tlw = cap; mRetVal = quiet; mTimerSocket = new QTimer ( this ); - connect( mTimerSocket, SIGNAL ( timeout () ), this, SLOT ( deleteSocket() ) ); + 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 ...") ); - mTimerSocket->start( 300000 ); + 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"; } @@ -1490,53 +1503,88 @@ void KCommandSocket::readFile( QString fn ) } mFileString = ""; mFileName = fn; mFirst = true; if ( tlw ) tlw->setCaption( i18n("Trying to connect to remote...") ); - mTimerSocket->start( 20000 ); + 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 ; - mTimerSocket->start( 20000 ); + 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";; while ( ! ts2.atEnd() ) { - os2 << ts2.readLine() << "\r\n"; + qApp->processEvents(); + mConnectProgress.setProgress( count ); + QString temp = ts2.readLine(); + count += temp.length(); + os2 << temp << "\r\n"; } + file2.close(); + mConnectProgress.hide(); + mConnectCount = -1; os2 << "\r\n"; mRetVal= successW; - file2.close(); 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()) ); @@ -1551,14 +1599,14 @@ void KCommandSocket::sendStop() } void KCommandSocket::startReadFileFromSocket() { if ( ! mFirst ) return; + mConnectProgress.setLabelText( i18n("Receiving file from remote...") ); mFirst = false; - mTimerSocket->stop(); mFileString = ""; mTime.start(); mFirstLine = true; QTimer::singleShot( 1, this , SLOT (readFileFromSocket( ) )); } @@ -1568,12 +1616,14 @@ void KCommandSocket::readFileFromSocket() 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" ) { @@ -1602,12 +1652,15 @@ void KCommandSocket::readFileFromSocket() 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() ); @@ -1629,27 +1682,33 @@ void KCommandSocket::readFileFromSocket() deleteSocket(); } void KCommandSocket::deleteSocket() { //qDebug("KCommandSocket::deleteSocket() "); - if ( mTimerSocket->isActive () ) { + 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 ) KMessageBox::error( 0, i18n("Connection to remote\nhost timed out!\nDid you forgot to enable\nsyncing on remote host?")); + else if ( tlw ) + tlw->setCaption( i18n("Connection to remote host cancelled!") ); emit commandFinished( this, mRetVal ); return; } //qDebug("KCommandSocket::deleteSocket() %d", mRetVal ); if ( mSocket) delete mSocket; mSocket = 0; + qDebug("commandFinished "); emit commandFinished( this, mRetVal ); } |