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