30 #include "kaddressbookgrantlee/formatter/grantleecontactformatter.h"
31 #include "kaddressbookgrantlee/formatter/grantleecontactgroupformatter.h"
32 #include "grantleetheme/grantleethememanager.h"
33 #include "grantleetheme/globalsettings_base.h"
35 #include "libkdepim/misc/uistatesaver.h"
37 #include <pimcommon/acl/collectionaclpage.h>
38 #include <pimcommon/acl/imapaclattribute.h>
40 #include <Akonadi/ETMViewStateSaver>
41 #include <Akonadi/CollectionFilterProxyModel>
42 #include <Akonadi/CollectionModel>
43 #include <Akonadi/Control>
44 #include <Akonadi/EntityMimeTypeFilterModel>
45 #include <Akonadi/EntityTreeView>
46 #include <Akonadi/ItemView>
47 #include <Akonadi/MimeTypeChecker>
48 #include <Akonadi/AttributeFactory>
49 #include <Akonadi/CollectionPropertiesDialog>
50 #include <Akonadi/Contact/ContactDefaultActions>
51 #include <Akonadi/Contact/ContactGroupEditorDialog>
52 #include <Akonadi/Contact/ContactGroupViewer>
53 #include <Akonadi/Contact/ContactsFilterProxyModel>
54 #include <Akonadi/Contact/ContactsTreeModel>
55 #include <Akonadi/Contact/ContactViewer>
56 #include <Akonadi/Contact/StandardContactActionManager>
58 #include <KABC/Addressee>
59 #include <KABC/ContactGroup>
62 #include <KActionCollection>
63 #include <KActionMenu>
64 #include <KApplication>
65 #include <KCheckableProxyModel>
66 #include <kdescendantsproxymodel.h>
70 #include <KSelectionProxyModel>
71 #include <KStandardDirs>
72 #include <KTextBrowser>
73 #include <KToggleAction>
75 #include <KXmlGuiWindow>
76 #include <KCMultiDialog>
77 #include <kdeprintdialog.h>
78 #include <KPrintPreview>
81 #include <QActionGroup>
82 #include <QHBoxLayout>
83 #include <QHeaderView>
86 #include <QPrintDialog>
87 #include <QSortFilterProxyModel>
89 #include <QStackedWidget>
92 static bool isStructuralCollection(
const Akonadi::Collection &collection )
94 QStringList mimeTypes;
95 mimeTypes << KABC::Addressee::mimeType() << KABC::ContactGroup::mimeType();
96 const QStringList collectionMimeTypes = collection.contentMimeTypes();
97 foreach (
const QString &mimeType, mimeTypes ) {
98 if ( collectionMimeTypes.contains( mimeType ) ) {
105 class StructuralCollectionsNotCheckableProxy :
public KCheckableProxyModel
108 StructuralCollectionsNotCheckableProxy(
QObject *parent )
109 : KCheckableProxyModel( parent )
113 QVariant data(
const QModelIndex &index,
int role )
const
115 if ( !index.isValid() ) {
119 if ( role == Qt::CheckStateRole ) {
121 const Akonadi::Collection collection =
122 index.data( Akonadi::EntityTreeModel::CollectionRole ).value<Akonadi::Collection>();
123 if ( collection.isValid() && isStructuralCollection( collection ) ) {
127 return KCheckableProxyModel::data( index, role );
134 : QWidget( parent ), mAllContactsModel( 0 ), mXmlGuiClient( guiClient ), mGrantleeThemeManager(0)
137 Akonadi::AttributeFactory::registerAttribute<PimCommon::ImapAclAttribute>();
140 setupActions( guiClient->actionCollection() );
189 mCollectionTree =
new Akonadi::EntityMimeTypeFilterModel(
this );
190 mCollectionTree->setDynamicSortFilter(
true );
191 mCollectionTree->setSortCaseSensitivity( Qt::CaseInsensitive );
193 mCollectionTree->addMimeTypeInclusionFilter( Akonadi::Collection::mimeType() );
194 mCollectionTree->setHeaderGroup( Akonadi::EntityTreeModel::CollectionTreeHeaders );
196 mCollectionSelectionModel =
new QItemSelectionModel( mCollectionTree );
197 StructuralCollectionsNotCheckableProxy *checkableProxyModel =
198 new StructuralCollectionsNotCheckableProxy(
this );
199 checkableProxyModel->setSelectionModel( mCollectionSelectionModel );
200 checkableProxyModel->setSourceModel( mCollectionTree );
202 mCollectionView->setModel( checkableProxyModel );
203 mCollectionView->setXmlGuiClient( guiClient );
204 mCollectionView->header()->setDefaultAlignment( Qt::AlignCenter );
205 mCollectionView->header()->setSortIndicatorShown(
false );
207 connect( mCollectionView->model(), SIGNAL(rowsInserted(QModelIndex,
int,
int)),
208 SLOT(slotCheckNewCalendar(QModelIndex,
int,
int)) );
210 connect( mCollectionView, SIGNAL(currentChanged(Akonadi::Collection)),
211 mXXPortManager, SLOT(setDefaultAddressBook(Akonadi::Collection)) );
213 KSelectionProxyModel *selectionProxyModel =
214 new KSelectionProxyModel( mCollectionSelectionModel,
this );
216 selectionProxyModel->setFilterBehavior( KSelectionProxyModel::ChildrenOfExactSelection );
218 mItemTree =
new Akonadi::EntityMimeTypeFilterModel(
this );
219 mItemTree->setSourceModel( selectionProxyModel );
220 mItemTree->addMimeTypeExclusionFilter( Akonadi::Collection::mimeType() );
221 mItemTree->setHeaderGroup( Akonadi::EntityTreeModel::ItemListHeaders );
223 mContactsFilterModel =
new Akonadi::ContactsFilterProxyModel(
this );
224 mContactsFilterModel->setSourceModel( mItemTree );
225 connect( mQuickSearchWidget, SIGNAL(filterStringChanged(QString)),
226 mContactsFilterModel, SLOT(setFilterString(QString)) );
227 connect( mQuickSearchWidget, SIGNAL(filterStringChanged(QString)),
228 this, SLOT(selectFirstItem()) );
229 connect( mQuickSearchWidget, SIGNAL(arrowDownKeyPressed()),
230 mItemView, SLOT(setFocus()) );
232 mItemView->setModel( mContactsFilterModel );
233 mItemView->setXmlGuiClient( guiClient );
234 mItemView->setSelectionMode( QAbstractItemView::ExtendedSelection );
235 mItemView->setRootIsDecorated(
false );
236 mItemView->header()->setDefaultAlignment( Qt::AlignCenter );
240 mActionManager =
new Akonadi::StandardContactActionManager( guiClient->actionCollection(), this );
241 mActionManager->setCollectionSelectionModel( mCollectionView->selectionModel() );
242 mActionManager->setItemSelectionModel( mItemView->selectionModel() );
244 QList<Akonadi::StandardActionManager::Type> standardActions;
245 standardActions << Akonadi::StandardActionManager::CreateCollection
246 << Akonadi::StandardActionManager::CopyCollections
247 << Akonadi::StandardActionManager::DeleteCollections
248 << Akonadi::StandardActionManager::SynchronizeCollections
249 << Akonadi::StandardActionManager::CollectionProperties
250 << Akonadi::StandardActionManager::CopyItems
251 << Akonadi::StandardActionManager::Paste
252 << Akonadi::StandardActionManager::DeleteItems
253 << Akonadi::StandardActionManager::CutItems
254 << Akonadi::StandardActionManager::CutCollections
255 << Akonadi::StandardActionManager::CreateResource
256 << Akonadi::StandardActionManager::DeleteResources
257 << Akonadi::StandardActionManager::ResourceProperties
258 << Akonadi::StandardActionManager::SynchronizeResources
259 << Akonadi::StandardActionManager::SynchronizeCollectionsRecursive;
261 Q_FOREACH( Akonadi::StandardActionManager::Type standardAction, standardActions ) {
262 mActionManager->createAction( standardAction );
265 QList<Akonadi::StandardContactActionManager::Type> contactActions;
266 contactActions << Akonadi::StandardContactActionManager::CreateContact
267 << Akonadi::StandardContactActionManager::CreateContactGroup
268 << Akonadi::StandardContactActionManager::EditItem;
270 Q_FOREACH( Akonadi::StandardContactActionManager::Type contactAction, contactActions ) {
271 mActionManager->createAction( contactAction );
273 static bool pageRegistered =
false;
275 if ( !pageRegistered ) {
276 Akonadi::CollectionPropertiesDialog::registerPage(
new PimCommon::CollectionAclPageFactory );
277 pageRegistered =
true;
280 const QStringList pages =
281 QStringList() << QLatin1String(
"Akonadi::CollectionGeneralPropertiesPage" )
282 << QLatin1String(
"Akonadi::CachePolicyPage" )
283 << QLatin1String(
"PimCommon::CollectionAclPage" );
285 mActionManager->setCollectionPropertiesPageNames( pages );
287 connect( mItemView, SIGNAL(currentChanged(Akonadi::Item)),
288 this, SLOT(itemSelected(Akonadi::Item)) );
289 connect( mItemView, SIGNAL(doubleClicked(Akonadi::Item)),
290 mActionManager->action( Akonadi::StandardContactActionManager::EditItem ),
292 connect( mItemView->selectionModel(), SIGNAL(currentChanged(QModelIndex,QModelIndex)),
293 this, SLOT(itemSelectionChanged(QModelIndex,QModelIndex)) );
296 mDetailsViewStack->setCurrentWidget( mContactDetails );
298 mContactSwitcher->
setView( mItemView );
300 Akonadi::Control::widgetNeedsAkonadi(
this );
303 mModelColumnManager->
setWidget( mItemView->header() );
304 mModelColumnManager->
load();
306 QMetaObject::invokeMethod(
this,
"delayedInit", Qt::QueuedConnection );
311 KCMultiDialog dlg(
this );
312 dlg.addModule( QLatin1String(
"akonadicontact_actions.desktop") );
313 dlg.addModule( QLatin1String(
"kcmldap.desktop") );
318 void MainWidget::delayedInit()
322 const KConfigGroup group(
Settings::self()->config(),
"UiState_ContactView" );
323 KPIM::UiStateSaver::restoreState( mItemView, group );
325 #if defined(HAVE_PRISON)
328 action( QLatin1String(
"options_show_qrcodes") )->setChecked( showQRCodes() );
334 SLOT(restoreState()) );
335 connect( kapp, SIGNAL(aboutToQuit()), SLOT(saveState()) );
342 mModelColumnManager->
store();
343 saveSplitterStates();
345 KConfigGroup group(
Settings::self()->config(),
"UiState_ContactView" );
346 KPIM::UiStateSaver::saveState( mItemView, group );
349 delete mGrantleeThemeManager;
354 void MainWidget::restoreState()
358 Akonadi::ETMViewStateSaver *saver =
new Akonadi::ETMViewStateSaver;
359 saver->setView( mCollectionView );
361 const KConfigGroup group(
Settings::self()->config(),
"CollectionViewState" );
362 saver->restoreState( group );
367 Akonadi::ETMViewStateSaver *saver =
new Akonadi::ETMViewStateSaver;
368 saver->setSelectionModel( mCollectionSelectionModel );
370 const KConfigGroup group(
Settings::self()->config(),
"CollectionViewCheckState" );
371 saver->restoreState( group );
376 Akonadi::ETMViewStateSaver *saver =
new Akonadi::ETMViewStateSaver;
377 saver->setView( mItemView );
378 saver->setSelectionModel( mItemView->selectionModel() );
380 const KConfigGroup group(
Settings::self()->config(),
"ItemViewState" );
381 saver->restoreState( group );
385 void MainWidget::saveState()
389 Akonadi::ETMViewStateSaver saver;
390 saver.setView( mCollectionView );
392 KConfigGroup group(
Settings::self()->config(),
"CollectionViewState" );
393 saver.saveState( group );
399 Akonadi::ETMViewStateSaver saver;
400 saver.setSelectionModel( mCollectionSelectionModel );
402 KConfigGroup group(
Settings::self()->config(),
"CollectionViewCheckState" );
403 saver.saveState( group );
409 Akonadi::ETMViewStateSaver saver;
410 saver.setView( mItemView );
411 saver.setSelectionModel( mItemView->selectionModel() );
413 KConfigGroup group(
Settings::self()->config(),
"ItemViewState" );
414 saver.saveState( group );
419 void MainWidget::setupGui()
422 QHBoxLayout *layout =
new QHBoxLayout(
this );
423 layout->setMargin( 0 );
430 mMainWidgetSplitter1 =
new QSplitter(Qt::Horizontal);
431 mMainWidgetSplitter1->setObjectName( QLatin1String(
"MainWidgetSplitter1") );
432 layout->addWidget( mMainWidgetSplitter1 );
439 mMainWidgetSplitter2 =
new QSplitter(Qt::Vertical);
440 mMainWidgetSplitter2->setObjectName( QLatin1String(
"MainWidgetSplitter2") );
441 mMainWidgetSplitter1->addWidget( mMainWidgetSplitter2 );
444 mCollectionView =
new Akonadi::EntityTreeView();
445 mMainWidgetSplitter2->addWidget( mCollectionView );
448 mItemView =
new Akonadi::EntityTreeView();
449 mItemView->setObjectName( QLatin1String(
"ContactView") );
450 mItemView->setDefaultPopupMenu( QLatin1String(
"akonadi_itemview_contextmenu" ) );
451 mItemView->setAlternatingRowColors(
true);
452 mMainWidgetSplitter2->addWidget( mItemView );
455 mDetailsPane =
new QWidget;
456 mMainWidgetSplitter1->addWidget( mDetailsPane );
458 mMainWidgetSplitter1->setStretchFactor( 1, 9 );
459 mMainWidgetSplitter2->setStretchFactor( 1, 9 );
460 mMainWidgetSplitter2->setChildrenCollapsible(
false);
461 mMainWidgetSplitter1->setChildrenCollapsible(
false);
463 QVBoxLayout *detailsPaneLayout =
new QVBoxLayout( mDetailsPane );
464 detailsPaneLayout->setMargin( 0 );
467 mDetailsViewStack =
new QStackedWidget();
468 detailsPaneLayout->addWidget( mDetailsViewStack );
471 mContactDetails =
new Akonadi::ContactViewer( mDetailsViewStack );
472 mDetailsViewStack->addWidget( mContactDetails );
475 mContactGroupDetails =
new Akonadi::ContactGroupViewer( mDetailsViewStack );
476 mDetailsViewStack->addWidget( mContactGroupDetails );
479 mEmptyDetails =
new KTextBrowser( mDetailsViewStack );
480 mDetailsViewStack->addWidget( mEmptyDetails );
484 detailsPaneLayout->addWidget( mContactSwitcher );
485 mContactSwitcher->setVisible(
false );
491 Akonadi::ContactDefaultActions *actions =
new Akonadi::ContactDefaultActions(
this );
492 actions->connectToView( mContactDetails );
493 actions->connectToView( mContactGroupDetails );
494 mFormatter =
new KAddressBookGrantlee::GrantleeContactFormatter;
496 mContactDetails->setContactFormatter( mFormatter );
498 mGroupFormatter =
new KAddressBookGrantlee::GrantleeContactGroupFormatter;
500 mContactGroupDetails->setContactGroupFormatter( mGroupFormatter );
503 void MainWidget::setupActions( KActionCollection *collection )
505 mGrantleeThemeManager =
new GrantleeTheme::GrantleeThemeManager(QString::fromLatin1(
"theme.desktop" ), collection, QLatin1String(
"kaddressbook/viewertemplates/"));
506 mGrantleeThemeManager->setDownloadNewStuffConfigFile(QLatin1String(
"kaddressbook_themes.knsrc"));
507 connect(mGrantleeThemeManager, SIGNAL(grantleeThemeSelected()),
this, SLOT(slotGrantleeThemeSelected()));
508 connect(mGrantleeThemeManager, SIGNAL(updateThemes()),
this, SLOT(slotGrantleeThemesUpdated()));
511 KActionMenu *themeMenu =
new KActionMenu(i18n(
"&Themes"),
this);
512 collection->addAction(QLatin1String(
"theme_menu"), themeMenu );
514 initGrantleeThemeName();
515 QActionGroup *group =
new QActionGroup(
this );
516 mGrantleeThemeManager->setThemeMenu(themeMenu);
517 mGrantleeThemeManager->setActionGroup(group);
519 KAction *action = KStandardAction::print(
this, SLOT(
print()), collection );
520 action->setWhatsThis(
521 i18nc(
"@info:whatsthis",
522 "Print the complete address book or a selected number of contacts." ) );
524 if(KPrintPreview::isAvailable())
525 KStandardAction::printPreview(
this, SLOT(
printPreview()), collection );
527 action = collection->addAction( QLatin1String(
"quick_search") );
528 action->setText( i18n(
"Quick search" ) );
529 action->setDefaultWidget( mQuickSearchWidget );
531 action = collection->addAction( QLatin1String(
"select_all") );
532 action->setText( i18n(
"Select All" ) );
533 action->setShortcut( QKeySequence( Qt::CTRL + Qt::Key_A ) );
534 action->setWhatsThis( i18n(
"Select all contacts in the current address book view." ) );
535 connect( action, SIGNAL(triggered(
bool)), mItemView, SLOT(selectAll()) );
537 #if defined(HAVE_PRISON)
538 KToggleAction *qrtoggleAction;
539 qrtoggleAction = collection->add<KToggleAction>( QLatin1String(
"options_show_qrcodes") );
540 qrtoggleAction->setText( i18n(
"Show QR Codes" ) );
541 qrtoggleAction->setWhatsThis( i18n(
"Show QR Codes in the contact." ) );
542 connect( qrtoggleAction, SIGNAL(toggled(
bool)), SLOT(setQRCodeShow(
bool)) );
545 mViewModeGroup =
new QActionGroup(
this );
547 KAction *act =
new KAction( i18nc(
"@action:inmenu",
"Simple (one column)" ), mViewModeGroup );
548 act->setCheckable(
true );
550 act->setShortcut( QKeySequence( Qt::CTRL + Qt::SHIFT + Qt::Key_1 ) );
551 act->setWhatsThis( i18n(
"Show a simple mode of the address book view." ) );
552 collection->addAction( QLatin1String(
"view_mode_simple"), act );
554 act =
new KAction( i18nc(
"@action:inmenu",
"Two Columns" ), mViewModeGroup );
555 act->setCheckable(
true );
557 act->setShortcut( QKeySequence( Qt::CTRL + Qt::SHIFT + Qt::Key_2 ) );
558 collection->addAction( QLatin1String(
"view_mode_2columns"), act );
560 act =
new KAction( i18nc(
"@action:inmenu",
"Three Columns" ), mViewModeGroup );
561 act->setCheckable(
true );
563 act->setShortcut( QKeySequence( Qt::CTRL + Qt::SHIFT + Qt::Key_3 ) );
564 collection->addAction( QLatin1String(
"view_mode_3columns"), act );
566 connect( mViewModeGroup, SIGNAL(triggered(QAction*)), SLOT(setViewMode(QAction*)) );
569 action = collection->addAction( QLatin1String(
"file_import_vcard") );
570 action->setText( i18n(
"Import vCard..." ) );
571 action->setWhatsThis( i18n(
"Import contacts from a vCard file." ) );
574 action = collection->addAction( QLatin1String(
"file_import_csv") );
575 action->setText( i18n(
"Import CSV file..." ) );
576 action->setWhatsThis( i18n(
"Import contacts from a file in comma separated value format." ) );
579 action = collection->addAction( QLatin1String(
"file_import_ldif") );
580 action->setText( i18n(
"Import LDIF file..." ) );
581 action->setWhatsThis( i18n(
"Import contacts from an LDIF file." ) );
584 action = collection->addAction( QLatin1String(
"file_import_ldap") );
585 action->setText( i18n(
"Import From LDAP server..." ) );
586 action->setWhatsThis( i18n(
"Import contacts from an LDAP server." ) );
589 action = collection->addAction( QLatin1String(
"file_import_gmx") );
590 action->setText( i18n(
"Import GMX file..." ) );
591 action->setWhatsThis( i18n(
"Import contacts from a GMX address book file." ) );
595 action = collection->addAction( QLatin1String(
"file_export_vcard30") );
596 action->setText( i18n(
"Export vCard 3.0..." ) );
597 action->setWhatsThis( i18n(
"Export contacts to a vCard 3.0 file." ) );
600 action = collection->addAction( QLatin1String(
"file_export_vcard21") );
601 action->setText( i18n(
"Export vCard 2.1..." ) );
602 action->setWhatsThis( i18n(
"Export contacts to a vCard 2.1 file." ) );
605 action = collection->addAction( QLatin1String(
"file_export_csv") );
606 action->setText( i18n(
"Export CSV file..." ) );
607 action->setWhatsThis( i18n(
"Export contacts to a file in comma separated value format." ) );
610 action = collection->addAction( QLatin1String(
"file_export_ldif") );
611 action->setText( i18n(
"Export LDIF file..." ) );
612 action->setWhatsThis( i18n(
"Export contacts to an LDIF file." ) );
615 action = collection->addAction( QLatin1String(
"file_export_gmx") );
616 action->setText( i18n(
"Export GMX file..." ) );
617 action->setWhatsThis( i18n(
"Export contacts to a GMX address book file." ) );
620 KToggleAction *actTheme = mGrantleeThemeManager->actionForTheme();
622 actTheme->setChecked(
true);
629 printer.setDocName( i18n(
"Address Book" ) );
631 printer.setOutputFormat( QPrinter::PdfFormat );
632 printer.setCollateCopies(
true );
634 KPrintPreview previewdlg( &printer,
this );
638 const int result = wizard.exec();
646 printer.setDocName( i18n(
"Address Book" ) );
648 printer.setOutputFormat( QPrinter::PdfFormat );
649 printer.setCollateCopies(
true );
651 QPrintDialog printDialog(KdePrint::createPrintDialog(&printer));
653 printDialog.setWindowTitle( i18n(
"Print Contacts" ) );
654 if ( !printDialog.exec() ) {
670 mActionManager->action( Akonadi::StandardContactActionManager::CreateContact )->trigger();
675 mActionManager->action( Akonadi::StandardContactActionManager::CreateContactGroup )->trigger();
683 void MainWidget::itemSelected(
const Akonadi::Item &item )
685 if ( Akonadi::MimeTypeChecker::isWantedItem( item, KABC::Addressee::mimeType() ) ) {
686 mDetailsViewStack->setCurrentWidget( mContactDetails );
687 mContactDetails->setContact( item );
688 }
else if ( Akonadi::MimeTypeChecker::isWantedItem( item, KABC::ContactGroup::mimeType() ) ) {
689 mDetailsViewStack->setCurrentWidget( mContactGroupDetails );
690 mContactGroupDetails->setContactGroup( item );
698 void MainWidget::itemSelectionChanged(
const QModelIndex ¤t,
const QModelIndex & )
700 if ( !current.isValid() ) {
701 mDetailsViewStack->setCurrentWidget( mEmptyDetails );
705 void MainWidget::selectFirstItem()
709 if ( mItemView && mItemView->selectionModel() ) {
710 mItemView->selectionModel()->setCurrentIndex( mItemView->model()->index( 0, 0 ),
711 QItemSelectionModel::Rows |
712 QItemSelectionModel::ClearAndSelect );
716 bool MainWidget::showQRCodes()
718 #if defined(HAVE_PRISON)
719 KConfig config( QLatin1String(
"akonadi_contactrc" ) );
720 KConfigGroup group( &config, QLatin1String(
"View" ) );
721 return group.readEntry(
"QRCodes",
true );
727 void MainWidget::setQRCodeShow(
bool on )
729 #if defined(HAVE_PRISON)
731 KConfig config( QLatin1String(
"akonadi_contactrc" ) );
732 KConfigGroup group( &config, QLatin1String(
"View" ) );
733 group.writeEntry(
"QRCodes", on );
734 if ( mItemView->model() ) {
735 mItemView->setCurrentIndex( mItemView->model()->index( 0, 0 ) );
742 Akonadi::Collection MainWidget::currentAddressBook()
const
744 if ( mCollectionView->selectionModel() && mCollectionView->selectionModel()->hasSelection() ) {
745 const QModelIndex index = mCollectionView->selectionModel()->selectedIndexes().first();
746 const Akonadi::Collection collection =
747 index.data( Akonadi::EntityTreeModel::CollectionRole ).value<Akonadi::Collection>();
752 return Akonadi::Collection();
755 QAbstractItemModel *MainWidget::allContactsModel()
757 if ( !mAllContactsModel ) {
758 KDescendantsProxyModel *descendantsModel =
new KDescendantsProxyModel(
this );
761 mAllContactsModel =
new Akonadi::EntityMimeTypeFilterModel(
this );
762 mAllContactsModel->setSourceModel( descendantsModel );
763 mAllContactsModel->addMimeTypeExclusionFilter( Akonadi::Collection::mimeType() );
764 mAllContactsModel->setHeaderGroup( Akonadi::EntityTreeModel::ItemListHeaders );
767 return mAllContactsModel;
770 void MainWidget::setViewMode( QAction *action )
772 setViewMode( action->data().toInt() );
775 void MainWidget::setViewMode(
int mode )
779 if ( mode == currentMode )
return;
784 saveSplitterStates();
787 mMainWidgetSplitter2->setVisible(
false );
788 mDetailsPane->setVisible(
true );
789 mContactSwitcher->setVisible(
true );
792 mMainWidgetSplitter2->setVisible(
true );
793 mContactSwitcher->setVisible(
false );
796 mMainWidgetSplitter2->setOrientation( Qt::Vertical );
798 else if ( mode == 3 ) {
799 mMainWidgetSplitter2->setOrientation( Qt::Horizontal );
804 restoreSplitterStates();
805 mViewModeGroup->actions().at( mode-1 )->setChecked(
true );
807 if ( mItemView->model() ) {
808 mItemView->setCurrentIndex( mItemView->model()->index( 0, 0 ) );
812 void MainWidget::saveSplitterStates()
const
817 if ( currentMode == 1 )
820 QString groupName = QString::fromLatin1(
"UiState_MainWidgetSplitter_%1" ).arg( currentMode );
823 KPIM::UiStateSaver::saveState( mMainWidgetSplitter1, group );
824 KPIM::UiStateSaver::saveState( mMainWidgetSplitter2, group );
827 void MainWidget::restoreSplitterStates()
832 if ( currentMode == 1 )
835 QString groupName = QString::fromLatin1(
"UiState_MainWidgetSplitter_%1" ).arg( currentMode );
838 KPIM::UiStateSaver::restoreState( mMainWidgetSplitter1, group );
839 KPIM::UiStateSaver::restoreState( mMainWidgetSplitter2, group );
842 void MainWidget::initGrantleeThemeName()
844 QString themeName = GrantleeTheme::GrantleeSettings::self()->grantleeThemeName();
845 if (themeName.isEmpty()) {
846 themeName = QLatin1String(
"default");
848 mFormatter->setGrantleeTheme(mGrantleeThemeManager->theme(themeName));
849 mGroupFormatter->setGrantleeTheme(mGrantleeThemeManager->theme(themeName));
852 void MainWidget::slotGrantleeThemeSelected()
854 initGrantleeThemeName();
855 if ( mItemView->model() ) {
856 mItemView->setCurrentIndex( mItemView->model()->index( 0, 0 ) );
860 void MainWidget::slotGrantleeThemesUpdated()
862 if ( mItemView->model() ) {
863 mItemView->setCurrentIndex( mItemView->model()->index( 0, 0 ) );
867 Akonadi::EntityTreeModel *MainWidget::entityTreeModel()
const
869 QAbstractProxyModel *proxy = qobject_cast<QAbstractProxyModel*>( mCollectionView->model() );
871 Akonadi::EntityTreeModel *etm = qobject_cast<Akonadi::EntityTreeModel*>( proxy->sourceModel() );
875 proxy = qobject_cast<QAbstractProxyModel*>( proxy->sourceModel() );
878 kWarning() <<
"Couldn't find EntityTreeModel";
882 void MainWidget::slotCheckNewCalendar(
const QModelIndex &parent,
int begin,
int end )
885 Akonadi::EntityTreeModel *etm = entityTreeModel();
886 if ( etm && etm->isCollectionTreeFetched() ) {
887 for(
int row=begin; row<=end; ++row ) {
888 QModelIndex index = mCollectionView->model()->index( row, 0, parent );
889 if ( index.isValid() )
890 mCollectionView->model()->setData( index, Qt::Checked, Qt::CheckStateRole );
892 if ( parent.isValid() ) {
893 mCollectionView->setExpanded( parent,
true );
899 #include "mainwidget.moc"
static void setSortOrder(int v)
Set Default sort order.
void store()
Stores the user configuration.
The PrintingWizard combines pages common for all print styles and those provided by the respective st...
void setDefaultAddressBook(const Akonadi::Collection &addressBook)
Sets the default addressbook of the contact selection.
void setSelectionModel(QItemSelectionModel *model)
Sets the model that contains the current selection.
void addImportAction(QAction *action, const QString &identifier)
Adds a new action to import contacts.
static int viewMode()
Get Viewing mode.
void load()
Loads the user configuration and applies it to the model.
void setWidget(QWidget *view)
Sets the widget that shall provide a RMB menu to configure the columns to be shown.
MainWidget(KXMLGUIClient *guiClient, QWidget *parent=0)
The class that manages import and export of contacts.
static void setDefaultFileName(const QString &v)
Set DefaultFileName.
static void setViewMode(int v)
Set Viewing mode.
A manager for the contacts model columns.
static void setPrintingStyle(int v)
Set Printing style.
void addExportAction(QAction *action, const QString &identifier)
Adds a new action to export contacts.