actionmanager.cpp 63.3 KB
Newer Older
1
2
3
4
5
6
7
8
/*
  This file is part of KOrganizer.

  Copyright (c) 2002 Mike Pilone <mpilone@slac.com>
  Copyright (c) 2002 Don Sanders <sanders@kde.org>
  Copyright (c) 2004 Cornelius Schumacher <schumacher@kde.org>
  Copyright (C) 2004 Reinhold Kainhofer <reinhold@kainhofer.com>
  Copyright (c) 2005 Rafal Rzepecki <divide@users.sourceforge.net>
Laurent Montel's avatar
Laurent Montel committed
9
  Copyright (c) 2010-2019 Laurent Montel <montel@kde.org>
Allen Winter's avatar
Allen Winter committed
10
  Copyright (c) 2012-2019 Allen Winter <winter@kde.org>
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29

  This program is free software; you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation; either version 2 of the License, or
  (at your option) any later version.

  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  GNU General Public License for more details.

  You should have received a copy of the GNU General Public License along
  with this program; if not, write to the Free Software Foundation, Inc.,
  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

  As a special exception, permission is given to link this program
  with any edition of Qt, and distribute the resulting executable,
  without including the source code for Qt in the source distribution.
*/
30
#include <config-korganizer.h>
31
#include "actionmanager.h"
Allen Winter's avatar
Allen Winter committed
32
#include "akonadicollectionview.h"
33
34
35
36
#include "calendaradaptor.h"
#include "calendarview.h"
#include "kocore.h"
#include "kodialogmanager.h"
37
#include "korganizeradaptor.h"
38
#include "koglobals.h"
Laurent Montel's avatar
Laurent Montel committed
39
#include "prefs/koprefs.h"
40
41
#include "koviewmanager.h"
#include "kowindowlist.h"
42
#include "kocheckableproxymodel.h"
43
#include <KAuthorized>
Laurent Montel's avatar
Laurent Montel committed
44
#include "KdepimDBusInterfaces/ReminderClient"
45

Laurent Montel's avatar
Laurent Montel committed
46
47
48
49
#include <CalendarSupport/CollectionSelection>
#include <CalendarSupport/EventArchiver>
#include <CalendarSupport/KCalPrefs>
#include <CalendarSupport/Utils>
50

51
#include <IncidenceEditor/IncidenceEditorSettings>
52

Laurent Montel's avatar
Laurent Montel committed
53
54
55
56
#include <AkonadiCore/EntityDisplayAttribute>
#include <AkonadiWidgets/EntityTreeView>
#include <AkonadiCore/EntityTreeModel>
#include <AkonadiWidgets/ETMViewStateSaver>
Sergio Martins's avatar
Sergio Martins committed
57
#include <Akonadi/Calendar/History>
58
#include <Akonadi/Calendar/ICalImporter>
Allen Winter's avatar
Allen Winter committed
59

60
61
62
#include <KCalendarCore/FileStorage>
#include <KCalendarCore/ICalFormat>
#include <KCalendarCore/Person>
63

Allen Winter's avatar
Allen Winter committed
64
#include <KMime/KMimeMessage>
65
66
67
#include <KJobWidgets>
#include <KIO/StatJob>
#include <KIO/FileCopyJob>
Allen Winter's avatar
Allen Winter committed
68

Laurent Montel's avatar
Laurent Montel committed
69
#include <QAction>
70
#include <KActionCollection>
Laurent Montel's avatar
Laurent Montel committed
71
#include <QFileDialog>
Laurent Montel's avatar
Laurent Montel committed
72
#include <QMenu>
Laurent Montel's avatar
Laurent Montel committed
73
#include <QMenuBar>
74
#include <KMessageBox>
75
76
77
78
#include <KProcess>
#include <KSelectAction>
#include <KShortcutsDialog>
#include <KStandardAction>
Laurent Montel's avatar
Laurent Montel committed
79

Laurent Montel's avatar
Laurent Montel committed
80
#include <QTemporaryFile>
81
82
#include <KToggleAction>
#include <KWindowSystem>
Allen Winter's avatar
Allen Winter committed
83
#include <KNS3/DownloadDialog>
Laurent Montel's avatar
Laurent Montel committed
84
#include <QIcon>
Laurent Montel's avatar
Laurent Montel committed
85
#include "korganizer_debug.h"
86
#include "korganizer_options.h"
87
88

#include <QApplication>
89
#include <QTimer>
90
#include <KSharedConfig>
Laurent Montel's avatar
Laurent Montel committed
91
#include <QStandardPaths>
92

Laurent Montel's avatar
Laurent Montel committed
93
KOWindowList *ActionManager::mWindowList = nullptr;
94

Laurent Montel's avatar
Laurent Montel committed
95
ActionManager::ActionManager(KXMLGUIClient *client, CalendarView *widget, QObject *parent, KOrg::MainWindow *mainWindow, bool isPart, QMenuBar *menuBar)
Laurent Montel's avatar
Laurent Montel committed
96
97
98
99
100
    : QObject(parent)
    , mCollectionViewShowAction(nullptr)
    , mCollectionView(nullptr)
    , mCollectionViewStateSaver(nullptr)
    , mCollectionSelectionModelStateSaver(nullptr)
101
{
Laurent Montel's avatar
Laurent Montel committed
102
    new KOrgCalendarAdaptor(this);
Laurent Montel's avatar
Laurent Montel committed
103
    QDBusConnection::sessionBus().registerObject(QStringLiteral("/Calendar"), this);
104

Laurent Montel's avatar
Laurent Montel committed
105
106
107
108
    mGUIClient = client;
    mACollection = mGUIClient->actionCollection();
    mCalendarView = widget;
    mIsPart = isPart;
Laurent Montel's avatar
Laurent Montel committed
109
    mTempFile = nullptr;
Laurent Montel's avatar
Laurent Montel committed
110
111
    mMainWindow = mainWindow;
    mMenuBar = menuBar;
112
113
114
115
}

ActionManager::~ActionManager()
{
Laurent Montel's avatar
Laurent Montel committed
116
117
    // Remove Part plugins
    KOCore::self()->unloadParts(mMainWindow, mParts);
118

Laurent Montel's avatar
Laurent Montel committed
119
    delete mTempFile;
120

Laurent Montel's avatar
Laurent Montel committed
121
122
    // Take this window out of the window list.
    mWindowList->removeWindow(mMainWindow);
123

Laurent Montel's avatar
Laurent Montel committed
124
125
    delete mCollectionSelectionModelStateSaver;
    delete mCollectionViewStateSaver;
126

Laurent Montel's avatar
Laurent Montel committed
127
    delete mCalendarView;
128
129
}

Laurent Montel's avatar
Laurent Montel committed
130
void ActionManager::toggleMenubar(bool dontShowWarning)
131
{
Laurent Montel's avatar
Laurent Montel committed
132
133
134
135
136
    if (mMenuBar) {
        if (mHideMenuBarAction->isChecked()) {
            mMenuBar->show();
        } else {
            if (!dontShowWarning) {
Laurent Montel's avatar
Laurent Montel committed
137
                const QString accel = mHideMenuBarAction->shortcut().toString();
Laurent Montel's avatar
Laurent Montel committed
138
139
140
                KMessageBox::information(mCalendarView,
                                         i18n("<qt>This will hide the menu bar completely."
                                              " You can show it again by typing %1.</qt>", accel),
Laurent Montel's avatar
Laurent Montel committed
141
142
                                         i18n("Hide menu bar"),
                                         QStringLiteral("HideMenuBarWarning"));
Laurent Montel's avatar
Laurent Montel committed
143
144
145
146
147
            }
            mMenuBar->hide();
        }
        KOPrefs::instance()->setShowMenuBar(mHideMenuBarAction->isChecked());
    }
148
}
Laurent Montel's avatar
Laurent Montel committed
149

150
151
152
// see the Note: below for why this method is necessary
void ActionManager::init()
{
Laurent Montel's avatar
Laurent Montel committed
153
154
155
    // add this instance of the window to the static list.
    if (!mWindowList) {
        mWindowList = new KOWindowList;
156
157
    }

Laurent Montel's avatar
Laurent Montel committed
158
159
160
161
    // Note: We need this ActionManager to be fully constructed, and
    // parent() to have a valid reference to it before the following
    // addWindow is called.
    mWindowList->addWindow(mMainWindow);
162

Laurent Montel's avatar
Minor    
Laurent Montel committed
163
    // initialize the QAction instances
Laurent Montel's avatar
Laurent Montel committed
164
    initActions();
165

Laurent Montel's avatar
Laurent Montel committed
166
167
168
169
    // set up autoSaving stuff
    mAutoArchiveTimer = new QTimer(this);
    mAutoArchiveTimer->setSingleShot(true);
    connect(mAutoArchiveTimer, &QTimer::timeout, this, &ActionManager::slotAutoArchive);
170

Laurent Montel's avatar
Laurent Montel committed
171
172
173
174
    // First auto-archive should be in 5 minutes (like in kmail).
    if (CalendarSupport::KCalPrefs::instance()->mAutoArchive) {
        mAutoArchiveTimer->start(5 * 60 * 1000);   // singleshot
    }
175

Laurent Montel's avatar
Laurent Montel committed
176
    setTitle();
177

Laurent Montel's avatar
Laurent Montel committed
178
179
    connect(mCalendarView, &CalendarView::modifiedChanged, this, &ActionManager::setTitle);
    connect(mCalendarView, &CalendarView::configChanged, this, &ActionManager::updateConfig);
180

181
182
    connect(mCalendarView, &CalendarView::incidenceSelected,
            this, &ActionManager::processIncidenceSelection);
183

Laurent Montel's avatar
Laurent Montel committed
184
    processIncidenceSelection(Akonadi::Item(), QDate());
185

Laurent Montel's avatar
Laurent Montel committed
186
187
    // Update state of paste action
    mCalendarView->checkClipboard();
188
189
}

190
191
Akonadi::ETMCalendar::Ptr ActionManager::calendar() const
{
Laurent Montel's avatar
Laurent Montel committed
192
    return mCalendarView->calendar();
193
194
}

195
196
void ActionManager::createCalendarAkonadi()
{
Laurent Montel's avatar
Laurent Montel committed
197
    Q_ASSERT(calendar());
198

199
    KSharedConfig::Ptr config = KSharedConfig::openConfig();
Laurent Montel's avatar
Laurent Montel committed
200
201
    mCollectionSelectionModelStateSaver
        = new KViewStateMaintainer<Akonadi::ETMViewStateSaver>(
Laurent Montel's avatar
Laurent Montel committed
202
              config->group("GlobalCollectionSelection"));
Laurent Montel's avatar
Laurent Montel committed
203
204
    mCollectionSelectionModelStateSaver->setSelectionModel(
        calendar()->checkableProxyModel()->selectionModel());
205

Laurent Montel's avatar
Laurent Montel committed
206
207
208
    AkonadiCollectionViewFactory factory(mCalendarView);
    mCalendarView->addExtension(&factory);
    mCollectionView = factory.collectionView();
Laurent Montel's avatar
Laurent Montel committed
209
    mCollectionView->setObjectName(QStringLiteral("Resource View"));
210
211
212
    connect(mCollectionView, &AkonadiCollectionView::resourcesAddedRemoved,
            this, &ActionManager::slotResourcesAddedRemoved);

213
214
    connect(mCollectionView, &AkonadiCollectionView::defaultResourceChanged,
            this, &ActionManager::slotDefaultResourceChanged);
215

216
    connect(mCollectionView, &AkonadiCollectionView::colorsChanged,
217
            mCalendarView, qOverload<>(&CalendarView::updateConfig));
218

Laurent Montel's avatar
Laurent Montel committed
219
220
    mCollectionViewStateSaver
        = new KViewStateMaintainer<Akonadi::ETMViewStateSaver>(config->group("GlobalCollectionView"));
Laurent Montel's avatar
Laurent Montel committed
221
    mCollectionViewStateSaver->setView(mCollectionView->view());
222

Laurent Montel's avatar
Laurent Montel committed
223
    KCheckableProxyModel *checkableProxy = calendar()->checkableProxyModel();
Laurent Montel's avatar
Laurent Montel committed
224
    QItemSelectionModel *selectionModel = checkableProxy->selectionModel();
Sergio Martins's avatar
Sergio Martins committed
225

Laurent Montel's avatar
Laurent Montel committed
226
    mCollectionView->setCollectionSelectionProxyModel(checkableProxy);
227

Laurent Montel's avatar
Laurent Montel committed
228
229
    CalendarSupport::CollectionSelection *collectionSelection
        = new CalendarSupport::CollectionSelection(selectionModel);
Laurent Montel's avatar
Laurent Montel committed
230
    EventViews::EventView::setGlobalCollectionSelection(collectionSelection);
231

Laurent Montel's avatar
Laurent Montel committed
232
    mCalendarView->readSettings();
233

234
235
    connect(calendar().data(), &Akonadi::ETMCalendar::calendarChanged,
            mCalendarView, &CalendarView::resourcesChanged);
Laurent Montel's avatar
Laurent Montel committed
236
    connect(mCalendarView, &CalendarView::configChanged, this, &ActionManager::updateConfig);
237

238
    calendar()->setOwner(KCalendarCore::Person(CalendarSupport::KCalPrefs::instance()->fullName(),
Laurent Montel's avatar
Laurent Montel committed
239
                                                                    CalendarSupport::KCalPrefs::
240
                                                                    instance()->email()));
241
242
243
244
}

void ActionManager::initActions()
{
Laurent Montel's avatar
Laurent Montel committed
245
    QAction *action = nullptr;
Laurent Montel's avatar
Laurent Montel committed
246
247
248
249
250
251
252

    /*************************** FILE MENU **********************************/

    //~~~~~~~~~~~~~~~~~~~~~~~ LOADING / SAVING ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    if (mIsPart) {
        if (mMainWindow->hasDocument()) {
            QAction *a = mACollection->addAction(KStandardAction::Open, this, SLOT(file_open()));
Laurent Montel's avatar
Laurent Montel committed
253
            mACollection->addAction(QStringLiteral("korganizer_open"), a);
Laurent Montel's avatar
Laurent Montel committed
254
255
256
        }

        QAction *a = mACollection->addAction(KStandardAction::Print, mCalendarView, SLOT(print()));
Laurent Montel's avatar
Laurent Montel committed
257
        mACollection->addAction(QStringLiteral("korganizer_print"), a);
Laurent Montel's avatar
Laurent Montel committed
258
259
260
        a
            = mACollection->addAction(KStandardAction::PrintPreview, mCalendarView,
                                      SLOT(printPreview()));
Laurent Montel's avatar
Laurent Montel committed
261
        mACollection->addAction(QStringLiteral("korganizer_print_preview"), a);
Laurent Montel's avatar
Laurent Montel committed
262
    } else {
263
        KStandardAction::open(this, qOverload<>(&ActionManager::file_open), mACollection);
Laurent Montel's avatar
Laurent Montel committed
264
265
        KStandardAction::print(mCalendarView, &CalendarView::print, mACollection);
        KStandardAction::printPreview(mCalendarView, &CalendarView::printPreview, mACollection);
Laurent Montel's avatar
Laurent Montel committed
266
267
268
269
270
271
272
273
    }

    //~~~~~~~~~~~~~~~~~~~~~~~~ IMPORT / EXPORT ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    mImportAction = new QAction(i18n("Import &Calendar..."), this);
    setHelpText(mImportAction, i18n("Merge the contents of another iCalendar"));
    mImportAction->setWhatsThis(
        i18n("Select this menu entry if you would like to merge the contents "
             "of another iCalendar into your current calendar."));
Laurent Montel's avatar
Laurent Montel committed
274
    mACollection->addAction(QStringLiteral("import_icalendar"), mImportAction);
Laurent Montel's avatar
Laurent Montel committed
275
276
    connect(mImportAction, &QAction::triggered, this, &ActionManager::file_import);

277
278
279
280
281
    if (KAuthorized::authorize(QStringLiteral("ghns"))) {
        action = new QAction(i18n("Get &Hot New Stuff..."), this);
        mACollection->addAction(QStringLiteral("downloadnewstuff"), action);
        connect(action, &QAction::triggered, this, &ActionManager::downloadNewStuff);
    }
Laurent Montel's avatar
Laurent Montel committed
282
283

    action = new QAction(i18n("Export as &iCalendar..."), this);
Laurent Montel's avatar
Laurent Montel committed
284
    mACollection->addAction(QStringLiteral("export_icalendar"), action);
Laurent Montel's avatar
Laurent Montel committed
285
286
287
    connect(action, &QAction::triggered, mCalendarView, &CalendarView::exportICalendar);

    action = new QAction(i18n("Archive O&ld Entries..."), this);
Laurent Montel's avatar
Laurent Montel committed
288
    mACollection->addAction(QStringLiteral("file_archive"), action);
Laurent Montel's avatar
Laurent Montel committed
289
290
291
    connect(action, &QAction::triggered, this, &ActionManager::file_archive);

    action = new QAction(i18n("Pur&ge Completed To-dos"), mACollection);
Laurent Montel's avatar
Laurent Montel committed
292
    mACollection->addAction(QStringLiteral("purge_completed"), action);
Laurent Montel's avatar
Laurent Montel committed
293
294
295
296
    connect(action, &QAction::triggered, mCalendarView, &CalendarView::purgeCompleted);

    /************************** EDIT MENU *********************************/

Laurent Montel's avatar
Laurent Montel committed
297
    QAction *pasteAction = nullptr;
Laurent Montel's avatar
Laurent Montel committed
298
299
300
    Akonadi::History *history = mCalendarView->history();
    if (mIsPart) {
        // edit menu
Laurent Montel's avatar
Laurent Montel committed
301
        mCutAction = mACollection->addAction(KStandardAction::Cut, QStringLiteral("korganizer_cut"),
Laurent Montel's avatar
Laurent Montel committed
302
                                             mCalendarView, SLOT(edit_cut()));
Laurent Montel's avatar
Laurent Montel committed
303
304
305
306
307
308
309
310
311
312
313
314
        mCopyAction
            = mACollection->addAction(KStandardAction::Copy, QStringLiteral("korganizer_copy"),
                                      mCalendarView, SLOT(edit_copy()));
        pasteAction
            = mACollection->addAction(KStandardAction::Paste, QStringLiteral("korganizer_paste"),
                                      mCalendarView, SLOT(edit_paste()));
        mUndoAction
            = mACollection->addAction(KStandardAction::Undo, QStringLiteral("korganizer_undo"),
                                      history, SLOT(undo()));
        mRedoAction
            = mACollection->addAction(KStandardAction::Redo, QStringLiteral("korganizer_redo"),
                                      history, SLOT(redo()));
Laurent Montel's avatar
Laurent Montel committed
315
    } else {
Laurent Montel's avatar
Laurent Montel committed
316
317
        mCutAction = KStandardAction::cut(mCalendarView, &CalendarView::edit_cut, mACollection);
        mCopyAction = KStandardAction::copy(mCalendarView, &CalendarView::edit_copy, mACollection);
Laurent Montel's avatar
Laurent Montel committed
318
319
        pasteAction
            = KStandardAction::paste(mCalendarView, &CalendarView::edit_paste, mACollection);
Laurent Montel's avatar
Laurent Montel committed
320
321
322
        mUndoAction = KStandardAction::undo(history, SLOT(undo()), mACollection);
        mRedoAction = KStandardAction::redo(history, SLOT(redo()), mACollection);
    }
Laurent Montel's avatar
Laurent Montel committed
323
324
    mDeleteAction = new QAction(QIcon::fromTheme(QStringLiteral("edit-delete")), i18n(
                                    "&Delete"), this);
Laurent Montel's avatar
Laurent Montel committed
325
    mACollection->addAction(QStringLiteral("edit_delete"), mDeleteAction);
Laurent Montel's avatar
Laurent Montel committed
326
327
    connect(mDeleteAction, &QAction::triggered, mCalendarView, &CalendarView::appointment_delete);
    if (mIsPart) {
Laurent Montel's avatar
Laurent Montel committed
328
329
330
        QAction *a
            = KStandardAction::find(mCalendarView->dialogManager(),
                                    SLOT(showSearchDialog()), mACollection);
Laurent Montel's avatar
Laurent Montel committed
331
        mACollection->addAction(QStringLiteral("korganizer_find"), a);
Laurent Montel's avatar
Laurent Montel committed
332
333
334
335
336
337
338
339
    } else {
        KStandardAction::find(mCalendarView->dialogManager(),
                              SLOT(showSearchDialog()), mACollection);
    }
    pasteAction->setEnabled(false);
    mUndoAction->setEnabled(false);
    mRedoAction->setEnabled(false);
    connect(mCalendarView, &CalendarView::pasteEnabled, pasteAction, &QAction::setEnabled);
340
    connect(history, &Akonadi::History::changed, this, &ActionManager::updateUndoRedoActions);
Laurent Montel's avatar
Laurent Montel committed
341
342
343
344

    /************************** VIEW MENU *********************************/

    //~~~~~~~~~~~~~~~~~~~~~~~~~~~~ VIEWS ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Laurent Montel's avatar
Laurent Montel committed
345
346
347
    action
        = new QAction(QIcon::fromTheme(QStringLiteral("view-calendar-upcoming-events")), i18n(
                          "What's &Next"), this);
Laurent Montel's avatar
Laurent Montel committed
348
    mACollection->addAction(QStringLiteral("view_whatsnext"), action);
Laurent Montel's avatar
Laurent Montel committed
349
350
    connect(action, &QAction::triggered, mCalendarView->viewManager(),
            &KOViewManager::showWhatsNextView);
Laurent Montel's avatar
Laurent Montel committed
351

Laurent Montel's avatar
Laurent Montel committed
352
353
    action = new QAction(QIcon::fromTheme(QStringLiteral("view-calendar-month")), i18n(
                             "&Month"), this);
Laurent Montel's avatar
Laurent Montel committed
354
    mACollection->addAction(QStringLiteral("view_month"), action);
Laurent Montel's avatar
Laurent Montel committed
355
356
    connect(action, &QAction::triggered,
            mCalendarView->viewManager(), &KOViewManager::showMonthView);
Laurent Montel's avatar
Laurent Montel committed
357

Laurent Montel's avatar
Laurent Montel committed
358
359
    action = new QAction(QIcon::fromTheme(QStringLiteral("view-calendar-agenda")), i18n(
                             "&Agenda"), this);
Laurent Montel's avatar
Laurent Montel committed
360
    mACollection->addAction(QStringLiteral("view_agenda"), action);
Laurent Montel's avatar
Laurent Montel committed
361
362
    connect(action, &QAction::triggered,
            mCalendarView->viewManager(), &KOViewManager::showAgendaView);
Laurent Montel's avatar
Laurent Montel committed
363

Laurent Montel's avatar
Laurent Montel committed
364
365
    action = new QAction(QIcon::fromTheme(QStringLiteral("view-calendar-list")), i18n(
                             "&Event List"), this);
Laurent Montel's avatar
Laurent Montel committed
366
    mACollection->addAction(QStringLiteral("view_list"), action);
Laurent Montel's avatar
Laurent Montel committed
367
368
    connect(action, &QAction::triggered, mCalendarView->viewManager(),
            &KOViewManager::showListView);
Laurent Montel's avatar
Laurent Montel committed
369

Laurent Montel's avatar
Laurent Montel committed
370
371
    action = new QAction(QIcon::fromTheme(QStringLiteral("view-calendar-tasks")), i18n(
                             "&To-do List"), this);
Laurent Montel's avatar
Laurent Montel committed
372
    mACollection->addAction(QStringLiteral("view_todo"), action);
Laurent Montel's avatar
Laurent Montel committed
373
374
    connect(action, &QAction::triggered, mCalendarView->viewManager(),
            &KOViewManager::showTodoView);
Laurent Montel's avatar
Laurent Montel committed
375

Laurent Montel's avatar
Laurent Montel committed
376
377
    action = new QAction(QIcon::fromTheme(QStringLiteral("view-calendar-journal")), i18n(
                             "&Journal"), this);
Laurent Montel's avatar
Laurent Montel committed
378
    mACollection->addAction(QStringLiteral("view_journal"), action);
Laurent Montel's avatar
Laurent Montel committed
379
380
    connect(action, &QAction::triggered, mCalendarView->viewManager(),
            &KOViewManager::showJournalView);
Laurent Montel's avatar
Laurent Montel committed
381

Laurent Montel's avatar
Laurent Montel committed
382
383
384
    action
        = new QAction(QIcon::fromTheme(QStringLiteral("view-calendar-timeline")), i18n(
                          "Time&line"), this);
Laurent Montel's avatar
Laurent Montel committed
385
    mACollection->addAction(QStringLiteral("view_timeline"), action);
Laurent Montel's avatar
Laurent Montel committed
386
387
    connect(action, &QAction::triggered, mCalendarView->viewManager(),
            &KOViewManager::showTimeLineView);
Laurent Montel's avatar
Laurent Montel committed
388
389
390

    //~~~~~~~~~~~~~~~~~~~~~~~~~~~ REFRESH ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    action = new QAction(i18n("&Refresh"), this);
Laurent Montel's avatar
Laurent Montel committed
391
    mACollection->addAction(QStringLiteral("update"), action);
392
    connect(action, &QAction::triggered, mCalendarView, qOverload<>(&CalendarView::updateView));
Laurent Montel's avatar
Laurent Montel committed
393
394
395
396
397

    //~~~~~~~~~~~~~~~~~~~~~~~~~~~ FILTER ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    mFilterAction = new KSelectAction(i18n("F&ilter"), this);
    mFilterAction->setToolBarMode(KSelectAction::MenuMode);
Laurent Montel's avatar
Laurent Montel committed
398
    mACollection->addAction(QStringLiteral("filter_select"), mFilterAction);
Laurent Montel's avatar
Laurent Montel committed
399
    mFilterAction->setEditable(false);
400
    connect(mFilterAction, qOverload<int>(&KSelectAction::triggered),
401
            mCalendarView, &CalendarView::filterActivated);
402
403
404
405
    connect(mCalendarView, &CalendarView::filtersUpdated,
            this, &ActionManager::setItems);
    connect(mCalendarView, &CalendarView::filterChanged,
            this, &ActionManager::setTitle);
Laurent Montel's avatar
Laurent Montel committed
406
407
408

    //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ZOOM ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    // TODO: try to find / create better icons for the following 4 actions
Laurent Montel's avatar
Laurent Montel committed
409
410
    action
        = new QAction(QIcon::fromTheme(QStringLiteral("zoom-in")), i18n("In Horizontally"), this);
Laurent Montel's avatar
Laurent Montel committed
411
    action->setEnabled(mCalendarView->currentView()->supportsZoom());
Laurent Montel's avatar
Laurent Montel committed
412
    mACollection->addAction(QStringLiteral("zoom_in_horizontally"), action);
413
414
    connect(action, &QAction::triggered, mCalendarView->viewManager(),
            &KOViewManager::zoomInHorizontally);
Laurent Montel's avatar
Laurent Montel committed
415

Laurent Montel's avatar
Laurent Montel committed
416
417
    action = new QAction(QIcon::fromTheme(QStringLiteral("zoom-out")), i18n(
                             "Out Horizontally"), this);
Laurent Montel's avatar
Laurent Montel committed
418
    action->setEnabled(mCalendarView->currentView()->supportsZoom());
Laurent Montel's avatar
Laurent Montel committed
419
    mACollection->addAction(QStringLiteral("zoom_out_horizontally"), action);
420
421
    connect(action, &QAction::triggered, mCalendarView->viewManager(),
            &KOViewManager::zoomOutHorizontally);
Laurent Montel's avatar
Laurent Montel committed
422

Laurent Montel's avatar
Laurent Montel committed
423
    action = new QAction(QIcon::fromTheme(QStringLiteral("zoom-in")), i18n("In Vertically"), this);
Laurent Montel's avatar
Laurent Montel committed
424
    action->setEnabled(mCalendarView->currentView()->supportsZoom());
Laurent Montel's avatar
Laurent Montel committed
425
    mACollection->addAction(QStringLiteral("zoom_in_vertically"), action);
426
427
    connect(action, &QAction::triggered, mCalendarView->viewManager(),
            &KOViewManager::zoomInVertically);
Laurent Montel's avatar
Laurent Montel committed
428

Laurent Montel's avatar
Laurent Montel committed
429
430
    action
        = new QAction(QIcon::fromTheme(QStringLiteral("zoom-out")), i18n("Out Vertically"), this);
Laurent Montel's avatar
Laurent Montel committed
431
    action->setEnabled(mCalendarView->currentView()->supportsZoom());
Laurent Montel's avatar
Laurent Montel committed
432
    mACollection->addAction(QStringLiteral("zoom_out_vertically"), action);
433
434
    connect(action, &QAction::triggered, mCalendarView->viewManager(),
            &KOViewManager::zoomOutVertically);
Laurent Montel's avatar
Laurent Montel committed
435
436
437
438

    /************************** Actions MENU *********************************/
    bool isRTL = QApplication::isRightToLeft();

Laurent Montel's avatar
Laurent Montel committed
439
    action = new QAction(QIcon::fromTheme(QStringLiteral("go-jump-today")),
Laurent Montel's avatar
Laurent Montel committed
440
441
442
                         i18nc("@action Jump to today", "To &Today"), this);
    action->setIconText(i18n("Today"));
    setHelpText(action, i18n("Scroll to Today"));
Laurent Montel's avatar
Laurent Montel committed
443
    mACollection->addAction(QStringLiteral("go_today"), action);
Laurent Montel's avatar
Laurent Montel committed
444
445
    connect(action, &QAction::triggered, mCalendarView, &CalendarView::goToday);

Laurent Montel's avatar
Laurent Montel committed
446
447
448
449
    action
        = new QAction(QIcon::fromTheme(isRTL ? QStringLiteral("go-next") : QStringLiteral(
                                           "go-previous")),
                      i18nc("scroll backward", "&Backward"), this);
Laurent Montel's avatar
Laurent Montel committed
450
451
    action->setIconText(i18nc("scroll backward", "Back"));
    setHelpText(action, i18n("Scroll Backward"));
Laurent Montel's avatar
Laurent Montel committed
452
    mACollection->addAction(QStringLiteral("go_previous"), action);
Laurent Montel's avatar
Laurent Montel committed
453
454
455
456
457
458
459
460
461
462
    connect(action, &QAction::triggered, mCalendarView, &CalendarView::goPrevious);

    // Changing the action text by setText makes the toolbar button disappear.
    // This has to be fixed first, before the connects below can be reenabled.
    /*
    connect( mCalendarView, SIGNAL(changeNavStringPrev(QString)),
             action, SLOT(setText(QString)) );
    connect( mCalendarView, SIGNAL(changeNavStringPrev(QString)),
             this, SLOT(dumpText(QString)) );*/

Laurent Montel's avatar
Laurent Montel committed
463
464
465
466
    action
        = new QAction(QIcon::fromTheme(isRTL ? QStringLiteral("go-previous") : QStringLiteral(
                                           "go-next")),
                      i18nc("scroll forward", "&Forward"), this);
Laurent Montel's avatar
Laurent Montel committed
467
468
    action->setIconText(i18nc("scoll forward", "Forward"));
    setHelpText(action, i18n("Scroll Forward"));
Laurent Montel's avatar
Laurent Montel committed
469
    mACollection->addAction(QStringLiteral("go_next"), action);
Laurent Montel's avatar
Laurent Montel committed
470
471
472
473
474
475
    connect(action, &QAction::triggered, mCalendarView, &CalendarView::goNext);
    /*
    connect( mCalendarView,SIGNAL(changeNavStringNext(QString)),
             action,SLOT(setText(QString)) );
    */

Laurent Montel's avatar
Laurent Montel committed
476
    action = new QAction(QIcon::fromTheme(QStringLiteral("view-calendar-day")), i18n("&Day"), this);
Laurent Montel's avatar
Laurent Montel committed
477
    mACollection->addAction(QStringLiteral("select_day"), action);
Laurent Montel's avatar
Laurent Montel committed
478
    action->setEnabled(mCalendarView->currentView()->supportsDateRangeSelection());
479
480
    connect(action, &QAction::triggered, mCalendarView->viewManager(),
            &KOViewManager::selectDay);
Laurent Montel's avatar
Laurent Montel committed
481

Laurent Montel's avatar
Laurent Montel committed
482
483
    mNextXDays = new QAction(QIcon::fromTheme(QStringLiteral(
                                                  "view-calendar-upcoming-days")), QString(), this);
Laurent Montel's avatar
Laurent Montel committed
484
    mNextXDays->setEnabled(mCalendarView->currentView()->supportsDateRangeSelection());
Laurent Montel's avatar
Laurent Montel committed
485
    mACollection->addAction(QStringLiteral("select_nextx"), mNextXDays);
486
487
    connect(mNextXDays, &QAction::triggered, mCalendarView->viewManager(),
            &KOViewManager::selectNextX);
Laurent Montel's avatar
Laurent Montel committed
488
489
    mNextXDays->setText(i18np("&Next Day", "&Next %1 Days", KOPrefs::instance()->mNextXDays));

Laurent Montel's avatar
Laurent Montel committed
490
491
492
    action
        = new QAction(QIcon::fromTheme(QStringLiteral("view-calendar-workweek")), i18n(
                          "W&ork Week"), this);
Laurent Montel's avatar
Laurent Montel committed
493
    action->setEnabled(mCalendarView->currentView()->supportsDateRangeSelection());
Laurent Montel's avatar
Laurent Montel committed
494
    mACollection->addAction(QStringLiteral("select_workweek"), action);
495
496
    connect(action, &QAction::triggered, mCalendarView->viewManager(),
            &KOViewManager::selectWorkWeek);
Laurent Montel's avatar
Laurent Montel committed
497

Laurent Montel's avatar
Laurent Montel committed
498
499
    action
        = new QAction(QIcon::fromTheme(QStringLiteral("view-calendar-week")), i18n("&Week"), this);
Laurent Montel's avatar
Laurent Montel committed
500
    action->setEnabled(mCalendarView->currentView()->supportsDateRangeSelection());
Laurent Montel's avatar
Laurent Montel committed
501
    mACollection->addAction(QStringLiteral("select_week"), action);
502
503
    connect(action, &QAction::triggered, mCalendarView->viewManager(),
            &KOViewManager::selectWeek);
Laurent Montel's avatar
Laurent Montel committed
504
505

    /************************** Actions MENU *********************************/
Laurent Montel's avatar
Laurent Montel committed
506
507
508
    mNewEventAction
        = new QAction(QIcon::fromTheme(QStringLiteral("appointment-new")), i18n(
                          "New E&vent..."), this);
Laurent Montel's avatar
Laurent Montel committed
509
510
511
    //mNewEventAction->setIconText( i18nc( "@action:intoolbar create a new event", "Event" ) );
    setHelpText(mNewEventAction, i18n("Create a new Event"));

Laurent Montel's avatar
Laurent Montel committed
512
    mACollection->addAction(QStringLiteral("new_event"), mNewEventAction);
513
514
    connect(mNewEventAction, &QAction::triggered, this,
            &ActionManager::slotNewEvent);
Laurent Montel's avatar
Laurent Montel committed
515

Laurent Montel's avatar
Laurent Montel committed
516
517
    mNewTodoAction = new QAction(QIcon::fromTheme(QStringLiteral("task-new")), i18n(
                                     "New &To-do..."), this);
Laurent Montel's avatar
Laurent Montel committed
518
519
    //mNewTodoAction->setIconText( i18n( "To-do" ) );
    setHelpText(mNewTodoAction, i18n("Create a new To-do"));
Laurent Montel's avatar
Laurent Montel committed
520
    mACollection->addAction(QStringLiteral("new_todo"), mNewTodoAction);
521
522
    connect(mNewTodoAction, &QAction::triggered, this,
            &ActionManager::slotNewTodo);
Laurent Montel's avatar
Laurent Montel committed
523
524

    mNewSubtodoAction = new QAction(i18n("New Su&b-to-do..."), this);
Laurent Montel's avatar
Laurent Montel committed
525
    mACollection->addAction(QStringLiteral("new_subtodo"), mNewSubtodoAction);
Laurent Montel's avatar
Laurent Montel committed
526
527
    connect(mNewSubtodoAction, &QAction::triggered, this,
            &ActionManager::slotNewSubTodo);
Laurent Montel's avatar
Laurent Montel committed
528
    mNewSubtodoAction->setEnabled(false);
Laurent Montel's avatar
Laurent Montel committed
529
530
    connect(mCalendarView, &CalendarView::todoSelected, mNewSubtodoAction,
            &QAction::setEnabled);
Laurent Montel's avatar
Laurent Montel committed
531

Laurent Montel's avatar
Laurent Montel committed
532
533
534
    mNewJournalAction
        = new QAction(QIcon::fromTheme(QStringLiteral("journal-new")), i18n("New &Journal..."),
                      this);
Laurent Montel's avatar
Laurent Montel committed
535
536
    //mNewJournalAction->setIconText( i18n( "Journal" ) );
    setHelpText(mNewJournalAction, i18n("Create a new Journal"));
Laurent Montel's avatar
Laurent Montel committed
537
    mACollection->addAction(QStringLiteral("new_journal"), mNewJournalAction);
Laurent Montel's avatar
Laurent Montel committed
538
539
    connect(mNewJournalAction, &QAction::triggered, this,
            &ActionManager::slotNewJournal);
Laurent Montel's avatar
Laurent Montel committed
540

Laurent Montel's avatar
Laurent Montel committed
541
542
543
    mConfigureViewAction
        = new QAction(QIcon::fromTheme(QStringLiteral("configure")), i18n("Configure View..."),
                      this);
Laurent Montel's avatar
Laurent Montel committed
544
545
    mConfigureViewAction->setIconText(i18n("Configure"));
    setHelpText(mConfigureViewAction, i18n("Configure the view"));
Laurent Montel's avatar
Laurent Montel committed
546
547
    mConfigureViewAction->setEnabled(mCalendarView->currentView()
                                     && mCalendarView->currentView()->hasConfigurationDialog());
Laurent Montel's avatar
Laurent Montel committed
548
    mACollection->addAction(QStringLiteral("configure_view"), mConfigureViewAction);
Laurent Montel's avatar
Laurent Montel committed
549
550
    connect(mConfigureViewAction, &QAction::triggered, mCalendarView,
            &CalendarView::configureCurrentView);
Laurent Montel's avatar
Laurent Montel committed
551
552

    mShowIncidenceAction = new QAction(i18n("&Show"), this);
Laurent Montel's avatar
Laurent Montel committed
553
    mACollection->addAction(QStringLiteral("show_incidence"), mShowIncidenceAction);
Laurent Montel's avatar
Laurent Montel committed
554
    connect(mShowIncidenceAction, &QAction::triggered, mCalendarView,
555
            qOverload<>(&CalendarView::showIncidence));
Laurent Montel's avatar
Laurent Montel committed
556
557

    mEditIncidenceAction = new QAction(i18n("&Edit..."), this);
Laurent Montel's avatar
Laurent Montel committed
558
    mACollection->addAction(QStringLiteral("edit_incidence"), mEditIncidenceAction);
Laurent Montel's avatar
Laurent Montel committed
559
    connect(mEditIncidenceAction, &QAction::triggered, mCalendarView,
560
            qOverload<>(&CalendarView::editIncidence));
Laurent Montel's avatar
Laurent Montel committed
561
562

    mDeleteIncidenceAction = new QAction(i18n("&Delete"), this);
Laurent Montel's avatar
Laurent Montel committed
563
    mACollection->addAction(QStringLiteral("delete_incidence"), mDeleteIncidenceAction);
Laurent Montel's avatar
Laurent Montel committed
564
    connect(mDeleteIncidenceAction, &QAction::triggered, mCalendarView,
565
            qOverload<>(&CalendarView::deleteIncidence));
Laurent Montel's avatar
Laurent Montel committed
566
567
568
    mACollection->setDefaultShortcut(mDeleteIncidenceAction, QKeySequence(Qt::Key_Delete));

    action = new QAction(i18n("&Make Sub-to-do Independent"), this);
Laurent Montel's avatar
Laurent Montel committed
569
    mACollection->addAction(QStringLiteral("unsub_todo"), action);
570
571
    connect(action, &QAction::triggered, mCalendarView,
            &CalendarView::todo_unsub);
Laurent Montel's avatar
Laurent Montel committed
572
    action->setEnabled(false);
573
574
    connect(mCalendarView, &CalendarView::subtodoSelected, action,
            &QAction::setEnabled);
575
576
577
578
579
580

// TODO: Add item to quickly toggle the reminder of a given incidence
//   mToggleAlarmAction = new KToggleAction( i18n( "&Activate Reminder" ), 0,
//                                         mCalendarView, SLOT(toggleAlarm()),
//                                         mACollection, "activate_alarm" );

Laurent Montel's avatar
Laurent Montel committed
581
    /************************** SCHEDULE MENU ********************************/
582
583
    mPublishEvent = new QAction(QIcon::fromTheme(QStringLiteral("mail-send")),
                                i18n("&Publish Item Information..."), this);
Laurent Montel's avatar
Laurent Montel committed
584
    mACollection->addAction(QStringLiteral("schedule_publish"), mPublishEvent);
Laurent Montel's avatar
Laurent Montel committed
585
586
587
    connect(mPublishEvent, SIGNAL(triggered(bool)), mCalendarView, SLOT(schedule_publish()));
    mPublishEvent->setEnabled(false);

588
589
    mSendInvitation = new QAction(QIcon::fromTheme(QStringLiteral("mail-send")),
                                  i18n("Send &Invitation to Attendees"), this);
Laurent Montel's avatar
Laurent Montel committed
590
    mACollection->addAction(QStringLiteral("schedule_request"), mSendInvitation);
Laurent Montel's avatar
Laurent Montel committed
591
592
    connect(mSendInvitation, SIGNAL(triggered(bool)), mCalendarView, SLOT(schedule_request()));
    mSendInvitation->setEnabled(false);
593
594
    connect(mCalendarView, &CalendarView::organizerEventsSelected,
            mSendInvitation, &QAction::setEnabled);
Laurent Montel's avatar
Laurent Montel committed
595
596

    mRequestUpdate = new QAction(i18n("Re&quest Update"), this);
Laurent Montel's avatar
Laurent Montel committed
597
    mACollection->addAction(QStringLiteral("schedule_refresh"), mRequestUpdate);
Laurent Montel's avatar
Laurent Montel committed
598
599
    connect(mRequestUpdate, SIGNAL(triggered(bool)), mCalendarView, SLOT(schedule_refresh()));
    mRequestUpdate->setEnabled(false);
600
601
    connect(mCalendarView, &CalendarView::groupEventsSelected,
            mRequestUpdate, &QAction::setEnabled);
Laurent Montel's avatar
Laurent Montel committed
602
603

    mSendCancel = new QAction(i18n("Send &Cancellation to Attendees"), this);
Laurent Montel's avatar
Laurent Montel committed
604
    mACollection->addAction(QStringLiteral("schedule_cancel"), mSendCancel);
Laurent Montel's avatar
Laurent Montel committed
605
606
    connect(mSendCancel, SIGNAL(triggered(bool)), mCalendarView, SLOT(schedule_cancel()));
    mSendCancel->setEnabled(false);
607
608
    connect(mCalendarView, &CalendarView::organizerEventsSelected,
            mSendCancel, &QAction::setEnabled);
Laurent Montel's avatar
Laurent Montel committed
609

610
611
    mSendStatusUpdate = new QAction(QIcon::fromTheme(QStringLiteral("mail-reply-sender")),
                                    i18n("Send Status &Update"), this);
Laurent Montel's avatar
Laurent Montel committed
612
    mACollection->addAction(QStringLiteral("schedule_reply"), mSendStatusUpdate);
Laurent Montel's avatar
Laurent Montel committed
613
614
    connect(mSendStatusUpdate, SIGNAL(triggered(bool)), mCalendarView, SLOT(schedule_reply()));
    mSendStatusUpdate->setEnabled(false);
615
616
    connect(mCalendarView, &CalendarView::groupEventsSelected,
            mSendStatusUpdate, &QAction::setEnabled);
Laurent Montel's avatar
Laurent Montel committed
617
618

    mRequestChange = new QAction(i18nc("counter proposal", "Request Chan&ge"), this);
Laurent Montel's avatar
Laurent Montel committed
619
    mACollection->addAction(QStringLiteral("schedule_counter"), mRequestChange);
Laurent Montel's avatar
Laurent Montel committed
620
621
    connect(mRequestChange, SIGNAL(triggered(bool)), mCalendarView, SLOT(schedule_counter()));
    mRequestChange->setEnabled(false);
622
623
    connect(mCalendarView, &CalendarView::groupEventsSelected,
            mRequestChange, &QAction::setEnabled);
Laurent Montel's avatar
Laurent Montel committed
624
625

    action = new QAction(i18n("&Mail Free Busy Information..."), this);
Laurent Montel's avatar
Laurent Montel committed
626
    mACollection->addAction(QStringLiteral("mail_freebusy"), action);
Laurent Montel's avatar
Laurent Montel committed
627
628
629
    connect(action, &QAction::triggered, mCalendarView, &CalendarView::mailFreeBusy);
    action->setEnabled(true);

630
631
    mForwardEvent = new QAction(QIcon::fromTheme(QStringLiteral("mail-forward")),
                                i18n("&Send as iCalendar..."), this);
Laurent Montel's avatar
Laurent Montel committed
632
    mACollection->addAction(QStringLiteral("schedule_forward"), mForwardEvent);
Laurent Montel's avatar
Laurent Montel committed
633
634
635
636
    connect(mForwardEvent, SIGNAL(triggered(bool)), mCalendarView, SLOT(schedule_forward()));
    mForwardEvent->setEnabled(false);

    action = new QAction(i18n("&Upload Free Busy Information"), this);
Laurent Montel's avatar
Laurent Montel committed
637
    mACollection->addAction(QStringLiteral("upload_freebusy"), action);
Laurent Montel's avatar
Laurent Montel committed
638
639
640
641
    connect(action, &QAction::triggered, mCalendarView, &CalendarView::uploadFreeBusy);
    action->setEnabled(true);

    if (!mIsPart) {
642
643
        action = new QAction(QIcon::fromTheme(QStringLiteral("help-contents")),
                             i18n("&Address Book"), this);
Laurent Montel's avatar
Laurent Montel committed
644
        mACollection->addAction(QStringLiteral("addressbook"), action);
Laurent Montel's avatar
Laurent Montel committed
645
646
647
648
649
650
651
        connect(action, &QAction::triggered, mCalendarView, &CalendarView::openAddressbook);
    }

    /************************** SETTINGS MENU ********************************/

    //~~~~~~~~~~~~~~~~~~~~~~~~~~~~ SIDEBAR ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    mDateNavigatorShowAction = new KToggleAction(i18n("Show Date Navigator"), this);
Laurent Montel's avatar
Laurent Montel committed
652
    mACollection->addAction(QStringLiteral("show_datenavigator"), mDateNavigatorShowAction);
653
654
    connect(mDateNavigatorShowAction, &KToggleAction::triggered,
            this, &ActionManager::toggleDateNavigator);
Laurent Montel's avatar
Laurent Montel committed
655
656

    mTodoViewShowAction = new KToggleAction(i18n("Show To-do View"), this);
Laurent Montel's avatar
Laurent Montel committed
657
    mACollection->addAction(QStringLiteral("show_todoview"), mTodoViewShowAction);
658
659
    connect(mTodoViewShowAction, &KToggleAction::triggered,
            this, &ActionManager::toggleTodoView);
Laurent Montel's avatar
Laurent Montel committed
660
661

    mEventViewerShowAction = new KToggleAction(i18n("Show Item Viewer"), this);
Laurent Montel's avatar
Laurent Montel committed
662
    mACollection->addAction(QStringLiteral("show_eventviewer"), mEventViewerShowAction);
663
664
    connect(mEventViewerShowAction, &KToggleAction::triggered,
            this, &ActionManager::toggleEventViewer);
665
666

    KConfigGroup config(KSharedConfig::openConfig(), "Settings");
Laurent Montel's avatar
Laurent Montel committed
667
668
669
670
671
672
673
674
675
676
677
678
679
    mDateNavigatorShowAction->setChecked(config.readEntry("DateNavigatorVisible", true));
    // if we are a kpart, then let's not show the todo in the left pane by
    // default since there's also a Todo part and we'll assume they'll be
    // using that as well, so let's not duplicate it (by default) here
    mTodoViewShowAction->setChecked(
        config.readEntry("TodoViewVisible", false));    //mIsPart ? false : true ) );
    mEventViewerShowAction->setChecked(config.readEntry("EventViewerVisible", true));
    toggleDateNavigator();
    toggleTodoView();
    toggleEventViewer();

    if (!mMainWindow->hasDocument()) {
        mCollectionViewShowAction = new KToggleAction(i18n("Show Calendar Manager"), this);
Laurent Montel's avatar
Laurent Montel committed
680
        mACollection->addAction(QStringLiteral("show_resourceview"), mCollectionViewShowAction);
681
682
        connect(mCollectionViewShowAction, &KToggleAction::triggered,
                this, &ActionManager::toggleResourceView);
Laurent Montel's avatar
Laurent Montel committed
683
684
685
686
687
688
        mCollectionViewShowAction->setChecked(config.readEntry("ResourceViewVisible", true));

        toggleResourceView();
    }

    //~~~~~~~~~~~~~~~~~~~~~~~~~~~~ SIDEBAR ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Laurent Montel's avatar
Laurent Montel committed
689
690
    mHideMenuBarAction = KStandardAction::showMenubar(this, &ActionManager::toggleMenubar,
                                                      mACollection);
Laurent Montel's avatar
Laurent Montel committed
691
692
693
694
    mHideMenuBarAction->setChecked(KOPrefs::instance()->showMenuBar());
    toggleMenubar(true);

    action = new QAction(i18n("Configure &Date && Time..."), this);
Laurent Montel's avatar
Laurent Montel committed
695
    mACollection->addAction(QStringLiteral("conf_datetime"), action);
696
    connect(action, &QAction::triggered, this, &ActionManager::configureDateTime);
697

698
699
    action = new QAction(QIcon::fromTheme(QStringLiteral("view-filter")),
                         i18n("Manage View &Filters..."), this);
Laurent Montel's avatar
Laurent Montel committed
700
    mACollection->addAction(QStringLiteral("edit_filters"), action);
701
    connect(action, &QAction::triggered, mCalendarView, &CalendarView::editFilters);
Laurent Montel's avatar
Laurent Montel committed
702
703

    action = new QAction(i18n("Manage C&ategories..."), this);
Laurent Montel's avatar
Laurent Montel committed
704
    mACollection->addAction(QStringLiteral("edit_categories"), action);
705
706
    connect(action, &QAction::triggered, mCalendarView->dialogManager(),
            &KODialogManager::showCategoryEditDialog);
Laurent Montel's avatar
Laurent Montel committed
707
708

    if (mIsPart) {
709
710
        action = new QAction(QIcon::fromTheme(QStringLiteral("configure")),
                             i18n("&Configure KOrganizer..."), this);
Laurent Montel's avatar
Laurent Montel committed
711
        mACollection->addAction(QStringLiteral("korganizer_configure"), action);
712
        connect(action, &QAction::triggered, mCalendarView, &CalendarView::edit_options);
Laurent Montel's avatar
Laurent Montel committed
713
714
        mACollection->addAction(KStandardAction::KeyBindings,
                                QStringLiteral("korganizer_configure_shortcuts"),
Laurent Montel's avatar
Laurent Montel committed
715
716
                                this, SLOT(keyBindings()));
    } else {
Laurent Montel's avatar
Laurent Montel committed
717
        KStandardAction::preferences(mCalendarView, &CalendarView::edit_options, mACollection);
Laurent Montel's avatar
Laurent Montel committed
718
        KStandardAction::keyBindings(this, &ActionManager::keyBindings, mACollection);
Laurent Montel's avatar
Laurent Montel committed
719
    }
720
721
}

Laurent Montel's avatar
Laurent Montel committed
722
void ActionManager::setItems(const QStringList &lst, int idx)
723
{
Laurent Montel's avatar
Laurent Montel committed
724
725
    mFilterAction->setItems(lst);
    mFilterAction->setCurrentItem(idx);
726
727
728
729
}

void ActionManager::slotResourcesAddedRemoved()
{
Laurent Montel's avatar
Laurent Montel committed
730
    restoreCollectionViewSetting();
731
732
}

Laurent Montel's avatar
Laurent Montel committed
733
void ActionManager::slotDefaultResourceChanged(const Akonadi::Collection &collection)
734
{
Laurent Montel's avatar
Laurent Montel committed
735
    mCalendarView->incidenceChanger()->setDefaultCollection(collection);
736
737
738
739
}

void ActionManager::slotNewEvent()
{
Laurent Montel's avatar
Laurent Montel committed
740
    mCalendarView->newEvent();
741
742
743
744
}

void ActionManager::slotNewTodo()
{
Laurent Montel's avatar
Laurent Montel committed
745
    mCalendarView->newTodo(selectedCollection());
746
747
748
749
}

void ActionManager::slotNewSubTodo()
{
Laurent Montel's avatar
Laurent Montel committed
750
    mCalendarView->newSubTodo(selectedCollection());
751
752
753
754
}

void ActionManager::slotNewJournal()
{
Laurent Montel's avatar
Laurent Montel committed
755
    mCalendarView->newJournal(selectedCollection());
756
757
}

Sergio Martins's avatar
Sergio Martins committed
758
void ActionManager::slotMergeFinished(bool success, int total)
759
760
761
{
    Q_ASSERT(sender());
    mImportAction->setEnabled(true);
Laurent Montel's avatar
Laurent Montel committed
762
    Akonadi::ICalImporter *importer = qobject_cast<Akonadi::ICalImporter *>(sender());
763
764

    if (success) {
765
766
767
        mCalendarView->showMessage(i18np("1 incidence was imported successfully.",
                                         "%1 incidences were imported successfully.", total),
                                   KMessageWidget::Information);
768
    } else {
769
770
771
        mCalendarView->showMessage(i18n("There was an error while merging the calendar: %1",
                                        importer->errorMessage()),
                                   KMessageWidget::Error);
772
    }
773
    sender()->deleteLater();
774
775
776
777
778
}

void ActionManager::slotNewResourceFinished(bool success)
{
    Q_ASSERT(sender());
Laurent Montel's avatar
Laurent Montel committed
779
    Akonadi::ICalImporter *importer = qobject_cast<Akonadi::ICalImporter *>(sender());
780
781
    mImportAction->setEnabled(true);
    if (success) {
782
783
        mCalendarView->showMessage(i18n("New calendar added successfully"),
                                   KMessageWidget::Information);
784
    } else {
785
786
787
        mCalendarView->showMessage(i18n("Could not add a calendar. Error: %1",
                                        importer->errorMessage()),
                                   KMessageWidget::Error);
788
    }
Laurent Montel's avatar
Laurent Montel committed
789
    sender()->deleteLater();
790
791
792
793
}

void ActionManager::readSettings()
{
Laurent Montel's avatar
Laurent Montel committed
794
795
    // read settings from the KConfig, supplying reasonable
    // defaults where none are to be found
796

Laurent Montel's avatar
Laurent Montel committed
797
798
    mCalendarView->readSettings();
    restoreCollectionViewSetting();
799
800
801
802
}

void ActionManager::restoreCollectionViewSetting()
{
Laurent Montel's avatar
Laurent Montel committed
803
804
    mCollectionSelectionModelStateSaver->restoreState();
    mCollectionViewStateSaver->restoreState();
805
806
807
808
}

void ActionManager::writeSettings()
{
809
810
    KSharedConfig::Ptr config = KSharedConfig::openConfig();
    KConfigGroup group = config->group("Settings");
Laurent Montel's avatar
Laurent Montel committed
811
    mCalendarView->writeSettings();
812

Laurent Montel's avatar
Laurent Montel committed
813
    if (mDateNavigatorShowAction) {
814
        group.writeEntry("DateNavigatorVisible", mDateNavigatorShowAction->isChecked());
Laurent Montel's avatar
Laurent Montel committed
815
    }
816

Laurent Montel's avatar
Laurent Montel committed
817
    if (mTodoViewShowAction) {
818
        group.writeEntry("TodoViewVisible", mTodoViewShowAction->isChecked());
Laurent Montel's avatar
Laurent Montel committed
819
    }
820

Laurent Montel's avatar
Laurent Montel committed
821
    if (mCollectionViewShowAction) {
822
        group.writeEntry("ResourceViewVisible", mCollectionViewShowAction->isChecked());
Laurent Montel's avatar
Laurent Montel committed
823
    }
824

Laurent Montel's avatar
Laurent Montel committed
825
    if (mEventViewerShowAction) {
826
        group.writeEntry("EventViewerVisible", mEventViewerShowAction->isChecked());
Laurent Montel's avatar
Laurent Montel committed
827
    }
828

Laurent Montel's avatar
Laurent Montel committed
829
830
    mCollectionViewStateSaver->saveState();
    mCollectionSelectionModelStateSaver->saveState();
831

832
833
    KConfigGroup selectionViewGroup = config->group("GlobalCollectionView");
    KConfigGroup selectionGroup = config->group("GlobalCollectionSelection");
Laurent Montel's avatar
Laurent Montel committed
834
835
    selectionGroup.sync();
    selectionViewGroup.sync();
836
    config->sync();
837
838
839
840
}

void ActionManager::file_open()
{
Laurent Montel's avatar
Laurent Montel committed
841
842
    const QString defaultPath
        = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation);
843
844
845
846
847
848
    const QUrl dir = QUrl::fromLocalFile(defaultPath + QLatin1String("/korganizer/"));
    const QUrl url = QFileDialog::getOpenFileUrl(
        dialogParent(),
        i18nc("@title:window", "Select Calendar File to Open"),
        dir,
        QStringLiteral("text/calendar (*.ics *.vcs)"));
849

Laurent Montel's avatar
Laurent Montel committed
850
    if (!url.isEmpty()) {  // isEmpty if user canceled the dialog
851
852
        file_open(url);
    }
853
854
}

Laurent Montel's avatar
KUrl--    
Laurent Montel committed
855
void ActionManager::file_open(const QUrl &url)
856
{
Laurent Montel's avatar
Laurent Montel committed
857
858
    // is that URL already opened somewhere else? Activate that window
    KOrg::MainWindow *korg = ActionManager::findInstance(url);
Laurent Montel's avatar
Laurent Montel committed
859
    if ((nullptr != korg) && (korg != mMainWindow)) {
Laurent Montel's avatar
Laurent Montel committed
860
#if KDEPIM_HAVE_X11
Laurent Montel's avatar
Laurent Montel committed
861
        KWindowSystem::activateWindow(korg->topLevelWidget()->winId());
862
#endif
Laurent Montel's avatar
Laurent Montel committed
863
864
        return;
    }
865