File indexing completed on 2024-05-12 05:11:13

0001 /*
0002     This file is part of Akonadi Mail.
0003 
0004     Copyright (c) 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-mime_export.h"
0012 
0013 #include <Akonadi/StandardActionManager>
0014 
0015 #include <QObject>
0016 
0017 #include <memory>
0018 
0019 class QAction;
0020 class KActionCollection;
0021 class QItemSelectionModel;
0022 class QWidget;
0023 
0024 namespace Akonadi
0025 {
0026 class Item;
0027 class StandardMailActionManagerPrivate;
0028 
0029 /**
0030  * @short Manages emails specific actions for collection and item views.
0031  *
0032  * @author Andras Mantia <amantia@kde.org>
0033  * @since 4.6
0034  */
0035 class AKONADI_MIME_EXPORT StandardMailActionManager : public QObject
0036 {
0037     Q_OBJECT
0038 
0039 public:
0040     /**
0041      * Describes the supported actions.
0042      */
0043     enum Type {
0044         MarkMailAsRead = StandardActionManager::LastType + 1, ///< Marks a mail as read
0045         MarkMailAsUnread, ///< Marks a mail as unread
0046         MarkMailAsImportant, ///< Marks a mail as important
0047         MarkMailAsActionItem, ///< Marks a mail as action item
0048         MarkAllMailAsRead, ///< Marks all mails in a folder as read.
0049         MarkAllMailAsReadRecursive, ///< Marks all mails in a folder and its subfolders as read.
0050         MarkAllMailAsUnread, ///< Marks all mails in a folder as unread.
0051         MarkAllMailAsImportant, ///< Marks all mails in a folder as important
0052         MarkAllMailAsActionItem, ///< Marks all mails in a folder as action item
0053         MoveToTrash, ///< Move all selected messages and folders to trash.
0054         MoveAllToTrash, ///< Move all messages of the current folder to trash.
0055         RemoveDuplicates, ///< Removes all duplicated messages.
0056         EmptyAllTrash, ///< Empties trash folders on all accounts
0057         EmptyTrash, ///< Empties the trash folder, if a trash folder was selected
0058         LastType ///< Marks last action.
0059     };
0060 
0061     /**
0062      * Creates a new standard mail action manager.
0063      *
0064      * @param actionCollection The action collection to operate on.
0065      * @param parent The parent widget.
0066      */
0067     explicit StandardMailActionManager(KActionCollection *actionCollection, QWidget *parent = nullptr);
0068 
0069     /**
0070      * Destroys the standard mail action manager.
0071      */
0072     ~StandardMailActionManager() override;
0073 
0074     /**
0075      * Sets the collection selection model based on which the collection
0076      * related actions should operate. If none is set, all collection actions
0077      * will be disabled.
0078      *
0079      * @param selectionModel selection model for collections
0080      */
0081     void setCollectionSelectionModel(QItemSelectionModel *selectionModel);
0082 
0083     /**
0084      * Sets the item selection model based on which the item related actions
0085      * should operate. If none is set, all item actions will be disabled.
0086      *
0087      * @param selectionModel selection model for items
0088      */
0089     void setItemSelectionModel(QItemSelectionModel *selectionModel);
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      *
0096      * @param type action type
0097      */
0098     QAction *createAction(Type type);
0099 
0100     /**
0101      * Creates the action of the given type and adds it to the action collection
0102      * specified in the constructor if it does not exist yet. The action is
0103      * connected to its default implementation provided by this class.
0104      * @param type action type
0105      */
0106     QAction *createAction(StandardActionManager::Type type);
0107 
0108     /**
0109      * Convenience method to create all standard actions.
0110      * @see createAction()
0111      */
0112     void createAllActions();
0113 
0114     /**
0115      * Returns the action of the given type, 0 if it has not been created (yet).
0116      * @param type action type
0117      */
0118     QAction *action(Type type) const;
0119 
0120     /**
0121      * Returns the action of the given type, 0 if it has not been created (yet).
0122      * @param type action type
0123      */
0124     QAction *action(StandardActionManager::Type type) const;
0125 
0126     /**
0127      * Sets the label of the action @p type to @p text, which is used during
0128      * updating the action state and substituted according to the number of
0129      * selected objects. This is mainly useful to customize the label of actions
0130      * that can operate on multiple objects.
0131      *
0132      * Example:
0133      * @code
0134      * acctMgr->setActionText( Akonadi::StandardActionManager::CopyItems,
0135      *                         ki18np( "Copy Item", "Copy %1 Items" ) );
0136      * @endcode
0137      *
0138      * @param type action type
0139      * @param text localized text for action
0140      */
0141     void setActionText(StandardActionManager::Type type, const KLocalizedString &text);
0142 
0143     /**
0144      * Sets whether the default implementation for the given action @p type
0145      * shall be executed when the action is triggered.
0146      *
0147      * @param intercept If @c false, the default implementation will be executed,
0148      *                  if @c true no action is taken.
0149      */
0150     void interceptAction(Type type, bool intercept = true);
0151 
0152     /**
0153      * Sets whether the default implementation for the given action @p type
0154      * shall be executed when the action is triggered.
0155      *
0156      * @param type action type
0157      * @param intercept If @c false, the default implementation will be executed,
0158      *                  if @c true no action is taken.
0159      */
0160     void interceptAction(StandardActionManager::Type type, bool intercept = true);
0161 
0162     /**
0163      * Returns the list of collections that are currently selected.
0164      * The list is empty if no collection is currently selected.
0165      */
0166     [[nodiscard]] Akonadi::Collection::List selectedCollections() const;
0167 
0168     /**
0169      * Returns the list of items that are currently selected.
0170      * The list is empty if no item is currently selected.
0171      */
0172     [[nodiscard]] Akonadi::Item::List selectedItems() const;
0173 
0174     /**
0175      * Sets the favorite collections model based on which the collection
0176      * relatedactions should operate. If none is set, the "Add to Favorite Folders" action
0177      * will be disabled.
0178      *
0179      * @param favoritesModel model for a user's favorite mail collections
0180      */
0181     void setFavoriteCollectionsModel(FavoriteCollectionsModel *favoritesModel);
0182 
0183     /**
0184      * Sets the favorite collection selection model based on which the favorite
0185      * collection related actions should operate. If none is set, all favorite modifications
0186      * actions will be disabled.
0187      *
0188      * @param selection model for favorite collections
0189      */
0190     void setFavoriteSelectionModel(QItemSelectionModel *selectionModel);
0191 
0192     void setCollectionPropertiesPageNames(const QStringList &names);
0193 
0194     Akonadi::StandardActionManager *standardActionManager() const;
0195 
0196     void markItemsAs(const QByteArray &typeStr, const Akonadi::Item::List &items, bool checkIntercept = true);
0197     void markAllItemsAs(const QByteArray &typeStr, const Akonadi::Collection::List &collections, bool checkIntercept = true);
0198 
0199     void setItems(const Item::List &selectedItems);
0200 
0201 Q_SIGNALS:
0202     /**
0203      * This signal is emitted whenever the action state has been updated.
0204      * In case you have special needs for changing the state of some actions,
0205      * connect to this signal and adjust the action state.
0206      */
0207     void actionStateUpdated();
0208 
0209 private:
0210     //@cond PRIVATE
0211     friend class StandardMailActionManagerPrivate;
0212     std::unique_ptr<StandardMailActionManagerPrivate> const d;
0213     //@endcond
0214 };
0215 }