File indexing completed on 2024-05-05 16:09:07
0001 /* 0002 This file is part of the KDE libraries 0003 0004 SPDX-FileCopyrightText: 2007 Andreas Hartmetz <ahartmetz@gmail.com> 0005 SPDX-FileCopyrightText: 2008 Michael Jansen <kde@michael-jansen.biz> 0006 0007 SPDX-License-Identifier: LGPL-2.0-or-later 0008 */ 0009 #ifndef KGLOBALACCELD_H 0010 #define KGLOBALACCELD_H 0011 0012 #include "kf5globalaccelprivate_export.h" 0013 0014 #include <kglobalshortcutinfo.h> 0015 0016 #include <KGlobalAccel> 0017 #include <QList> 0018 #include <QStringList> 0019 #include <QtDBus> 0020 0021 struct KGlobalAccelDPrivate; 0022 0023 /** 0024 * @note: Even though this is private API, KWin creates an object 0025 * of this type, check in KWin to see which methods are used before 0026 * removing them from here. 0027 * 0028 * @todo get rid of all of those QStringList parameters. 0029 */ 0030 class KGLOBALACCELPRIVATE_EXPORT KGlobalAccelD : public QObject, protected QDBusContext 0031 { 0032 Q_OBJECT 0033 Q_CLASSINFO("D-Bus Interface", "org.kde.KGlobalAccel") 0034 0035 public: 0036 enum SetShortcutFlag { 0037 SetPresent = 2, 0038 NoAutoloading = 4, 0039 IsDefault = 8, 0040 }; 0041 Q_ENUM(SetShortcutFlag) 0042 Q_DECLARE_FLAGS(SetShortcutFlags, SetShortcutFlag) 0043 Q_FLAG(SetShortcutFlags) 0044 0045 explicit KGlobalAccelD(QObject *parent = nullptr); 0046 ~KGlobalAccelD() override; 0047 0048 bool init(); 0049 0050 public Q_SLOTS: 0051 0052 /** 0053 * Get the dbus path for all known components. 0054 * 0055 * The returned path is absolute. No need to prepend anything. 0056 */ 0057 Q_SCRIPTABLE QList<QDBusObjectPath> allComponents() const; 0058 0059 /** 0060 * Returns a list of QStringLists (one string list per known component, 0061 * with each string list containing four strings, one for each enumerator 0062 * in KGlobalAccel::actionIdFields). 0063 */ 0064 Q_SCRIPTABLE QList<QStringList> allMainComponents() const; 0065 0066 Q_SCRIPTABLE QList<QStringList> allActionsForComponent(const QStringList &actionId) const; 0067 0068 #if KGLOBALACCEL_ENABLE_DEPRECATED_SINCE(5, 90) 0069 KGLOBALACCELPRIVATE_DEPRECATED_VERSION(5, 90, "Use actionList(const QKeySequence&, int) instead.") 0070 Q_SCRIPTABLE QStringList action(int key) const; 0071 #endif 0072 Q_SCRIPTABLE QStringList actionList(const QKeySequence &key) const; 0073 0074 // to be called by main components not owning the action 0075 #if KGLOBALACCEL_ENABLE_DEPRECATED_SINCE(5, 90) 0076 KGLOBALACCELPRIVATE_DEPRECATED_VERSION(5, 90, "Use shortcutKeys(const QStringList &) instead.") 0077 Q_SCRIPTABLE QList<int> shortcut(const QStringList &actionId) const; 0078 #endif 0079 Q_SCRIPTABLE QList<QKeySequence> shortcutKeys(const QStringList &actionId) const; 0080 0081 // to be called by main components not owning the action 0082 #if KGLOBALACCEL_ENABLE_DEPRECATED_SINCE(5, 90) 0083 KGLOBALACCELPRIVATE_DEPRECATED_VERSION(5, 90, "Use defaultShortcutKeys(const QStringList &) instead.") 0084 Q_SCRIPTABLE QList<int> defaultShortcut(const QStringList &actionId) const; 0085 #endif 0086 Q_SCRIPTABLE QList<QKeySequence> defaultShortcutKeys(const QStringList &actionId) const; 0087 0088 /** 0089 * Get the dbus path for @ componentUnique 0090 * 0091 * @param componentUnique the components unique identifier 0092 * 0093 * @return the absolute dbus path 0094 */ 0095 Q_SCRIPTABLE QDBusObjectPath getComponent(const QString &componentUnique) const; 0096 0097 // to be called by main components owning the action 0098 #if KGLOBALACCEL_ENABLE_DEPRECATED_SINCE(5, 90) 0099 KGLOBALACCELPRIVATE_DEPRECATED_VERSION(5, 90, "Use setShortcutKeys(const QStringList &, const QList<QKeySequence> &, uint) instead.") 0100 Q_SCRIPTABLE QList<int> setShortcut(const QStringList &actionId, const QList<int> &keys, uint flags); 0101 #endif 0102 Q_SCRIPTABLE QList<QKeySequence> setShortcutKeys(const QStringList &actionId, const QList<QKeySequence> &keys, uint flags); 0103 0104 // this is used if application A wants to change shortcuts of application B 0105 #if KGLOBALACCEL_ENABLE_DEPRECATED_SINCE(5, 90) 0106 KGLOBALACCELPRIVATE_DEPRECATED_VERSION(5, 90, "Use setForeignShortcutKeys(const QStringList &, const QList<QKeySequence> &) instead.") 0107 Q_SCRIPTABLE void setForeignShortcut(const QStringList &actionId, const QList<int> &keys); 0108 #endif 0109 Q_SCRIPTABLE void setForeignShortcutKeys(const QStringList &actionId, const QList<QKeySequence> &keys); 0110 0111 // to be called when a KAction is destroyed. The shortcut stays in the data structures for 0112 // conflict resolution but won't trigger. 0113 Q_SCRIPTABLE void setInactive(const QStringList &actionId); 0114 0115 Q_SCRIPTABLE void doRegister(const QStringList &actionId); 0116 0117 #if KGLOBALACCELPRIVATE_ENABLE_DEPRECATED_SINCE(4, 3) 0118 //! @deprecated Since 4.3, use KGlobalAccelD::unregister 0119 KGLOBALACCELPRIVATE_DEPRECATED_VERSION(4, 3, "Use KGlobalAccelD::unregister(const QString&, const QString&") 0120 Q_SCRIPTABLE void unRegister(const QStringList &actionId); 0121 #endif 0122 0123 Q_SCRIPTABLE void activateGlobalShortcutContext(const QString &component, const QString &context); 0124 0125 #if KGLOBALACCEL_ENABLE_DEPRECATED_SINCE(5, 90) 0126 /** 0127 * Returns the shortcuts registered for @p key. 0128 * 0129 * If there is more than one shortcut they are guaranteed to be from the 0130 * same component but different contexts. All shortcuts are searched. 0131 * 0132 * @deprecated Since 5.90, use globalShortcutsByKey(const QKeySequence &, int) instead. 0133 */ 0134 KGLOBALACCELPRIVATE_DEPRECATED_VERSION(5, 90, "Use globalShortcutsByKey(const QKeySequence &, int) instead.") 0135 Q_SCRIPTABLE QList<KGlobalShortcutInfo> getGlobalShortcutsByKey(int key) const; 0136 #endif 0137 0138 /** 0139 * Returns the shortcuts registered for @p key. 0140 * 0141 * If there is more than one shortcut they are guaranteed to be from the 0142 * same component but different contexts. All shortcuts are searched. 0143 * 0144 * @since 5.90 0145 */ 0146 Q_SCRIPTABLE QList<KGlobalShortcutInfo> globalShortcutsByKey(const QKeySequence &key, KGlobalAccel::MatchType type) const; 0147 0148 #if KGLOBALACCEL_ENABLE_DEPRECATED_SINCE(5, 90) 0149 /** 0150 * Returns true if the @p shortcut is available for @p component. 0151 * 0152 * @deprecated Since 5.90, use globalShortcutAvailable(const QKeySequence &, const QString &) instead. 0153 */ 0154 KGLOBALACCELPRIVATE_DEPRECATED_VERSION(5, 90, "Use globalShortcutAvailable(const QKeySequence &, const QString &) instead.") 0155 Q_SCRIPTABLE bool isGlobalShortcutAvailable(int key, const QString &component) const; 0156 #endif 0157 0158 /** 0159 * Returns true if the @p shortcut is available for @p component. 0160 * 0161 * @since 5.90 0162 */ 0163 Q_SCRIPTABLE bool globalShortcutAvailable(const QKeySequence &key, const QString &component) const; 0164 0165 /** 0166 * Delete the shortcut with @a component and @name. 0167 * 0168 * The shortcut is removed from the registry even if it is currently 0169 * present. It is removed from all contexts. 0170 * 0171 * @param componentUnique the components unique identifier 0172 * @param shortcutUnique the shortcut id 0173 * 0174 * @return @c true if the shortcuts was deleted, @c false if it didn't * exist. 0175 */ 0176 Q_SCRIPTABLE bool unregister(const QString &componentUnique, const QString &shortcutUnique); 0177 0178 Q_SCRIPTABLE void blockGlobalShortcuts(bool); 0179 0180 Q_SIGNALS: 0181 #if KGLOBALACCEL_ENABLE_DEPRECATED_SINCE(5, 90) 0182 KGLOBALACCELPRIVATE_DEPRECATED_VERSION(5, 90, "Use the yourShortcutsChanged(const QStringList &, const QList<QKeySequence> &) signal instead.") 0183 Q_SCRIPTABLE void yourShortcutGotChanged(const QStringList &actionId, const QList<int> &newKeys); 0184 #endif 0185 0186 Q_SCRIPTABLE void yourShortcutsChanged(const QStringList &actionId, const QList<QKeySequence> &newKeys); 0187 0188 private: 0189 void scheduleWriteSettings() const; 0190 0191 KGlobalAccelDPrivate *const d; 0192 }; 0193 0194 #endif // KGLOBALACCELD_H