File indexing completed on 2024-11-24 04:39:35
0001 /* 0002 This file is part of Akonadi Contact. 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-contact-widgets_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 namespace Akonadi 0024 { 0025 class Item; 0026 class StandardContactActionManagerPrivate; 0027 0028 /** 0029 * @short Manages contact specific actions for collection and item views. 0030 * 0031 * @author Tobias Koenig <tokoe@kde.org> 0032 * @since 4.6 0033 */ 0034 class AKONADI_CONTACT_WIDGETS_EXPORT StandardContactActionManager : public QObject 0035 { 0036 Q_OBJECT 0037 0038 public: 0039 /** 0040 * Describes the supported actions. 0041 */ 0042 enum Type { 0043 CreateContact = Akonadi::StandardActionManager::LastType + 1, ///< Creates a new contact 0044 CreateContactGroup, ///< Creates a new contact group 0045 EditItem, ///< Edits the selected contact resp. contact group 0046 LastType ///< Marks last action 0047 }; 0048 0049 /** 0050 * Creates a new standard contact action manager. 0051 * 0052 * @param actionCollection The action collection to operate on. 0053 * @param parent The parent widget. 0054 */ 0055 explicit StandardContactActionManager(KActionCollection *actionCollection, QWidget *parent = nullptr); 0056 0057 /** 0058 * Destroys the standard contact action manager. 0059 */ 0060 ~StandardContactActionManager() override; 0061 0062 /** 0063 * Sets the collection selection model based on which the collection 0064 * related actions should operate. If none is set, all collection actions 0065 * will be disabled. 0066 * @param selectionModel the selection model for collections 0067 */ 0068 void setCollectionSelectionModel(QItemSelectionModel *selectionModel); 0069 0070 /** 0071 * Sets the item selection model based on which the item related actions 0072 * should operate. If none is set, all item actions will be disabled. 0073 * @param selectionModel the selection model for items 0074 */ 0075 void setItemSelectionModel(QItemSelectionModel *selectionModel); 0076 0077 /** 0078 * Creates the action of the given type and adds it to the action collection 0079 * specified in the constructor if it does not exist yet. The action is 0080 * connected to its default implementation provided by this class. 0081 * @param type the type of action to create 0082 */ 0083 QAction *createAction(Type type); 0084 0085 /** 0086 * Creates the action of the given type and adds it to the action collection 0087 * specified in the constructor if it does not exist yet. The action is 0088 * connected to its default implementation provided by this class. 0089 * @param type the type of action to create 0090 */ 0091 QAction *createAction(Akonadi::StandardActionManager::Type type); 0092 0093 /** 0094 * Convenience method to create all standard actions. 0095 * @see createAction() 0096 */ 0097 void createAllActions(); 0098 0099 /** 0100 * Returns the action of the given type, 0 if it has not been created (yet). 0101 */ 0102 QAction *action(Type type) const; 0103 0104 /** 0105 * Returns the action of the given type, 0 if it has not been created (yet). 0106 * @param type the type of action to return 0107 */ 0108 QAction *action(Akonadi::StandardActionManager::Type type) const; 0109 0110 /** 0111 * Sets the label of the action @p type to @p text, which is used during 0112 * updating the action state and substituted according to the number of 0113 * selected objects. This is mainly useful to customize the label of actions 0114 * that can operate on multiple objects. 0115 * 0116 * Example: 0117 * @code 0118 * acctMgr->setActionText( Akonadi::StandardActionManager::CopyItems, 0119 * ki18np( "Copy Item", "Copy %1 Items" ) ); 0120 * @endcode 0121 */ 0122 void setActionText(Akonadi::StandardActionManager::Type type, const KLocalizedString &text); 0123 0124 /** 0125 * Sets whether the default implementation for the given action @p type 0126 * shall be executed when the action is triggered. 0127 * 0128 * @param intercept If @c false, the default implementation will be executed, 0129 * if @c true no action is taken. 0130 */ 0131 void interceptAction(Type type, bool intercept = true); 0132 0133 /** 0134 * Sets whether the default implementation for the given action @p type 0135 * shall be executed when the action is triggered. 0136 * 0137 * @param intercept If @c false, the default implementation will be executed, 0138 * if @c true no action is taken. 0139 */ 0140 void interceptAction(Akonadi::StandardActionManager::Type type, bool intercept = true); 0141 0142 /** 0143 * Returns the list of collections that are currently selected. 0144 * The list is empty if no collection is currently selected. 0145 */ 0146 [[nodiscard]] Akonadi::Collection::List selectedCollections() const; 0147 0148 /** 0149 * Returns the list of items that are currently selected. 0150 * The list is empty if no item is currently selected. 0151 */ 0152 [[nodiscard]] Akonadi::Item::List selectedItems() const; 0153 0154 /** 0155 * @param names the list of names to set as collection properties page names 0156 * @since 4.8.2 0157 */ 0158 void setCollectionPropertiesPageNames(const QStringList &names); 0159 0160 Q_SIGNALS: 0161 /** 0162 * This signal is emitted whenever the action state has been updated. 0163 * In case you have special needs for changing the state of some actions, 0164 * connect to this signal and adjust the action state. 0165 */ 0166 void actionStateUpdated(); 0167 0168 private: 0169 //@cond PRIVATE 0170 std::unique_ptr<StandardContactActionManagerPrivate> const d; 0171 //@endcond 0172 }; 0173 }