aboutsummaryrefslogtreecommitdiff
path: root/autotests/kstandardshortcutwatchertest.cpp
diff options
context:
space:
mode:
authorDavid Redondo <kde@david-redondo.de>2022-01-13 10:04:13 +0100
committerDavid Redondo <kde@david-redondo.de>2022-01-24 13:23:55 +0000
commit820dc0a553e50cc4560733d43fca2674a61d43b3 (patch)
tree6a89465d257b5b238b6bcd6a7f2f339ac167b9b6 /autotests/kstandardshortcutwatchertest.cpp
parent41d37407e80f5ccd110cf303c20a181f95fa7e73 (diff)
downloadkconfig-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 'autotests/kstandardshortcutwatchertest.cpp')
-rw-r--r--autotests/kstandardshortcutwatchertest.cpp63
1 files changed, 63 insertions, 0 deletions
diff --git a/autotests/kstandardshortcutwatchertest.cpp b/autotests/kstandardshortcutwatchertest.cpp
new file mode 100644
index 00000000..f20fc635
--- /dev/null
+++ b/autotests/kstandardshortcutwatchertest.cpp
@@ -0,0 +1,63 @@
+/*
+ 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 "kconfiggroup.h"
+#include "ksharedconfig.h"
+
+#include <QSignalSpy>
+#include <QStandardPaths>
+#include <QTest>
+
+class KStandardShortcutWatcherTest : public QObject
+{
+ Q_OBJECT
+private Q_SLOTS:
+ void initTestCase();
+ void init();
+ void testSignal();
+ void testDataUpdated();
+};
+
+Q_DECLARE_METATYPE(KStandardShortcut::StandardShortcut)
+
+const QList<QKeySequence> newShortcut = {Qt::CTRL + Qt::Key_Adiaeresis};
+
+void KStandardShortcutWatcherTest::initTestCase()
+{
+ QStandardPaths::setTestModeEnabled(true);
+ qRegisterMetaType<KStandardShortcut::StandardShortcut>();
+ QVERIFY(KStandardShortcut::hardcodedDefaultShortcut(KStandardShortcut::Open) != newShortcut);
+}
+
+void KStandardShortcutWatcherTest::init()
+{
+ KStandardShortcut::saveShortcut(KStandardShortcut::Open, KStandardShortcut::hardcodedDefaultShortcut(KStandardShortcut::Open));
+}
+
+void KStandardShortcutWatcherTest::testSignal()
+{
+ QSignalSpy signalSpy(KStandardShortcut::shortcutWatcher(), &KStandardShortcut::StandardShortcutWatcher::shortcutChanged);
+ KStandardShortcut::saveShortcut(KStandardShortcut::Open, newShortcut);
+ QTRY_COMPARE(signalSpy.count(), 1);
+ const QList<QVariant> arguments = signalSpy.takeFirst();
+ QCOMPARE(arguments[0].toInt(), KStandardShortcut::Open);
+ QCOMPARE(arguments[1].value<QList<QKeySequence>>(), newShortcut);
+}
+
+void KStandardShortcutWatcherTest::testDataUpdated()
+{
+ QSignalSpy signalSpy(KStandardShortcut::shortcutWatcher(), &KStandardShortcut::StandardShortcutWatcher::shortcutChanged);
+ // Writing manually to forego automatic update in saveShortcut()
+ KConfigGroup group(KSharedConfig::openConfig(), "Shortcuts");
+ group.writeEntry("Open", QKeySequence::listToString(newShortcut), KConfig::Global | KConfig::Notify);
+ group.config()->sync();
+ QTRY_COMPARE(signalSpy.count(), 1);
+ QCOMPARE(KStandardShortcut::open(), newShortcut);
+}
+
+QTEST_MAIN(KStandardShortcutWatcherTest)
+#include "kstandardshortcutwatchertest.moc"