-rw-r--r-- | kaddressbook/kabcore.cpp | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/kaddressbook/kabcore.cpp b/kaddressbook/kabcore.cpp index c75b4bc..9ef97c9 100644 --- a/kaddressbook/kabcore.cpp +++ b/kaddressbook/kabcore.cpp | |||
@@ -2354,626 +2354,626 @@ void KABCore::whatsnew() | |||
2354 | { | 2354 | { |
2355 | KApplication::showFile( "KDE-Pim/Pi Version Info", "kdepim/WhatsNew.txt" ); | 2355 | KApplication::showFile( "KDE-Pim/Pi Version Info", "kdepim/WhatsNew.txt" ); |
2356 | } | 2356 | } |
2357 | void KABCore::synchowto() | 2357 | void KABCore::synchowto() |
2358 | { | 2358 | { |
2359 | KApplication::showFile( "KDE-Pim/Pi Synchronization HowTo", "kdepim/SyncHowto.txt" ); | 2359 | KApplication::showFile( "KDE-Pim/Pi Synchronization HowTo", "kdepim/SyncHowto.txt" ); |
2360 | } | 2360 | } |
2361 | void KABCore::kdesynchowto() | 2361 | void KABCore::kdesynchowto() |
2362 | { | 2362 | { |
2363 | KApplication::showFile( "KDE-Pim/Pi Synchronization HowTo", "kdepim/Zaurus-KDE_syncHowTo.txt" ); | 2363 | KApplication::showFile( "KDE-Pim/Pi Synchronization HowTo", "kdepim/Zaurus-KDE_syncHowTo.txt" ); |
2364 | } | 2364 | } |
2365 | void KABCore::multisynchowto() | 2365 | void KABCore::multisynchowto() |
2366 | { | 2366 | { |
2367 | KApplication::showFile( "KDE-Pim/Pi Synchronization HowTo", "kdepim/MultiSyncHowTo.txt" ); | 2367 | KApplication::showFile( "KDE-Pim/Pi Synchronization HowTo", "kdepim/MultiSyncHowTo.txt" ); |
2368 | } | 2368 | } |
2369 | void KABCore::faq() | 2369 | void KABCore::faq() |
2370 | { | 2370 | { |
2371 | KApplication::showFile( "KA/Pi FAQ", "kdepim/kaddressbook/kapiFAQ.txt" ); | 2371 | KApplication::showFile( "KA/Pi FAQ", "kdepim/kaddressbook/kapiFAQ.txt" ); |
2372 | } | 2372 | } |
2373 | 2373 | ||
2374 | #include <libkcal/syncdefines.h> | 2374 | #include <libkcal/syncdefines.h> |
2375 | 2375 | ||
2376 | KABC::Addressee KABCore::getLastSyncAddressee() | 2376 | KABC::Addressee KABCore::getLastSyncAddressee() |
2377 | { | 2377 | { |
2378 | Addressee lse; | 2378 | Addressee lse; |
2379 | QString mCurrentSyncDevice = syncManager->getCurrentSyncDevice(); | 2379 | QString mCurrentSyncDevice = syncManager->getCurrentSyncDevice(); |
2380 | 2380 | ||
2381 | //qDebug("CurrentSyncDevice %s ",mCurrentSyncDevice .latin1() ); | 2381 | //qDebug("CurrentSyncDevice %s ",mCurrentSyncDevice .latin1() ); |
2382 | lse = mAddressBook->findByUid( "last-syncAddressee-"+mCurrentSyncDevice ); | 2382 | lse = mAddressBook->findByUid( "last-syncAddressee-"+mCurrentSyncDevice ); |
2383 | if (lse.isEmpty()) { | 2383 | if (lse.isEmpty()) { |
2384 | qDebug("Creating new last-syncAddressee "); | 2384 | qDebug("Creating new last-syncAddressee "); |
2385 | lse.setUid( "last-syncAddressee-"+mCurrentSyncDevice ); | 2385 | lse.setUid( "last-syncAddressee-"+mCurrentSyncDevice ); |
2386 | QString sum = ""; | 2386 | QString sum = ""; |
2387 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) | 2387 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) |
2388 | sum = "E: "; | 2388 | sum = "E: "; |
2389 | lse.setFamilyName("!"+sum+mCurrentSyncDevice + i18n(" - sync event")); | 2389 | lse.setFamilyName("!"+sum+mCurrentSyncDevice + i18n(" - sync event")); |
2390 | lse.setRevision( mLastAddressbookSync ); | 2390 | lse.setRevision( mLastAddressbookSync ); |
2391 | lse.setCategories( i18n("SyncEvent") ); | 2391 | lse.setCategories( i18n("SyncEvent") ); |
2392 | mAddressBook->insertAddressee( lse ); | 2392 | mAddressBook->insertAddressee( lse ); |
2393 | } | 2393 | } |
2394 | return lse; | 2394 | return lse; |
2395 | } | 2395 | } |
2396 | int KABCore::takeAddressee( KABC::Addressee* local, KABC::Addressee* remote, int mode , bool full ) | 2396 | int KABCore::takeAddressee( KABC::Addressee* local, KABC::Addressee* remote, int mode , bool full ) |
2397 | { | 2397 | { |
2398 | 2398 | ||
2399 | //void setZaurusId(int id); | 2399 | //void setZaurusId(int id); |
2400 | // int zaurusId() const; | 2400 | // int zaurusId() const; |
2401 | // void setZaurusUid(int id); | 2401 | // void setZaurusUid(int id); |
2402 | // int zaurusUid() const; | 2402 | // int zaurusUid() const; |
2403 | // void setZaurusStat(int id); | 2403 | // void setZaurusStat(int id); |
2404 | // int zaurusStat() const; | 2404 | // int zaurusStat() const; |
2405 | // 0 equal | 2405 | // 0 equal |
2406 | // 1 take local | 2406 | // 1 take local |
2407 | // 2 take remote | 2407 | // 2 take remote |
2408 | // 3 cancel | 2408 | // 3 cancel |
2409 | QDateTime lastSync = mLastAddressbookSync; | 2409 | QDateTime lastSync = mLastAddressbookSync; |
2410 | QDateTime localMod = local->revision(); | 2410 | QDateTime localMod = local->revision(); |
2411 | QDateTime remoteMod = remote->revision(); | 2411 | QDateTime remoteMod = remote->revision(); |
2412 | 2412 | ||
2413 | QString mCurrentSyncDevice = syncManager->getCurrentSyncDevice(); | 2413 | QString mCurrentSyncDevice = syncManager->getCurrentSyncDevice(); |
2414 | 2414 | ||
2415 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { | 2415 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { |
2416 | bool remCh, locCh; | 2416 | bool remCh, locCh; |
2417 | remCh = ( remote->getCsum(mCurrentSyncDevice) != local->getCsum(mCurrentSyncDevice) ); | 2417 | remCh = ( remote->getCsum(mCurrentSyncDevice) != local->getCsum(mCurrentSyncDevice) ); |
2418 | 2418 | ||
2419 | //qDebug("loc %s rem %s", local->getCsum(mCurrentSyncDevice).latin1(), remote->getCsum(mCurrentSyncDevice).latin1() ); | 2419 | //qDebug("loc %s rem %s", local->getCsum(mCurrentSyncDevice).latin1(), remote->getCsum(mCurrentSyncDevice).latin1() ); |
2420 | locCh = ( localMod > mLastAddressbookSync ); | 2420 | locCh = ( localMod > mLastAddressbookSync ); |
2421 | if ( !remCh && ! locCh ) { | 2421 | if ( !remCh && ! locCh ) { |
2422 | //qDebug("both not changed "); | 2422 | //qDebug("both not changed "); |
2423 | lastSync = localMod.addDays(1); | 2423 | lastSync = localMod.addDays(1); |
2424 | if ( mode <= SYNC_PREF_ASK ) | 2424 | if ( mode <= SYNC_PREF_ASK ) |
2425 | return 0; | 2425 | return 0; |
2426 | } else { | 2426 | } else { |
2427 | if ( locCh ) { | 2427 | if ( locCh ) { |
2428 | //qDebug("loc changed %s %s", localMod.toString().latin1(), mLastAddressbookSync.toString().latin1()); | 2428 | //qDebug("loc changed %s %s", localMod.toString().latin1(), mLastAddressbookSync.toString().latin1()); |
2429 | lastSync = localMod.addDays( -1 ); | 2429 | lastSync = localMod.addDays( -1 ); |
2430 | if ( !remCh ) | 2430 | if ( !remCh ) |
2431 | remoteMod =( lastSync.addDays( -1 ) ); | 2431 | remoteMod =( lastSync.addDays( -1 ) ); |
2432 | } else { | 2432 | } else { |
2433 | //qDebug(" not loc changed "); | 2433 | //qDebug(" not loc changed "); |
2434 | lastSync = localMod.addDays( 1 ); | 2434 | lastSync = localMod.addDays( 1 ); |
2435 | if ( remCh ) | 2435 | if ( remCh ) |
2436 | remoteMod =( lastSync.addDays( 1 ) ); | 2436 | remoteMod =( lastSync.addDays( 1 ) ); |
2437 | 2437 | ||
2438 | } | 2438 | } |
2439 | } | 2439 | } |
2440 | full = true; | 2440 | full = true; |
2441 | if ( mode < SYNC_PREF_ASK ) | 2441 | if ( mode < SYNC_PREF_ASK ) |
2442 | mode = SYNC_PREF_ASK; | 2442 | mode = SYNC_PREF_ASK; |
2443 | } else { | 2443 | } else { |
2444 | if ( localMod == remoteMod ) | 2444 | if ( localMod == remoteMod ) |
2445 | return 0; | 2445 | return 0; |
2446 | 2446 | ||
2447 | } | 2447 | } |
2448 | // qDebug(" %d %d conflict on %s %s ", mode, full, local->summary().latin1(), remote->summary().latin1() ); | 2448 | // qDebug(" %d %d conflict on %s %s ", mode, full, local->summary().latin1(), remote->summary().latin1() ); |
2449 | 2449 | ||
2450 | //qDebug("%s %d %s %d", local->lastModified().toString().latin1() , localMod, remote->lastModified().toString().latin1(), remoteMod); | 2450 | //qDebug("%s %d %s %d", local->lastModified().toString().latin1() , localMod, remote->lastModified().toString().latin1(), remoteMod); |
2451 | //qDebug("%d %d %d %d ", local->lastModified().time().second(), local->lastModified().time().msec(), remote->lastModified().time().second(), remote->lastModified().time().msec() ); | 2451 | //qDebug("%d %d %d %d ", local->lastModified().time().second(), local->lastModified().time().msec(), remote->lastModified().time().second(), remote->lastModified().time().msec() ); |
2452 | //full = true; //debug only | 2452 | //full = true; //debug only |
2453 | if ( full ) { | 2453 | if ( full ) { |
2454 | bool equ = ( (*local) == (*remote) ); | 2454 | bool equ = ( (*local) == (*remote) ); |
2455 | if ( equ ) { | 2455 | if ( equ ) { |
2456 | //qDebug("equal "); | 2456 | //qDebug("equal "); |
2457 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { | 2457 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { |
2458 | local->setCsum( mCurrentSyncDevice, remote->getCsum(mCurrentSyncDevice) ); | 2458 | local->setCsum( mCurrentSyncDevice, remote->getCsum(mCurrentSyncDevice) ); |
2459 | } | 2459 | } |
2460 | if ( mode < SYNC_PREF_FORCE_LOCAL ) | 2460 | if ( mode < SYNC_PREF_FORCE_LOCAL ) |
2461 | return 0; | 2461 | return 0; |
2462 | 2462 | ||
2463 | }//else //debug only | 2463 | }//else //debug only |
2464 | //qDebug("not equal %s %s ", local->summary().latin1(), remote->summary().latin1()); | 2464 | //qDebug("not equal %s %s ", local->summary().latin1(), remote->summary().latin1()); |
2465 | } | 2465 | } |
2466 | int result; | 2466 | int result; |
2467 | bool localIsNew; | 2467 | bool localIsNew; |
2468 | //qDebug("%s -- %s mLastCalendarSync %s lastsync %s --- local %s remote %s ",local->summary().latin1(), remote->summary().latin1(),mLastCalendarSync.toString().latin1() ,lastSync.toString().latin1() , local->lastModified().toString().latin1() , remote->lastModified().toString().latin1() ); | 2468 | //qDebug("%s -- %s mLastCalendarSync %s lastsync %s --- local %s remote %s ",local->summary().latin1(), remote->summary().latin1(),mLastCalendarSync.toString().latin1() ,lastSync.toString().latin1() , local->lastModified().toString().latin1() , remote->lastModified().toString().latin1() ); |
2469 | 2469 | ||
2470 | if ( full && mode < SYNC_PREF_NEWEST ) | 2470 | if ( full && mode < SYNC_PREF_NEWEST ) |
2471 | mode = SYNC_PREF_ASK; | 2471 | mode = SYNC_PREF_ASK; |
2472 | 2472 | ||
2473 | switch( mode ) { | 2473 | switch( mode ) { |
2474 | case SYNC_PREF_LOCAL: | 2474 | case SYNC_PREF_LOCAL: |
2475 | if ( lastSync > remoteMod ) | 2475 | if ( lastSync > remoteMod ) |
2476 | return 1; | 2476 | return 1; |
2477 | if ( lastSync > localMod ) | 2477 | if ( lastSync > localMod ) |
2478 | return 2; | 2478 | return 2; |
2479 | return 1; | 2479 | return 1; |
2480 | break; | 2480 | break; |
2481 | case SYNC_PREF_REMOTE: | 2481 | case SYNC_PREF_REMOTE: |
2482 | if ( lastSync > remoteMod ) | 2482 | if ( lastSync > remoteMod ) |
2483 | return 1; | 2483 | return 1; |
2484 | if ( lastSync > localMod ) | 2484 | if ( lastSync > localMod ) |
2485 | return 2; | 2485 | return 2; |
2486 | return 2; | 2486 | return 2; |
2487 | break; | 2487 | break; |
2488 | case SYNC_PREF_NEWEST: | 2488 | case SYNC_PREF_NEWEST: |
2489 | if ( localMod > remoteMod ) | 2489 | if ( localMod > remoteMod ) |
2490 | return 1; | 2490 | return 1; |
2491 | else | 2491 | else |
2492 | return 2; | 2492 | return 2; |
2493 | break; | 2493 | break; |
2494 | case SYNC_PREF_ASK: | 2494 | case SYNC_PREF_ASK: |
2495 | //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() ); | 2495 | //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() ); |
2496 | if ( lastSync > remoteMod ) | 2496 | if ( lastSync > remoteMod ) |
2497 | return 1; | 2497 | return 1; |
2498 | if ( lastSync > localMod ) | 2498 | if ( lastSync > localMod ) |
2499 | return 2; | 2499 | return 2; |
2500 | localIsNew = localMod >= remoteMod; | 2500 | localIsNew = localMod >= remoteMod; |
2501 | //qDebug("conflict! ************************************** "); | 2501 | //qDebug("conflict! ************************************** "); |
2502 | { | 2502 | { |
2503 | KPIM::AddresseeChooser acd ( *local,*remote, localIsNew , this ); | 2503 | KPIM::AddresseeChooser acd ( *local,*remote, localIsNew , this ); |
2504 | result = acd.executeD(localIsNew); | 2504 | result = acd.executeD(localIsNew); |
2505 | return result; | 2505 | return result; |
2506 | } | 2506 | } |
2507 | break; | 2507 | break; |
2508 | case SYNC_PREF_FORCE_LOCAL: | 2508 | case SYNC_PREF_FORCE_LOCAL: |
2509 | return 1; | 2509 | return 1; |
2510 | break; | 2510 | break; |
2511 | case SYNC_PREF_FORCE_REMOTE: | 2511 | case SYNC_PREF_FORCE_REMOTE: |
2512 | return 2; | 2512 | return 2; |
2513 | break; | 2513 | break; |
2514 | 2514 | ||
2515 | default: | 2515 | default: |
2516 | // SYNC_PREF_TAKE_BOTH not implemented | 2516 | // SYNC_PREF_TAKE_BOTH not implemented |
2517 | break; | 2517 | break; |
2518 | } | 2518 | } |
2519 | return 0; | 2519 | return 0; |
2520 | } | 2520 | } |
2521 | 2521 | ||
2522 | 2522 | ||
2523 | bool KABCore::synchronizeAddressbooks( KABC::AddressBook* local, KABC::AddressBook* remote,int mode) | 2523 | bool KABCore::synchronizeAddressbooks( KABC::AddressBook* local, KABC::AddressBook* remote,int mode) |
2524 | { | 2524 | { |
2525 | bool syncOK = true; | 2525 | bool syncOK = true; |
2526 | int addedAddressee = 0; | 2526 | int addedAddressee = 0; |
2527 | int addedAddresseeR = 0; | 2527 | int addedAddresseeR = 0; |
2528 | int deletedAddresseeR = 0; | 2528 | int deletedAddresseeR = 0; |
2529 | int deletedAddresseeL = 0; | 2529 | int deletedAddresseeL = 0; |
2530 | int changedLocal = 0; | 2530 | int changedLocal = 0; |
2531 | int changedRemote = 0; | 2531 | int changedRemote = 0; |
2532 | 2532 | ||
2533 | QString mCurrentSyncName = syncManager->getCurrentSyncName(); | 2533 | QString mCurrentSyncName = syncManager->getCurrentSyncName(); |
2534 | QString mCurrentSyncDevice = syncManager->getCurrentSyncDevice(); | 2534 | QString mCurrentSyncDevice = syncManager->getCurrentSyncDevice(); |
2535 | 2535 | ||
2536 | //QPtrList<Addressee> el = local->rawAddressees(); | 2536 | //QPtrList<Addressee> el = local->rawAddressees(); |
2537 | Addressee addresseeR; | 2537 | Addressee addresseeR; |
2538 | QString uid; | 2538 | QString uid; |
2539 | int take; | 2539 | int take; |
2540 | Addressee addresseeL; | 2540 | Addressee addresseeL; |
2541 | Addressee addresseeRSync; | 2541 | Addressee addresseeRSync; |
2542 | Addressee addresseeLSync; | 2542 | Addressee addresseeLSync; |
2543 | // KABC::Addressee::List addresseeRSyncSharp = remote->getExternLastSyncAddressees(); | 2543 | // KABC::Addressee::List addresseeRSyncSharp = remote->getExternLastSyncAddressees(); |
2544 | //KABC::Addressee::List addresseeLSyncSharp = local->getExternLastSyncAddressees(); | 2544 | //KABC::Addressee::List addresseeLSyncSharp = local->getExternLastSyncAddressees(); |
2545 | bool fullDateRange = false; | 2545 | bool fullDateRange = false; |
2546 | local->resetTempSyncStat(); | 2546 | local->resetTempSyncStat(); |
2547 | mLastAddressbookSync = QDateTime::currentDateTime(); | 2547 | mLastAddressbookSync = QDateTime::currentDateTime(); |
2548 | if ( syncManager->syncWithDesktop() ) { | 2548 | if ( syncManager->syncWithDesktop() ) { |
2549 | // remote->removeSyncInfo( QString());//remove all info | 2549 | // remote->removeSyncInfo( QString());//remove all info |
2550 | if ( KSyncManager::mRequestedSyncEvent.isValid() ) { | 2550 | if ( KSyncManager::mRequestedSyncEvent.isValid() ) { |
2551 | mLastAddressbookSync = KSyncManager::mRequestedSyncEvent; | 2551 | mLastAddressbookSync = KSyncManager::mRequestedSyncEvent; |
2552 | qDebug("using extern time for calendar sync: %s ", mLastAddressbookSync.toString().latin1() ); | 2552 | qDebug("using extern time for calendar sync: %s ", mLastAddressbookSync.toString().latin1() ); |
2553 | } else { | 2553 | } else { |
2554 | qDebug("KSyncManager::mRequestedSyncEvent has invalid datatime "); | 2554 | qDebug("KSyncManager::mRequestedSyncEvent has invalid datatime "); |
2555 | } | 2555 | } |
2556 | } | 2556 | } |
2557 | QDateTime modifiedCalendar = mLastAddressbookSync; | 2557 | QDateTime modifiedCalendar = mLastAddressbookSync; |
2558 | addresseeLSync = getLastSyncAddressee(); | 2558 | addresseeLSync = getLastSyncAddressee(); |
2559 | qDebug("Last Sync %s ", addresseeLSync.revision().toString().latin1()); | 2559 | qDebug("Last Sync %s ", addresseeLSync.revision().toString().latin1()); |
2560 | addresseeR = remote->findByUid("last-syncAddressee-"+mCurrentSyncName ); | 2560 | addresseeR = remote->findByUid("last-syncAddressee-"+mCurrentSyncName ); |
2561 | if ( !addresseeR.isEmpty() ) { | 2561 | if ( !addresseeR.isEmpty() ) { |
2562 | addresseeRSync = addresseeR; | 2562 | addresseeRSync = addresseeR; |
2563 | remote->removeAddressee(addresseeR ); | 2563 | remote->removeAddressee(addresseeR ); |
2564 | 2564 | ||
2565 | } else { | 2565 | } else { |
2566 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { | 2566 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { |
2567 | addresseeRSync = addresseeLSync ; | 2567 | addresseeRSync = addresseeLSync ; |
2568 | } else { | 2568 | } else { |
2569 | qDebug("FULLDATE 1"); | 2569 | qDebug("FULLDATE 1"); |
2570 | fullDateRange = true; | 2570 | fullDateRange = true; |
2571 | Addressee newAdd; | 2571 | Addressee newAdd; |
2572 | addresseeRSync = newAdd; | 2572 | addresseeRSync = newAdd; |
2573 | addresseeRSync.setFamilyName(mCurrentSyncName + i18n(" - sync addressee")); | 2573 | addresseeRSync.setFamilyName(mCurrentSyncName + i18n(" - sync addressee")); |
2574 | addresseeRSync.setUid("last-syncAddressee-"+mCurrentSyncName ); | 2574 | addresseeRSync.setUid("last-syncAddressee-"+mCurrentSyncName ); |
2575 | addresseeRSync.setRevision( mLastAddressbookSync ); | 2575 | addresseeRSync.setRevision( mLastAddressbookSync ); |
2576 | addresseeRSync.setCategories( i18n("SyncAddressee") ); | 2576 | addresseeRSync.setCategories( i18n("SyncAddressee") ); |
2577 | } | 2577 | } |
2578 | } | 2578 | } |
2579 | if ( addresseeLSync.revision() == mLastAddressbookSync ) { | 2579 | if ( addresseeLSync.revision() == mLastAddressbookSync ) { |
2580 | qDebug("FULLDATE 2"); | 2580 | qDebug("FULLDATE 2"); |
2581 | fullDateRange = true; | 2581 | fullDateRange = true; |
2582 | } | 2582 | } |
2583 | if ( ! fullDateRange ) { | 2583 | if ( ! fullDateRange ) { |
2584 | if ( addresseeLSync.revision() != addresseeRSync.revision() ) { | 2584 | if ( addresseeLSync.revision() != addresseeRSync.revision() ) { |
2585 | 2585 | ||
2586 | // qDebug("set fulldate to true %s %s" ,addresseeLSync->dtStart().toString().latin1(), addresseeRSync->dtStart().toString().latin1() ); | 2586 | // qDebug("set fulldate to true %s %s" ,addresseeLSync->dtStart().toString().latin1(), addresseeRSync->dtStart().toString().latin1() ); |
2587 | //qDebug("%d %d %d %d ", addresseeLSync->dtStart().time().second(), addresseeLSync->dtStart().time().msec() , addresseeRSync->dtStart().time().second(), addresseeRSync->dtStart().time().msec()); | 2587 | //qDebug("%d %d %d %d ", addresseeLSync->dtStart().time().second(), addresseeLSync->dtStart().time().msec() , addresseeRSync->dtStart().time().second(), addresseeRSync->dtStart().time().msec()); |
2588 | fullDateRange = true; | 2588 | fullDateRange = true; |
2589 | qDebug("FULLDATE 3 %s %s", addresseeLSync.revision().toString().latin1() , addresseeRSync.revision().toString().latin1() ); | 2589 | qDebug("FULLDATE 3 %s %s", addresseeLSync.revision().toString().latin1() , addresseeRSync.revision().toString().latin1() ); |
2590 | } | 2590 | } |
2591 | } | 2591 | } |
2592 | // fullDateRange = true; // debug only! | 2592 | // fullDateRange = true; // debug only! |
2593 | if ( fullDateRange ) | 2593 | if ( fullDateRange ) |
2594 | mLastAddressbookSync = QDateTime::currentDateTime().addDays( -100*365); | 2594 | mLastAddressbookSync = QDateTime::currentDateTime().addDays( -100*365); |
2595 | else | 2595 | else |
2596 | mLastAddressbookSync = addresseeLSync.revision(); | 2596 | mLastAddressbookSync = addresseeLSync.revision(); |
2597 | // for resyncing if own file has changed | 2597 | // for resyncing if own file has changed |
2598 | // PENDING fixme later when implemented | 2598 | // PENDING fixme later when implemented |
2599 | #if 0 | 2599 | #if 0 |
2600 | if ( mCurrentSyncDevice == "deleteaftersync" ) { | 2600 | if ( mCurrentSyncDevice == "deleteaftersync" ) { |
2601 | mLastAddressbookSync = loadedFileVersion; | 2601 | mLastAddressbookSync = loadedFileVersion; |
2602 | qDebug("setting mLastAddressbookSync "); | 2602 | qDebug("setting mLastAddressbookSync "); |
2603 | } | 2603 | } |
2604 | #endif | 2604 | #endif |
2605 | 2605 | ||
2606 | //qDebug("*************************** "); | 2606 | //qDebug("*************************** "); |
2607 | // qDebug("mLastAddressbookSync %s ",mLastAddressbookSync.toString().latin1() ); | 2607 | // qDebug("mLastAddressbookSync %s ",mLastAddressbookSync.toString().latin1() ); |
2608 | QStringList er = remote->uidList(); | 2608 | QStringList er = remote->uidList(); |
2609 | Addressee inR ;//= er.first(); | 2609 | Addressee inR ;//= er.first(); |
2610 | Addressee inL; | 2610 | Addressee inL; |
2611 | 2611 | ||
2612 | syncManager->showProgressBar(0, i18n("Syncing - close to abort!"), er.count()); | 2612 | syncManager->showProgressBar(0, i18n("Syncing - close to abort!"), er.count()); |
2613 | 2613 | ||
2614 | int modulo = (er.count()/10)+1; | 2614 | int modulo = (er.count()/10)+1; |
2615 | int incCounter = 0; | 2615 | int incCounter = 0; |
2616 | while ( incCounter < er.count()) { | 2616 | while ( incCounter < er.count()) { |
2617 | if (syncManager->isProgressBarCanceled()) | 2617 | if (syncManager->isProgressBarCanceled()) |
2618 | return false; | 2618 | return false; |
2619 | if ( incCounter % modulo == 0 ) | 2619 | if ( incCounter % modulo == 0 ) |
2620 | syncManager->showProgressBar(incCounter); | 2620 | syncManager->showProgressBar(incCounter); |
2621 | 2621 | ||
2622 | uid = er[ incCounter ]; | 2622 | uid = er[ incCounter ]; |
2623 | bool skipIncidence = false; | 2623 | bool skipIncidence = false; |
2624 | if ( uid.left(19) == QString("last-syncAddressee-") ) | 2624 | if ( uid.left(19) == QString("last-syncAddressee-") ) |
2625 | skipIncidence = true; | 2625 | skipIncidence = true; |
2626 | QString idS,OidS; | 2626 | QString idS,OidS; |
2627 | qApp->processEvents(); | 2627 | qApp->processEvents(); |
2628 | if ( !skipIncidence ) { | 2628 | if ( !skipIncidence ) { |
2629 | inL = local->findByUid( uid ); | 2629 | inL = local->findByUid( uid ); |
2630 | inR = remote->findByUid( uid ); | 2630 | inR = remote->findByUid( uid ); |
2631 | //inL.setResource( 0 ); | 2631 | //inL.setResource( 0 ); |
2632 | //inR.setResource( 0 ); | 2632 | //inR.setResource( 0 ); |
2633 | if ( !inL.isEmpty() ) { // maybe conflict - same uid in both calendars | 2633 | if ( !inL.isEmpty() ) { // maybe conflict - same uid in both calendars |
2634 | if ( !inL.resource() || inL.resource()->includeInSync() ) { | 2634 | if ( !inL.resource() || inL.resource()->includeInSync() ) { |
2635 | if ( take = takeAddressee( &inL, &inR, mode, fullDateRange ) ) { | 2635 | if ( take = takeAddressee( &inL, &inR, mode, fullDateRange ) ) { |
2636 | //qDebug("take %d %s ", take, inL.summary().latin1()); | 2636 | //qDebug("take %d %s ", take, inL.summary().latin1()); |
2637 | if ( take == 3 ) | 2637 | if ( take == 3 ) |
2638 | return false; | 2638 | return false; |
2639 | if ( take == 1 ) {// take local ********************** | 2639 | if ( take == 1 ) {// take local ********************** |
2640 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { | 2640 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { |
2641 | inL.setCsum( mCurrentSyncDevice, inR.getCsum(mCurrentSyncDevice) ); | 2641 | inL.setCsum( mCurrentSyncDevice, inR.getCsum(mCurrentSyncDevice) ); |
2642 | inL.setID( mCurrentSyncDevice, inR.getID(mCurrentSyncDevice) ); | 2642 | inL.setID( mCurrentSyncDevice, inR.getID(mCurrentSyncDevice) ); |
2643 | local->insertAddressee( inL, false ); | 2643 | local->insertAddressee( inL, false ); |
2644 | idS = inR.externalUID(); | 2644 | idS = inR.externalUID(); |
2645 | OidS = inR.originalExternalUID(); | 2645 | OidS = inR.originalExternalUID(); |
2646 | } | 2646 | } |
2647 | else | 2647 | else |
2648 | idS = inR.IDStr(); | 2648 | idS = inR.IDStr(); |
2649 | remote->removeAddressee( inR ); | 2649 | remote->removeAddressee( inR ); |
2650 | inR = inL; | 2650 | inR = inL; |
2651 | inR.setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); | 2651 | inR.setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); |
2652 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { | 2652 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { |
2653 | inR.setOriginalExternalUID( OidS ); | 2653 | inR.setOriginalExternalUID( OidS ); |
2654 | inR.setExternalUID( idS ); | 2654 | inR.setExternalUID( idS ); |
2655 | if ( syncManager->syncWithDesktop() ) | 2655 | if ( syncManager->syncWithDesktop() ) |
2656 | inR.setIDStr("changed" ); | 2656 | inR.setIDStr("changed" ); |
2657 | //inR.insertCustom( "KADDRESSBOOK", "X-KDESYNC","changed" ); | 2657 | //inR.insertCustom( "KADDRESSBOOK", "X-KDESYNC","changed" ); |
2658 | } else { | 2658 | } else { |
2659 | inR.setIDStr( idS ); | 2659 | inR.setIDStr( idS ); |
2660 | } | 2660 | } |
2661 | inR.setResource( 0 ); | 2661 | inR.setResource( 0 ); |
2662 | remote->insertAddressee( inR , false); | 2662 | remote->insertAddressee( inR , false); |
2663 | ++changedRemote; | 2663 | ++changedRemote; |
2664 | } else { // take == 2 take remote ********************** | 2664 | } else { // take == 2 take remote ********************** |
2665 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { | 2665 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { |
2666 | if ( inR.revision().date().year() < 2004 ) | 2666 | if ( inR.revision().date().year() < 2004 ) |
2667 | inR.setRevision( modifiedCalendar ); | 2667 | inR.setRevision( modifiedCalendar ); |
2668 | } | 2668 | } |
2669 | idS = inL.IDStr(); | 2669 | idS = inL.IDStr(); |
2670 | local->removeAddressee( inL ); | 2670 | local->removeAddressee( inL ); |
2671 | inL = inR; | 2671 | inL = inR; |
2672 | inL.setIDStr( idS ); | 2672 | inL.setIDStr( idS ); |
2673 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { | 2673 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { |
2674 | inL.setCsum( mCurrentSyncDevice, inR.getCsum(mCurrentSyncDevice) ); | 2674 | inL.setCsum( mCurrentSyncDevice, inR.getCsum(mCurrentSyncDevice) ); |
2675 | inL.setID( mCurrentSyncDevice, inR.getID(mCurrentSyncDevice) ); | 2675 | inL.setID( mCurrentSyncDevice, inR.getID(mCurrentSyncDevice) ); |
2676 | } | 2676 | } |
2677 | inL.setResource( 0 ); | 2677 | inL.setResource( 0 ); |
2678 | local->insertAddressee( inL , false ); | 2678 | local->insertAddressee( inL , false ); |
2679 | ++changedLocal; | 2679 | ++changedLocal; |
2680 | } | 2680 | } |
2681 | } | 2681 | } |
2682 | } | 2682 | } |
2683 | } else { // no conflict ********** add or delete remote | 2683 | } else { // no conflict ********** add or delete remote |
2684 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { | 2684 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { |
2685 | QString des = addresseeLSync.note(); | 2685 | QString des = addresseeLSync.note(); |
2686 | if ( des.find( inR.getID(mCurrentSyncDevice) +"," ) >= 0 && mode != 5) { // delete it | 2686 | if ( des.find( inR.getID(mCurrentSyncDevice) +"," ) >= 0 && mode != 5) { // delete it |
2687 | inR.setTempSyncStat( SYNC_TEMPSTATE_DELETE ); | 2687 | inR.setTempSyncStat( SYNC_TEMPSTATE_DELETE ); |
2688 | remote->insertAddressee( inR, false ); | 2688 | remote->insertAddressee( inR, false ); |
2689 | ++deletedAddresseeR; | 2689 | ++deletedAddresseeR; |
2690 | } else { | 2690 | } else { |
2691 | inR.setRevision( modifiedCalendar ); | 2691 | inR.setRevision( modifiedCalendar ); |
2692 | remote->insertAddressee( inR, false ); | 2692 | remote->insertAddressee( inR, false ); |
2693 | inL = inR; | 2693 | inL = inR; |
2694 | inL.setIDStr( ":" ); | 2694 | inL.setIDStr( ":" ); |
2695 | inL.setCsum( mCurrentSyncDevice, inR.getCsum(mCurrentSyncDevice) ); | 2695 | inL.setCsum( mCurrentSyncDevice, inR.getCsum(mCurrentSyncDevice) ); |
2696 | inL.setID( mCurrentSyncDevice, inR.getID(mCurrentSyncDevice) ); | 2696 | inL.setID( mCurrentSyncDevice, inR.getID(mCurrentSyncDevice) ); |
2697 | inL.setResource( 0 ); | 2697 | inL.setResource( 0 ); |
2698 | local->insertAddressee( inL , false); | 2698 | local->insertAddressee( inL , false); |
2699 | ++addedAddressee; | 2699 | ++addedAddressee; |
2700 | } | 2700 | } |
2701 | } else { | 2701 | } else { |
2702 | if ( inR.revision() > mLastAddressbookSync || mode == 5 ) { | 2702 | if ( inR.revision() > mLastAddressbookSync || mode == 5 ) { |
2703 | inR.setRevision( modifiedCalendar ); | 2703 | inR.setRevision( modifiedCalendar ); |
2704 | remote->insertAddressee( inR, false ); | 2704 | remote->insertAddressee( inR, false ); |
2705 | inR.setResource( 0 ); | 2705 | inR.setResource( 0 ); |
2706 | local->insertAddressee( inR, false ); | 2706 | local->insertAddressee( inR, false ); |
2707 | ++addedAddressee; | 2707 | ++addedAddressee; |
2708 | } else { | 2708 | } else { |
2709 | // pending checkExternSyncAddressee(addresseeRSyncSharp, inR); | 2709 | // pending checkExternSyncAddressee(addresseeRSyncSharp, inR); |
2710 | remote->removeAddressee( inR ); | 2710 | remote->removeAddressee( inR ); |
2711 | ++deletedAddresseeR; | 2711 | ++deletedAddresseeR; |
2712 | } | 2712 | } |
2713 | } | 2713 | } |
2714 | } | 2714 | } |
2715 | } | 2715 | } |
2716 | ++incCounter; | 2716 | ++incCounter; |
2717 | } | 2717 | } |
2718 | er.clear(); | 2718 | er.clear(); |
2719 | QStringList el = local->uidList(); | 2719 | QStringList el = local->uidList(); |
2720 | modulo = (el.count()/10)+1; | 2720 | modulo = (el.count()/10)+1; |
2721 | 2721 | ||
2722 | syncManager->showProgressBar(0, i18n("Add / remove addressees"), el.count()); | 2722 | syncManager->showProgressBar(0, i18n("Add / remove addressees"), el.count()); |
2723 | incCounter = 0; | 2723 | incCounter = 0; |
2724 | while ( incCounter < el.count()) { | 2724 | while ( incCounter < el.count()) { |
2725 | qApp->processEvents(); | 2725 | qApp->processEvents(); |
2726 | if (syncManager->isProgressBarCanceled()) | 2726 | if (syncManager->isProgressBarCanceled()) |
2727 | return false; | 2727 | return false; |
2728 | if ( incCounter % modulo == 0 ) | 2728 | if ( incCounter % modulo == 0 ) |
2729 | syncManager->showProgressBar(incCounter); | 2729 | syncManager->showProgressBar(incCounter); |
2730 | uid = el[ incCounter ]; | 2730 | uid = el[ incCounter ]; |
2731 | bool skipIncidence = false; | 2731 | bool skipIncidence = false; |
2732 | if ( uid.left(19) == QString("last-syncAddressee-") ) | 2732 | if ( uid.left(19) == QString("last-syncAddressee-") ) |
2733 | skipIncidence = true; | 2733 | skipIncidence = true; |
2734 | if ( !skipIncidence ) { | 2734 | if ( !skipIncidence ) { |
2735 | inL = local->findByUid( uid ); | 2735 | inL = local->findByUid( uid ); |
2736 | if ( !inL.resource() || inL.resource()->includeInSync() ) { | 2736 | if ( !inL.resource() || inL.resource()->includeInSync() ) { |
2737 | inR = remote->findByUid( uid ); | 2737 | inR = remote->findByUid( uid ); |
2738 | if ( inR.isEmpty() ) { / no conflict ********** add or delete local | 2738 | if ( inR.isEmpty() ) { // no conflict ********** add or delete local |
2739 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { | 2739 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { |
2740 | if ( !inL.getID(mCurrentSyncDevice).isEmpty() && mode != 4 ) { | 2740 | if ( !inL.getID(mCurrentSyncDevice).isEmpty() && mode != 4 ) { |
2741 | // pending checkExternSyncAddressee(addresseeLSyncSharp, inL); | 2741 | // pending checkExternSyncAddressee(addresseeLSyncSharp, inL); |
2742 | local->removeAddressee( inL ); | 2742 | local->removeAddressee( inL ); |
2743 | ++deletedAddresseeL; | 2743 | ++deletedAddresseeL; |
2744 | } else { | 2744 | } else { |
2745 | if ( ! syncManager->mWriteBackExistingOnly ) { | 2745 | if ( ! syncManager->mWriteBackExistingOnly ) { |
2746 | inL.removeID(mCurrentSyncDevice ); | 2746 | inL.removeID(mCurrentSyncDevice ); |
2747 | ++addedAddresseeR; | 2747 | ++addedAddresseeR; |
2748 | inL.setRevision( modifiedCalendar ); | 2748 | inL.setRevision( modifiedCalendar ); |
2749 | local->insertAddressee( inL, false ); | 2749 | local->insertAddressee( inL, false ); |
2750 | inR = inL; | 2750 | inR = inL; |
2751 | inR.setTempSyncStat( SYNC_TEMPSTATE_ADDED_EXTERNAL ); | 2751 | inR.setTempSyncStat( SYNC_TEMPSTATE_ADDED_EXTERNAL ); |
2752 | inR.setResource( 0 ); | 2752 | inR.setResource( 0 ); |
2753 | remote->insertAddressee( inR, false ); | 2753 | remote->insertAddressee( inR, false ); |
2754 | } | 2754 | } |
2755 | } | 2755 | } |
2756 | } else { | 2756 | } else { |
2757 | if ( inL.revision() < mLastAddressbookSync && mode != 4 ) { | 2757 | if ( inL.revision() < mLastAddressbookSync && mode != 4 ) { |
2758 | // pending checkExternSyncAddressee(addresseeLSyncSharp, inL); | 2758 | // pending checkExternSyncAddressee(addresseeLSyncSharp, inL); |
2759 | local->removeAddressee( inL ); | 2759 | local->removeAddressee( inL ); |
2760 | ++deletedAddresseeL; | 2760 | ++deletedAddresseeL; |
2761 | } else { | 2761 | } else { |
2762 | if ( ! syncManager->mWriteBackExistingOnly ) { | 2762 | if ( ! syncManager->mWriteBackExistingOnly ) { |
2763 | ++addedAddresseeR; | 2763 | ++addedAddresseeR; |
2764 | inL.setRevision( modifiedCalendar ); | 2764 | inL.setRevision( modifiedCalendar ); |
2765 | local->insertAddressee( inL, false ); | 2765 | local->insertAddressee( inL, false ); |
2766 | inR = inL; | 2766 | inR = inL; |
2767 | inR.setIDStr( ":" ); | 2767 | inR.setIDStr( ":" ); |
2768 | inR.setResource( 0 ); | 2768 | inR.setResource( 0 ); |
2769 | remote->insertAddressee( inR, false ); | 2769 | remote->insertAddressee( inR, false ); |
2770 | } | 2770 | } |
2771 | } | 2771 | } |
2772 | } | 2772 | } |
2773 | } | 2773 | } |
2774 | } | 2774 | } |
2775 | } | 2775 | } |
2776 | ++incCounter; | 2776 | ++incCounter; |
2777 | } | 2777 | } |
2778 | el.clear(); | 2778 | el.clear(); |
2779 | syncManager->hideProgressBar(); | 2779 | syncManager->hideProgressBar(); |
2780 | mLastAddressbookSync = QDateTime::currentDateTime().addSecs( 1 ); | 2780 | mLastAddressbookSync = QDateTime::currentDateTime().addSecs( 1 ); |
2781 | // get rid of micro seconds | 2781 | // get rid of micro seconds |
2782 | QTime t = mLastAddressbookSync.time(); | 2782 | QTime t = mLastAddressbookSync.time(); |
2783 | mLastAddressbookSync.setTime( QTime (t.hour (), t.minute (), t.second () ) ); | 2783 | mLastAddressbookSync.setTime( QTime (t.hour (), t.minute (), t.second () ) ); |
2784 | addresseeLSync.setRevision( mLastAddressbookSync ); | 2784 | addresseeLSync.setRevision( mLastAddressbookSync ); |
2785 | addresseeRSync.setRevision( mLastAddressbookSync ); | 2785 | addresseeRSync.setRevision( mLastAddressbookSync ); |
2786 | addresseeRSync.setRole( i18n("!Remote from: ")+mCurrentSyncName ) ; | 2786 | addresseeRSync.setRole( i18n("!Remote from: ")+mCurrentSyncName ) ; |
2787 | addresseeLSync.setRole(i18n("!Local from: ") + mCurrentSyncName ); | 2787 | addresseeLSync.setRole(i18n("!Local from: ") + mCurrentSyncName ); |
2788 | addresseeRSync.setGivenName( i18n("!DO NOT EDIT!") ) ; | 2788 | addresseeRSync.setGivenName( i18n("!DO NOT EDIT!") ) ; |
2789 | addresseeLSync.setGivenName(i18n("!DO NOT EDIT!") ); | 2789 | addresseeLSync.setGivenName(i18n("!DO NOT EDIT!") ); |
2790 | addresseeRSync.setOrganization( "!"+mLastAddressbookSync.toString() ) ; | 2790 | addresseeRSync.setOrganization( "!"+mLastAddressbookSync.toString() ) ; |
2791 | addresseeLSync.setOrganization("!"+ mLastAddressbookSync.toString() ); | 2791 | addresseeLSync.setOrganization("!"+ mLastAddressbookSync.toString() ); |
2792 | addresseeRSync.setNote( "" ) ; | 2792 | addresseeRSync.setNote( "" ) ; |
2793 | addresseeLSync.setNote( "" ); | 2793 | addresseeLSync.setNote( "" ); |
2794 | 2794 | ||
2795 | if ( mGlobalSyncMode == SYNC_MODE_NORMAL) | 2795 | if ( mGlobalSyncMode == SYNC_MODE_NORMAL) |
2796 | remote->insertAddressee( addresseeRSync, false ); | 2796 | remote->insertAddressee( addresseeRSync, false ); |
2797 | local->insertAddressee( addresseeLSync, false ); | 2797 | local->insertAddressee( addresseeLSync, false ); |
2798 | QString mes; | 2798 | QString mes; |
2799 | 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 ); | 2799 | 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 ); |
2800 | qDebug( mes ); | 2800 | qDebug( mes ); |
2801 | if ( syncManager->mShowSyncSummary ) { | 2801 | if ( syncManager->mShowSyncSummary ) { |
2802 | if ( KMessageBox::Cancel == KMessageBox::warningContinueCancel(this, mes, | 2802 | if ( KMessageBox::Cancel == KMessageBox::warningContinueCancel(this, mes, |
2803 | i18n("KA/Pi Synchronization"),i18n("Write back"))) { | 2803 | i18n("KA/Pi Synchronization"),i18n("Write back"))) { |
2804 | qDebug("cancelled "); | 2804 | qDebug("cancelled "); |
2805 | return false; | 2805 | return false; |
2806 | } | 2806 | } |
2807 | } | 2807 | } |
2808 | return syncOK; | 2808 | return syncOK; |
2809 | } | 2809 | } |
2810 | 2810 | ||
2811 | 2811 | ||
2812 | //this is a overwritten callbackmethods from the syncinterface | 2812 | //this is a overwritten callbackmethods from the syncinterface |
2813 | bool KABCore::sync(KSyncManager* manager, QString filename, int mode) | 2813 | bool KABCore::sync(KSyncManager* manager, QString filename, int mode) |
2814 | { | 2814 | { |
2815 | 2815 | ||
2816 | //pending prepare addresseeview for output | 2816 | //pending prepare addresseeview for output |
2817 | //pending detect, if remote file has REV field. if not switch to external sync | 2817 | //pending detect, if remote file has REV field. if not switch to external sync |
2818 | mGlobalSyncMode = SYNC_MODE_NORMAL; | 2818 | mGlobalSyncMode = SYNC_MODE_NORMAL; |
2819 | QString mCurrentSyncDevice = manager->getCurrentSyncDevice(); | 2819 | QString mCurrentSyncDevice = manager->getCurrentSyncDevice(); |
2820 | 2820 | ||
2821 | AddressBook abLocal(filename,"syncContact"); | 2821 | AddressBook abLocal(filename,"syncContact"); |
2822 | bool syncOK = false; | 2822 | bool syncOK = false; |
2823 | if ( abLocal.load() ) { | 2823 | if ( abLocal.load() ) { |
2824 | qDebug("AB loaded %s,sync mode %d",filename.latin1(), mode ); | 2824 | qDebug("AB loaded %s,sync mode %d",filename.latin1(), mode ); |
2825 | bool external = false; | 2825 | bool external = false; |
2826 | bool isXML = false; | 2826 | bool isXML = false; |
2827 | if ( filename.right(4) == ".xml") { | 2827 | if ( filename.right(4) == ".xml") { |
2828 | mGlobalSyncMode = SYNC_MODE_EXTERNAL; | 2828 | mGlobalSyncMode = SYNC_MODE_EXTERNAL; |
2829 | isXML = true; | 2829 | isXML = true; |
2830 | abLocal.preExternSync( mAddressBook ,mCurrentSyncDevice, true ); | 2830 | abLocal.preExternSync( mAddressBook ,mCurrentSyncDevice, true ); |
2831 | } else { | 2831 | } else { |
2832 | external = !manager->mIsKapiFile; | 2832 | external = !manager->mIsKapiFile; |
2833 | if ( external ) { | 2833 | if ( external ) { |
2834 | qDebug("Setting vcf mode to external "); | 2834 | qDebug("Setting vcf mode to external "); |
2835 | mGlobalSyncMode = SYNC_MODE_EXTERNAL; | 2835 | mGlobalSyncMode = SYNC_MODE_EXTERNAL; |
2836 | AddressBook::Iterator it; | 2836 | AddressBook::Iterator it; |
2837 | for ( it = abLocal.begin(); it != abLocal.end(); ++it ) { | 2837 | for ( it = abLocal.begin(); it != abLocal.end(); ++it ) { |
2838 | (*it).setID( mCurrentSyncDevice, (*it).uid() ); | 2838 | (*it).setID( mCurrentSyncDevice, (*it).uid() ); |
2839 | (*it).computeCsum( mCurrentSyncDevice ); | 2839 | (*it).computeCsum( mCurrentSyncDevice ); |
2840 | } | 2840 | } |
2841 | } | 2841 | } |
2842 | } | 2842 | } |
2843 | //AddressBook::Iterator it; | 2843 | //AddressBook::Iterator it; |
2844 | //QStringList vcards; | 2844 | //QStringList vcards; |
2845 | //for ( it = abLocal.begin(); it != abLocal.end(); ++it ) { | 2845 | //for ( it = abLocal.begin(); it != abLocal.end(); ++it ) { |
2846 | // qDebug("Name %s ", (*it).familyName().latin1()); | 2846 | // qDebug("Name %s ", (*it).familyName().latin1()); |
2847 | //} | 2847 | //} |
2848 | syncOK = synchronizeAddressbooks( mAddressBook, &abLocal, mode ); | 2848 | syncOK = synchronizeAddressbooks( mAddressBook, &abLocal, mode ); |
2849 | if ( syncOK ) { | 2849 | if ( syncOK ) { |
2850 | if ( syncManager->mWriteBackFile ) | 2850 | if ( syncManager->mWriteBackFile ) |
2851 | { | 2851 | { |
2852 | if ( external ) | 2852 | if ( external ) |
2853 | abLocal.removeSyncAddressees( !isXML); | 2853 | abLocal.removeSyncAddressees( !isXML); |
2854 | qDebug("Saving remote AB "); | 2854 | qDebug("Saving remote AB "); |
2855 | if ( ! abLocal.saveAB()) | 2855 | if ( ! abLocal.saveAB()) |
2856 | qDebug("Error writing back AB to file "); | 2856 | qDebug("Error writing back AB to file "); |
2857 | if ( external ) { | 2857 | if ( external ) { |
2858 | // afterwrite processing | 2858 | // afterwrite processing |
2859 | abLocal.postExternSync( mAddressBook,mCurrentSyncDevice ,isXML); | 2859 | abLocal.postExternSync( mAddressBook,mCurrentSyncDevice ,isXML); |
2860 | } | 2860 | } |
2861 | } | 2861 | } |
2862 | } | 2862 | } |
2863 | setModified(); | 2863 | setModified(); |
2864 | 2864 | ||
2865 | } | 2865 | } |
2866 | if ( syncOK ) | 2866 | if ( syncOK ) |
2867 | mViewManager->refreshView(); | 2867 | mViewManager->refreshView(); |
2868 | return syncOK; | 2868 | return syncOK; |
2869 | 2869 | ||
2870 | } | 2870 | } |
2871 | void KABCore::removeSyncInfo( QString syncProfile) | 2871 | void KABCore::removeSyncInfo( QString syncProfile) |
2872 | { | 2872 | { |
2873 | qDebug("AB:removeSyncInfo for profile %s ", syncProfile.latin1()); | 2873 | qDebug("AB:removeSyncInfo for profile %s ", syncProfile.latin1()); |
2874 | mAddressBook->removeSyncInfo( syncProfile ); | 2874 | mAddressBook->removeSyncInfo( syncProfile ); |
2875 | setModified(); | 2875 | setModified(); |
2876 | } | 2876 | } |
2877 | 2877 | ||
2878 | 2878 | ||
2879 | //this is a overwritten callbackmethods from the syncinterface | 2879 | //this is a overwritten callbackmethods from the syncinterface |
2880 | bool KABCore::syncExternal(KSyncManager* manager, QString resource) | 2880 | bool KABCore::syncExternal(KSyncManager* manager, QString resource) |
2881 | { | 2881 | { |
2882 | if ( resource == "phone" ) | 2882 | if ( resource == "phone" ) |
2883 | return syncPhone(); | 2883 | return syncPhone(); |
2884 | disableBR( true ); | 2884 | disableBR( true ); |
2885 | QString mCurrentSyncDevice = manager->getCurrentSyncDevice(); | 2885 | QString mCurrentSyncDevice = manager->getCurrentSyncDevice(); |
2886 | 2886 | ||
2887 | AddressBook abLocal( resource,"syncContact"); | 2887 | AddressBook abLocal( resource,"syncContact"); |
2888 | bool syncOK = false; | 2888 | bool syncOK = false; |
2889 | if ( abLocal.load() ) { | 2889 | if ( abLocal.load() ) { |
2890 | qDebug("AB sharp loaded ,sync device %s",mCurrentSyncDevice.latin1()); | 2890 | qDebug("AB sharp loaded ,sync device %s",mCurrentSyncDevice.latin1()); |
2891 | mGlobalSyncMode = SYNC_MODE_EXTERNAL; | 2891 | mGlobalSyncMode = SYNC_MODE_EXTERNAL; |
2892 | abLocal.preExternSync( mAddressBook ,mCurrentSyncDevice, false ); | 2892 | abLocal.preExternSync( mAddressBook ,mCurrentSyncDevice, false ); |
2893 | syncOK = synchronizeAddressbooks( mAddressBook, &abLocal, syncManager->mSyncAlgoPrefs ); | 2893 | syncOK = synchronizeAddressbooks( mAddressBook, &abLocal, syncManager->mSyncAlgoPrefs ); |
2894 | if ( syncOK ) { | 2894 | if ( syncOK ) { |
2895 | if ( syncManager->mWriteBackFile ) { | 2895 | if ( syncManager->mWriteBackFile ) { |
2896 | abLocal.removeSyncAddressees( false ); | 2896 | abLocal.removeSyncAddressees( false ); |
2897 | abLocal.saveAB(); | 2897 | abLocal.saveAB(); |
2898 | abLocal.postExternSync( mAddressBook,mCurrentSyncDevice, true ); | 2898 | abLocal.postExternSync( mAddressBook,mCurrentSyncDevice, true ); |
2899 | } | 2899 | } |
2900 | } else | 2900 | } else |
2901 | message( i18n("Sync cancelled or failed.") ); | 2901 | message( i18n("Sync cancelled or failed.") ); |
2902 | setModified(); | 2902 | setModified(); |
2903 | } | 2903 | } |
2904 | if ( syncOK ) | 2904 | if ( syncOK ) |
2905 | mViewManager->refreshView(); | 2905 | mViewManager->refreshView(); |
2906 | disableBR( false ); | 2906 | disableBR( false ); |
2907 | return syncOK; | 2907 | return syncOK; |
2908 | 2908 | ||
2909 | } | 2909 | } |
2910 | void KABCore::message( QString m ) | 2910 | void KABCore::message( QString m ) |
2911 | { | 2911 | { |
2912 | topLevelWidget()->setCaption( m ); | 2912 | topLevelWidget()->setCaption( m ); |
2913 | mMessageTimer->start( 15000, true ); | 2913 | mMessageTimer->start( 15000, true ); |
2914 | } | 2914 | } |
2915 | bool KABCore::syncPhone() | 2915 | bool KABCore::syncPhone() |
2916 | { | 2916 | { |
2917 | QString mCurrentSyncDevice = syncManager->getCurrentSyncDevice(); | 2917 | QString mCurrentSyncDevice = syncManager->getCurrentSyncDevice(); |
2918 | QString fileName = getPhoneFile(); | 2918 | QString fileName = getPhoneFile(); |
2919 | if ( !PhoneAccess::readFromPhone( fileName) ) { | 2919 | if ( !PhoneAccess::readFromPhone( fileName) ) { |
2920 | message(i18n("Phone access failed!")); | 2920 | message(i18n("Phone access failed!")); |
2921 | return false; | 2921 | return false; |
2922 | } | 2922 | } |
2923 | AddressBook abLocal( fileName,"syncContact"); | 2923 | AddressBook abLocal( fileName,"syncContact"); |
2924 | bool syncOK = false; | 2924 | bool syncOK = false; |
2925 | { | 2925 | { |
2926 | abLocal.importFromFile( fileName ); | 2926 | abLocal.importFromFile( fileName ); |
2927 | qDebug("AB phone loaded ,sync device %s",mCurrentSyncDevice.latin1()); | 2927 | qDebug("AB phone loaded ,sync device %s",mCurrentSyncDevice.latin1()); |
2928 | mGlobalSyncMode = SYNC_MODE_EXTERNAL; | 2928 | mGlobalSyncMode = SYNC_MODE_EXTERNAL; |
2929 | abLocal.preparePhoneSync( mCurrentSyncDevice, true ); | 2929 | abLocal.preparePhoneSync( mCurrentSyncDevice, true ); |
2930 | abLocal.preExternSync( mAddressBook ,mCurrentSyncDevice, true ); | 2930 | abLocal.preExternSync( mAddressBook ,mCurrentSyncDevice, true ); |
2931 | syncOK = synchronizeAddressbooks( mAddressBook, &abLocal, syncManager->mSyncAlgoPrefs ); | 2931 | syncOK = synchronizeAddressbooks( mAddressBook, &abLocal, syncManager->mSyncAlgoPrefs ); |
2932 | if ( syncOK ) { | 2932 | if ( syncOK ) { |
2933 | if ( syncManager->mWriteBackFile ) { | 2933 | if ( syncManager->mWriteBackFile ) { |
2934 | abLocal.removeSyncAddressees( true ); | 2934 | abLocal.removeSyncAddressees( true ); |
2935 | abLocal.saveABphone( fileName ); | 2935 | abLocal.saveABphone( fileName ); |
2936 | abLocal.findNewExtIds( fileName, mCurrentSyncDevice ); | 2936 | abLocal.findNewExtIds( fileName, mCurrentSyncDevice ); |
2937 | //abLocal.preparePhoneSync( mCurrentSyncDevice, false ); | 2937 | //abLocal.preparePhoneSync( mCurrentSyncDevice, false ); |
2938 | abLocal.postExternSync( mAddressBook,mCurrentSyncDevice, true ); | 2938 | abLocal.postExternSync( mAddressBook,mCurrentSyncDevice, true ); |
2939 | } | 2939 | } |
2940 | } | 2940 | } |
2941 | setModified(); | 2941 | setModified(); |
2942 | } | 2942 | } |
2943 | if ( syncOK ) | 2943 | if ( syncOK ) |
2944 | mViewManager->refreshView(); | 2944 | mViewManager->refreshView(); |
2945 | return syncOK; | 2945 | return syncOK; |
2946 | } | 2946 | } |
2947 | void KABCore::getFile( bool success ) | 2947 | void KABCore::getFile( bool success ) |
2948 | { | 2948 | { |
2949 | if ( ! success ) { | 2949 | if ( ! success ) { |
2950 | message( i18n("Error receiving file. Nothing changed!") ); | 2950 | message( i18n("Error receiving file. Nothing changed!") ); |
2951 | return; | 2951 | return; |
2952 | } | 2952 | } |
2953 | int count = mAddressBook->importFromFile( sentSyncFile() , false, true ); | 2953 | int count = mAddressBook->importFromFile( sentSyncFile() , false, true ); |
2954 | if ( count ) | 2954 | if ( count ) |
2955 | setModified( true ); | 2955 | setModified( true ); |
2956 | message( i18n("Pi-Sync successful!") ); | 2956 | message( i18n("Pi-Sync successful!") ); |
2957 | mViewManager->refreshView(); | 2957 | mViewManager->refreshView(); |
2958 | } | 2958 | } |
2959 | void KABCore::syncFileRequest() | 2959 | void KABCore::syncFileRequest() |
2960 | { | 2960 | { |
2961 | if ( KABPrefs::instance()->mPassiveSyncWithDesktop ) { | 2961 | if ( KABPrefs::instance()->mPassiveSyncWithDesktop ) { |
2962 | syncManager->slotSyncMenu( 999 ); | 2962 | syncManager->slotSyncMenu( 999 ); |
2963 | } | 2963 | } |
2964 | mAddressBook->export2File( sentSyncFile() ); | 2964 | mAddressBook->export2File( sentSyncFile() ); |
2965 | } | 2965 | } |
2966 | QString KABCore::sentSyncFile() | 2966 | QString KABCore::sentSyncFile() |
2967 | { | 2967 | { |
2968 | #ifdef DESKTOP_VERSION | 2968 | #ifdef DESKTOP_VERSION |
2969 | return locateLocal( "tmp", "copysyncab.vcf" ); | 2969 | return locateLocal( "tmp", "copysyncab.vcf" ); |
2970 | #else | 2970 | #else |
2971 | return QString( "/tmp/copysyncab.vcf" ); | 2971 | return QString( "/tmp/copysyncab.vcf" ); |
2972 | #endif | 2972 | #endif |
2973 | } | 2973 | } |
2974 | 2974 | ||
2975 | void KABCore::setCaptionBack() | 2975 | void KABCore::setCaptionBack() |
2976 | { | 2976 | { |
2977 | mMessageTimer->stop(); | 2977 | mMessageTimer->stop(); |
2978 | topLevelWidget()->setCaption( i18n("KAddressbook/Pi") ); | 2978 | topLevelWidget()->setCaption( i18n("KAddressbook/Pi") ); |
2979 | } | 2979 | } |