KConfig

kstandardshortcutwatcher.cpp
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:
18};
19
20StandardShortcutWatcher::StandardShortcutWatcher(QObject *parent)
21 : QObject(parent)
22 , d(std::make_unique<StandardShortcutWatcherPrivate>())
23{
24 connect(d->watcher.get(), &KConfigWatcher::configChanged, this, [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(QString::fromUtf8(key));
30 if (shortcut != KStandardShortcut::AccelNone) {
31 initialize(shortcut);
32 Q_EMIT shortcutChanged(shortcut, KStandardShortcut::shortcut(shortcut));
33 }
34 }
35 });
36}
37
38StandardShortcutWatcher::~StandardShortcutWatcher() = default;
39
41{
42 static StandardShortcutWatcher watcher;
43 return &watcher;
44}
45
46}
47
48#include "moc_kstandardshortcutwatcher.cpp"
A class for one specific group in a KConfig object.
static Ptr create(const KSharedConfig::Ptr &config)
Instantiate a ConfigWatcher for a given config.
void configChanged(const KConfigGroup &group, const QByteArrayList &names)
Emitted when a config group has changed The config will be reloaded before this signal is emitted.
static KSharedConfig::Ptr openConfig(const QString &fileName=QString(), OpenFlags mode=FullConfig, QStandardPaths::StandardLocation type=QStandardPaths::GenericConfigLocation)
Creates a KSharedConfig object to manipulate a configuration file.
Watches for changes made to standard shortcuts and notifies about those changes.
KCRASH_EXPORT void initialize()
Convenient methods for access to the common accelerator keys in the key configuration.
StandardShortcutWatcher * shortcutWatcher()
Returns the global KStandardShortcutWatcher instance of this program.
StandardShortcut findByName(const QString &name)
Return the StandardShortcut id of the standard accelerator action which has name as its name,...
const QList< QKeySequence > & shortcut(StandardShortcut id)
Returns the keybinding for accel.
QString fromUtf8(QByteArrayView str)
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 17:01:09 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.