Akonadi Contacts

standardcontactactionmanager.h
1 /*
2  This file is part of Akonadi Contact.
3 
4  Copyright (c) 2009 - 2010 Tobias Koenig <[email protected]>
5 
6  SPDX-License-Identifier: LGPL-2.0-or-later
7 */
8 
9 #pragma once
10 
11 #include "akonadi-contact_export.h"
12 
13 #include <Akonadi/StandardActionManager>
14 
15 #include <QObject>
16 
17 #include <memory>
18 
19 class QAction;
20 class KActionCollection;
22 class QWidget;
23 
24 namespace Akonadi
25 {
26 class Item;
27 class StandardContactActionManagerPrivate;
28 
29 /**
30  * @short Manages contact specific actions for collection and item views.
31  *
32  * @author Tobias Koenig <[email protected]>
33  * @since 4.6
34  */
35 class AKONADI_CONTACT_EXPORT StandardContactActionManager : public QObject
36 {
37  Q_OBJECT
38 
39 public:
40  /**
41  * Describes the supported actions.
42  */
43  enum Type {
44  CreateContact = StandardActionManager::LastType + 1, ///< Creates a new contact
45  CreateContactGroup, ///< Creates a new contact group
46  EditItem, ///< Edits the selected contact resp. contact group
47  LastType ///< Marks last action
48  };
49 
50  /**
51  * Creates a new standard contact action manager.
52  *
53  * @param actionCollection The action collection to operate on.
54  * @param parent The parent widget.
55  */
56  explicit StandardContactActionManager(KActionCollection *actionCollection, QWidget *parent = nullptr);
57 
58  /**
59  * Destroys the standard contact action manager.
60  */
61  ~StandardContactActionManager() override;
62 
63  /**
64  * Sets the collection selection model based on which the collection
65  * related actions should operate. If none is set, all collection actions
66  * will be disabled.
67  * @param selectionModel the selection model for collections
68  */
69  void setCollectionSelectionModel(QItemSelectionModel *selectionModel);
70 
71  /**
72  * Sets the item selection model based on which the item related actions
73  * should operate. If none is set, all item actions will be disabled.
74  * @param selectionModel the selection model for items
75  */
76  void setItemSelectionModel(QItemSelectionModel *selectionModel);
77 
78  /**
79  * Creates the action of the given type and adds it to the action collection
80  * specified in the constructor if it does not exist yet. The action is
81  * connected to its default implementation provided by this class.
82  * @param type the type of action to create
83  */
84  QAction *createAction(Type type);
85 
86  /**
87  * Creates the action of the given type and adds it to the action collection
88  * specified in the constructor if it does not exist yet. The action is
89  * connected to its default implementation provided by this class.
90  * @param type the type of action to create
91  */
92  QAction *createAction(StandardActionManager::Type type);
93 
94  /**
95  * Convenience method to create all standard actions.
96  * @see createAction()
97  */
98  void createAllActions();
99 
100  /**
101  * Returns the action of the given type, 0 if it has not been created (yet).
102  */
103  QAction *action(Type type) const;
104 
105  /**
106  * Returns the action of the given type, 0 if it has not been created (yet).
107  * @param type the type of action to return
108  */
109  QAction *action(StandardActionManager::Type type) const;
110 
111  /**
112  * Sets the label of the action @p type to @p text, which is used during
113  * updating the action state and substituted according to the number of
114  * selected objects. This is mainly useful to customize the label of actions
115  * that can operate on multiple objects.
116  *
117  * Example:
118  * @code
119  * acctMgr->setActionText( Akonadi::StandardActionManager::CopyItems,
120  * ki18np( "Copy Item", "Copy %1 Items" ) );
121  * @endcode
122  */
123  void setActionText(StandardActionManager::Type type, const KLocalizedString &text);
124 
125  /**
126  * Sets whether the default implementation for the given action @p type
127  * shall be executed when the action is triggered.
128  *
129  * @param intercept If @c false, the default implementation will be executed,
130  * if @c true no action is taken.
131  */
132  void interceptAction(Type type, bool intercept = true);
133 
134  /**
135  * Sets whether the default implementation for the given action @p type
136  * shall be executed when the action is triggered.
137  *
138  * @param intercept If @c false, the default implementation will be executed,
139  * if @c true no action is taken.
140  */
141  void interceptAction(StandardActionManager::Type type, bool intercept = true);
142 
143  /**
144  * Returns the list of collections that are currently selected.
145  * The list is empty if no collection is currently selected.
146  */
147  Q_REQUIRED_RESULT Akonadi::Collection::List selectedCollections() const;
148 
149  /**
150  * Returns the list of items that are currently selected.
151  * The list is empty if no item is currently selected.
152  */
153  Q_REQUIRED_RESULT Akonadi::Item::List selectedItems() const;
154 
155  /**
156  * @param names the list of names to set as collection properties page names
157  * @since 4.8.2
158  */
159  void setCollectionPropertiesPageNames(const QStringList &names);
160 
161 Q_SIGNALS:
162  /**
163  * This signal is emitted whenever the action state has been updated.
164  * In case you have special needs for changing the state of some actions,
165  * connect to this signal and adjust the action state.
166  */
167  void actionStateUpdated();
168 
169 private:
170  //@cond PRIVATE
171  std::unique_ptr<StandardContactActionManagerPrivate> const d;
172  //@endcond
173 };
174 }
@ EditItem
Edits the selected contact resp. contact group.
@ CreateContactGroup
Creates a new contact group.
Manages contact specific actions for collection and item views.
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Sat Apr 1 2023 04:09:05 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.