File indexing completed on 2024-05-12 05:10:50
0001 /* 0002 * SPDX-FileCopyrightText: 2010 Casey Link <unnamedrambler@gmail.com> 0003 * SPDX-FileCopyrightText: 2010 Klaralvdalens Datakonsult AB, a KDAB Group company <info@kdab.net> 0004 * SPDX-FileCopyrightText: 2009-2010 Tobias Koenig <tokoe@kde.org> 0005 * 0006 * SPDX-License-Identifier: LGPL-2.0-or-later 0007 */ 0008 0009 #pragma once 0010 0011 #include "akonadi-calendar_export.h" 0012 0013 #include <Akonadi/StandardActionManager> 0014 #include <KCalendarCore/Todo> 0015 0016 #include <QObject> 0017 0018 #include <memory> 0019 0020 // needed for windows ce, its defined somewhere 0021 #undef CreateEvent 0022 0023 class QAction; 0024 class KActionCollection; 0025 class QItemSelectionModel; 0026 class QWidget; 0027 0028 namespace Akonadi 0029 { 0030 class Item; 0031 class StandardCalendarActionManagerPrivate; 0032 0033 /** 0034 * @short Manages calendar specific actions for collection and item views. 0035 * 0036 * @author Casey Link <unnamedrambler@gmail.com> 0037 * @since 4.6 0038 */ 0039 class AKONADI_CALENDAR_EXPORT StandardCalendarActionManager : public QObject 0040 { 0041 Q_OBJECT 0042 public: 0043 /** 0044 * Describes the supported actions. 0045 */ 0046 enum Type { 0047 CreateEvent = StandardActionManager::LastType + 1, ///< Creates a new event 0048 CreateTodo, ///< Creates a new todo 0049 CreateSubTodo, ///< Creates a new sub-todo 0050 CreateJournal, ///< Creates a new journal 0051 EditIncidence, ///< Edit currently selected event/todo/journal 0052 LastType ///< Marks last action 0053 }; 0054 0055 /** 0056 * Creates a new standard calendar action manager. 0057 * 0058 * @param actionCollection The action collection to operate on. 0059 * @param parent The parent widget. 0060 */ 0061 explicit StandardCalendarActionManager(KActionCollection *actionCollection, QWidget *parent = nullptr); 0062 0063 /** 0064 * Destroys the standard calendar action manager. 0065 */ 0066 ~StandardCalendarActionManager() override; 0067 0068 /** 0069 * Sets the collection selection model based on which the collection 0070 * related actions should operate. If none is set, all collection actions 0071 * will be disabled. 0072 * @param selectionModel the selection model for collections 0073 */ 0074 void setCollectionSelectionModel(QItemSelectionModel *selectionModel); 0075 0076 /** 0077 * Sets the item selection model based on which the item related actions 0078 * should operate. If none is set, all item actions will be disabled. 0079 * @param selectionModel the selection model for items 0080 */ 0081 void setItemSelectionModel(QItemSelectionModel *selectionModel); 0082 0083 /** 0084 * Creates the action of the given type and adds it to the action collection 0085 * specified in the constructor if it does not exist yet. The action is 0086 * connected to its default implementation provided by this class. 0087 * @param type the type of action to create 0088 */ 0089 QAction *createAction(Type type); 0090 0091 /** 0092 * Creates the action of the given type and adds it to the action collection 0093 * specified in the constructor if it does not exist yet. The action is 0094 * connected to its default implementation provided by this class. 0095 * @param type the type of action to create 0096 */ 0097 QAction *createAction(StandardActionManager::Type type); 0098 0099 /** 0100 * Convenience method to create all standard actions. 0101 * @see createAction() 0102 */ 0103 void createAllActions(); 0104 0105 /** 0106 * Returns the action of the given type, 0 if it has not been created (yet). 0107 */ 0108 QAction *action(Type type) const; 0109 0110 /** 0111 * Returns the action of the given type, 0 if it has not been created (yet). 0112 * @param type the type of action to return 0113 */ 0114 QAction *action(StandardActionManager::Type type) const; 0115 0116 /** 0117 * Sets the label of the action @p type to @p text, which is used during 0118 * updating the action state and substituted according to the number of 0119 * selected objects. This is mainly useful to customize the label of actions 0120 * that can operate on multiple objects. 0121 * 0122 * Example: 0123 * @code 0124 * acctMgr->setActionText( Akonadi::StandardActionManager::CopyItems, 0125 * ki18np( "Copy Item", "Copy %1 Items" ) ); 0126 * @endcode 0127 */ 0128 void setActionText(StandardActionManager::Type type, const KLocalizedString &text); 0129 0130 /** 0131 * Sets whether the default implementation for the given action @p type 0132 * shall be executed when the action is triggered. 0133 * 0134 * @param intercept If @c false, the default implementation will be executed, 0135 * if @c true no action is taken. 0136 */ 0137 void interceptAction(Type type, bool intercept = true); 0138 0139 /** 0140 * Sets whether the default implementation for the given action @p type 0141 * shall be executed when the action is triggered. 0142 * 0143 * @param intercept If @c false, the default implementation will be executed, 0144 * if @c true no action is taken. 0145 */ 0146 void interceptAction(StandardActionManager::Type type, bool intercept = true); 0147 0148 /** 0149 * Returns the list of collections that are currently selected. 0150 * The list is empty if no collection is currently selected. 0151 */ 0152 [[nodiscard]] Akonadi::Collection::List selectedCollections() const; 0153 0154 /** 0155 * Returns the list of items that are currently selected. 0156 * The list is empty if no item is currently selected. 0157 */ 0158 [[nodiscard]] Akonadi::Item::List selectedItems() const; 0159 0160 /** 0161 * Sets the @p text of the action @p type for the given @p context. 0162 */ 0163 void setContextText(StandardActionManager::Type type, StandardActionManager::TextContext context, const QString &text); 0164 0165 /** 0166 * Sets the @p text of the action @p type for the given @p context. 0167 */ 0168 void setContextText(StandardActionManager::Type type, StandardActionManager::TextContext context, const KLocalizedString &text); 0169 0170 void setCollectionPropertiesPageNames(const QStringList &names); 0171 0172 Q_SIGNALS: 0173 /** 0174 * This signal is emitted whenever the action state has been updated. 0175 * In case you have special needs for changing the state of some actions, 0176 * connect to this signal and adjust the action state. 0177 */ 0178 void actionStateUpdated(); 0179 0180 private: 0181 //@cond PRIVATE 0182 std::unique_ptr<StandardCalendarActionManagerPrivate> const d; 0183 //@endcond 0184 }; 0185 }