-rw-r--r-- | libkdepim/ksyncmanager.cpp | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/libkdepim/ksyncmanager.cpp b/libkdepim/ksyncmanager.cpp index 7c53948..6f68d84 100644 --- a/libkdepim/ksyncmanager.cpp +++ b/libkdepim/ksyncmanager.cpp | |||
@@ -1251,193 +1251,193 @@ void KServerSocket::send_file() | |||
1251 | QTextStream os( mSocket ); | 1251 | QTextStream os( mSocket ); |
1252 | os.setEncoding( QTextStream::Latin1 ); | 1252 | os.setEncoding( QTextStream::Latin1 ); |
1253 | while ( ! ts.atEnd() ) { | 1253 | while ( ! ts.atEnd() ) { |
1254 | os << ts.readLine() << "\r\n"; | 1254 | os << ts.readLine() << "\r\n"; |
1255 | } | 1255 | } |
1256 | //os << ts.read(); | 1256 | //os << ts.read(); |
1257 | file.close(); | 1257 | file.close(); |
1258 | mSyncActionDialog->setCaption( i18n("Waiting for synced file...") ); | 1258 | mSyncActionDialog->setCaption( i18n("Waiting for synced file...") ); |
1259 | mSocket->close(); | 1259 | mSocket->close(); |
1260 | if ( mSocket->state() == QSocket::Idle ) | 1260 | if ( mSocket->state() == QSocket::Idle ) |
1261 | QTimer::singleShot( 10, this , SLOT ( discardClient())); | 1261 | QTimer::singleShot( 10, this , SLOT ( discardClient())); |
1262 | } | 1262 | } |
1263 | void KServerSocket::get_file() | 1263 | void KServerSocket::get_file() |
1264 | { | 1264 | { |
1265 | mSyncActionDialog->setCaption( i18n("Receiving synced file...") ); | 1265 | mSyncActionDialog->setCaption( i18n("Receiving synced file...") ); |
1266 | 1266 | ||
1267 | piTime.start(); | 1267 | piTime.start(); |
1268 | piFileString = ""; | 1268 | piFileString = ""; |
1269 | QTimer::singleShot( 1, this , SLOT (readBackFileFromSocket( ) )); | 1269 | QTimer::singleShot( 1, this , SLOT (readBackFileFromSocket( ) )); |
1270 | } | 1270 | } |
1271 | 1271 | ||
1272 | 1272 | ||
1273 | void KServerSocket::readBackFileFromSocket() | 1273 | void KServerSocket::readBackFileFromSocket() |
1274 | { | 1274 | { |
1275 | //qDebug("readBackFileFromSocket() %d ", piTime.elapsed ()); | 1275 | //qDebug("readBackFileFromSocket() %d ", piTime.elapsed ()); |
1276 | while ( mSocket->canReadLine () ) { | 1276 | while ( mSocket->canReadLine () ) { |
1277 | piTime.restart(); | 1277 | piTime.restart(); |
1278 | QString line = mSocket->readLine (); | 1278 | QString line = mSocket->readLine (); |
1279 | piFileString += line; | 1279 | piFileString += line; |
1280 | //qDebug("readline: %s ", line.latin1()); | 1280 | //qDebug("readline: %s ", line.latin1()); |
1281 | mSyncActionDialog->setCaption( i18n("Received %1 bytes").arg( piFileString.length() ) ); | 1281 | mSyncActionDialog->setCaption( i18n("Received %1 bytes").arg( piFileString.length() ) ); |
1282 | 1282 | ||
1283 | } | 1283 | } |
1284 | if ( piTime.elapsed () < 3000 ) { | 1284 | if ( piTime.elapsed () < 3000 ) { |
1285 | // wait for more | 1285 | // wait for more |
1286 | //qDebug("waitformore "); | 1286 | //qDebug("waitformore "); |
1287 | QTimer::singleShot( 100, this , SLOT (readBackFileFromSocket( ) )); | 1287 | QTimer::singleShot( 100, this , SLOT (readBackFileFromSocket( ) )); |
1288 | return; | 1288 | return; |
1289 | } | 1289 | } |
1290 | QString fileName = mFileName; | 1290 | QString fileName = mFileName; |
1291 | QFile file ( fileName ); | 1291 | QFile file ( fileName ); |
1292 | if (!file.open( IO_WriteOnly ) ) { | 1292 | if (!file.open( IO_WriteOnly ) ) { |
1293 | delete mSyncActionDialog; | 1293 | delete mSyncActionDialog; |
1294 | mSyncActionDialog = 0; | 1294 | mSyncActionDialog = 0; |
1295 | qDebug("KSS:Error open read back file "); | 1295 | qDebug("KSS:Error open read back file "); |
1296 | piFileString = ""; | 1296 | piFileString = ""; |
1297 | emit file_received( false ); | 1297 | emit file_received( false ); |
1298 | blockRC = false; | 1298 | blockRC = false; |
1299 | return ; | 1299 | return ; |
1300 | 1300 | ||
1301 | } | 1301 | } |
1302 | 1302 | ||
1303 | // mView->setLoadedFileVersion(QDateTime::currentDateTime().addSecs( -1)); | 1303 | // mView->setLoadedFileVersion(QDateTime::currentDateTime().addSecs( -1)); |
1304 | QTextStream ts ( &file ); | 1304 | QTextStream ts ( &file ); |
1305 | ts.setEncoding( QTextStream::Latin1 ); | 1305 | ts.setEncoding( QTextStream::Latin1 ); |
1306 | mSyncActionDialog->setCaption( i18n("Writing file to disk...") ); | 1306 | mSyncActionDialog->setCaption( i18n("Writing file to disk...") ); |
1307 | ts << piFileString; | 1307 | ts << piFileString; |
1308 | mSocket->close(); | 1308 | mSocket->close(); |
1309 | if ( mSocket->state() == QSocket::Idle ) | 1309 | if ( mSocket->state() == QSocket::Idle ) |
1310 | QTimer::singleShot( 10, this , SLOT ( discardClient())); | 1310 | QTimer::singleShot( 10, this , SLOT ( discardClient())); |
1311 | file.close(); | 1311 | file.close(); |
1312 | piFileString = ""; | 1312 | piFileString = ""; |
1313 | emit file_received( true ); | 1313 | emit file_received( true ); |
1314 | delete mSyncActionDialog; | 1314 | delete mSyncActionDialog; |
1315 | mSyncActionDialog = 0; | 1315 | mSyncActionDialog = 0; |
1316 | blockRC = false; | 1316 | blockRC = false; |
1317 | 1317 | ||
1318 | } | 1318 | } |
1319 | 1319 | ||
1320 | KCommandSocket::KCommandSocket ( QString password, Q_UINT16 port, QString host, QObject * parent, const char * name ): QObject( parent, name ) | 1320 | KCommandSocket::KCommandSocket ( QString password, Q_UINT16 port, QString host, QObject * parent, const char * name ): QObject( parent, name ) |
1321 | { | 1321 | { |
1322 | mPassWord = password; | 1322 | mPassWord = password; |
1323 | mSocket = 0; | 1323 | mSocket = 0; |
1324 | mPort = port; | 1324 | mPort = port; |
1325 | mHost = host; | 1325 | mHost = host; |
1326 | 1326 | ||
1327 | mRetVal = quiet; | 1327 | mRetVal = quiet; |
1328 | mTimerSocket = new QTimer ( this ); | 1328 | mTimerSocket = new QTimer ( this ); |
1329 | connect( mTimerSocket, SIGNAL ( timeout () ), this, SLOT ( deleteSocket() ) ); | 1329 | connect( mTimerSocket, SIGNAL ( timeout () ), this, SLOT ( deleteSocket() ) ); |
1330 | } | 1330 | } |
1331 | void KCommandSocket::readFile( QString fn ) | 1331 | void KCommandSocket::readFile( QString fn ) |
1332 | { | 1332 | { |
1333 | if ( !mSocket ) { | 1333 | if ( !mSocket ) { |
1334 | mSocket = new QSocket( this ); | 1334 | mSocket = new QSocket( this ); |
1335 | connect( mSocket, SIGNAL(readyRead()), this, SLOT(startReadFileFromSocket()) ); | 1335 | connect( mSocket, SIGNAL(readyRead()), this, SLOT(startReadFileFromSocket()) ); |
1336 | connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) ); | 1336 | connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) ); |
1337 | } | 1337 | } |
1338 | mFileString = ""; | 1338 | mFileString = ""; |
1339 | mFileName = fn; | 1339 | mFileName = fn; |
1340 | mFirst = true; | 1340 | mFirst = true; |
1341 | mSocket->connectToHost( mHost, mPort ); | 1341 | mSocket->connectToHost( mHost, mPort ); |
1342 | QTextStream os( mSocket ); | 1342 | QTextStream os( mSocket ); |
1343 | os.setEncoding( QTextStream::Latin1 ); | 1343 | os.setEncoding( QTextStream::Latin1 ); |
1344 | 1344 | ||
1345 | QString curDt = " " +KGlobal::locale()->formatDateTime(QDateTime::currentDateTime().addSecs(-1),true, true,KLocale::ISODate ); | 1345 | QString curDt = " " +KGlobal::locale()->formatDateTime(QDateTime::currentDateTime().addSecs(-1),true, true,KLocale::ISODate ); |
1346 | os << "GET " << mPassWord << curDt <<"\r\n"; | 1346 | os << "GET " << mPassWord << curDt <<"\r\n"; |
1347 | mTimerSocket->start( 20000 ); | 1347 | mTimerSocket->start( 300000 ); |
1348 | } | 1348 | } |
1349 | 1349 | ||
1350 | void KCommandSocket::writeFile( QString fileName ) | 1350 | void KCommandSocket::writeFile( QString fileName ) |
1351 | { | 1351 | { |
1352 | if ( !mSocket ) { | 1352 | if ( !mSocket ) { |
1353 | mSocket = new QSocket( this ); | 1353 | mSocket = new QSocket( this ); |
1354 | connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) ); | 1354 | connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) ); |
1355 | connect( mSocket, SIGNAL(connected ()), this, SLOT(writeFileToSocket()) ); | 1355 | connect( mSocket, SIGNAL(connected ()), this, SLOT(writeFileToSocket()) ); |
1356 | } | 1356 | } |
1357 | mFileName = fileName ; | 1357 | mFileName = fileName ; |
1358 | mSocket->connectToHost( mHost, mPort ); | 1358 | mSocket->connectToHost( mHost, mPort ); |
1359 | } | 1359 | } |
1360 | void KCommandSocket::writeFileToSocket() | 1360 | void KCommandSocket::writeFileToSocket() |
1361 | { | 1361 | { |
1362 | QFile file2( mFileName ); | 1362 | QFile file2( mFileName ); |
1363 | if (!file2.open( IO_ReadOnly ) ) { | 1363 | if (!file2.open( IO_ReadOnly ) ) { |
1364 | mRetVal= errorW; | 1364 | mRetVal= errorW; |
1365 | mSocket->close(); | 1365 | mSocket->close(); |
1366 | if ( mSocket->state() == QSocket::Idle ) | 1366 | if ( mSocket->state() == QSocket::Idle ) |
1367 | QTimer::singleShot( 10, this , SLOT ( deleteSocket())); | 1367 | QTimer::singleShot( 10, this , SLOT ( deleteSocket())); |
1368 | return ; | 1368 | return ; |
1369 | } | 1369 | } |
1370 | QTextStream ts2( &file2 ); | 1370 | QTextStream ts2( &file2 ); |
1371 | ts2.setEncoding( QTextStream::Latin1 ); | 1371 | ts2.setEncoding( QTextStream::Latin1 ); |
1372 | QTextStream os2( mSocket ); | 1372 | QTextStream os2( mSocket ); |
1373 | os2.setEncoding( QTextStream::Latin1 ); | 1373 | os2.setEncoding( QTextStream::Latin1 ); |
1374 | os2 << "PUT " << mPassWord << "\r\n";; | 1374 | os2 << "PUT " << mPassWord << "\r\n";; |
1375 | while ( ! ts2.atEnd() ) { | 1375 | while ( ! ts2.atEnd() ) { |
1376 | os2 << ts2.readLine() << "\r\n"; | 1376 | os2 << ts2.readLine() << "\r\n"; |
1377 | } | 1377 | } |
1378 | mRetVal= successW; | 1378 | mRetVal= successW; |
1379 | file2.close(); | 1379 | file2.close(); |
1380 | mSocket->close(); | 1380 | mSocket->close(); |
1381 | if ( mSocket->state() == QSocket::Idle ) | 1381 | if ( mSocket->state() == QSocket::Idle ) |
1382 | QTimer::singleShot( 10, this , SLOT ( deleteSocket())); | 1382 | QTimer::singleShot( 10, this , SLOT ( deleteSocket())); |
1383 | } | 1383 | } |
1384 | void KCommandSocket::sendStop() | 1384 | void KCommandSocket::sendStop() |
1385 | { | 1385 | { |
1386 | if ( !mSocket ) { | 1386 | if ( !mSocket ) { |
1387 | mSocket = new QSocket( this ); | 1387 | mSocket = new QSocket( this ); |
1388 | connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) ); | 1388 | connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) ); |
1389 | } | 1389 | } |
1390 | mSocket->connectToHost( mHost, mPort ); | 1390 | mSocket->connectToHost( mHost, mPort ); |
1391 | QTextStream os2( mSocket ); | 1391 | QTextStream os2( mSocket ); |
1392 | os2.setEncoding( QTextStream::Latin1 ); | 1392 | os2.setEncoding( QTextStream::Latin1 ); |
1393 | os2 << "STOP\r\n"; | 1393 | os2 << "STOP\r\n"; |
1394 | mSocket->close(); | 1394 | mSocket->close(); |
1395 | if ( mSocket->state() == QSocket::Idle ) | 1395 | if ( mSocket->state() == QSocket::Idle ) |
1396 | QTimer::singleShot( 10, this , SLOT ( deleteSocket())); | 1396 | QTimer::singleShot( 10, this , SLOT ( deleteSocket())); |
1397 | } | 1397 | } |
1398 | 1398 | ||
1399 | void KCommandSocket::startReadFileFromSocket() | 1399 | void KCommandSocket::startReadFileFromSocket() |
1400 | { | 1400 | { |
1401 | if ( ! mFirst ) | 1401 | if ( ! mFirst ) |
1402 | return; | 1402 | return; |
1403 | mFirst = false; | 1403 | mFirst = false; |
1404 | mTimerSocket->stop(); | 1404 | mTimerSocket->stop(); |
1405 | mFileString = ""; | 1405 | mFileString = ""; |
1406 | mTime.start(); | 1406 | mTime.start(); |
1407 | QTimer::singleShot( 1, this , SLOT (readFileFromSocket( ) )); | 1407 | QTimer::singleShot( 1, this , SLOT (readFileFromSocket( ) )); |
1408 | 1408 | ||
1409 | } | 1409 | } |
1410 | void KCommandSocket::readFileFromSocket() | 1410 | void KCommandSocket::readFileFromSocket() |
1411 | { | 1411 | { |
1412 | //qDebug("readBackFileFromSocket() %d ", mTime.elapsed ()); | 1412 | //qDebug("readBackFileFromSocket() %d ", mTime.elapsed ()); |
1413 | while ( mSocket->canReadLine () ) { | 1413 | while ( mSocket->canReadLine () ) { |
1414 | mTime.restart(); | 1414 | mTime.restart(); |
1415 | QString line = mSocket->readLine (); | 1415 | QString line = mSocket->readLine (); |
1416 | mFileString += line; | 1416 | mFileString += line; |
1417 | //qDebug("readline: %s ", line.latin1()); | 1417 | //qDebug("readline: %s ", line.latin1()); |
1418 | } | 1418 | } |
1419 | if ( mTime.elapsed () < 3000 ) { | 1419 | if ( mTime.elapsed () < 3000 ) { |
1420 | // wait for more | 1420 | // wait for more |
1421 | //qDebug("waitformore "); | 1421 | //qDebug("waitformore "); |
1422 | QTimer::singleShot( 100, this , SLOT (readFileFromSocket( ) )); | 1422 | QTimer::singleShot( 100, this , SLOT (readFileFromSocket( ) )); |
1423 | return; | 1423 | return; |
1424 | } | 1424 | } |
1425 | QString fileName = mFileName; | 1425 | QString fileName = mFileName; |
1426 | QFile file ( fileName ); | 1426 | QFile file ( fileName ); |
1427 | if (!file.open( IO_WriteOnly ) ) { | 1427 | if (!file.open( IO_WriteOnly ) ) { |
1428 | mFileString = ""; | 1428 | mFileString = ""; |
1429 | mRetVal = errorR; | 1429 | mRetVal = errorR; |
1430 | qDebug("KSS:Error open temp sync file for writing: %s",fileName.latin1() ); | 1430 | qDebug("KSS:Error open temp sync file for writing: %s",fileName.latin1() ); |
1431 | deleteSocket(); | 1431 | deleteSocket(); |
1432 | return ; | 1432 | return ; |
1433 | 1433 | ||
1434 | } | 1434 | } |
1435 | // mView->setLoadedFileVersion(QDateTime::currentDateTime().addSecs( -1)); | 1435 | // mView->setLoadedFileVersion(QDateTime::currentDateTime().addSecs( -1)); |
1436 | QTextStream ts ( &file ); | 1436 | QTextStream ts ( &file ); |
1437 | ts.setEncoding( QTextStream::Latin1 ); | 1437 | ts.setEncoding( QTextStream::Latin1 ); |
1438 | ts << mFileString; | 1438 | ts << mFileString; |
1439 | file.close(); | 1439 | file.close(); |
1440 | mFileString = ""; | 1440 | mFileString = ""; |
1441 | mRetVal = successR; | 1441 | mRetVal = successR; |
1442 | mSocket->close(); | 1442 | mSocket->close(); |
1443 | // if state is not idle, deleteSocket(); is called via | 1443 | // if state is not idle, deleteSocket(); is called via |