Diffstat (limited to 'core/pim/addressbook/abtable.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | core/pim/addressbook/abtable.cpp | 76 |
1 files changed, 44 insertions, 32 deletions
diff --git a/core/pim/addressbook/abtable.cpp b/core/pim/addressbook/abtable.cpp index 97b26db..4feadeb 100644 --- a/core/pim/addressbook/abtable.cpp +++ b/core/pim/addressbook/abtable.cpp | |||
@@ -665,83 +665,95 @@ void AbTable::slotDoFind( const QString &findString, bool caseSensitive, bool us | |||
665 | bool backwards, QString cat /* int category */ ) | 665 | bool backwards, QString cat /* int category */ ) |
666 | { | 666 | { |
667 | int category = 0; | 667 | int category = 0; |
668 | 668 | ||
669 | // Use the current Category if nothing else selected | 669 | // Use the current Category if nothing else selected |
670 | if ( cat.isEmpty() ) | 670 | if ( cat.isEmpty() ) |
671 | category = mCat.id( "Contacts", showCat ); | 671 | category = mCat.id( "Contacts", showCat ); |
672 | else{ | 672 | else{ |
673 | category = mCat.id("Contacts", cat ); | 673 | category = mCat.id("Contacts", cat ); |
674 | } | 674 | } |
675 | 675 | ||
676 | qWarning ("Found in Category %d", category); | 676 | qWarning ("Found in Category %d", category); |
677 | 677 | ||
678 | if ( currFindRow < -1 ) | 678 | if ( currFindRow < -1 ) |
679 | currFindRow = - 1; | 679 | currFindRow = - 1; |
680 | 680 | ||
681 | clearSelection( TRUE ); | 681 | clearSelection( TRUE ); |
682 | int rows, row; | 682 | int rows, row; |
683 | AbTableItem *ati; | 683 | AbTableItem *ati; |
684 | QRegExp r( findString ); | 684 | QRegExp r( findString ); |
685 | r.setCaseSensitive( caseSensitive ); | 685 | r.setCaseSensitive( caseSensitive ); |
686 | r.setWildcard( !useRegExp ); | 686 | r.setWildcard( !useRegExp ); |
687 | rows = numRows(); | 687 | rows = numRows(); |
688 | static bool wrapAround = true; | 688 | static bool wrapAround = true; |
689 | bool try_again = false; | ||
689 | 690 | ||
690 | if ( !backwards ) { | 691 | // We will loop until we found an entry or found nothing. |
691 | for ( row = currFindRow + 1; row < rows; row++ ) { | 692 | do { |
692 | ati = static_cast<AbTableItem*>( item(row, 0) ); | 693 | if ( !backwards ) { |
693 | if ( contactCompare( contactList[ati], r, category ) ) | 694 | for ( row = currFindRow + 1; row < rows; row++ ) { |
694 | break; | 695 | ati = static_cast<AbTableItem*>( item(row, 0) ); |
696 | if ( contactCompare( contactList[ati], r, category ) ){ | ||
697 | try_again = false; | ||
698 | break; | ||
699 | } | ||
700 | } | ||
701 | } else { | ||
702 | for ( row = currFindRow - 1; row > -1; row-- ) { | ||
703 | ati = static_cast<AbTableItem*>( item(row, 0) ); | ||
704 | if ( contactCompare( contactList[ati], r, category ) ){ | ||
705 | try_again = false; | ||
706 | break; | ||
707 | } | ||
708 | } | ||
695 | } | 709 | } |
696 | } else { | 710 | if ( row >= rows || row < 0 ) { |
697 | for ( row = currFindRow - 1; row > -1; row-- ) { | 711 | if ( row < 0 ) |
698 | ati = static_cast<AbTableItem*>( item(row, 0) ); | 712 | currFindRow = rows; |
699 | if ( contactCompare( contactList[ati], r, category ) ) | 713 | else |
700 | break; | 714 | currFindRow = -1; |
715 | |||
716 | if ( wrapAround ){ | ||
717 | emit signalWrapAround(); | ||
718 | try_again = true; | ||
719 | }else{ | ||
720 | emit signalNotFound(); | ||
721 | try_again = false; | ||
722 | } | ||
723 | |||
724 | wrapAround = !wrapAround; | ||
725 | } else { | ||
726 | currFindRow = row; | ||
727 | QTableSelection foundSelection; | ||
728 | foundSelection.init( currFindRow, 0 ); | ||
729 | foundSelection.expandTo( currFindRow, numCols() - 1 ); | ||
730 | addSelection( foundSelection ); | ||
731 | setCurrentCell( currFindRow, 0 /* numCols() - 1 */ ); | ||
732 | wrapAround = true; | ||
733 | try_again = false; | ||
701 | } | 734 | } |
702 | } | 735 | } while ( try_again ); |
703 | if ( row >= rows || row < 0 ) { | ||
704 | if ( row < 0 ) | ||
705 | currFindRow = rows; | ||
706 | else | ||
707 | currFindRow = -1; | ||
708 | |||
709 | if ( wrapAround ) | ||
710 | emit signalWrapAround(); | ||
711 | else | ||
712 | emit signalNotFound(); | ||
713 | |||
714 | wrapAround = !wrapAround; | ||
715 | } else { | ||
716 | currFindRow = row; | ||
717 | QTableSelection foundSelection; | ||
718 | foundSelection.init( currFindRow, 0 ); | ||
719 | foundSelection.expandTo( currFindRow, numCols() - 1 ); | ||
720 | addSelection( foundSelection ); | ||
721 | setCurrentCell( currFindRow, 0 /* numCols() - 1 */ ); | ||
722 | wrapAround = true; | ||
723 | } | ||
724 | } | 736 | } |
725 | 737 | ||
726 | static bool contactCompare( const OContact &cnt, const QRegExp &r, int category ) | 738 | static bool contactCompare( const OContact &cnt, const QRegExp &r, int category ) |
727 | { | 739 | { |
728 | bool returnMe; | 740 | bool returnMe; |
729 | QArray<int> cats; | 741 | QArray<int> cats; |
730 | cats = cnt.categories(); | 742 | cats = cnt.categories(); |
731 | 743 | ||
732 | returnMe = false; | 744 | returnMe = false; |
733 | if ( (cats.count() == 0) || (category == 0) ) | 745 | if ( (cats.count() == 0) || (category == 0) ) |
734 | returnMe = cnt.match( r ); | 746 | returnMe = cnt.match( r ); |
735 | else { | 747 | else { |
736 | int i; | 748 | int i; |
737 | for ( i = 0; i < int(cats.count()); i++ ) { | 749 | for ( i = 0; i < int(cats.count()); i++ ) { |
738 | if ( cats[i] == category ) { | 750 | if ( cats[i] == category ) { |
739 | returnMe = cnt.match( r ); | 751 | returnMe = cnt.match( r ); |
740 | break; | 752 | break; |
741 | } | 753 | } |
742 | } | 754 | } |
743 | } | 755 | } |
744 | 756 | ||
745 | return returnMe; | 757 | return returnMe; |
746 | } | 758 | } |
747 | 759 | ||