author | zautrix <zautrix> | 2004-09-03 09:23:23 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2004-09-03 09:23:23 (UTC) |
commit | d171ed3b09665db0f511310d6c84a23d75135f50 (patch) (unidiff) | |
tree | 557b3fd423a022559971ceafa61def5adbb7e828 | |
parent | f6b72fd55671131cd81a3357940c9337ea5d7494 (diff) | |
download | kdepimpi-d171ed3b09665db0f511310d6c84a23d75135f50.zip kdepimpi-d171ed3b09665db0f511310d6c84a23d75135f50.tar.gz kdepimpi-d171ed3b09665db0f511310d6c84a23d75135f50.tar.bz2 |
Much better search possibility in kapi
-rw-r--r-- | kaddressbook/incsearchwidget.cpp | 7 | ||||
-rw-r--r-- | kaddressbook/kabcore.cpp | 42 | ||||
-rw-r--r-- | kaddressbook/viewmanager.cpp | 7 | ||||
-rw-r--r-- | kaddressbook/viewmanager.h | 1 | ||||
-rw-r--r-- | kaddressbook/views/kaddressbooktableview.cpp | 6 |
5 files changed, 48 insertions, 15 deletions
diff --git a/kaddressbook/incsearchwidget.cpp b/kaddressbook/incsearchwidget.cpp index 94c37e7..2ffa357 100644 --- a/kaddressbook/incsearchwidget.cpp +++ b/kaddressbook/incsearchwidget.cpp | |||
@@ -1,147 +1,150 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of KAddressBook. | 2 | This file is part of KAddressBook. |
3 | Copyright (c) 2002 Tobias Koenig <tokoe@kde.org> | 3 | Copyright (c) 2002 Tobias Koenig <tokoe@kde.org> |
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 | #include <qlabel.h> | 24 | #include <qlabel.h> |
25 | #include <qlayout.h> | 25 | #include <qlayout.h> |
26 | #include <qtooltip.h> | 26 | #include <qtooltip.h> |
27 | #include <qcombobox.h> | 27 | #include <qcombobox.h> |
28 | 28 | ||
29 | #include <kdialog.h> | 29 | #include <kdialog.h> |
30 | #include <klineedit.h> | 30 | #include <klineedit.h> |
31 | #include <klocale.h> | 31 | #include <klocale.h> |
32 | #include <kglobal.h> | 32 | #include <kglobal.h> |
33 | 33 | ||
34 | #include "incsearchwidget.h" | 34 | #include "incsearchwidget.h" |
35 | 35 | ||
36 | IncSearchWidget::IncSearchWidget( QWidget *parent, const char *name ) | 36 | IncSearchWidget::IncSearchWidget( QWidget *parent, const char *name ) |
37 | : QWidget( parent, name ) | 37 | : QWidget( parent, name ) |
38 | { | 38 | { |
39 | #ifndef KAB_EMBEDDED | 39 | #ifndef KAB_EMBEDDED |
40 | //US setCaption( i18n( "Incremental Search" ) ); | 40 | //US setCaption( i18n( "Incremental Search" ) ); |
41 | #endif //KAB_EMBEDDED | 41 | #endif //KAB_EMBEDDED |
42 | 42 | ||
43 | QHBoxLayout *layout = new QHBoxLayout( this, 2, KDialog::spacingHint() ); | 43 | QHBoxLayout *layout = new QHBoxLayout( this, 2, KDialog::spacingHint() ); |
44 | 44 | ||
45 | #ifdef DESKTOP_VERSION | 45 | #ifdef DESKTOP_VERSION |
46 | QLabel *label = new QLabel( i18n( "Search:" ), this ); | 46 | QLabel *label = new QLabel( i18n( "Search:" ), this ); |
47 | label->setAlignment( QLabel::AlignVCenter | QLabel::AlignRight ); | 47 | label->setAlignment( QLabel::AlignVCenter | QLabel::AlignRight ); |
48 | layout->addWidget( label ); | 48 | layout->addWidget( label ); |
49 | #endif //KAB_EMBEDDED | 49 | #endif //KAB_EMBEDDED |
50 | 50 | ||
51 | mSearchText = new KLineEdit( this ); | 51 | mSearchText = new KLineEdit( this ); |
52 | layout->addWidget( mSearchText ); | 52 | layout->addWidget( mSearchText ); |
53 | // #ifdef KAB_EMBEDDED | 53 | // #ifdef KAB_EMBEDDED |
54 | // if (KGlobal::getOrientation() == KGlobal::Portrait) | 54 | // if (KGlobal::getOrientation() == KGlobal::Portrait) |
55 | // mSearchText->setMaximumWidth(30); | 55 | // mSearchText->setMaximumWidth(30); |
56 | // #endif //KAB_EMBEDDED | 56 | // #endif //KAB_EMBEDDED |
57 | 57 | ||
58 | 58 | ||
59 | mFieldCombo = new QComboBox( false, this ); | 59 | mFieldCombo = new QComboBox( false, this ); |
60 | layout->addWidget( mFieldCombo ); | 60 | layout->addWidget( mFieldCombo ); |
61 | mFieldCombo->setMaximumHeight( 34 ); | 61 | mFieldCombo->setMaximumHeight( 34 ); |
62 | QToolTip::add( mFieldCombo, i18n( "Select Incremental Search Field" ) ); | 62 | QToolTip::add( mFieldCombo, i18n( "Select Incremental Search Field" ) ); |
63 | 63 | ||
64 | // #ifndef KAB_EMBEDDED | 64 | // #ifndef KAB_EMBEDDED |
65 | // resize( QSize(420, 50).expandedTo( sizeHint() ) ); | 65 | // resize( QSize(420, 50).expandedTo( sizeHint() ) ); |
66 | // #else //KAB_EMBEDDED | 66 | // #else //KAB_EMBEDDED |
67 | // resize( QSize(30, 10).expandedTo( sizeHint() ) ); | 67 | // resize( QSize(30, 10).expandedTo( sizeHint() ) ); |
68 | // #endif //KAB_EMBEDDED | 68 | // #endif //KAB_EMBEDDED |
69 | 69 | ||
70 | #ifdef DESKTOP_VERSION | ||
71 | // for performance reasons, we do a search on the pda only after return is pressed | ||
70 | connect( mSearchText, SIGNAL( textChanged( const QString& ) ), | 72 | connect( mSearchText, SIGNAL( textChanged( const QString& ) ), |
71 | SLOT( announceDoSearch() ) ); | 73 | SLOT( announceDoSearch() ) ); |
72 | connect( mSearchText, SIGNAL( returnPressed() ), | ||
73 | SLOT( announceDoSearch() ) ); | ||
74 | connect( mFieldCombo, SIGNAL( activated( const QString& ) ), | 74 | connect( mFieldCombo, SIGNAL( activated( const QString& ) ), |
75 | SLOT( announceDoSearch() ) ); | 75 | SLOT( announceDoSearch() ) ); |
76 | #endif | ||
77 | connect( mSearchText, SIGNAL( returnPressed() ), | ||
78 | SLOT( announceDoSearch() ) ); | ||
76 | connect( mFieldCombo, SIGNAL( activated( const QString& ) ), | 79 | connect( mFieldCombo, SIGNAL( activated( const QString& ) ), |
77 | SLOT( announceFieldChanged() ) ); | 80 | SLOT( announceFieldChanged() ) ); |
78 | 81 | ||
79 | setFocusProxy( mSearchText ); | 82 | setFocusProxy( mSearchText ); |
80 | } | 83 | } |
81 | 84 | ||
82 | IncSearchWidget::~IncSearchWidget() | 85 | IncSearchWidget::~IncSearchWidget() |
83 | { | 86 | { |
84 | 87 | ||
85 | } | 88 | } |
86 | 89 | ||
87 | void IncSearchWidget::announceDoSearch() | 90 | void IncSearchWidget::announceDoSearch() |
88 | { | 91 | { |
89 | emit doSearch( mSearchText->text() ); | 92 | emit doSearch( mSearchText->text() ); |
90 | } | 93 | } |
91 | 94 | ||
92 | void IncSearchWidget::announceFieldChanged() | 95 | void IncSearchWidget::announceFieldChanged() |
93 | { | 96 | { |
94 | emit fieldChanged(); | 97 | emit fieldChanged(); |
95 | } | 98 | } |
96 | 99 | ||
97 | void IncSearchWidget::setFields( const KABC::Field::List &list ) | 100 | void IncSearchWidget::setFields( const KABC::Field::List &list ) |
98 | { | 101 | { |
99 | 102 | ||
100 | mFieldCombo->clear(); | 103 | mFieldCombo->clear(); |
101 | mFieldCombo->insertItem( i18n( "All Fields" ) ); | 104 | mFieldCombo->insertItem( i18n( "All Fields" ) ); |
102 | QFontMetrics fm ( mFieldCombo->font() ); | 105 | QFontMetrics fm ( mFieldCombo->font() ); |
103 | int wid = fm.width(i18n( "All Fields" ) ); | 106 | int wid = fm.width(i18n( "All Fields" ) ); |
104 | int max = wid; | 107 | int max = wid; |
105 | 108 | ||
106 | KABC::Field::List::ConstIterator it; | 109 | KABC::Field::List::ConstIterator it; |
107 | for ( it = list.begin(); it != list.end(); ++it ) { | 110 | for ( it = list.begin(); it != list.end(); ++it ) { |
108 | mFieldCombo->insertItem( (*it)->label() ); | 111 | mFieldCombo->insertItem( (*it)->label() ); |
109 | // wid = fm.width((*it)->label() ); | 112 | // wid = fm.width((*it)->label() ); |
110 | //if ( wid > max ) | 113 | //if ( wid > max ) |
111 | // max = wid; | 114 | // max = wid; |
112 | } | 115 | } |
113 | 116 | ||
114 | mFieldList = list; | 117 | mFieldList = list; |
115 | 118 | ||
116 | announceDoSearch(); | 119 | announceDoSearch(); |
117 | announceFieldChanged(); | 120 | announceFieldChanged(); |
118 | mFieldCombo->setMaximumWidth( wid+60 ); | 121 | mFieldCombo->setMaximumWidth( wid+60 ); |
119 | } | 122 | } |
120 | 123 | ||
121 | KABC::Field::List IncSearchWidget::fields() const | 124 | KABC::Field::List IncSearchWidget::fields() const |
122 | { | 125 | { |
123 | return mFieldList; | 126 | return mFieldList; |
124 | } | 127 | } |
125 | 128 | ||
126 | KABC::Field *IncSearchWidget::currentField()const | 129 | KABC::Field *IncSearchWidget::currentField()const |
127 | { | 130 | { |
128 | if ( mFieldCombo->currentItem() == -1 || mFieldCombo->currentItem() == 0 ) | 131 | if ( mFieldCombo->currentItem() == -1 || mFieldCombo->currentItem() == 0 ) |
129 | return 0; // for error or 'use all fields' | 132 | return 0; // for error or 'use all fields' |
130 | else | 133 | else |
131 | return mFieldList[ mFieldCombo->currentItem() - 1 ]; | 134 | return mFieldList[ mFieldCombo->currentItem() - 1 ]; |
132 | } | 135 | } |
133 | 136 | ||
134 | void IncSearchWidget::setCurrentItem( int pos ) | 137 | void IncSearchWidget::setCurrentItem( int pos ) |
135 | { | 138 | { |
136 | mFieldCombo->setCurrentItem( pos ); | 139 | mFieldCombo->setCurrentItem( pos ); |
137 | announceFieldChanged(); | 140 | announceFieldChanged(); |
138 | } | 141 | } |
139 | 142 | ||
140 | int IncSearchWidget::currentItem() const | 143 | int IncSearchWidget::currentItem() const |
141 | { | 144 | { |
142 | 145 | ||
143 | return mFieldCombo->currentItem(); | 146 | return mFieldCombo->currentItem(); |
144 | } | 147 | } |
145 | #ifndef KAB_EMBEDDED | 148 | #ifndef KAB_EMBEDDED |
146 | #include "incsearchwidget.moc" | 149 | #include "incsearchwidget.moc" |
147 | #endif //KAB_EMBEDDED | 150 | #endif //KAB_EMBEDDED |
diff --git a/kaddressbook/kabcore.cpp b/kaddressbook/kabcore.cpp index f0f08f4..4299ebd 100644 --- a/kaddressbook/kabcore.cpp +++ b/kaddressbook/kabcore.cpp | |||
@@ -740,219 +740,241 @@ void KABCore::cutContacts() | |||
740 | //US if ( uidList.size() > 0 ) { | 740 | //US if ( uidList.size() > 0 ) { |
741 | if ( uidList.count() > 0 ) { | 741 | if ( uidList.count() > 0 ) { |
742 | PwCutCommand *command = new PwCutCommand( mAddressBook, uidList ); | 742 | PwCutCommand *command = new PwCutCommand( mAddressBook, uidList ); |
743 | UndoStack::instance()->push( command ); | 743 | UndoStack::instance()->push( command ); |
744 | RedoStack::instance()->clear(); | 744 | RedoStack::instance()->clear(); |
745 | 745 | ||
746 | setModified( true ); | 746 | setModified( true ); |
747 | } | 747 | } |
748 | } | 748 | } |
749 | 749 | ||
750 | void KABCore::pasteContacts() | 750 | void KABCore::pasteContacts() |
751 | { | 751 | { |
752 | QClipboard *cb = QApplication::clipboard(); | 752 | QClipboard *cb = QApplication::clipboard(); |
753 | 753 | ||
754 | KABC::Addressee::List list = AddresseeUtil::clipboardToAddressees( cb->text() ); | 754 | KABC::Addressee::List list = AddresseeUtil::clipboardToAddressees( cb->text() ); |
755 | 755 | ||
756 | pasteContacts( list ); | 756 | pasteContacts( list ); |
757 | } | 757 | } |
758 | 758 | ||
759 | void KABCore::pasteContacts( KABC::Addressee::List &list ) | 759 | void KABCore::pasteContacts( KABC::Addressee::List &list ) |
760 | { | 760 | { |
761 | KABC::Resource *resource = requestResource( this ); | 761 | KABC::Resource *resource = requestResource( this ); |
762 | KABC::Addressee::List::Iterator it; | 762 | KABC::Addressee::List::Iterator it; |
763 | for ( it = list.begin(); it != list.end(); ++it ) | 763 | for ( it = list.begin(); it != list.end(); ++it ) |
764 | (*it).setResource( resource ); | 764 | (*it).setResource( resource ); |
765 | 765 | ||
766 | PwPasteCommand *command = new PwPasteCommand( this, list ); | 766 | PwPasteCommand *command = new PwPasteCommand( this, list ); |
767 | UndoStack::instance()->push( command ); | 767 | UndoStack::instance()->push( command ); |
768 | RedoStack::instance()->clear(); | 768 | RedoStack::instance()->clear(); |
769 | 769 | ||
770 | setModified( true ); | 770 | setModified( true ); |
771 | } | 771 | } |
772 | 772 | ||
773 | void KABCore::setWhoAmI() | 773 | void KABCore::setWhoAmI() |
774 | { | 774 | { |
775 | KABC::Addressee::List addrList = mViewManager->selectedAddressees(); | 775 | KABC::Addressee::List addrList = mViewManager->selectedAddressees(); |
776 | 776 | ||
777 | if ( addrList.count() > 1 ) { | 777 | if ( addrList.count() > 1 ) { |
778 | KMessageBox::sorry( this, i18n( "Please select only one contact." ) ); | 778 | KMessageBox::sorry( this, i18n( "Please select only one contact." ) ); |
779 | return; | 779 | return; |
780 | } | 780 | } |
781 | 781 | ||
782 | QString text( i18n( "<qt>Do you really want to use <b>%1</b> as your new personal contact?</qt>" ) ); | 782 | QString text( i18n( "<qt>Do you really want to use <b>%1</b> as your new personal contact?</qt>" ) ); |
783 | if ( KMessageBox::questionYesNo( this, text.arg( addrList[ 0 ].assembledName() ) ) == KMessageBox::Yes ) | 783 | if ( KMessageBox::questionYesNo( this, text.arg( addrList[ 0 ].assembledName() ) ) == KMessageBox::Yes ) |
784 | static_cast<KABC::StdAddressBook*>( KABC::StdAddressBook::self() )->setWhoAmI( addrList[ 0 ] ); | 784 | static_cast<KABC::StdAddressBook*>( KABC::StdAddressBook::self() )->setWhoAmI( addrList[ 0 ] ); |
785 | } | 785 | } |
786 | 786 | ||
787 | void KABCore::setCategories() | 787 | void KABCore::setCategories() |
788 | { | 788 | { |
789 | KPIM::CategorySelectDialog dlg( KABPrefs::instance(), this, "", true ); | 789 | KPIM::CategorySelectDialog dlg( KABPrefs::instance(), this, "", true ); |
790 | if ( !dlg.exec() ) | 790 | if ( !dlg.exec() ) |
791 | return; | 791 | return; |
792 | 792 | ||
793 | bool merge = false; | 793 | bool merge = false; |
794 | QString msg = i18n( "Merge with existing categories?" ); | 794 | QString msg = i18n( "Merge with existing categories?" ); |
795 | if ( KMessageBox::questionYesNo( this, msg ) == KMessageBox::Yes ) | 795 | if ( KMessageBox::questionYesNo( this, msg ) == KMessageBox::Yes ) |
796 | merge = true; | 796 | merge = true; |
797 | 797 | ||
798 | QStringList categories = dlg.selectedCategories(); | 798 | QStringList categories = dlg.selectedCategories(); |
799 | 799 | ||
800 | QStringList uids = mViewManager->selectedUids(); | 800 | QStringList uids = mViewManager->selectedUids(); |
801 | QStringList::Iterator it; | 801 | QStringList::Iterator it; |
802 | for ( it = uids.begin(); it != uids.end(); ++it ) { | 802 | for ( it = uids.begin(); it != uids.end(); ++it ) { |
803 | KABC::Addressee addr = mAddressBook->findByUid( *it ); | 803 | KABC::Addressee addr = mAddressBook->findByUid( *it ); |
804 | if ( !addr.isEmpty() ) { | 804 | if ( !addr.isEmpty() ) { |
805 | if ( !merge ) | 805 | if ( !merge ) |
806 | addr.setCategories( categories ); | 806 | addr.setCategories( categories ); |
807 | else { | 807 | else { |
808 | QStringList addrCategories = addr.categories(); | 808 | QStringList addrCategories = addr.categories(); |
809 | QStringList::Iterator catIt; | 809 | QStringList::Iterator catIt; |
810 | for ( catIt = categories.begin(); catIt != categories.end(); ++catIt ) { | 810 | for ( catIt = categories.begin(); catIt != categories.end(); ++catIt ) { |
811 | if ( !addrCategories.contains( *catIt ) ) | 811 | if ( !addrCategories.contains( *catIt ) ) |
812 | addrCategories.append( *catIt ); | 812 | addrCategories.append( *catIt ); |
813 | } | 813 | } |
814 | addr.setCategories( addrCategories ); | 814 | addr.setCategories( addrCategories ); |
815 | } | 815 | } |
816 | 816 | ||
817 | mAddressBook->insertAddressee( addr ); | 817 | mAddressBook->insertAddressee( addr ); |
818 | } | 818 | } |
819 | } | 819 | } |
820 | 820 | ||
821 | if ( uids.count() > 0 ) | 821 | if ( uids.count() > 0 ) |
822 | setModified( true ); | 822 | setModified( true ); |
823 | } | 823 | } |
824 | 824 | ||
825 | void KABCore::setSearchFields( const KABC::Field::List &fields ) | 825 | void KABCore::setSearchFields( const KABC::Field::List &fields ) |
826 | { | 826 | { |
827 | mIncSearchWidget->setFields( fields ); | 827 | mIncSearchWidget->setFields( fields ); |
828 | } | 828 | } |
829 | 829 | ||
830 | void KABCore::incrementalSearch( const QString& text ) | 830 | void KABCore::incrementalSearch( const QString& text ) |
831 | { | 831 | { |
832 | mViewManager->setSelected( QString::null, false ); | 832 | mViewManager->setSelected( QString::null, false ); |
833 | 833 | ||
834 | if ( !text.isEmpty() ) { | 834 | if ( !text.isEmpty() ) { |
835 | KABC::Field *field = mIncSearchWidget->currentField(); | 835 | KABC::Field *field = mIncSearchWidget->currentField(); |
836 | 836 | QString pattern = text.lower()+"*"; | |
837 | QString pattern = text.lower(); | 837 | QRegExp re; |
838 | 838 | re.setWildcard(true); // most people understand these better. | |
839 | re.setCaseSensitive(false); | ||
840 | re.setPattern( pattern ); | ||
841 | QStringList foundUids; | ||
842 | if (!re.isValid()) | ||
843 | return; | ||
839 | #if 1 //KDE_VERSION >= 319 | 844 | #if 1 //KDE_VERSION >= 319 |
840 | KABC::AddresseeList list( mAddressBook->allAddressees() ); | 845 | KABC::AddresseeList list( mAddressBook->allAddressees() ); |
841 | if ( field ) { | 846 | if ( field ) { |
842 | list.sortByField( field ); | 847 | list.sortByField( field ); |
843 | KABC::AddresseeList::Iterator it; | 848 | KABC::AddresseeList::Iterator it; |
844 | for ( it = list.begin(); it != list.end(); ++it ) { | 849 | for ( it = list.begin(); it != list.end(); ++it ) { |
845 | if ( field->value( *it ).lower().startsWith( pattern ) ) { | 850 | |
846 | mViewManager->setSelected( (*it).uid(), true ); | 851 | #if QT_VERSION >= 300 |
847 | return; | 852 | if (re.search(field->value( *it ).lower()) != -1) |
848 | } | 853 | #else |
854 | if (re.match(field->value( *it ).lower()) != -1) | ||
855 | #endif | ||
856 | { | ||
857 | // if ( field->value( *it ).lower().startsWith( pattern ) ) { | ||
858 | //mViewManager->setSelected( (*it).uid(), true ); | ||
859 | foundUids.append( (*it).uid() ); | ||
860 | //return; | ||
861 | } | ||
849 | } | 862 | } |
850 | } else { | 863 | } else { |
851 | KABC::AddresseeList::Iterator it; | 864 | KABC::AddresseeList::Iterator it; |
852 | for ( it = list.begin(); it != list.end(); ++it ) { | 865 | for ( it = list.begin(); it != list.end(); ++it ) { |
853 | KABC::Field::List fieldList = mIncSearchWidget->fields(); | 866 | KABC::Field::List fieldList = mIncSearchWidget->fields(); |
854 | KABC::Field::List::ConstIterator fieldIt; | 867 | KABC::Field::List::ConstIterator fieldIt; |
855 | for ( fieldIt = fieldList.begin(); fieldIt != fieldList.end(); ++fieldIt ) { | 868 | for ( fieldIt = fieldList.begin(); fieldIt != fieldList.end(); ++fieldIt ) { |
856 | if ( (*fieldIt)->value( *it ).lower().startsWith( pattern ) ) { | 869 | #if QT_VERSION >= 300 |
857 | mViewManager->setSelected( (*it).uid(), true ); | 870 | if (re.search((*fieldIt)->value( *it ).lower()) != -1) |
858 | return; | 871 | #else |
872 | if (re.match((*fieldIt)->value( *it ).lower()) != -1) | ||
873 | #endif | ||
874 | { | ||
875 | // if ( (*fieldIt)->value( *it ).lower().startsWith( pattern ) ) { | ||
876 | //mViewManager->setSelected( (*it).uid(), true ); | ||
877 | foundUids.append( (*it).uid() ); | ||
878 | //return; | ||
859 | } | 879 | } |
860 | } | 880 | } |
861 | } | 881 | } |
862 | } | 882 | } |
883 | if ( foundUids.count() > 0 ) | ||
884 | mViewManager->setListSelected( foundUids ); | ||
863 | #else | 885 | #else |
864 | KABC::AddressBook::Iterator it; | 886 | KABC::AddressBook::Iterator it; |
865 | for ( it = mAddressBook->begin(); it != mAddressBook->end(); ++it ) { | 887 | for ( it = mAddressBook->begin(); it != mAddressBook->end(); ++it ) { |
866 | if ( field ) { | 888 | if ( field ) { |
867 | if ( field->value( *it ).lower().startsWith( pattern ) ) { | 889 | if ( field->value( *it ).lower().startsWith( pattern ) ) { |
868 | mViewManager->setSelected( (*it).uid(), true ); | 890 | mViewManager->setSelected( (*it).uid(), true ); |
869 | return; | 891 | return; |
870 | } | 892 | } |
871 | } else { | 893 | } else { |
872 | KABC::Field::List fieldList = mIncSearchWidget->fields(); | 894 | KABC::Field::List fieldList = mIncSearchWidget->fields(); |
873 | KABC::Field::List::ConstIterator fieldIt; | 895 | KABC::Field::List::ConstIterator fieldIt; |
874 | for ( fieldIt = fieldList.begin(); fieldIt != fieldList.end(); ++fieldIt ) { | 896 | for ( fieldIt = fieldList.begin(); fieldIt != fieldList.end(); ++fieldIt ) { |
875 | if ( (*fieldIt)->value( *it ).lower().startsWith( pattern ) ) { | 897 | if ( (*fieldIt)->value( *it ).lower().startsWith( pattern ) ) { |
876 | mViewManager->setSelected( (*it).uid(), true ); | 898 | mViewManager->setSelected( (*it).uid(), true ); |
877 | return; | 899 | return; |
878 | } | 900 | } |
879 | } | 901 | } |
880 | } | 902 | } |
881 | } | 903 | } |
882 | #endif | 904 | #endif |
883 | } | 905 | } |
884 | } | 906 | } |
885 | 907 | ||
886 | void KABCore::setModified() | 908 | void KABCore::setModified() |
887 | { | 909 | { |
888 | setModified( true ); | 910 | setModified( true ); |
889 | } | 911 | } |
890 | 912 | ||
891 | void KABCore::setModifiedWOrefresh() | 913 | void KABCore::setModifiedWOrefresh() |
892 | { | 914 | { |
893 | // qDebug("KABCore::setModifiedWOrefresh() "); | 915 | // qDebug("KABCore::setModifiedWOrefresh() "); |
894 | mModified = true; | 916 | mModified = true; |
895 | mActionSave->setEnabled( mModified ); | 917 | mActionSave->setEnabled( mModified ); |
896 | #ifdef DESKTOP_VERSION | 918 | #ifdef DESKTOP_VERSION |
897 | mDetails->refreshView(); | 919 | mDetails->refreshView(); |
898 | #endif | 920 | #endif |
899 | 921 | ||
900 | } | 922 | } |
901 | void KABCore::setModified( bool modified ) | 923 | void KABCore::setModified( bool modified ) |
902 | { | 924 | { |
903 | mModified = modified; | 925 | mModified = modified; |
904 | mActionSave->setEnabled( mModified ); | 926 | mActionSave->setEnabled( mModified ); |
905 | 927 | ||
906 | if ( modified ) | 928 | if ( modified ) |
907 | mJumpButtonBar->recreateButtons(); | 929 | mJumpButtonBar->recreateButtons(); |
908 | 930 | ||
909 | mViewManager->refreshView(); | 931 | mViewManager->refreshView(); |
910 | mDetails->refreshView(); | 932 | mDetails->refreshView(); |
911 | 933 | ||
912 | } | 934 | } |
913 | 935 | ||
914 | bool KABCore::modified() const | 936 | bool KABCore::modified() const |
915 | { | 937 | { |
916 | return mModified; | 938 | return mModified; |
917 | } | 939 | } |
918 | 940 | ||
919 | void KABCore::contactModified( const KABC::Addressee &addr ) | 941 | void KABCore::contactModified( const KABC::Addressee &addr ) |
920 | { | 942 | { |
921 | 943 | ||
922 | Command *command = 0; | 944 | Command *command = 0; |
923 | QString uid; | 945 | QString uid; |
924 | 946 | ||
925 | // check if it exists already | 947 | // check if it exists already |
926 | KABC::Addressee origAddr = mAddressBook->findByUid( addr.uid() ); | 948 | KABC::Addressee origAddr = mAddressBook->findByUid( addr.uid() ); |
927 | if ( origAddr.isEmpty() ) | 949 | if ( origAddr.isEmpty() ) |
928 | command = new PwNewCommand( mAddressBook, addr ); | 950 | command = new PwNewCommand( mAddressBook, addr ); |
929 | else { | 951 | else { |
930 | command = new PwEditCommand( mAddressBook, origAddr, addr ); | 952 | command = new PwEditCommand( mAddressBook, origAddr, addr ); |
931 | uid = addr.uid(); | 953 | uid = addr.uid(); |
932 | } | 954 | } |
933 | 955 | ||
934 | UndoStack::instance()->push( command ); | 956 | UndoStack::instance()->push( command ); |
935 | RedoStack::instance()->clear(); | 957 | RedoStack::instance()->clear(); |
936 | 958 | ||
937 | setModified( true ); | 959 | setModified( true ); |
938 | } | 960 | } |
939 | 961 | ||
940 | void KABCore::newContact() | 962 | void KABCore::newContact() |
941 | { | 963 | { |
942 | 964 | ||
943 | 965 | ||
944 | QPtrList<KABC::Resource> kabcResources = mAddressBook->resources(); | 966 | QPtrList<KABC::Resource> kabcResources = mAddressBook->resources(); |
945 | 967 | ||
946 | QPtrList<KRES::Resource> kresResources; | 968 | QPtrList<KRES::Resource> kresResources; |
947 | QPtrListIterator<KABC::Resource> it( kabcResources ); | 969 | QPtrListIterator<KABC::Resource> it( kabcResources ); |
948 | KABC::Resource *resource; | 970 | KABC::Resource *resource; |
949 | while ( ( resource = it.current() ) != 0 ) { | 971 | while ( ( resource = it.current() ) != 0 ) { |
950 | ++it; | 972 | ++it; |
951 | if ( !resource->readOnly() ) { | 973 | if ( !resource->readOnly() ) { |
952 | KRES::Resource *res = static_cast<KRES::Resource*>( resource ); | 974 | KRES::Resource *res = static_cast<KRES::Resource*>( resource ); |
953 | if ( res ) | 975 | if ( res ) |
954 | kresResources.append( res ); | 976 | kresResources.append( res ); |
955 | } | 977 | } |
956 | } | 978 | } |
957 | 979 | ||
958 | KRES::Resource *res = KRES::SelectDialog::getResource( kresResources, this ); | 980 | KRES::Resource *res = KRES::SelectDialog::getResource( kresResources, this ); |
diff --git a/kaddressbook/viewmanager.cpp b/kaddressbook/viewmanager.cpp index 45c7b55..c93d51a 100644 --- a/kaddressbook/viewmanager.cpp +++ b/kaddressbook/viewmanager.cpp | |||
@@ -85,192 +85,199 @@ ViewManager::~ViewManager() | |||
85 | unloadViews(); | 85 | unloadViews(); |
86 | mViewFactoryDict.clear(); | 86 | mViewFactoryDict.clear(); |
87 | } | 87 | } |
88 | 88 | ||
89 | void ViewManager::restoreSettings() | 89 | void ViewManager::restoreSettings() |
90 | { | 90 | { |
91 | mViewNameList = KABPrefs::instance()->mViewNames; | 91 | mViewNameList = KABPrefs::instance()->mViewNames; |
92 | QString activeViewName = KABPrefs::instance()->mCurrentView; | 92 | QString activeViewName = KABPrefs::instance()->mCurrentView; |
93 | 93 | ||
94 | mActionSelectView->setItems( mViewNameList ); | 94 | mActionSelectView->setItems( mViewNameList ); |
95 | 95 | ||
96 | // Filter | 96 | // Filter |
97 | mFilterList = Filter::restore( mCore->config(), "Filter" ); | 97 | mFilterList = Filter::restore( mCore->config(), "Filter" ); |
98 | mActionSelectFilter->setItems( filterNames() ); | 98 | mActionSelectFilter->setItems( filterNames() ); |
99 | mActionSelectFilter->setCurrentItem( KABPrefs::instance()->mCurrentFilter ); | 99 | mActionSelectFilter->setCurrentItem( KABPrefs::instance()->mCurrentFilter ); |
100 | 100 | ||
101 | // Tell the views to reread their config, since they may have | 101 | // Tell the views to reread their config, since they may have |
102 | // been modified by global settings | 102 | // been modified by global settings |
103 | QString _oldgroup = mCore->config()->group(); | 103 | QString _oldgroup = mCore->config()->group(); |
104 | 104 | ||
105 | QDictIterator<KAddressBookView> it( mViewDict ); | 105 | QDictIterator<KAddressBookView> it( mViewDict ); |
106 | for ( it.toFirst(); it.current(); ++it ) { | 106 | for ( it.toFirst(); it.current(); ++it ) { |
107 | KConfigGroupSaver saver( mCore->config(), it.currentKey() ); | 107 | KConfigGroupSaver saver( mCore->config(), it.currentKey() ); |
108 | it.current()->readConfig( mCore->config() ); | 108 | it.current()->readConfig( mCore->config() ); |
109 | } | 109 | } |
110 | setActiveView( activeViewName ); | 110 | setActiveView( activeViewName ); |
111 | 111 | ||
112 | mActionDeleteView->setEnabled( mViewNameList.count() > 1 ); | 112 | mActionDeleteView->setEnabled( mViewNameList.count() > 1 ); |
113 | } | 113 | } |
114 | 114 | ||
115 | void ViewManager::saveSettings() | 115 | void ViewManager::saveSettings() |
116 | { | 116 | { |
117 | QString _oldgroup = mCore->config()->group(); | 117 | QString _oldgroup = mCore->config()->group(); |
118 | 118 | ||
119 | QDictIterator<KAddressBookView> it( mViewDict ); | 119 | QDictIterator<KAddressBookView> it( mViewDict ); |
120 | for ( it.toFirst(); it.current(); ++it ) { | 120 | for ( it.toFirst(); it.current(); ++it ) { |
121 | KConfigGroupSaver saver( mCore->config(), it.currentKey() ); | 121 | KConfigGroupSaver saver( mCore->config(), it.currentKey() ); |
122 | #ifdef DESKTOP_VERSION | 122 | #ifdef DESKTOP_VERSION |
123 | (*it)->writeConfig( mCore->config() ); | 123 | (*it)->writeConfig( mCore->config() ); |
124 | #else | 124 | #else |
125 | (*it).writeConfig( mCore->config() ); | 125 | (*it).writeConfig( mCore->config() ); |
126 | #endif | 126 | #endif |
127 | } | 127 | } |
128 | 128 | ||
129 | Filter::save( mCore->config(), "Filter", mFilterList ); | 129 | Filter::save( mCore->config(), "Filter", mFilterList ); |
130 | KABPrefs::instance()->mCurrentFilter = mActionSelectFilter->currentItem(); | 130 | KABPrefs::instance()->mCurrentFilter = mActionSelectFilter->currentItem(); |
131 | 131 | ||
132 | // write the view name list | 132 | // write the view name list |
133 | KABPrefs::instance()->mViewNames = mViewNameList; | 133 | KABPrefs::instance()->mViewNames = mViewNameList; |
134 | KABPrefs::instance()->mCurrentView = mActiveView->caption(); | 134 | KABPrefs::instance()->mCurrentView = mActiveView->caption(); |
135 | 135 | ||
136 | } | 136 | } |
137 | 137 | ||
138 | QStringList ViewManager::selectedUids() const | 138 | QStringList ViewManager::selectedUids() const |
139 | { | 139 | { |
140 | if ( mActiveView ) | 140 | if ( mActiveView ) |
141 | return mActiveView->selectedUids(); | 141 | return mActiveView->selectedUids(); |
142 | else | 142 | else |
143 | return QStringList(); | 143 | return QStringList(); |
144 | } | 144 | } |
145 | 145 | ||
146 | QStringList ViewManager::selectedEmails() const | 146 | QStringList ViewManager::selectedEmails() const |
147 | { | 147 | { |
148 | if ( mActiveView ) | 148 | if ( mActiveView ) |
149 | return mActiveView->selectedEmails(); | 149 | return mActiveView->selectedEmails(); |
150 | else | 150 | else |
151 | return QStringList(); | 151 | return QStringList(); |
152 | } | 152 | } |
153 | 153 | ||
154 | KABC::Addressee::List ViewManager::selectedAddressees() const | 154 | KABC::Addressee::List ViewManager::selectedAddressees() const |
155 | { | 155 | { |
156 | KABC::Addressee::List list; | 156 | KABC::Addressee::List list; |
157 | if ( mActiveView ) { | 157 | if ( mActiveView ) { |
158 | QStringList uids = mActiveView->selectedUids(); | 158 | QStringList uids = mActiveView->selectedUids(); |
159 | QStringList::Iterator it; | 159 | QStringList::Iterator it; |
160 | for ( it = uids.begin(); it != uids.end(); ++it ) { | 160 | for ( it = uids.begin(); it != uids.end(); ++it ) { |
161 | KABC::Addressee addr = mCore->addressBook()->findByUid( *it ); | 161 | KABC::Addressee addr = mCore->addressBook()->findByUid( *it ); |
162 | if ( !addr.isEmpty() ) | 162 | if ( !addr.isEmpty() ) |
163 | list.append( addr ); | 163 | list.append( addr ); |
164 | } | 164 | } |
165 | } | 165 | } |
166 | 166 | ||
167 | return list; | 167 | return list; |
168 | } | 168 | } |
169 | //US added another method with no parameter, since my moc compiler does not support default parameters. | 169 | //US added another method with no parameter, since my moc compiler does not support default parameters. |
170 | void ViewManager::setSelected() | 170 | void ViewManager::setSelected() |
171 | { | 171 | { |
172 | setSelected( QString::null, true ); | 172 | setSelected( QString::null, true ); |
173 | } | 173 | } |
174 | 174 | ||
175 | void ViewManager::setSelected( const QString &uid, bool selected ) | 175 | void ViewManager::setSelected( const QString &uid, bool selected ) |
176 | { | 176 | { |
177 | if ( mActiveView ) | 177 | if ( mActiveView ) |
178 | mActiveView->setSelected( uid, selected ); | 178 | mActiveView->setSelected( uid, selected ); |
179 | } | 179 | } |
180 | 180 | ||
181 | void ViewManager::setListSelected(QStringList list) | ||
182 | { | ||
183 | int i, count = list.count(); | ||
184 | for ( i = 0; i < count;++i ) | ||
185 | setSelected( list[i], true ); | ||
186 | |||
187 | } | ||
181 | void ViewManager::unloadViews() | 188 | void ViewManager::unloadViews() |
182 | { | 189 | { |
183 | mViewDict.clear(); | 190 | mViewDict.clear(); |
184 | mActiveView = 0; | 191 | mActiveView = 0; |
185 | } | 192 | } |
186 | 193 | ||
187 | void ViewManager::setActiveView( const QString &name ) | 194 | void ViewManager::setActiveView( const QString &name ) |
188 | { | 195 | { |
189 | KAddressBookView *view = 0; | 196 | KAddressBookView *view = 0; |
190 | 197 | ||
191 | // Check that this isn't the same as the current active view | 198 | // Check that this isn't the same as the current active view |
192 | if ( mActiveView && ( mActiveView->caption() == name ) ) | 199 | if ( mActiveView && ( mActiveView->caption() == name ) ) |
193 | return; | 200 | return; |
194 | 201 | ||
195 | // At this point we know the view that should be active is not | 202 | // At this point we know the view that should be active is not |
196 | // currently active. We will try to find the new on in the list. If | 203 | // currently active. We will try to find the new on in the list. If |
197 | // we can't find it, it means it hasn't been instantiated, so we will | 204 | // we can't find it, it means it hasn't been instantiated, so we will |
198 | // create it on demand. | 205 | // create it on demand. |
199 | 206 | ||
200 | view = mViewDict.find( name ); | 207 | view = mViewDict.find( name ); |
201 | 208 | ||
202 | // Check if we found the view. If we didn't, then we need to create it | 209 | // Check if we found the view. If we didn't, then we need to create it |
203 | if ( view == 0 ) { | 210 | if ( view == 0 ) { |
204 | KConfig *config = mCore->config(); | 211 | KConfig *config = mCore->config(); |
205 | 212 | ||
206 | KConfigGroupSaver saver( config, name ); | 213 | KConfigGroupSaver saver( config, name ); |
207 | 214 | ||
208 | QString type = config->readEntry( "Type", "Table" ); | 215 | QString type = config->readEntry( "Type", "Table" ); |
209 | 216 | ||
210 | kdDebug(5720) << "ViewManager::setActiveView: creating view - " << name << endl; | 217 | kdDebug(5720) << "ViewManager::setActiveView: creating view - " << name << endl; |
211 | 218 | ||
212 | ViewFactory *factory = mViewFactoryDict.find( type ); | 219 | ViewFactory *factory = mViewFactoryDict.find( type ); |
213 | if ( factory ) | 220 | if ( factory ) |
214 | view = factory->view( mCore->addressBook(), mViewWidgetStack ); | 221 | view = factory->view( mCore->addressBook(), mViewWidgetStack ); |
215 | 222 | ||
216 | if ( view ) { | 223 | if ( view ) { |
217 | view->setCaption( name ); | 224 | view->setCaption( name ); |
218 | mViewDict.insert( name, view ); | 225 | mViewDict.insert( name, view ); |
219 | //US my version needs an int as second parameter to addWidget | 226 | //US my version needs an int as second parameter to addWidget |
220 | mViewWidgetStack->addWidget( view, -1 ); | 227 | mViewWidgetStack->addWidget( view, -1 ); |
221 | view->readConfig( config ); | 228 | view->readConfig( config ); |
222 | 229 | ||
223 | // The manager just relays the signals | 230 | // The manager just relays the signals |
224 | connect( view, SIGNAL( selected( const QString& ) ), | 231 | connect( view, SIGNAL( selected( const QString& ) ), |
225 | SIGNAL( selected( const QString & ) ) ); | 232 | SIGNAL( selected( const QString & ) ) ); |
226 | connect( view, SIGNAL( executed( const QString& ) ), | 233 | connect( view, SIGNAL( executed( const QString& ) ), |
227 | SIGNAL( executed( const QString& ) ) ); | 234 | SIGNAL( executed( const QString& ) ) ); |
228 | 235 | ||
229 | connect( view, SIGNAL( deleteRequest( ) ), | 236 | connect( view, SIGNAL( deleteRequest( ) ), |
230 | SIGNAL( deleteRequest( ) ) ); | 237 | SIGNAL( deleteRequest( ) ) ); |
231 | 238 | ||
232 | connect( view, SIGNAL( modified() ), SIGNAL( modified() ) ); | 239 | connect( view, SIGNAL( modified() ), SIGNAL( modified() ) ); |
233 | connect( view, SIGNAL( dropped( QDropEvent* ) ), | 240 | connect( view, SIGNAL( dropped( QDropEvent* ) ), |
234 | SLOT( dropped( QDropEvent* ) ) ); | 241 | SLOT( dropped( QDropEvent* ) ) ); |
235 | connect( view, SIGNAL( startDrag() ), SLOT( startDrag() ) ); | 242 | connect( view, SIGNAL( startDrag() ), SLOT( startDrag() ) ); |
236 | } | 243 | } |
237 | } | 244 | } |
238 | 245 | ||
239 | // If we found or created the view, raise it and refresh it | 246 | // If we found or created the view, raise it and refresh it |
240 | if ( view ) { | 247 | if ( view ) { |
241 | mActiveView = view; | 248 | mActiveView = view; |
242 | mViewWidgetStack->raiseWidget( view ); | 249 | mViewWidgetStack->raiseWidget( view ); |
243 | // Set the proper filter in the view. By setting the combo | 250 | // Set the proper filter in the view. By setting the combo |
244 | // box, the activated slot will be called, which will push | 251 | // box, the activated slot will be called, which will push |
245 | // the filter to the view and refresh it. | 252 | // the filter to the view and refresh it. |
246 | 253 | ||
247 | if ( view->defaultFilterType() == KAddressBookView::None ) { | 254 | if ( view->defaultFilterType() == KAddressBookView::None ) { |
248 | 255 | ||
249 | mActionSelectFilter->setCurrentItem( 0 ); | 256 | mActionSelectFilter->setCurrentItem( 0 ); |
250 | setActiveFilter( 0 ); | 257 | setActiveFilter( 0 ); |
251 | } else if ( view->defaultFilterType() == KAddressBookView::Active ) { | 258 | } else if ( view->defaultFilterType() == KAddressBookView::Active ) { |
252 | setActiveFilter( mActionSelectFilter->currentItem() ); | 259 | setActiveFilter( mActionSelectFilter->currentItem() ); |
253 | } else { | 260 | } else { |
254 | uint pos = filterPosition( view->defaultFilterName() ); | 261 | uint pos = filterPosition( view->defaultFilterName() ); |
255 | mActionSelectFilter->setCurrentItem( pos ); | 262 | mActionSelectFilter->setCurrentItem( pos ); |
256 | setActiveFilter( pos ); | 263 | setActiveFilter( pos ); |
257 | } | 264 | } |
258 | //US qDebug("ViewManager::setActiveView 6" ); | 265 | //US qDebug("ViewManager::setActiveView 6" ); |
259 | 266 | ||
260 | // Update the inc search widget to show the fields in the new active | 267 | // Update the inc search widget to show the fields in the new active |
261 | // view. | 268 | // view. |
262 | mCore->setSearchFields( mActiveView->fields() ); | 269 | mCore->setSearchFields( mActiveView->fields() ); |
263 | 270 | ||
264 | //US performance optimization. setActiveFilter calls also mActiveView->refresh() | 271 | //US performance optimization. setActiveFilter calls also mActiveView->refresh() |
265 | //US mActiveView->refresh(); | 272 | //US mActiveView->refresh(); |
266 | 273 | ||
267 | } | 274 | } |
268 | else | 275 | else |
269 | { | 276 | { |
270 | qDebug("ViewManager::setActiveView: unable to find view" ); | 277 | qDebug("ViewManager::setActiveView: unable to find view" ); |
271 | kdDebug(5720) << "ViewManager::setActiveView: unable to find view\n"; | 278 | kdDebug(5720) << "ViewManager::setActiveView: unable to find view\n"; |
272 | } | 279 | } |
273 | } | 280 | } |
274 | 281 | ||
275 | //US added another method with no parameter, since my moc compiler does not support default parameters. | 282 | //US added another method with no parameter, since my moc compiler does not support default parameters. |
276 | void ViewManager::refreshView() | 283 | void ViewManager::refreshView() |
diff --git a/kaddressbook/viewmanager.h b/kaddressbook/viewmanager.h index a18e87d..97c2275 100644 --- a/kaddressbook/viewmanager.h +++ b/kaddressbook/viewmanager.h | |||
@@ -1,152 +1,153 @@ | |||
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 | 31 | ||
32 | class KAction; | 32 | class KAction; |
33 | class KSelectAction; | 33 | class KSelectAction; |
34 | 34 | ||
35 | class KABCore; | 35 | class KABCore; |
36 | class QWidgetStack; | 36 | class QWidgetStack; |
37 | class QDropEvent; | 37 | class QDropEvent; |
38 | 38 | ||
39 | namespace KABC { class AddressBook; } | 39 | namespace KABC { class AddressBook; } |
40 | 40 | ||
41 | /** | 41 | /** |
42 | The view manager manages the views and everything related to them. The | 42 | 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 | 43 | manager will load the views at startup and display a view when told to |
44 | make one active. | 44 | make one active. |
45 | 45 | ||
46 | The view manager will also create and manage all dialogs directly related to | 46 | The view manager will also create and manage all dialogs directly related to |
47 | views (ie: AddView, ConfigureView, DeleteView, etc). | 47 | views (ie: AddView, ConfigureView, DeleteView, etc). |
48 | */ | 48 | */ |
49 | class ViewManager : public QWidget | 49 | class ViewManager : public QWidget |
50 | { | 50 | { |
51 | Q_OBJECT | 51 | Q_OBJECT |
52 | public: | 52 | public: |
53 | ViewManager( KABCore *core, QWidget *parent, const char *name = 0 ); | 53 | ViewManager( KABCore *core, QWidget *parent, const char *name = 0 ); |
54 | ~ViewManager(); | 54 | ~ViewManager(); |
55 | 55 | ||
56 | void restoreSettings(); | 56 | void restoreSettings(); |
57 | void saveSettings(); | 57 | void saveSettings(); |
58 | 58 | ||
59 | void unloadViews(); | 59 | void unloadViews(); |
60 | KSelectAction * getFilterAction() { return mActionSelectFilter; } | 60 | KSelectAction * getFilterAction() { return mActionSelectFilter; } |
61 | 61 | ||
62 | QStringList selectedUids() const; | 62 | QStringList selectedUids() const; |
63 | QStringList selectedEmails() const; | 63 | QStringList selectedEmails() const; |
64 | KABC::Addressee::List selectedAddressees() const; | 64 | KABC::Addressee::List selectedAddressees() const; |
65 | void setListSelected(QStringList); | ||
65 | 66 | ||
66 | public slots: | 67 | public slots: |
67 | 68 | ||
68 | //US void setSelected( const QString &uid = QString::null, bool selected = true ); | 69 | //US void setSelected( const QString &uid = QString::null, bool selected = true ); |
69 | void setSelected( const QString &uid, bool); | 70 | void setSelected( const QString &uid, bool); |
70 | //US added another method with no parameter, since my moc compiler does not support default parameters. | 71 | //US added another method with no parameter, since my moc compiler does not support default parameters. |
71 | void setSelected(); | 72 | void setSelected(); |
72 | 73 | ||
73 | 74 | ||
74 | 75 | ||
75 | //US added another method with no parameter, since my moc compiler does not support default parameters. | 76 | //US added another method with no parameter, since my moc compiler does not support default parameters. |
76 | void refreshView(); | 77 | void refreshView(); |
77 | void refreshView( const QString &uid); | 78 | void refreshView( const QString &uid); |
78 | 79 | ||
79 | void editView(); | 80 | void editView(); |
80 | void deleteView(); | 81 | void deleteView(); |
81 | void addView(); | 82 | void addView(); |
82 | 83 | ||
83 | protected slots: | 84 | protected slots: |
84 | /** | 85 | /** |
85 | Called whenever the user drops something in the active view. | 86 | Called whenever the user drops something in the active view. |
86 | This method will try to decode what was dropped, and if it was | 87 | This method will try to decode what was dropped, and if it was |
87 | a valid addressee, add it to the addressbook. | 88 | a valid addressee, add it to the addressbook. |
88 | */ | 89 | */ |
89 | void dropped( QDropEvent* ); | 90 | void dropped( QDropEvent* ); |
90 | 91 | ||
91 | /** | 92 | /** |
92 | Called whenever the user attempts to start a drag in the view. | 93 | Called whenever the user attempts to start a drag in the view. |
93 | This method will convert all the selected addressees into text (vcard) | 94 | This method will convert all the selected addressees into text (vcard) |
94 | and create a drag object. | 95 | and create a drag object. |
95 | */ | 96 | */ |
96 | void startDrag(); | 97 | void startDrag(); |
97 | 98 | ||
98 | signals: | 99 | signals: |
99 | /** | 100 | /** |
100 | Emitted whenever the user selects an entry in the view. | 101 | Emitted whenever the user selects an entry in the view. |
101 | */ | 102 | */ |
102 | void selected( const QString &uid ); | 103 | void selected( const QString &uid ); |
103 | void deleteRequest( ); | 104 | void deleteRequest( ); |
104 | 105 | ||
105 | /** | 106 | /** |
106 | Emitted whenever the user activates an entry in the view. | 107 | Emitted whenever the user activates an entry in the view. |
107 | */ | 108 | */ |
108 | void executed( const QString &uid ); | 109 | void executed( const QString &uid ); |
109 | 110 | ||
110 | /** | 111 | /** |
111 | Emitted whenever the address book is modified in some way. | 112 | Emitted whenever the address book is modified in some way. |
112 | */ | 113 | */ |
113 | void modified(); | 114 | void modified(); |
114 | 115 | ||
115 | /** | 116 | /** |
116 | Emitted whenever a url is dragged on a view. | 117 | Emitted whenever a url is dragged on a view. |
117 | */ | 118 | */ |
118 | void urlDropped( const KURL& ); | 119 | void urlDropped( const KURL& ); |
119 | 120 | ||
120 | private slots: | 121 | private slots: |
121 | void setActiveView( const QString &name ); | 122 | void setActiveView( const QString &name ); |
122 | void setActiveFilter( int index ); | 123 | void setActiveFilter( int index ); |
123 | void configureFilters(); | 124 | void configureFilters(); |
124 | 125 | ||
125 | private: | 126 | private: |
126 | void createViewFactories(); | 127 | void createViewFactories(); |
127 | QStringList filterNames() const; | 128 | QStringList filterNames() const; |
128 | int filterPosition( const QString &name ) const; | 129 | int filterPosition( const QString &name ) const; |
129 | QStringList viewNames() const; | 130 | QStringList viewNames() const; |
130 | int viewPosition( const QString &name ) const; | 131 | int viewPosition( const QString &name ) const; |
131 | void initActions(); | 132 | void initActions(); |
132 | void initGUI(); | 133 | void initGUI(); |
133 | 134 | ||
134 | KABCore *mCore; | 135 | KABCore *mCore; |
135 | 136 | ||
136 | Filter mCurrentFilter; | 137 | Filter mCurrentFilter; |
137 | Filter::List mFilterList; | 138 | Filter::List mFilterList; |
138 | 139 | ||
139 | QDict<KAddressBookView> mViewDict; | 140 | QDict<KAddressBookView> mViewDict; |
140 | QDict<ViewFactory> mViewFactoryDict; | 141 | QDict<ViewFactory> mViewFactoryDict; |
141 | QStringList mViewNameList; | 142 | QStringList mViewNameList; |
142 | 143 | ||
143 | QWidgetStack *mViewWidgetStack; | 144 | QWidgetStack *mViewWidgetStack; |
144 | KAddressBookView *mActiveView; | 145 | KAddressBookView *mActiveView; |
145 | 146 | ||
146 | KAction *mActionDeleteView; | 147 | KAction *mActionDeleteView; |
147 | KSelectAction *mActionSelectFilter; | 148 | KSelectAction *mActionSelectFilter; |
148 | KSelectAction *mActionSelectView; | 149 | KSelectAction *mActionSelectView; |
149 | 150 | ||
150 | }; | 151 | }; |
151 | 152 | ||
152 | #endif | 153 | #endif |
diff --git a/kaddressbook/views/kaddressbooktableview.cpp b/kaddressbook/views/kaddressbooktableview.cpp index 66a3f0b..0847b64 100644 --- a/kaddressbook/views/kaddressbooktableview.cpp +++ b/kaddressbook/views/kaddressbooktableview.cpp | |||
@@ -29,240 +29,240 @@ | |||
29 | #include "contactlistview.h" | 29 | #include "contactlistview.h" |
30 | #include "kabprefs.h" | 30 | #include "kabprefs.h" |
31 | #include "undocmds.h" | 31 | #include "undocmds.h" |
32 | #include "viewmanager.h" | 32 | #include "viewmanager.h" |
33 | 33 | ||
34 | #include <qlayout.h> | 34 | #include <qlayout.h> |
35 | 35 | ||
36 | 36 | ||
37 | #include "kaddressbooktableview.h" | 37 | #include "kaddressbooktableview.h" |
38 | 38 | ||
39 | 39 | ||
40 | KAddressBookTableView::KAddressBookTableView( KABC::AddressBook *ab, | 40 | KAddressBookTableView::KAddressBookTableView( KABC::AddressBook *ab, |
41 | QWidget *parent, const char *name ) | 41 | QWidget *parent, const char *name ) |
42 | : KAddressBookView( ab, parent, name ) | 42 | : KAddressBookView( ab, parent, name ) |
43 | { | 43 | { |
44 | mainLayout = new QVBoxLayout( viewWidget(), 2 ); | 44 | mainLayout = new QVBoxLayout( viewWidget(), 2 ); |
45 | 45 | ||
46 | // The list view will be created when the config is read. | 46 | // The list view will be created when the config is read. |
47 | mListView = 0; | 47 | mListView = 0; |
48 | } | 48 | } |
49 | 49 | ||
50 | KAddressBookTableView::~KAddressBookTableView() | 50 | KAddressBookTableView::~KAddressBookTableView() |
51 | { | 51 | { |
52 | } | 52 | } |
53 | 53 | ||
54 | void KAddressBookTableView::reconstructListView() | 54 | void KAddressBookTableView::reconstructListView() |
55 | { | 55 | { |
56 | if (mListView) | 56 | if (mListView) |
57 | { | 57 | { |
58 | disconnect(mListView, SIGNAL(selectionChanged()), | 58 | disconnect(mListView, SIGNAL(selectionChanged()), |
59 | this, SLOT(addresseeSelected())); | 59 | this, SLOT(addresseeSelected())); |
60 | disconnect(mListView, SIGNAL(executed(QListViewItem*)), | 60 | disconnect(mListView, SIGNAL(executed(QListViewItem*)), |
61 | this, SLOT(addresseeExecuted(QListViewItem*))); | 61 | this, SLOT(addresseeExecuted(QListViewItem*))); |
62 | disconnect(mListView, SIGNAL(doubleClicked(QListViewItem*)), | 62 | disconnect(mListView, SIGNAL(doubleClicked(QListViewItem*)), |
63 | this, SLOT(addresseeExecuted(QListViewItem*))); | 63 | this, SLOT(addresseeExecuted(QListViewItem*))); |
64 | disconnect(mListView, SIGNAL(startAddresseeDrag()), this, | 64 | disconnect(mListView, SIGNAL(startAddresseeDrag()), this, |
65 | SIGNAL(startDrag())); | 65 | SIGNAL(startDrag())); |
66 | disconnect(mListView, SIGNAL(returnPressed(QListViewItem*)), | 66 | disconnect(mListView, SIGNAL(returnPressed(QListViewItem*)), |
67 | this, SLOT(addresseeExecuted(QListViewItem*))); | 67 | this, SLOT(addresseeExecuted(QListViewItem*))); |
68 | 68 | ||
69 | disconnect(mListView, SIGNAL(addresseeDropped(QDropEvent*)), this, | 69 | disconnect(mListView, SIGNAL(addresseeDropped(QDropEvent*)), this, |
70 | SIGNAL(dropped(QDropEvent*))); | 70 | SIGNAL(dropped(QDropEvent*))); |
71 | delete mListView; | 71 | delete mListView; |
72 | } | 72 | } |
73 | 73 | ||
74 | mListView = new ContactListView( this, addressBook(), viewWidget() ); | 74 | mListView = new ContactListView( this, addressBook(), viewWidget() ); |
75 | 75 | ||
76 | // Add the columns | 76 | // Add the columns |
77 | KABC::Field::List fieldList = fields(); | 77 | KABC::Field::List fieldList = fields(); |
78 | KABC::Field::List::ConstIterator it; | 78 | KABC::Field::List::ConstIterator it; |
79 | 79 | ||
80 | int c = 0; | 80 | int c = 0; |
81 | for( it = fieldList.begin(); it != fieldList.end(); ++it ) { | 81 | for( it = fieldList.begin(); it != fieldList.end(); ++it ) { |
82 | mListView->addColumn( (*it)->label() ); | 82 | mListView->addColumn( (*it)->label() ); |
83 | mListView->setColumnWidthMode(c++, QListView::Manual); | 83 | mListView->setColumnWidthMode(c++, QListView::Manual); |
84 | //US | 84 | //US |
85 | // qDebug("KAddressBookTableView::reconstructListView: field %s", (*it)->label().latin1()); | 85 | // qDebug("KAddressBookTableView::reconstructListView: field %s", (*it)->label().latin1()); |
86 | } | 86 | } |
87 | 87 | ||
88 | connect(mListView, SIGNAL(selectionChanged()), | 88 | connect(mListView, SIGNAL(selectionChanged()), |
89 | this, SLOT(addresseeSelected())); | 89 | this, SLOT(addresseeSelected())); |
90 | connect(mListView, SIGNAL(startAddresseeDrag()), this, | 90 | connect(mListView, SIGNAL(startAddresseeDrag()), this, |
91 | SIGNAL(startDrag())); | 91 | SIGNAL(startDrag())); |
92 | connect(mListView, SIGNAL(addresseeDropped(QDropEvent*)), this, | 92 | connect(mListView, SIGNAL(addresseeDropped(QDropEvent*)), this, |
93 | SIGNAL(dropped(QDropEvent*))); | 93 | SIGNAL(dropped(QDropEvent*))); |
94 | 94 | ||
95 | if (KABPrefs::instance()->mHonorSingleClick) | 95 | if (KABPrefs::instance()->mHonorSingleClick) |
96 | connect(mListView, SIGNAL(executed(QListViewItem*)), | 96 | connect(mListView, SIGNAL(executed(QListViewItem*)), |
97 | this, SLOT(addresseeExecuted(QListViewItem*))); | 97 | this, SLOT(addresseeExecuted(QListViewItem*))); |
98 | else | 98 | else |
99 | connect(mListView, SIGNAL(doubleClicked(QListViewItem*)), | 99 | connect(mListView, SIGNAL(doubleClicked(QListViewItem*)), |
100 | this, SLOT(addresseeExecuted(QListViewItem*))); | 100 | this, SLOT(addresseeExecuted(QListViewItem*))); |
101 | connect(mListView, SIGNAL(returnPressed(QListViewItem*)), | 101 | connect(mListView, SIGNAL(returnPressed(QListViewItem*)), |
102 | this, SLOT(addresseeExecuted(QListViewItem*))); | 102 | this, SLOT(addresseeExecuted(QListViewItem*))); |
103 | connect(mListView, SIGNAL(signalDelete()), | 103 | connect(mListView, SIGNAL(signalDelete()), |
104 | this, SLOT(addresseeDeleted())); | 104 | this, SLOT(addresseeDeleted())); |
105 | 105 | ||
106 | //US performceimprovement. Refresh is done from the outside | 106 | //US performceimprovement. Refresh is done from the outside |
107 | //US refresh(); | 107 | //US refresh(); |
108 | 108 | ||
109 | mListView->setSorting( 0, true ); | 109 | mListView->setSorting( 0, true ); |
110 | mainLayout->addWidget( mListView ); | 110 | mainLayout->addWidget( mListView ); |
111 | mainLayout->activate(); | 111 | mainLayout->activate(); |
112 | mListView->show(); | 112 | mListView->show(); |
113 | } | 113 | } |
114 | 114 | ||
115 | void KAddressBookTableView::writeConfig(KConfig *config) | 115 | void KAddressBookTableView::writeConfig(KConfig *config) |
116 | { | 116 | { |
117 | KAddressBookView::writeConfig(config); | 117 | KAddressBookView::writeConfig(config); |
118 | 118 | ||
119 | mListView->saveLayout(config, config->group()); | 119 | mListView->saveLayout(config, config->group()); |
120 | } | 120 | } |
121 | 121 | ||
122 | void KAddressBookTableView::readConfig(KConfig *config) | 122 | void KAddressBookTableView::readConfig(KConfig *config) |
123 | { | 123 | { |
124 | KAddressBookView::readConfig( config ); | 124 | KAddressBookView::readConfig( config ); |
125 | // The config could have changed the fields, so we need to reconstruct | ||
126 | // the listview. | ||
127 | reconstructListView(); | ||
125 | 128 | ||
126 | // costum colors? | 129 | // costum colors? |
127 | if ( config->readBoolEntry( "EnableCustomColors", false ) ) | 130 | if ( config->readBoolEntry( "EnableCustomColors", false ) ) |
128 | { | 131 | { |
129 | QPalette p( mListView->palette() ); | 132 | QPalette p( mListView->palette() ); |
130 | QColor c = p.color(QPalette::Normal, QColorGroup::Base ); | 133 | QColor c = p.color(QPalette::Normal, QColorGroup::Base ); |
131 | p.setColor( QPalette::Normal, QColorGroup::Base, config->readColorEntry( "BackgroundColor", &c ) ); | 134 | p.setColor( QPalette::Normal, QColorGroup::Base, config->readColorEntry( "BackgroundColor", &c ) ); |
132 | c = p.color(QPalette::Normal, QColorGroup::Text ); | 135 | c = p.color(QPalette::Normal, QColorGroup::Text ); |
133 | p.setColor( QPalette::Normal, QColorGroup::Text, config->readColorEntry( "TextColor", &c ) ); | 136 | p.setColor( QPalette::Normal, QColorGroup::Text, config->readColorEntry( "TextColor", &c ) ); |
134 | c = p.color(QPalette::Normal, QColorGroup::Button ); | 137 | c = p.color(QPalette::Normal, QColorGroup::Button ); |
135 | p.setColor( QPalette::Normal, QColorGroup::Button, config->readColorEntry( "HeaderColor", &c ) ); | 138 | p.setColor( QPalette::Normal, QColorGroup::Button, config->readColorEntry( "HeaderColor", &c ) ); |
136 | c = p.color(QPalette::Normal, QColorGroup::ButtonText ); | 139 | c = p.color(QPalette::Normal, QColorGroup::ButtonText ); |
137 | p.setColor( QPalette::Normal, QColorGroup::ButtonText, config->readColorEntry( "HeaderTextColor", &c ) ); | 140 | p.setColor( QPalette::Normal, QColorGroup::ButtonText, config->readColorEntry( "HeaderTextColor", &c ) ); |
138 | c = p.color(QPalette::Normal, QColorGroup::Highlight ); | 141 | c = p.color(QPalette::Normal, QColorGroup::Highlight ); |
139 | p.setColor( QPalette::Normal, QColorGroup::Highlight, config->readColorEntry( "HighlightColor", &c ) ); | 142 | p.setColor( QPalette::Normal, QColorGroup::Highlight, config->readColorEntry( "HighlightColor", &c ) ); |
140 | c = p.color(QPalette::Normal, QColorGroup::HighlightedText ); | 143 | c = p.color(QPalette::Normal, QColorGroup::HighlightedText ); |
141 | p.setColor( QPalette::Normal, QColorGroup::HighlightedText, config->readColorEntry( "HighlightedTextColor", &c ) ); | 144 | p.setColor( QPalette::Normal, QColorGroup::HighlightedText, config->readColorEntry( "HighlightedTextColor", &c ) ); |
142 | c = p.color(QPalette::Normal, QColorGroup::Base ); | 145 | c = p.color(QPalette::Normal, QColorGroup::Base ); |
143 | p.setColor( QPalette::Normal, QColorGroup::Base, config->readColorEntry( "AlternatingBackgroundColor", &c ) ); | 146 | p.setColor( QPalette::Normal, QColorGroup::Base, config->readColorEntry( "AlternatingBackgroundColor", &c ) ); |
144 | mListView->viewport()->setPalette( p ); | 147 | mListView->viewport()->setPalette( p ); |
145 | } | 148 | } |
146 | else | 149 | else |
147 | { | 150 | { |
148 | // needed if turned off during a session. | 151 | // needed if turned off during a session. |
149 | mListView->viewport()->setPalette( mListView->palette() ); | 152 | mListView->viewport()->setPalette( mListView->palette() ); |
150 | } | 153 | } |
151 | 154 | ||
152 | //custom fonts? | 155 | //custom fonts? |
153 | QFont f( font() ); | 156 | QFont f( font() ); |
154 | if ( config->readBoolEntry( "EnableCustomFonts", false ) ) | 157 | if ( config->readBoolEntry( "EnableCustomFonts", false ) ) |
155 | { | 158 | { |
156 | // mListView->setFont( config->readFontEntry( "TextFont", &f) ); | 159 | // mListView->setFont( config->readFontEntry( "TextFont", &f) ); |
157 | f.setBold( true ); | 160 | f.setBold( true ); |
158 | // mListView->setHeaderFont( config->readFontEntry( "HeaderFont", &f ) ); | 161 | // mListView->setHeaderFont( config->readFontEntry( "HeaderFont", &f ) ); |
159 | } | 162 | } |
160 | else | 163 | else |
161 | { | 164 | { |
162 | // mListView->setFont( f ); | 165 | // mListView->setFont( f ); |
163 | f.setBold( true ); | 166 | f.setBold( true ); |
164 | // mListView->setHeaderFont( f ); | 167 | // mListView->setHeaderFont( f ); |
165 | } | 168 | } |
166 | 169 | ||
167 | 170 | ||
168 | 171 | ||
169 | 172 | ||
170 | // The config could have changed the fields, so we need to reconstruct | ||
171 | // the listview. | ||
172 | reconstructListView(); | ||
173 | 173 | ||
174 | // Set the list view options | 174 | // Set the list view options |
175 | mListView->setAlternateBackgroundEnabled(config->readBoolEntry("ABackground", | 175 | mListView->setAlternateBackgroundEnabled(config->readBoolEntry("ABackground", |
176 | true)); | 176 | true)); |
177 | mListView->setSingleLineEnabled(config->readBoolEntry("SingleLine", false)); | 177 | mListView->setSingleLineEnabled(config->readBoolEntry("SingleLine", false)); |
178 | mListView->setToolTipsEnabled(config->readBoolEntry("ToolTips", true)); | 178 | mListView->setToolTipsEnabled(config->readBoolEntry("ToolTips", true)); |
179 | 179 | ||
180 | if (config->readBoolEntry("Background", false)) | 180 | if (config->readBoolEntry("Background", false)) |
181 | mListView->setBackgroundPixmap(config->readEntry("BackgroundName")); | 181 | mListView->setBackgroundPixmap(config->readEntry("BackgroundName")); |
182 | 182 | ||
183 | // Restore the layout of the listview | 183 | // Restore the layout of the listview |
184 | mListView->restoreLayout(config, config->group()); | 184 | mListView->restoreLayout(config, config->group()); |
185 | } | 185 | } |
186 | 186 | ||
187 | void KAddressBookTableView::refresh(QString uid) | 187 | void KAddressBookTableView::refresh(QString uid) |
188 | { | 188 | { |
189 | // For now just repopulate. In reality this method should | 189 | // For now just repopulate. In reality this method should |
190 | // check the value of uid, and if valid iterate through | 190 | // check the value of uid, and if valid iterate through |
191 | // the listview to find the entry, then tell it to refresh. | 191 | // the listview to find the entry, then tell it to refresh. |
192 | 192 | ||
193 | if (uid.isNull()) { | 193 | if (uid.isNull()) { |
194 | // Clear the list view | 194 | // Clear the list view |
195 | QString currentUID, nextUID; | 195 | QString currentUID, nextUID; |
196 | #ifndef KAB_EMBEDDED | 196 | #ifndef KAB_EMBEDDED |
197 | ContactListViewItem *currentItem = dynamic_cast<ContactListViewItem*>( mListView->currentItem() ); | 197 | ContactListViewItem *currentItem = dynamic_cast<ContactListViewItem*>( mListView->currentItem() ); |
198 | #else //KAB_EMBEDDED | 198 | #else //KAB_EMBEDDED |
199 | ContactListViewItem *currentItem = (ContactListViewItem*)( mListView->currentItem() ); | 199 | ContactListViewItem *currentItem = (ContactListViewItem*)( mListView->currentItem() ); |
200 | #endif //KAB_EMBEDDED | 200 | #endif //KAB_EMBEDDED |
201 | 201 | ||
202 | if ( currentItem ) { | 202 | if ( currentItem ) { |
203 | #ifndef KAB_EMBEDDED | 203 | #ifndef KAB_EMBEDDED |
204 | ContactListViewItem *nextItem = dynamic_cast<ContactListViewItem*>( currentItem->itemBelow() ); | 204 | ContactListViewItem *nextItem = dynamic_cast<ContactListViewItem*>( currentItem->itemBelow() ); |
205 | #else //KAB_EMBEDDED | 205 | #else //KAB_EMBEDDED |
206 | ContactListViewItem *nextItem = (ContactListViewItem*)( currentItem->itemBelow() ); | 206 | ContactListViewItem *nextItem = (ContactListViewItem*)( currentItem->itemBelow() ); |
207 | #endif //KAB_EMBEDDED | 207 | #endif //KAB_EMBEDDED |
208 | if ( nextItem ) | 208 | if ( nextItem ) |
209 | nextUID = nextItem->addressee().uid(); | 209 | nextUID = nextItem->addressee().uid(); |
210 | currentUID = currentItem->addressee().uid(); | 210 | currentUID = currentItem->addressee().uid(); |
211 | } | 211 | } |
212 | 212 | ||
213 | mListView->clear(); | 213 | mListView->clear(); |
214 | 214 | ||
215 | currentItem = 0; | 215 | currentItem = 0; |
216 | KABC::Addressee::List addresseeList = addressees(); | 216 | KABC::Addressee::List addresseeList = addressees(); |
217 | KABC::Addressee::List::Iterator it; | 217 | KABC::Addressee::List::Iterator it; |
218 | for (it = addresseeList.begin(); it != addresseeList.end(); ++it ) { | 218 | for (it = addresseeList.begin(); it != addresseeList.end(); ++it ) { |
219 | ContactListViewItem *item = new ContactListViewItem(*it, mListView, addressBook(), fields()); | 219 | ContactListViewItem *item = new ContactListViewItem(*it, mListView, addressBook(), fields()); |
220 | if ( (*it).uid() == currentUID ) | 220 | if ( (*it).uid() == currentUID ) |
221 | currentItem = item; | 221 | currentItem = item; |
222 | else if ( (*it).uid() == nextUID && !currentItem ) | 222 | else if ( (*it).uid() == nextUID && !currentItem ) |
223 | currentItem = item; | 223 | currentItem = item; |
224 | } | 224 | } |
225 | 225 | ||
226 | // Sometimes the background pixmap gets messed up when we add lots | 226 | // Sometimes the background pixmap gets messed up when we add lots |
227 | // of items. | 227 | // of items. |
228 | mListView->repaint(); | 228 | mListView->repaint(); |
229 | 229 | ||
230 | if ( currentItem ) { | 230 | if ( currentItem ) { |
231 | mListView->setCurrentItem( currentItem ); | 231 | mListView->setCurrentItem( currentItem ); |
232 | mListView->ensureItemVisible( currentItem ); | 232 | mListView->ensureItemVisible( currentItem ); |
233 | } | 233 | } |
234 | } else { | 234 | } else { |
235 | // Only need to update on entry. Iterate through and try to find it | 235 | // Only need to update on entry. Iterate through and try to find it |
236 | ContactListViewItem *ceItem; | 236 | ContactListViewItem *ceItem; |
237 | QListViewItemIterator it( mListView ); | 237 | QListViewItemIterator it( mListView ); |
238 | while ( it.current() ) { | 238 | while ( it.current() ) { |
239 | #ifndef KAB_EMBEDDED | 239 | #ifndef KAB_EMBEDDED |
240 | ceItem = dynamic_cast<ContactListViewItem*>( it.current() ); | 240 | ceItem = dynamic_cast<ContactListViewItem*>( it.current() ); |
241 | #else //KAB_EMBEDDED | 241 | #else //KAB_EMBEDDED |
242 | ceItem = (ContactListViewItem*)( it.current() ); | 242 | ceItem = (ContactListViewItem*)( it.current() ); |
243 | #endif //KAB_EMBEDDED | 243 | #endif //KAB_EMBEDDED |
244 | 244 | ||
245 | if ( ceItem && ceItem->addressee().uid() == uid ) { | 245 | if ( ceItem && ceItem->addressee().uid() == uid ) { |
246 | ceItem->refresh(); | 246 | ceItem->refresh(); |
247 | return; | 247 | return; |
248 | } | 248 | } |
249 | ++it; | 249 | ++it; |
250 | } | 250 | } |
251 | 251 | ||
252 | refresh( QString::null ); | 252 | refresh( QString::null ); |
253 | } | 253 | } |
254 | } | 254 | } |
255 | 255 | ||
256 | QStringList KAddressBookTableView::selectedUids() | 256 | QStringList KAddressBookTableView::selectedUids() |
257 | { | 257 | { |
258 | QStringList uidList; | 258 | QStringList uidList; |
259 | QListViewItem *item; | 259 | QListViewItem *item; |
260 | ContactListViewItem *ceItem; | 260 | ContactListViewItem *ceItem; |
261 | 261 | ||
262 | for(item = mListView->firstChild(); item; item = item->itemBelow()) | 262 | for(item = mListView->firstChild(); item; item = item->itemBelow()) |
263 | { | 263 | { |
264 | if (mListView->isSelected( item )) | 264 | if (mListView->isSelected( item )) |
265 | { | 265 | { |
266 | #ifndef KAB_EMBEDDED | 266 | #ifndef KAB_EMBEDDED |
267 | ceItem = dynamic_cast<ContactListViewItem*>(item); | 267 | ceItem = dynamic_cast<ContactListViewItem*>(item); |
268 | #else //KAB_EMBEDDED | 268 | #else //KAB_EMBEDDED |