-rw-r--r-- | libkdepim/ksyncmanager.cpp | 94 | ||||
-rw-r--r-- | libkdepim/ksyncmanager.h | 7 |
2 files changed, 74 insertions, 27 deletions
diff --git a/libkdepim/ksyncmanager.cpp b/libkdepim/ksyncmanager.cpp index d8ca3ba..47d00a4 100644 --- a/libkdepim/ksyncmanager.cpp +++ b/libkdepim/ksyncmanager.cpp @@ -1065,21 +1065,31 @@ void KSyncManager::syncPi() 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 ) { + + + + if ( state == KCommandSocket::errorR ||state == KCommandSocket::errorTO ||state == KCommandSocket::errorPW || + state == KCommandSocket::errorCA ||state == KCommandSocket::errorFI ||state == KCommandSocket::errorUN ) { if ( state == KCommandSocket::errorPW ) mParent->topLevelWidget()->setCaption( i18n("Wrong password: Receiving remote file failed.") ); - else + 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::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; @@ -1127,16 +1137,17 @@ void KSyncManager::readFileFromSocket() } 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; @@ -1145,31 +1156,42 @@ void KServerSocket::newConnection ( int socket ) mSocket = new QSocket( this ); connect( mSocket , SIGNAL(readyRead()), this, SLOT(readClient()) ); connect( mSocket , SIGNAL(delayedCloseFinished()), this, SLOT(discardClient()) ); mSocket->setSocket( socket ); } void KServerSocket::discardClient() { - //qDebug(" KServerSocket::discardClient()"); + QTimer::singleShot( 10, this , SLOT ( deleteSocket())); +} +void KServerSocket::deleteSocket() +{ + qDebug("KSS::deleteSocket"); if ( mSocket ) { delete mSocket; mSocket = 0; } - //emit endConnect(); + 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_UN\r\n\r\n"); + return; + } + 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 ); @@ -1178,48 +1200,55 @@ void KServerSocket::readClient() if ( ok ) { KSyncManager::mRequestedSyncEvent = dt; } else KSyncManager::mRequestedSyncEvent = QDateTime(); send_file(); } else { - error_connect(); - KMessageBox::error( 0, i18n("Got send file request\nwith invalid password")); - //qDebug("password %s, invalid password %s ",mPassWord.latin1(), tokens[1].latin1() ); + mErrorMessage = 1; + error_connect("ERROR_PW\r\n\r\n"); } } if ( tokens[0] == "PUT" ) { if ( tokens[1] == mPassWord ) { //emit getFile( mSocket ); blockRC = true; get_file(); } else { - error_connect(); + mErrorMessage = 2; + error_connect("ERROR_PW\r\n\r\n"); end_connect(); - KMessageBox::error( 0, i18n("Got receive file request\nwith invalid password")); - //qDebug("password %s, invalid password %s ",mPassWord.latin1(), tokens[1].latin1() ); } } if ( tokens[0] == "STOP" ) { //emit endConnect(); end_connect(); } } } -void KServerSocket::error_connect() +void KServerSocket::displayErrorMessage() +{ + if ( mErrorMessage == 1 ) + KMessageBox::error( 0, i18n("Got send file request\nwith invalid password")); + else if ( mErrorMessage == 2 ) + KMessageBox::error( 0, i18n("Got receive file request\nwith invalid password")); + mErrorMessage = 0; +} +void KServerSocket::error_connect( QString errmess ) { QTextStream os( mSocket ); os.setEncoding( QTextStream::Latin1 ); - os << "ERROR_PW\r\n\r\n"; + os << errmess ; mSocket->close(); - if ( mSocket->state() == QSocket::Idle ) - QTimer::singleShot( 10, this , SLOT ( discardClient())); + if ( mSocket->state() == QSocket::Idle ) { + QTimer::singleShot( 0, this , SLOT ( discardClient())); + } } void KServerSocket::end_connect() { delete mSyncActionDialog; mSyncActionDialog = 0; } void KServerSocket::send_file() { @@ -1231,30 +1260,34 @@ void KServerSocket::send_file() 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"); + 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 ); @@ -1273,24 +1306,20 @@ void KServerSocket::send_file() mSyncActionDialog->setFixedSize( 230, 120); mSyncActionDialog->show(); mSyncActionDialog->raise(); emit request_file(); qApp->processEvents(); QString fileName = mFileName; QFile file( fileName ); if (!file.open( IO_ReadOnly ) ) { - delete mSyncActionDialog; - mSyncActionDialog = 0; - qDebug("KSS::error open sync file: %s ", fileName.latin1()); - mSocket->close(); - if ( mSocket->state() == QSocket::Idle ) - QTimer::singleShot( 10, this , SLOT ( discardClient())); - return ; - + 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() ) { @@ -1471,18 +1500,33 @@ void KCommandSocket::startReadFileFromSocket() void KCommandSocket::readFileFromSocket() { //qDebug("readBackFileFromSocket() %d ", mTime.elapsed ()); while ( mSocket->canReadLine () ) { mTime.restart(); QString line = mSocket->readLine (); if ( mFirstLine ) { mFirstLine = false; - if ( line.left( 8 ) == "ERROR_PW" ) { - mRetVal = errorPW; + if ( line.left( 6 ) == "ERROR_" ) { + 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 ; + } + mRetVal = errorUN; deleteSocket(); return ; } } mFileString += line; //qDebug("readline: %s ", line.latin1()); } if ( mTime.elapsed () < 3000 ) { diff --git a/libkdepim/ksyncmanager.h b/libkdepim/ksyncmanager.h index 810a515..bd3ecdc 100644 --- a/libkdepim/ksyncmanager.h +++ b/libkdepim/ksyncmanager.h @@ -50,37 +50,40 @@ class KServerSocket : public QServerSocket void setFileName( QString fn ) {mFileName = fn;}; signals: void file_received( bool ); void request_file(); void saveFile(); void endConnect(); private slots: void discardClient(); + void deleteSocket(); void readClient(); + void displayErrorMessage(); void readBackFileFromSocket(); private : + int mErrorMessage; bool blockRC; void send_file(); void get_file(); void end_connect(); - void error_connect(); + void error_connect( QString ); QDialog* mSyncActionDialog; QSocket* mSocket; QString mPassWord; QString mFileName; QTime piTime; QString piFileString; }; class KCommandSocket : public QObject { Q_OBJECT public: - enum state { successR, errorR, successW, errorW, errorTO, errorPW,quiet }; + enum state { successR, errorR, successW, errorW, errorTO, errorPW, errorCA, errorFI, errorUN,quiet }; KCommandSocket ( QString password, Q_UINT16 port, QString host, QObject * parent=0, QWidget* cap = 0, const char * name=0 ); void readFile( QString ); void writeFile( QString ); void sendStop(); private slots : void sendFileRequest(); |