File indexing completed on 2025-01-05 03:59:54

0001 /* ============================================================
0002  *
0003  * This file is a part of digiKam project
0004  * https://www.digikam.org
0005  *
0006  * Date        : 2012-07-13
0007  * Description : Modified context menu helper for import tool
0008  *
0009  * SPDX-FileCopyrightText: 2012      by Islam Wazery <wazery at ubuntu dot com>
0010  * SPDX-FileCopyrightText: 2012-2024 by Gilles Caulier <caulier dot gilles at gmail dot com>
0011  *
0012  * SPDX-License-Identifier: GPL-2.0-or-later
0013  *
0014  * ============================================================ */
0015 
0016 #ifndef DIGIKAM_IMPORT_CONTEXT_MENU_H
0017 #define DIGIKAM_IMPORT_CONTEXT_MENU_H
0018 
0019 // Qt includes
0020 
0021 #include <QMenu>
0022 
0023 // Local includes
0024 
0025 #include "digikam_config.h"
0026 #include "camiteminfo.h"
0027 #include "importfiltermodel.h"
0028 
0029 class QAction;
0030 
0031 class KActionCollection;
0032 
0033 namespace Digikam
0034 {
0035 
0036 class ImportContextMenuHelper : public QObject
0037 {
0038     Q_OBJECT
0039 
0040 public:
0041 
0042     typedef const QList<qlonglong> itemIds;
0043 
0044 Q_SIGNALS:
0045 
0046 /*
0047     void signalAssignTag(int);
0048     void signalRemoveTag(int);
0049     void signalPopupTagsView();
0050 */
0051     void signalAssignPickLabel(int);
0052     void signalAssignColorLabel(int);
0053     void signalAssignRating(int);
0054     void signalAddNewTagFromABCMenu(const QString&);
0055 /*
0056     TODO
0057     void signalCreateGroup();
0058     void signalUngroup();
0059     void signalRemoveFromGroup();
0060 */
0061 public:
0062 
0063     /**
0064      * Constructs the helper class.
0065      *
0066      * @param parent the menu the helper class is linked to
0067      * @param actionCollection the actionCollection that should be used. If not set, the standard
0068      * action from DigikamApp is used
0069      */
0070     explicit ImportContextMenuHelper(QMenu* const parent, KActionCollection* const actionCollection = nullptr);
0071     ~ImportContextMenuHelper() override;
0072 
0073     /**
0074      * Add an action from the actionCollection.
0075      *
0076      * This method adds actions from the actionCollection. The actionCollection can
0077      * be set in the constructor of the ImportContextMenuHelper class.
0078      *
0079      * @param name the name of the action in the actionCollection
0080      * @param addDisabled if set, disabled actions are added to the menu
0081      */
0082     void addAction(const QString& name, bool addDisabled = false);
0083 
0084     /**
0085      * Add a temporary action.
0086      *
0087      * Sometimes it is necessary to define actions that only exist in the current context menu content.
0088      * Use this method to add such an action.
0089      *
0090      * @param action the action to add
0091      * @param addDisabled if set, disabled actions are added to the menu
0092      */
0093     void addAction(QAction* action, bool addDisabled = false);
0094 
0095     /**
0096      * Add a temporary action and assign it to a custom slot.
0097      *
0098      * Use this method if you want to add a temporary action and immediately connect it to the
0099      * receiving slot.
0100      *
0101      * @param action the action to add
0102      * @param recv the receiver of the triggered action
0103      * @param slot the slot to connect the triggered action to
0104      * @param addDisabled if set, disabled actions are added to the menu
0105      */
0106     void addAction(QAction* action, QObject* recv, const char* slot, bool addDisabled = false);
0107 
0108     /**
0109      * Add the services menu to the menu.
0110      *
0111      * The services menu is used to open the selected items in a different application.
0112      * It will query the item for registered services and provide them in a submenu.
0113      * The menu will be titled "Open With...".
0114      *
0115      * @param selectedItems the list of selected items
0116      */
0117     void addServicesMenu(const QList<QUrl>& selectedItems);
0118 
0119     /**
0120      * Add actions to add, remove or edit a tag.
0121      * The tag modification helper is used to execute the action.
0122      * You must set the parent tag to use on modification helper.
0123      */
0124 /*
0125     TODO
0126     void addActionNewTag(TagModificationHelper* helper, TAlbum* parentTag = 0);
0127     void addActionDeleteTag(TagModificationHelper* helper, TAlbum* tag);
0128     void addActionEditTag(TagModificationHelper* helper, TAlbum* tag);
0129 */
0130     /**
0131      * Add "Assign Tags" menu.
0132      *
0133      * This menu will provide a list of all tags available so that they can be assigned to the current
0134      * selected items.
0135      *
0136      * To make this menu work, you need to run exec() from this class, otherwise the signals
0137      * are not emitted and you will not be able to react on triggered actions from this menu.
0138      * Make sure to connect the signals to the appropriate slots in the context menu handling method.
0139      *
0140      * @param ids the selected items
0141      * @see exec()
0142      * @see signalAssignTag()
0143      */
0144     void addAssignTagsMenu(itemIds& ids);
0145 
0146     /**
0147      * Add "Remove Tags" menu.
0148      *
0149      * This menu will provide a list of all tags assigned to the current items. Actions triggered in here
0150      * will remove the selected tag from the items.
0151      *
0152      * To make this menu work, you need to run exec() from this class, otherwise the signals
0153      * are not emitted and you will not be able to react on triggered actions from this menu.
0154      * Make sure to connect the signals to the appropriate slots in the context menu handling method.
0155      *
0156      * @param ids the selected items
0157      * @see exec()
0158      * @see signalRemoveTag()
0159      */
0160     void addRemoveTagsMenu(itemIds& ids);
0161 
0162     /**
0163      * Add "Pick/Color/Rating Labels" action.
0164      *
0165      * This action will provide methods to assign pick/color/rating labels to the currently selected items.
0166      *
0167      * To make this menu work, you need to run exec() from this class, otherwise the signals
0168      * are not emitted and you will not be able to react on triggered actions from this menu.
0169      * Make sure to connect the signals to the appropriate slots in the context menu handling method.
0170      *
0171      * @see exec()
0172      * @see signalAssignPickLabel()
0173      * @see signalAssignColorLabel()
0174      * @see signalAssignRating()
0175      */
0176     void addLabelsAction();
0177 
0178     /**
0179      * Add a menu to rotate item.
0180      * @param ids the selected items
0181      */
0182     void addRotateMenu(itemIds& ids);
0183 
0184     /**
0185      * Add a "Group" menu.
0186      * This menu will provide actions open, close, add to, remove from, or split a group.
0187      *
0188      * addGroupActions will add the actions as a flat list, not in a submenu.
0189      * Note: Call setItemFilterModel before to have Open/Close group actions.
0190      */
0191     void addGroupMenu(itemIds& ids);
0192     void addGroupActions(itemIds& ids);
0193 
0194     /**
0195      * Set a filter model.
0196      * Some of the group actions will operate directly on the model.
0197      */
0198     void setImportFilterModel(ImportFilterModel* model);
0199 
0200     /**
0201      * Add a submenu to the parent context menu.
0202      *
0203      * @param subMenu   the submenu to be added
0204      */
0205     void addSubMenu(QMenu* subMenu);
0206 
0207     /**
0208      * Add a separator to the context menu
0209      */
0210     void addSeparator();
0211 
0212     /**
0213      * Execute the registered parent menu and evaluate the triggered actions.
0214      *
0215      * Always use this method instead the one from the parent menu.
0216      * It will ensure that the signals are emitted and special cases are handled.
0217      *
0218      * @param pos position of the triggered action in the registered menu
0219      * @param at the action that should be at the position pos
0220      * @return the triggered action
0221      */
0222     QAction* exec(const QPoint& pos, QAction* at = nullptr);
0223 
0224 private Q_SLOTS:
0225 
0226     void slotOpenWith();
0227     void slotOpenWith(QAction* action);
0228 /*
0229     void slotABCImportContextMenu();
0230 */
0231     void slotABCMenuTriggered(QAction*);
0232 /*
0233     void slotOpenGroups();
0234     void slotCloseGroups();
0235     void slotOpenAllGroups();
0236     void slotCloseAllGroups();
0237 */
0238     void slotRotate();
0239 
0240 private:
0241 
0242     void setSelectedIds(itemIds& ids);
0243     void setSelectedItems(const QList<QUrl>& urls);
0244 /*
0245     QList<QAction*> groupMenuActions(itemIds& ids);
0246 */
0247     void setGroupsOpen(bool open);
0248 
0249 private:
0250 
0251     class Private;
0252     Private* const d;
0253 };
0254 
0255 } // namespace Digikam
0256 
0257 #endif // DIGIKAM_IMPORT_CONTEXT_MENU_H