2 This file is part of KOrganizer.
4 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
5 Copyright (C) 2003-2004 Reinhold Kainhofer <reinhold@kainhofer.com>
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License along
18 with this program; if not, write to the Free Software Foundation, Inc.,
19 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21 As a special exception, permission is given to link this program
22 with any edition of Qt, and distribute the resulting executable,
23 without including the source code for Qt in the source distribution.
26 #include "kodialogmanager.h"
27 #include "calendarview.h"
28 #include "dialog/filtereditdialog.h"
29 #include "prefs/koprefs.h"
30 #include "dialog/searchdialog.h"
32 #include <PimCommon/PimUtil>
33 #include <CalendarSupport/ArchiveDialog>
34 #include <CalendarSupport/CategoryConfig>
35 #include <CalendarSupport/Utils>
37 #include <IncidenceEditor/CategoryEditDialog>
38 #include <IncidenceEditor/IncidenceDialog>
39 #include <IncidenceEditor/IncidenceDialogFactory>
41 #include <AkonadiCore/Item>
42 #include <AkonadiWidgets/TagManagementDialog>
44 #include <KCalCore/Visitor>
46 #include <KCMultiDialog>
47 #include <QPushButton>
51 // FIXME: Handle KOEventViewerDialogs in dialog manager.
53 class KODialogManager::DialogManagerVisitor
: public KCalCore::Visitor
56 DialogManagerVisitor() : mDialogManager(Q_NULLPTR
) {}
58 bool act(KCalCore::IncidenceBase::Ptr incidence
, KODialogManager
*manager
)
60 mDialogManager
= manager
;
61 return incidence
->accept(*this, incidence
);
65 KODialogManager
*mDialogManager
;
68 KODialogManager::KODialogManager(CalendarView
*mainView
)
69 : QObject(), mMainView(mainView
)
71 mOptionsDialog
= Q_NULLPTR
;
72 mSearchDialog
= Q_NULLPTR
;
73 mArchiveDialog
= Q_NULLPTR
;
74 mFilterEditDialog
= Q_NULLPTR
;
75 mCategoryEditDialog
= Q_NULLPTR
;
78 KODialogManager::~KODialogManager()
80 delete mOptionsDialog
;
82 delete mArchiveDialog
;
83 delete mFilterEditDialog
;
84 delete mCategoryEditDialog
;
87 void KODialogManager::showOptionsDialog()
89 if (!mOptionsDialog
) {
90 mOptionsDialog
= new KCMultiDialog(mMainView
);
91 connect(mOptionsDialog
, SIGNAL(configCommitted(QByteArray
)),
92 mMainView
, SLOT(updateConfig(QByteArray
)));
95 modules
.append(QStringLiteral("korganizer_configmain.desktop"));
96 modules
.append(QStringLiteral("korganizer_configtime.desktop"));
97 modules
.append(QStringLiteral("korganizer_configviews.desktop"));
98 modules
.append(QStringLiteral("korganizer_configcolorsandfonts.desktop"));
99 modules
.append(QStringLiteral("korganizer_configgroupscheduling.desktop"));
100 modules
.append(QStringLiteral("korganizer_configfreebusy.desktop"));
101 modules
.append(QStringLiteral("korganizer_configplugins.desktop"));
102 modules
.append(QStringLiteral("korganizer_configdesignerfields.desktop"));
105 QStringList::iterator mit
;
106 for (mit
= modules
.begin(); mit
!= modules
.end(); ++mit
) {
107 mOptionsDialog
->addModule(*mit
);
111 mOptionsDialog
->show();
112 mOptionsDialog
->raise();
115 void KODialogManager::showCategoryEditDialog()
117 createCategoryEditor();
118 mCategoryEditDialog
->exec();
121 void KODialogManager::showSearchDialog()
123 if (!mSearchDialog
) {
124 mSearchDialog
= new SearchDialog(mMainView
);
125 //mSearchDialog->setCalendar( mMainView->calendar() );
126 connect(mSearchDialog
, SIGNAL(showIncidenceSignal(Akonadi::Item
)), mMainView
, SLOT(showIncidence(Akonadi::Item
)));
127 connect(mSearchDialog
, SIGNAL(editIncidenceSignal(Akonadi::Item
)), mMainView
, SLOT(editIncidence(Akonadi::Item
)));
128 connect(mSearchDialog
, SIGNAL(deleteIncidenceSignal(Akonadi::Item
)), mMainView
, SLOT(deleteIncidence(Akonadi::Item
)));
130 // make sure the widget is on top again
131 mSearchDialog
->show();
132 mSearchDialog
->raise();
135 void KODialogManager::showArchiveDialog()
137 if (!mArchiveDialog
) {
139 new CalendarSupport::ArchiveDialog(mMainView
->calendar(), mMainView
->incidenceChanger());
140 connect(mArchiveDialog
, SIGNAL(eventsDeleted()), mMainView
, SLOT(updateView()));
141 connect(mArchiveDialog
, &CalendarSupport::ArchiveDialog::autoArchivingSettingsModified
, mMainView
, &CalendarView::slotAutoArchivingSettingsModified
);
143 mArchiveDialog
->show();
144 mArchiveDialog
->raise();
147 QApplication::restoreOverrideCursor();
150 void KODialogManager::showFilterEditDialog(QList
<KCalCore::CalFilter
*> *filters
)
152 createCategoryEditor();
153 if (!mFilterEditDialog
) {
154 mFilterEditDialog
= new FilterEditDialog(filters
, mMainView
);
155 connect(mFilterEditDialog
, &FilterEditDialog::filterChanged
, mMainView
, &CalendarView::updateFilter
);
156 connect(mFilterEditDialog
, &FilterEditDialog::editCategories
, mCategoryEditDialog
.data(), &QWidget::show
);
158 connect(mCategoryEditDialog
, SIGNAL(categoryConfigChanged()),
159 mFilterEditDialog
, SLOT(updateCategoryConfig()));
162 mFilterEditDialog
->show();
163 mFilterEditDialog
->raise();
166 IncidenceEditorNG::IncidenceDialog
*KODialogManager::createDialog(const Akonadi::Item
&item
)
168 const KCalCore::Incidence::Ptr incidence
= CalendarSupport::incidence(item
);
173 IncidenceEditorNG::IncidenceDialog
*dialog
=
174 IncidenceEditorNG::IncidenceDialogFactory::create(
175 /*needs initial saving=*/false,
176 incidence
->type(), mMainView
->incidenceChanger(), mMainView
);
181 void KODialogManager::connectTypeAhead(IncidenceEditorNG::IncidenceDialog
*dialog
,
184 if (dialog
&& view
) {
185 view
->setTypeAheadReceiver(dialog
->typeAheadReceiver());
189 void KODialogManager::connectEditor(IncidenceEditorNG::IncidenceDialog
*editor
)
191 createCategoryEditor();
192 connect(editor
, SIGNAL(deleteIncidenceSignal(Akonadi::Item
)), mMainView
, SLOT(deleteIncidence(Akonadi::Item
)));
194 connect(editor
, SIGNAL(dialogClose(Akonadi::Item
)), mMainView
, SLOT(dialogClosing(Akonadi::Item
)));
195 connect(editor
, SIGNAL(deleteAttendee(Akonadi::Item
)), mMainView
, SIGNAL(cancelAttendees(Akonadi::Item
)));
198 void KODialogManager::updateSearchDialog()
201 mSearchDialog
->updateView();
205 void KODialogManager::createCategoryEditor()
207 if (mCategoryEditDialog
== Q_NULLPTR
) {
208 mCategoryEditDialog
= new Akonadi::TagManagementDialog(mMainView
);
209 mCategoryEditDialog
->buttons()->setStandardButtons(QDialogButtonBox::Ok
| QDialogButtonBox::Cancel
| QDialogButtonBox::Help
);
210 connect(mCategoryEditDialog
->buttons()->button(QDialogButtonBox::Help
), &QPushButton::clicked
, this, &KODialogManager::slotHelp
);
212 mCategoryEditDialog
->setModal(true);
216 void KODialogManager::slotHelp()
218 PimCommon::Util::invokeHelp(QStringLiteral("korganizer/categories-view.html"));