File indexing completed on 2019-01-15 11:47:11

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