summaryrefslogtreecommitdiffabout
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--kaddressbook/viewmanager.cpp66
-rw-r--r--kaddressbook/views/kaddressbooktableview.cpp65
2 files changed, 67 insertions, 64 deletions
diff --git a/kaddressbook/viewmanager.cpp b/kaddressbook/viewmanager.cpp
index e8c5b45..bec1862 100644
--- a/kaddressbook/viewmanager.cpp
+++ b/kaddressbook/viewmanager.cpp
@@ -72,460 +72,462 @@ $Id$
72ViewManager::ViewManager( KABCore *core, QWidget *parent, const char *name ) 72ViewManager::ViewManager( KABCore *core, QWidget *parent, const char *name )
73 : QWidget( parent, name ), mCore( core ), mActiveView( 0 ) 73 : QWidget( parent, name ), mCore( core ), mActiveView( 0 )
74{ 74{
75 initGUI(); 75 initGUI();
76 initActions(); 76 initActions();
77 77
78 mViewDict.setAutoDelete( true ); 78 mViewDict.setAutoDelete( true );
79 79
80 createViewFactories(); 80 createViewFactories();
81} 81}
82 82
83ViewManager::~ViewManager() 83ViewManager::~ViewManager()
84{ 84{
85 unloadViews(); 85 unloadViews();
86 mViewFactoryDict.clear(); 86 mViewFactoryDict.clear();
87} 87}
88 88
89void ViewManager::restoreSettings() 89void ViewManager::restoreSettings()
90{ 90{
91 mViewNameList = KABPrefs::instance()->mViewNames; 91 mViewNameList = KABPrefs::instance()->mViewNames;
92 QString activeViewName = KABPrefs::instance()->mCurrentView; 92 QString activeViewName = KABPrefs::instance()->mCurrentView;
93 93
94 mActionSelectView->setItems( mViewNameList ); 94 mActionSelectView->setItems( mViewNameList );
95 95
96 // Filter 96 // Filter
97 mFilterList = Filter::restore( mCore->config(), "Filter" ); 97 mFilterList = Filter::restore( mCore->config(), "Filter" );
98 mActionSelectFilter->setItems( filterNames() ); 98 mActionSelectFilter->setItems( filterNames() );
99 mActionSelectFilter->setCurrentItem( KABPrefs::instance()->mCurrentFilter ); 99 mActionSelectFilter->setCurrentItem( KABPrefs::instance()->mCurrentFilter );
100 100
101 // Tell the views to reread their config, since they may have 101 // Tell the views to reread their config, since they may have
102 // been modified by global settings 102 // been modified by global settings
103 QString _oldgroup = mCore->config()->group(); 103 QString _oldgroup = mCore->config()->group();
104 104
105 QDictIterator<KAddressBookView> it( mViewDict ); 105 QDictIterator<KAddressBookView> it( mViewDict );
106 for ( it.toFirst(); it.current(); ++it ) { 106 for ( it.toFirst(); it.current(); ++it ) {
107 KConfigGroupSaver saver( mCore->config(), it.currentKey() ); 107 KConfigGroupSaver saver( mCore->config(), it.currentKey() );
108 it.current()->readConfig( mCore->config() ); 108 it.current()->readConfig( mCore->config() );
109 } 109 }
110 setActiveView( activeViewName ); 110 setActiveView( activeViewName );
111 111
112 mActionDeleteView->setEnabled( mViewNameList.count() > 1 ); 112 mActionDeleteView->setEnabled( mViewNameList.count() > 1 );
113} 113}
114 114
115void ViewManager::saveSettings() 115void ViewManager::saveSettings()
116{ 116{
117 QString _oldgroup = mCore->config()->group(); 117 QString _oldgroup = mCore->config()->group();
118 118
119 QDictIterator<KAddressBookView> it( mViewDict ); 119 QDictIterator<KAddressBookView> it( mViewDict );
120 for ( it.toFirst(); it.current(); ++it ) { 120 for ( it.toFirst(); it.current(); ++it ) {
121 KConfigGroupSaver saver( mCore->config(), it.currentKey() ); 121 KConfigGroupSaver saver( mCore->config(), it.currentKey() );
122#ifdef DESKTOP_VERSION 122#ifdef DESKTOP_VERSION
123 (*it)->writeConfig( mCore->config() ); 123 (*it)->writeConfig( mCore->config() );
124#else 124#else
125 (*it).writeConfig( mCore->config() ); 125 (*it).writeConfig( mCore->config() );
126#endif 126#endif
127 } 127 }
128 128
129 Filter::save( mCore->config(), "Filter", mFilterList ); 129 Filter::save( mCore->config(), "Filter", mFilterList );
130 KABPrefs::instance()->mCurrentFilter = mActionSelectFilter->currentItem(); 130 KABPrefs::instance()->mCurrentFilter = mActionSelectFilter->currentItem();
131 131
132 // write the view name list 132 // write the view name list
133 KABPrefs::instance()->mViewNames = mViewNameList; 133 KABPrefs::instance()->mViewNames = mViewNameList;
134 KABPrefs::instance()->mCurrentView = mActiveView->caption(); 134 KABPrefs::instance()->mCurrentView = mActiveView->caption();
135 135
136} 136}
137 137
138QStringList ViewManager::selectedUids() const 138QStringList ViewManager::selectedUids() const
139{ 139{
140 if ( mActiveView ) 140 if ( mActiveView )
141 return mActiveView->selectedUids(); 141 return mActiveView->selectedUids();
142 else 142 else
143 return QStringList(); 143 return QStringList();
144} 144}
145 145
146QStringList ViewManager::selectedEmails() const 146QStringList ViewManager::selectedEmails() const
147{ 147{
148 if ( mActiveView ) 148 if ( mActiveView )
149 return mActiveView->selectedEmails(); 149 return mActiveView->selectedEmails();
150 else 150 else
151 return QStringList(); 151 return QStringList();
152} 152}
153 153
154KABC::Addressee::List ViewManager::selectedAddressees() const 154KABC::Addressee::List ViewManager::selectedAddressees() const
155{ 155{
156 KABC::Addressee::List list; 156 KABC::Addressee::List list;
157 if ( mActiveView ) { 157 if ( mActiveView ) {
158 QStringList uids = mActiveView->selectedUids(); 158 QStringList uids = mActiveView->selectedUids();
159 QStringList::Iterator it; 159 QStringList::Iterator it;
160 for ( it = uids.begin(); it != uids.end(); ++it ) { 160 for ( it = uids.begin(); it != uids.end(); ++it ) {
161 KABC::Addressee addr = mCore->addressBook()->findByUid( *it ); 161 KABC::Addressee addr = mCore->addressBook()->findByUid( *it );
162 if ( !addr.isEmpty() ) 162 if ( !addr.isEmpty() )
163 list.append( addr ); 163 list.append( addr );
164 } 164 }
165 } 165 }
166 166
167 return list; 167 return list;
168} 168}
169//US added another method with no parameter, since my moc compiler does not support default parameters. 169//US added another method with no parameter, since my moc compiler does not support default parameters.
170void ViewManager::setSelected() 170void ViewManager::setSelected()
171{ 171{
172 setSelected( QString::null, true ); 172 setSelected( QString::null, true );
173} 173}
174 174
175void ViewManager::setSelected( const QString &uid, bool selected ) 175void ViewManager::setSelected( const QString &uid, bool selected )
176{ 176{
177 if ( mActiveView ) 177 if ( mActiveView )
178 mActiveView->setSelected( uid, selected ); 178 mActiveView->setSelected( uid, selected );
179} 179}
180 180
181void ViewManager::unloadViews() 181void ViewManager::unloadViews()
182{ 182{
183 mViewDict.clear(); 183 mViewDict.clear();
184 mActiveView = 0; 184 mActiveView = 0;
185} 185}
186 186
187void ViewManager::setActiveView( const QString &name ) 187void ViewManager::setActiveView( const QString &name )
188{ 188{
189 KAddressBookView *view = 0; 189 KAddressBookView *view = 0;
190 190
191 // Check that this isn't the same as the current active view 191 // Check that this isn't the same as the current active view
192 if ( mActiveView && ( mActiveView->caption() == name ) ) 192 if ( mActiveView && ( mActiveView->caption() == name ) )
193 return; 193 return;
194 194
195 // At this point we know the view that should be active is not 195 // At this point we know the view that should be active is not
196 // currently active. We will try to find the new on in the list. If 196 // currently active. We will try to find the new on in the list. If
197 // we can't find it, it means it hasn't been instantiated, so we will 197 // we can't find it, it means it hasn't been instantiated, so we will
198 // create it on demand. 198 // create it on demand.
199 199
200 view = mViewDict.find( name ); 200 view = mViewDict.find( name );
201 201
202 // Check if we found the view. If we didn't, then we need to create it 202 // Check if we found the view. If we didn't, then we need to create it
203 if ( view == 0 ) { 203 if ( view == 0 ) {
204 KConfig *config = mCore->config(); 204 KConfig *config = mCore->config();
205 205
206 KConfigGroupSaver saver( config, name ); 206 KConfigGroupSaver saver( config, name );
207 207
208 QString type = config->readEntry( "Type", "Table" ); 208 QString type = config->readEntry( "Type", "Table" );
209 209
210 kdDebug(5720) << "ViewManager::setActiveView: creating view - " << name << endl; 210 kdDebug(5720) << "ViewManager::setActiveView: creating view - " << name << endl;
211 211
212 ViewFactory *factory = mViewFactoryDict.find( type ); 212 ViewFactory *factory = mViewFactoryDict.find( type );
213 if ( factory ) 213 if ( factory )
214 view = factory->view( mCore->addressBook(), mViewWidgetStack ); 214 view = factory->view( mCore->addressBook(), mViewWidgetStack );
215 215
216 if ( view ) { 216 if ( view ) {
217 view->setCaption( name ); 217 view->setCaption( name );
218 mViewDict.insert( name, view ); 218 mViewDict.insert( name, view );
219//US my version needs an int as second parameter to addWidget 219//US my version needs an int as second parameter to addWidget
220 mViewWidgetStack->addWidget( view, -1 ); 220 mViewWidgetStack->addWidget( view, -1 );
221 view->readConfig( config ); 221 view->readConfig( config );
222 222
223 // The manager just relays the signals 223 // The manager just relays the signals
224 connect( view, SIGNAL( selected( const QString& ) ), 224 connect( view, SIGNAL( selected( const QString& ) ),
225 SIGNAL( selected( const QString & ) ) ); 225 SIGNAL( selected( const QString & ) ) );
226 connect( view, SIGNAL( executed( const QString& ) ), 226 connect( view, SIGNAL( executed( const QString& ) ),
227 SIGNAL( executed( const QString& ) ) ); 227 SIGNAL( executed( const QString& ) ) );
228 228
229 connect( view, SIGNAL( deleteRequest( ) ), 229 connect( view, SIGNAL( deleteRequest( ) ),
230 SIGNAL( deleteRequest( ) ) ); 230 SIGNAL( deleteRequest( ) ) );
231 231
232 connect( view, SIGNAL( modified() ), SIGNAL( modified() ) ); 232 connect( view, SIGNAL( modified() ), SIGNAL( modified() ) );
233 connect( view, SIGNAL( dropped( QDropEvent* ) ), 233 connect( view, SIGNAL( dropped( QDropEvent* ) ),
234 SLOT( dropped( QDropEvent* ) ) ); 234 SLOT( dropped( QDropEvent* ) ) );
235 connect( view, SIGNAL( startDrag() ), SLOT( startDrag() ) ); 235 connect( view, SIGNAL( startDrag() ), SLOT( startDrag() ) );
236 } 236 }
237 } 237 }
238 238
239 // If we found or created the view, raise it and refresh it 239 // If we found or created the view, raise it and refresh it
240 if ( view ) { 240 if ( view ) {
241 mActiveView = view; 241 mActiveView = view;
242 mViewWidgetStack->raiseWidget( view ); 242 mViewWidgetStack->raiseWidget( view );
243 // Set the proper filter in the view. By setting the combo 243 // Set the proper filter in the view. By setting the combo
244 // box, the activated slot will be called, which will push 244 // box, the activated slot will be called, which will push
245 // the filter to the view and refresh it. 245 // the filter to the view and refresh it.
246 246
247 if ( view->defaultFilterType() == KAddressBookView::None ) { 247 if ( view->defaultFilterType() == KAddressBookView::None ) {
248 248
249 mActionSelectFilter->setCurrentItem( 0 ); 249 mActionSelectFilter->setCurrentItem( 0 );
250 setActiveFilter( 0 ); 250 setActiveFilter( 0 );
251 } else if ( view->defaultFilterType() == KAddressBookView::Active ) { 251 } else if ( view->defaultFilterType() == KAddressBookView::Active ) {
252 setActiveFilter( mActionSelectFilter->currentItem() ); 252 setActiveFilter( mActionSelectFilter->currentItem() );
253 } else { 253 } else {
254 uint pos = filterPosition( view->defaultFilterName() ); 254 uint pos = filterPosition( view->defaultFilterName() );
255 mActionSelectFilter->setCurrentItem( pos ); 255 mActionSelectFilter->setCurrentItem( pos );
256 setActiveFilter( pos ); 256 setActiveFilter( pos );
257 } 257 }
258//US qDebug("ViewManager::setActiveView 6" ); 258//US qDebug("ViewManager::setActiveView 6" );
259 259
260 // Update the inc search widget to show the fields in the new active 260 // Update the inc search widget to show the fields in the new active
261 // view. 261 // view.
262 mCore->setSearchFields( mActiveView->fields() ); 262 mCore->setSearchFields( mActiveView->fields() );
263 263
264 mActiveView->refresh(); 264//US performance optimization. setActiveFilter calls also mActiveView->refresh()
265//US mActiveView->refresh();
265 266
266 } 267 }
267 else 268 else
268 { 269 {
269 qDebug("ViewManager::setActiveView: unable to find view" ); 270 qDebug("ViewManager::setActiveView: unable to find view" );
270 kdDebug(5720) << "ViewManager::setActiveView: unable to find view\n"; 271 kdDebug(5720) << "ViewManager::setActiveView: unable to find view\n";
271 } 272 }
272} 273}
273 274
274//US added another method with no parameter, since my moc compiler does not support default parameters. 275//US added another method with no parameter, since my moc compiler does not support default parameters.
275void ViewManager::refreshView() 276void ViewManager::refreshView()
276{ 277{
277 refreshView( QString::null ); 278 refreshView( QString::null );
278} 279}
279 280
280void ViewManager::refreshView( const QString &uid ) 281void ViewManager::refreshView( const QString &uid )
281{ 282{
282 if ( mActiveView ) 283 if ( mActiveView )
283 mActiveView->refresh( uid ); 284 mActiveView->refresh( uid );
284} 285}
285 286
286void ViewManager::editView() 287void ViewManager::editView()
287{ 288{
288 if ( !mActiveView ) 289 if ( !mActiveView )
289 return; 290 return;
290 291
291 ViewFactory *factory = mViewFactoryDict.find( mActiveView->type() ); 292 ViewFactory *factory = mViewFactoryDict.find( mActiveView->type() );
292 ViewConfigureWidget *wdg = 0; 293 ViewConfigureWidget *wdg = 0;
293 ViewConfigureDialog* dlg = 0; 294 ViewConfigureDialog* dlg = 0;
294 if ( factory ) { 295 if ( factory ) {
295 // Save the filters so the dialog has the latest set 296 // Save the filters so the dialog has the latest set
296 Filter::save( mCore->config(), "Filter", mFilterList ); 297 Filter::save( mCore->config(), "Filter", mFilterList );
297 dlg = new ViewConfigureDialog( 0, mActiveView->caption(), this, "conf_dlg" ); 298 dlg = new ViewConfigureDialog( 0, mActiveView->caption(), this, "conf_dlg" );
298 wdg = factory->configureWidget( mCore->addressBook(), dlg,"conf_wid" ); 299 wdg = factory->configureWidget( mCore->addressBook(), dlg,"conf_wid" );
299 } else { 300 } else {
300 qDebug("ViewManager::editView()::cannot find viewfactory "); 301 qDebug("ViewManager::editView()::cannot find viewfactory ");
301 return; 302 return;
302 } 303 }
303 if ( wdg ) { 304 if ( wdg ) {
304 dlg->setWidget( wdg ); 305 dlg->setWidget( wdg );
305 306
306#ifndef DESKTOP_VERSION 307#ifndef DESKTOP_VERSION
307 //dlg.setMaximumSize( 640, 480 ); 308 //dlg.setMaximumSize( 640, 480 );
308 //dlg->setGeometry( 40,40, 400, 300); 309 //dlg->setGeometry( 40,40, 400, 300);
309 dlg->showMaximized(); 310 dlg->showMaximized();
310#endif 311#endif
311 312
312 KConfigGroupSaver saver( mCore->config(), mActiveView->caption() ); 313 KConfigGroupSaver saver( mCore->config(), mActiveView->caption() );
313 314
314 dlg->restoreSettings( mCore->config() ); 315 dlg->restoreSettings( mCore->config() );
315 316
316 if ( dlg->exec() ) { 317 if ( dlg->exec() ) {
317 dlg->saveSettings( mCore->config() ); 318 dlg->saveSettings( mCore->config() );
318 mActiveView->readConfig( mCore->config() ); 319 mActiveView->readConfig( mCore->config() );
319 320
320 // Set the proper filter in the view. By setting the combo 321 // Set the proper filter in the view. By setting the combo
321 // box, the activated slot will be called, which will push 322 // box, the activated slot will be called, which will push
322 // the filter to the view and refresh it. 323 // the filter to the view and refresh it.
323 if ( mActiveView->defaultFilterType() == KAddressBookView::None ) { 324 if ( mActiveView->defaultFilterType() == KAddressBookView::None ) {
324 mActionSelectFilter->setCurrentItem( 0 ); 325 mActionSelectFilter->setCurrentItem( 0 );
325 setActiveFilter( 0 ); 326 setActiveFilter( 0 );
326 } else if ( mActiveView->defaultFilterType() == KAddressBookView::Active ) { 327 } else if ( mActiveView->defaultFilterType() == KAddressBookView::Active ) {
327 setActiveFilter( mActionSelectFilter->currentItem() ); 328 setActiveFilter( mActionSelectFilter->currentItem() );
328 } else { 329 } else {
329 uint pos = filterPosition( mActiveView->defaultFilterName() ); 330 uint pos = filterPosition( mActiveView->defaultFilterName() );
330 mActionSelectFilter->setCurrentItem( pos ); 331 mActionSelectFilter->setCurrentItem( pos );
331 setActiveFilter( pos ); 332 setActiveFilter( pos );
332 } 333 }
333 mCore->setSearchFields( mActiveView->fields() ); 334 mCore->setSearchFields( mActiveView->fields() );
334 mActiveView->refresh(); 335//US performance optimization. setActiveFilter calls also mActiveView->refresh()
336//US mActiveView->refresh();
335 } 337 }
336 338
337 } 339 }
338 delete dlg; 340 delete dlg;
339} 341}
340 342
341void ViewManager::deleteView() 343void ViewManager::deleteView()
342{ 344{
343 QString text = i18n( "<qt>Are you sure that you want to delete the view <b>%1</b>?</qt>" ) 345 QString text = i18n( "<qt>Are you sure that you want to delete the view <b>%1</b>?</qt>" )
344 .arg( mActiveView->caption() ); 346 .arg( mActiveView->caption() );
345 QString caption = i18n( "Confirm Delete" ); 347 QString caption = i18n( "Confirm Delete" );
346 348
347 349
348 if (QMessageBox::information( this, caption, 350 if (QMessageBox::information( this, caption,
349 text, 351 text,
350 i18n("Yes!"), i18n("No"), 0, 0 ) == 0) 352 i18n("Yes!"), i18n("No"), 0, 0 ) == 0)
351 { 353 {
352 mViewNameList.remove( mActiveView->caption() ); 354 mViewNameList.remove( mActiveView->caption() );
353 355
354 // remove the view from the config file 356 // remove the view from the config file
355 KConfig *config = mCore->config(); 357 KConfig *config = mCore->config();
356 config->deleteGroup( mActiveView->caption() ); 358 config->deleteGroup( mActiveView->caption() );
357 359
358 mViewDict.remove( mActiveView->caption() ); 360 mViewDict.remove( mActiveView->caption() );
359 mActiveView = 0; 361 mActiveView = 0;
360 362
361 // we are in an invalid state now, but that should be fixed after 363 // we are in an invalid state now, but that should be fixed after
362 // we emit the signal 364 // we emit the signal
363 mActionSelectView->setItems( mViewNameList ); 365 mActionSelectView->setItems( mViewNameList );
364 if ( mViewNameList.count() > 0 ) { 366 if ( mViewNameList.count() > 0 ) {
365 mActionSelectView->setCurrentItem( 0 ); 367 mActionSelectView->setCurrentItem( 0 );
366 setActiveView( mViewNameList[ 0 ] ); 368 setActiveView( mViewNameList[ 0 ] );
367 } 369 }
368 mActionDeleteView->setEnabled( mViewNameList.count() > 1 ); 370 mActionDeleteView->setEnabled( mViewNameList.count() > 1 );
369 } 371 }
370} 372}
371 373
372void ViewManager::addView() 374void ViewManager::addView()
373{ 375{
374 AddViewDialog dialog( &mViewFactoryDict, this ); 376 AddViewDialog dialog( &mViewFactoryDict, this );
375 377
376 if ( dialog.exec() ) { 378 if ( dialog.exec() ) {
377 QString newName = dialog.viewName(); 379 QString newName = dialog.viewName();
378 QString type = dialog.viewType(); 380 QString type = dialog.viewType();
379 381
380 // Check for name conflicts 382 // Check for name conflicts
381 bool firstConflict = true; 383 bool firstConflict = true;
382 int numTries = 1; 384 int numTries = 1;
383 while ( mViewNameList.contains( newName ) > 0 ) { 385 while ( mViewNameList.contains( newName ) > 0 ) {
384 if ( !firstConflict ) { 386 if ( !firstConflict ) {
385 newName = newName.left( newName.length() - 4 ); 387 newName = newName.left( newName.length() - 4 );
386 firstConflict = false; 388 firstConflict = false;
387 } 389 }
388 390
389 newName = QString( "%1 <%2>" ).arg( newName ).arg( numTries ); 391 newName = QString( "%1 <%2>" ).arg( newName ).arg( numTries );
390 numTries++; 392 numTries++;
391 } 393 }
392 394
393 // Add the new one to the list 395 // Add the new one to the list
394 mViewNameList.append( newName ); 396 mViewNameList.append( newName );
395 397
396 // write the view to the config file, 398 // write the view to the config file,
397 KConfig *config = mCore->config(); 399 KConfig *config = mCore->config();
398 400
399 config->deleteGroup( newName ); 401 config->deleteGroup( newName );
400 402
401 KConfigGroupSaver saver( config, newName ); 403 KConfigGroupSaver saver( config, newName );
402 404
403 config->writeEntry( "Type", type ); 405 config->writeEntry( "Type", type );
404 406
405 // try to set the active view 407 // try to set the active view
406 mActionSelectView->setItems( mViewNameList ); 408 mActionSelectView->setItems( mViewNameList );
407 mActionSelectView->setCurrentItem( mViewNameList.findIndex( newName ) ); 409 mActionSelectView->setCurrentItem( mViewNameList.findIndex( newName ) );
408 setActiveView( newName ); 410 setActiveView( newName );
409 411
410 editView(); 412 editView();
411 413
412 mActionDeleteView->setEnabled( mViewNameList.count() > 1 ); 414 mActionDeleteView->setEnabled( mViewNameList.count() > 1 );
413 } 415 }
414} 416}
415 417
416void ViewManager::createViewFactories() 418void ViewManager::createViewFactories()
417{ 419{
418#ifndef KAB_EMBEDDED 420#ifndef KAB_EMBEDDED
419 KTrader::OfferList plugins = KTrader::self()->query( "KAddressBook/View" ); 421 KTrader::OfferList plugins = KTrader::self()->query( "KAddressBook/View" );
420 KTrader::OfferList::ConstIterator it; 422 KTrader::OfferList::ConstIterator it;
421 for ( it = plugins.begin(); it != plugins.end(); ++it ) { 423 for ( it = plugins.begin(); it != plugins.end(); ++it ) {
422 if ( !(*it)->hasServiceType( "KAddressBook/View" ) ) 424 if ( !(*it)->hasServiceType( "KAddressBook/View" ) )
423 continue; 425 continue;
424 426
425 KLibFactory *factory = KLibLoader::self()->factory( (*it)->library().latin1() ); 427 KLibFactory *factory = KLibLoader::self()->factory( (*it)->library().latin1() );
426 428
427 if ( !factory ) { 429 if ( !factory ) {
428 kdDebug(5720) << "ViewManager::createViewFactories(): Factory creation failed" << endl; 430 kdDebug(5720) << "ViewManager::createViewFactories(): Factory creation failed" << endl;
429 continue; 431 continue;
430 } 432 }
431 433
432 ViewFactory *viewFactory = static_cast<ViewFactory*>( factory ); 434 ViewFactory *viewFactory = static_cast<ViewFactory*>( factory );
433 435
434 if ( !viewFactory ) { 436 if ( !viewFactory ) {
435 kdDebug(5720) << "ViewManager::createViewFactories(): Cast failed" << endl; 437 kdDebug(5720) << "ViewManager::createViewFactories(): Cast failed" << endl;
436 continue; 438 continue;
437 } 439 }
438 440
439 mViewFactoryDict.insert( viewFactory->type(), viewFactory ); 441 mViewFactoryDict.insert( viewFactory->type(), viewFactory );
440 } 442 }
441 443
442#else //KAB_EMBEDDED 444#else //KAB_EMBEDDED
443 ViewFactory* viewFactory = new IconViewFactory(); 445 ViewFactory* viewFactory = new IconViewFactory();
444 mViewFactoryDict.insert( viewFactory->type(), viewFactory ); 446 mViewFactoryDict.insert( viewFactory->type(), viewFactory );
445// qDebug("ViewManager::createViewFactories() Loading factory: %s", viewFactory->type().latin1()); 447// qDebug("ViewManager::createViewFactories() Loading factory: %s", viewFactory->type().latin1());
446 448
447 viewFactory = new TableViewFactory(); 449 viewFactory = new TableViewFactory();
448 mViewFactoryDict.insert( viewFactory->type(), viewFactory ); 450 mViewFactoryDict.insert( viewFactory->type(), viewFactory );
449// qDebug("ViewManager::createViewFactories() Loading factory: %s", viewFactory->type().latin1()); 451// qDebug("ViewManager::createViewFactories() Loading factory: %s", viewFactory->type().latin1());
450 452
451 viewFactory = new CardViewFactory(); 453 viewFactory = new CardViewFactory();
452 mViewFactoryDict.insert( viewFactory->type(), viewFactory ); 454 mViewFactoryDict.insert( viewFactory->type(), viewFactory );
453// qDebug("ViewManager::createViewFactories() Loading factory: %s", viewFactory->type().latin1()); 455// qDebug("ViewManager::createViewFactories() Loading factory: %s", viewFactory->type().latin1());
454 456
455#endif //KAB_EMBEDDED 457#endif //KAB_EMBEDDED
456 458
457} 459}
458 460
459void ViewManager::dropped( QDropEvent *e ) 461void ViewManager::dropped( QDropEvent *e )
460{ 462{
461 kdDebug(5720) << "ViewManager::dropped: got a drop event" << endl; 463 kdDebug(5720) << "ViewManager::dropped: got a drop event" << endl;
462 464
463#ifndef KAB_EMBEDDED 465#ifndef KAB_EMBEDDED
464 466
465 QString clipText, vcards; 467 QString clipText, vcards;
466 KURL::List urls; 468 KURL::List urls;
467 469
468 if ( KURLDrag::decode( e, urls) ) { 470 if ( KURLDrag::decode( e, urls) ) {
469 KURL::List::Iterator it = urls.begin(); 471 KURL::List::Iterator it = urls.begin();
470 int c = urls.count(); 472 int c = urls.count();
471 if ( c > 1 ) { 473 if ( c > 1 ) {
472 QString questionString = i18n( "Import one contact into your addressbook?", "Import %n contacts into your addressbook?", c ); 474 QString questionString = i18n( "Import one contact into your addressbook?", "Import %n contacts into your addressbook?", c );
473 if ( KMessageBox::questionYesNo( this, questionString, i18n( "Import Contacts?" ) ) == KMessageBox::Yes ) { 475 if ( KMessageBox::questionYesNo( this, questionString, i18n( "Import Contacts?" ) ) == KMessageBox::Yes ) {
474 for ( ; it != urls.end(); ++it ) 476 for ( ; it != urls.end(); ++it )
475 emit urlDropped( *it ); 477 emit urlDropped( *it );
476 } 478 }
477 } else if ( c == 1 ) 479 } else if ( c == 1 )
478 emit urlDropped( *it ); 480 emit urlDropped( *it );
479 } else if ( KVCardDrag::decode( e, vcards ) ) { 481 } else if ( KVCardDrag::decode( e, vcards ) ) {
480 KABC::Addressee addr; 482 KABC::Addressee addr;
481 KABC::VCardConverter converter; 483 KABC::VCardConverter converter;
482 QStringList list = QStringList::split( "\r\n\r\n", vcards ); 484 QStringList list = QStringList::split( "\r\n\r\n", vcards );
483 QStringList::Iterator it; 485 QStringList::Iterator it;
484 for ( it = list.begin(); it != list.end(); ++it ) { 486 for ( it = list.begin(); it != list.end(); ++it ) {
485 if ( converter.vCardToAddressee( (*it).stripWhiteSpace(), addr ) ) { 487 if ( converter.vCardToAddressee( (*it).stripWhiteSpace(), addr ) ) {
486 KABC::Addressee a = mCore->addressBook()->findByUid( addr.uid() ); 488 KABC::Addressee a = mCore->addressBook()->findByUid( addr.uid() );
487 if ( a.isEmpty() ) { 489 if ( a.isEmpty() ) {
488 mCore->addressBook()->insertAddressee( addr ); 490 mCore->addressBook()->insertAddressee( addr );
489 emit modified(); 491 emit modified();
490 } 492 }
491 } 493 }
492 } 494 }
493 495
494 mActiveView->refresh(); 496 mActiveView->refresh();
495 } 497 }
496#else //KAB_EMBEDDED 498#else //KAB_EMBEDDED
497qDebug("ViewManager::dropped() has to be changed!!" ); 499qDebug("ViewManager::dropped() has to be changed!!" );
498#endif //KAB_EMBEDDED 500#endif //KAB_EMBEDDED
499 501
500} 502}
501 503
502void ViewManager::startDrag() 504void ViewManager::startDrag()
503{ 505{
504 kdDebug(5720) << "ViewManager::startDrag: starting to drag" << endl; 506 kdDebug(5720) << "ViewManager::startDrag: starting to drag" << endl;
505 507
506#ifndef KAB_EMBEDDED 508#ifndef KAB_EMBEDDED
507 509
508 // Get the list of all the selected addressees 510 // Get the list of all the selected addressees
509 KABC::Addressee::List addrList; 511 KABC::Addressee::List addrList;
510 QStringList uidList = selectedUids(); 512 QStringList uidList = selectedUids();
511 QStringList::Iterator iter; 513 QStringList::Iterator iter;
512 for ( iter = uidList.begin(); iter != uidList.end(); ++iter ) 514 for ( iter = uidList.begin(); iter != uidList.end(); ++iter )
513 addrList.append( mCore->addressBook()->findByUid( *iter ) ); 515 addrList.append( mCore->addressBook()->findByUid( *iter ) );
514 516
515 KMultipleDrag *drag = new KMultipleDrag( this ); 517 KMultipleDrag *drag = new KMultipleDrag( this );
516 drag->addDragObject( new QTextDrag( AddresseeUtil::addresseesToClipboard(addrList), this ) ); 518 drag->addDragObject( new QTextDrag( AddresseeUtil::addresseesToClipboard(addrList), this ) );
517 KABC::Addressee::List::Iterator it; 519 KABC::Addressee::List::Iterator it;
518 QStringList vcards; 520 QStringList vcards;
519 for ( it = addrList.begin(); it != addrList.end(); ++it ) { 521 for ( it = addrList.begin(); it != addrList.end(); ++it ) {
520 QString vcard = QString::null; 522 QString vcard = QString::null;
521 KABC::VCardConverter converter; 523 KABC::VCardConverter converter;
522 if ( converter.addresseeToVCard( *it, vcard ) ) 524 if ( converter.addresseeToVCard( *it, vcard ) )
523 vcards.append( vcard ); 525 vcards.append( vcard );
524 } 526 }
525 drag->addDragObject( new KVCardDrag( vcards.join( "\r\n" ), this ) ); 527 drag->addDragObject( new KVCardDrag( vcards.join( "\r\n" ), this ) );
526 528
527 drag->setPixmap( KGlobal::iconLoader()->loadIcon( "vcard", KIcon::Desktop ) ); 529 drag->setPixmap( KGlobal::iconLoader()->loadIcon( "vcard", KIcon::Desktop ) );
528 drag->dragCopy(); 530 drag->dragCopy();
529 531
530#else //KAB_EMBEDDED 532#else //KAB_EMBEDDED
531qDebug("ViewManager::startDrag() has to be changed!!" ); 533qDebug("ViewManager::startDrag() has to be changed!!" );
@@ -562,124 +564,124 @@ void ViewManager::configureFilters()
562 564
563 uint pos = mActionSelectFilter->currentItem(); 565 uint pos = mActionSelectFilter->currentItem();
564 mActionSelectFilter->setItems( filterNames() ); 566 mActionSelectFilter->setItems( filterNames() );
565 mActionSelectFilter->setCurrentItem( pos ); 567 mActionSelectFilter->setCurrentItem( pos );
566 setActiveFilter( pos ); 568 setActiveFilter( pos );
567} 569}
568 570
569QStringList ViewManager::filterNames() const 571QStringList ViewManager::filterNames() const
570{ 572{
571 QStringList names( i18n( "No Filter" ) ); 573 QStringList names( i18n( "No Filter" ) );
572 574
573 Filter::List::ConstIterator it; 575 Filter::List::ConstIterator it;
574 for ( it = mFilterList.begin(); it != mFilterList.end(); ++it ) 576 for ( it = mFilterList.begin(); it != mFilterList.end(); ++it )
575 names.append( (*it).name() ); 577 names.append( (*it).name() );
576 578
577 return names; 579 return names;
578} 580}
579 581
580int ViewManager::filterPosition( const QString &name ) const 582int ViewManager::filterPosition( const QString &name ) const
581{ 583{
582 int pos = 0; 584 int pos = 0;
583 585
584 Filter::List::ConstIterator it; 586 Filter::List::ConstIterator it;
585 for ( it = mFilterList.begin(); it != mFilterList.end(); ++it, ++pos ) 587 for ( it = mFilterList.begin(); it != mFilterList.end(); ++it, ++pos )
586 if ( name == (*it).name() ) 588 if ( name == (*it).name() )
587 return pos + 1; 589 return pos + 1;
588 590
589 return 0; 591 return 0;
590} 592}
591 593
592void ViewManager::initActions() 594void ViewManager::initActions()
593{ 595{
594//US <ActionList name="view_loadedviews"/> 596//US <ActionList name="view_loadedviews"/>
595//US <Separator/> 597//US <Separator/>
596 598
597#ifdef KAB_EMBEDDED 599#ifdef KAB_EMBEDDED
598 QPopupMenu *viewmenu = (QPopupMenu*)mCore->getViewMenu(); 600 QPopupMenu *viewmenu = (QPopupMenu*)mCore->getViewMenu();
599 QPopupMenu *settingsmenu = (QPopupMenu*)mCore->getSettingsMenu(); 601 QPopupMenu *settingsmenu = (QPopupMenu*)mCore->getSettingsMenu();
600 QPopupMenu *filtermenu = (QPopupMenu*)mCore->getFilterMenu(); 602 QPopupMenu *filtermenu = (QPopupMenu*)mCore->getFilterMenu();
601#endif //KAB_EMBEDDED 603#endif //KAB_EMBEDDED
602 604
603 mActionSelectView = new KSelectAction( i18n( "Select View" ), 0, mCore->actionCollection(), "select_view" ); 605 mActionSelectView = new KSelectAction( i18n( "Select View" ), 0, mCore->actionCollection(), "select_view" );
604#if KDE_VERSION >= 309 606#if KDE_VERSION >= 309
605 mActionSelectView->setMenuAccelsEnabled( false ); 607 mActionSelectView->setMenuAccelsEnabled( false );
606#endif 608#endif
607 connect( mActionSelectView, SIGNAL( activated( const QString& ) ), 609 connect( mActionSelectView, SIGNAL( activated( const QString& ) ),
608 SLOT( setActiveView( const QString& ) ) ); 610 SLOT( setActiveView( const QString& ) ) );
609 611
610 612
611#ifdef KAB_EMBEDDED 613#ifdef KAB_EMBEDDED
612 mActionSelectView->plug(viewmenu); 614 mActionSelectView->plug(viewmenu);
613 viewmenu->insertSeparator(); 615 viewmenu->insertSeparator();
614#endif //KAB_EMBEDDED 616#endif //KAB_EMBEDDED
615 617
616 KAction *action; 618 KAction *action;
617 619
618 action = new KAction( i18n( "Modify View..." ), "configure", 0, this, 620 action = new KAction( i18n( "Modify View..." ), "configure", 0, this,
619 SLOT( editView() ), mCore->actionCollection(), "view_modify" ); 621 SLOT( editView() ), mCore->actionCollection(), "view_modify" );
620#ifndef KAB_EMBEDDED 622#ifndef KAB_EMBEDDED
621 action->setWhatsThis( i18n( "By pressing this button a dialog opens that allows you to modify the view of the addressbook. There you can add or remove fields that you want to be shown or hidden in the addressbook like the name for example." ) ); 623 action->setWhatsThis( i18n( "By pressing this button a dialog opens that allows you to modify the view of the addressbook. There you can add or remove fields that you want to be shown or hidden in the addressbook like the name for example." ) );
622#else //KAB_EMBEDDED 624#else //KAB_EMBEDDED
623 action->plug(viewmenu); 625 action->plug(viewmenu);
624#endif //KAB_EMBEDDED 626#endif //KAB_EMBEDDED
625 627
626 action = new KAction( i18n( "Add View..." ), "window_new", 0, this, 628 action = new KAction( i18n( "Add View..." ), "window_new", 0, this,
627 SLOT( addView() ), mCore->actionCollection(), "view_add" ); 629 SLOT( addView() ), mCore->actionCollection(), "view_add" );
628#ifndef KAB_EMBEDDED 630#ifndef KAB_EMBEDDED
629 action->setWhatsThis( i18n( "You can add a new view by choosing one of the dialog that appears after pressing the button. You have to give the view a name, so that you can distinguish between the different views." ) ); 631 action->setWhatsThis( i18n( "You can add a new view by choosing one of the dialog that appears after pressing the button. You have to give the view a name, so that you can distinguish between the different views." ) );
630#else //KAB_EMBEDDED 632#else //KAB_EMBEDDED
631 action->plug(viewmenu); 633 action->plug(viewmenu);
632#endif //KAB_EMBEDDED 634#endif //KAB_EMBEDDED
633 635
634 mActionDeleteView = new KAction( i18n( "Delete View" ), "view_remove", 0, 636 mActionDeleteView = new KAction( i18n( "Delete View" ), "view_remove", 0,
635 this, SLOT( deleteView() ), 637 this, SLOT( deleteView() ),
636 mCore->actionCollection(), "view_delete" ); 638 mCore->actionCollection(), "view_delete" );
637#ifndef KAB_EMBEDDED 639#ifndef KAB_EMBEDDED
638 mActionDeleteView->setWhatsThis( i18n( "By pressing this button you can delete the actual view, which you have added before." ) ); 640 mActionDeleteView->setWhatsThis( i18n( "By pressing this button you can delete the actual view, which you have added before." ) );
639#else //KAB_EMBEDDED 641#else //KAB_EMBEDDED
640 mActionDeleteView->plug(viewmenu); 642 mActionDeleteView->plug(viewmenu);
641 viewmenu->insertSeparator(); 643 viewmenu->insertSeparator();
642#endif //KAB_EMBEDDED 644#endif //KAB_EMBEDDED
643 645
644#ifndef KAB_EMBEDDED 646#ifndef KAB_EMBEDDED
645 action = new KAction( i18n( "Refresh View" ), "reload", 0, this, 647 action = new KAction( i18n( "Refresh View" ), "reload", 0, this,
646 SLOT( refreshView(const QString &) ), mCore->actionCollection(), 648 SLOT( refreshView(const QString &) ), mCore->actionCollection(),
647 "view_refresh" ); 649 "view_refresh" );
648 action->setWhatsThis( i18n( "The view will be refreshed by pressing this button." ) ); 650 action->setWhatsThis( i18n( "The view will be refreshed by pressing this button." ) );
649#else //KAB_EMBEDDED 651#else //KAB_EMBEDDED
650 action = new KAction( i18n( "Refresh View" ), "reload", 0, this, 652 action = new KAction( i18n( "Refresh View" ), "reload", 0, this,
651 SLOT( refreshView()), mCore->actionCollection(), 653 SLOT( refreshView()), mCore->actionCollection(),
652 "view_refresh" ); 654 "view_refresh" );
653 action->plug(viewmenu); 655 action->plug(viewmenu);
654 viewmenu->insertSeparator(); 656 viewmenu->insertSeparator();
655#endif //KAB_EMBEDDED 657#endif //KAB_EMBEDDED
656 658
657 action = new KAction( i18n( "Edit &Filters..." ), "filter", 0, this, 659 action = new KAction( i18n( "Edit &Filters..." ), "filter", 0, this,
658 SLOT( configureFilters() ), mCore->actionCollection(), 660 SLOT( configureFilters() ), mCore->actionCollection(),
659 "options_edit_filters" ); 661 "options_edit_filters" );
660 662
661 mActionSelectFilter = new KSelectAction( i18n( "Select Filter" ), "filter", mCore->actionCollection(), "select_filter" ); 663 mActionSelectFilter = new KSelectAction( i18n( "Select Filter" ), "filter", mCore->actionCollection(), "select_filter" );
662 664
663#if KDE_VERSION >= 309 665#if KDE_VERSION >= 309
664 mActionSelectFilter->setMenuAccelsEnabled( false ); 666 mActionSelectFilter->setMenuAccelsEnabled( false );
665#endif 667#endif
666 connect( mActionSelectFilter, SIGNAL( activated( int ) ), 668 connect( mActionSelectFilter, SIGNAL( activated( int ) ),
667 SLOT( setActiveFilter( int ) ) ); 669 SLOT( setActiveFilter( int ) ) );
668 670
669#ifdef KAB_EMBEDDED 671#ifdef KAB_EMBEDDED
670 action->plug(settingsmenu); 672 action->plug(settingsmenu);
671 mActionSelectFilter->plug(viewmenu); 673 mActionSelectFilter->plug(viewmenu);
672#endif //KAB_EMBEDDED 674#endif //KAB_EMBEDDED
673 675
674} 676}
675 677
676void ViewManager::initGUI() 678void ViewManager::initGUI()
677{ 679{
678 QHBoxLayout *layout = new QHBoxLayout( this, 0, 0 ); 680 QHBoxLayout *layout = new QHBoxLayout( this, 0, 0 );
679 mViewWidgetStack = new QWidgetStack( this ); 681 mViewWidgetStack = new QWidgetStack( this );
680 layout->addWidget( mViewWidgetStack ); 682 layout->addWidget( mViewWidgetStack );
681} 683}
682 684
683#ifndef KAB_EMBEDDED 685#ifndef KAB_EMBEDDED
684#include "viewmanager.moc" 686#include "viewmanager.moc"
685#endif //KAB_EMBEDDED 687#endif //KAB_EMBEDDED
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
@@ -52,286 +52,287 @@ KAddressBookTableView::~KAddressBookTableView()
52} 52}
53 53
54void KAddressBookTableView::reconstructListView() 54void 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
114void KAddressBookTableView::writeConfig(KConfig *config) 115void 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
121void KAddressBookTableView::readConfig(KConfig *config) 122void 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
142void KAddressBookTableView::refresh(QString uid) 143void 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
211QStringList KAddressBookTableView::selectedUids() 212QStringList 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
240void KAddressBookTableView::setSelected(QString uid, bool selected) 241void 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
271void KAddressBookTableView::addresseeSelected() 272void 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
301void KAddressBookTableView::addresseeExecuted(QListViewItem *item) 302void 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
324void KAddressBookTableView::addresseeDeleted() 325void 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