From 59b184735c057482995cc0a8014bb90d12f09cf9 Mon Sep 17 00:00:00 2001 From: Albert Astals Cid Date: Mon, 6 Mar 2017 22:57:39 +0100 Subject: 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 --- src/gui/kstandardshortcut.cpp | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'src') 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 *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(); } @@ -244,6 +263,7 @@ void saveShortcut(StandardShortcut id, const QList &newShortcut) } // Write the changed shortcut to kdeglobals + sanitizeShortcutList(&info->cut); cg.writeEntry(info->name, QKeySequence::listToString(info->cut), KConfig::Global | KConfig::Persistent); } -- cgit v1.2.1