summaryrefslogtreecommitdiffabout
path: root/libkdepim/ksyncmanager.cpp
authorzautrix <zautrix>2004-12-05 13:41:41 (UTC)
committer zautrix <zautrix>2004-12-05 13:41:41 (UTC)
commit06bebf5be01898145c4f721a8d002519141e7f3b (patch) (unidiff)
treebc44d996a58a63de8c43cb5ba54d55bf1494eb5c /libkdepim/ksyncmanager.cpp
parent5ab47964d8b52897bb0662ef4a5fcf9604acaf6c (diff)
downloadkdepimpi-06bebf5be01898145c4f721a8d002519141e7f3b.zip
kdepimpi-06bebf5be01898145c4f721a8d002519141e7f3b.tar.gz
kdepimpi-06bebf5be01898145c4f721a8d002519141e7f3b.tar.bz2
added better debug output to sync file problems
Diffstat (limited to 'libkdepim/ksyncmanager.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--libkdepim/ksyncmanager.cpp4
1 files changed, 2 insertions, 2 deletions
diff --git a/libkdepim/ksyncmanager.cpp b/libkdepim/ksyncmanager.cpp
index c12ba1c..7c53948 100644
--- a/libkdepim/ksyncmanager.cpp
+++ b/libkdepim/ksyncmanager.cpp
@@ -275,257 +275,257 @@ void KSyncManager::slotSyncMenu( int action )
275 { 275 {
276 case (KAPI): 276 case (KAPI):
277 if ( syncWithFile( temp->getRemoteFileNameAB( ), false ) ) 277 if ( syncWithFile( temp->getRemoteFileNameAB( ), false ) )
278 mPrefs->mLastSyncedLocalFile = temp->getRemoteFileNameAB(); 278 mPrefs->mLastSyncedLocalFile = temp->getRemoteFileNameAB();
279 break; 279 break;
280 case (KOPI): 280 case (KOPI):
281 if ( syncWithFile( temp->getRemoteFileName( ), false ) ) 281 if ( syncWithFile( temp->getRemoteFileName( ), false ) )
282 mPrefs->mLastSyncedLocalFile = temp->getRemoteFileName(); 282 mPrefs->mLastSyncedLocalFile = temp->getRemoteFileName();
283 break; 283 break;
284 case (PWMPI): 284 case (PWMPI):
285 if ( syncWithFile( temp->getRemoteFileNamePWM( ), false ) ) 285 if ( syncWithFile( temp->getRemoteFileNamePWM( ), false ) )
286 mPrefs->mLastSyncedLocalFile = temp->getRemoteFileNamePWM(); 286 mPrefs->mLastSyncedLocalFile = temp->getRemoteFileNamePWM();
287 break; 287 break;
288 default: 288 default:
289 qDebug("KSyncManager::slotSyncMenu: invalid apptype selected"); 289 qDebug("KSyncManager::slotSyncMenu: invalid apptype selected");
290 break; 290 break;
291 291
292 } 292 }
293 } else { 293 } else {
294 if ( temp->getIsPhoneSync() ) { 294 if ( temp->getIsPhoneSync() ) {
295 mPhoneDevice = temp->getPhoneDevice( ) ; 295 mPhoneDevice = temp->getPhoneDevice( ) ;
296 mPhoneConnection = temp->getPhoneConnection( ); 296 mPhoneConnection = temp->getPhoneConnection( );
297 mPhoneModel = temp->getPhoneModel( ); 297 mPhoneModel = temp->getPhoneModel( );
298 syncPhone(); 298 syncPhone();
299 } else if ( temp->getIsPiSync() ) { 299 } else if ( temp->getIsPiSync() ) {
300 if ( mTargetApp == KAPI ) { 300 if ( mTargetApp == KAPI ) {
301 mPassWordPiSync = temp->getRemotePwAB(); 301 mPassWordPiSync = temp->getRemotePwAB();
302 mActiveSyncPort = temp->getRemotePortAB(); 302 mActiveSyncPort = temp->getRemotePortAB();
303 mActiveSyncIP = temp->getRemoteIPAB(); 303 mActiveSyncIP = temp->getRemoteIPAB();
304 } else if ( mTargetApp == KOPI ) { 304 } else if ( mTargetApp == KOPI ) {
305 mPassWordPiSync = temp->getRemotePw(); 305 mPassWordPiSync = temp->getRemotePw();
306 mActiveSyncPort = temp->getRemotePort(); 306 mActiveSyncPort = temp->getRemotePort();
307 mActiveSyncIP = temp->getRemoteIP(); 307 mActiveSyncIP = temp->getRemoteIP();
308 } else { 308 } else {
309 mPassWordPiSync = temp->getRemotePwPWM(); 309 mPassWordPiSync = temp->getRemotePwPWM();
310 mActiveSyncPort = temp->getRemotePortPWM(); 310 mActiveSyncPort = temp->getRemotePortPWM();
311 mActiveSyncIP = temp->getRemoteIPPWM(); 311 mActiveSyncIP = temp->getRemoteIPPWM();
312 } 312 }
313 syncPi(); 313 syncPi();
314 while ( !mPisyncFinished ) { 314 while ( !mPisyncFinished ) {
315 //qDebug("waiting "); 315 //qDebug("waiting ");
316 qApp->processEvents(); 316 qApp->processEvents();
317 } 317 }
318 } else 318 } else
319 syncRemote( temp ); 319 syncRemote( temp );
320 320
321 } 321 }
322 } 322 }
323 delete temp; 323 delete temp;
324 setBlockSave(false); 324 setBlockSave(false);
325} 325}
326 326
327void KSyncManager::enableQuick( bool ask ) 327void KSyncManager::enableQuick( bool ask )
328{ 328{
329 bool autoStart; 329 bool autoStart;
330 bool changed = false; 330 bool changed = false;
331 if ( ask ) { 331 if ( ask ) {
332 QDialog dia ( 0, "input-dialog", true ); 332 QDialog dia ( 0, "input-dialog", true );
333 QLineEdit lab ( &dia ); 333 QLineEdit lab ( &dia );
334 QVBoxLayout lay( &dia ); 334 QVBoxLayout lay( &dia );
335 lab.setText( mPrefs->mPassiveSyncPort ); 335 lab.setText( mPrefs->mPassiveSyncPort );
336 lay.setMargin(7); 336 lay.setMargin(7);
337 lay.setSpacing(7); 337 lay.setSpacing(7);
338 int po = 9197+mTargetApp; 338 int po = 9197+mTargetApp;
339 QLabel label ( i18n("Port number (Default: %1)").arg(po), &dia ); 339 QLabel label ( i18n("Port number (Default: %1)").arg(po), &dia );
340 lay.addWidget( &label); 340 lay.addWidget( &label);
341 lay.addWidget( &lab); 341 lay.addWidget( &lab);
342 342
343 QLineEdit lepw ( &dia ); 343 QLineEdit lepw ( &dia );
344 lepw.setText( mPrefs->mPassiveSyncPw ); 344 lepw.setText( mPrefs->mPassiveSyncPw );
345 QLabel label2 ( i18n("Password to enable\naccess from remote:"), &dia ); 345 QLabel label2 ( i18n("Password to enable\naccess from remote:"), &dia );
346 lay.addWidget( &label2); 346 lay.addWidget( &label2);
347 lay.addWidget( &lepw); 347 lay.addWidget( &lepw);
348 QCheckBox autostart(i18n("Automatically start\nat application startup"), &dia ); 348 QCheckBox autostart(i18n("Automatically start\nat application startup"), &dia );
349 lay.addWidget( &autostart); 349 lay.addWidget( &autostart);
350 autostart.setChecked( mPrefs->mPassiveSyncAutoStart ); 350 autostart.setChecked( mPrefs->mPassiveSyncAutoStart );
351#ifdef DESKTOP_VERSION 351#ifdef DESKTOP_VERSION
352#ifdef _WIN32_ 352#ifdef _WIN32_
353 QCheckBox syncdesktop( i18n("Automatically sync with Outlook\nwhen receiving sync request"),&dia ); 353 QCheckBox syncdesktop( i18n("Automatically sync with Outlook\nwhen receiving sync request"),&dia );
354 syncdesktop.hide();// not implemented! 354 syncdesktop.hide();// not implemented!
355#else 355#else
356 QCheckBox syncdesktop( i18n("Automatically sync with KDE-Desktop\nwhen receiving sync request"),&dia ); 356 QCheckBox syncdesktop( i18n("Automatically sync with KDE-Desktop\nwhen receiving sync request"),&dia );
357#endif 357#endif
358 lay.addWidget( &syncdesktop); 358 lay.addWidget( &syncdesktop);
359#else 359#else
360 mPrefs->mPassiveSyncWithDesktop = false; 360 mPrefs->mPassiveSyncWithDesktop = false;
361 QCheckBox syncdesktop( i18n("Automatically sync\nwith KDE-Desktop"),&dia ); 361 QCheckBox syncdesktop( i18n("Automatically sync\nwith KDE-Desktop"),&dia );
362 syncdesktop.hide(); 362 syncdesktop.hide();
363#endif 363#endif
364 syncdesktop.setChecked( mPrefs->mPassiveSyncWithDesktop ); 364 syncdesktop.setChecked( mPrefs->mPassiveSyncWithDesktop );
365 365
366 dia.setFixedSize( 230,120 ); 366 dia.setFixedSize( 230,120 );
367 dia.setCaption( i18n("Enter port for Pi-Sync") ); 367 dia.setCaption( i18n("Enter port for Pi-Sync") );
368 QPushButton pb ( "OK", &dia); 368 QPushButton pb ( "OK", &dia);
369 lay.addWidget( &pb ); 369 lay.addWidget( &pb );
370 connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) ); 370 connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) );
371 dia.show(); 371 dia.show();
372 if ( ! dia.exec() ) 372 if ( ! dia.exec() )
373 return; 373 return;
374 dia.hide(); 374 dia.hide();
375 qApp->processEvents(); 375 qApp->processEvents();
376 if ( mPrefs->mPassiveSyncPw != lepw.text() ) { 376 if ( mPrefs->mPassiveSyncPw != lepw.text() ) {
377 changed = true; 377 changed = true;
378 mPrefs->mPassiveSyncPw = lepw.text(); 378 mPrefs->mPassiveSyncPw = lepw.text();
379 } 379 }
380 if ( mPrefs->mPassiveSyncPort != lab.text() ) { 380 if ( mPrefs->mPassiveSyncPort != lab.text() ) {
381 mPrefs->mPassiveSyncPort = lab.text(); 381 mPrefs->mPassiveSyncPort = lab.text();
382 changed = true; 382 changed = true;
383 } 383 }
384 autoStart = autostart.isChecked(); 384 autoStart = autostart.isChecked();
385 if (mPrefs->mPassiveSyncWithDesktop != syncdesktop.isChecked() ) { 385 if (mPrefs->mPassiveSyncWithDesktop != syncdesktop.isChecked() ) {
386 changed = true; 386 changed = true;
387 mPrefs->mPassiveSyncWithDesktop = syncdesktop.isChecked(); 387 mPrefs->mPassiveSyncWithDesktop = syncdesktop.isChecked();
388 } 388 }
389 } 389 }
390 else 390 else
391 autoStart = mPrefs->mPassiveSyncAutoStart; 391 autoStart = mPrefs->mPassiveSyncAutoStart;
392 if ( autoStart != mPrefs->mPassiveSyncAutoStart ) 392 if ( autoStart != mPrefs->mPassiveSyncAutoStart )
393 changed = true; 393 changed = true;
394 bool ok; 394 bool ok;
395 mPrefs->mPassiveSyncAutoStart = false; 395 mPrefs->mPassiveSyncAutoStart = false;
396 Q_UINT16 port = mPrefs->mPassiveSyncPort.toUInt(&ok); 396 Q_UINT16 port = mPrefs->mPassiveSyncPort.toUInt(&ok);
397 if ( ! ok ) { 397 if ( ! ok ) {
398 KMessageBox::information( 0, i18n("No valid port")); 398 KMessageBox::information( 0, i18n("No valid port"));
399 return; 399 return;
400 } 400 }
401 //qDebug("port %d ", port); 401 //qDebug("port %d ", port);
402 mServerSocket = new KServerSocket ( mPrefs->mPassiveSyncPw, port ,1 ); 402 mServerSocket = new KServerSocket ( mPrefs->mPassiveSyncPw, port ,1 );
403 mServerSocket->setFileName( defaultFileName() ); 403 mServerSocket->setFileName( defaultFileName() );//bbb
404 //qDebug("connected "); 404 //qDebug("connected ");
405 if ( !mServerSocket->ok() ) { 405 if ( !mServerSocket->ok() ) {
406 KMessageBox::information( 0, i18n("Failed to bind or\nlisten to the port!")); 406 KMessageBox::information( 0, i18n("Failed to bind or\nlisten to the port!"));
407 delete mServerSocket; 407 delete mServerSocket;
408 mServerSocket = 0; 408 mServerSocket = 0;
409 return; 409 return;
410 } 410 }
411 mPrefs->mPassiveSyncAutoStart = autoStart; 411 mPrefs->mPassiveSyncAutoStart = autoStart;
412 if ( changed ) { 412 if ( changed ) {
413 mPrefs->writeConfig(); 413 mPrefs->writeConfig();
414 } 414 }
415 connect( mServerSocket, SIGNAL ( request_file() ),this, SIGNAL ( request_file() ) ); 415 connect( mServerSocket, SIGNAL ( request_file() ),this, SIGNAL ( request_file() ) );
416 connect( mServerSocket, SIGNAL ( file_received( bool ) ), this, SIGNAL ( getFile( bool ) ) ); 416 connect( mServerSocket, SIGNAL ( file_received( bool ) ), this, SIGNAL ( getFile( bool ) ) );
417} 417}
418 418
419void KSyncManager::syncLocalFile() 419void KSyncManager::syncLocalFile()
420{ 420{
421 421
422 QString fn =mPrefs->mLastSyncedLocalFile; 422 QString fn =mPrefs->mLastSyncedLocalFile;
423 QString ext; 423 QString ext;
424 424
425 switch(mTargetApp) 425 switch(mTargetApp)
426 { 426 {
427 case (KAPI): 427 case (KAPI):
428 ext = "(*.vcf)"; 428 ext = "(*.vcf)";
429 break; 429 break;
430 case (KOPI): 430 case (KOPI):
431 ext = "(*.ics/*.vcs)"; 431 ext = "(*.ics/*.vcs)";
432 break; 432 break;
433 case (PWMPI): 433 case (PWMPI):
434 ext = "(*.pwm)"; 434 ext = "(*.pwm)";
435 break; 435 break;
436 default: 436 default:
437 qDebug("KSyncManager::syncLocalFile: invalid apptype selected"); 437 qDebug("KSyncManager::syncLocalFile: invalid apptype selected");
438 break; 438 break;
439 439
440 } 440 }
441 441
442 fn =KFileDialog:: getOpenFileName( fn, i18n("Sync filename"+ext), mParent ); 442 fn =KFileDialog:: getOpenFileName( fn, i18n("Sync filename"+ext), mParent );
443 if ( fn == "" ) 443 if ( fn == "" )
444 return; 444 return;
445 if ( syncWithFile( fn, false ) ) { 445 if ( syncWithFile( fn, false ) ) {
446 qDebug("syncLocalFile() successful "); 446 qDebug("syncLocalFile() successful ");
447 } 447 }
448 448
449} 449}
450 450
451bool KSyncManager::syncWithFile( QString fn , bool quick ) 451bool KSyncManager::syncWithFile( QString fn , bool quick )
452{ 452{
453 bool ret = false; 453 bool ret = false;
454 QFileInfo info; 454 QFileInfo info;
455 info.setFile( fn ); 455 info.setFile( fn );
456 QString mess; 456 QString mess;
457 bool loadbup = true; 457 bool loadbup = true;
458 if ( !info. exists() ) { 458 if ( !info. exists() ) {
459 mess = i18n( "Sync file \n...%1\ndoes not exist!\nNothing synced!\n").arg(fn.right( 30) ); 459 mess = i18n( "Sync file \n...%1\ndoes not exist!\nNothing synced!\n").arg(fn.right( 30) );
460 int result = QMessageBox::warning( mParent, i18n("Warning!"), 460 int result = QMessageBox::warning( mParent, i18n("Warning!"),
461 mess ); 461 mess );
462 return ret; 462 return ret;
463 } 463 }
464 int result = 0; 464 int result = 0;
465 if ( !quick ) { 465 if ( !quick ) {
466 mess = i18n("Sync with file \n...%1\nfrom:\n%2\n").arg(fn.right( 25)).arg(KGlobal::locale()->formatDateTime(info.lastModified (), true, false )); 466 mess = i18n("Sync with file \n...%1\nfrom:\n%2\n").arg(fn.right( 25)).arg(KGlobal::locale()->formatDateTime(info.lastModified (), true, false ));
467 result = QMessageBox::warning( mParent, i18n("Warning!"), 467 result = QMessageBox::warning( mParent, i18n("Warning!"),
468 mess, 468 mess,
469 i18n("Sync"), i18n("Cancel"), 0, 469 i18n("Sync"), i18n("Cancel"), 0,
470 0, 1 ); 470 0, 1 );
471 if ( result ) 471 if ( result )
472 return false; 472 return false;
473 } 473 }
474 if ( mAskForPreferences ) 474 if ( mAskForPreferences )
475 if ( !edit_sync_options()) { 475 if ( !edit_sync_options()) {
476 mParent->topLevelWidget()->setCaption( i18n("Syncing aborted. Nothing synced.") ); 476 mParent->topLevelWidget()->setCaption( i18n("Syncing aborted. Nothing synced.") );
477 return false; 477 return false;
478 } 478 }
479 if ( result == 0 ) { 479 if ( result == 0 ) {
480 //qDebug("Now sycing ... "); 480 //qDebug("Now sycing ... ");
481 if ( ret = mImplementation->sync( this, fn, mSyncAlgoPrefs ) ) 481 if ( ret = mImplementation->sync( this, fn, mSyncAlgoPrefs ) )
482 mParent->topLevelWidget()->setCaption( i18n("Synchronization successful") ); 482 mParent->topLevelWidget()->setCaption( i18n("Synchronization successful") );
483 else 483 else
484 mParent->topLevelWidget()->setCaption( i18n("Sync cancelled or failed.") ); 484 mParent->topLevelWidget()->setCaption( i18n("Sync cancelled or failed.") );
485 if ( ! quick ) 485 if ( ! quick )
486 mPrefs->mLastSyncedLocalFile = fn; 486 mPrefs->mLastSyncedLocalFile = fn;
487 } 487 }
488 return ret; 488 return ret;
489} 489}
490 490
491void KSyncManager::quickSyncLocalFile() 491void KSyncManager::quickSyncLocalFile()
492{ 492{
493 493
494 if ( syncWithFile( mPrefs->mLastSyncedLocalFile, true ) ) { 494 if ( syncWithFile( mPrefs->mLastSyncedLocalFile, true ) ) {
495 qDebug("quick syncLocalFile() successful "); 495 qDebug("quick syncLocalFile() successful ");
496 496
497 } 497 }
498} 498}
499 499
500void KSyncManager::multiSync( bool askforPrefs ) 500void KSyncManager::multiSync( bool askforPrefs )
501{ 501{
502 if (blockSave()) 502 if (blockSave())
503 return; 503 return;
504 setBlockSave(true); 504 setBlockSave(true);
505 QString question = i18n("Do you really want\nto multiple sync\nwith all checked profiles?\nSyncing takes some\ntime - all profiles\nare synced twice!"); 505 QString question = i18n("Do you really want\nto multiple sync\nwith all checked profiles?\nSyncing takes some\ntime - all profiles\nare synced twice!");
506 if ( QMessageBox::information( mParent, i18n("KDE-Pim Sync"), 506 if ( QMessageBox::information( mParent, i18n("KDE-Pim Sync"),
507 question, 507 question,
508 i18n("Yes"), i18n("No"), 508 i18n("Yes"), i18n("No"),
509 0, 0 ) != 0 ) { 509 0, 0 ) != 0 ) {
510 setBlockSave(false); 510 setBlockSave(false);
511 mParent->topLevelWidget()->setCaption(i18n("Aborted! Nothing synced!")); 511 mParent->topLevelWidget()->setCaption(i18n("Aborted! Nothing synced!"));
512 return; 512 return;
513 } 513 }
514 mCurrentSyncDevice = i18n("Multiple profiles") ; 514 mCurrentSyncDevice = i18n("Multiple profiles") ;
515 mSyncAlgoPrefs = mPrefs->mRingSyncAlgoPrefs; 515 mSyncAlgoPrefs = mPrefs->mRingSyncAlgoPrefs;
516 if ( askforPrefs ) { 516 if ( askforPrefs ) {
517 if ( !edit_sync_options()) { 517 if ( !edit_sync_options()) {
518 mParent->topLevelWidget()->setCaption( i18n("Syncing aborted.") ); 518 mParent->topLevelWidget()->setCaption( i18n("Syncing aborted.") );
519 return; 519 return;
520 } 520 }
521 mPrefs->mRingSyncAlgoPrefs = mSyncAlgoPrefs; 521 mPrefs->mRingSyncAlgoPrefs = mSyncAlgoPrefs;
522 } 522 }
523 mParent->topLevelWidget()->setCaption(i18n("Multiple sync started.") ); 523 mParent->topLevelWidget()->setCaption(i18n("Multiple sync started.") );
524 qApp->processEvents(); 524 qApp->processEvents();
525 int num = ringSync() ; 525 int num = ringSync() ;
526 if ( num > 1 ) 526 if ( num > 1 )
527 ringSync(); 527 ringSync();
528 setBlockSave(false); 528 setBlockSave(false);
529 if ( num ) 529 if ( num )
530 emit save(); 530 emit save();
531 if ( num ) 531 if ( num )
@@ -1112,257 +1112,257 @@ void KServerSocket::newConnection ( int socket )
1112 mSocket = 0; 1112 mSocket = 0;
1113 } 1113 }
1114 mSocket = new QSocket( this ); 1114 mSocket = new QSocket( this );
1115 connect( mSocket , SIGNAL(readyRead()), this, SLOT(readClient()) ); 1115 connect( mSocket , SIGNAL(readyRead()), this, SLOT(readClient()) );
1116 connect( mSocket , SIGNAL(delayedCloseFinished()), this, SLOT(discardClient()) ); 1116 connect( mSocket , SIGNAL(delayedCloseFinished()), this, SLOT(discardClient()) );
1117 mSocket->setSocket( socket ); 1117 mSocket->setSocket( socket );
1118} 1118}
1119 1119
1120void KServerSocket::discardClient() 1120void KServerSocket::discardClient()
1121{ 1121{
1122 //qDebug(" KServerSocket::discardClient()"); 1122 //qDebug(" KServerSocket::discardClient()");
1123 if ( mSocket ) { 1123 if ( mSocket ) {
1124 delete mSocket; 1124 delete mSocket;
1125 mSocket = 0; 1125 mSocket = 0;
1126 } 1126 }
1127 //emit endConnect(); 1127 //emit endConnect();
1128} 1128}
1129void KServerSocket::readClient() 1129void KServerSocket::readClient()
1130{ 1130{
1131 if ( blockRC ) 1131 if ( blockRC )
1132 return; 1132 return;
1133 if ( mSocket == 0 ) { 1133 if ( mSocket == 0 ) {
1134 qDebug("ERROR::KServerSocket::readClient(): mSocket == 0 "); 1134 qDebug("ERROR::KServerSocket::readClient(): mSocket == 0 ");
1135 return; 1135 return;
1136 } 1136 }
1137 //qDebug("KServerSocket::readClient()"); 1137 //qDebug("KServerSocket::readClient()");
1138 if ( mSocket->canReadLine() ) { 1138 if ( mSocket->canReadLine() ) {
1139 QString line = mSocket->readLine(); 1139 QString line = mSocket->readLine();
1140 //qDebug("KServerSocket readline: %s ", line.latin1()); 1140 //qDebug("KServerSocket readline: %s ", line.latin1());
1141 QStringList tokens = QStringList::split( QRegExp("[ \r\n][ \r\n]*"), line ); 1141 QStringList tokens = QStringList::split( QRegExp("[ \r\n][ \r\n]*"), line );
1142 if ( tokens[0] == "GET" ) { 1142 if ( tokens[0] == "GET" ) {
1143 if ( tokens[1] == mPassWord ) { 1143 if ( tokens[1] == mPassWord ) {
1144 //emit sendFile( mSocket ); 1144 //emit sendFile( mSocket );
1145 bool ok = false; 1145 bool ok = false;
1146 QDateTime dt = KGlobal::locale()->readDateTime( tokens[2], KLocale::ISODate, &ok); 1146 QDateTime dt = KGlobal::locale()->readDateTime( tokens[2], KLocale::ISODate, &ok);
1147 if ( ok ) { 1147 if ( ok ) {
1148 KSyncManager::mRequestedSyncEvent = dt; 1148 KSyncManager::mRequestedSyncEvent = dt;
1149 } 1149 }
1150 else 1150 else
1151 KSyncManager::mRequestedSyncEvent = QDateTime(); 1151 KSyncManager::mRequestedSyncEvent = QDateTime();
1152 send_file(); 1152 send_file();
1153 } 1153 }
1154 else { 1154 else {
1155 KMessageBox::error( 0, i18n("Got send file request\nwith invalid password")); 1155 KMessageBox::error( 0, i18n("Got send file request\nwith invalid password"));
1156 //qDebug("password %s, invalid password %s ",mPassWord.latin1(), tokens[1].latin1() ); 1156 //qDebug("password %s, invalid password %s ",mPassWord.latin1(), tokens[1].latin1() );
1157 } 1157 }
1158 } 1158 }
1159 if ( tokens[0] == "PUT" ) { 1159 if ( tokens[0] == "PUT" ) {
1160 if ( tokens[1] == mPassWord ) { 1160 if ( tokens[1] == mPassWord ) {
1161 //emit getFile( mSocket ); 1161 //emit getFile( mSocket );
1162 blockRC = true; 1162 blockRC = true;
1163 get_file(); 1163 get_file();
1164 } 1164 }
1165 else { 1165 else {
1166 KMessageBox::error( 0, i18n("Got receive file request\nwith invalid password")); 1166 KMessageBox::error( 0, i18n("Got receive file request\nwith invalid password"));
1167 //qDebug("password %s, invalid password %s ",mPassWord.latin1(), tokens[1].latin1() ); 1167 //qDebug("password %s, invalid password %s ",mPassWord.latin1(), tokens[1].latin1() );
1168 } 1168 }
1169 } 1169 }
1170 if ( tokens[0] == "STOP" ) { 1170 if ( tokens[0] == "STOP" ) {
1171 //emit endConnect(); 1171 //emit endConnect();
1172 end_connect(); 1172 end_connect();
1173 } 1173 }
1174 } 1174 }
1175} 1175}
1176void KServerSocket::end_connect() 1176void KServerSocket::end_connect()
1177{ 1177{
1178 delete mSyncActionDialog; 1178 delete mSyncActionDialog;
1179 mSyncActionDialog = 0; 1179 mSyncActionDialog = 0;
1180} 1180}
1181void KServerSocket::send_file() 1181void KServerSocket::send_file()
1182{ 1182{
1183 //qDebug("MainWindow::sendFile(QSocket* s) "); 1183 //qDebug("MainWindow::sendFile(QSocket* s) ");
1184 if ( mSyncActionDialog ) 1184 if ( mSyncActionDialog )
1185 delete mSyncActionDialog; 1185 delete mSyncActionDialog;
1186 mSyncActionDialog = new QDialog ( 0, "input-dialog", true ); 1186 mSyncActionDialog = new QDialog ( 0, "input-dialog", true );
1187 mSyncActionDialog->setCaption(i18n("Received sync request")); 1187 mSyncActionDialog->setCaption(i18n("Received sync request"));
1188 QLabel* label = new QLabel( i18n("Synchronizing from remote ...\n\nDo not use this application!\n\nIf syncing fails\nyou can close this dialog."), mSyncActionDialog ); 1188 QLabel* label = new QLabel( i18n("Synchronizing from remote ...\n\nDo not use this application!\n\nIf syncing fails\nyou can close this dialog."), mSyncActionDialog );
1189 label->setAlignment ( Qt::AlignHCenter ); 1189 label->setAlignment ( Qt::AlignHCenter );
1190 QVBoxLayout* lay = new QVBoxLayout( mSyncActionDialog ); 1190 QVBoxLayout* lay = new QVBoxLayout( mSyncActionDialog );
1191 lay->addWidget( label); 1191 lay->addWidget( label);
1192 lay->setMargin(7); 1192 lay->setMargin(7);
1193 lay->setSpacing(7); 1193 lay->setSpacing(7);
1194 if ( KSyncManager::mRequestedSyncEvent.isValid() ) { 1194 if ( KSyncManager::mRequestedSyncEvent.isValid() ) {
1195 int secs = QDateTime::currentDateTime().secsTo( KSyncManager::mRequestedSyncEvent ); 1195 int secs = QDateTime::currentDateTime().secsTo( KSyncManager::mRequestedSyncEvent );
1196 if ( secs < 0 ) 1196 if ( secs < 0 )
1197 secs = secs * (-1); 1197 secs = secs * (-1);
1198 if ( secs > 30 ) 1198 if ( secs > 30 )
1199 //if ( true ) 1199 //if ( true )
1200 { 1200 {
1201 QString warning = i18n("Clock skew of\nsyncing devices\nis %1 seconds!").arg( secs ); 1201 QString warning = i18n("Clock skew of\nsyncing devices\nis %1 seconds!").arg( secs );
1202 QLabel* label = new QLabel( warning, mSyncActionDialog ); 1202 QLabel* label = new QLabel( warning, mSyncActionDialog );
1203 label->setAlignment ( Qt::AlignHCenter ); 1203 label->setAlignment ( Qt::AlignHCenter );
1204 lay->addWidget( label); 1204 lay->addWidget( label);
1205 if ( secs > 180 ) 1205 if ( secs > 180 )
1206 { 1206 {
1207 if ( secs > 300 ) { 1207 if ( secs > 300 ) {
1208 if ( KMessageBox::Cancel == KMessageBox::warningContinueCancel(0, i18n("The clocks of the syncing\ndevices have a difference\n of more than 5 minutes.\nPlease adjust your clocks.\n<b>You may get wrong syncing results!<\b>\nPlease confirm synchronization!"), i18n("High clock skew!"),i18n("Synchronize!"))) { 1208 if ( KMessageBox::Cancel == KMessageBox::warningContinueCancel(0, i18n("The clocks of the syncing\ndevices have a difference\n of more than 5 minutes.\nPlease adjust your clocks.\n<b>You may get wrong syncing results!<\b>\nPlease confirm synchronization!"), i18n("High clock skew!"),i18n("Synchronize!"))) {
1209 qDebug("cancelled "); 1209 qDebug("cancelled ");
1210 return ; 1210 return ;
1211 } 1211 }
1212 } 1212 }
1213 QFont f = label->font(); 1213 QFont f = label->font();
1214 f.setPointSize ( f.pointSize() *2 ); 1214 f.setPointSize ( f.pointSize() *2 );
1215 f. setBold (true ); 1215 f. setBold (true );
1216 QLabel* label = new QLabel( warning, mSyncActionDialog ); 1216 QLabel* label = new QLabel( warning, mSyncActionDialog );
1217 label->setFont( f ); 1217 label->setFont( f );
1218 warning = i18n("ADJUST\nYOUR\nCLOCKS!"); 1218 warning = i18n("ADJUST\nYOUR\nCLOCKS!");
1219 label->setText( warning ); 1219 label->setText( warning );
1220 label->setAlignment ( Qt::AlignHCenter ); 1220 label->setAlignment ( Qt::AlignHCenter );
1221 lay->addWidget( label); 1221 lay->addWidget( label);
1222 mSyncActionDialog->setFixedSize( 230, 300); 1222 mSyncActionDialog->setFixedSize( 230, 300);
1223 } else { 1223 } else {
1224 mSyncActionDialog->setFixedSize( 230, 200); 1224 mSyncActionDialog->setFixedSize( 230, 200);
1225 } 1225 }
1226 } else { 1226 } else {
1227 mSyncActionDialog->setFixedSize( 230, 120); 1227 mSyncActionDialog->setFixedSize( 230, 120);
1228 } 1228 }
1229 } else 1229 } else
1230 mSyncActionDialog->setFixedSize( 230, 120); 1230 mSyncActionDialog->setFixedSize( 230, 120);
1231 mSyncActionDialog->show(); 1231 mSyncActionDialog->show();
1232 mSyncActionDialog->raise(); 1232 mSyncActionDialog->raise();
1233 emit request_file(); 1233 emit request_file();
1234 qApp->processEvents(); 1234 qApp->processEvents();
1235 QString fileName = mFileName; 1235 QString fileName = mFileName;
1236 QFile file( fileName ); 1236 QFile file( fileName );
1237 if (!file.open( IO_ReadOnly ) ) { 1237 if (!file.open( IO_ReadOnly ) ) {
1238 delete mSyncActionDialog; 1238 delete mSyncActionDialog;
1239 mSyncActionDialog = 0; 1239 mSyncActionDialog = 0;
1240 qDebug("KSS::error open file "); 1240 qDebug("KSS::error open sync file: %s ", fileName.latin1());
1241 mSocket->close(); 1241 mSocket->close();
1242 if ( mSocket->state() == QSocket::Idle ) 1242 if ( mSocket->state() == QSocket::Idle )
1243 QTimer::singleShot( 10, this , SLOT ( discardClient())); 1243 QTimer::singleShot( 10, this , SLOT ( discardClient()));
1244 return ; 1244 return ;
1245 1245
1246 } 1246 }
1247 mSyncActionDialog->setCaption( i18n("Sending file...") ); 1247 mSyncActionDialog->setCaption( i18n("Sending file...") );
1248 QTextStream ts( &file ); 1248 QTextStream ts( &file );
1249 ts.setEncoding( QTextStream::Latin1 ); 1249 ts.setEncoding( QTextStream::Latin1 );
1250 1250
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}
1263void KServerSocket::get_file() 1263void 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
1273void KServerSocket::readBackFileFromSocket() 1273void 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
1320KCommandSocket::KCommandSocket ( QString password, Q_UINT16 port, QString host, QObject * parent, const char * name ): QObject( parent, name ) 1320KCommandSocket::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}
1331void KCommandSocket::readFile( QString fn ) 1331void 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( 20000 );
1348} 1348}
1349 1349
1350void KCommandSocket::writeFile( QString fileName ) 1350void 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}
1360void KCommandSocket::writeFileToSocket() 1360void 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 ;