1 /* ============================================================
2  *
3  * This file is a part of digiKam project
4  * https://www.digikam.org
5  *
6  * Date        : 2012-07-13
7  * Description : Modified context menu helper for import tool
8  *
9  * Copyright (C) 2012      by Islam Wazery <wazery at ubuntu dot com>
10  * Copyright (C) 2012-2021 by Gilles Caulier <caulier dot gilles at gmail dot com>
11  *
12  * This program is free software; you can redistribute it
13  * and/or modify it under the terms of the GNU General
14  * Public License as published by the Free Software Foundation;
15  * either version 2, or (at your option)
16  * any later version.
17  *
18  * This program is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21  * GNU General Public License for more details.
22  *
23  * ============================================================ */
24 
25 #ifndef DIGIKAM_IMPORT_CONTEXT_MENU_H
26 #define DIGIKAM_IMPORT_CONTEXT_MENU_H
27 
28 // Qt includes
29 
30 #include <QMenu>
31 
32 // Local includes
33 
34 #include "digikam_config.h"
35 #include "camiteminfo.h"
36 #include "importfiltermodel.h"
37 
38 class QAction;
39 
40 class KActionCollection;
41 
42 namespace Digikam
43 {
44 
45 class ImportContextMenuHelper : public QObject
46 {
47     Q_OBJECT
48 
49 public:
50 
51     typedef const QList<qlonglong> itemIds;
52 
53 Q_SIGNALS:
54 
55 /*
56     void signalAssignTag(int);
57     void signalRemoveTag(int);
58     void signalPopupTagsView();
59 */
60     void signalAssignPickLabel(int);
61     void signalAssignColorLabel(int);
62     void signalAssignRating(int);
63     void signalAddNewTagFromABCMenu(const QString&);
64 /*
65     TODO
66     void signalCreateGroup();
67     void signalUngroup();
68     void signalRemoveFromGroup();
69 */
70 public:
71 
72     /**
73      * Constructs the helper class.
74      *
75      * @param parent the menu the helper class is linked to
76      * @param actionCollection the actionCollection that should be used. If not set, the standard
77      * action from DigikamApp is used
78      */
79     explicit ImportContextMenuHelper(QMenu* const parent, KActionCollection* const actionCollection = nullptr);
80     ~ImportContextMenuHelper() override;
81 
82     /**
83      * Add an action from the actionCollection.
84      *
85      * This method adds actions from the actionCollection. The actionCollection can
86      * be set in the constructor of the ImportContextMenuHelper class.
87      *
88      * @param name the name of the action in the actionCollection
89      * @param addDisabled if set, disabled actions are added to the menu
90      */
91     void addAction(const QString& name, bool addDisabled = false);
92 
93     /**
94      * Add a temporary action.
95      *
96      * Sometimes it is necessary to define actions that only exist in the current context menu content.
97      * Use this method to add such an action.
98      *
99      * @param action the action to add
100      * @param addDisabled if set, disabled actions are added to the menu
101      */
102     void addAction(QAction* action, bool addDisabled = false);
103 
104     /**
105      * Add a temporary action and assign it to a custom slot.
106      *
107      * Use this method if you want to add a temporary action and immediately connect it to the
108      * receiving slot.
109      *
110      * @param action the action to add
111      * @param recv the receiver of the triggered action
112      * @param slot the slot to connect the triggered action to
113      * @param addDisabled if set, disabled actions are added to the menu
114      */
115     void addAction(QAction* action, QObject* recv, const char* slot, bool addDisabled = false);
116 
117     /**
118      * Add the services menu to the menu.
119      *
120      * The services menu is used to open the selected items in a different application.
121      * It will query the item for registered services and provide them in a submenu.
122      * The menu will be titled "Open With...".
123      *
124      * @param selectedItems the list of selected items
125      */
126     void addServicesMenu(const QList<QUrl>& selectedItems);
127 
128     /**
129      * Add actions to add, remove or edit a tag.
130      * The tag modification helper is used to execute the action.
131      * You must set the parent tag to use on modification helper.
132      */
133 /*
134     TODO
135     void addActionNewTag(TagModificationHelper* helper, TAlbum* parentTag = 0);
136     void addActionDeleteTag(TagModificationHelper* helper, TAlbum* tag);
137     void addActionEditTag(TagModificationHelper* helper, TAlbum* tag);
138 */
139     /**
140      * Add "Assign Tags" menu.
141      *
142      * This menu will provide a list of all tags available so that they can be assigned to the current
143      * selected items.
144      *
145      * To make this menu work, you need to run exec() from this class, otherwise the signals
146      * are not emitted and you will not be able to react on triggered actions from this menu.
147      * Make sure to connect the signals to the appropriate slots in the context menu handling method.
148      *
149      * @param ids the selected items
150      * @see exec()
151      * @see signalAssignTag()
152      */
153     void addAssignTagsMenu(itemIds& ids);
154 
155     /**
156      * Add "Remove Tags" menu.
157      *
158      * This menu will provide a list of all tags assigned to the current items. Actions triggered in here
159      * will remove the selected tag from the items.
160      *
161      * To make this menu work, you need to run exec() from this class, otherwise the signals
162      * are not emitted and you will not be able to react on triggered actions from this menu.
163      * Make sure to connect the signals to the appropriate slots in the context menu handling method.
164      *
165      * @param ids the selected items
166      * @see exec()
167      * @see signalRemoveTag()
168      */
169     void addRemoveTagsMenu(itemIds& ids);
170 
171     /**
172      * Add "Pick/Color/Rating Labels" action.
173      *
174      * This action will provide methods to assign pick/color/rating labels to the currently selected items.
175      *
176      * To make this menu work, you need to run exec() from this class, otherwise the signals
177      * are not emitted and you will not be able to react on triggered actions from this menu.
178      * Make sure to connect the signals to the appropriate slots in the context menu handling method.
179      *
180      * @see exec()
181      * @see signalAssignPickLabel()
182      * @see signalAssignColorLabel()
183      * @see signalAssignRating()
184      */
185     void addLabelsAction();
186 
187     /**
188      * Add a menu to rotate item.
189      * @param ids the selected items
190      */
191     void addRotateMenu(itemIds& ids);
192 
193     /**
194      * Add a "Group" menu.
195      * This menu will provide actions open, close, add to, remove from, or split a group.
196      *
197      * addGroupActions will add the actions as a flat list, not in a submenu.
198      * Note: Call setItemFilterModel before to have Open/Close group actions.
199      */
200     void addGroupMenu(itemIds& ids);
201     void addGroupActions(itemIds& ids);
202 
203     /**
204      * Set a filter model.
205      * Some of the group actions will operate directly on the model.
206      */
207     void setImportFilterModel(ImportFilterModel* model);
208 
209     /**
210      * Add a submenu to the parent context menu.
211      *
212      * @param subMenu   the submenu to be added
213      */
214     void addSubMenu(QMenu* subMenu);
215 
216     /**
217      * Add a separator to the context menu
218      */
219     void addSeparator();
220 
221     /**
222      * Execute the registered parent menu and evaluate the triggered actions.
223      *
224      * Always use this method instead the one from the parent menu.
225      * It will ensure that the signals are emitted and special cases are handled.
226      *
227      * @param pos position of the triggered action in the registered menu
228      * @param at the action that should be at the position pos
229      * @return the triggered action
230      */
231     QAction* exec(const QPoint& pos, QAction* at = nullptr);
232 
233 private Q_SLOTS:
234 
235     void slotOpenWith();
236     void slotOpenWith(QAction* action);
237 /*
238     void slotABCImportContextMenu();
239 */
240     void slotABCMenuTriggered(QAction*);
241 /*
242     void slotOpenGroups();
243     void slotCloseGroups();
244     void slotOpenAllGroups();
245     void slotCloseAllGroups();
246 */
247     void slotRotate();
248 
249 private:
250 
251     void setSelectedIds(itemIds& ids);
252     void setSelectedItems(const QList<QUrl>& urls);
253 /*
254     QList<QAction*> groupMenuActions(itemIds& ids);
255 */
256     void setGroupsOpen(bool open);
257 
258 private:
259 
260     class Private;
261     Private* const d;
262 };
263 
264 } // namespace Digikam
265 
266 #endif // DIGIKAM_IMPORT_CONTEXT_MENU_H
267