-rw-r--r-- | libkdepim/ksyncmanager.cpp | 97 |
1 files changed, 78 insertions, 19 deletions
diff --git a/libkdepim/ksyncmanager.cpp b/libkdepim/ksyncmanager.cpp index fc0ac6b..f2ee0ab 100644 --- a/libkdepim/ksyncmanager.cpp +++ b/libkdepim/ksyncmanager.cpp | |||
@@ -228,340 +228,345 @@ void KSyncManager::slotSyncMenu( int action ) | |||
228 | 228 | ||
229 | if (blockSave()) | 229 | if (blockSave()) |
230 | return; | 230 | return; |
231 | 231 | ||
232 | setBlockSave(true); | 232 | setBlockSave(true); |
233 | bool silent = false; | 233 | bool silent = false; |
234 | if ( action == 999 ) { | 234 | if ( action == 999 ) { |
235 | //special mode for silent syncing | 235 | //special mode for silent syncing |
236 | action = 1000; | 236 | action = 1000; |
237 | silent = true; | 237 | silent = true; |
238 | } | 238 | } |
239 | 239 | ||
240 | mCurrentSyncProfile = action - 1000 ; | 240 | mCurrentSyncProfile = action - 1000 ; |
241 | mCurrentSyncDevice = mSyncProfileNames[mCurrentSyncProfile] ; | 241 | mCurrentSyncDevice = mSyncProfileNames[mCurrentSyncProfile] ; |
242 | mCurrentSyncName = mLocalMachineName ; | 242 | mCurrentSyncName = mLocalMachineName ; |
243 | KConfig config ( locateLocal( "config","ksyncprofilesrc" ) ); | 243 | KConfig config ( locateLocal( "config","ksyncprofilesrc" ) ); |
244 | KSyncProfile* temp = new KSyncProfile (); | 244 | KSyncProfile* temp = new KSyncProfile (); |
245 | temp->setName(mSyncProfileNames[mCurrentSyncProfile]); | 245 | temp->setName(mSyncProfileNames[mCurrentSyncProfile]); |
246 | temp->readConfig(&config); | 246 | temp->readConfig(&config); |
247 | if (silent) { | 247 | if (silent) { |
248 | mAskForPreferences = false; | 248 | mAskForPreferences = false; |
249 | mShowSyncSummary = false; | 249 | mShowSyncSummary = false; |
250 | mWriteBackFile = true; | 250 | mWriteBackFile = true; |
251 | mSyncAlgoPrefs = 2;// take newest | 251 | mSyncAlgoPrefs = 2;// take newest |
252 | } | 252 | } |
253 | else { | 253 | else { |
254 | mAskForPreferences = temp->getAskForPreferences(); | 254 | mAskForPreferences = temp->getAskForPreferences(); |
255 | mShowSyncSummary = temp->getShowSummaryAfterSync(); | 255 | mShowSyncSummary = temp->getShowSummaryAfterSync(); |
256 | mWriteBackFile = temp->getWriteBackFile(); | 256 | mWriteBackFile = temp->getWriteBackFile(); |
257 | mSyncAlgoPrefs = temp->getSyncPrefs(); | 257 | mSyncAlgoPrefs = temp->getSyncPrefs(); |
258 | } | 258 | } |
259 | mWriteBackExistingOnly = temp->getWriteBackExisting(); | 259 | mWriteBackExistingOnly = temp->getWriteBackExisting(); |
260 | mIsKapiFile = temp->getIsKapiFile(); | 260 | mIsKapiFile = temp->getIsKapiFile(); |
261 | mWriteBackInFuture = 0; | 261 | mWriteBackInFuture = 0; |
262 | if ( temp->getWriteBackFuture() ) { | 262 | if ( temp->getWriteBackFuture() ) { |
263 | mWriteBackInFuture = temp->getWriteBackFutureWeeks( ); | 263 | mWriteBackInFuture = temp->getWriteBackFutureWeeks( ); |
264 | mWriteBackInPast = temp->getWriteBackPastWeeks( ); | 264 | mWriteBackInPast = temp->getWriteBackPastWeeks( ); |
265 | } | 265 | } |
266 | mFilterInCal = temp->getFilterInCal(); | 266 | mFilterInCal = temp->getFilterInCal(); |
267 | mFilterOutCal = temp->getFilterOutCal(); | 267 | mFilterOutCal = temp->getFilterOutCal(); |
268 | mFilterInAB = temp->getFilterInAB(); | 268 | mFilterInAB = temp->getFilterInAB(); |
269 | mFilterOutAB = temp->getFilterOutAB(); | 269 | mFilterOutAB = temp->getFilterOutAB(); |
270 | 270 | ||
271 | if ( action == 1000 ) { | 271 | if ( action == 1000 ) { |
272 | mIsKapiFile = false; | 272 | mIsKapiFile = false; |
273 | #ifdef DESKTOP_VERSION | 273 | #ifdef DESKTOP_VERSION |
274 | syncKDE(); | 274 | syncKDE(); |
275 | #else | 275 | #else |
276 | syncSharp(); | 276 | syncSharp(); |
277 | #endif | 277 | #endif |
278 | 278 | ||
279 | } else if ( action == 1001 ) { | 279 | } else if ( action == 1001 ) { |
280 | syncLocalFile(); | 280 | syncLocalFile(); |
281 | 281 | ||
282 | } else if ( action == 1002 ) { | 282 | } else if ( action == 1002 ) { |
283 | mWriteBackFile = false; | 283 | mWriteBackFile = false; |
284 | mAskForPreferences = false; | 284 | mAskForPreferences = false; |
285 | mShowSyncSummary = false; | 285 | mShowSyncSummary = false; |
286 | mSyncAlgoPrefs = 3; | 286 | mSyncAlgoPrefs = 3; |
287 | quickSyncLocalFile(); | 287 | quickSyncLocalFile(); |
288 | 288 | ||
289 | } else if ( action >= 1003 ) { | 289 | } else if ( action >= 1003 ) { |
290 | if ( temp->getIsLocalFileSync() ) { | 290 | if ( temp->getIsLocalFileSync() ) { |
291 | switch(mTargetApp) | 291 | switch(mTargetApp) |
292 | { | 292 | { |
293 | case (KAPI): | 293 | case (KAPI): |
294 | if ( syncWithFile( temp->getRemoteFileNameAB( ), false ) ) | 294 | if ( syncWithFile( temp->getRemoteFileNameAB( ), false ) ) |
295 | mPrefs->mLastSyncedLocalFile = temp->getRemoteFileNameAB(); | 295 | mPrefs->mLastSyncedLocalFile = temp->getRemoteFileNameAB(); |
296 | break; | 296 | break; |
297 | case (KOPI): | 297 | case (KOPI): |
298 | if ( syncWithFile( temp->getRemoteFileName( ), false ) ) | 298 | if ( syncWithFile( temp->getRemoteFileName( ), false ) ) |
299 | mPrefs->mLastSyncedLocalFile = temp->getRemoteFileName(); | 299 | mPrefs->mLastSyncedLocalFile = temp->getRemoteFileName(); |
300 | break; | 300 | break; |
301 | case (PWMPI): | 301 | case (PWMPI): |
302 | if ( syncWithFile( temp->getRemoteFileNamePWM( ), false ) ) | 302 | if ( syncWithFile( temp->getRemoteFileNamePWM( ), false ) ) |
303 | mPrefs->mLastSyncedLocalFile = temp->getRemoteFileNamePWM(); | 303 | mPrefs->mLastSyncedLocalFile = temp->getRemoteFileNamePWM(); |
304 | break; | 304 | break; |
305 | default: | 305 | default: |
306 | qDebug("KSM::slotSyncMenu: invalid apptype selected"); | 306 | qDebug("KSM::slotSyncMenu: invalid apptype selected"); |
307 | break; | 307 | break; |
308 | 308 | ||
309 | } | 309 | } |
310 | } else { | 310 | } else { |
311 | if ( temp->getIsPhoneSync() ) { | 311 | if ( temp->getIsPhoneSync() ) { |
312 | mPhoneDevice = temp->getPhoneDevice( ) ; | 312 | mPhoneDevice = temp->getPhoneDevice( ) ; |
313 | mPhoneConnection = temp->getPhoneConnection( ); | 313 | mPhoneConnection = temp->getPhoneConnection( ); |
314 | mPhoneModel = temp->getPhoneModel( ); | 314 | mPhoneModel = temp->getPhoneModel( ); |
315 | syncPhone(); | 315 | syncPhone(); |
316 | } else if ( temp->getIsPiSync() ) { | 316 | } else if ( temp->getIsPiSync() ) { |
317 | if ( mTargetApp == KAPI ) { | 317 | if ( mTargetApp == KAPI ) { |
318 | mPassWordPiSync = temp->getRemotePwAB(); | 318 | mPassWordPiSync = temp->getRemotePwAB(); |
319 | mActiveSyncPort = temp->getRemotePortAB(); | 319 | mActiveSyncPort = temp->getRemotePortAB(); |
320 | mActiveSyncIP = temp->getRemoteIPAB(); | 320 | mActiveSyncIP = temp->getRemoteIPAB(); |
321 | } else if ( mTargetApp == KOPI ) { | 321 | } else if ( mTargetApp == KOPI ) { |
322 | mPassWordPiSync = temp->getRemotePw(); | 322 | mPassWordPiSync = temp->getRemotePw(); |
323 | mActiveSyncPort = temp->getRemotePort(); | 323 | mActiveSyncPort = temp->getRemotePort(); |
324 | mActiveSyncIP = temp->getRemoteIP(); | 324 | mActiveSyncIP = temp->getRemoteIP(); |
325 | } else { | 325 | } else { |
326 | mPassWordPiSync = temp->getRemotePwPWM(); | 326 | mPassWordPiSync = temp->getRemotePwPWM(); |
327 | mActiveSyncPort = temp->getRemotePortPWM(); | 327 | mActiveSyncPort = temp->getRemotePortPWM(); |
328 | mActiveSyncIP = temp->getRemoteIPPWM(); | 328 | mActiveSyncIP = temp->getRemoteIPPWM(); |
329 | } | 329 | } |
330 | syncPi(); | 330 | syncPi(); |
331 | while ( !mPisyncFinished ) { | 331 | while ( !mPisyncFinished ) { |
332 | //qDebug("waiting "); | 332 | //qDebug("waiting "); |
333 | qApp->processEvents(); | 333 | qApp->processEvents(); |
334 | } | 334 | } |
335 | } else | 335 | } else |
336 | syncRemote( temp ); | 336 | syncRemote( temp ); |
337 | 337 | ||
338 | } | 338 | } |
339 | } | 339 | } |
340 | delete temp; | 340 | delete temp; |
341 | setBlockSave(false); | 341 | setBlockSave(false); |
342 | } | 342 | } |
343 | 343 | ||
344 | void KSyncManager::enableQuick( bool ask ) | 344 | void KSyncManager::enableQuick( bool ask ) |
345 | { | 345 | { |
346 | bool autoStart; | 346 | bool autoStart; |
347 | bool changed = false; | 347 | bool changed = false; |
348 | if ( ask ) { | 348 | if ( ask ) { |
349 | QDialog dia ( 0, "input-dialog", true ); | 349 | QDialog dia ( 0, "input-dialog", true ); |
350 | QLineEdit lab ( &dia ); | 350 | QLineEdit lab ( &dia ); |
351 | QVBoxLayout lay( &dia ); | 351 | QVBoxLayout lay( &dia ); |
352 | lab.setText( mPrefs->mPassiveSyncPort ); | 352 | lab.setText( mPrefs->mPassiveSyncPort ); |
353 | lay.setMargin(7); | 353 | lay.setMargin(7); |
354 | lay.setSpacing(7); | 354 | lay.setSpacing(7); |
355 | int po = 9197+mTargetApp; | 355 | int po = 9197+mTargetApp; |
356 | QLabel label ( i18n("Port number (Default: %1)").arg(po), &dia ); | 356 | QLabel label ( i18n("Port number (Default: %1)\nValid range from 1 to 65535").arg(po), &dia ); |
357 | lay.addWidget( &label); | 357 | lay.addWidget( &label); |
358 | lay.addWidget( &lab); | 358 | lay.addWidget( &lab); |
359 | 359 | ||
360 | QLineEdit lepw ( &dia ); | 360 | QLineEdit lepw ( &dia ); |
361 | lepw.setText( mPrefs->mPassiveSyncPw ); | 361 | lepw.setText( mPrefs->mPassiveSyncPw ); |
362 | QLabel label2 ( i18n("Password to enable\naccess from remote:"), &dia ); | 362 | QLabel label2 ( i18n("Password to enable\naccess from remote:"), &dia ); |
363 | lay.addWidget( &label2); | 363 | lay.addWidget( &label2); |
364 | lay.addWidget( &lepw); | 364 | lay.addWidget( &lepw); |
365 | QCheckBox autostart(i18n("Automatically start\nat application startup"), &dia ); | 365 | QCheckBox autostart(i18n("Automatically start\nat application startup"), &dia ); |
366 | lay.addWidget( &autostart); | 366 | lay.addWidget( &autostart); |
367 | autostart.setChecked( mPrefs->mPassiveSyncAutoStart ); | 367 | autostart.setChecked( mPrefs->mPassiveSyncAutoStart ); |
368 | #ifdef DESKTOP_VERSION | 368 | #ifdef DESKTOP_VERSION |
369 | #ifdef _WIN32_ | 369 | #ifdef _WIN32_ |
370 | QCheckBox syncdesktop( i18n("Automatically sync with Outlook\nwhen receiving sync request"),&dia ); | 370 | QCheckBox syncdesktop( i18n("Automatically sync with Outlook\nwhen receiving sync request"),&dia ); |
371 | syncdesktop.hide();// not implemented! | 371 | syncdesktop.hide();// not implemented! |
372 | #else | 372 | #else |
373 | QCheckBox syncdesktop( i18n("Automatically sync with KDE-Desktop\nwhen receiving sync request"),&dia ); | 373 | QCheckBox syncdesktop( i18n("Automatically sync with KDE-Desktop\nwhen receiving sync request"),&dia ); |
374 | #endif | 374 | #endif |
375 | lay.addWidget( &syncdesktop); | 375 | lay.addWidget( &syncdesktop); |
376 | #else | 376 | #else |
377 | mPrefs->mPassiveSyncWithDesktop = false; | 377 | mPrefs->mPassiveSyncWithDesktop = false; |
378 | QCheckBox syncdesktop( i18n("Automatically sync\nwith KDE-Desktop"),&dia ); | 378 | QCheckBox syncdesktop( i18n("Automatically sync\nwith KDE-Desktop"),&dia ); |
379 | syncdesktop.hide(); | 379 | syncdesktop.hide(); |
380 | #endif | 380 | #endif |
381 | syncdesktop.setChecked( mPrefs->mPassiveSyncWithDesktop ); | 381 | syncdesktop.setChecked( mPrefs->mPassiveSyncWithDesktop ); |
382 | 382 | ||
383 | QPushButton pb ( "OK", &dia); | 383 | QPushButton pb ( "OK", &dia); |
384 | lay.addWidget( &pb ); | 384 | lay.addWidget( &pb ); |
385 | connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) ); | 385 | connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) ); |
386 | dia.resize( 230,120 ); | 386 | dia.resize( 230,120 ); |
387 | dia.setCaption( i18n("Enter port for Pi-Sync") ); | 387 | dia.setCaption( i18n("Enter port for Pi-Sync") ); |
388 | dia.show(); | 388 | dia.show(); |
389 | #ifndef DESKTOP_VERSION | 389 | #ifndef DESKTOP_VERSION |
390 | int dw = QApplication::desktop()->width(); | 390 | int dw = QApplication::desktop()->width(); |
391 | int dh = QApplication::desktop()->height(); | 391 | int dh = QApplication::desktop()->height(); |
392 | dia.move( (dw-dia.width())/2, (dh - dia.height() )/2 ); | 392 | dia.move( (dw-dia.width())/2, (dh - dia.height() )/2 ); |
393 | #endif | 393 | #endif |
394 | if ( ! dia.exec() ) | 394 | if ( ! dia.exec() ) |
395 | return; | 395 | return; |
396 | dia.hide(); | 396 | dia.hide(); |
397 | qApp->processEvents(); | 397 | qApp->processEvents(); |
398 | if ( mPrefs->mPassiveSyncPw != lepw.text() ) { | 398 | if ( mPrefs->mPassiveSyncPw != lepw.text() ) { |
399 | changed = true; | 399 | changed = true; |
400 | mPrefs->mPassiveSyncPw = lepw.text(); | 400 | mPrefs->mPassiveSyncPw = lepw.text(); |
401 | } | 401 | } |
402 | if ( mPrefs->mPassiveSyncPort != lab.text() ) { | 402 | if ( mPrefs->mPassiveSyncPort != lab.text() ) { |
403 | mPrefs->mPassiveSyncPort = lab.text(); | 403 | mPrefs->mPassiveSyncPort = lab.text(); |
404 | changed = true; | 404 | changed = true; |
405 | } | 405 | } |
406 | autoStart = autostart.isChecked(); | 406 | autoStart = autostart.isChecked(); |
407 | if (mPrefs->mPassiveSyncWithDesktop != syncdesktop.isChecked() ) { | 407 | if (mPrefs->mPassiveSyncWithDesktop != syncdesktop.isChecked() ) { |
408 | changed = true; | 408 | changed = true; |
409 | mPrefs->mPassiveSyncWithDesktop = syncdesktop.isChecked(); | 409 | mPrefs->mPassiveSyncWithDesktop = syncdesktop.isChecked(); |
410 | } | 410 | } |
411 | } | 411 | } |
412 | else | 412 | else |
413 | autoStart = mPrefs->mPassiveSyncAutoStart; | 413 | autoStart = mPrefs->mPassiveSyncAutoStart; |
414 | if ( autoStart != mPrefs->mPassiveSyncAutoStart ) | 414 | if ( autoStart != mPrefs->mPassiveSyncAutoStart ) |
415 | changed = true; | 415 | changed = true; |
416 | bool ok; | 416 | bool ok; |
417 | mPrefs->mPassiveSyncAutoStart = false; | 417 | mPrefs->mPassiveSyncAutoStart = false; |
418 | Q_UINT16 port = mPrefs->mPassiveSyncPort.toUInt(&ok); | 418 | Q_UINT32 port_t = mPrefs->mPassiveSyncPort.toUInt(&ok); |
419 | if ( ! ok ) { | 419 | qDebug("%d ", port_t); |
420 | KMessageBox::information( 0, i18n("No valid port")); | 420 | if ( ! ok || port_t > 65535 ) { |
421 | KMessageBox::information( 0, i18n("No valid port number:\n%1").arg ( mPrefs->mPassiveSyncPort ), i18n("Pi-Sync Port Error")); | ||
421 | return; | 422 | return; |
422 | } | 423 | } |
424 | Q_UINT16 port = port_t; | ||
423 | //qDebug("port %d ", port); | 425 | //qDebug("port %d ", port); |
424 | mServerSocket = new KServerSocket ( mPrefs->mPassiveSyncPw, port ,1 ); | 426 | mServerSocket = new KServerSocket ( mPrefs->mPassiveSyncPw, port ,1 ); |
425 | mServerSocket->setFileName( defaultFileName() );//bbb | 427 | mServerSocket->setFileName( defaultFileName() );//bbb |
426 | if ( !mServerSocket->ok() ) { | 428 | if ( !mServerSocket->ok() ) { |
427 | KMessageBox::information( 0, i18n("Failed to bind or\nlisten to the port!")); | 429 | QTimer::singleShot( 2000, this, SLOT ( displayErrorPort() ) ); |
428 | delete mServerSocket; | 430 | delete mServerSocket; |
429 | mServerSocket = 0; | 431 | mServerSocket = 0; |
430 | return; | 432 | return; |
431 | } | 433 | } |
432 | mPrefs->mPassiveSyncAutoStart = autoStart; | 434 | mPrefs->mPassiveSyncAutoStart = autoStart; |
433 | if ( changed ) { | 435 | if ( changed ) { |
434 | mPrefs->writeConfig(); | 436 | mPrefs->writeConfig(); |
435 | } | 437 | } |
436 | connect( mServerSocket, SIGNAL ( request_file() ),this, SIGNAL ( request_file() ) ); | 438 | connect( mServerSocket, SIGNAL ( request_file() ),this, SIGNAL ( request_file() ) ); |
437 | connect( mServerSocket, SIGNAL ( file_received( bool ) ), this, SIGNAL ( getFile( bool ) ) ); | 439 | connect( mServerSocket, SIGNAL ( file_received( bool ) ), this, SIGNAL ( getFile( bool ) ) ); |
438 | } | 440 | } |
439 | 441 | void KSyncManager::displayErrorPort() | |
442 | { | ||
443 | KMessageBox::information( 0, i18n("<b>Enabling Pi-Sync failed!</b> Failed to bind or listen to the port %1! Is another instance already listening to that port?").arg( mPrefs->mPassiveSyncPort) , i18n("Pi-Sync Port Error")); | ||
444 | } | ||
440 | void KSyncManager::syncLocalFile() | 445 | void KSyncManager::syncLocalFile() |
441 | { | 446 | { |
442 | 447 | ||
443 | QString fn =mPrefs->mLastSyncedLocalFile; | 448 | QString fn =mPrefs->mLastSyncedLocalFile; |
444 | QString ext; | 449 | QString ext; |
445 | 450 | ||
446 | switch(mTargetApp) | 451 | switch(mTargetApp) |
447 | { | 452 | { |
448 | case (KAPI): | 453 | case (KAPI): |
449 | ext = "(*.vcf)"; | 454 | ext = "(*.vcf)"; |
450 | break; | 455 | break; |
451 | case (KOPI): | 456 | case (KOPI): |
452 | ext = "(*.ics/*.vcs)"; | 457 | ext = "(*.ics/*.vcs)"; |
453 | break; | 458 | break; |
454 | case (PWMPI): | 459 | case (PWMPI): |
455 | ext = "(*.pwm)"; | 460 | ext = "(*.pwm)"; |
456 | break; | 461 | break; |
457 | default: | 462 | default: |
458 | qDebug("KSM::syncLocalFile: invalid apptype selected"); | 463 | qDebug("KSM::syncLocalFile: invalid apptype selected"); |
459 | break; | 464 | break; |
460 | 465 | ||
461 | } | 466 | } |
462 | 467 | ||
463 | fn =KFileDialog:: getOpenFileName( fn, i18n("Sync filename"+ext), mParent ); | 468 | fn =KFileDialog:: getOpenFileName( fn, i18n("Sync filename"+ext), mParent ); |
464 | if ( fn == "" ) | 469 | if ( fn == "" ) |
465 | return; | 470 | return; |
466 | if ( syncWithFile( fn, false ) ) { | 471 | if ( syncWithFile( fn, false ) ) { |
467 | qDebug("KSM::syncLocalFile() successful "); | 472 | qDebug("KSM::syncLocalFile() successful "); |
468 | } | 473 | } |
469 | 474 | ||
470 | } | 475 | } |
471 | 476 | ||
472 | bool KSyncManager::syncWithFile( QString fn , bool quick ) | 477 | bool KSyncManager::syncWithFile( QString fn , bool quick ) |
473 | { | 478 | { |
474 | bool ret = false; | 479 | bool ret = false; |
475 | QFileInfo info; | 480 | QFileInfo info; |
476 | info.setFile( fn ); | 481 | info.setFile( fn ); |
477 | QString mess; | 482 | QString mess; |
478 | if ( !info. exists() ) { | 483 | if ( !info. exists() ) { |
479 | mess = i18n( "Sync file \n...%1\ndoes not exist!\nNothing synced!\n").arg(fn.right( 30) ); | 484 | mess = i18n( "Sync file \n...%1\ndoes not exist!\nNothing synced!\n").arg(fn.right( 30) ); |
480 | QMessageBox::warning( mParent, i18n("Warning!"), | 485 | QMessageBox::warning( mParent, i18n("Warning!"), |
481 | mess ); | 486 | mess ); |
482 | return ret; | 487 | return ret; |
483 | } | 488 | } |
484 | int result = 0; | 489 | int result = 0; |
485 | if ( !quick ) { | 490 | if ( !quick ) { |
486 | mess = i18n("Sync with file \n...%1\nfrom:\n%2\n").arg(fn.right( 25)).arg(KGlobal::locale()->formatDateTime(info.lastModified (), true, false )); | 491 | mess = i18n("Sync with file \n...%1\nfrom:\n%2\n").arg(fn.right( 25)).arg(KGlobal::locale()->formatDateTime(info.lastModified (), true, false )); |
487 | result = QMessageBox::warning( mParent, i18n("Warning!"), | 492 | result = QMessageBox::warning( mParent, i18n("Warning!"), |
488 | mess, | 493 | mess, |
489 | i18n("Sync"), i18n("Cancel"), 0, | 494 | i18n("Sync"), i18n("Cancel"), 0, |
490 | 0, 1 ); | 495 | 0, 1 ); |
491 | if ( result ) | 496 | if ( result ) |
492 | return false; | 497 | return false; |
493 | } | 498 | } |
494 | if ( mAskForPreferences ) | 499 | if ( mAskForPreferences ) |
495 | if ( !edit_sync_options()) { | 500 | if ( !edit_sync_options()) { |
496 | mParent->topLevelWidget()->setCaption( i18n("Syncing aborted. Nothing synced.") ); | 501 | mParent->topLevelWidget()->setCaption( i18n("Syncing aborted. Nothing synced.") ); |
497 | return false; | 502 | return false; |
498 | } | 503 | } |
499 | if ( result == 0 ) { | 504 | if ( result == 0 ) { |
500 | //qDebug("Now sycing ... "); | 505 | //qDebug("Now sycing ... "); |
501 | if ( ret = mImplementation->sync( this, fn, mSyncAlgoPrefs ) ) | 506 | if ( ret = mImplementation->sync( this, fn, mSyncAlgoPrefs ) ) |
502 | mParent->topLevelWidget()->setCaption( i18n("Synchronization successful") ); | 507 | mParent->topLevelWidget()->setCaption( i18n("Synchronization successful") ); |
503 | else | 508 | else |
504 | mParent->topLevelWidget()->setCaption( i18n("Sync cancelled or failed.") ); | 509 | mParent->topLevelWidget()->setCaption( i18n("Sync cancelled or failed.") ); |
505 | if ( ! quick ) | 510 | if ( ! quick ) |
506 | mPrefs->mLastSyncedLocalFile = fn; | 511 | mPrefs->mLastSyncedLocalFile = fn; |
507 | } | 512 | } |
508 | return ret; | 513 | return ret; |
509 | } | 514 | } |
510 | 515 | ||
511 | void KSyncManager::quickSyncLocalFile() | 516 | void KSyncManager::quickSyncLocalFile() |
512 | { | 517 | { |
513 | 518 | ||
514 | if ( syncWithFile( mPrefs->mLastSyncedLocalFile, true ) ) { | 519 | if ( syncWithFile( mPrefs->mLastSyncedLocalFile, true ) ) { |
515 | qDebug("KSM::quick syncLocalFile() successful "); | 520 | qDebug("KSM::quick syncLocalFile() successful "); |
516 | 521 | ||
517 | } | 522 | } |
518 | } | 523 | } |
519 | 524 | ||
520 | void KSyncManager::multiSync( bool askforPrefs ) | 525 | void KSyncManager::multiSync( bool askforPrefs ) |
521 | { | 526 | { |
522 | if (blockSave()) | 527 | if (blockSave()) |
523 | return; | 528 | return; |
524 | setBlockSave(true); | 529 | setBlockSave(true); |
525 | if ( askforPrefs ) { | 530 | if ( askforPrefs ) { |
526 | QString question = i18n("Do you really want\nto multiple sync\nwith all checked profiles?\nSyncing takes some\ntime - all profiles\nare synced twice!"); | 531 | QString question = i18n("Do you really want\nto multiple sync\nwith all checked profiles?\nSyncing takes some\ntime - all profiles\nare synced twice!"); |
527 | if ( QMessageBox::information( mParent, i18n("KDE-Pim Sync"), | 532 | if ( QMessageBox::information( mParent, i18n("KDE-Pim Sync"), |
528 | question, | 533 | question, |
529 | i18n("Yes"), i18n("No"), | 534 | i18n("Yes"), i18n("No"), |
530 | 0, 0 ) != 0 ) { | 535 | 0, 0 ) != 0 ) { |
531 | setBlockSave(false); | 536 | setBlockSave(false); |
532 | mParent->topLevelWidget()->setCaption(i18n("Aborted! Nothing synced!")); | 537 | mParent->topLevelWidget()->setCaption(i18n("Aborted! Nothing synced!")); |
533 | return; | 538 | return; |
534 | } | 539 | } |
535 | } | 540 | } |
536 | mCurrentSyncDevice = i18n("Multiple profiles") ; | 541 | mCurrentSyncDevice = i18n("Multiple profiles") ; |
537 | mSyncAlgoPrefs = mPrefs->mRingSyncAlgoPrefs; | 542 | mSyncAlgoPrefs = mPrefs->mRingSyncAlgoPrefs; |
538 | if ( askforPrefs ) { | 543 | if ( askforPrefs ) { |
539 | if ( !edit_sync_options()) { | 544 | if ( !edit_sync_options()) { |
540 | mParent->topLevelWidget()->setCaption( i18n("Syncing aborted.") ); | 545 | mParent->topLevelWidget()->setCaption( i18n("Syncing aborted.") ); |
541 | return; | 546 | return; |
542 | } | 547 | } |
543 | mPrefs->mRingSyncAlgoPrefs = mSyncAlgoPrefs; | 548 | mPrefs->mRingSyncAlgoPrefs = mSyncAlgoPrefs; |
544 | } | 549 | } |
545 | mParent->topLevelWidget()->setCaption(i18n("Multiple sync started.") ); | 550 | mParent->topLevelWidget()->setCaption(i18n("Multiple sync started.") ); |
546 | qApp->processEvents(); | 551 | qApp->processEvents(); |
547 | int num = ringSync() ; | 552 | int num = ringSync() ; |
548 | if ( num > 1 ) | 553 | if ( num > 1 ) |
549 | ringSync(); | 554 | ringSync(); |
550 | setBlockSave(false); | 555 | setBlockSave(false); |
551 | if ( num ) | 556 | if ( num ) |
552 | emit save(); | 557 | emit save(); |
553 | if ( num ) | 558 | if ( num ) |
554 | mParent->topLevelWidget()->setCaption(i18n("%1 profiles synced. Multiple sync complete!").arg(num) ); | 559 | mParent->topLevelWidget()->setCaption(i18n("%1 profiles synced. Multiple sync complete!").arg(num) ); |
555 | else | 560 | else |
556 | mParent->topLevelWidget()->setCaption(i18n("Nothing synced! No profiles defined for multisync!")); | 561 | mParent->topLevelWidget()->setCaption(i18n("Nothing synced! No profiles defined for multisync!")); |
557 | return; | 562 | return; |
558 | } | 563 | } |
559 | 564 | ||
560 | int KSyncManager::ringSync() | 565 | int KSyncManager::ringSync() |
561 | { | 566 | { |
562 | 567 | ||
563 | int syncedProfiles = 0; | 568 | int syncedProfiles = 0; |
564 | unsigned int i; | 569 | unsigned int i; |
565 | QTime timer; | 570 | QTime timer; |
566 | KConfig config ( locateLocal( "config","ksyncprofilesrc" ) ); | 571 | KConfig config ( locateLocal( "config","ksyncprofilesrc" ) ); |
567 | QStringList syncProfileNames = mSyncProfileNames; | 572 | QStringList syncProfileNames = mSyncProfileNames; |
@@ -671,257 +676,257 @@ int KSyncManager::ringSync() | |||
671 | syncRemote( temp, false ); | 676 | syncRemote( temp, false ); |
672 | 677 | ||
673 | } | 678 | } |
674 | } | 679 | } |
675 | timer.start(); | 680 | timer.start(); |
676 | mParent->topLevelWidget()->setCaption(i18n("Multiple sync in progress ... please wait!") ); | 681 | mParent->topLevelWidget()->setCaption(i18n("Multiple sync in progress ... please wait!") ); |
677 | while ( timer.elapsed () < 2000 ) { | 682 | while ( timer.elapsed () < 2000 ) { |
678 | qApp->processEvents(); | 683 | qApp->processEvents(); |
679 | #ifndef _WIN32_ | 684 | #ifndef _WIN32_ |
680 | sleep (1); | 685 | sleep (1); |
681 | #endif | 686 | #endif |
682 | } | 687 | } |
683 | 688 | ||
684 | } | 689 | } |
685 | 690 | ||
686 | } | 691 | } |
687 | delete temp; | 692 | delete temp; |
688 | return syncedProfiles; | 693 | return syncedProfiles; |
689 | } | 694 | } |
690 | 695 | ||
691 | void KSyncManager::syncRemote( KSyncProfile* prof, bool ask) | 696 | void KSyncManager::syncRemote( KSyncProfile* prof, bool ask) |
692 | { | 697 | { |
693 | QString question; | 698 | QString question; |
694 | if ( ask ) { | 699 | if ( ask ) { |
695 | question = i18n("Do you really want\nto remote sync\nwith profile \n")+ prof->getName()+" ?\n"; | 700 | question = i18n("Do you really want\nto remote sync\nwith profile \n")+ prof->getName()+" ?\n"; |
696 | if ( QMessageBox::information( mParent, i18n("Sync"), | 701 | if ( QMessageBox::information( mParent, i18n("Sync"), |
697 | question, | 702 | question, |
698 | i18n("Yes"), i18n("No"), | 703 | i18n("Yes"), i18n("No"), |
699 | 0, 0 ) != 0 ) | 704 | 0, 0 ) != 0 ) |
700 | return; | 705 | return; |
701 | } | 706 | } |
702 | 707 | ||
703 | QString preCommand; | 708 | QString preCommand; |
704 | QString localTempFile; | 709 | QString localTempFile; |
705 | QString postCommand; | 710 | QString postCommand; |
706 | 711 | ||
707 | switch(mTargetApp) | 712 | switch(mTargetApp) |
708 | { | 713 | { |
709 | case (KAPI): | 714 | case (KAPI): |
710 | preCommand = prof->getPreSyncCommandAB(); | 715 | preCommand = prof->getPreSyncCommandAB(); |
711 | postCommand = prof->getPostSyncCommandAB(); | 716 | postCommand = prof->getPostSyncCommandAB(); |
712 | localTempFile = prof->getLocalTempFileAB(); | 717 | localTempFile = prof->getLocalTempFileAB(); |
713 | break; | 718 | break; |
714 | case (KOPI): | 719 | case (KOPI): |
715 | preCommand = prof->getPreSyncCommand(); | 720 | preCommand = prof->getPreSyncCommand(); |
716 | postCommand = prof->getPostSyncCommand(); | 721 | postCommand = prof->getPostSyncCommand(); |
717 | localTempFile = prof->getLocalTempFile(); | 722 | localTempFile = prof->getLocalTempFile(); |
718 | break; | 723 | break; |
719 | case (PWMPI): | 724 | case (PWMPI): |
720 | preCommand = prof->getPreSyncCommandPWM(); | 725 | preCommand = prof->getPreSyncCommandPWM(); |
721 | postCommand = prof->getPostSyncCommandPWM(); | 726 | postCommand = prof->getPostSyncCommandPWM(); |
722 | localTempFile = prof->getLocalTempFilePWM(); | 727 | localTempFile = prof->getLocalTempFilePWM(); |
723 | break; | 728 | break; |
724 | default: | 729 | default: |
725 | qDebug("KSM::syncRemote: invalid apptype selected"); | 730 | qDebug("KSM::syncRemote: invalid apptype selected"); |
726 | break; | 731 | break; |
727 | } | 732 | } |
728 | 733 | ||
729 | 734 | ||
730 | int fi; | 735 | int fi; |
731 | if ( (fi = preCommand.find("$PWD$")) > 0 ) { | 736 | if ( (fi = preCommand.find("$PWD$")) > 0 ) { |
732 | QString pwd = getPassword(); | 737 | QString pwd = getPassword(); |
733 | preCommand = preCommand.left( fi )+ pwd + preCommand.mid( fi+5 ); | 738 | preCommand = preCommand.left( fi )+ pwd + preCommand.mid( fi+5 ); |
734 | 739 | ||
735 | } | 740 | } |
736 | int maxlen = 30; | 741 | int maxlen = 30; |
737 | if ( QApplication::desktop()->width() > 320 ) | 742 | if ( QApplication::desktop()->width() > 320 ) |
738 | maxlen += 25; | 743 | maxlen += 25; |
739 | mParent->topLevelWidget()->setCaption ( i18n( "Copy remote file to local machine..." ) ); | 744 | mParent->topLevelWidget()->setCaption ( i18n( "Copy remote file to local machine..." ) ); |
740 | int fileSize = 0; | 745 | int fileSize = 0; |
741 | int result = system ( preCommand ); | 746 | int result = system ( preCommand ); |
742 | // 0 : okay | 747 | // 0 : okay |
743 | // 256: no such file or dir | 748 | // 256: no such file or dir |
744 | // | 749 | // |
745 | qDebug("KSM::Sync: Remote copy result(0 = okay): %d ",result ); | 750 | qDebug("KSM::Sync: Remote copy result(0 = okay): %d ",result ); |
746 | if ( result != 0 ) { | 751 | if ( result != 0 ) { |
747 | unsigned int len = maxlen; | 752 | unsigned int len = maxlen; |
748 | while ( len < preCommand.length() ) { | 753 | while ( len < preCommand.length() ) { |
749 | preCommand.insert( len , "\n" ); | 754 | preCommand.insert( len , "\n" ); |
750 | len += maxlen +2; | 755 | len += maxlen +2; |
751 | } | 756 | } |
752 | 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) ; | 757 | 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) ; |
753 | QMessageBox::information( mParent, i18n("Sync - ERROR"), | 758 | QMessageBox::information( mParent, i18n("Sync - ERROR"), |
754 | question, | 759 | question, |
755 | i18n("Okay!")) ; | 760 | i18n("Okay!")) ; |
756 | mParent->topLevelWidget()->setCaption ("KDE-Pim"); | 761 | mParent->topLevelWidget()->setCaption ("KDE-Pim"); |
757 | return; | 762 | return; |
758 | } | 763 | } |
759 | mParent->topLevelWidget()->setCaption ( i18n( "Copying succeed." ) ); | 764 | mParent->topLevelWidget()->setCaption ( i18n( "Copying succeed." ) ); |
760 | //qDebug(" file **%s** ",prof->getLocalTempFile().latin1() ); | 765 | //qDebug(" file **%s** ",prof->getLocalTempFile().latin1() ); |
761 | 766 | ||
762 | if ( syncWithFile( localTempFile, true ) ) { | 767 | if ( syncWithFile( localTempFile, true ) ) { |
763 | 768 | ||
764 | if ( mWriteBackFile ) { | 769 | if ( mWriteBackFile ) { |
765 | int fi; | 770 | int fi; |
766 | if ( (fi = postCommand.find("$PWD$")) > 0 ) { | 771 | if ( (fi = postCommand.find("$PWD$")) > 0 ) { |
767 | QString pwd = getPassword(); | 772 | QString pwd = getPassword(); |
768 | postCommand = postCommand.left( fi )+ pwd + postCommand.mid( fi+5 ); | 773 | postCommand = postCommand.left( fi )+ pwd + postCommand.mid( fi+5 ); |
769 | 774 | ||
770 | } | 775 | } |
771 | mParent->topLevelWidget()->setCaption ( i18n( "Writing back file ..." ) ); | 776 | mParent->topLevelWidget()->setCaption ( i18n( "Writing back file ..." ) ); |
772 | result = system ( postCommand ); | 777 | result = system ( postCommand ); |
773 | qDebug("KSM::Sync:Writing back file result: %d ", result); | 778 | qDebug("KSM::Sync:Writing back file result: %d ", result); |
774 | if ( result != 0 ) { | 779 | if ( result != 0 ) { |
775 | mParent->topLevelWidget()->setCaption ( i18n( "Writing back file result: " )+QString::number( result ) ); | 780 | mParent->topLevelWidget()->setCaption ( i18n( "Writing back file result: " )+QString::number( result ) ); |
776 | return; | 781 | return; |
777 | } else { | 782 | } else { |
778 | mParent->topLevelWidget()->setCaption ( i18n( "Syncronization sucessfully completed" ) ); | 783 | mParent->topLevelWidget()->setCaption ( i18n( "Syncronization sucessfully completed" ) ); |
779 | } | 784 | } |
780 | } | 785 | } |
781 | } | 786 | } |
782 | return; | 787 | return; |
783 | } | 788 | } |
784 | bool KSyncManager::edit_pisync_options() | 789 | bool KSyncManager::edit_pisync_options() |
785 | { | 790 | { |
786 | QDialog dia( mParent, "dia", true ); | 791 | QDialog dia( mParent, "dia", true ); |
787 | dia.setCaption( i18n("Pi-Sync options for device: " ) +mCurrentSyncDevice ); | 792 | dia.setCaption( i18n("Pi-Sync options for device: " ) +mCurrentSyncDevice ); |
788 | QVBoxLayout lay ( &dia ); | 793 | QVBoxLayout lay ( &dia ); |
789 | lay.setSpacing( 5 ); | 794 | lay.setSpacing( 5 ); |
790 | lay.setMargin( 3 ); | 795 | lay.setMargin( 3 ); |
791 | QLabel lab1 ( i18n("Password for remote access:"), &dia); | 796 | QLabel lab1 ( i18n("Password for remote access:"), &dia); |
792 | lay.addWidget( &lab1 ); | 797 | lay.addWidget( &lab1 ); |
793 | QLineEdit le1 (&dia ); | 798 | QLineEdit le1 (&dia ); |
794 | lay.addWidget( &le1 ); | 799 | lay.addWidget( &le1 ); |
795 | QLabel lab2 ( i18n("Remote IP address:"), &dia); | 800 | QLabel lab2 ( i18n("Remote IP address:"), &dia); |
796 | lay.addWidget( &lab2 ); | 801 | lay.addWidget( &lab2 ); |
797 | QLineEdit le2 (&dia ); | 802 | QLineEdit le2 (&dia ); |
798 | lay.addWidget( &le2 ); | 803 | lay.addWidget( &le2 ); |
799 | QLabel lab3 ( i18n("Remote port number:"), &dia); | 804 | QLabel lab3 ( i18n("Remote port number:\n(May be: 1 - 65535)"), &dia); |
800 | lay.addWidget( &lab3 ); | 805 | lay.addWidget( &lab3 ); |
801 | QLineEdit le3 (&dia ); | 806 | QLineEdit le3 (&dia ); |
802 | lay.addWidget( &le3 ); | 807 | lay.addWidget( &le3 ); |
803 | QPushButton pb ( "OK", &dia); | 808 | QPushButton pb ( "OK", &dia); |
804 | lay.addWidget( &pb ); | 809 | lay.addWidget( &pb ); |
805 | connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) ); | 810 | connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) ); |
806 | le1.setText( mPassWordPiSync ); | 811 | le1.setText( mPassWordPiSync ); |
807 | le2.setText( mActiveSyncIP ); | 812 | le2.setText( mActiveSyncIP ); |
808 | le3.setText( mActiveSyncPort ); | 813 | le3.setText( mActiveSyncPort ); |
809 | if ( dia.exec() ) { | 814 | if ( dia.exec() ) { |
810 | mPassWordPiSync = le1.text(); | 815 | mPassWordPiSync = le1.text(); |
811 | mActiveSyncPort = le3.text(); | 816 | mActiveSyncPort = le3.text(); |
812 | mActiveSyncIP = le2.text(); | 817 | mActiveSyncIP = le2.text(); |
813 | return true; | 818 | return true; |
814 | } | 819 | } |
815 | return false; | 820 | return false; |
816 | } | 821 | } |
817 | bool KSyncManager::edit_sync_options() | 822 | bool KSyncManager::edit_sync_options() |
818 | { | 823 | { |
819 | 824 | ||
820 | QDialog dia( mParent, "dia", true ); | 825 | QDialog dia( mParent, "dia", true ); |
821 | dia.setCaption( i18n("Device: " ) +mCurrentSyncDevice ); | 826 | dia.setCaption( i18n("Device: " ) +mCurrentSyncDevice ); |
822 | QButtonGroup gr ( 1, Qt::Horizontal, i18n("Sync preferences"), &dia); | 827 | QButtonGroup gr ( 1, Qt::Horizontal, i18n("Sync preferences"), &dia); |
823 | QVBoxLayout lay ( &dia ); | 828 | QVBoxLayout lay ( &dia ); |
824 | lay.setSpacing( 2 ); | 829 | lay.setSpacing( 2 ); |
825 | lay.setMargin( 3 ); | 830 | lay.setMargin( 3 ); |
826 | lay.addWidget(&gr); | 831 | lay.addWidget(&gr); |
827 | QRadioButton loc ( i18n("Take local entry on conflict"), &gr ); | 832 | QRadioButton loc ( i18n("Take local entry on conflict"), &gr ); |
828 | QRadioButton rem ( i18n("Take remote entry on conflict"), &gr ); | 833 | QRadioButton rem ( i18n("Take remote entry on conflict"), &gr ); |
829 | QRadioButton newest( i18n("Take newest entry on conflict"), &gr ); | 834 | QRadioButton newest( i18n("Take newest entry on conflict"), &gr ); |
830 | QRadioButton ask( i18n("Ask for every entry on conflict"), &gr ); | 835 | QRadioButton ask( i18n("Ask for every entry on conflict"), &gr ); |
831 | QRadioButton f_loc( i18n("Force: Take local entry always"), &gr ); | 836 | QRadioButton f_loc( i18n("Force: Take local entry always"), &gr ); |
832 | QRadioButton f_rem( i18n("Force: Take remote entry always"), &gr ); | 837 | QRadioButton f_rem( i18n("Force: Take remote entry always"), &gr ); |
833 | //QRadioButton both( i18n("Take both on conflict"), &gr ); | 838 | //QRadioButton both( i18n("Take both on conflict"), &gr ); |
834 | QPushButton pb ( "OK", &dia); | 839 | QPushButton pb ( "OK", &dia); |
835 | lay.addWidget( &pb ); | 840 | lay.addWidget( &pb ); |
836 | connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) ); | 841 | connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) ); |
837 | switch ( mSyncAlgoPrefs ) { | 842 | switch ( mSyncAlgoPrefs ) { |
838 | case 0: | 843 | case 0: |
839 | loc.setChecked( true); | 844 | loc.setChecked( true); |
840 | break; | 845 | break; |
841 | case 1: | 846 | case 1: |
842 | rem.setChecked( true ); | 847 | rem.setChecked( true ); |
843 | break; | 848 | break; |
844 | case 2: | 849 | case 2: |
845 | newest.setChecked( true); | 850 | newest.setChecked( true); |
846 | break; | 851 | break; |
847 | case 3: | 852 | case 3: |
848 | ask.setChecked( true); | 853 | ask.setChecked( true); |
849 | break; | 854 | break; |
850 | case 4: | 855 | case 4: |
851 | f_loc.setChecked( true); | 856 | f_loc.setChecked( true); |
852 | break; | 857 | break; |
853 | case 5: | 858 | case 5: |
854 | f_rem.setChecked( true); | 859 | f_rem.setChecked( true); |
855 | break; | 860 | break; |
856 | case 6: | 861 | case 6: |
857 | // both.setChecked( true); | 862 | // both.setChecked( true); |
858 | break; | 863 | break; |
859 | default: | 864 | default: |
860 | break; | 865 | break; |
861 | } | 866 | } |
862 | if ( dia.exec() ) { | 867 | if ( dia.exec() ) { |
863 | mSyncAlgoPrefs = rem.isChecked()*1+newest.isChecked()*2+ ask.isChecked()*3+ f_loc.isChecked()*4+ f_rem.isChecked()*5;//+ both.isChecked()*6 ; | 868 | mSyncAlgoPrefs = rem.isChecked()*1+newest.isChecked()*2+ ask.isChecked()*3+ f_loc.isChecked()*4+ f_rem.isChecked()*5;//+ both.isChecked()*6 ; |
864 | return true; | 869 | return true; |
865 | } | 870 | } |
866 | return false; | 871 | return false; |
867 | } | 872 | } |
868 | 873 | ||
869 | QString KSyncManager::getPassword( ) | 874 | QString KSyncManager::getPassword( ) |
870 | { | 875 | { |
871 | QString retfile = ""; | 876 | QString retfile = ""; |
872 | QDialog dia ( mParent, "input-dialog", true ); | 877 | QDialog dia ( mParent, "input-dialog", true ); |
873 | QLineEdit lab ( &dia ); | 878 | QLineEdit lab ( &dia ); |
874 | lab.setEchoMode( QLineEdit::Password ); | 879 | lab.setEchoMode( QLineEdit::Password ); |
875 | QVBoxLayout lay( &dia ); | 880 | QVBoxLayout lay( &dia ); |
876 | lay.setMargin(7); | 881 | lay.setMargin(7); |
877 | lay.setSpacing(7); | 882 | lay.setSpacing(7); |
878 | lay.addWidget( &lab); | 883 | lay.addWidget( &lab); |
879 | dia.setFixedSize( 230,50 ); | 884 | dia.setFixedSize( 230,50 ); |
880 | dia.setCaption( i18n("Enter password") ); | 885 | dia.setCaption( i18n("Enter password") ); |
881 | QPushButton pb ( "OK", &dia); | 886 | QPushButton pb ( "OK", &dia); |
882 | lay.addWidget( &pb ); | 887 | lay.addWidget( &pb ); |
883 | connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) ); | 888 | connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) ); |
884 | dia.show(); | 889 | dia.show(); |
885 | int res = dia.exec(); | 890 | int res = dia.exec(); |
886 | if ( res ) | 891 | if ( res ) |
887 | retfile = lab.text(); | 892 | retfile = lab.text(); |
888 | dia.hide(); | 893 | dia.hide(); |
889 | qApp->processEvents(); | 894 | qApp->processEvents(); |
890 | return retfile; | 895 | return retfile; |
891 | 896 | ||
892 | } | 897 | } |
893 | 898 | ||
894 | 899 | ||
895 | void KSyncManager::confSync() | 900 | void KSyncManager::confSync() |
896 | { | 901 | { |
897 | static KSyncPrefsDialog* sp = 0; | 902 | static KSyncPrefsDialog* sp = 0; |
898 | if ( ! sp ) { | 903 | if ( ! sp ) { |
899 | sp = new KSyncPrefsDialog( mParent, "syncprefs", true ); | 904 | sp = new KSyncPrefsDialog( mParent, "syncprefs", true ); |
900 | } | 905 | } |
901 | sp->usrReadConfig(); | 906 | sp->usrReadConfig(); |
902 | #ifndef DESKTOP_VERSION | 907 | #ifndef DESKTOP_VERSION |
903 | sp->showMaximized(); | 908 | sp->showMaximized(); |
904 | #else | 909 | #else |
905 | sp->show(); | 910 | sp->show(); |
906 | #endif | 911 | #endif |
907 | sp->exec(); | 912 | sp->exec(); |
908 | QStringList oldSyncProfileNames = mSyncProfileNames; | 913 | QStringList oldSyncProfileNames = mSyncProfileNames; |
909 | mSyncProfileNames = sp->getSyncProfileNames(); | 914 | mSyncProfileNames = sp->getSyncProfileNames(); |
910 | mLocalMachineName = sp->getLocalMachineName (); | 915 | mLocalMachineName = sp->getLocalMachineName (); |
911 | int ii; | 916 | int ii; |
912 | for ( ii = 0; ii < oldSyncProfileNames.count(); ++ii ) { | 917 | for ( ii = 0; ii < oldSyncProfileNames.count(); ++ii ) { |
913 | if ( ! mSyncProfileNames.contains( oldSyncProfileNames[ii] ) ) | 918 | if ( ! mSyncProfileNames.contains( oldSyncProfileNames[ii] ) ) |
914 | mImplementation->removeSyncInfo( oldSyncProfileNames[ii] ); | 919 | mImplementation->removeSyncInfo( oldSyncProfileNames[ii] ); |
915 | } | 920 | } |
916 | QTimer::singleShot ( 1, this, SLOT ( fillSyncMenu() ) ); | 921 | QTimer::singleShot ( 1, this, SLOT ( fillSyncMenu() ) ); |
917 | } | 922 | } |
918 | void KSyncManager::syncKDE() | 923 | void KSyncManager::syncKDE() |
919 | { | 924 | { |
920 | mSyncWithDesktop = true; | 925 | mSyncWithDesktop = true; |
921 | emit save(); | 926 | emit save(); |
922 | switch(mTargetApp) | 927 | switch(mTargetApp) |
923 | { | 928 | { |
924 | case (KAPI): | 929 | case (KAPI): |
925 | { | 930 | { |
926 | #ifdef DESKTOP_VERSION | 931 | #ifdef DESKTOP_VERSION |
927 | QString command = "kdeabdump33"; | 932 | QString command = "kdeabdump33"; |
@@ -1063,593 +1068,647 @@ void KSyncManager::showProgressBar(int percentage, QString caption, int total) | |||
1063 | bar->setTotalSteps ( total ) ; | 1068 | bar->setTotalSteps ( total ) ; |
1064 | bar->show(); | 1069 | bar->show(); |
1065 | } | 1070 | } |
1066 | bar->raise(); | 1071 | bar->raise(); |
1067 | bar->setProgress( percentage ); | 1072 | bar->setProgress( percentage ); |
1068 | qApp->processEvents(); | 1073 | qApp->processEvents(); |
1069 | } | 1074 | } |
1070 | 1075 | ||
1071 | void KSyncManager::hideProgressBar() | 1076 | void KSyncManager::hideProgressBar() |
1072 | { | 1077 | { |
1073 | bar->hide(); | 1078 | bar->hide(); |
1074 | qApp->processEvents(); | 1079 | qApp->processEvents(); |
1075 | } | 1080 | } |
1076 | 1081 | ||
1077 | bool KSyncManager::isProgressBarCanceled() | 1082 | bool KSyncManager::isProgressBarCanceled() |
1078 | { | 1083 | { |
1079 | return !bar->isVisible(); | 1084 | return !bar->isVisible(); |
1080 | } | 1085 | } |
1081 | 1086 | ||
1082 | QString KSyncManager::syncFileName() | 1087 | QString KSyncManager::syncFileName() |
1083 | { | 1088 | { |
1084 | 1089 | ||
1085 | QString fn = "tempfile"; | 1090 | QString fn = "tempfile"; |
1086 | switch(mTargetApp) | 1091 | switch(mTargetApp) |
1087 | { | 1092 | { |
1088 | case (KAPI): | 1093 | case (KAPI): |
1089 | fn = "tempsyncab.vcf"; | 1094 | fn = "tempsyncab.vcf"; |
1090 | break; | 1095 | break; |
1091 | case (KOPI): | 1096 | case (KOPI): |
1092 | fn = "tempsynccal.ics"; | 1097 | fn = "tempsynccal.ics"; |
1093 | break; | 1098 | break; |
1094 | case (PWMPI): | 1099 | case (PWMPI): |
1095 | fn = "tempsyncpw.pwm"; | 1100 | fn = "tempsyncpw.pwm"; |
1096 | break; | 1101 | break; |
1097 | default: | 1102 | default: |
1098 | break; | 1103 | break; |
1099 | } | 1104 | } |
1100 | #ifdef _WIN32_ | 1105 | #ifdef _WIN32_ |
1101 | return locateLocal( "tmp", fn ); | 1106 | return locateLocal( "tmp", fn ); |
1102 | #else | 1107 | #else |
1103 | return (QString( "/tmp/" )+ fn ); | 1108 | return (QString( "/tmp/" )+ fn ); |
1104 | #endif | 1109 | #endif |
1105 | } | 1110 | } |
1106 | 1111 | ||
1107 | void KSyncManager::syncPi() | 1112 | void KSyncManager::syncPi() |
1108 | { | 1113 | { |
1109 | mIsKapiFile = true; | 1114 | mIsKapiFile = true; |
1110 | mPisyncFinished = false; | 1115 | mPisyncFinished = false; |
1111 | qApp->processEvents(); | 1116 | qApp->processEvents(); |
1112 | if ( mAskForPreferences ) | 1117 | if ( mAskForPreferences ) |
1113 | if ( !edit_pisync_options()) { | 1118 | if ( !edit_pisync_options()) { |
1114 | mParent->topLevelWidget()->setCaption( i18n("Syncing aborted. Nothing synced.") ); | 1119 | mParent->topLevelWidget()->setCaption( i18n("Syncing aborted. Nothing synced.") ); |
1115 | mPisyncFinished = true; | 1120 | mPisyncFinished = true; |
1116 | return; | 1121 | return; |
1117 | } | 1122 | } |
1118 | bool ok; | 1123 | bool ok; |
1119 | Q_UINT16 port = mActiveSyncPort.toUInt(&ok); | 1124 | Q_UINT16 port = mActiveSyncPort.toUInt(&ok); |
1120 | if ( ! ok ) { | 1125 | if ( ! ok ) { |
1121 | mParent->topLevelWidget()->setCaption( i18n("Sorry, no valid port.Syncing cancelled.") ); | 1126 | mParent->topLevelWidget()->setCaption( i18n("Sorry, no valid port.Syncing cancelled.") ); |
1122 | mPisyncFinished = true; | 1127 | mPisyncFinished = true; |
1123 | return; | 1128 | return; |
1124 | } | 1129 | } |
1125 | KCommandSocket* commandSocket = new KCommandSocket( mPassWordPiSync, port, mActiveSyncIP, this, mParent->topLevelWidget() ); | 1130 | KCommandSocket* commandSocket = new KCommandSocket( mPassWordPiSync, port, mActiveSyncIP, this, mParent->topLevelWidget() ); |
1126 | connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int )), this, SLOT(deleteCommandSocket(KCommandSocket*, int)) ); | 1131 | connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int )), this, SLOT(deleteCommandSocket(KCommandSocket*, int)) ); |
1127 | commandSocket->readFile( syncFileName() ); | 1132 | commandSocket->readFile( syncFileName() ); |
1128 | } | 1133 | } |
1129 | 1134 | ||
1130 | void KSyncManager::deleteCommandSocket(KCommandSocket*s, int state) | 1135 | void KSyncManager::deleteCommandSocket(KCommandSocket*s, int state) |
1131 | { | 1136 | { |
1132 | //enum { success, errorW, errorR, quiet }; | 1137 | //enum { success, errorW, errorR, quiet }; |
1133 | 1138 | ||
1134 | 1139 | ||
1135 | 1140 | ||
1136 | if ( state == KCommandSocket::errorR ||state == KCommandSocket::errorTO ||state == KCommandSocket::errorPW || | 1141 | if ( state == KCommandSocket::errorR ||state == KCommandSocket::errorTO ||state == KCommandSocket::errorPW || |
1137 | state == KCommandSocket::errorCA ||state == KCommandSocket::errorFI ||state == KCommandSocket::errorUN||state == KCommandSocket::errorED ) { | 1142 | state == KCommandSocket::errorCA ||state == KCommandSocket::errorFI ||state == KCommandSocket::errorUN||state == KCommandSocket::errorED ) { |
1138 | if ( state == KCommandSocket::errorPW ) | 1143 | if ( state == KCommandSocket::errorPW ) |
1139 | mParent->topLevelWidget()->setCaption( i18n("Wrong password: Receiving remote file failed.") ); | 1144 | mParent->topLevelWidget()->setCaption( i18n("Wrong password: Receiving remote file failed.") ); |
1140 | else if ( state == KCommandSocket::errorR ||state == KCommandSocket::errorTO ) | 1145 | else if ( state == KCommandSocket::errorR ||state == KCommandSocket::errorTO ) |
1141 | mParent->topLevelWidget()->setCaption( i18n("ERROR: Receiving remote file failed.") ); | 1146 | mParent->topLevelWidget()->setCaption( i18n("ERROR: Receiving remote file failed.") ); |
1142 | else if ( state == KCommandSocket::errorCA ) | 1147 | else if ( state == KCommandSocket::errorCA ) |
1143 | mParent->topLevelWidget()->setCaption( i18n("Sync cancelled from remote.") ); | 1148 | mParent->topLevelWidget()->setCaption( i18n("Sync cancelled from remote.") ); |
1144 | else if ( state == KCommandSocket::errorFI ) | 1149 | else if ( state == KCommandSocket::errorFI ) |
1145 | mParent->topLevelWidget()->setCaption( i18n("File error on remote.") ); | 1150 | mParent->topLevelWidget()->setCaption( i18n("File error on remote.") ); |
1146 | else if ( state == KCommandSocket::errorED ) | 1151 | else if ( state == KCommandSocket::errorED ) |
1147 | mParent->topLevelWidget()->setCaption( i18n("Please close error dialog on remote.") ); | 1152 | mParent->topLevelWidget()->setCaption( i18n("Please close error dialog on remote.") ); |
1148 | else if ( state == KCommandSocket::errorUN ) | 1153 | else if ( state == KCommandSocket::errorUN ) |
1149 | mParent->topLevelWidget()->setCaption( i18n("Unknown error on remote.") ); | 1154 | mParent->topLevelWidget()->setCaption( i18n("Unknown error on remote.") ); |
1150 | delete s; | 1155 | delete s; |
1151 | if ( state == KCommandSocket::errorR ) { | 1156 | if ( state == KCommandSocket::errorR ) { |
1152 | KCommandSocket* commandSocket = new KCommandSocket( mPassWordPiSync, mActiveSyncPort.toUInt(), mActiveSyncIP, this, mParent->topLevelWidget()); | 1157 | KCommandSocket* commandSocket = new KCommandSocket( mPassWordPiSync, mActiveSyncPort.toUInt(), mActiveSyncIP, this, mParent->topLevelWidget()); |
1153 | connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int)), this, SLOT(deleteCommandSocket(KCommandSocket*, int )) ); | 1158 | connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int)), this, SLOT(deleteCommandSocket(KCommandSocket*, int )) ); |
1154 | commandSocket->sendStop(); | 1159 | commandSocket->sendStop(); |
1155 | } | 1160 | } |
1156 | mPisyncFinished = true; | 1161 | mPisyncFinished = true; |
1157 | return; | 1162 | return; |
1158 | 1163 | ||
1159 | } else if ( state == KCommandSocket::errorW ) { | 1164 | } else if ( state == KCommandSocket::errorW ) { |
1160 | mParent->topLevelWidget()->setCaption( i18n("ERROR:Writing back file failed.") ); | 1165 | mParent->topLevelWidget()->setCaption( i18n("ERROR:Writing back file failed.") ); |
1161 | mPisyncFinished = true; | 1166 | mPisyncFinished = true; |
1162 | 1167 | ||
1163 | } else if ( state == KCommandSocket::successR ) { | 1168 | } else if ( state == KCommandSocket::successR ) { |
1164 | QTimer::singleShot( 1, this , SLOT ( readFileFromSocket())); | 1169 | QTimer::singleShot( 1, this , SLOT ( readFileFromSocket())); |
1165 | 1170 | ||
1166 | } else if ( state == KCommandSocket::successW ) { | 1171 | } else if ( state == KCommandSocket::successW ) { |
1167 | mParent->topLevelWidget()->setCaption( i18n("Pi-Sync successful!") ); | 1172 | mParent->topLevelWidget()->setCaption( i18n("Pi-Sync successful!") ); |
1168 | mPisyncFinished = true; | 1173 | mPisyncFinished = true; |
1169 | } else if ( state == KCommandSocket::quiet ){ | 1174 | } else if ( state == KCommandSocket::quiet ){ |
1170 | qDebug("KSS: quiet "); | 1175 | qDebug("KSS: quiet "); |
1171 | mPisyncFinished = true; | 1176 | mPisyncFinished = true; |
1172 | } else { | 1177 | } else { |
1173 | qDebug("KSS: Error: unknown state: %d ", state); | 1178 | qDebug("KSS: Error: unknown state: %d ", state); |
1174 | mPisyncFinished = true; | 1179 | mPisyncFinished = true; |
1175 | } | 1180 | } |
1176 | 1181 | ||
1177 | delete s; | 1182 | delete s; |
1178 | } | 1183 | } |
1179 | 1184 | ||
1180 | void KSyncManager::readFileFromSocket() | 1185 | void KSyncManager::readFileFromSocket() |
1181 | { | 1186 | { |
1182 | QString fileName = syncFileName(); | 1187 | QString fileName = syncFileName(); |
1183 | bool syncOK = true; | 1188 | bool syncOK = true; |
1184 | mParent->topLevelWidget()->setCaption( i18n("Remote file saved to temp file.") ); | 1189 | mParent->topLevelWidget()->setCaption( i18n("Remote file saved to temp file.") ); |
1185 | if ( ! syncWithFile( fileName , true ) ) { | 1190 | if ( ! syncWithFile( fileName , true ) ) { |
1186 | mParent->topLevelWidget()->setCaption( i18n("Syncing failed.") ); | 1191 | mParent->topLevelWidget()->setCaption( i18n("Syncing failed.") ); |
1187 | syncOK = false; | 1192 | syncOK = false; |
1188 | } | 1193 | } |
1189 | KCommandSocket* commandSocket = new KCommandSocket( mPassWordPiSync, mActiveSyncPort.toUInt(), mActiveSyncIP, this, mParent->topLevelWidget() ); | 1194 | KCommandSocket* commandSocket = new KCommandSocket( mPassWordPiSync, mActiveSyncPort.toUInt(), mActiveSyncIP, this, mParent->topLevelWidget() ); |
1190 | connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int)), this, SLOT(deleteCommandSocket(KCommandSocket*, int )) ); | 1195 | connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int)), this, SLOT(deleteCommandSocket(KCommandSocket*, int )) ); |
1191 | if ( mWriteBackFile && syncOK ) | 1196 | if ( mWriteBackFile && syncOK ) { |
1197 | mParent->topLevelWidget()->setCaption( i18n("Sending back file ...") ); | ||
1192 | commandSocket->writeFile( fileName ); | 1198 | commandSocket->writeFile( fileName ); |
1199 | } | ||
1193 | else { | 1200 | else { |
1194 | commandSocket->sendStop(); | 1201 | commandSocket->sendStop(); |
1195 | if ( syncOK ) | 1202 | if ( syncOK ) |
1196 | mParent->topLevelWidget()->setCaption( i18n("Pi-Sync succesful!") ); | 1203 | mParent->topLevelWidget()->setCaption( i18n("Pi-Sync succesful!") ); |
1197 | mPisyncFinished = true; | 1204 | mPisyncFinished = true; |
1198 | } | 1205 | } |
1199 | } | 1206 | } |
1200 | 1207 | ||
1201 | KServerSocket:: KServerSocket ( QString pw, Q_UINT16 port, int backlog, QObject * parent, const char * name ) : QServerSocket( port, backlog, parent, name ) | 1208 | KServerSocket:: KServerSocket ( QString pw, Q_UINT16 port, int backlog, QObject * parent, const char * name ) : QServerSocket( port, backlog, parent, name ) |
1202 | { | 1209 | { |
1203 | mPassWord = pw; | 1210 | mPassWord = pw; |
1204 | mSocket = 0; | 1211 | mSocket = 0; |
1205 | mSyncActionDialog = 0; | 1212 | mSyncActionDialog = 0; |
1206 | blockRC = false; | 1213 | blockRC = false; |
1207 | mErrorMessage = 0; | 1214 | mErrorMessage = 0; |
1208 | } | 1215 | } |
1209 | 1216 | ||
1210 | void KServerSocket::newConnection ( int socket ) | 1217 | void KServerSocket::newConnection ( int socket ) |
1211 | { | 1218 | { |
1212 | // qDebug("KServerSocket:New connection %d ", socket); | 1219 | // qDebug("KServerSocket:New connection %d ", socket); |
1213 | if ( mSocket ) { | 1220 | if ( mSocket ) { |
1214 | qDebug("KSS::newConnection Socket deleted! "); | 1221 | qDebug("KSS::newConnection Socket deleted! "); |
1215 | delete mSocket; | 1222 | delete mSocket; |
1216 | mSocket = 0; | 1223 | mSocket = 0; |
1217 | } | 1224 | } |
1218 | mSocket = new QSocket( this ); | 1225 | mSocket = new QSocket( this ); |
1219 | connect( mSocket , SIGNAL(readyRead()), this, SLOT(readClient()) ); | 1226 | connect( mSocket , SIGNAL(readyRead()), this, SLOT(readClient()) ); |
1220 | connect( mSocket , SIGNAL(delayedCloseFinished()), this, SLOT(discardClient()) ); | 1227 | connect( mSocket , SIGNAL(delayedCloseFinished()), this, SLOT(discardClient()) ); |
1221 | mSocket->setSocket( socket ); | 1228 | mSocket->setSocket( socket ); |
1222 | } | 1229 | } |
1223 | 1230 | ||
1224 | void KServerSocket::discardClient() | 1231 | void KServerSocket::discardClient() |
1225 | { | 1232 | { |
1226 | QTimer::singleShot( 10, this , SLOT ( deleteSocket())); | 1233 | QTimer::singleShot( 10, this , SLOT ( deleteSocket())); |
1227 | } | 1234 | } |
1228 | void KServerSocket::deleteSocket() | 1235 | void KServerSocket::deleteSocket() |
1229 | { | 1236 | { |
1230 | qDebug("KSS::deleteSocket"); | 1237 | qDebug("KSS::deleteSocket"); |
1231 | if ( mSocket ) { | 1238 | if ( mSocket ) { |
1232 | delete mSocket; | 1239 | delete mSocket; |
1233 | mSocket = 0; | 1240 | mSocket = 0; |
1234 | } | 1241 | } |
1235 | if ( mErrorMessage ) | 1242 | if ( mErrorMessage ) |
1236 | QTimer::singleShot( 10, this , SLOT ( displayErrorMessage())); | 1243 | QTimer::singleShot( 10, this , SLOT ( displayErrorMessage())); |
1237 | } | 1244 | } |
1238 | void KServerSocket::readClient() | 1245 | void KServerSocket::readClient() |
1239 | { | 1246 | { |
1240 | if ( blockRC ) | 1247 | if ( blockRC ) |
1241 | return; | 1248 | return; |
1242 | if ( mSocket == 0 ) { | 1249 | if ( mSocket == 0 ) { |
1243 | qDebug("ERROR::KSS::readClient(): mSocket == 0 "); | 1250 | qDebug("ERROR::KSS::readClient(): mSocket == 0 "); |
1244 | return; | 1251 | return; |
1245 | } | 1252 | } |
1246 | if ( mErrorMessage ) { | 1253 | if ( mErrorMessage ) { |
1247 | mErrorMessage = 999; | 1254 | mErrorMessage = 999; |
1248 | error_connect("ERROR_ED\r\n\r\n"); | 1255 | error_connect("ERROR_ED\r\n\r\n"); |
1249 | return; | 1256 | return; |
1250 | } | 1257 | } |
1251 | mErrorMessage = 0; | 1258 | mErrorMessage = 0; |
1252 | //qDebug("KServerSocket::readClient()"); | 1259 | //qDebug("KServerSocket::readClient()"); |
1253 | if ( mSocket->canReadLine() ) { | 1260 | if ( mSocket->canReadLine() ) { |
1254 | QString line = mSocket->readLine(); | 1261 | QString line = mSocket->readLine(); |
1255 | //qDebug("KServerSocket readline: %s ", line.latin1()); | 1262 | //qDebug("KServerSocket readline: %s ", line.latin1()); |
1256 | QStringList tokens = QStringList::split( QRegExp("[ \r\n][ \r\n]*"), line ); | 1263 | QStringList tokens = QStringList::split( QRegExp("[ \r\n][ \r\n]*"), line ); |
1257 | if ( tokens[0] == "GET" ) { | 1264 | if ( tokens[0] == "GET" ) { |
1258 | if ( tokens[1] == mPassWord ) { | 1265 | if ( tokens[1] == mPassWord ) { |
1259 | //emit sendFile( mSocket ); | 1266 | //emit sendFile( mSocket ); |
1260 | bool ok = false; | 1267 | bool ok = false; |
1261 | QDateTime dt = KGlobal::locale()->readDateTime( tokens[2], KLocale::ISODate, &ok); | 1268 | QDateTime dt = KGlobal::locale()->readDateTime( tokens[2], KLocale::ISODate, &ok); |
1262 | if ( ok ) { | 1269 | if ( ok ) { |
1263 | KSyncManager::mRequestedSyncEvent = dt; | 1270 | KSyncManager::mRequestedSyncEvent = dt; |
1264 | } | 1271 | } |
1265 | else | 1272 | else |
1266 | KSyncManager::mRequestedSyncEvent = QDateTime(); | 1273 | KSyncManager::mRequestedSyncEvent = QDateTime(); |
1267 | send_file(); | 1274 | send_file(); |
1268 | } | 1275 | } |
1269 | else { | 1276 | else { |
1270 | mErrorMessage = 1; | 1277 | mErrorMessage = 1; |
1271 | error_connect("ERROR_PW\r\n\r\n"); | 1278 | error_connect("ERROR_PW\r\n\r\n"); |
1272 | } | 1279 | } |
1273 | } | 1280 | } |
1274 | if ( tokens[0] == "PUT" ) { | 1281 | if ( tokens[0] == "PUT" ) { |
1275 | if ( tokens[1] == mPassWord ) { | 1282 | if ( tokens[1] == mPassWord ) { |
1276 | //emit getFile( mSocket ); | 1283 | //emit getFile( mSocket ); |
1277 | blockRC = true; | 1284 | blockRC = true; |
1278 | get_file(); | 1285 | get_file(); |
1279 | } | 1286 | } |
1280 | else { | 1287 | else { |
1281 | mErrorMessage = 2; | 1288 | mErrorMessage = 2; |
1282 | error_connect("ERROR_PW\r\n\r\n"); | 1289 | error_connect("ERROR_PW\r\n\r\n"); |
1283 | end_connect(); | 1290 | end_connect(); |
1284 | } | 1291 | } |
1285 | } | 1292 | } |
1286 | if ( tokens[0] == "STOP" ) { | 1293 | if ( tokens[0] == "STOP" ) { |
1287 | //emit endConnect(); | 1294 | //emit endConnect(); |
1288 | end_connect(); | 1295 | end_connect(); |
1289 | } | 1296 | } |
1290 | } | 1297 | } |
1291 | } | 1298 | } |
1292 | void KServerSocket::displayErrorMessage() | 1299 | void KServerSocket::displayErrorMessage() |
1293 | { | 1300 | { |
1294 | if ( mErrorMessage == 1 ) { | 1301 | if ( mErrorMessage == 1 ) { |
1295 | KMessageBox::error( 0, i18n("Got send file request\nwith invalid password")); | 1302 | KMessageBox::error( 0, i18n("Got send file request\nwith invalid password"), i18n("Pi-Sync Error")); |
1296 | mErrorMessage = 0; | 1303 | mErrorMessage = 0; |
1297 | } | 1304 | } |
1298 | else if ( mErrorMessage == 2 ) { | 1305 | else if ( mErrorMessage == 2 ) { |
1299 | KMessageBox::error( 0, i18n("Got receive file request\nwith invalid password")); | 1306 | KMessageBox::error( 0, i18n("Got receive file request\nwith invalid password"), i18n("Pi-Sync Error")); |
1300 | mErrorMessage = 0; | 1307 | mErrorMessage = 0; |
1301 | } | 1308 | } |
1302 | } | 1309 | } |
1303 | void KServerSocket::error_connect( QString errmess ) | 1310 | void KServerSocket::error_connect( QString errmess ) |
1304 | { | 1311 | { |
1305 | QTextStream os( mSocket ); | 1312 | QTextStream os( mSocket ); |
1306 | os.setEncoding( QTextStream::Latin1 ); | 1313 | os.setEncoding( QTextStream::Latin1 ); |
1307 | os << errmess ; | 1314 | os << errmess ; |
1308 | mSocket->close(); | 1315 | mSocket->close(); |
1309 | if ( mSocket->state() == QSocket::Idle ) { | 1316 | if ( mSocket->state() == QSocket::Idle ) { |
1310 | QTimer::singleShot( 0, this , SLOT ( discardClient())); | 1317 | QTimer::singleShot( 0, this , SLOT ( discardClient())); |
1311 | } | 1318 | } |
1312 | } | 1319 | } |
1313 | void KServerSocket::end_connect() | 1320 | void KServerSocket::end_connect() |
1314 | { | 1321 | { |
1315 | delete mSyncActionDialog; | 1322 | delete mSyncActionDialog; |
1316 | mSyncActionDialog = 0; | 1323 | mSyncActionDialog = 0; |
1317 | } | 1324 | } |
1318 | void KServerSocket::send_file() | 1325 | void KServerSocket::send_file() |
1319 | { | 1326 | { |
1320 | //qDebug("MainWindow::sendFile(QSocket* s) "); | 1327 | //qDebug("MainWindow::sendFile(QSocket* s) "); |
1321 | if ( mSyncActionDialog ) | 1328 | if ( mSyncActionDialog ) |
1322 | delete mSyncActionDialog; | 1329 | delete mSyncActionDialog; |
1323 | mSyncActionDialog = new QDialog ( 0, "input-dialog", true ); | 1330 | mSyncActionDialog = new QDialog ( 0, "input-dialog", true ); |
1324 | mSyncActionDialog->setCaption(i18n("Received sync request")); | 1331 | mSyncActionDialog->setCaption(i18n("Received sync request")); |
1325 | QLabel* label = new QLabel( i18n("Synchronizing from remote ...\n\nDo not use this application!\n\nIf syncing fails\nyou can close this dialog."), mSyncActionDialog ); | 1332 | QLabel* label = new QLabel( i18n("Synchronizing from remote ...\n\nDo not use this application!\n\nIf syncing fails\nyou can close this dialog."), mSyncActionDialog ); |
1326 | label->setAlignment ( Qt::AlignHCenter ); | 1333 | label->setAlignment ( Qt::AlignHCenter ); |
1327 | QVBoxLayout* lay = new QVBoxLayout( mSyncActionDialog ); | 1334 | QVBoxLayout* lay = new QVBoxLayout( mSyncActionDialog ); |
1328 | lay->addWidget( label); | 1335 | lay->addWidget( label); |
1329 | lay->setMargin(7); | 1336 | lay->setMargin(7); |
1330 | lay->setSpacing(7); | 1337 | lay->setSpacing(7); |
1331 | if ( KSyncManager::mRequestedSyncEvent.isValid() ) { | 1338 | if ( KSyncManager::mRequestedSyncEvent.isValid() ) { |
1332 | int secs = QDateTime::currentDateTime().secsTo( KSyncManager::mRequestedSyncEvent ); | 1339 | int secs = QDateTime::currentDateTime().secsTo( KSyncManager::mRequestedSyncEvent ); |
1333 | //secs = 333; | 1340 | //secs = 333; |
1334 | if ( secs < 0 ) | 1341 | if ( secs < 0 ) |
1335 | secs = secs * (-1); | 1342 | secs = secs * (-1); |
1336 | if ( secs > 30 ) | 1343 | if ( secs > 30 ) |
1337 | //if ( true ) | 1344 | //if ( true ) |
1338 | { | 1345 | { |
1339 | QString warning = i18n("Clock skew of\nsyncing devices\nis %1 seconds!").arg( secs ); | 1346 | QString warning = i18n("Clock skew of\nsyncing devices\nis %1 seconds!").arg( secs ); |
1340 | QLabel* label = new QLabel( warning, mSyncActionDialog ); | 1347 | QLabel* label = new QLabel( warning, mSyncActionDialog ); |
1341 | label->setAlignment ( Qt::AlignHCenter ); | 1348 | label->setAlignment ( Qt::AlignHCenter ); |
1342 | lay->addWidget( label); | 1349 | lay->addWidget( label); |
1343 | if ( secs > 180 ) | 1350 | if ( secs > 180 ) |
1344 | { | 1351 | { |
1345 | if ( secs > 300 ) { | 1352 | if ( secs > 300 ) { |
1346 | if ( KMessageBox::Cancel == KMessageBox::warningContinueCancel(0, i18n("The clocks of the syncing\ndevices have a difference\nof more than 5 minutes.\nPlease adjust your clocks.\nYou may get wrong syncing results!\nPlease confirm synchronization!"), i18n("High clock skew!"),i18n("Synchronize!"))) { | 1353 | if ( KMessageBox::Cancel == KMessageBox::warningContinueCancel(0, i18n("The clocks of the syncing\ndevices have a difference\nof more than 5 minutes.\nPlease adjust your clocks.\nYou may get wrong syncing results!\nPlease confirm synchronization!"), i18n("High clock skew!"),i18n("Synchronize!"))) { |
1347 | qDebug("KSS::Sync cancelled ,cs"); | 1354 | qDebug("KSS::Sync cancelled ,cs"); |
1348 | mErrorMessage = 0; | 1355 | mErrorMessage = 0; |
1349 | end_connect(); | 1356 | end_connect(); |
1350 | error_connect("ERROR_CA\r\n\r\n"); | 1357 | error_connect("ERROR_CA\r\n\r\n"); |
1351 | return ; | 1358 | return ; |
1352 | } | 1359 | } |
1353 | } | 1360 | } |
1354 | QFont f = label->font(); | 1361 | QFont f = label->font(); |
1355 | f.setPointSize ( f.pointSize() *2 ); | 1362 | f.setPointSize ( f.pointSize() *2 ); |
1356 | f. setBold (true ); | 1363 | f. setBold (true ); |
1357 | QLabel* label = new QLabel( warning, mSyncActionDialog ); | 1364 | QLabel* label = new QLabel( warning, mSyncActionDialog ); |
1358 | label->setFont( f ); | 1365 | label->setFont( f ); |
1359 | warning = i18n("ADJUST\nYOUR\nCLOCKS!"); | 1366 | warning = i18n("ADJUST\nYOUR\nCLOCKS!"); |
1360 | label->setText( warning ); | 1367 | label->setText( warning ); |
1361 | label->setAlignment ( Qt::AlignHCenter ); | 1368 | label->setAlignment ( Qt::AlignHCenter ); |
1362 | lay->addWidget( label); | 1369 | lay->addWidget( label); |
1363 | mSyncActionDialog->setFixedSize( 230, 300); | 1370 | mSyncActionDialog->setFixedSize( 230, 300); |
1364 | } else { | 1371 | } else { |
1365 | mSyncActionDialog->setFixedSize( 230, 200); | 1372 | mSyncActionDialog->setFixedSize( 230, 200); |
1366 | } | 1373 | } |
1367 | } else { | 1374 | } else { |
1368 | mSyncActionDialog->setFixedSize( 230, 120); | 1375 | mSyncActionDialog->setFixedSize( 230, 120); |
1369 | } | 1376 | } |
1370 | } else | 1377 | } else |
1371 | mSyncActionDialog->setFixedSize( 230, 120); | 1378 | mSyncActionDialog->setFixedSize( 230, 120); |
1372 | mSyncActionDialog->show(); | 1379 | mSyncActionDialog->show(); |
1373 | mSyncActionDialog->raise(); | 1380 | mSyncActionDialog->raise(); |
1374 | emit request_file(); | 1381 | emit request_file(); |
1375 | qApp->processEvents(); | 1382 | qApp->processEvents(); |
1376 | QString fileName = mFileName; | 1383 | QString fileName = mFileName; |
1377 | QFile file( fileName ); | 1384 | QFile file( fileName ); |
1378 | if (!file.open( IO_ReadOnly ) ) { | 1385 | if (!file.open( IO_ReadOnly ) ) { |
1379 | mErrorMessage = 0; | 1386 | mErrorMessage = 0; |
1380 | end_connect(); | 1387 | end_connect(); |
1381 | error_connect("ERROR_FI\r\n\r\n"); | 1388 | error_connect("ERROR_FI\r\n\r\n"); |
1382 | return ; | 1389 | return ; |
1383 | } | 1390 | } |
1384 | mSyncActionDialog->setCaption( i18n("Sending file...") ); | 1391 | mSyncActionDialog->setCaption( i18n("Sending file...") ); |
1385 | QTextStream ts( &file ); | 1392 | QTextStream ts( &file ); |
1386 | ts.setEncoding( QTextStream::Latin1 ); | 1393 | ts.setEncoding( QTextStream::Latin1 ); |
1387 | 1394 | ||
1388 | QTextStream os( mSocket ); | 1395 | QTextStream os( mSocket ); |
1389 | os.setEncoding( QTextStream::Latin1 ); | 1396 | os.setEncoding( QTextStream::Latin1 ); |
1390 | while ( ! ts.atEnd() ) { | 1397 | while ( ! ts.atEnd() ) { |
1391 | os << ts.readLine() << "\r\n"; | 1398 | os << ts.readLine() << "\r\n"; |
1392 | } | 1399 | } |
1393 | os << "\r\n"; | 1400 | os << "\r\n"; |
1394 | //os << ts.read(); | 1401 | //os << ts.read(); |
1395 | file.close(); | 1402 | file.close(); |
1396 | mSyncActionDialog->setCaption( i18n("Waiting for synced file...") ); | 1403 | mSyncActionDialog->setCaption( i18n("Waiting for synced file...") ); |
1397 | mSocket->close(); | 1404 | mSocket->close(); |
1398 | if ( mSocket->state() == QSocket::Idle ) | 1405 | if ( mSocket->state() == QSocket::Idle ) |
1399 | QTimer::singleShot( 10, this , SLOT ( discardClient())); | 1406 | QTimer::singleShot( 10, this , SLOT ( discardClient())); |
1400 | } | 1407 | } |
1401 | void KServerSocket::get_file() | 1408 | void KServerSocket::get_file() |
1402 | { | 1409 | { |
1403 | mSyncActionDialog->setCaption( i18n("Receiving synced file...") ); | 1410 | mSyncActionDialog->setCaption( i18n("Receiving synced file...") ); |
1404 | 1411 | ||
1405 | piTime.start(); | 1412 | piTime.start(); |
1406 | piFileString = ""; | 1413 | piFileString = ""; |
1407 | QTimer::singleShot( 1, this , SLOT (readBackFileFromSocket( ) )); | 1414 | QTimer::singleShot( 1, this , SLOT (readBackFileFromSocket( ) )); |
1408 | } | 1415 | } |
1409 | 1416 | ||
1410 | 1417 | ||
1411 | void KServerSocket::readBackFileFromSocket() | 1418 | void KServerSocket::readBackFileFromSocket() |
1412 | { | 1419 | { |
1413 | //qDebug("readBackFileFromSocket() %d ", piTime.elapsed ()); | 1420 | //qDebug("readBackFileFromSocket() %d ", piTime.elapsed ()); |
1414 | while ( mSocket->canReadLine () ) { | 1421 | while ( mSocket->canReadLine () ) { |
1415 | piTime.restart(); | 1422 | piTime.restart(); |
1416 | QString line = mSocket->readLine (); | 1423 | QString line = mSocket->readLine (); |
1417 | piFileString += line; | 1424 | piFileString += line; |
1418 | //qDebug("readline: %s ", line.latin1()); | 1425 | //qDebug("readline: %s ", line.latin1()); |
1419 | mSyncActionDialog->setCaption( i18n("Received %1 bytes").arg( piFileString.length() ) ); | 1426 | mSyncActionDialog->setCaption( i18n("Received %1 bytes").arg( piFileString.length() ) ); |
1420 | 1427 | ||
1421 | } | 1428 | } |
1422 | if ( piTime.elapsed () < 3000 ) { | 1429 | if ( piTime.elapsed () < 3000 ) { |
1423 | // wait for more | 1430 | // wait for more |
1424 | //qDebug("waitformore "); | 1431 | //qDebug("waitformore "); |
1425 | QTimer::singleShot( 100, this , SLOT (readBackFileFromSocket( ) )); | 1432 | QTimer::singleShot( 100, this , SLOT (readBackFileFromSocket( ) )); |
1426 | return; | 1433 | return; |
1427 | } | 1434 | } |
1428 | QString fileName = mFileName; | 1435 | QString fileName = mFileName; |
1429 | QFile file ( fileName ); | 1436 | QFile file ( fileName ); |
1430 | if (!file.open( IO_WriteOnly ) ) { | 1437 | if (!file.open( IO_WriteOnly ) ) { |
1431 | delete mSyncActionDialog; | 1438 | delete mSyncActionDialog; |
1432 | mSyncActionDialog = 0; | 1439 | mSyncActionDialog = 0; |
1433 | qDebug("KSS:Error open read back file "); | 1440 | qDebug("KSS:Error open read back file "); |
1434 | piFileString = ""; | 1441 | piFileString = ""; |
1435 | emit file_received( false ); | 1442 | emit file_received( false ); |
1436 | blockRC = false; | 1443 | blockRC = false; |
1437 | return ; | 1444 | return ; |
1438 | 1445 | ||
1439 | } | 1446 | } |
1440 | 1447 | ||
1441 | // mView->setLoadedFileVersion(QDateTime::currentDateTime().addSecs( -1)); | 1448 | // mView->setLoadedFileVersion(QDateTime::currentDateTime().addSecs( -1)); |
1442 | QTextStream ts ( &file ); | 1449 | QTextStream ts ( &file ); |
1443 | ts.setEncoding( QTextStream::Latin1 ); | 1450 | ts.setEncoding( QTextStream::Latin1 ); |
1444 | mSyncActionDialog->setCaption( i18n("Writing file to disk...") ); | 1451 | mSyncActionDialog->setCaption( i18n("Writing file to disk...") ); |
1445 | ts << piFileString; | 1452 | ts << piFileString; |
1446 | mSocket->close(); | 1453 | mSocket->close(); |
1447 | if ( mSocket->state() == QSocket::Idle ) | 1454 | if ( mSocket->state() == QSocket::Idle ) |
1448 | QTimer::singleShot( 10, this , SLOT ( discardClient())); | 1455 | QTimer::singleShot( 10, this , SLOT ( discardClient())); |
1449 | file.close(); | 1456 | file.close(); |
1450 | piFileString = ""; | 1457 | piFileString = ""; |
1451 | emit file_received( true ); | 1458 | emit file_received( true ); |
1452 | delete mSyncActionDialog; | 1459 | delete mSyncActionDialog; |
1453 | mSyncActionDialog = 0; | 1460 | mSyncActionDialog = 0; |
1454 | blockRC = false; | 1461 | blockRC = false; |
1455 | 1462 | ||
1456 | } | 1463 | } |
1457 | 1464 | ||
1458 | KCommandSocket::KCommandSocket ( QString password, Q_UINT16 port, QString host, QObject * parent, QWidget * cap, const char * name ): QObject( parent, name ) | 1465 | KCommandSocket::KCommandSocket ( QString password, Q_UINT16 port, QString host, QObject * parent, QWidget * cap, const char * name ): QObject( parent, name ) |
1459 | { | 1466 | { |
1460 | mPassWord = password; | 1467 | mPassWord = password; |
1461 | mSocket = 0; | 1468 | mSocket = 0; |
1462 | mFirst = false; | 1469 | mFirst = false; |
1463 | mFirstLine = true; | 1470 | mFirstLine = true; |
1464 | mPort = port; | 1471 | mPort = port; |
1465 | mHost = host; | 1472 | mHost = host; |
1466 | tlw = cap; | 1473 | tlw = cap; |
1467 | mRetVal = quiet; | 1474 | mRetVal = quiet; |
1468 | mTimerSocket = new QTimer ( this ); | 1475 | mTimerSocket = new QTimer ( this ); |
1469 | connect( mTimerSocket, SIGNAL ( timeout () ), this, SLOT ( deleteSocket() ) ); | 1476 | connect( mTimerSocket, SIGNAL ( timeout () ), this, SLOT ( updateConnectDialog() ) ); |
1477 | mConnectProgress.setCaption( i18n("Pi-Sync") ); | ||
1478 | connect( &mConnectProgress, SIGNAL ( cancelled () ), this, SLOT ( deleteSocket() ) ); | ||
1479 | mConnectCount = -1; | ||
1470 | } | 1480 | } |
1471 | void KCommandSocket::sendFileRequest() | 1481 | void KCommandSocket::sendFileRequest() |
1472 | { | 1482 | { |
1473 | if ( tlw ) | 1483 | if ( tlw ) |
1474 | tlw->setCaption( i18n("Connected! Sending request for remote file ...") ); | 1484 | tlw->setCaption( i18n("Connected! Sending request for remote file ...") ); |
1475 | mTimerSocket->start( 300000 ); | 1485 | mConnectProgress.hide(); |
1486 | mConnectCount = 300;mConnectMax = 300; | ||
1487 | mConnectProgress.setCaption( i18n("Pi-Sync: Connected!") ); | ||
1488 | mTimerSocket->start( 100, true ); | ||
1476 | QTextStream os( mSocket ); | 1489 | QTextStream os( mSocket ); |
1477 | os.setEncoding( QTextStream::Latin1 ); | 1490 | os.setEncoding( QTextStream::Latin1 ); |
1478 | 1491 | ||
1479 | QString curDt = " " +KGlobal::locale()->formatDateTime(QDateTime::currentDateTime().addSecs(-1),true, true,KLocale::ISODate ); | 1492 | QString curDt = " " +KGlobal::locale()->formatDateTime(QDateTime::currentDateTime().addSecs(-1),true, true,KLocale::ISODate ); |
1480 | os << "GET " << mPassWord << curDt <<"\r\n\r\n"; | 1493 | os << "GET " << mPassWord << curDt <<"\r\n\r\n"; |
1481 | } | 1494 | } |
1482 | 1495 | ||
1483 | void KCommandSocket::readFile( QString fn ) | 1496 | void KCommandSocket::readFile( QString fn ) |
1484 | { | 1497 | { |
1485 | if ( !mSocket ) { | 1498 | if ( !mSocket ) { |
1486 | mSocket = new QSocket( this ); | 1499 | mSocket = new QSocket( this ); |
1487 | connect( mSocket, SIGNAL(readyRead()), this, SLOT(startReadFileFromSocket()) ); | 1500 | connect( mSocket, SIGNAL(readyRead()), this, SLOT(startReadFileFromSocket()) ); |
1488 | connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) ); | 1501 | connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) ); |
1489 | connect( mSocket, SIGNAL(connected ()), this, SLOT(sendFileRequest() )); | 1502 | connect( mSocket, SIGNAL(connected ()), this, SLOT(sendFileRequest() )); |
1490 | } | 1503 | } |
1491 | mFileString = ""; | 1504 | mFileString = ""; |
1492 | mFileName = fn; | 1505 | mFileName = fn; |
1493 | mFirst = true; | 1506 | mFirst = true; |
1494 | if ( tlw ) | 1507 | if ( tlw ) |
1495 | tlw->setCaption( i18n("Trying to connect to remote...") ); | 1508 | tlw->setCaption( i18n("Trying to connect to remote...") ); |
1496 | mTimerSocket->start( 20000 ); | 1509 | mConnectCount = 30;mConnectMax = 30; |
1510 | mTimerSocket->start( 1000, true ); | ||
1497 | mSocket->connectToHost( mHost, mPort ); | 1511 | mSocket->connectToHost( mHost, mPort ); |
1498 | qDebug("KSS: Waiting for connection"); | 1512 | qDebug("KSS: Waiting for connection"); |
1499 | } | 1513 | } |
1500 | 1514 | void KCommandSocket::updateConnectDialog() | |
1515 | { | ||
1516 | |||
1517 | if ( mConnectCount == mConnectMax ) { | ||
1518 | //qDebug("MAXX %d", mConnectMax); | ||
1519 | mConnectProgress.setTotalSteps ( 30 ); | ||
1520 | mConnectProgress.show(); | ||
1521 | mConnectProgress.setLabelText( i18n("Trying to connect to remote...") ); | ||
1522 | } | ||
1523 | //qDebug("updateConnectDialog() %d", mConnectCount); | ||
1524 | mConnectProgress.raise(); | ||
1525 | mConnectProgress.setProgress( (mConnectMax - mConnectCount)%30 ); | ||
1526 | --mConnectCount; | ||
1527 | if ( mConnectCount > 0 ) | ||
1528 | mTimerSocket->start( 1000, true ); | ||
1529 | else | ||
1530 | deleteSocket(); | ||
1531 | |||
1532 | } | ||
1501 | void KCommandSocket::writeFile( QString fileName ) | 1533 | void KCommandSocket::writeFile( QString fileName ) |
1502 | { | 1534 | { |
1503 | if ( !mSocket ) { | 1535 | if ( !mSocket ) { |
1504 | mSocket = new QSocket( this ); | 1536 | mSocket = new QSocket( this ); |
1505 | connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) ); | 1537 | connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) ); |
1506 | connect( mSocket, SIGNAL(connected ()), this, SLOT(writeFileToSocket()) ); | 1538 | connect( mSocket, SIGNAL(connected ()), this, SLOT(writeFileToSocket()) ); |
1507 | } | 1539 | } |
1508 | mFileName = fileName ; | 1540 | mFileName = fileName ; |
1509 | mTimerSocket->start( 20000 ); | 1541 | mConnectCount = 30;mConnectMax = 30; |
1542 | mTimerSocket->start( 1000, true ); | ||
1510 | mSocket->connectToHost( mHost, mPort ); | 1543 | mSocket->connectToHost( mHost, mPort ); |
1511 | } | 1544 | } |
1512 | void KCommandSocket::writeFileToSocket() | 1545 | void KCommandSocket::writeFileToSocket() |
1513 | { | 1546 | { |
1514 | mTimerSocket->stop(); | 1547 | mTimerSocket->stop(); |
1515 | QFile file2( mFileName ); | 1548 | QFile file2( mFileName ); |
1516 | if (!file2.open( IO_ReadOnly ) ) { | 1549 | if (!file2.open( IO_ReadOnly ) ) { |
1550 | mConnectProgress.hide(); | ||
1551 | mConnectCount = -1; | ||
1517 | mRetVal= errorW; | 1552 | mRetVal= errorW; |
1518 | mSocket->close(); | 1553 | mSocket->close(); |
1519 | if ( mSocket->state() == QSocket::Idle ) | 1554 | if ( mSocket->state() == QSocket::Idle ) |
1520 | QTimer::singleShot( 10, this , SLOT ( deleteSocket())); | 1555 | QTimer::singleShot( 10, this , SLOT ( deleteSocket())); |
1521 | return ; | 1556 | return ; |
1522 | } | 1557 | } |
1558 | mConnectProgress.setTotalSteps ( file2.size() ); | ||
1559 | mConnectProgress.show(); | ||
1560 | int count = 0; | ||
1561 | mConnectProgress.setLabelText( i18n("Sending back synced file...") ); | ||
1562 | mConnectProgress.setProgress( count ); | ||
1563 | mConnectProgress.blockSignals( true ); | ||
1523 | QTextStream ts2( &file2 ); | 1564 | QTextStream ts2( &file2 ); |
1524 | ts2.setEncoding( QTextStream::Latin1 ); | 1565 | ts2.setEncoding( QTextStream::Latin1 ); |
1525 | QTextStream os2( mSocket ); | 1566 | QTextStream os2( mSocket ); |
1526 | os2.setEncoding( QTextStream::Latin1 ); | 1567 | os2.setEncoding( QTextStream::Latin1 ); |
1527 | os2 << "PUT " << mPassWord << "\r\n\r\n";; | 1568 | os2 << "PUT " << mPassWord << "\r\n\r\n";; |
1528 | while ( ! ts2.atEnd() ) { | 1569 | while ( ! ts2.atEnd() ) { |
1529 | os2 << ts2.readLine() << "\r\n"; | 1570 | qApp->processEvents(); |
1571 | mConnectProgress.setProgress( count ); | ||
1572 | QString temp = ts2.readLine(); | ||
1573 | count += temp.length(); | ||
1574 | os2 << temp << "\r\n"; | ||
1530 | } | 1575 | } |
1576 | file2.close(); | ||
1577 | mConnectProgress.hide(); | ||
1578 | mConnectCount = -1; | ||
1531 | os2 << "\r\n"; | 1579 | os2 << "\r\n"; |
1532 | mRetVal= successW; | 1580 | mRetVal= successW; |
1533 | file2.close(); | ||
1534 | mSocket->close(); | 1581 | mSocket->close(); |
1535 | if ( mSocket->state() == QSocket::Idle ) | 1582 | if ( mSocket->state() == QSocket::Idle ) |
1536 | QTimer::singleShot( 10, this , SLOT ( deleteSocket())); | 1583 | QTimer::singleShot( 10, this , SLOT ( deleteSocket())); |
1584 | mConnectProgress.blockSignals( false ); | ||
1537 | } | 1585 | } |
1538 | void KCommandSocket::sendStop() | 1586 | void KCommandSocket::sendStop() |
1539 | { | 1587 | { |
1540 | if ( !mSocket ) { | 1588 | if ( !mSocket ) { |
1541 | mSocket = new QSocket( this ); | 1589 | mSocket = new QSocket( this ); |
1542 | connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) ); | 1590 | connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) ); |
1543 | } | 1591 | } |
1544 | mSocket->connectToHost( mHost, mPort ); | 1592 | mSocket->connectToHost( mHost, mPort ); |
1545 | QTextStream os2( mSocket ); | 1593 | QTextStream os2( mSocket ); |
1546 | os2.setEncoding( QTextStream::Latin1 ); | 1594 | os2.setEncoding( QTextStream::Latin1 ); |
1547 | os2 << "STOP\r\n\r\n"; | 1595 | os2 << "STOP\r\n\r\n"; |
1548 | mSocket->close(); | 1596 | mSocket->close(); |
1549 | if ( mSocket->state() == QSocket::Idle ) | 1597 | if ( mSocket->state() == QSocket::Idle ) |
1550 | QTimer::singleShot( 10, this , SLOT ( deleteSocket())); | 1598 | QTimer::singleShot( 10, this , SLOT ( deleteSocket())); |
1551 | } | 1599 | } |
1552 | 1600 | ||
1553 | void KCommandSocket::startReadFileFromSocket() | 1601 | void KCommandSocket::startReadFileFromSocket() |
1554 | { | 1602 | { |
1555 | if ( ! mFirst ) | 1603 | if ( ! mFirst ) |
1556 | return; | 1604 | return; |
1605 | mConnectProgress.setLabelText( i18n("Receiving file from remote...") ); | ||
1557 | mFirst = false; | 1606 | mFirst = false; |
1558 | mTimerSocket->stop(); | ||
1559 | mFileString = ""; | 1607 | mFileString = ""; |
1560 | mTime.start(); | 1608 | mTime.start(); |
1561 | mFirstLine = true; | 1609 | mFirstLine = true; |
1562 | QTimer::singleShot( 1, this , SLOT (readFileFromSocket( ) )); | 1610 | QTimer::singleShot( 1, this , SLOT (readFileFromSocket( ) )); |
1563 | 1611 | ||
1564 | } | 1612 | } |
1565 | void KCommandSocket::readFileFromSocket() | 1613 | void KCommandSocket::readFileFromSocket() |
1566 | { | 1614 | { |
1567 | //qDebug("readBackFileFromSocket() %d ", mTime.elapsed ()); | 1615 | //qDebug("readBackFileFromSocket() %d ", mTime.elapsed ()); |
1568 | while ( mSocket->canReadLine () ) { | 1616 | while ( mSocket->canReadLine () ) { |
1569 | mTime.restart(); | 1617 | mTime.restart(); |
1570 | QString line = mSocket->readLine (); | 1618 | QString line = mSocket->readLine (); |
1571 | if ( mFirstLine ) { | 1619 | if ( mFirstLine ) { |
1572 | mFirstLine = false; | 1620 | mFirstLine = false; |
1573 | if ( line.left( 6 ) == "ERROR_" ) { | 1621 | if ( line.left( 6 ) == "ERROR_" ) { |
1622 | mTimerSocket->stop(); | ||
1623 | mConnectCount = -1; | ||
1574 | if ( line.left( 8 ) == "ERROR_PW" ) { | 1624 | if ( line.left( 8 ) == "ERROR_PW" ) { |
1575 | mRetVal = errorPW; | 1625 | mRetVal = errorPW; |
1576 | deleteSocket(); | 1626 | deleteSocket(); |
1577 | return ; | 1627 | return ; |
1578 | } | 1628 | } |
1579 | if ( line.left( 8 ) == "ERROR_CA" ) { | 1629 | if ( line.left( 8 ) == "ERROR_CA" ) { |
1580 | mRetVal = errorCA; | 1630 | mRetVal = errorCA; |
1581 | deleteSocket(); | 1631 | deleteSocket(); |
1582 | return ; | 1632 | return ; |
1583 | } | 1633 | } |
1584 | if ( line.left( 8 ) == "ERROR_FI" ) { | 1634 | if ( line.left( 8 ) == "ERROR_FI" ) { |
1585 | mRetVal = errorFI; | 1635 | mRetVal = errorFI; |
1586 | deleteSocket(); | 1636 | deleteSocket(); |
1587 | return ; | 1637 | return ; |
1588 | } | 1638 | } |
1589 | if ( line.left( 8 ) == "ERROR_ED" ) { | 1639 | if ( line.left( 8 ) == "ERROR_ED" ) { |
1590 | mRetVal = errorED; | 1640 | mRetVal = errorED; |
1591 | deleteSocket(); | 1641 | deleteSocket(); |
1592 | return ; | 1642 | return ; |
1593 | } | 1643 | } |
1594 | mRetVal = errorUN; | 1644 | mRetVal = errorUN; |
1595 | deleteSocket(); | 1645 | deleteSocket(); |
1596 | return ; | 1646 | return ; |
1597 | } | 1647 | } |
1598 | } | 1648 | } |
1599 | mFileString += line; | 1649 | mFileString += line; |
1600 | //qDebug("readline: %s ", line.latin1()); | 1650 | //qDebug("readline: %s ", line.latin1()); |
1601 | } | 1651 | } |
1602 | if ( mTime.elapsed () < 3000 ) { | 1652 | if ( mTime.elapsed () < 3000 ) { |
1603 | // wait for more | 1653 | // wait for more |
1604 | //qDebug("waitformore "); | 1654 | //qDebug("waitformore "); |
1605 | QTimer::singleShot( 100, this , SLOT (readFileFromSocket( ) )); | 1655 | QTimer::singleShot( 100, this , SLOT (readFileFromSocket( ) )); |
1606 | return; | 1656 | return; |
1607 | } | 1657 | } |
1658 | mTimerSocket->stop(); | ||
1659 | mConnectCount = -1; | ||
1660 | mConnectProgress.hide(); | ||
1608 | QString fileName = mFileName; | 1661 | QString fileName = mFileName; |
1609 | QFile file ( fileName ); | 1662 | QFile file ( fileName ); |
1610 | if (!file.open( IO_WriteOnly ) ) { | 1663 | if (!file.open( IO_WriteOnly ) ) { |
1611 | mFileString = ""; | 1664 | mFileString = ""; |
1612 | mRetVal = errorR; | 1665 | mRetVal = errorR; |
1613 | qDebug("KSS:Error open temp sync file for writing: %s",fileName.latin1() ); | 1666 | qDebug("KSS:Error open temp sync file for writing: %s",fileName.latin1() ); |
1614 | deleteSocket(); | 1667 | deleteSocket(); |
1615 | return ; | 1668 | return ; |
1616 | 1669 | ||
1617 | } | 1670 | } |
1618 | // mView->setLoadedFileVersion(QDateTime::currentDateTime().addSecs( -1)); | 1671 | // mView->setLoadedFileVersion(QDateTime::currentDateTime().addSecs( -1)); |
1619 | QTextStream ts ( &file ); | 1672 | QTextStream ts ( &file ); |
1620 | ts.setEncoding( QTextStream::Latin1 ); | 1673 | ts.setEncoding( QTextStream::Latin1 ); |
1621 | ts << mFileString; | 1674 | ts << mFileString; |
1622 | file.close(); | 1675 | file.close(); |
1623 | mFileString = ""; | 1676 | mFileString = ""; |
1624 | mRetVal = successR; | 1677 | mRetVal = successR; |
1625 | mSocket->close(); | 1678 | mSocket->close(); |
1626 | // if state is not idle, deleteSocket(); is called via | 1679 | // if state is not idle, deleteSocket(); is called via |
1627 | // connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) ); | 1680 | // connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) ); |
1628 | if ( mSocket->state() == QSocket::Idle ) | 1681 | if ( mSocket->state() == QSocket::Idle ) |
1629 | deleteSocket(); | 1682 | deleteSocket(); |
1630 | } | 1683 | } |
1631 | 1684 | ||
1632 | void KCommandSocket::deleteSocket() | 1685 | void KCommandSocket::deleteSocket() |
1633 | { | 1686 | { |
1634 | //qDebug("KCommandSocket::deleteSocket() "); | 1687 | //qDebug("KCommandSocket::deleteSocket() "); |
1635 | if ( mTimerSocket->isActive () ) { | 1688 | mConnectProgress.hide(); |
1689 | |||
1690 | if ( mConnectCount >= 0 ) { | ||
1636 | mTimerSocket->stop(); | 1691 | mTimerSocket->stop(); |
1637 | mRetVal = errorTO; | 1692 | mRetVal = errorTO; |
1638 | qDebug("KCS::Connection to remote host timed out"); | 1693 | qDebug("KCS::Connection to remote host timed out"); |
1639 | if ( mSocket ) { | 1694 | if ( mSocket ) { |
1640 | mSocket->close(); | 1695 | mSocket->close(); |
1641 | //if ( mSocket->state() == QSocket::Idle ) | 1696 | //if ( mSocket->state() == QSocket::Idle ) |
1642 | // deleteSocket(); | 1697 | // deleteSocket(); |
1643 | delete mSocket; | 1698 | delete mSocket; |
1644 | mSocket = 0; | 1699 | mSocket = 0; |
1645 | } | 1700 | } |
1701 | if ( mConnectCount == 0 ) | ||
1646 | KMessageBox::error( 0, i18n("Connection to remote\nhost timed out!\nDid you forgot to enable\nsyncing on remote host?")); | 1702 | KMessageBox::error( 0, i18n("Connection to remote\nhost timed out!\nDid you forgot to enable\nsyncing on remote host?")); |
1703 | else if ( tlw ) | ||
1704 | tlw->setCaption( i18n("Connection to remote host cancelled!") ); | ||
1647 | emit commandFinished( this, mRetVal ); | 1705 | emit commandFinished( this, mRetVal ); |
1648 | return; | 1706 | return; |
1649 | } | 1707 | } |
1650 | //qDebug("KCommandSocket::deleteSocket() %d", mRetVal ); | 1708 | //qDebug("KCommandSocket::deleteSocket() %d", mRetVal ); |
1651 | if ( mSocket) | 1709 | if ( mSocket) |
1652 | delete mSocket; | 1710 | delete mSocket; |
1653 | mSocket = 0; | 1711 | mSocket = 0; |
1712 | qDebug("commandFinished "); | ||
1654 | emit commandFinished( this, mRetVal ); | 1713 | emit commandFinished( this, mRetVal ); |
1655 | } | 1714 | } |