Take into account standard paths folders also for KIO::iconNameForUrl
ClosedPublic

Authored by broulik on Dec 31 2016, 9:10 PM.

Details

Summary

This moves the logic from KFileItem to KIO global private to make it available to KIO::iconNameForUrl

Test Plan

Unittests still pass, adjusted the iconNameForUrl test

Diff Detail

Repository
R241 KIO
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.
broulik updated this revision to Diff 9566.Dec 31 2016, 9:10 PM
broulik retitled this revision from to Take into account standard paths folders also for KIO::iconNameForUrl.
broulik updated this object.
broulik edited the test plan for this revision. (Show Details)
broulik added a reviewer: dfaure.
broulik set the repository for this revision to R241 KIO.
Restricted Application added a project: Frameworks. · View Herald TranscriptDec 31 2016, 9:10 PM
dfaure added inline comments.Dec 31 2016, 9:17 PM
autotests/kfileitemtest.cpp
492

Use QUrl::fromLocalFile, such concatenation can be buggy (for non-ascii cases, paths with '#', etc.).

Probably best to change the column type from QString to QUrl.

493

Same.

broulik updated this revision to Diff 9568.Dec 31 2016, 9:22 PM

Use QUrl in unit test instead of file:// + string foo

broulik marked 2 inline comments as done.Dec 31 2016, 9:22 PM
dfaure accepted this revision.Jan 2 2017, 9:23 AM
dfaure edited edge metadata.
This revision is now accepted and ready to land.Jan 2 2017, 9:23 AM
sitter accepted this revision.Jan 2 2017, 10:18 AM
sitter edited edge metadata.

This reminds me that someone still needs to extend QStandardPaths to cover the other XDG paths such as templates, a thing I shoved to the side and then forgot about ^^

src/core/global.cpp
311

should be a QStringLiteral. I don't see a QL1S version of inherits()

This revision was automatically updated to reflect the committed changes.

Can't reproduce locally. Could it be that XDG dirs aren't properly setup on CI or something like that?

dfaure added a comment.Jan 8 2017, 3:54 PM

No XDG is well set up since everything else passes ;)

Actually I have the same error locally. Where does the string "folder-videos" come from?

That's in kioglobal_p.cpp mapped from MoviesLocation, so KIO::fileNameForUrl should return that.

It's also tested for in testIconNameForStandardPath (though here it's just $HOME + /Videos)

dfaure added a comment.Jan 8 2017, 4:04 PM

Ah I see.

The problem is that /home/dfaure/Videos (i.e. what is returned by QSP) does NOT exist (I guess I deleted it, can't remember).

I don't see anyone (neither iconNameForUrl nor iconForStandardPath) checking for existance, though, it would/should always return videos icon for a folder that potentially be in StandardPaths?

dfaure added a comment.Jan 8 2017, 4:22 PM

OK, not sure what happened, but something changed ~/.config/user-dirs.dirs and here's what happens now:

~/.config/user-dirs.dirs says
XDG_VIDEOS_DIR="$HOME/"
which leads to MoviesLocation returning /home/dfaure, so the code in iconForStandardPath() matches the home folder first and returns "user-home".

QDEBUG : KFileItemTest::testIconNameForUrl(videos) KFileItemTest::testIconNameForUrl: QUrl("file:///home/dfaure")
FAIL! : KFileItemTest::testIconNameForUrl(videos) Compared values are not the same

Actual   (KIO::iconNameForUrl(url)): "user-home"
Expected (expectedIcon)            : "folder-videos"
dfaure added a comment.Jan 8 2017, 6:36 PM

... and when it's actually set to /home/dfaure/Videos, then KIO::iconNameForUrl skips the call to KIOPrivate::iconForStandardPath because of the mt.inherits(QLatin1String("inode/directory") check.
The mimetype is application/octet-stream (default mimetype) if the dir doesn't exist.

I'll commit a fix for both cases (equal to home and non-existent).