Warning, file /frameworks/kglobalaccel/src/runtime/globalshortcutsregistry.h was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001 /* 0002 SPDX-FileCopyrightText: 2008 Michael Jansen <kde@michael-jansen.biz> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #ifndef GLOBALSHORTCUTSREGISTRY_H 0008 #define GLOBALSHORTCUTSREGISTRY_H 0009 0010 #include "kglobalaccel.h" 0011 0012 #include <KSharedConfig> 0013 0014 #include <QDBusObjectPath> 0015 #include <QHash> 0016 #include <QKeySequence> 0017 #include <QObject> 0018 0019 class GlobalShortcut; 0020 class KGlobalAccelInterface; 0021 0022 namespace KdeDGlobalAccel 0023 { 0024 class Component; 0025 } 0026 0027 /** 0028 * Global Shortcut Registry. 0029 * 0030 * Shortcuts are registered by component. A component is for example kmail or 0031 * amarok. 0032 * 0033 * A component can have contexts. Currently on plasma is planned to support 0034 * that feature. A context enables plasma to keep track of global shortcut 0035 * settings when switching containments. 0036 * 0037 * A shortcut (WIN+x) can be registered by one component only. The component 0038 * is allowed to register it more than once in different contexts. 0039 * 0040 * @author Michael Jansen <kde@michael-jansen.biz> 0041 */ 0042 class GlobalShortcutsRegistry : public QObject 0043 { 0044 Q_OBJECT 0045 0046 Q_CLASSINFO("D-Bus Interface", "org.kde.KdedGlobalAccel.GlobalShortcutsRegistry") 0047 0048 public: 0049 /** 0050 * Use GlobalShortcutsRegistry::self() 0051 * 0052 * @internal 0053 */ 0054 GlobalShortcutsRegistry(); 0055 ~GlobalShortcutsRegistry() override; 0056 0057 /** 0058 * Activate all shortcuts having their application present. 0059 */ 0060 void activateShortcuts(); 0061 0062 /** 0063 * Return a list of all main components 0064 */ 0065 const std::vector<KdeDGlobalAccel::Component *> &allMainComponents() const; 0066 0067 /** 0068 * Return the root dbus path for the registry. 0069 */ 0070 QDBusObjectPath dbusPath() const; 0071 0072 /** 0073 * Deactivate all currently active shortcuts. 0074 */ 0075 void deactivateShortcuts(bool temporarily = false); 0076 0077 /** 0078 */ 0079 KdeDGlobalAccel::Component *getComponent(const QString &uniqueName); 0080 0081 /** 0082 * Get the shortcut corresponding to key. Active and inactive shortcuts 0083 * are considered. But if the matching application uses contexts only one 0084 * shortcut is returned. 0085 * 0086 * @see getShortcutsByKey(int key) 0087 */ 0088 GlobalShortcut *getShortcutByKey(const QKeySequence &key, KGlobalAccel::MatchType type = KGlobalAccel::MatchType::Equal) const; 0089 0090 /** 0091 * Get the shortcuts corresponding to key. Active and inactive shortcuts 0092 * are considered. 0093 * 0094 * @see getShortcutsByKey(int key) 0095 */ 0096 QList<GlobalShortcut *> getShortcutsByKey(const QKeySequence &key, KGlobalAccel::MatchType type) const; 0097 0098 /** 0099 * Checks if @p shortcut is available for @p component. 0100 * 0101 * It is available if not used by another component in any context or used 0102 * by @p component only in not active contexts. 0103 */ 0104 bool isShortcutAvailable(const QKeySequence &shortcut, const QString &component, const QString &context) const; 0105 0106 static GlobalShortcutsRegistry *self(); 0107 0108 bool registerKey(const QKeySequence &key, GlobalShortcut *shortcut); 0109 0110 void setAccelManager(KGlobalAccelInterface *manager); 0111 0112 void setDBusPath(const QDBusObjectPath &path); 0113 0114 bool unregisterKey(const QKeySequence &key, GlobalShortcut *shortcut); 0115 0116 public Q_SLOTS: 0117 0118 void clear(); 0119 0120 void loadSettings(); 0121 0122 void writeSettings() const; 0123 0124 // Grab the keys 0125 void grabKeys(); 0126 0127 // Ungrab the keys 0128 void ungrabKeys(); 0129 0130 private: 0131 friend class KdeDGlobalAccel::Component; 0132 friend class KGlobalAccelInterface; 0133 friend class KGlobalAccelInterfaceV2; 0134 0135 KdeDGlobalAccel::Component *addComponent(KdeDGlobalAccel::Component *component); 0136 KdeDGlobalAccel::Component *takeComponent(KdeDGlobalAccel::Component *component); 0137 0138 // called by the implementation to inform us about key presses 0139 // returns true if the key was handled 0140 bool keyPressed(int keyQt); 0141 bool keyReleased(int keyQt); 0142 0143 QHash<QKeySequence, GlobalShortcut *> _active_keys; 0144 QKeySequence _active_sequence; 0145 QHash<int, int> _keys_count; 0146 std::vector<KdeDGlobalAccel::Component *> m_components; 0147 0148 KGlobalAccelInterface *_manager = nullptr; 0149 0150 mutable KConfig _config; 0151 0152 QDBusObjectPath _dbusPath; 0153 GlobalShortcut *m_lastShortcut = nullptr; 0154 }; 0155 0156 #endif /* #ifndef GLOBALSHORTCUTSREGISTRY_H */