File indexing completed on 2020-08-09 10:58:00

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