actionmanager.h 11.3 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
/*
  This file is part of KOrganizer.

  Copyright (c) 2002 Mike Pilone <mpilone@slac.com>
  Copyright (c) 2002 Don Sanders <sanders@kde.org>
  Copyright (c) 2003,2004 Cornelius Schumacher <schumacher@kde.org>
  Copyright (C) 2003-2004 Reinhold Kainhofer <reinhold@kainhofer.com>
  Copyright (c) 2005 Rafal Rzepecki <divide@users.sourceforge.net>

  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.
*/
28

29
30
31
#ifndef KORG_ACTIONMANAGER_H
#define KORG_ACTIONMANAGER_H

Laurent Montel's avatar
Laurent Montel committed
32
#include "korganizerprivate_export.h"
33
#include "part.h"
34

Laurent Montel's avatar
Laurent Montel committed
35
#include <AkonadiCore/Item>
Sergio Martins's avatar
Sergio Martins committed
36
#include <Akonadi/Calendar/ETMCalendar>
37

Laurent Montel's avatar
Laurent Montel committed
38
#include <QUrl>
39
#include <KViewStateMaintainer>
40
41
42

#include <QObject>

43
44
45
class AkonadiCollectionView;
class CalendarView;
class KOWindowList;
46

Laurent Montel's avatar
Laurent Montel committed
47
namespace Akonadi {
Laurent Montel's avatar
Laurent Montel committed
48
class ETMViewStateSaver;
49
50
}

Laurent Montel's avatar
Laurent Montel committed
51
class QAction;
Laurent Montel's avatar
Laurent Montel committed
52
class QMenuBar;
53
class KSelectAction;
Laurent Montel's avatar
Laurent Montel committed
54
class QTemporaryFile;
55
56
57
58
59
60
61
62
63
64
class KToggleAction;

/**
  The ActionManager creates all the actions in KOrganizer. This class
  is shared between the main application and the part so all common
  actions are in one location.
  It also provides D-Bus interfaces.
*/
class KORGANIZERPRIVATE_EXPORT ActionManager : public QObject
{
Laurent Montel's avatar
Laurent Montel committed
65
66
    Q_OBJECT
public:
Laurent Montel's avatar
Laurent Montel committed
67
    ActionManager(KXMLGUIClient *client, CalendarView *widget, QObject *parent, KOrg::MainWindow *mainWindow, bool isPart, QMenuBar *menuBar = nullptr);
Laurent Montel's avatar
Laurent Montel committed
68
    ~ActionManager() override;
69

Yuri Chornoivan's avatar
Yuri Chornoivan committed
70
    /** Perform initialization that requires this* to be full constructed */
71
72
    void init();

Laurent Montel's avatar
Laurent Montel committed
73
74
75
76
    CalendarView *view() const
    {
        return mCalendarView;
    }
77
78
79
80
81
82

    /**
      Create Calendar object based on the akonadi framework and set it on the view.
    */
    void createCalendarAkonadi();

Laurent Montel's avatar
Laurent Montel committed
83
public Q_SLOTS:
Laurent Montel's avatar
Laurent Montel committed
84
    bool importURL(const QUrl &url, bool merge);
85
86

    /** Save calendar file to URL of current calendar */
Laurent Montel's avatar
Laurent Montel committed
87
    Q_REQUIRED_RESULT bool saveURL();
88
89

    /** Save calendar file to URL */
Laurent Montel's avatar
Laurent Montel committed
90
    Q_REQUIRED_RESULT bool saveAsURL(const QUrl &QUrl);
91

Laurent Montel's avatar
Laurent Montel committed
92
    void toggleMenubar(bool dontShowWarning = false);
93

Laurent Montel's avatar
Laurent Montel committed
94
public:
95
    /** Get current URL */
Laurent Montel's avatar
Laurent Montel committed
96
    Q_REQUIRED_RESULT QUrl url() const
Laurent Montel's avatar
Laurent Montel committed
97
98
99
    {
        return mURL;
    }
100
101

    /** Is there a instance with this URL? */
Laurent Montel's avatar
Laurent Montel committed
102
    static KOrg::MainWindow *findInstance(const QUrl &url);
103
104

    /** Open calendar file from URL */
Laurent Montel's avatar
Laurent Montel committed
105
    Q_REQUIRED_RESULT bool openURL(const QString &url);
106
107

    /** Open calendar file from URL */
Laurent Montel's avatar
Laurent Montel committed
108
    Q_REQUIRED_RESULT bool mergeURL(const QString &url);
109
110

    /** Save calendar file to URL */
Laurent Montel's avatar
Laurent Montel committed
111
    Q_REQUIRED_RESULT bool saveAsURL(const QString &url);
112
113

    /** Get current URL as QString */
Laurent Montel's avatar
Laurent Montel committed
114
    Q_REQUIRED_RESULT QString getCurrentURLasString() const;
115
116
117
118
119
120
121

    /**
      Delete the incidence with the given unique id from current calendar.
      @param uid UID of the incidence to delete.
      @param force If true, all recurrences and sub-todos (if applicable) will
      be deleted without prompting for confirmation.
    */
Laurent Montel's avatar
Laurent Montel committed
122
    virtual bool deleteIncidence(Akonadi::Item::Id id, bool force = false);
123

Laurent Montel's avatar
Laurent Montel committed
124
    bool editIncidence(Akonadi::Item::Id id);
125
126
127
128
129

    /**
      Add an incidence to the active calendar.
      @param ical A calendar in iCalendar format containing the incidence.
    */
Laurent Montel's avatar
Laurent Montel committed
130
    bool addIncidence(const QString &ical);
131
132
    //bool addIncidence( const Akonadi::Item::Id &ical );

Laurent Montel's avatar
Laurent Montel committed
133
    bool showIncidence(Akonadi::Item::Id id);
134
135
136
137
138
139

    /**
      Show an incidence in context. This means showing the todo, agenda or
      journal view (as appropriate) and scrolling it to show the incidence.
      @param uid Unique ID of the incidence to show.
    */
Laurent Montel's avatar
Laurent Montel committed
140
    bool showIncidenceContext(Akonadi::Item::Id id);
141
142
143
144
145
146

    /**
     * Called by KOrganizerUniqueAppHandler in the kontact plugin
     * Returns true if the command line was successfully handled
     * false otherwise.
     */
147
    bool handleCommandLine(const QStringList &args);
148

Laurent Montel's avatar
Laurent Montel committed
149
public Q_SLOTS:
Laurent Montel's avatar
Laurent Montel committed
150
    void openEventEditor(const QString &);
Laurent Montel's avatar
Laurent Montel committed
151
152
153
    void openEventEditor(const QString &summary, const QString &description, const QStringList &attachments);
    void openEventEditor(const QString &summary, const QString &description, const QStringList &attachments, const QStringList &attendees);
    void openEventEditor(const QString &summary, const QString &description, const QString &uri, const QString &file, const QStringList &attendees, const QString &attachmentMimetype);
Laurent Montel's avatar
Laurent Montel committed
154
    void openEventEditor(const QString &summary, const QString &description, const QStringList &attachmentUris, const QStringList &attendees, const QStringList &attachmentMimetypes, bool attachmentIsInline);
Laurent Montel's avatar
Laurent Montel committed
155
    void openTodoEditor(const QString &);
Laurent Montel's avatar
Laurent Montel committed
156
157
158
    void openTodoEditor(const QString &summary, const QString &description, const QStringList &attachments);
    void openTodoEditor(const QString &summary, const QString &description, const QStringList &attachments, const QStringList &attendees);
    void openTodoEditor(const QString &summary, const QString &description, const QString &uri, const QString &file, const QStringList &attendees, const QString &attachmentMimetype);
Laurent Montel's avatar
Laurent Montel committed
159
    void openTodoEditor(const QString &summary, const QString &description, const QStringList &attachmentUris, const QStringList &attendees, const QStringList &attachmentMimetypes, bool attachmentIsInline);
Laurent Montel's avatar
Laurent Montel committed
160
161
162
163

    void openJournalEditor(const QDate &date);
    void openJournalEditor(const QString &text, const QDate &date);
    void openJournalEditor(const QString &text);
164
165
166
167
168

    void showJournalView();
    void showTodoView();
    void showEventView();

Laurent Montel's avatar
Laurent Montel committed
169
170
171
    void goDate(const QDate &);
    void goDate(const QString &);
    void showDate(const QDate &date);
172

Laurent Montel's avatar
Laurent Montel committed
173
public:
174
175
176
177
    QString localFileName();

    bool queryClose();

Laurent Montel's avatar
Laurent Montel committed
178
Q_SIGNALS:
179
180
181
    /**
      Emitted when the "New" action is activated.
    */
Laurent Montel's avatar
Laurent Montel committed
182
    //void actionNewMainWindow( const QUrl &url = QUrl() );
183
184
185
    void toggleMenuBar();
    /**
      When change is made to options dialog, the topwidget will catch this
Laurent Montel's avatar
Laurent Montel committed
186
      and Q_EMIT this signal which notifies all widgets which have registered
187
188
189
190
      for notification to update their settings.
    */
    void configChanged();

Laurent Montel's avatar
Laurent Montel committed
191
public Q_SLOTS:
192
193
194
195
196
197
    /**
      Options dialog made a changed to the configuration. we catch this
      and notify all widgets which need to update their configuration.
    */
    void updateConfig();

Laurent Montel's avatar
Laurent Montel committed
198
    void processIncidenceSelection(const Akonadi::Item &item, const QDate &date);
199
200
201
202
203
204
205
206
207
208
209
210
211
212
    void keyBindings();

    /**
      Using the KConfig associated with the kapp variable, read in the
      settings from the config file.
    */
    void readSettings();

    /**
      Write current state to config file.
    */
    void writeSettings();

    /* Session management */
Laurent Montel's avatar
Laurent Montel committed
213
214
    void saveProperties(KConfigGroup &);
    void readProperties(const KConfigGroup &);
215
216
217

    void loadParts();

Laurent Montel's avatar
Laurent Montel committed
218
    void importCalendar(const QUrl &url);
219

Laurent Montel's avatar
Laurent Montel committed
220
protected Q_SLOTS:
Laurent Montel's avatar
Laurent Montel committed
221
    void setItems(const QStringList &, int);
222
223
224
225
226
227
228
229

    /** open a file, load it into the calendar. */
    void file_open();

    /** open a file from the list of recent files. Also called from file_open()
        after the URL is obtained from the user.
        @param url the URL to open
    */
Laurent Montel's avatar
KUrl--    
Laurent Montel committed
230
    void file_open(const QUrl &url);
231

232
233
    /** import a generic ics file */
    void file_import();
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255

    /** delete or archive old entries in your calendar for speed/space. */
    void file_archive();

    /** Open kcontrol module for configuring date and time formats */
    void configureDateTime();

    void downloadNewStuff();

    void toggleDateNavigator();
    void toggleTodoView();
    void toggleEventViewer();
    void toggleResourceView();

    /** connected to CalendarView's signal which comes from the ArchiveDialog */
    void slotAutoArchivingSettingsModified();

    /** called by the auto archive timer to automatically delete/archive events */
    void slotAutoArchive();

    void setTitle();

Sergio Martins's avatar
Sergio Martins committed
256
    void updateUndoRedoActions();
257

Laurent Montel's avatar
Laurent Montel committed
258
protected:
259
260
261
262
263
264

    /**
      Return widget used as parent for dialogs and message boxes.
    */
    QWidget *dialogParent();

Laurent Montel's avatar
Laurent Montel committed
265
private Q_SLOTS:
Laurent Montel's avatar
Laurent Montel committed
266
    void dumpText(const QString &);    // only for debugging purposes
267

Laurent Montel's avatar
Laurent Montel committed
268
    void slotDefaultResourceChanged(const Akonadi::Collection &);
269
270
271
272
273
274
    void slotResourcesAddedRemoved();

    void slotNewEvent();
    void slotNewTodo();
    void slotNewSubTodo();
    void slotNewJournal();
275

Sergio Martins's avatar
Sergio Martins committed
276
    void slotMergeFinished(bool success, int total);
277
278
    void slotNewResourceFinished(bool);

Laurent Montel's avatar
Laurent Montel committed
279
private:
280
281
282
283
    class ActionStringsVisitor;
    void restoreCollectionViewSetting();
    /** Create all the actions. */
    void initActions();
Laurent Montel's avatar
Laurent Montel committed
284
    void enableIncidenceActions(bool enable);
285
    Akonadi::ETMCalendar::Ptr calendar() const;
286
287
288
289

    Akonadi::Collection selectedCollection() const;

    KOrg::Part::List mParts; // List of parts loaded
Laurent Montel's avatar
Laurent Montel committed
290
    QUrl mURL;               // URL of calendar file
291
292
293
    QString mFile;           // Local name of calendar file
    QString mLastUrl;        // URL of last loaded calendar.

Laurent Montel's avatar
Laurent Montel committed
294
295
296
    QTemporaryFile *mTempFile = nullptr;
    QTimer *mAutoExportTimer = nullptr;    // used if calendar is to be autoexported
    QTimer *mAutoArchiveTimer = nullptr; // used for the auto-archiving feature
297
298
299
300

    // list of all existing KOrganizer instances
    static KOWindowList *mWindowList;

Laurent Montel's avatar
Laurent Montel committed
301
302
303
304
    KToggleAction *mDateNavigatorShowAction = nullptr;
    KToggleAction *mTodoViewShowAction = nullptr;
    KToggleAction *mCollectionViewShowAction = nullptr;
    KToggleAction *mEventViewerShowAction = nullptr;
305

Laurent Montel's avatar
Laurent Montel committed
306
    KToggleAction *mHideMenuBarAction = nullptr;
307

Laurent Montel's avatar
Laurent Montel committed
308
    QAction *mImportAction = nullptr;
309

Laurent Montel's avatar
Laurent Montel committed
310
311
312
313
314
    QAction *mNewEventAction = nullptr;
    QAction *mNewTodoAction = nullptr;
    QAction *mNewSubtodoAction = nullptr;
    QAction *mNewJournalAction = nullptr;
    QAction *mConfigureViewAction = nullptr;
315

Laurent Montel's avatar
Laurent Montel committed
316
317
318
    QAction *mShowIncidenceAction = nullptr;
    QAction *mEditIncidenceAction = nullptr;
    QAction *mDeleteIncidenceAction = nullptr;
319

Laurent Montel's avatar
Laurent Montel committed
320
321
322
323
324
325
    QAction *mCutAction = nullptr;
    QAction *mCopyAction = nullptr;
    QAction *mDeleteAction = nullptr;
    QAction *mNextXDays = nullptr;
    QAction *mPublishEvent = nullptr;
    QAction *mForwardEvent = nullptr;
326

Laurent Montel's avatar
Laurent Montel committed
327
328
329
    QAction *mSendInvitation = nullptr;
    QAction *mSendCancel = nullptr;
    QAction *mSendStatusUpdate = nullptr;
330

Laurent Montel's avatar
Laurent Montel committed
331
332
    QAction *mRequestChange = nullptr;
    QAction *mRequestUpdate = nullptr;
333

Laurent Montel's avatar
Laurent Montel committed
334
335
336
    QAction *mUndoAction = nullptr;
    QAction *mRedoAction = nullptr;
    QMenuBar *mMenuBar = nullptr;
337

Laurent Montel's avatar
Laurent Montel committed
338
    KSelectAction *mFilterAction = nullptr;
339

Laurent Montel's avatar
Laurent Montel committed
340
341
342
343
    KXMLGUIClient *mGUIClient = nullptr;
    KActionCollection *mACollection = nullptr;
    CalendarView *mCalendarView = nullptr;
    KOrg::MainWindow *mMainWindow = nullptr;
344
345
    bool mIsPart;

Laurent Montel's avatar
Laurent Montel committed
346
347
348
    AkonadiCollectionView *mCollectionView = nullptr;
    KViewStateMaintainer<Akonadi::ETMViewStateSaver> *mCollectionViewStateSaver = nullptr;
    KViewStateMaintainer<Akonadi::ETMViewStateSaver> *mCollectionSelectionModelStateSaver = nullptr;
349
350
351
};

#endif