-rw-r--r-- | kaddressbook/kabcore.cpp | 293 |
1 files changed, 277 insertions, 16 deletions
diff --git a/kaddressbook/kabcore.cpp b/kaddressbook/kabcore.cpp index e912941..1196360 100644 --- a/kaddressbook/kabcore.cpp +++ b/kaddressbook/kabcore.cpp | |||
@@ -2326,287 +2326,548 @@ int KABCore::ringSync() | |||
2326 | // KABPrefs::instance()->mAskForPreferences = temp->getAskForPreferences(); | 2326 | // KABPrefs::instance()->mAskForPreferences = temp->getAskForPreferences(); |
2327 | KABPrefs::instance()->mWriteBackFile = temp->getWriteBackFile(); | 2327 | KABPrefs::instance()->mWriteBackFile = temp->getWriteBackFile(); |
2328 | KABPrefs::instance()->mWriteBackExistingOnly = temp->getWriteBackExisting(); | 2328 | KABPrefs::instance()->mWriteBackExistingOnly = temp->getWriteBackExisting(); |
2329 | KABPrefs::instance()->mWriteBackInFuture = 0; | 2329 | KABPrefs::instance()->mWriteBackInFuture = 0; |
2330 | if ( temp->getWriteBackFuture() ) | 2330 | if ( temp->getWriteBackFuture() ) |
2331 | KABPrefs::instance()->mWriteBackInFuture = temp->getWriteBackFutureWeeks( ); | 2331 | KABPrefs::instance()->mWriteBackInFuture = temp->getWriteBackFutureWeeks( ); |
2332 | KABPrefs::instance()->mShowSyncSummary = false; | 2332 | KABPrefs::instance()->mShowSyncSummary = false; |
2333 | mCurrentSyncDevice = syncProfileNames[i] ; | 2333 | mCurrentSyncDevice = syncProfileNames[i] ; |
2334 | mCurrentSyncName = KABPrefs::instance()->mLocalMachineName; | 2334 | mCurrentSyncName = KABPrefs::instance()->mLocalMachineName; |
2335 | if ( i == 0 ) { | 2335 | if ( i == 0 ) { |
2336 | syncSharp(); | 2336 | syncSharp(); |
2337 | } else { | 2337 | } else { |
2338 | if ( temp->getIsLocalFileSync() ) { | 2338 | if ( temp->getIsLocalFileSync() ) { |
2339 | if ( syncWithFile( temp->getRemoteFileNameAB( ), true ) ) | 2339 | if ( syncWithFile( temp->getRemoteFileNameAB( ), true ) ) |
2340 | KABPrefs::instance()->mLastSyncedLocalFile = temp->getRemoteFileNameAB(); | 2340 | KABPrefs::instance()->mLastSyncedLocalFile = temp->getRemoteFileNameAB(); |
2341 | } else { | 2341 | } else { |
2342 | if ( temp->getIsPhoneSync() ) { | 2342 | if ( temp->getIsPhoneSync() ) { |
2343 | KABPrefs::instance()->mPhoneDevice = temp->getPhoneDevice( ) ; | 2343 | KABPrefs::instance()->mPhoneDevice = temp->getPhoneDevice( ) ; |
2344 | KABPrefs::instance()->mPhoneConnection = temp->getPhoneConnection( ); | 2344 | KABPrefs::instance()->mPhoneConnection = temp->getPhoneConnection( ); |
2345 | KABPrefs::instance()->mPhoneModel = temp->getPhoneModel( ); | 2345 | KABPrefs::instance()->mPhoneModel = temp->getPhoneModel( ); |
2346 | syncPhone(); | 2346 | syncPhone(); |
2347 | } else | 2347 | } else |
2348 | syncRemote( temp, false ); | 2348 | syncRemote( temp, false ); |
2349 | 2349 | ||
2350 | } | 2350 | } |
2351 | } | 2351 | } |
2352 | timer.start(); | 2352 | timer.start(); |
2353 | setCaption(i18n("Multiple sync in progress ... please wait!") ); | 2353 | setCaption(i18n("Multiple sync in progress ... please wait!") ); |
2354 | while ( timer.elapsed () < 2000 ) { | 2354 | while ( timer.elapsed () < 2000 ) { |
2355 | qApp->processEvents(); | 2355 | qApp->processEvents(); |
2356 | #ifndef _WIN32_ | 2356 | #ifndef _WIN32_ |
2357 | sleep (1); | 2357 | sleep (1); |
2358 | #endif | 2358 | #endif |
2359 | } | 2359 | } |
2360 | 2360 | ||
2361 | } | 2361 | } |
2362 | 2362 | ||
2363 | } | 2363 | } |
2364 | delete temp; | 2364 | delete temp; |
2365 | return syncedProfiles; | 2365 | return syncedProfiles; |
2366 | } | 2366 | } |
2367 | 2367 | ||
2368 | void KABCore::syncRemote( KSyncProfile* prof, bool ask) | 2368 | void KABCore::syncRemote( KSyncProfile* prof, bool ask) |
2369 | { | 2369 | { |
2370 | QString question; | 2370 | QString question; |
2371 | if ( ask ) { | 2371 | if ( ask ) { |
2372 | question = i18n("Do you really want\nto remote sync\nwith profile \n")+ prof->getName()+" ?\n"; | 2372 | question = i18n("Do you really want\nto remote sync\nwith profile \n")+ prof->getName()+" ?\n"; |
2373 | if ( QMessageBox::information( this, i18n("KO/Pi Sync"), | 2373 | if ( QMessageBox::information( this, i18n("KO/Pi Sync"), |
2374 | question, | 2374 | question, |
2375 | i18n("Yes"), i18n("No"), | 2375 | i18n("Yes"), i18n("No"), |
2376 | 0, 0 ) != 0 ) | 2376 | 0, 0 ) != 0 ) |
2377 | return; | 2377 | return; |
2378 | } | 2378 | } |
2379 | QString command = prof->getPreSyncCommandAB(); | 2379 | QString command = prof->getPreSyncCommandAB(); |
2380 | int fi; | 2380 | int fi; |
2381 | if ( (fi = command.find("$PWD$")) > 0 ) { | 2381 | if ( (fi = command.find("$PWD$")) > 0 ) { |
2382 | QString pwd = getPassword(); | 2382 | QString pwd = getPassword(); |
2383 | command = command.left( fi )+ pwd + command.mid( fi+5 ); | 2383 | command = command.left( fi )+ pwd + command.mid( fi+5 ); |
2384 | 2384 | ||
2385 | } | 2385 | } |
2386 | int maxlen = 30; | 2386 | int maxlen = 30; |
2387 | if ( QApplication::desktop()->width() > 320 ) | 2387 | if ( QApplication::desktop()->width() > 320 ) |
2388 | maxlen += 25; | 2388 | maxlen += 25; |
2389 | setCaption ( i18n( "Copy remote file to local machine..." ) ); | 2389 | setCaption ( i18n( "Copy remote file to local machine..." ) ); |
2390 | int fileSize = 0; | 2390 | int fileSize = 0; |
2391 | int result = system ( command ); | 2391 | int result = system ( command ); |
2392 | // 0 : okay | 2392 | // 0 : okay |
2393 | // 256: no such file or dir | 2393 | // 256: no such file or dir |
2394 | // | 2394 | // |
2395 | qDebug("KO: Remote copy result(0 = okay): %d ",result ); | 2395 | qDebug("KO: Remote copy result(0 = okay): %d ",result ); |
2396 | if ( result != 0 ) { | 2396 | if ( result != 0 ) { |
2397 | int len = maxlen; | 2397 | int len = maxlen; |
2398 | while ( len < command.length() ) { | 2398 | while ( len < command.length() ) { |
2399 | command.insert( len , "\n" ); | 2399 | command.insert( len , "\n" ); |
2400 | len += maxlen +2; | 2400 | len += maxlen +2; |
2401 | } | 2401 | } |
2402 | 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 (command) ; | 2402 | 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 (command) ; |
2403 | QMessageBox::information( this, i18n("KO/Pi Sync - ERROR"), | 2403 | QMessageBox::information( this, i18n("KO/Pi Sync - ERROR"), |
2404 | question, | 2404 | question, |
2405 | i18n("Okay!")) ; | 2405 | i18n("Okay!")) ; |
2406 | setCaption ("KO/Pi"); | 2406 | setCaption ("KO/Pi"); |
2407 | return; | 2407 | return; |
2408 | } | 2408 | } |
2409 | setCaption ( i18n( "Copying succeed." ) ); | 2409 | setCaption ( i18n( "Copying succeed." ) ); |
2410 | //qDebug(" file **%s** ",prof->getLocalTempFile().latin1() ); | 2410 | //qDebug(" file **%s** ",prof->getLocalTempFile().latin1() ); |
2411 | if ( syncWithFile( prof->getLocalTempFileAB(), true ) ) { | 2411 | if ( syncWithFile( prof->getLocalTempFileAB(), true ) ) { |
2412 | // Event* e = mView->getLastSyncEvent(); | 2412 | // Event* e = mView->getLastSyncEvent(); |
2413 | // e->setReadOnly( false ); | 2413 | // e->setReadOnly( false ); |
2414 | // e->setLocation( KOPrefs::instance()->mSyncProfileNames[mCurrentSyncProfile]); | 2414 | // e->setLocation( KOPrefs::instance()->mSyncProfileNames[mCurrentSyncProfile]); |
2415 | // e->setReadOnly( true ); | 2415 | // e->setReadOnly( true ); |
2416 | if ( KABPrefs::instance()->mWriteBackFile ) { | 2416 | if ( KABPrefs::instance()->mWriteBackFile ) { |
2417 | command = prof->getPostSyncCommandAB(); | 2417 | command = prof->getPostSyncCommandAB(); |
2418 | int fi; | 2418 | int fi; |
2419 | if ( (fi = command.find("$PWD$")) > 0 ) { | 2419 | if ( (fi = command.find("$PWD$")) > 0 ) { |
2420 | QString pwd = getPassword(); | 2420 | QString pwd = getPassword(); |
2421 | command = command.left( fi )+ pwd + command.mid( fi+5 ); | 2421 | command = command.left( fi )+ pwd + command.mid( fi+5 ); |
2422 | 2422 | ||
2423 | } | 2423 | } |
2424 | setCaption ( i18n( "Writing back file ..." ) ); | 2424 | setCaption ( i18n( "Writing back file ..." ) ); |
2425 | result = system ( command ); | 2425 | result = system ( command ); |
2426 | qDebug("KO: Writing back file result: %d ", result); | 2426 | qDebug("KO: Writing back file result: %d ", result); |
2427 | if ( result != 0 ) { | 2427 | if ( result != 0 ) { |
2428 | setCaption ( i18n( "Writing back file result: " )+QString::number( result ) ); | 2428 | setCaption ( i18n( "Writing back file result: " )+QString::number( result ) ); |
2429 | return; | 2429 | return; |
2430 | } else { | 2430 | } else { |
2431 | setCaption ( i18n( "Syncronization sucessfully completed" ) ); | 2431 | setCaption ( i18n( "Syncronization sucessfully completed" ) ); |
2432 | } | 2432 | } |
2433 | } | 2433 | } |
2434 | } | 2434 | } |
2435 | return; | 2435 | return; |
2436 | } | 2436 | } |
2437 | #include <qpushbutton.h> | 2437 | #include <qpushbutton.h> |
2438 | #include <qradiobutton.h> | 2438 | #include <qradiobutton.h> |
2439 | #include <qbuttongroup.h> | 2439 | #include <qbuttongroup.h> |
2440 | void KABCore::edit_sync_options() | 2440 | void KABCore::edit_sync_options() |
2441 | { | 2441 | { |
2442 | //mDialogManager->showSyncOptions(); | 2442 | //mDialogManager->showSyncOptions(); |
2443 | //KABPrefs::instance()->mSyncAlgoPrefs | 2443 | //KABPrefs::instance()->mSyncAlgoPrefs |
2444 | QDialog dia( this, "dia", true ); | 2444 | QDialog dia( this, "dia", true ); |
2445 | dia.setCaption( i18n("Device: " ) +mCurrentSyncDevice ); | 2445 | dia.setCaption( i18n("Device: " ) +mCurrentSyncDevice ); |
2446 | QButtonGroup gr ( 1, Qt::Horizontal, i18n("Sync preferences"), &dia); | 2446 | QButtonGroup gr ( 1, Qt::Horizontal, i18n("Sync preferences"), &dia); |
2447 | QVBoxLayout lay ( &dia ); | 2447 | QVBoxLayout lay ( &dia ); |
2448 | lay.setSpacing( 2 ); | 2448 | lay.setSpacing( 2 ); |
2449 | lay.setMargin( 3 ); | 2449 | lay.setMargin( 3 ); |
2450 | lay.addWidget(&gr); | 2450 | lay.addWidget(&gr); |
2451 | QRadioButton loc ( i18n("Take local entry on conflict"), &gr ); | 2451 | QRadioButton loc ( i18n("Take local entry on conflict"), &gr ); |
2452 | QRadioButton rem ( i18n("Take remote entry on conflict"), &gr ); | 2452 | QRadioButton rem ( i18n("Take remote entry on conflict"), &gr ); |
2453 | QRadioButton newest( i18n("Take newest entry on conflict"), &gr ); | 2453 | QRadioButton newest( i18n("Take newest entry on conflict"), &gr ); |
2454 | QRadioButton ask( i18n("Ask for every entry on conflict"), &gr ); | 2454 | QRadioButton ask( i18n("Ask for every entry on conflict"), &gr ); |
2455 | QRadioButton f_loc( i18n("Force: Take local entry always"), &gr ); | 2455 | QRadioButton f_loc( i18n("Force: Take local entry always"), &gr ); |
2456 | QRadioButton f_rem( i18n("Force: Take remote entry always"), &gr ); | 2456 | QRadioButton f_rem( i18n("Force: Take remote entry always"), &gr ); |
2457 | //QRadioButton both( i18n("Take both on conflict"), &gr ); | 2457 | //QRadioButton both( i18n("Take both on conflict"), &gr ); |
2458 | QPushButton pb ( "OK", &dia); | 2458 | QPushButton pb ( "OK", &dia); |
2459 | lay.addWidget( &pb ); | 2459 | lay.addWidget( &pb ); |
2460 | connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) ); | 2460 | connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) ); |
2461 | switch ( KABPrefs::instance()->mSyncAlgoPrefs ) { | 2461 | switch ( KABPrefs::instance()->mSyncAlgoPrefs ) { |
2462 | case 0: | 2462 | case 0: |
2463 | loc.setChecked( true); | 2463 | loc.setChecked( true); |
2464 | break; | 2464 | break; |
2465 | case 1: | 2465 | case 1: |
2466 | rem.setChecked( true ); | 2466 | rem.setChecked( true ); |
2467 | break; | 2467 | break; |
2468 | case 2: | 2468 | case 2: |
2469 | newest.setChecked( true); | 2469 | newest.setChecked( true); |
2470 | break; | 2470 | break; |
2471 | case 3: | 2471 | case 3: |
2472 | ask.setChecked( true); | 2472 | ask.setChecked( true); |
2473 | break; | 2473 | break; |
2474 | case 4: | 2474 | case 4: |
2475 | f_loc.setChecked( true); | 2475 | f_loc.setChecked( true); |
2476 | break; | 2476 | break; |
2477 | case 5: | 2477 | case 5: |
2478 | f_rem.setChecked( true); | 2478 | f_rem.setChecked( true); |
2479 | break; | 2479 | break; |
2480 | case 6: | 2480 | case 6: |
2481 | // both.setChecked( true); | 2481 | // both.setChecked( true); |
2482 | break; | 2482 | break; |
2483 | default: | 2483 | default: |
2484 | break; | 2484 | break; |
2485 | } | 2485 | } |
2486 | if ( dia.exec() ) { | 2486 | if ( dia.exec() ) { |
2487 | KABPrefs::instance()->mSyncAlgoPrefs = rem.isChecked()*1+newest.isChecked()*2+ ask.isChecked()*3+ f_loc.isChecked()*4+ f_rem.isChecked()*5;//+ both.isChecked()*6 ; | 2487 | KABPrefs::instance()->mSyncAlgoPrefs = rem.isChecked()*1+newest.isChecked()*2+ ask.isChecked()*3+ f_loc.isChecked()*4+ f_rem.isChecked()*5;//+ both.isChecked()*6 ; |
2488 | } | 2488 | } |
2489 | 2489 | ||
2490 | 2490 | ||
2491 | } | 2491 | } |
2492 | QString KABCore::getPassword( ) | 2492 | QString KABCore::getPassword( ) |
2493 | { | 2493 | { |
2494 | QString retfile = ""; | 2494 | QString retfile = ""; |
2495 | QDialog dia ( this, "input-dialog", true ); | 2495 | QDialog dia ( this, "input-dialog", true ); |
2496 | QLineEdit lab ( &dia ); | 2496 | QLineEdit lab ( &dia ); |
2497 | lab.setEchoMode( QLineEdit::Password ); | 2497 | lab.setEchoMode( QLineEdit::Password ); |
2498 | QVBoxLayout lay( &dia ); | 2498 | QVBoxLayout lay( &dia ); |
2499 | lay.setMargin(7); | 2499 | lay.setMargin(7); |
2500 | lay.setSpacing(7); | 2500 | lay.setSpacing(7); |
2501 | lay.addWidget( &lab); | 2501 | lay.addWidget( &lab); |
2502 | dia.setFixedSize( 230,50 ); | 2502 | dia.setFixedSize( 230,50 ); |
2503 | dia.setCaption( i18n("Enter password") ); | 2503 | dia.setCaption( i18n("Enter password") ); |
2504 | QPushButton pb ( "OK", &dia); | 2504 | QPushButton pb ( "OK", &dia); |
2505 | lay.addWidget( &pb ); | 2505 | lay.addWidget( &pb ); |
2506 | connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) ); | 2506 | connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) ); |
2507 | dia.show(); | 2507 | dia.show(); |
2508 | int res = dia.exec(); | 2508 | int res = dia.exec(); |
2509 | if ( res ) | 2509 | if ( res ) |
2510 | retfile = lab.text(); | 2510 | retfile = lab.text(); |
2511 | dia.hide(); | 2511 | dia.hide(); |
2512 | qApp->processEvents(); | 2512 | qApp->processEvents(); |
2513 | return retfile; | 2513 | return retfile; |
2514 | 2514 | ||
2515 | } | 2515 | } |
2516 | bool KABCore::synchronizeAddressbooks( KABC::AddressBook* local, KABC::AddressBook* remote,int mode) | 2516 | bool KABCore::synchronizeAddressbooks( KABC::AddressBook* local, KABC::AddressBook* remote,int mode) |
2517 | { | 2517 | { |
2518 | 2518 | #if 0 | |
2519 | bool syncOK = true; | ||
2520 | int addedAddressee = 0; | ||
2521 | int addedAddresseeR = 0; | ||
2522 | int deletedAddresseeR = 0; | ||
2523 | int deletedAddresseeL = 0; | ||
2524 | int changedLocal = 0; | ||
2525 | int changedRemote = 0; | ||
2526 | //QPtrList<Addressee> el = local->rawAddressees(); | ||
2527 | Addressee* addresseeR; | ||
2528 | QString uid; | ||
2529 | int take; | ||
2530 | Addressee* addresseeL; | ||
2531 | Addressee* addresseeRSync; | ||
2532 | Addressee* addresseeLSync; | ||
2533 | QPtrList<Addressee> addresseeRSyncSharp = remote->getExternLastSyncAddressees(); | ||
2534 | QPtrList<Addressee> addresseeLSyncSharp = local->getExternLastSyncAddressees(); | ||
2535 | bool fullDateRange = false; | ||
2536 | local->resetTempSyncStat(); | ||
2537 | mLastCalendarSync = QDateTime::currentDateTime(); | ||
2538 | QDateTime modifiedCalendar = mLastCalendarSync;; | ||
2539 | addresseeLSync = getLastSyncAddressee(); | ||
2540 | addresseeR = remote->addressee("last-syncAddressee-"+mCurrentSyncName ); | ||
2541 | if ( addresseeR ) { | ||
2542 | addresseeRSync = (Addressee*) addresseeR->clone(); | ||
2543 | remote->deleteAddressee(addresseeR ); | ||
2544 | |||
2545 | } else { | ||
2546 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { | ||
2547 | addresseeRSync = (Addressee*)addresseeLSync->clone(); | ||
2548 | } else { | ||
2549 | fullDateRange = true; | ||
2550 | addresseeRSync = new Addressee(); | ||
2551 | addresseeRSync->setSummary(mCurrentSyncName + i18n(" - sync addressee")); | ||
2552 | addresseeRSync->setUid("last-syncAddressee-"+mCurrentSyncName ); | ||
2553 | addresseeRSync->setDtStart( mLastCalendarSync ); | ||
2554 | addresseeRSync->setDtEnd( mLastCalendarSync.addSecs( 7200 ) ); | ||
2555 | addresseeRSync->setCategories( i18n("SyncAddressee") ); | ||
2556 | } | ||
2557 | } | ||
2558 | if ( addresseeLSync->dtStart() == mLastCalendarSync ) | ||
2559 | fullDateRange = true; | ||
2560 | |||
2561 | if ( ! fullDateRange ) { | ||
2562 | if ( addresseeLSync->dtStart() != addresseeRSync->dtStart() ) { | ||
2563 | |||
2564 | // qDebug("set fulldate to true %s %s" ,addresseeLSync->dtStart().toString().latin1(), addresseeRSync->dtStart().toString().latin1() ); | ||
2565 | //qDebug("%d %d %d %d ", addresseeLSync->dtStart().time().second(), addresseeLSync->dtStart().time().msec() , addresseeRSync->dtStart().time().second(), addresseeRSync->dtStart().time().msec()); | ||
2566 | fullDateRange = true; | ||
2567 | } | ||
2568 | } | ||
2569 | if ( fullDateRange ) | ||
2570 | mLastCalendarSync = QDateTime::currentDateTime().addDays( -100*365); | ||
2571 | else | ||
2572 | mLastCalendarSync = addresseeLSync->dtStart(); | ||
2573 | // for resyncing if own file has changed | ||
2574 | if ( mCurrentSyncDevice == "deleteaftersync" ) { | ||
2575 | mLastCalendarSync = loadedFileVersion; | ||
2576 | qDebug("setting mLastCalendarSync "); | ||
2577 | } | ||
2578 | //qDebug("*************************** "); | ||
2579 | qDebug("mLastCalendarSync %s ",mLastCalendarSync.toString().latin1() ); | ||
2580 | QPtrList<Incidence> er = remote->rawIncidences(); | ||
2581 | Incidence* inR = er.first(); | ||
2582 | Incidence* inL; | ||
2583 | QProgressBar bar( er.count(),0 ); | ||
2584 | bar.setCaption (i18n("Syncing - close to abort!") ); | ||
2585 | |||
2586 | int w = 300; | ||
2587 | if ( QApplication::desktop()->width() < 320 ) | ||
2588 | w = 220; | ||
2589 | int h = bar.sizeHint().height() ; | ||
2590 | int dw = QApplication::desktop()->width(); | ||
2591 | int dh = QApplication::desktop()->height(); | ||
2592 | bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); | ||
2593 | bar.show(); | ||
2594 | int modulo = (er.count()/10)+1; | ||
2595 | int incCounter = 0; | ||
2596 | while ( inR ) { | ||
2597 | if ( ! bar.isVisible() ) | ||
2598 | return false; | ||
2599 | if ( incCounter % modulo == 0 ) | ||
2600 | bar.setProgress( incCounter ); | ||
2601 | ++incCounter; | ||
2602 | uid = inR->uid(); | ||
2603 | bool skipIncidence = false; | ||
2604 | if ( uid.left(15) == QString("last-syncAddressee-") ) | ||
2605 | skipIncidence = true; | ||
2606 | QString idS; | ||
2607 | qApp->processAddressees(); | ||
2608 | if ( !skipIncidence ) { | ||
2609 | inL = local->incidence( uid ); | ||
2610 | if ( inL ) { // maybe conflict - same uid in both calendars | ||
2611 | int maxrev = inL->revision(); | ||
2612 | if ( maxrev < inR->revision() ) | ||
2613 | maxrev = inR->revision(); | ||
2614 | if ( (take = takeAddressee( inL, inR, mode, fullDateRange )) > 0 ) { | ||
2615 | //qDebug("take %d %s ", take, inL->summary().latin1()); | ||
2616 | if ( take == 3 ) | ||
2617 | return false; | ||
2618 | if ( take == 1 ) {// take local | ||
2619 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) | ||
2620 | inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) ); | ||
2621 | else | ||
2622 | idS = inR->IDStr(); | ||
2623 | remote->deleteIncidence( inR ); | ||
2624 | if ( inL->revision() < maxrev ) | ||
2625 | inL->setRevision( maxrev ); | ||
2626 | inR = inL->clone(); | ||
2627 | inR->setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); | ||
2628 | if ( mGlobalSyncMode != SYNC_MODE_EXTERNAL ) | ||
2629 | inR->setIDStr( idS ); | ||
2630 | remote->addIncidence( inR ); | ||
2631 | ++changedRemote; | ||
2632 | } else { | ||
2633 | if ( inR->revision() < maxrev ) | ||
2634 | inR->setRevision( maxrev ); | ||
2635 | idS = inL->IDStr(); | ||
2636 | local->deleteIncidence( inL ); | ||
2637 | inL = inR->clone(); | ||
2638 | inL->setIDStr( idS ); | ||
2639 | local->addIncidence( inL ); | ||
2640 | ++changedLocal; | ||
2641 | } | ||
2642 | } | ||
2643 | } else { // no conflict | ||
2644 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { | ||
2645 | QString des = addresseeLSync->description(); | ||
2646 | QString pref = "e"; | ||
2647 | if ( inR->type() == "Todo" ) | ||
2648 | pref = "t"; | ||
2649 | if ( des.find(pref+ inR->getID(mCurrentSyncDevice) +"," ) >= 0 && mode != 5) { // delete it | ||
2650 | inR->setTempSyncStat( SYNC_TEMPSTATE_DELETE ); | ||
2651 | //remote->deleteIncidence( inR ); | ||
2652 | ++deletedAddresseeR; | ||
2653 | } else { | ||
2654 | inR->setLastModified( modifiedCalendar ); | ||
2655 | inL = inR->clone(); | ||
2656 | local->addIncidence( inL ); | ||
2657 | ++addedAddressee; | ||
2658 | } | ||
2659 | } else { | ||
2660 | if ( inR->lastModified() > mLastCalendarSync || mode == 5 ) { | ||
2661 | inR->setLastModified( modifiedCalendar ); | ||
2662 | local->addIncidence( inR->clone() ); | ||
2663 | ++addedAddressee; | ||
2664 | } else { | ||
2665 | checkExternSyncAddressee(addresseeRSyncSharp, inR); | ||
2666 | remote->deleteIncidence( inR ); | ||
2667 | ++deletedAddresseeR; | ||
2668 | } | ||
2669 | } | ||
2670 | } | ||
2671 | } | ||
2672 | inR = er.next(); | ||
2673 | } | ||
2674 | QPtrList<Incidence> el = local->rawIncidences(); | ||
2675 | inL = el.first(); | ||
2676 | modulo = (el.count()/10)+1; | ||
2677 | bar.setCaption (i18n("Add / remove addressees") ); | ||
2678 | bar.setTotalSteps ( el.count() ) ; | ||
2679 | bar.show(); | ||
2680 | incCounter = 0; | ||
2681 | |||
2682 | while ( inL ) { | ||
2683 | |||
2684 | qApp->processAddressees(); | ||
2685 | if ( ! bar.isVisible() ) | ||
2686 | return false; | ||
2687 | if ( incCounter % modulo == 0 ) | ||
2688 | bar.setProgress( incCounter ); | ||
2689 | ++incCounter; | ||
2690 | uid = inL->uid(); | ||
2691 | bool skipIncidence = false; | ||
2692 | if ( uid.left(15) == QString("last-syncAddressee-") ) | ||
2693 | skipIncidence = true; | ||
2694 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL && inL->type() == "Journal" ) | ||
2695 | skipIncidence = true; | ||
2696 | if ( !skipIncidence ) { | ||
2697 | inR = remote->incidence( uid ); | ||
2698 | if ( ! inR ) { | ||
2699 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { | ||
2700 | if ( !inL->getID(mCurrentSyncDevice).isEmpty() && mode != 4 ) { | ||
2701 | checkExternSyncAddressee(addresseeLSyncSharp, inL); | ||
2702 | local->deleteIncidence( inL ); | ||
2703 | ++deletedAddresseeL; | ||
2704 | } else { | ||
2705 | if ( ! KOPrefs::instance()->mWriteBackExistingOnly ) { | ||
2706 | inL->removeID(mCurrentSyncDevice ); | ||
2707 | ++addedAddresseeR; | ||
2708 | //qDebug("remote added Incidence %s ", inL->summary().latin1()); | ||
2709 | inL->setLastModified( modifiedCalendar ); | ||
2710 | inR = inL->clone(); | ||
2711 | inR->setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); | ||
2712 | remote->addIncidence( inR ); | ||
2713 | } | ||
2714 | } | ||
2715 | } else { | ||
2716 | if ( inL->lastModified() < mLastCalendarSync && mode != 4 ) { | ||
2717 | checkExternSyncAddressee(addresseeLSyncSharp, inL); | ||
2718 | local->deleteIncidence( inL ); | ||
2719 | ++deletedAddresseeL; | ||
2720 | } else { | ||
2721 | if ( ! KOPrefs::instance()->mWriteBackExistingOnly ) { | ||
2722 | ++addedAddresseeR; | ||
2723 | inL->setLastModified( modifiedCalendar ); | ||
2724 | remote->addIncidence( inL->clone() ); | ||
2725 | } | ||
2726 | } | ||
2727 | } | ||
2728 | } | ||
2729 | } | ||
2730 | inL = el.next(); | ||
2731 | } | ||
2732 | int delFut = 0; | ||
2733 | if ( KOPrefs::instance()->mWriteBackInFuture ) { | ||
2734 | er = remote->rawIncidences(); | ||
2735 | inR = er.first(); | ||
2736 | QDateTime dt; | ||
2737 | QDateTime cur = QDateTime::currentDateTime(); | ||
2738 | QDateTime end = cur.addSecs( KOPrefs::instance()->mWriteBackInFuture * 3600 *24 *7 ); | ||
2739 | while ( inR ) { | ||
2740 | if ( inR->type() == "Todo" ) { | ||
2741 | Todo * t = (Todo*)inR; | ||
2742 | if ( t->hasDueDate() ) | ||
2743 | dt = t->dtDue(); | ||
2744 | else | ||
2745 | dt = cur.addSecs( 62 ); | ||
2746 | } | ||
2747 | else if (inR->type() == "Addressee" ) { | ||
2748 | bool ok; | ||
2749 | dt = inR->getNextOccurence( cur, &ok ); | ||
2750 | if ( !ok ) | ||
2751 | dt = cur.addSecs( -62 ); | ||
2752 | } | ||
2753 | else | ||
2754 | dt = inR->dtStart(); | ||
2755 | if ( dt < cur || dt > end ) { | ||
2756 | remote->deleteIncidence( inR ); | ||
2757 | ++delFut; | ||
2758 | } | ||
2759 | inR = er.next(); | ||
2760 | } | ||
2761 | } | ||
2762 | bar.hide(); | ||
2763 | mLastCalendarSync = QDateTime::currentDateTime().addSecs( 1 ); | ||
2764 | addresseeLSync->setReadOnly( false ); | ||
2765 | addresseeLSync->setDtStart( mLastCalendarSync ); | ||
2766 | addresseeRSync->setDtStart( mLastCalendarSync ); | ||
2767 | addresseeLSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) ); | ||
2768 | addresseeRSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) ); | ||
2769 | addresseeRSync->setLocation( i18n("Remote from: ")+mCurrentSyncName ) ; | ||
2770 | addresseeLSync->setLocation(i18n("Local from: ") + mCurrentSyncName ); | ||
2771 | addresseeLSync->setReadOnly( true ); | ||
2772 | if ( mGlobalSyncMode == SYNC_MODE_NORMAL) | ||
2773 | remote->addAddressee( addresseeRSync ); | ||
2774 | QString mes; | ||
2775 | mes .sprintf( i18n("Synchronization summary:\n\n %d items added to local\n %d items added to remote\n %d items updated on local\n %d items updated on remote\n %d items deleted on local\n %d items deleted on remote\n"),addedAddressee, addedAddresseeR, changedLocal, changedRemote, deletedAddresseeL, deletedAddresseeR ); | ||
2776 | QString delmess; | ||
2777 | if ( delFut ) { | ||
2778 | delmess.sprintf( i18n("%d items skipped on remote,\nbecause they are in the past or\nmore than %d weeks in the future.\n"),delFut, KOPrefs::instance()->mWriteBackInFuture ); | ||
2779 | mes += delmess; | ||
2780 | } | ||
2781 | if ( KOPrefs::instance()->mShowSyncSummary ) { | ||
2782 | KMessageBox::information(this, mes, i18n("KO/Pi Synchronization") ); | ||
2783 | } | ||
2784 | qDebug( mes ); | ||
2785 | mCalendar->checkAlarmForIncidence( 0, true ); | ||
2786 | return syncOK; | ||
2787 | #endif | ||
2788 | return false; | ||
2519 | } | 2789 | } |
2520 | bool KABCore::syncAB(QString filename, int mode) | 2790 | bool KABCore::syncAB(QString filename, int mode) |
2521 | { | 2791 | { |
2522 | 2792 | ||
2523 | 2793 | //pending prepare addresseeview for output | |
2524 | 2794 | //pending detect, if remote file has REV field. if not switch to external sync | |
2525 | mGlobalSyncMode = SYNC_MODE_NORMAL; | 2795 | mGlobalSyncMode = SYNC_MODE_NORMAL; |
2526 | AddressBook abLocal(filename,"syncContact"); | 2796 | AddressBook abLocal(filename,"syncContact"); |
2527 | bool syncOK = false; | 2797 | bool syncOK = false; |
2528 | if ( abLocal.load() ) { | 2798 | if ( abLocal.load() ) { |
2529 | qDebug("AB loaded %s mode %d",filename.latin1(), mode ); | 2799 | qDebug("AB loaded %s mode %d",filename.latin1(), mode ); |
2530 | AddressBook::Iterator it; | 2800 | AddressBook::Iterator it; |
2531 | QStringList vcards; | 2801 | QStringList vcards; |
2532 | for ( it = abLocal.begin(); it != abLocal.end(); ++it ) { | 2802 | for ( it = abLocal.begin(); it != abLocal.end(); ++it ) { |
2533 | qDebug("Name %s ", (*it).familyName().latin1()); | 2803 | qDebug("Name %s ", (*it).familyName().latin1()); |
2534 | } | 2804 | } |
2535 | syncOK = synchronizeAddressbooks( mAddressBook, &abLocal, mode ); | 2805 | syncOK = synchronizeAddressbooks( mAddressBook, &abLocal, mode ); |
2536 | if ( syncOK ) { | 2806 | if ( syncOK ) { |
2537 | if ( KABPrefs::instance()->mWriteBackFile ) | 2807 | if ( KABPrefs::instance()->mWriteBackFile ) |
2538 | { | 2808 | { |
2809 | qDebug("saving remote AB "); | ||
2539 | abLocal.saveAB(); | 2810 | abLocal.saveAB(); |
2540 | } | 2811 | } |
2541 | } | 2812 | } |
2542 | setModified(); | 2813 | setModified(); |
2543 | 2814 | ||
2544 | } | 2815 | } |
2545 | if ( syncOK ) | 2816 | if ( syncOK ) |
2546 | ;//updateView(); | 2817 | mViewManager->refreshView(); |
2547 | return syncOK; | 2818 | return syncOK; |
2548 | #if 0 | 2819 | #if 0 |
2549 | mGlobalSyncMode = SYNC_MODE_NORMAL; | 2820 | |
2550 | CalendarLocal* calendar = new CalendarLocal(); | ||
2551 | calendar->setTimeZoneId(KOPrefs::instance()->mTimeZoneId); | ||
2552 | FileStorage* storage = new FileStorage( calendar ); | ||
2553 | bool syncOK = false; | ||
2554 | storage->setFileName( filename ); | ||
2555 | // qDebug("loading ... "); | ||
2556 | if ( storage->load(KOPrefs::instance()->mUseQuicksave) ) { | 2821 | if ( storage->load(KOPrefs::instance()->mUseQuicksave) ) { |
2557 | getEventViewerDialog()->setSyncMode( true ); | 2822 | getEventViewerDialog()->setSyncMode( true ); |
2558 | syncOK = synchronizeCalendar( mCalendar, calendar, mode ); | 2823 | syncOK = synchronizeCalendar( mCalendar, calendar, mode ); |
2559 | getEventViewerDialog()->setSyncMode( false ); | 2824 | getEventViewerDialog()->setSyncMode( false ); |
2560 | if ( syncOK ) { | 2825 | if ( syncOK ) { |
2561 | if ( KOPrefs::instance()->mWriteBackFile ) | 2826 | if ( KOPrefs::instance()->mWriteBackFile ) |
2562 | { | 2827 | { |
2563 | storage->setSaveFormat( new ICalFormat( KOPrefs::instance()->mUseQuicksave) ); | 2828 | storage->setSaveFormat( new ICalFormat( KOPrefs::instance()->mUseQuicksave) ); |
2564 | storage->save(); | 2829 | storage->save(); |
2565 | } | 2830 | } |
2566 | } | 2831 | } |
2567 | setModified(); | 2832 | setModified(); |
2568 | } | 2833 | } |
2569 | delete storage; | 2834 | |
2570 | delete calendar; | ||
2571 | if ( syncOK ) | ||
2572 | updateView(); | ||
2573 | return syncOK; | ||
2574 | #endif | 2835 | #endif |
2575 | } | 2836 | } |
2576 | 2837 | ||
2577 | 2838 | ||
2578 | void KABCore::confSync() | 2839 | void KABCore::confSync() |
2579 | { | 2840 | { |
2580 | static KSyncPrefsDialog* sp = 0; | 2841 | static KSyncPrefsDialog* sp = 0; |
2581 | if ( ! sp ) { | 2842 | if ( ! sp ) { |
2582 | sp = new KSyncPrefsDialog( this, "syncprefs", true ); | 2843 | sp = new KSyncPrefsDialog( this, "syncprefs", true ); |
2583 | } | 2844 | } |
2584 | sp->usrReadConfig(); | 2845 | sp->usrReadConfig(); |
2585 | #ifndef DESKTOP_VERSION | 2846 | #ifndef DESKTOP_VERSION |
2586 | sp->showMaximized(); | 2847 | sp->showMaximized(); |
2587 | #else | 2848 | #else |
2588 | sp->show(); | 2849 | sp->show(); |
2589 | #endif | 2850 | #endif |
2590 | sp->exec(); | 2851 | sp->exec(); |
2591 | KABPrefs::instance()->mSyncProfileNames = sp->getSyncProfileNames(); | 2852 | KABPrefs::instance()->mSyncProfileNames = sp->getSyncProfileNames(); |
2592 | KABPrefs::instance()->mLocalMachineName = sp->getLocalMachineName (); | 2853 | KABPrefs::instance()->mLocalMachineName = sp->getLocalMachineName (); |
2593 | fillSyncMenu(); | 2854 | fillSyncMenu(); |
2594 | } | 2855 | } |
2595 | void KABCore::syncSharp() | 2856 | void KABCore::syncSharp() |
2596 | { | 2857 | { |
2597 | if ( mModified ) | 2858 | if ( mModified ) |
2598 | save(); | 2859 | save(); |
2599 | qDebug("pending syncSharp() "); | 2860 | qDebug("pending syncSharp() "); |
2600 | //mView->syncSharp(); | 2861 | //mView->syncSharp(); |
2601 | setModified(); | 2862 | setModified(); |
2602 | 2863 | ||
2603 | } | 2864 | } |
2604 | void KABCore::syncPhone() | 2865 | void KABCore::syncPhone() |
2605 | { | 2866 | { |
2606 | if ( mModified ) | 2867 | if ( mModified ) |
2607 | save(); | 2868 | save(); |
2608 | qDebug("pending syncPhone(); "); | 2869 | qDebug("pending syncPhone(); "); |
2609 | //mView->syncPhone(); | 2870 | //mView->syncPhone(); |
2610 | setModified(); | 2871 | setModified(); |
2611 | 2872 | ||
2612 | } | 2873 | } |