-rw-r--r-- | libkdepim/ksyncmanager.cpp | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/libkdepim/ksyncmanager.cpp b/libkdepim/ksyncmanager.cpp index c6e06f8..8851097 100644 --- a/libkdepim/ksyncmanager.cpp +++ b/libkdepim/ksyncmanager.cpp | |||
@@ -272,1006 +272,1009 @@ void KSyncManager::enableQuick() | |||
272 | QDialog dia ( 0, "input-dialog", true ); | 272 | QDialog dia ( 0, "input-dialog", true ); |
273 | QLineEdit lab ( &dia ); | 273 | QLineEdit lab ( &dia ); |
274 | QVBoxLayout lay( &dia ); | 274 | QVBoxLayout lay( &dia ); |
275 | lab.setText( mPrefs->mPassiveSyncPort ); | 275 | lab.setText( mPrefs->mPassiveSyncPort ); |
276 | lay.setMargin(7); | 276 | lay.setMargin(7); |
277 | lay.setSpacing(7); | 277 | lay.setSpacing(7); |
278 | int po = 9197+mTargetApp; | 278 | int po = 9197+mTargetApp; |
279 | QLabel label ( i18n("Port number (Default: %1)").arg(po), &dia ); | 279 | QLabel label ( i18n("Port number (Default: %1)").arg(po), &dia ); |
280 | lay.addWidget( &label); | 280 | lay.addWidget( &label); |
281 | lay.addWidget( &lab); | 281 | lay.addWidget( &lab); |
282 | 282 | ||
283 | QLineEdit lepw ( &dia ); | 283 | QLineEdit lepw ( &dia ); |
284 | lepw.setText( mPrefs->mPassiveSyncPw ); | 284 | lepw.setText( mPrefs->mPassiveSyncPw ); |
285 | QLabel label2 ( i18n("Password to enable\naccess from remote:"), &dia ); | 285 | QLabel label2 ( i18n("Password to enable\naccess from remote:"), &dia ); |
286 | lay.addWidget( &label2); | 286 | lay.addWidget( &label2); |
287 | lay.addWidget( &lepw); | 287 | lay.addWidget( &lepw); |
288 | dia.setFixedSize( 230,80 ); | 288 | dia.setFixedSize( 230,80 ); |
289 | dia.setCaption( i18n("Enter port for Pi-Sync") ); | 289 | dia.setCaption( i18n("Enter port for Pi-Sync") ); |
290 | QPushButton pb ( "OK", &dia); | 290 | QPushButton pb ( "OK", &dia); |
291 | lay.addWidget( &pb ); | 291 | lay.addWidget( &pb ); |
292 | connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) ); | 292 | connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) ); |
293 | dia.show(); | 293 | dia.show(); |
294 | if ( ! dia.exec() ) | 294 | if ( ! dia.exec() ) |
295 | return; | 295 | return; |
296 | dia.hide(); | 296 | dia.hide(); |
297 | qApp->processEvents(); | 297 | qApp->processEvents(); |
298 | mPrefs->mPassiveSyncPw = lepw.text(); | 298 | mPrefs->mPassiveSyncPw = lepw.text(); |
299 | mPrefs->mPassiveSyncPort = lab.text(); | 299 | mPrefs->mPassiveSyncPort = lab.text(); |
300 | bool ok; | 300 | bool ok; |
301 | Q_UINT16 port = mPrefs->mPassiveSyncPort.toUInt(&ok); | 301 | Q_UINT16 port = mPrefs->mPassiveSyncPort.toUInt(&ok); |
302 | if ( ! ok ) { | 302 | if ( ! ok ) { |
303 | KMessageBox::information( 0, i18n("No valid port")); | 303 | KMessageBox::information( 0, i18n("No valid port")); |
304 | return; | 304 | return; |
305 | } | 305 | } |
306 | //qDebug("port %d ", port); | 306 | //qDebug("port %d ", port); |
307 | mServerSocket = new KServerSocket ( mPrefs->mPassiveSyncPw, port ,1 ); | 307 | mServerSocket = new KServerSocket ( mPrefs->mPassiveSyncPw, port ,1 ); |
308 | mServerSocket->setFileName( defaultFileName() ); | 308 | mServerSocket->setFileName( defaultFileName() ); |
309 | //qDebug("connected "); | 309 | //qDebug("connected "); |
310 | if ( !mServerSocket->ok() ) { | 310 | if ( !mServerSocket->ok() ) { |
311 | KMessageBox::information( 0, i18n("Failed to bind or\nlisten to the port!")); | 311 | KMessageBox::information( 0, i18n("Failed to bind or\nlisten to the port!")); |
312 | delete mServerSocket; | 312 | delete mServerSocket; |
313 | mServerSocket = 0; | 313 | mServerSocket = 0; |
314 | return; | 314 | return; |
315 | } | 315 | } |
316 | connect( mServerSocket, SIGNAL ( request_file() ),this, SIGNAL ( request_file() ) ); | 316 | connect( mServerSocket, SIGNAL ( request_file() ),this, SIGNAL ( request_file() ) ); |
317 | connect( mServerSocket, SIGNAL ( file_received( bool ) ), this, SIGNAL ( getFile( bool ) ) ); | 317 | connect( mServerSocket, SIGNAL ( file_received( bool ) ), this, SIGNAL ( getFile( bool ) ) ); |
318 | } | 318 | } |
319 | 319 | ||
320 | void KSyncManager::syncLocalFile() | 320 | void KSyncManager::syncLocalFile() |
321 | { | 321 | { |
322 | 322 | ||
323 | QString fn =mPrefs->mLastSyncedLocalFile; | 323 | QString fn =mPrefs->mLastSyncedLocalFile; |
324 | QString ext; | 324 | QString ext; |
325 | 325 | ||
326 | switch(mTargetApp) | 326 | switch(mTargetApp) |
327 | { | 327 | { |
328 | case (KAPI): | 328 | case (KAPI): |
329 | ext = "(*.vcf)"; | 329 | ext = "(*.vcf)"; |
330 | break; | 330 | break; |
331 | case (KOPI): | 331 | case (KOPI): |
332 | ext = "(*.ics/*.vcs)"; | 332 | ext = "(*.ics/*.vcs)"; |
333 | break; | 333 | break; |
334 | case (PWMPI): | 334 | case (PWMPI): |
335 | ext = "(*.pwm)"; | 335 | ext = "(*.pwm)"; |
336 | break; | 336 | break; |
337 | default: | 337 | default: |
338 | qDebug("KSyncManager::syncLocalFile: invalid apptype selected"); | 338 | qDebug("KSyncManager::syncLocalFile: invalid apptype selected"); |
339 | break; | 339 | break; |
340 | 340 | ||
341 | } | 341 | } |
342 | 342 | ||
343 | fn =KFileDialog:: getOpenFileName( fn, i18n("Sync filename"+ext), mParent ); | 343 | fn =KFileDialog:: getOpenFileName( fn, i18n("Sync filename"+ext), mParent ); |
344 | if ( fn == "" ) | 344 | if ( fn == "" ) |
345 | return; | 345 | return; |
346 | if ( syncWithFile( fn, false ) ) { | 346 | if ( syncWithFile( fn, false ) ) { |
347 | qDebug("syncLocalFile() successful "); | 347 | qDebug("syncLocalFile() successful "); |
348 | } | 348 | } |
349 | 349 | ||
350 | } | 350 | } |
351 | 351 | ||
352 | bool KSyncManager::syncWithFile( QString fn , bool quick ) | 352 | bool KSyncManager::syncWithFile( QString fn , bool quick ) |
353 | { | 353 | { |
354 | bool ret = false; | 354 | bool ret = false; |
355 | QFileInfo info; | 355 | QFileInfo info; |
356 | info.setFile( fn ); | 356 | info.setFile( fn ); |
357 | QString mess; | 357 | QString mess; |
358 | bool loadbup = true; | 358 | bool loadbup = true; |
359 | if ( !info. exists() ) { | 359 | if ( !info. exists() ) { |
360 | mess = i18n( "Sync file \n...%1\ndoes not exist!\nNothing synced!\n").arg(fn.right( 30) ); | 360 | mess = i18n( "Sync file \n...%1\ndoes not exist!\nNothing synced!\n").arg(fn.right( 30) ); |
361 | int result = QMessageBox::warning( mParent, i18n("Warning!"), | 361 | int result = QMessageBox::warning( mParent, i18n("Warning!"), |
362 | mess ); | 362 | mess ); |
363 | return ret; | 363 | return ret; |
364 | } | 364 | } |
365 | int result = 0; | 365 | int result = 0; |
366 | if ( !quick ) { | 366 | if ( !quick ) { |
367 | mess = i18n("Sync with file \n...%1\nfrom:\n%2\n").arg(fn.right( 25)).arg(KGlobal::locale()->formatDateTime(info.lastModified (), true, false )); | 367 | mess = i18n("Sync with file \n...%1\nfrom:\n%2\n").arg(fn.right( 25)).arg(KGlobal::locale()->formatDateTime(info.lastModified (), true, false )); |
368 | result = QMessageBox::warning( mParent, i18n("Warning!"), | 368 | result = QMessageBox::warning( mParent, i18n("Warning!"), |
369 | mess, | 369 | mess, |
370 | i18n("Sync"), i18n("Cancel"), 0, | 370 | i18n("Sync"), i18n("Cancel"), 0, |
371 | 0, 1 ); | 371 | 0, 1 ); |
372 | if ( result ) | 372 | if ( result ) |
373 | return false; | 373 | return false; |
374 | } | 374 | } |
375 | if ( mAskForPreferences ) | 375 | if ( mAskForPreferences ) |
376 | edit_sync_options(); | 376 | edit_sync_options(); |
377 | if ( result == 0 ) { | 377 | if ( result == 0 ) { |
378 | //qDebug("Now sycing ... "); | 378 | //qDebug("Now sycing ... "); |
379 | if ( ret = mImplementation->sync( this, fn, mSyncAlgoPrefs ) ) | 379 | if ( ret = mImplementation->sync( this, fn, mSyncAlgoPrefs ) ) |
380 | mParent->topLevelWidget()->setCaption( i18n("Synchronization successful") ); | 380 | mParent->topLevelWidget()->setCaption( i18n("Synchronization successful") ); |
381 | else | 381 | else |
382 | mParent->topLevelWidget()->setCaption( i18n("Sync cancelled or failed. Nothing synced.") ); | 382 | mParent->topLevelWidget()->setCaption( i18n("Sync cancelled or failed. Nothing synced.") ); |
383 | if ( ! quick ) | 383 | if ( ! quick ) |
384 | mPrefs->mLastSyncedLocalFile = fn; | 384 | mPrefs->mLastSyncedLocalFile = fn; |
385 | } | 385 | } |
386 | return ret; | 386 | return ret; |
387 | } | 387 | } |
388 | 388 | ||
389 | void KSyncManager::quickSyncLocalFile() | 389 | void KSyncManager::quickSyncLocalFile() |
390 | { | 390 | { |
391 | 391 | ||
392 | if ( syncWithFile( mPrefs->mLastSyncedLocalFile, true ) ) { | 392 | if ( syncWithFile( mPrefs->mLastSyncedLocalFile, true ) ) { |
393 | qDebug("quick syncLocalFile() successful "); | 393 | qDebug("quick syncLocalFile() successful "); |
394 | 394 | ||
395 | } | 395 | } |
396 | } | 396 | } |
397 | 397 | ||
398 | void KSyncManager::multiSync( bool askforPrefs ) | 398 | void KSyncManager::multiSync( bool askforPrefs ) |
399 | { | 399 | { |
400 | if (blockSave()) | 400 | if (blockSave()) |
401 | return; | 401 | return; |
402 | setBlockSave(true); | 402 | setBlockSave(true); |
403 | QString question = i18n("Do you really want\nto multiple sync\nwith all checked profiles?\nSyncing takes some\ntime - all profiles\nare synced twice!"); | 403 | QString question = i18n("Do you really want\nto multiple sync\nwith all checked profiles?\nSyncing takes some\ntime - all profiles\nare synced twice!"); |
404 | if ( QMessageBox::information( mParent, i18n("KDE-Pim Sync"), | 404 | if ( QMessageBox::information( mParent, i18n("KDE-Pim Sync"), |
405 | question, | 405 | question, |
406 | i18n("Yes"), i18n("No"), | 406 | i18n("Yes"), i18n("No"), |
407 | 0, 0 ) != 0 ) { | 407 | 0, 0 ) != 0 ) { |
408 | setBlockSave(false); | 408 | setBlockSave(false); |
409 | mParent->topLevelWidget()->setCaption(i18n("Aborted! Nothing synced!")); | 409 | mParent->topLevelWidget()->setCaption(i18n("Aborted! Nothing synced!")); |
410 | return; | 410 | return; |
411 | } | 411 | } |
412 | mCurrentSyncDevice = i18n("Multiple profiles") ; | 412 | mCurrentSyncDevice = i18n("Multiple profiles") ; |
413 | mSyncAlgoPrefs = mPrefs->mRingSyncAlgoPrefs; | 413 | mSyncAlgoPrefs = mPrefs->mRingSyncAlgoPrefs; |
414 | if ( askforPrefs ) { | 414 | if ( askforPrefs ) { |
415 | edit_sync_options(); | 415 | edit_sync_options(); |
416 | mPrefs->mRingSyncAlgoPrefs = mSyncAlgoPrefs; | 416 | mPrefs->mRingSyncAlgoPrefs = mSyncAlgoPrefs; |
417 | } | 417 | } |
418 | mParent->topLevelWidget()->setCaption(i18n("Multiple sync started.") ); | 418 | mParent->topLevelWidget()->setCaption(i18n("Multiple sync started.") ); |
419 | qApp->processEvents(); | 419 | qApp->processEvents(); |
420 | int num = ringSync() ; | 420 | int num = ringSync() ; |
421 | if ( num > 1 ) | 421 | if ( num > 1 ) |
422 | ringSync(); | 422 | ringSync(); |
423 | setBlockSave(false); | 423 | setBlockSave(false); |
424 | if ( num ) | 424 | if ( num ) |
425 | emit save(); | 425 | emit save(); |
426 | if ( num ) | 426 | if ( num ) |
427 | mParent->topLevelWidget()->setCaption(i18n("%1 profiles synced. Multiple sync complete!").arg(num) ); | 427 | mParent->topLevelWidget()->setCaption(i18n("%1 profiles synced. Multiple sync complete!").arg(num) ); |
428 | else | 428 | else |
429 | mParent->topLevelWidget()->setCaption(i18n("Nothing synced! No profiles defined for multisync!")); | 429 | mParent->topLevelWidget()->setCaption(i18n("Nothing synced! No profiles defined for multisync!")); |
430 | return; | 430 | return; |
431 | } | 431 | } |
432 | 432 | ||
433 | int KSyncManager::ringSync() | 433 | int KSyncManager::ringSync() |
434 | { | 434 | { |
435 | int syncedProfiles = 0; | 435 | int syncedProfiles = 0; |
436 | unsigned int i; | 436 | unsigned int i; |
437 | QTime timer; | 437 | QTime timer; |
438 | KConfig config ( locateLocal( "config","ksyncprofilesrc" ) ); | 438 | KConfig config ( locateLocal( "config","ksyncprofilesrc" ) ); |
439 | QStringList syncProfileNames = mSyncProfileNames; | 439 | QStringList syncProfileNames = mSyncProfileNames; |
440 | KSyncProfile* temp = new KSyncProfile (); | 440 | KSyncProfile* temp = new KSyncProfile (); |
441 | mAskForPreferences = false; | 441 | mAskForPreferences = false; |
442 | for ( i = 0; i < syncProfileNames.count(); ++i ) { | 442 | for ( i = 0; i < syncProfileNames.count(); ++i ) { |
443 | mCurrentSyncProfile = i; | 443 | mCurrentSyncProfile = i; |
444 | temp->setName(syncProfileNames[mCurrentSyncProfile]); | 444 | temp->setName(syncProfileNames[mCurrentSyncProfile]); |
445 | temp->readConfig(&config); | 445 | temp->readConfig(&config); |
446 | 446 | ||
447 | bool includeInRingSync; | 447 | bool includeInRingSync; |
448 | switch(mTargetApp) | 448 | switch(mTargetApp) |
449 | { | 449 | { |
450 | case (KAPI): | 450 | case (KAPI): |
451 | includeInRingSync = temp->getIncludeInRingSyncAB(); | 451 | includeInRingSync = temp->getIncludeInRingSyncAB(); |
452 | break; | 452 | break; |
453 | case (KOPI): | 453 | case (KOPI): |
454 | includeInRingSync = temp->getIncludeInRingSync(); | 454 | includeInRingSync = temp->getIncludeInRingSync(); |
455 | break; | 455 | break; |
456 | case (PWMPI): | 456 | case (PWMPI): |
457 | includeInRingSync = temp->getIncludeInRingSyncPWM(); | 457 | includeInRingSync = temp->getIncludeInRingSyncPWM(); |
458 | break; | 458 | break; |
459 | default: | 459 | default: |
460 | qDebug("KSyncManager::ringSync: invalid apptype selected"); | 460 | qDebug("KSyncManager::ringSync: invalid apptype selected"); |
461 | break; | 461 | break; |
462 | 462 | ||
463 | } | 463 | } |
464 | 464 | ||
465 | 465 | ||
466 | if ( includeInRingSync && ( i < 1 || i > 2 )) { | 466 | if ( includeInRingSync && ( i < 1 || i > 2 )) { |
467 | mParent->topLevelWidget()->setCaption(i18n("Profile ")+syncProfileNames[mCurrentSyncProfile]+ i18n(" is synced ... ")); | 467 | mParent->topLevelWidget()->setCaption(i18n("Profile ")+syncProfileNames[mCurrentSyncProfile]+ i18n(" is synced ... ")); |
468 | ++syncedProfiles; | 468 | ++syncedProfiles; |
469 | // mAskForPreferences = temp->getAskForPreferences(); | 469 | // mAskForPreferences = temp->getAskForPreferences(); |
470 | mWriteBackFile = temp->getWriteBackFile(); | 470 | mWriteBackFile = temp->getWriteBackFile(); |
471 | mWriteBackExistingOnly = temp->getWriteBackExisting(); | 471 | mWriteBackExistingOnly = temp->getWriteBackExisting(); |
472 | mWriteBackInFuture = 0; | 472 | mWriteBackInFuture = 0; |
473 | if ( temp->getWriteBackFuture() ) | 473 | if ( temp->getWriteBackFuture() ) |
474 | mWriteBackInFuture = temp->getWriteBackFutureWeeks( ); | 474 | mWriteBackInFuture = temp->getWriteBackFutureWeeks( ); |
475 | mShowSyncSummary = false; | 475 | mShowSyncSummary = false; |
476 | mCurrentSyncDevice = syncProfileNames[i] ; | 476 | mCurrentSyncDevice = syncProfileNames[i] ; |
477 | mCurrentSyncName = mLocalMachineName; | 477 | mCurrentSyncName = mLocalMachineName; |
478 | if ( i == 0 ) { | 478 | if ( i == 0 ) { |
479 | #ifdef DESKTOP_VERSION | 479 | #ifdef DESKTOP_VERSION |
480 | syncKDE(); | 480 | syncKDE(); |
481 | #else | 481 | #else |
482 | syncSharp(); | 482 | syncSharp(); |
483 | #endif | 483 | #endif |
484 | } else { | 484 | } else { |
485 | if ( temp->getIsLocalFileSync() ) { | 485 | if ( temp->getIsLocalFileSync() ) { |
486 | switch(mTargetApp) | 486 | switch(mTargetApp) |
487 | { | 487 | { |
488 | case (KAPI): | 488 | case (KAPI): |
489 | if ( syncWithFile( temp->getRemoteFileNameAB( ), false ) ) | 489 | if ( syncWithFile( temp->getRemoteFileNameAB( ), false ) ) |
490 | mPrefs->mLastSyncedLocalFile = temp->getRemoteFileNameAB(); | 490 | mPrefs->mLastSyncedLocalFile = temp->getRemoteFileNameAB(); |
491 | break; | 491 | break; |
492 | case (KOPI): | 492 | case (KOPI): |
493 | if ( syncWithFile( temp->getRemoteFileName( ), false ) ) | 493 | if ( syncWithFile( temp->getRemoteFileName( ), false ) ) |
494 | mPrefs->mLastSyncedLocalFile = temp->getRemoteFileName(); | 494 | mPrefs->mLastSyncedLocalFile = temp->getRemoteFileName(); |
495 | break; | 495 | break; |
496 | case (PWMPI): | 496 | case (PWMPI): |
497 | if ( syncWithFile( temp->getRemoteFileNamePWM( ), false ) ) | 497 | if ( syncWithFile( temp->getRemoteFileNamePWM( ), false ) ) |
498 | mPrefs->mLastSyncedLocalFile = temp->getRemoteFileNamePWM(); | 498 | mPrefs->mLastSyncedLocalFile = temp->getRemoteFileNamePWM(); |
499 | break; | 499 | break; |
500 | default: | 500 | default: |
501 | qDebug("KSyncManager::slotSyncMenu: invalid apptype selected"); | 501 | qDebug("KSyncManager::slotSyncMenu: invalid apptype selected"); |
502 | break; | 502 | break; |
503 | } | 503 | } |
504 | } else { | 504 | } else { |
505 | if ( temp->getIsPhoneSync() ) { | 505 | if ( temp->getIsPhoneSync() ) { |
506 | mPhoneDevice = temp->getPhoneDevice( ) ; | 506 | mPhoneDevice = temp->getPhoneDevice( ) ; |
507 | mPhoneConnection = temp->getPhoneConnection( ); | 507 | mPhoneConnection = temp->getPhoneConnection( ); |
508 | mPhoneModel = temp->getPhoneModel( ); | 508 | mPhoneModel = temp->getPhoneModel( ); |
509 | syncPhone(); | 509 | syncPhone(); |
510 | } else if ( temp->getIsPiSync() ) { | 510 | } else if ( temp->getIsPiSync() ) { |
511 | if ( mTargetApp == KAPI ) { | 511 | if ( mTargetApp == KAPI ) { |
512 | mPassWordPiSync = temp->getRemotePwAB(); | 512 | mPassWordPiSync = temp->getRemotePwAB(); |
513 | mActiveSyncPort = temp->getRemotePortAB(); | 513 | mActiveSyncPort = temp->getRemotePortAB(); |
514 | mActiveSyncIP = temp->getRemoteIPAB(); | 514 | mActiveSyncIP = temp->getRemoteIPAB(); |
515 | } else if ( mTargetApp == KOPI ) { | 515 | } else if ( mTargetApp == KOPI ) { |
516 | mPassWordPiSync = temp->getRemotePw(); | 516 | mPassWordPiSync = temp->getRemotePw(); |
517 | mActiveSyncPort = temp->getRemotePort(); | 517 | mActiveSyncPort = temp->getRemotePort(); |
518 | mActiveSyncIP = temp->getRemoteIP(); | 518 | mActiveSyncIP = temp->getRemoteIP(); |
519 | } else { | 519 | } else { |
520 | mPassWordPiSync = temp->getRemotePwPWM(); | 520 | mPassWordPiSync = temp->getRemotePwPWM(); |
521 | mActiveSyncPort = temp->getRemotePortPWM(); | 521 | mActiveSyncPort = temp->getRemotePortPWM(); |
522 | mActiveSyncIP = temp->getRemoteIPPWM(); | 522 | mActiveSyncIP = temp->getRemoteIPPWM(); |
523 | } | 523 | } |
524 | syncPi(); | 524 | syncPi(); |
525 | while ( !mPisyncFinished ) { | 525 | while ( !mPisyncFinished ) { |
526 | //qDebug("waiting "); | 526 | //qDebug("waiting "); |
527 | qApp->processEvents(); | 527 | qApp->processEvents(); |
528 | } | 528 | } |
529 | timer.start(); | 529 | timer.start(); |
530 | while ( timer.elapsed () < 2000 ) { | 530 | while ( timer.elapsed () < 2000 ) { |
531 | qApp->processEvents(); | 531 | qApp->processEvents(); |
532 | } | 532 | } |
533 | } else | 533 | } else |
534 | syncRemote( temp, false ); | 534 | syncRemote( temp, false ); |
535 | 535 | ||
536 | } | 536 | } |
537 | } | 537 | } |
538 | timer.start(); | 538 | timer.start(); |
539 | mParent->topLevelWidget()->setCaption(i18n("Multiple sync in progress ... please wait!") ); | 539 | mParent->topLevelWidget()->setCaption(i18n("Multiple sync in progress ... please wait!") ); |
540 | while ( timer.elapsed () < 2000 ) { | 540 | while ( timer.elapsed () < 2000 ) { |
541 | qApp->processEvents(); | 541 | qApp->processEvents(); |
542 | #ifndef _WIN32_ | 542 | #ifndef _WIN32_ |
543 | sleep (1); | 543 | sleep (1); |
544 | #endif | 544 | #endif |
545 | } | 545 | } |
546 | 546 | ||
547 | } | 547 | } |
548 | 548 | ||
549 | } | 549 | } |
550 | delete temp; | 550 | delete temp; |
551 | return syncedProfiles; | 551 | return syncedProfiles; |
552 | } | 552 | } |
553 | 553 | ||
554 | void KSyncManager::syncRemote( KSyncProfile* prof, bool ask) | 554 | void KSyncManager::syncRemote( KSyncProfile* prof, bool ask) |
555 | { | 555 | { |
556 | QString question; | 556 | QString question; |
557 | if ( ask ) { | 557 | if ( ask ) { |
558 | question = i18n("Do you really want\nto remote sync\nwith profile \n")+ prof->getName()+" ?\n"; | 558 | question = i18n("Do you really want\nto remote sync\nwith profile \n")+ prof->getName()+" ?\n"; |
559 | if ( QMessageBox::information( mParent, i18n("Sync"), | 559 | if ( QMessageBox::information( mParent, i18n("Sync"), |
560 | question, | 560 | question, |
561 | i18n("Yes"), i18n("No"), | 561 | i18n("Yes"), i18n("No"), |
562 | 0, 0 ) != 0 ) | 562 | 0, 0 ) != 0 ) |
563 | return; | 563 | return; |
564 | } | 564 | } |
565 | 565 | ||
566 | QString preCommand; | 566 | QString preCommand; |
567 | QString localTempFile; | 567 | QString localTempFile; |
568 | QString postCommand; | 568 | QString postCommand; |
569 | 569 | ||
570 | switch(mTargetApp) | 570 | switch(mTargetApp) |
571 | { | 571 | { |
572 | case (KAPI): | 572 | case (KAPI): |
573 | preCommand = prof->getPreSyncCommandAB(); | 573 | preCommand = prof->getPreSyncCommandAB(); |
574 | postCommand = prof->getPostSyncCommandAB(); | 574 | postCommand = prof->getPostSyncCommandAB(); |
575 | localTempFile = prof->getLocalTempFileAB(); | 575 | localTempFile = prof->getLocalTempFileAB(); |
576 | break; | 576 | break; |
577 | case (KOPI): | 577 | case (KOPI): |
578 | preCommand = prof->getPreSyncCommand(); | 578 | preCommand = prof->getPreSyncCommand(); |
579 | postCommand = prof->getPostSyncCommand(); | 579 | postCommand = prof->getPostSyncCommand(); |
580 | localTempFile = prof->getLocalTempFile(); | 580 | localTempFile = prof->getLocalTempFile(); |
581 | break; | 581 | break; |
582 | case (PWMPI): | 582 | case (PWMPI): |
583 | preCommand = prof->getPreSyncCommandPWM(); | 583 | preCommand = prof->getPreSyncCommandPWM(); |
584 | postCommand = prof->getPostSyncCommandPWM(); | 584 | postCommand = prof->getPostSyncCommandPWM(); |
585 | localTempFile = prof->getLocalTempFilePWM(); | 585 | localTempFile = prof->getLocalTempFilePWM(); |
586 | break; | 586 | break; |
587 | default: | 587 | default: |
588 | qDebug("KSyncManager::syncRemote: invalid apptype selected"); | 588 | qDebug("KSyncManager::syncRemote: invalid apptype selected"); |
589 | break; | 589 | break; |
590 | } | 590 | } |
591 | 591 | ||
592 | 592 | ||
593 | int fi; | 593 | int fi; |
594 | if ( (fi = preCommand.find("$PWD$")) > 0 ) { | 594 | if ( (fi = preCommand.find("$PWD$")) > 0 ) { |
595 | QString pwd = getPassword(); | 595 | QString pwd = getPassword(); |
596 | preCommand = preCommand.left( fi )+ pwd + preCommand.mid( fi+5 ); | 596 | preCommand = preCommand.left( fi )+ pwd + preCommand.mid( fi+5 ); |
597 | 597 | ||
598 | } | 598 | } |
599 | int maxlen = 30; | 599 | int maxlen = 30; |
600 | if ( QApplication::desktop()->width() > 320 ) | 600 | if ( QApplication::desktop()->width() > 320 ) |
601 | maxlen += 25; | 601 | maxlen += 25; |
602 | mParent->topLevelWidget()->setCaption ( i18n( "Copy remote file to local machine..." ) ); | 602 | mParent->topLevelWidget()->setCaption ( i18n( "Copy remote file to local machine..." ) ); |
603 | int fileSize = 0; | 603 | int fileSize = 0; |
604 | int result = system ( preCommand ); | 604 | int result = system ( preCommand ); |
605 | // 0 : okay | 605 | // 0 : okay |
606 | // 256: no such file or dir | 606 | // 256: no such file or dir |
607 | // | 607 | // |
608 | qDebug("Sync: Remote copy result(0 = okay): %d ",result ); | 608 | qDebug("Sync: Remote copy result(0 = okay): %d ",result ); |
609 | if ( result != 0 ) { | 609 | if ( result != 0 ) { |
610 | unsigned int len = maxlen; | 610 | unsigned int len = maxlen; |
611 | while ( len < preCommand.length() ) { | 611 | while ( len < preCommand.length() ) { |
612 | preCommand.insert( len , "\n" ); | 612 | preCommand.insert( len , "\n" ); |
613 | len += maxlen +2; | 613 | len += maxlen +2; |
614 | } | 614 | } |
615 | question = i18n("Sorry, the copy command failed!\nCommand was:\n%1\n \nTry command on console to get more\ndetailed info about the reason.\n").arg (preCommand) ; | 615 | question = i18n("Sorry, the copy command failed!\nCommand was:\n%1\n \nTry command on console to get more\ndetailed info about the reason.\n").arg (preCommand) ; |
616 | QMessageBox::information( mParent, i18n("Sync - ERROR"), | 616 | QMessageBox::information( mParent, i18n("Sync - ERROR"), |
617 | question, | 617 | question, |
618 | i18n("Okay!")) ; | 618 | i18n("Okay!")) ; |
619 | mParent->topLevelWidget()->setCaption ("KDE-Pim"); | 619 | mParent->topLevelWidget()->setCaption ("KDE-Pim"); |
620 | return; | 620 | return; |
621 | } | 621 | } |
622 | mParent->topLevelWidget()->setCaption ( i18n( "Copying succeed." ) ); | 622 | mParent->topLevelWidget()->setCaption ( i18n( "Copying succeed." ) ); |
623 | //qDebug(" file **%s** ",prof->getLocalTempFile().latin1() ); | 623 | //qDebug(" file **%s** ",prof->getLocalTempFile().latin1() ); |
624 | 624 | ||
625 | if ( syncWithFile( localTempFile, true ) ) { | 625 | if ( syncWithFile( localTempFile, true ) ) { |
626 | 626 | ||
627 | if ( mWriteBackFile ) { | 627 | if ( mWriteBackFile ) { |
628 | int fi; | 628 | int fi; |
629 | if ( (fi = postCommand.find("$PWD$")) > 0 ) { | 629 | if ( (fi = postCommand.find("$PWD$")) > 0 ) { |
630 | QString pwd = getPassword(); | 630 | QString pwd = getPassword(); |
631 | postCommand = postCommand.left( fi )+ pwd + postCommand.mid( fi+5 ); | 631 | postCommand = postCommand.left( fi )+ pwd + postCommand.mid( fi+5 ); |
632 | 632 | ||
633 | } | 633 | } |
634 | mParent->topLevelWidget()->setCaption ( i18n( "Writing back file ..." ) ); | 634 | mParent->topLevelWidget()->setCaption ( i18n( "Writing back file ..." ) ); |
635 | result = system ( postCommand ); | 635 | result = system ( postCommand ); |
636 | qDebug("Sync:Writing back file result: %d ", result); | 636 | qDebug("Sync:Writing back file result: %d ", result); |
637 | if ( result != 0 ) { | 637 | if ( result != 0 ) { |
638 | mParent->topLevelWidget()->setCaption ( i18n( "Writing back file result: " )+QString::number( result ) ); | 638 | mParent->topLevelWidget()->setCaption ( i18n( "Writing back file result: " )+QString::number( result ) ); |
639 | return; | 639 | return; |
640 | } else { | 640 | } else { |
641 | mParent->topLevelWidget()->setCaption ( i18n( "Syncronization sucessfully completed" ) ); | 641 | mParent->topLevelWidget()->setCaption ( i18n( "Syncronization sucessfully completed" ) ); |
642 | } | 642 | } |
643 | } | 643 | } |
644 | } | 644 | } |
645 | return; | 645 | return; |
646 | } | 646 | } |
647 | void KSyncManager::edit_pisync_options() | 647 | void KSyncManager::edit_pisync_options() |
648 | { | 648 | { |
649 | QDialog dia( mParent, "dia", true ); | 649 | QDialog dia( mParent, "dia", true ); |
650 | dia.setCaption( i18n("Pi-Sync options for device: " ) +mCurrentSyncDevice ); | 650 | dia.setCaption( i18n("Pi-Sync options for device: " ) +mCurrentSyncDevice ); |
651 | QVBoxLayout lay ( &dia ); | 651 | QVBoxLayout lay ( &dia ); |
652 | lay.setSpacing( 5 ); | 652 | lay.setSpacing( 5 ); |
653 | lay.setMargin( 3 ); | 653 | lay.setMargin( 3 ); |
654 | QLabel lab1 ( i18n("Password for remote access:"), &dia); | 654 | QLabel lab1 ( i18n("Password for remote access:"), &dia); |
655 | lay.addWidget( &lab1 ); | 655 | lay.addWidget( &lab1 ); |
656 | QLineEdit le1 (&dia ); | 656 | QLineEdit le1 (&dia ); |
657 | lay.addWidget( &le1 ); | 657 | lay.addWidget( &le1 ); |
658 | QLabel lab2 ( i18n("Remote IP address:"), &dia); | 658 | QLabel lab2 ( i18n("Remote IP address:"), &dia); |
659 | lay.addWidget( &lab2 ); | 659 | lay.addWidget( &lab2 ); |
660 | QLineEdit le2 (&dia ); | 660 | QLineEdit le2 (&dia ); |
661 | lay.addWidget( &le2 ); | 661 | lay.addWidget( &le2 ); |
662 | QLabel lab3 ( i18n("Remote port number:"), &dia); | 662 | QLabel lab3 ( i18n("Remote port number:"), &dia); |
663 | lay.addWidget( &lab3 ); | 663 | lay.addWidget( &lab3 ); |
664 | QLineEdit le3 (&dia ); | 664 | QLineEdit le3 (&dia ); |
665 | lay.addWidget( &le3 ); | 665 | lay.addWidget( &le3 ); |
666 | QPushButton pb ( "OK", &dia); | 666 | QPushButton pb ( "OK", &dia); |
667 | lay.addWidget( &pb ); | 667 | lay.addWidget( &pb ); |
668 | connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) ); | 668 | connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) ); |
669 | le1.setText( mPassWordPiSync ); | 669 | le1.setText( mPassWordPiSync ); |
670 | le2.setText( mActiveSyncIP ); | 670 | le2.setText( mActiveSyncIP ); |
671 | le3.setText( mActiveSyncPort ); | 671 | le3.setText( mActiveSyncPort ); |
672 | if ( dia.exec() ) { | 672 | if ( dia.exec() ) { |
673 | mPassWordPiSync = le1.text(); | 673 | mPassWordPiSync = le1.text(); |
674 | mActiveSyncPort = le3.text(); | 674 | mActiveSyncPort = le3.text(); |
675 | mActiveSyncIP = le2.text(); | 675 | mActiveSyncIP = le2.text(); |
676 | } | 676 | } |
677 | 677 | ||
678 | } | 678 | } |
679 | void KSyncManager::edit_sync_options() | 679 | void KSyncManager::edit_sync_options() |
680 | { | 680 | { |
681 | 681 | ||
682 | QDialog dia( mParent, "dia", true ); | 682 | QDialog dia( mParent, "dia", true ); |
683 | dia.setCaption( i18n("Device: " ) +mCurrentSyncDevice ); | 683 | dia.setCaption( i18n("Device: " ) +mCurrentSyncDevice ); |
684 | QButtonGroup gr ( 1, Qt::Horizontal, i18n("Sync preferences"), &dia); | 684 | QButtonGroup gr ( 1, Qt::Horizontal, i18n("Sync preferences"), &dia); |
685 | QVBoxLayout lay ( &dia ); | 685 | QVBoxLayout lay ( &dia ); |
686 | lay.setSpacing( 2 ); | 686 | lay.setSpacing( 2 ); |
687 | lay.setMargin( 3 ); | 687 | lay.setMargin( 3 ); |
688 | lay.addWidget(&gr); | 688 | lay.addWidget(&gr); |
689 | QRadioButton loc ( i18n("Take local entry on conflict"), &gr ); | 689 | QRadioButton loc ( i18n("Take local entry on conflict"), &gr ); |
690 | QRadioButton rem ( i18n("Take remote entry on conflict"), &gr ); | 690 | QRadioButton rem ( i18n("Take remote entry on conflict"), &gr ); |
691 | QRadioButton newest( i18n("Take newest entry on conflict"), &gr ); | 691 | QRadioButton newest( i18n("Take newest entry on conflict"), &gr ); |
692 | QRadioButton ask( i18n("Ask for every entry on conflict"), &gr ); | 692 | QRadioButton ask( i18n("Ask for every entry on conflict"), &gr ); |
693 | QRadioButton f_loc( i18n("Force: Take local entry always"), &gr ); | 693 | QRadioButton f_loc( i18n("Force: Take local entry always"), &gr ); |
694 | QRadioButton f_rem( i18n("Force: Take remote entry always"), &gr ); | 694 | QRadioButton f_rem( i18n("Force: Take remote entry always"), &gr ); |
695 | //QRadioButton both( i18n("Take both on conflict"), &gr ); | 695 | //QRadioButton both( i18n("Take both on conflict"), &gr ); |
696 | QPushButton pb ( "OK", &dia); | 696 | QPushButton pb ( "OK", &dia); |
697 | lay.addWidget( &pb ); | 697 | lay.addWidget( &pb ); |
698 | connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) ); | 698 | connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) ); |
699 | switch ( mSyncAlgoPrefs ) { | 699 | switch ( mSyncAlgoPrefs ) { |
700 | case 0: | 700 | case 0: |
701 | loc.setChecked( true); | 701 | loc.setChecked( true); |
702 | break; | 702 | break; |
703 | case 1: | 703 | case 1: |
704 | rem.setChecked( true ); | 704 | rem.setChecked( true ); |
705 | break; | 705 | break; |
706 | case 2: | 706 | case 2: |
707 | newest.setChecked( true); | 707 | newest.setChecked( true); |
708 | break; | 708 | break; |
709 | case 3: | 709 | case 3: |
710 | ask.setChecked( true); | 710 | ask.setChecked( true); |
711 | break; | 711 | break; |
712 | case 4: | 712 | case 4: |
713 | f_loc.setChecked( true); | 713 | f_loc.setChecked( true); |
714 | break; | 714 | break; |
715 | case 5: | 715 | case 5: |
716 | f_rem.setChecked( true); | 716 | f_rem.setChecked( true); |
717 | break; | 717 | break; |
718 | case 6: | 718 | case 6: |
719 | // both.setChecked( true); | 719 | // both.setChecked( true); |
720 | break; | 720 | break; |
721 | default: | 721 | default: |
722 | break; | 722 | break; |
723 | } | 723 | } |
724 | if ( dia.exec() ) { | 724 | if ( dia.exec() ) { |
725 | mSyncAlgoPrefs = rem.isChecked()*1+newest.isChecked()*2+ ask.isChecked()*3+ f_loc.isChecked()*4+ f_rem.isChecked()*5;//+ both.isChecked()*6 ; | 725 | mSyncAlgoPrefs = rem.isChecked()*1+newest.isChecked()*2+ ask.isChecked()*3+ f_loc.isChecked()*4+ f_rem.isChecked()*5;//+ both.isChecked()*6 ; |
726 | } | 726 | } |
727 | 727 | ||
728 | 728 | ||
729 | } | 729 | } |
730 | 730 | ||
731 | QString KSyncManager::getPassword( ) | 731 | QString KSyncManager::getPassword( ) |
732 | { | 732 | { |
733 | QString retfile = ""; | 733 | QString retfile = ""; |
734 | QDialog dia ( mParent, "input-dialog", true ); | 734 | QDialog dia ( mParent, "input-dialog", true ); |
735 | QLineEdit lab ( &dia ); | 735 | QLineEdit lab ( &dia ); |
736 | lab.setEchoMode( QLineEdit::Password ); | 736 | lab.setEchoMode( QLineEdit::Password ); |
737 | QVBoxLayout lay( &dia ); | 737 | QVBoxLayout lay( &dia ); |
738 | lay.setMargin(7); | 738 | lay.setMargin(7); |
739 | lay.setSpacing(7); | 739 | lay.setSpacing(7); |
740 | lay.addWidget( &lab); | 740 | lay.addWidget( &lab); |
741 | dia.setFixedSize( 230,50 ); | 741 | dia.setFixedSize( 230,50 ); |
742 | dia.setCaption( i18n("Enter password") ); | 742 | dia.setCaption( i18n("Enter password") ); |
743 | QPushButton pb ( "OK", &dia); | 743 | QPushButton pb ( "OK", &dia); |
744 | lay.addWidget( &pb ); | 744 | lay.addWidget( &pb ); |
745 | connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) ); | 745 | connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) ); |
746 | dia.show(); | 746 | dia.show(); |
747 | int res = dia.exec(); | 747 | int res = dia.exec(); |
748 | if ( res ) | 748 | if ( res ) |
749 | retfile = lab.text(); | 749 | retfile = lab.text(); |
750 | dia.hide(); | 750 | dia.hide(); |
751 | qApp->processEvents(); | 751 | qApp->processEvents(); |
752 | return retfile; | 752 | return retfile; |
753 | 753 | ||
754 | } | 754 | } |
755 | 755 | ||
756 | 756 | ||
757 | void KSyncManager::confSync() | 757 | void KSyncManager::confSync() |
758 | { | 758 | { |
759 | static KSyncPrefsDialog* sp = 0; | 759 | static KSyncPrefsDialog* sp = 0; |
760 | if ( ! sp ) { | 760 | if ( ! sp ) { |
761 | sp = new KSyncPrefsDialog( mParent, "syncprefs", true ); | 761 | sp = new KSyncPrefsDialog( mParent, "syncprefs", true ); |
762 | } | 762 | } |
763 | sp->usrReadConfig(); | 763 | sp->usrReadConfig(); |
764 | #ifndef DESKTOP_VERSION | 764 | #ifndef DESKTOP_VERSION |
765 | sp->showMaximized(); | 765 | sp->showMaximized(); |
766 | #else | 766 | #else |
767 | sp->show(); | 767 | sp->show(); |
768 | #endif | 768 | #endif |
769 | sp->exec(); | 769 | sp->exec(); |
770 | mSyncProfileNames = sp->getSyncProfileNames(); | 770 | mSyncProfileNames = sp->getSyncProfileNames(); |
771 | mLocalMachineName = sp->getLocalMachineName (); | 771 | mLocalMachineName = sp->getLocalMachineName (); |
772 | QTimer::singleShot ( 1, this, SLOT ( fillSyncMenu() ) ); | 772 | QTimer::singleShot ( 1, this, SLOT ( fillSyncMenu() ) ); |
773 | } | 773 | } |
774 | void KSyncManager::syncKDE() | 774 | void KSyncManager::syncKDE() |
775 | { | 775 | { |
776 | emit save(); | 776 | emit save(); |
777 | switch(mTargetApp) | 777 | switch(mTargetApp) |
778 | { | 778 | { |
779 | case (KAPI): | 779 | case (KAPI): |
780 | 780 | ||
781 | break; | 781 | break; |
782 | case (KOPI): | 782 | case (KOPI): |
783 | { | 783 | { |
784 | QString command ="./kdecaldump"; | 784 | QString command = qApp->applicationDirPath () + "/kdecaldump"; |
785 | if ( ! QFile::exists ( command ) ) | ||
786 | command = "kdecaldump"; | ||
787 | QString fileName = QDir::homeDirPath ()+"/.kdecalendardump.ics"; | ||
785 | system ( command.latin1()); | 788 | system ( command.latin1()); |
786 | if ( syncWithFile( "/tmp/kdedumpall.ics",true ) ) { | 789 | if ( syncWithFile( fileName,true ) ) { |
787 | if ( mWriteBackFile ) { | 790 | if ( mWriteBackFile ) { |
788 | command += " --read"; | 791 | command += " --read"; |
789 | system ( command.latin1()); | 792 | system ( command.latin1()); |
790 | } | 793 | } |
791 | } | 794 | } |
792 | 795 | ||
793 | } | 796 | } |
794 | break; | 797 | break; |
795 | case (PWMPI): | 798 | case (PWMPI): |
796 | 799 | ||
797 | break; | 800 | break; |
798 | default: | 801 | default: |
799 | qDebug("KSyncManager::slotSyncMenu: invalid apptype selected"); | 802 | qDebug("KSyncManager::slotSyncMenu: invalid apptype selected"); |
800 | break; | 803 | break; |
801 | 804 | ||
802 | } | 805 | } |
803 | } | 806 | } |
804 | 807 | ||
805 | void KSyncManager::syncSharp() | 808 | void KSyncManager::syncSharp() |
806 | { | 809 | { |
807 | 810 | ||
808 | if ( ! syncExternalApplication("sharp") ) | 811 | if ( ! syncExternalApplication("sharp") ) |
809 | qDebug("ERROR sync sharp "); | 812 | qDebug("ERROR sync sharp "); |
810 | } | 813 | } |
811 | 814 | ||
812 | bool KSyncManager::syncExternalApplication(QString resource) | 815 | bool KSyncManager::syncExternalApplication(QString resource) |
813 | { | 816 | { |
814 | 817 | ||
815 | emit save(); | 818 | emit save(); |
816 | 819 | ||
817 | if ( mAskForPreferences ) | 820 | if ( mAskForPreferences ) |
818 | edit_sync_options(); | 821 | edit_sync_options(); |
819 | 822 | ||
820 | qDebug("Sync extern %s", resource.latin1()); | 823 | qDebug("Sync extern %s", resource.latin1()); |
821 | 824 | ||
822 | bool syncOK = mImplementation->syncExternal(this, resource); | 825 | bool syncOK = mImplementation->syncExternal(this, resource); |
823 | 826 | ||
824 | return syncOK; | 827 | return syncOK; |
825 | 828 | ||
826 | } | 829 | } |
827 | 830 | ||
828 | void KSyncManager::syncPhone() | 831 | void KSyncManager::syncPhone() |
829 | { | 832 | { |
830 | 833 | ||
831 | syncExternalApplication("phone"); | 834 | syncExternalApplication("phone"); |
832 | 835 | ||
833 | } | 836 | } |
834 | 837 | ||
835 | void KSyncManager::showProgressBar(int percentage, QString caption, int total) | 838 | void KSyncManager::showProgressBar(int percentage, QString caption, int total) |
836 | { | 839 | { |
837 | if (!bar->isVisible()) | 840 | if (!bar->isVisible()) |
838 | { | 841 | { |
839 | bar->setCaption (caption); | 842 | bar->setCaption (caption); |
840 | bar->setTotalSteps ( total ) ; | 843 | bar->setTotalSteps ( total ) ; |
841 | 844 | ||
842 | bar->show(); | 845 | bar->show(); |
843 | } | 846 | } |
844 | 847 | ||
845 | bar->setProgress( percentage ); | 848 | bar->setProgress( percentage ); |
846 | } | 849 | } |
847 | 850 | ||
848 | void KSyncManager::hideProgressBar() | 851 | void KSyncManager::hideProgressBar() |
849 | { | 852 | { |
850 | bar->hide(); | 853 | bar->hide(); |
851 | } | 854 | } |
852 | 855 | ||
853 | bool KSyncManager::isProgressBarCanceled() | 856 | bool KSyncManager::isProgressBarCanceled() |
854 | { | 857 | { |
855 | return !bar->isVisible(); | 858 | return !bar->isVisible(); |
856 | } | 859 | } |
857 | 860 | ||
858 | QString KSyncManager::syncFileName() | 861 | QString KSyncManager::syncFileName() |
859 | { | 862 | { |
860 | 863 | ||
861 | QString fn = "tempfile"; | 864 | QString fn = "tempfile"; |
862 | switch(mTargetApp) | 865 | switch(mTargetApp) |
863 | { | 866 | { |
864 | case (KAPI): | 867 | case (KAPI): |
865 | fn = "tempsyncab.vcf"; | 868 | fn = "tempsyncab.vcf"; |
866 | break; | 869 | break; |
867 | case (KOPI): | 870 | case (KOPI): |
868 | fn = "tempsynccal.ics"; | 871 | fn = "tempsynccal.ics"; |
869 | break; | 872 | break; |
870 | case (PWMPI): | 873 | case (PWMPI): |
871 | fn = "tempsyncpw.pwm"; | 874 | fn = "tempsyncpw.pwm"; |
872 | break; | 875 | break; |
873 | default: | 876 | default: |
874 | break; | 877 | break; |
875 | } | 878 | } |
876 | #ifdef _WIN32_ | 879 | #ifdef _WIN32_ |
877 | return locateLocal( "tmp", fn ); | 880 | return locateLocal( "tmp", fn ); |
878 | #else | 881 | #else |
879 | return (QString( "/tmp/" )+ fn ); | 882 | return (QString( "/tmp/" )+ fn ); |
880 | #endif | 883 | #endif |
881 | } | 884 | } |
882 | 885 | ||
883 | void KSyncManager::syncPi() | 886 | void KSyncManager::syncPi() |
884 | { | 887 | { |
885 | mPisyncFinished = false; | 888 | mPisyncFinished = false; |
886 | qApp->processEvents(); | 889 | qApp->processEvents(); |
887 | if ( mAskForPreferences ) | 890 | if ( mAskForPreferences ) |
888 | edit_pisync_options(); | 891 | edit_pisync_options(); |
889 | bool ok; | 892 | bool ok; |
890 | Q_UINT16 port = mActiveSyncPort.toUInt(&ok); | 893 | Q_UINT16 port = mActiveSyncPort.toUInt(&ok); |
891 | if ( ! ok ) { | 894 | if ( ! ok ) { |
892 | mParent->topLevelWidget()->setCaption( i18n("Sorry, no valid port.Syncing cancelled.") ); | 895 | mParent->topLevelWidget()->setCaption( i18n("Sorry, no valid port.Syncing cancelled.") ); |
893 | return; | 896 | return; |
894 | } | 897 | } |
895 | KCommandSocket* commandSocket = new KCommandSocket( mPassWordPiSync, port, mActiveSyncIP, this ); | 898 | KCommandSocket* commandSocket = new KCommandSocket( mPassWordPiSync, port, mActiveSyncIP, this ); |
896 | connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int )), this, SLOT(deleteCommandSocket(KCommandSocket*, int)) ); | 899 | connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int )), this, SLOT(deleteCommandSocket(KCommandSocket*, int)) ); |
897 | mParent->topLevelWidget()->setCaption( i18n("Sending request for remote file ...") ); | 900 | mParent->topLevelWidget()->setCaption( i18n("Sending request for remote file ...") ); |
898 | commandSocket->readFile( syncFileName() ); | 901 | commandSocket->readFile( syncFileName() ); |
899 | } | 902 | } |
900 | 903 | ||
901 | void KSyncManager::deleteCommandSocket(KCommandSocket*s, int state) | 904 | void KSyncManager::deleteCommandSocket(KCommandSocket*s, int state) |
902 | { | 905 | { |
903 | //enum { success, errorW, errorR, quiet }; | 906 | //enum { success, errorW, errorR, quiet }; |
904 | if ( state == KCommandSocket::errorR ||state == KCommandSocket::errorTO ) { | 907 | if ( state == KCommandSocket::errorR ||state == KCommandSocket::errorTO ) { |
905 | mParent->topLevelWidget()->setCaption( i18n("ERROR: Receiving remote file failed.") ); | 908 | mParent->topLevelWidget()->setCaption( i18n("ERROR: Receiving remote file failed.") ); |
906 | delete s; | 909 | delete s; |
907 | if ( state == KCommandSocket::errorR ) { | 910 | if ( state == KCommandSocket::errorR ) { |
908 | KCommandSocket* commandSocket = new KCommandSocket( mPassWordPiSync, mActiveSyncPort.toUInt(), mActiveSyncIP, this ); | 911 | KCommandSocket* commandSocket = new KCommandSocket( mPassWordPiSync, mActiveSyncPort.toUInt(), mActiveSyncIP, this ); |
909 | connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int)), this, SLOT(deleteCommandSocket(KCommandSocket*, int )) ); | 912 | connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int)), this, SLOT(deleteCommandSocket(KCommandSocket*, int )) ); |
910 | commandSocket->sendStop(); | 913 | commandSocket->sendStop(); |
911 | } | 914 | } |
912 | mPisyncFinished = true; | 915 | mPisyncFinished = true; |
913 | return; | 916 | return; |
914 | 917 | ||
915 | } else if ( state == KCommandSocket::errorW ) { | 918 | } else if ( state == KCommandSocket::errorW ) { |
916 | mParent->topLevelWidget()->setCaption( i18n("ERROR:Writing back file failed.") ); | 919 | mParent->topLevelWidget()->setCaption( i18n("ERROR:Writing back file failed.") ); |
917 | mPisyncFinished = true; | 920 | mPisyncFinished = true; |
918 | 921 | ||
919 | } else if ( state == KCommandSocket::successR ) { | 922 | } else if ( state == KCommandSocket::successR ) { |
920 | QTimer::singleShot( 1, this , SLOT ( readFileFromSocket())); | 923 | QTimer::singleShot( 1, this , SLOT ( readFileFromSocket())); |
921 | 924 | ||
922 | } else if ( state == KCommandSocket::successW ) { | 925 | } else if ( state == KCommandSocket::successW ) { |
923 | mParent->topLevelWidget()->setCaption( i18n("Pi-Sync succesful!") ); | 926 | mParent->topLevelWidget()->setCaption( i18n("Pi-Sync succesful!") ); |
924 | mPisyncFinished = true; | 927 | mPisyncFinished = true; |
925 | } | 928 | } |
926 | 929 | ||
927 | delete s; | 930 | delete s; |
928 | } | 931 | } |
929 | 932 | ||
930 | void KSyncManager::readFileFromSocket() | 933 | void KSyncManager::readFileFromSocket() |
931 | { | 934 | { |
932 | QString fileName = syncFileName(); | 935 | QString fileName = syncFileName(); |
933 | mParent->topLevelWidget()->setCaption( i18n("Remote file saved to temp file.") ); | 936 | mParent->topLevelWidget()->setCaption( i18n("Remote file saved to temp file.") ); |
934 | if ( ! syncWithFile( fileName , true ) ) { | 937 | if ( ! syncWithFile( fileName , true ) ) { |
935 | mParent->topLevelWidget()->setCaption( i18n("Syncing failed.") ); | 938 | mParent->topLevelWidget()->setCaption( i18n("Syncing failed.") ); |
936 | mPisyncFinished = true; | 939 | mPisyncFinished = true; |
937 | return; | 940 | return; |
938 | } | 941 | } |
939 | KCommandSocket* commandSocket = new KCommandSocket( mPassWordPiSync, mActiveSyncPort.toUInt(), mActiveSyncIP, this ); | 942 | KCommandSocket* commandSocket = new KCommandSocket( mPassWordPiSync, mActiveSyncPort.toUInt(), mActiveSyncIP, this ); |
940 | connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int)), this, SLOT(deleteCommandSocket(KCommandSocket*, int )) ); | 943 | connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int)), this, SLOT(deleteCommandSocket(KCommandSocket*, int )) ); |
941 | if ( mWriteBackFile ) | 944 | if ( mWriteBackFile ) |
942 | commandSocket->writeFile( fileName ); | 945 | commandSocket->writeFile( fileName ); |
943 | else { | 946 | else { |
944 | commandSocket->sendStop(); | 947 | commandSocket->sendStop(); |
945 | mParent->topLevelWidget()->setCaption( i18n("Pi-Sync succesful!") ); | 948 | mParent->topLevelWidget()->setCaption( i18n("Pi-Sync succesful!") ); |
946 | mPisyncFinished = true; | 949 | mPisyncFinished = true; |
947 | } | 950 | } |
948 | } | 951 | } |
949 | 952 | ||
950 | KServerSocket:: KServerSocket ( QString pw, Q_UINT16 port, int backlog, QObject * parent, const char * name ) : QServerSocket( port, backlog, parent, name ) | 953 | KServerSocket:: KServerSocket ( QString pw, Q_UINT16 port, int backlog, QObject * parent, const char * name ) : QServerSocket( port, backlog, parent, name ) |
951 | { | 954 | { |
952 | mPassWord = pw; | 955 | mPassWord = pw; |
953 | mSocket = 0; | 956 | mSocket = 0; |
954 | mSyncActionDialog = 0; | 957 | mSyncActionDialog = 0; |
955 | blockRC = false; | 958 | blockRC = false; |
956 | }; | 959 | }; |
957 | 960 | ||
958 | void KServerSocket::newConnection ( int socket ) | 961 | void KServerSocket::newConnection ( int socket ) |
959 | { | 962 | { |
960 | // qDebug("KServerSocket:New connection %d ", socket); | 963 | // qDebug("KServerSocket:New connection %d ", socket); |
961 | if ( mSocket ) { | 964 | if ( mSocket ) { |
962 | qDebug("KServerSocket::newConnection Socket deleted! "); | 965 | qDebug("KServerSocket::newConnection Socket deleted! "); |
963 | delete mSocket; | 966 | delete mSocket; |
964 | mSocket = 0; | 967 | mSocket = 0; |
965 | } | 968 | } |
966 | mSocket = new QSocket( this ); | 969 | mSocket = new QSocket( this ); |
967 | connect( mSocket , SIGNAL(readyRead()), this, SLOT(readClient()) ); | 970 | connect( mSocket , SIGNAL(readyRead()), this, SLOT(readClient()) ); |
968 | connect( mSocket , SIGNAL(delayedCloseFinished()), this, SLOT(discardClient()) ); | 971 | connect( mSocket , SIGNAL(delayedCloseFinished()), this, SLOT(discardClient()) ); |
969 | mSocket->setSocket( socket ); | 972 | mSocket->setSocket( socket ); |
970 | } | 973 | } |
971 | 974 | ||
972 | void KServerSocket::discardClient() | 975 | void KServerSocket::discardClient() |
973 | { | 976 | { |
974 | //qDebug(" KServerSocket::discardClient()"); | 977 | //qDebug(" KServerSocket::discardClient()"); |
975 | if ( mSocket ) { | 978 | if ( mSocket ) { |
976 | delete mSocket; | 979 | delete mSocket; |
977 | mSocket = 0; | 980 | mSocket = 0; |
978 | } | 981 | } |
979 | //emit endConnect(); | 982 | //emit endConnect(); |
980 | } | 983 | } |
981 | void KServerSocket::readClient() | 984 | void KServerSocket::readClient() |
982 | { | 985 | { |
983 | if ( blockRC ) | 986 | if ( blockRC ) |
984 | return; | 987 | return; |
985 | if ( mSocket == 0 ) { | 988 | if ( mSocket == 0 ) { |
986 | qDebug("ERROR::KServerSocket::readClient(): mSocket == 0 "); | 989 | qDebug("ERROR::KServerSocket::readClient(): mSocket == 0 "); |
987 | return; | 990 | return; |
988 | } | 991 | } |
989 | //qDebug("KServerSocket::readClient()"); | 992 | //qDebug("KServerSocket::readClient()"); |
990 | if ( mSocket->canReadLine() ) { | 993 | if ( mSocket->canReadLine() ) { |
991 | QString line = mSocket->readLine(); | 994 | QString line = mSocket->readLine(); |
992 | //qDebug("KServerSocket readline: %s ", line.latin1()); | 995 | //qDebug("KServerSocket readline: %s ", line.latin1()); |
993 | QStringList tokens = QStringList::split( QRegExp("[ \r\n][ \r\n]*"), line ); | 996 | QStringList tokens = QStringList::split( QRegExp("[ \r\n][ \r\n]*"), line ); |
994 | if ( tokens[0] == "GET" ) { | 997 | if ( tokens[0] == "GET" ) { |
995 | if ( tokens[1] == mPassWord ) | 998 | if ( tokens[1] == mPassWord ) |
996 | //emit sendFile( mSocket ); | 999 | //emit sendFile( mSocket ); |
997 | send_file(); | 1000 | send_file(); |
998 | else { | 1001 | else { |
999 | KMessageBox::error( 0, i18n("Got send file request\nwith invalid password")); | 1002 | KMessageBox::error( 0, i18n("Got send file request\nwith invalid password")); |
1000 | //qDebug("password %s, invalid password %s ",mPassWord.latin1(), tokens[1].latin1() ); | 1003 | //qDebug("password %s, invalid password %s ",mPassWord.latin1(), tokens[1].latin1() ); |
1001 | } | 1004 | } |
1002 | } | 1005 | } |
1003 | if ( tokens[0] == "PUT" ) { | 1006 | if ( tokens[0] == "PUT" ) { |
1004 | if ( tokens[1] == mPassWord ) { | 1007 | if ( tokens[1] == mPassWord ) { |
1005 | //emit getFile( mSocket ); | 1008 | //emit getFile( mSocket ); |
1006 | blockRC = true; | 1009 | blockRC = true; |
1007 | get_file(); | 1010 | get_file(); |
1008 | } | 1011 | } |
1009 | else { | 1012 | else { |
1010 | KMessageBox::error( 0, i18n("Got receive file request\nwith invalid password")); | 1013 | KMessageBox::error( 0, i18n("Got receive file request\nwith invalid password")); |
1011 | //qDebug("password %s, invalid password %s ",mPassWord.latin1(), tokens[1].latin1() ); | 1014 | //qDebug("password %s, invalid password %s ",mPassWord.latin1(), tokens[1].latin1() ); |
1012 | } | 1015 | } |
1013 | } | 1016 | } |
1014 | if ( tokens[0] == "STOP" ) { | 1017 | if ( tokens[0] == "STOP" ) { |
1015 | //emit endConnect(); | 1018 | //emit endConnect(); |
1016 | end_connect(); | 1019 | end_connect(); |
1017 | } | 1020 | } |
1018 | } | 1021 | } |
1019 | } | 1022 | } |
1020 | void KServerSocket::end_connect() | 1023 | void KServerSocket::end_connect() |
1021 | { | 1024 | { |
1022 | delete mSyncActionDialog; | 1025 | delete mSyncActionDialog; |
1023 | mSyncActionDialog = 0; | 1026 | mSyncActionDialog = 0; |
1024 | } | 1027 | } |
1025 | void KServerSocket::send_file() | 1028 | void KServerSocket::send_file() |
1026 | { | 1029 | { |
1027 | //qDebug("MainWindow::sendFile(QSocket* s) "); | 1030 | //qDebug("MainWindow::sendFile(QSocket* s) "); |
1028 | if ( mSyncActionDialog ) | 1031 | if ( mSyncActionDialog ) |
1029 | delete mSyncActionDialog; | 1032 | delete mSyncActionDialog; |
1030 | mSyncActionDialog = new QDialog ( 0, "input-dialog", true ); | 1033 | mSyncActionDialog = new QDialog ( 0, "input-dialog", true ); |
1031 | mSyncActionDialog->setCaption(i18n("Received sync request")); | 1034 | mSyncActionDialog->setCaption(i18n("Received sync request")); |
1032 | QLabel* label = new QLabel( i18n("Synchronizing from remote ...\n\nDo not use this application!\n\nIf syncing fails\nyou can close this dialog."), mSyncActionDialog ); | 1035 | QLabel* label = new QLabel( i18n("Synchronizing from remote ...\n\nDo not use this application!\n\nIf syncing fails\nyou can close this dialog."), mSyncActionDialog ); |
1033 | QVBoxLayout* lay = new QVBoxLayout( mSyncActionDialog ); | 1036 | QVBoxLayout* lay = new QVBoxLayout( mSyncActionDialog ); |
1034 | lay->addWidget( label); | 1037 | lay->addWidget( label); |
1035 | lay->setMargin(7); | 1038 | lay->setMargin(7); |
1036 | lay->setSpacing(7); | 1039 | lay->setSpacing(7); |
1037 | mSyncActionDialog->setFixedSize( 230, 120); | 1040 | mSyncActionDialog->setFixedSize( 230, 120); |
1038 | mSyncActionDialog->show(); | 1041 | mSyncActionDialog->show(); |
1039 | mSyncActionDialog->raise(); | 1042 | mSyncActionDialog->raise(); |
1040 | emit request_file(); | 1043 | emit request_file(); |
1041 | qApp->processEvents(); | 1044 | qApp->processEvents(); |
1042 | QString fileName = mFileName; | 1045 | QString fileName = mFileName; |
1043 | QFile file( fileName ); | 1046 | QFile file( fileName ); |
1044 | if (!file.open( IO_ReadOnly ) ) { | 1047 | if (!file.open( IO_ReadOnly ) ) { |
1045 | delete mSyncActionDialog; | 1048 | delete mSyncActionDialog; |
1046 | mSyncActionDialog = 0; | 1049 | mSyncActionDialog = 0; |
1047 | qDebug("KSS::error open file "); | 1050 | qDebug("KSS::error open file "); |
1048 | mSocket->close(); | 1051 | mSocket->close(); |
1049 | if ( mSocket->state() == QSocket::Idle ) | 1052 | if ( mSocket->state() == QSocket::Idle ) |
1050 | QTimer::singleShot( 10, this , SLOT ( discardClient())); | 1053 | QTimer::singleShot( 10, this , SLOT ( discardClient())); |
1051 | return ; | 1054 | return ; |
1052 | 1055 | ||
1053 | } | 1056 | } |
1054 | mSyncActionDialog->setCaption( i18n("Sending file...") ); | 1057 | mSyncActionDialog->setCaption( i18n("Sending file...") ); |
1055 | QTextStream ts( &file ); | 1058 | QTextStream ts( &file ); |
1056 | ts.setEncoding( QTextStream::Latin1 ); | 1059 | ts.setEncoding( QTextStream::Latin1 ); |
1057 | 1060 | ||
1058 | QTextStream os( mSocket ); | 1061 | QTextStream os( mSocket ); |
1059 | os.setEncoding( QTextStream::Latin1 ); | 1062 | os.setEncoding( QTextStream::Latin1 ); |
1060 | while ( ! ts.atEnd() ) { | 1063 | while ( ! ts.atEnd() ) { |
1061 | os << ts.readLine() << "\r\n"; | 1064 | os << ts.readLine() << "\r\n"; |
1062 | } | 1065 | } |
1063 | //os << ts.read(); | 1066 | //os << ts.read(); |
1064 | file.close(); | 1067 | file.close(); |
1065 | mSyncActionDialog->setCaption( i18n("Waiting for synced file...") ); | 1068 | mSyncActionDialog->setCaption( i18n("Waiting for synced file...") ); |
1066 | mSocket->close(); | 1069 | mSocket->close(); |
1067 | if ( mSocket->state() == QSocket::Idle ) | 1070 | if ( mSocket->state() == QSocket::Idle ) |
1068 | QTimer::singleShot( 10, this , SLOT ( discardClient())); | 1071 | QTimer::singleShot( 10, this , SLOT ( discardClient())); |
1069 | } | 1072 | } |
1070 | void KServerSocket::get_file() | 1073 | void KServerSocket::get_file() |
1071 | { | 1074 | { |
1072 | mSyncActionDialog->setCaption( i18n("Receiving synced file...") ); | 1075 | mSyncActionDialog->setCaption( i18n("Receiving synced file...") ); |
1073 | 1076 | ||
1074 | piTime.start(); | 1077 | piTime.start(); |
1075 | piFileString = ""; | 1078 | piFileString = ""; |
1076 | QTimer::singleShot( 1, this , SLOT (readBackFileFromSocket( ) )); | 1079 | QTimer::singleShot( 1, this , SLOT (readBackFileFromSocket( ) )); |
1077 | } | 1080 | } |
1078 | 1081 | ||
1079 | 1082 | ||
1080 | void KServerSocket::readBackFileFromSocket() | 1083 | void KServerSocket::readBackFileFromSocket() |
1081 | { | 1084 | { |
1082 | //qDebug("readBackFileFromSocket() %d ", piTime.elapsed ()); | 1085 | //qDebug("readBackFileFromSocket() %d ", piTime.elapsed ()); |
1083 | while ( mSocket->canReadLine () ) { | 1086 | while ( mSocket->canReadLine () ) { |
1084 | piTime.restart(); | 1087 | piTime.restart(); |
1085 | QString line = mSocket->readLine (); | 1088 | QString line = mSocket->readLine (); |
1086 | piFileString += line; | 1089 | piFileString += line; |
1087 | //qDebug("readline: %s ", line.latin1()); | 1090 | //qDebug("readline: %s ", line.latin1()); |
1088 | mSyncActionDialog->setCaption( i18n("Received %1 bytes").arg( piFileString.length() ) ); | 1091 | mSyncActionDialog->setCaption( i18n("Received %1 bytes").arg( piFileString.length() ) ); |
1089 | 1092 | ||
1090 | } | 1093 | } |
1091 | if ( piTime.elapsed () < 3000 ) { | 1094 | if ( piTime.elapsed () < 3000 ) { |
1092 | // wait for more | 1095 | // wait for more |
1093 | //qDebug("waitformore "); | 1096 | //qDebug("waitformore "); |
1094 | QTimer::singleShot( 100, this , SLOT (readBackFileFromSocket( ) )); | 1097 | QTimer::singleShot( 100, this , SLOT (readBackFileFromSocket( ) )); |
1095 | return; | 1098 | return; |
1096 | } | 1099 | } |
1097 | QString fileName = mFileName; | 1100 | QString fileName = mFileName; |
1098 | QFile file ( fileName ); | 1101 | QFile file ( fileName ); |
1099 | if (!file.open( IO_WriteOnly ) ) { | 1102 | if (!file.open( IO_WriteOnly ) ) { |
1100 | delete mSyncActionDialog; | 1103 | delete mSyncActionDialog; |
1101 | mSyncActionDialog = 0; | 1104 | mSyncActionDialog = 0; |
1102 | qDebug("KSS:Error open read back file "); | 1105 | qDebug("KSS:Error open read back file "); |
1103 | piFileString = ""; | 1106 | piFileString = ""; |
1104 | emit file_received( false ); | 1107 | emit file_received( false ); |
1105 | blockRC = false; | 1108 | blockRC = false; |
1106 | return ; | 1109 | return ; |
1107 | 1110 | ||
1108 | } | 1111 | } |
1109 | 1112 | ||
1110 | // mView->setLoadedFileVersion(QDateTime::currentDateTime().addSecs( -1)); | 1113 | // mView->setLoadedFileVersion(QDateTime::currentDateTime().addSecs( -1)); |
1111 | QTextStream ts ( &file ); | 1114 | QTextStream ts ( &file ); |
1112 | ts.setEncoding( QTextStream::Latin1 ); | 1115 | ts.setEncoding( QTextStream::Latin1 ); |
1113 | mSyncActionDialog->setCaption( i18n("Writing file to disk...") ); | 1116 | mSyncActionDialog->setCaption( i18n("Writing file to disk...") ); |
1114 | ts << piFileString; | 1117 | ts << piFileString; |
1115 | mSocket->close(); | 1118 | mSocket->close(); |
1116 | if ( mSocket->state() == QSocket::Idle ) | 1119 | if ( mSocket->state() == QSocket::Idle ) |
1117 | QTimer::singleShot( 10, this , SLOT ( discardClient())); | 1120 | QTimer::singleShot( 10, this , SLOT ( discardClient())); |
1118 | file.close(); | 1121 | file.close(); |
1119 | delete mSyncActionDialog; | 1122 | delete mSyncActionDialog; |
1120 | mSyncActionDialog = 0; | 1123 | mSyncActionDialog = 0; |
1121 | piFileString = ""; | 1124 | piFileString = ""; |
1122 | blockRC = false; | 1125 | blockRC = false; |
1123 | emit file_received( true ); | 1126 | emit file_received( true ); |
1124 | 1127 | ||
1125 | } | 1128 | } |
1126 | 1129 | ||
1127 | KCommandSocket::KCommandSocket ( QString password, Q_UINT16 port, QString host, QObject * parent, const char * name ): QObject( parent, name ) | 1130 | KCommandSocket::KCommandSocket ( QString password, Q_UINT16 port, QString host, QObject * parent, const char * name ): QObject( parent, name ) |
1128 | { | 1131 | { |
1129 | mPassWord = password; | 1132 | mPassWord = password; |
1130 | mSocket = 0; | 1133 | mSocket = 0; |
1131 | mPort = port; | 1134 | mPort = port; |
1132 | mHost = host; | 1135 | mHost = host; |
1133 | 1136 | ||
1134 | mRetVal = quiet; | 1137 | mRetVal = quiet; |
1135 | mTimerSocket = new QTimer ( this ); | 1138 | mTimerSocket = new QTimer ( this ); |
1136 | connect( mTimerSocket, SIGNAL ( timeout () ), this, SLOT ( deleteSocket() ) ); | 1139 | connect( mTimerSocket, SIGNAL ( timeout () ), this, SLOT ( deleteSocket() ) ); |
1137 | } | 1140 | } |
1138 | void KCommandSocket::readFile( QString fn ) | 1141 | void KCommandSocket::readFile( QString fn ) |
1139 | { | 1142 | { |
1140 | if ( !mSocket ) { | 1143 | if ( !mSocket ) { |
1141 | mSocket = new QSocket( this ); | 1144 | mSocket = new QSocket( this ); |
1142 | connect( mSocket, SIGNAL(readyRead()), this, SLOT(startReadFileFromSocket()) ); | 1145 | connect( mSocket, SIGNAL(readyRead()), this, SLOT(startReadFileFromSocket()) ); |
1143 | connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) ); | 1146 | connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) ); |
1144 | } | 1147 | } |
1145 | mFileString = ""; | 1148 | mFileString = ""; |
1146 | mFileName = fn; | 1149 | mFileName = fn; |
1147 | mFirst = true; | 1150 | mFirst = true; |
1148 | mSocket->connectToHost( mHost, mPort ); | 1151 | mSocket->connectToHost( mHost, mPort ); |
1149 | QTextStream os( mSocket ); | 1152 | QTextStream os( mSocket ); |
1150 | os.setEncoding( QTextStream::Latin1 ); | 1153 | os.setEncoding( QTextStream::Latin1 ); |
1151 | os << "GET " << mPassWord << "\r\n"; | 1154 | os << "GET " << mPassWord << "\r\n"; |
1152 | mTimerSocket->start( 10000 ); | 1155 | mTimerSocket->start( 10000 ); |
1153 | } | 1156 | } |
1154 | 1157 | ||
1155 | void KCommandSocket::writeFile( QString fileName ) | 1158 | void KCommandSocket::writeFile( QString fileName ) |
1156 | { | 1159 | { |
1157 | if ( !mSocket ) { | 1160 | if ( !mSocket ) { |
1158 | mSocket = new QSocket( this ); | 1161 | mSocket = new QSocket( this ); |
1159 | connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) ); | 1162 | connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) ); |
1160 | connect( mSocket, SIGNAL(connected ()), this, SLOT(writeFileToSocket()) ); | 1163 | connect( mSocket, SIGNAL(connected ()), this, SLOT(writeFileToSocket()) ); |
1161 | } | 1164 | } |
1162 | mFileName = fileName ; | 1165 | mFileName = fileName ; |
1163 | mSocket->connectToHost( mHost, mPort ); | 1166 | mSocket->connectToHost( mHost, mPort ); |
1164 | } | 1167 | } |
1165 | void KCommandSocket::writeFileToSocket() | 1168 | void KCommandSocket::writeFileToSocket() |
1166 | { | 1169 | { |
1167 | QFile file2( mFileName ); | 1170 | QFile file2( mFileName ); |
1168 | if (!file2.open( IO_ReadOnly ) ) { | 1171 | if (!file2.open( IO_ReadOnly ) ) { |
1169 | mRetVal= errorW; | 1172 | mRetVal= errorW; |
1170 | mSocket->close(); | 1173 | mSocket->close(); |
1171 | if ( mSocket->state() == QSocket::Idle ) | 1174 | if ( mSocket->state() == QSocket::Idle ) |
1172 | QTimer::singleShot( 10, this , SLOT ( deleteSocket())); | 1175 | QTimer::singleShot( 10, this , SLOT ( deleteSocket())); |
1173 | return ; | 1176 | return ; |
1174 | } | 1177 | } |
1175 | QTextStream ts2( &file2 ); | 1178 | QTextStream ts2( &file2 ); |
1176 | ts2.setEncoding( QTextStream::Latin1 ); | 1179 | ts2.setEncoding( QTextStream::Latin1 ); |
1177 | QTextStream os2( mSocket ); | 1180 | QTextStream os2( mSocket ); |
1178 | os2.setEncoding( QTextStream::Latin1 ); | 1181 | os2.setEncoding( QTextStream::Latin1 ); |
1179 | os2 << "PUT " << mPassWord << "\r\n";; | 1182 | os2 << "PUT " << mPassWord << "\r\n";; |
1180 | while ( ! ts2.atEnd() ) { | 1183 | while ( ! ts2.atEnd() ) { |
1181 | os2 << ts2.readLine() << "\r\n"; | 1184 | os2 << ts2.readLine() << "\r\n"; |
1182 | } | 1185 | } |
1183 | mRetVal= successW; | 1186 | mRetVal= successW; |
1184 | file2.close(); | 1187 | file2.close(); |
1185 | mSocket->close(); | 1188 | mSocket->close(); |
1186 | if ( mSocket->state() == QSocket::Idle ) | 1189 | if ( mSocket->state() == QSocket::Idle ) |
1187 | QTimer::singleShot( 10, this , SLOT ( deleteSocket())); | 1190 | QTimer::singleShot( 10, this , SLOT ( deleteSocket())); |
1188 | } | 1191 | } |
1189 | void KCommandSocket::sendStop() | 1192 | void KCommandSocket::sendStop() |
1190 | { | 1193 | { |
1191 | if ( !mSocket ) { | 1194 | if ( !mSocket ) { |
1192 | mSocket = new QSocket( this ); | 1195 | mSocket = new QSocket( this ); |
1193 | connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) ); | 1196 | connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) ); |
1194 | } | 1197 | } |
1195 | mSocket->connectToHost( mHost, mPort ); | 1198 | mSocket->connectToHost( mHost, mPort ); |
1196 | QTextStream os2( mSocket ); | 1199 | QTextStream os2( mSocket ); |
1197 | os2.setEncoding( QTextStream::Latin1 ); | 1200 | os2.setEncoding( QTextStream::Latin1 ); |
1198 | os2 << "STOP\r\n"; | 1201 | os2 << "STOP\r\n"; |
1199 | mSocket->close(); | 1202 | mSocket->close(); |
1200 | if ( mSocket->state() == QSocket::Idle ) | 1203 | if ( mSocket->state() == QSocket::Idle ) |
1201 | QTimer::singleShot( 10, this , SLOT ( deleteSocket())); | 1204 | QTimer::singleShot( 10, this , SLOT ( deleteSocket())); |
1202 | } | 1205 | } |
1203 | 1206 | ||
1204 | void KCommandSocket::startReadFileFromSocket() | 1207 | void KCommandSocket::startReadFileFromSocket() |
1205 | { | 1208 | { |
1206 | if ( ! mFirst ) | 1209 | if ( ! mFirst ) |
1207 | return; | 1210 | return; |
1208 | mFirst = false; | 1211 | mFirst = false; |
1209 | mTimerSocket->stop(); | 1212 | mTimerSocket->stop(); |
1210 | mFileString = ""; | 1213 | mFileString = ""; |
1211 | mTime.start(); | 1214 | mTime.start(); |
1212 | QTimer::singleShot( 1, this , SLOT (readFileFromSocket( ) )); | 1215 | QTimer::singleShot( 1, this , SLOT (readFileFromSocket( ) )); |
1213 | 1216 | ||
1214 | } | 1217 | } |
1215 | void KCommandSocket::readFileFromSocket() | 1218 | void KCommandSocket::readFileFromSocket() |
1216 | { | 1219 | { |
1217 | //qDebug("readBackFileFromSocket() %d ", mTime.elapsed ()); | 1220 | //qDebug("readBackFileFromSocket() %d ", mTime.elapsed ()); |
1218 | while ( mSocket->canReadLine () ) { | 1221 | while ( mSocket->canReadLine () ) { |
1219 | mTime.restart(); | 1222 | mTime.restart(); |
1220 | QString line = mSocket->readLine (); | 1223 | QString line = mSocket->readLine (); |
1221 | mFileString += line; | 1224 | mFileString += line; |
1222 | //qDebug("readline: %s ", line.latin1()); | 1225 | //qDebug("readline: %s ", line.latin1()); |
1223 | } | 1226 | } |
1224 | if ( mTime.elapsed () < 3000 ) { | 1227 | if ( mTime.elapsed () < 3000 ) { |
1225 | // wait for more | 1228 | // wait for more |
1226 | //qDebug("waitformore "); | 1229 | //qDebug("waitformore "); |
1227 | QTimer::singleShot( 100, this , SLOT (readFileFromSocket( ) )); | 1230 | QTimer::singleShot( 100, this , SLOT (readFileFromSocket( ) )); |
1228 | return; | 1231 | return; |
1229 | } | 1232 | } |
1230 | QString fileName = mFileName; | 1233 | QString fileName = mFileName; |
1231 | QFile file ( fileName ); | 1234 | QFile file ( fileName ); |
1232 | if (!file.open( IO_WriteOnly ) ) { | 1235 | if (!file.open( IO_WriteOnly ) ) { |
1233 | mFileString = ""; | 1236 | mFileString = ""; |
1234 | mRetVal = errorR; | 1237 | mRetVal = errorR; |
1235 | qDebug("KSS:Error open temp sync file for writing: %s",fileName.latin1() ); | 1238 | qDebug("KSS:Error open temp sync file for writing: %s",fileName.latin1() ); |
1236 | deleteSocket(); | 1239 | deleteSocket(); |
1237 | return ; | 1240 | return ; |
1238 | 1241 | ||
1239 | } | 1242 | } |
1240 | // mView->setLoadedFileVersion(QDateTime::currentDateTime().addSecs( -1)); | 1243 | // mView->setLoadedFileVersion(QDateTime::currentDateTime().addSecs( -1)); |
1241 | QTextStream ts ( &file ); | 1244 | QTextStream ts ( &file ); |
1242 | ts.setEncoding( QTextStream::Latin1 ); | 1245 | ts.setEncoding( QTextStream::Latin1 ); |
1243 | ts << mFileString; | 1246 | ts << mFileString; |
1244 | file.close(); | 1247 | file.close(); |
1245 | mFileString = ""; | 1248 | mFileString = ""; |
1246 | mRetVal = successR; | 1249 | mRetVal = successR; |
1247 | mSocket->close(); | 1250 | mSocket->close(); |
1248 | // if state is not idle, deleteSocket(); is called via | 1251 | // if state is not idle, deleteSocket(); is called via |
1249 | // connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) ); | 1252 | // connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) ); |
1250 | if ( mSocket->state() == QSocket::Idle ) | 1253 | if ( mSocket->state() == QSocket::Idle ) |
1251 | deleteSocket(); | 1254 | deleteSocket(); |
1252 | } | 1255 | } |
1253 | 1256 | ||
1254 | void KCommandSocket::deleteSocket() | 1257 | void KCommandSocket::deleteSocket() |
1255 | { | 1258 | { |
1256 | //qDebug("KCommandSocket::deleteSocket() "); | 1259 | //qDebug("KCommandSocket::deleteSocket() "); |
1257 | if ( mTimerSocket->isActive () ) { | 1260 | if ( mTimerSocket->isActive () ) { |
1258 | mTimerSocket->stop(); | 1261 | mTimerSocket->stop(); |
1259 | mRetVal = errorTO; | 1262 | mRetVal = errorTO; |
1260 | qDebug("Connection to remote host timed out"); | 1263 | qDebug("Connection to remote host timed out"); |
1261 | if ( mSocket ) { | 1264 | if ( mSocket ) { |
1262 | mSocket->close(); | 1265 | mSocket->close(); |
1263 | //if ( mSocket->state() == QSocket::Idle ) | 1266 | //if ( mSocket->state() == QSocket::Idle ) |
1264 | // deleteSocket(); | 1267 | // deleteSocket(); |
1265 | delete mSocket; | 1268 | delete mSocket; |
1266 | mSocket = 0; | 1269 | mSocket = 0; |
1267 | } | 1270 | } |
1268 | KMessageBox::error( 0, i18n("Connection to remote\nhost timed out!\nDid you forgot to enable\nsyncing on remote host? ")); | 1271 | KMessageBox::error( 0, i18n("Connection to remote\nhost timed out!\nDid you forgot to enable\nsyncing on remote host? ")); |
1269 | emit commandFinished( this, mRetVal ); | 1272 | emit commandFinished( this, mRetVal ); |
1270 | return; | 1273 | return; |
1271 | } | 1274 | } |
1272 | //qDebug("KCommandSocket::deleteSocket() %d", mRetVal ); | 1275 | //qDebug("KCommandSocket::deleteSocket() %d", mRetVal ); |
1273 | if ( mSocket) | 1276 | if ( mSocket) |
1274 | delete mSocket; | 1277 | delete mSocket; |
1275 | mSocket = 0; | 1278 | mSocket = 0; |
1276 | emit commandFinished( this, mRetVal ); | 1279 | emit commandFinished( this, mRetVal ); |
1277 | } | 1280 | } |