actionmanager.cpp 73.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-2016 Laurent Montel <montel@kde.org>
10
  Copyright (c) 2012 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.
*/
Laurent Montel's avatar
Laurent Montel committed
30
#include "config-korganizer.h"
31
#include "actionmanager.h"
Allen Winter's avatar
Allen Winter committed
32
#include "akonadicollectionview.h"
33 34
#include "calendaradaptor.h"
#include "calendarview.h"
Laurent Montel's avatar
Laurent Montel committed
35
#include "job/htmlexportjob.h"
Allen Winter's avatar
Allen Winter committed
36
#include "htmlexportsettings.h"
37 38
#include "kocore.h"
#include "kodialogmanager.h"
39
#include "korganizeradaptor.h"
40
#include "koglobals.h"
Laurent Montel's avatar
Laurent Montel committed
41
#include "prefs/koprefs.h"
42 43
#include "koviewmanager.h"
#include "kowindowlist.h"
Laurent Montel's avatar
Build++  
Laurent Montel committed
44
#include "KdepimDBusInterfaces/ReminderClient"
45
#include "kocheckableproxymodel.h"
46

John Layt's avatar
John Layt committed
47
#include <KHolidays/HolidayRegion>
Laurent Montel's avatar
Laurent Montel committed
48

Laurent Montel's avatar
Laurent Montel committed
49 50 51 52
#include <CalendarSupport/CollectionSelection>
#include <CalendarSupport/EventArchiver>
#include <CalendarSupport/KCalPrefs>
#include <CalendarSupport/Utils>
53

54
#include <IncidenceEditor/IncidenceEditorSettings>
55

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

#include <KCalCore/FileStorage>
64
#include <KCalCore/ICalFormat>
65
#include <KCalCore/Person>
66

Allen Winter's avatar
Allen Winter committed
67
#include <KMime/KMimeMessage>
68 69 70
#include <KJobWidgets>
#include <KIO/StatJob>
#include <KIO/FileCopyJob>
Allen Winter's avatar
Allen Winter committed
71

Laurent Montel's avatar
Laurent Montel committed
72
#include <QAction>
73
#include <KActionCollection>
Laurent Montel's avatar
Laurent Montel committed
74
#include <QFileDialog>
Laurent Montel's avatar
Laurent Montel committed
75
#include <QFileDialog>
Laurent Montel's avatar
Laurent Montel committed
76
#include <QMenu>
Laurent Montel's avatar
Laurent Montel committed
77
#include <QMenuBar>
78
#include <KMessageBox>
Allen Winter's avatar
Allen Winter committed
79
#include <KMimeTypeTrader>
80 81 82 83
#include <KProcess>
#include <KSelectAction>
#include <KShortcutsDialog>
#include <KStandardAction>
Laurent Montel's avatar
Laurent Montel committed
84

Laurent Montel's avatar
Laurent Montel committed
85
#include <QTemporaryFile>
86 87 88
#include <KToggleAction>
#include <KWindowSystem>
#include <KIO/NetAccess>
Allen Winter's avatar
Allen Winter committed
89
#include <KNS3/DownloadDialog>
Laurent Montel's avatar
Laurent Montel committed
90
#include <QIcon>
Laurent Montel's avatar
Laurent Montel committed
91
#include "korganizer_debug.h"
92
#include "korganizer_options.h"
93 94

#include <QApplication>
95
#include <QTimer>
96
#include <KSharedConfig>
Laurent Montel's avatar
Laurent Montel committed
97
#include <QStandardPaths>
98

Laurent Montel's avatar
Laurent Montel committed
99
KOWindowList *ActionManager::mWindowList = Q_NULLPTR;
100

Laurent Montel's avatar
Laurent Montel committed
101 102 103 104
ActionManager::ActionManager(KXMLGUIClient *client, CalendarView *widget,
                             QObject *parent, KOrg::MainWindow *mainWindow,
                             bool isPart, QMenuBar *menuBar)
    : QObject(parent),
Laurent Montel's avatar
Laurent Montel committed
105 106 107
      mCollectionViewShowAction(Q_NULLPTR),
      mCollectionView(Q_NULLPTR), mCollectionViewStateSaver(Q_NULLPTR),
      mCollectionSelectionModelStateSaver(Q_NULLPTR)
108
{
Laurent Montel's avatar
Laurent Montel committed
109
    new KOrgCalendarAdaptor(this);
Laurent Montel's avatar
Laurent Montel committed
110
    QDBusConnection::sessionBus().registerObject(QStringLiteral("/Calendar"), this);
111

Laurent Montel's avatar
Laurent Montel committed
112 113 114 115
    mGUIClient = client;
    mACollection = mGUIClient->actionCollection();
    mCalendarView = widget;
    mIsPart = isPart;
Laurent Montel's avatar
Laurent Montel committed
116
    mTempFile = Q_NULLPTR;
Laurent Montel's avatar
Laurent Montel committed
117 118 119
    mHtmlExportSync = false;
    mMainWindow = mainWindow;
    mMenuBar = menuBar;
120 121 122 123
}

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

Laurent Montel's avatar
Laurent Montel committed
127
    delete mTempFile;
128

Laurent Montel's avatar
Laurent Montel committed
129 130
    // Take this window out of the window list.
    mWindowList->removeWindow(mMainWindow);
131

Laurent Montel's avatar
Laurent Montel committed
132 133
    delete mCollectionSelectionModelStateSaver;
    delete mCollectionViewStateSaver;
134

Laurent Montel's avatar
Laurent Montel committed
135
    delete mCalendarView;
136 137
}

Laurent Montel's avatar
Laurent Montel committed
138
void ActionManager::toggleMenubar(bool dontShowWarning)
139
{
Laurent Montel's avatar
Laurent Montel committed
140 141 142 143 144 145 146 147 148
    if (mMenuBar) {
        if (mHideMenuBarAction->isChecked()) {
            mMenuBar->show();
        } else {
            if (!dontShowWarning) {
                QString accel = mHideMenuBarAction->shortcut().toString();
                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
149
                                         i18n("Hide menu bar"), QStringLiteral("HideMenuBarWarning"));
Laurent Montel's avatar
Laurent Montel committed
150 151 152 153 154
            }
            mMenuBar->hide();
        }
        KOPrefs::instance()->setShowMenuBar(mHideMenuBarAction->isChecked());
    }
155 156 157 158
}
// see the Note: below for why this method is necessary
void ActionManager::init()
{
Laurent Montel's avatar
Laurent Montel committed
159 160 161
    // add this instance of the window to the static list.
    if (!mWindowList) {
        mWindowList = new KOWindowList;
162 163
    }

Laurent Montel's avatar
Laurent Montel committed
164 165 166 167
    // 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);
168

Laurent Montel's avatar
Minor  
Laurent Montel committed
169
    // initialize the QAction instances
Laurent Montel's avatar
Laurent Montel committed
170
    initActions();
171

Laurent Montel's avatar
Laurent Montel committed
172 173 174 175 176 177 178
    // set up autoExporting stuff
    mAutoExportTimer = new QTimer(this);
    connect(mAutoExportTimer, &QTimer::timeout, this, &ActionManager::checkAutoExport);
    if (KOPrefs::instance()->mAutoExport &&
            KOPrefs::instance()->mAutoExportInterval > 0) {
        mAutoExportTimer->start(1000 * 60 * KOPrefs::instance()->mAutoExportInterval);
    }
179

Laurent Montel's avatar
Laurent Montel committed
180 181 182 183
    // set up autoSaving stuff
    mAutoArchiveTimer = new QTimer(this);
    mAutoArchiveTimer->setSingleShot(true);
    connect(mAutoArchiveTimer, &QTimer::timeout, this, &ActionManager::slotAutoArchive);
184

Laurent Montel's avatar
Laurent Montel committed
185 186 187 188
    // First auto-archive should be in 5 minutes (like in kmail).
    if (CalendarSupport::KCalPrefs::instance()->mAutoArchive) {
        mAutoArchiveTimer->start(5 * 60 * 1000);   // singleshot
    }
189

Laurent Montel's avatar
Laurent Montel committed
190
    setTitle();
191

Laurent Montel's avatar
Laurent Montel committed
192 193
    connect(mCalendarView, &CalendarView::modifiedChanged, this, &ActionManager::setTitle);
    connect(mCalendarView, &CalendarView::configChanged, this, &ActionManager::updateConfig);
194

195 196
    connect(mCalendarView, &CalendarView::incidenceSelected,
            this, &ActionManager::processIncidenceSelection);
Laurent Montel's avatar
Laurent Montel committed
197 198
    connect(mCalendarView, SIGNAL(exportHTML(KOrg::HTMLExportSettings*)),
            this, SLOT(exportHTML(KOrg::HTMLExportSettings*)));
199

Laurent Montel's avatar
Laurent Montel committed
200
    processIncidenceSelection(Akonadi::Item(), QDate());
201

Laurent Montel's avatar
Laurent Montel committed
202 203
    // Update state of paste action
    mCalendarView->checkClipboard();
204 205
}

206 207
Akonadi::ETMCalendar::Ptr ActionManager::calendar() const
{
Laurent Montel's avatar
Laurent Montel committed
208
    return mCalendarView->calendar();
209 210
}

211 212
void ActionManager::createCalendarAkonadi()
{
Laurent Montel's avatar
Laurent Montel committed
213
    Q_ASSERT(calendar());
214

215
    KSharedConfig::Ptr config = KSharedConfig::openConfig();
Laurent Montel's avatar
Laurent Montel committed
216 217 218 219
    mCollectionSelectionModelStateSaver =
        new KViewStateMaintainer<Akonadi::ETMViewStateSaver>(
        config->group("GlobalCollectionSelection"));
    mCollectionSelectionModelStateSaver->setSelectionModel(calendar()->checkableProxyModel()->selectionModel());
220

Laurent Montel's avatar
Laurent Montel committed
221 222 223
    AkonadiCollectionViewFactory factory(mCalendarView);
    mCalendarView->addExtension(&factory);
    mCollectionView = factory.collectionView();
Laurent Montel's avatar
Laurent Montel committed
224
    mCollectionView->setObjectName(QStringLiteral("Resource View"));
Laurent Montel's avatar
Laurent Montel committed
225
    connect(mCollectionView, &AkonadiCollectionView::resourcesAddedRemoved, this, &ActionManager::slotResourcesAddedRemoved);
226 227
    connect(mCollectionView, &AkonadiCollectionView::defaultResourceChanged,
            this, &ActionManager::slotDefaultResourceChanged);
Laurent Montel's avatar
Laurent Montel committed
228 229
    connect(mCollectionView, SIGNAL(colorsChanged()),
            mCalendarView, SLOT(updateConfig()));
230

Laurent Montel's avatar
Laurent Montel committed
231 232
    mCollectionViewStateSaver = new KViewStateMaintainer<Akonadi::ETMViewStateSaver>(config->group("GlobalCollectionView"));
    mCollectionViewStateSaver->setView(mCollectionView->view());
233

Laurent Montel's avatar
Laurent Montel committed
234 235
    KCheckableProxyModel *checkableProxy = calendar()->checkableProxyModel();
    QItemSelectionModel  *selectionModel = checkableProxy->selectionModel();
Sergio Martins's avatar
Sergio Martins committed
236

Laurent Montel's avatar
Laurent Montel committed
237
    mCollectionView->setCollectionSelectionProxyModel(checkableProxy);
238

Laurent Montel's avatar
Laurent Montel committed
239 240
    CalendarSupport::CollectionSelection *collectionSelection = new CalendarSupport::CollectionSelection(selectionModel);
    EventViews::EventView::setGlobalCollectionSelection(collectionSelection);
241

Laurent Montel's avatar
Laurent Montel committed
242
    mCalendarView->readSettings();
243

244 245
    connect(calendar().data(), &Akonadi::ETMCalendar::calendarChanged,
            mCalendarView, &CalendarView::resourcesChanged);
Laurent Montel's avatar
Laurent Montel committed
246
    connect(mCalendarView, &CalendarView::configChanged, this, &ActionManager::updateConfig);
247

Laurent Montel's avatar
Laurent Montel committed
248 249
    calendar()->setOwner(KCalCore::Person::Ptr(new KCalCore::Person(CalendarSupport::KCalPrefs::instance()->fullName(),
                         CalendarSupport::KCalPrefs::instance()->email())));
250 251 252 253 254

}

void ActionManager::initActions()
{
Laurent Montel's avatar
Laurent Montel committed
255 256 257 258 259 260 261 262
    QAction *action;

    /*************************** 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
263
            mACollection->addAction(QStringLiteral("korganizer_open"), a);
Laurent Montel's avatar
Laurent Montel committed
264 265 266
        }

        QAction *a = mACollection->addAction(KStandardAction::Print, mCalendarView, SLOT(print()));
Laurent Montel's avatar
Laurent Montel committed
267
        mACollection->addAction(QStringLiteral("korganizer_print"), a);
Laurent Montel's avatar
Laurent Montel committed
268
        a = mACollection->addAction(KStandardAction::PrintPreview, mCalendarView, SLOT(printPreview()));
Laurent Montel's avatar
Laurent Montel committed
269
        mACollection->addAction(QStringLiteral("korganizer_print_preview"), a);
Laurent Montel's avatar
Laurent Montel committed
270 271 272
    } else {
        KStandardAction::open(this, SLOT(file_open()), mACollection);
        KStandardAction::print(mCalendarView, SLOT(print()), mACollection);
273
        KStandardAction::printPreview(mCalendarView, SLOT(printPreview()), mACollection);
Laurent Montel's avatar
Laurent Montel committed
274 275 276 277 278 279 280 281
    }

    //~~~~~~~~~~~~~~~~~~~~~~~~ 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
282
    mACollection->addAction(QStringLiteral("import_icalendar"), mImportAction);
Laurent Montel's avatar
Laurent Montel committed
283 284 285 286 287 288 289
    connect(mImportAction, &QAction::triggered, this, &ActionManager::file_import);

    QAction *importAction = new QAction(i18n("&Import From UNIX Ical Tool"), this);
    setHelpText(importAction, i18n("Import a calendar in another format"));
    importAction->setWhatsThis(
        i18n("Select this menu entry if you would like to import the contents "
             "of a non-iCalendar formatted file into your current calendar."));
Laurent Montel's avatar
Laurent Montel committed
290
    mACollection->addAction(QStringLiteral("import_ical"), importAction);
Laurent Montel's avatar
Laurent Montel committed
291 292 293
    connect(importAction, &QAction::triggered, this, &ActionManager::file_icalimport);

    action = new QAction(i18n("Get &Hot New Stuff..."), this);
Laurent Montel's avatar
Laurent Montel committed
294
    mACollection->addAction(QStringLiteral("downloadnewstuff"), action);
Laurent Montel's avatar
Laurent Montel committed
295 296 297
    connect(action, &QAction::triggered, this, &ActionManager::downloadNewStuff);

    action = new QAction(i18n("Export &Web Page..."), this);
Laurent Montel's avatar
Laurent Montel committed
298
    mACollection->addAction(QStringLiteral("export_web"), action);
Laurent Montel's avatar
Laurent Montel committed
299 300 301
    connect(action, &QAction::triggered, mCalendarView, &CalendarView::exportWeb);

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

    action = new QAction(i18n("Export as &vCalendar..."), this);
Laurent Montel's avatar
Laurent Montel committed
306
    mACollection->addAction(QStringLiteral("export_vcalendar"), action);
Laurent Montel's avatar
Laurent Montel committed
307 308 309 310 311 312 313 314
    connect(action, &QAction::triggered, mCalendarView, &CalendarView::exportVCalendar);

    //Laurent: 2009-03-24 comment it until upload will implement
    //action = new QAction( i18n( "Upload &Hot New Stuff..." ), this );
    //mACollection->addAction( "uploadnewstuff", action );
    //connect( action, SIGNAL(triggered(bool)), SLOT(uploadNewStuff()) );

    action = new QAction(i18n("Archive O&ld Entries..."), this);
Laurent Montel's avatar
Laurent Montel committed
315
    mACollection->addAction(QStringLiteral("file_archive"), action);
Laurent Montel's avatar
Laurent Montel committed
316 317 318
    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
319
    mACollection->addAction(QStringLiteral("purge_completed"), action);
Laurent Montel's avatar
Laurent Montel committed
320 321 322 323 324 325 326 327
    connect(action, &QAction::triggered, mCalendarView, &CalendarView::purgeCompleted);

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

    QAction *pasteAction;
    Akonadi::History *history = mCalendarView->history();
    if (mIsPart) {
        // edit menu
Laurent Montel's avatar
Laurent Montel committed
328
        mCutAction = mACollection->addAction(KStandardAction::Cut, QStringLiteral("korganizer_cut"),
Laurent Montel's avatar
Laurent Montel committed
329
                                             mCalendarView, SLOT(edit_cut()));
Laurent Montel's avatar
Laurent Montel committed
330
        mCopyAction = mACollection->addAction(KStandardAction::Copy, QStringLiteral("korganizer_copy"),
Laurent Montel's avatar
Laurent Montel committed
331
                                              mCalendarView, SLOT(edit_copy()));
Laurent Montel's avatar
Laurent Montel committed
332
        pasteAction = mACollection->addAction(KStandardAction::Paste, QStringLiteral("korganizer_paste"),
Laurent Montel's avatar
Laurent Montel committed
333
                                              mCalendarView, SLOT(edit_paste()));
Laurent Montel's avatar
Laurent Montel committed
334
        mUndoAction = mACollection->addAction(KStandardAction::Undo, QStringLiteral("korganizer_undo"),
Laurent Montel's avatar
Laurent Montel committed
335
                                              history, SLOT(undo()));
Laurent Montel's avatar
Laurent Montel committed
336
        mRedoAction = mACollection->addAction(KStandardAction::Redo, QStringLiteral("korganizer_redo"),
Laurent Montel's avatar
Laurent Montel committed
337 338 339 340 341 342 343 344
                                              history, SLOT(redo()));
    } else {
        mCutAction = KStandardAction::cut(mCalendarView, SLOT(edit_cut()), mACollection);
        mCopyAction = KStandardAction::copy(mCalendarView, SLOT(edit_copy()), mACollection);
        pasteAction = KStandardAction::paste(mCalendarView, SLOT(edit_paste()), mACollection);
        mUndoAction = KStandardAction::undo(history, SLOT(undo()), mACollection);
        mRedoAction = KStandardAction::redo(history, SLOT(redo()), mACollection);
    }
Laurent Montel's avatar
Laurent Montel committed
345
    mDeleteAction = new QAction(QIcon::fromTheme(QStringLiteral("edit-delete")), i18n("&Delete"), this);
Laurent Montel's avatar
Laurent Montel committed
346
    mACollection->addAction(QStringLiteral("edit_delete"), mDeleteAction);
Laurent Montel's avatar
Laurent Montel committed
347 348 349 350 351
    connect(mDeleteAction, &QAction::triggered, mCalendarView, &CalendarView::appointment_delete);
    if (mIsPart) {
        QAction *a =
            KStandardAction::find(mCalendarView->dialogManager(),
                                  SLOT(showSearchDialog()), mACollection);
Laurent Montel's avatar
Laurent Montel committed
352
        mACollection->addAction(QStringLiteral("korganizer_find"), a);
Laurent Montel's avatar
Laurent Montel committed
353 354 355 356 357 358 359 360
    } else {
        KStandardAction::find(mCalendarView->dialogManager(),
                              SLOT(showSearchDialog()), mACollection);
    }
    pasteAction->setEnabled(false);
    mUndoAction->setEnabled(false);
    mRedoAction->setEnabled(false);
    connect(mCalendarView, &CalendarView::pasteEnabled, pasteAction, &QAction::setEnabled);
361
    connect(history, &Akonadi::History::changed, this, &ActionManager::updateUndoRedoActions);
Laurent Montel's avatar
Laurent Montel committed
362 363 364 365

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

    //~~~~~~~~~~~~~~~~~~~~~~~~~~~~ VIEWS ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Laurent Montel's avatar
Laurent Montel committed
366 367
    action = new QAction(QIcon::fromTheme(QStringLiteral("view-calendar-upcoming-events")), i18n("What's &Next"), this);
    mACollection->addAction(QStringLiteral("view_whatsnext"), action);
Laurent Montel's avatar
Laurent Montel committed
368 369
    connect(action, &QAction::triggered, mCalendarView->viewManager(),
            &KOViewManager::showWhatsNextView);
Laurent Montel's avatar
Laurent Montel committed
370

Laurent Montel's avatar
Laurent Montel committed
371 372
    action = new QAction(QIcon::fromTheme(QStringLiteral("view-calendar-month")), i18n("&Month"), this);
    mACollection->addAction(QStringLiteral("view_month"), action);
Laurent Montel's avatar
Laurent Montel committed
373 374
    connect(action, &QAction::triggered,
            mCalendarView->viewManager(), &KOViewManager::showMonthView);
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-agenda")), i18n("&Agenda"), this);
    mACollection->addAction(QStringLiteral("view_agenda"), action);
Laurent Montel's avatar
Laurent Montel committed
378 379
    connect(action, &QAction::triggered,
            mCalendarView->viewManager(), &KOViewManager::showAgendaView);
Laurent Montel's avatar
Laurent Montel committed
380

Laurent Montel's avatar
Laurent Montel committed
381 382
    action = new QAction(QIcon::fromTheme(QStringLiteral("view-calendar-list")), i18n("&Event List"), this);
    mACollection->addAction(QStringLiteral("view_list"), action);
Laurent Montel's avatar
Laurent Montel committed
383 384
    connect(action, &QAction::triggered, mCalendarView->viewManager(),
            &KOViewManager::showListView);
Laurent Montel's avatar
Laurent Montel committed
385

Laurent Montel's avatar
Laurent Montel committed
386 387
    action = new QAction(QIcon::fromTheme(QStringLiteral("view-calendar-tasks")), i18n("&To-do List"), this);
    mACollection->addAction(QStringLiteral("view_todo"), action);
Laurent Montel's avatar
Laurent Montel committed
388 389
    connect(action, &QAction::triggered, mCalendarView->viewManager(),
            &KOViewManager::showTodoView);
Laurent Montel's avatar
Laurent Montel committed
390

Laurent Montel's avatar
Laurent Montel committed
391 392
    action = new QAction(QIcon::fromTheme(QStringLiteral("view-calendar-journal")), i18n("&Journal"), this);
    mACollection->addAction(QStringLiteral("view_journal"), action);
Laurent Montel's avatar
Laurent Montel committed
393 394
    connect(action, &QAction::triggered, mCalendarView->viewManager(),
            &KOViewManager::showJournalView);
Laurent Montel's avatar
Laurent Montel committed
395

Laurent Montel's avatar
Laurent Montel committed
396 397
    action = new QAction(QIcon::fromTheme(QStringLiteral("view-calendar-timeline")), i18n("Time&line"), this);
    mACollection->addAction(QStringLiteral("view_timeline"), action);
Laurent Montel's avatar
Laurent Montel committed
398 399
    connect(action, &QAction::triggered, mCalendarView->viewManager(),
            &KOViewManager::showTimeLineView);
Laurent Montel's avatar
Laurent Montel committed
400

Laurent Montel's avatar
Laurent Montel committed
401 402
    action = new QAction(QIcon::fromTheme(QStringLiteral("view-calendar-time-spent")), i18n("Time&spent"), this);
    mACollection->addAction(QStringLiteral("view_timespent"), action);
Laurent Montel's avatar
Laurent Montel committed
403 404
    connect(action, &QAction::triggered, mCalendarView->viewManager(),
            &KOViewManager::showTimeSpentView);
Laurent Montel's avatar
Laurent Montel committed
405 406 407

    //~~~~~~~~~~~~~~~~~~~~~~~~~~~ REFRESH ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    action = new QAction(i18n("&Refresh"), this);
Laurent Montel's avatar
Laurent Montel committed
408
    mACollection->addAction(QStringLiteral("update"), action);
Laurent Montel's avatar
Laurent Montel committed
409 410 411 412 413 414
    connect(action, SIGNAL(triggered(bool)), mCalendarView, SLOT(updateView()));

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

    mFilterAction = new KSelectAction(i18n("F&ilter"), this);
    mFilterAction->setToolBarMode(KSelectAction::MenuMode);
Laurent Montel's avatar
Laurent Montel committed
415
    mACollection->addAction(QStringLiteral("filter_select"), mFilterAction);
Laurent Montel's avatar
Laurent Montel committed
416 417 418
    mFilterAction->setEditable(false);
    connect(mFilterAction, SIGNAL(triggered(int)),
            mCalendarView, SLOT(filterActivated(int)));
419 420 421 422
    connect(mCalendarView, &CalendarView::filtersUpdated,
            this, &ActionManager::setItems);
    connect(mCalendarView, &CalendarView::filterChanged,
            this, &ActionManager::setTitle);
Laurent Montel's avatar
Laurent Montel committed
423 424 425

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

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

Laurent Montel's avatar
Laurent Montel committed
438
    action = new QAction(QIcon::fromTheme(QStringLiteral("zoom-in")), i18n("In Vertically"), this);
Laurent Montel's avatar
Laurent Montel committed
439
    action->setEnabled(mCalendarView->currentView()->supportsZoom());
Laurent Montel's avatar
Laurent Montel committed
440
    mACollection->addAction(QStringLiteral("zoom_in_vertically"), action);
441 442
    connect(action, &QAction::triggered, mCalendarView->viewManager(),
            &KOViewManager::zoomInVertically);
Laurent Montel's avatar
Laurent Montel committed
443

Laurent Montel's avatar
Laurent Montel committed
444
    action = new QAction(QIcon::fromTheme(QStringLiteral("zoom-out")), i18n("Out Vertically"), this);
Laurent Montel's avatar
Laurent Montel committed
445
    action->setEnabled(mCalendarView->currentView()->supportsZoom());
Laurent Montel's avatar
Laurent Montel committed
446
    mACollection->addAction(QStringLiteral("zoom_out_vertically"), action);
447 448
    connect(action, &QAction::triggered, mCalendarView->viewManager(),
            &KOViewManager::zoomOutVertically);
Laurent Montel's avatar
Laurent Montel committed
449 450 451 452

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

Laurent Montel's avatar
Laurent Montel committed
453
    action = new QAction(QIcon::fromTheme(QStringLiteral("go-jump-today")),
Laurent Montel's avatar
Laurent Montel committed
454 455 456
                         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
457
    mACollection->addAction(QStringLiteral("go_today"), action);
Laurent Montel's avatar
Laurent Montel committed
458 459
    connect(action, &QAction::triggered, mCalendarView, &CalendarView::goToday);

460
    action = new QAction(QIcon::fromTheme(isRTL ? QStringLiteral("go-next") : QStringLiteral("go-previous")),
Laurent Montel's avatar
Laurent Montel committed
461 462 463
                         i18nc("scroll backward", "&Backward"), this);
    action->setIconText(i18nc("scroll backward", "Back"));
    setHelpText(action, i18n("Scroll Backward"));
Laurent Montel's avatar
Laurent Montel committed
464
    mACollection->addAction(QStringLiteral("go_previous"), action);
Laurent Montel's avatar
Laurent Montel committed
465 466 467 468 469 470 471 472 473 474
    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)) );*/

475
    action = new QAction(QIcon::fromTheme(isRTL ? QStringLiteral("go-previous") : QStringLiteral("go-next")),
Laurent Montel's avatar
Laurent Montel committed
476 477 478
                         i18nc("scroll forward", "&Forward"), this);
    action->setIconText(i18nc("scoll forward", "Forward"));
    setHelpText(action, i18n("Scroll Forward"));
Laurent Montel's avatar
Laurent Montel committed
479
    mACollection->addAction(QStringLiteral("go_next"), action);
Laurent Montel's avatar
Laurent Montel committed
480 481 482 483 484 485
    connect(action, &QAction::triggered, mCalendarView, &CalendarView::goNext);
    /*
    connect( mCalendarView,SIGNAL(changeNavStringNext(QString)),
             action,SLOT(setText(QString)) );
    */

Laurent Montel's avatar
Laurent Montel committed
486
    action = new QAction(QIcon::fromTheme(QStringLiteral("view-calendar-day")), i18n("&Day"), this);
Laurent Montel's avatar
Laurent Montel committed
487
    mACollection->addAction(QStringLiteral("select_day"), action);
Laurent Montel's avatar
Laurent Montel committed
488
    action->setEnabled(mCalendarView->currentView()->supportsDateRangeSelection());
489 490
    connect(action, &QAction::triggered, mCalendarView->viewManager(),
            &KOViewManager::selectDay);
Laurent Montel's avatar
Laurent Montel committed
491

Laurent Montel's avatar
Laurent Montel committed
492
    mNextXDays = new QAction(QIcon::fromTheme(QStringLiteral("view-calendar-upcoming-days")), QString(), this);
Laurent Montel's avatar
Laurent Montel committed
493
    mNextXDays->setEnabled(mCalendarView->currentView()->supportsDateRangeSelection());
Laurent Montel's avatar
Laurent Montel committed
494
    mACollection->addAction(QStringLiteral("select_nextx"), mNextXDays);
495 496
    connect(mNextXDays, &QAction::triggered, mCalendarView->viewManager(),
            &KOViewManager::selectNextX);
Laurent Montel's avatar
Laurent Montel committed
497 498
    mNextXDays->setText(i18np("&Next Day", "&Next %1 Days", KOPrefs::instance()->mNextXDays));

Laurent Montel's avatar
Laurent Montel committed
499
    action = new QAction(QIcon::fromTheme(QStringLiteral("view-calendar-workweek")), i18n("W&ork 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_workweek"), action);
502 503
    connect(action, &QAction::triggered, mCalendarView->viewManager(),
            &KOViewManager::selectWorkWeek);
Laurent Montel's avatar
Laurent Montel committed
504

Laurent Montel's avatar
Laurent Montel committed
505
    action = new QAction(QIcon::fromTheme(QStringLiteral("view-calendar-week")), i18n("&Week"), this);
Laurent Montel's avatar
Laurent Montel committed
506
    action->setEnabled(mCalendarView->currentView()->supportsDateRangeSelection());
Laurent Montel's avatar
Laurent Montel committed
507
    mACollection->addAction(QStringLiteral("select_week"), action);
508 509
    connect(action, &QAction::triggered, mCalendarView->viewManager(),
            &KOViewManager::selectWeek);
Laurent Montel's avatar
Laurent Montel committed
510 511

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

Laurent Montel's avatar
Laurent Montel committed
516
    mACollection->addAction(QStringLiteral("new_event"), mNewEventAction);
517 518
    connect(mNewEventAction, &QAction::triggered, this,
            &ActionManager::slotNewEvent);
Laurent Montel's avatar
Laurent Montel committed
519

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

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

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

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

    mShowIncidenceAction = new QAction(i18n("&Show"), this);
Laurent Montel's avatar
Laurent Montel committed
552
    mACollection->addAction(QStringLiteral("show_incidence"), mShowIncidenceAction);
Laurent Montel's avatar
Laurent Montel committed
553 554 555 556
    connect(mShowIncidenceAction, SIGNAL(triggered(bool)), mCalendarView,
            SLOT(showIncidence()));

    mEditIncidenceAction = new QAction(i18n("&Edit..."), this);
Laurent Montel's avatar
Laurent Montel committed
557
    mACollection->addAction(QStringLiteral("edit_incidence"), mEditIncidenceAction);
Laurent Montel's avatar
Laurent Montel committed
558 559 560 561
    connect(mEditIncidenceAction, SIGNAL(triggered(bool)), mCalendarView,
            SLOT(editIncidence()));

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

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

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

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

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

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

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

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

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

Laurent Montel's avatar
Laurent Montel committed
628
    mForwardEvent = new QAction(QIcon::fromTheme(QStringLiteral("mail-forward")), i18n("&Send as iCalendar..."), this);
Laurent Montel's avatar
Laurent Montel committed
629
    mACollection->addAction(QStringLiteral("schedule_forward"), mForwardEvent);
Laurent Montel's avatar
Laurent Montel committed
630 631 632 633
    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
634
    mACollection->addAction(QStringLiteral("upload_freebusy"), action);
Laurent Montel's avatar
Laurent Montel committed
635 636 637 638
    connect(action, &QAction::triggered, mCalendarView, &CalendarView::uploadFreeBusy);
    action->setEnabled(true);

    if (!mIsPart) {
Laurent Montel's avatar
Laurent Montel committed
639
        action = new QAction(QIcon::fromTheme(QStringLiteral("help-contents")), i18n("&Address Book"), this);
Laurent Montel's avatar
Laurent Montel committed
640
        mACollection->addAction(QStringLiteral("addressbook"), action);
Laurent Montel's avatar
Laurent Montel committed
641 642 643 644 645 646 647
        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
648
    mACollection->addAction(QStringLiteral("show_datenavigator"), mDateNavigatorShowAction);
Laurent Montel's avatar
Laurent Montel committed
649 650 651
    connect(mDateNavigatorShowAction, &KToggleAction::triggered, this, &ActionManager::toggleDateNavigator);

    mTodoViewShowAction = new KToggleAction(i18n("Show To-do View"), this);
Laurent Montel's avatar
Laurent Montel committed
652
    mACollection->addAction(QStringLiteral("show_todoview"), mTodoViewShowAction);
Laurent Montel's avatar
Laurent Montel committed
653 654 655
    connect(mTodoViewShowAction, &KToggleAction::triggered, this, &ActionManager::toggleTodoView);

    mEventViewerShowAction = new KToggleAction(i18n("Show Item Viewer"), this);
Laurent Montel's avatar
Laurent Montel committed
656
    mACollection->addAction(QStringLiteral("show_eventviewer"), mEventViewerShowAction);
Laurent Montel's avatar
Laurent Montel committed
657
    connect(mEventViewerShowAction, &KToggleAction::triggered, this, &ActionManager::toggleEventViewer);
658 659

    KConfigGroup config(KSharedConfig::openConfig(), "Settings");
Laurent Montel's avatar
Laurent Montel committed
660 661 662 663 664 665 666 667 668 669 670 671 672
    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
673
        mACollection->addAction(QStringLiteral("show_resourceview"), mCollectionViewShowAction);
Laurent Montel's avatar
Laurent Montel committed
674 675 676 677 678 679 680 681 682 683 684 685
        connect(mCollectionViewShowAction, &KToggleAction::triggered, this, &ActionManager::toggleResourceView);
        mCollectionViewShowAction->setChecked(config.readEntry("ResourceViewVisible", true));

        toggleResourceView();
    }

    //~~~~~~~~~~~~~~~~~~~~~~~~~~~~ SIDEBAR ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    mHideMenuBarAction = KStandardAction::showMenubar(this, SLOT(toggleMenubar()), mACollection);
    mHideMenuBarAction->setChecked(KOPrefs::instance()->showMenuBar());
    toggleMenubar(true);

    action = new QAction(i18n("Configure &Date && Time..."), this);
Laurent Montel's avatar
Laurent Montel committed
686
    mACollection->addAction(QStringLiteral("conf_datetime"), action);
687 688
    connect(action, &QAction::triggered,
            this, &ActionManager::configureDateTime);
689
// TODO: Add an item to show the resource management dlg
Laurent Montel's avatar
Laurent Montel committed
690
//   new QAction( i18n( "Manage &Calendars..." ), 0,
691 692 693
//                     this, SLOT(manageResources()),
//                     mACollection, "conf_resources" );

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

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

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

Laurent Montel's avatar
Laurent Montel committed
717
void ActionManager::setItems(const QStringList &lst, int idx)
718
{
Laurent Montel's avatar
Laurent Montel committed
719 720
    mFilterAction->setItems(lst);
    mFilterAction->setCurrentItem(idx);
721 722 723 724
}

void ActionManager::slotResourcesAddedRemoved()
{
Laurent Montel's avatar
Laurent Montel committed
725
    restoreCollectionViewSetting();
726 727
}

Laurent Montel's avatar
Laurent Montel committed
728
void ActionManager::slotDefaultResourceChanged(const Akonadi::Collection &collection)
729
{
Laurent Montel's avatar
Laurent Montel committed
730
    mCalendarView->incidenceChanger()->setDefaultCollection(collection);
731 732 733 734
}

void ActionManager::slotNewEvent()
{
Laurent Montel's avatar
Laurent Montel committed
735
    mCalendarView->newEvent();
736 737 738 739
}

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

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

void ActionManager::slotNewJournal()
{
Laurent Montel's avatar
Laurent Montel committed
750
    mCalendarView->newJournal(selectedCollection());
751 752
}

Sergio Martins's avatar
Sergio Martins committed
753
void ActionManager::slotMergeFinished(bool success, int total)
754 755 756 757
{
    Q_ASSERT(sender());
    sender()->deleteLater();
    mImportAction->setEnabled(true);
Laurent Montel's avatar
Laurent Montel committed
758
    Akonadi::ICalImporter *importer = qobject_cast<Akonadi::ICalImporter *>(sender());
759 760

    if (success) {
Pino Toscano's avatar
Pino Toscano committed
761
        mCalendarView->showMessage(i18np("1 incidence was imported successfully.", "%1 incidences were imported successfully.", total), KMessageWidget::Information);
762
    } else {
Sergio Martins's avatar
Sergio Martins committed
763
        mCalendarView->showMessage(i18n("There was an error while merging the calendar: %1", importer->errorMessage()), KMessageWidget::Error);
764 765 766 767 768 769 770
    }
}

void ActionManager::slotNewResourceFinished(bool success)
{
    Q_ASSERT(sender());
    sender()->deleteLater();
Laurent Montel's avatar
Laurent Montel committed
771
    Akonadi::ICalImporter *importer = qobject_cast<Akonadi::ICalImporter *>(sender());
772 773 774 775 776 777
    mImportAction->setEnabled(true);
    if (success) {
        mCalendarView->showMessage(i18n("New calendar added successfully"), KMessageWidget::Information);
    } else {
        mCalendarView->showMessage(i18n("Could not add a calendar. Error: %1", importer->errorMessage()), KMessageWidget::Error);
    }
778 779 780 781
}

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

Laurent Montel's avatar
Laurent Montel committed
785 786
    mCalendarView->readSettings();
    restoreCollectionViewSetting();
787 788 789 790
}

void ActionManager::restoreCollectionViewSetting()
{
Laurent Montel's avatar
Laurent Montel committed
791 792
    mCollectionSelectionModelStateSaver->restoreState();
    mCollectionViewStateSaver->restoreState();
793 794 795 796
}

void ActionManager::writeSettings()
{
797 798
    KSharedConfig::Ptr config = KSharedConfig::openConfig();
    KConfigGroup group = config->group("Settings");
Laurent Montel's avatar
Laurent Montel committed
799
    mCalendarView->writeSettings();
800

Laurent Montel's avatar
Laurent Montel committed
801
    if (mDateNavigatorShowAction) {
802
        group.writeEntry("DateNavigatorVisible", mDateNavigatorShowAction->isChecked());
Laurent Montel's avatar
Laurent Montel committed
803
    }
804

Laurent Montel's avatar
Laurent Montel committed
805
    if (mTodoViewShowAction) {
806
        group.writeEntry("TodoViewVisible", mTodoViewShowAction->isChecked());
Laurent Montel's avatar
Laurent Montel committed
807
    }
808

Laurent Montel's avatar
Laurent Montel committed
809
    if (mCollectionViewShowAction) {
810
        group.writeEntry("ResourceViewVisible", mCollectionViewShowAction->isChecked());
Laurent Montel's avatar
Laurent Montel committed
811
    }
812

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

Laurent Montel's avatar
Laurent Montel committed
817 818
    mCollectionViewStateSaver->saveState();
    mCollectionSelectionModelStateSaver->saveState();
819

820 821
    KConfigGroup selectionViewGroup = config->group("GlobalCollectionView");
    KConfigGroup selectionGroup = config->group("GlobalCollectionSelection");
Laurent Montel's avatar
Laurent Montel committed
822 823
    selectionGroup.sync();
    selectionViewGroup.sync();
824
    config->sync();
825 826
}