1/*
2 This file is part of the KDE libraries
3 SPDX-FileCopyrightText: 2001, 2002 Ellis Whitehead <ellis@kde.org>
4 SPDX-FileCopyrightText: 2006 Hamish Rodda <rodda@kde.org>
5 SPDX-FileCopyrightText: 2007 Andreas Hartmetz <ahartmetz@gmail.com>
6
7 SPDX-License-Identifier: LGPL-2.0-or-later
8*/
9
10#ifndef KGLOBALACCEL_P_H
11#define KGLOBALACCEL_P_H
12
13#include <QHash>
14#include <QKeySequence>
15#include <QList>
16#include <QStringList>
17
18#include "kglobalaccel.h"
19#include "kglobalaccel_component_interface.h"
20#include "kglobalaccel_interface.h"
21
22enum SetShortcutFlag {
23 SetPresent = 2,
24 NoAutoloading = 4,
25 IsDefault = 8,
26};
27
28class KGlobalAccelPrivate
29{
30public:
31 enum ShortcutState {
32 Pressed,
33 Repeated,
34 Released
35 };
36 enum ShortcutType {
37 /// The shortcut will immediately become active but may be reset to "default".
38 ActiveShortcut = 0x1,
39 /// The shortcut is a default shortcut - it becomes active when somebody decides to
40 /// reset shortcuts to default.
41 DefaultShortcut = 0x2,
42 };
43
44 Q_DECLARE_FLAGS(ShortcutTypes, ShortcutType)
45 enum Removal {
46 SetInactive = 0, ///< Forget the action in this class and mark it as not present in the KDED module
47 UnRegister, ///< Remove any trace of the action in this class and in the KDED module
48 };
49 KGlobalAccelPrivate(KGlobalAccel *);
50
51 /// Propagate any shortcut changes to the KDED module that does the bookkeeping
52 /// and the key grabbing.
53 ///@todo KF6
54 void updateGlobalShortcut(/*const would be better*/ QAction *action,
55 KGlobalAccelPrivate::ShortcutTypes actionFlags,
56 KGlobalAccel::GlobalShortcutLoading globalFlags);
57
58 /// Register the action in this class and in the KDED module
59 bool doRegister(QAction *action); //"register" is a C keyword :p
60 /// cf. the RemoveAction enum
61 void remove(QAction *action, Removal r);
62
63 //"private" helpers
64 QString componentUniqueForAction(const QAction *action);
65 QString componentFriendlyForAction(const QAction *action);
66 QStringList makeActionId(const QAction *action);
67 QList<int> intListFromShortcut(const QList<QKeySequence> &cut);
68 QList<QKeySequence> shortcutFromIntList(const QList<int> &list);
69
70 void cleanup();
71
72 // private slot implementations
73 QAction *findAction(const QString &, const QString &);
74 void invokeAction(const QString &, const QString &, qlonglong, ShortcutState wasHeld);
75 void invokeDeactivate(const QString &, const QString &);
76 void shortcutGotChanged(const QStringList &, const QList<int> &);
77 void shortcutsChanged(const QStringList &, const QList<QKeySequence> &);
78 void serviceOwnerChanged(const QString &name, const QString &oldOwner, const QString &newOwner);
79 void reRegisterAll();
80
81 // for all actions with (isEnabled() && globalShortcutAllowed())
82 QMultiHash<QString, QAction *> nameToAction;
83 QSet<QAction *> actions;
84
85 org::kde::KGlobalAccel *iface();
86
87 //! Get the component @p componentUnique. If @p remember is true the instance is cached and we
88 //! subscribe to signals about changes to the component.
89 org::kde::kglobalaccel::Component *getComponent(const QString &componentUnique, bool remember);
90
91 //! Our owner
92 KGlobalAccel *q;
93
94 //! The components the application is using
95 QHash<QString, org::kde::kglobalaccel::Component *> components;
96 QMap<const QAction *, QList<QKeySequence>> actionDefaultShortcuts;
97 QMap<const QAction *, QList<QKeySequence>> actionShortcuts;
98
99 bool setShortcutWithDefault(QAction *action, const QList<QKeySequence> &shortcut, KGlobalAccel::GlobalShortcutLoading loadFlag);
100
101 void unregister(const QStringList &actionId);
102 void setInactive(const QStringList &actionId);
103
104private:
105 org::kde::KGlobalAccel *m_iface = nullptr;
106 QPointer<QAction> m_lastActivatedAction;
107 QDBusServiceWatcher *m_watcher;
108};
109
110Q_DECLARE_OPERATORS_FOR_FLAGS(KGlobalAccelPrivate::ShortcutTypes)
111
112#endif
113

source code of kglobalaccel/src/kglobalaccel_p.h