Diffstat (limited to 'kaddressbook/views/kaddressbookcardview.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | kaddressbook/views/kaddressbookcardview.cpp | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/kaddressbook/views/kaddressbookcardview.cpp b/kaddressbook/views/kaddressbookcardview.cpp index 4babf67..a7bf6c9 100644 --- a/kaddressbook/views/kaddressbookcardview.cpp +++ b/kaddressbook/views/kaddressbookcardview.cpp | |||
@@ -1,390 +1,406 @@ | |||
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 | #include <qdragobject.h> | 24 | #include <qdragobject.h> |
25 | #include <qevent.h> | 25 | #include <qevent.h> |
26 | #include <qiconview.h> | 26 | #include <qiconview.h> |
27 | #include <qlayout.h> | 27 | #include <qlayout.h> |
28 | #include <qstringlist.h> | 28 | #include <qstringlist.h> |
29 | #include <qregexp.h> | 29 | #include <qregexp.h> |
30 | #include <qapplication.h> | ||
30 | 31 | ||
31 | #include <kabc/addressbook.h> | 32 | #include <kabc/addressbook.h> |
32 | #include <kabc/addressee.h> | 33 | #include <kabc/addressee.h> |
33 | #include <kconfig.h> | 34 | #include <kconfig.h> |
34 | #include <kdebug.h> | 35 | #include <kdebug.h> |
35 | #include <klocale.h> | 36 | #include <klocale.h> |
36 | 37 | ||
37 | #include "kabprefs.h" | 38 | #include "kabprefs.h" |
38 | #include "viewmanager.h" | 39 | #include "viewmanager.h" |
39 | 40 | ||
40 | #include "kaddressbookcardview.h" | 41 | #include "kaddressbookcardview.h" |
41 | 42 | ||
42 | #ifndef KAB_EMBEDDED | 43 | #ifndef KAB_EMBEDDED |
43 | extern "C" { | 44 | extern "C" { |
44 | void *init_libkaddrbk_cardview() | 45 | void *init_libkaddrbk_cardview() |
45 | { | 46 | { |
46 | return ( new CardViewFactory ); | 47 | return ( new CardViewFactory ); |
47 | } | 48 | } |
48 | } | 49 | } |
49 | #endif //KAB_EMBEDDED | 50 | #endif //KAB_EMBEDDED |
50 | 51 | ||
51 | //////////////////////////////// | 52 | //////////////////////////////// |
52 | // AddresseeCardViewItem (internal class) | 53 | // AddresseeCardViewItem (internal class) |
53 | class AddresseeCardViewItem : public CardViewItem | 54 | class AddresseeCardViewItem : public CardViewItem |
54 | { | 55 | { |
55 | public: | 56 | public: |
56 | AddresseeCardViewItem(const KABC::Field::List &fields, | 57 | AddresseeCardViewItem(const KABC::Field::List &fields, |
57 | bool showEmptyFields, | 58 | bool showEmptyFields, |
58 | KABC::AddressBook *doc, const KABC::Addressee &a, | 59 | KABC::AddressBook *doc, const KABC::Addressee &a, |
59 | CardView *parent) | 60 | CardView *parent) |
60 | : CardViewItem(parent, a.formattedName()), | 61 | : CardViewItem(parent, a.formattedName()), |
61 | mFields( fields ), mShowEmptyFields(showEmptyFields), | 62 | mFields( fields ), mShowEmptyFields(showEmptyFields), |
62 | mDocument(doc), mAddressee(a) | 63 | mDocument(doc), mAddressee(a) |
63 | { | 64 | { |
64 | if ( mFields.isEmpty() ) { | 65 | if ( mFields.isEmpty() ) { |
65 | mFields = KABC::Field::defaultFields(); | 66 | mFields = KABC::Field::defaultFields(); |
66 | } | 67 | } |
67 | refresh(); | 68 | refresh(); |
68 | } | 69 | } |
69 | 70 | ||
70 | const KABC::Addressee &addressee() const { return mAddressee; } | 71 | const KABC::Addressee &addressee() const { return mAddressee; } |
71 | 72 | ||
72 | void refresh() | 73 | void refresh() |
73 | { | 74 | { |
74 | // Update our addressee, since it may have changed elsewhere | 75 | // Update our addressee, since it may have changed elsewhere |
75 | mAddressee = mDocument->findByUid(mAddressee.uid()); | 76 | mAddressee = mDocument->findByUid(mAddressee.uid()); |
76 | 77 | ||
77 | if (!mAddressee.isEmpty()) | 78 | if (!mAddressee.isEmpty()) |
78 | { | 79 | { |
79 | clearFields(); | 80 | clearFields(); |
80 | 81 | ||
81 | // Try all the selected fields until we find one with text. | 82 | // Try all the selected fields until we find one with text. |
82 | // This will limit the number of unlabeled icons in the view | 83 | // This will limit the number of unlabeled icons in the view |
83 | KABC::Field::List::Iterator iter; | 84 | KABC::Field::List::Iterator iter; |
84 | for (iter = mFields.begin(); iter != mFields.end(); ++iter) | 85 | for (iter = mFields.begin(); iter != mFields.end(); ++iter) |
85 | { | 86 | { |
86 | // insert empty fields or not? not doing so saves a bit of memory and CPU | 87 | // insert empty fields or not? not doing so saves a bit of memory and CPU |
87 | // (during geometry calculations), but prevents having equally | 88 | // (during geometry calculations), but prevents having equally |
88 | // wide label columns in all cards, unless CardViewItem/CardView search | 89 | // wide label columns in all cards, unless CardViewItem/CardView search |
89 | // globally for the widest label. (anders) | 90 | // globally for the widest label. (anders) |
90 | //if (mShowEmptyFields || !(*iter)->value( mAddressee ).isEmpty()) | 91 | //if (mShowEmptyFields || !(*iter)->value( mAddressee ).isEmpty()) |
91 | insertField((*iter)->label(), (*iter)->value( mAddressee )); | 92 | insertField((*iter)->label(), (*iter)->value( mAddressee )); |
92 | } | 93 | } |
93 | 94 | ||
94 | // We might want to make this the first field. hmm... -mpilone | 95 | // We might want to make this the first field. hmm... -mpilone |
95 | setCaption( mAddressee.realName() ); | 96 | setCaption( mAddressee.realName() ); |
96 | } | 97 | } |
97 | } | 98 | } |
98 | 99 | ||
99 | private: | 100 | private: |
100 | KABC::Field::List mFields; | 101 | KABC::Field::List mFields; |
101 | bool mShowEmptyFields; | 102 | bool mShowEmptyFields; |
102 | KABC::AddressBook *mDocument; | 103 | KABC::AddressBook *mDocument; |
103 | KABC::Addressee mAddressee; | 104 | KABC::Addressee mAddressee; |
104 | }; | 105 | }; |
105 | 106 | ||
106 | /////////////////////////////// | 107 | /////////////////////////////// |
107 | // AddresseeCardView | 108 | // AddresseeCardView |
108 | 109 | ||
109 | AddresseeCardView::AddresseeCardView(QWidget *parent, const char *name) | 110 | AddresseeCardView::AddresseeCardView(QWidget *parent, const char *name) |
110 | : CardView(parent, name) | 111 | : CardView(parent, name) |
111 | { | 112 | { |
112 | setAcceptDrops(true); | 113 | setAcceptDrops(true); |
113 | } | 114 | } |
114 | 115 | ||
115 | AddresseeCardView::~AddresseeCardView() | 116 | AddresseeCardView::~AddresseeCardView() |
116 | { | 117 | { |
117 | } | 118 | } |
118 | 119 | ||
119 | 120 | ||
120 | void AddresseeCardView::dragEnterEvent(QDragEnterEvent *e) | 121 | void AddresseeCardView::dragEnterEvent(QDragEnterEvent *e) |
121 | { | 122 | { |
122 | #ifndef KAB_EMBEDDED | 123 | #ifndef KAB_EMBEDDED |
123 | if (QTextDrag::canDecode(e)) | 124 | if (QTextDrag::canDecode(e)) |
124 | e->accept(); | 125 | e->accept(); |
125 | #else //KAB_EMBEDDED | 126 | #else //KAB_EMBEDDED |
126 | qDebug("AddresseeCardView::dragEnterEvent drag&drop is not implemented"); | 127 | qDebug("AddresseeCardView::dragEnterEvent drag&drop is not implemented"); |
127 | #endif //KAB_EMBEDDED | 128 | #endif //KAB_EMBEDDED |
128 | } | 129 | } |
129 | 130 | ||
130 | void AddresseeCardView::dropEvent(QDropEvent *e) | 131 | void AddresseeCardView::dropEvent(QDropEvent *e) |
131 | { | 132 | { |
132 | emit addresseeDropped(e); | 133 | emit addresseeDropped(e); |
133 | } | 134 | } |
134 | 135 | ||
135 | void AddresseeCardView::startDrag() | 136 | void AddresseeCardView::startDrag() |
136 | { | 137 | { |
137 | emit startAddresseeDrag(); | 138 | emit startAddresseeDrag(); |
138 | } | 139 | } |
139 | 140 | ||
140 | 141 | ||
141 | /////////////////////////////// | 142 | /////////////////////////////// |
142 | // KAddressBookCardView | 143 | // KAddressBookCardView |
143 | 144 | ||
144 | KAddressBookCardView::KAddressBookCardView( KABC::AddressBook *ab, | 145 | KAddressBookCardView::KAddressBookCardView( KABC::AddressBook *ab, |
145 | QWidget *parent, const char *name ) | 146 | QWidget *parent, const char *name ) |
146 | : KAddressBookView( ab, parent, name ) | 147 | : KAddressBookView( ab, parent, name ) |
147 | { | 148 | { |
148 | mShowEmptyFields = false; | 149 | mShowEmptyFields = false; |
149 | 150 | ||
150 | // Init the GUI | 151 | // Init the GUI |
151 | QVBoxLayout *layout = new QVBoxLayout(viewWidget()); | 152 | QVBoxLayout *layout = new QVBoxLayout(viewWidget()); |
152 | 153 | ||
153 | mCardView = new AddresseeCardView(viewWidget(), "mCardView"); | 154 | mCardView = new AddresseeCardView(viewWidget(), "mCardView"); |
154 | mCardView->setSelectionMode(CardView::Extended); | 155 | mCardView->setSelectionMode(CardView::Extended); |
155 | layout->addWidget(mCardView); | 156 | layout->addWidget(mCardView); |
156 | 157 | ||
157 | // Connect up the signals | 158 | // Connect up the signals |
158 | connect(mCardView, SIGNAL(executed(CardViewItem *)), | 159 | connect(mCardView, SIGNAL(executed(CardViewItem *)), |
159 | this, SLOT(addresseeExecuted(CardViewItem *))); | 160 | this, SLOT(addresseeExecuted(CardViewItem *))); |
160 | connect(mCardView, SIGNAL(selectionChanged()), | 161 | connect(mCardView, SIGNAL(selectionChanged()), |
161 | this, SLOT(addresseeSelected())); | 162 | this, SLOT(addresseeSelected())); |
162 | connect(mCardView, SIGNAL(addresseeDropped(QDropEvent*)), | 163 | connect(mCardView, SIGNAL(addresseeDropped(QDropEvent*)), |
163 | this, SIGNAL(dropped(QDropEvent*))); | 164 | this, SIGNAL(dropped(QDropEvent*))); |
164 | connect(mCardView, SIGNAL(startAddresseeDrag()), | 165 | connect(mCardView, SIGNAL(startAddresseeDrag()), |
165 | this, SIGNAL(startDrag())); | 166 | this, SIGNAL(startDrag())); |
166 | } | 167 | } |
167 | 168 | ||
168 | KAddressBookCardView::~KAddressBookCardView() | 169 | KAddressBookCardView::~KAddressBookCardView() |
169 | { | 170 | { |
170 | } | 171 | } |
171 | 172 | ||
173 | void KAddressBookCardView::scrollUP() | ||
174 | { | ||
175 | QKeyEvent * ev = new QKeyEvent ( QEvent::KeyPress, Qt::Key_Up, 0,0 ); | ||
176 | QApplication::postEvent( mCardView, ev ); | ||
177 | |||
178 | } | ||
179 | void KAddressBookCardView::scrollDOWN() | ||
180 | { | ||
181 | QKeyEvent * ev = new QKeyEvent ( QEvent::KeyPress, Qt::Key_Down, 0,0 ); | ||
182 | QApplication::postEvent( mCardView, ev ); | ||
183 | } | ||
172 | void KAddressBookCardView::readConfig(KConfig *config) | 184 | void KAddressBookCardView::readConfig(KConfig *config) |
173 | { | 185 | { |
174 | KAddressBookView::readConfig(config); | 186 | KAddressBookView::readConfig(config); |
175 | 187 | ||
176 | // costum colors? | 188 | // costum colors? |
177 | if ( config->readBoolEntry( "EnableCustomColors", false ) ) | 189 | if ( config->readBoolEntry( "EnableCustomColors", false ) ) |
178 | { | 190 | { |
179 | QPalette p( mCardView->palette() ); | 191 | QPalette p( mCardView->palette() ); |
180 | QColor c = p.color(QPalette::Normal, QColorGroup::Base ); | 192 | QColor c = p.color(QPalette::Normal, QColorGroup::Base ); |
181 | p.setColor( QPalette::Normal, QColorGroup::Base, config->readColorEntry( "BackgroundColor", &c ) ); | 193 | p.setColor( QPalette::Normal, QColorGroup::Base, config->readColorEntry( "BackgroundColor", &c ) ); |
182 | c = p.color(QPalette::Normal, QColorGroup::Text ); | 194 | c = p.color(QPalette::Normal, QColorGroup::Text ); |
183 | p.setColor( QPalette::Normal, QColorGroup::Text, config->readColorEntry( "TextColor", &c ) ); | 195 | p.setColor( QPalette::Normal, QColorGroup::Text, config->readColorEntry( "TextColor", &c ) ); |
184 | c = p.color(QPalette::Normal, QColorGroup::Button ); | 196 | c = p.color(QPalette::Normal, QColorGroup::Button ); |
185 | p.setColor( QPalette::Normal, QColorGroup::Button, config->readColorEntry( "HeaderColor", &c ) ); | 197 | p.setColor( QPalette::Normal, QColorGroup::Button, config->readColorEntry( "HeaderColor", &c ) ); |
186 | c = p.color(QPalette::Normal, QColorGroup::ButtonText ); | 198 | c = p.color(QPalette::Normal, QColorGroup::ButtonText ); |
187 | p.setColor( QPalette::Normal, QColorGroup::ButtonText, config->readColorEntry( "HeaderTextColor", &c ) ); | 199 | p.setColor( QPalette::Normal, QColorGroup::ButtonText, config->readColorEntry( "HeaderTextColor", &c ) ); |
188 | c = p.color(QPalette::Normal, QColorGroup::Highlight ); | 200 | c = p.color(QPalette::Normal, QColorGroup::Highlight ); |
189 | p.setColor( QPalette::Normal, QColorGroup::Highlight, config->readColorEntry( "HighlightColor", &c ) ); | 201 | p.setColor( QPalette::Normal, QColorGroup::Highlight, config->readColorEntry( "HighlightColor", &c ) ); |
190 | c = p.color(QPalette::Normal, QColorGroup::HighlightedText ); | 202 | c = p.color(QPalette::Normal, QColorGroup::HighlightedText ); |
191 | p.setColor( QPalette::Normal, QColorGroup::HighlightedText, config->readColorEntry( "HighlightedTextColor", &c ) ); | 203 | p.setColor( QPalette::Normal, QColorGroup::HighlightedText, config->readColorEntry( "HighlightedTextColor", &c ) ); |
192 | mCardView->viewport()->setPalette( p ); | 204 | mCardView->viewport()->setPalette( p ); |
193 | } | 205 | } |
194 | else | 206 | else |
195 | { | 207 | { |
196 | // needed if turned off during a session. | 208 | // needed if turned off during a session. |
197 | mCardView->viewport()->setPalette( mCardView->palette() ); | 209 | mCardView->viewport()->setPalette( mCardView->palette() ); |
198 | } | 210 | } |
199 | 211 | ||
200 | //custom fonts? | 212 | //custom fonts? |
201 | QFont f( font() ); | 213 | QFont f( font() ); |
202 | if ( config->readBoolEntry( "EnableCustomFonts", false ) ) | 214 | if ( config->readBoolEntry( "EnableCustomFonts", false ) ) |
203 | { | 215 | { |
204 | mCardView->setFont( config->readFontEntry( "TextFont", &f) ); | 216 | mCardView->setFont( config->readFontEntry( "TextFont", &f) ); |
205 | f.setBold( true ); | 217 | f.setBold( true ); |
206 | mCardView->setHeaderFont( config->readFontEntry( "HeaderFont", &f ) ); | 218 | mCardView->setHeaderFont( config->readFontEntry( "HeaderFont", &f ) ); |
207 | } | 219 | } |
208 | else | 220 | else |
209 | { | 221 | { |
210 | mCardView->setFont( f ); | 222 | mCardView->setFont( f ); |
211 | f.setBold( true ); | 223 | f.setBold( true ); |
212 | mCardView->setHeaderFont( f ); | 224 | mCardView->setHeaderFont( f ); |
213 | } | 225 | } |
214 | 226 | ||
215 | mCardView->setDrawCardBorder(config->readBoolEntry("DrawBorder", true)); | 227 | mCardView->setDrawCardBorder(config->readBoolEntry("DrawBorder", true)); |
216 | mCardView->setDrawColSeparators(config->readBoolEntry("DrawSeparators", | 228 | mCardView->setDrawColSeparators(config->readBoolEntry("DrawSeparators", |
217 | true)); | 229 | true)); |
218 | mCardView->setDrawFieldLabels(config->readBoolEntry("DrawFieldLabels",false)); | 230 | mCardView->setDrawFieldLabels(config->readBoolEntry("DrawFieldLabels",false)); |
219 | mShowEmptyFields = config->readBoolEntry("ShowEmptyFields", false); | 231 | mShowEmptyFields = config->readBoolEntry("ShowEmptyFields", false); |
220 | 232 | ||
221 | mCardView->setShowEmptyFields( mShowEmptyFields ); | 233 | mCardView->setShowEmptyFields( mShowEmptyFields ); |
222 | 234 | ||
223 | mCardView->setItemWidth( config->readNumEntry( "ItemWidth", 200 ) ); | 235 | mCardView->setItemWidth( config->readNumEntry( "ItemWidth", 200 ) ); |
224 | mCardView->setItemMargin( config->readNumEntry( "ItemMargin", 0 ) ); | 236 | mCardView->setItemMargin( config->readNumEntry( "ItemMargin", 0 ) ); |
225 | mCardView->setItemSpacing( config->readNumEntry( "ItemSpacing", 10 ) ); | 237 | mCardView->setItemSpacing( config->readNumEntry( "ItemSpacing", 10 ) ); |
226 | mCardView->setSeparatorWidth( config->readNumEntry( "SeparatorWidth", 2 ) ); | 238 | mCardView->setSeparatorWidth( config->readNumEntry( "SeparatorWidth", 2 ) ); |
227 | 239 | ||
228 | disconnect(mCardView, SIGNAL(executed(CardViewItem *)), | 240 | disconnect(mCardView, SIGNAL(executed(CardViewItem *)), |
229 | this, SLOT(addresseeExecuted(CardViewItem *))); | 241 | this, SLOT(addresseeExecuted(CardViewItem *))); |
230 | 242 | ||
231 | if (KABPrefs::instance()->mHonorSingleClick) | 243 | if (KABPrefs::instance()->mHonorSingleClick) |
232 | connect(mCardView, SIGNAL(executed(CardViewItem *)), | 244 | connect(mCardView, SIGNAL(executed(CardViewItem *)), |
233 | this, SLOT(addresseeExecuted(CardViewItem *))); | 245 | this, SLOT(addresseeExecuted(CardViewItem *))); |
234 | else | 246 | else |
235 | connect(mCardView, SIGNAL(doubleClicked(CardViewItem *)), | 247 | connect(mCardView, SIGNAL(doubleClicked(CardViewItem *)), |
236 | this, SLOT(addresseeExecuted(CardViewItem *))); | 248 | this, SLOT(addresseeExecuted(CardViewItem *))); |
237 | 249 | ||
238 | } | 250 | } |
239 | 251 | ||
240 | void KAddressBookCardView::writeConfig( KConfig *config ) | 252 | void KAddressBookCardView::writeConfig( KConfig *config ) |
241 | { | 253 | { |
242 | config->writeEntry( "ItemWidth", mCardView->itemWidth() ); | 254 | config->writeEntry( "ItemWidth", mCardView->itemWidth() ); |
243 | KAddressBookView::writeConfig( config ); | 255 | KAddressBookView::writeConfig( config ); |
244 | } | 256 | } |
245 | void KAddressBookCardView::doSearch( const QString& s,KABC::Field *field ) | 257 | void KAddressBookCardView::doSearch( const QString& s,KABC::Field *field ) |
246 | { | 258 | { |
247 | mCardView->clear(); | 259 | mCardView->clear(); |
248 | if ( s.isEmpty() || s == "*" ) { | 260 | if ( s.isEmpty() || s == "*" ) { |
249 | refresh(); | 261 | refresh(); |
250 | return; | 262 | return; |
251 | } | 263 | } |
252 | QString pattern = s.lower()+"*"; | 264 | QString pattern = s.lower()+"*"; |
253 | QRegExp re; | 265 | QRegExp re; |
254 | re.setWildcard(true); // most people understand these better. | 266 | re.setWildcard(true); // most people understand these better. |
255 | re.setCaseSensitive(false); | 267 | re.setCaseSensitive(false); |
256 | re.setPattern( pattern ); | 268 | re.setPattern( pattern ); |
257 | if (!re.isValid()) | 269 | if (!re.isValid()) |
258 | return; | 270 | return; |
259 | mCardView->viewport()->setUpdatesEnabled( false ); | 271 | mCardView->viewport()->setUpdatesEnabled( false ); |
260 | KABC::Addressee::List addresseeList = addressees(); | 272 | KABC::Addressee::List addresseeList = addressees(); |
261 | KABC::Addressee::List::Iterator it; | 273 | KABC::Addressee::List::Iterator it; |
262 | if ( field ) { | 274 | if ( field ) { |
263 | for (it = addresseeList.begin(); it != addresseeList.end(); ++it ) { | 275 | for (it = addresseeList.begin(); it != addresseeList.end(); ++it ) { |
264 | #if QT_VERSION >= 300 | 276 | #if QT_VERSION >= 300 |
265 | if (re.search(field->value( *it ).lower()) != -1) | 277 | if (re.search(field->value( *it ).lower()) != -1) |
266 | #else | 278 | #else |
267 | if (re.match(field->value( *it ).lower()) != -1) | 279 | if (re.match(field->value( *it ).lower()) != -1) |
268 | #endif | 280 | #endif |
269 | new AddresseeCardViewItem(fields(), mShowEmptyFields, | 281 | new AddresseeCardViewItem(fields(), mShowEmptyFields, |
270 | addressBook(), *it, mCardView); | 282 | addressBook(), *it, mCardView); |
271 | 283 | ||
272 | } | 284 | } |
273 | } else { | 285 | } else { |
274 | KABC::Field::List fieldList = fields(); | 286 | KABC::Field::List fieldList = fields(); |
275 | KABC::Field::List::ConstIterator fieldIt; | 287 | KABC::Field::List::ConstIterator fieldIt; |
276 | for (it = addresseeList.begin(); it != addresseeList.end(); ++it ) { | 288 | for (it = addresseeList.begin(); it != addresseeList.end(); ++it ) { |
277 | for ( fieldIt = fieldList.begin(); fieldIt != fieldList.end(); ++fieldIt ) { | 289 | for ( fieldIt = fieldList.begin(); fieldIt != fieldList.end(); ++fieldIt ) { |
278 | #if QT_VERSION >= 300 | 290 | #if QT_VERSION >= 300 |
279 | if (re.search((*fieldIt)->value( *it ).lower()) != -1) | 291 | if (re.search((*fieldIt)->value( *it ).lower()) != -1) |
280 | #else | 292 | #else |
281 | if (re.match((*fieldIt)->value( *it ).lower()) != -1) | 293 | if (re.match((*fieldIt)->value( *it ).lower()) != -1) |
282 | #endif | 294 | #endif |
283 | { | 295 | { |
284 | new AddresseeCardViewItem(fields(), mShowEmptyFields, | 296 | new AddresseeCardViewItem(fields(), mShowEmptyFields, |
285 | addressBook(), *it, mCardView); | 297 | addressBook(), *it, mCardView); |
286 | continue; | 298 | continue; |
287 | } | 299 | } |
288 | } | 300 | } |
289 | } | 301 | } |
290 | } | 302 | } |
291 | mCardView->viewport()->setUpdatesEnabled( true ); | 303 | mCardView->viewport()->setUpdatesEnabled( true ); |
292 | mCardView->viewport()->update(); | 304 | mCardView->viewport()->update(); |
293 | // by default nothing is selected | 305 | if ( mCardView->firstItem() ) { |
294 | emit selected(QString::null); | 306 | mCardView->setCurrentItem ( mCardView->firstItem() ); |
307 | mCardView->setSelected ( mCardView->firstItem() , true ); | ||
308 | } | ||
309 | else | ||
310 | emit selected(QString::null); | ||
295 | } | 311 | } |
296 | QStringList KAddressBookCardView::selectedUids() | 312 | QStringList KAddressBookCardView::selectedUids() |
297 | { | 313 | { |
298 | QStringList uidList; | 314 | QStringList uidList; |
299 | CardViewItem *item; | 315 | CardViewItem *item; |
300 | AddresseeCardViewItem *aItem; | 316 | AddresseeCardViewItem *aItem; |
301 | 317 | ||
302 | for (item = mCardView->firstItem(); item; item = item->nextItem()) | 318 | for (item = mCardView->firstItem(); item; item = item->nextItem()) |
303 | { | 319 | { |
304 | if (item->isSelected()) | 320 | if (item->isSelected()) |
305 | { | 321 | { |
306 | #ifndef KAB_EMBEDDED | 322 | #ifndef KAB_EMBEDDED |
307 | aItem = dynamic_cast<AddresseeCardViewItem*>(item); | 323 | aItem = dynamic_cast<AddresseeCardViewItem*>(item); |
308 | #else //KAB_EMBEDDED | 324 | #else //KAB_EMBEDDED |
309 | aItem = (AddresseeCardViewItem*)(item); | 325 | aItem = (AddresseeCardViewItem*)(item); |
310 | #endif //KAB_EMBEDDED | 326 | #endif //KAB_EMBEDDED |
311 | if (aItem) | 327 | if (aItem) |
312 | uidList << aItem->addressee().uid(); | 328 | uidList << aItem->addressee().uid(); |
313 | } | 329 | } |
314 | } | 330 | } |
315 | 331 | ||
316 | return uidList; | 332 | return uidList; |
317 | } | 333 | } |
318 | 334 | ||
319 | void KAddressBookCardView::refresh(QString uid) | 335 | void KAddressBookCardView::refresh(QString uid) |
320 | { | 336 | { |
321 | CardViewItem *item; | 337 | CardViewItem *item; |
322 | AddresseeCardViewItem *aItem; | 338 | AddresseeCardViewItem *aItem; |
323 | 339 | ||
324 | if (uid.isNull()) | 340 | if (uid.isNull()) |
325 | { | 341 | { |
326 | // Rebuild the view | 342 | // Rebuild the view |
327 | mCardView->viewport()->setUpdatesEnabled( false ); | 343 | mCardView->viewport()->setUpdatesEnabled( false ); |
328 | mCardView->clear(); | 344 | mCardView->clear(); |
329 | 345 | ||
330 | KABC::Addressee::List addresseeList = addressees(); | 346 | KABC::Addressee::List addresseeList = addressees(); |
331 | KABC::Addressee::List::Iterator iter; | 347 | KABC::Addressee::List::Iterator iter; |
332 | for (iter = addresseeList.begin(); iter != addresseeList.end(); ++iter) | 348 | for (iter = addresseeList.begin(); iter != addresseeList.end(); ++iter) |
333 | { | 349 | { |
334 | if ( (*iter).uid().left(2) == "la" && (*iter).uid().left(19) == QString("last-syncAddressee-") ) | 350 | if ( (*iter).uid().left(2) == "la" && (*iter).uid().left(19) == QString("last-syncAddressee-") ) |
335 | continue; | 351 | continue; |
336 | aItem = new AddresseeCardViewItem(fields(), mShowEmptyFields, | 352 | aItem = new AddresseeCardViewItem(fields(), mShowEmptyFields, |
337 | addressBook(), *iter, mCardView); | 353 | addressBook(), *iter, mCardView); |
338 | } | 354 | } |
339 | mCardView->viewport()->setUpdatesEnabled( true ); | 355 | mCardView->viewport()->setUpdatesEnabled( true ); |
340 | mCardView->viewport()->update(); | 356 | mCardView->viewport()->update(); |
341 | 357 | ||
342 | // by default nothing is selected | 358 | // by default nothing is selected |
343 | emit selected(QString::null); | 359 | emit selected(QString::null); |
344 | } | 360 | } |
345 | else | 361 | else |
346 | { | 362 | { |
347 | // Try to find the one to refresh | 363 | // Try to find the one to refresh |
348 | bool found = false; | 364 | bool found = false; |
349 | for (item = mCardView->firstItem(); item && !found; | 365 | for (item = mCardView->firstItem(); item && !found; |
350 | item = item->nextItem()) | 366 | item = item->nextItem()) |
351 | { | 367 | { |
352 | #ifndef KAB_EMBEDDED | 368 | #ifndef KAB_EMBEDDED |
353 | aItem = dynamic_cast<AddresseeCardViewItem*>(item); | 369 | aItem = dynamic_cast<AddresseeCardViewItem*>(item); |
354 | #else //KAB_EMBEDDED | 370 | #else //KAB_EMBEDDED |
355 | aItem = (AddresseeCardViewItem*)(item); | 371 | aItem = (AddresseeCardViewItem*)(item); |
356 | #endif //KAB_EMBEDDED | 372 | #endif //KAB_EMBEDDED |
357 | 373 | ||
358 | if ((aItem) && (aItem->addressee().uid() == uid)) | 374 | if ((aItem) && (aItem->addressee().uid() == uid)) |
359 | { | 375 | { |
360 | aItem->refresh(); | 376 | aItem->refresh(); |
361 | found = true; | 377 | found = true; |
362 | } | 378 | } |
363 | } | 379 | } |
364 | } | 380 | } |
365 | } | 381 | } |
366 | 382 | ||
367 | void KAddressBookCardView::setSelected(QString uid, bool selected) | 383 | void KAddressBookCardView::setSelected(QString uid, bool selected) |
368 | { | 384 | { |
369 | CardViewItem *item; | 385 | CardViewItem *item; |
370 | AddresseeCardViewItem *aItem; | 386 | AddresseeCardViewItem *aItem; |
371 | 387 | ||
372 | if (uid.isNull()) | 388 | if (uid.isNull()) |
373 | { | 389 | { |
374 | mCardView->selectAll(selected); | 390 | mCardView->selectAll(selected); |
375 | } | 391 | } |
376 | else | 392 | else |
377 | { | 393 | { |
378 | bool found = false; | 394 | bool found = false; |
379 | for (item = mCardView->firstItem(); item && !found; | 395 | for (item = mCardView->firstItem(); item && !found; |
380 | item = item->nextItem()) | 396 | item = item->nextItem()) |
381 | { | 397 | { |
382 | #ifndef KAB_EMBEDDED | 398 | #ifndef KAB_EMBEDDED |
383 | aItem = dynamic_cast<AddresseeCardViewItem*>(item); | 399 | aItem = dynamic_cast<AddresseeCardViewItem*>(item); |
384 | #else //KAB_EMBEDDED | 400 | #else //KAB_EMBEDDED |
385 | aItem = (AddresseeCardViewItem*)(item); | 401 | aItem = (AddresseeCardViewItem*)(item); |
386 | #endif //KAB_EMBEDDED | 402 | #endif //KAB_EMBEDDED |
387 | 403 | ||
388 | if ((aItem) && (aItem->addressee().uid() == uid)) | 404 | if ((aItem) && (aItem->addressee().uid() == uid)) |
389 | { | 405 | { |
390 | mCardView->setSelected(aItem, selected); | 406 | mCardView->setSelected(aItem, selected); |