Diffstat (limited to 'kaddressbook/views/kaddressbooktableview.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | kaddressbook/views/kaddressbooktableview.cpp | 65 |
1 files changed, 33 insertions, 32 deletions
diff --git a/kaddressbook/views/kaddressbooktableview.cpp b/kaddressbook/views/kaddressbooktableview.cpp index ee2fcf8..8d2203e 100644 --- a/kaddressbook/views/kaddressbooktableview.cpp +++ b/kaddressbook/views/kaddressbooktableview.cpp | |||
@@ -36,302 +36,303 @@ | |||
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 | refresh(); | 106 | //US performceimprovement. Refresh is done from the outside |
107 | //US refresh(); | ||
107 | 108 | ||
108 | mListView->setSorting( 0, true ); | 109 | mListView->setSorting( 0, true ); |
109 | mainLayout->addWidget( mListView ); | 110 | mainLayout->addWidget( mListView ); |
110 | mainLayout->activate(); | 111 | mainLayout->activate(); |
111 | mListView->show(); | 112 | mListView->show(); |
112 | } | 113 | } |
113 | 114 | ||
114 | void KAddressBookTableView::writeConfig(KConfig *config) | 115 | void KAddressBookTableView::writeConfig(KConfig *config) |
115 | { | 116 | { |
116 | KAddressBookView::writeConfig(config); | 117 | KAddressBookView::writeConfig(config); |
117 | 118 | ||
118 | mListView->saveLayout(config, config->group()); | 119 | mListView->saveLayout(config, config->group()); |
119 | } | 120 | } |
120 | 121 | ||
121 | void KAddressBookTableView::readConfig(KConfig *config) | 122 | void KAddressBookTableView::readConfig(KConfig *config) |
122 | { | 123 | { |
123 | KAddressBookView::readConfig( config ); | 124 | KAddressBookView::readConfig( config ); |
124 | 125 | ||
125 | // The config could have changed the fields, so we need to reconstruct | 126 | // The config could have changed the fields, so we need to reconstruct |
126 | // the listview. | 127 | // the listview. |
127 | reconstructListView(); | 128 | reconstructListView(); |
128 | 129 | ||
129 | // Set the list view options | 130 | // Set the list view options |
130 | mListView->setAlternateBackgroundEnabled(config->readBoolEntry("ABackground", | 131 | mListView->setAlternateBackgroundEnabled(config->readBoolEntry("ABackground", |
131 | true)); | 132 | true)); |
132 | mListView->setSingleLineEnabled(config->readBoolEntry("SingleLine", false)); | 133 | mListView->setSingleLineEnabled(config->readBoolEntry("SingleLine", false)); |
133 | mListView->setToolTipsEnabled(config->readBoolEntry("ToolTips", true)); | 134 | mListView->setToolTipsEnabled(config->readBoolEntry("ToolTips", true)); |
134 | 135 | ||
135 | if (config->readBoolEntry("Background", false)) | 136 | if (config->readBoolEntry("Background", false)) |
136 | mListView->setBackgroundPixmap(config->readEntry("BackgroundName")); | 137 | mListView->setBackgroundPixmap(config->readEntry("BackgroundName")); |
137 | 138 | ||
138 | // Restore the layout of the listview | 139 | // Restore the layout of the listview |
139 | mListView->restoreLayout(config, config->group()); | 140 | mListView->restoreLayout(config, config->group()); |
140 | } | 141 | } |
141 | 142 | ||
142 | void KAddressBookTableView::refresh(QString uid) | 143 | void KAddressBookTableView::refresh(QString uid) |
143 | { | 144 | { |
144 | // For now just repopulate. In reality this method should | 145 | // For now just repopulate. In reality this method should |
145 | // check the value of uid, and if valid iterate through | 146 | // check the value of uid, and if valid iterate through |
146 | // the listview to find the entry, then tell it to refresh. | 147 | // the listview to find the entry, then tell it to refresh. |
147 | 148 | ||
148 | if (uid.isNull()) { | 149 | if (uid.isNull()) { |
149 | // Clear the list view | 150 | // Clear the list view |
150 | QString currentUID, nextUID; | 151 | QString currentUID, nextUID; |
151 | #ifndef KAB_EMBEDDED | 152 | #ifndef KAB_EMBEDDED |
152 | ContactListViewItem *currentItem = dynamic_cast<ContactListViewItem*>( mListView->currentItem() ); | 153 | ContactListViewItem *currentItem = dynamic_cast<ContactListViewItem*>( mListView->currentItem() ); |
153 | #else //KAB_EMBEDDED | 154 | #else //KAB_EMBEDDED |
154 | ContactListViewItem *currentItem = (ContactListViewItem*)( mListView->currentItem() ); | 155 | ContactListViewItem *currentItem = (ContactListViewItem*)( mListView->currentItem() ); |
155 | #endif //KAB_EMBEDDED | 156 | #endif //KAB_EMBEDDED |
156 | 157 | ||
157 | if ( currentItem ) { | 158 | if ( currentItem ) { |
158 | #ifndef KAB_EMBEDDED | 159 | #ifndef KAB_EMBEDDED |
159 | ContactListViewItem *nextItem = dynamic_cast<ContactListViewItem*>( currentItem->itemBelow() ); | 160 | ContactListViewItem *nextItem = dynamic_cast<ContactListViewItem*>( currentItem->itemBelow() ); |
160 | #else //KAB_EMBEDDED | 161 | #else //KAB_EMBEDDED |
161 | ContactListViewItem *nextItem = (ContactListViewItem*)( currentItem->itemBelow() ); | 162 | ContactListViewItem *nextItem = (ContactListViewItem*)( currentItem->itemBelow() ); |
162 | #endif //KAB_EMBEDDED | 163 | #endif //KAB_EMBEDDED |
163 | if ( nextItem ) | 164 | if ( nextItem ) |
164 | nextUID = nextItem->addressee().uid(); | 165 | nextUID = nextItem->addressee().uid(); |
165 | currentUID = currentItem->addressee().uid(); | 166 | currentUID = currentItem->addressee().uid(); |
166 | } | 167 | } |
167 | 168 | ||
168 | mListView->clear(); | 169 | mListView->clear(); |
169 | 170 | ||
170 | currentItem = 0; | 171 | currentItem = 0; |
171 | KABC::Addressee::List addresseeList = addressees(); | 172 | KABC::Addressee::List addresseeList = addressees(); |
172 | KABC::Addressee::List::Iterator it; | 173 | KABC::Addressee::List::Iterator it; |
173 | for (it = addresseeList.begin(); it != addresseeList.end(); ++it ) { | 174 | for (it = addresseeList.begin(); it != addresseeList.end(); ++it ) { |
174 | ContactListViewItem *item = new ContactListViewItem(*it, mListView, addressBook(), fields()); | 175 | ContactListViewItem *item = new ContactListViewItem(*it, mListView, addressBook(), fields()); |
175 | if ( (*it).uid() == currentUID ) | 176 | if ( (*it).uid() == currentUID ) |
176 | currentItem = item; | 177 | currentItem = item; |
177 | else if ( (*it).uid() == nextUID && !currentItem ) | 178 | else if ( (*it).uid() == nextUID && !currentItem ) |
178 | currentItem = item; | 179 | currentItem = item; |
179 | } | 180 | } |
180 | 181 | ||
181 | // Sometimes the background pixmap gets messed up when we add lots | 182 | // Sometimes the background pixmap gets messed up when we add lots |
182 | // of items. | 183 | // of items. |
183 | mListView->repaint(); | 184 | mListView->repaint(); |
184 | 185 | ||
185 | if ( currentItem ) { | 186 | if ( currentItem ) { |
186 | mListView->setCurrentItem( currentItem ); | 187 | mListView->setCurrentItem( currentItem ); |
187 | mListView->ensureItemVisible( currentItem ); | 188 | mListView->ensureItemVisible( currentItem ); |
188 | } | 189 | } |
189 | } else { | 190 | } else { |
190 | // Only need to update on entry. Iterate through and try to find it | 191 | // Only need to update on entry. Iterate through and try to find it |
191 | ContactListViewItem *ceItem; | 192 | ContactListViewItem *ceItem; |
192 | QListViewItemIterator it( mListView ); | 193 | QListViewItemIterator it( mListView ); |
193 | while ( it.current() ) { | 194 | while ( it.current() ) { |
194 | #ifndef KAB_EMBEDDED | 195 | #ifndef KAB_EMBEDDED |
195 | ceItem = dynamic_cast<ContactListViewItem*>( it.current() ); | 196 | ceItem = dynamic_cast<ContactListViewItem*>( it.current() ); |
196 | #else //KAB_EMBEDDED | 197 | #else //KAB_EMBEDDED |
197 | ceItem = (ContactListViewItem*)( it.current() ); | 198 | ceItem = (ContactListViewItem*)( it.current() ); |
198 | #endif //KAB_EMBEDDED | 199 | #endif //KAB_EMBEDDED |
199 | 200 | ||
200 | if ( ceItem && ceItem->addressee().uid() == uid ) { | 201 | if ( ceItem && ceItem->addressee().uid() == uid ) { |
201 | ceItem->refresh(); | 202 | ceItem->refresh(); |
202 | return; | 203 | return; |
203 | } | 204 | } |
204 | ++it; | 205 | ++it; |
205 | } | 206 | } |
206 | 207 | ||
207 | refresh( QString::null ); | 208 | refresh( QString::null ); |
208 | } | 209 | } |
209 | } | 210 | } |
210 | 211 | ||
211 | QStringList KAddressBookTableView::selectedUids() | 212 | QStringList KAddressBookTableView::selectedUids() |
212 | { | 213 | { |
213 | QStringList uidList; | 214 | QStringList uidList; |
214 | QListViewItem *item; | 215 | QListViewItem *item; |
215 | ContactListViewItem *ceItem; | 216 | ContactListViewItem *ceItem; |
216 | 217 | ||
217 | for(item = mListView->firstChild(); item; item = item->itemBelow()) | 218 | for(item = mListView->firstChild(); item; item = item->itemBelow()) |
218 | { | 219 | { |
219 | if (mListView->isSelected( item )) | 220 | if (mListView->isSelected( item )) |
220 | { | 221 | { |
221 | #ifndef KAB_EMBEDDED | 222 | #ifndef KAB_EMBEDDED |
222 | ceItem = dynamic_cast<ContactListViewItem*>(item); | 223 | ceItem = dynamic_cast<ContactListViewItem*>(item); |
223 | #else //KAB_EMBEDDED | 224 | #else //KAB_EMBEDDED |
224 | ceItem = (ContactListViewItem*)(item); | 225 | ceItem = (ContactListViewItem*)(item); |
225 | #endif //KAB_EMBEDDED | 226 | #endif //KAB_EMBEDDED |
226 | 227 | ||
227 | if (ceItem != 0L) | 228 | if (ceItem != 0L) |
228 | uidList << ceItem->addressee().uid(); | 229 | uidList << ceItem->addressee().uid(); |
229 | } | 230 | } |
230 | } | 231 | } |
231 | if ( uidList.count() == 0 ) | 232 | if ( uidList.count() == 0 ) |
232 | if ( mListView->currentItem() ) { | 233 | if ( mListView->currentItem() ) { |
233 | ceItem = (ContactListViewItem*)(mListView->currentItem()) ; | 234 | ceItem = (ContactListViewItem*)(mListView->currentItem()) ; |
234 | uidList << ceItem->addressee().uid(); | 235 | uidList << ceItem->addressee().uid(); |
235 | } | 236 | } |
236 | 237 | ||
237 | return uidList; | 238 | return uidList; |
238 | } | 239 | } |
239 | 240 | ||
240 | void KAddressBookTableView::setSelected(QString uid, bool selected) | 241 | void KAddressBookTableView::setSelected(QString uid, bool selected) |
241 | { | 242 | { |
242 | QListViewItem *item; | 243 | QListViewItem *item; |
243 | ContactListViewItem *ceItem; | 244 | ContactListViewItem *ceItem; |
244 | 245 | ||
245 | if (uid.isNull()) | 246 | if (uid.isNull()) |
246 | { | 247 | { |
247 | mListView->selectAll(selected); | 248 | mListView->selectAll(selected); |
248 | } | 249 | } |
249 | else | 250 | else |
250 | { | 251 | { |
251 | for(item = mListView->firstChild(); item; item = item->itemBelow()) | 252 | for(item = mListView->firstChild(); item; item = item->itemBelow()) |
252 | { | 253 | { |
253 | #ifndef KAB_EMBEDDED | 254 | #ifndef KAB_EMBEDDED |
254 | ceItem = dynamic_cast<ContactListViewItem*>(item); | 255 | ceItem = dynamic_cast<ContactListViewItem*>(item); |
255 | #else //KAB_EMBEDDED | 256 | #else //KAB_EMBEDDED |
256 | ceItem = (ContactListViewItem*)(item); | 257 | ceItem = (ContactListViewItem*)(item); |
257 | #endif //KAB_EMBEDDED | 258 | #endif //KAB_EMBEDDED |
258 | 259 | ||
259 | 260 | ||
260 | if ((ceItem != 0L) && (ceItem->addressee().uid() == uid)) | 261 | if ((ceItem != 0L) && (ceItem->addressee().uid() == uid)) |
261 | { | 262 | { |
262 | mListView->setSelected(item, selected); | 263 | mListView->setSelected(item, selected); |
263 | 264 | ||
264 | if (selected) | 265 | if (selected) |
265 | mListView->ensureItemVisible(item); | 266 | mListView->ensureItemVisible(item); |
266 | } | 267 | } |
267 | } | 268 | } |
268 | } | 269 | } |
269 | } | 270 | } |
270 | 271 | ||
271 | void KAddressBookTableView::addresseeSelected() | 272 | void KAddressBookTableView::addresseeSelected() |
272 | { | 273 | { |
273 | // We need to try to find the first selected item. This might not be the | 274 | // We need to try to find the first selected item. This might not be the |
274 | // last selected item, but when QListView is in multiselection mode, | 275 | // last selected item, but when QListView is in multiselection mode, |
275 | // there is no way to figure out which one was | 276 | // there is no way to figure out which one was |
276 | // selected last. | 277 | // selected last. |
277 | QListViewItem *item; | 278 | QListViewItem *item; |
278 | bool found =false; | 279 | bool found =false; |
279 | for (item = mListView->firstChild(); item && !found; | 280 | for (item = mListView->firstChild(); item && !found; |
280 | item = item->nextSibling()) | 281 | item = item->nextSibling()) |
281 | { | 282 | { |
282 | if (item->isSelected()) | 283 | if (item->isSelected()) |
283 | { | 284 | { |
284 | found = true; | 285 | found = true; |
285 | #ifndef KAB_EMBEDDED | 286 | #ifndef KAB_EMBEDDED |
286 | ContactListViewItem *ceItem | 287 | ContactListViewItem *ceItem |
287 | = dynamic_cast<ContactListViewItem*>(item); | 288 | = dynamic_cast<ContactListViewItem*>(item); |
288 | #else //KAB_EMBEDDED | 289 | #else //KAB_EMBEDDED |
289 | ContactListViewItem *ceItem | 290 | ContactListViewItem *ceItem |
290 | = (ContactListViewItem*)(item); | 291 | = (ContactListViewItem*)(item); |
291 | #endif //KAB_EMBEDDED | 292 | #endif //KAB_EMBEDDED |
292 | 293 | ||
293 | if ( ceItem ) emit selected(ceItem->addressee().uid()); | 294 | if ( ceItem ) emit selected(ceItem->addressee().uid()); |
294 | } | 295 | } |
295 | } | 296 | } |
296 | 297 | ||
297 | if (!found) | 298 | if (!found) |
298 | emit selected(QString::null); | 299 | emit selected(QString::null); |
299 | } | 300 | } |
300 | 301 | ||
301 | void KAddressBookTableView::addresseeExecuted(QListViewItem *item) | 302 | void KAddressBookTableView::addresseeExecuted(QListViewItem *item) |
302 | { | 303 | { |
303 | if (item) | 304 | if (item) |
304 | { | 305 | { |
305 | #ifndef KAB_EMBEDDED | 306 | #ifndef KAB_EMBEDDED |
306 | ContactListViewItem *ceItem | 307 | ContactListViewItem *ceItem |
307 | = dynamic_cast<ContactListViewItem*>(item); | 308 | = dynamic_cast<ContactListViewItem*>(item); |
308 | #else //KAB_EMBEDDED | 309 | #else //KAB_EMBEDDED |
309 | ContactListViewItem *ceItem | 310 | ContactListViewItem *ceItem |
310 | = (ContactListViewItem*)(item); | 311 | = (ContactListViewItem*)(item); |
311 | #endif //KAB_EMBEDDED | 312 | #endif //KAB_EMBEDDED |
312 | 313 | ||
313 | if (ceItem) | 314 | if (ceItem) |
314 | { | 315 | { |
315 | emit executed(ceItem->addressee().uid()); | 316 | emit executed(ceItem->addressee().uid()); |
316 | } | 317 | } |
317 | } | 318 | } |
318 | else | 319 | else |
319 | { | 320 | { |
320 | emit executed(QString::null); | 321 | emit executed(QString::null); |
321 | } | 322 | } |
322 | } | 323 | } |
323 | 324 | ||
324 | void KAddressBookTableView::addresseeDeleted() | 325 | void KAddressBookTableView::addresseeDeleted() |
325 | { | 326 | { |
326 | 327 | ||
327 | emit deleteRequest(); | 328 | emit deleteRequest(); |
328 | 329 | ||
329 | } | 330 | } |
330 | 331 | ||
331 | 332 | ||
332 | 333 | ||
333 | 334 | ||
334 | 335 | ||
335 | #ifndef KAB_EMBEDDED | 336 | #ifndef KAB_EMBEDDED |
336 | #include "kaddressbooktableview.moc" | 337 | #include "kaddressbooktableview.moc" |
337 | #endif //KAB_EMBEDDED | 338 | #endif //KAB_EMBEDDED |