32 #include "kaddressbookadaptor.h"
39 #include "kaddressbookgrantlee/formatter/grantleecontactformatter.h"
40 #include "kaddressbookgrantlee/formatter/grantleecontactgroupformatter.h"
41 #include "grantleetheme/grantleethememanager.h"
42 #include "grantleetheme/globalsettings_base.h"
44 #include "libkdepim/misc/uistatesaver.h"
46 #include <pimcommon/acl/collectionaclpage.h>
47 #include <pimcommon/acl/imapaclattribute.h>
49 #include <pimcommon/baloodebug/baloodebugdialog.h>
51 #include <QtCore/QPointer>
54 #include <Akonadi/ETMViewStateSaver>
55 #include <Akonadi/CollectionFilterProxyModel>
56 #include <Akonadi/CollectionModel>
57 #include <Akonadi/Control>
58 #include <Akonadi/EntityMimeTypeFilterModel>
59 #include <Akonadi/EntityTreeView>
60 #include <Akonadi/ItemView>
61 #include <Akonadi/MimeTypeChecker>
62 #include <Akonadi/AttributeFactory>
63 #include <Akonadi/CollectionPropertiesDialog>
64 #include <Akonadi/Contact/ContactDefaultActions>
65 #include <Akonadi/Contact/ContactGroupEditorDialog>
66 #include <Akonadi/Contact/ContactGroupViewer>
67 #include <Akonadi/Contact/ContactsFilterProxyModel>
68 #include <Akonadi/Contact/ContactsTreeModel>
69 #include <Akonadi/Contact/ContactViewer>
70 #include <Akonadi/Contact/StandardContactActionManager>
72 #include <KABC/Addressee>
73 #include <KABC/ContactGroup>
75 #include <KCmdLineArgs>
77 #include <KActionCollection>
78 #include <KActionMenu>
79 #include <KApplication>
80 #include <KCheckableProxyModel>
81 #include <kdescendantsproxymodel.h>
82 #include <KLocalizedString>
83 #include <KSelectionProxyModel>
84 #include <KTextBrowser>
85 #include <KToggleAction>
86 #include <KCMultiDialog>
87 #include <kdeprintdialog.h>
88 #include <KPrintPreview>
89 #include <KXMLGUIClient>
90 #include <KToolInvocation>
91 #include <KMessageBox>
94 #include <QActionGroup>
95 #include <QHBoxLayout>
96 #include <QHeaderView>
98 #include <QPrintDialog>
100 #include <QStackedWidget>
101 #include <QDBusConnection>
104 static bool isStructuralCollection(
const Akonadi::Collection &collection )
107 mimeTypes << KABC::Addressee::mimeType() << KABC::ContactGroup::mimeType();
108 const QStringList collectionMimeTypes = collection.contentMimeTypes();
109 foreach (
const QString &mimeType, mimeTypes ) {
110 if ( collectionMimeTypes.
contains( mimeType ) ) {
117 class StructuralCollectionsNotCheckableProxy :
public KCheckableProxyModel
120 StructuralCollectionsNotCheckableProxy(
QObject *parent )
121 : KCheckableProxyModel( parent )
131 if ( role == Qt::CheckStateRole ) {
133 const Akonadi::Collection collection =
134 index.
data( Akonadi::EntityTreeModel::CollectionRole ).
value<Akonadi::Collection>();
135 if ( collection.isValid() && isStructuralCollection( collection ) ) {
139 return KCheckableProxyModel::data( index, role );
146 :
QWidget( parent ), mAllContactsModel( 0 ), mXmlGuiClient( guiClient ), mGrantleeThemeManager(0), mQuickSearchAction(0)
149 (void)
new KaddressbookAdaptor(
this );
154 Akonadi::AttributeFactory::registerAttribute<PimCommon::ImapAclAttribute>();
157 setupActions( guiClient->actionCollection() );
211 mCollectionTree =
new Akonadi::EntityMimeTypeFilterModel(
this );
212 mCollectionTree->setDynamicSortFilter(
true );
213 mCollectionTree->setSortCaseSensitivity( Qt::CaseInsensitive );
215 mCollectionTree->addMimeTypeInclusionFilter( Akonadi::Collection::mimeType() );
216 mCollectionTree->setHeaderGroup( Akonadi::EntityTreeModel::CollectionTreeHeaders );
219 StructuralCollectionsNotCheckableProxy *checkableProxyModel =
220 new StructuralCollectionsNotCheckableProxy(
this );
221 checkableProxyModel->setSelectionModel( mCollectionSelectionModel );
222 checkableProxyModel->setSourceModel( mCollectionTree );
224 mCollectionView->setModel( checkableProxyModel );
225 mCollectionView->setXmlGuiClient( guiClient );
226 mCollectionView->header()->setDefaultAlignment( Qt::AlignCenter );
227 mCollectionView->header()->setSortIndicatorShown(
false );
232 connect( mCollectionView, SIGNAL(currentChanged(Akonadi::Collection)),
233 mXXPortManager, SLOT(setDefaultAddressBook(Akonadi::Collection)) );
235 KSelectionProxyModel *selectionProxyModel =
236 new KSelectionProxyModel( mCollectionSelectionModel,
this );
238 selectionProxyModel->setFilterBehavior( KSelectionProxyModel::ChildrenOfExactSelection );
240 mItemTree =
new Akonadi::EntityMimeTypeFilterModel(
this );
241 mItemTree->setSourceModel( selectionProxyModel );
242 mItemTree->addMimeTypeExclusionFilter( Akonadi::Collection::mimeType() );
243 mItemTree->setHeaderGroup( Akonadi::EntityTreeModel::ItemListHeaders );
253 mContactsFilterModel =
new Akonadi::ContactsFilterProxyModel(
this );
254 mContactsFilterModel->setSourceModel( mCategoryFilterModel );
256 connect( mQuickSearchWidget, SIGNAL(filterStringChanged(
QString)),
257 mContactsFilterModel, SLOT(setFilterString(
QString)) );
258 connect( mQuickSearchWidget, SIGNAL(filterStringChanged(
QString)),
259 this, SLOT(selectFirstItem()) );
260 connect( mQuickSearchWidget, SIGNAL(arrowDownKeyPressed()),
263 mItemView->setModel( mContactsFilterModel );
264 mItemView->setXmlGuiClient( guiClient );
265 mItemView->setSelectionMode( QAbstractItemView::ExtendedSelection );
266 mItemView->setRootIsDecorated(
false );
267 mItemView->header()->setDefaultAlignment( Qt::AlignCenter );
271 mActionManager =
new Akonadi::StandardContactActionManager( guiClient->actionCollection(), this );
272 mActionManager->setCollectionSelectionModel( mCollectionView->selectionModel() );
273 mActionManager->setItemSelectionModel( mItemView->selectionModel() );
276 standardActions << Akonadi::StandardActionManager::CreateCollection
277 << Akonadi::StandardActionManager::DeleteCollections
278 << Akonadi::StandardActionManager::SynchronizeCollections
279 << Akonadi::StandardActionManager::CollectionProperties
280 << Akonadi::StandardActionManager::CopyItems
281 << Akonadi::StandardActionManager::Paste
282 << Akonadi::StandardActionManager::DeleteItems
283 << Akonadi::StandardActionManager::CutItems
284 << Akonadi::StandardActionManager::CreateResource
285 << Akonadi::StandardActionManager::DeleteResources
286 << Akonadi::StandardActionManager::ResourceProperties
287 << Akonadi::StandardActionManager::SynchronizeResources
288 << Akonadi::StandardActionManager::SynchronizeCollectionsRecursive
289 << Akonadi::StandardActionManager::MoveItemToMenu
290 << Akonadi::StandardActionManager::CopyItemToMenu
291 << Akonadi::StandardActionManager::CopyCollectionToMenu
292 << Akonadi::StandardActionManager::MoveCollectionToMenu;
295 Q_FOREACH( Akonadi::StandardActionManager::Type standardAction, standardActions ) {
296 mActionManager->createAction( standardAction );
300 contactActions << Akonadi::StandardContactActionManager::CreateContact
301 << Akonadi::StandardContactActionManager::CreateContactGroup
302 << Akonadi::StandardContactActionManager::EditItem;
304 Q_FOREACH( Akonadi::StandardContactActionManager::Type contactAction, contactActions ) {
305 mActionManager->createAction( contactAction );
307 static bool pageRegistered =
false;
309 if ( !pageRegistered ) {
310 Akonadi::CollectionPropertiesDialog::registerPage(
new PimCommon::CollectionAclPageFactory );
311 pageRegistered =
true;
319 mActionManager->setCollectionPropertiesPageNames( pages );
321 connect( mItemView, SIGNAL(currentChanged(Akonadi::Item)),
322 this, SLOT(itemSelected(Akonadi::Item)) );
323 connect( mItemView, SIGNAL(doubleClicked(Akonadi::Item)),
324 mActionManager->action( Akonadi::StandardContactActionManager::EditItem ),
332 mContactSwitcher->
setView( mItemView );
334 Akonadi::Control::widgetNeedsAkonadi(
this );
337 mModelColumnManager->
setWidget( mItemView->header() );
338 mModelColumnManager->
load();
346 KCMultiDialog dlg(
this );
347 dlg.addModule(
QLatin1String(
"akonadicontact_actions.desktop") );
355 KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
356 if ( args->isSet(
"import" ) ) {
357 for (
int i = 0; i < args->count(); ++i ) {
367 return mXXPortManager;
372 mQuickSearchWidget->
updateQuickSearchText(i18nc(
"@label Search contacts in list",
"Search...<%1>", mQuickSearchAction->shortcut().toString() ));
375 void MainWidget::delayedInit()
379 const KConfigGroup group( Settings::self()->config(),
"UiState_ContactView" );
380 KPIM::UiStateSaver::restoreState( mItemView, group );
382 #if defined(HAVE_PRISON)
385 action(
QLatin1String(
"options_show_qrcodes") )->setChecked( showQRCodes() );
391 SLOT(restoreState()) );
392 connect( kapp, SIGNAL(aboutToQuit()), SLOT(saveState()) );
400 mModelColumnManager->
store();
401 saveSplitterStates();
403 KConfigGroup group( Settings::self()->config(),
"UiState_ContactView" );
404 KPIM::UiStateSaver::saveState( mItemView, group );
407 delete mGrantleeThemeManager;
409 Settings::self()->writeConfig();
412 void MainWidget::restoreState()
416 Akonadi::ETMViewStateSaver *saver =
new Akonadi::ETMViewStateSaver;
417 saver->setView( mCollectionView );
419 const KConfigGroup group( Settings::self()->config(),
"CollectionViewState" );
420 saver->restoreState( group );
425 Akonadi::ETMViewStateSaver *saver =
new Akonadi::ETMViewStateSaver;
426 saver->setSelectionModel( mCollectionSelectionModel );
428 const KConfigGroup group( Settings::self()->config(),
"CollectionViewCheckState" );
429 saver->restoreState( group );
434 Akonadi::ETMViewStateSaver *saver =
new Akonadi::ETMViewStateSaver;
435 saver->setView( mItemView );
436 saver->setSelectionModel( mItemView->selectionModel() );
438 const KConfigGroup group( Settings::self()->config(),
"ItemViewState" );
439 saver->restoreState( group );
443 void MainWidget::saveState()
447 Akonadi::ETMViewStateSaver saver;
448 saver.setView( mCollectionView );
450 KConfigGroup group( Settings::self()->config(),
"CollectionViewState" );
451 saver.saveState( group );
457 Akonadi::ETMViewStateSaver saver;
458 saver.setSelectionModel( mCollectionSelectionModel );
460 KConfigGroup group( Settings::self()->config(),
"CollectionViewCheckState" );
461 saver.saveState( group );
467 Akonadi::ETMViewStateSaver saver;
468 saver.setView( mItemView );
469 saver.setSelectionModel( mItemView->selectionModel() );
471 KConfigGroup group( Settings::self()->config(),
"ItemViewState" );
472 saver.saveState( group );
477 void MainWidget::setupGui()
488 mMainWidgetSplitter1 =
new QSplitter(Qt::Horizontal);
490 layout->
addWidget( mMainWidgetSplitter1 );
497 mMainWidgetSplitter2 =
new QSplitter(Qt::Vertical);
499 mMainWidgetSplitter1->
addWidget( mMainWidgetSplitter2 );
502 mCollectionView =
new Akonadi::EntityTreeView();
503 mMainWidgetSplitter2->
addWidget( mCollectionView );
506 mItemView =
new Akonadi::EntityTreeView();
508 mItemView->setDefaultPopupMenu(
QLatin1String(
"akonadi_itemview_contextmenu" ) );
509 mItemView->setAlternatingRowColors(
true);
510 mMainWidgetSplitter2->
addWidget( mItemView );
514 mMainWidgetSplitter1->
addWidget( mDetailsPane );
526 detailsPaneLayout->
addWidget( mDetailsViewStack );
529 mContactDetails =
new Akonadi::ContactViewer( mDetailsViewStack );
530 mDetailsViewStack->
addWidget( mContactDetails );
533 mContactGroupDetails =
new Akonadi::ContactGroupViewer( mDetailsViewStack );
534 mDetailsViewStack->
addWidget( mContactGroupDetails );
537 mEmptyDetails =
new KTextBrowser( mDetailsViewStack );
538 mDetailsViewStack->
addWidget( mEmptyDetails );
542 detailsPaneLayout->
addWidget( mContactSwitcher );
553 Akonadi::ContactDefaultActions *
actions =
new Akonadi::ContactDefaultActions(
this );
554 actions->connectToView( mContactDetails );
555 actions->connectToView( mContactGroupDetails );
556 mFormatter =
new KAddressBookGrantlee::GrantleeContactFormatter;
558 mContactDetails->setContactFormatter( mFormatter );
560 mGroupFormatter =
new KAddressBookGrantlee::GrantleeContactGroupFormatter;
562 mContactGroupDetails->setContactGroupFormatter( mGroupFormatter );
565 void MainWidget::setupActions( KActionCollection *collection )
567 mGrantleeThemeManager =
new GrantleeTheme::GrantleeThemeManager(GrantleeTheme::GrantleeThemeManager::Addressbook,
QString::fromLatin1(
"theme.desktop" ), collection,
QLatin1String(
"kaddressbook/viewertemplates/"));
568 mGrantleeThemeManager->setDownloadNewStuffConfigFile(
QLatin1String(
"kaddressbook_themes.knsrc"));
569 connect(mGrantleeThemeManager, SIGNAL(grantleeThemeSelected()),
this, SLOT(slotGrantleeThemeSelected()));
570 connect(mGrantleeThemeManager, SIGNAL(updateThemes()),
this, SLOT(slotGrantleeThemesUpdated()));
573 KActionMenu *themeMenu =
new KActionMenu(i18n(
"&Themes"),
this);
574 collection->addAction(
QLatin1String(
"theme_menu"), themeMenu );
576 initGrantleeThemeName();
578 mGrantleeThemeManager->setThemeMenu(themeMenu);
579 mGrantleeThemeManager->setActionGroup(group);
581 KAction *action = KStandardAction::print(
this, SLOT(
print()), collection );
582 action->setWhatsThis(
583 i18nc(
"@info:whatsthis",
584 "Print the complete address book or a selected number of contacts." ) );
586 if(KPrintPreview::isAvailable())
587 KStandardAction::printPreview(
this, SLOT(
printPreview()), collection );
589 action = collection->addAction(
QLatin1String(
"quick_search") );
590 action->setText( i18n(
"Quick search" ) );
591 action->setDefaultWidget( mQuickSearchWidget );
593 action = collection->addAction(
QLatin1String(
"category_filter") );
594 action->setText( i18n(
"Category filter" ) );
595 action->setDefaultWidget( mCategorySelectWidget );
597 action = collection->addAction(
QLatin1String(
"select_all") );
598 action->setText( i18n(
"Select All" ) );
599 action->setShortcut(
QKeySequence( Qt::CTRL + Qt::Key_A ) );
600 action->setWhatsThis( i18n(
"Select all contacts in the current address book view." ) );
601 connect( action, SIGNAL(triggered(
bool)), mItemView, SLOT(selectAll()) );
603 #if defined(HAVE_PRISON)
604 KToggleAction *qrtoggleAction;
605 qrtoggleAction = collection->add<KToggleAction>(
QLatin1String(
"options_show_qrcodes") );
606 qrtoggleAction->setText( i18n(
"Show QR Codes" ) );
607 qrtoggleAction->setWhatsThis( i18n(
"Show QR Codes in the contact." ) );
608 connect( qrtoggleAction, SIGNAL(toggled(
bool)), SLOT(setQRCodeShow(
bool)) );
613 KAction *act =
new KAction( i18nc(
"@action:inmenu",
"Simple (one column)" ), mViewModeGroup );
614 act->setCheckable(
true );
616 act->setShortcut(
QKeySequence( Qt::CTRL + Qt::SHIFT + Qt::Key_1 ) );
617 act->setWhatsThis( i18n(
"Show a simple mode of the address book view." ) );
618 collection->addAction(
QLatin1String(
"view_mode_simple"), act );
620 act =
new KAction( i18nc(
"@action:inmenu",
"Two Columns" ), mViewModeGroup );
621 act->setCheckable(
true );
623 act->setShortcut(
QKeySequence( Qt::CTRL + Qt::SHIFT + Qt::Key_2 ) );
624 collection->addAction(
QLatin1String(
"view_mode_2columns"), act );
626 act =
new KAction( i18nc(
"@action:inmenu",
"Three Columns" ), mViewModeGroup );
627 act->setCheckable(
true );
629 act->setShortcut(
QKeySequence( Qt::CTRL + Qt::SHIFT + Qt::Key_3 ) );
630 collection->addAction(
QLatin1String(
"view_mode_3columns"), act );
635 action = collection->addAction(
QLatin1String(
"file_import_vcard") );
636 action->setText( i18n(
"Import vCard..." ) );
637 action->setWhatsThis( i18n(
"Import contacts from a vCard file." ) );
640 action = collection->addAction(
QLatin1String(
"file_import_csv") );
641 action->setText( i18n(
"Import CSV file..." ) );
642 action->setWhatsThis( i18n(
"Import contacts from a file in comma separated value format." ) );
645 action = collection->addAction(
QLatin1String(
"file_import_ldif") );
646 action->setText( i18n(
"Import LDIF file..." ) );
647 action->setWhatsThis( i18n(
"Import contacts from an LDIF file." ) );
650 action = collection->addAction(
QLatin1String(
"file_import_ldap") );
651 action->setText( i18n(
"Import From LDAP server..." ) );
652 action->setWhatsThis( i18n(
"Import contacts from an LDAP server." ) );
655 action = collection->addAction(
QLatin1String(
"file_import_gmx") );
656 action->setText( i18n(
"Import GMX file..." ) );
657 action->setWhatsThis( i18n(
"Import contacts from a GMX address book file." ) );
661 action = collection->addAction(
QLatin1String(
"file_export_vcard40") );
662 action->setText( i18n(
"Export vCard 4.0..." ) );
663 action->setWhatsThis( i18n(
"Export contacts to a vCard 4.0 file." ) );
666 action = collection->addAction(
QLatin1String(
"file_export_vcard30") );
667 action->setText( i18n(
"Export vCard 3.0..." ) );
668 action->setWhatsThis( i18n(
"Export contacts to a vCard 3.0 file." ) );
671 action = collection->addAction(
QLatin1String(
"file_export_vcard21") );
672 action->setText( i18n(
"Export vCard 2.1..." ) );
673 action->setWhatsThis( i18n(
"Export contacts to a vCard 2.1 file." ) );
676 action = collection->addAction(
QLatin1String(
"file_export_csv") );
677 action->setText( i18n(
"Export CSV file..." ) );
678 action->setWhatsThis( i18n(
"Export contacts to a file in comma separated value format." ) );
681 action = collection->addAction(
QLatin1String(
"file_export_ldif") );
682 action->setText( i18n(
"Export LDIF file..." ) );
683 action->setWhatsThis( i18n(
"Export contacts to an LDIF file." ) );
686 action = collection->addAction(
QLatin1String(
"file_export_gmx") );
687 action->setText( i18n(
"Export GMX file..." ) );
688 action->setWhatsThis( i18n(
"Export contacts to a GMX address book file." ) );
691 KToggleAction *actTheme = mGrantleeThemeManager->actionForTheme();
693 actTheme->setChecked(
true);
695 action = collection->addAction(
QLatin1String(
"merge_contacts") );
696 action->setText( i18n(
"Merge Contacts..." ) );
699 action = collection->addAction(
QLatin1String(
"search_duplicate_contacts") );
700 action->setText( i18n(
"Search Duplicate Contacts..." ) );
703 mQuickSearchAction =
new KAction( i18n(
"Set Focus to Quick Search"),
this );
705 mQuickSearchAction->setShortcut(
QKeySequence( Qt::ALT + Qt::Key_Q ) );
706 collection->addAction(
QLatin1String(
"focus_to_quickseach"), mQuickSearchAction );
707 connect( mQuickSearchAction, SIGNAL(triggered(
bool)), mQuickSearchWidget, SLOT(slotFocusQuickSearch()) );
709 action = collection->addAction(
QLatin1String(
"send_mail") );
710 action->setText( i18n(
"Send an email...") );
711 action->setIcon(KIconLoader::global()->loadIcon(
QLatin1String(
"mail-message-new"), KIconLoader::Small ));
712 connect( action, SIGNAL(triggered(
bool)),
this, SLOT(slotSendMail()));
714 #if 0 //Activate it for kf5
715 action = collection->addAction(
QLatin1String(
"send_vcards") );
717 action->setIcon(KIconLoader::global()->loadIcon(
QLatin1String(
"mail-message-new"), KIconLoader::Small ));
718 connect( action, SIGNAL(triggered(
bool)),
this, SLOT(slotSendVcards()));
721 if (!qgetenv(
"KDEPIM_BALOO_DEBUG").isEmpty()) {
722 action = collection->addAction(
QLatin1String(
"debug_baloo") );
725 connect( action, SIGNAL(triggered(
bool)),
this, SLOT(slotDebugBaloo()));
737 KPrintPreview previewdlg( &printer,
this );
741 const int result = wizard.exec();
744 Settings::self()->setPrintingStyle( wizard.printingStyle() );
745 Settings::self()->setSortOrder( wizard.sortOrder() );
759 printDialog->setWindowTitle( i18n(
"Print Contacts" ) );
760 if ( !printDialog->exec() || !printDialog ) {
770 Settings::self()->setPrintingStyle( wizard.printingStyle() );
771 Settings::self()->setSortOrder( wizard.sortOrder() );
776 mActionManager->action( Akonadi::StandardContactActionManager::CreateContact )->trigger();
781 mActionManager->action( Akonadi::StandardContactActionManager::CreateContactGroup )->trigger();
789 void MainWidget::itemSelected(
const Akonadi::Item &item )
791 if ( Akonadi::MimeTypeChecker::isWantedItem( item, KABC::Addressee::mimeType() ) ) {
793 mContactDetails->setContact( item );
794 }
else if ( Akonadi::MimeTypeChecker::isWantedItem( item, KABC::ContactGroup::mimeType() ) ) {
796 mContactGroupDetails->setContactGroup( item );
811 void MainWidget::selectFirstItem()
815 if ( mItemView && mItemView->selectionModel() ) {
816 mItemView->selectionModel()->setCurrentIndex( mItemView->model()->index( 0, 0 ),
817 QItemSelectionModel::Rows |
818 QItemSelectionModel::ClearAndSelect );
822 bool MainWidget::showQRCodes()
824 #if defined(HAVE_PRISON)
827 return group.readEntry(
"QRCodes",
true );
833 void MainWidget::setQRCodeShow(
bool on )
835 #if defined(HAVE_PRISON)
839 group.writeEntry(
"QRCodes", on );
840 if ( mItemView->model() ) {
841 mItemView->setCurrentIndex( mItemView->model()->index( 0, 0 ) );
848 Akonadi::Collection MainWidget::currentAddressBook()
const
850 if ( mCollectionView->selectionModel() && mCollectionView->selectionModel()->hasSelection() ) {
851 const QModelIndex index = mCollectionView->selectionModel()->selectedIndexes().first();
852 const Akonadi::Collection collection =
853 index.
data( Akonadi::EntityTreeModel::CollectionRole ).
value<Akonadi::Collection>();
858 return Akonadi::Collection();
863 if ( !mAllContactsModel ) {
864 KDescendantsProxyModel *descendantsModel =
new KDescendantsProxyModel(
this );
867 mAllContactsModel =
new Akonadi::EntityMimeTypeFilterModel(
this );
868 mAllContactsModel->setSourceModel( descendantsModel );
869 mAllContactsModel->addMimeTypeExclusionFilter( Akonadi::Collection::mimeType() );
870 mAllContactsModel->setHeaderGroup( Akonadi::EntityTreeModel::ItemListHeaders );
873 return mAllContactsModel;
876 void MainWidget::setViewMode(
QAction *action )
881 void MainWidget::setViewMode(
int mode )
883 int currentMode = Settings::self()->viewMode();
885 if ( mode == currentMode )
return;
890 saveSplitterStates();
904 else if ( mode == 3 ) {
909 Settings::self()->setViewMode( mode );
910 restoreSplitterStates();
911 mViewModeGroup->
actions().at( mode-1 )->setChecked(
true );
913 if ( mItemView->model() ) {
914 mItemView->setCurrentIndex( mItemView->model()->index( 0, 0 ) );
918 void MainWidget::saveSplitterStates()
const
922 int currentMode = Settings::self()->viewMode();
923 if ( currentMode == 1 )
928 KConfigGroup group( Settings::self()->config(), groupName );
929 KPIM::UiStateSaver::saveState( mMainWidgetSplitter1, group );
930 KPIM::UiStateSaver::saveState( mMainWidgetSplitter2, group );
933 void MainWidget::restoreSplitterStates()
937 int currentMode = Settings::self()->viewMode();
938 if ( currentMode == 1 )
943 KConfigGroup group( Settings::self()->config(), groupName );
944 KPIM::UiStateSaver::restoreState( mMainWidgetSplitter1, group );
945 KPIM::UiStateSaver::restoreState( mMainWidgetSplitter2, group );
948 void MainWidget::initGrantleeThemeName()
950 QString themeName = GrantleeTheme::GrantleeSettings::self()->grantleeAddressBookThemeName();
954 mFormatter->setGrantleeTheme(mGrantleeThemeManager->theme(themeName));
955 mGroupFormatter->setGrantleeTheme(mGrantleeThemeManager->theme(themeName));
958 void MainWidget::slotGrantleeThemeSelected()
960 initGrantleeThemeName();
961 if ( mItemView->model() ) {
962 mItemView->setCurrentIndex( mItemView->model()->index( 0, 0 ) );
966 void MainWidget::slotGrantleeThemesUpdated()
968 if ( mItemView->model() ) {
969 mItemView->setCurrentIndex( mItemView->model()->index( 0, 0 ) );
977 dlg->setContacts(lst);
986 dlg->searchPotentialDuplicateContacts(lst);
991 Akonadi::EntityTreeModel *MainWidget::entityTreeModel()
const
995 Akonadi::EntityTreeModel *etm = qobject_cast<Akonadi::EntityTreeModel*>( proxy->
sourceModel() );
1002 kWarning() <<
"Couldn't find EntityTreeModel";
1006 void MainWidget::slotCheckNewCalendar(
const QModelIndex &parent,
int begin,
int end )
1010 if ( begin < end ) {
1014 Akonadi::EntityTreeModel *etm = entityTreeModel();
1016 if ( etm && etm->isCollectionTreeFetched() ) {
1017 for(
int row=begin; row<=end; ++row ) {
1020 model->
setData( index, Qt::Checked, Qt::CheckStateRole );
1021 slotCheckNewCalendar( index, 0, model->
rowCount(index) - 1 );
1025 mCollectionView->setExpanded( parent,
true );
1030 void MainWidget::slotSendVcards()
1032 const Akonadi::Item::List lst = collectSelectedAllContactsItem(mItemView->selectionModel());
1033 if (!lst.isEmpty()) {
1036 sendVcards->
start();
1040 void MainWidget::slotSendVcardsError(
const QString &error)
1042 KMessageBox::error(
this, error );
1045 void MainWidget::slotSendMail()
1047 const Akonadi::Item::List lst = collectSelectedAllContactsItem(mItemView->selectionModel());
1048 if (!lst.isEmpty()) {
1051 mailSender->
start();
1053 KMessageBox::sorry(
this, i18n(
"You have not selected any contacts." ) );
1057 void MainWidget::slotSendMails(
const QStringList &emails)
1063 KToolInvocation::invokeMailer( url );
1067 void MainWidget::slotDebugBaloo()
1069 const Akonadi::Item::List lst = collectSelectedAllContactsItem(mItemView->selectionModel());
1070 if (lst.isEmpty()) {
1074 dlg->setAkonadiId(lst.at(0).id());
1075 dlg->setAttribute( Qt::WA_DeleteOnClose );
1076 dlg->setSearchType(PimCommon::BalooDebugSearchPathComboBox::Contacts);
1081 const Akonadi::Item::List MainWidget::collectSelectedAllContactsItem(
QItemSelectionModel *model)
1083 Akonadi::Item::List lst;
1085 const QModelIndexList indexes = model->
selectedRows( 0 );
1086 for (
int i = 0; i < indexes.count(); ++i ) {
1089 const Akonadi::Item item =
1090 index.
data( Akonadi::EntityTreeModel::ItemRole ).
value<Akonadi::Item>();
1091 if ( item.isValid() ) {
1092 if ( item.hasPayload<KABC::Addressee>() || item.hasPayload<KABC::ContactGroup>() ) {
virtual int rowCount(const QModelIndex &parent) const =0
void store()
Stores the user configuration.
virtual QModelIndex index(int row, int column, const QModelIndex &parent) const =0
void setOutputFileName(const QString &fileName)
XXPortManager * importManager() const
void setStretchFactor(int index, int stretch)
virtual void setSourceModel(QAbstractItemModel *sourceModel)
The PrintingWizard combines pages common for all print styles and those provided by the respective st...
bool registerObject(const QString &path, QObject *object, QFlags< QDBusConnection::RegisterOption > options)
bool contains(const QString &str, Qt::CaseSensitivity cs) const
void setDefaultAddressBook(const Akonadi::Collection &addressBook)
Sets the default addressbook of the contact selection.
Akonadi::Item::List collectSelectedContactsItem(QItemSelectionModel *model)
QDBusConnection sessionBus()
void importFile(const KUrl &url)
QString join(const QString &separator) const
A proxy model to filter contacts by categories (tags).
void setOrientation(Qt::Orientation)
QString outputFileName() const
void setChildrenCollapsible(bool)
int toInt(bool *ok) const
void setSelectionModel(QItemSelectionModel *model)
Sets the model that contains the current selection.
void setObjectName(const QString &name)
QModelIndexList selectedRows(int column) const
void addImportAction(QAction *action, const QString &identifier)
Adds a new action to import contacts.
void setDocName(const QString &name)
void load()
Loads the user configuration and applies it to the model.
void setMargin(int margin)
void setWidget(QWidget *view)
Sets the widget that shall provide a RMB menu to configure the columns to be shown.
QList< QAction * > actions() const
QAbstractItemModel * sourceModel() const
void setFilterEnabled(bool enable)
Enable or disable the filter.
MainWidget(KXMLGUIClient *guiClient, QWidget *parent=0)
QVariant data(int role) const
The class that manages import and export of contacts.
void updateQuickSearchText()
void slotSearchDuplicateContacts()
virtual bool setData(const QModelIndex &index, const QVariant &value, int role)
void setFilterCategories(const QList< Akonadi::Tag::Id > &idList)
Set the categories to be accepted by the filter.
QString fromLatin1(const char *str, int size)
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
A manager for the contacts model columns.
QString arg(qlonglong a, int fieldWidth, int base, const QChar &fillChar) const
void setCollateCopies(bool collate)
void addExportAction(QAction *action, const QString &identifier)
Adds a new action to export contacts.