<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>dennogumi.org &#187; KDE</title>
	<atom:link href="http://www.dennogumi.org/category/kde/feed" rel="self" type="application/rss+xml" />
	<link>http://www.dennogumi.org</link>
	<description>On the web since 1999</description>
	<lastBuildDate>Fri, 06 Jan 2012 14:56:54 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Screensavers and the KDE Workspaces &#8211; your opinion is needed</title>
		<link>http://www.dennogumi.org/2011/10/screensavers-and-the-kde-workspaces-your-opinion-is-needed</link>
		<comments>http://www.dennogumi.org/2011/10/screensavers-and-the-kde-workspaces-your-opinion-is-needed#comments</comments>
		<pubDate>Sun, 02 Oct 2011 11:26:37 +0000</pubDate>
		<dc:creator>Einar</dc:creator>
				<category><![CDATA[KDE]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[plasma]]></category>
		<category><![CDATA[screensaver]]></category>

		<guid isPermaLink="false">http://www.dennogumi.org/?p=927</guid>
		<description><![CDATA[Recently in the Plasma mailing list, KDE developers have discussed a new screen-locking implementation that could be added to the upcoming 4.8 release of the KDE Workspaces. The first reason to do so was to solve some security constraints of &#8230; <a href="http://www.dennogumi.org/2011/10/screensavers-and-the-kde-workspaces-your-opinion-is-needed">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Recently in the Plasma mailing list, KDE developers have discussed a new screen-locking implementation that could be added to the upcoming 4.8 release of the KDE Workspaces. The first reason to do so was to solve some security constraints of the existing implementation. As an added bonus, screen locking should be also more aestetically pleasing.
<div></div>
<div>There is however a trade-off: such implementation would mean that screensavers that rely on X (also called <i>X screensavers</i>)&nbsp;would not be compatible. The current plan is to have a fallback mechanism if a user has a screen saver configured, and remove the support for X scrensavers entirely by 4.9. It is the intention of the developers to ultimately provide a way to make screensavers with QtQuick (QML) and in a way that they could be shared via GHNS (e.g., places like kde-look.org).&nbsp;</div>
<div></div>
<div>That said, this looks like a large change because existing functionality will change or be removed. Hence, to quote KWin maintainer&#8217;s Martin Graesslin,</div>
<blockquote><p><i>We are not sure how our users would react if we remove the X screen savers and replace them by a new solution. We would like you to contribute and share your opinion. Tell us why you need screen savers and how you would think about if the currently used screen saver could no longer be used.</i></p></blockquote>
<div>And how to gather your opinion? Through a poll. <a href="http://forum.kde.org/viewtopic.php?f=66&amp;t=97102">A poll has been opened in the KDE Community Forums</a> by Martin himself to gather opinions on this upcoming change. Please jump in and let the developers know what you think!</div>
]]></content:encoded>
			<wfw:commentRss>http://www.dennogumi.org/2011/10/screensavers-and-the-kde-workspaces-your-opinion-is-needed/feed</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
		<item>
		<title>PyKDE4: Queries with Nepomuk</title>
		<link>http://www.dennogumi.org/2011/06/pykde4-queries-with-nepomuk</link>
		<comments>http://www.dennogumi.org/2011/06/pykde4-queries-with-nepomuk#comments</comments>
		<pubDate>Wed, 29 Jun 2011 19:27:42 +0000</pubDate>
		<dc:creator>Einar</dc:creator>
				<category><![CDATA[KDE]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[pykde]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://www.dennogumi.org/?p=924</guid>
		<description><![CDATA[In one of my previous blog posts I dealt with tagging files and resources with Nepomuk. But Nepomuk is not only about storing metadata, it is also about retrieving&#160;and interrogating data. Normally, this would mean querying the metadata database directly, &#8230; <a href="http://www.dennogumi.org/2011/06/pykde4-queries-with-nepomuk">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>In one of my previous blog posts I dealt with <a href="http://www.dennogumi.org/2010/10/pykde4-tag-and-annotate-files-using-nepomuk">tagging files and resources with Nepomuk</a>. But Nepomuk is not only about storing metadata, it is also about <i>retrieving</i>&nbsp;and <i>interrogating </i>data. Normally, this would mean querying the metadata database directly, using queries written in SPARQL. But this is not intuitive, can be inefficient (if you do things the wrong way) and error prone (oops, I messed up a parameter!).&nbsp;
<p>Fortunately, the Nepomuk developers have come up with a high level API to query already stored metadata, and today&#8217;s post will deal with querying tags in Nepomuk. As per the past tutorials, the full source code is available <a href="https://projects.kde.org/projects/kde/kdeexamples/repository/revisions/master/changes/bindings/python/nepomuk/nepomuk_tag_query_example.py">in the kdeexamples module</a>.</p>
<p>Let&#8217;s start off with the basic imports:</p>
<pre class="brush: python; title: ; notranslate">
import sys

import PyQt4.QtCore as QtCore

import PyKDE4.kdecore as kdecore
import PyKDE4.kdeui as kdeui
from PyKDE4.kio import KIO
from PyKDE4.nepomuk import Nepomuk
from PyKDE4.soprano import Soprano
</pre>
<p>Then let&#8217;s create a simple class that wil be used for the rest of this exercise:</p>
<pre class="brush: python; title: ; notranslate">
class NepomukTagQueryExample(QtCore.QObject):

    def __init__(self, parent=None):

        super(NepomukTagQueryExample, self).__init__(parent)
</pre>
<p>__init__ is just used to construct the instance, nothing more. The bulk of the work is in the query_tag() function, which we&#8217;ll take a look at in parts.</p>
<pre class="brush: python; title: ; notranslate">
    def query_tag(self, tag):

        &quot;&quot;&quot;Query for a specific tag.&quot;&quot;&quot;

        tag = Nepomuk.Tag(tag)
</pre>
<p>First of all we convert the tag we want to query into a proper Nepomuk.Tag() instance. Of course we should use an already existing tag: even if Nepomuk.Tag() automatically creates new tags, it makes little sense to query for a newly created tag, doesn&#8217;t it?</p>
<p>For our job, we need to use <i>properties</i>&nbsp;which define the terms of our query. As we&#8217;re looking for tags, we&#8217;ll use Soprano.Vocabulary.NAO.hasTag():</p>
<pre class="brush: python; title: ; notranslate">
        soprano_term_uri = Soprano.Vocabulary.NAO.hasTag()
        nepomuk_property = Nepomuk.Types.Property(soprano_term_uri)
</pre>
<p>The first call generates an URI pointing to a specific RDF resource for this specific term, which is then wrapped as a Nepomuk.Types.Property in the second call. While the C++ API docs don&#8217;t show this, I found it to be necessary, or the Python interpreter would raise a TypeError. Notice that this is not the only term we can use: aside for tags, there are a lot of other URIs we can use for querying, <a href="http://api.kde.org/kdesupport-api/kdesupport-apidocs/soprano/html/namespaceSoprano_1_1Vocabulary_1_1NAO.html">listed in the Soprano API docs</a>.</p>
<p>Once we have our property set up, it&#8217;s time to define which kind of query we&#8217;re going to use. In this case, since we want to check for the presence of tags, we use a Nepomuk.Query.ComparisonTerm, which is a query term used to match values of specific properties (in our case, tags):</p>
<pre class="brush: python; title: ; notranslate">
        comparison_term = Nepomuk.Query.ComparisonTerm(nepomuk_property,
                Nepomuk.Query.ResourceTerm(tag))
</pre>
<p>Our tag is wrapped in a ResourceTerm, which is used exactly for the purpose. Now we make the proper query: in this specific case, we want to look up <i>files </i>tagged, so we use a FileQuery. We could also get other items, such as mails (in Akonadi): in that case we could use a a Nepomuk.Query.Query():</p>
<pre class="brush: python; title: ; notranslate">
        query = Nepomuk.Query.FileQuery(comparison_term)
</pre>
<p>Lastly, we want to get some <i>results</i> out of this query. There are different methods, but for this tutorial we&#8217;ll use the tried-and-tested KIO technology:</p>
<pre class="brush: python; title: ; notranslate">
        search_url = query.toSearchUrl()
        search_job = KIO.listDir(kdecore.KUrl(search_url))
        search_job.entries.connect(self.search_slot)
        search_job.result.connect(search_job.entries.disconnect)
</pre>
<p>First we convert the query to a nepomuksearch:// url, which then we pass to KIO.listDir, to list the entries. Unlike <a href="http://www.dennogumi.org/2011/01/pykde4-retrieve-data-using-kio">my previous post on KIO</a>, this job emits entries() every time one is found, so we connect the signal to our search_slot method. We also connect the job&#8217;s result() signal in a way that it will disconnect the job once it&#8217;s over.</p>
<p>Finally, let&#8217;s take a look at the search_slot function:</p>
<pre class="brush: python; title: ; notranslate">
    def search_slot(self, job, data):

        # We may get invalid entries, so skip those
        if not data:
            return

        for item in data:
            print item.stringValue(KIO.UDSEntry.UDS_DISPLAY_NAME)
</pre>
<p>Entries are emitted as <a href="http://api.kde.org/4.x-api/kdelibs-apidocs/kio/html/classKIO_1_1UDSEntry.html">UDSEntries</a>: to get something at least understandable, we turn them into the file name, which is obtained by the stringValue() call using KIO.UDSEntry.UDS_DISPLAY_NAME.</p>
<p>That&#8217;s it. As you can see, it was pretty easy. Of course there&#8217;s more than that. For further reading, take a look at <a href="http://api.kde.org/4.x-api/kdelibs-apidocs/nepomuk/html/namespaceNepomuk_1_1Query.html">Nepomuk&#8217;s Query API docs</a>, and <a href="http://api.kde.org/4.x-api/kdelibs-apidocs/nepomuk/html/examples.html#examples_query">Query Examples</a>. Bear in mind however that to the best of my knowledge, the &#8220;fancy operators&#8221; mentioned there will not work with Python.</p>
<p>Happy Nepomuk querying!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dennogumi.org/2011/06/pykde4-queries-with-nepomuk/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Access multiple Google Calendars from KOrganizer</title>
		<link>http://www.dennogumi.org/2011/06/access-multiple-google-calendars-from-korganizer</link>
		<comments>http://www.dennogumi.org/2011/06/access-multiple-google-calendars-from-korganizer#comments</comments>
		<pubDate>Sat, 11 Jun 2011 10:06:29 +0000</pubDate>
		<dc:creator>Einar</dc:creator>
				<category><![CDATA[KDE]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[akonadi]]></category>
		<category><![CDATA[korganizer]]></category>

		<guid isPermaLink="false">http://www.dennogumi.org/?p=919</guid>
		<description><![CDATA[Recently, a question came up on the KDE Community Forums regarding the use of multiple Google Calendars with KOrganizer. The preferred access up to now has been with googledata Akonadi resource, however that doesn&#8217;t support more than one calendar, and &#8230; <a href="http://www.dennogumi.org/2011/06/access-multiple-google-calendars-from-korganizer">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Recently, a question came up on the KDE Community Forums <a href="http://forum.kde.org/viewtopic.php?f=20&amp;t=91324">regarding the use of multiple Google Calendars with KOrganizer</a>. The preferred access up to now has been with googledata Akonadi resource, however that doesn&#8217;t support more than one calendar, and (at least from my unscientific observation) seems to be rather unmaintained these days.&nbsp;
<div>Luckily, not all&#8217;s lost. Akonadi recently gained the opportunity of accessing CalDAV resources, and Google Calendar also offers a CalDAV interface, hence this is possible.&nbsp;</div>
<div>This post will briefly describe how (thanks go to PIMster krop, which casually mentioned the possibility on IRC and prompted me to investigate).</div>
<p><span id="more-919"></span></p>
<div><b>Notice</b>: I am running trunk (4.7) so I have no idea if the steps posted below are possible in 4.6. Also, this worked for <i>me</i>&nbsp;with my particular setup. YMMV.</div>
<div>First of all, you need to obtain the <i>calendar IDs</i>&nbsp;you want to use. This is done in the web version of Google Organizer, in the settings page of your specific calendar, near the private links: it&#8217;s a string of alphanumeric characters followed by <i>@gmail.com</i>. Copy it in full (even the address part) as you will need it later, and do it for every calendar you want to use.</div>
<div>Next, open KOrganizer, locate the list of the calendars, right click on an emtpy spot and select <i>Add Calendar:</i></div>
<div><i><br /></i></div>
<div style="text-align: center;"><i><img width="299" height="409" src="http://www.dennogumi.org/wp-content/uploads/2011/06/korgtut1.png?cda6c1"/></i></div>
<div><i><br /></i></div>
<div>In the next screen, select &#8220;DAV Groupware resource&#8221;, then a wizard will come up. Fill in username and password (apologies for the language! I haven&#8217;t found a quick way to switch these dialogs to English) and click on Next:</div>
<div></div>
<div></div>
<div style="text-align: center;"><img width="566" height="445" src="http://www.dennogumi.org/wp-content/uploads/2011/06/korgtut2.png?cda6c1"/></div>
<div style="text-align: left;"></div>
<div><i><br /></i></div>
<div>In the following screen, choose <i>Configure the resource manually:</i></div>
<div><i><br /></i></div>
<div style="text-align: center;"><i><img width="566" height="445" src="http://www.dennogumi.org/wp-content/uploads/2011/06/korgtut3.png?cda6c1"/></i></div>
<div><i><br /></i></div>
<div>Click on <i>Finish</i>, but you&#8217;re not finished yet. In fact, we will have to add more stuff here. In the new window, select the display name (here shown as <i>Nome visualizzato</i>)&nbsp; of the calendar, then click on Add (which is translated as <i>Aggiungi</i>&nbsp;in this screen):</div>
<div></div>
<div style="text-align: center;"><img width="446" height="467" src="http://www.dennogumi.org/wp-content/uploads/2011/06/korgtut4.png?cda6c1"/></div>
<div></div>
<div>In the next screen we&#8217;ll have to add what&#8217;s needed for our calendar to work. In <i>Remote URL</i>&nbsp;put <i>https://www.google.com/calendar/dav/YOURCALENDARID/events</i>&nbsp;(https,<b>&nbsp;not</b>&nbsp;http)&nbsp;then put (again) your Google account credentials in the relevant places. Then click on &#8220;Download&#8221; (<i>Scarica</i>&nbsp;here) and you will see (after a while) your Calendar being loaded in the &#8220;Found collections&#8221; pane, with the name you set in Google Calendar. Click OK to save the configuration.&nbsp;</div>
<div></div>
<div style="text-align: center;"><img width="365" height="637" src="http://www.dennogumi.org/wp-content/uploads/2011/06/korgtut5.png?cda6c1"/></div>
<div></div>
<div>This will bring you back to the previous window. For more calendars, repeat the steps (click on Add, insert URL, Download, OK) for all the calendars you have to display.</div>
<div>That&#8217;s it. If you encounter trouble, have a look at ~/.xsession-errors to see whether Akonadi managed to connect and download your existing items correctly. And don&#8217;t forget to <a href="http://bugs.kde.org">file bugs!</a></div>
<div><i><br /></i></div>
<div><i><br /></i></div>
]]></content:encoded>
			<wfw:commentRss>http://www.dennogumi.org/2011/06/access-multiple-google-calendars-from-korganizer/feed</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Taking video snapshots quickly: KDE VLC Snapper</title>
		<link>http://www.dennogumi.org/2011/04/taking-video-snapshots-quickly-kde-vlc-snapper</link>
		<comments>http://www.dennogumi.org/2011/04/taking-video-snapshots-quickly-kde-vlc-snapper#comments</comments>
		<pubDate>Sun, 10 Apr 2011 12:40:26 +0000</pubDate>
		<dc:creator>Einar</dc:creator>
				<category><![CDATA[Anime]]></category>
		<category><![CDATA[KDE]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[vlc]]></category>

		<guid isPermaLink="false">http://www.dennogumi.org/?p=823</guid>
		<description><![CDATA[Some of the oldest readers of this blog are well aware of a certain hobby of mine. Over the years I&#8217;ve always wanted to write more about that, including the stuff I&#8217;m viewing nowadays, but I found a hassle to &#8230; <a href="http://www.dennogumi.org/2011/04/taking-video-snapshots-quickly-kde-vlc-snapper">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Some of the oldest readers of this blog are well aware of <a href="http://www.dennogumi.org/category/anime">a certain hobby of mine</a>. Over the years I&#8217;ve always wanted to write more about that, including the stuff I&#8217;m viewing nowadays, but I found a hassle to collect snapshots from videos / DVDs, selecting them, and so on.&nbsp;
<div>Recently I learnt that VLC has <a href="http://wiki.videolan.org/Python_bindings">some rather complete Python bindings</a>, and I thought, <i>why not make the process automated?</i>&nbsp;Yesterday I had some free time on my hands and a quick session of hacking brought some results already.</div>
<div>As the stuff is somewhat past prototypal stage, I thought I would push somewhere for others to use. &nbsp;Lo and behold, here I present you <i>KDE VLC Snapper</i>.</div>
<div></div>
<div style="text-align: center;"><img width="300" height="313" src="http://www.dennogumi.org/wp-content/uploads/2011/04/vlcsnapper_resized.png?cda6c1"/></div>
<div style="text-align: left;">As you can see, it&#8217;s a minimal dialog: just select your source video file (any file supported by VLC will do), the number of screencaps, the destination directory, and the program will do the rest. Currently it works <i>somewhat</i>&nbsp;OK (see caveats below) and is good enough for my use cases.</div>
<h2>How do I get it?</h2>
<div>Just clone this repository:
<pre class="brush: plain; title: ; notranslate">git clone http://git.gitorious.org/kde-vlc-snapper/kde-vlc-snapper.git</pre>
<p> followed by
<pre class="brush: bash; title: ; notranslate">sudo python setup.py install</pre>
<p> You can then invoke the program with
<pre class="brush: plain; title: ; notranslate">kdevlcsnapper</pre>
</div>
<div></div>
<div><b>Requirements</b>&nbsp;include PyKDE4 (tested on KDE Dev Platform 4.6), numpy (just for its &#8220;linspace&#8221; function, alternatives are welcome) and VLC installed (you don&#8217;t need the bindings, however: I provide a local copy).</div>
<div>What about <b>bugs</b>? Well, currently there are two issues that I&#8217;m unsure on how to fix: the first is a crash on exit, the second is that certain media files make VLC crash in the background when called from the bindings.</div>
<div>In any case, if you try it out, let me know what you think in the comments!</div>
]]></content:encoded>
			<wfw:commentRss>http://www.dennogumi.org/2011/04/taking-video-snapshots-quickly-kde-vlc-snapper/feed</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Improvements to the Git hooks</title>
		<link>http://www.dennogumi.org/2011/01/improvements-to-the-git-hooks</link>
		<comments>http://www.dennogumi.org/2011/01/improvements-to-the-git-hooks#comments</comments>
		<pubDate>Wed, 26 Jan 2011 11:59:04 +0000</pubDate>
		<dc:creator>Einar</dc:creator>
				<category><![CDATA[KDE]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[git]]></category>
		<category><![CDATA[review board]]></category>

		<guid isPermaLink="false">http://www.dennogumi.org/?p=816</guid>
		<description><![CDATA[As you may already know, recently the KDE sysadmins completely overhauled the commit hooks used with the Git infrastructure. Written in Python, they have already brought significant improvements to the current workflows. These hooks include keywords that when specified trigger &#8230; <a href="http://www.dennogumi.org/2011/01/improvements-to-the-git-hooks">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>As you may already know, recently the KDE sysadmins completely overhauled the commit hooks used with the Git infrastructure. Written in Python, they have already brought significant improvements to the current workflows. These hooks include keywords that when specified trigger particular actions: the most used are &nbsp;to CC specific email addresses (CCMAIL), to CC bug reports (CCBUG) or to close bug reports (BUG).</p>
<p>With the adoption of <a href="http://www.reviewboard.org/">Review Board</a>&nbsp;to facilitate code reviews, there were also requests for a REVIEW keyword that could close the review requests without asking the submitters to do so manually (which is slow and not always effective). Since the hooks for Git were written in Python, I thought I could give a hand there.</p>
<p>I looked into the Review Board API, which is a simple REST API: tasks are performed with HTTP GET, POST, or PUT. As I didn&#8217;t want to dive too much into the technicalities, I decided to use a wrapper that would make things easier: <a href="http://code.google.com/p/python-rest-client/" title="Python REST client">python-rest-client</a>. Once that was in place, it was just a matter of adding some sugar to handle replies, errors and logging. All in 78 lines of code.</p>
<p>Now that the &#8220;field tests&#8221; passed with flying colors, I&#8217;m happy to announce that such a hook exists and is operational for KDE&#8217;s Git infrastructure. By using the REVIEW keyword at the start of a line, followed by a number, the hook will notify the Review Board instance and close the request. It will also publish a comment stating the commit&#8217;s SHA1 and the person who did it.</p>
<p>You can take a look at the finished results <a href="http://git.reviewboard.kde.org/r/100270/">in this review request.</a></p>
<p>Credits for this also go to Ben &#8220;bcooksley&#8221; Cooksley for helping with testing and fixes, and Eike &#8220;Sho&#8221; Hein for helpful suggestions.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dennogumi.org/2011/01/improvements-to-the-git-hooks/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>PyKDE4: Retrieve data using KIO</title>
		<link>http://www.dennogumi.org/2011/01/pykde4-retrieve-data-using-kio</link>
		<comments>http://www.dennogumi.org/2011/01/pykde4-retrieve-data-using-kio#comments</comments>
		<pubDate>Sat, 01 Jan 2011 21:09:26 +0000</pubDate>
		<dc:creator>Einar</dc:creator>
				<category><![CDATA[KDE]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[pykde]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://www.dennogumi.org/?p=810</guid>
		<description><![CDATA[One of the greatest strengths of KDE is undoubtedly the asynchronous and network-transparent I/O access, employed by the so-called &#8220;I/O&#8221; slaves, part of the KIO class. If you are developing an application that requires file or network access, those classes &#8230; <a href="http://www.dennogumi.org/2011/01/pykde4-retrieve-data-using-kio">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>One of the greatest strengths of KDE is undoubtedly the asynchronous and network-transparent I/O access, employed by the so-called &#8220;I/O&#8221; slaves, part of the KIO class. If you are developing an application that requires file or network access, those classes make things incredibly simple to do, and they don&#8217;t freeze your GUI when you are in the middle of a process.
<div></div>
<div>In this post I&#8217;ll show how to use KIO to retrieve files from network resources using PyKDE4. The whole example is also available <a href="http://websvn.kde.org/trunk/KDE/kdeexamples/bindings/python/kio/">in the kdeexamples module</a>.</p>
<p>Our first step is to create a simple UI to show how KIO works. It will be a text edit along with two buttons to retrieve and clear items. Here&#8217;s how it looks in Designer (the ui file and its compiled Python version are available at the above link):</p>
<div style="text-align: center;"><img width="400" height="300" title="Example form" src="http://www.dennogumi.org/wp-content/uploads/2011/01/kio_tutorial.png?cda6c1" alt="Image of the example form"/></div>
<p>Once this is done, we turn our attention to code. We start customary imports:</p>
<pre class="brush: python; title: ; notranslate">
#!/usr/bin/env python
import sys
import PyQt4.QtCore as QtCore
import PyQt4.QtGui as QtGui
import PyKDE4.kdecore as kdecore
import PyKDE4.kdeui as kdeui
from PyKDE4.kio import KIO</pre>
<p>These will provide for everything we need. Then we set up our widget:</p>
<pre class="brush: python; title: ; notranslate">

from ui_textbrowser import Ui_Form

class TextArea(QtGui.QWidget, Ui_Form):

    &quot;&quot;&quot;Example class used to show how KIO works.&quot;&quot;&quot;

    def __init__(self, parent=None):

        super(TextArea, self).__init__(parent)
        self.setupUi(self)

        self.downloadButton.clicked.connect(self.start_download)
        self.clearButton.clicked.connect(self.textWidget.clear)
</pre>
<p>Nothing strange in the initializer here. We simply make two connections, one to the clear() slot of the clear button, and the other to start the KIO process, that is the retrieval of the index from www.kde.org. Let&#8217;s take a look at the start_download slot:</p>
<pre class="brush: python; title: ; notranslate">
    def start_download(self):
        kdeui.KMessageBox.information(self.parent(),
                                      &quot;Now data will be retrieved from &quot;
                                      &quot;www.kde.org using KIO&quot;)

        # KIO wants KUrls
        data_url = kdecore.KUrl(&quot;http://www.kde.org&quot;)
        retrieve_job = KIO.storedGet(data_url, KIO.NoReload, KIO.HideProgressInfo)
        retrieve_job.result.connect(self.handle_download)
</pre>
<p>What do we do here? We show a KMessageBox, just for informational purposes. Once this is done, we prepare the actual KIO &nbsp;job. KIO wants KUrls so we first of all wrap the URL we want to download from in that. Then we create the actual job: in this case it&#8217;s KIO.storedGet, that is we retrieve the data in full from our URL and store it in a QByteArray. This is a common use case, but you have to keep in mind that for large files this may be impractical. In such a case, we would be better off using KIO.get followed by a connection to the &#8220;data&#8221; signal, to get the data in chunks.</p>
<p>A KIO job can have many flags: here we set to remove the progress information, so that you won&#8217;t get a notification in the Plasma notifier. For small operations, this should be always present. For longer downloads, it&#8217;s likely not a good idea. More information are available in the <a href="http://api.kde.org/4.5-api/kdelibs-apidocs/kio/html/namespaceKIO.html">KIO namespace page (C++ version).</a></p>
<p>As a last step, we connect the result signal (emitted when the job is complete) to a slot to handle the download. This is what makes KIO useful, because it&#8217;s asynchronous, so you can perform long downloads without blocking the user interface of your program</p>
<p>Lastly, we see the &#8220;handle_download&#8221; slot:</p>
<pre class="brush: python; title: ; notranslate">

    def handle_download(self, job):

        # Bail out in case of errors
        if job.error():
            return

        print &quot;This slot has been called. The job has finished its operation.&quot;

        data = job.data()
        self.textWidget.setPlainText(QtCore.QString(data))
</pre>
<p>This slot&#8217;s signature include a KJob instance, that is what we&#8217;ll use to get the data. In fact, using the data() function we can obtain the QByteArray containing what we have retrieved. Then, in this case we simply use setPlainText to put the downloaded data into the text edit.</p>
<p>What if something goes wrong? We can check for errors if job.error() returns True: in that case we can perform recovery, or simply tell our user that something went wrong. Especially with networked resources, this should always be present in your code.</p>
<p>So that&#8217;s all for now. As you can see, it was pretty simple, and also very effective.</p></div>
]]></content:encoded>
			<wfw:commentRss>http://www.dennogumi.org/2011/01/pykde4-retrieve-data-using-kio/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>PyKDE4: Tag and annotate files using Nepomuk</title>
		<link>http://www.dennogumi.org/2010/10/pykde4-tag-and-annotate-files-using-nepomuk</link>
		<comments>http://www.dennogumi.org/2010/10/pykde4-tag-and-annotate-files-using-nepomuk#comments</comments>
		<pubDate>Tue, 26 Oct 2010 19:37:16 +0000</pubDate>
		<dc:creator>Einar</dc:creator>
				<category><![CDATA[KDE]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[semantic desktop]]></category>

		<guid isPermaLink="false">http://www.dennogumi.org/?p=803</guid>
		<description><![CDATA[Some time has passed since I last blogged&#8230; this was not only due to lack of time but also due to motivation (writing long texts can be discouraging at times). In any case, I&#8217;d like to rectify for that. In &#8230; <a href="http://www.dennogumi.org/2010/10/pykde4-tag-and-annotate-files-using-nepomuk">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Some time has passed since I last blogged&#8230; this was not only due to lack of time but also due to motivation (writing long texts can be discouraging at times). In any case, I&#8217;d like to rectify for that. In this post, I&#8217;ll talk about Nepomuk, and in particular how to use it to tag and annotate arbitrary files using its API in PyKDE4.</p>
<p>Before starting, let me say that creating this tutorial was only possible thanks to the help of Sebastian Trueg, who helped me by pointing out some mistakes I was doing.</p>
<p>The example here is not showing the extra methods to set up a KApplication, etc.:  the full code for this tutorial<a href="http://websvn.kde.org/trunk/KDE/kdeexamples/bindings/python/nepomuk/" title="WebSVN link"> is available in the kdeexamples module</a>. </p>
<p>Let&#8217;s start with the basics.</p>
<pre class="brush: python; title: ; notranslate">import sys
from PyQt4 import QtCore
from PyKDE4 import kdecore
from PyKDE4 import kdeui
from PyKDE4.nepomuk import Nepomuk</pre>
<p>This will import all the bits needed to test our experiment. As a second step, we&#8217;ll create a dummy empty file.</p>
<pre class="brush: python; title: ; notranslate">dummy_file = open(&quot;dummy.txt&quot;, &quot;w&quot;)
dummy_file.write(&quot;Some text\n&quot;)
dummy_file.close()</pre>
<p>Or, if we have Python 2.6+ (as pointed out in the comments):</p>
<pre class="brush: python; title: ; notranslate">
with open(&quot;dummy.txt&quot;, &quot;w&quot;) as handle:
    handle.write(&quot;Some text\n&quot;)
</pre>
<p>Now that we have our file, it&#8217;s time to do something productive with it. But first and foremost, we have to ensure that Nepomuk is running. To do so, we make a simple check (EDIT: fixed the syntax):</p>
<pre class="brush: python; title: ; notranslate">result = Nepomuk.ResourceManager.instance().init()
if result != 0:
     return</pre>
<p>Neomuk.instance().init() must return 0 if Nepomuk is properly set up. Once this is taken care of, we can manipulate the semantic information of our file. Thus, Nepomuk needs to be made aware of it: this is done by creating a <em>resource</em> that points to the actual file:</p>
<pre class="brush: python; title: ; notranslate">file_info = QtCore.QFileInfo(&quot;dummy.txt&quot;)
absolute_path = file_info.absoluteFilePath()
resource = Nepomuk.Resource(kdecore.KUrl(absolute_path)</pre>
<p>Notice that we <strong>must</strong> use an absolute file path, or the resource will be not created properly and although no errors will happen when tagging, changes will not be made. Let&#8217;s now create a tag, which is done by simply constructing a Nepomuk.Tag instance:</p>
<pre class="brush: python; title: ; notranslate">tag = Nepomuk.Tag(&quot;test_example&quot;)
tag.setLabel(&quot;test_example&quot;)</pre>
<p>In the first line we create the tag, then we associate it with a label, so that it will be displayed in applications such as Dolphin. The nice thing is that if the Tag already exists, it will be recycled: no duplicates will occur. A simple call to addTag to the resource we created earlier will now tag it:</p>
<pre class="brush: python; title: ; notranslate">resource.addTag(tag)</pre>
<p>We can also add comments that can show up in Dolphin as well by using the setDescription method:</p>
<pre class="brush: python; title: ; notranslate">resource.setDescription(&quot;This is an example comment.&quot;)</pre>
<p>What if we want to remove tags and descriptions? To wipe them all, we can use the remove() method of the Resource, otherwise we can strip elements by using removeProperty along with the tagUri() or descriptionUri() methods of the resource:</p>
<pre class="brush: python; title: ; notranslate">resource.remove() # strip everything
resource.removeProperty(resource.descriptionUri()) # remove comment
resource.removeProperty(resource.tagUri()) # remove tags
</pre>
<p>That&#8217;s it. As you can see, adding semantic information from PyKDE4 isn&#8217;t that hard. Sooner or later I&#8217;ll try my hand at queries and report back my findings.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dennogumi.org/2010/10/pykde4-tag-and-annotate-files-using-nepomuk/feed</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>What this might ever be?</title>
		<link>http://www.dennogumi.org/2010/07/what-this-might-ever-be</link>
		<comments>http://www.dennogumi.org/2010/07/what-this-might-ever-be#comments</comments>
		<pubDate>Tue, 27 Jul 2010 22:41:14 +0000</pubDate>
		<dc:creator>Einar</dc:creator>
				<category><![CDATA[KDE]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://www.dennogumi.org/?p=790</guid>
		<description><![CDATA[The rest is up to you to figure out.]]></description>
			<content:encoded><![CDATA[<p align="center"><img src="http://imagebin.ca/img/V-7GlD.png" /></p>
<p align="left">The rest is up to you to figure out.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dennogumi.org/2010/07/what-this-might-ever-be/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>OCS and KDE Forums &#8211; work continues</title>
		<link>http://www.dennogumi.org/2010/07/ocs-and-kde-forums-work-continues</link>
		<comments>http://www.dennogumi.org/2010/07/ocs-and-kde-forums-work-continues#comments</comments>
		<pubDate>Sun, 25 Jul 2010 18:49:22 +0000</pubDate>
		<dc:creator>Einar</dc:creator>
				<category><![CDATA[KDE]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[OCS]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://www.dennogumi.org/?p=787</guid>
		<description><![CDATA[With my last entry, I announced the start of the work for an OCS library for the KDE Community Forums. Today I&#8217;d like to blog again about the recent developments. First of all, now there isn&#8217;t one, but two Python &#8230; <a href="http://www.dennogumi.org/2010/07/ocs-and-kde-forums-work-continues">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>With my last entry, I announced the start of the work for an OCS library for the KDE Community Forums. Today I&#8217;d like to blog again about the recent developments. </p>
<p>First of all, now there isn&#8217;t one, but <em>two</em> Python modules:</p>
<ul>
<li><em>ocslib, </em> a pure Python module that can be used to interface with OCS-based forum systems;</li>
<li><em>ocslibkde</em>, a PyKDE4 based module that can be used to interface with OCS-based forum system in KDE applications.</li>
</ul>
<p>Currently ocslib supports reading and posting, while ocslibkde only reading (as of now). Both can be retrieved from the <a href="http://gitorious.org/kde-forum-mods" title="Gitorious.org repository">kde-forum-mods repository</a> under the <em>ocs-client</em> subdirectory. The Python lib needs unit-testing, then I&#8217;ll be able to push a tarball soon for people to test (but you can always check out the Git repository). With regards to the PyKDE4 library, I plan on making a proof-of-concept plasmoid soon that shows how to use the API.</p>
<p>Speaking of API, here are some examples using ocslib:</p>
</p>
<pre class="brush: python; title: ; notranslate">
&gt;&gt;&gt; from ocslib import service# Connect to OCS
&gt;&gt;&gt; ocs_service = ocslib.service.OCService(&quot;http://www.example.com&quot;)
#Retrieve all forums
&gt;&gt;&gt; forums = ocs_service.list_forums()
# Elements have attributes for name, posts, etc.
&gt;&gt;&gt; print forums[0].name
&quot;Test forum&quot;
#Retrieve threads for forum 15
&gt;&gt;&gt; threads = ocs_service.list_forum_threads(forum_id=15)
# Retrieve thread 8945 from forum 15
&gt;&gt;&gt; messages = ocs_service.show_thread(forum_id=15, topic_id=8945)
&gt;&gt;&gt; print messages[0].text
&quot;Hello world!
#Post to a forum - requires authentication
&gt;&gt;&gt; ocs_service = service.OCService(&quot;http://www.example.com&quot;, username=&quot;foo&quot;, password=&quot;bar&quot;)
&gt;&gt;&gt; message = &quot;Hello, KDE people!&quot;
&gt;&gt;&gt; subject = &quot;Test message&quot;
&gt;&gt;&gt; ocs_service.post(forum_id=15, subject=subject, message=message)
True # Return code of operation
</pre>
<p>Feedback (especially on the API) welcome!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dennogumi.org/2010/07/ocs-and-kde-forums-work-continues/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Open Collaboration Services and KDE Forums</title>
		<link>http://www.dennogumi.org/2010/07/open-collaboration-services-and-kde-forums</link>
		<comments>http://www.dennogumi.org/2010/07/open-collaboration-services-and-kde-forums#comments</comments>
		<pubDate>Sun, 18 Jul 2010 10:00:39 +0000</pubDate>
		<dc:creator>Einar</dc:creator>
				<category><![CDATA[KDE]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[forums]]></category>
		<category><![CDATA[OCS]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://www.dennogumi.org/?p=785</guid>
		<description><![CDATA[For KDE developers, web-based forums are often uncommon workflows. Indeed, for communication among developers mailing lists are much better tools, especially since you can handle everything inside a client (most of the time), compared to forums where you have to &#8230; <a href="http://www.dennogumi.org/2010/07/open-collaboration-services-and-kde-forums">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>For KDE developers, web-based forums are often uncommon workflows. Indeed, for communication among developers mailing lists are much better tools, especially since you can handle everything inside a client (most of the time), compared to forums where you have to use a web browser. The ways of reading, replying and interacting with posters are dramatically different. And that is why some developers find themselves uncomfortable with the <a href="http://forum.kde.org" title="KDE Community Forums">KDE Community Forums</a>.</p>
<p>A dedicated application would be usually much better than a browser, because you can work around the intrinsic limitations of the browser itself. The problem is that you can&#8217;t really access a forum with anything else than a browser. That is, it <em>used to be</em> like this, but now things are changing.</p>
<p>In the past months fellow administrator bcooksley has been working quite hard implementing the <a href="http://freedesktop.org/wiki/Specifications/open-collaboration-services" title="OCS specification">Open Collaboration Services (OCS) specification</a> in the KDE Community Forums. For the uninformed, it&#8217;s the same API that powers <a href="http://opendesktop.org" title="OpenDesktop.org">OpenDesktop.org</a> and related web pages. This means that you could access the forum contents programmatically using a REST API and parsing the XML that is returned by the service. </p>
<p>Unfortunately, bcooksley had no time to implement a client that would make use of this newly-made service.</p>
<p>That&#8217;s where I stepped in. This morning <a href="http://gitorious.org/kde-forum-mods/phpbb/commit/471f6f7b4135d004be040c2bbd552b12451badfe" title="OCS commit">I committed in the kde-forum-mods repository</a> the first implementation of a backend to access the forums&#8217; OCS service. Currently it&#8217;s extremely basic &#8211; just a few classes to wrap the XML responses into decent data representation, and a basic class to perform reading requests: that means that technically it is possible to request forum listings, thread listing, and posts. I&#8217;m still working on the ability of replying and posting messages.</p>
<p>Being a Pythonista, the backend is written entirely in Python: currently it uses the standard library plus <a href="http://labix.org/python-dateutil" title="Python-dateutil"><em>dateutil</em></a> and <a href="http://codespeak.net/lxml/" title="lxml home page"><em>lxml</em></a> to do its bidding, but the next steps would be to turn it into a PyKDE4 library to access all the KDE related goodness (hello, KIO!). Bear in mind that currently there is no application using this: I merely completed (part of) the backend. </p>
<p>If you&#8217;re interested, the code can be found on gitorious.org, in the <em>ocs-client</em> directory, branch <em>experimental</em>,  inside the <a href="http://gitorious.org/kde-forum-mods" title="Gitorious.org repository">kde-forum-mods repository</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dennogumi.org/2010/07/open-collaboration-services-and-kde-forums/feed</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
	</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Minified using xcache (Feed is rejected)
Page Caching using xcache
Database Caching using xcache
Object Caching 771/873 objects using xcache

Served from: www.dennogumi.org @ 2012-02-05 04:59:42 -->
