[Icon Applet] Use KIO::statJob to work with remote URLs
ClosedPublic

Authored by broulik on Jan 16 2017, 12:35 PM.

Details

Summary

Files in desktop:/ are local files but QUrl doesn't know this.
Also allows us to determin mime type and icon for files on a network share.
While at it, improve default naming logic.

BUG: 375103
FIXED-IN: 5.9.0

Test Plan

When I drag a file from desktop:/ into my panel I now get a proper icon widget rather than just a generic Link to the file. Most noticeable when I drag a .desktop file of an application there.

When I drag a file from smb:/ into my panel, I get a busy indicator on the applet until it has determined the icon/mime and then updates accordingly.

Dropped a www URL on my desktop and still get a blue HTML icon (didnt work with KFileItem but works with KIO::iconNameForUrl)

Verified that jump list actions still work, migration path (ie. plasma generating the .desktop files in plasma_icons if not existing) still works, even with multiple identical ones (ie. (1), (2), hence the file name being determined *after* the stat finished)

Diff Detail

Repository
R120 Plasma Workspace
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 10223.Jan 16 2017, 12:35 PM
broulik retitled this revision from to [Icon Applet] Use KIO::mostLocalUrl instead of just replying on isLocalFile.
broulik updated this object.
broulik edited the test plan for this revision. (Show Details)
broulik added reviewers: Plasma, dfaure.
broulik set the repository for this revision to R120 Plasma Workspace.
Restricted Application added a project: Plasma. · View Herald TranscriptJan 16 2017, 12:35 PM
Restricted Application added a subscriber: plasma-devel. · View Herald Transcript
mart accepted this revision.Jan 16 2017, 4:08 PM
mart added a reviewer: mart.
This revision is now accepted and ready to land.Jan 16 2017, 4:08 PM
dfaure added inline comments.Jan 16 2017, 4:14 PM
applets/icon/iconapplet.cpp
159

Isn't this TODO exactly what you implemented now?

189

You don't need to start() KIO jobs, they start automatically.

broulik updated this revision to Diff 10246.Jan 16 2017, 4:55 PM
broulik retitled this revision from [Icon Applet] Use KIO::mostLocalUrl instead of just replying on isLocalFile to [Icon Applet] Use KIO::statJob to work with remote URLs.
broulik updated this object.
broulik edited the test plan for this revision. (Show Details)
broulik edited edge metadata.
broulik edited the test plan for this revision. (Show Details)Jan 16 2017, 4:58 PM
broulik edited the test plan for this revision. (Show Details)
broulik updated this revision to Diff 10247.Jan 16 2017, 5:03 PM
  • Just use setBusy() in the Plasma::Applet we inherit from
dfaure edited edge metadata.Jan 16 2017, 5:45 PM

Much nicer indeed. +2 on the KIO part.

broulik updated this revision to Diff 10253.Jan 16 2017, 6:38 PM
broulik edited edge metadata.
  • Don't bail out just because stat job failed, otherwise when user manually changes Link to a non-existing file it locks him out of the icon applet so he can never correct this mistake
  • Clean up a bit

It will now always show file extension (used to do QFileInfo(localUrlString).baseName() before)

dfaure added inline comments.Jan 19 2017, 8:20 AM
applets/icon/iconapplet.cpp
159

Why only http?

This would be useful for FTP, SMB and many other things, no?

broulik added inline comments.Jan 19 2017, 9:08 AM
applets/icon/iconapplet.cpp
159

There you would usually have a filename that makes sense.

dfaure added inline comments.Jan 19 2017, 9:14 AM
applets/icon/iconapplet.cpp
159

No, not necessarily. You can point to the root of a FTP server with ftp://ftp.kde.org/ and you can even point to your home dir on an FTP server with ftp://user@host (and no trailing slash).

Similarly there's smb://workgroup or smb://host (I forgot the exact syntax for workgroups), no filename.

Why not handle any case without a filename in the same way, http or not?

broulik added inline comments.Jan 19 2017, 9:18 AM
applets/icon/iconapplet.cpp
159

I see. Still when I do http://www.kde.org/index.php I would get "index.php" as name which is non-descript.

Ok, I'll put it after

if (name.isEmpty()) {
    name = url.path();
}

and do a

if (name.isEmpty() || url.scheme().startsWith(QLatin1String("http"))) {
    name = url.host();
}
dfaure added a comment.EditedJan 19 2017, 9:21 AM

But then every HTTP URL, even with a filename, will use the host as filename?
Useful if you have only one link to a given website, but what if you have 5 links to different pages on that website?

Or maybe I didn't understand the order you wanted to use.

broulik updated this revision to Diff 10348.Jan 19 2017, 9:37 AM
broulik updated this object.
  • Improve default naming logic

file:/// → "/" (would be neat to also ask kfileplaces at some point)
ftp://www.somehost.com/ → "www.somehost.com"
ftp://www.somehost.com/foo/bar/ → "bar"

(I think showing domain for websites always by default is fine, if user really has multiple links he or she can still change the name)

What I used to do about all this is to turn every '/' into a unicode fraction slash (so that it still looks like a '/' to the user, but can be used in a filename), and name the link with the full URL like "ftp://www.somehost.com/foo/bar/".

See KIO::encodeFileName (and copyjob.cpp:813, i.e. if you use KIO::link() this happens automatically in KIO).

But maybe that's because I like URLs :-)

So, should we go with this now?

dfaure added inline comments.Jan 25 2017, 7:57 AM
applets/icon/iconapplet.cpp
108

Not convinced that KIO::encodeFileName would be better than a MD5 filename, then?

broulik added inline comments.Jan 25 2017, 12:36 PM
applets/icon/iconapplet.cpp
108

Ah, that's what you meant with that. I got confused as to where and why I should use this … so, will work for when there's no fileName? Then I can just use that indeed.

broulik updated this revision to Diff 10534.Jan 25 2017, 12:41 PM
  • Use KIO::encodeFileName instead of QCryptoGraphicHash
broulik updated this revision to Diff 10535.Jan 25 2017, 12:42 PM
  • Reflect in comment that we no longer hash
dfaure accepted this revision.Jan 26 2017, 8:19 AM
dfaure edited edge metadata.
This revision was automatically updated to reflect the committed changes.