Diffstat (limited to 'kaddressbook/views/kaddressbookiconview.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | kaddressbook/views/kaddressbookiconview.cpp | 39 |
1 files changed, 34 insertions, 5 deletions
diff --git a/kaddressbook/views/kaddressbookiconview.cpp b/kaddressbook/views/kaddressbookiconview.cpp index 4bbdf1d..d6ddec3 100644 --- a/kaddressbook/views/kaddressbookiconview.cpp +++ b/kaddressbook/views/kaddressbookiconview.cpp | |||
@@ -1,452 +1,481 @@ | |||
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 KAB_EMBEDDED | 24 | #ifndef KAB_EMBEDDED |
25 | #include <qiconview.h> | 25 | #include <qiconview.h> |
26 | #include <qstringlist.h> | 26 | #include <qstringlist.h> |
27 | 27 | ||
28 | #include <kabc/addressee.h> | 28 | #include <kabc/addressee.h> |
29 | #include <kconfig.h> | 29 | #include <kconfig.h> |
30 | #include <kdebug.h> | 30 | #include <kdebug.h> |
31 | #include <kglobal.h> | 31 | #include <kglobal.h> |
32 | #include <kiconloader.h> | 32 | #include <kiconloader.h> |
33 | #include <klocale.h> | 33 | #include <klocale.h> |
34 | 34 | ||
35 | #else //KAB_EMBEDDED | 35 | #else //KAB_EMBEDDED |
36 | #endif //KAB_EMBEDDED | 36 | #endif //KAB_EMBEDDED |
37 | 37 | ||
38 | #include <kabc/addressbook.h> | 38 | #include <kabc/addressbook.h> |
39 | #include "kabprefs.h" | 39 | #include "kabprefs.h" |
40 | #include "viewmanager.h" | 40 | #include "viewmanager.h" |
41 | #include "kaddressbookiconview.h" | 41 | #include "kaddressbookiconview.h" |
42 | #include <qlayout.h> | 42 | #include <qlayout.h> |
43 | #include <qregexp.h> | 43 | #include <qregexp.h> |
44 | #include <qapplication.h> | 44 | #include <qapplication.h> |
45 | #include <kglobal.h> | 45 | #include <kglobal.h> |
46 | /*US transfered to the headerfile | 46 | /*US transfered to the headerfile |
47 | class IconViewFactory : public ViewFactory | 47 | class IconViewFactory : public ViewFactory |
48 | { | 48 | { |
49 | public: | 49 | public: |
50 | KAddressBookView *view( KABC::AddressBook *ab, QWidget *parent, const char *name ) | 50 | KAddressBookView *view( KABC::AddressBook *ab, QWidget *parent, const char *name ) |
51 | { | 51 | { |
52 | return new KAddressBookIconView( ab, parent, name ); | 52 | return new KAddressBookIconView( ab, parent, name ); |
53 | } | 53 | } |
54 | 54 | ||
55 | QString type() const { return "Icon"; } | 55 | QString type() const { return "Icon"; } |
56 | 56 | ||
57 | QString description() const { return i18n( "Icons represent contacts. Very simple view." ); } | 57 | QString description() const { return i18n( "Icons represent contacts. Very simple view." ); } |
58 | }; | 58 | }; |
59 | 59 | ||
60 | */ | 60 | */ |
61 | 61 | ||
62 | extern "C" { | 62 | extern "C" { |
63 | void *init_libkaddrbk_iconview() | 63 | void *init_libkaddrbk_iconview() |
64 | { | 64 | { |
65 | return ( new IconViewFactory ); | 65 | return ( new IconViewFactory ); |
66 | } | 66 | } |
67 | } | 67 | } |
68 | 68 | ||
69 | //////////////////////////////// | 69 | //////////////////////////////// |
70 | // AddresseeIconView (internal class) | 70 | // AddresseeIconView (internal class) |
71 | #ifndef KAB_EMBEDDED | 71 | #ifndef KAB_EMBEDDED |
72 | AddresseeIconView::AddresseeIconView(QWidget *parent, const char *name) | 72 | AddresseeIconView::AddresseeIconView(QWidget *parent, const char *name) |
73 | : KIconView(parent, name) | 73 | : KIconView(parent, name) |
74 | #else //KAB_EMBEDDED | 74 | #else //KAB_EMBEDDED |
75 | AddresseeIconView::AddresseeIconView(QWidget *parent, const char *name) | 75 | AddresseeIconView::AddresseeIconView(QWidget *parent, const char *name) |
76 | : QIconView(parent, name) | 76 | : QIconView(parent, name) |
77 | #endif //KAB_EMBEDDED | 77 | #endif //KAB_EMBEDDED |
78 | 78 | ||
79 | { | 79 | { |
80 | setSelectionMode( QIconView::Extended ); | 80 | setSelectionMode( QIconView::Extended ); |
81 | setResizeMode( QIconView::Adjust ); | 81 | setResizeMode( QIconView::Adjust ); |
82 | setWordWrapIconText( true ); | 82 | setWordWrapIconText( true ); |
83 | setGridX( 100 ); | 83 | setGridX( 100 ); |
84 | setItemsMovable(false); | 84 | setItemsMovable(false); |
85 | setSorting(true, true); | 85 | setSorting(true, true); |
86 | 86 | ||
87 | 87 | ||
88 | //US ??? setMode( KIconView::Select ); | 88 | //US ??? setMode( KIconView::Select ); |
89 | 89 | ||
90 | #ifndef KAB_EMBEDDED | 90 | #ifndef KAB_EMBEDDED |
91 | 91 | ||
92 | connect(this, SIGNAL(dropped(QDropEvent*, const QValueList<QIconDragItem>&)), | 92 | connect(this, SIGNAL(dropped(QDropEvent*, const QValueList<QIconDragItem>&)), |
93 | this, SLOT(itemDropped(QDropEvent*, const QValueList<QIconDragItem>&))); | 93 | this, SLOT(itemDropped(QDropEvent*, const QValueList<QIconDragItem>&))); |
94 | #endif //KAB_EMBEDDED | 94 | #endif //KAB_EMBEDDED |
95 | } | 95 | } |
96 | 96 | ||
97 | AddresseeIconView::~AddresseeIconView() | 97 | AddresseeIconView::~AddresseeIconView() |
98 | { | 98 | { |
99 | } | 99 | } |
100 | 100 | ||
101 | 101 | ||
102 | void AddresseeIconView::itemDropped(QDropEvent *e, | 102 | void AddresseeIconView::itemDropped(QDropEvent *e, |
103 | const QValueList<QIconDragItem> &) | 103 | const QValueList<QIconDragItem> &) |
104 | { | 104 | { |
105 | emit addresseeDropped(e); | 105 | emit addresseeDropped(e); |
106 | } | 106 | } |
107 | 107 | ||
108 | QDragObject *AddresseeIconView::dragObject() | 108 | QDragObject *AddresseeIconView::dragObject() |
109 | { | 109 | { |
110 | emit startAddresseeDrag(); | 110 | emit startAddresseeDrag(); |
111 | 111 | ||
112 | // We never want IconView to start the drag | 112 | // We never want IconView to start the drag |
113 | return 0; | 113 | return 0; |
114 | } | 114 | } |
115 | //////////////////////////////// | 115 | //////////////////////////////// |
116 | // AddresseeIconViewItem (internal class) | 116 | // AddresseeIconViewItem (internal class) |
117 | #ifndef KAB_EMBEDDED | 117 | #ifndef KAB_EMBEDDED |
118 | class AddresseeIconViewItem : public KIconViewItem | 118 | class AddresseeIconViewItem : public KIconViewItem |
119 | #else //KAB_EMBEDDED | 119 | #else //KAB_EMBEDDED |
120 | class AddresseeIconViewItem : public QIconViewItem | 120 | class AddresseeIconViewItem : public QIconViewItem |
121 | #endif //KAB_EMBEDDED | 121 | #endif //KAB_EMBEDDED |
122 | { | 122 | { |
123 | public: | 123 | public: |
124 | #ifndef KAB_EMBEDDED | 124 | #ifndef KAB_EMBEDDED |
125 | AddresseeIconViewItem(const KABC::Field::List &fields, | 125 | AddresseeIconViewItem(const KABC::Field::List &fields, |
126 | KABC::AddressBook *doc, const KABC::Addressee &a, | 126 | KABC::AddressBook *doc, const KABC::Addressee &a, |
127 | QIconView *parent) | 127 | QIconView *parent) |
128 | : KIconViewItem(parent), mFields( fields ), mDocument(doc), mAddressee(a) | 128 | : KIconViewItem(parent), mFields( fields ), mDocument(doc), mAddressee(a) |
129 | #else //KAB_EMBEDDED | 129 | #else //KAB_EMBEDDED |
130 | AddresseeIconViewItem(const KABC::Field::List &fields, | 130 | AddresseeIconViewItem(const KABC::Field::List &fields, |
131 | KABC::AddressBook *doc, const KABC::Addressee &a, | 131 | KABC::AddressBook *doc, const KABC::Addressee &a, |
132 | QIconView *parent) | 132 | QIconView *parent) |
133 | : QIconViewItem(parent), mFields( fields ), mDocument(doc), mAddressee(a) | 133 | : QIconViewItem(parent), mFields( fields ), mDocument(doc), mAddressee(a) |
134 | #endif //KAB_EMBEDDED | 134 | #endif //KAB_EMBEDDED |
135 | { | 135 | { |
136 | if ( mFields.isEmpty() ) { | 136 | if ( mFields.isEmpty() ) { |
137 | mFields = KABC::Field::defaultFields(); | 137 | mFields = KABC::Field::defaultFields(); |
138 | } | 138 | } |
139 | refresh(); | 139 | refresh(); |
140 | } | 140 | } |
141 | 141 | ||
142 | const KABC::Addressee &addressee() const { return mAddressee; } | 142 | const KABC::Addressee &addressee() const { return mAddressee; } |
143 | 143 | ||
144 | void refresh() | 144 | void refresh() |
145 | { | 145 | { |
146 | // Update our addressee, since it may have changed elsewhere | 146 | // Update our addressee, since it may have changed elsewhere |
147 | mAddressee = mDocument->findByUid(mAddressee.uid()); | 147 | mAddressee = mDocument->findByUid(mAddressee.uid()); |
148 | 148 | ||
149 | if (!mAddressee.isEmpty()) | 149 | if (!mAddressee.isEmpty()) |
150 | setText( mAddressee.givenName() + " " + mAddressee.familyName() ); | 150 | setText( mAddressee.givenName() + " " + mAddressee.familyName() ); |
151 | 151 | ||
152 | QPixmap icon; | 152 | QPixmap icon; |
153 | QPixmap defaultIcon( KGlobal::iconLoader()->loadIcon( "vcard", KIcon::Desktop, 128 ) ); | 153 | |
154 | KABC::Picture pic = mAddressee.photo(); | 154 | KABC::Picture pic = mAddressee.photo(); |
155 | if ( pic.data().isNull() ) | 155 | if ( pic.data().isNull() ) |
156 | pic = mAddressee.logo(); | 156 | pic = mAddressee.logo(); |
157 | 157 | ||
158 | if ( pic.isIntern() && !pic.data().isNull() ) { | 158 | if ( pic.isIntern() && !pic.data().isNull() ) { |
159 | QImage img = pic.data(); | 159 | QImage img = pic.data(); |
160 | #ifndef KAB_EMBEDDED | 160 | #ifndef KAB_EMBEDDED |
161 | if ( img.width() > img.height() ) | 161 | if ( img.width() > img.height() ) |
162 | icon = img.scaleWidth( 32 ); | 162 | icon = img.scaleWidth( 32 ); |
163 | else | 163 | else |
164 | icon = img.scaleHeight( 32 ); | 164 | icon = img.scaleHeight( 32 ); |
165 | #else //KAB_EMBEDDED | 165 | #else //KAB_EMBEDDED |
166 | |||
167 | int wid = pic.data().width(); | ||
168 | int hei = pic.data().height(); | ||
169 | int max = 48; | ||
170 | if ( wid > max || hei > max ) { | ||
171 | if ( wid > hei ) { | ||
172 | hei = (hei*max)/wid; | ||
173 | wid = max; | ||
174 | } else { | ||
175 | wid = (wid*max)/hei; | ||
176 | hei = max; | ||
177 | } | ||
178 | } | ||
166 | qDebug("AddresseeIconViewItem::refresh - scale here dependend of the displaysize and the right factor"); | 179 | qDebug("AddresseeIconViewItem::refresh - scale here dependend of the displaysize and the right factor"); |
167 | icon.convertFromImage(img.smoothScale(32, 32)); | 180 | icon.convertFromImage(img.smoothScale(wid, hei)); |
168 | #endif //KAB_EMBEDDED | 181 | #endif //KAB_EMBEDDED |
169 | 182 | ||
170 | } else | 183 | } else { |
171 | icon = defaultIcon; | 184 | icon = KGlobal::iconLoader()->loadIcon( "vcard", KIcon::Desktop, 128 ); |
172 | 185 | } | |
173 | setPixmap( icon ); | 186 | setPixmap( icon ); |
174 | } | 187 | } |
175 | 188 | ||
176 | private: | 189 | private: |
177 | KABC::Field::List mFields; | 190 | KABC::Field::List mFields; |
178 | KABC::AddressBook *mDocument; | 191 | KABC::AddressBook *mDocument; |
179 | KABC::Addressee mAddressee; | 192 | KABC::Addressee mAddressee; |
180 | }; | 193 | }; |
181 | 194 | ||
182 | /////////////////////////////// | 195 | /////////////////////////////// |
183 | // KAddressBookView | 196 | // KAddressBookView |
184 | 197 | ||
185 | KAddressBookIconView::KAddressBookIconView( KABC::AddressBook *ab, | 198 | KAddressBookIconView::KAddressBookIconView( KABC::AddressBook *ab, |
186 | QWidget *parent, const char *name) | 199 | QWidget *parent, const char *name) |
187 | : KAddressBookView( ab, parent, name ) | 200 | : KAddressBookView( ab, parent, name ) |
188 | { | 201 | { |
189 | // Init the GUI | 202 | // Init the GUI |
190 | QVBoxLayout *layout = new QVBoxLayout(viewWidget()); | 203 | QVBoxLayout *layout = new QVBoxLayout(viewWidget()); |
191 | 204 | ||
192 | mIconView = new AddresseeIconView(viewWidget(), "mIconView"); | 205 | mIconView = new AddresseeIconView(viewWidget(), "mIconView"); |
193 | layout->addWidget(mIconView); | 206 | layout->addWidget(mIconView); |
194 | 207 | ||
195 | // Connect up the signals | 208 | // Connect up the signals |
196 | 209 | ||
197 | //US method executed is part of KIconView | 210 | //US method executed is part of KIconView |
198 | //US connect(mIconView, SIGNAL(executed(QIconViewItem *)), | 211 | //US connect(mIconView, SIGNAL(executed(QIconViewItem *)), |
199 | //US this, SLOT(addresseeExecuted(QIconViewItem *))); | 212 | //US this, SLOT(addresseeExecuted(QIconViewItem *))); |
200 | connect(mIconView, SIGNAL(selectionChanged(QIconViewItem *)), | 213 | connect(mIconView, SIGNAL(selectionChanged(QIconViewItem *)), |
201 | this, SLOT(addresseeExecuted(QIconViewItem *))); | 214 | this, SLOT(addresseeExecuted(QIconViewItem *))); |
202 | 215 | ||
203 | connect(mIconView, SIGNAL(selectionChanged()), | 216 | connect(mIconView, SIGNAL(selectionChanged()), |
204 | this, SLOT(addresseeSelected())); | 217 | this, SLOT(addresseeSelected())); |
205 | connect(mIconView, SIGNAL(addresseeDropped(QDropEvent*)), | 218 | connect(mIconView, SIGNAL(addresseeDropped(QDropEvent*)), |
206 | this, SIGNAL(dropped(QDropEvent*))); | 219 | this, SIGNAL(dropped(QDropEvent*))); |
207 | connect(mIconView, SIGNAL(startAddresseeDrag()), | 220 | connect(mIconView, SIGNAL(startAddresseeDrag()), |
208 | this, SIGNAL(startDrag())); | 221 | this, SIGNAL(startDrag())); |
209 | } | 222 | } |
210 | 223 | ||
211 | KAddressBookIconView::~KAddressBookIconView() | 224 | KAddressBookIconView::~KAddressBookIconView() |
212 | { | 225 | { |
213 | } | 226 | } |
214 | void KAddressBookIconView::setFocusAV() | 227 | void KAddressBookIconView::setFocusAV() |
215 | { | 228 | { |
216 | if ( mIconView ) | 229 | if ( mIconView ) |
217 | mIconView->setFocus(); | 230 | mIconView->setFocus(); |
218 | } | 231 | } |
219 | 232 | ||
220 | 233 | ||
221 | void KAddressBookIconView::scrollUP() | 234 | void KAddressBookIconView::scrollUP() |
222 | { | 235 | { |
223 | QKeyEvent * ev = new QKeyEvent ( QEvent::KeyPress, Qt::Key_Up, 0,0 ); | 236 | QKeyEvent * ev = new QKeyEvent ( QEvent::KeyPress, Qt::Key_Up, 0,0 ); |
224 | QApplication::postEvent( mIconView, ev ); | 237 | QApplication::postEvent( mIconView, ev ); |
225 | } | 238 | } |
226 | void KAddressBookIconView::scrollDOWN() | 239 | void KAddressBookIconView::scrollDOWN() |
227 | { | 240 | { |
228 | QKeyEvent * ev = new QKeyEvent ( QEvent::KeyPress, Qt::Key_Down, 0,0 ); | 241 | QKeyEvent * ev = new QKeyEvent ( QEvent::KeyPress, Qt::Key_Down, 0,0 ); |
229 | QApplication::postEvent( mIconView, ev ); | 242 | QApplication::postEvent( mIconView, ev ); |
230 | } | 243 | } |
231 | void KAddressBookIconView::readConfig(KConfig *config) | 244 | void KAddressBookIconView::readConfig(KConfig *config) |
232 | { | 245 | { |
233 | KAddressBookView::readConfig(config); | 246 | KAddressBookView::readConfig(config); |
234 | 247 | ||
235 | //US method executed is part of KIconView | 248 | //US method executed is part of KIconView |
236 | //US disconnect(mIconView, SIGNAL(executed(QIconViewItem *)), | 249 | //US disconnect(mIconView, SIGNAL(executed(QIconViewItem *)), |
237 | //US this, SLOT(addresseeExecuted(QIconViewItem *))); | 250 | //US this, SLOT(addresseeExecuted(QIconViewItem *))); |
238 | disconnect(mIconView, SIGNAL(selectionChanged(QIconViewItem *)), | 251 | disconnect(mIconView, SIGNAL(selectionChanged(QIconViewItem *)), |
239 | this, SLOT(addresseeExecuted(QIconViewItem *))); | 252 | this, SLOT(addresseeExecuted(QIconViewItem *))); |
240 | 253 | ||
241 | //US method executed is part of KIconView. Use selectionChanged instead | 254 | //US method executed is part of KIconView. Use selectionChanged instead |
242 | /*US | 255 | /*US |
243 | if (KABPrefs::instance()->mHonorSingleClick) | 256 | if (KABPrefs::instance()->mHonorSingleClick) |
244 | connect(mIconView, SIGNAL(executed(QIconViewItem *)), | 257 | connect(mIconView, SIGNAL(executed(QIconViewItem *)), |
245 | this, SLOT(addresseeExecuted(QIconViewItem *))); | 258 | this, SLOT(addresseeExecuted(QIconViewItem *))); |
246 | else | 259 | else |
247 | connect(mIconView, SIGNAL(doubleClicked(QIconViewItem *)), | 260 | connect(mIconView, SIGNAL(doubleClicked(QIconViewItem *)), |
248 | this, SLOT(addresseeExecuted(QIconViewItem *))); | 261 | this, SLOT(addresseeExecuted(QIconViewItem *))); |
249 | */ | 262 | */ |
250 | connect(mIconView, SIGNAL(selectionChanged(QIconViewItem *)), | 263 | connect(mIconView, SIGNAL(selectionChanged(QIconViewItem *)), |
251 | this, SLOT(addresseeExecuted(QIconViewItem *))); | 264 | this, SLOT(addresseeExecuted(QIconViewItem *))); |
252 | 265 | ||
253 | } | 266 | } |
254 | void KAddressBookIconView::doSearch( const QString& s ,KABC::Field *field ) | 267 | void KAddressBookIconView::doSearch( const QString& s ,KABC::Field *field ) |
255 | { | 268 | { |
256 | mIconView->clear(); | 269 | mIconView->clear(); |
257 | mIconList.clear(); | 270 | mIconList.clear(); |
258 | if ( s.isEmpty() || s == "*" ) { | 271 | if ( s.isEmpty() || s == "*" ) { |
259 | refresh(); | 272 | refresh(); |
260 | return; | 273 | return; |
261 | } | 274 | } |
262 | QRegExp re = getRegExp( s ); | 275 | QRegExp re = getRegExp( s ); |
263 | if (!re.isValid()) | 276 | if (!re.isValid()) |
264 | return; | 277 | return; |
265 | KABC::Addressee::List addresseeList = addressees(); | 278 | KABC::Addressee::List addresseeList = addressees(); |
266 | KABC::Addressee::List::Iterator it; | 279 | KABC::Addressee::List::Iterator it; |
267 | if ( field ) { | 280 | if ( field ) { |
268 | for (it = addresseeList.begin(); it != addresseeList.end(); ++it ) { | 281 | for (it = addresseeList.begin(); it != addresseeList.end(); ++it ) { |
269 | if ( (*it).uid().left(2) == "la" && (*it).uid().left(19) == QString("last-syncAddressee-") ) | 282 | if ( (*it).uid().left(2) == "la" && (*it).uid().left(19) == QString("last-syncAddressee-") ) |
270 | continue; | 283 | continue; |
271 | #if QT_VERSION >= 0x030000 | 284 | #if QT_VERSION >= 0x030000 |
272 | if (re.search(field->value( *it ).lower()) == 0) | 285 | if (re.search(field->value( *it ).lower()) == 0) |
273 | #else | 286 | #else |
274 | if (re.match(field->value( *it ).lower()) == 0) | 287 | if (re.match(field->value( *it ).lower()) == 0) |
275 | #endif | 288 | #endif |
276 | mIconList.append(new AddresseeIconViewItem( fields(), addressBook(), *it, mIconView )); | 289 | mIconList.append(new AddresseeIconViewItem( fields(), addressBook(), *it, mIconView )); |
277 | 290 | ||
278 | 291 | ||
279 | } | 292 | } |
280 | } else { | 293 | } else { |
281 | KABC::Field::List fieldList = allFields(); | 294 | KABC::Field::List fieldList = allFields(); |
282 | KABC::Field::List::ConstIterator fieldIt; | 295 | KABC::Field::List::ConstIterator fieldIt; |
283 | for (it = addresseeList.begin(); it != addresseeList.end(); ++it ) { | 296 | for (it = addresseeList.begin(); it != addresseeList.end(); ++it ) { |
284 | if ( (*it).uid().left(2) == "la" && (*it).uid().left(19) == QString("last-syncAddressee-") ) | 297 | if ( (*it).uid().left(2) == "la" && (*it).uid().left(19) == QString("last-syncAddressee-") ) |
285 | continue; | 298 | continue; |
299 | bool match = false; | ||
286 | for ( fieldIt = fieldList.begin(); fieldIt != fieldList.end(); ++fieldIt ) { | 300 | for ( fieldIt = fieldList.begin(); fieldIt != fieldList.end(); ++fieldIt ) { |
287 | #if QT_VERSION >= 0x030000 | 301 | #if QT_VERSION >= 0x030000 |
288 | if (re.search((*fieldIt)->value( *it ).lower()) == 0) | 302 | if (re.search((*fieldIt)->value( *it ).lower()) == 0) |
289 | #else | 303 | #else |
290 | if (re.match((*fieldIt)->value( *it ).lower()) == 0) | 304 | if (re.match((*fieldIt)->value( *it ).lower()) == 0) |
291 | #endif | 305 | #endif |
292 | { | 306 | { |
293 | mIconList.append( new AddresseeIconViewItem( fields(), addressBook(), *it, mIconView )); | 307 | mIconList.append( new AddresseeIconViewItem( fields(), addressBook(), *it, mIconView )); |
308 | match = true; | ||
294 | break; | 309 | break; |
295 | } | 310 | } |
311 | } | ||
312 | if ( ! match ) { | ||
313 | if ( (*it).matchPhoneNumber( &re ) ) { | ||
314 | mIconList.append( new AddresseeIconViewItem( fields(), addressBook(), *it, mIconView )); | ||
315 | match = true; | ||
316 | break; | ||
317 | } | ||
318 | } | ||
319 | if ( ! match ) { | ||
320 | if ( (*it).matchAddress( &re ) ) { | ||
321 | mIconList.append( new AddresseeIconViewItem( fields(), addressBook(), *it, mIconView )); | ||
322 | match = true; | ||
323 | break; | ||
324 | } | ||
296 | } | 325 | } |
297 | } | 326 | } |
298 | } | 327 | } |
299 | mIconView->arrangeItemsInGrid( true ); | 328 | mIconView->arrangeItemsInGrid( true ); |
300 | if ( mIconView->firstItem() ) { | 329 | if ( mIconView->firstItem() ) { |
301 | mIconView->setCurrentItem ( mIconView->firstItem() ); | 330 | mIconView->setCurrentItem ( mIconView->firstItem() ); |
302 | mIconView->setSelected ( mIconView->firstItem() , true ); | 331 | mIconView->setSelected ( mIconView->firstItem() , true ); |
303 | } | 332 | } |
304 | else | 333 | else |
305 | emit selected(QString::null); | 334 | emit selected(QString::null); |
306 | } | 335 | } |
307 | QStringList KAddressBookIconView::selectedUids() | 336 | QStringList KAddressBookIconView::selectedUids() |
308 | { | 337 | { |
309 | QStringList uidList; | 338 | QStringList uidList; |
310 | QIconViewItem *item; | 339 | QIconViewItem *item; |
311 | AddresseeIconViewItem *aItem; | 340 | AddresseeIconViewItem *aItem; |
312 | 341 | ||
313 | for (item = mIconView->firstItem(); item; item = item->nextItem()) | 342 | for (item = mIconView->firstItem(); item; item = item->nextItem()) |
314 | { | 343 | { |
315 | if (item->isSelected()) | 344 | if (item->isSelected()) |
316 | { | 345 | { |
317 | #ifndef KAB_EMBEDDED | 346 | #ifndef KAB_EMBEDDED |
318 | aItem = dynamic_cast<AddresseeIconViewItem*>(item); | 347 | aItem = dynamic_cast<AddresseeIconViewItem*>(item); |
319 | #else //KAB_EMBEDDED | 348 | #else //KAB_EMBEDDED |
320 | aItem = (AddresseeIconViewItem*)(item); | 349 | aItem = (AddresseeIconViewItem*)(item); |
321 | #endif //KAB_EMBEDDED | 350 | #endif //KAB_EMBEDDED |
322 | if (aItem) | 351 | if (aItem) |
323 | uidList << aItem->addressee().uid(); | 352 | uidList << aItem->addressee().uid(); |
324 | } | 353 | } |
325 | } | 354 | } |
326 | 355 | ||
327 | return uidList; | 356 | return uidList; |
328 | } | 357 | } |
329 | 358 | ||
330 | void KAddressBookIconView::refresh(QString uid) | 359 | void KAddressBookIconView::refresh(QString uid) |
331 | { | 360 | { |
332 | QIconViewItem *item; | 361 | QIconViewItem *item; |
333 | AddresseeIconViewItem *aItem; | 362 | AddresseeIconViewItem *aItem; |
334 | 363 | ||
335 | if ( uid.isNull() ) { | 364 | if ( uid.isNull() ) { |
336 | // Rebuild the view | 365 | // Rebuild the view |
337 | mIconView->clear(); | 366 | mIconView->clear(); |
338 | mIconList.clear(); | 367 | mIconList.clear(); |
339 | 368 | ||
340 | KABC::Addressee::List addresseeList = addressees(); | 369 | KABC::Addressee::List addresseeList = addressees(); |
341 | KABC::Addressee::List::Iterator iter; | 370 | KABC::Addressee::List::Iterator iter; |
342 | for ( iter = addresseeList.begin(); iter != addresseeList.end(); ++iter ) { | 371 | for ( iter = addresseeList.begin(); iter != addresseeList.end(); ++iter ) { |
343 | if ( (*iter).uid().left(2) == "la" && (*iter).uid().left(19) == QString("last-syncAddressee-") ) | 372 | if ( (*iter).uid().left(2) == "la" && (*iter).uid().left(19) == QString("last-syncAddressee-") ) |
344 | continue; | 373 | continue; |
345 | aItem = new AddresseeIconViewItem( fields(), addressBook(), *iter, mIconView ); | 374 | aItem = new AddresseeIconViewItem( fields(), addressBook(), *iter, mIconView ); |
346 | } | 375 | } |
347 | 376 | ||
348 | mIconView->arrangeItemsInGrid( true ); | 377 | mIconView->arrangeItemsInGrid( true ); |
349 | 378 | ||
350 | for ( item = mIconView->firstItem(); item; item = item->nextItem() ) | 379 | for ( item = mIconView->firstItem(); item; item = item->nextItem() ) |
351 | { | 380 | { |
352 | #ifndef KAB_EMBEDDED | 381 | #ifndef KAB_EMBEDDED |
353 | AddresseeIconViewItem* aivi = dynamic_cast<AddresseeIconViewItem*>( item ); | 382 | AddresseeIconViewItem* aivi = dynamic_cast<AddresseeIconViewItem*>( item ); |
354 | #else //KAB_EMBEDDED | 383 | #else //KAB_EMBEDDED |
355 | AddresseeIconViewItem* aivi = (AddresseeIconViewItem*)( item ); | 384 | AddresseeIconViewItem* aivi = (AddresseeIconViewItem*)( item ); |
356 | #endif //KAB_EMBEDDED | 385 | #endif //KAB_EMBEDDED |
357 | mIconList.append( aivi ); | 386 | mIconList.append( aivi ); |
358 | } | 387 | } |
359 | 388 | ||
360 | } else { | 389 | } else { |
361 | // Try to find the one to refresh | 390 | // Try to find the one to refresh |
362 | for ( item = mIconView->firstItem(); item; item = item->nextItem() ) { | 391 | for ( item = mIconView->firstItem(); item; item = item->nextItem() ) { |
363 | #ifndef KAB_EMBEDDED | 392 | #ifndef KAB_EMBEDDED |
364 | aItem = dynamic_cast<AddresseeIconViewItem*>(item); | 393 | aItem = dynamic_cast<AddresseeIconViewItem*>(item); |
365 | #else //KAB_EMBEDDED | 394 | #else //KAB_EMBEDDED |
366 | aItem = (AddresseeIconViewItem*)(item); | 395 | aItem = (AddresseeIconViewItem*)(item); |
367 | #endif //KAB_EMBEDDED | 396 | #endif //KAB_EMBEDDED |
368 | if ((aItem) && (aItem->addressee().uid() == uid)) { | 397 | if ((aItem) && (aItem->addressee().uid() == uid)) { |
369 | aItem->refresh(); | 398 | aItem->refresh(); |
370 | mIconView->arrangeItemsInGrid( true ); | 399 | mIconView->arrangeItemsInGrid( true ); |
371 | return; | 400 | return; |
372 | } | 401 | } |
373 | } | 402 | } |
374 | refresh( QString::null ); | 403 | refresh( QString::null ); |
375 | } | 404 | } |
376 | } | 405 | } |
377 | 406 | ||
378 | void KAddressBookIconView::setSelected(QString uid, bool selected) | 407 | void KAddressBookIconView::setSelected(QString uid, bool selected) |
379 | { | 408 | { |
380 | QIconViewItem *item; | 409 | QIconViewItem *item; |
381 | AddresseeIconViewItem *aItem; | 410 | AddresseeIconViewItem *aItem; |
382 | 411 | ||
383 | if (uid.isNull()) | 412 | if (uid.isNull()) |
384 | { | 413 | { |
385 | mIconView->selectAll(selected); | 414 | mIconView->selectAll(selected); |
386 | } | 415 | } |
387 | else | 416 | else |
388 | { | 417 | { |
389 | bool found = false; | 418 | bool found = false; |
390 | for (item = mIconView->firstItem(); item && !found; | 419 | for (item = mIconView->firstItem(); item && !found; |
391 | item = item->nextItem()) | 420 | item = item->nextItem()) |
392 | { | 421 | { |
393 | #ifndef KAB_EMBEDDED | 422 | #ifndef KAB_EMBEDDED |
394 | aItem = dynamic_cast<AddresseeIconViewItem*>(item); | 423 | aItem = dynamic_cast<AddresseeIconViewItem*>(item); |
395 | #else //KAB_EMBEDDED | 424 | #else //KAB_EMBEDDED |
396 | aItem = (AddresseeIconViewItem*)(item); | 425 | aItem = (AddresseeIconViewItem*)(item); |
397 | #endif //KAB_EMBEDDED | 426 | #endif //KAB_EMBEDDED |
398 | 427 | ||
399 | if ((aItem) && (aItem->addressee().uid() == uid)) | 428 | if ((aItem) && (aItem->addressee().uid() == uid)) |
400 | { | 429 | { |
401 | mIconView->setSelected(aItem, selected); | 430 | mIconView->setSelected(aItem, selected); |
402 | mIconView->ensureItemVisible( aItem ); | 431 | mIconView->ensureItemVisible( aItem ); |
403 | found = true; | 432 | found = true; |
404 | } | 433 | } |
405 | } | 434 | } |
406 | } | 435 | } |
407 | } | 436 | } |
408 | 437 | ||
409 | void KAddressBookIconView::addresseeExecuted(QIconViewItem *item) | 438 | void KAddressBookIconView::addresseeExecuted(QIconViewItem *item) |
410 | { | 439 | { |
411 | #ifndef KAB_EMBEDDED | 440 | #ifndef KAB_EMBEDDED |
412 | AddresseeIconViewItem *aItem = dynamic_cast<AddresseeIconViewItem*>(item); | 441 | AddresseeIconViewItem *aItem = dynamic_cast<AddresseeIconViewItem*>(item); |
413 | #else //KAB_EMBEDDED | 442 | #else //KAB_EMBEDDED |
414 | AddresseeIconViewItem *aItem = (AddresseeIconViewItem*)(item); | 443 | AddresseeIconViewItem *aItem = (AddresseeIconViewItem*)(item); |
415 | #endif //KAB_EMBEDDED | 444 | #endif //KAB_EMBEDDED |
416 | 445 | ||
417 | if (aItem) { | 446 | if (aItem) { |
418 | emit executed(aItem->addressee().uid()); | 447 | emit executed(aItem->addressee().uid()); |
419 | } | 448 | } |
420 | } | 449 | } |
421 | 450 | ||
422 | void KAddressBookIconView::addresseeSelected() | 451 | void KAddressBookIconView::addresseeSelected() |
423 | { | 452 | { |
424 | QIconViewItem *item; | 453 | QIconViewItem *item; |
425 | AddresseeIconViewItem *aItem; | 454 | AddresseeIconViewItem *aItem; |
426 | 455 | ||
427 | bool found = false; | 456 | bool found = false; |
428 | for (item = mIconView->firstItem(); item && !found; | 457 | for (item = mIconView->firstItem(); item && !found; |
429 | item = item->nextItem()) | 458 | item = item->nextItem()) |
430 | { | 459 | { |
431 | if (item->isSelected()) | 460 | if (item->isSelected()) |
432 | { | 461 | { |
433 | #ifndef KAB_EMBEDDED | 462 | #ifndef KAB_EMBEDDED |
434 | aItem = dynamic_cast<AddresseeIconViewItem*>(item); | 463 | aItem = dynamic_cast<AddresseeIconViewItem*>(item); |
435 | #else //KAB_EMBEDDED | 464 | #else //KAB_EMBEDDED |
436 | aItem = (AddresseeIconViewItem*)(item); | 465 | aItem = (AddresseeIconViewItem*)(item); |
437 | #endif //KAB_EMBEDDED | 466 | #endif //KAB_EMBEDDED |
438 | if (aItem) | 467 | if (aItem) |
439 | { | 468 | { |
440 | emit selected(aItem->addressee().uid()); | 469 | emit selected(aItem->addressee().uid()); |
441 | found = true; | 470 | found = true; |
442 | } | 471 | } |
443 | } | 472 | } |
444 | } | 473 | } |
445 | 474 | ||
446 | if (!found) | 475 | if (!found) |
447 | emit selected(QString::null); | 476 | emit selected(QString::null); |
448 | } | 477 | } |
449 | 478 | ||
450 | #ifndef KAB_EMBEDDED | 479 | #ifndef KAB_EMBEDDED |
451 | #include "kaddressbookiconview.moc" | 480 | #include "kaddressbookiconview.moc" |
452 | #endif //KAB_EMBEDDED | 481 | #endif //KAB_EMBEDDED |