diff options
| author | David Redondo <kde@david-redondo.de> | 2022-01-13 10:04:13 +0100 | 
|---|---|---|
| committer | David Redondo <kde@david-redondo.de> | 2022-01-24 13:23:55 +0000 | 
| commit | 820dc0a553e50cc4560733d43fca2674a61d43b3 (patch) | |
| tree | 6a89465d257b5b238b6bcd6a7f2f339ac167b9b6 /src/gui/kstandardshortcutwatcher.cpp | |
| parent | 41d37407e80f5ccd110cf303c20a181f95fa7e73 (diff) | |
| download | kconfig-820dc0a553e50cc4560733d43fca2674a61d43b3.tar.gz kconfig-820dc0a553e50cc4560733d43fca2674a61d43b3.tar.bz2  | |
Introduce StandardShortcutWatcher to watch for runtime changes
Currently an application needs to be restarted before it can see
any changes made to the standard shortcut configuration. To notify
about changes a new class is introduced that looks for those
changes using KConfigWatcher and also updates the global map.
CCBUG:426656
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; +} + +}  | 
