{"id":4334,"date":"2010-11-01T08:25:55","date_gmt":"2010-11-01T08:25:55","guid":{"rendered":"http:\/\/www.notmart.org\/index.php\/BlaBla\/Declarative_Knowledge_Base"},"modified":"2010-11-01T08:25:55","modified_gmt":"2010-11-01T08:25:55","slug":"declarative_knowledge_base","status":"publish","type":"post","link":"https:\/\/notmart.org\/blog\/2010\/11\/declarative_knowledge_base\/","title":{"rendered":"Declarative Knowledge Base"},"content":{"rendered":"<p>As I described in the latest entry, with the KDE Plasma Workspace 4.6 there will be a new feature that will be a key one for the future evolution of the Plasma platform: the ability to write plasmoids with just QML and Javascript.<\/p>\n<p>So, let&#8217;s try to see if it&#8217;s possible rewrite the average widget in with the declarative scriptengine&#8230;<\/p>\n<p>We have a dataengine (using a neat library called Attica) that can query the various functionalities of websites that offer an API compatible with the Open Collaboration Services, such as <a href=\"http:\/\/www.opendesktop.org\">OpenDesktop.org<\/a>. One of the features offered by this API is the Knowledge Base: users subscribed to the site can ask any question (in topic with the website) and other users can answer to them. Plasma offers a <a href=\"http:\/\/www.notmart.org\/index.php\/BlaBla\/Spread_your_knowledge\">desktop widget<\/a> that can query and visualize those question\/answers. It&#8217;s written in c++ and is about 400-500 lines of code.<\/p>\n<p>How much QML code would take to write a very minimal Declarative Plasmoid that can access the knowledge base entries trough the Plasma dataengine? Here it is<\/p>\n<pre>\nimport Qt 4.7\nimport org.kde.plasma.core 0.1 as PlasmaCore\n\nListView {\n    clip: true\n    width: 200\n    height: 300\n\n    PlasmaCore.DataSource {\n        id: source\n        engine: \"ocs\"\n        source: \"KnowledgeBaseList\\provider:https:\/\/api.opendesktop.org\/v1\/\\query:opendesktop\\sortMode:new\\page:0\\pageSize:10\"\n        interval: 120000\n    }\n\n    model: PlasmaCore.DataModel {\n        dataSource: source\n        key: \"KnowledgeBase-[\\d]*\"\n    }\n\n    delegate: Text {\n        text: Name\n    }\n}\n<\/pre>\n<p>24 lines \ud83d\ude09<\/p>\n<p>What is important to look here is the DataSource{} definition that defines to what engine we&#8217;re connecting and to what source. And the DataModel{} that hooks up what has been fetched by the DataSource to a suitable model for the use by the ListView.<\/p>\n<p>Let&#8217;s expand from this to something that can be compared to the C++ version in terms of functionality. You can download an early example of the code from <a href=\"http:\/\/www.notmart.org\/misc\/declarativeknowledgebase.qml\">here<\/a>. (all is available from the <a href=\"http:\/\/www.notmart.org\/misc\/declarativeknowledgebase.qml\">playground<\/a> svn repo). It&#8217;s still early to include it in the 4.6 release for various reasons, but the path is definitely clear \ud83d\ude42<\/p>\n<p>Here you can see a brief screencast of the two plasmoids, the C++ and the declarative one working side by side.<\/p>\n<p><object width=\"480\" height=\"385\"><embed src=\"http:\/\/www.youtube.com\/v\/wI-Aag0clQY?fs=1&amp;hl=en_US&amp;color1=0x234900&amp;color2=0x4e9e00\" type=\"application\/x-shockwave-flash\" allowscriptaccess=\"always\" allowfullscreen=\"true\" width=\"480\" height=\"385\"><\/embed><\/object><\/p>\n<p><a href=\"http:\/\/blip.tv\/file\/get\/Notmart-CAndQMLOCSKnowledgeBasePlasmoids899.ogv\">OGG version<\/a><\/p>\n<p>Here is a video tutorial that explains the steps taken to write this plasmoid.<\/p>\n<p>It is also a little demo of the Plasmate IDE that while it&#8217;s still at early development stages, it&#8217;s pretty impressive already: all you have to do is write the code and test it in the preview side panel. zero worries about creating the package structure, desktop files or installing :p<\/p><embed src=\"http:\/\/blip.tv\/play\/AYKIyxoA\" type=\"application\/x-shockwave-flash\" width=\"480\" height=\"300\" allowscriptaccess=\"always\" allowfullscreen=\"true\"><\/embed><p><a href=\"http:\/\/blip.tv\/file\/get\/Notmart-TutorialDeclarativePlasmoids691.ogv\">OGG version<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>As I described in the latest entry, with the KDE Plasma Workspace 4.6 there will be a new feature that will be a key one for the future evolution of the Plasma platform: the ability to write plasmoids with just QML and Javascript. So, let&#8217;s try to see if it&#8217;s possible rewrite the average widget [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[47,2,10,21,7,18,48],"class_list":["post-4334","post","type-post","status-publish","format-standard","hentry","category-blabla","tag-declarative","tag-kde","tag-kde4","tag-linux","tag-plasma","tag-qml","tag-qt"],"_links":{"self":[{"href":"https:\/\/notmart.org\/blog\/wp-json\/wp\/v2\/posts\/4334","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/notmart.org\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/notmart.org\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/notmart.org\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/notmart.org\/blog\/wp-json\/wp\/v2\/comments?post=4334"}],"version-history":[{"count":0,"href":"https:\/\/notmart.org\/blog\/wp-json\/wp\/v2\/posts\/4334\/revisions"}],"wp:attachment":[{"href":"https:\/\/notmart.org\/blog\/wp-json\/wp\/v2\/media?parent=4334"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/notmart.org\/blog\/wp-json\/wp\/v2\/categories?post=4334"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/notmart.org\/blog\/wp-json\/wp\/v2\/tags?post=4334"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}