core/desktopentry: prioritize fallback keys over mismatched keys

The fallback key will now be selected when there isn't a more specific
key to select, instead of the first key.
This commit is contained in:
outfoxxed 2024-08-28 22:05:21 -07:00
parent af29bc277e
commit a116f39c63
Signed by: outfoxxed
GPG key ID: 4C88A185FB89301E

View file

@ -142,7 +142,7 @@ void DesktopEntry::parseEntry(const QString& text) {
auto splitIdx = line.indexOf(u'=');
if (splitIdx == -1) {
qCDebug(logDesktopEntry) << "Encountered invalid line in desktop entry (no =)" << line;
qCWarning(logDesktopEntry) << "Encountered invalid line in desktop entry (no =)" << line;
continue;
}
@ -159,7 +159,10 @@ void DesktopEntry::parseEntry(const QString& text) {
if (entries.contains(key)) {
const auto& old = entries.value(key);
if (system.matchScore(locale) > system.matchScore(old.first)) {
auto oldScore = system.matchScore(old.first);
auto newScore = system.matchScore(locale);
if (newScore > oldScore || (oldScore == 0 && !locale.isValid())) {
entries.insert(key, qMakePair(locale, value));
}
} else {