author | zautrix <zautrix> | 2005-02-09 12:21:39 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2005-02-09 12:21:39 (UTC) |
commit | 940cdd0fd1349e7f8e53adff0595c1d946322ef1 (patch) (unidiff) | |
tree | 1a78f2c862afbc0d3c019c0905775782c906df64 /libkdepim | |
parent | 968099947455adc0e8681aedf8c161327e311f38 (diff) | |
download | kdepimpi-940cdd0fd1349e7f8e53adff0595c1d946322ef1.zip kdepimpi-940cdd0fd1349e7f8e53adff0595c1d946322ef1.tar.gz kdepimpi-940cdd0fd1349e7f8e53adff0595c1d946322ef1.tar.bz2 |
pisync fixes
-rw-r--r-- | libkdepim/ksyncmanager.cpp | 45 | ||||
-rw-r--r-- | libkdepim/ksyncmanager.h | 6 |
2 files changed, 33 insertions, 18 deletions
diff --git a/libkdepim/ksyncmanager.cpp b/libkdepim/ksyncmanager.cpp index df5a0d9..1f5f4c7 100644 --- a/libkdepim/ksyncmanager.cpp +++ b/libkdepim/ksyncmanager.cpp | |||
@@ -1047,30 +1047,29 @@ void KSyncManager::syncPi() | |||
1047 | return; | 1047 | return; |
1048 | } | 1048 | } |
1049 | bool ok; | 1049 | bool ok; |
1050 | Q_UINT16 port = mActiveSyncPort.toUInt(&ok); | 1050 | Q_UINT16 port = mActiveSyncPort.toUInt(&ok); |
1051 | if ( ! ok ) { | 1051 | if ( ! ok ) { |
1052 | mParent->topLevelWidget()->setCaption( i18n("Sorry, no valid port.Syncing cancelled.") ); | 1052 | mParent->topLevelWidget()->setCaption( i18n("Sorry, no valid port.Syncing cancelled.") ); |
1053 | return; | 1053 | return; |
1054 | } | 1054 | } |
1055 | KCommandSocket* commandSocket = new KCommandSocket( mPassWordPiSync, port, mActiveSyncIP, this ); | 1055 | KCommandSocket* commandSocket = new KCommandSocket( mPassWordPiSync, port, mActiveSyncIP, this, mParent->topLevelWidget() ); |
1056 | connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int )), this, SLOT(deleteCommandSocket(KCommandSocket*, int)) ); | 1056 | connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int )), this, SLOT(deleteCommandSocket(KCommandSocket*, int)) ); |
1057 | mParent->topLevelWidget()->setCaption( i18n("Sending request for remote file ...") ); | ||
1058 | commandSocket->readFile( syncFileName() ); | 1057 | commandSocket->readFile( syncFileName() ); |
1059 | } | 1058 | } |
1060 | 1059 | ||
1061 | void KSyncManager::deleteCommandSocket(KCommandSocket*s, int state) | 1060 | void KSyncManager::deleteCommandSocket(KCommandSocket*s, int state) |
1062 | { | 1061 | { |
1063 | //enum { success, errorW, errorR, quiet }; | 1062 | //enum { success, errorW, errorR, quiet }; |
1064 | if ( state == KCommandSocket::errorR ||state == KCommandSocket::errorTO ) { | 1063 | if ( state == KCommandSocket::errorR ||state == KCommandSocket::errorTO ) { |
1065 | mParent->topLevelWidget()->setCaption( i18n("ERROR: Receiving remote file failed.") ); | 1064 | mParent->topLevelWidget()->setCaption( i18n("ERROR: Receiving remote file failed.") ); |
1066 | delete s; | 1065 | delete s; |
1067 | if ( state == KCommandSocket::errorR ) { | 1066 | if ( state == KCommandSocket::errorR ) { |
1068 | KCommandSocket* commandSocket = new KCommandSocket( mPassWordPiSync, mActiveSyncPort.toUInt(), mActiveSyncIP, this ); | 1067 | KCommandSocket* commandSocket = new KCommandSocket( mPassWordPiSync, mActiveSyncPort.toUInt(), mActiveSyncIP, this, mParent->topLevelWidget()); |
1069 | connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int)), this, SLOT(deleteCommandSocket(KCommandSocket*, int )) ); | 1068 | connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int)), this, SLOT(deleteCommandSocket(KCommandSocket*, int )) ); |
1070 | commandSocket->sendStop(); | 1069 | commandSocket->sendStop(); |
1071 | } | 1070 | } |
1072 | mPisyncFinished = true; | 1071 | mPisyncFinished = true; |
1073 | return; | 1072 | return; |
1074 | 1073 | ||
1075 | } else if ( state == KCommandSocket::errorW ) { | 1074 | } else if ( state == KCommandSocket::errorW ) { |
1076 | mParent->topLevelWidget()->setCaption( i18n("ERROR:Writing back file failed.") ); | 1075 | mParent->topLevelWidget()->setCaption( i18n("ERROR:Writing back file failed.") ); |
@@ -1091,17 +1090,17 @@ void KSyncManager::readFileFromSocket() | |||
1091 | { | 1090 | { |
1092 | QString fileName = syncFileName(); | 1091 | QString fileName = syncFileName(); |
1093 | mParent->topLevelWidget()->setCaption( i18n("Remote file saved to temp file.") ); | 1092 | mParent->topLevelWidget()->setCaption( i18n("Remote file saved to temp file.") ); |
1094 | if ( ! syncWithFile( fileName , true ) ) { | 1093 | if ( ! syncWithFile( fileName , true ) ) { |
1095 | mParent->topLevelWidget()->setCaption( i18n("Syncing failed.") ); | 1094 | mParent->topLevelWidget()->setCaption( i18n("Syncing failed.") ); |
1096 | mPisyncFinished = true; | 1095 | mPisyncFinished = true; |
1097 | return; | 1096 | return; |
1098 | } | 1097 | } |
1099 | KCommandSocket* commandSocket = new KCommandSocket( mPassWordPiSync, mActiveSyncPort.toUInt(), mActiveSyncIP, this ); | 1098 | KCommandSocket* commandSocket = new KCommandSocket( mPassWordPiSync, mActiveSyncPort.toUInt(), mActiveSyncIP, this, mParent->topLevelWidget() ); |
1100 | connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int)), this, SLOT(deleteCommandSocket(KCommandSocket*, int )) ); | 1099 | connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int)), this, SLOT(deleteCommandSocket(KCommandSocket*, int )) ); |
1101 | if ( mWriteBackFile ) | 1100 | if ( mWriteBackFile ) |
1102 | commandSocket->writeFile( fileName ); | 1101 | commandSocket->writeFile( fileName ); |
1103 | else { | 1102 | else { |
1104 | commandSocket->sendStop(); | 1103 | commandSocket->sendStop(); |
1105 | mParent->topLevelWidget()->setCaption( i18n("Pi-Sync succesful!") ); | 1104 | mParent->topLevelWidget()->setCaption( i18n("Pi-Sync succesful!") ); |
1106 | mPisyncFinished = true; | 1105 | mPisyncFinished = true; |
1107 | } | 1106 | } |
@@ -1258,17 +1257,17 @@ void KServerSocket::send_file() | |||
1258 | } | 1257 | } |
1259 | mSyncActionDialog->setCaption( i18n("Sending file...") ); | 1258 | mSyncActionDialog->setCaption( i18n("Sending file...") ); |
1260 | QTextStream ts( &file ); | 1259 | QTextStream ts( &file ); |
1261 | ts.setEncoding( QTextStream::Latin1 ); | 1260 | ts.setEncoding( QTextStream::Latin1 ); |
1262 | 1261 | ||
1263 | QTextStream os( mSocket ); | 1262 | QTextStream os( mSocket ); |
1264 | os.setEncoding( QTextStream::Latin1 ); | 1263 | os.setEncoding( QTextStream::Latin1 ); |
1265 | while ( ! ts.atEnd() ) { | 1264 | while ( ! ts.atEnd() ) { |
1266 | os << ts.readLine() << "\r\n"; | 1265 | os << ts.readLine() << "\r\n\r\n"; |
1267 | } | 1266 | } |
1268 | //os << ts.read(); | 1267 | //os << ts.read(); |
1269 | file.close(); | 1268 | file.close(); |
1270 | mSyncActionDialog->setCaption( i18n("Waiting for synced file...") ); | 1269 | mSyncActionDialog->setCaption( i18n("Waiting for synced file...") ); |
1271 | mSocket->close(); | 1270 | mSocket->close(); |
1272 | if ( mSocket->state() == QSocket::Idle ) | 1271 | if ( mSocket->state() == QSocket::Idle ) |
1273 | QTimer::singleShot( 10, this , SLOT ( discardClient())); | 1272 | QTimer::singleShot( 10, this , SLOT ( discardClient())); |
1274 | } | 1273 | } |
@@ -1324,44 +1323,56 @@ void KServerSocket::readBackFileFromSocket() | |||
1324 | piFileString = ""; | 1323 | piFileString = ""; |
1325 | emit file_received( true ); | 1324 | emit file_received( true ); |
1326 | delete mSyncActionDialog; | 1325 | delete mSyncActionDialog; |
1327 | mSyncActionDialog = 0; | 1326 | mSyncActionDialog = 0; |
1328 | blockRC = false; | 1327 | blockRC = false; |
1329 | 1328 | ||
1330 | } | 1329 | } |
1331 | 1330 | ||
1332 | KCommandSocket::KCommandSocket ( QString password, Q_UINT16 port, QString host, QObject * parent, const char * name ): QObject( parent, name ) | 1331 | KCommandSocket::KCommandSocket ( QString password, Q_UINT16 port, QString host, QObject * parent, QWidget * cap, const char * name ): QObject( parent, name ) |
1333 | { | 1332 | { |
1334 | mPassWord = password; | 1333 | mPassWord = password; |
1335 | mSocket = 0; | 1334 | mSocket = 0; |
1335 | mFirst = false; | ||
1336 | mPort = port; | 1336 | mPort = port; |
1337 | mHost = host; | 1337 | mHost = host; |
1338 | 1338 | tlw = cap; | |
1339 | mRetVal = quiet; | 1339 | mRetVal = quiet; |
1340 | mTimerSocket = new QTimer ( this ); | 1340 | mTimerSocket = new QTimer ( this ); |
1341 | connect( mTimerSocket, SIGNAL ( timeout () ), this, SLOT ( deleteSocket() ) ); | 1341 | connect( mTimerSocket, SIGNAL ( timeout () ), this, SLOT ( deleteSocket() ) ); |
1342 | } | 1342 | } |
1343 | void KCommandSocket::sendFileRequest() | ||
1344 | { | ||
1345 | if ( tlw ) | ||
1346 | tlw->setCaption( i18n("Connected! Sending request for remote file ...") ); | ||
1347 | mTimerSocket->start( 300000 ); | ||
1348 | QTextStream os( mSocket ); | ||
1349 | os.setEncoding( QTextStream::Latin1 ); | ||
1350 | |||
1351 | QString curDt = " " +KGlobal::locale()->formatDateTime(QDateTime::currentDateTime().addSecs(-1),true, true,KLocale::ISODate ); | ||
1352 | os << "GET " << mPassWord << curDt <<"\r\n\r\n"; | ||
1353 | } | ||
1354 | |||
1343 | void KCommandSocket::readFile( QString fn ) | 1355 | void KCommandSocket::readFile( QString fn ) |
1344 | { | 1356 | { |
1345 | if ( !mSocket ) { | 1357 | if ( !mSocket ) { |
1346 | mSocket = new QSocket( this ); | 1358 | mSocket = new QSocket( this ); |
1347 | connect( mSocket, SIGNAL(readyRead()), this, SLOT(startReadFileFromSocket()) ); | 1359 | connect( mSocket, SIGNAL(readyRead()), this, SLOT(startReadFileFromSocket()) ); |
1348 | connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) ); | 1360 | connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) ); |
1361 | connect( mSocket, SIGNAL(connected ()), this, SLOT(sendFileRequest() )); | ||
1349 | } | 1362 | } |
1350 | mFileString = ""; | 1363 | mFileString = ""; |
1351 | mFileName = fn; | 1364 | mFileName = fn; |
1352 | mFirst = true; | 1365 | mFirst = true; |
1366 | if ( tlw ) | ||
1367 | tlw->setCaption( i18n("Trying to connect to remote...") ); | ||
1353 | mSocket->connectToHost( mHost, mPort ); | 1368 | mSocket->connectToHost( mHost, mPort ); |
1354 | QTextStream os( mSocket ); | 1369 | qDebug("KSS: Waiting for connection"); |
1355 | os.setEncoding( QTextStream::Latin1 ); | 1370 | mTimerSocket->start( 20000 ); |
1356 | |||
1357 | QString curDt = " " +KGlobal::locale()->formatDateTime(QDateTime::currentDateTime().addSecs(-1),true, true,KLocale::ISODate ); | ||
1358 | os << "GET " << mPassWord << curDt <<"\r\n"; | ||
1359 | mTimerSocket->start( 300000 ); | ||
1360 | } | 1371 | } |
1361 | 1372 | ||
1362 | void KCommandSocket::writeFile( QString fileName ) | 1373 | void KCommandSocket::writeFile( QString fileName ) |
1363 | { | 1374 | { |
1364 | if ( !mSocket ) { | 1375 | if ( !mSocket ) { |
1365 | mSocket = new QSocket( this ); | 1376 | mSocket = new QSocket( this ); |
1366 | connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) ); | 1377 | connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) ); |
1367 | connect( mSocket, SIGNAL(connected ()), this, SLOT(writeFileToSocket()) ); | 1378 | connect( mSocket, SIGNAL(connected ()), this, SLOT(writeFileToSocket()) ); |
@@ -1378,36 +1389,36 @@ void KCommandSocket::writeFileToSocket() | |||
1378 | if ( mSocket->state() == QSocket::Idle ) | 1389 | if ( mSocket->state() == QSocket::Idle ) |
1379 | QTimer::singleShot( 10, this , SLOT ( deleteSocket())); | 1390 | QTimer::singleShot( 10, this , SLOT ( deleteSocket())); |
1380 | return ; | 1391 | return ; |
1381 | } | 1392 | } |
1382 | QTextStream ts2( &file2 ); | 1393 | QTextStream ts2( &file2 ); |
1383 | ts2.setEncoding( QTextStream::Latin1 ); | 1394 | ts2.setEncoding( QTextStream::Latin1 ); |
1384 | QTextStream os2( mSocket ); | 1395 | QTextStream os2( mSocket ); |
1385 | os2.setEncoding( QTextStream::Latin1 ); | 1396 | os2.setEncoding( QTextStream::Latin1 ); |
1386 | os2 << "PUT " << mPassWord << "\r\n";; | 1397 | os2 << "PUT " << mPassWord << "\r\n\r\n";; |
1387 | while ( ! ts2.atEnd() ) { | 1398 | while ( ! ts2.atEnd() ) { |
1388 | os2 << ts2.readLine() << "\r\n"; | 1399 | os2 << ts2.readLine() << "\r\n\r\n"; |
1389 | } | 1400 | } |
1390 | mRetVal= successW; | 1401 | mRetVal= successW; |
1391 | file2.close(); | 1402 | file2.close(); |
1392 | mSocket->close(); | 1403 | mSocket->close(); |
1393 | if ( mSocket->state() == QSocket::Idle ) | 1404 | if ( mSocket->state() == QSocket::Idle ) |
1394 | QTimer::singleShot( 10, this , SLOT ( deleteSocket())); | 1405 | QTimer::singleShot( 10, this , SLOT ( deleteSocket())); |
1395 | } | 1406 | } |
1396 | void KCommandSocket::sendStop() | 1407 | void KCommandSocket::sendStop() |
1397 | { | 1408 | { |
1398 | if ( !mSocket ) { | 1409 | if ( !mSocket ) { |
1399 | mSocket = new QSocket( this ); | 1410 | mSocket = new QSocket( this ); |
1400 | connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) ); | 1411 | connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) ); |
1401 | } | 1412 | } |
1402 | mSocket->connectToHost( mHost, mPort ); | 1413 | mSocket->connectToHost( mHost, mPort ); |
1403 | QTextStream os2( mSocket ); | 1414 | QTextStream os2( mSocket ); |
1404 | os2.setEncoding( QTextStream::Latin1 ); | 1415 | os2.setEncoding( QTextStream::Latin1 ); |
1405 | os2 << "STOP\r\n"; | 1416 | os2 << "STOP\r\n\r\n"; |
1406 | mSocket->close(); | 1417 | mSocket->close(); |
1407 | if ( mSocket->state() == QSocket::Idle ) | 1418 | if ( mSocket->state() == QSocket::Idle ) |
1408 | QTimer::singleShot( 10, this , SLOT ( deleteSocket())); | 1419 | QTimer::singleShot( 10, this , SLOT ( deleteSocket())); |
1409 | } | 1420 | } |
1410 | 1421 | ||
1411 | void KCommandSocket::startReadFileFromSocket() | 1422 | void KCommandSocket::startReadFileFromSocket() |
1412 | { | 1423 | { |
1413 | if ( ! mFirst ) | 1424 | if ( ! mFirst ) |
@@ -1467,17 +1478,17 @@ void KCommandSocket::deleteSocket() | |||
1467 | qDebug("KCS::Connection to remote host timed out"); | 1478 | qDebug("KCS::Connection to remote host timed out"); |
1468 | if ( mSocket ) { | 1479 | if ( mSocket ) { |
1469 | mSocket->close(); | 1480 | mSocket->close(); |
1470 | //if ( mSocket->state() == QSocket::Idle ) | 1481 | //if ( mSocket->state() == QSocket::Idle ) |
1471 | // deleteSocket(); | 1482 | // deleteSocket(); |
1472 | delete mSocket; | 1483 | delete mSocket; |
1473 | mSocket = 0; | 1484 | mSocket = 0; |
1474 | } | 1485 | } |
1475 | KMessageBox::error( 0, i18n("Connection to remote\nhost timed out!\nDid you forgot to enable\nsyncing on remote host? ")); | 1486 | KMessageBox::error( 0, i18n("Connection to remote\nhost timed out!\nDid you forgot to enable\nsyncing on remote host?")); |
1476 | emit commandFinished( this, mRetVal ); | 1487 | emit commandFinished( this, mRetVal ); |
1477 | return; | 1488 | return; |
1478 | } | 1489 | } |
1479 | //qDebug("KCommandSocket::deleteSocket() %d", mRetVal ); | 1490 | //qDebug("KCommandSocket::deleteSocket() %d", mRetVal ); |
1480 | if ( mSocket) | 1491 | if ( mSocket) |
1481 | delete mSocket; | 1492 | delete mSocket; |
1482 | mSocket = 0; | 1493 | mSocket = 0; |
1483 | emit commandFinished( this, mRetVal ); | 1494 | emit commandFinished( this, mRetVal ); |
diff --git a/libkdepim/ksyncmanager.h b/libkdepim/ksyncmanager.h index 6d89950..9a3066e 100644 --- a/libkdepim/ksyncmanager.h +++ b/libkdepim/ksyncmanager.h | |||
@@ -70,29 +70,33 @@ class KServerSocket : public QServerSocket | |||
70 | QString piFileString; | 70 | QString piFileString; |
71 | }; | 71 | }; |
72 | 72 | ||
73 | class KCommandSocket : public QObject | 73 | class KCommandSocket : public QObject |
74 | { | 74 | { |
75 | Q_OBJECT | 75 | Q_OBJECT |
76 | public: | 76 | public: |
77 | enum state { successR, errorR, successW, errorW, errorTO, quiet }; | 77 | enum state { successR, errorR, successW, errorW, errorTO, quiet }; |
78 | KCommandSocket ( QString password, Q_UINT16 port, QString host, QObject * parent=0, const char * name=0 ); | 78 | KCommandSocket ( QString password, Q_UINT16 port, QString host, QObject * parent=0, QWidget* cap = 0, const char * name=0 ); |
79 | void readFile( QString ); | 79 | void readFile( QString ); |
80 | void writeFile( QString ); | 80 | void writeFile( QString ); |
81 | void sendStop(); | 81 | void sendStop(); |
82 | |||
83 | private slots : | ||
84 | void sendFileRequest(); | ||
82 | 85 | ||
83 | signals: | 86 | signals: |
84 | void commandFinished( KCommandSocket*, int ); | 87 | void commandFinished( KCommandSocket*, int ); |
85 | private slots: | 88 | private slots: |
86 | void startReadFileFromSocket(); | 89 | void startReadFileFromSocket(); |
87 | void readFileFromSocket(); | 90 | void readFileFromSocket(); |
88 | void deleteSocket(); | 91 | void deleteSocket(); |
89 | void writeFileToSocket(); | 92 | void writeFileToSocket(); |
90 | private : | 93 | private : |
94 | QWidget* tlw; | ||
91 | QSocket* mSocket; | 95 | QSocket* mSocket; |
92 | QString mPassWord; | 96 | QString mPassWord; |
93 | Q_UINT16 mPort; | 97 | Q_UINT16 mPort; |
94 | QString mHost; | 98 | QString mHost; |
95 | QString mFileName; | 99 | QString mFileName; |
96 | QTimer* mTimerSocket; | 100 | QTimer* mTimerSocket; |
97 | int mRetVal; | 101 | int mRetVal; |
98 | QTime mTime; | 102 | QTime mTime; |