diff options
author | Albert Astals Cid <aacid@kde.org> | 2017-03-06 22:57:39 +0100 |
---|---|---|
committer | Albert Astals Cid <aacid@kde.org> | 2017-03-06 22:58:30 +0100 |
commit | 59b184735c057482995cc0a8014bb90d12f09cf9 (patch) | |
tree | 77a732d8aec3cb56fa571aa5f109fb04e9f200cc /src/gui/kstandardshortcut.cpp | |
parent | 75fd07b5007473e61f3c39a82773524a392e4fa5 (diff) | |
download | kconfig-59b184735c057482995cc0a8014bb90d12f09cf9.tar.gz kconfig-59b184735c057482995cc0a8014bb90d12f09cf9.tar.bz2 |
Sanitize shortcut list on read/write from kdeglobals
For some reason some people have kdeglobals entries like
Close=Ctrl+W; Ctrl+Esc; Ctrl+W; Ctrl+Esc;
having the same shortcut more than once in the shortcut declaration is clearly bogus so fix it
BUGS: 375555
REVIEW: 129987
Diffstat (limited to 'src/gui/kstandardshortcut.cpp')
-rw-r--r-- | src/gui/kstandardshortcut.cpp | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/src/gui/kstandardshortcut.cpp b/src/gui/kstandardshortcut.cpp index 9e7b1cfc..050bd3dc 100644 --- a/src/gui/kstandardshortcut.cpp +++ b/src/gui/kstandardshortcut.cpp @@ -187,6 +187,24 @@ static KStandardShortcutInfo *guardedStandardShortcutInfo(StandardShortcut id) } } + +// Sanitize the list for duplicates. For some reason some +// people have kdeglobals entries like +// Close=Ctrl+W; Ctrl+Esc; Ctrl+W; Ctrl+Esc; +// having the same shortcut more than once in the shortcut +// declaration is clearly bogus so fix it +static void sanitizeShortcutList(QList<QKeySequence> *list) +{ + for (int i = 0; i < list->size(); ++i) { + const QKeySequence &ks = list->at(i); + int other = list->indexOf(ks, i + 1); + while (other != -1) { + list->removeAt(other); + other = list->indexOf(ks, other); + } + } +} + /** Initialize the accelerator @p id by checking if it is overridden in the configuration file (and if it isn't, use the default). On X11, if QApplication was initialized with GUI disabled, @@ -209,6 +227,7 @@ static void initialize(StandardShortcut id) QString s = cg.readEntry(info->name); if (s != QLatin1String("none")) { info->cut = QKeySequence::listFromString(s); + sanitizeShortcutList(&info->cut); } else { info->cut = QList<QKeySequence>(); } @@ -244,6 +263,7 @@ void saveShortcut(StandardShortcut id, const QList<QKeySequence> &newShortcut) } // Write the changed shortcut to kdeglobals + sanitizeShortcutList(&info->cut); cg.writeEntry(info->name, QKeySequence::listToString(info->cut), KConfig::Global | KConfig::Persistent); } |