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 ShortcutType {
32 /// The shortcut will immediately become active but may be reset to "default".
33 ActiveShortcut = 0x1,
34 /// The shortcut is a default shortcut - it becomes active when somebody decides to
35 /// reset shortcuts to default.
36 DefaultShortcut = 0x2,
37 };
38
39 Q_DECLARE_FLAGS(ShortcutTypes, ShortcutType)
40 enum Removal {
41 SetInactive = 0, ///< Forget the action in this class and mark it as not present in the KDED module
42 UnRegister, ///< Remove any trace of the action in this class and in the KDED module
43 };
44 KGlobalAccelPrivate(KGlobalAccel *);
45
46 /// Propagate any shortcut changes to the KDED module that does the bookkeeping
47 /// and the key grabbing.
48 ///@todo KF6
49 void updateGlobalShortcut(/*const would be better*/ QAction *action,
50 KGlobalAccelPrivate::ShortcutTypes actionFlags,
51 KGlobalAccel::GlobalShortcutLoading globalFlags);
52
53 /// Register the action in this class and in the KDED module
54 bool doRegister(QAction *action); //"register" is a C keyword :p
55 /// cf. the RemoveAction enum
56 void remove(QAction *action, Removal r);
57
58 //"private" helpers
59 QString componentUniqueForAction(const QAction *action);
60 QString componentFriendlyForAction(const QAction *action);
61 QStringList makeActionId(const QAction *action);
62 QList<int> intListFromShortcut(const QList<QKeySequence> &cut);
63 QList<QKeySequence> shortcutFromIntList(const QList<int> &list);
64
65 void cleanup();
66
67 // private slot implementations
68 QAction *findAction(const QString &, const QString &);
69 void invokeAction(const QString &, const QString &, qlonglong);
70 void invokeDeactivate(const QString &, const QString &);
71 void shortcutGotChanged(const QStringList &, const QList<int> &);
72 void shortcutsChanged(const QStringList &, const QList<QKeySequence> &);
73 void serviceOwnerChanged(const QString &name, const QString &oldOwner, const QString &newOwner);
74 void reRegisterAll();
75
76 // for all actions with (isEnabled() && globalShortcutAllowed())
77 QMultiHash<QString, QAction *> nameToAction;
78 QSet<QAction *> actions;
79
80 org::kde::KGlobalAccel *iface();
81
82 //! Get the component @p componentUnique. If @p remember is true the instance is cached and we
83 //! subscribe to signals about changes to the component.
84 org::kde::kglobalaccel::Component *getComponent(const QString &componentUnique, bool remember);
85
86 //! Our owner
87 KGlobalAccel *q;
88
89 //! The components the application is using
90 QHash<QString, org::kde::kglobalaccel::Component *> components;
91 QMap<const QAction *, QList<QKeySequence>> actionDefaultShortcuts;
92 QMap<const QAction *, QList<QKeySequence>> actionShortcuts;
93
94 bool setShortcutWithDefault(QAction *action, const QList<QKeySequence> &shortcut, KGlobalAccel::GlobalShortcutLoading loadFlag);
95
96 void unregister(const QStringList &actionId);
97 void setInactive(const QStringList &actionId);
98
99private:
100 org::kde::KGlobalAccel *m_iface = nullptr;
101 QPointer<QAction> m_lastActivatedAction;
102 QDBusServiceWatcher *m_watcher;
103};
104
105Q_DECLARE_OPERATORS_FOR_FLAGS(KGlobalAccelPrivate::ShortcutTypes)
106
107#endif
108

source code of kglobalaccel/src/kglobalaccel_p.h