-rw-r--r-- | kaddressbook/kabcore.cpp | 63 | ||||
-rw-r--r-- | kaddressbook/viewmanager.cpp | 9 | ||||
-rw-r--r-- | kaddressbook/viewmanager.h | 2 |
3 files changed, 47 insertions, 27 deletions
diff --git a/kaddressbook/kabcore.cpp b/kaddressbook/kabcore.cpp index c6288fa..c5a36e2 100644 --- a/kaddressbook/kabcore.cpp +++ b/kaddressbook/kabcore.cpp | |||
@@ -2486,768 +2486,777 @@ void KABCore::requestForBirthdayList(const QString& sourceChannel, const QString | |||
2486 | bar.show(); | 2486 | bar.show(); |
2487 | bar.setCaption (i18n("Collecting birthdays - close to abort!") ); | 2487 | bar.setCaption (i18n("Collecting birthdays - close to abort!") ); |
2488 | qApp->processEvents(); | 2488 | qApp->processEvents(); |
2489 | 2489 | ||
2490 | QDate bday; | 2490 | QDate bday; |
2491 | QString anni; | 2491 | QString anni; |
2492 | QString formattedbday; | 2492 | QString formattedbday; |
2493 | 2493 | ||
2494 | for( it = mAddressBook->begin(); it != mAddressBook->end(); ++it ) | 2494 | for( it = mAddressBook->begin(); it != mAddressBook->end(); ++it ) |
2495 | { | 2495 | { |
2496 | if ( ! bar.isVisible() ) | 2496 | if ( ! bar.isVisible() ) |
2497 | return; | 2497 | return; |
2498 | bar.setProgress( count++ ); | 2498 | bar.setProgress( count++ ); |
2499 | qApp->processEvents(); | 2499 | qApp->processEvents(); |
2500 | bday = (*it).birthday().date(); | 2500 | bday = (*it).birthday().date(); |
2501 | anni = (*it).custom("KADDRESSBOOK", "X-Anniversary" ); | 2501 | anni = (*it).custom("KADDRESSBOOK", "X-Anniversary" ); |
2502 | 2502 | ||
2503 | if ( bday.isValid() || !anni.isEmpty()) | 2503 | if ( bday.isValid() || !anni.isEmpty()) |
2504 | { | 2504 | { |
2505 | if (bday.isValid()) | 2505 | if (bday.isValid()) |
2506 | formattedbday = KGlobal::locale()->formatDate(bday, true, KLocale::ISODate); | 2506 | formattedbday = KGlobal::locale()->formatDate(bday, true, KLocale::ISODate); |
2507 | else | 2507 | else |
2508 | formattedbday = "NOTVALID"; | 2508 | formattedbday = "NOTVALID"; |
2509 | if (anni.isEmpty()) | 2509 | if (anni.isEmpty()) |
2510 | anni = "INVALID"; | 2510 | anni = "INVALID"; |
2511 | 2511 | ||
2512 | birthdayList.append(formattedbday); | 2512 | birthdayList.append(formattedbday); |
2513 | anniversaryList.append(anni); //should be ISODate | 2513 | anniversaryList.append(anni); //should be ISODate |
2514 | realNameList.append((*it).realName()); | 2514 | realNameList.append((*it).realName()); |
2515 | preferredEmailList.append((*it).preferredEmail()); | 2515 | preferredEmailList.append((*it).preferredEmail()); |
2516 | assembledNameList.append((*it).assembledName()); | 2516 | assembledNameList.append((*it).assembledName()); |
2517 | uidList.append((*it).uid()); | 2517 | uidList.append((*it).uid()); |
2518 | 2518 | ||
2519 | //qDebug("found birthday in KA/Pi: %s,%s,%s,%s: %s, %s", (*it).realName().latin1(), (*it).preferredEmail().latin1(), (*it).assembledName().latin1(), (*it).uid().latin1(), formattedbday.latin1(), anni.latin1() ); | 2519 | //qDebug("found birthday in KA/Pi: %s,%s,%s,%s: %s, %s", (*it).realName().latin1(), (*it).preferredEmail().latin1(), (*it).assembledName().latin1(), (*it).uid().latin1(), formattedbday.latin1(), anni.latin1() ); |
2520 | } | 2520 | } |
2521 | } | 2521 | } |
2522 | 2522 | ||
2523 | bool res = ExternalAppHandler::instance()->returnBirthdayListFromKAPI(sourceChannel, uid, birthdayList, anniversaryList, realNameList, preferredEmailList, assembledNameList, uidList); | 2523 | bool res = ExternalAppHandler::instance()->returnBirthdayListFromKAPI(sourceChannel, uid, birthdayList, anniversaryList, realNameList, preferredEmailList, assembledNameList, uidList); |
2524 | 2524 | ||
2525 | } | 2525 | } |
2526 | 2526 | ||
2527 | /* this method will be called through the QCop interface from other apps to show details of a contact. | 2527 | /* this method will be called through the QCop interface from other apps to show details of a contact. |
2528 | */ | 2528 | */ |
2529 | void KABCore::requestForDetails(const QString& sourceChannel, const QString& sessionuid, const QString& name, const QString& email, const QString& uid) | 2529 | void KABCore::requestForDetails(const QString& sourceChannel, const QString& sessionuid, const QString& name, const QString& email, const QString& uid) |
2530 | { | 2530 | { |
2531 | //qDebug("KABCore::requestForDetails %s %s %s %s %s", sourceChannel.latin1(), sessionuid.latin1(), name.latin1(), email.latin1(), uid.latin1()); | 2531 | //qDebug("KABCore::requestForDetails %s %s %s %s %s", sourceChannel.latin1(), sessionuid.latin1(), name.latin1(), email.latin1(), uid.latin1()); |
2532 | 2532 | ||
2533 | QString foundUid = QString::null; | 2533 | QString foundUid = QString::null; |
2534 | if ( ! uid.isEmpty() ) { | 2534 | if ( ! uid.isEmpty() ) { |
2535 | Addressee adrr = mAddressBook->findByUid( uid ); | 2535 | Addressee adrr = mAddressBook->findByUid( uid ); |
2536 | if ( !adrr.isEmpty() ) { | 2536 | if ( !adrr.isEmpty() ) { |
2537 | foundUid = uid; | 2537 | foundUid = uid; |
2538 | } | 2538 | } |
2539 | if ( email == "sendbacklist" ) { | 2539 | if ( email == "sendbacklist" ) { |
2540 | //qDebug("ssssssssssssssssssssssend "); | 2540 | //qDebug("ssssssssssssssssssssssend "); |
2541 | QStringList nameList; | 2541 | QStringList nameList; |
2542 | QStringList emailList; | 2542 | QStringList emailList; |
2543 | QStringList uidList; | 2543 | QStringList uidList; |
2544 | nameList.append(adrr.realName()); | 2544 | nameList.append(adrr.realName()); |
2545 | emailList = adrr.emails(); | 2545 | emailList = adrr.emails(); |
2546 | uidList.append( adrr.preferredEmail()); | 2546 | uidList.append( adrr.preferredEmail()); |
2547 | bool res = ExternalAppHandler::instance()->returnNameEmailUidListFromKAPI("QPE/Application/ompi", uid, nameList, emailList, uidList); | 2547 | bool res = ExternalAppHandler::instance()->returnNameEmailUidListFromKAPI("QPE/Application/ompi", uid, nameList, emailList, uidList); |
2548 | return; | 2548 | return; |
2549 | } | 2549 | } |
2550 | 2550 | ||
2551 | } | 2551 | } |
2552 | 2552 | ||
2553 | if ( email == "sendbacklist" ) | 2553 | if ( email == "sendbacklist" ) |
2554 | return; | 2554 | return; |
2555 | if (foundUid.isEmpty()) | 2555 | if (foundUid.isEmpty()) |
2556 | { | 2556 | { |
2557 | //find the uid of the person first | 2557 | //find the uid of the person first |
2558 | Addressee::List namelist; | 2558 | Addressee::List namelist; |
2559 | Addressee::List emaillist; | 2559 | Addressee::List emaillist; |
2560 | 2560 | ||
2561 | if (!name.isEmpty()) | 2561 | if (!name.isEmpty()) |
2562 | namelist = mAddressBook->findByName( name ); | 2562 | namelist = mAddressBook->findByName( name ); |
2563 | 2563 | ||
2564 | if (!email.isEmpty()) | 2564 | if (!email.isEmpty()) |
2565 | emaillist = mAddressBook->findByEmail( email ); | 2565 | emaillist = mAddressBook->findByEmail( email ); |
2566 | //qDebug("count %d %d ", namelist.count(),emaillist.count() ); | 2566 | //qDebug("count %d %d ", namelist.count(),emaillist.count() ); |
2567 | //check if we have a match in Namelist and Emaillist | 2567 | //check if we have a match in Namelist and Emaillist |
2568 | if ((namelist.count() == 0) && (emaillist.count() > 0)) { | 2568 | if ((namelist.count() == 0) && (emaillist.count() > 0)) { |
2569 | foundUid = emaillist[0].uid(); | 2569 | foundUid = emaillist[0].uid(); |
2570 | } | 2570 | } |
2571 | else if ((namelist.count() > 0) && (emaillist.count() == 0)) | 2571 | else if ((namelist.count() > 0) && (emaillist.count() == 0)) |
2572 | foundUid = namelist[0].uid(); | 2572 | foundUid = namelist[0].uid(); |
2573 | else | 2573 | else |
2574 | { | 2574 | { |
2575 | for (int i = 0; i < namelist.count(); i++) | 2575 | for (int i = 0; i < namelist.count(); i++) |
2576 | { | 2576 | { |
2577 | for (int j = 0; j < emaillist.count(); j++) | 2577 | for (int j = 0; j < emaillist.count(); j++) |
2578 | { | 2578 | { |
2579 | if (namelist[i] == emaillist[j]) | 2579 | if (namelist[i] == emaillist[j]) |
2580 | { | 2580 | { |
2581 | foundUid = namelist[i].uid(); | 2581 | foundUid = namelist[i].uid(); |
2582 | } | 2582 | } |
2583 | } | 2583 | } |
2584 | } | 2584 | } |
2585 | } | 2585 | } |
2586 | } | 2586 | } |
2587 | else | 2587 | else |
2588 | { | 2588 | { |
2589 | foundUid = uid; | 2589 | foundUid = uid; |
2590 | } | 2590 | } |
2591 | 2591 | ||
2592 | if (!foundUid.isEmpty()) | 2592 | if (!foundUid.isEmpty()) |
2593 | { | 2593 | { |
2594 | 2594 | ||
2595 | // raise Ka/Pi if it is in the background | 2595 | // raise Ka/Pi if it is in the background |
2596 | #ifndef DESKTOP_VERSION | 2596 | #ifndef DESKTOP_VERSION |
2597 | #ifndef KORG_NODCOP | 2597 | #ifndef KORG_NODCOP |
2598 | //QCopEnvelope e("QPE/Application/kapi", "raise()"); | 2598 | //QCopEnvelope e("QPE/Application/kapi", "raise()"); |
2599 | #endif | 2599 | #endif |
2600 | #endif | 2600 | #endif |
2601 | 2601 | ||
2602 | mMainWindow->showMaximized(); | 2602 | mMainWindow->showMaximized(); |
2603 | mMainWindow-> raise(); | 2603 | mMainWindow-> raise(); |
2604 | 2604 | ||
2605 | mViewManager->setSelected( "", false); | 2605 | mViewManager->setSelected( "", false); |
2606 | mViewManager->refreshView( "" ); | 2606 | mViewManager->refreshView( "" ); |
2607 | mViewManager->setSelected( foundUid, true ); | 2607 | mViewManager->setSelected( foundUid, true ); |
2608 | mViewManager->refreshView( foundUid ); | 2608 | mViewManager->refreshView( foundUid ); |
2609 | 2609 | ||
2610 | if ( !mMultipleViewsAtOnce ) | 2610 | if ( !mMultipleViewsAtOnce ) |
2611 | { | 2611 | { |
2612 | setDetailsVisible( true ); | 2612 | setDetailsVisible( true ); |
2613 | mActionDetails->setChecked(true); | 2613 | mActionDetails->setChecked(true); |
2614 | } | 2614 | } |
2615 | } | 2615 | } |
2616 | } | 2616 | } |
2617 | 2617 | ||
2618 | void KABCore::whatsnew() | 2618 | void KABCore::whatsnew() |
2619 | { | 2619 | { |
2620 | KApplication::showFile( "KDE-Pim/Pi Version Info", "kdepim/WhatsNew.txt" ); | 2620 | KApplication::showFile( "KDE-Pim/Pi Version Info", "kdepim/WhatsNew.txt" ); |
2621 | } | 2621 | } |
2622 | void KABCore::synchowto() | 2622 | void KABCore::synchowto() |
2623 | { | 2623 | { |
2624 | KApplication::showFile( "KDE-Pim/Pi Synchronization HowTo", "kdepim/SyncHowto.txt" ); | 2624 | KApplication::showFile( "KDE-Pim/Pi Synchronization HowTo", "kdepim/SyncHowto.txt" ); |
2625 | } | 2625 | } |
2626 | void KABCore::kdesynchowto() | 2626 | void KABCore::kdesynchowto() |
2627 | { | 2627 | { |
2628 | KApplication::showFile( "KDE-Pim/Pi Synchronization HowTo", "kdepim/Zaurus-KDE_syncHowTo.txt" ); | 2628 | KApplication::showFile( "KDE-Pim/Pi Synchronization HowTo", "kdepim/Zaurus-KDE_syncHowTo.txt" ); |
2629 | } | 2629 | } |
2630 | void KABCore::multisynchowto() | 2630 | void KABCore::multisynchowto() |
2631 | { | 2631 | { |
2632 | KApplication::showFile( "KDE-Pim/Pi Synchronization HowTo", "kdepim/MultiSyncHowTo.txt" ); | 2632 | KApplication::showFile( "KDE-Pim/Pi Synchronization HowTo", "kdepim/MultiSyncHowTo.txt" ); |
2633 | } | 2633 | } |
2634 | void KABCore::faq() | 2634 | void KABCore::faq() |
2635 | { | 2635 | { |
2636 | KApplication::showFile( "KA/Pi FAQ", "kdepim/kaddressbook/kapiFAQ.txt" ); | 2636 | KApplication::showFile( "KA/Pi FAQ", "kdepim/kaddressbook/kapiFAQ.txt" ); |
2637 | } | 2637 | } |
2638 | 2638 | ||
2639 | #include <libkcal/syncdefines.h> | 2639 | #include <libkcal/syncdefines.h> |
2640 | 2640 | ||
2641 | KABC::Addressee KABCore::getLastSyncAddressee() | 2641 | KABC::Addressee KABCore::getLastSyncAddressee() |
2642 | { | 2642 | { |
2643 | Addressee lse; | 2643 | Addressee lse; |
2644 | QString mCurrentSyncDevice = syncManager->getCurrentSyncDevice(); | 2644 | QString mCurrentSyncDevice = syncManager->getCurrentSyncDevice(); |
2645 | 2645 | ||
2646 | //qDebug("CurrentSyncDevice %s ",mCurrentSyncDevice .latin1() ); | 2646 | //qDebug("CurrentSyncDevice %s ",mCurrentSyncDevice .latin1() ); |
2647 | lse = mAddressBook->findByUid( "last-syncAddressee-"+mCurrentSyncDevice ); | 2647 | lse = mAddressBook->findByUid( "last-syncAddressee-"+mCurrentSyncDevice ); |
2648 | if (lse.isEmpty()) { | 2648 | if (lse.isEmpty()) { |
2649 | qDebug("Creating new last-syncAddressee "); | 2649 | qDebug("Creating new last-syncAddressee "); |
2650 | lse.setUid( "last-syncAddressee-"+mCurrentSyncDevice ); | 2650 | lse.setUid( "last-syncAddressee-"+mCurrentSyncDevice ); |
2651 | QString sum = ""; | 2651 | QString sum = ""; |
2652 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) | 2652 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) |
2653 | sum = "E: "; | 2653 | sum = "E: "; |
2654 | lse.setFamilyName("!"+sum+mCurrentSyncDevice + i18n(" - sync event")); | 2654 | lse.setFamilyName("!"+sum+mCurrentSyncDevice + i18n(" - sync event")); |
2655 | lse.setRevision( mLastAddressbookSync ); | 2655 | lse.setRevision( mLastAddressbookSync ); |
2656 | lse.setCategories( i18n("SyncEvent") ); | 2656 | lse.setCategories( i18n("SyncEvent") ); |
2657 | mAddressBook->insertAddressee( lse ); | 2657 | mAddressBook->insertAddressee( lse ); |
2658 | } | 2658 | } |
2659 | return lse; | 2659 | return lse; |
2660 | } | 2660 | } |
2661 | int KABCore::takeAddressee( KABC::Addressee* local, KABC::Addressee* remote, int mode , bool full ) | 2661 | int KABCore::takeAddressee( KABC::Addressee* local, KABC::Addressee* remote, int mode , bool full ) |
2662 | { | 2662 | { |
2663 | 2663 | ||
2664 | //void setZaurusId(int id); | 2664 | //void setZaurusId(int id); |
2665 | // int zaurusId() const; | 2665 | // int zaurusId() const; |
2666 | // void setZaurusUid(int id); | 2666 | // void setZaurusUid(int id); |
2667 | // int zaurusUid() const; | 2667 | // int zaurusUid() const; |
2668 | // void setZaurusStat(int id); | 2668 | // void setZaurusStat(int id); |
2669 | // int zaurusStat() const; | 2669 | // int zaurusStat() const; |
2670 | // 0 equal | 2670 | // 0 equal |
2671 | // 1 take local | 2671 | // 1 take local |
2672 | // 2 take remote | 2672 | // 2 take remote |
2673 | // 3 cancel | 2673 | // 3 cancel |
2674 | QDateTime lastSync = mLastAddressbookSync; | 2674 | QDateTime lastSync = mLastAddressbookSync; |
2675 | QDateTime localMod = local->revision(); | 2675 | QDateTime localMod = local->revision(); |
2676 | QDateTime remoteMod = remote->revision(); | 2676 | QDateTime remoteMod = remote->revision(); |
2677 | 2677 | ||
2678 | QString mCurrentSyncDevice = syncManager->getCurrentSyncDevice(); | 2678 | QString mCurrentSyncDevice = syncManager->getCurrentSyncDevice(); |
2679 | 2679 | ||
2680 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { | 2680 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { |
2681 | bool remCh, locCh; | 2681 | bool remCh, locCh; |
2682 | remCh = ( remote->getCsum(mCurrentSyncDevice) != local->getCsum(mCurrentSyncDevice) ); | 2682 | remCh = ( remote->getCsum(mCurrentSyncDevice) != local->getCsum(mCurrentSyncDevice) ); |
2683 | //qDebug("loc %s rem %s", local->getCsum(mCurrentSyncDevice).latin1(), remote->getCsum(mCurrentSyncDevice).latin1() ); | 2683 | //qDebug("loc %s rem %s", local->getCsum(mCurrentSyncDevice).latin1(), remote->getCsum(mCurrentSyncDevice).latin1() ); |
2684 | locCh = ( localMod > mLastAddressbookSync ); | 2684 | locCh = ( localMod > mLastAddressbookSync ); |
2685 | if ( !remCh && ! locCh ) { | 2685 | if ( !remCh && ! locCh ) { |
2686 | //qDebug("both not changed "); | 2686 | //qDebug("both not changed "); |
2687 | lastSync = localMod.addDays(1); | 2687 | lastSync = localMod.addDays(1); |
2688 | if ( mode <= SYNC_PREF_ASK ) | 2688 | if ( mode <= SYNC_PREF_ASK ) |
2689 | return 0; | 2689 | return 0; |
2690 | } else { | 2690 | } else { |
2691 | if ( locCh ) { | 2691 | if ( locCh ) { |
2692 | //qDebug("loc changed %s %s", localMod.toString().latin1(), mLastAddressbookSync.toString().latin1()); | 2692 | //qDebug("loc changed %s %s", localMod.toString().latin1(), mLastAddressbookSync.toString().latin1()); |
2693 | lastSync = localMod.addDays( -1 ); | 2693 | lastSync = localMod.addDays( -1 ); |
2694 | if ( !remCh ) | 2694 | if ( !remCh ) |
2695 | remoteMod =( lastSync.addDays( -1 ) ); | 2695 | remoteMod =( lastSync.addDays( -1 ) ); |
2696 | } else { | 2696 | } else { |
2697 | //qDebug(" not loc changed "); | 2697 | //qDebug(" not loc changed "); |
2698 | lastSync = localMod.addDays( 1 ); | 2698 | lastSync = localMod.addDays( 1 ); |
2699 | if ( remCh ) { | 2699 | if ( remCh ) { |
2700 | //qDebug("rem changed "); | 2700 | //qDebug("rem changed "); |
2701 | remoteMod =( lastSync.addDays( 1 ) ); | 2701 | remoteMod =( lastSync.addDays( 1 ) ); |
2702 | } | 2702 | } |
2703 | 2703 | ||
2704 | } | 2704 | } |
2705 | } | 2705 | } |
2706 | full = true; | 2706 | full = true; |
2707 | if ( mode < SYNC_PREF_ASK ) | 2707 | if ( mode < SYNC_PREF_ASK ) |
2708 | mode = SYNC_PREF_ASK; | 2708 | mode = SYNC_PREF_ASK; |
2709 | } else { | 2709 | } else { |
2710 | if ( localMod == remoteMod ) | 2710 | if ( localMod == remoteMod ) |
2711 | return 0; | 2711 | return 0; |
2712 | 2712 | ||
2713 | } | 2713 | } |
2714 | //qDebug("%s %s --- %d %d", localMod.toString().latin1() , remoteMod.toString().latin1(), localMod.time().msec(), remoteMod.time().msec()); | 2714 | //qDebug("%s %s --- %d %d", localMod.toString().latin1() , remoteMod.toString().latin1(), localMod.time().msec(), remoteMod.time().msec()); |
2715 | //qDebug("lastsync %s ", lastSync.toString().latin1() ); | 2715 | //qDebug("lastsync %s ", lastSync.toString().latin1() ); |
2716 | //full = true; //debug only | 2716 | //full = true; //debug only |
2717 | if ( full ) { | 2717 | if ( full ) { |
2718 | bool equ = ( (*local) == (*remote) ); | 2718 | bool equ = ( (*local) == (*remote) ); |
2719 | if ( equ ) { | 2719 | if ( equ ) { |
2720 | //qDebug("equal "); | 2720 | //qDebug("equal "); |
2721 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { | 2721 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { |
2722 | local->setCsum( mCurrentSyncDevice, remote->getCsum(mCurrentSyncDevice) ); | 2722 | local->setCsum( mCurrentSyncDevice, remote->getCsum(mCurrentSyncDevice) ); |
2723 | } | 2723 | } |
2724 | if ( mode < SYNC_PREF_FORCE_LOCAL ) | 2724 | if ( mode < SYNC_PREF_FORCE_LOCAL ) |
2725 | return 0; | 2725 | return 0; |
2726 | 2726 | ||
2727 | }//else //debug only | 2727 | }//else //debug only |
2728 | //qDebug("not equal %s %s ", local->summary().latin1(), remote->summary().latin1()); | 2728 | //qDebug("not equal %s %s ", local->summary().latin1(), remote->summary().latin1()); |
2729 | } | 2729 | } |
2730 | int result; | 2730 | int result; |
2731 | bool localIsNew; | 2731 | bool localIsNew; |
2732 | //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() ); | 2732 | //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() ); |
2733 | 2733 | ||
2734 | if ( full && mode < SYNC_PREF_NEWEST ) | 2734 | if ( full && mode < SYNC_PREF_NEWEST ) |
2735 | mode = SYNC_PREF_ASK; | 2735 | mode = SYNC_PREF_ASK; |
2736 | 2736 | ||
2737 | switch( mode ) { | 2737 | switch( mode ) { |
2738 | case SYNC_PREF_LOCAL: | 2738 | case SYNC_PREF_LOCAL: |
2739 | if ( lastSync > remoteMod ) | 2739 | if ( lastSync > remoteMod ) |
2740 | return 1; | 2740 | return 1; |
2741 | if ( lastSync > localMod ) | 2741 | if ( lastSync > localMod ) |
2742 | return 2; | 2742 | return 2; |
2743 | return 1; | 2743 | return 1; |
2744 | break; | 2744 | break; |
2745 | case SYNC_PREF_REMOTE: | 2745 | case SYNC_PREF_REMOTE: |
2746 | if ( lastSync > remoteMod ) | 2746 | if ( lastSync > remoteMod ) |
2747 | return 1; | 2747 | return 1; |
2748 | if ( lastSync > localMod ) | 2748 | if ( lastSync > localMod ) |
2749 | return 2; | 2749 | return 2; |
2750 | return 2; | 2750 | return 2; |
2751 | break; | 2751 | break; |
2752 | case SYNC_PREF_NEWEST: | 2752 | case SYNC_PREF_NEWEST: |
2753 | if ( localMod > remoteMod ) | 2753 | if ( localMod > remoteMod ) |
2754 | return 1; | 2754 | return 1; |
2755 | else | 2755 | else |
2756 | return 2; | 2756 | return 2; |
2757 | break; | 2757 | break; |
2758 | case SYNC_PREF_ASK: | 2758 | case SYNC_PREF_ASK: |
2759 | //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() ); | 2759 | //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() ); |
2760 | if ( lastSync > remoteMod ) | 2760 | if ( lastSync > remoteMod ) |
2761 | return 1; | 2761 | return 1; |
2762 | if ( lastSync > localMod ) | 2762 | if ( lastSync > localMod ) |
2763 | return 2; | 2763 | return 2; |
2764 | localIsNew = localMod >= remoteMod; | 2764 | localIsNew = localMod >= remoteMod; |
2765 | //qDebug("conflict! ************************************** "); | 2765 | //qDebug("conflict! ************************************** "); |
2766 | { | 2766 | { |
2767 | KPIM::AddresseeChooser acd ( *local,*remote, localIsNew , this ); | 2767 | KPIM::AddresseeChooser acd ( *local,*remote, localIsNew , this ); |
2768 | result = acd.executeD(localIsNew); | 2768 | result = acd.executeD(localIsNew); |
2769 | return result; | 2769 | return result; |
2770 | } | 2770 | } |
2771 | break; | 2771 | break; |
2772 | case SYNC_PREF_FORCE_LOCAL: | 2772 | case SYNC_PREF_FORCE_LOCAL: |
2773 | return 1; | 2773 | return 1; |
2774 | break; | 2774 | break; |
2775 | case SYNC_PREF_FORCE_REMOTE: | 2775 | case SYNC_PREF_FORCE_REMOTE: |
2776 | return 2; | 2776 | return 2; |
2777 | break; | 2777 | break; |
2778 | 2778 | ||
2779 | default: | 2779 | default: |
2780 | // SYNC_PREF_TAKE_BOTH not implemented | 2780 | // SYNC_PREF_TAKE_BOTH not implemented |
2781 | break; | 2781 | break; |
2782 | } | 2782 | } |
2783 | return 0; | 2783 | return 0; |
2784 | } | 2784 | } |
2785 | 2785 | ||
2786 | 2786 | ||
2787 | bool KABCore::synchronizeAddressbooks( KABC::AddressBook* local, KABC::AddressBook* remote,int mode) | 2787 | bool KABCore::synchronizeAddressbooks( KABC::AddressBook* local, KABC::AddressBook* remote,int mode) |
2788 | { | 2788 | { |
2789 | bool syncOK = true; | 2789 | bool syncOK = true; |
2790 | int addedAddressee = 0; | 2790 | int addedAddressee = 0; |
2791 | int addedAddresseeR = 0; | 2791 | int addedAddresseeR = 0; |
2792 | int deletedAddresseeR = 0; | 2792 | int deletedAddresseeR = 0; |
2793 | int deletedAddresseeL = 0; | 2793 | int deletedAddresseeL = 0; |
2794 | int changedLocal = 0; | 2794 | int changedLocal = 0; |
2795 | int changedRemote = 0; | 2795 | int changedRemote = 0; |
2796 | 2796 | ||
2797 | QString mCurrentSyncName = syncManager->getCurrentSyncName(); | 2797 | QString mCurrentSyncName = syncManager->getCurrentSyncName(); |
2798 | QString mCurrentSyncDevice = syncManager->getCurrentSyncDevice(); | 2798 | QString mCurrentSyncDevice = syncManager->getCurrentSyncDevice(); |
2799 | 2799 | ||
2800 | //QPtrList<Addressee> el = local->rawAddressees(); | 2800 | //QPtrList<Addressee> el = local->rawAddressees(); |
2801 | Addressee addresseeR; | 2801 | Addressee addresseeR; |
2802 | QString uid; | 2802 | QString uid; |
2803 | int take; | 2803 | int take; |
2804 | Addressee addresseeL; | 2804 | Addressee addresseeL; |
2805 | Addressee addresseeRSync; | 2805 | Addressee addresseeRSync; |
2806 | Addressee addresseeLSync; | 2806 | Addressee addresseeLSync; |
2807 | // KABC::Addressee::List addresseeRSyncSharp = remote->getExternLastSyncAddressees(); | 2807 | // KABC::Addressee::List addresseeRSyncSharp = remote->getExternLastSyncAddressees(); |
2808 | //KABC::Addressee::List addresseeLSyncSharp = local->getExternLastSyncAddressees(); | 2808 | //KABC::Addressee::List addresseeLSyncSharp = local->getExternLastSyncAddressees(); |
2809 | bool fullDateRange = false; | 2809 | bool fullDateRange = false; |
2810 | local->resetTempSyncStat(); | 2810 | local->resetTempSyncStat(); |
2811 | mLastAddressbookSync = QDateTime::currentDateTime(); | 2811 | mLastAddressbookSync = QDateTime::currentDateTime(); |
2812 | if ( syncManager->syncWithDesktop() ) { | 2812 | if ( syncManager->syncWithDesktop() ) { |
2813 | // remote->removeSyncInfo( QString());//remove all info | 2813 | // remote->removeSyncInfo( QString());//remove all info |
2814 | if ( KSyncManager::mRequestedSyncEvent.isValid() ) { | 2814 | if ( KSyncManager::mRequestedSyncEvent.isValid() ) { |
2815 | mLastAddressbookSync = KSyncManager::mRequestedSyncEvent; | 2815 | mLastAddressbookSync = KSyncManager::mRequestedSyncEvent; |
2816 | qDebug("using extern time for calendar sync: %s ", mLastAddressbookSync.toString().latin1() ); | 2816 | qDebug("using extern time for calendar sync: %s ", mLastAddressbookSync.toString().latin1() ); |
2817 | } else { | 2817 | } else { |
2818 | qDebug("KSyncManager::mRequestedSyncEvent has invalid datatime "); | 2818 | qDebug("KSyncManager::mRequestedSyncEvent has invalid datatime "); |
2819 | } | 2819 | } |
2820 | } | 2820 | } |
2821 | QDateTime modifiedCalendar = mLastAddressbookSync; | 2821 | QDateTime modifiedCalendar = mLastAddressbookSync; |
2822 | addresseeLSync = getLastSyncAddressee(); | 2822 | addresseeLSync = getLastSyncAddressee(); |
2823 | qDebug("Last Sync %s ", addresseeLSync.revision().toString().latin1()); | 2823 | qDebug("Last Sync %s ", addresseeLSync.revision().toString().latin1()); |
2824 | addresseeR = remote->findByUid("last-syncAddressee-"+mCurrentSyncName ); | 2824 | addresseeR = remote->findByUid("last-syncAddressee-"+mCurrentSyncName ); |
2825 | if ( !addresseeR.isEmpty() ) { | 2825 | if ( !addresseeR.isEmpty() ) { |
2826 | addresseeRSync = addresseeR; | 2826 | addresseeRSync = addresseeR; |
2827 | remote->removeAddressee(addresseeR ); | 2827 | remote->removeAddressee(addresseeR ); |
2828 | 2828 | ||
2829 | } else { | 2829 | } else { |
2830 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { | 2830 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { |
2831 | addresseeRSync = addresseeLSync ; | 2831 | addresseeRSync = addresseeLSync ; |
2832 | } else { | 2832 | } else { |
2833 | //qDebug("FULLDATE 1"); | 2833 | //qDebug("FULLDATE 1"); |
2834 | fullDateRange = true; | 2834 | fullDateRange = true; |
2835 | Addressee newAdd; | 2835 | Addressee newAdd; |
2836 | addresseeRSync = newAdd; | 2836 | addresseeRSync = newAdd; |
2837 | addresseeRSync.setFamilyName(mCurrentSyncName + i18n(" - sync addressee")); | 2837 | addresseeRSync.setFamilyName(mCurrentSyncName + i18n(" - sync addressee")); |
2838 | addresseeRSync.setUid("last-syncAddressee-"+mCurrentSyncName ); | 2838 | addresseeRSync.setUid("last-syncAddressee-"+mCurrentSyncName ); |
2839 | addresseeRSync.setRevision( mLastAddressbookSync ); | 2839 | addresseeRSync.setRevision( mLastAddressbookSync ); |
2840 | addresseeRSync.setCategories( i18n("SyncAddressee") ); | 2840 | addresseeRSync.setCategories( i18n("SyncAddressee") ); |
2841 | } | 2841 | } |
2842 | } | 2842 | } |
2843 | if ( addresseeLSync.revision() == mLastAddressbookSync ) { | 2843 | if ( addresseeLSync.revision() == mLastAddressbookSync ) { |
2844 | // qDebug("FULLDATE 2"); | 2844 | // qDebug("FULLDATE 2"); |
2845 | fullDateRange = true; | 2845 | fullDateRange = true; |
2846 | } | 2846 | } |
2847 | if ( ! fullDateRange ) { | 2847 | if ( ! fullDateRange ) { |
2848 | if ( addresseeLSync.revision() != addresseeRSync.revision() ) { | 2848 | if ( addresseeLSync.revision() != addresseeRSync.revision() ) { |
2849 | 2849 | ||
2850 | // qDebug("set fulldate to true %s %s" ,addresseeLSync->dtStart().toString().latin1(), addresseeRSync->dtStart().toString().latin1() ); | 2850 | // qDebug("set fulldate to true %s %s" ,addresseeLSync->dtStart().toString().latin1(), addresseeRSync->dtStart().toString().latin1() ); |
2851 | //qDebug("%d %d %d %d ", addresseeLSync->dtStart().time().second(), addresseeLSync->dtStart().time().msec() , addresseeRSync->dtStart().time().second(), addresseeRSync->dtStart().time().msec()); | 2851 | //qDebug("%d %d %d %d ", addresseeLSync->dtStart().time().second(), addresseeLSync->dtStart().time().msec() , addresseeRSync->dtStart().time().second(), addresseeRSync->dtStart().time().msec()); |
2852 | fullDateRange = true; | 2852 | fullDateRange = true; |
2853 | //qDebug("FULLDATE 3 %s %s", addresseeLSync.revision().toString().latin1() , addresseeRSync.revision().toString().latin1() ); | 2853 | //qDebug("FULLDATE 3 %s %s", addresseeLSync.revision().toString().latin1() , addresseeRSync.revision().toString().latin1() ); |
2854 | } | 2854 | } |
2855 | } | 2855 | } |
2856 | // fullDateRange = true; // debug only! | 2856 | // fullDateRange = true; // debug only! |
2857 | if ( fullDateRange ) | 2857 | if ( fullDateRange ) |
2858 | mLastAddressbookSync = QDateTime::currentDateTime().addDays( -100*365); | 2858 | mLastAddressbookSync = QDateTime::currentDateTime().addDays( -100*365); |
2859 | else | 2859 | else |
2860 | mLastAddressbookSync = addresseeLSync.revision(); | 2860 | mLastAddressbookSync = addresseeLSync.revision(); |
2861 | // for resyncing if own file has changed | 2861 | // for resyncing if own file has changed |
2862 | // PENDING fixme later when implemented | 2862 | // PENDING fixme later when implemented |
2863 | #if 0 | 2863 | #if 0 |
2864 | if ( mCurrentSyncDevice == "deleteaftersync" ) { | 2864 | if ( mCurrentSyncDevice == "deleteaftersync" ) { |
2865 | mLastAddressbookSync = loadedFileVersion; | 2865 | mLastAddressbookSync = loadedFileVersion; |
2866 | qDebug("setting mLastAddressbookSync "); | 2866 | qDebug("setting mLastAddressbookSync "); |
2867 | } | 2867 | } |
2868 | #endif | 2868 | #endif |
2869 | 2869 | ||
2870 | |||
2871 | // ********** setting filters **************** | ||
2872 | Filter filterIN = mViewManager->getFilterByName( syncManager->mFilterInAB ); | ||
2873 | Filter filterOUT = mViewManager->getFilterByName( syncManager->mFilterOutAB ); | ||
2874 | |||
2870 | //qDebug("*************************** "); | 2875 | //qDebug("*************************** "); |
2871 | // qDebug("mLastAddressbookSync %s ",mLastAddressbookSync.toString().latin1() ); | 2876 | // qDebug("mLastAddressbookSync %s ",mLastAddressbookSync.toString().latin1() ); |
2872 | QStringList er = remote->uidList(); | 2877 | QStringList er = remote->uidList(); |
2873 | Addressee inR ;//= er.first(); | 2878 | Addressee inR ;//= er.first(); |
2874 | Addressee inL; | 2879 | Addressee inL; |
2875 | 2880 | ||
2876 | syncManager->showProgressBar(0, i18n("Syncing - close to abort!"), er.count()); | 2881 | syncManager->showProgressBar(0, i18n("Syncing - close to abort!"), er.count()); |
2877 | 2882 | ||
2878 | int modulo = (er.count()/10)+1; | 2883 | int modulo = (er.count()/10)+1; |
2879 | int incCounter = 0; | 2884 | int incCounter = 0; |
2880 | while ( incCounter < er.count()) { | 2885 | while ( incCounter < er.count()) { |
2881 | if (syncManager->isProgressBarCanceled()) | 2886 | if (syncManager->isProgressBarCanceled()) |
2882 | return false; | 2887 | return false; |
2883 | if ( incCounter % modulo == 0 ) | 2888 | if ( incCounter % modulo == 0 ) |
2884 | syncManager->showProgressBar(incCounter); | 2889 | syncManager->showProgressBar(incCounter); |
2885 | 2890 | ||
2886 | uid = er[ incCounter ]; | 2891 | uid = er[ incCounter ]; |
2887 | bool skipIncidence = false; | 2892 | bool skipIncidence = false; |
2888 | if ( uid.left(19) == QString("last-syncAddressee-") ) | 2893 | if ( uid.left(19) == QString("last-syncAddressee-") ) |
2889 | skipIncidence = true; | 2894 | skipIncidence = true; |
2890 | QString idS,OidS; | 2895 | QString idS,OidS; |
2891 | qApp->processEvents(); | 2896 | qApp->processEvents(); |
2892 | if ( !skipIncidence ) { | 2897 | if ( !skipIncidence ) { |
2893 | inL = local->findByUid( uid ); | 2898 | inL = local->findByUid( uid ); |
2894 | inR = remote->findByUid( uid ); | 2899 | inR = remote->findByUid( uid ); |
2895 | //inL.setResource( 0 ); | 2900 | //inL.setResource( 0 ); |
2896 | //inR.setResource( 0 ); | 2901 | //inR.setResource( 0 ); |
2897 | if ( !inL.isEmpty() ) { // maybe conflict - same uid in both calendars | 2902 | if ( !inL.isEmpty() ) { // maybe conflict - same uid in both calendars |
2898 | if ( !inL.resource() || inL.resource()->includeInSync() ) { | 2903 | if ( !inL.resource() || inL.resource()->includeInSync() ) { |
2899 | if ( (take = takeAddressee( &inL, &inR, mode, fullDateRange )) ) { | 2904 | if ( (take = takeAddressee( &inL, &inR, mode, fullDateRange )) ) { |
2900 | //qDebug("take %d %s ", take, inL.summary().latin1()); | 2905 | //qDebug("take %d %s ", take, inL.summary().latin1()); |
2901 | if ( take == 3 ) | 2906 | if ( take == 3 ) |
2902 | return false; | 2907 | return false; |
2903 | if ( take == 1 ) {// take local ********************** | 2908 | if ( take == 1 ) {// take local ********************** |
2904 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { | 2909 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { |
2905 | inL.setCsum( mCurrentSyncDevice, inR.getCsum(mCurrentSyncDevice) ); | 2910 | inL.setCsum( mCurrentSyncDevice, inR.getCsum(mCurrentSyncDevice) ); |
2906 | inL.setID( mCurrentSyncDevice, inR.getID(mCurrentSyncDevice) ); | 2911 | inL.setID( mCurrentSyncDevice, inR.getID(mCurrentSyncDevice) ); |
2907 | local->insertAddressee( inL, false ); | 2912 | local->insertAddressee( inL, false ); |
2908 | idS = inR.externalUID(); | 2913 | idS = inR.externalUID(); |
2909 | OidS = inR.originalExternalUID(); | 2914 | OidS = inR.originalExternalUID(); |
2910 | } | 2915 | } |
2911 | else | 2916 | else |
2912 | idS = inR.IDStr(); | 2917 | idS = inR.IDStr(); |
2913 | remote->removeAddressee( inR ); | 2918 | remote->removeAddressee( inR ); |
2914 | inR = inL; | 2919 | inR = inL; |
2915 | inR.setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); | 2920 | inR.setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); |
2916 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { | 2921 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { |
2917 | inR.setOriginalExternalUID( OidS ); | 2922 | inR.setOriginalExternalUID( OidS ); |
2918 | inR.setExternalUID( idS ); | 2923 | inR.setExternalUID( idS ); |
2919 | if ( syncManager->syncWithDesktop() ) { | 2924 | if ( syncManager->syncWithDesktop() ) { |
2920 | inR.setIDStr("changed" ); | 2925 | inR.setIDStr("changed" ); |
2921 | } | 2926 | } |
2922 | //inR.insertCustom( "KADDRESSBOOK", "X-KDESYNC","changed" ); | 2927 | //inR.insertCustom( "KADDRESSBOOK", "X-KDESYNC","changed" ); |
2923 | } else { | 2928 | } else { |
2924 | inR.setIDStr( idS ); | 2929 | inR.setIDStr( idS ); |
2925 | } | 2930 | } |
2926 | inR.setResource( 0 ); | 2931 | inR.setResource( 0 ); |
2927 | remote->insertAddressee( inR , false); | 2932 | remote->insertAddressee( inR , false); |
2928 | ++changedRemote; | 2933 | ++changedRemote; |
2929 | } else { // take == 2 take remote ********************** | 2934 | } else { // take == 2 take remote ********************** |
2930 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { | 2935 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { |
2931 | if ( inR.revision().date().year() < 2004 ) | 2936 | if ( inR.revision().date().year() < 2004 ) |
2932 | inR.setRevision( modifiedCalendar ); | 2937 | inR.setRevision( modifiedCalendar ); |
2933 | } | 2938 | } |
2934 | idS = inL.IDStr(); | 2939 | idS = inL.IDStr(); |
2935 | local->removeAddressee( inL ); | 2940 | local->removeAddressee( inL ); |
2936 | inL = inR; | 2941 | inL = inR; |
2937 | inL.setIDStr( idS ); | 2942 | inL.setIDStr( idS ); |
2938 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { | 2943 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { |
2939 | inL.setCsum( mCurrentSyncDevice, inR.getCsum(mCurrentSyncDevice) ); | 2944 | inL.setCsum( mCurrentSyncDevice, inR.getCsum(mCurrentSyncDevice) ); |
2940 | inL.setID( mCurrentSyncDevice, inR.getID(mCurrentSyncDevice) ); | 2945 | inL.setID( mCurrentSyncDevice, inR.getID(mCurrentSyncDevice) ); |
2941 | } | 2946 | } |
2942 | inL.setResource( 0 ); | 2947 | inL.setResource( 0 ); |
2943 | local->insertAddressee( inL , false ); | 2948 | local->insertAddressee( inL , false ); |
2944 | ++changedLocal; | 2949 | ++changedLocal; |
2945 | } | 2950 | } |
2946 | } | 2951 | } |
2947 | } | 2952 | } |
2948 | } else { // no conflict ********** add or delete remote | 2953 | } else { // no conflict ********** add or delete remote |
2949 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { | 2954 | if ( filterIN.name().isEmpty() || filterIN.filterAddressee( inR ) ) { |
2950 | QString des = addresseeLSync.note(); | 2955 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { |
2951 | if ( des.find( inR.getID(mCurrentSyncDevice) +"," ) >= 0 && mode != 5) { // delete it | 2956 | QString des = addresseeLSync.note(); |
2952 | inR.setTempSyncStat( SYNC_TEMPSTATE_DELETE ); | 2957 | if ( des.find( inR.getID(mCurrentSyncDevice) +"," ) >= 0 && mode != 5) { // delete it |
2953 | remote->insertAddressee( inR, false ); | 2958 | inR.setTempSyncStat( SYNC_TEMPSTATE_DELETE ); |
2954 | ++deletedAddresseeR; | 2959 | remote->insertAddressee( inR, false ); |
2955 | } else { | 2960 | ++deletedAddresseeR; |
2956 | inR.setRevision( modifiedCalendar ); | 2961 | } else { |
2957 | remote->insertAddressee( inR, false ); | 2962 | inR.setRevision( modifiedCalendar ); |
2958 | inL = inR; | 2963 | remote->insertAddressee( inR, false ); |
2959 | inL.setIDStr( ":" ); | 2964 | inL = inR; |
2960 | inL.setCsum( mCurrentSyncDevice, inR.getCsum(mCurrentSyncDevice) ); | 2965 | inL.setIDStr( ":" ); |
2961 | inL.setID( mCurrentSyncDevice, inR.getID(mCurrentSyncDevice) ); | 2966 | inL.setCsum( mCurrentSyncDevice, inR.getCsum(mCurrentSyncDevice) ); |
2962 | inL.setResource( 0 ); | 2967 | inL.setID( mCurrentSyncDevice, inR.getID(mCurrentSyncDevice) ); |
2963 | local->insertAddressee( inL , false); | 2968 | inL.setResource( 0 ); |
2964 | ++addedAddressee; | 2969 | local->insertAddressee( inL , false); |
2965 | } | 2970 | ++addedAddressee; |
2966 | } else { | 2971 | } |
2967 | if ( inR.revision() > mLastAddressbookSync || mode == 5 ) { | ||
2968 | inR.setRevision( modifiedCalendar ); | ||
2969 | remote->insertAddressee( inR, false ); | ||
2970 | inR.setResource( 0 ); | ||
2971 | local->insertAddressee( inR, false ); | ||
2972 | ++addedAddressee; | ||
2973 | } else { | 2972 | } else { |
2974 | // pending checkExternSyncAddressee(addresseeRSyncSharp, inR); | 2973 | if ( inR.revision() > mLastAddressbookSync || mode == 5 ) { |
2975 | remote->removeAddressee( inR ); | 2974 | inR.setRevision( modifiedCalendar ); |
2976 | ++deletedAddresseeR; | 2975 | remote->insertAddressee( inR, false ); |
2976 | inR.setResource( 0 ); | ||
2977 | local->insertAddressee( inR, false ); | ||
2978 | ++addedAddressee; | ||
2979 | } else { | ||
2980 | // pending checkExternSyncAddressee(addresseeRSyncSharp, inR); | ||
2981 | remote->removeAddressee( inR ); | ||
2982 | ++deletedAddresseeR; | ||
2983 | } | ||
2977 | } | 2984 | } |
2978 | } | 2985 | } |
2979 | } | 2986 | } |
2980 | } | 2987 | } |
2981 | ++incCounter; | 2988 | ++incCounter; |
2982 | } | 2989 | } |
2983 | er.clear(); | 2990 | er.clear(); |
2984 | QStringList el = local->uidList(); | 2991 | QStringList el = local->uidList(); |
2985 | modulo = (el.count()/10)+1; | 2992 | modulo = (el.count()/10)+1; |
2986 | 2993 | ||
2987 | syncManager->showProgressBar(0, i18n("Add / remove addressees"), el.count()); | 2994 | syncManager->showProgressBar(0, i18n("Add / remove addressees"), el.count()); |
2988 | incCounter = 0; | 2995 | incCounter = 0; |
2989 | while ( incCounter < el.count()) { | 2996 | while ( incCounter < el.count()) { |
2990 | qApp->processEvents(); | 2997 | qApp->processEvents(); |
2991 | if (syncManager->isProgressBarCanceled()) | 2998 | if (syncManager->isProgressBarCanceled()) |
2992 | return false; | 2999 | return false; |
2993 | if ( incCounter % modulo == 0 ) | 3000 | if ( incCounter % modulo == 0 ) |
2994 | syncManager->showProgressBar(incCounter); | 3001 | syncManager->showProgressBar(incCounter); |
2995 | uid = el[ incCounter ]; | 3002 | uid = el[ incCounter ]; |
2996 | bool skipIncidence = false; | 3003 | bool skipIncidence = false; |
2997 | if ( uid.left(19) == QString("last-syncAddressee-") ) | 3004 | if ( uid.left(19) == QString("last-syncAddressee-") ) |
2998 | skipIncidence = true; | 3005 | skipIncidence = true; |
3006 | if ( !filterOUT.name().isEmpty() && ! filterOUT.filterAddressee( inL ) ) | ||
3007 | skipIncidence = true; | ||
2999 | if ( !skipIncidence ) { | 3008 | if ( !skipIncidence ) { |
3000 | inL = local->findByUid( uid ); | 3009 | inL = local->findByUid( uid ); |
3001 | if ( !inL.resource() || inL.resource()->includeInSync() ) { | 3010 | if ( !inL.resource() || inL.resource()->includeInSync() ) { |
3002 | inR = remote->findByUid( uid ); | 3011 | inR = remote->findByUid( uid ); |
3003 | if ( inR.isEmpty() ) { // no conflict ********** add or delete local | 3012 | if ( inR.isEmpty() ) { // no conflict ********** add or delete local |
3004 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { | 3013 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { |
3005 | if ( !inL.getID(mCurrentSyncDevice).isEmpty() && mode != 4 ) { | 3014 | if ( !inL.getID(mCurrentSyncDevice).isEmpty() && mode != 4 ) { |
3006 | // pending checkExternSyncAddressee(addresseeLSyncSharp, inL); | 3015 | // pending checkExternSyncAddressee(addresseeLSyncSharp, inL); |
3007 | local->removeAddressee( inL ); | 3016 | local->removeAddressee( inL ); |
3008 | ++deletedAddresseeL; | 3017 | ++deletedAddresseeL; |
3009 | } else { | 3018 | } else { |
3010 | if ( ! syncManager->mWriteBackExistingOnly ) { | 3019 | if ( ! syncManager->mWriteBackExistingOnly ) { |
3011 | inL.removeID(mCurrentSyncDevice ); | 3020 | inL.removeID(mCurrentSyncDevice ); |
3012 | ++addedAddresseeR; | 3021 | ++addedAddresseeR; |
3013 | inL.setRevision( modifiedCalendar ); | 3022 | inL.setRevision( modifiedCalendar ); |
3014 | local->insertAddressee( inL, false ); | 3023 | local->insertAddressee( inL, false ); |
3015 | inR = inL; | 3024 | inR = inL; |
3016 | inR.setTempSyncStat( SYNC_TEMPSTATE_ADDED_EXTERNAL ); | 3025 | inR.setTempSyncStat( SYNC_TEMPSTATE_ADDED_EXTERNAL ); |
3017 | inR.setResource( 0 ); | 3026 | inR.setResource( 0 ); |
3018 | remote->insertAddressee( inR, false ); | 3027 | remote->insertAddressee( inR, false ); |
3019 | } | 3028 | } |
3020 | } | 3029 | } |
3021 | } else { | 3030 | } else { |
3022 | if ( inL.revision() < mLastAddressbookSync && mode != 4 ) { | 3031 | if ( inL.revision() < mLastAddressbookSync && mode != 4 ) { |
3023 | //qDebug("data %s ", inL.revision().toString().latin1()); | 3032 | //qDebug("data %s ", inL.revision().toString().latin1()); |
3024 | // pending checkExternSyncAddressee(addresseeLSyncSharp, inL); | 3033 | // pending checkExternSyncAddressee(addresseeLSyncSharp, inL); |
3025 | local->removeAddressee( inL ); | 3034 | local->removeAddressee( inL ); |
3026 | ++deletedAddresseeL; | 3035 | ++deletedAddresseeL; |
3027 | } else { | 3036 | } else { |
3028 | if ( ! syncManager->mWriteBackExistingOnly ) { | 3037 | if ( ! syncManager->mWriteBackExistingOnly ) { |
3029 | ++addedAddresseeR; | 3038 | ++addedAddresseeR; |
3030 | inL.setRevision( modifiedCalendar ); | 3039 | inL.setRevision( modifiedCalendar ); |
3031 | local->insertAddressee( inL, false ); | 3040 | local->insertAddressee( inL, false ); |
3032 | inR = inL; | 3041 | inR = inL; |
3033 | inR.setIDStr( ":" ); | 3042 | inR.setIDStr( ":" ); |
3034 | inR.setResource( 0 ); | 3043 | inR.setResource( 0 ); |
3035 | remote->insertAddressee( inR, false ); | 3044 | remote->insertAddressee( inR, false ); |
3036 | } | 3045 | } |
3037 | } | 3046 | } |
3038 | } | 3047 | } |
3039 | } | 3048 | } |
3040 | } | 3049 | } |
3041 | } | 3050 | } |
3042 | ++incCounter; | 3051 | ++incCounter; |
3043 | } | 3052 | } |
3044 | el.clear(); | 3053 | el.clear(); |
3045 | syncManager->hideProgressBar(); | 3054 | syncManager->hideProgressBar(); |
3046 | mLastAddressbookSync = QDateTime::currentDateTime().addSecs( 1 ); | 3055 | mLastAddressbookSync = QDateTime::currentDateTime().addSecs( 1 ); |
3047 | // get rid of micro seconds | 3056 | // get rid of micro seconds |
3048 | QTime t = mLastAddressbookSync.time(); | 3057 | QTime t = mLastAddressbookSync.time(); |
3049 | mLastAddressbookSync.setTime( QTime (t.hour (), t.minute (), t.second () ) ); | 3058 | mLastAddressbookSync.setTime( QTime (t.hour (), t.minute (), t.second () ) ); |
3050 | addresseeLSync.setRevision( mLastAddressbookSync ); | 3059 | addresseeLSync.setRevision( mLastAddressbookSync ); |
3051 | addresseeRSync.setRevision( mLastAddressbookSync ); | 3060 | addresseeRSync.setRevision( mLastAddressbookSync ); |
3052 | addresseeRSync.setRole( i18n("!Remote from: ")+mCurrentSyncName ) ; | 3061 | addresseeRSync.setRole( i18n("!Remote from: ")+mCurrentSyncName ) ; |
3053 | addresseeLSync.setRole(i18n("!Local from: ") + mCurrentSyncName ); | 3062 | addresseeLSync.setRole(i18n("!Local from: ") + mCurrentSyncName ); |
3054 | addresseeRSync.setGivenName( i18n("!DO NOT EDIT!") ) ; | 3063 | addresseeRSync.setGivenName( i18n("!DO NOT EDIT!") ) ; |
3055 | addresseeLSync.setGivenName(i18n("!DO NOT EDIT!") ); | 3064 | addresseeLSync.setGivenName(i18n("!DO NOT EDIT!") ); |
3056 | addresseeRSync.setOrganization( "!"+mLastAddressbookSync.toString() ) ; | 3065 | addresseeRSync.setOrganization( "!"+mLastAddressbookSync.toString() ) ; |
3057 | addresseeLSync.setOrganization("!"+ mLastAddressbookSync.toString() ); | 3066 | addresseeLSync.setOrganization("!"+ mLastAddressbookSync.toString() ); |
3058 | addresseeRSync.setNote( "" ) ; | 3067 | addresseeRSync.setNote( "" ) ; |
3059 | addresseeLSync.setNote( "" ); | 3068 | addresseeLSync.setNote( "" ); |
3060 | 3069 | ||
3061 | if ( mGlobalSyncMode == SYNC_MODE_NORMAL) | 3070 | if ( mGlobalSyncMode == SYNC_MODE_NORMAL) |
3062 | remote->insertAddressee( addresseeRSync, false ); | 3071 | remote->insertAddressee( addresseeRSync, false ); |
3063 | local->insertAddressee( addresseeLSync, false ); | 3072 | local->insertAddressee( addresseeLSync, false ); |
3064 | QString mes; | 3073 | QString mes; |
3065 | 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 ); | 3074 | 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 ); |
3066 | qDebug( mes ); | 3075 | qDebug( mes ); |
3067 | mes = i18n("Local addressbook changed!\n") +mes; | 3076 | mes = i18n("Local addressbook changed!\n") +mes; |
3068 | if ( syncManager->mShowSyncSummary ) { | 3077 | if ( syncManager->mShowSyncSummary ) { |
3069 | if ( KMessageBox::Cancel == KMessageBox::warningContinueCancel(this, mes, | 3078 | if ( KMessageBox::Cancel == KMessageBox::warningContinueCancel(this, mes, |
3070 | i18n("KA/Pi Synchronization"),i18n("Write back"))) { | 3079 | i18n("KA/Pi Synchronization"),i18n("Write back"))) { |
3071 | qDebug("cancelled "); | 3080 | qDebug("cancelled "); |
3072 | return false; | 3081 | return false; |
3073 | } | 3082 | } |
3074 | } | 3083 | } |
3075 | return syncOK; | 3084 | return syncOK; |
3076 | } | 3085 | } |
3077 | 3086 | ||
3078 | 3087 | ||
3079 | //this is a overwritten callbackmethods from the syncinterface | 3088 | //this is a overwritten callbackmethods from the syncinterface |
3080 | bool KABCore::sync(KSyncManager* manager, QString filename, int mode) | 3089 | bool KABCore::sync(KSyncManager* manager, QString filename, int mode) |
3081 | { | 3090 | { |
3082 | 3091 | ||
3083 | //pending prepare addresseeview for output | 3092 | //pending prepare addresseeview for output |
3084 | //pending detect, if remote file has REV field. if not switch to external sync | 3093 | //pending detect, if remote file has REV field. if not switch to external sync |
3085 | mGlobalSyncMode = SYNC_MODE_NORMAL; | 3094 | mGlobalSyncMode = SYNC_MODE_NORMAL; |
3086 | if ( manager != syncManager ) | 3095 | if ( manager != syncManager ) |
3087 | qDebug("KABCore::sync:: ERROR! :: manager != syncManager "); | 3096 | qDebug("KABCore::sync:: ERROR! :: manager != syncManager "); |
3088 | QString mCurrentSyncDevice = manager->getCurrentSyncDevice(); | 3097 | QString mCurrentSyncDevice = manager->getCurrentSyncDevice(); |
3089 | 3098 | ||
3090 | AddressBook abLocal(filename,"syncContact"); | 3099 | AddressBook abLocal(filename,"syncContact"); |
3091 | bool syncOK = false; | 3100 | bool syncOK = false; |
3092 | if ( abLocal.load() ) { | 3101 | if ( abLocal.load() ) { |
3093 | qDebug("AB loaded %s,sync mode %d",filename.latin1(), mode ); | 3102 | qDebug("AB loaded %s,sync mode %d",filename.latin1(), mode ); |
3094 | bool external = false; | 3103 | bool external = false; |
3095 | bool isXML = false; | 3104 | bool isXML = false; |
3096 | if ( filename.right(4) == ".xml") { | 3105 | if ( filename.right(4) == ".xml") { |
3097 | mGlobalSyncMode = SYNC_MODE_EXTERNAL; | 3106 | mGlobalSyncMode = SYNC_MODE_EXTERNAL; |
3098 | isXML = true; | 3107 | isXML = true; |
3099 | abLocal.preExternSync( mAddressBook ,mCurrentSyncDevice, true ); | 3108 | abLocal.preExternSync( mAddressBook ,mCurrentSyncDevice, true ); |
3100 | } else { | 3109 | } else { |
3101 | external = !manager->mIsKapiFile; | 3110 | external = !manager->mIsKapiFile; |
3102 | if ( external ) { | 3111 | if ( external ) { |
3103 | qDebug("Setting vcf mode to external "); | 3112 | qDebug("Setting vcf mode to external "); |
3104 | mGlobalSyncMode = SYNC_MODE_EXTERNAL; | 3113 | mGlobalSyncMode = SYNC_MODE_EXTERNAL; |
3105 | AddressBook::Iterator it; | 3114 | AddressBook::Iterator it; |
3106 | for ( it = abLocal.begin(); it != abLocal.end(); ++it ) { | 3115 | for ( it = abLocal.begin(); it != abLocal.end(); ++it ) { |
3107 | (*it).setID( mCurrentSyncDevice, (*it).uid() ); | 3116 | (*it).setID( mCurrentSyncDevice, (*it).uid() ); |
3108 | (*it).computeCsum( mCurrentSyncDevice ); | 3117 | (*it).computeCsum( mCurrentSyncDevice ); |
3109 | } | 3118 | } |
3110 | } | 3119 | } |
3111 | } | 3120 | } |
3112 | //AddressBook::Iterator it; | 3121 | //AddressBook::Iterator it; |
3113 | //QStringList vcards; | 3122 | //QStringList vcards; |
3114 | //for ( it = abLocal.begin(); it != abLocal.end(); ++it ) { | 3123 | //for ( it = abLocal.begin(); it != abLocal.end(); ++it ) { |
3115 | // qDebug("Name %s ", (*it).familyName().latin1()); | 3124 | // qDebug("Name %s ", (*it).familyName().latin1()); |
3116 | //} | 3125 | //} |
3117 | syncOK = synchronizeAddressbooks( mAddressBook, &abLocal, mode ); | 3126 | syncOK = synchronizeAddressbooks( mAddressBook, &abLocal, mode ); |
3118 | if ( syncOK ) { | 3127 | if ( syncOK ) { |
3119 | if ( syncManager->mWriteBackFile ) | 3128 | if ( syncManager->mWriteBackFile ) |
3120 | { | 3129 | { |
3121 | if ( external ) | 3130 | if ( external ) |
3122 | abLocal.removeSyncAddressees( !isXML); | 3131 | abLocal.removeSyncAddressees( !isXML); |
3123 | qDebug("Saving remote AB "); | 3132 | qDebug("Saving remote AB "); |
3124 | if ( ! abLocal.saveAB()) | 3133 | if ( ! abLocal.saveAB()) |
3125 | qDebug("Error writing back AB to file "); | 3134 | qDebug("Error writing back AB to file "); |
3126 | if ( external ) { | 3135 | if ( external ) { |
3127 | // afterwrite processing | 3136 | // afterwrite processing |
3128 | abLocal.postExternSync( mAddressBook,mCurrentSyncDevice ,isXML); | 3137 | abLocal.postExternSync( mAddressBook,mCurrentSyncDevice ,isXML); |
3129 | } | 3138 | } |
3130 | } | 3139 | } |
3131 | } | 3140 | } |
3132 | setModified(); | 3141 | setModified(); |
3133 | 3142 | ||
3134 | } | 3143 | } |
3135 | abLocal.removeResources(); | 3144 | abLocal.removeResources(); |
3136 | if ( syncOK ) | 3145 | if ( syncOK ) |
3137 | mViewManager->refreshView(); | 3146 | mViewManager->refreshView(); |
3138 | return syncOK; | 3147 | return syncOK; |
3139 | 3148 | ||
3140 | } | 3149 | } |
3141 | void KABCore::removeSyncInfo( QString syncProfile) | 3150 | void KABCore::removeSyncInfo( QString syncProfile) |
3142 | { | 3151 | { |
3143 | qDebug("AB:removeSyncInfo for profile %s ", syncProfile.latin1()); | 3152 | qDebug("AB:removeSyncInfo for profile %s ", syncProfile.latin1()); |
3144 | mAddressBook->removeSyncInfo( syncProfile ); | 3153 | mAddressBook->removeSyncInfo( syncProfile ); |
3145 | setModified(); | 3154 | setModified(); |
3146 | } | 3155 | } |
3147 | 3156 | ||
3148 | 3157 | ||
3149 | //this is a overwritten callbackmethods from the syncinterface | 3158 | //this is a overwritten callbackmethods from the syncinterface |
3150 | bool KABCore::syncExternal(KSyncManager* manager, QString resource) | 3159 | bool KABCore::syncExternal(KSyncManager* manager, QString resource) |
3151 | { | 3160 | { |
3152 | if ( resource == "phone" ) | 3161 | if ( resource == "phone" ) |
3153 | return syncPhone(); | 3162 | return syncPhone(); |
3154 | disableBR( true ); | 3163 | disableBR( true ); |
3155 | if ( manager != syncManager ) | 3164 | if ( manager != syncManager ) |
3156 | qDebug("KABCore::syncExternal:: ERROR! :: manager != syncManager "); | 3165 | qDebug("KABCore::syncExternal:: ERROR! :: manager != syncManager "); |
3157 | QString mCurrentSyncDevice = manager->getCurrentSyncDevice(); | 3166 | QString mCurrentSyncDevice = manager->getCurrentSyncDevice(); |
3158 | 3167 | ||
3159 | AddressBook abLocal( resource,"syncContact"); | 3168 | AddressBook abLocal( resource,"syncContact"); |
3160 | bool syncOK = false; | 3169 | bool syncOK = false; |
3161 | if ( abLocal.load() ) { | 3170 | if ( abLocal.load() ) { |
3162 | qDebug("AB sharp loaded ,sync device %s",mCurrentSyncDevice.latin1()); | 3171 | qDebug("AB sharp loaded ,sync device %s",mCurrentSyncDevice.latin1()); |
3163 | mGlobalSyncMode = SYNC_MODE_EXTERNAL; | 3172 | mGlobalSyncMode = SYNC_MODE_EXTERNAL; |
3164 | abLocal.preExternSync( mAddressBook ,mCurrentSyncDevice, false ); | 3173 | abLocal.preExternSync( mAddressBook ,mCurrentSyncDevice, false ); |
3165 | syncOK = synchronizeAddressbooks( mAddressBook, &abLocal, syncManager->mSyncAlgoPrefs ); | 3174 | syncOK = synchronizeAddressbooks( mAddressBook, &abLocal, syncManager->mSyncAlgoPrefs ); |
3166 | if ( syncOK ) { | 3175 | if ( syncOK ) { |
3167 | if ( syncManager->mWriteBackFile ) { | 3176 | if ( syncManager->mWriteBackFile ) { |
3168 | abLocal.removeSyncAddressees( false ); | 3177 | abLocal.removeSyncAddressees( false ); |
3169 | abLocal.saveAB(); | 3178 | abLocal.saveAB(); |
3170 | abLocal.postExternSync( mAddressBook,mCurrentSyncDevice, true ); | 3179 | abLocal.postExternSync( mAddressBook,mCurrentSyncDevice, true ); |
3171 | } | 3180 | } |
3172 | } else | 3181 | } else |
3173 | message( i18n("Sync cancelled or failed.") ); | 3182 | message( i18n("Sync cancelled or failed.") ); |
3174 | setModified(); | 3183 | setModified(); |
3175 | } | 3184 | } |
3176 | abLocal.removeResources(); | 3185 | abLocal.removeResources(); |
3177 | if ( syncOK ) | 3186 | if ( syncOK ) |
3178 | mViewManager->refreshView(); | 3187 | mViewManager->refreshView(); |
3179 | disableBR( false ); | 3188 | disableBR( false ); |
3180 | return syncOK; | 3189 | return syncOK; |
3181 | 3190 | ||
3182 | } | 3191 | } |
3183 | void KABCore::message( QString m ) | 3192 | void KABCore::message( QString m ) |
3184 | { | 3193 | { |
3185 | topLevelWidget()->setCaption( m ); | 3194 | topLevelWidget()->setCaption( m ); |
3186 | mMessageTimer->start( 15000, true ); | 3195 | mMessageTimer->start( 15000, true ); |
3187 | } | 3196 | } |
3188 | bool KABCore::syncPhone() | 3197 | bool KABCore::syncPhone() |
3189 | { | 3198 | { |
3190 | QString mCurrentSyncDevice = syncManager->getCurrentSyncDevice(); | 3199 | QString mCurrentSyncDevice = syncManager->getCurrentSyncDevice(); |
3191 | QString fileName = getPhoneFile(); | 3200 | QString fileName = getPhoneFile(); |
3192 | if ( !PhoneAccess::readFromPhone( fileName) ) { | 3201 | if ( !PhoneAccess::readFromPhone( fileName) ) { |
3193 | message(i18n("Phone access failed!")); | 3202 | message(i18n("Phone access failed!")); |
3194 | return false; | 3203 | return false; |
3195 | } | 3204 | } |
3196 | AddressBook abLocal( fileName,"syncContact"); | 3205 | AddressBook abLocal( fileName,"syncContact"); |
3197 | bool syncOK = false; | 3206 | bool syncOK = false; |
3198 | { | 3207 | { |
3199 | abLocal.importFromFile( fileName ); | 3208 | abLocal.importFromFile( fileName ); |
3200 | qDebug("AB phone loaded ,sync device %s",mCurrentSyncDevice.latin1()); | 3209 | qDebug("AB phone loaded ,sync device %s",mCurrentSyncDevice.latin1()); |
3201 | mGlobalSyncMode = SYNC_MODE_EXTERNAL; | 3210 | mGlobalSyncMode = SYNC_MODE_EXTERNAL; |
3202 | abLocal.preparePhoneSync( mCurrentSyncDevice, true ); | 3211 | abLocal.preparePhoneSync( mCurrentSyncDevice, true ); |
3203 | abLocal.preExternSync( mAddressBook ,mCurrentSyncDevice, true ); | 3212 | abLocal.preExternSync( mAddressBook ,mCurrentSyncDevice, true ); |
3204 | syncOK = synchronizeAddressbooks( mAddressBook, &abLocal, syncManager->mSyncAlgoPrefs ); | 3213 | syncOK = synchronizeAddressbooks( mAddressBook, &abLocal, syncManager->mSyncAlgoPrefs ); |
3205 | if ( syncOK ) { | 3214 | if ( syncOK ) { |
3206 | if ( syncManager->mWriteBackFile ) { | 3215 | if ( syncManager->mWriteBackFile ) { |
3207 | abLocal.removeSyncAddressees( true ); | 3216 | abLocal.removeSyncAddressees( true ); |
3208 | abLocal.saveABphone( fileName ); | 3217 | abLocal.saveABphone( fileName ); |
3209 | abLocal.findNewExtIds( fileName, mCurrentSyncDevice ); | 3218 | abLocal.findNewExtIds( fileName, mCurrentSyncDevice ); |
3210 | //abLocal.preparePhoneSync( mCurrentSyncDevice, false ); | 3219 | //abLocal.preparePhoneSync( mCurrentSyncDevice, false ); |
3211 | abLocal.postExternSync( mAddressBook,mCurrentSyncDevice, true ); | 3220 | abLocal.postExternSync( mAddressBook,mCurrentSyncDevice, true ); |
3212 | } | 3221 | } |
3213 | } | 3222 | } |
3214 | setModified(); | 3223 | setModified(); |
3215 | } | 3224 | } |
3216 | abLocal.removeResources(); | 3225 | abLocal.removeResources(); |
3217 | if ( syncOK ) | 3226 | if ( syncOK ) |
3218 | mViewManager->refreshView(); | 3227 | mViewManager->refreshView(); |
3219 | return syncOK; | 3228 | return syncOK; |
3220 | } | 3229 | } |
3221 | void KABCore::getFile( bool success ) | 3230 | void KABCore::getFile( bool success ) |
3222 | { | 3231 | { |
3223 | if ( ! success ) { | 3232 | if ( ! success ) { |
3224 | message( i18n("Error receiving file. Nothing changed!") ); | 3233 | message( i18n("Error receiving file. Nothing changed!") ); |
3225 | return; | 3234 | return; |
3226 | } | 3235 | } |
3227 | int count = mAddressBook->importFromFile( sentSyncFile() , false, true ); | 3236 | int count = mAddressBook->importFromFile( sentSyncFile() , false, true ); |
3228 | if ( count ) | 3237 | if ( count ) |
3229 | setModified( true ); | 3238 | setModified( true ); |
3230 | message( i18n("Pi-Sync successful!") ); | 3239 | message( i18n("Pi-Sync successful!") ); |
3231 | mViewManager->refreshView(); | 3240 | mViewManager->refreshView(); |
3232 | } | 3241 | } |
3233 | void KABCore::syncFileRequest() | 3242 | void KABCore::syncFileRequest() |
3234 | { | 3243 | { |
3235 | if ( KABPrefs::instance()->mPassiveSyncWithDesktop ) { | 3244 | if ( KABPrefs::instance()->mPassiveSyncWithDesktop ) { |
3236 | syncManager->slotSyncMenu( 999 ); | 3245 | syncManager->slotSyncMenu( 999 ); |
3237 | } | 3246 | } |
3238 | mAddressBook->export2File( sentSyncFile() ); | 3247 | mAddressBook->export2File( sentSyncFile() ); |
3239 | } | 3248 | } |
3240 | QString KABCore::sentSyncFile() | 3249 | QString KABCore::sentSyncFile() |
3241 | { | 3250 | { |
3242 | #ifdef DESKTOP_VERSION | 3251 | #ifdef DESKTOP_VERSION |
3243 | return locateLocal( "tmp", "copysyncab.vcf" ); | 3252 | return locateLocal( "tmp", "copysyncab.vcf" ); |
3244 | #else | 3253 | #else |
3245 | return QString( "/tmp/copysyncab.vcf" ); | 3254 | return QString( "/tmp/copysyncab.vcf" ); |
3246 | #endif | 3255 | #endif |
3247 | } | 3256 | } |
3248 | 3257 | ||
3249 | void KABCore::setCaptionBack() | 3258 | void KABCore::setCaptionBack() |
3250 | { | 3259 | { |
3251 | mMessageTimer->stop(); | 3260 | mMessageTimer->stop(); |
3252 | topLevelWidget()->setCaption( i18n("KAddressbook/Pi") ); | 3261 | topLevelWidget()->setCaption( i18n("KAddressbook/Pi") ); |
3253 | } | 3262 | } |
diff --git a/kaddressbook/viewmanager.cpp b/kaddressbook/viewmanager.cpp index 59bddd9..9c3a641 100644 --- a/kaddressbook/viewmanager.cpp +++ b/kaddressbook/viewmanager.cpp | |||
@@ -237,490 +237,499 @@ void ViewManager::setActiveView( const QString &name ) | |||
237 | view->setCaption( name ); | 237 | view->setCaption( name ); |
238 | mViewDict.insert( name, view ); | 238 | mViewDict.insert( name, view ); |
239 | //US my version needs an int as second parameter to addWidget | 239 | //US my version needs an int as second parameter to addWidget |
240 | mViewWidgetStack->addWidget( view, -1 ); | 240 | mViewWidgetStack->addWidget( view, -1 ); |
241 | view->readConfig( config ); | 241 | view->readConfig( config ); |
242 | 242 | ||
243 | // The manager just relays the signals | 243 | // The manager just relays the signals |
244 | connect( view, SIGNAL( selected( const QString& ) ), | 244 | connect( view, SIGNAL( selected( const QString& ) ), |
245 | SIGNAL( selected( const QString & ) ) ); | 245 | SIGNAL( selected( const QString & ) ) ); |
246 | connect( view, SIGNAL( executed( const QString& ) ), | 246 | connect( view, SIGNAL( executed( const QString& ) ), |
247 | SIGNAL( executed( const QString& ) ) ); | 247 | SIGNAL( executed( const QString& ) ) ); |
248 | 248 | ||
249 | connect( view, SIGNAL( deleteRequest( ) ), | 249 | connect( view, SIGNAL( deleteRequest( ) ), |
250 | SIGNAL( deleteRequest( ) ) ); | 250 | SIGNAL( deleteRequest( ) ) ); |
251 | 251 | ||
252 | connect( view, SIGNAL( modified() ), SIGNAL( modified() ) ); | 252 | connect( view, SIGNAL( modified() ), SIGNAL( modified() ) ); |
253 | connect( view, SIGNAL( dropped( QDropEvent* ) ), | 253 | connect( view, SIGNAL( dropped( QDropEvent* ) ), |
254 | SLOT( dropped( QDropEvent* ) ) ); | 254 | SLOT( dropped( QDropEvent* ) ) ); |
255 | connect( view, SIGNAL( startDrag() ), SLOT( startDrag() ) ); | 255 | connect( view, SIGNAL( startDrag() ), SLOT( startDrag() ) ); |
256 | } | 256 | } |
257 | } | 257 | } |
258 | 258 | ||
259 | // If we found or created the view, raise it and refresh it | 259 | // If we found or created the view, raise it and refresh it |
260 | if ( view ) { | 260 | if ( view ) { |
261 | mActiveView = view; | 261 | mActiveView = view; |
262 | mViewWidgetStack->raiseWidget( view ); | 262 | mViewWidgetStack->raiseWidget( view ); |
263 | // Set the proper filter in the view. By setting the combo | 263 | // Set the proper filter in the view. By setting the combo |
264 | // box, the activated slot will be called, which will push | 264 | // box, the activated slot will be called, which will push |
265 | // the filter to the view and refresh it. | 265 | // the filter to the view and refresh it. |
266 | 266 | ||
267 | if ( view->defaultFilterType() == KAddressBookView::None ) { | 267 | if ( view->defaultFilterType() == KAddressBookView::None ) { |
268 | 268 | ||
269 | mActionSelectFilter->setCurrentItem( 0 ); | 269 | mActionSelectFilter->setCurrentItem( 0 ); |
270 | setActiveFilter( 0 ); | 270 | setActiveFilter( 0 ); |
271 | } else if ( view->defaultFilterType() == KAddressBookView::Active ) { | 271 | } else if ( view->defaultFilterType() == KAddressBookView::Active ) { |
272 | setActiveFilter( mActionSelectFilter->currentItem() ); | 272 | setActiveFilter( mActionSelectFilter->currentItem() ); |
273 | } else { | 273 | } else { |
274 | uint pos = filterPosition( view->defaultFilterName() ); | 274 | uint pos = filterPosition( view->defaultFilterName() ); |
275 | mActionSelectFilter->setCurrentItem( pos ); | 275 | mActionSelectFilter->setCurrentItem( pos ); |
276 | setActiveFilter( pos ); | 276 | setActiveFilter( pos ); |
277 | } | 277 | } |
278 | //US qDebug("ViewManager::setActiveView 6" ); | 278 | //US qDebug("ViewManager::setActiveView 6" ); |
279 | 279 | ||
280 | // Update the inc search widget to show the fields in the new active | 280 | // Update the inc search widget to show the fields in the new active |
281 | // view. | 281 | // view. |
282 | mCore->setSearchFields( mActiveView->fields() ); | 282 | mCore->setSearchFields( mActiveView->fields() ); |
283 | 283 | ||
284 | //US performance optimization. setActiveFilter calls also mActiveView->refresh() | 284 | //US performance optimization. setActiveFilter calls also mActiveView->refresh() |
285 | //US mActiveView->refresh(); | 285 | //US mActiveView->refresh(); |
286 | 286 | ||
287 | } | 287 | } |
288 | else | 288 | else |
289 | { | 289 | { |
290 | qDebug("ViewManager::setActiveView: unable to find view" ); | 290 | qDebug("ViewManager::setActiveView: unable to find view" ); |
291 | kdDebug(5720) << "ViewManager::setActiveView: unable to find view\n"; | 291 | kdDebug(5720) << "ViewManager::setActiveView: unable to find view\n"; |
292 | } | 292 | } |
293 | } | 293 | } |
294 | 294 | ||
295 | //US added another method with no parameter, since my moc compiler does not support default parameters. | 295 | //US added another method with no parameter, since my moc compiler does not support default parameters. |
296 | void ViewManager::refreshView() | 296 | void ViewManager::refreshView() |
297 | { | 297 | { |
298 | refreshView( QString::null ); | 298 | refreshView( QString::null ); |
299 | } | 299 | } |
300 | 300 | ||
301 | void ViewManager::refreshView( const QString &uid ) | 301 | void ViewManager::refreshView( const QString &uid ) |
302 | { | 302 | { |
303 | if ( mActiveView ) | 303 | if ( mActiveView ) |
304 | mActiveView->refresh( uid ); | 304 | mActiveView->refresh( uid ); |
305 | } | 305 | } |
306 | 306 | ||
307 | void ViewManager::setFocusAV() | 307 | void ViewManager::setFocusAV() |
308 | { | 308 | { |
309 | if ( mActiveView ) | 309 | if ( mActiveView ) |
310 | mActiveView->setFocusAV(); | 310 | mActiveView->setFocusAV(); |
311 | } | 311 | } |
312 | void ViewManager::editView() | 312 | void ViewManager::editView() |
313 | { | 313 | { |
314 | if ( !mActiveView ) | 314 | if ( !mActiveView ) |
315 | return; | 315 | return; |
316 | 316 | ||
317 | ViewFactory *factory = mViewFactoryDict.find( mActiveView->type() ); | 317 | ViewFactory *factory = mViewFactoryDict.find( mActiveView->type() ); |
318 | ViewConfigureWidget *wdg = 0; | 318 | ViewConfigureWidget *wdg = 0; |
319 | ViewConfigureDialog* dlg = 0; | 319 | ViewConfigureDialog* dlg = 0; |
320 | if ( factory ) { | 320 | if ( factory ) { |
321 | // Save the filters so the dialog has the latest set | 321 | // Save the filters so the dialog has the latest set |
322 | Filter::save( mCore->config(), "Filter", mFilterList ); | 322 | Filter::save( mCore->config(), "Filter", mFilterList ); |
323 | dlg = new ViewConfigureDialog( 0, mActiveView->caption(), this, "conf_dlg" ); | 323 | dlg = new ViewConfigureDialog( 0, mActiveView->caption(), this, "conf_dlg" ); |
324 | wdg = factory->configureWidget( mCore->addressBook(), dlg,"conf_wid" ); | 324 | wdg = factory->configureWidget( mCore->addressBook(), dlg,"conf_wid" ); |
325 | } else { | 325 | } else { |
326 | qDebug("ViewManager::editView()::cannot find viewfactory "); | 326 | qDebug("ViewManager::editView()::cannot find viewfactory "); |
327 | return; | 327 | return; |
328 | } | 328 | } |
329 | if ( wdg ) { | 329 | if ( wdg ) { |
330 | dlg->setWidget( wdg ); | 330 | dlg->setWidget( wdg ); |
331 | 331 | ||
332 | #ifndef DESKTOP_VERSION | 332 | #ifndef DESKTOP_VERSION |
333 | //dlg.setMaximumSize( 640, 480 ); | 333 | //dlg.setMaximumSize( 640, 480 ); |
334 | //dlg->setGeometry( 40,40, 400, 300); | 334 | //dlg->setGeometry( 40,40, 400, 300); |
335 | dlg->showMaximized(); | 335 | dlg->showMaximized(); |
336 | #endif | 336 | #endif |
337 | 337 | ||
338 | KConfigGroupSaver saver( mCore->config(), mActiveView->caption() ); | 338 | KConfigGroupSaver saver( mCore->config(), mActiveView->caption() ); |
339 | 339 | ||
340 | dlg->restoreSettings( mCore->config() ); | 340 | dlg->restoreSettings( mCore->config() ); |
341 | 341 | ||
342 | if ( dlg->exec() ) { | 342 | if ( dlg->exec() ) { |
343 | dlg->saveSettings( mCore->config() ); | 343 | dlg->saveSettings( mCore->config() ); |
344 | mActiveView->readConfig( mCore->config() ); | 344 | mActiveView->readConfig( mCore->config() ); |
345 | 345 | ||
346 | // Set the proper filter in the view. By setting the combo | 346 | // Set the proper filter in the view. By setting the combo |
347 | // box, the activated slot will be called, which will push | 347 | // box, the activated slot will be called, which will push |
348 | // the filter to the view and refresh it. | 348 | // the filter to the view and refresh it. |
349 | if ( mActiveView->defaultFilterType() == KAddressBookView::None ) { | 349 | if ( mActiveView->defaultFilterType() == KAddressBookView::None ) { |
350 | mActionSelectFilter->setCurrentItem( 0 ); | 350 | mActionSelectFilter->setCurrentItem( 0 ); |
351 | setActiveFilter( 0 ); | 351 | setActiveFilter( 0 ); |
352 | } else if ( mActiveView->defaultFilterType() == KAddressBookView::Active ) { | 352 | } else if ( mActiveView->defaultFilterType() == KAddressBookView::Active ) { |
353 | setActiveFilter( mActionSelectFilter->currentItem() ); | 353 | setActiveFilter( mActionSelectFilter->currentItem() ); |
354 | } else { | 354 | } else { |
355 | uint pos = filterPosition( mActiveView->defaultFilterName() ); | 355 | uint pos = filterPosition( mActiveView->defaultFilterName() ); |
356 | mActionSelectFilter->setCurrentItem( pos ); | 356 | mActionSelectFilter->setCurrentItem( pos ); |
357 | setActiveFilter( pos ); | 357 | setActiveFilter( pos ); |
358 | } | 358 | } |
359 | mCore->setSearchFields( mActiveView->fields() ); | 359 | mCore->setSearchFields( mActiveView->fields() ); |
360 | //US performance optimization. setActiveFilter calls also mActiveView->refresh() | 360 | //US performance optimization. setActiveFilter calls also mActiveView->refresh() |
361 | //US mActiveView->refresh(); | 361 | //US mActiveView->refresh(); |
362 | 362 | ||
363 | 363 | ||
364 | //US this is a bugfix, that we get notified if we change a views configuration | 364 | //US this is a bugfix, that we get notified if we change a views configuration |
365 | emit modified(); | 365 | emit modified(); |
366 | 366 | ||
367 | } | 367 | } |
368 | 368 | ||
369 | } | 369 | } |
370 | delete dlg; | 370 | delete dlg; |
371 | } | 371 | } |
372 | 372 | ||
373 | void ViewManager::deleteView() | 373 | void ViewManager::deleteView() |
374 | { | 374 | { |
375 | QString text = i18n( "<qt>Are you sure that you want to delete the view <b>%1</b>?</qt>" ) | 375 | QString text = i18n( "<qt>Are you sure that you want to delete the view <b>%1</b>?</qt>" ) |
376 | .arg( mActiveView->caption() ); | 376 | .arg( mActiveView->caption() ); |
377 | QString caption = i18n( "Confirm Delete" ); | 377 | QString caption = i18n( "Confirm Delete" ); |
378 | 378 | ||
379 | 379 | ||
380 | if (QMessageBox::information( this, caption, | 380 | if (QMessageBox::information( this, caption, |
381 | text, | 381 | text, |
382 | i18n("Yes!"), i18n("No"), 0, 0 ) == 0) | 382 | i18n("Yes!"), i18n("No"), 0, 0 ) == 0) |
383 | { | 383 | { |
384 | mViewNameList.remove( mActiveView->caption() ); | 384 | mViewNameList.remove( mActiveView->caption() ); |
385 | 385 | ||
386 | // remove the view from the config file | 386 | // remove the view from the config file |
387 | KConfig *config = mCore->config(); | 387 | KConfig *config = mCore->config(); |
388 | config->deleteGroup( mActiveView->caption() ); | 388 | config->deleteGroup( mActiveView->caption() ); |
389 | 389 | ||
390 | mViewDict.remove( mActiveView->caption() ); | 390 | mViewDict.remove( mActiveView->caption() ); |
391 | mActiveView = 0; | 391 | mActiveView = 0; |
392 | 392 | ||
393 | // we are in an invalid state now, but that should be fixed after | 393 | // we are in an invalid state now, but that should be fixed after |
394 | // we emit the signal | 394 | // we emit the signal |
395 | mActionSelectView->setItems( mViewNameList ); | 395 | mActionSelectView->setItems( mViewNameList ); |
396 | if ( mViewNameList.count() > 0 ) { | 396 | if ( mViewNameList.count() > 0 ) { |
397 | mActionSelectView->setCurrentItem( 0 ); | 397 | mActionSelectView->setCurrentItem( 0 ); |
398 | setActiveView( mViewNameList[ 0 ] ); | 398 | setActiveView( mViewNameList[ 0 ] ); |
399 | } | 399 | } |
400 | mActionDeleteView->setEnabled( mViewNameList.count() > 1 ); | 400 | mActionDeleteView->setEnabled( mViewNameList.count() > 1 ); |
401 | } | 401 | } |
402 | } | 402 | } |
403 | 403 | ||
404 | void ViewManager::addView() | 404 | void ViewManager::addView() |
405 | { | 405 | { |
406 | AddViewDialog dialog( &mViewFactoryDict, this ); | 406 | AddViewDialog dialog( &mViewFactoryDict, this ); |
407 | 407 | ||
408 | if ( dialog.exec() ) { | 408 | if ( dialog.exec() ) { |
409 | QString newName = dialog.viewName(); | 409 | QString newName = dialog.viewName(); |
410 | QString type = dialog.viewType(); | 410 | QString type = dialog.viewType(); |
411 | 411 | ||
412 | // Check for name conflicts | 412 | // Check for name conflicts |
413 | bool firstConflict = true; | 413 | bool firstConflict = true; |
414 | int numTries = 1; | 414 | int numTries = 1; |
415 | while ( mViewNameList.contains( newName ) > 0 ) { | 415 | while ( mViewNameList.contains( newName ) > 0 ) { |
416 | if ( !firstConflict ) { | 416 | if ( !firstConflict ) { |
417 | newName = newName.left( newName.length() - 4 ); | 417 | newName = newName.left( newName.length() - 4 ); |
418 | firstConflict = false; | 418 | firstConflict = false; |
419 | } | 419 | } |
420 | 420 | ||
421 | newName = QString( "%1 <%2>" ).arg( newName ).arg( numTries ); | 421 | newName = QString( "%1 <%2>" ).arg( newName ).arg( numTries ); |
422 | numTries++; | 422 | numTries++; |
423 | } | 423 | } |
424 | 424 | ||
425 | // Add the new one to the list | 425 | // Add the new one to the list |
426 | mViewNameList.append( newName ); | 426 | mViewNameList.append( newName ); |
427 | 427 | ||
428 | // write the view to the config file, | 428 | // write the view to the config file, |
429 | KConfig *config = mCore->config(); | 429 | KConfig *config = mCore->config(); |
430 | 430 | ||
431 | config->deleteGroup( newName ); | 431 | config->deleteGroup( newName ); |
432 | 432 | ||
433 | KConfigGroupSaver saver( config, newName ); | 433 | KConfigGroupSaver saver( config, newName ); |
434 | 434 | ||
435 | config->writeEntry( "Type", type ); | 435 | config->writeEntry( "Type", type ); |
436 | 436 | ||
437 | // try to set the active view | 437 | // try to set the active view |
438 | mActionSelectView->setItems( mViewNameList ); | 438 | mActionSelectView->setItems( mViewNameList ); |
439 | mActionSelectView->setCurrentItem( mViewNameList.findIndex( newName ) ); | 439 | mActionSelectView->setCurrentItem( mViewNameList.findIndex( newName ) ); |
440 | setActiveView( newName ); | 440 | setActiveView( newName ); |
441 | 441 | ||
442 | editView(); | 442 | editView(); |
443 | 443 | ||
444 | mActionDeleteView->setEnabled( mViewNameList.count() > 1 ); | 444 | mActionDeleteView->setEnabled( mViewNameList.count() > 1 ); |
445 | } | 445 | } |
446 | } | 446 | } |
447 | 447 | ||
448 | void ViewManager::createViewFactories() | 448 | void ViewManager::createViewFactories() |
449 | { | 449 | { |
450 | #ifndef KAB_EMBEDDED | 450 | #ifndef KAB_EMBEDDED |
451 | KTrader::OfferList plugins = KTrader::self()->query( "KAddressBook/View" ); | 451 | KTrader::OfferList plugins = KTrader::self()->query( "KAddressBook/View" ); |
452 | KTrader::OfferList::ConstIterator it; | 452 | KTrader::OfferList::ConstIterator it; |
453 | for ( it = plugins.begin(); it != plugins.end(); ++it ) { | 453 | for ( it = plugins.begin(); it != plugins.end(); ++it ) { |
454 | if ( !(*it)->hasServiceType( "KAddressBook/View" ) ) | 454 | if ( !(*it)->hasServiceType( "KAddressBook/View" ) ) |
455 | continue; | 455 | continue; |
456 | 456 | ||
457 | KLibFactory *factory = KLibLoader::self()->factory( (*it)->library().latin1() ); | 457 | KLibFactory *factory = KLibLoader::self()->factory( (*it)->library().latin1() ); |
458 | 458 | ||
459 | if ( !factory ) { | 459 | if ( !factory ) { |
460 | kdDebug(5720) << "ViewManager::createViewFactories(): Factory creation failed" << endl; | 460 | kdDebug(5720) << "ViewManager::createViewFactories(): Factory creation failed" << endl; |
461 | continue; | 461 | continue; |
462 | } | 462 | } |
463 | 463 | ||
464 | ViewFactory *viewFactory = static_cast<ViewFactory*>( factory ); | 464 | ViewFactory *viewFactory = static_cast<ViewFactory*>( factory ); |
465 | 465 | ||
466 | if ( !viewFactory ) { | 466 | if ( !viewFactory ) { |
467 | kdDebug(5720) << "ViewManager::createViewFactories(): Cast failed" << endl; | 467 | kdDebug(5720) << "ViewManager::createViewFactories(): Cast failed" << endl; |
468 | continue; | 468 | continue; |
469 | } | 469 | } |
470 | 470 | ||
471 | mViewFactoryDict.insert( viewFactory->type(), viewFactory ); | 471 | mViewFactoryDict.insert( viewFactory->type(), viewFactory ); |
472 | } | 472 | } |
473 | 473 | ||
474 | #else //KAB_EMBEDDED | 474 | #else //KAB_EMBEDDED |
475 | ViewFactory* viewFactory = new IconViewFactory(); | 475 | ViewFactory* viewFactory = new IconViewFactory(); |
476 | mViewFactoryDict.insert( viewFactory->type(), viewFactory ); | 476 | mViewFactoryDict.insert( viewFactory->type(), viewFactory ); |
477 | // qDebug("ViewManager::createViewFactories() Loading factory: %s", viewFactory->type().latin1()); | 477 | // qDebug("ViewManager::createViewFactories() Loading factory: %s", viewFactory->type().latin1()); |
478 | 478 | ||
479 | viewFactory = new TableViewFactory(); | 479 | viewFactory = new TableViewFactory(); |
480 | mViewFactoryDict.insert( viewFactory->type(), viewFactory ); | 480 | mViewFactoryDict.insert( viewFactory->type(), viewFactory ); |
481 | // qDebug("ViewManager::createViewFactories() Loading factory: %s", viewFactory->type().latin1()); | 481 | // qDebug("ViewManager::createViewFactories() Loading factory: %s", viewFactory->type().latin1()); |
482 | 482 | ||
483 | viewFactory = new CardViewFactory(); | 483 | viewFactory = new CardViewFactory(); |
484 | mViewFactoryDict.insert( viewFactory->type(), viewFactory ); | 484 | mViewFactoryDict.insert( viewFactory->type(), viewFactory ); |
485 | // qDebug("ViewManager::createViewFactories() Loading factory: %s", viewFactory->type().latin1()); | 485 | // qDebug("ViewManager::createViewFactories() Loading factory: %s", viewFactory->type().latin1()); |
486 | 486 | ||
487 | #endif //KAB_EMBEDDED | 487 | #endif //KAB_EMBEDDED |
488 | 488 | ||
489 | } | 489 | } |
490 | 490 | ||
491 | void ViewManager::dropped( QDropEvent *e ) | 491 | void ViewManager::dropped( QDropEvent *e ) |
492 | { | 492 | { |
493 | kdDebug(5720) << "ViewManager::dropped: got a drop event" << endl; | 493 | kdDebug(5720) << "ViewManager::dropped: got a drop event" << endl; |
494 | 494 | ||
495 | #ifndef KAB_EMBEDDED | 495 | #ifndef KAB_EMBEDDED |
496 | 496 | ||
497 | QString clipText, vcards; | 497 | QString clipText, vcards; |
498 | KURL::List urls; | 498 | KURL::List urls; |
499 | 499 | ||
500 | if ( KURLDrag::decode( e, urls) ) { | 500 | if ( KURLDrag::decode( e, urls) ) { |
501 | KURL::List::Iterator it = urls.begin(); | 501 | KURL::List::Iterator it = urls.begin(); |
502 | int c = urls.count(); | 502 | int c = urls.count(); |
503 | if ( c > 1 ) { | 503 | if ( c > 1 ) { |
504 | QString questionString = i18n( "Import one contact into your addressbook?", "Import %n contacts into your addressbook?", c ); | 504 | QString questionString = i18n( "Import one contact into your addressbook?", "Import %n contacts into your addressbook?", c ); |
505 | if ( KMessageBox::questionYesNo( this, questionString, i18n( "Import Contacts?" ) ) == KMessageBox::Yes ) { | 505 | if ( KMessageBox::questionYesNo( this, questionString, i18n( "Import Contacts?" ) ) == KMessageBox::Yes ) { |
506 | for ( ; it != urls.end(); ++it ) | 506 | for ( ; it != urls.end(); ++it ) |
507 | emit urlDropped( *it ); | 507 | emit urlDropped( *it ); |
508 | } | 508 | } |
509 | } else if ( c == 1 ) | 509 | } else if ( c == 1 ) |
510 | emit urlDropped( *it ); | 510 | emit urlDropped( *it ); |
511 | } else if ( KVCardDrag::decode( e, vcards ) ) { | 511 | } else if ( KVCardDrag::decode( e, vcards ) ) { |
512 | KABC::Addressee addr; | 512 | KABC::Addressee addr; |
513 | KABC::VCardConverter converter; | 513 | KABC::VCardConverter converter; |
514 | QStringList list = QStringList::split( "\r\n\r\n", vcards ); | 514 | QStringList list = QStringList::split( "\r\n\r\n", vcards ); |
515 | QStringList::Iterator it; | 515 | QStringList::Iterator it; |
516 | for ( it = list.begin(); it != list.end(); ++it ) { | 516 | for ( it = list.begin(); it != list.end(); ++it ) { |
517 | if ( converter.vCardToAddressee( (*it).stripWhiteSpace(), addr ) ) { | 517 | if ( converter.vCardToAddressee( (*it).stripWhiteSpace(), addr ) ) { |
518 | KABC::Addressee a = mCore->addressBook()->findByUid( addr.uid() ); | 518 | KABC::Addressee a = mCore->addressBook()->findByUid( addr.uid() ); |
519 | if ( a.isEmpty() ) { | 519 | if ( a.isEmpty() ) { |
520 | mCore->addressBook()->insertAddressee( addr ); | 520 | mCore->addressBook()->insertAddressee( addr ); |
521 | emit modified(); | 521 | emit modified(); |
522 | } | 522 | } |
523 | } | 523 | } |
524 | } | 524 | } |
525 | 525 | ||
526 | mActiveView->refresh(); | 526 | mActiveView->refresh(); |
527 | } | 527 | } |
528 | #else //KAB_EMBEDDED | 528 | #else //KAB_EMBEDDED |
529 | qDebug("ViewManager::dropped() has to be changed!!" ); | 529 | qDebug("ViewManager::dropped() has to be changed!!" ); |
530 | #endif //KAB_EMBEDDED | 530 | #endif //KAB_EMBEDDED |
531 | 531 | ||
532 | } | 532 | } |
533 | 533 | ||
534 | void ViewManager::startDrag() | 534 | void ViewManager::startDrag() |
535 | { | 535 | { |
536 | kdDebug(5720) << "ViewManager::startDrag: starting to drag" << endl; | 536 | kdDebug(5720) << "ViewManager::startDrag: starting to drag" << endl; |
537 | 537 | ||
538 | #ifndef KAB_EMBEDDED | 538 | #ifndef KAB_EMBEDDED |
539 | 539 | ||
540 | // Get the list of all the selected addressees | 540 | // Get the list of all the selected addressees |
541 | KABC::Addressee::List addrList; | 541 | KABC::Addressee::List addrList; |
542 | QStringList uidList = selectedUids(); | 542 | QStringList uidList = selectedUids(); |
543 | QStringList::Iterator iter; | 543 | QStringList::Iterator iter; |
544 | for ( iter = uidList.begin(); iter != uidList.end(); ++iter ) | 544 | for ( iter = uidList.begin(); iter != uidList.end(); ++iter ) |
545 | addrList.append( mCore->addressBook()->findByUid( *iter ) ); | 545 | addrList.append( mCore->addressBook()->findByUid( *iter ) ); |
546 | 546 | ||
547 | KMultipleDrag *drag = new KMultipleDrag( this ); | 547 | KMultipleDrag *drag = new KMultipleDrag( this ); |
548 | drag->addDragObject( new QTextDrag( AddresseeUtil::addresseesToClipboard(addrList), this ) ); | 548 | drag->addDragObject( new QTextDrag( AddresseeUtil::addresseesToClipboard(addrList), this ) ); |
549 | KABC::Addressee::List::Iterator it; | 549 | KABC::Addressee::List::Iterator it; |
550 | QStringList vcards; | 550 | QStringList vcards; |
551 | for ( it = addrList.begin(); it != addrList.end(); ++it ) { | 551 | for ( it = addrList.begin(); it != addrList.end(); ++it ) { |
552 | QString vcard = QString::null; | 552 | QString vcard = QString::null; |
553 | KABC::VCardConverter converter; | 553 | KABC::VCardConverter converter; |
554 | if ( converter.addresseeToVCard( *it, vcard ) ) | 554 | if ( converter.addresseeToVCard( *it, vcard ) ) |
555 | vcards.append( vcard ); | 555 | vcards.append( vcard ); |
556 | } | 556 | } |
557 | drag->addDragObject( new KVCardDrag( vcards.join( "\r\n" ), this ) ); | 557 | drag->addDragObject( new KVCardDrag( vcards.join( "\r\n" ), this ) ); |
558 | 558 | ||
559 | drag->setPixmap( KGlobal::iconLoader()->loadIcon( "vcard", KIcon::Desktop ) ); | 559 | drag->setPixmap( KGlobal::iconLoader()->loadIcon( "vcard", KIcon::Desktop ) ); |
560 | drag->dragCopy(); | 560 | drag->dragCopy(); |
561 | 561 | ||
562 | #else //KAB_EMBEDDED | 562 | #else //KAB_EMBEDDED |
563 | qDebug("ViewManager::startDrag() has to be changed!!" ); | 563 | qDebug("ViewManager::startDrag() has to be changed!!" ); |
564 | #endif //KAB_EMBEDDED | 564 | #endif //KAB_EMBEDDED |
565 | 565 | ||
566 | } | 566 | } |
567 | void ViewManager::doSearch( const QString& s,KABC::Field *field ) | 567 | void ViewManager::doSearch( const QString& s,KABC::Field *field ) |
568 | { | 568 | { |
569 | if ( mActiveView ) | 569 | if ( mActiveView ) |
570 | mActiveView->doSearch( s, field ); | 570 | mActiveView->doSearch( s, field ); |
571 | 571 | ||
572 | } | 572 | } |
573 | void ViewManager::setActiveFilter( int index ) | 573 | void ViewManager::setActiveFilter( int index ) |
574 | { | 574 | { |
575 | Filter currentFilter; | 575 | Filter currentFilter; |
576 | 576 | ||
577 | if ( ( index - 1 ) < 0 ) | 577 | if ( ( index - 1 ) < 0 ) |
578 | currentFilter = Filter(); | 578 | currentFilter = Filter(); |
579 | else | 579 | else |
580 | currentFilter = mFilterList[ index - 1 ]; | 580 | currentFilter = mFilterList[ index - 1 ]; |
581 | 581 | ||
582 | // Check if we have a view. Since the filter combo is created before | 582 | // Check if we have a view. Since the filter combo is created before |
583 | // the view, this slot could be called before there is a valid view. | 583 | // the view, this slot could be called before there is a valid view. |
584 | if ( mActiveView ) { | 584 | if ( mActiveView ) { |
585 | mActiveView->setFilter( currentFilter ); | 585 | mActiveView->setFilter( currentFilter ); |
586 | mActiveView->refresh(); | 586 | mActiveView->refresh(); |
587 | emit selected( QString::null ); | 587 | emit selected( QString::null ); |
588 | } | 588 | } |
589 | } | 589 | } |
590 | 590 | ||
591 | void ViewManager::configureFilters() | 591 | void ViewManager::configureFilters() |
592 | { | 592 | { |
593 | FilterDialog dlg( this ); | 593 | FilterDialog dlg( this ); |
594 | 594 | ||
595 | dlg.setFilters( mFilterList ); | 595 | dlg.setFilters( mFilterList ); |
596 | 596 | ||
597 | if ( dlg.exec() ) | 597 | if ( dlg.exec() ) |
598 | mFilterList = dlg.filters(); | 598 | mFilterList = dlg.filters(); |
599 | 599 | ||
600 | uint pos = mActionSelectFilter->currentItem(); | 600 | uint pos = mActionSelectFilter->currentItem(); |
601 | mActionSelectFilter->setItems( filterNames() ); | 601 | mActionSelectFilter->setItems( filterNames() ); |
602 | mActionSelectFilter->setCurrentItem( pos ); | 602 | mActionSelectFilter->setCurrentItem( pos ); |
603 | setActiveFilter( pos ); | 603 | setActiveFilter( pos ); |
604 | int cw = 150; | 604 | int cw = 150; |
605 | if (QApplication::desktop()->width() == 480 ) | 605 | if (QApplication::desktop()->width() == 480 ) |
606 | cw = 0; | 606 | cw = 0; |
607 | mActionSelectFilter->setComboWidth( cw ); | 607 | mActionSelectFilter->setComboWidth( cw ); |
608 | saveSettings(); | 608 | saveSettings(); |
609 | } | 609 | } |
610 | 610 | ||
611 | QStringList ViewManager::filterNames() const | 611 | QStringList ViewManager::filterNames() const |
612 | { | 612 | { |
613 | QStringList names( i18n( "No Filter" ) ); | 613 | QStringList names( i18n( "No Filter" ) ); |
614 | 614 | ||
615 | Filter::List::ConstIterator it; | 615 | Filter::List::ConstIterator it; |
616 | for ( it = mFilterList.begin(); it != mFilterList.end(); ++it ) | 616 | for ( it = mFilterList.begin(); it != mFilterList.end(); ++it ) |
617 | names.append( (*it).name() ); | 617 | names.append( (*it).name() ); |
618 | 618 | ||
619 | return names; | 619 | return names; |
620 | } | 620 | } |
621 | Filter ViewManager::getFilterByName( const QString &name ) const | ||
622 | { | ||
623 | Filter::List::ConstIterator it; | ||
624 | for ( it = mFilterList.begin(); it != mFilterList.end(); ++it ) | ||
625 | if ( name == (*it).name() ) | ||
626 | return (*it); | ||
627 | |||
628 | return Filter(); | ||
629 | } | ||
621 | 630 | ||
622 | int ViewManager::filterPosition( const QString &name ) const | 631 | int ViewManager::filterPosition( const QString &name ) const |
623 | { | 632 | { |
624 | int pos = 0; | 633 | int pos = 0; |
625 | 634 | ||
626 | Filter::List::ConstIterator it; | 635 | Filter::List::ConstIterator it; |
627 | for ( it = mFilterList.begin(); it != mFilterList.end(); ++it, ++pos ) | 636 | for ( it = mFilterList.begin(); it != mFilterList.end(); ++it, ++pos ) |
628 | if ( name == (*it).name() ) | 637 | if ( name == (*it).name() ) |
629 | return pos + 1; | 638 | return pos + 1; |
630 | 639 | ||
631 | return 0; | 640 | return 0; |
632 | } | 641 | } |
633 | 642 | ||
634 | void ViewManager::initActions() | 643 | void ViewManager::initActions() |
635 | { | 644 | { |
636 | //US <ActionList name="view_loadedviews"/> | 645 | //US <ActionList name="view_loadedviews"/> |
637 | //US <Separator/> | 646 | //US <Separator/> |
638 | 647 | ||
639 | #ifdef KAB_EMBEDDED | 648 | #ifdef KAB_EMBEDDED |
640 | QPopupMenu *viewmenu = (QPopupMenu*)mCore->getViewMenu(); | 649 | QPopupMenu *viewmenu = (QPopupMenu*)mCore->getViewMenu(); |
641 | QPopupMenu *settingsmenu = (QPopupMenu*)mCore->getSettingsMenu(); | 650 | QPopupMenu *settingsmenu = (QPopupMenu*)mCore->getSettingsMenu(); |
642 | QPopupMenu *filtermenu = (QPopupMenu*)mCore->getFilterMenu(); | 651 | QPopupMenu *filtermenu = (QPopupMenu*)mCore->getFilterMenu(); |
643 | #endif //KAB_EMBEDDED | 652 | #endif //KAB_EMBEDDED |
644 | 653 | ||
645 | mActionSelectView = new KSelectAction( i18n( "Select View" ), 0, mCore->actionCollection(), "select_view" ); | 654 | mActionSelectView = new KSelectAction( i18n( "Select View" ), 0, mCore->actionCollection(), "select_view" ); |
646 | #if KDE_VERSION >= 309 | 655 | #if KDE_VERSION >= 309 |
647 | mActionSelectView->setMenuAccelsEnabled( false ); | 656 | mActionSelectView->setMenuAccelsEnabled( false ); |
648 | #endif | 657 | #endif |
649 | connect( mActionSelectView, SIGNAL( activated( const QString& ) ), | 658 | connect( mActionSelectView, SIGNAL( activated( const QString& ) ), |
650 | SLOT( setActiveView( const QString& ) ) ); | 659 | SLOT( setActiveView( const QString& ) ) ); |
651 | 660 | ||
652 | 661 | ||
653 | #ifdef KAB_EMBEDDED | 662 | #ifdef KAB_EMBEDDED |
654 | mActionSelectView->plug(viewmenu); | 663 | mActionSelectView->plug(viewmenu); |
655 | viewmenu->insertSeparator(); | 664 | viewmenu->insertSeparator(); |
656 | #endif //KAB_EMBEDDED | 665 | #endif //KAB_EMBEDDED |
657 | 666 | ||
658 | KAction *action; | 667 | KAction *action; |
659 | 668 | ||
660 | action = new KAction( i18n( "Modify View..." ), "configure", 0, this, | 669 | action = new KAction( i18n( "Modify View..." ), "configure", 0, this, |
661 | SLOT( editView() ), mCore->actionCollection(), "view_modify" ); | 670 | SLOT( editView() ), mCore->actionCollection(), "view_modify" ); |
662 | #ifndef KAB_EMBEDDED | 671 | #ifndef KAB_EMBEDDED |
663 | action->setWhatsThis( i18n( "By pressing this button a dialog opens that allows you to modify the view of the addressbook. There you can add or remove fields that you want to be shown or hidden in the addressbook like the name for example." ) ); | 672 | action->setWhatsThis( i18n( "By pressing this button a dialog opens that allows you to modify the view of the addressbook. There you can add or remove fields that you want to be shown or hidden in the addressbook like the name for example." ) ); |
664 | #else //KAB_EMBEDDED | 673 | #else //KAB_EMBEDDED |
665 | action->plug(viewmenu); | 674 | action->plug(viewmenu); |
666 | #endif //KAB_EMBEDDED | 675 | #endif //KAB_EMBEDDED |
667 | 676 | ||
668 | action = new KAction( i18n( "Add View..." ), "window_new", 0, this, | 677 | action = new KAction( i18n( "Add View..." ), "window_new", 0, this, |
669 | SLOT( addView() ), mCore->actionCollection(), "view_add" ); | 678 | SLOT( addView() ), mCore->actionCollection(), "view_add" ); |
670 | #ifndef KAB_EMBEDDED | 679 | #ifndef KAB_EMBEDDED |
671 | action->setWhatsThis( i18n( "You can add a new view by choosing one of the dialog that appears after pressing the button. You have to give the view a name, so that you can distinguish between the different views." ) ); | 680 | action->setWhatsThis( i18n( "You can add a new view by choosing one of the dialog that appears after pressing the button. You have to give the view a name, so that you can distinguish between the different views." ) ); |
672 | #else //KAB_EMBEDDED | 681 | #else //KAB_EMBEDDED |
673 | action->plug(viewmenu); | 682 | action->plug(viewmenu); |
674 | #endif //KAB_EMBEDDED | 683 | #endif //KAB_EMBEDDED |
675 | 684 | ||
676 | mActionDeleteView = new KAction( i18n( "Delete View" ), "view_remove", 0, | 685 | mActionDeleteView = new KAction( i18n( "Delete View" ), "view_remove", 0, |
677 | this, SLOT( deleteView() ), | 686 | this, SLOT( deleteView() ), |
678 | mCore->actionCollection(), "view_delete" ); | 687 | mCore->actionCollection(), "view_delete" ); |
679 | #ifndef KAB_EMBEDDED | 688 | #ifndef KAB_EMBEDDED |
680 | mActionDeleteView->setWhatsThis( i18n( "By pressing this button you can delete the actual view, which you have added before." ) ); | 689 | mActionDeleteView->setWhatsThis( i18n( "By pressing this button you can delete the actual view, which you have added before." ) ); |
681 | #else //KAB_EMBEDDED | 690 | #else //KAB_EMBEDDED |
682 | mActionDeleteView->plug(viewmenu); | 691 | mActionDeleteView->plug(viewmenu); |
683 | viewmenu->insertSeparator(); | 692 | viewmenu->insertSeparator(); |
684 | #endif //KAB_EMBEDDED | 693 | #endif //KAB_EMBEDDED |
685 | 694 | ||
686 | #ifndef KAB_EMBEDDED | 695 | #ifndef KAB_EMBEDDED |
687 | action = new KAction( i18n( "Refresh View" ), "reload", 0, this, | 696 | action = new KAction( i18n( "Refresh View" ), "reload", 0, this, |
688 | SLOT( refreshView(const QString &) ), mCore->actionCollection(), | 697 | SLOT( refreshView(const QString &) ), mCore->actionCollection(), |
689 | "view_refresh" ); | 698 | "view_refresh" ); |
690 | action->setWhatsThis( i18n( "The view will be refreshed by pressing this button." ) ); | 699 | action->setWhatsThis( i18n( "The view will be refreshed by pressing this button." ) ); |
691 | #else //KAB_EMBEDDED | 700 | #else //KAB_EMBEDDED |
692 | action = new KAction( i18n( "Refresh View" ), "reload", 0, this, | 701 | action = new KAction( i18n( "Refresh View" ), "reload", 0, this, |
693 | SLOT( refreshView()), mCore->actionCollection(), | 702 | SLOT( refreshView()), mCore->actionCollection(), |
694 | "view_refresh" ); | 703 | "view_refresh" ); |
695 | action->plug(viewmenu); | 704 | action->plug(viewmenu); |
696 | viewmenu->insertSeparator(); | 705 | viewmenu->insertSeparator(); |
697 | #endif //KAB_EMBEDDED | 706 | #endif //KAB_EMBEDDED |
698 | 707 | ||
699 | action = new KAction( i18n( "Edit &Filters..." ), "filter", 0, this, | 708 | action = new KAction( i18n( "Edit &Filters..." ), "filter", 0, this, |
700 | SLOT( configureFilters() ), mCore->actionCollection(), | 709 | SLOT( configureFilters() ), mCore->actionCollection(), |
701 | "options_edit_filters" ); | 710 | "options_edit_filters" ); |
702 | 711 | ||
703 | mActionSelectFilter = new KSelectAction( i18n( "Select Filter" ), "filter", mCore->actionCollection(), "select_filter" ); | 712 | mActionSelectFilter = new KSelectAction( i18n( "Select Filter" ), "filter", mCore->actionCollection(), "select_filter" ); |
704 | #if KDE_VERSION >= 309 | 713 | #if KDE_VERSION >= 309 |
705 | mActionSelectFilter->setMenuAccelsEnabled( false ); | 714 | mActionSelectFilter->setMenuAccelsEnabled( false ); |
706 | #endif | 715 | #endif |
707 | connect( mActionSelectFilter, SIGNAL( activated( int ) ), | 716 | connect( mActionSelectFilter, SIGNAL( activated( int ) ), |
708 | SLOT( setActiveFilter( int ) ) ); | 717 | SLOT( setActiveFilter( int ) ) ); |
709 | 718 | ||
710 | #ifdef KAB_EMBEDDED | 719 | #ifdef KAB_EMBEDDED |
711 | action->plug(settingsmenu); | 720 | action->plug(settingsmenu); |
712 | mActionSelectFilter->plug(viewmenu); | 721 | mActionSelectFilter->plug(viewmenu); |
713 | #endif //KAB_EMBEDDED | 722 | #endif //KAB_EMBEDDED |
714 | 723 | ||
715 | } | 724 | } |
716 | 725 | ||
717 | void ViewManager::initGUI() | 726 | void ViewManager::initGUI() |
718 | { | 727 | { |
719 | QHBoxLayout *layout = new QHBoxLayout( this, 0, 0 ); | 728 | QHBoxLayout *layout = new QHBoxLayout( this, 0, 0 ); |
720 | mViewWidgetStack = new QWidgetStack( this ); | 729 | mViewWidgetStack = new QWidgetStack( this ); |
721 | layout->addWidget( mViewWidgetStack ); | 730 | layout->addWidget( mViewWidgetStack ); |
722 | } | 731 | } |
723 | 732 | ||
724 | #ifndef KAB_EMBEDDED | 733 | #ifndef KAB_EMBEDDED |
725 | #include "viewmanager.moc" | 734 | #include "viewmanager.moc" |
726 | #endif //KAB_EMBEDDED | 735 | #endif //KAB_EMBEDDED |
diff --git a/kaddressbook/viewmanager.h b/kaddressbook/viewmanager.h index a03a83f..272e1b0 100644 --- a/kaddressbook/viewmanager.h +++ b/kaddressbook/viewmanager.h | |||
@@ -1,157 +1,159 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of KAddressBook. | 2 | This file is part of KAddressBook. |
3 | Copyright (c) 2002 Mike Pilone <mpilone@slac.com> | 3 | Copyright (c) 2002 Mike Pilone <mpilone@slac.com> |
4 | 4 | ||
5 | This program is free software; you can redistribute it and/or modify | 5 | This program is free software; you can redistribute it and/or modify |
6 | it under the terms of the GNU General Public License as published by | 6 | it under the terms of the GNU General Public License as published by |
7 | the Free Software Foundation; either version 2 of the License, or | 7 | the Free Software Foundation; either version 2 of the License, or |
8 | (at your option) any later version. | 8 | (at your option) any later version. |
9 | 9 | ||
10 | This program is distributed in the hope that it will be useful, | 10 | This program is distributed in the hope that it will be useful, |
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 | GNU General Public License for more details. | 13 | GNU General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU General Public License | 15 | You should have received a copy of the GNU General Public License |
16 | along with this program; if not, write to the Free Software | 16 | along with this program; if not, write to the Free Software |
17 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | 17 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
18 | 18 | ||
19 | As a special exception, permission is given to link this program | 19 | As a special exception, permission is given to link this program |
20 | with any edition of Qt, and distribute the resulting executable, | 20 | with any edition of Qt, and distribute the resulting executable, |
21 | without including the source code for Qt in the source distribution. | 21 | without including the source code for Qt in the source distribution. |
22 | */ | 22 | */ |
23 | 23 | ||
24 | #ifndef VIEWMANAGER_H | 24 | #ifndef VIEWMANAGER_H |
25 | #define VIEWMANAGER_H | 25 | #define VIEWMANAGER_H |
26 | 26 | ||
27 | #include <qwidget.h> | 27 | #include <qwidget.h> |
28 | #include <qstringlist.h> | 28 | #include <qstringlist.h> |
29 | #include <kaddressbookview.h> | 29 | #include <kaddressbookview.h> |
30 | #include <qdict.h> | 30 | #include <qdict.h> |
31 | #include "filter.h" | ||
31 | 32 | ||
32 | class KAction; | 33 | class KAction; |
33 | class KSelectAction; | 34 | class KSelectAction; |
34 | 35 | ||
35 | class KABCore; | 36 | class KABCore; |
36 | class QWidgetStack; | 37 | class QWidgetStack; |
37 | class QDropEvent; | 38 | class QDropEvent; |
38 | 39 | ||
39 | namespace KABC { class AddressBook; } | 40 | namespace KABC { class AddressBook; } |
40 | 41 | ||
41 | /** | 42 | /** |
42 | The view manager manages the views and everything related to them. The | 43 | The view manager manages the views and everything related to them. The |
43 | manager will load the views at startup and display a view when told to | 44 | manager will load the views at startup and display a view when told to |
44 | make one active. | 45 | make one active. |
45 | 46 | ||
46 | The view manager will also create and manage all dialogs directly related to | 47 | The view manager will also create and manage all dialogs directly related to |
47 | views (ie: AddView, ConfigureView, DeleteView, etc). | 48 | views (ie: AddView, ConfigureView, DeleteView, etc). |
48 | */ | 49 | */ |
49 | class ViewManager : public QWidget | 50 | class ViewManager : public QWidget |
50 | { | 51 | { |
51 | Q_OBJECT | 52 | Q_OBJECT |
52 | public: | 53 | public: |
53 | ViewManager( KABCore *core, QWidget *parent, const char *name = 0 ); | 54 | ViewManager( KABCore *core, QWidget *parent, const char *name = 0 ); |
54 | ~ViewManager(); | 55 | ~ViewManager(); |
55 | 56 | ||
56 | void restoreSettings(); | 57 | void restoreSettings(); |
57 | void saveSettings(); | 58 | void saveSettings(); |
58 | void doSearch( const QString& s ,KABC::Field *field ); | 59 | void doSearch( const QString& s ,KABC::Field *field ); |
59 | 60 | ||
60 | void unloadViews(); | 61 | void unloadViews(); |
61 | KSelectAction * getFilterAction() { return mActionSelectFilter; } | 62 | KSelectAction * getFilterAction() { return mActionSelectFilter; } |
63 | Filter getFilterByName( const QString &name ) const; | ||
62 | 64 | ||
63 | QStringList selectedUids() const; | 65 | QStringList selectedUids() const; |
64 | QStringList selectedEmails() const; | 66 | QStringList selectedEmails() const; |
65 | KABC::Addressee::List selectedAddressees() const; | 67 | KABC::Addressee::List selectedAddressees() const; |
66 | void setListSelected(QStringList); | 68 | void setListSelected(QStringList); |
67 | void setFocusAV(); | 69 | void setFocusAV(); |
68 | 70 | ||
69 | public slots: | 71 | public slots: |
70 | void scrollUP(); | 72 | void scrollUP(); |
71 | void scrollDOWN(); | 73 | void scrollDOWN(); |
72 | 74 | ||
73 | //US void setSelected( const QString &uid = QString::null, bool selected = true ); | 75 | //US void setSelected( const QString &uid = QString::null, bool selected = true ); |
74 | void setSelected( const QString &uid, bool); | 76 | void setSelected( const QString &uid, bool); |
75 | //US added another method with no parameter, since my moc compiler does not support default parameters. | 77 | //US added another method with no parameter, since my moc compiler does not support default parameters. |
76 | void setSelected(); | 78 | void setSelected(); |
77 | 79 | ||
78 | 80 | ||
79 | 81 | ||
80 | //US added another method with no parameter, since my moc compiler does not support default parameters. | 82 | //US added another method with no parameter, since my moc compiler does not support default parameters. |
81 | void refreshView(); | 83 | void refreshView(); |
82 | void refreshView( const QString &uid); | 84 | void refreshView( const QString &uid); |
83 | 85 | ||
84 | void editView(); | 86 | void editView(); |
85 | void deleteView(); | 87 | void deleteView(); |
86 | void addView(); | 88 | void addView(); |
87 | 89 | ||
88 | protected slots: | 90 | protected slots: |
89 | /** | 91 | /** |
90 | Called whenever the user drops something in the active view. | 92 | Called whenever the user drops something in the active view. |
91 | This method will try to decode what was dropped, and if it was | 93 | This method will try to decode what was dropped, and if it was |
92 | a valid addressee, add it to the addressbook. | 94 | a valid addressee, add it to the addressbook. |
93 | */ | 95 | */ |
94 | void dropped( QDropEvent* ); | 96 | void dropped( QDropEvent* ); |
95 | 97 | ||
96 | /** | 98 | /** |
97 | Called whenever the user attempts to start a drag in the view. | 99 | Called whenever the user attempts to start a drag in the view. |
98 | This method will convert all the selected addressees into text (vcard) | 100 | This method will convert all the selected addressees into text (vcard) |
99 | and create a drag object. | 101 | and create a drag object. |
100 | */ | 102 | */ |
101 | void startDrag(); | 103 | void startDrag(); |
102 | 104 | ||
103 | signals: | 105 | signals: |
104 | /** | 106 | /** |
105 | Emitted whenever the user selects an entry in the view. | 107 | Emitted whenever the user selects an entry in the view. |
106 | */ | 108 | */ |
107 | void selected( const QString &uid ); | 109 | void selected( const QString &uid ); |
108 | void deleteRequest( ); | 110 | void deleteRequest( ); |
109 | 111 | ||
110 | /** | 112 | /** |
111 | Emitted whenever the user activates an entry in the view. | 113 | Emitted whenever the user activates an entry in the view. |
112 | */ | 114 | */ |
113 | void executed( const QString &uid ); | 115 | void executed( const QString &uid ); |
114 | 116 | ||
115 | /** | 117 | /** |
116 | Emitted whenever the address book is modified in some way. | 118 | Emitted whenever the address book is modified in some way. |
117 | */ | 119 | */ |
118 | void modified(); | 120 | void modified(); |
119 | 121 | ||
120 | /** | 122 | /** |
121 | Emitted whenever a url is dragged on a view. | 123 | Emitted whenever a url is dragged on a view. |
122 | */ | 124 | */ |
123 | void urlDropped( const KURL& ); | 125 | void urlDropped( const KURL& ); |
124 | 126 | ||
125 | private slots: | 127 | private slots: |
126 | void setActiveView( const QString &name ); | 128 | void setActiveView( const QString &name ); |
127 | void setActiveFilter( int index ); | 129 | void setActiveFilter( int index ); |
128 | void configureFilters(); | 130 | void configureFilters(); |
129 | 131 | ||
130 | private: | 132 | private: |
131 | void createViewFactories(); | 133 | void createViewFactories(); |
132 | QStringList filterNames() const; | 134 | QStringList filterNames() const; |
133 | int filterPosition( const QString &name ) const; | 135 | int filterPosition( const QString &name ) const; |
134 | QStringList viewNames() const; | 136 | QStringList viewNames() const; |
135 | int viewPosition( const QString &name ) const; | 137 | int viewPosition( const QString &name ) const; |
136 | void initActions(); | 138 | void initActions(); |
137 | void initGUI(); | 139 | void initGUI(); |
138 | 140 | ||
139 | KABCore *mCore; | 141 | KABCore *mCore; |
140 | 142 | ||
141 | Filter mCurrentFilter; | 143 | Filter mCurrentFilter; |
142 | Filter::List mFilterList; | 144 | Filter::List mFilterList; |
143 | 145 | ||
144 | QDict<KAddressBookView> mViewDict; | 146 | QDict<KAddressBookView> mViewDict; |
145 | QDict<ViewFactory> mViewFactoryDict; | 147 | QDict<ViewFactory> mViewFactoryDict; |
146 | QStringList mViewNameList; | 148 | QStringList mViewNameList; |
147 | 149 | ||
148 | QWidgetStack *mViewWidgetStack; | 150 | QWidgetStack *mViewWidgetStack; |
149 | KAddressBookView *mActiveView; | 151 | KAddressBookView *mActiveView; |
150 | 152 | ||
151 | KAction *mActionDeleteView; | 153 | KAction *mActionDeleteView; |
152 | KSelectAction *mActionSelectFilter; | 154 | KSelectAction *mActionSelectFilter; |
153 | KSelectAction *mActionSelectView; | 155 | KSelectAction *mActionSelectView; |
154 | 156 | ||
155 | }; | 157 | }; |
156 | 158 | ||
157 | #endif | 159 | #endif |