File indexing completed on 2019-03-26 12:08:28

0001 /* This file is part of the KDE libraries
0002     Copyright (C) 2001,2002 Ellis Whitehead <ellis@kde.org>
0003     Copyright (C) 2015 Martin Gräßlin <mgraesslin@kde.org>
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 #ifndef KGLOBALACCEL_INTERFACE_H
0022 #define KGLOBALACCEL_INTERFACE_H
0023 
0024 #include <QObject>
0025 
0026 #include "kf5globalaccelprivate_export.h"
0027 
0028 class GlobalShortcutsRegistry;
0029 
0030 /**
0031  * Abstract interface for plugins to implement
0032  */
0033 class KF5GLOBALACCELPRIVATE_EXPORT KGlobalAccelInterface : public QObject
0034 {
0035     Q_OBJECT
0036 
0037 public:
0038     explicit KGlobalAccelInterface(QObject *parent);
0039     virtual ~KGlobalAccelInterface();
0040 
0041 public:
0042     /**
0043      * This function registers or unregisters a certain key for global capture,
0044      * depending on \b grab.
0045      *
0046      * Before destruction, every grabbed key will be released, so this
0047      * object does not need to do any tracking.
0048      *
0049      * \param key the Qt keycode to grab or release.
0050      * \param grab true to grab they key, false to release the key.
0051      *
0052      * \return true if successful, otherwise false.
0053      */
0054     virtual bool grabKey(int key, bool grab) = 0;
0055 
0056     /*
0057      * Enable/disable all shortcuts. There will not be any grabbed shortcuts at this point.
0058      */
0059     virtual void setEnabled(bool) = 0;
0060 
0061     /**
0062      * Allows implementing plugins to synchronize with the windowing system.
0063      * Default implementation does nothing.
0064      **/
0065     virtual void syncWindowingSystem();
0066 
0067     void setRegistry(GlobalShortcutsRegistry *registry);
0068 
0069 protected:
0070     /**
0071      * called by the implementation to inform us about key presses
0072      * @returns @c true if the key was handled
0073      **/
0074     bool keyPressed(int keyQt);
0075     void grabKeys();
0076     void ungrabKeys();
0077 
0078 private:
0079     class Private;
0080     QScopedPointer<Private> d;
0081 };
0082 
0083 Q_DECLARE_INTERFACE(KGlobalAccelInterface, "org.kde.kglobalaccel5.KGlobalAccelInterface")
0084 
0085 #endif