/* This file is part of the KDE libraries SPDX-FileCopyrightText: 2007 Andreas Hartmetz SPDX-FileCopyrightText: 2008 Michael Jansen SPDX-License-Identifier: LGPL-2.0-or-later */ #ifndef KGLOBALACCELD_H #define KGLOBALACCELD_H #include "kglobalacceld_export.h" #include #include #include #include #include #include struct KGlobalAccelDPrivate; /** * @note: Even though this is private API, KWin creates an object * of this type, check in KWin to see which methods are used before * removing them from here. * * @todo get rid of all of those QStringList parameters. */ class KGLOBALACCELD_EXPORT KGlobalAccelD : public QObject, protected QDBusContext { Q_OBJECT Q_CLASSINFO("D-Bus Interface", "org.kde.KGlobalAccel") public: enum SetShortcutFlag { SetPresent = 2, NoAutoloading = 4, IsDefault = 8, }; Q_ENUM(SetShortcutFlag) Q_DECLARE_FLAGS(SetShortcutFlags, SetShortcutFlag) Q_FLAG(SetShortcutFlags) explicit KGlobalAccelD(QObject *parent = nullptr); ~KGlobalAccelD() override; bool init(); public Q_SLOTS: /** * Get the dbus path for all known components. * * The returned path is absolute. No need to prepend anything. */ Q_SCRIPTABLE QList allComponents() const; /** * Returns a list of QStringLists (one string list per known component, * with each string list containing four strings, one for each enumerator * in KGlobalAccel::actionIdFields). */ Q_SCRIPTABLE QList allMainComponents() const; Q_SCRIPTABLE QList allActionsForComponent(const QStringList &actionId) const; #if KGLOBALACCELD_ENABLE_DEPRECATED_SINCE(5, 90) KGLOBALACCELD_DEPRECATED_VERSION(5, 90, "Use actionList(const QKeySequence&, int) instead.") Q_SCRIPTABLE QStringList action(int key) const; #endif Q_SCRIPTABLE QStringList actionList(const QKeySequence &key) const; // to be called by main components not owning the action #if KGLOBALACCELD_ENABLE_DEPRECATED_SINCE(5, 90) KGLOBALACCELD_DEPRECATED_VERSION(5, 90, "Use shortcutKeys(const QStringList &) instead.") Q_SCRIPTABLE QList shortcut(const QStringList &actionId) const; #endif Q_SCRIPTABLE QList shortcutKeys(const QStringList &actionId) const; // to be called by main components not owning the action #if KGLOBALACCELD_ENABLE_DEPRECATED_SINCE(5, 90) KGLOBALACCELD_DEPRECATED_VERSION(5, 90, "Use defaultShortcutKeys(const QStringList &) instead.") Q_SCRIPTABLE QList defaultShortcut(const QStringList &actionId) const; #endif Q_SCRIPTABLE QList defaultShortcutKeys(const QStringList &actionId) const; /** * Get the dbus path for @ componentUnique * * @param componentUnique the components unique identifier * * @return the absolute dbus path */ Q_SCRIPTABLE QDBusObjectPath getComponent(const QString &componentUnique) const; // to be called by main components owning the action #if KGLOBALACCELD_ENABLE_DEPRECATED_SINCE(5, 90) KGLOBALACCELD_DEPRECATED_VERSION(5, 90, "Use setShortcutKeys(const QStringList &, const QList &, uint) instead.") Q_SCRIPTABLE QList setShortcut(const QStringList &actionId, const QList &keys, uint flags); #endif Q_SCRIPTABLE QList setShortcutKeys(const QStringList &actionId, const QList &keys, uint flags); // this is used if application A wants to change shortcuts of application B #if KGLOBALACCELD_ENABLE_DEPRECATED_SINCE(5, 90) KGLOBALACCELD_DEPRECATED_VERSION(5, 90, "Use setForeignShortcutKeys(const QStringList &, const QList &) instead.") Q_SCRIPTABLE void setForeignShortcut(const QStringList &actionId, const QList &keys); #endif Q_SCRIPTABLE void setForeignShortcutKeys(const QStringList &actionId, const QList &keys); // to be called when a KAction is destroyed. The shortcut stays in the data structures for // conflict resolution but won't trigger. Q_SCRIPTABLE void setInactive(const QStringList &actionId); Q_SCRIPTABLE void doRegister(const QStringList &actionId); #if KGLOBALACCELD_ENABLE_DEPRECATED_SINCE(4, 3) //! @deprecated Since 4.3, use KGlobalAccelD::unregister KGLOBALACCELD_DEPRECATED_VERSION(4, 3, "Use KGlobalAccelD::unregister(const QString&, const QString&") Q_SCRIPTABLE void unRegister(const QStringList &actionId); #endif Q_SCRIPTABLE void activateGlobalShortcutContext(const QString &component, const QString &context); #if KGLOBALACCELD_ENABLE_DEPRECATED_SINCE(5, 90) /** * Returns the shortcuts registered for @p key. * * If there is more than one shortcut they are guaranteed to be from the * same component but different contexts. All shortcuts are searched. * * @deprecated Since 5.90, use globalShortcutsByKey(const QKeySequence &, int) instead. */ KGLOBALACCELD_DEPRECATED_VERSION(5, 90, "Use globalShortcutsByKey(const QKeySequence &, int) instead.") Q_SCRIPTABLE QList getGlobalShortcutsByKey(int key) const; #endif /** * Returns the shortcuts registered for @p key. * * If there is more than one shortcut they are guaranteed to be from the * same component but different contexts. All shortcuts are searched. * * @since 5.90 */ Q_SCRIPTABLE QList globalShortcutsByKey(const QKeySequence &key, KGlobalAccel::MatchType type) const; #if KGLOBALACCELD_ENABLE_DEPRECATED_SINCE(5, 90) /** * Returns true if the @p shortcut is available for @p component. * * @deprecated Since 5.90, use globalShortcutAvailable(const QKeySequence &, const QString &) instead. */ KGLOBALACCELD_DEPRECATED_VERSION(5, 90, "Use globalShortcutAvailable(const QKeySequence &, const QString &) instead.") Q_SCRIPTABLE bool isGlobalShortcutAvailable(int key, const QString &component) const; #endif /** * Returns true if the @p shortcut is available for @p component. * * @since 5.90 */ Q_SCRIPTABLE bool globalShortcutAvailable(const QKeySequence &key, const QString &component) const; /** * Delete the shortcut with @a component and @name. * * The shortcut is removed from the registry even if it is currently * present. It is removed from all contexts. * * @param componentUnique the components unique identifier * @param shortcutUnique the shortcut id * * @return @c true if the shortcuts was deleted, @c false if it didn't * exist. */ Q_SCRIPTABLE bool unregister(const QString &componentUnique, const QString &shortcutUnique); Q_SCRIPTABLE void blockGlobalShortcuts(bool); Q_SIGNALS: #if KGLOBALACCELD_ENABLE_DEPRECATED_SINCE(5, 90) KGLOBALACCELD_DEPRECATED_VERSION(5, 90, "Use the yourShortcutsChanged(const QStringList &, const QList &) signal instead.") Q_SCRIPTABLE void yourShortcutGotChanged(const QStringList &actionId, const QList &newKeys); #endif Q_SCRIPTABLE void yourShortcutsChanged(const QStringList &actionId, const QList &newKeys); private: void scheduleWriteSettings() const; KGlobalAccelDPrivate *const d; }; #endif // KGLOBALACCELD_H