[keditfiletype] Prevent removing the "main" glob pattern for mime types
AbandonedPublic

Authored by ahmadsamir on Mar 16 2020, 5:24 PM.

Details

Reviewers
dfaure
davidedmundson
apol
Group Reviewers
Plasma
Summary

QMimeDatabase re-adds/prepends the "main" glob pattern (the first one
in the system-wide xml file) to the glob patterns list, even if the user
has previously removed it e.g. via the filetypes kcm, as a result of that:

  • Don't change the sort order of m_patterns. It seems the list returned by QMimeType::globPatterns() is "ordered". Also no need to sort() the patterns list in the unit test or in MimeTypeData::isMimeTypeDirty()
  • Disable the "Remove" button for the first entry in the glob patterns list view

Fix filetypetest (unit test), use "*.inf" instead of "*.txt", the latter
was always re-added by QMimeDatabase, which made the test fail.

Test Plan

Before applying the diff:

    • Open the filetypes kcm, and remove the first glob pattern, "*.mp3" from audio/mpeg, apply, restart, note that it's been added back to the top of the list.
  • Go to text/plain mimetype, the first entry isn't "*.txt"
  • Apply the diff then try again, the "Remove" button should be disabled when you select the first row in the patterns list view.
  • Select a different entry, "Remove" button should become enabled.
  • Go to text/plain mimetype, "*.txt" is the first entry.

Diff Detail

Repository
R126 KDE CLI Utilities
Branch
l-mainglobpattern (branched from master)
Lint
No Linters Available
Unit
No Unit Test Coverage
Build Status
Buildable 23772
Build 23790: arc lint + arc unit
ahmadsamir created this revision.Mar 16 2020, 5:24 PM
Restricted Application added a project: Plasma. · View Herald TranscriptMar 16 2020, 5:24 PM
Restricted Application added a subscriber: plasma-devel. · View Herald Transcript
ahmadsamir requested review of this revision.Mar 16 2020, 5:24 PM
ahmadsamir updated this revision to Diff 77754.Mar 16 2020, 5:26 PM

Tweak comment

For background see: https://bugs.kde.org/show_bug.cgi?id=414742

I may be wrong, but personally I think QMimeDatabase is acting sensibly by not allowing to remove the "main" glob pattern of a mimetype.

Also IIUC it seems other tools are sort of doing the same, e.g. gio (see the bug report for some testing I posted there).

So, either this diff makes sense, or someone will have to put his upstream Qt hat on and change QMimeDatabase :p; I dug into the git history upstream, and IIRC it seems QMimeDatabase prepends the main glob pattern since 2012 (from before it was merged into qtbase).

I wrote QMimeDatabase, and my only intent was to move the main glob to be first. Not to prevent people from removing it. So this is a Qt bug.