~ubuntu-branches/ubuntu/oneiric/kdepim/oneiric-updates

« back to all changes in this revision

Viewing changes to kaddressbook/mainwidget.cpp

  • Committer: Package Import Robot
  • Author(s): Philip Muškovac
  • Date: 2011-06-28 19:33:24 UTC
  • mfrom: (0.2.13) (0.1.13 sid)
  • Revision ID: package-import@ubuntu.com-20110628193324-8yvjs8sdv9rdoo6c
Tags: 4:4.7.0-0ubuntu1
* New upstream release
  - update install files
  - add missing kdepim-doc package to control file
  - Fix Vcs lines
  - kontact breaks/replaces korganizer << 4:4.6.80
  - tighten the dependency of kdepim-dev on libkdepim4 to fix lintian error

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
*/
20
20
 
21
21
#include "mainwidget.h"
22
 
#include <QPrinter>
23
 
#include <QPrintDialog>
24
 
 
25
 
#include <QtGui/QAction>
26
 
#include <QtGui/QHBoxLayout>
27
 
#include <QtGui/QHeaderView>
28
 
#include <QtGui/QListView>
29
 
#include <QtGui/QSortFilterProxyModel>
30
 
#include <QtGui/QSplitter>
31
 
#include <QtGui/QStackedWidget>
32
 
#include <QtGui/QTextBrowser>
33
 
 
 
22
 
 
23
#include "contactswitcher.h"
 
24
#include "globalcontactmodel.h"
 
25
#include <kdescendantsproxymodel.h>
 
26
#include "modelcolumnmanager.h"
 
27
#include "printing/printingwizard.h"
 
28
#include "quicksearchwidget.h"
 
29
#include "settings.h"
 
30
#include "xxportmanager.h"
 
31
 
 
32
#ifdef GRANTLEE_FOUND
 
33
#include "grantleecontactformatter.h"
 
34
#include "grantleecontactgroupformatter.h"
 
35
#endif
 
36
 
 
37
#include <akonadi/etmviewstatesaver.h>
34
38
#include <akonadi/collectionfilterproxymodel.h>
35
39
#include <akonadi/collectionmodel.h>
36
40
#include <akonadi/contact/contactdefaultactions.h>
37
41
#include <akonadi/contact/contacteditordialog.h>
38
42
#include <akonadi/contact/contactgroupeditordialog.h>
39
43
#include <akonadi/contact/contactgroupviewer.h>
 
44
#include <akonadi/contact/contactsfilterproxymodel.h>
 
45
#include <akonadi/contact/contactstreemodel.h>
40
46
#include <akonadi/contact/contactviewer.h>
 
47
#include <akonadi/contact/standardcontactactionmanager.h>
41
48
#include <akonadi/control.h>
42
49
#include <akonadi/entitymimetypefiltermodel.h>
43
50
#include <akonadi/entitytreeview.h>
49
56
#include <kactioncollection.h>
50
57
#include <kabc/addressee.h>
51
58
#include <kabc/contactgroup.h>
52
 
#include "kdescendantsproxymodel_p.h"
 
59
#include <kapplication.h>
 
60
#include <kcheckableproxymodel.h>
53
61
#include <kicon.h>
54
62
#include <klineedit.h>
55
63
#include <klocale.h>
56
64
#include <kselectionproxymodel.h>
 
65
#include <kstandarddirs.h>
 
66
#include <ktextbrowser.h>
57
67
#include <ktoggleaction.h>
58
68
#include <ktoolbar.h>
59
69
#include <kxmlguiwindow.h>
60
 
#include <libkdepim/contactstreemodel.h>
61
 
#include <libkdepim/contactsfilterproxymodel.h>
62
70
#include <libkdepim/uistatesaver.h>
63
71
 
64
 
#include "contactswitcher.h"
65
 
#include "globalcontactmodel.h"
66
 
#include "modelcolumnmanager.h"
67
 
#include "quicksearchwidget.h"
68
 
#include "settings.h"
69
 
#include "standardcontactactionmanager.h"
70
 
#include "xxportmanager.h"
71
 
 
72
 
#include "printing/printingwizard.h"
 
72
#include <QtGui/QAction>
 
73
#include <QtGui/QHBoxLayout>
 
74
#include <QtGui/QHeaderView>
 
75
#include <QtGui/QListView>
 
76
#include <QtGui/QPrinter>
 
77
#include <QtGui/QPrintDialog>
 
78
#include <QtGui/QSortFilterProxyModel>
 
79
#include <QtGui/QSplitter>
 
80
#include <QtGui/QStackedWidget>
 
81
 
 
82
 
 
83
 
 
84
namespace {
 
85
static bool isStructuralCollection( const Akonadi::Collection &collection )
 
86
{
 
87
  QStringList mimeTypes;
 
88
  mimeTypes << KABC::Addressee::mimeType() << KABC::ContactGroup::mimeType();
 
89
  const QStringList collectionMimeTypes = collection.contentMimeTypes();
 
90
  foreach ( const QString &mimeType, mimeTypes ) {
 
91
    if ( collectionMimeTypes.contains( mimeType ) )
 
92
      return false;
 
93
  }
 
94
  return true;
 
95
}
 
96
 
 
97
class StructuralCollectionsNotCheckableProxy : public KCheckableProxyModel {
 
98
public:
 
99
  StructuralCollectionsNotCheckableProxy(QObject* parent)
 
100
      : KCheckableProxyModel(parent)
 
101
  { }
 
102
 
 
103
  /* reimp */ QVariant data( const QModelIndex &index, int role ) const
 
104
  {
 
105
    if ( !index.isValid() )
 
106
      return QVariant();
 
107
 
 
108
    if ( role == Qt::CheckStateRole ) {
 
109
      // Don't show the checkbox if the collection can't contain incidences
 
110
      const Akonadi::Collection collection = index.data( Akonadi::EntityTreeModel::CollectionRole ).value<Akonadi::Collection>();
 
111
      if ( collection.isValid() && isStructuralCollection( collection ) ) {
 
112
        return QVariant();
 
113
      }
 
114
    }
 
115
    return KCheckableProxyModel::data( index, role );
 
116
  }
 
117
};
 
118
 
 
119
}
73
120
 
74
121
MainWidget::MainWidget( KXMLGUIClient *guiClient, QWidget *parent )
75
 
  : QWidget( parent ), mAllContactsModel( 0 )
 
122
  : QWidget( parent ), mAllContactsModel( 0 ), mXmlGuiClient( guiClient )
76
123
{
77
124
  mXXPortManager = new XXPortManager( this );
78
125
 
94
141
   *                                   |           mAllContactsModel
95
142
   *                                   |                  ^
96
143
   *                                   |                  |
97
 
   *      mCollectionView  ->  selectionProxyModel  descendantsModel
98
 
   *            ^                      ^                  ^
 
144
   *      mCollectionView     selectionProxyModel  descendantsModel
 
145
   *            ^               ^      ^                  ^
 
146
   *            |               |      |                  |
 
147
   *            |       selectionModel |                  |
 
148
   *            |               |      |                  |
 
149
   *        proxyModel ---------'      |                  |
 
150
   *            ^                      |                  |
99
151
   *            |                      |                  |
100
152
   *      mCollectionTree              |                  |
101
153
   *            ^                      |                  |
106
158
   *
107
159
   *  GlobalContactModel::instance():  The global contact model (contains collections and items)
108
160
   *                 mCollectionTree:  Filters out all items
 
161
   *                      proxyModel:  Allows the user to select collections by checkboxes
 
162
   *                  selectionModel:  Represents the selected collections that have been selected in
 
163
   *                                   proxyModel
109
164
   *                 mCollectionView:  Shows the collections (address books) in a view
110
165
   *             selectionProxyModel:  Filters out all collections and items that are no children
111
 
   *                                   of the collection currently selected in mCollectionView
 
166
   *                                   of the collections currently selected in selectionModel
112
167
   *                       mItemTree:  Filters out all collections
113
168
   *            mContactsFilterModel:  Filters the contacts by the content of mQuickSearchWidget
114
169
   *                       mItemView:  Shows the items (contacts and contact groups) in a view
118
173
   */
119
174
 
120
175
  mCollectionTree = new Akonadi::EntityMimeTypeFilterModel( this );
 
176
  mCollectionTree->setDynamicSortFilter( true );
 
177
  mCollectionTree->setSortCaseSensitivity( Qt::CaseInsensitive );
121
178
  mCollectionTree->setSourceModel( GlobalContactModel::instance()->model() );
122
179
  mCollectionTree->addMimeTypeInclusionFilter( Akonadi::Collection::mimeType() );
123
180
  mCollectionTree->setHeaderGroup( Akonadi::EntityTreeModel::CollectionTreeHeaders );
124
181
 
125
 
  mXXPortManager->setItemModel( allContactsModel() );
 
182
  mCollectionSelectionModel = new QItemSelectionModel( mCollectionTree );
 
183
  StructuralCollectionsNotCheckableProxy *checkableProxyModel = new StructuralCollectionsNotCheckableProxy( this );
 
184
  checkableProxyModel->setSelectionModel( mCollectionSelectionModel );
 
185
  checkableProxyModel->setSourceModel( mCollectionTree );
126
186
 
127
 
  mCollectionView->setModel( mCollectionTree );
 
187
  mCollectionView->setModel( checkableProxyModel );
128
188
  mCollectionView->setXmlGuiClient( guiClient );
129
189
  mCollectionView->header()->setDefaultAlignment( Qt::AlignCenter );
130
190
  mCollectionView->header()->setSortIndicatorShown( false );
132
192
  connect( mCollectionView, SIGNAL( currentChanged( const Akonadi::Collection& ) ),
133
193
           mXXPortManager, SLOT( setDefaultAddressBook( const Akonadi::Collection& ) ) );
134
194
 
135
 
  KSelectionProxyModel *selectionProxyModel = new KSelectionProxyModel( mCollectionView->selectionModel(),
136
 
                                                                                        this );
 
195
  KSelectionProxyModel *selectionProxyModel = new KSelectionProxyModel( mCollectionSelectionModel,
 
196
                                                                        this );
137
197
  selectionProxyModel->setSourceModel( GlobalContactModel::instance()->model() );
138
198
  selectionProxyModel->setFilterBehavior( KSelectionProxyModel::ChildrenOfExactSelection );
139
199
 
142
202
  mItemTree->addMimeTypeExclusionFilter( Akonadi::Collection::mimeType() );
143
203
  mItemTree->setHeaderGroup( Akonadi::EntityTreeModel::ItemListHeaders );
144
204
 
145
 
  mContactsFilterModel = new AkonadiFuture::ContactsFilterModel( this );
 
205
  mContactsFilterModel = new Akonadi::ContactsFilterProxyModel( this );
146
206
  mContactsFilterModel->setSourceModel( mItemTree );
147
207
  connect( mQuickSearchWidget, SIGNAL( filterStringChanged( const QString& ) ),
148
208
           mContactsFilterModel, SLOT( setFilterString( const QString& ) ) );
159
219
 
160
220
  mXXPortManager->setSelectionModel( mItemView->selectionModel() );
161
221
 
 
222
  mActionManager = new Akonadi::StandardContactActionManager( guiClient->actionCollection(), this );
 
223
  mActionManager->setCollectionSelectionModel( mCollectionView->selectionModel() );
 
224
  mActionManager->setItemSelectionModel( mItemView->selectionModel() );
 
225
  mActionManager->createAllActions();
 
226
 
162
227
  connect( mItemView, SIGNAL( currentChanged( const Akonadi::Item& ) ),
163
228
           this, SLOT( itemSelected( const Akonadi::Item& ) ) );
164
229
  connect( mItemView, SIGNAL( doubleClicked( const Akonadi::Item& ) ),
165
 
           this, SLOT( editItem( const Akonadi::Item& ) ) );
 
230
           mActionManager->action( Akonadi::StandardContactActionManager::EditItem ), SLOT( trigger() ) );
166
231
  connect( mItemView->selectionModel(), SIGNAL( currentChanged( const QModelIndex&, const QModelIndex& ) ),
167
232
           this, SLOT( itemSelectionChanged( const QModelIndex&, const QModelIndex& ) ) );
168
233
 
173
238
 
174
239
  Akonadi::Control::widgetNeedsAkonadi( this );
175
240
 
176
 
  mActionManager = new AkonadiFuture::StandardContactActionManager( guiClient->actionCollection(), this );
177
 
  mActionManager->setCollectionSelectionModel( mCollectionView->selectionModel() );
178
 
  mActionManager->setItemSelectionModel( mItemView->selectionModel() );
179
 
 
180
 
  mActionManager->createAllActions();
181
 
 
182
 
  connect( mActionManager->action( AkonadiFuture::StandardContactActionManager::CreateContact ), SIGNAL( triggered( bool ) ),
183
 
           this, SLOT( newContact() ) );
184
 
  connect( mActionManager->action( AkonadiFuture::StandardContactActionManager::CreateContactGroup ), SIGNAL( triggered( bool ) ),
185
 
           this, SLOT( newGroup() ) );
186
 
  connect( mActionManager, SIGNAL( editItem( const Akonadi::Item& ) ),
187
 
           this, SLOT( editItem( const Akonadi::Item& ) ) );
188
 
 
189
241
  mModelColumnManager = new ModelColumnManager( GlobalContactModel::instance()->model(), this );
190
242
  mModelColumnManager->setWidget( mItemView->header() );
191
243
  mModelColumnManager->load();
192
244
 
 
245
  QMetaObject::invokeMethod( this, "delayedInit", Qt::QueuedConnection );
 
246
}
 
247
 
 
248
void MainWidget::delayedInit()
 
249
{
193
250
  // restore previous state
194
251
  {
195
252
    const KConfigGroup group( Settings::self()->config(), "UiState_MainWidgetSplitter" );
199
256
    const KConfigGroup group( Settings::self()->config(), "UiState_ContactView" );
200
257
    KPIM::UiStateSaver::restoreState( mItemView, group );
201
258
  }
202
 
  {
203
 
    const KConfigGroup group( Settings::self()->config(), "CollectionViewState" );
204
 
    Akonadi::EntityTreeViewStateSaver *restorer = new Akonadi::EntityTreeViewStateSaver( mCollectionView );
205
 
    restorer->restoreState( group );
206
 
  }
207
 
  {
208
 
    const KConfigGroup group( Settings::self()->config(), "ItemViewState" );
209
 
    Akonadi::EntityTreeViewStateSaver *restorer = new Akonadi::EntityTreeViewStateSaver( mItemView );
210
 
    restorer->restoreState( group );
211
 
  }
212
 
 
213
 
  guiClient->actionCollection()->action( "options_show_simplegui" )->setChecked( Settings::self()->useSimpleMode() );
 
259
 
 
260
  mXmlGuiClient->actionCollection()->action( "options_show_simplegui" )->setChecked( Settings::self()->useSimpleMode() );
 
261
 
 
262
  connect( GlobalContactModel::instance()->model(), SIGNAL( modelAboutToBeReset() ), SLOT( saveState() ) );
 
263
  connect( GlobalContactModel::instance()->model(), SIGNAL( modelReset() ), SLOT( restoreState() ) );
 
264
  connect( kapp, SIGNAL( aboutToQuit() ), SLOT( saveState() ) );
 
265
 
 
266
  restoreState();
214
267
}
215
268
 
216
269
MainWidget::~MainWidget()
218
271
  mModelColumnManager->store();
219
272
 
220
273
  {
221
 
    KConfigGroup group( Settings::self()->config(), "CollectionViewState" );
222
 
    Akonadi::EntityTreeViewStateSaver saver( mCollectionView );
223
 
    saver.saveState( group );
224
 
    group.sync();
225
 
  }
226
 
  {
227
 
    KConfigGroup group( Settings::self()->config(), "ItemViewState" );
228
 
    Akonadi::EntityTreeViewStateSaver saver( mItemView );
229
 
    saver.saveState( group );
230
 
    group.sync();
231
 
  }
232
 
  {
233
274
    if ( !Settings::self()->useSimpleMode() ) {
234
275
      // Do not save the splitter values when in simple mode, because we can't
235
276
      // restore them correctly when switching back to normal mode
243
284
    KPIM::UiStateSaver::saveState( mItemView, group );
244
285
  }
245
286
 
 
287
  saveState();
 
288
 
246
289
  Settings::self()->writeConfig();
247
290
}
248
291
 
 
292
void MainWidget::restoreState()
 
293
{
 
294
  // collection view
 
295
  {
 
296
    Akonadi::ETMViewStateSaver *saver = new Akonadi::ETMViewStateSaver;
 
297
    saver->setView( mCollectionView );
 
298
 
 
299
    const KConfigGroup group( Settings::self()->config(), "CollectionViewState" );
 
300
    saver->restoreState( group );
 
301
  }
 
302
 
 
303
  // collection view
 
304
  {
 
305
    Akonadi::ETMViewStateSaver *saver = new Akonadi::ETMViewStateSaver;
 
306
    saver->setSelectionModel( mCollectionSelectionModel );
 
307
 
 
308
    const KConfigGroup group( Settings::self()->config(), "CollectionViewCheckState" );
 
309
    saver->restoreState( group );
 
310
  }
 
311
 
 
312
  // item view
 
313
  {
 
314
    Akonadi::ETMViewStateSaver *saver = new Akonadi::ETMViewStateSaver;
 
315
    saver->setView( mItemView );
 
316
    saver->setSelectionModel( mItemView->selectionModel() );
 
317
 
 
318
    const KConfigGroup group( Settings::self()->config(), "ItemViewState" );
 
319
    saver->restoreState( group );
 
320
  }
 
321
}
 
322
 
 
323
void MainWidget::saveState()
 
324
{
 
325
  // collection view
 
326
  {
 
327
    Akonadi::ETMViewStateSaver saver;
 
328
    saver.setView( mCollectionView );
 
329
 
 
330
    KConfigGroup group( Settings::self()->config(), "CollectionViewState" );
 
331
    saver.saveState( group );
 
332
    group.sync();
 
333
  }
 
334
 
 
335
  // collection view
 
336
  {
 
337
    Akonadi::ETMViewStateSaver saver;
 
338
    saver.setSelectionModel( mCollectionSelectionModel );
 
339
 
 
340
    KConfigGroup group( Settings::self()->config(), "CollectionViewCheckState" );
 
341
    saver.saveState( group );
 
342
    group.sync();
 
343
  }
 
344
 
 
345
  // item view
 
346
  {
 
347
    Akonadi::ETMViewStateSaver saver;
 
348
    saver.setView( mItemView );
 
349
    saver.setSelectionModel( mItemView->selectionModel() );
 
350
 
 
351
    KConfigGroup group( Settings::self()->config(), "ItemViewState" );
 
352
    saver.saveState( group );
 
353
    group.sync();
 
354
  }
 
355
}
 
356
 
249
357
void MainWidget::setupGui()
250
358
{
251
359
  // the horizontal main layout
252
360
  QHBoxLayout *layout = new QHBoxLayout( this );
 
361
  layout->setMargin( 0 );
253
362
 
254
363
  // The splitter that contains the three main parts of the gui
255
364
  //   - collection view on the left
291
400
  mDetailsViewStack->addWidget( mContactGroupDetails );
292
401
 
293
402
  // the details widget for empty items
294
 
  mEmptyDetails = new QTextBrowser( mDetailsViewStack );
 
403
  mEmptyDetails = new KTextBrowser( mDetailsViewStack );
295
404
  mDetailsViewStack->addWidget( mEmptyDetails );
296
405
 
297
406
  // the contact switcher for the simple gui mode
306
415
  Akonadi::ContactDefaultActions *actions = new Akonadi::ContactDefaultActions( this );
307
416
  actions->connectToView( mContactDetails );
308
417
  actions->connectToView( mContactGroupDetails );
 
418
 
 
419
#if 0 // disabled because Grantlee supports no i18n for KDE 4.6 yet
 
420
 Akonadi::GrantleeContactFormatter *formatter =
 
421
       new Akonadi::GrantleeContactFormatter( KStandardDirs::locate( "data", QLatin1String( "kaddressbook/viewertemplates/" ) ) );
 
422
 
 
423
 mContactDetails->setContactFormatter( formatter );
 
424
 
 
425
 Akonadi::GrantleeContactGroupFormatter *groupFormatter =
 
426
       new Akonadi::GrantleeContactGroupFormatter( KStandardDirs::locate( "data", QLatin1String( "kaddressbook/viewertemplates/" ) ) );
 
427
 
 
428
 mContactGroupDetails->setContactGroupFormatter( groupFormatter );
 
429
#endif
309
430
}
310
431
 
311
432
void MainWidget::setupActions( KActionCollection *collection )
326
447
  action->setWhatsThis( i18n( "Select all contacts in the current address book view." ) );
327
448
  connect( action, SIGNAL( triggered( bool ) ), mItemView, SLOT( selectAll() ) );
328
449
 
329
 
  toggleAction = collection->add<KToggleAction>( "options_show_collectionview" );
330
 
  toggleAction->setText( i18n( "Show Address Books View" ) );
331
 
  toggleAction->setWhatsThis( i18n( "Toggle whether the address books view shall be visible." ) );
332
 
  toggleAction->setCheckedState( KGuiItem( i18n( "Hide Address Books View" ) ) );
333
 
  toggleAction->setChecked( true );
334
 
  connect( toggleAction, SIGNAL( toggled( bool ) ), SLOT( setCollectionViewVisible( bool ) ) );
335
 
 
336
 
  toggleAction = collection->add<KToggleAction>( "options_show_itemview" );
337
 
  toggleAction->setText( i18n( "Show Contacts View" ) );
338
 
  toggleAction->setWhatsThis( i18n( "Toggle whether the contacts view shall be visible." ) );
339
 
  toggleAction->setCheckedState( KGuiItem( i18n( "Hide Contacts View" ) ) );
340
 
  toggleAction->setChecked( true );
341
 
  connect( toggleAction, SIGNAL( toggled( bool ) ), SLOT( setItemViewVisible( bool ) ) );
342
 
 
343
 
  toggleAction = collection->add<KToggleAction>( "options_show_detailsview" );
344
 
  toggleAction->setText( i18n( "Show Details View" ) );
345
 
  toggleAction->setWhatsThis( i18n( "Toggle whether the details view shall be visible." ) );
346
 
  toggleAction->setCheckedState( KGuiItem( i18n( "Hide Details View" ) ) );
347
 
  toggleAction->setChecked( true );
348
 
  connect( toggleAction, SIGNAL( toggled( bool ) ), SLOT( setDetailsViewVisible( bool ) ) );
349
 
 
350
450
  toggleAction = collection->add<KToggleAction>( "options_show_simplegui" );
351
451
  toggleAction->setText( i18n( "Show Simple View" ) );
352
452
  action->setWhatsThis( i18n( "Show a simple mode of the address book view." ) );
416
516
 
417
517
  QPrintDialog printDialog( &printer, this );
418
518
  printDialog.setWindowTitle( i18n( "Print Contacts" ) );
419
 
  if ( !printDialog.exec() )
 
519
  if ( !printDialog.exec() ) //krazy:exclude=crashy
420
520
    return;
421
521
 
422
 
  KABPrinting::PrintingWizard wizard( &printer, allContactsModel(),
423
 
                                      mItemView->selectionModel(), this );
 
522
  KABPrinting::PrintingWizard wizard( &printer, mItemView->selectionModel(), this );
424
523
  wizard.setDefaultAddressBook( currentAddressBook() );
425
524
 
426
525
  wizard.exec();
428
527
 
429
528
void MainWidget::newContact()
430
529
{
431
 
  Akonadi::ContactEditorDialog dlg( Akonadi::ContactEditorDialog::CreateMode, this );
432
 
  dlg.setDefaultAddressBook( currentAddressBook() );
433
 
 
434
 
  dlg.exec();
 
530
  mActionManager->action( Akonadi::StandardContactActionManager::CreateContact )->trigger();
435
531
}
436
532
 
437
533
void MainWidget::newGroup()
438
534
{
439
 
  Akonadi::ContactGroupEditorDialog dlg( Akonadi::ContactGroupEditorDialog::CreateMode, this );
440
 
  dlg.setDefaultAddressBook( currentAddressBook() );
441
 
 
442
 
  dlg.exec();
443
 
}
444
 
 
445
 
void MainWidget::editItem( const Akonadi::Item &reference )
446
 
{
447
 
  if ( Akonadi::MimeTypeChecker::isWantedItem( reference, KABC::Addressee::mimeType() ) ) {
448
 
    editContact( reference );
449
 
  } else if ( Akonadi::MimeTypeChecker::isWantedItem( reference, KABC::ContactGroup::mimeType() ) ) {
450
 
    editGroup( reference );
451
 
  }
 
535
  mActionManager->action( Akonadi::StandardContactActionManager::CreateContactGroup )->trigger();
452
536
}
453
537
 
454
538
/**
488
572
  }
489
573
}
490
574
 
491
 
void MainWidget::setCollectionViewVisible( bool visible )
492
 
{
493
 
  mCollectionView->setVisible( visible );
494
 
}
495
 
 
496
 
void MainWidget::setItemViewVisible( bool visible )
497
 
{
498
 
  mItemView->setVisible( visible );
499
 
}
500
 
 
501
 
void MainWidget::setDetailsViewVisible( bool visible )
502
 
{
503
 
  mDetailsPane->setVisible( visible );
504
 
}
505
 
 
506
575
void MainWidget::setSimpleGuiMode( bool on )
507
576
{
508
577
  mCollectionView->setVisible( !on );
510
579
  mDetailsPane->setVisible( true );
511
580
  mContactSwitcher->setVisible( on );
512
581
 
513
 
  // If simple mode is on, we use a model that provides all available contacts
514
 
  // in a list, otherwise we use the model that provides all contacts of the
515
 
  // currently selected collection.
516
 
  if ( on )
517
 
    mContactsFilterModel->setSourceModel( allContactsModel() );
518
 
  else
519
 
    mContactsFilterModel->setSourceModel( mItemTree );
520
 
 
521
 
  if ( mCollectionView->model() )
522
 
    mCollectionView->setCurrentIndex( mCollectionView->model()->index( 0, 0 ) );
523
 
 
524
582
  if ( mItemView->model() )
525
583
    mItemView->setCurrentIndex( mItemView->model()->index( 0, 0 ) );
526
584
 
527
585
  Settings::self()->setUseSimpleMode( on );
528
586
}
529
587
 
530
 
void MainWidget::editContact( const Akonadi::Item &contact )
531
 
{
532
 
  Akonadi::ContactEditorDialog dlg( Akonadi::ContactEditorDialog::EditMode, this );
533
 
  dlg.setContact( contact );
534
 
  dlg.exec();
535
 
}
536
 
 
537
 
void MainWidget::editGroup( const Akonadi::Item &group )
538
 
{
539
 
  Akonadi::ContactGroupEditorDialog dlg( Akonadi::ContactGroupEditorDialog::EditMode, this );
540
 
  dlg.setContactGroup( group );
541
 
  dlg.exec();
542
 
}
543
 
 
544
588
Akonadi::Collection MainWidget::currentAddressBook() const
545
589
{
546
590
  if ( mCollectionView->selectionModel() && mCollectionView->selectionModel()->hasSelection() ) {