1/*
2 SPDX-FileCopyrightText: 2022 David Redondo <kde@david-redondo.de>
3
4 SPDX-License-Identifier: LGPL-2.0-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
5*/
6
7#include "kstandardshortcutwatcher.h"
8
9#include "kconfigwatcher.h"
10#include "kstandardshortcut_p.h"
11
12namespace KStandardShortcut
13{
14class StandardShortcutWatcherPrivate
15{
16public:
17 KConfigWatcher::Ptr watcher = KConfigWatcher::create(config: KSharedConfig::openConfig());
18};
19
20StandardShortcutWatcher::StandardShortcutWatcher(QObject *parent)
21 : QObject(parent)
22 , d(std::make_unique<StandardShortcutWatcherPrivate>())
23{
24 connect(sender: d->watcher.get(), signal: &KConfigWatcher::configChanged, context: this, slot: [this](const KConfigGroup &group, const QByteArrayList &keys) {
25 if (group.name() != QStringLiteral("Shortcuts")) {
26 return;
27 }
28 for (const auto &key : keys) {
29 const StandardShortcut shortcut = KStandardShortcut::findByName(name: QString::fromUtf8(ba: key));
30 if (shortcut != KStandardShortcut::AccelNone) {
31 initialize(id: shortcut);
32 Q_EMIT shortcutChanged(id: shortcut, shortcut: KStandardShortcut::shortcut(id: shortcut));
33 }
34 }
35 });
36}
37
38StandardShortcutWatcher::~StandardShortcutWatcher() = default;
39
40StandardShortcutWatcher *shortcutWatcher()
41{
42 static StandardShortcutWatcher watcher;
43 return &watcher;
44}
45
46}
47
48#include "moc_kstandardshortcutwatcher.cpp"
49

source code of kconfig/src/gui/kstandardshortcutwatcher.cpp