1 #ifndef CORE_KGLOBALACCELGLOBALSHORTCUTBACKEND_H_
2 #define CORE_KGLOBALACCELGLOBALSHORTCUTBACKEND_H_
3 
4 #include "config.h"
5 #include "globalshortcutbackend.h"
6 #include "globalshortcuts.h"
7 
8 #include <QSet>
9 #include <QStringList>
10 
11 class QAction;
12 
13 class OrgKdeKGlobalAccelInterface;
14 
15 class OrgKdeKglobalaccelComponentInterface;
16 
17 class KGlobalAccelShortcutBackend : public GlobalShortcutBackend {
18   Q_OBJECT
19 
20  public:
21   explicit KGlobalAccelShortcutBackend(GlobalShortcuts* parent);
22 
23   static bool IsKGlobalAccelAvailable();
24 
25  protected:
26   bool DoRegister() override;
27 
28   void DoUnregister() override;
29 
30  private:
31 #ifdef HAVE_DBUS
32   enum SetShortcutFlag { SetPresent = 2, NoAutoloading = 4, IsDefault = 8 };
33 
34   bool AcquireComponent();
35 
36   bool AcquireInterface();
37 
38   static QStringList GetId(const QString& name, const QAction* action);
39 
40   static QList<int> ToIntList(const QList<QKeySequence>& seq);
41 
42   bool RegisterAction(const QString& name, QAction* action);
43 
44   bool RegisterShortcut(const GlobalShortcuts::Shortcut& shortcut);
45 
46   static QList<QKeySequence> ToKeySequenceList(const QList<int>& seq);
47 
48   void UnregisterAction(const QString& name, QAction* action);
49 
50  private slots:
51 
52   void OnShortcutPressed(const QString& component_unique,
53                          const QString& action_unique,
54                          qlonglong timestamp) const;
55 
56  private:
57   static const char* kService;
58   static const char* kPath;
59 
60   OrgKdeKGlobalAccelInterface* iface_;
61   OrgKdeKglobalaccelComponentInterface* component_;
62   QMultiHash<QString, QAction*> name_to_action_;
63 #endif  // HAVE_DBUS
64 };
65 
66 #endif  // CORE_KGLOBALACCELGLOBALSHORTCUTBACKEND_H_
67