diff options
Diffstat (limited to 'src/gui/kstandardshortcutwatcher.cpp')
-rw-r--r-- | src/gui/kstandardshortcutwatcher.cpp | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/src/gui/kstandardshortcutwatcher.cpp b/src/gui/kstandardshortcutwatcher.cpp new file mode 100644 index 00000000..1be5e503 --- /dev/null +++ b/src/gui/kstandardshortcutwatcher.cpp @@ -0,0 +1,46 @@ +/* + SPDX-FileCopyrightText: 2022 David Redondo <kde@david-redondo.de> + + SPDX-License-Identifier: LGPL-2.0-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +#include "kstandardshortcutwatcher.h" + +#include "kconfigwatcher.h" +#include "kstandardshortcut_p.h" + +namespace KStandardShortcut +{ +class StandardShortcutWatcherPrivate +{ +public: + KConfigWatcher::Ptr watcher = KConfigWatcher::create(KSharedConfig::openConfig()); +}; + +StandardShortcutWatcher::StandardShortcutWatcher(QObject *parent) + : QObject(parent) + , d(std::make_unique<StandardShortcutWatcherPrivate>()) +{ + connect(d->watcher.get(), &KConfigWatcher::configChanged, this, [this](const KConfigGroup &group, const QByteArrayList &keys) { + if (group.name() != QStringLiteral("Shortcuts")) { + return; + } + for (const auto &key : keys) { + const StandardShortcut shortcut = KStandardShortcut::findByName(QString::fromUtf8(key)); + if (shortcut != KStandardShortcut::AccelNone) { + initialize(shortcut); + Q_EMIT shortcutChanged(shortcut, KStandardShortcut::shortcut(shortcut)); + } + } + }); +} + +StandardShortcutWatcher::~StandardShortcutWatcher() = default; + +StandardShortcutWatcher *shortcutWatcher() +{ + static StandardShortcutWatcher watcher; + return &watcher; +} + +} |