File indexing completed on 2024-05-19 05:29:57

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