File indexing completed on 2025-01-05 04:47:06
0001 /* 0002 SPDX-FileCopyrightText: 2010 Tobias Koenig <tokoe@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #pragma once 0008 0009 #include "akonadiwidgets_export.h" 0010 // AkonadiCore 0011 #include "akonadi/agentinstance.h" 0012 0013 #include <QObject> 0014 0015 #include <memory> 0016 0017 class QAction; 0018 class KActionCollection; 0019 class KLocalizedString; 0020 class QItemSelectionModel; 0021 class QWidget; 0022 0023 namespace Akonadi 0024 { 0025 class AgentActionManagerPrivate; 0026 0027 /** 0028 * @short Manages generic actions for agent and agent instance views. 0029 * 0030 * @author Tobias Koenig <tokoe@kde.org> 0031 * @since 4.6 0032 */ 0033 class AKONADIWIDGETS_EXPORT AgentActionManager : public QObject 0034 { 0035 Q_OBJECT 0036 public: 0037 /** 0038 * Describes the supported actions. 0039 */ 0040 enum Type { 0041 CreateAgentInstance, ///< Creates an agent instance 0042 DeleteAgentInstance, ///< Deletes the selected agent instance 0043 ConfigureAgentInstance, ///< Configures the selected agent instance 0044 LastType ///< Marks last action 0045 }; 0046 0047 /** 0048 * Describes the text context that can be customized. 0049 */ 0050 enum TextContext { 0051 DialogTitle, ///< The window title of a dialog 0052 DialogText, ///< The text of a dialog 0053 MessageBoxTitle, ///< The window title of a message box 0054 MessageBoxText, ///< The text of a message box 0055 MessageBoxAlternativeText, ///< An alternative text of a message box 0056 ErrorMessageTitle, ///< The window title of an error message 0057 ErrorMessageText ///< The text of an error message 0058 }; 0059 0060 /** 0061 * Creates a new agent action manager. 0062 * 0063 * @param actionCollection The action collection to operate on. 0064 * @param parent The parent widget. 0065 */ 0066 explicit AgentActionManager(KActionCollection *actionCollection, QWidget *parent = nullptr); 0067 0068 /** 0069 * Destroys the agent action manager. 0070 */ 0071 ~AgentActionManager() override; 0072 0073 /** 0074 * Sets the agent selection @p model based on which the actions should operate. 0075 * If none is set, all actions will be disabled. 0076 * @param model model based on which actions should operate 0077 */ 0078 void setSelectionModel(QItemSelectionModel *model); 0079 0080 /** 0081 * Sets the mime type filter that will be used when creating new agent instances. 0082 */ 0083 void setMimeTypeFilter(const QStringList &mimeTypes); 0084 0085 /** 0086 * Sets the capability filter that will be used when creating new agent instances. 0087 */ 0088 void setCapabilityFilter(const QStringList &capabilities); 0089 0090 /** 0091 * Creates the action of the given type and adds it to the action collection 0092 * specified in the constructor if it does not exist yet. The action is 0093 * connected to its default implementation provided by this class. 0094 * @param type action type 0095 */ 0096 [[nodiscard]] QAction *createAction(Type type); 0097 0098 /** 0099 * Convenience method to create all standard actions. 0100 * @see createAction() 0101 */ 0102 void createAllActions(); 0103 0104 /** 0105 * Returns the action of the given type, 0 if it has not been created (yet). 0106 */ 0107 [[nodiscard]] QAction *action(Type type) const; 0108 0109 /** 0110 * Sets whether the default implementation for the given action @p type 0111 * shall be executed when the action is triggered. 0112 * 0113 * @param intercept If @c false, the default implementation will be executed, 0114 * if @c true no action is taken. 0115 * 0116 * @since 4.6 0117 */ 0118 void interceptAction(Type type, bool intercept = true); 0119 0120 /** 0121 * Returns the list of agent instances that are currently selected. 0122 * The list is empty if no agent instance is currently selected. 0123 * 0124 * @since 4.6 0125 */ 0126 [[nodiscard]] Akonadi::AgentInstance::List selectedAgentInstances() const; 0127 0128 /** 0129 * Sets the @p text of the action @p type for the given @p context. 0130 * 0131 * @param type action type 0132 * @param context context of the given action 0133 * @param text text for the given action type 0134 * 0135 * @since 4.6 0136 */ 0137 void setContextText(Type type, TextContext context, const QString &text); 0138 0139 /** 0140 * Sets the @p text of the action @p type for the given @p context. 0141 * 0142 * @since 4.8 0143 * @param type action type 0144 * @param context context of the given action type 0145 * @param text localized text for the given action type 0146 */ 0147 void setContextText(Type type, TextContext context, const KLocalizedString &text); 0148 0149 Q_SIGNALS: 0150 /** 0151 * This signal is emitted whenever the action state has been updated. 0152 * In case you have special needs for changing the state of some actions, 0153 * connect to this signal and adjust the action state. 0154 */ 0155 void actionStateUpdated(); 0156 0157 private: 0158 /// @cond PRIVATE 0159 std::unique_ptr<AgentActionManagerPrivate> const d; 0160 0161 Q_PRIVATE_SLOT(d, void updateActions()) 0162 0163 Q_PRIVATE_SLOT(d, void slotCreateAgentInstance()) 0164 Q_PRIVATE_SLOT(d, void slotDeleteAgentInstance()) 0165 Q_PRIVATE_SLOT(d, void slotConfigureAgentInstance()) 0166 0167 Q_PRIVATE_SLOT(d, void slotAgentInstanceCreationResult(KJob *)) 0168 /// @endcond 0169 }; 0170 0171 }