Akonadi

agentactionmanager.h
1/*
2 SPDX-FileCopyrightText: 2010 Tobias Koenig <tokoe@kde.org>
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5*/
6
7#pragma once
8
9#include "akonadiwidgets_export.h"
10// AkonadiCore
11#include "akonadi/agentinstance.h"
12
13#include <QObject>
14
15#include <memory>
16
17class QAction;
21class QWidget;
22
23namespace Akonadi
24{
25class AgentActionManagerPrivate;
26
27/**
28 * @short Manages generic actions for agent and agent instance views.
29 *
30 * @author Tobias Koenig <tokoe@kde.org>
31 * @since 4.6
32 */
33class AKONADIWIDGETS_EXPORT AgentActionManager : public QObject
34{
35 Q_OBJECT
36public:
37 /**
38 * Describes the supported actions.
39 */
40 enum Type {
41 CreateAgentInstance, ///< Creates an agent instance
42 DeleteAgentInstance, ///< Deletes the selected agent instance
43 ConfigureAgentInstance, ///< Configures the selected agent instance
44 LastType ///< Marks last action
45 };
46
47 /**
48 * Describes the text context that can be customized.
49 */
51 DialogTitle, ///< The window title of a dialog
52 DialogText, ///< The text of a dialog
53 MessageBoxTitle, ///< The window title of a message box
54 MessageBoxText, ///< The text of a message box
55 MessageBoxAlternativeText, ///< An alternative text of a message box
56 ErrorMessageTitle, ///< The window title of an error message
57 ErrorMessageText ///< The text of an error message
58 };
59
60 /**
61 * Creates a new agent action manager.
62 *
63 * @param actionCollection The action collection to operate on.
64 * @param parent The parent widget.
65 */
66 explicit AgentActionManager(KActionCollection *actionCollection, QWidget *parent = nullptr);
67
68 /**
69 * Destroys the agent action manager.
70 */
72
73 /**
74 * Sets the agent selection @p model based on which the actions should operate.
75 * If none is set, all actions will be disabled.
76 * @param model model based on which actions should operate
77 */
78 void setSelectionModel(QItemSelectionModel *model);
79
80 /**
81 * Sets the mime type filter that will be used when creating new agent instances.
82 */
83 void setMimeTypeFilter(const QStringList &mimeTypes);
84
85 /**
86 * Sets the capability filter that will be used when creating new agent instances.
87 */
88 void setCapabilityFilter(const QStringList &capabilities);
89
90 /**
91 * Creates the action of the given type and adds it to the action collection
92 * specified in the constructor if it does not exist yet. The action is
93 * connected to its default implementation provided by this class.
94 * @param type action type
95 */
96 [[nodiscard]] QAction *createAction(Type type);
97
98 /**
99 * Convenience method to create all standard actions.
100 * @see createAction()
101 */
102 void createAllActions();
103
104 /**
105 * Returns the action of the given type, 0 if it has not been created (yet).
106 */
107 [[nodiscard]] QAction *action(Type type) const;
108
109 /**
110 * Sets whether the default implementation for the given action @p type
111 * shall be executed when the action is triggered.
112 *
113 * @param intercept If @c false, the default implementation will be executed,
114 * if @c true no action is taken.
115 *
116 * @since 4.6
117 */
118 void interceptAction(Type type, bool intercept = true);
119
120 /**
121 * Returns the list of agent instances that are currently selected.
122 * The list is empty if no agent instance is currently selected.
123 *
124 * @since 4.6
125 */
126 [[nodiscard]] Akonadi::AgentInstance::List selectedAgentInstances() const;
127
128 /**
129 * Sets the @p text of the action @p type for the given @p context.
130 *
131 * @param type action type
132 * @param context context of the given action
133 * @param text text for the given action type
134 *
135 * @since 4.6
136 */
137 void setContextText(Type type, TextContext context, const QString &text);
138
139 /**
140 * Sets the @p text of the action @p type for the given @p context.
141 *
142 * @since 4.8
143 * @param type action type
144 * @param context context of the given action type
145 * @param text localized text for the given action type
146 */
147 void setContextText(Type type, TextContext context, const KLocalizedString &text);
148
149Q_SIGNALS:
150 /**
151 * This signal is emitted whenever the action state has been updated.
152 * In case you have special needs for changing the state of some actions,
153 * connect to this signal and adjust the action state.
154 */
156
157private:
158 /// @cond PRIVATE
159 std::unique_ptr<AgentActionManagerPrivate> const d;
160
161 Q_PRIVATE_SLOT(d, void updateActions())
162
163 Q_PRIVATE_SLOT(d, void slotCreateAgentInstance())
164 Q_PRIVATE_SLOT(d, void slotDeleteAgentInstance())
165 Q_PRIVATE_SLOT(d, void slotConfigureAgentInstance())
166
167 Q_PRIVATE_SLOT(d, void slotAgentInstanceCreationResult(KJob *))
168 /// @endcond
169};
170
171}
Manages generic actions for agent and agent instance views.
void actionStateUpdated()
This signal is emitted whenever the action state has been updated.
~AgentActionManager() override
Destroys the agent action manager.
Type
Describes the supported actions.
@ CreateAgentInstance
Creates an agent instance.
@ ConfigureAgentInstance
Configures the selected agent instance.
@ DeleteAgentInstance
Deletes the selected agent instance.
TextContext
Describes the text context that can be customized.
@ DialogTitle
The window title of a dialog.
@ MessageBoxAlternativeText
An alternative text of a message box.
@ DialogText
The text of a dialog.
@ MessageBoxText
The text of a message box.
@ ErrorMessageTitle
The window title of an error message.
@ MessageBoxTitle
The window title of a message box.
Helper integration between Akonadi and Qt.
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 4 2024 16:31:59 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.