-rw-r--r-- | libkdepim/ksyncmanager.cpp | 97 |
1 files changed, 78 insertions, 19 deletions
diff --git a/libkdepim/ksyncmanager.cpp b/libkdepim/ksyncmanager.cpp index fc0ac6b..f2ee0ab 100644 --- a/libkdepim/ksyncmanager.cpp +++ b/libkdepim/ksyncmanager.cpp @@ -354,5 +354,5 @@ void KSyncManager::enableQuick( bool ask ) 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); @@ -416,14 +416,16 @@ void KSyncManager::enableQuick( bool ask ) 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; @@ -437,5 +439,8 @@ void KSyncManager::enableQuick( bool ask ) 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() { @@ -797,5 +802,5 @@ bool KSyncManager::edit_pisync_options() 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 ); @@ -1189,6 +1194,8 @@ void KSyncManager::readFileFromSocket() 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(); @@ -1293,9 +1300,9 @@ 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; } @@ -1467,5 +1474,8 @@ KCommandSocket::KCommandSocket ( QString password, Q_UINT16 port, QString host, 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() @@ -1473,5 +1483,8 @@ 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 ); @@ -1494,9 +1507,28 @@ void KCommandSocket::readFile( QString fn ) 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 ) { @@ -1507,5 +1539,6 @@ void KCommandSocket::writeFile( QString fileName ) } mFileName = fileName ; - mTimerSocket->start( 20000 ); + mConnectCount = 30;mConnectMax = 30; + mTimerSocket->start( 1000, true ); mSocket->connectToHost( mHost, mPort ); } @@ -1515,4 +1548,6 @@ void KCommandSocket::writeFileToSocket() QFile file2( mFileName ); if (!file2.open( IO_ReadOnly ) ) { + mConnectProgress.hide(); + mConnectCount = -1; mRetVal= errorW; mSocket->close(); @@ -1521,4 +1556,10 @@ void KCommandSocket::writeFileToSocket() 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 ); @@ -1527,12 +1568,19 @@ void KCommandSocket::writeFileToSocket() 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() @@ -1555,6 +1603,6 @@ void KCommandSocket::startReadFileFromSocket() if ( ! mFirst ) return; + mConnectProgress.setLabelText( i18n("Receiving file from remote...") ); mFirst = false; - mTimerSocket->stop(); mFileString = ""; mTime.start(); @@ -1572,4 +1620,6 @@ void KCommandSocket::readFileFromSocket() mFirstLine = false; if ( line.left( 6 ) == "ERROR_" ) { + mTimerSocket->stop(); + mConnectCount = -1; if ( line.left( 8 ) == "ERROR_PW" ) { mRetVal = errorPW; @@ -1606,4 +1656,7 @@ void KCommandSocket::readFileFromSocket() return; } + mTimerSocket->stop(); + mConnectCount = -1; + mConnectProgress.hide(); QString fileName = mFileName; QFile file ( fileName ); @@ -1633,5 +1686,7 @@ void KCommandSocket::deleteSocket() { //qDebug("KCommandSocket::deleteSocket() "); - if ( mTimerSocket->isActive () ) { + mConnectProgress.hide(); + + if ( mConnectCount >= 0 ) { mTimerSocket->stop(); mRetVal = errorTO; @@ -1644,5 +1699,8 @@ void KCommandSocket::deleteSocket() 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; @@ -1652,4 +1710,5 @@ void KCommandSocket::deleteSocket() delete mSocket; mSocket = 0; + qDebug("commandFinished "); emit commandFinished( this, mRetVal ); } |