[KFileFilterCombo] Don't add invalid QMimeType to mimes filter
ClosedPublic

Authored by ahmadsamir on Mar 5 2020, 11:29 AM.

Details

Summary

When setting the mime filter, check that the QMimeType we get from
QMimeDatabase::mimeTypeForName() is valid before adding it to the mime
filter list. This fixes a bug where if the QMimeType is invalid its name
(and comment) property is empty, leading to empty entries in the filter
widget drop-down menu.

Per dfaure's recommendation, display a warning about the invalid mimeType.

Also install the necessary Qt logging catergory bits for KFileWidgets.

BUG: 417355

FIXED-IN: 5.68

Test Plan
  • Open gwenview -> file -> open and check the filter drown-down menu there are a couple (two?) empty entries
  • Apply diff and try again, no empty entries

Diff Detail

Repository
R241 KIO
Branch
l-kfilefiltercombo (branched from master)
Lint
No Linters Available
Unit
No Unit Test Coverage
Build Status
Buildable 23318
Build 23336: arc lint + arc unit
ahmadsamir created this revision.Mar 5 2020, 11:29 AM
Restricted Application added a project: Frameworks. · View Herald TranscriptMar 5 2020, 11:29 AM
ahmadsamir requested review of this revision.Mar 5 2020, 11:29 AM

Maybe add a warning about the invalid type? After all it's a programmer error to send us invalid mimetypes here, right? Are you also fixing the source of the issue in gwenview?

Thanks!

Maybe add a warning about the invalid type? After all it's a programmer error to send us invalid mimetypes here, right? Are you also fixing the source of the issue in gwenview?

A warning makes sense, yes.

About gwenview, it's on my todo list to track down the issue there next.

ahmadsamir updated this revision to Diff 77015.Mar 5 2020, 12:49 PM
ahmadsamir edited the summary of this revision. (Show Details)

Give a warning about invalid mimeTypes

ahmadsamir added a subscriber: kossebau.

@kossebau: did I get the Qt logging bits correctly? (I copied from your other related commits :)).

Looks good from a quick scan. If the content of the generated kio.categories files also matches what you expect, things are fine. Perhaps I would invert things and generate the header for kf5.kio.filewidgets.kfilefiltercombo and include that, instead of the manual definition in the C++ code. And do the ecm_qt_export_logging_category for kf5.kio.filewidgets instead, given this is not yet used.

Meh, I really need to get to finish my prototype for T12741, which also brings the ability to define multiple categories per generated header, instead of just one. That should get more sanity into things.

dfaure requested changes to this revision.Mar 5 2020, 2:00 PM
dfaure added inline comments.
src/filewidgets/kfilefiltercombo.cpp
32

Err why don't you include kiofilewidgets_debug.h instead?

You're redefining what the generated file contains, here.

This revision now requires changes to proceed.Mar 5 2020, 2:00 PM
kossebau added inline comments.Mar 5 2020, 2:05 PM
src/filewidgets/kfilefiltercombo.cpp
32

No, the generated one contains only kf5.kio.filewidgets, not kf5.kio.filewidgets.kfilefiltercombo.
That's why I proposed to invert things and use ecm_qt_declare_logging_category() for the latter, so we have a generated header to include indeed for the caegory we use here, and use ecm_qt_export_logging_category() for the virtual base category kf5.kio.filewidgets instead (done only to have this one available & "documented" in KDebugSettings).

BTW, typo in title of commit ("inadlid").

ahmadsamir updated this revision to Diff 77029.Mar 5 2020, 2:12 PM
ahmadsamir retitled this revision from [KFileFilterCombo] Don't add inavlid QMimeType to mime filter to [KFileFilterCombo] Don't add invalid QMimeType to mimes filter.
ahmadsamir removed a reviewer: kossebau.
ahmadsamir removed a subscriber: kossebau.

Fix typo; fix qt logging bits

kossebau added inline comments.Mar 5 2020, 2:21 PM
src/filewidgets/CMakeLists.txt
57 ↗(On Diff #77029)

Perhaps name the header matching kfilefiltercombo, to make clear this one is not providing the general library category.

src/filewidgets/kfilefiltercombo.cpp
29 ↗(On Diff #77029)

Should not be needed, served by generated header already.

ahmadsamir updated this revision to Diff 77031.Mar 5 2020, 2:33 PM

Fix _debug.h file name

ahmadsamir updated this revision to Diff 77032.Mar 5 2020, 2:34 PM

Remove redundant #include

FTR, gwenview should be fixed by D27875.

dfaure added inline comments.Mar 6 2020, 9:27 PM
src/filewidgets/kfilefiltercombo.cpp
157 ↗(On Diff #77029)

IMHO it's a programmer error so it should be a qCWarning (visible by default), not a qCDebug (invisible by default).

ahmadsamir updated this revision to Diff 77139.Mar 6 2020, 9:42 PM

Rebase. Per dfaure's recommendation use qCWarning instead of qCDebug, the former is visible by default, which makes sense for a programmer error (feeding the open file dialog invalid mimeTypes).

dfaure accepted this revision.Mar 6 2020, 10:49 PM
This revision is now accepted and ready to land.Mar 6 2020, 10:49 PM
This revision was automatically updated to reflect the committed changes.