summaryrefslogtreecommitdiffabout
authorzautrix <zautrix>2005-02-22 03:43:50 (UTC)
committer zautrix <zautrix>2005-02-22 03:43:50 (UTC)
commit26f4ba7e3cc59ff5c5b9b8705179626e2752451b (patch) (unidiff)
tree2fd2b8ef6c9b80b4408fd885577d0dbc764dc35f
parent2097bbebc5e90e6469c24023e7796ada1762e9ed (diff)
downloadkdepimpi-26f4ba7e3cc59ff5c5b9b8705179626e2752451b.zip
kdepimpi-26f4ba7e3cc59ff5c5b9b8705179626e2752451b.tar.gz
kdepimpi-26f4ba7e3cc59ff5c5b9b8705179626e2752451b.tar.bz2
pi-sync fixes
Diffstat (more/less context) (show whitespace changes)
-rw-r--r--libkdepim/ksyncmanager.cpp18
1 files changed, 15 insertions, 3 deletions
diff --git a/libkdepim/ksyncmanager.cpp b/libkdepim/ksyncmanager.cpp
index 02e5587..08a263c 100644
--- a/libkdepim/ksyncmanager.cpp
+++ b/libkdepim/ksyncmanager.cpp
@@ -1043,30 +1043,32 @@ QString KSyncManager::syncFileName()
1043 return (QString( "/tmp/" )+ fn ); 1043 return (QString( "/tmp/" )+ fn );
1044#endif 1044#endif
1045} 1045}
1046 1046
1047void KSyncManager::syncPi() 1047void KSyncManager::syncPi()
1048{ 1048{
1049 mIsKapiFile = true; 1049 mIsKapiFile = true;
1050 mPisyncFinished = false; 1050 mPisyncFinished = false;
1051 qApp->processEvents(); 1051 qApp->processEvents();
1052 if ( mAskForPreferences ) 1052 if ( mAskForPreferences )
1053 if ( !edit_pisync_options()) { 1053 if ( !edit_pisync_options()) {
1054 mParent->topLevelWidget()->setCaption( i18n("Syncing aborted. Nothing synced.") ); 1054 mParent->topLevelWidget()->setCaption( i18n("Syncing aborted. Nothing synced.") );
1055 mPisyncFinished = true;
1055 return; 1056 return;
1056 } 1057 }
1057 bool ok; 1058 bool ok;
1058 Q_UINT16 port = mActiveSyncPort.toUInt(&ok); 1059 Q_UINT16 port = mActiveSyncPort.toUInt(&ok);
1059 if ( ! ok ) { 1060 if ( ! ok ) {
1060 mParent->topLevelWidget()->setCaption( i18n("Sorry, no valid port.Syncing cancelled.") ); 1061 mParent->topLevelWidget()->setCaption( i18n("Sorry, no valid port.Syncing cancelled.") );
1062 mPisyncFinished = true;
1061 return; 1063 return;
1062 } 1064 }
1063 KCommandSocket* commandSocket = new KCommandSocket( mPassWordPiSync, port, mActiveSyncIP, this, mParent->topLevelWidget() ); 1065 KCommandSocket* commandSocket = new KCommandSocket( mPassWordPiSync, port, mActiveSyncIP, this, mParent->topLevelWidget() );
1064 connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int )), this, SLOT(deleteCommandSocket(KCommandSocket*, int)) ); 1066 connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int )), this, SLOT(deleteCommandSocket(KCommandSocket*, int)) );
1065 commandSocket->readFile( syncFileName() ); 1067 commandSocket->readFile( syncFileName() );
1066} 1068}
1067 1069
1068void KSyncManager::deleteCommandSocket(KCommandSocket*s, int state) 1070void KSyncManager::deleteCommandSocket(KCommandSocket*s, int state)
1069{ 1071{
1070 //enum { success, errorW, errorR, quiet }; 1072 //enum { success, errorW, errorR, quiet };
1071 if ( state == KCommandSocket::errorR ||state == KCommandSocket::errorTO ) { 1073 if ( state == KCommandSocket::errorR ||state == KCommandSocket::errorTO ) {
1072 mParent->topLevelWidget()->setCaption( i18n("ERROR: Receiving remote file failed.") ); 1074 mParent->topLevelWidget()->setCaption( i18n("ERROR: Receiving remote file failed.") );
@@ -1080,24 +1082,30 @@ void KSyncManager::deleteCommandSocket(KCommandSocket*s, int state)
1080 return; 1082 return;
1081 1083
1082 } else if ( state == KCommandSocket::errorW ) { 1084 } else if ( state == KCommandSocket::errorW ) {
1083 mParent->topLevelWidget()->setCaption( i18n("ERROR:Writing back file failed.") ); 1085 mParent->topLevelWidget()->setCaption( i18n("ERROR:Writing back file failed.") );
1084 mPisyncFinished = true; 1086 mPisyncFinished = true;
1085 1087
1086 } else if ( state == KCommandSocket::successR ) { 1088 } else if ( state == KCommandSocket::successR ) {
1087 QTimer::singleShot( 1, this , SLOT ( readFileFromSocket())); 1089 QTimer::singleShot( 1, this , SLOT ( readFileFromSocket()));
1088 1090
1089 } else if ( state == KCommandSocket::successW ) { 1091 } else if ( state == KCommandSocket::successW ) {
1090 mParent->topLevelWidget()->setCaption( i18n("Pi-Sync successful!") ); 1092 mParent->topLevelWidget()->setCaption( i18n("Pi-Sync successful!") );
1091 mPisyncFinished = true; 1093 mPisyncFinished = true;
1094 } else if ( state == KCommandSocket::quiet ){
1095 qDebug("KSS: quiet ");
1096 mPisyncFinished = true;
1097 } else {
1098 qDebug("KSS: Error: unknown state: %d ", state);
1099 mPisyncFinished = true;
1092 } 1100 }
1093 1101
1094 delete s; 1102 delete s;
1095} 1103}
1096 1104
1097void KSyncManager::readFileFromSocket() 1105void KSyncManager::readFileFromSocket()
1098{ 1106{
1099 QString fileName = syncFileName(); 1107 QString fileName = syncFileName();
1100 bool syncOK = true; 1108 bool syncOK = true;
1101 mParent->topLevelWidget()->setCaption( i18n("Remote file saved to temp file.") ); 1109 mParent->topLevelWidget()->setCaption( i18n("Remote file saved to temp file.") );
1102 if ( ! syncWithFile( fileName , true ) ) { 1110 if ( ! syncWithFile( fileName , true ) ) {
1103 mParent->topLevelWidget()->setCaption( i18n("Syncing failed.") ); 1111 mParent->topLevelWidget()->setCaption( i18n("Syncing failed.") );
@@ -1262,26 +1270,27 @@ void KServerSocket::send_file()
1262 if ( mSocket->state() == QSocket::Idle ) 1270 if ( mSocket->state() == QSocket::Idle )
1263 QTimer::singleShot( 10, this , SLOT ( discardClient())); 1271 QTimer::singleShot( 10, this , SLOT ( discardClient()));
1264 return ; 1272 return ;
1265 1273
1266 } 1274 }
1267 mSyncActionDialog->setCaption( i18n("Sending file...") ); 1275 mSyncActionDialog->setCaption( i18n("Sending file...") );
1268 QTextStream ts( &file ); 1276 QTextStream ts( &file );
1269 ts.setEncoding( QTextStream::Latin1 ); 1277 ts.setEncoding( QTextStream::Latin1 );
1270 1278
1271 QTextStream os( mSocket ); 1279 QTextStream os( mSocket );
1272 os.setEncoding( QTextStream::Latin1 ); 1280 os.setEncoding( QTextStream::Latin1 );
1273 while ( ! ts.atEnd() ) { 1281 while ( ! ts.atEnd() ) {
1274 os << ts.readLine() << "\r\n\r\n"; 1282 os << ts.readLine() << "\r\n";
1275 } 1283 }
1284 os << "\r\n";
1276 //os << ts.read(); 1285 //os << ts.read();
1277 file.close(); 1286 file.close();
1278 mSyncActionDialog->setCaption( i18n("Waiting for synced file...") ); 1287 mSyncActionDialog->setCaption( i18n("Waiting for synced file...") );
1279 mSocket->close(); 1288 mSocket->close();
1280 if ( mSocket->state() == QSocket::Idle ) 1289 if ( mSocket->state() == QSocket::Idle )
1281 QTimer::singleShot( 10, this , SLOT ( discardClient())); 1290 QTimer::singleShot( 10, this , SLOT ( discardClient()));
1282} 1291}
1283void KServerSocket::get_file() 1292void KServerSocket::get_file()
1284{ 1293{
1285 mSyncActionDialog->setCaption( i18n("Receiving synced file...") ); 1294 mSyncActionDialog->setCaption( i18n("Receiving synced file...") );
1286 1295
1287 piTime.start(); 1296 piTime.start();
@@ -1365,57 +1374,60 @@ void KCommandSocket::readFile( QString fn )
1365{ 1374{
1366 if ( !mSocket ) { 1375 if ( !mSocket ) {
1367 mSocket = new QSocket( this ); 1376 mSocket = new QSocket( this );
1368 connect( mSocket, SIGNAL(readyRead()), this, SLOT(startReadFileFromSocket()) ); 1377 connect( mSocket, SIGNAL(readyRead()), this, SLOT(startReadFileFromSocket()) );
1369 connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) ); 1378 connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) );
1370 connect( mSocket, SIGNAL(connected ()), this, SLOT(sendFileRequest() )); 1379 connect( mSocket, SIGNAL(connected ()), this, SLOT(sendFileRequest() ));
1371 } 1380 }
1372 mFileString = ""; 1381 mFileString = "";
1373 mFileName = fn; 1382 mFileName = fn;
1374 mFirst = true; 1383 mFirst = true;
1375 if ( tlw ) 1384 if ( tlw )
1376 tlw->setCaption( i18n("Trying to connect to remote...") ); 1385 tlw->setCaption( i18n("Trying to connect to remote...") );
1386 mTimerSocket->start( 20000 );
1377 mSocket->connectToHost( mHost, mPort ); 1387 mSocket->connectToHost( mHost, mPort );
1378 qDebug("KSS: Waiting for connection"); 1388 qDebug("KSS: Waiting for connection");
1379 mTimerSocket->start( 20000 );
1380} 1389}
1381 1390
1382void KCommandSocket::writeFile( QString fileName ) 1391void KCommandSocket::writeFile( QString fileName )
1383{ 1392{
1384 if ( !mSocket ) { 1393 if ( !mSocket ) {
1385 mSocket = new QSocket( this ); 1394 mSocket = new QSocket( this );
1386 connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) ); 1395 connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) );
1387 connect( mSocket, SIGNAL(connected ()), this, SLOT(writeFileToSocket()) ); 1396 connect( mSocket, SIGNAL(connected ()), this, SLOT(writeFileToSocket()) );
1388 } 1397 }
1389 mFileName = fileName ; 1398 mFileName = fileName ;
1399 mTimerSocket->start( 20000 );
1390 mSocket->connectToHost( mHost, mPort ); 1400 mSocket->connectToHost( mHost, mPort );
1391} 1401}
1392void KCommandSocket::writeFileToSocket() 1402void KCommandSocket::writeFileToSocket()
1393{ 1403{
1404 mTimerSocket->stop();
1394 QFile file2( mFileName ); 1405 QFile file2( mFileName );
1395 if (!file2.open( IO_ReadOnly ) ) { 1406 if (!file2.open( IO_ReadOnly ) ) {
1396 mRetVal= errorW; 1407 mRetVal= errorW;
1397 mSocket->close(); 1408 mSocket->close();
1398 if ( mSocket->state() == QSocket::Idle ) 1409 if ( mSocket->state() == QSocket::Idle )
1399 QTimer::singleShot( 10, this , SLOT ( deleteSocket())); 1410 QTimer::singleShot( 10, this , SLOT ( deleteSocket()));
1400 return ; 1411 return ;
1401 } 1412 }
1402 QTextStream ts2( &file2 ); 1413 QTextStream ts2( &file2 );
1403 ts2.setEncoding( QTextStream::Latin1 ); 1414 ts2.setEncoding( QTextStream::Latin1 );
1404 QTextStream os2( mSocket ); 1415 QTextStream os2( mSocket );
1405 os2.setEncoding( QTextStream::Latin1 ); 1416 os2.setEncoding( QTextStream::Latin1 );
1406 os2 << "PUT " << mPassWord << "\r\n\r\n";; 1417 os2 << "PUT " << mPassWord << "\r\n\r\n";;
1407 while ( ! ts2.atEnd() ) { 1418 while ( ! ts2.atEnd() ) {
1408 os2 << ts2.readLine() << "\r\n\r\n"; 1419 os2 << ts2.readLine() << "\r\n";
1409 } 1420 }
1421 os2 << "\r\n";
1410 mRetVal= successW; 1422 mRetVal= successW;
1411 file2.close(); 1423 file2.close();
1412 mSocket->close(); 1424 mSocket->close();
1413 if ( mSocket->state() == QSocket::Idle ) 1425 if ( mSocket->state() == QSocket::Idle )
1414 QTimer::singleShot( 10, this , SLOT ( deleteSocket())); 1426 QTimer::singleShot( 10, this , SLOT ( deleteSocket()));
1415} 1427}
1416void KCommandSocket::sendStop() 1428void KCommandSocket::sendStop()
1417{ 1429{
1418 if ( !mSocket ) { 1430 if ( !mSocket ) {
1419 mSocket = new QSocket( this ); 1431 mSocket = new QSocket( this );
1420 connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) ); 1432 connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) );
1421 } 1433 }