
In the Add Widgets dialog the Install New Widgets button is now a menu, letting you choose between downloading from the Internet using GetHotNewStuff and DXS (where what you are about to see is even more automated) or opening a widget from a file. Our test case was the Hello World widget example from Apple.
When you select the "Open From File" entry you get this:

It's an assistant dialog that lists all known packages. It doesn't list all known applet types because to the user it shouldn't matter whether a widget is implemented in Python, Ruby, ECMA Script, XTHML+JavaScript or what-not. If they behave the same and load the same then to the user they are the same. The difference here is the package type: Apple's widgets are different from Plasma's native widgets in how they are packed up and they appear to the user as different.
I'd like to eventually automate this by trying to get plasma to figure out what kind of package it is automatically. Unfortunately right now we don't have mimetype detection for different kinds of widgets and I just haven't done enough research with all the possible package types before me to do this. This is something I want to look into for 4.2 (unless someone beats me to it, of course).
Anyways, the way we get this listing is Plasma queries for all known widget types. Every widget type advertises what "language" it is; for Mac Dashboard support the language is "dashboard". Every widget type may also advertise what sort of package structure it uses. Here's the .desktop file contents for Mac Dashboard:
[Desktop Entry]
Encoding=UTF-8
Name=Dashboard
Comment=MacOS X dashboard widget
Type=Service
ServiceTypes=Plasma/ScriptEngine
Icon=internet-web-browser
X-KDE-Library=plasma_appletscriptengine_dashboard
X-KDE-PluginInfo-Author=Zack Rusin
X-KDE-PluginInfo-Email=zackr@kde.org
X-KDE-PluginInfo-Name=dashboard
X-KDE-PluginInfo-Version=pre0.1
X-KDE-PluginInfo-Website=http://plasma.kde.org/
X-KDE-PluginInfo-Category=Applet
X-KDE-PluginInfo-Depends=
X-KDE-PluginInfo-License=BSD
X-KDE-PluginInfo-EnabledByDefault=true
X-Plasma-ComponentTypes=Applet
X-Plasma-Language=dashboard
X-Plasma-PackageFormat=dashboard
Currently Plasma has package structures for wallpapers, Plasma themes and widgets. New ones can be added at runtime, however. If the package structure is static, which is to say the files are always in the same place in the package, you can do this with a simple rc file. The PackageStructure class can read and write these files as well. If the package is not static, then you can instead provide a C++ plugin that manages this. Also, if the package requires special installation routines the same C++ plugin can provide that. Both are true in the case of the Mac Dashboard widget support.
So when a Mac Dashboard widget is opened up, Plasma looks at the X-Plasma-PackageFormat entry and goes off in search of the dashboard package format. It finds it here:
[Desktop Entry]
Encoding=UTF-8
Name=Dashboard Widget
Comment=MacOS dashboard widget
Type=Service
ServiceTypes=Plasma/PackageStructure
X-KDE-Library=plasma_packagestructure_dashboard
X-KDE-PluginInfo-Author=Zack Rusin
X-KDE-PluginInfo-Email=zackr@kde.org
X-KDE-PluginInfo-Name=dashboard
X-KDE-PluginInfo-Version=pre0.1
X-KDE-PluginInfo-Website=http://plasma.kde.org/
X-KDE-PluginInfo-Category=Applet
X-KDE-PluginInfo-Depends=
X-KDE-PluginInfo-License=BSD
X-KDE-PluginInfo-EnabledByDefault=true
X-Plasma-PackageFileFilter=*
X-Plasma-PackageFileMimetypes=application/zip
Mimetypes and filters for the file selection are defined, as is the library and plugin name by which to load it. At this point Plasma can now call the install method which looks like this in the dashboard package structure plugin:
bool Bundle::installPackage(const QString &archivePath,
const QString &packageRoot)
{
QFile f(archivePath);
f.open(QIODevice::ReadOnly);
m_data = f.readAll();
f.close();
open();
if (m_isValid) {
m_tempDir->setAutoRemove(false);
QString pluginName = "dashboard_" + m_bundleId;
//kDebug() << "valid, so going to move it in to" << pluginName;
KIO::CopyJob* job = KIO::move(m_tempDir->name(), packageRoot + pluginName,
KIO::HideProgressInfo);
m_isValid = job->exec();
if (m_isValid) {
//kDebug() << "still so good ... registering";
Plasma::PackageMetadata data;
data.setName(m_name);
data.setDescription(m_description);
data.setPluginName(pluginName);
data.setImplementationLanguage("dashboard");
Plasma::Package::registerPackage(data, m_iconLocation);
}
}
if (!m_isValid) {
// make sure we clean up after ourselves afterwards on failure
m_tempDir->setAutoRemove(true);
}
return m_isValid;
}
What's happening in the code above is that Bundle opens the file at archivePath and makes sure it does indeed have the needed contents. It then copies it to packagRoot and registers the widget. Reigstration is accomplished by creating a PackageMetadata object, setting the relevant fields and passing it to Package::registerPackage, optionally along with the path to an icon for it. This creates an entry in the ksycoca database using a .desktop file that looks exactly like a native Plasma widget, except that this one is marked as being in the "dashboard" language.
This process all happens fairly well instantly and the result is that the widget appears in the widget listing alongside all the others:

The user sees no real difference. Places on the canvas we get:

As with native Plasmoids you can rotate it, resize it, drag it around to wherever you want, etc. Corona, Containment and even Applet are all blithely unaware anything different is going on. Zack was downloading various widgets from apple.com and trying them out and they tended to Just Work(tm).
(There are some issues currently with QtWebkit and these widgets (such as the white background and incorrect starting size), but Zack has pushed fixes for those upstream and those should be trickling down soon.)
Remember, however, that this is not specific to Mac Dashboard widgets. We can do this for any widget type we want. Indeed, Zack went ahead and did up a "native" webkit based widget for Plasma. As with Mac Dashboard widgets you do it all in HTML and use JavaScript within the webpage itself to manipulate it. Unlike Mac Dashboard, you can access Plasma goodies ... like DataEngines. So from embedded JavaScript you can fetch data from an engine and display it on your web based widget. Langauge type is "webkit". Nice.
(In fact, the Package stuff isn't specific to widgets at all. We could apply this to all sorts of after-market application add-ons.)
If you would like to add other types of widgets, I'd be happy and interested to both help you out and get resulting code into svn. Google Gadgets, Yahoo widgets, Windows Vista widgets, Opera Widgets ... they are all game. While they won't have all the features of the native Plasma widgets or cover the same kinds of topics, it would be great to be able to give people access to the whole world of widgets on their desktop.
Be Free to use the widgets you want, we have no agendas to push here.

27 comments:
Nice!!! :-)
Wow thats just so cool..
B.t.w. when will superkaramba widgets be supported?
You mean, moreless, that will be posible to use any of these in KDE?:
http://www.apple.com/downloads/dashboard/top50/
Wow!!
amazing!
nice work!
Now we're waiting for a qt-copy update so the changes in webkit allow this stuff to actually work for us mere "kdesvn-build" users out there :D
@second anonymous: superkaramba has been supported since 4.0 (and before)... they just need to be in this same dialog, I guess. I must confess I can't find the way to add superkaramba applets to plasma right now, I thought there was a 'plasmoid' which loads superkaramba applets...
The Encoding key is deprecated, the ServiceTypes key is not part of the Desktop Entry spec, should therefore be prefixed with X-KDE- as well.
I for one am glad th screen cast didn't work. I can't watch screencasts, and pictures are worth so much more to me. :)
Oh nice, we have a broken panel but can open Apple dashboard widgets... Sorry, but it seems more like a joke to me, and although this may sound offensive - it isnt... Having core functionality ready and usable before the fancy stuff arrives should be first on the list...
And just in case you want to tell me that others will handle this stuff sooner or later: Its all a matter of organization and priorities...
And where the heck is a roadmap or something like that for Plasma?
great work! thank you
@2nd anonymous : http://techbase.kde.org/index.php?title=Development/Tutorials/SuperKaramba#SuperKaramba_on_KDE4
@joshen : please stop complaining...
http://techbase.kde.org/index.php?title=Projects/Plasma/4.1_Roadmap
@aseigo : A screencast of the 'chuck norris facts' dashboard widget would have been better ;[. Anyway, great work ! as always...
Awesome!
Just one little comment; is the black border supposed to remain there? It looks kind of odd with it there, seeing as Dashboard widgets are designed to draw their own borders and such.
@anonymous: "when will superkaramba widgets be supported?"
they already are. to take advantage of the install system we just need a proper .desktop file added.
@Jochen: "Oh nice, we have a broken panel but can open Apple dashboard widgets... Sorry, but it seems more like a joke to me, and although this may sound offensive - it isnt..."
it's not offensive, it's just stupidity. as such, it's hard to be offended. annoyed at your ignorant ranting, certainly, since it's so amazingly uncalled for, but not offended.
see: Zack did all the work for the actual dashboard widget support. am i supposed to turn to Zack, who isn't even a regular plasma contributor, and say, "work on the panels! no dashboard! no webkit!" of course not. that's not how open source works.
meantime, the Package support needed to be completed just as the panel things need to be completed for Plasma to be fully functional. Packages are not just for mac dashboard widgets, but for all of our add ons (wallpapers, themes and native widgets to name three). you may have noticed that modularity and management of that modularity are key themes in plasma.
at the *same* time, we *are* working on improving panel support. we've even backported fixes to 4.0.2 such as sizing and position controls in the UI. if you follow the panel-devel mailing list or review-board, you would know that.
"Having core functionality ready and usable before the fancy stuff arrives should be first on the list..."
so let me reiterate this again: Package is core functionality. it's not "fancy" stuff. the dashboard stuff is, but that was zack's contribution on his own time and made for a great test case for Package since it's a sort of worst case scenario.
"And just in case you want to tell me that others will handle this stuff sooner or later: Its all a matter of organization and priorities..."
honestly, i don't need your lectures. particularly since your lecture is not based in reality.
"And where the heck is a roadmap or something like that for Plasma?"
someone already pointed you to it. my question to you is what are you going to do with that knowledge?
btw, i "love" the polite "where the heck" there as if i owe you a roadmap. is it too much for you to be, you know, mildly nice?
you can say what you want without it being so blatantly outlandish. if you can't manage that, i'll start moderating your comments on my blog. hopefully that will give you some motivation to stop being a douche here.
@anonymous: the border will probably go away, yes.
propably offtopic:
fontrendering does not look nice on these screenshots, somewhat blurred. and has the kde-team ever considered to change the default "Sans" font with bitstream or dejavu -sans ?
The "kde-team" doesn't decide your default fonts. Your distro's developers does. Talk to them.
Aaron, you must be like honey, always attracting angry bees ;)
Seriously, I have a suggestion how to better emotionally deal with the crap people like Jochen throw at you:
It is often said that for every troll there are hundreds of silent satisfied users. I have a better one.
By definition, absolutely EVERY unhappy, socially-inept KDE-user MUST vent his/her anger/frustration in life somewhere. On-line comments on Aaron's blog and dot articles is the cheapest way to do it, so they do, while every other kind of user/reader may or may not post.
A blog post with 14 comments so far and only one being of the unpolite, completely useless kind is pretty good by that standard. You are doing really fine ^-^
Cheers
Oh, little nitpick: Isn't it "Mac OS X", not "MacOS X"?
nice work
This is very cool :)
Do you have a list who works on what (Google/Opera/Yahoo widgets)?
@Aaron,
I must confess to being a bit confused about how plasma and superkaramba integrates...
"they already are. to take advantage of the install system we just need a proper .desktop file added."
Does that mean, like I think it does, once that .desktop file has been added that you can install them using whatever that gadget in the top-right corner is called? Even pre-KDE4 themes, or do the legacy themes if you will need to be run using the standalone app? The latter works but it would be nice if they were installed using the "Add widget" dialogue.
Hm...wonder if someone is crazy enough to patch plasma to use gdesklets and/or conky scripts...
@Jonas
SuperKaramba works now too, see http://www.kdedevelopers.org/node/3305
@ Sebastian Sauer: I think that I am a bit too stupid for this but I just can't figure out how to get my Liquid Weather running on Plasma.
Kannst du es mir bitte auf Deutsch erklären?
@ Aseigo: Sir, you are doing a fine job so don't let "bad mouths" discourage you :)
I welcome and greatly appreciate every improvement of KDE.
Plasma is obviously still in it's early stage of development but it's fun watching it as it evolves and matures.
Thank you and the rest of the team for making it possible for us Linux users to take advantage of the most modern technologies and innovations on the Desktop.
Aaron, i have to apologize for my previous comment here.
For a user like me, its not always clear where the direction goes... Now that i have read more about this all (thanks for the links guys!), i am fully confident in what the devs trying to accomplish...
Again, sorry for my stupid comment.
@Jochen
Wow! very little people are big enough to apologize like that. Congrats!
I have not "Install New widgets button ". I must install additianal pakiges?
hi! like last Anonymous said, I do not have the Install New widgets button. I installed Fedora 9.
I am just going crazy... where is it?!?!
I have downloaded some mac widget, and when I try to install them... well, nothing happend..
Did I missed something?
Post a Comment