File indexing completed on 2022-07-07 12:49:33

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