summaryrefslogtreecommitdiffabout
path: root/libkdepim
Side-by-side diff
Diffstat (limited to 'libkdepim') (more/less context) (ignore whitespace changes)
-rw-r--r--libkdepim/ksyncmanager.cpp97
-rw-r--r--libkdepim/ksyncmanager.h6
2 files changed, 84 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
@@ -352,9 +352,9 @@ void KSyncManager::enableQuick( bool ask )
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 );
@@ -414,18 +414,20 @@ void KSyncManager::enableQuick( bool ask )
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;
}
@@ -435,9 +437,12 @@ void KSyncManager::enableQuick( bool ask )
}
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;
@@ -795,9 +800,9 @@ bool KSyncManager::edit_pisync_options()
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);
@@ -1187,10 +1192,12 @@ void KSyncManager::readFileFromSocket()
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!") );
@@ -1291,13 +1298,13 @@ 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 )
@@ -1465,15 +1472,21 @@ KCommandSocket::KCommandSocket ( QString password, Q_UINT16 port, QString host,
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 );
@@ -1492,49 +1505,84 @@ void KCommandSocket::readFile( QString fn )
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 ) {
@@ -1553,10 +1601,10 @@ 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( ) ));
@@ -1570,8 +1618,10 @@ void KCommandSocket::readFileFromSocket()
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 ;
@@ -1604,8 +1654,11 @@ void KCommandSocket::readFileFromSocket()
//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 = "";
@@ -1631,9 +1684,11 @@ void KCommandSocket::readFileFromSocket()
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 ) {
@@ -1642,14 +1697,18 @@ void KCommandSocket::deleteSocket()
// 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 );
}
diff --git a/libkdepim/ksyncmanager.h b/libkdepim/ksyncmanager.h
index 30ec1e6..e6738b6 100644
--- a/libkdepim/ksyncmanager.h
+++ b/libkdepim/ksyncmanager.h
@@ -28,8 +28,9 @@
#include <qdatetime.h>
#include <qserversocket.h>
#include <qtextstream.h>
#include <qregexp.h>
+#include <qprogressdialog.h>
class QPopupMenu;
class KSyncProfile;
class KPimPrefs;
@@ -85,8 +86,9 @@ class KCommandSocket : public QObject
void sendStop();
private slots :
void sendFileRequest();
+ void updateConnectDialog();
signals:
void commandFinished( KCommandSocket*, int );
private slots:
@@ -94,8 +96,11 @@ class KCommandSocket : public QObject
void readFileFromSocket();
void deleteSocket();
void writeFileToSocket();
private :
+ int mConnectCount;
+ int mConnectMax;
+ QProgressDialog mConnectProgress;
QWidget* tlw;
QSocket* mSocket;
QString mPassWord;
Q_UINT16 mPort;
@@ -204,8 +209,9 @@ class KSyncManager : public QObject
QProgressBar* bar;
bool mSyncWithDesktop;
private slots:
+ void displayErrorPort();
void confSync();
};