My first plasmoid with JavaScript

Enviado por Alex el Sáb, 06/08/2011 - 21:43

Posted in kde | coding | es | blog de Alex | agregar nuevo comentario | 3559 lecturas »

When I bought my computer I chose on purpose a couple of hard disks with a small capacity, and I set them up them on RAID 1. I wanted to force myself to delete stuff often, and avoid hoarding. I still hoard probably more than I really need, and coupled with the size of videos nowadays, and the fact that I usually have several virtual machines, or chroot environments, my hard disk is usually close to being full. One of the commands that I run more often is df, to the point that sometimes I even have a virtual console running watch df.

This is so impractical that I started testing different plasmoids (that is, the applets for the Plasma KDE Workspace) to display permanently the remaining space of my two main partitions. The default applet that comes with the workspace looks great, but only on the desktop. If you move it to a panel it looks bad, and much worse, it doesn't clearly display the number with the information, just a bar that always looks almost filled.

The optimal solution is digging in the code and trying to fix the applet myself to make it more useful in the panel, but I'm still using the latest available packages of my distribution, which are version 4.6, when 4.7 is freshly released. If I had to wait for 4.8 to be released and packaged, that would mean about half a year. There is also the problem of conflicts of interest: I might be able to do some changes to the applet, but the maintainer might not like them (that already happened to me).

So the suboptimal solution was creating an applet myself. Thanks to the awesome work of the Plasma team, you can code a plasmoid in almost any programming language. That includes JavaScript, which is kind of preferred, since you don't require compiling, is pretty lightweight, and doesn't need additional dependencies because a JavaScript runtime is shipped with Qt. I have to admit that it was pretty easy because I just had to read some stuff, copy lines from the examples and tutorials, and now is working with all the functionality that I need.

I'm not specially proud of how it looks, but what the heck, here it is (as I said, is just what I need):

disk usage on a panel

Unfortunately, the documentation is kind of rough. Many APIs are loosely described and the tutorials are half baked (and spread between the different programming languages), so I had to work around problems that I still don't understand. Is very likely that I will at least try to fix or complete those docs, because I really think that I owe that to the KDE community, and since I had so much fun doing it (although I had some frustration too), I already started another plasmoid. This time I will be using QML so I expect to provide some decent looking UI.