-rw-r--r-- | kaddressbook/kabcore.cpp | 33 |
1 files changed, 13 insertions, 20 deletions
diff --git a/kaddressbook/kabcore.cpp b/kaddressbook/kabcore.cpp index f222234..f8359de 100644 --- a/kaddressbook/kabcore.cpp +++ b/kaddressbook/kabcore.cpp | |||
@@ -1057,51 +1057,52 @@ void KABCore::editContact( const QString &uid ) | |||
1057 | } | 1057 | } |
1058 | 1058 | ||
1059 | /** | 1059 | /** |
1060 | Shows or edits the detail view for the given uid. If the uid is QString::null, | 1060 | Shows or edits the detail view for the given uid. If the uid is QString::null, |
1061 | the method will try to find a selected addressee in the view. | 1061 | the method will try to find a selected addressee in the view. |
1062 | */ | 1062 | */ |
1063 | void KABCore::executeContact( const QString &uid /*US = QString::null*/ ) | 1063 | void KABCore::executeContact( const QString &uid /*US = QString::null*/ ) |
1064 | { | 1064 | { |
1065 | if ( mMultipleViewsAtOnce ) | 1065 | if ( mMultipleViewsAtOnce ) |
1066 | { | 1066 | { |
1067 | editContact( uid ); | 1067 | editContact( uid ); |
1068 | } | 1068 | } |
1069 | else | 1069 | else |
1070 | { | 1070 | { |
1071 | setDetailsVisible( true ); | 1071 | setDetailsVisible( true ); |
1072 | mActionDetails->setChecked(true); | 1072 | mActionDetails->setChecked(true); |
1073 | } | 1073 | } |
1074 | 1074 | ||
1075 | } | 1075 | } |
1076 | 1076 | ||
1077 | void KABCore::save() | 1077 | void KABCore::save() |
1078 | { | 1078 | { |
1079 | if (syncManager->blockSave()) | 1079 | if (syncManager->blockSave()) |
1080 | return; | 1080 | return; |
1081 | syncManager->setBlockSave(true); | ||
1082 | if ( !mModified ) | 1081 | if ( !mModified ) |
1083 | return; | 1082 | return; |
1083 | |||
1084 | syncManager->setBlockSave(true); | ||
1084 | QString text = i18n( "There was an error while attempting to save\n the " | 1085 | QString text = i18n( "There was an error while attempting to save\n the " |
1085 | "address book. Please check that some \nother application is " | 1086 | "address book. Please check that some \nother application is " |
1086 | "not using it. " ); | 1087 | "not using it. " ); |
1087 | statusMessage(i18n("Saving addressbook ... ")); | 1088 | statusMessage(i18n("Saving addressbook ... ")); |
1088 | #ifndef KAB_EMBEDDED | 1089 | #ifndef KAB_EMBEDDED |
1089 | KABC::StdAddressBook *b = dynamic_cast<KABC::StdAddressBook*>( mAddressBook ); | 1090 | KABC::StdAddressBook *b = dynamic_cast<KABC::StdAddressBook*>( mAddressBook ); |
1090 | if ( !b || !b->save() ) { | 1091 | if ( !b || !b->save() ) { |
1091 | KMessageBox::error( this, text, i18n( "Unable to Save" ) ); | 1092 | KMessageBox::error( this, text, i18n( "Unable to Save" ) ); |
1092 | } | 1093 | } |
1093 | #else //KAB_EMBEDDED | 1094 | #else //KAB_EMBEDDED |
1094 | KABC::StdAddressBook *b = (KABC::StdAddressBook*)( mAddressBook ); | 1095 | KABC::StdAddressBook *b = (KABC::StdAddressBook*)( mAddressBook ); |
1095 | if ( !b || !b->save() ) { | 1096 | if ( !b || !b->save() ) { |
1096 | QMessageBox::critical( this, i18n( "Unable to Save" ), text, i18n("Ok")); | 1097 | QMessageBox::critical( this, i18n( "Unable to Save" ), text, i18n("Ok")); |
1097 | } | 1098 | } |
1098 | #endif //KAB_EMBEDDED | 1099 | #endif //KAB_EMBEDDED |
1099 | 1100 | ||
1100 | statusMessage(i18n("Addressbook saved!")); | 1101 | statusMessage(i18n("Addressbook saved!")); |
1101 | setModified( false ); | 1102 | setModified( false ); |
1102 | syncManager->setBlockSave(false); | 1103 | syncManager->setBlockSave(false); |
1103 | } | 1104 | } |
1104 | 1105 | ||
1105 | void KABCore::statusMessage(QString mess , int time ) | 1106 | void KABCore::statusMessage(QString mess , int time ) |
1106 | { | 1107 | { |
1107 | //topLevelWidget()->setCaption( mess ); | 1108 | //topLevelWidget()->setCaption( mess ); |
@@ -2313,66 +2314,59 @@ bool KABCore::synchronizeAddressbooks( KABC::AddressBook* local, KABC::AddressBo | |||
2313 | //qDebug("%d %d %d %d ", addresseeLSync->dtStart().time().second(), addresseeLSync->dtStart().time().msec() , addresseeRSync->dtStart().time().second(), addresseeRSync->dtStart().time().msec()); | 2314 | //qDebug("%d %d %d %d ", addresseeLSync->dtStart().time().second(), addresseeLSync->dtStart().time().msec() , addresseeRSync->dtStart().time().second(), addresseeRSync->dtStart().time().msec()); |
2314 | fullDateRange = true; | 2315 | fullDateRange = true; |
2315 | qDebug("FULLDATE 3 %s %s", addresseeLSync.revision().toString().latin1() , addresseeRSync.revision().toString().latin1() ); | 2316 | qDebug("FULLDATE 3 %s %s", addresseeLSync.revision().toString().latin1() , addresseeRSync.revision().toString().latin1() ); |
2316 | } | 2317 | } |
2317 | } | 2318 | } |
2318 | // fullDateRange = true; // debug only! | 2319 | // fullDateRange = true; // debug only! |
2319 | if ( fullDateRange ) | 2320 | if ( fullDateRange ) |
2320 | mLastAddressbookSync = QDateTime::currentDateTime().addDays( -100*365); | 2321 | mLastAddressbookSync = QDateTime::currentDateTime().addDays( -100*365); |
2321 | else | 2322 | else |
2322 | mLastAddressbookSync = addresseeLSync.revision(); | 2323 | mLastAddressbookSync = addresseeLSync.revision(); |
2323 | // for resyncing if own file has changed | 2324 | // for resyncing if own file has changed |
2324 | // PENDING fixme later when implemented | 2325 | // PENDING fixme later when implemented |
2325 | #if 0 | 2326 | #if 0 |
2326 | if ( mCurrentSyncDevice == "deleteaftersync" ) { | 2327 | if ( mCurrentSyncDevice == "deleteaftersync" ) { |
2327 | mLastAddressbookSync = loadedFileVersion; | 2328 | mLastAddressbookSync = loadedFileVersion; |
2328 | qDebug("setting mLastAddressbookSync "); | 2329 | qDebug("setting mLastAddressbookSync "); |
2329 | } | 2330 | } |
2330 | #endif | 2331 | #endif |
2331 | 2332 | ||
2332 | //qDebug("*************************** "); | 2333 | //qDebug("*************************** "); |
2333 | // qDebug("mLastAddressbookSync %s ",mLastAddressbookSync.toString().latin1() ); | 2334 | // qDebug("mLastAddressbookSync %s ",mLastAddressbookSync.toString().latin1() ); |
2334 | QStringList er = remote->uidList(); | 2335 | QStringList er = remote->uidList(); |
2335 | Addressee inR ;//= er.first(); | 2336 | Addressee inR ;//= er.first(); |
2336 | Addressee inL; | 2337 | Addressee inL; |
2337 | QProgressBar bar( er.count(),0 ); | 2338 | |
2338 | bar.setCaption (i18n("Syncing - close to abort!") ); | 2339 | syncManager->showProgressBar(0, i18n("Syncing - close to abort!"), er.count()); |
2339 | 2340 | ||
2340 | int w = 300; | ||
2341 | if ( QApplication::desktop()->width() < 320 ) | ||
2342 | w = 220; | ||
2343 | int h = bar.sizeHint().height() ; | ||
2344 | int dw = QApplication::desktop()->width(); | ||
2345 | int dh = QApplication::desktop()->height(); | ||
2346 | bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); | ||
2347 | bar.show(); | ||
2348 | int modulo = (er.count()/10)+1; | 2341 | int modulo = (er.count()/10)+1; |
2349 | int incCounter = 0; | 2342 | int incCounter = 0; |
2350 | while ( incCounter < er.count()) { | 2343 | while ( incCounter < er.count()) { |
2351 | if ( ! bar.isVisible() ) | 2344 | if (syncManager->isProgressBarCanceled()) |
2352 | return false; | 2345 | return false; |
2353 | if ( incCounter % modulo == 0 ) | 2346 | if ( incCounter % modulo == 0 ) |
2354 | bar.setProgress( incCounter ); | 2347 | syncManager->showProgressBar(incCounter); |
2348 | |||
2355 | uid = er[ incCounter ]; | 2349 | uid = er[ incCounter ]; |
2356 | bool skipIncidence = false; | 2350 | bool skipIncidence = false; |
2357 | if ( uid.left(19) == QString("last-syncAddressee-") ) | 2351 | if ( uid.left(19) == QString("last-syncAddressee-") ) |
2358 | skipIncidence = true; | 2352 | skipIncidence = true; |
2359 | QString idS,OidS; | 2353 | QString idS,OidS; |
2360 | qApp->processEvents(); | 2354 | qApp->processEvents(); |
2361 | if ( !skipIncidence ) { | 2355 | if ( !skipIncidence ) { |
2362 | inL = local->findByUid( uid ); | 2356 | inL = local->findByUid( uid ); |
2363 | inR = remote->findByUid( uid ); | 2357 | inR = remote->findByUid( uid ); |
2364 | //inL.setResource( 0 ); | 2358 | //inL.setResource( 0 ); |
2365 | //inR.setResource( 0 ); | 2359 | //inR.setResource( 0 ); |
2366 | if ( !inL.isEmpty() ) { // maybe conflict - same uid in both calendars | 2360 | if ( !inL.isEmpty() ) { // maybe conflict - same uid in both calendars |
2367 | if ( take = takeAddressee( &inL, &inR, mode, fullDateRange ) ) { | 2361 | if ( take = takeAddressee( &inL, &inR, mode, fullDateRange ) ) { |
2368 | //qDebug("take %d %s ", take, inL.summary().latin1()); | 2362 | //qDebug("take %d %s ", take, inL.summary().latin1()); |
2369 | if ( take == 3 ) | 2363 | if ( take == 3 ) |
2370 | return false; | 2364 | return false; |
2371 | if ( take == 1 ) {// take local | 2365 | if ( take == 1 ) {// take local |
2372 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { | 2366 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { |
2373 | inL.setCsum( mCurrentSyncDevice, inR.getCsum(mCurrentSyncDevice) ); | 2367 | inL.setCsum( mCurrentSyncDevice, inR.getCsum(mCurrentSyncDevice) ); |
2374 | inL.setID( mCurrentSyncDevice, inR.getID(mCurrentSyncDevice) ); | 2368 | inL.setID( mCurrentSyncDevice, inR.getID(mCurrentSyncDevice) ); |
2375 | local->insertAddressee( inL, false ); | 2369 | local->insertAddressee( inL, false ); |
2376 | idS = inR.externalUID(); | 2370 | idS = inR.externalUID(); |
2377 | OidS = inR.originalExternalUID(); | 2371 | OidS = inR.originalExternalUID(); |
2378 | } | 2372 | } |
@@ -2422,105 +2416,104 @@ bool KABCore::synchronizeAddressbooks( KABC::AddressBook* local, KABC::AddressBo | |||
2422 | inL.setResource( 0 ); | 2416 | inL.setResource( 0 ); |
2423 | local->insertAddressee( inL , false); | 2417 | local->insertAddressee( inL , false); |
2424 | ++addedAddressee; | 2418 | ++addedAddressee; |
2425 | } | 2419 | } |
2426 | } else { | 2420 | } else { |
2427 | if ( inR.revision() > mLastAddressbookSync || mode == 5 ) { | 2421 | if ( inR.revision() > mLastAddressbookSync || mode == 5 ) { |
2428 | inR.setRevision( modifiedCalendar ); | 2422 | inR.setRevision( modifiedCalendar ); |
2429 | remote->insertAddressee( inR, false ); | 2423 | remote->insertAddressee( inR, false ); |
2430 | inR.setResource( 0 ); | 2424 | inR.setResource( 0 ); |
2431 | local->insertAddressee( inR, false ); | 2425 | local->insertAddressee( inR, false ); |
2432 | ++addedAddressee; | 2426 | ++addedAddressee; |
2433 | } else { | 2427 | } else { |
2434 | // pending checkExternSyncAddressee(addresseeRSyncSharp, inR); | 2428 | // pending checkExternSyncAddressee(addresseeRSyncSharp, inR); |
2435 | remote->removeAddressee( inR ); | 2429 | remote->removeAddressee( inR ); |
2436 | ++deletedAddresseeR; | 2430 | ++deletedAddresseeR; |
2437 | } | 2431 | } |
2438 | } | 2432 | } |
2439 | } | 2433 | } |
2440 | } | 2434 | } |
2441 | ++incCounter; | 2435 | ++incCounter; |
2442 | } | 2436 | } |
2443 | er.clear(); | 2437 | er.clear(); |
2444 | QStringList el = local->uidList(); | 2438 | QStringList el = local->uidList(); |
2445 | modulo = (el.count()/10)+1; | 2439 | modulo = (el.count()/10)+1; |
2446 | bar.setCaption (i18n("Add / remove addressees") ); | 2440 | |
2447 | bar.setTotalSteps ( el.count() ) ; | 2441 | syncManager->showProgressBar(0, i18n("Add / remove addressees"), el.count()); |
2448 | bar.show(); | ||
2449 | incCounter = 0; | 2442 | incCounter = 0; |
2450 | while ( incCounter < el.count()) { | 2443 | while ( incCounter < el.count()) { |
2451 | qApp->processEvents(); | 2444 | qApp->processEvents(); |
2452 | if ( ! bar.isVisible() ) | 2445 | if (syncManager->isProgressBarCanceled()) |
2453 | return false; | 2446 | return false; |
2454 | if ( incCounter % modulo == 0 ) | 2447 | if ( incCounter % modulo == 0 ) |
2455 | bar.setProgress( incCounter ); | 2448 | syncManager->showProgressBar(incCounter); |
2456 | uid = el[ incCounter ]; | 2449 | uid = el[ incCounter ]; |
2457 | bool skipIncidence = false; | 2450 | bool skipIncidence = false; |
2458 | if ( uid.left(19) == QString("last-syncAddressee-") ) | 2451 | if ( uid.left(19) == QString("last-syncAddressee-") ) |
2459 | skipIncidence = true; | 2452 | skipIncidence = true; |
2460 | if ( !skipIncidence ) { | 2453 | if ( !skipIncidence ) { |
2461 | inL = local->findByUid( uid ); | 2454 | inL = local->findByUid( uid ); |
2462 | inR = remote->findByUid( uid ); | 2455 | inR = remote->findByUid( uid ); |
2463 | if ( inR.isEmpty() ) { | 2456 | if ( inR.isEmpty() ) { |
2464 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { | 2457 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { |
2465 | if ( !inL.getID(mCurrentSyncDevice).isEmpty() && mode != 4 ) { | 2458 | if ( !inL.getID(mCurrentSyncDevice).isEmpty() && mode != 4 ) { |
2466 | // pending checkExternSyncAddressee(addresseeLSyncSharp, inL); | 2459 | // pending checkExternSyncAddressee(addresseeLSyncSharp, inL); |
2467 | local->removeAddressee( inL ); | 2460 | local->removeAddressee( inL ); |
2468 | ++deletedAddresseeL; | 2461 | ++deletedAddresseeL; |
2469 | } else { | 2462 | } else { |
2470 | if ( ! KABPrefs::instance()->mWriteBackExistingOnly ) { | 2463 | if ( ! KABPrefs::instance()->mWriteBackExistingOnly ) { |
2471 | inL.removeID(mCurrentSyncDevice ); | 2464 | inL.removeID(mCurrentSyncDevice ); |
2472 | ++addedAddresseeR; | 2465 | ++addedAddresseeR; |
2473 | inL.setRevision( modifiedCalendar ); | 2466 | inL.setRevision( modifiedCalendar ); |
2474 | local->insertAddressee( inL, false ); | 2467 | local->insertAddressee( inL, false ); |
2475 | inR = inL; | 2468 | inR = inL; |
2476 | inR.setTempSyncStat( SYNC_TEMPSTATE_ADDED_EXTERNAL ); | 2469 | inR.setTempSyncStat( SYNC_TEMPSTATE_ADDED_EXTERNAL ); |
2477 | inR.setResource( 0 ); | 2470 | inR.setResource( 0 ); |
2478 | remote->insertAddressee( inR, false ); | 2471 | remote->insertAddressee( inR, false ); |
2479 | } | 2472 | } |
2480 | } | 2473 | } |
2481 | } else { | 2474 | } else { |
2482 | if ( inL.revision() < mLastAddressbookSync && mode != 4 ) { | 2475 | if ( inL.revision() < mLastAddressbookSync && mode != 4 ) { |
2483 | // pending checkExternSyncAddressee(addresseeLSyncSharp, inL); | 2476 | // pending checkExternSyncAddressee(addresseeLSyncSharp, inL); |
2484 | local->removeAddressee( inL ); | 2477 | local->removeAddressee( inL ); |
2485 | ++deletedAddresseeL; | 2478 | ++deletedAddresseeL; |
2486 | } else { | 2479 | } else { |
2487 | if ( ! KABPrefs::instance()->mWriteBackExistingOnly ) { | 2480 | if ( ! KABPrefs::instance()->mWriteBackExistingOnly ) { |
2488 | ++addedAddresseeR; | 2481 | ++addedAddresseeR; |
2489 | inL.setRevision( modifiedCalendar ); | 2482 | inL.setRevision( modifiedCalendar ); |
2490 | local->insertAddressee( inL, false ); | 2483 | local->insertAddressee( inL, false ); |
2491 | inR = inL; | 2484 | inR = inL; |
2492 | inR.setResource( 0 ); | 2485 | inR.setResource( 0 ); |
2493 | remote->insertAddressee( inR, false ); | 2486 | remote->insertAddressee( inR, false ); |
2494 | } | 2487 | } |
2495 | } | 2488 | } |
2496 | } | 2489 | } |
2497 | } | 2490 | } |
2498 | } | 2491 | } |
2499 | ++incCounter; | 2492 | ++incCounter; |
2500 | } | 2493 | } |
2501 | el.clear(); | 2494 | el.clear(); |
2502 | bar.hide(); | 2495 | syncManager->hideProgressBar(); |
2503 | mLastAddressbookSync = QDateTime::currentDateTime().addSecs( 1 ); | 2496 | mLastAddressbookSync = QDateTime::currentDateTime().addSecs( 1 ); |
2504 | // get rid of micro seconds | 2497 | // get rid of micro seconds |
2505 | QTime t = mLastAddressbookSync.time(); | 2498 | QTime t = mLastAddressbookSync.time(); |
2506 | mLastAddressbookSync.setTime( QTime (t.hour (), t.minute (), t.second () ) ); | 2499 | mLastAddressbookSync.setTime( QTime (t.hour (), t.minute (), t.second () ) ); |
2507 | addresseeLSync.setRevision( mLastAddressbookSync ); | 2500 | addresseeLSync.setRevision( mLastAddressbookSync ); |
2508 | addresseeRSync.setRevision( mLastAddressbookSync ); | 2501 | addresseeRSync.setRevision( mLastAddressbookSync ); |
2509 | addresseeRSync.setRole( i18n("!Remote from: ")+mCurrentSyncName ) ; | 2502 | addresseeRSync.setRole( i18n("!Remote from: ")+mCurrentSyncName ) ; |
2510 | addresseeLSync.setRole(i18n("!Local from: ") + mCurrentSyncName ); | 2503 | addresseeLSync.setRole(i18n("!Local from: ") + mCurrentSyncName ); |
2511 | addresseeRSync.setGivenName( i18n("!DO NOT EDIT!") ) ; | 2504 | addresseeRSync.setGivenName( i18n("!DO NOT EDIT!") ) ; |
2512 | addresseeLSync.setGivenName(i18n("!DO NOT EDIT!") ); | 2505 | addresseeLSync.setGivenName(i18n("!DO NOT EDIT!") ); |
2513 | addresseeRSync.setOrganization( "!"+mLastAddressbookSync.toString() ) ; | 2506 | addresseeRSync.setOrganization( "!"+mLastAddressbookSync.toString() ) ; |
2514 | addresseeLSync.setOrganization("!"+ mLastAddressbookSync.toString() ); | 2507 | addresseeLSync.setOrganization("!"+ mLastAddressbookSync.toString() ); |
2515 | addresseeRSync.setNote( "" ) ; | 2508 | addresseeRSync.setNote( "" ) ; |
2516 | addresseeLSync.setNote( "" ); | 2509 | addresseeLSync.setNote( "" ); |
2517 | 2510 | ||
2518 | if ( mGlobalSyncMode == SYNC_MODE_NORMAL) | 2511 | if ( mGlobalSyncMode == SYNC_MODE_NORMAL) |
2519 | remote->insertAddressee( addresseeRSync, false ); | 2512 | remote->insertAddressee( addresseeRSync, false ); |
2520 | local->insertAddressee( addresseeLSync, false ); | 2513 | local->insertAddressee( addresseeLSync, false ); |
2521 | QString mes; | 2514 | QString mes; |
2522 | 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 ); | 2515 | 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 ); |
2523 | if ( KABPrefs::instance()->mShowSyncSummary ) { | 2516 | if ( KABPrefs::instance()->mShowSyncSummary ) { |
2524 | KMessageBox::information(this, mes, i18n("KA/Pi Synchronization") ); | 2517 | KMessageBox::information(this, mes, i18n("KA/Pi Synchronization") ); |
2525 | } | 2518 | } |
2526 | qDebug( mes ); | 2519 | qDebug( mes ); |