File indexing completed on 2024-04-21 14:56:32

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 GLOBALSHORTCUT_H
0008 #define GLOBALSHORTCUT_H
0009 
0010 #include <KGlobalShortcutInfo>
0011 
0012 class GlobalShortcutContext;
0013 class GlobalShortcutsRegistry;
0014 
0015 /**
0016  * Represents a global shortcut.
0017  *
0018  * @internal
0019  *
0020  * \note This class can handle multiple keys (default and active). This
0021  * feature isn't used currently. kde4 only allows setting one key per global
0022  * shortcut.
0023  *
0024  * @author Michael Jansen <kde@michael-jansen.biz>
0025  */
0026 class GlobalShortcut
0027 {
0028 public:
0029     GlobalShortcut(const QString &uniqueName, const QString &friendlyName, GlobalShortcutContext *context);
0030     GlobalShortcut();
0031 
0032     ~GlobalShortcut();
0033 
0034     //! Returns the context the shortcuts belongs to
0035     GlobalShortcutContext *context();
0036     GlobalShortcutContext const *context() const;
0037 
0038     //! Returns the default keys for this shortcut.
0039     QList<QKeySequence> defaultKeys() const;
0040 
0041     //! Return the friendly display name for this shortcut.
0042     QString friendlyName() const;
0043 
0044     //! Check if the shortcut is active. It's keys are grabbed
0045     bool isActive() const;
0046 
0047     //! Check if the shortcut is fresh/new. Is an internal state
0048     bool isFresh() const;
0049 
0050     //! Check if the shortcut is present. It application is running.
0051     bool isPresent() const;
0052 
0053     //! Returns true if the shortcut is a session shortcut
0054     bool isSessionShortcut() const;
0055 
0056     //! Returns a list of keys associated with this shortcut.
0057     QList<QKeySequence> keys() const;
0058 
0059     //! Activates the shortcut. The keys are grabbed.
0060     void setActive();
0061 
0062     //! Sets the default keys for this shortcut.
0063     void setDefaultKeys(const QList<QKeySequence> &);
0064 
0065     //! Sets the friendly name for the shortcut. For display.
0066     void setFriendlyName(const QString &);
0067 
0068     //! Sets the shortcut inactive. No longer grabs the keys.
0069     void setInactive();
0070 
0071     void setIsPresent(bool);
0072     void setIsFresh(bool);
0073 
0074     //! Sets the keys activated with this shortcut. The old keys are freed.
0075     void setKeys(const QList<QKeySequence> &);
0076 
0077     //! Returns the unique name aka id for the shortcuts.
0078     QString uniqueName() const;
0079 
0080     operator KGlobalShortcutInfo() const;
0081 
0082     //! Remove this shortcut and it's siblings
0083     void unRegister();
0084 
0085 private:
0086     //! means the associated application is present.
0087     bool _isPresent : 1;
0088 
0089     //! means the shortcut is registered with GlobalShortcutsRegistry
0090     bool _isRegistered : 1;
0091 
0092     //! means the shortcut is new
0093     bool _isFresh : 1;
0094 
0095     GlobalShortcutsRegistry *_registry = nullptr;
0096 
0097     //! The context the shortcut belongs too
0098     GlobalShortcutContext *_context = nullptr;
0099 
0100     QString _uniqueName;
0101     QString _friendlyName; // usually localized
0102 
0103     QList<QKeySequence> _keys;
0104     QList<QKeySequence> _defaultKeys;
0105 };
0106 
0107 #endif /* #ifndef GLOBALSHORTCUT_H */