1 /* ============================================================
2  *
3  * This file is a part of digiKam project
4  * https://www.digikam.org
5  *
6  * Date        : 2011-01-24
7  * Description : Tags Action Manager
8  *
9  * Copyright (C) 2011-2021 by Gilles Caulier <caulier dot gilles at gmail dot com>
10  *
11  * This program is free software; you can redistribute it
12  * and/or modify it under the terms of the GNU General
13  * Public License as published by the Free Software Foundation;
14  * either version 2, or (at your option)
15  * any later version.
16  *
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20  * GNU General Public License for more details.
21  *
22  * ============================================================ */
23 
24 #ifndef DIGIKAM_TAGS_ACTION_MNGR_H
25 #define DIGIKAM_TAGS_ACTION_MNGR_H
26 
27 // Qt includes
28 
29 #include <QObject>
30 #include <QWidget>
31 
32 class KActionCollection;
33 
34 namespace Digikam
35 {
36 
37 class Album;
38 class ImageTagChangeset;
39 
40 class TagsActionMngr : public QObject
41 {
42     Q_OBJECT
43 
44 public:
45 
46     explicit TagsActionMngr(QWidget* const parent);
47     ~TagsActionMngr() override;
48 
49     /**
50      * Register all tag actions to collections managed with keyboard shortcuts.
51      * Because Tags shortcuts are stored in database this method must be called after
52      * database initialization and after that all root window instances have been created.
53      */
54     void registerTagsActionCollections();
55 
56     /**
57      * Register all labels actions to collections managed with keyboard shortcuts.
58      * Unlike tags actions, labels shortcuts are stored in XML GUI file of each root windows,
59      * to be able to customize it through KDE keyboards shortcuts config panel.
60      * This method must be called before to DXmlGuiWindow::createGUI(), typically
61      * when window actions are registered to ActionCollection instance.
62      */
63     void registerLabelsActions(KActionCollection* const ac);
64 
65     void registerActionsToWidget(QWidget* const wdg);
66 
67     /**
68      * Return the list of whole action collections managed.
69      */
70     QList<KActionCollection*> actionCollections()   const;
71 
72     /**
73      * Updates the shortcut action for a tag. Call this when a shortcut was
74      * added, removed or changed.
75      */
76     void updateTagShortcut(int tagId, const QKeySequence& ks, bool delAction = true);
77 
78     QString ratingShortcutPrefix()                  const;
79     QString tagShortcutPrefix()                     const;
80     QString pickShortcutPrefix()                    const;
81     QString colorShortcutPrefix()                   const;
82 
83     static TagsActionMngr* defaultManager();
84 
85 Q_SIGNALS:
86 
87     void signalShortcutPressed(const QString& shortcut, int val);
88 
89 private Q_SLOTS:
90 
91     /**
92      * Removes the shortcut actions associated with a tag.
93      */
94     void slotAlbumDeleted(Album*);
95 
96     /**
97      * Wrapper around windows to run relevant code about keyboard shortcuts in GUI.
98      */
99     void slotAssignFromShortcut();
100 
101     /**
102      * Called by config shortcuts dialog, when user change action properties.
103      */
104     void slotTagActionChanged();
105 
106 private:
107 
108     bool createTagActionShortcut(int tagId);
109     bool removeTagActionShortcut(int tagId, bool delAction = true);
110 
111     bool createRatingActionShortcut(KActionCollection* const ac, int rating);
112     bool createPickLabelActionShortcut(KActionCollection* const ac, int pickId);
113     bool createColorLabelActionShortcut(KActionCollection* const ac, int colorId);
114 
115 private:
116 
117     static TagsActionMngr* m_defaultManager;
118 
119     class Private;
120     Private* const d;
121 };
122 
123 } // namespace Digikam
124 
125 #endif // DIGIKAM_TAGS_ACTION_MNGR_H
126