File indexing completed on 2019-08-13 13:47:06

0001 #ifndef GLOBALSHORTCUT_H
0002 #define GLOBALSHORTCUT_H
0003 /* Copyright (C) 2008 Michael Jansen <kde@michael-jansen.biz>
0004 
0005    This library is free software; you can redistribute it and/or
0006    modify it under the terms of the GNU Library General Public
0007    License as published by the Free Software Foundation; either
0008    version 2 of the License, or (at your option) any later version.
0009 
0010    This library is distributed in the hope that it will be useful,
0011    but WITHOUT ANY WARRANTY; without even the implied warranty of
0012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0013    Library General Public License for more details.
0014 
0015    You should have received a copy of the GNU Library General Public License
0016    along with this library; see the file COPYING.LIB.  If not, write to
0017    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
0018    Boston, MA 02110-1301, USA.
0019 */
0020 
0021 #include <KGlobalShortcutInfo>
0022 
0023 
0024 
0025 class GlobalShortcutContext;
0026 
0027 /**
0028  * Represents a global shortcut.
0029  *
0030  * @internal
0031  *
0032  * \note This class can handle multiple keys (default and active). This
0033  * feature isn't used currently. kde4 only allows setting one key per global
0034  * shortcut.
0035  *
0036  * @author Michael Jansen <kde@michael-jansen.biz>
0037  */
0038 class GlobalShortcut
0039     {
0040 public:
0041 
0042     GlobalShortcut(const QString &uniqueName, const QString &friendlyName, GlobalShortcutContext *context);
0043     GlobalShortcut();
0044 
0045     ~GlobalShortcut();
0046 
0047     //! Returns the context the shortcuts belongs to
0048     GlobalShortcutContext *context();
0049     GlobalShortcutContext const *context() const;
0050 
0051     //! Returns the default keys for this shortcut.
0052     QList<int> defaultKeys() const;
0053 
0054     //! Return the friendly display name for this shortcut.
0055     QString friendlyName() const;
0056 
0057     //! Check if the shortcut is active. It's keys are grabbed
0058     bool isActive() const;
0059 
0060     //! Check if the shortcut is fresh/new. Is an internal state
0061     bool isFresh() const;
0062 
0063     //! Check if the shortcut is present. It application is running.
0064     bool isPresent() const;
0065 
0066     //! Returns true if the shortcut is a session shortcut
0067     bool isSessionShortcut() const;
0068 
0069     //! Returns a list of keys associated with this shortcut.
0070     QList<int> keys() const;
0071 
0072     //! Activates the shortcut. The keys are grabbed.
0073     void setActive();
0074 
0075     //! Sets the default keys for this shortcut.
0076     void setDefaultKeys(const QList<int>);
0077 
0078     //! Sets the friendly name for the shortcut. For display.
0079     void setFriendlyName(const QString &);
0080 
0081     //! Sets the shortcut inactive. No longer grabs the keys.
0082     void setInactive();
0083 
0084     void setIsPresent(bool);
0085     void setIsFresh(bool);
0086 
0087     //! Sets the keys activated with this shortcut. The old keys are freed.
0088     void setKeys(const QList<int>);
0089 
0090     //! Returns the unique name aka id for the shortcuts.
0091     QString uniqueName() const;
0092 
0093     operator KGlobalShortcutInfo () const;
0094 
0095     //! Remove this shortcut and it's siblings
0096     void unRegister();
0097 
0098 private:
0099 
0100     //! means the associated application is present.
0101     bool _isPresent:1;
0102 
0103     //! means the shortcut is registered with GlobalShortcutsRegistry
0104     bool _isRegistered:1;
0105 
0106     //! means the shortcut is new
0107     bool _isFresh:1;
0108 
0109     //! The context the shortcut belongs too
0110     GlobalShortcutContext *_context;
0111 
0112     QString _uniqueName;
0113     QString _friendlyName; //usually localized
0114 
0115     QList<int> _keys;
0116     QList<int> _defaultKeys;
0117     };
0118 
0119 
0120 #endif /* #ifndef GLOBALSHORTCUT_H */