Monday, 29 July 2013

GSoC - Week 6

Hey :)
I'm Anmol, and this is the report for week 6 of my work on revamping Amarok's scripting interface. This week has been mostly been about polishing existing functionality and documenting code.

A major problem I faced this week was with the KPluginSelector widget and the KNewStuff plugin installation. KDELibs provides a DownloadDialog for easy downloading of plugins from, and uses a .knsregistry file for storing a list of files installed as part of the plugin, used by the download dialog when uninstalling files.

But annoyingly,  these installation, removal and updation methods don't seem to be exposed in any way besides the download dialog, which explains  the way we handle updation in Amarok. ( Which also means that uninstallation via the download dialog of scripts updated through amarok will leave behind newly introduced files ). The KPluginSelector, likewise, is pretty inflexible.

So what I ended up settling on is re-creating our KPluginSelector [derivative] everytime the scripts are modified, with some other workarounds to keep everything sane, like having to sort entries before insertion and having to keep a map of script names to their indices in the KPluginSelector.

For the uninstall, instead of parsing the knsregistry file, I'm just recursively deleting the script's base folder in amarok/scripts/, so here's hoping nobody bundles multiple scripts into one folder, atleast until this is improved.

Another problem was the deprecation framework- I couldn't detect an object call. For example, Amarok.Collection is now deprecated, and Amarok.CollectionManager should be used instead ( though we could possibly just keep both indefinitely ), so I had to be able to detect it. I needed dynamic getters, and fortunately stumbled upon Object.defineProperty introduced in ECMAScript5.
So I subclassed QScriptEngine and introduced a setDeprecatedProperty function:
So with this, most of what remains of my revamp are the actual APIs I am to  expose, and I still have to explore SMOKE! Hopefully I can automate those interfaces instead of having to manually write a bunch of wrappers, there are better things to do for Amarok :)

Tuesday, 23 July 2013

Weeks 4 and 5

Hey, as mentioned in my previous posts, I'm working on revamping Amarok's Scripting Interface as part of this year's Google Summer of Code. For those of you who've been living under a rock, Amarok is the best thing in music players since the phonograph.

So here's what I've been upto:

  • Scripting documentation
One of the biggest gripes about Amarok's scripting API has been the lack of documentation. There's mostly just a manually created [read error-prone] list of exposed interfaces on the wiki.

Auto-magic documentation of the scripting API posed a different challenge, as the scripting API does not resemble the standard Amarok C++ code.
After procrastinating it for a good three weeks ( how many of us follow their proposals, anyway? ), I settled on this python script to generate a pseudo-header, and also an auto-completion list, but more on that later.

Here's the resulting doxygen output.

It's not perfect yet, but the results look pretty decent. Please do comment though if you know of a better way of going about this!

  • Autocomplete
The script console's auto-complete is working now. Because nobody likes looking up the documentation too often ( or retrying, or introspecting, or whatever ),  just to get the syntax of an arbitrarily named interface right.

Sadly, no contextual information, but anything more would probably require me to move to kdevplatform. Any katepart/ ktexteditor guys willing to correct me?

  • Deprecation Notification

This might be one of the more controversial additions, but hey, it's all for the greater good.

Users running scripts accessing deprecated API calls see a popup of the sort on the left, so they can bug script writers into updating their scripts.

What are your views on this, Amarok Script Writers?

  • No restarts
That's right, you no longer have to restart on installing a new script in Amarok, so you can right down to listening to your Google Music content after installing the script ( well, as soon as streamitem's fixed in my branch actually ).

There's more changes under the hood, and still lots more to cleanup and document, but I have new leads - Markey just pointed me Richard Dale's SMOKE, which might hopefully help get things done better.

Monday, 8 July 2013

GSoC - Weeks 1, 2 & 3

Hey :)
As I mentioned in my previous post, I'm working on revamping Amarok's scripting interface for GSoC 2013. Here's an update on what I've been working on these past 3 weeks.

1. Script Termination

Amarok now checks running scripts, and offers to terminate long running/ unresponsive ones after a 5 second duration, so you can now kill unresponsive scripts instead of having Amarok freeze on you.Here's a screenshot of the popup:

Yes, the popup's ugly. It's going to be a simple modal dialog instead, as Mark [my mentor, Amarok founder] suggested.

2. Collection Management

Now, script writers have access to Amarok's underlying collection management. Scripts can now access collections, query them using simple collection browser like queries, and copy/ move files among them.

3.Script Console

I've now been working on a new script console- here's a screenshot:

Hovering over the running script , you now get controls for stopping the script, and clearing it. Scripts are automatically saved to the disk (with random names and other plugin specs for now), and you can optionally have them cleared from the disk too.

Double clicking on the script, opens up the editor, and like the main editor on the left. It is a standard katepart, so you get cool features like syntax highlighting, word completion and auto-indentation.

This is quite crude a prototype right now, though. If approved, I'll hopefully be able to work on a code completion model, so you can have auto-completion for Amarok Script. This does, however, pose some difficulties, but they can hopefully be sorted out with the help of my mentor and the kparts team.

There's also two bug fixes- a fix for the crashes on disabling Free Music Charts, and a fix for crashes that may occur when the dependencies for a script weren't listed in its specs.

PS - My apologies for not having been regular with my blog updates- there isn't really much I can say in my defense, except for the assurance that I'll be more regular from now on.

Again, I repeat:
Amarok Script Authors please provide feedback on what you'd like to see in the scripting interface here [comments on the blog are okay, too] so I can work on implementing it.