-rw-r--r-- | libkdepim/ksyncmanager.cpp | 5 |
1 files changed, 2 insertions, 3 deletions
diff --git a/libkdepim/ksyncmanager.cpp b/libkdepim/ksyncmanager.cpp index 28c48fe..4d859ce 100644 --- a/libkdepim/ksyncmanager.cpp +++ b/libkdepim/ksyncmanager.cpp | |||
@@ -360,129 +360,128 @@ void KSyncManager::enableQuick( bool ask ) | |||
360 | int po = 9197+mTargetApp; | 360 | int po = 9197+mTargetApp; |
361 | QLabel label ( i18n("Port number (Default: %1)\nValid range from 1 to 65535").arg(po), &dia ); | 361 | QLabel label ( i18n("Port number (Default: %1)\nValid range from 1 to 65535").arg(po), &dia ); |
362 | lay.addWidget( &label); | 362 | lay.addWidget( &label); |
363 | lay.addWidget( &lab); | 363 | lay.addWidget( &lab); |
364 | 364 | ||
365 | QLineEdit lepw ( &dia ); | 365 | QLineEdit lepw ( &dia ); |
366 | lepw.setText( mPrefs->mPassiveSyncPw ); | 366 | lepw.setText( mPrefs->mPassiveSyncPw ); |
367 | QLabel label2 ( i18n("Password to enable\naccess from remote:"), &dia ); | 367 | QLabel label2 ( i18n("Password to enable\naccess from remote:"), &dia ); |
368 | lay.addWidget( &label2); | 368 | lay.addWidget( &label2); |
369 | lay.addWidget( &lepw); | 369 | lay.addWidget( &lepw); |
370 | QCheckBox autostart(i18n("Automatically start\nat application startup"), &dia ); | 370 | QCheckBox autostart(i18n("Automatically start\nat application startup"), &dia ); |
371 | lay.addWidget( &autostart); | 371 | lay.addWidget( &autostart); |
372 | autostart.setChecked( mPrefs->mPassiveSyncAutoStart ); | 372 | autostart.setChecked( mPrefs->mPassiveSyncAutoStart ); |
373 | #ifdef DESKTOP_VERSION | 373 | #ifdef DESKTOP_VERSION |
374 | #ifdef _WIN32_ | 374 | #ifdef _WIN32_ |
375 | QCheckBox syncdesktop( i18n("Automatically sync with Outlook\nwhen receiving sync request"),&dia ); | 375 | QCheckBox syncdesktop( i18n("Automatically sync with Outlook\nwhen receiving sync request"),&dia ); |
376 | syncdesktop.hide();// not implemented! | 376 | syncdesktop.hide();// not implemented! |
377 | #else | 377 | #else |
378 | QCheckBox syncdesktop( i18n("Automatically sync with KDE-Desktop\nwhen receiving sync request"),&dia ); | 378 | QCheckBox syncdesktop( i18n("Automatically sync with KDE-Desktop\nwhen receiving sync request"),&dia ); |
379 | #endif | 379 | #endif |
380 | lay.addWidget( &syncdesktop); | 380 | lay.addWidget( &syncdesktop); |
381 | #else | 381 | #else |
382 | mPrefs->mPassiveSyncWithDesktop = false; | 382 | mPrefs->mPassiveSyncWithDesktop = false; |
383 | QCheckBox syncdesktop( i18n("Automatically sync\nwith KDE-Desktop"),&dia ); | 383 | QCheckBox syncdesktop( i18n("Automatically sync\nwith KDE-Desktop"),&dia ); |
384 | syncdesktop.hide(); | 384 | syncdesktop.hide(); |
385 | #endif | 385 | #endif |
386 | syncdesktop.setChecked( mPrefs->mPassiveSyncWithDesktop ); | 386 | syncdesktop.setChecked( mPrefs->mPassiveSyncWithDesktop ); |
387 | 387 | ||
388 | QPushButton pb ( "OK", &dia); | 388 | QPushButton pb ( "OK", &dia); |
389 | lay.addWidget( &pb ); | 389 | lay.addWidget( &pb ); |
390 | connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) ); | 390 | connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) ); |
391 | dia.resize( 230,120 ); | 391 | dia.resize( 230,120 ); |
392 | dia.setCaption( i18n("Enter port for Pi-Sync") ); | 392 | dia.setCaption( i18n("Enter port for Pi-Sync") ); |
393 | dia.show(); | 393 | dia.show(); |
394 | #ifndef DESKTOP_VERSION | 394 | #ifndef DESKTOP_VERSION |
395 | int dw = QApplication::desktop()->width(); | 395 | int dw = QApplication::desktop()->width(); |
396 | int dh = QApplication::desktop()->height(); | 396 | int dh = QApplication::desktop()->height(); |
397 | dia.move( (dw-dia.width())/2, (dh - dia.height() )/2 ); | 397 | dia.move( (dw-dia.width())/2, (dh - dia.height() )/2 ); |
398 | #endif | 398 | #endif |
399 | if ( ! dia.exec() ) | 399 | if ( ! dia.exec() ) |
400 | return; | 400 | return; |
401 | dia.hide(); | 401 | dia.hide(); |
402 | qApp->processEvents(); | 402 | qApp->processEvents(); |
403 | if ( mPrefs->mPassiveSyncPw != lepw.text() ) { | 403 | if ( mPrefs->mPassiveSyncPw != lepw.text() ) { |
404 | changed = true; | 404 | changed = true; |
405 | mPrefs->mPassiveSyncPw = lepw.text(); | 405 | mPrefs->mPassiveSyncPw = lepw.text(); |
406 | } | 406 | } |
407 | if ( mPrefs->mPassiveSyncPort != lab.text() ) { | 407 | if ( mPrefs->mPassiveSyncPort != lab.text() ) { |
408 | mPrefs->mPassiveSyncPort = lab.text(); | 408 | mPrefs->mPassiveSyncPort = lab.text(); |
409 | changed = true; | 409 | changed = true; |
410 | } | 410 | } |
411 | autoStart = autostart.isChecked(); | 411 | autoStart = autostart.isChecked(); |
412 | if (mPrefs->mPassiveSyncWithDesktop != syncdesktop.isChecked() ) { | 412 | if (mPrefs->mPassiveSyncWithDesktop != syncdesktop.isChecked() ) { |
413 | changed = true; | 413 | changed = true; |
414 | mPrefs->mPassiveSyncWithDesktop = syncdesktop.isChecked(); | 414 | mPrefs->mPassiveSyncWithDesktop = syncdesktop.isChecked(); |
415 | } | 415 | } |
416 | } | 416 | } |
417 | else | 417 | else |
418 | autoStart = mPrefs->mPassiveSyncAutoStart; | 418 | autoStart = mPrefs->mPassiveSyncAutoStart; |
419 | if ( autoStart != mPrefs->mPassiveSyncAutoStart ) | 419 | if ( autoStart != mPrefs->mPassiveSyncAutoStart ) |
420 | changed = true; | 420 | changed = true; |
421 | bool ok; | 421 | bool ok; |
422 | mPrefs->mPassiveSyncAutoStart = false; | 422 | mPrefs->mPassiveSyncAutoStart = false; |
423 | Q_UINT32 port_t = mPrefs->mPassiveSyncPort.toUInt(&ok); | 423 | Q_UINT32 port_t = mPrefs->mPassiveSyncPort.toUInt(&ok); |
424 | qDebug("%d ", port_t); | ||
425 | if ( ! ok || port_t > 65535 ) { | 424 | if ( ! ok || port_t > 65535 ) { |
426 | KMessageBox::information( 0, i18n("No valid port number:\n%1").arg ( mPrefs->mPassiveSyncPort ), i18n("Pi-Sync Port Error")); | 425 | KMessageBox::information( 0, i18n("No valid port number:\n%1").arg ( mPrefs->mPassiveSyncPort ), i18n("Pi-Sync Port Error")); |
427 | return; | 426 | return; |
428 | } | 427 | } |
429 | Q_UINT16 port = port_t; | 428 | Q_UINT16 port = port_t; |
430 | //qDebug("port %d ", port); | 429 | //qDebug("port %d ", port); |
431 | mServerSocket = new KServerSocket ( mPrefs->mPassiveSyncPw, port ,1 ); | 430 | mServerSocket = new KServerSocket ( mPrefs->mPassiveSyncPw, port ,1 ); |
432 | mServerSocket->setFileName( defaultFileName() );//bbb | 431 | mServerSocket->setFileName( defaultFileName() );//bbb |
433 | if ( !mServerSocket->ok() ) { | 432 | if ( !mServerSocket->ok() ) { |
434 | QTimer::singleShot( 2000, this, SLOT ( displayErrorPort() ) ); | 433 | QTimer::singleShot( 2000, this, SLOT ( displayErrorPort() ) ); |
435 | delete mServerSocket; | 434 | delete mServerSocket; |
436 | mServerSocket = 0; | 435 | mServerSocket = 0; |
437 | return; | 436 | return; |
438 | } | 437 | } |
439 | mPrefs->mPassiveSyncAutoStart = autoStart; | 438 | mPrefs->mPassiveSyncAutoStart = autoStart; |
440 | if ( changed ) { | 439 | if ( changed ) { |
441 | mPrefs->writeConfig(); | 440 | mPrefs->writeConfig(); |
442 | } | 441 | } |
443 | connect( mServerSocket, SIGNAL ( request_file() ),this, SIGNAL ( request_file() ) ); | 442 | connect( mServerSocket, SIGNAL ( request_file() ),this, SIGNAL ( request_file() ) ); |
444 | connect( mServerSocket, SIGNAL ( file_received( bool ) ), this, SIGNAL ( getFile( bool ) ) ); | 443 | connect( mServerSocket, SIGNAL ( file_received( bool ) ), this, SIGNAL ( getFile( bool ) ) ); |
445 | connect( mServerSocket, SIGNAL ( request_file(const QString &) ),this, SIGNAL ( request_file(const QString &) ) ); | 444 | connect( mServerSocket, SIGNAL ( request_file(const QString &) ),this, SIGNAL ( request_file(const QString &) ) ); |
446 | connect( mServerSocket, SIGNAL ( file_received( bool ,const QString &) ), this, SIGNAL ( getFile( bool,const QString & ) ) ); | 445 | connect( mServerSocket, SIGNAL ( file_received( bool ,const QString &) ), this, SIGNAL ( getFile( bool,const QString & ) ) ); |
447 | } | 446 | } |
448 | void KSyncManager::displayErrorPort() | 447 | void KSyncManager::displayErrorPort() |
449 | { | 448 | { |
450 | 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")); | 449 | 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")); |
451 | } | 450 | } |
452 | void KSyncManager::syncLocalFile() | 451 | void KSyncManager::syncLocalFile() |
453 | { | 452 | { |
454 | 453 | ||
455 | QString fn =mPrefs->mLastSyncedLocalFile; | 454 | QString fn =mPrefs->mLastSyncedLocalFile; |
456 | QString ext; | 455 | QString ext; |
457 | 456 | ||
458 | switch(mTargetApp) | 457 | switch(mTargetApp) |
459 | { | 458 | { |
460 | case (KAPI): | 459 | case (KAPI): |
461 | ext = "(*.vcf)"; | 460 | ext = "(*.vcf)"; |
462 | break; | 461 | break; |
463 | case (KOPI): | 462 | case (KOPI): |
464 | ext = "(*.ics/*.vcs)"; | 463 | ext = "(*.ics/*.vcs)"; |
465 | break; | 464 | break; |
466 | case (PWMPI): | 465 | case (PWMPI): |
467 | ext = "(*.pwm)"; | 466 | ext = "(*.pwm)"; |
468 | break; | 467 | break; |
469 | default: | 468 | default: |
470 | qDebug("KSM::syncLocalFile: invalid apptype selected"); | 469 | qDebug("KSM::syncLocalFile: invalid apptype selected"); |
471 | break; | 470 | break; |
472 | 471 | ||
473 | } | 472 | } |
474 | 473 | ||
475 | fn =KFileDialog:: getOpenFileName( fn, i18n("Sync filename"+ext), mParent ); | 474 | fn =KFileDialog:: getOpenFileName( fn, i18n("Sync filename"+ext), mParent ); |
476 | if ( fn == "" ) | 475 | if ( fn == "" ) |
477 | return; | 476 | return; |
478 | if ( syncWithFile( fn, false ) ) { | 477 | if ( syncWithFile( fn, false ) ) { |
479 | qDebug("KSM::syncLocalFile() successful "); | 478 | qDebug("KSM::syncLocalFile() successful "); |
480 | } | 479 | } |
481 | 480 | ||
482 | } | 481 | } |
483 | 482 | ||
484 | bool KSyncManager::syncWithFile( QString fn , bool quick ) | 483 | bool KSyncManager::syncWithFile( QString fn , bool quick ) |
485 | { | 484 | { |
486 | bool ret = false; | 485 | bool ret = false; |
487 | QFileInfo info; | 486 | QFileInfo info; |
488 | info.setFile( fn ); | 487 | info.setFile( fn ); |
@@ -1251,129 +1250,129 @@ void KSyncManager::readFileFromSocket() | |||
1251 | KCommandSocket* commandSocket = new KCommandSocket( mCurrentResourceRemote,mPassWordPiSync, mActiveSyncPort.toUInt(), mActiveSyncIP, this, mParent->topLevelWidget() ); | 1250 | KCommandSocket* commandSocket = new KCommandSocket( mCurrentResourceRemote,mPassWordPiSync, mActiveSyncPort.toUInt(), mActiveSyncIP, this, mParent->topLevelWidget() ); |
1252 | connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int)), this, SLOT(deleteCommandSocket(KCommandSocket*, int )) ); | 1251 | connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int)), this, SLOT(deleteCommandSocket(KCommandSocket*, int )) ); |
1253 | if ( mWriteBackFile && syncOK ) { | 1252 | if ( mWriteBackFile && syncOK ) { |
1254 | mParent->topLevelWidget()->setCaption( i18n("Sending back file ...") ); | 1253 | mParent->topLevelWidget()->setCaption( i18n("Sending back file ...") ); |
1255 | commandSocket->writeFile( fileName ); | 1254 | commandSocket->writeFile( fileName ); |
1256 | } | 1255 | } |
1257 | else { | 1256 | else { |
1258 | commandSocket->sendStop(); | 1257 | commandSocket->sendStop(); |
1259 | if ( syncOK ) | 1258 | if ( syncOK ) |
1260 | mParent->topLevelWidget()->setCaption( i18n("Pi-Sync succesful!") ); | 1259 | mParent->topLevelWidget()->setCaption( i18n("Pi-Sync succesful!") ); |
1261 | mPisyncFinished = true; | 1260 | mPisyncFinished = true; |
1262 | } | 1261 | } |
1263 | } | 1262 | } |
1264 | 1263 | ||
1265 | KServerSocket:: KServerSocket ( QString pw, Q_UINT16 port, int backlog, QObject * parent, const char * name ) : QServerSocket( port, backlog, parent, name ) | 1264 | KServerSocket:: KServerSocket ( QString pw, Q_UINT16 port, int backlog, QObject * parent, const char * name ) : QServerSocket( port, backlog, parent, name ) |
1266 | { | 1265 | { |
1267 | mPendingConnect = 0; | 1266 | mPendingConnect = 0; |
1268 | mPassWord = pw; | 1267 | mPassWord = pw; |
1269 | mSocket = 0; | 1268 | mSocket = 0; |
1270 | mSyncActionDialog = 0; | 1269 | mSyncActionDialog = 0; |
1271 | blockRC = false; | 1270 | blockRC = false; |
1272 | mErrorMessage = 0; | 1271 | mErrorMessage = 0; |
1273 | } | 1272 | } |
1274 | void KServerSocket::waitForSocketFinish() | 1273 | void KServerSocket::waitForSocketFinish() |
1275 | { | 1274 | { |
1276 | if ( mSocket ) { | 1275 | if ( mSocket ) { |
1277 | //qDebug("KSS:: waiting for finish operation"); | 1276 | //qDebug("KSS:: waiting for finish operation"); |
1278 | QTimer::singleShot( 250, this , SLOT ( waitForSocketFinish())); | 1277 | QTimer::singleShot( 250, this , SLOT ( waitForSocketFinish())); |
1279 | return; | 1278 | return; |
1280 | } | 1279 | } |
1281 | mSocket = new QSocket( this ); | 1280 | mSocket = new QSocket( this ); |
1282 | connect( mSocket , SIGNAL(readyRead()), this, SLOT(readClient()) ); | 1281 | connect( mSocket , SIGNAL(readyRead()), this, SLOT(readClient()) ); |
1283 | connect( mSocket , SIGNAL(delayedCloseFinished()), this, SLOT(discardClient()) ); | 1282 | connect( mSocket , SIGNAL(delayedCloseFinished()), this, SLOT(discardClient()) ); |
1284 | mSocket->setSocket( mPendingConnect ); | 1283 | mSocket->setSocket( mPendingConnect ); |
1285 | mPendingConnect = 0; | 1284 | mPendingConnect = 0; |
1286 | } | 1285 | } |
1287 | void KServerSocket::newConnection ( int socket ) | 1286 | void KServerSocket::newConnection ( int socket ) |
1288 | { | 1287 | { |
1289 | // qDebug("KServerSocket:New connection %d ", socket); | 1288 | // qDebug("KServerSocket:New connection %d ", socket); |
1290 | if ( mPendingConnect ) { | 1289 | if ( mPendingConnect ) { |
1291 | qDebug("KSS::Error : new Connection"); | 1290 | qDebug("KSS::Error : new Connection"); |
1292 | return; | 1291 | return; |
1293 | } | 1292 | } |
1294 | if ( mSocket ) { | 1293 | if ( mSocket ) { |
1295 | mPendingConnect = socket; | 1294 | mPendingConnect = socket; |
1296 | QTimer::singleShot( 250, this , SLOT ( waitForSocketFinish())); | 1295 | QTimer::singleShot( 250, this , SLOT ( waitForSocketFinish())); |
1297 | return; | 1296 | return; |
1298 | qDebug("KSS::newConnection Socket deleted! "); | 1297 | qDebug("KSS::newConnection Socket deleted! "); |
1299 | delete mSocket; | 1298 | delete mSocket; |
1300 | mSocket = 0; | 1299 | mSocket = 0; |
1301 | } | 1300 | } |
1302 | mPendingConnect = 0; | 1301 | mPendingConnect = 0; |
1303 | mSocket = new QSocket( this ); | 1302 | mSocket = new QSocket( this ); |
1304 | connect( mSocket , SIGNAL(readyRead()), this, SLOT(readClient()) ); | 1303 | connect( mSocket , SIGNAL(readyRead()), this, SLOT(readClient()) ); |
1305 | connect( mSocket , SIGNAL(delayedCloseFinished()), this, SLOT(discardClient()) ); | 1304 | connect( mSocket , SIGNAL(delayedCloseFinished()), this, SLOT(discardClient()) ); |
1306 | mSocket->setSocket( socket ); | 1305 | mSocket->setSocket( socket ); |
1307 | } | 1306 | } |
1308 | 1307 | ||
1309 | void KServerSocket::discardClient() | 1308 | void KServerSocket::discardClient() |
1310 | { | 1309 | { |
1311 | QTimer::singleShot( 10, this , SLOT ( deleteSocket())); | 1310 | QTimer::singleShot( 10, this , SLOT ( deleteSocket())); |
1312 | } | 1311 | } |
1313 | void KServerSocket::deleteSocket() | 1312 | void KServerSocket::deleteSocket() |
1314 | { | 1313 | { |
1315 | qDebug("KSS::deleteSocket"); | 1314 | //qDebug("KSS::deleteSocket"); |
1316 | if ( mSocket ) { | 1315 | if ( mSocket ) { |
1317 | delete mSocket; | 1316 | delete mSocket; |
1318 | mSocket = 0; | 1317 | mSocket = 0; |
1319 | } | 1318 | } |
1320 | if ( mErrorMessage ) | 1319 | if ( mErrorMessage ) |
1321 | QTimer::singleShot( 10, this , SLOT ( displayErrorMessage())); | 1320 | QTimer::singleShot( 10, this , SLOT ( displayErrorMessage())); |
1322 | } | 1321 | } |
1323 | void KServerSocket::readClient() | 1322 | void KServerSocket::readClient() |
1324 | { | 1323 | { |
1325 | if ( blockRC ) | 1324 | if ( blockRC ) |
1326 | return; | 1325 | return; |
1327 | if ( mSocket == 0 ) { | 1326 | if ( mSocket == 0 ) { |
1328 | qDebug("ERROR::KSS::readClient(): mSocket == 0 "); | 1327 | qDebug("ERROR::KSS::readClient(): mSocket == 0 "); |
1329 | return; | 1328 | return; |
1330 | } | 1329 | } |
1331 | if ( mErrorMessage ) { | 1330 | if ( mErrorMessage ) { |
1332 | mErrorMessage = 999; | 1331 | mErrorMessage = 999; |
1333 | error_connect("ERROR_ED\r\n\r\n"); | 1332 | error_connect("ERROR_ED\r\n\r\n"); |
1334 | return; | 1333 | return; |
1335 | } | 1334 | } |
1336 | mResource = ""; | 1335 | mResource = ""; |
1337 | mErrorMessage = 0; | 1336 | mErrorMessage = 0; |
1338 | //qDebug("KServerSocket::readClient()"); | 1337 | //qDebug("KServerSocket::readClient()"); |
1339 | if ( mSocket->canReadLine() ) { | 1338 | if ( mSocket->canReadLine() ) { |
1340 | QString line = mSocket->readLine(); | 1339 | QString line = mSocket->readLine(); |
1341 | //qDebug("KServerSocket readline: %s ", line.latin1()); | 1340 | //qDebug("KServerSocket readline: %s ", line.latin1()); |
1342 | QStringList tokens = QStringList::split( QRegExp("[ \r\n][ \r\n]*"), line ); | 1341 | QStringList tokens = QStringList::split( QRegExp("[ \r\n][ \r\n]*"), line ); |
1343 | if ( tokens[0] == "GET" ) { | 1342 | if ( tokens[0] == "GET" ) { |
1344 | if ( tokens[1] == mPassWord ) { | 1343 | if ( tokens[1] == mPassWord ) { |
1345 | //emit sendFile( mSocket ); | 1344 | //emit sendFile( mSocket ); |
1346 | bool ok = false; | 1345 | bool ok = false; |
1347 | QDateTime dt = KGlobal::locale()->readDateTime( tokens[2], KLocale::ISODate, &ok); | 1346 | QDateTime dt = KGlobal::locale()->readDateTime( tokens[2], KLocale::ISODate, &ok); |
1348 | if ( ok ) { | 1347 | if ( ok ) { |
1349 | KSyncManager::mRequestedSyncEvent = dt; | 1348 | KSyncManager::mRequestedSyncEvent = dt; |
1350 | } | 1349 | } |
1351 | else | 1350 | else |
1352 | KSyncManager::mRequestedSyncEvent = QDateTime(); | 1351 | KSyncManager::mRequestedSyncEvent = QDateTime(); |
1353 | mResource =tokens[3]; | 1352 | mResource =tokens[3]; |
1354 | send_file(); | 1353 | send_file(); |
1355 | } | 1354 | } |
1356 | else { | 1355 | else { |
1357 | mErrorMessage = 1; | 1356 | mErrorMessage = 1; |
1358 | error_connect("ERROR_PW\r\n\r\n"); | 1357 | error_connect("ERROR_PW\r\n\r\n"); |
1359 | } | 1358 | } |
1360 | } | 1359 | } |
1361 | if ( tokens[0] == "PUT" ) { | 1360 | if ( tokens[0] == "PUT" ) { |
1362 | if ( tokens[1] == mPassWord ) { | 1361 | if ( tokens[1] == mPassWord ) { |
1363 | //emit getFile( mSocket ); | 1362 | //emit getFile( mSocket ); |
1364 | blockRC = true; | 1363 | blockRC = true; |
1365 | mResource =tokens[2]; | 1364 | mResource =tokens[2]; |
1366 | get_file(); | 1365 | get_file(); |
1367 | } | 1366 | } |
1368 | else { | 1367 | else { |
1369 | mErrorMessage = 2; | 1368 | mErrorMessage = 2; |
1370 | error_connect("ERROR_PW\r\n\r\n"); | 1369 | error_connect("ERROR_PW\r\n\r\n"); |
1371 | end_connect(); | 1370 | end_connect(); |
1372 | } | 1371 | } |
1373 | } | 1372 | } |
1374 | if ( tokens[0] == "STOP" ) { | 1373 | if ( tokens[0] == "STOP" ) { |
1375 | //emit endConnect(); | 1374 | //emit endConnect(); |
1376 | end_connect(); | 1375 | end_connect(); |
1377 | } | 1376 | } |
1378 | } | 1377 | } |
1379 | } | 1378 | } |
@@ -1539,129 +1538,129 @@ void KServerSocket::readBackFileFromSocket() | |||
1539 | file.close(); | 1538 | file.close(); |
1540 | piFileString = ""; | 1539 | piFileString = ""; |
1541 | emit file_received( true, mResource ); | 1540 | emit file_received( true, mResource ); |
1542 | emit file_received( true); | 1541 | emit file_received( true); |
1543 | delete mSyncActionDialog; | 1542 | delete mSyncActionDialog; |
1544 | mSyncActionDialog = 0; | 1543 | mSyncActionDialog = 0; |
1545 | blockRC = false; | 1544 | blockRC = false; |
1546 | 1545 | ||
1547 | } | 1546 | } |
1548 | 1547 | ||
1549 | KCommandSocket::KCommandSocket ( QString remres, QString password, Q_UINT16 port, QString host, QObject * parent, QWidget * cap, const char * name ): QObject( parent, name ) | 1548 | KCommandSocket::KCommandSocket ( QString remres, QString password, Q_UINT16 port, QString host, QObject * parent, QWidget * cap, const char * name ): QObject( parent, name ) |
1550 | { | 1549 | { |
1551 | mRemoteResource = remres; | 1550 | mRemoteResource = remres; |
1552 | if ( mRemoteResource.isEmpty() ) | 1551 | if ( mRemoteResource.isEmpty() ) |
1553 | mRemoteResource = "ALL"; | 1552 | mRemoteResource = "ALL"; |
1554 | else | 1553 | else |
1555 | mRemoteResource.replace (QRegExp (" "),"_" ); | 1554 | mRemoteResource.replace (QRegExp (" "),"_" ); |
1556 | mPassWord = password; | 1555 | mPassWord = password; |
1557 | mSocket = 0; | 1556 | mSocket = 0; |
1558 | mFirst = false; | 1557 | mFirst = false; |
1559 | mFirstLine = true; | 1558 | mFirstLine = true; |
1560 | mPort = port; | 1559 | mPort = port; |
1561 | mHost = host; | 1560 | mHost = host; |
1562 | tlw = cap; | 1561 | tlw = cap; |
1563 | mRetVal = quiet; | 1562 | mRetVal = quiet; |
1564 | mTimerSocket = new QTimer ( this ); | 1563 | mTimerSocket = new QTimer ( this ); |
1565 | connect( mTimerSocket, SIGNAL ( timeout () ), this, SLOT ( updateConnectDialog() ) ); | 1564 | connect( mTimerSocket, SIGNAL ( timeout () ), this, SLOT ( updateConnectDialog() ) ); |
1566 | mConnectProgress.setCaption( i18n("Pi-Sync") ); | 1565 | mConnectProgress.setCaption( i18n("Pi-Sync") ); |
1567 | connect( &mConnectProgress, SIGNAL ( cancelled () ), this, SLOT ( deleteSocket() ) ); | 1566 | connect( &mConnectProgress, SIGNAL ( cancelled () ), this, SLOT ( deleteSocket() ) ); |
1568 | mConnectCount = -1; | 1567 | mConnectCount = -1; |
1569 | } | 1568 | } |
1570 | void KCommandSocket::sendFileRequest() | 1569 | void KCommandSocket::sendFileRequest() |
1571 | { | 1570 | { |
1572 | if ( tlw ) | 1571 | if ( tlw ) |
1573 | tlw->setCaption( i18n("Connected! Sending request for remote file ...") ); | 1572 | tlw->setCaption( i18n("Connected! Sending request for remote file ...") ); |
1574 | mConnectProgress.hide(); | 1573 | mConnectProgress.hide(); |
1575 | mConnectCount = 300;mConnectMax = 300; | 1574 | mConnectCount = 300;mConnectMax = 300; |
1576 | mConnectProgress.setCaption( i18n("Pi-Sync: Connected!") ); | 1575 | mConnectProgress.setCaption( i18n("Pi-Sync: Connected!") ); |
1577 | mConnectProgress.setLabelText( i18n("Waiting for remote file...") ); | 1576 | mConnectProgress.setLabelText( i18n("Waiting for remote file...") ); |
1578 | mTimerSocket->start( 100, true ); | 1577 | mTimerSocket->start( 100, true ); |
1579 | QTextStream os( mSocket ); | 1578 | QTextStream os( mSocket ); |
1580 | os.setEncoding( QTextStream::Latin1 ); | 1579 | os.setEncoding( QTextStream::Latin1 ); |
1581 | 1580 | ||
1582 | QString curDt = " " +KGlobal::locale()->formatDateTime(QDateTime::currentDateTime().addSecs(-1),true, true,KLocale::ISODate ); | 1581 | QString curDt = " " +KGlobal::locale()->formatDateTime(QDateTime::currentDateTime().addSecs(-1),true, true,KLocale::ISODate ); |
1583 | os << "GET " << mPassWord << curDt << " " << mRemoteResource << "\r\n\r\n"; | 1582 | os << "GET " << mPassWord << curDt << " " << mRemoteResource << "\r\n\r\n"; |
1584 | } | 1583 | } |
1585 | 1584 | ||
1586 | void KCommandSocket::readFile( QString fn ) | 1585 | void KCommandSocket::readFile( QString fn ) |
1587 | { | 1586 | { |
1588 | if ( !mSocket ) { | 1587 | if ( !mSocket ) { |
1589 | mSocket = new QSocket( this ); | 1588 | mSocket = new QSocket( this ); |
1590 | //qDebug("KCS: read file - new socket"); | 1589 | //qDebug("KCS: read file - new socket"); |
1591 | connect( mSocket, SIGNAL(readyRead()), this, SLOT(startReadFileFromSocket()) ); | 1590 | connect( mSocket, SIGNAL(readyRead()), this, SLOT(startReadFileFromSocket()) ); |
1592 | connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) ); | 1591 | connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) ); |
1593 | connect( mSocket, SIGNAL(connected ()), this, SLOT(sendFileRequest() )); | 1592 | connect( mSocket, SIGNAL(connected ()), this, SLOT(sendFileRequest() )); |
1594 | } | 1593 | } |
1595 | mFileString = ""; | 1594 | mFileString = ""; |
1596 | mFileName = fn; | 1595 | mFileName = fn; |
1597 | mFirst = true; | 1596 | mFirst = true; |
1598 | if ( tlw ) | 1597 | if ( tlw ) |
1599 | tlw->setCaption( i18n("Trying to connect to remote...") ); | 1598 | tlw->setCaption( i18n("Trying to connect to remote...") ); |
1600 | mConnectCount = 30;mConnectMax = 30; | 1599 | mConnectCount = 30;mConnectMax = 30; |
1601 | mTimerSocket->start( 1000, true ); | 1600 | mTimerSocket->start( 1000, true ); |
1602 | mSocket->connectToHost( mHost, mPort ); | 1601 | mSocket->connectToHost( mHost, mPort ); |
1603 | qDebug("KCS: Waiting for connection"); | 1602 | //qDebug("KCS: Waiting for connection"); |
1604 | } | 1603 | } |
1605 | void KCommandSocket::updateConnectDialog() | 1604 | void KCommandSocket::updateConnectDialog() |
1606 | { | 1605 | { |
1607 | 1606 | ||
1608 | if ( mConnectCount == mConnectMax ) { | 1607 | if ( mConnectCount == mConnectMax ) { |
1609 | //qDebug("MAXX %d", mConnectMax); | 1608 | //qDebug("MAXX %d", mConnectMax); |
1610 | mConnectProgress.setTotalSteps ( 30 ); | 1609 | mConnectProgress.setTotalSteps ( 30 ); |
1611 | mConnectProgress.show(); | 1610 | mConnectProgress.show(); |
1612 | mConnectProgress.setLabelText( i18n("Trying to connect to remote...") ); | 1611 | mConnectProgress.setLabelText( i18n("Trying to connect to remote...") ); |
1613 | } | 1612 | } |
1614 | //qDebug("updateConnectDialog() %d", mConnectCount); | 1613 | //qDebug("updateConnectDialog() %d", mConnectCount); |
1615 | mConnectProgress.raise(); | 1614 | mConnectProgress.raise(); |
1616 | mConnectProgress.setProgress( (mConnectMax - mConnectCount)%30 ); | 1615 | mConnectProgress.setProgress( (mConnectMax - mConnectCount)%30 ); |
1617 | --mConnectCount; | 1616 | --mConnectCount; |
1618 | if ( mConnectCount > 0 ) | 1617 | if ( mConnectCount > 0 ) |
1619 | mTimerSocket->start( 1000, true ); | 1618 | mTimerSocket->start( 1000, true ); |
1620 | else | 1619 | else |
1621 | deleteSocket(); | 1620 | deleteSocket(); |
1622 | 1621 | ||
1623 | } | 1622 | } |
1624 | void KCommandSocket::writeFile( QString fileName ) | 1623 | void KCommandSocket::writeFile( QString fileName ) |
1625 | { | 1624 | { |
1626 | if ( !mSocket ) { | 1625 | if ( !mSocket ) { |
1627 | mSocket = new QSocket( this ); | 1626 | mSocket = new QSocket( this ); |
1628 | connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) ); | 1627 | connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) ); |
1629 | connect( mSocket, SIGNAL(connected ()), this, SLOT(writeFileToSocket()) ); | 1628 | connect( mSocket, SIGNAL(connected ()), this, SLOT(writeFileToSocket()) ); |
1630 | } | 1629 | } |
1631 | mFileName = fileName ; | 1630 | mFileName = fileName ; |
1632 | mConnectCount = 30;mConnectMax = 30; | 1631 | mConnectCount = 30;mConnectMax = 30; |
1633 | mTimerSocket->start( 1000, true ); | 1632 | mTimerSocket->start( 1000, true ); |
1634 | mSocket->connectToHost( mHost, mPort ); | 1633 | mSocket->connectToHost( mHost, mPort ); |
1635 | } | 1634 | } |
1636 | void KCommandSocket::writeFileToSocket() | 1635 | void KCommandSocket::writeFileToSocket() |
1637 | { | 1636 | { |
1638 | mTimerSocket->stop(); | 1637 | mTimerSocket->stop(); |
1639 | QFile file2( mFileName ); | 1638 | QFile file2( mFileName ); |
1640 | if (!file2.open( IO_ReadOnly ) ) { | 1639 | if (!file2.open( IO_ReadOnly ) ) { |
1641 | mConnectProgress.hide(); | 1640 | mConnectProgress.hide(); |
1642 | mConnectCount = -1; | 1641 | mConnectCount = -1; |
1643 | mRetVal= errorW; | 1642 | mRetVal= errorW; |
1644 | mSocket->close(); | 1643 | mSocket->close(); |
1645 | if ( mSocket->state() == QSocket::Idle ) | 1644 | if ( mSocket->state() == QSocket::Idle ) |
1646 | QTimer::singleShot( 10, this , SLOT ( deleteSocket())); | 1645 | QTimer::singleShot( 10, this , SLOT ( deleteSocket())); |
1647 | return ; | 1646 | return ; |
1648 | } | 1647 | } |
1649 | mConnectProgress.setTotalSteps ( file2.size() ); | 1648 | mConnectProgress.setTotalSteps ( file2.size() ); |
1650 | mConnectProgress.show(); | 1649 | mConnectProgress.show(); |
1651 | int count = 0; | 1650 | int count = 0; |
1652 | mConnectProgress.setLabelText( i18n("Sending back synced file...") ); | 1651 | mConnectProgress.setLabelText( i18n("Sending back synced file...") ); |
1653 | mConnectProgress.setProgress( count ); | 1652 | mConnectProgress.setProgress( count ); |
1654 | mConnectProgress.blockSignals( true ); | 1653 | mConnectProgress.blockSignals( true ); |
1655 | QTextStream ts2( &file2 ); | 1654 | QTextStream ts2( &file2 ); |
1656 | ts2.setEncoding( QTextStream::Latin1 ); | 1655 | ts2.setEncoding( QTextStream::Latin1 ); |
1657 | QTextStream os2( mSocket ); | 1656 | QTextStream os2( mSocket ); |
1658 | os2.setEncoding( QTextStream::Latin1 ); | 1657 | os2.setEncoding( QTextStream::Latin1 ); |
1659 | os2 << "PUT " << mPassWord << " " << mRemoteResource << "\r\n\r\n";; | 1658 | os2 << "PUT " << mPassWord << " " << mRemoteResource << "\r\n\r\n";; |
1660 | int byteCount = 0; | 1659 | int byteCount = 0; |
1661 | int byteMax = file2.size()/53; | 1660 | int byteMax = file2.size()/53; |
1662 | while ( ! ts2.atEnd() ) { | 1661 | while ( ! ts2.atEnd() ) { |
1663 | qApp->processEvents(); | 1662 | qApp->processEvents(); |
1664 | if ( byteCount > byteMax ) { | 1663 | if ( byteCount > byteMax ) { |
1665 | byteCount = 0; | 1664 | byteCount = 0; |
1666 | mConnectProgress.setProgress( count ); | 1665 | mConnectProgress.setProgress( count ); |
1667 | } | 1666 | } |