File indexing completed on 2024-05-12 05:21:18
0001 /* 0002 This file is part of KOrganizer. 0003 0004 SPDX-FileCopyrightText: 2002 Mike Pilone <mpilone@slac.com> 0005 SPDX-FileCopyrightText: 2002 Don Sanders <sanders@kde.org> 0006 SPDX-FileCopyrightText: 2003, 2004 Cornelius Schumacher <schumacher@kde.org> 0007 SPDX-FileCopyrightText: 2003-2004 Reinhold Kainhofer <reinhold@kainhofer.com> 0008 SPDX-FileCopyrightText: 2005 Rafal Rzepecki <divide@users.sourceforge.net> 0009 0010 SPDX-License-Identifier: GPL-2.0-or-later WITH Qt-Commercial-exception-1.0 0011 */ 0012 0013 #pragma once 0014 0015 #include "korganizerprivate_export.h" 0016 0017 #include <Akonadi/ETMCalendar> 0018 #include <Akonadi/Item> 0019 0020 #include <KViewStateMaintainer> 0021 #include <KXMLGUIClient> 0022 0023 #include <QUrl> 0024 0025 #include <QObject> 0026 0027 #include "mainwindow.h" 0028 0029 class AkonadiCollectionView; 0030 class CalendarView; 0031 class KOWindowList; 0032 0033 namespace Akonadi 0034 { 0035 class ETMViewStateSaver; 0036 } 0037 0038 class QAction; 0039 class QMenuBar; 0040 class QToolBar; 0041 class KSelectAction; 0042 class QTemporaryFile; 0043 class KToggleAction; 0044 class KHamburgerMenu; 0045 0046 /** 0047 The ActionManager creates all the actions in KOrganizer. This class 0048 is shared between the main application and the part so all common 0049 actions are in one location. 0050 It also provides D-Bus interfaces. 0051 */ 0052 class KORGANIZERPRIVATE_EXPORT ActionManager : public QObject 0053 { 0054 Q_OBJECT 0055 public: 0056 ActionManager(KXMLGUIClient *client, 0057 CalendarView *widget, 0058 QObject *parent, 0059 KOrg::MainWindow *mainWindow, 0060 bool isPart, 0061 QMenuBar *menuBar = nullptr, 0062 QToolBar *toolBar = nullptr); 0063 ~ActionManager() override; 0064 0065 /** Perform initialization that requires this* to be full constructed */ 0066 void init(); 0067 0068 CalendarView *view() const 0069 { 0070 return mCalendarView; 0071 } 0072 0073 /** 0074 Create Calendar object based on the akonadi framework and set it on the view. 0075 */ 0076 void createCalendarAkonadi(); 0077 0078 public Q_SLOTS: 0079 bool importURL(const QUrl &url, bool merge); 0080 0081 /** Save calendar file to URL of current calendar */ 0082 [[nodiscard]] bool saveURL(); 0083 0084 /** Save calendar file to URL */ 0085 [[nodiscard]] bool saveAsURL(const QUrl &QUrl); 0086 0087 void toggleMenubar(bool dontShowWarning = false); 0088 0089 public: 0090 /** Get current URL */ 0091 [[nodiscard]] QUrl url() const 0092 { 0093 return mURL; 0094 } 0095 0096 /** Is there a instance with this URL? */ 0097 static KOrg::MainWindow *findInstance(const QUrl &url); 0098 0099 /** Open calendar file from URL */ 0100 [[nodiscard]] bool openURL(const QString &url); 0101 0102 /** Open calendar file from URL */ 0103 [[nodiscard]] bool mergeURL(const QString &url); 0104 0105 /** Save calendar file to URL */ 0106 [[nodiscard]] bool saveAsURL(const QString &url); 0107 0108 /** Get current URL as QString */ 0109 [[nodiscard]] QString getCurrentURLasString() const; 0110 0111 /** 0112 Delete the incidence with the given unique id from current calendar. 0113 @param uid UID of the incidence to delete. 0114 @param force If true, all recurrences and sub-todos (if applicable) will 0115 be deleted without prompting for confirmation. 0116 */ 0117 virtual bool deleteIncidence(Akonadi::Item::Id id, bool force = false); 0118 0119 bool editIncidence(Akonadi::Item::Id id); 0120 0121 /** 0122 Add an incidence to the active calendar. 0123 @param ical A calendar in iCalendar format containing the incidence. 0124 */ 0125 bool addIncidence(const QString &ical); 0126 // bool addIncidence( const Akonadi::Item::Id &ical ); 0127 0128 bool showIncidence(Akonadi::Item::Id id); 0129 0130 /** 0131 Show an incidence in context. This means showing the todo, agenda or 0132 journal view (as appropriate) and scrolling it to show the incidence. 0133 @param uid Unique ID of the incidence to show. 0134 */ 0135 bool showIncidenceContext(Akonadi::Item::Id id); 0136 0137 /** 0138 Show an incidence in context, given its uid. 0139 @param uid the iCal uid of the incidence to show. 0140 */ 0141 void showIncidenceByUid(const QString &uid, const QDateTime &occurrence, const QString &xdgActivationToken); 0142 0143 /** 0144 * Called by KOrganizerUniqueAppHandler in the kontact plugin 0145 * Returns true if the command line was successfully handled 0146 * false otherwise. 0147 */ 0148 bool handleCommandLine(const QStringList &args); 0149 0150 public Q_SLOTS: 0151 void openEventEditor(const QString &summary); 0152 void openEventEditor(const QString &summary, const QString &description, const QStringList &attachments); 0153 void openEventEditor(const QString &summary, const QString &description, const QStringList &attachments, const QStringList &attendees); 0154 void openEventEditor(const QString &summary, 0155 const QString &description, 0156 const QString &uri, 0157 const QString &file, 0158 const QStringList &attendees, 0159 const QString &attachmentMimetype); 0160 void openEventEditor(const QString &summary, 0161 const QString &description, 0162 const QStringList &attachmentUris, 0163 const QStringList &attendees, 0164 const QStringList &attachmentMimetypes, 0165 bool attachmentIsInline); 0166 void openTodoEditor(const QString &); 0167 void openTodoEditor(const QString &summary, const QString &description, const QStringList &attachments); 0168 void openTodoEditor(const QString &summary, const QString &description, const QStringList &attachments, const QStringList &attendees); 0169 void openTodoEditor(const QString &summary, 0170 const QString &description, 0171 const QString &uri, 0172 const QString &file, 0173 const QStringList &attendees, 0174 const QString &attachmentMimetype); 0175 void openTodoEditor(const QString &summary, 0176 const QString &description, 0177 const QStringList &attachmentUris, 0178 const QStringList &attendees, 0179 const QStringList &attachmentMimetypes, 0180 bool attachmentIsInline); 0181 0182 void openJournalEditor(QDate date); 0183 void openJournalEditor(const QString &text, QDate date); 0184 void openJournalEditor(const QString &text); 0185 0186 void showJournalView(); 0187 void showTodoView(); 0188 void showEventView(); 0189 0190 void goDate(QDate); 0191 void goDate(const QString &); 0192 void showDate(QDate date); 0193 0194 public: 0195 QString localFileName() const; 0196 0197 bool queryClose(); 0198 0199 Q_SIGNALS: 0200 /** 0201 Emitted when the "New" action is activated. 0202 */ 0203 // void actionNewMainWindow( const QUrl &url = QUrl() ); 0204 /** 0205 When change is made to options dialog, the topwidget will catch this 0206 and Q_EMIT this signal which notifies all widgets which have registered 0207 for notification to update their settings. 0208 */ 0209 void configChanged(); 0210 0211 public Q_SLOTS: 0212 /** 0213 Options dialog made a changed to the configuration. we catch this 0214 and notify all widgets which need to update their configuration. 0215 */ 0216 void updateConfig(); 0217 0218 void processIncidenceSelection(const Akonadi::Item &item, QDate date); 0219 void keyBindings(); 0220 0221 /** 0222 Using the KConfig associated with the kapp variable, read in the 0223 settings from the config file. 0224 */ 0225 void readSettings(); 0226 0227 /** 0228 Write current state to config file. 0229 */ 0230 void writeSettings(); 0231 0232 /* Session management */ 0233 void saveProperties(KConfigGroup &); 0234 void readProperties(const KConfigGroup &); 0235 0236 void importCalendar(const QUrl &url); 0237 0238 protected Q_SLOTS: 0239 void setItems(const QStringList &, int); 0240 0241 /** open a file, load it into the calendar. */ 0242 void file_open(); 0243 0244 /** open a file from the list of recent files. Also called from file_open() 0245 after the URL is obtained from the user. 0246 @param url the URL to open 0247 */ 0248 void file_open(const QUrl &url); 0249 0250 /** import a generic ics file */ 0251 void file_import(); 0252 0253 /** delete or archive old entries in your calendar for speed/space. */ 0254 void file_archive(); 0255 0256 /** Open kcontrol module for configuring date and time formats */ 0257 void configureDateTime(); 0258 0259 void toggleDateNavigator(); 0260 void toggleTodoView(); 0261 void toggleEventViewer(); 0262 void toggleResourceView(); 0263 0264 /** connected to CalendarView's signal which comes from the ArchiveDialog */ 0265 void slotAutoArchivingSettingsModified(); 0266 0267 /** called by the auto archive timer to automatically delete/archive events */ 0268 void slotAutoArchive(); 0269 0270 void setTitle(); 0271 0272 void updateUndoRedoActions(); 0273 0274 protected: 0275 /** 0276 Return widget used as parent for dialogs and message boxes. 0277 */ 0278 QWidget *dialogParent(); 0279 0280 private Q_SLOTS: 0281 void dumpText(const QString &); // only for debugging purposes 0282 0283 void slotDefaultResourceChanged(const Akonadi::Collection &); 0284 void slotResourcesAddedRemoved(); 0285 0286 void slotNewEvent(); 0287 void slotNewTodo(); 0288 void slotNewSubTodo(); 0289 void slotNewJournal(); 0290 0291 void slotMergeFinished(bool success, int total); 0292 void slotNewResourceFinished(bool); 0293 0294 private: 0295 class ActionStringsVisitor; 0296 void restoreCollectionViewSetting(); 0297 /** Create all the actions. */ 0298 void initActions(); 0299 void enableIncidenceActions(bool enable); 0300 void updateHamburgerMenu(); 0301 Akonadi::ETMCalendar::Ptr calendar() const; 0302 0303 Akonadi::Collection selectedCollection() const; 0304 0305 QUrl mURL; // URL of calendar file 0306 QString mFile; // Local name of calendar file 0307 QString mLastUrl; // URL of last loaded calendar. 0308 0309 QTemporaryFile *mTempFile = nullptr; 0310 QTimer *mAutoExportTimer = nullptr; // used if calendar is to be autoexported 0311 QTimer *mAutoArchiveTimer = nullptr; // used for the auto-archiving feature 0312 0313 // list of all existing KOrganizer instances 0314 static KOWindowList *mWindowList; 0315 0316 KToggleAction *mDateNavigatorShowAction = nullptr; 0317 KToggleAction *mTodoViewShowAction = nullptr; 0318 KToggleAction *mCollectionViewShowAction = nullptr; 0319 KToggleAction *mEventViewerShowAction = nullptr; 0320 0321 KToggleAction *mShowMenuBarAction = nullptr; 0322 0323 QAction *mImportAction = nullptr; 0324 0325 QAction *mNewEventAction = nullptr; 0326 QAction *mNewTodoAction = nullptr; 0327 QAction *mNewSubtodoAction = nullptr; 0328 QAction *mNewJournalAction = nullptr; 0329 QAction *mConfigureViewAction = nullptr; 0330 0331 QAction *mShowIncidenceAction = nullptr; 0332 QAction *mEditIncidenceAction = nullptr; 0333 QAction *mDeleteIncidenceAction = nullptr; 0334 0335 QAction *mCutAction = nullptr; 0336 QAction *mCopyAction = nullptr; 0337 QAction *mDeleteAction = nullptr; 0338 QAction *mNextXDays = nullptr; 0339 QAction *mPublishEvent = nullptr; 0340 QAction *mForwardEvent = nullptr; 0341 0342 QAction *mSendInvitation = nullptr; 0343 QAction *mSendCancel = nullptr; 0344 QAction *mSendStatusUpdate = nullptr; 0345 0346 QAction *mRequestChange = nullptr; 0347 QAction *mRequestUpdate = nullptr; 0348 0349 QAction *mUndoAction = nullptr; 0350 QAction *mRedoAction = nullptr; 0351 QMenuBar *mMenuBar = nullptr; 0352 0353 KSelectAction *mFilterAction = nullptr; 0354 0355 KXMLGUIClient *mGUIClient = nullptr; 0356 KActionCollection *mACollection = nullptr; 0357 CalendarView *mCalendarView = nullptr; 0358 KOrg::MainWindow *mMainWindow = nullptr; 0359 QToolBar *mToolBar = nullptr; 0360 bool mIsPart; 0361 0362 AkonadiCollectionView *mCollectionView = nullptr; 0363 KViewStateMaintainer<Akonadi::ETMViewStateSaver> *mCollectionViewStateSaver = nullptr; 0364 KViewStateMaintainer<Akonadi::ETMViewStateSaver> *mCollectionSelectionModelStateSaver = nullptr; 0365 KHamburgerMenu *mHamburgerMenu = nullptr; 0366 };