Port away from deprecated KIO::NetAccess
ClosedPublic

Authored by yurchor on Feb 13 2019, 5:16 PM.

Details

Summary

Port away from KIO::NetAccess leftovers

Test Plan

Compiles and installs, works at least with usual downloads.

Diff Detail

Repository
R433 KGet
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.
yurchor requested review of this revision.Feb 13 2019, 5:16 PM
yurchor created this revision.

First of all, thank you for your contributions! ;-)

TBH, I'll need some time to look through this though...
Comments from other people are of course very welcome!

Just one thing I'd like to tell you right now, because of
https://cgit.kde.org/kget.git/commit/?id=e779f1896c8a2892f1e9acfab5425252eeeb06b6

AFAIK, KStandardDirs guaranteed that the target directory exists, while QStandardDirs doesn't.
I did fix a couple of porting problems related to that in other areas myself...
It looks to me that this commit might have introduced new ones in kget, i.e. certain things might seize to work if ~/.local/share/kget/ doesn't exist yet.
That's something I need to test myself anyway, but maybe you could help. ;-)

First of all, thank you for your contributions! ;-)

TBH, I'll need some time to look through this though...
Comments from other people are of course very welcome!

Just one thing I'd like to tell you right now, because of
https://cgit.kde.org/kget.git/commit/?id=e779f1896c8a2892f1e9acfab5425252eeeb06b6

AFAIK, KStandardDirs guaranteed that the target directory exists, while QStandardDirs doesn't.
I did fix a couple of porting problems related to that in other areas myself...
It looks to me that this commit might have introduced new ones in kget, i.e. certain things might seize to work if ~/.local/share/kget/ doesn't exist yet.
That's something I need to test myself anyway, but maybe you could help. ;-)

This should be fixed now. Thoroughly tested on a clean profile for generic testing downloads of zip files and torrents.

https://cgit.kde.org/kget.git/commit/?id=f12296b9241a218a9f88169e0cb450eda4dddb99

Sorry for that breakage.

This should be fixed now. Thoroughly tested on a clean profile for generic testing downloads of zip files and torrents.

https://cgit.kde.org/kget.git/commit/?id=f12296b9241a218a9f88169e0cb450eda4dddb99

Great, thank you very much! (for the testing as well)

I suppose it could be optimized a bit (e.g. it's not really necessary to test the existance of the directories, as QDir::mkPath() does that anyway, David Faure told me that once in one of the review requests I made... ;-) )
But please don't bother, it's more important that it works I think.

Sorry for that breakage.

Don't worry. That's a more common pitfall, and that's actually why I decided to mention it here even though it's unrelated to this patch.

Regarding this, I think it should be fine, except maybe one thing that I mentioned inline.

And I'm not sure the additional debug output is necessary, but it certainly doesn't harm either I think. (so no need to remove it from my point of view)

core/mostlocalurl.cpp
39–55

Maybe use KIO::mostLocalUrl + job->exec() instead?

As mentioned in the KIO::NetAccess::mostLocalUrl docs:
https://api.kde.org/frameworks/kdelibs4support/html/classKIO_1_1NetAccess.html#af5169ea05b504a687094c3279e7b8b83

yurchor added inline comments.Feb 20 2019, 7:18 PM
core/mostlocalurl.cpp
39–55

That was some kind of copy-paste from the current implementation in kdelibs4support, but I'll try to rewrite it asap. Thanks.

yurchor updated this revision to Diff 52208.Feb 21 2019, 2:38 PM

Use the proposed scheme, KIO::mostLocalUrl + job->exec()

yurchor marked an inline comment as done.Feb 21 2019, 2:38 PM
wbauer requested changes to this revision.Feb 22 2019, 12:04 PM

See inline, the if (job->error()) branch in particular looks quite broken to me.
OTOH, I'm not sure if trying to do something else in case of an error actually makes sense, it's probably sufficient to just return the original URL in case the job fails.
I.e., I think this could be reduced to just:

if(job->exec()) {
   return job->mostLocalUrl();
}

return url;

A general remark: the { should usually be on the same line as the if. Although, the original code probably isn't completely consistent either...

core/mostlocalurl.cpp
42

This leads to a compiler error here:

error: 'KJobWidgets' has not been declared

But, do we actually need that at all?
I assume that window will be nullptr anyway unless we'd explicitly set it.

44

Coding style: job->exec(); (without spaces)

Also, I'd probably rather test the return value of job->exec() directly like you did in the rest of this patch, instead of testing job->error() in the next line.

46–47

What is this supposed to do?
entry does not get assigned anything and should therefore be empty AFAICS.

Also, coding style nitpick: no spaces inside the ()

52–54

Wrong indentation. This else belongs to the if (job->error()) { in line#44 and should be aligned to that.
(and if not, there would be a } in the wrong place...)

This revision now requires changes to proceed.Feb 22 2019, 12:04 PM
yurchor marked 4 inline comments as done.Feb 22 2019, 12:23 PM

That was actually a try inspired by the similar code in Dolphin. I've tried to implement everything and might be failed. :)

yurchor updated this revision to Diff 52292.Feb 22 2019, 12:26 PM

Simplify the code

wbauer requested changes to this revision.Feb 22 2019, 3:38 PM

Should be good now, thanks!

Just noticed another minor thing.

And I would maybe just omit the additional if's and debug output altogether like the original KIO::NetAccess:synchronousRun code did (it's probably not very useful to know that deleting a temporary file failed...).
I'll leave that decision to you though. ;-)

core/mostlocalurl.cpp
40

Please change to job->exec(), i.e. remove the spaces around ->.

transfer-plugins/kio/transferKio.cpp
25–26

Is this change intentional?
CopyJob is used in the file, I don't see how your changes would suddenly require KJobWidgets instead.

This revision now requires changes to proceed.Feb 22 2019, 3:38 PM
yurchor marked 2 inline comments as done.Feb 22 2019, 4:03 PM

And I would maybe just omit the additional if's and debug output altogether like the original KIO::NetAccess:synchronousRun code did (it's probably not very useful to know that deleting a temporary file failed...).
I'll leave that decision to you though. ;-)

Cannot decide either. It's a common pattern, although not very useful indeed.

yurchor updated this revision to Diff 52314.Feb 22 2019, 4:04 PM

Fix braces for if(), spaces for '->' and include

wbauer accepted this revision.Feb 27 2019, 8:35 PM

Sorry for the delay again, I was busy with other things...
Thanks for the additional changes.

Please push it, master only of course.

This revision is now accepted and ready to land.Feb 27 2019, 8:35 PM
This revision was automatically updated to reflect the committed changes.