Wednesday, August 27, 2008

KTorrent + Plasma = Good Times

I just found out today that KTorrent ships with a DataEngine and Plasmoid. (Yes, sometimes I'm a bit slow. ;) Now I can watch my torrents progress without having to keep popping up the KTorrent window. Nice!

This inspired me to do a little bit of hacking on the applet this evening. When the icon is clicked, it now pops up the KTorrent window and if you drop an entry from KTorrent to the desktop KTorrent plasmoid is created.

Since KTorrent already has drag and drop support internally, all I had to do to get plasmoid creation working was add one line to the plasma-applet-ktorrent.desktop file: X-Plasma-DropMimeTypes=application/x-ktorrent-drag-object. Extra nice!

It took 17 lines of code, however, to have the plasmoid set itself to the dropped plasmoid. There's obviously room for improvement there in the Plasma API. Possible improvements might include a way to get at the drop data as text (would have eliminated 4 lines) and a way to query an engine for a sorce based on some data (QStringList DataEngine::sourcesMatching(const QString &key, const QVariant &value) would have eliminated another 6 lines). Those two additions would take those 17 lines of code and turn them into just 7.

It remains to be seen if these methods would have general purpose use outside of this one plasmoid, though. There's no point in expanding the Plasma API just for the KTorrent plasmoid ;) so it's an important question.

Finding and activating the window for KTorrent took only 8 lines of code, thanks to libtaskmanager and KWindowSystem. If this becomes a common thing for plasmoids to do we will probably want to provide a convenience function in libplasma for this to make it easy for plasmoids and to avoid having to bind all of a libtaskmanager for scripted plasmoids.

It also occurred to me that it would be cool to support dropping a torrent file to the desktop and having a KTorrent download plasmoid offered as an option. I haven't implemented this, but it would be easy enough to do with a Plasma::Service that encapsulated aspects of the KTorrent D-Bus service (which is rather comprehensive and well designed in my opinion). That way the plasmoid could just do engine("ktorrent")->serviceForSource("core") and use that to load the file. In fact, this approach could be used to provide interaction such as start/stop/pause as well.

And all of this because I found a cute new toy to enjoy but wanted it to be drag and drop aware. ;)

7 comments:

Leonardo said...

Considering that:

a) System tray icons are sometimes used to visualize data (KTorrent up/down speed; amarok progress bar/playing status) or are used as a link to an application (Basket),

b) applications can ship with their own data engine, and

c) many developers (including yourself) have expressed dissatisfaction with the current implementation of the system tray,

is it possible that the system tray will be phased out by individual plasmoids?

For instance, a plasmoid can be associated with an application, which means it will load when the application is launched, including in the panel.

Aaron J. Seigo said...

@leonardo: "is it possible that the system tray will be phased out by individual plasmoids?"

probably not entirely, but we will be replacing several systray icons that currently exist in this manner, yes.

Mark said...

Why should the system tray icons be replaced by placemoids? Please leave a chance for users who do not follow this new desktop philosophy. I try to follow KDE-development for quite a while and I am really enthusiastic about a lot of things. The one thing I have failed making a sense of is having a desktop (which is normally covered with opened apps) crowded by a lot of stylish, geeky plasmoids which you can't see anyway. I have installed KDE 4 several times, tried and stil can not make any use of it. So please leave a chance for old style users to stay with KDE and enjoy other improvements.

Aaron J. Seigo said...

@Mark: "Why should the system tray icons be replaced by placemoids?"

because we can make plasmoids behave and look just like system tray icons, but not the other way around, and because the systray spec is horribly broken in terms of consistency between entries

"a lot of stylish, geeky plasmoids which you can't see anyway"

stylish .. and geeky? at the same time? heh. o-o-ok. as for "you can't see anyway": everything on the panel is a plasmoid. i imagine you can see those, right? there's also ctrl-f12.

"tried and stil can not make any use of it."

let me make a humble suggestion then: use it like you used kde3. that's completely possible, and the plasma team have spent a lot of time making sure that was possible.

in fact, we have spent the bulk of our time pandering exactly to people just like you.

"So please leave a chance for old style users to stay with KDE and enjoy other improvements."

the system tray protocol as it stands right now has absolutely zero to do with "new" vs "old" style. it's a very poor way to get icons into a panel application, nothing more.

parena said...

@Aaron & Mark: What I think Mark is afraid of, is that he can no longer see hit ktorrent, k3b or Amarok status when the system tray is gone. But what I gather from Aaron's words is that this good ol' systray icons can/will be replaced with plasmoids that show the same thing on your 'desktop' and, for Mark very important, in your panel. So, you will have, 'faked' systray icons which do the same thing as the old ones but can possibly do more.

1 Use I can think of real quickly is if you get an instant message through kopete from someone and the plasmoid in your panel flashes or it shows as the good old bubble or as an extender (or however it will develop). You can then click "quick reply" and within the extender you can type a quick message and send it without having to open a chat window or kopete itself.

Maybe not the perfect example, but I think Mark can be rest assured his "old school" systray icons will never be truly gone, but that they'll get more usable than ever before. And if I'm completely wrong on this one, maybe I just gave the KDE devs a great idea. ;)

Matthieu Gallien said...

Hi,
Congratulations to the plasma team for the 4.1 release. It is very easy to use.
Why do you want to extend libplasma to deal with libtaskmanager instead of using a service engine ?
I thought that the service engine were made to do this type of job.
Do you know if somebody has already started to write such a service engine ? I may found time to do it next week. Still I cannot promise anything.

Todd said...

I don't know the technical underpinnings of what you did, but at the very least applications that I think could benefit from this sort of drag-and-drop behavior would be any program with large progress bars, any folder dealing with pictures or videos (to open a picture viewer or video viewer), okular and koffice programs for previews, and any program that can show hyperlinks for the plasma web browser. So for instance dropping a url could open the web browser plasmoid, dropping a picture could open a picture frame, etc. As I said, I don't know if any of that would benefit from your changes.

As for system tray icons I would really like to see changed to plasmoids (some, or all, of which probably will be at some point): kmix, kdebluetooth, knetworkmanager, kwallet, and krandr. I would also like to see the kpowermanager icon merged with the battery monitor applet.

With all the functionality present in plasma applets I don't see any reason to use the system tray at all any more. Plasma applets can do everything system tray icons can do, but can do far more, can do it anywhere you want on your screen, and you can have as many copies of them as you want. System tray applets all have to be stuck together and they can only appear once.