Akonadi Mime

standardmailactionmanager.h
1/*
2 This file is part of Akonadi Mail.
3
4 Copyright (c) 2009 - 2010 Tobias Koenig <tokoe@kde.org>
5
6 SPDX-License-Identifier: LGPL-2.0-or-later
7*/
8
9#pragma once
10
11#include "akonadi-mime_export.h"
12
13#include <Akonadi/StandardActionManager>
14
15#include <QObject>
16
17#include <memory>
18
19class QAction;
22class QWidget;
23
24namespace Akonadi
25{
26class Item;
27class StandardMailActionManagerPrivate;
28
29/**
30 * @short Manages emails specific actions for collection and item views.
31 *
32 * @author Andras Mantia <amantia@kde.org>
33 * @since 4.6
34 */
35class AKONADI_MIME_EXPORT StandardMailActionManager : public QObject
36{
37 Q_OBJECT
38
39public:
40 /**
41 * Describes the supported actions.
42 */
43 enum Type {
44 MarkMailAsRead = StandardActionManager::LastType + 1, ///< Marks a mail as read
45 MarkMailAsUnread, ///< Marks a mail as unread
46 MarkMailAsImportant, ///< Marks a mail as important
47 MarkMailAsActionItem, ///< Marks a mail as action item
48 MarkAllMailAsRead, ///< Marks all mails in a folder as read.
49 MarkAllMailAsReadRecursive, ///< Marks all mails in a folder and its subfolders as read.
50 MarkAllMailAsUnread, ///< Marks all mails in a folder as unread.
51 MarkAllMailAsImportant, ///< Marks all mails in a folder as important
52 MarkAllMailAsActionItem, ///< Marks all mails in a folder as action item
53 MoveToTrash, ///< Move all selected messages and folders to trash.
54 MoveAllToTrash, ///< Move all messages of the current folder to trash.
55 RemoveDuplicates, ///< Removes all duplicated messages.
56 EmptyAllTrash, ///< Empties trash folders on all accounts
57 EmptyTrash, ///< Empties the trash folder, if a trash folder was selected
58 LastType ///< Marks last action.
59 };
60
61 /**
62 * Creates a new standard mail action manager.
63 *
64 * @param actionCollection The action collection to operate on.
65 * @param parent The parent widget.
66 */
67 explicit StandardMailActionManager(KActionCollection *actionCollection, QWidget *parent = nullptr);
68
69 /**
70 * Destroys the standard mail action manager.
71 */
73
74 /**
75 * Sets the collection selection model based on which the collection
76 * related actions should operate. If none is set, all collection actions
77 * will be disabled.
78 *
79 * @param selectionModel selection model for collections
80 */
81 void setCollectionSelectionModel(QItemSelectionModel *selectionModel);
82
83 /**
84 * Sets the item selection model based on which the item related actions
85 * should operate. If none is set, all item actions will be disabled.
86 *
87 * @param selectionModel selection model for items
88 */
89 void setItemSelectionModel(QItemSelectionModel *selectionModel);
90
91 /**
92 * Creates the action of the given type and adds it to the action collection
93 * specified in the constructor if it does not exist yet. The action is
94 * connected to its default implementation provided by this class.
95 *
96 * @param type action type
97 */
98 QAction *createAction(Type type);
99
100 /**
101 * Creates the action of the given type and adds it to the action collection
102 * specified in the constructor if it does not exist yet. The action is
103 * connected to its default implementation provided by this class.
104 * @param type action type
105 */
106 QAction *createAction(StandardActionManager::Type type);
107
108 /**
109 * Convenience method to create all standard actions.
110 * @see createAction()
111 */
112 void createAllActions();
113
114 /**
115 * Returns the action of the given type, 0 if it has not been created (yet).
116 * @param type action type
117 */
118 [[nodiscard]] QAction *action(Type type) const;
119
120 /**
121 * Returns the action of the given type, 0 if it has not been created (yet).
122 * @param type action type
123 */
124 [[nodiscard]] QAction *action(StandardActionManager::Type type) const;
125
126 /**
127 * Sets the label of the action @p type to @p text, which is used during
128 * updating the action state and substituted according to the number of
129 * selected objects. This is mainly useful to customize the label of actions
130 * that can operate on multiple objects.
131 *
132 * Example:
133 * @code
134 * acctMgr->setActionText( Akonadi::StandardActionManager::CopyItems,
135 * ki18np( "Copy Item", "Copy %1 Items" ) );
136 * @endcode
137 *
138 * @param type action type
139 * @param text localized text for action
140 */
141 void setActionText(StandardActionManager::Type type, const KLocalizedString &text);
142
143 /**
144 * Sets whether the default implementation for the given action @p type
145 * shall be executed when the action is triggered.
146 *
147 * @param intercept If @c false, the default implementation will be executed,
148 * if @c true no action is taken.
149 */
150 void interceptAction(Type type, bool intercept = true);
151
152 /**
153 * Sets whether the default implementation for the given action @p type
154 * shall be executed when the action is triggered.
155 *
156 * @param type action type
157 * @param intercept If @c false, the default implementation will be executed,
158 * if @c true no action is taken.
159 */
160 void interceptAction(StandardActionManager::Type type, bool intercept = true);
161
162 /**
163 * Returns the list of collections that are currently selected.
164 * The list is empty if no collection is currently selected.
165 */
166 [[nodiscard]] Akonadi::Collection::List selectedCollections() const;
167
168 /**
169 * Returns the list of items that are currently selected.
170 * The list is empty if no item is currently selected.
171 */
172 [[nodiscard]] Akonadi::Item::List selectedItems() const;
173
174 /**
175 * Sets the favorite collections model based on which the collection
176 * relatedactions should operate. If none is set, the "Add to Favorite Folders" action
177 * will be disabled.
178 *
179 * @param favoritesModel model for a user's favorite mail collections
180 */
181 void setFavoriteCollectionsModel(FavoriteCollectionsModel *favoritesModel);
182
183 /**
184 * Sets the favorite collection selection model based on which the favorite
185 * collection related actions should operate. If none is set, all favorite modifications
186 * actions will be disabled.
187 *
188 * @param selection model for favorite collections
189 */
190 void setFavoriteSelectionModel(QItemSelectionModel *selectionModel);
191
192 void setCollectionPropertiesPageNames(const QStringList &names);
193
194 [[nodiscard]] Akonadi::StandardActionManager *standardActionManager() const;
195
196 void markItemsAs(const QByteArray &typeStr, const Akonadi::Item::List &items, bool checkIntercept = true);
197 void markAllItemsAs(const QByteArray &typeStr, const Akonadi::Collection::List &collections, bool checkIntercept = true);
198
199 void setItems(const Item::List &selectedItems);
200
201Q_SIGNALS:
202 /**
203 * This signal is emitted whenever the action state has been updated.
204 * In case you have special needs for changing the state of some actions,
205 * connect to this signal and adjust the action state.
206 */
208
209private:
210 //@cond PRIVATE
211 friend class StandardMailActionManagerPrivate;
212 std::unique_ptr<StandardMailActionManagerPrivate> const d;
213 //@endcond
214};
215}
Manages emails specific actions for collection and item views.
~StandardMailActionManager() override
Destroys the standard mail action manager.
Type
Describes the supported actions.
@ RemoveDuplicates
Removes all duplicated messages.
@ MoveToTrash
Move all selected messages and folders to trash.
@ EmptyTrash
Empties the trash folder, if a trash folder was selected.
@ MarkAllMailAsReadRecursive
Marks all mails in a folder and its subfolders as read.
@ MarkMailAsActionItem
Marks a mail as action item.
@ MarkAllMailAsActionItem
Marks all mails in a folder as action item.
@ EmptyAllTrash
Empties trash folders on all accounts.
@ MoveAllToTrash
Move all messages of the current folder to trash.
@ MarkAllMailAsImportant
Marks all mails in a folder as important.
@ MarkAllMailAsRead
Marks all mails in a folder as read.
@ MarkMailAsImportant
Marks a mail as important.
@ MarkAllMailAsUnread
Marks all mails in a folder as unread.
void actionStateUpdated()
This signal is emitted whenever the action state has been updated.
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:19:28 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.