Use a faster way to determine kio-stash isn't installed
ClosedPublic

Authored by hein on Dec 1 2017, 9:52 PM.

Details

Summary

Dolphin needs to figure out whether or not kio-stash is installed
to set the enabled state of a UI action.

When KProtocolInfo::isKnownProtocol can't find a protocol it gets
worried its protocol cache might be out of date, so it rebuilds it
(doing plenty of disk I/O) and looks again. kio-stash is currently
not yet installed on many systems, so this means most Dolphin
startups out there.

This patch switches to using QDBusConnectionInterface::isServiceRegistered
instead to determine whether the stash notifier daemon is running,
which should be faster than doing disk I/O.

Diff Detail

Repository
R318 Dolphin
Branch
master
Lint
No Linters Available
Unit
No Unit Test Coverage
hein created this revision.Dec 1 2017, 9:52 PM
Restricted Application added a subscriber: Dolphin. · View Herald TranscriptDec 1 2017, 9:52 PM
hein requested review of this revision.Dec 1 2017, 9:52 PM

What about non-unix systems? e.g. on Windows we don't have dbus but the stash ioslave could still be functional (or maybe not, @shortstheory what do you say?)

on Windows we don't have dbus

Why is it so? Craft installs and packages dbus...

on Windows we don't have dbus

Why is it so? Craft installs and packages dbus...

Oh that's news to me. Then I guess the patch is fine.
Let's wait for @shortstheory opinion.

Sorry for the late reply, I have endsem college exams atm.

How do daemons register themselves on Windows' KDED5 module (if there is one)? Otherwise, the patch looks good.

 QDBusMessage msg;
 QDBusMessage replyMessage;
 msg = QDBusMessage::createMethodCall(
           "org.kde.kio.StashNotifier", "/StashNotifier", "", "pingDaemon");
 replyMessage = QDBusConnection::sessionBus().call(msg);
 if (replyMessage.type() == QDBusMessage::ErrorMessage) {
     qDebug() << "Launching fallback daemon";
     const QString program = "./testdaemon";
     stashDaemonProcess->start(program);
}

I've been doing it like this for testing if the stash daemon is active for the unit tests. This makes sure that the caller is able to use DBus and get replies from it successfully. Perhaps that should change to the approach used in this patch as well...

hein added a comment.Dec 4 2017, 5:41 PM

I'm not expert but I don't think this breaks Windows.

I need a ship-it ... :)

-2

You shouldn't depend on the implementation details of ioslaves. KIO has a well-defined interface to determine if an protocol can be handled.
And if the implementation of this interface is not good enough, then it needs to be improved (e.g. decrease number of file system look-ups, better cache invalidation, ...).

hein added a comment.Dec 4 2017, 8:48 PM

It's tricky. On the face of it you're right, because what the action does is open a view using the ioslave, and yes, it shouldn't be aware of the implementation details.

Here's the best argument for it: The protocol being known isn't the same as kio-stash actually working, because if the service isn't registered then even if the protocol is known the stash won't work anyway. You can therefore argue that this code better captures intent - the action will actually work if this requirement is satisfied.

It would be nicer if the "aware of implementation details" part were encapsulated within kio-stash itself, i.e. if it could supply this action as a plugin to Dolphin. But Dolphin isn't currently extensible in this way, so given that this action being in Dolphin code is suboptimal to begin with (it's coded against an ioslave it doesn't install itself), I still think this patch is a pragmatic way forward as it improves both performance and reliability.

To sum it up: This should be done in a more proper way (kio-stash adding this action to Dolphin in some way knowing when it can be enabled), but in the meantime there's no good reason for it to be slower and less reliable.

Alright, my college exams finally got over so I have some time to think about this.

I feel that Dolphin should have some more configurability and having dedicated code just for showing a button for a not-very-commonly used ioslave is probably not the best idea. Perhaps it's better if this is moved to the add-on "Services" which can be opened from a Context menu? @emmanuelp would know if it's possible to add a toolbar button that way (should be because it's just a QAction at the end of the day).

elvisangelaccio added a comment.EditedDec 13 2017, 10:13 PM

@shortstheory Have a look at KAbstractFileItemActionPlugin, it definitely allows to show context menu actions depending on some custom logic.

elvisangelaccio accepted this revision.Dec 28 2020, 5:06 PM

Given that nothing happened in 3 years and that kio-stash (sadly) is still not very popular, I'm going to merge this patch.

This revision is now accepted and ready to land.Dec 28 2020, 5:06 PM
Restricted Application added a project: Dolphin. · View Herald TranscriptDec 28 2020, 5:06 PM
Restricted Application edited subscribers, added: kfm-devel; removed: Dolphin. · View Herald Transcript

Merged with b339ac1b5f22efb57619c738eb39268c3e00948d