From 820dc0a553e50cc4560733d43fca2674a61d43b3 Mon Sep 17 00:00:00 2001 From: David Redondo Date: Thu, 13 Jan 2022 10:04:13 +0100 Subject: 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 --- src/gui/kstandardshortcutwatcher.h | 54 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 src/gui/kstandardshortcutwatcher.h (limited to 'src/gui/kstandardshortcutwatcher.h') diff --git a/src/gui/kstandardshortcutwatcher.h b/src/gui/kstandardshortcutwatcher.h new file mode 100644 index 00000000..64c6d3d4 --- /dev/null +++ b/src/gui/kstandardshortcutwatcher.h @@ -0,0 +1,54 @@ +/* + SPDX-FileCopyrightText: 2022 David Redondo + + SPDX-License-Identifier: LGPL-2.0-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +#ifndef KSTANDARDSHORTCUTWATCHER_H +#define KSTANDARDSHORTCUTWATCHER_H + +#include "kstandardshortcut.h" + +#include + +#include + +#include + +namespace KStandardShortcut +{ +class StandardShortcutWatcherPrivate; + +/** + * Watches for changes made to standard shortcuts and notifies about those changes. + * @see KStandardShortcut::shortcutWatcher + * @since 5.91 + */ +class KCONFIGGUI_EXPORT StandardShortcutWatcher : public QObject +{ + Q_OBJECT +public: + ~StandardShortcutWatcher(); +Q_SIGNALS: + /** + * The standardshortcut @p id was changed to @p shortcut + */ + void shortcutChanged(KStandardShortcut::StandardShortcut id, const QList &shortcut); + +private: + explicit StandardShortcutWatcher(QObject *parent = nullptr); + friend StandardShortcutWatcher *shortcutWatcher(); + std::unique_ptr d; +}; + +/** + * Returns the global KStandardShortcutWatcher instance of this program. + * In addition to the notifying about changes it also keeps the information returned by the + * functions in @p KStandardShortcut up to date. + * The object is created by the first call to this function. + * @since 5.91 + */ +KCONFIGGUI_EXPORT StandardShortcutWatcher *shortcutWatcher(); +} + +#endif -- cgit v1.2.1