File indexing completed on 2024-05-12 03:54:28
0001 /* 0002 SPDX-FileCopyrightText: 2022 David Redondo <kde@david-redondo.de> 0003 0004 SPDX-License-Identifier: LGPL-2.0-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL 0005 */ 0006 0007 #include "kstandardshortcutwatcher.h" 0008 0009 #include "kconfigwatcher.h" 0010 #include "kstandardshortcut_p.h" 0011 0012 namespace KStandardShortcut 0013 { 0014 class StandardShortcutWatcherPrivate 0015 { 0016 public: 0017 KConfigWatcher::Ptr watcher = KConfigWatcher::create(KSharedConfig::openConfig()); 0018 }; 0019 0020 StandardShortcutWatcher::StandardShortcutWatcher(QObject *parent) 0021 : QObject(parent) 0022 , d(std::make_unique<StandardShortcutWatcherPrivate>()) 0023 { 0024 connect(d->watcher.get(), &KConfigWatcher::configChanged, this, [this](const KConfigGroup &group, const QByteArrayList &keys) { 0025 if (group.name() != QStringLiteral("Shortcuts")) { 0026 return; 0027 } 0028 for (const auto &key : keys) { 0029 const StandardShortcut shortcut = KStandardShortcut::findByName(QString::fromUtf8(key)); 0030 if (shortcut != KStandardShortcut::AccelNone) { 0031 initialize(shortcut); 0032 Q_EMIT shortcutChanged(shortcut, KStandardShortcut::shortcut(shortcut)); 0033 } 0034 } 0035 }); 0036 } 0037 0038 StandardShortcutWatcher::~StandardShortcutWatcher() = default; 0039 0040 StandardShortcutWatcher *shortcutWatcher() 0041 { 0042 static StandardShortcutWatcher watcher; 0043 return &watcher; 0044 } 0045 0046 } 0047 0048 #include "moc_kstandardshortcutwatcher.cpp"