summaryrefslogtreecommitdiffabout
path: root/kaddressbook/viewmanager.cpp
Unidiff
Diffstat (limited to 'kaddressbook/viewmanager.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--kaddressbook/viewmanager.cpp5
1 files changed, 5 insertions, 0 deletions
diff --git a/kaddressbook/viewmanager.cpp b/kaddressbook/viewmanager.cpp
index bec1862..45c7b55 100644
--- a/kaddressbook/viewmanager.cpp
+++ b/kaddressbook/viewmanager.cpp
@@ -241,192 +241,197 @@ void ViewManager::setActiveView( const QString &name )
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//US performance optimization. setActiveFilter calls also mActiveView->refresh() 264//US performance optimization. setActiveFilter calls also mActiveView->refresh()
265//US mActiveView->refresh(); 265//US mActiveView->refresh();
266 266
267 } 267 }
268 else 268 else
269 { 269 {
270 qDebug("ViewManager::setActiveView: unable to find view" ); 270 qDebug("ViewManager::setActiveView: unable to find view" );
271 kdDebug(5720) << "ViewManager::setActiveView: unable to find view\n"; 271 kdDebug(5720) << "ViewManager::setActiveView: unable to find view\n";
272 } 272 }
273} 273}
274 274
275//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.
276void ViewManager::refreshView() 276void ViewManager::refreshView()
277{ 277{
278 refreshView( QString::null ); 278 refreshView( QString::null );
279} 279}
280 280
281void ViewManager::refreshView( const QString &uid ) 281void ViewManager::refreshView( const QString &uid )
282{ 282{
283 if ( mActiveView ) 283 if ( mActiveView )
284 mActiveView->refresh( uid ); 284 mActiveView->refresh( uid );
285} 285}
286 286
287void ViewManager::editView() 287void ViewManager::editView()
288{ 288{
289 if ( !mActiveView ) 289 if ( !mActiveView )
290 return; 290 return;
291 291
292 ViewFactory *factory = mViewFactoryDict.find( mActiveView->type() ); 292 ViewFactory *factory = mViewFactoryDict.find( mActiveView->type() );
293 ViewConfigureWidget *wdg = 0; 293 ViewConfigureWidget *wdg = 0;
294 ViewConfigureDialog* dlg = 0; 294 ViewConfigureDialog* dlg = 0;
295 if ( factory ) { 295 if ( factory ) {
296 // Save the filters so the dialog has the latest set 296 // Save the filters so the dialog has the latest set
297 Filter::save( mCore->config(), "Filter", mFilterList ); 297 Filter::save( mCore->config(), "Filter", mFilterList );
298 dlg = new ViewConfigureDialog( 0, mActiveView->caption(), this, "conf_dlg" ); 298 dlg = new ViewConfigureDialog( 0, mActiveView->caption(), this, "conf_dlg" );
299 wdg = factory->configureWidget( mCore->addressBook(), dlg,"conf_wid" ); 299 wdg = factory->configureWidget( mCore->addressBook(), dlg,"conf_wid" );
300 } else { 300 } else {
301 qDebug("ViewManager::editView()::cannot find viewfactory "); 301 qDebug("ViewManager::editView()::cannot find viewfactory ");
302 return; 302 return;
303 } 303 }
304 if ( wdg ) { 304 if ( wdg ) {
305 dlg->setWidget( wdg ); 305 dlg->setWidget( wdg );
306 306
307#ifndef DESKTOP_VERSION 307#ifndef DESKTOP_VERSION
308 //dlg.setMaximumSize( 640, 480 ); 308 //dlg.setMaximumSize( 640, 480 );
309 //dlg->setGeometry( 40,40, 400, 300); 309 //dlg->setGeometry( 40,40, 400, 300);
310 dlg->showMaximized(); 310 dlg->showMaximized();
311#endif 311#endif
312 312
313 KConfigGroupSaver saver( mCore->config(), mActiveView->caption() ); 313 KConfigGroupSaver saver( mCore->config(), mActiveView->caption() );
314 314
315 dlg->restoreSettings( mCore->config() ); 315 dlg->restoreSettings( mCore->config() );
316 316
317 if ( dlg->exec() ) { 317 if ( dlg->exec() ) {
318 dlg->saveSettings( mCore->config() ); 318 dlg->saveSettings( mCore->config() );
319 mActiveView->readConfig( mCore->config() ); 319 mActiveView->readConfig( mCore->config() );
320 320
321 // Set the proper filter in the view. By setting the combo 321 // Set the proper filter in the view. By setting the combo
322 // box, the activated slot will be called, which will push 322 // box, the activated slot will be called, which will push
323 // the filter to the view and refresh it. 323 // the filter to the view and refresh it.
324 if ( mActiveView->defaultFilterType() == KAddressBookView::None ) { 324 if ( mActiveView->defaultFilterType() == KAddressBookView::None ) {
325 mActionSelectFilter->setCurrentItem( 0 ); 325 mActionSelectFilter->setCurrentItem( 0 );
326 setActiveFilter( 0 ); 326 setActiveFilter( 0 );
327 } else if ( mActiveView->defaultFilterType() == KAddressBookView::Active ) { 327 } else if ( mActiveView->defaultFilterType() == KAddressBookView::Active ) {
328 setActiveFilter( mActionSelectFilter->currentItem() ); 328 setActiveFilter( mActionSelectFilter->currentItem() );
329 } else { 329 } else {
330 uint pos = filterPosition( mActiveView->defaultFilterName() ); 330 uint pos = filterPosition( mActiveView->defaultFilterName() );
331 mActionSelectFilter->setCurrentItem( pos ); 331 mActionSelectFilter->setCurrentItem( pos );
332 setActiveFilter( pos ); 332 setActiveFilter( pos );
333 } 333 }
334 mCore->setSearchFields( mActiveView->fields() ); 334 mCore->setSearchFields( mActiveView->fields() );
335//US performance optimization. setActiveFilter calls also mActiveView->refresh() 335//US performance optimization. setActiveFilter calls also mActiveView->refresh()
336//US mActiveView->refresh(); 336//US mActiveView->refresh();
337
338
339 //US this is a bugfix, that we get notified if we change a views configuration
340 emit modified();
341
337 } 342 }
338 343
339 } 344 }
340 delete dlg; 345 delete dlg;
341} 346}
342 347
343void ViewManager::deleteView() 348void ViewManager::deleteView()
344{ 349{
345 QString text = i18n( "<qt>Are you sure that you want to delete the view <b>%1</b>?</qt>" ) 350 QString text = i18n( "<qt>Are you sure that you want to delete the view <b>%1</b>?</qt>" )
346 .arg( mActiveView->caption() ); 351 .arg( mActiveView->caption() );
347 QString caption = i18n( "Confirm Delete" ); 352 QString caption = i18n( "Confirm Delete" );
348 353
349 354
350 if (QMessageBox::information( this, caption, 355 if (QMessageBox::information( this, caption,
351 text, 356 text,
352 i18n("Yes!"), i18n("No"), 0, 0 ) == 0) 357 i18n("Yes!"), i18n("No"), 0, 0 ) == 0)
353 { 358 {
354 mViewNameList.remove( mActiveView->caption() ); 359 mViewNameList.remove( mActiveView->caption() );
355 360
356 // remove the view from the config file 361 // remove the view from the config file
357 KConfig *config = mCore->config(); 362 KConfig *config = mCore->config();
358 config->deleteGroup( mActiveView->caption() ); 363 config->deleteGroup( mActiveView->caption() );
359 364
360 mViewDict.remove( mActiveView->caption() ); 365 mViewDict.remove( mActiveView->caption() );
361 mActiveView = 0; 366 mActiveView = 0;
362 367
363 // we are in an invalid state now, but that should be fixed after 368 // we are in an invalid state now, but that should be fixed after
364 // we emit the signal 369 // we emit the signal
365 mActionSelectView->setItems( mViewNameList ); 370 mActionSelectView->setItems( mViewNameList );
366 if ( mViewNameList.count() > 0 ) { 371 if ( mViewNameList.count() > 0 ) {
367 mActionSelectView->setCurrentItem( 0 ); 372 mActionSelectView->setCurrentItem( 0 );
368 setActiveView( mViewNameList[ 0 ] ); 373 setActiveView( mViewNameList[ 0 ] );
369 } 374 }
370 mActionDeleteView->setEnabled( mViewNameList.count() > 1 ); 375 mActionDeleteView->setEnabled( mViewNameList.count() > 1 );
371 } 376 }
372} 377}
373 378
374void ViewManager::addView() 379void ViewManager::addView()
375{ 380{
376 AddViewDialog dialog( &mViewFactoryDict, this ); 381 AddViewDialog dialog( &mViewFactoryDict, this );
377 382
378 if ( dialog.exec() ) { 383 if ( dialog.exec() ) {
379 QString newName = dialog.viewName(); 384 QString newName = dialog.viewName();
380 QString type = dialog.viewType(); 385 QString type = dialog.viewType();
381 386
382 // Check for name conflicts 387 // Check for name conflicts
383 bool firstConflict = true; 388 bool firstConflict = true;
384 int numTries = 1; 389 int numTries = 1;
385 while ( mViewNameList.contains( newName ) > 0 ) { 390 while ( mViewNameList.contains( newName ) > 0 ) {
386 if ( !firstConflict ) { 391 if ( !firstConflict ) {
387 newName = newName.left( newName.length() - 4 ); 392 newName = newName.left( newName.length() - 4 );
388 firstConflict = false; 393 firstConflict = false;
389 } 394 }
390 395
391 newName = QString( "%1 <%2>" ).arg( newName ).arg( numTries ); 396 newName = QString( "%1 <%2>" ).arg( newName ).arg( numTries );
392 numTries++; 397 numTries++;
393 } 398 }
394 399
395 // Add the new one to the list 400 // Add the new one to the list
396 mViewNameList.append( newName ); 401 mViewNameList.append( newName );
397 402
398 // write the view to the config file, 403 // write the view to the config file,
399 KConfig *config = mCore->config(); 404 KConfig *config = mCore->config();
400 405
401 config->deleteGroup( newName ); 406 config->deleteGroup( newName );
402 407
403 KConfigGroupSaver saver( config, newName ); 408 KConfigGroupSaver saver( config, newName );
404 409
405 config->writeEntry( "Type", type ); 410 config->writeEntry( "Type", type );
406 411
407 // try to set the active view 412 // try to set the active view
408 mActionSelectView->setItems( mViewNameList ); 413 mActionSelectView->setItems( mViewNameList );
409 mActionSelectView->setCurrentItem( mViewNameList.findIndex( newName ) ); 414 mActionSelectView->setCurrentItem( mViewNameList.findIndex( newName ) );
410 setActiveView( newName ); 415 setActiveView( newName );
411 416
412 editView(); 417 editView();
413 418
414 mActionDeleteView->setEnabled( mViewNameList.count() > 1 ); 419 mActionDeleteView->setEnabled( mViewNameList.count() > 1 );
415 } 420 }
416} 421}
417 422
418void ViewManager::createViewFactories() 423void ViewManager::createViewFactories()
419{ 424{
420#ifndef KAB_EMBEDDED 425#ifndef KAB_EMBEDDED
421 KTrader::OfferList plugins = KTrader::self()->query( "KAddressBook/View" ); 426 KTrader::OfferList plugins = KTrader::self()->query( "KAddressBook/View" );
422 KTrader::OfferList::ConstIterator it; 427 KTrader::OfferList::ConstIterator it;
423 for ( it = plugins.begin(); it != plugins.end(); ++it ) { 428 for ( it = plugins.begin(); it != plugins.end(); ++it ) {
424 if ( !(*it)->hasServiceType( "KAddressBook/View" ) ) 429 if ( !(*it)->hasServiceType( "KAddressBook/View" ) )
425 continue; 430 continue;
426 431
427 KLibFactory *factory = KLibLoader::self()->factory( (*it)->library().latin1() ); 432 KLibFactory *factory = KLibLoader::self()->factory( (*it)->library().latin1() );
428 433
429 if ( !factory ) { 434 if ( !factory ) {
430 kdDebug(5720) << "ViewManager::createViewFactories(): Factory creation failed" << endl; 435 kdDebug(5720) << "ViewManager::createViewFactories(): Factory creation failed" << endl;
431 continue; 436 continue;
432 } 437 }