1 /* ShortcutHandler.h */
2 
3 /* Copyright (C) 2011-2020 Michael Lugmair (Lucio Carreras)
4  *
5  * This file is part of sayonara player
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11 
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16 
17  * You should have received a copy of the GNU General Public License
18  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
19  */
20 
21 #ifndef SHORTCUTHANDLER_H
22 #define SHORTCUTHANDLER_H
23 
24 
25 #include "ShortcutIdentifier.h"
26 #include "Utils/Singleton.h"
27 #include "Utils/Pimpl.h"
28 
29 #include <QShortcut>
30 #include <QObject>
31 
32 class Shortcut;
33 
34 #define ShortcutPrivate private
35 
36 /**
37  * @brief A singleton class for retrieving shortcuts
38  * @ingroup Shortcuts
39  */
40 class ShortcutHandler :
41 	public QObject
42 {
43 	Q_OBJECT
44 	SINGLETON(ShortcutHandler)
45 	PIMPL(ShortcutHandler)
46 
47 	friend class Shortcut;
48 
49 ShortcutPrivate:
50 	void qtShortcutsAdded(ShortcutIdentifier databaseKey, const QList<QShortcut*>& qtShortcuts);
51 
52 signals:
53 	void sigShortcutChanged(ShortcutIdentifier databaseKey);
54 
55 public:
56 	/**
57 	 * @brief get a shortcut by its unique identifier
58 	 * @param identifier the identifier which is used in database
59 	 * @return a shortcut instance
60 	 */
61 	Shortcut shortcut(ShortcutIdentifier databaseKey) const;
62 
63 	/**
64 	 * @brief set the shortcut by its unique identifier
65 	 * @param identifier  the identifier which is used in database
66 	 * @param shortcut a shortcut instance
67 	 */
68 	void setShortcut(ShortcutIdentifier databaseKey, const QStringList& shortcut);
69 
70 	/**
71 	 * @brief get all shortcuts
72 	 * @return
73 	 */
74 	QList<ShortcutIdentifier> allIdentifiers() const;
75 
76 	QString databaseKey(ShortcutIdentifier id) const;
77 	QString shortcut_text(ShortcutIdentifier id) const;
78 
79 private slots:
80 	void qtShortcutDestroyed();
81 };
82 
83 #endif // SHORTCUTHANDLER_H
84