<?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>The Evil Blog</title>
	<atom:link href="http://www.grillbar.org/wordpress/?feed=rss2" rel="self" type="application/rss+xml" />
	<link>http://www.grillbar.org/wordpress</link>
	<description>the infernal output of Mikkel Kamstrup Erlandsen</description>
	<lastBuildDate>Wed, 28 Mar 2012 20:57:00 +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>wutsamakallit? DPipe?</title>
		<link>http://www.grillbar.org/wordpress/?p=618</link>
		<comments>http://www.grillbar.org/wordpress/?p=618#comments</comments>
		<pubDate>Wed, 28 Mar 2012 20:57:00 +0000</pubDate>
		<dc:creator>kamstrup</dc:creator>
				<category><![CDATA[Gnome]]></category>
		<category><![CDATA[Hacking]]></category>
		<category><![CDATA[dbus]]></category>
		<category><![CDATA[ipc]]></category>

		<guid isPermaLink="false">http://www.grillbar.org/wordpress/?p=618</guid>
		<description><![CDATA[Recently I&#8217;ve been pondering different methods a parent process can control a child process (or generally any old process, via a pipe). There are many interesting ways one can do this. On the most basic level there is the classical chaining of Unix commands connected via pipes. This works when you are streaming raw data. [...]]]></description>
			<content:encoded><![CDATA[<p>Recently I&#8217;ve been pondering different methods a parent process can control a child process (or generally any old process, via a pipe). There are many interesting ways one can do this.</p>
<p>On the most basic level there is the classical chaining of Unix commands connected via pipes. This works when you are streaming raw data. That&#8217;s not what I am interested in, I am considering the case where the parent process uses the child as some helper and the parent sends the child a stream of commands.</p>
<p>There are two common approaches these days.</p>
<ol>
<li>Invent an ad-hoc protocol and the parent communicates to the child via that. This will be super effective (if you are clever about it), but require some work on your behalf.</li>
<li>Totally decouple parent and child and use the DBus session bus between the two.</li>
</ol>
<p>On the free desktop there seems to be a trend towards 2. Probably because it is just some damn convenient! <img src='http://www.grillbar.org/wordpress/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<p>The DBus approach comes with quite some attachments though.</p>
<ul>
<li>You now have a public API on the bus (you may <em>tell</em> people that it is private, but that is not always gonna be respected)</li>
<li>You&#8217;re adding round trips to the bus daemon</li>
<li>Other processes can eavesdrop</li>
<li>You may really want to send quite a lot of commands</li>
</ul>
<p>As it happens, round trips and bus spamming is very detrimental to the entire desktop (it causes priority inversion and general lagginess as was described in the document located <a href="http://shorestreet.com/sites/shorestreet.com/files/dbus-perf-report-0.9.9.pdf">here</a>, which unfortunately has gone 404(??)). So you definitely want to do that carefully.</p>
<p>Enter Teh Hack. It solves all of the listed problems, and gives you the nice API of GDBus. The idea is to talk DBus, but over a <em>pipe</em>, not a socket. Let&#8217;s call the idea DPipe to have a word for it. You might be surprised to hear that this Just Works &#8482;. At least when using the awesome GDBus implementation. I&#8217;ve pasted a complete example, in Vala, below.</p>
<p>It&#8217;s a bit hackish, as it is, but the idea is simple enough. Create a GIOStream with the two pipe ends. Create a new GDBusConnection with this GIOStream. The parent must be careful to only write to the connection and the child must be careful to only read. But I can trust you on that, right?</p>

<div class="wp_syntax"><div class="code"><pre class="vala" style="font-family:monospace;"><span style="color: #008080; font-style: italic;">/* 
 * Hack: Using the stdin/stdout pipes for DBusConnections
 * Compile with: valac --pkg gio-2.0 --pkg gio-unix-2.0 dpipe.vala
 * Run with: ./dpipe | ./dpipe client
 */</span>
&nbsp;
<span style="color: #0600FF;">namespace</span> DPipe <span style="color: #000000;">&#123;</span>
&nbsp;
  <span style="color: #008080; font-style: italic;">/* We need a custom IOStream subclass, as IOStream is abstract */</span>
  <span style="color: #FF0000;">class</span> Stream <span style="color: #008000;">:</span> IOStream <span style="color: #000000;">&#123;</span>
&nbsp;
    <span style="color: #0600FF;">private</span> InputStream _in<span style="color: #008000;">;</span>
    <span style="color: #0600FF;">private</span> OutputStream _out<span style="color: #008000;">;</span>
&nbsp;
    <span style="color: #0600FF;">public</span> <span style="color: #0600FF;">override</span> InputStream input_stream <span style="color: #000000;">&#123;</span> <span style="color: #0600FF;">get</span> <span style="color: #000000;">&#123;</span> <span style="color: #0600FF;">return</span> _in<span style="color: #008000;">;</span> <span style="color: #000000;">&#125;</span> <span style="color: #000000;">&#125;</span>
    <span style="color: #0600FF;">public</span> <span style="color: #0600FF;">override</span> OutputStream output_stream <span style="color: #000000;">&#123;</span> <span style="color: #0600FF;">get</span> <span style="color: #000000;">&#123;</span> <span style="color: #0600FF;">return</span> _out<span style="color: #008000;">;</span> <span style="color: #000000;">&#125;</span> <span style="color: #000000;">&#125;</span>
&nbsp;
    <span style="color: #0600FF;">public</span> Stream <span style="color: #000000;">&#40;</span>InputStream input, OutputStream output<span style="color: #000000;">&#41;</span>
    <span style="color: #000000;">&#123;</span>
      _in <span style="color: #008000;">=</span> input<span style="color: #008000;">;</span>
      _out <span style="color: #008000;">=</span> output<span style="color: #008000;">;</span>
    <span style="color: #000000;">&#125;</span>
  <span style="color: #000000;">&#125;</span>
&nbsp;
  <span style="color: #FF0000;">int</span> main <span style="color: #000000;">&#40;</span><span style="color: #FF0000;">string</span><span style="color: #000000;">&#91;</span><span style="color: #000000;">&#93;</span> args<span style="color: #000000;">&#41;</span>
  <span style="color: #000000;">&#123;</span>
    Stream stream <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> Stream <span style="color: #000000;">&#40;</span><span style="color: #008000;">new</span> UnixInputStream <span style="color: #000000;">&#40;</span>stdin.<span style="color: #0000FF;">fileno</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>, <span style="color: #0600FF;">false</span><span style="color: #000000;">&#41;</span>,
                                <span style="color: #008000;">new</span> UnixOutputStream <span style="color: #000000;">&#40;</span>stdout.<span style="color: #0000FF;">fileno</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>, <span style="color: #0600FF;">false</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
    DBusConnection conn <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> DBusConnection.<span style="color: #0000FF;">sync</span> <span style="color: #000000;">&#40;</span>stream,
                                                   <span style="color: #666666;">&quot;fixme&quot;</span>,
                                                   DBusConnectionFlags.<span style="color: #0000FF;">NONE</span>,
                                                   <span style="color: #0600FF;">null</span>,
                                                   <span style="color: #0600FF;">null</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
    <span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span>args.<span style="color: #0000FF;">length</span> <span style="color: #008000;">&gt;</span> <span style="color: #FF0000;">1</span> <span style="color: #008000;">&amp;&amp;</span> args<span style="color: #000000;">&#91;</span><span style="color: #FF0000;">1</span><span style="color: #000000;">&#93;</span> <span style="color: #008000;">==</span> <span style="color: #666666;">&quot;client&quot;</span><span style="color: #000000;">&#41;</span>
    <span style="color: #000000;">&#123;</span>
      <span style="color: #008080; font-style: italic;">/* Beware: The filter handler runs in the GDBus worker thread */</span>
      conn.<span style="color: #0000FF;">add_filter</span> <span style="color: #000000;">&#40;</span> <span style="color: #000000;">&#40;</span>conn, msg, incoming<span style="color: #000000;">&#41;</span> <span style="color: #008000;">=&amp;</span>gt<span style="color: #008000;">;</span> <span style="color: #000000;">&#123;</span>
        print <span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;Got message on %s: %s<span style="color: #008080; font-weight: bold;">\n</span>&quot;</span>, msg.<span style="color: #0000FF;">get_interface</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>, msg.<span style="color: #0000FF;">get_body</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>.<span style="color: #0000FF;">print</span><span style="color: #000000;">&#40;</span><span style="color: #0600FF;">false</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #0600FF;">return</span> msg<span style="color: #008000;">;</span>
      <span style="color: #000000;">&#125;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
    <span style="color: #000000;">&#125;</span>
    <span style="color: #0600FF;">else</span>
    <span style="color: #000000;">&#123;</span>
      conn.<span style="color: #0000FF;">emit_signal</span> <span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;target.name&quot;</span>,
                        <span style="color: #666666;">&quot;/target/path&quot;</span>,
                        <span style="color: #666666;">&quot;target.iface&quot;</span>,
                        <span style="color: #666666;">&quot;SignalName&quot;</span>,
                        <span style="color: #008000;">new</span> Variant <span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;(s)&quot;</span>, <span style="color: #666666;">&quot;Hello dpipe&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
    <span style="color: #000000;">&#125;</span>
&nbsp;
    MainLoop mainloop <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> MainLoop <span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
    Timeout.<span style="color: #0000FF;">add_seconds</span> <span style="color: #000000;">&#40;</span><span style="color: #FF0000;">1</span>, <span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #008000;">=&gt;</span> <span style="color: #000000;">&#123;</span> mainloop.<span style="color: #0000FF;">quit</span> <span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span> <span style="color: #0600FF;">return</span> false<span style="color: #008000;">;</span> <span style="color: #000000;">&#125;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
    mainloop.<span style="color: #0000FF;">run</span> <span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
    <span style="color: #0600FF;">return</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">;</span>
  <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>But please don&#8217;t got hating on me if this blows up on you. I really haven&#8217;t played with it a whole lot.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.grillbar.org/wordpress/?feed=rss2&#038;p=618</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>Lenses in Unity-5.0. Porting and New Features</title>
		<link>http://www.grillbar.org/wordpress/?p=585</link>
		<comments>http://www.grillbar.org/wordpress/?p=585#comments</comments>
		<pubDate>Wed, 18 Jan 2012 11:31:18 +0000</pubDate>
		<dc:creator>kamstrup</dc:creator>
				<category><![CDATA[desktop search]]></category>
		<category><![CDATA[Hacking]]></category>
		<category><![CDATA[unity]]></category>
		<category><![CDATA[canonical]]></category>
		<category><![CDATA[dee]]></category>
		<category><![CDATA[libunity]]></category>
		<category><![CDATA[ubuntu]]></category>

		<guid isPermaLink="false">http://www.grillbar.org/wordpress/?p=585</guid>
		<description><![CDATA[Hi there. More gibberish about Unity lenses. You&#8217;d think that I don&#8217;t experience much else in life, huh? I am, believe you me, but for some reason it is so much easier to blog about technical matters Now, as some have picked up, the Unity Lenses API has changed slightly in Unity-5.0 (the version that&#8217;ll [...]]]></description>
			<content:encoded><![CDATA[<p>Hi there. More gibberish about Unity lenses. You&#8217;d think that I don&#8217;t experience much else in life, huh? I am, believe you me, but for some reason it is so much easier to blog about technical matters <img src='http://www.grillbar.org/wordpress/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<p>Now, as some have picked up, the Unity Lenses API has changed slightly in Unity-5.0 (the version that&#8217;ll be in Ubuntu 12.04). First of all; <em>sorry!</em> As I&#8217;ll outline why we did this you&#8217;ll hopefully learn to appreciate it. Flames and pitchforks can go in my general direction if not. And if you still have hate to spare after that you can direct it at <a title="Michal Hruby's Google+ page" href="https://www.google.com/url?sa=t&amp;rct=j&amp;q=&amp;esrc=s&amp;source=web&amp;cd=1&amp;ved=0CCoQ9gkwAA&amp;url=https%3A%2F%2Fplus.google.com%2F101899139221851198594&amp;ei=f30WT8qKCoOAtQbB_qhP&amp;usg=AFQjCNHwfTGTrbggfzBhvWUpou2QnMnApw&amp;sig2=jbMv1Zm73JD_dvje-hR75Q&amp;cad=rja">Michal</a> <img src='http://www.grillbar.org/wordpress/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' />  Before we start, do note that <a title="Unity-5.0 API overview" href="http://developer.ubuntu.com/api/ubuntu-12.04/python/Unity-5.0.html">the Unity-5.0 API overview on developer.ubuntu.com</a> is already updated, and <a href="https://wiki.ubuntu.com/Unity/Lenses">Michal is updating the wiki documentation</a>.</p>
<p>I&#8217;ll take this on in the form of a case study; updating <a href="http://www.grillbar.org/wordpress/?p=568">my <em>unity-lens-bliss</em></a>. This is a Python lens, which makes for a good example &#8211; identical changes apply to lenses written in Vala or C. Let&#8217;s roll.</p>
<h3>Porting unity-lens-bliss to Unity-5.0</h3>
<p>We introduced a new signal <em>&#8220;search-changed&#8221;</em> on the <em>Unity.Scope</em> class. The old property notification (on <em>&#8220;notify::active-search&#8221;</em> and <em>&#8220;notify::active-global-search&#8221;</em>) is still not available anymore, as the properties has been removed. The reason for the new signal was that the property notification scheme was racy in some subtle ways that would require some tricky GObject magic in the scopes to work correctly in all circumstances. The race manifested itself in lenses that dispatched the property change notification to an async handler of some sort. If the scope received another search while the async handler was still running we&#8217;d have re-entrancy issues in the async handler. This was the reason why you might have seen some mysterious calls to <em>self.freeze_notify()</em> and <em>self.thaw_notify()</em>. It seemed that no one really understood this, and I think we can all agree that having to know the intricacies of GObject property notifications is not a nice requirement for an API that should be simple.</p>
<p>For unity-lens-bliss, what was before:</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #008000;">self</span>.<span style="color: black;">connect</span> <span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;notify::active-search&quot;</span>, <span style="color: #008000;">self</span>._on_search_changed<span style="color: black;">&#41;</span>
<span style="color: #008000;">self</span>.<span style="color: black;">connect</span> <span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;notify::active-global-search&quot;</span>, <span style="color: #008000;">self</span>._on_global_search_changed<span style="color: black;">&#41;</span></pre></div></div>

<p>Should now become:</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #008000;">self</span>.<span style="color: black;">connect</span> <span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;search-changed&quot;</span>, <span style="color: #008000;">self</span>._on_search_changed<span style="color: black;">&#41;</span></pre></div></div>

<p>The callback  <em>_on_search_changed()</em> changes signature from:</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">def</span> _on_search_changed <span style="color: black;">&#40;</span><span style="color: #008000;">self</span>, scope, param_spec<span style="color: black;">&#41;</span>:</pre></div></div>

<p>to</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">def</span> _on_search_changed <span style="color: black;">&#40;</span><span style="color: #008000;">self</span>, scope, search, search_type, cancellable<span style="color: black;">&#41;</span>:</pre></div></div>

<p>The <em>search</em> parameter is a <em>LensSearch</em> instance. The <em>LensSearch</em> class has grown some new public properties. Of particular interest is the <em>&#8220;results-model&#8221;</em> property. This property will hold the correct model depending on whether it is a global- or in-scope search. You can figure out what kind of search this is by looking at the <em>search_type</em> parameter which is an enumeration <em>Unity.SearchType</em> with values <em>Unity.SearchType.GLOBAL</em> and <em>Unity.SearchType.DEFAULT</em> for global- and in-scope searches respectively.</p>
<p>So the implementation of the <em>_on_search_changed()</em> callback changes from:</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">def</span> _on_search_changed <span style="color: black;">&#40;</span><span style="color: #008000;">self</span>, scope, search, search_type, cancellable<span style="color: black;">&#41;</span>:
	search = <span style="color: #008000;">self</span>.<span style="color: black;">get_search_string</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
	results = scope.<span style="color: black;">props</span>.<span style="color: black;">results_model</span>
&nbsp;
	<span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">&quot;Search changed to: '%s'&quot;</span> <span style="color: #66cc66;">%</span> search
&nbsp;
	<span style="color: #008000;">self</span>._update_results_model <span style="color: black;">&#40;</span>search, results<span style="color: black;">&#41;</span>
	<span style="color: #008000;">self</span>.<span style="color: black;">search_finished</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span></pre></div></div>

<p>to</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">def</span> _on_search_changed <span style="color: black;">&#40;</span><span style="color: #008000;">self</span>, scope, search, search_type, cancellable<span style="color: black;">&#41;</span>:
	search_string = search.<span style="color: black;">props</span>.<span style="color: black;">search_string</span>
	results = search.<span style="color: black;">props</span>.<span style="color: black;">results_model</span>
&nbsp;
	<span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">&quot;Search changed to: '%s'&quot;</span> <span style="color: #66cc66;">%</span> search_string
&nbsp;
	<span style="color: #008000;">self</span>._update_results_model <span style="color: black;">&#40;</span>search_string, results<span style="color: black;">&#41;</span>
	search.<span style="color: black;">emit</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;finished&quot;</span><span style="color: black;">&#41;</span></pre></div></div>

<p>And this is all there is to it! Bliss will work fine in Unity-5.0 with these changes.</p>
<p>We haven&#8217;t yet mentioned the new parameter <em>cancellable</em>. Unsurprisingly (hopefully <img src='http://www.grillbar.org/wordpress/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> ) this is a <em>Gio.Cancellable</em> instance. If you&#8217;re writing a fully synchronous lens (like bliss is) it wont be of interest to you, but if you&#8217;re dispatching to async methods from your <em>&#8220;search-changed&#8221;</em> handler (like fx. both <em>unity-lens-files</em> and <em>unity-lens-applications</em> does) then read the next section carefully.</p>
<h3>Concurrency and Cancellation</h3>
<p>Before we get too deep into this, let&#8217;s make it clear what I mean by <em>asynchronous</em>. A method being async means that GLib will spin the mainloop while waiting for the method to return. This means that your app/daemon will continue to handle events (in particular requests from Unity to update the search) while your methods are running. Why would one want to use async methods if it is so complicated? Good question. If you&#8217;re just writing a simple scope or lens then chances are that it may not be worth it. But if you go beyond &#8220;simple&#8221; then it may matter.</p>
<p>Let&#8217;s imagine a slightly more complex scope. Maybe something that puts webapps inside the applications lens. The listing is done by first asynchronously querying a web service to list the apps and then asynchronously querying Zeitgeist to sort by popularity. If we didn&#8217;t do the web- and Zeitgeist queries asynchronously then the scope would block all requests while any queries were running. This would mean slower responses if the user changes the query under you (which is very likely when we&#8217;re talking live searching here), and also you&#8217;d run the chance of showing &#8220;outdated&#8221; results and doing work that you&#8217;ll discard immediately anyway. What you want is to be told in the middle of everything that <em>&#8220;hey, there&#8217;s a new query; stop what you&#8217;re doing and do this in stead!&#8221;</em>.</p>
<p>An alternative case where&#8217;d you want async searching is if you wrote a scope that was living <em>inside</em> an application. There&#8217;s really no reason why this wouldn&#8217;t work. And it circumvents some of the intricacies of sharing a datastore between a scope daemon and an app. Anyways, back to the example with the web apps. In simplified form it would look something like this:</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">def</span> _on_search_changed <span style="color: black;">&#40;</span><span style="color: #008000;">self</span>, scope, search, search_type, cancellable<span style="color: black;">&#41;</span>:
	<span style="color: #808080; font-style: italic;"># Dispatch an async call with callback _on_web_apps_received()</span>
	<span style="color: #008000;">self</span>._query_web_service_async <span style="color: black;">&#40;</span>search, <span style="color: #008000;">self</span>._on_web_apps_received<span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">def</span> _on_web_apps_received <span style="color: black;">&#40;</span><span style="color: #008000;">self</span>, search, list_of_webapps<span style="color: black;">&#41;</span>:
	<span style="color: #808080; font-style: italic;"># Web apps listed by remote server.</span>
	<span style="color: #808080; font-style: italic;"># Now sort them async with zeitgeist, with callback _on_webapps_sorted_received()</span>
	<span style="color: #008000;">self</span>._sort_webaps_with_zeitgeist_async <span style="color: black;">&#40;</span>list_of_webapps, search, <span style="color: #008000;">self</span>._on_webapps_sorted_received<span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">def</span> _on_webapps_sorted_received <span style="color: black;">&#40;</span><span style="color: #008000;">self</span>, search, sorted_list_of_webapps<span style="color: black;">&#41;</span>:
	<span style="color: #808080; font-style: italic;"># We now have the web apps sorted by popularity,</span>
	<span style="color: #808080; font-style: italic;"># add them to the results model</span>
&nbsp;
	results_model = search.<span style="color: black;">props</span>.<span style="color: black;">results_model</span>
	results_model.<span style="color: black;">clear</span> <span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
&nbsp;
	<span style="color: #ff7700;font-weight:bold;">for</span> app <span style="color: #ff7700;font-weight:bold;">in</span> sorted_list_of_webapps:
		results_model.<span style="color: black;">append</span><span style="color: black;">&#40;</span>...<span style="color: black;">&#41;</span>
&nbsp;
	search.<span style="color: black;">finished</span> <span style="color: black;">&#40;</span><span style="color: black;">&#41;</span></pre></div></div>

<p>If you did something like this in the Unity-4.0 API then have to deal with all the re-entrancy, cancellation, and concurrent search handling yourself. Probably by elaborate application of <em>freeze/thaw_notify()</em> and <em>Gio.Cancellables</em>. Tricky stuff. In Unity-5.0 this is a breeze! Contrary to the old way with <em>&#8220;notify::active-search&#8221;</em> libunity goes out of its way to make the <em>&#8220;search-changed&#8221;</em> signal nice to use for scope authors (and no, it wouldn&#8217;t be technically possible to do the same with the old property notification system).</p>
<p>Firstly, libunity wont call you again before you&#8217;ve called <em>search.finished()</em>. So we&#8217;re re-entrancy safe in the example already. What&#8217;s more &#8211; libunity will cancel the <em>cancellable</em> parameter when you get a new query. So sprinkling some <em>if cancellable.is_cancelled(): return</em> lines around will make sure that you don&#8217;t do work in vain. We could fx. insert one  right after we receive the results from the web service. Note that you don&#8217;t have to call <em>search.finished()</em> if you have been cancelled (libunity will ignore it if you do):</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">def</span> _on_search_changed <span style="color: black;">&#40;</span><span style="color: #008000;">self</span>, scope, search, search_type, cancellable<span style="color: black;">&#41;</span>:
	<span style="color: #008000;">self</span>._query_web_service_async <span style="color: black;">&#40;</span>search, cancellable, <span style="color: #008000;">self</span>._on_web_apps_received<span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">def</span> _on_web_apps_received <span style="color: black;">&#40;</span><span style="color: #008000;">self</span>, search, cancellable, list_of_webapps<span style="color: black;">&#41;</span>:
	<span style="color: #808080; font-style: italic;"># NOTE: The new parameter        ^^^^^^^^^^^</span>
	<span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: black;">&#40;</span>cancellable.<span style="color: black;">is_cancelled</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>: <span style="color: #ff7700;font-weight:bold;">return</span>
	<span style="color: #008000;">self</span>._sort_webaps_with_zeitgeist_async <span style="color: black;">&#40;</span>list_of_webapps, search, cancellable, <span style="color: #008000;">self</span>._on_webapps_sorted_received<span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">def</span> _on_webapps_sorted_received <span style="color: black;">&#40;</span><span style="color: #008000;">self</span>, search, cancellable, sorted_list_of_webapps<span style="color: black;">&#41;</span>:
	<span style="color: #808080; font-style: italic;"># NOTE: The new parameter              ^^^^^^^^^^^</span>
	<span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: black;">&#40;</span>cancellable.<span style="color: black;">is_cancelled</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>: <span style="color: #ff7700;font-weight:bold;">return</span>
	...</pre></div></div>

<h3>Filters</h3>
<p>Bliss doesn&#8217;t use filters, so I didn&#8217;t touch on that yet. If your scope is using filters, the correct thing is in 99.99% of all scopes to connect the <em>&#8220;filters-changed&#8221;</em> signal to calling <em>self.queue_search_changed(Unity.SearchType.DEFAULT)</em>. In Python:</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">def</span> <span style="color: #0000cd;">__init__</span> <span style="color: black;">&#40;</span><span style="color: #008000;">self</span><span style="color: black;">&#41;</span>:
	...
	<span style="color: #008000;">self</span>.<span style="color: black;">connect</span> <span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;filters-changed&quot;</span>, <span style="color: #008000;">self</span>._on_filters_changed<span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">def</span> _on_filters_changed <span style="color: black;">&#40;</span><span style="color: #008000;">self</span>, scope<span style="color: black;">&#41;</span>:
	<span style="color: #008000;">self</span>.<span style="color: black;">queue_search_changed</span><span style="color: black;">&#40;</span>Unity.<span style="color: black;">SearchType</span>.<span style="color: black;">DEFAULT</span><span style="color: black;">&#41;</span></pre></div></div>

<p>Personally I&#8217;d probably do it with lambdas:</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;">	...
	<span style="color: #008000;">self</span>.<span style="color: black;">connect</span> <span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;filters-changed&quot;</span>,
	              <span style="color: #ff7700;font-weight:bold;">lambda</span> scope: <span style="color: #008000;">self</span>.<span style="color: black;">queue_search_changed</span><span style="color: black;">&#40;</span>Unity.<span style="color: black;">SearchType</span>.<span style="color: black;">DEFAULT</span><span style="color: black;">&#41;</span></pre></div></div>

<p>&nbsp;</p>
<h3>Out of Band Result Changes</h3>
<p>Many scopes feature result sets that can change through external means. Fx. if you  are listing the contents of a directory, listing browser bookmarks, listing recent stuff from Zeitgeist, etc. All can change when the user is doing something else than searching the lenses. When the result set should be updated, disregarding whether the search string has changed, you can call <em>self.invalidate_search()</em>.</p>
<h3>Search String Change Checking</h3>
<p>In the previous paragraph I wrote <em>&#8220;disregarding whether the search string has changed&#8221;</em>. But when has the search string changed? Does appending a white space change the search string? Most lenses strips the search string from white spaces anyway; so in essence the strings <em>&#8220;xyz&#8221;</em> and <em>&#8220;xyz    &#8220;</em> are identical, seen from the scope. We don&#8217;t want to fire off a new search for these kinds of changes. Going further down this road &#8211; is <em>&#8220;XYZ&#8221;</em> and &#8220;<em>xYz&#8221;</em> the same as well? For most scopes, they will be. The problem is that this is highly dependent on the particular scope.</p>
<p>Doing change checking on search strings was a recurring chunk of similar code in all the default Unity lenses. In order to make this easier for our selves and everyone we baked it into libunity by means of the <em>&#8220;generate-search-key&#8221;</em> signal on the <em>Unity.Scope</em> class. This is a particular kind of signal that has a return value. The signal takes a <em>Unity.LensSearch</em> as input and returns a &#8220;normalized&#8221; version of the search string. This could typically be lower casing and chugging off white space at the ends. In code:</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">def</span> <span style="color: #0000cd;">__init__</span> <span style="color: black;">&#40;</span><span style="color: #008000;">self</span><span style="color: black;">&#41;</span>:
	...
	<span style="color: #008000;">self</span>.<span style="color: black;">connect</span> <span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;generate-search-key&quot;</span>, <span style="color: #008000;">self</span>._generate_search_key<span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">def</span> _generate_search_key <span style="color: black;">&#40;</span><span style="color: #008000;">self</span>, scope, search<span style="color: black;">&#41;</span>:
	<span style="color: #ff7700;font-weight:bold;">return</span> search.<span style="color: black;">props</span>.<span style="color: black;">search_string</span>.<span style="color: black;">lower</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>.<span style="color: black;">strip</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span></pre></div></div>

<h3>Cancellation and Transactions</h3>
<p>Considering again the example with async searches and cancellation. One could easily imagine a scenario where you had a bunch of async methods, some of which added rows to the results model and then going on to dispatch more async searches before calling <em>search.finished()</em>. If we got cancelled in the middle of all this, the results model would be left in a dirty state with only half the results of the search. Enter <em><a href="http://developer.ubuntu.com/api/ubuntu-12.04/python/Dee-1.0.html#Dee.Transaction">Dee.Transaction</a>.</em></p>
<p><em>Dee.Transaction</em> is new class in Dee that implements the <em>Dee.Model</em> interface. You create a new Transaction instance, <em>txn</em>, from your results model, then go on clearing and adding rows to the <em>txn</em> model as you go through your chain of async calls. The real results model will not be updated before you call <em>txn.commit()</em>. So if you&#8217;re cancelled somewhere in the middle you just let <em>txn</em> go out of scope (or unref it if you&#8217;re writing in C) and it&#8217;ll vanish like the Cheshire cat. If you make it all the way to the end you call <em>txn.commit()</em> right before you call <em>search.finished()</em>. So with an example:</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">def</span> _on_search_changed <span style="color: black;">&#40;</span><span style="color: #008000;">self</span>, scope, search, search_type, cancellable<span style="color: black;">&#41;</span>:
	txn = Dee.<span style="color: black;">Transaction</span>.<span style="color: #dc143c;">new</span> <span style="color: black;">&#40;</span>search.<span style="color: black;">props</span>.<span style="color: black;">results_model</span><span style="color: black;">&#41;</span>
	<span style="color: #008000;">self</span>._query_web_service1_async <span style="color: black;">&#40;</span>search, txn, cancellable, <span style="color: #008000;">self</span>._on_web_apps1_received<span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">def</span> _on_web_apps1_received <span style="color: black;">&#40;</span><span style="color: #008000;">self</span>, search, txn, cancellable, list_of_webapps<span style="color: black;">&#41;</span>:
	<span style="color: #808080; font-style: italic;"># First set of results retrieved, add them to the transaction</span>
	<span style="color: #808080; font-style: italic;"># and then fetch some more results from another web service</span>
	<span style="color: #ff7700;font-weight:bold;">if</span> cancellable.<span style="color: black;">is_cancelled</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>: <span style="color: #ff7700;font-weight:bold;">return</span>
&nbsp;
	txn.<span style="color: black;">clear</span> <span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
&nbsp;
	<span style="color: #ff7700;font-weight:bold;">for</span> app <span style="color: #ff7700;font-weight:bold;">in</span> list_of_webapps:
		txn.<span style="color: black;">append</span><span style="color: black;">&#40;</span>...<span style="color: black;">&#41;</span>
&nbsp;
	<span style="color: #008000;">self</span>._query_web_service2_async <span style="color: black;">&#40;</span>search, txn, cancellable, <span style="color: #008000;">self</span>._on_web_apps2_received<span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">def</span> _on_web_apps2_received <span style="color: black;">&#40;</span><span style="color: #008000;">self</span>, search, txn, cancellable, list_of_webapps<span style="color: black;">&#41;</span>:
	<span style="color: #808080; font-style: italic;"># Second batch of results</span>
	<span style="color: #ff7700;font-weight:bold;">if</span> cancellable.<span style="color: black;">is_cancelled</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>: <span style="color: #ff7700;font-weight:bold;">return</span>
&nbsp;
	<span style="color: #ff7700;font-weight:bold;">for</span> app <span style="color: #ff7700;font-weight:bold;">in</span> list_of_webapps:
		txn.<span style="color: black;">append</span><span style="color: black;">&#40;</span>...<span style="color: black;">&#41;</span>
&nbsp;
	txn.<span style="color: black;">commit</span> <span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
	search.<span style="color: black;">finished</span> <span style="color: black;">&#40;</span><span style="color: black;">&#41;</span></pre></div></div>

<h3>Fin!</h3>
<p>Wow, you&#8217;ve made it to the end of this blog post! You surely are an impressively patient person <img src='http://www.grillbar.org/wordpress/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<p>Please feel free to ask questions or post corrections in the comments. Or catch me, <em>kamstrup</em>, or Michal, <em>mhr3</em>, on #ayatana on FreeNode if you&#8217;re into IRC.</p>
<p>Now as a bonus for your patience you&#8217;ll get&#8230; A FREE picture of Me Looking At A Webcam!</p>
<p><center><a title="Mikkel Looking at a Webcam by kamstrup, on Flickr" href="http://www.flickr.com/photos/kamstrup/6719563539/"><img src="http://farm8.staticflickr.com/7008/6719563539_0835a1df1f.jpg" alt="Mikkel Looking at a Webcam" width="500" height="280" /></a></center></p>
]]></content:encoded>
			<wfw:commentRss>http://www.grillbar.org/wordpress/?feed=rss2&#038;p=585</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Hacking the Unity Shell &#8211; An Alternative Apps Lens</title>
		<link>http://www.grillbar.org/wordpress/?p=568</link>
		<comments>http://www.grillbar.org/wordpress/?p=568#comments</comments>
		<pubDate>Fri, 04 Nov 2011 15:01:49 +0000</pubDate>
		<dc:creator>kamstrup</dc:creator>
				<category><![CDATA[desktop search]]></category>
		<category><![CDATA[Hacking]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[unity]]></category>

		<guid isPermaLink="false">http://www.grillbar.org/wordpress/?p=568</guid>
		<description><![CDATA[(fret not, this is not only a wall of text, there&#8217;s a juicy screencast at the end if you make it all the way) Me being the maintainer of the applications lens in Unity you might wonder why I am now blogging about an alternative apps lens &#8211; let alone why I actually wrote the [...]]]></description>
			<content:encoded><![CDATA[<p>(fret not, this is not only a wall of text, there&#8217;s a juicy screencast at the end if you make it all the way)</p>
<p>Me being the maintainer of the applications lens in Unity you might wonder why I am now blogging about an alternative apps lens &#8211; let alone why I actually wrote the alternative myself! <img src='http://www.grillbar.org/wordpress/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<p>I am personally quite happy about the current default apps lens in Unity. It doesn&#8217;t try to be too smart, but aims more for the simple and intuitive. That&#8217;s why we only do <strong>prefix matching</strong> on the words in the application, eg  if the user types<em> &#8220;term&#8221;</em> it matches th word<em> &#8220;Terminal&#8221;</em>, but not <em>&#8220;XTerm&#8221;</em>. We also want the matching to be consistent with that of the results coming from the Ubuntu Software Center &#8211; which also works with prefix matching.</p>
<p>Not all users find prefix matching to be the best thing since sliced bread. I like it, but astonishingly the whole world doesn&#8217;t think like me!? Nonetheless I can respect that <img src='http://www.grillbar.org/wordpress/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<p>Some users wants to see <strong>substring matching</strong> which means that <em>&#8220;term&#8221;</em> matches both <em>&#8220;Terminal&#8221;</em> and <em>&#8220;XTerm&#8221;</em>. More progressive users wants a more powerful approach that we can call <strong>subpattern matching</strong> where the letters in the input string must occur in the same order in the string we test against, eg. <em>&#8220;term&#8221;</em> matches both <em>&#8220;Terminal&#8221;</em>, <em>&#8220;XTerm&#8221;</em> and <em>&#8220;<strong>Te</strong>levision <strong>R</strong>e<strong>m</strong>ote&#8221;</em>. This can also be thought of as some sort of &#8220;acronym matching&#8221;.</p>
<p>Matching algorithms aside some users simply hate to search for their apps and doesn&#8217;t like to go digging in the filters we have on the right (the filters are also hidden by default which makes them not so easily discoverable). They want to browse their good olde hierarchical menus.</p>
<p>&#8230; some users abhor the Most Used and Downloadable apps categories of the deafults lens &#8211; and some users probably want something completely different!</p>
<p>Had I not been an old fart I would probably gladly had added tonnes of options to the unity-lens-applications codebase trying to make everyone happy. But I <em>am</em> an old fart <img src='http://www.grillbar.org/wordpress/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' />  I want a simple and tight codebase and I don&#8217;t want tonnes of options because that makes the code harder to maintain. More tricky maintenance means that the ones that are happy with the defaults will suffer.</p>
<p><strong>Enter the power of Unity!</strong> You see; Unity is not only a shell in the user-facing kinda way. It is also a shell in the programmable kind of way <img src='http://www.grillbar.org/wordpress/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' />  The default lenses are not hard coded, you can replace them. So you can replace the apps lens as well if you want.</p>
<p>I&#8217;ve aired the idea of writing an alternative apps lens numerous times to the ones requesting changes, but none ever appeared that I know of. So I was thinking that I could maybe kick start that effort if I provide a solid starting point. Hence I whipped up <em><strong>Bliss</strong></em>, <a href="https://launchpad.net/unity-lens-bliss">https://launchpad.net/unity-lens-bliss</a>.</p>
<p>Bliss is a very simple replacement for the apps lens. It does basic searching with substring matching and it allows you to browse your apps by category. It also contains a good collection of bugs, but I&#8217;ve been dogfooding it here for a while now and it&#8217;s nothing unbearable <img src='http://www.grillbar.org/wordpress/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<p>Considering the new focus on power users for the Precise cycle I thought/hoped that I could inspire someone to grab the code and write a production ready app launcher specifically tailored for power users. I made the code so that it should be easy to hack on and extend, so let&#8217;s see where it ends up&#8230;</p>
<p><strong>Caveat emptor: </strong><em>Bliss is by no means official or anything. It is a quick hack to showcase how you can go about this, mostly intended for developers who want to do their own thing. That is also why you wont find a PPA for it (not from me at least <img src='http://www.grillbar.org/wordpress/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> ).</em></p>
<p><iframe src="http://player.vimeo.com/video/31596017?title=0&amp;byline=0&amp;portrait=0" frameborder="0" width="400" height="300"></iframe></p>
<p><a href="http://vimeo.com/31596017">Intruding Bliss, an Alternative Apps Lens for Unity</a> from <a href="http://vimeo.com/user4494468">Mikkel Kamstrup Erlandsen</a> on <a href="http://vimeo.com">Vimeo</a>.</p>
<p>So branch it, hack it, break, it, fork it. Knock yourselves out!</p>
<p>(I know of at least two obvious bugs: b1) the back arrow sometimes doesn&#8217;t appear as the first item, b2) the More Apps shortcut on the dash home screen breaks when you remove unity-lens-applications)</p>
]]></content:encoded>
			<wfw:commentRss>http://www.grillbar.org/wordpress/?feed=rss2&#038;p=568</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>2 times 410, is that 820?</title>
		<link>http://www.grillbar.org/wordpress/?p=565</link>
		<comments>http://www.grillbar.org/wordpress/?p=565#comments</comments>
		<pubDate>Thu, 06 Oct 2011 18:37:12 +0000</pubDate>
		<dc:creator>kamstrup</dc:creator>
				<category><![CDATA[Hacking]]></category>
		<category><![CDATA[Memes]]></category>

		<guid isPermaLink="false">http://www.grillbar.org/wordpress/?p=565</guid>
		<description><![CDATA[First thing this morning I learn we&#8217;ve lost Steve Jobs. This got me unexpectedly bummed out today. Unexpectedly, I am pretty far from being an Apple fanboy, and never consciously cared much about Apple. I had to do some soul searching to figure out if I was just jumping on the emotional slide created by [...]]]></description>
			<content:encoded><![CDATA[<p>First thing this morning I learn <a href="http://www.apple.com/stevejobs/">we&#8217;ve lost Steve Jobs</a>. This got me unexpectedly bummed out today. Unexpectedly, I am pretty far from being an Apple fanboy, and never consciously cared much about Apple. I had to do some soul searching to figure out if I was just jumping on the emotional slide created by the absolutely massive internet hype, or if it had genuinely moved me. I think it must be a bit of both.</p>
<p>Apple is a big contributor to open source and has clearly inspired a lot of things in the open source world, so it wouldn&#8217;t be an overstatement to say that I have daily exposure through my work. With my view from the code trenches I&#8217;ve seen the entire tech world being paced forward by Steve&#8217;s unwaivering focus. I&#8217;ve always been highly skeptical of Apple&#8217;s way to do business, but I guess I&#8217;ve grown a subconscious acknowledgement how important Steve has been to the computing world. Knowing that he was fighting cancer I think this promoted respect to inspiration. Adding in the massive online emotional hype this must explain why I got so bummed out.</p>
<p>My sadness turned into grumpiness later today when I learned about <a href="http://meyerweb.com/eric/thoughts/2011/10/04/searching-for-mark-pilgrim/">Mark Pilgrim&#8217;s recent departure from the online world</a> (on 4/10 to be exact &#8211; HTTP code 410, GONE).  I have all respect for him wanting to leave the digital world, but the way he did it is just not cool. Thousands of people looked to him as a role model (including me) or relied on his abundant and generous online materials to do their jobs.</p>
<p>Deliberately pulling the plug without warning is just unfair. You can go out like a gentleman or you can go out like an asshole.</p>
<p>When I wake up tomorrow I am gonna wake up to a new world, without Jobs, without Pilgrim. Meh.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.grillbar.org/wordpress/?feed=rss2&#038;p=565</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>On Application Startup Time: Why do we have it anyway?</title>
		<link>http://www.grillbar.org/wordpress/?p=554</link>
		<comments>http://www.grillbar.org/wordpress/?p=554#comments</comments>
		<pubDate>Mon, 12 Sep 2011 20:32:41 +0000</pubDate>
		<dc:creator>kamstrup</dc:creator>
				<category><![CDATA[Gnome]]></category>
		<category><![CDATA[Hacking]]></category>

		<guid isPermaLink="false">http://www.grillbar.org/wordpress/?p=554</guid>
		<description><![CDATA[Recently Jason Gerard DeRose brought up a subject that I have been considering from time to time over the last 6 months or so: &#8220;Why do our desktop applications take such a long time to start up, when they don&#8217;t do that on my phone?&#8221;. So thanks, Jason, for inspiring me to blog A few [...]]]></description>
			<content:encoded><![CDATA[<p>Recently <a href="http://jderose.blogspot.com/2011/09/our-apps-should-all-launch-instantly.html">Jason Gerard DeRose brought up a subject that I have been considering</a> from time to time over the last 6 months or so: <em>&#8220;Why do our desktop applications take such a long time to start up, when they don&#8217;t do that on my phone?&#8221;</em>. So thanks, Jason, for inspiring me to blog <img src='http://www.grillbar.org/wordpress/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<p>A few years back it was all the rave to get rid of the &#8220;login splash&#8221; &#8211; for newcomers: GNOME used to have splash screen displayed while it was loading your desktop. The mantra in the community was <em>&#8220;Let&#8217;s login so fast that we don&#8217;t even need a splash!&#8221;</em>. Lots of people did awesome hard work and we got to a point where we could reasonably remove that splash screen. That&#8217;s all well and good &#8211; but recent developments in the device industry has shown people that it&#8217;s not really the boot/login time that kills you, it&#8217;s the app startup time. And I confess; I totally jumped on that band wagon.</p>
<p>Sure &#8211; it&#8217;s annoying as heck that my Android phone takes <em>ages</em> (bloody ages!) to boot up. But my nerves are instantly soothed by the responsive system that comes alive. And this is something I&#8217;ve heard over and over and over again. From Apple fangirls to Android fanboys &#8211; users <em>really</em> dig the fast loading apps. Unrelated non-tech people have highlighted to me that the <em>primary feature</em> they loved on their tablet computer of choice was the fast app launching.</p>
<p>So my rhetorical question: <strong><em>&#8220;Startup time, why do we have it anyway?&#8221;</em></strong>. Maybe this is really a call to rally. Let&#8217;s make our Gnome apps start instantaneously!</p>
<p>But let me get slightly more technical. If you&#8217;ve ever set up a semi complex prototype of a Gtk+ app, some C stub code and a Glade project, you&#8217;d probably have seen that it starts up almost instantly. So why doesn&#8217;t it do that anymore when you put actual real world code in there? This is of course where it all starts to get tricky. Common things that make startup slow:</p>
<ul>
<li>Anything you load of disk takes time (and don&#8217;t even think about writing). More files to load is bad, badder, baddest. Also if you do it async, less apparent but still. On a related note: For some reason heavy IO of any kind messes up graphics performance under Linux. So &#8211; just <em>really</em> minimize that IO on startup.</li>
<li>There&#8217;s a tradition to set everything up before you show the window. This avoids that your layouts will be jumping all over the screen if you show your window immediately and start populating it with data. So you need a clever way to get the widget sizes just about right before really knowing what you&#8217;ll end up putting in there. This needs clever thinking by app authors, but maybe also some clever help from toolkit writers?</li>
<li>Complex data model? Maybe you have a simple on disk format that is quick to load, maybe even mmap()able, but requires lots of secondary parsing? Try to be clever and only parse what you need to show something and delay the rest until the user is distracted.</li>
<li>Using spinners when waiting for data. If the window and empty widgets are there in a snap the user wont really notice the 1-2s spinny there. Otoh if you add 1-2s on startup time they&#8217;ll have that hard-to-place sluggish feeling of the system.</li>
</ul>
<p>If we want instant app launching to be something we can do in Gnome, then it requires a big concerted effort, but definitely not insurmountable. We&#8217;d need to play around with a few techniques, someone documenting the good ones, identifying patterns and anti patterns and making it part of our documentation. Maybe adding in some support from the plumbing layers and toolkit and we could really make this sing.</p>
<p>Jason proposes a 250ms startup budget. A little playing around shows me that this is very ambitious with our current stack and a semi complex app (our desktop apps tend to be more complex than mobile apps, so mobile apps have the obvious advantage there). Before reading Jason&#8217;s proposition my idea was 500ms, but maybe we should really aim for the 250ms?</p>
<p>What&#8217;s your take on this?</p>
<p><span style="color: gray;">(as a closing remark let me add that I <em>deliberately</em> didn&#8217;t put my SSD in my new laptop because I want to feel the pain. Feel the pain so that we can eradicate it also for those without SSD)</span></p>
]]></content:encoded>
			<wfw:commentRss>http://www.grillbar.org/wordpress/?feed=rss2&#038;p=554</wfw:commentRss>
		<slash:comments>19</slash:comments>
		</item>
		<item>
		<title>Back in ~12 Hours!</title>
		<link>http://www.grillbar.org/wordpress/?p=550</link>
		<comments>http://www.grillbar.org/wordpress/?p=550#comments</comments>
		<pubDate>Tue, 30 Aug 2011 20:05:29 +0000</pubDate>
		<dc:creator>kamstrup</dc:creator>
				<category><![CDATA[Family]]></category>
		<category><![CDATA[Hacking]]></category>

		<guid isPermaLink="false">http://www.grillbar.org/wordpress/?p=550</guid>
		<description><![CDATA[My 4 month paternity leave is coming to an end in ~12 hours from now. I feel so privileged that I had this opportunity to spend so much time with my kid(s); it&#8217;s been awesome. On the other hand I am also itching to get back to some hacking. So who knows? Maybe you&#8217;ll start [...]]]></description>
			<content:encoded><![CDATA[<p>My 4 month paternity leave is coming to an end in ~12 hours from now. I feel so privileged that I had this opportunity to spend so much time with my kid(s); it&#8217;s been awesome. On the other hand I am also itching to get back to some hacking. So who knows? Maybe you&#8217;ll start seeing some posts on this blog again (yeah, <em>right!</em>).</p>
<p>I had so many grand plans for the leave, but pretty much the only one of them that I didn&#8217;t abandon was that of taking care of the baby and the household. I really thought I had it all planned and ready to roll as this was the third kid and I knew the drill. <em>Not so much</em> <img src='http://www.grillbar.org/wordpress/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<p>Most of the ditched plans were related to coding somehow, but I ended up spending next to no time in front of the screen (compared to what I normally do! not compared to what normal, sane, people do). Looking back on the 4 months there was a tonne of stuff that I <em>did</em> get to do. Fx. <a href="http://www.flickr.com/photos/kamstrup/5713304230">exploring</a> the <a href="http://www.flickr.com/photos/kamstrup/5873243187">finer details</a> of <a href="http://www.flickr.com/photos/kamstrup/5921394287">bread making</a>, brew some beer, <a href="https://plus.google.com/114917792033374998389/posts/NykF4Wcw6yR">brew some apple wine</a> (still waiting on that one), work on our house in Ålbæk, <a href="http://twitter.com/#!/kamstrup/status/101375754289426433">learned about the Japanese</a> <a href="https://plus.google.com/114917792033374998389/posts/HdecsPSteYG">cuisine</a>, refreshed my old math curriculum from uni, and started to read up on the maths and physics behind superstring theory (mostly the math part)&#8230;</p>
<p>&#8230; <em>enough with the link dropping</em>, who am I trying to fool &#8211; it was really mostly about diapers, laundry, dish washing, and sleepless nights <img src='http://www.grillbar.org/wordpress/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.grillbar.org/wordpress/?feed=rss2&#038;p=550</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Unity Places &#8211; now with 100% More Python</title>
		<link>http://www.grillbar.org/wordpress/?p=544</link>
		<comments>http://www.grillbar.org/wordpress/?p=544#comments</comments>
		<pubDate>Thu, 03 Mar 2011 09:03:45 +0000</pubDate>
		<dc:creator>kamstrup</dc:creator>
				<category><![CDATA[Hacking]]></category>
		<category><![CDATA[unity]]></category>
		<category><![CDATA[pygi]]></category>
		<category><![CDATA[pygobject]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[ubuntu]]></category>

		<guid isPermaLink="false">http://www.grillbar.org/wordpress/?p=544</guid>
		<description><![CDATA[Some may have seen that I was pimping my session Rocking out with libunity at the Ubuntu Developer Week promising a surprise. The surprise was that I had a fully working Unity Place implementation all in Python. If you want you can peruse the full log from the IRC session, it might be helpful if [...]]]></description>
			<content:encoded><![CDATA[<p>Some may have seen that I was <a href="http://twitter.com/kamstrup/status/42923724873277440">pimping</a> my session <em>Rocking out with libunity </em>at the <a href="https://wiki.ubuntu.com/UbuntuDeveloperWeek">Ubuntu Developer Week</a> promising a surprise. The surprise was that I had a fully working Unity Place implementation all in Python. If you want you can peruse the <a href="http://irclogs.ubuntu.com/2011/03/02/%23ubuntu-classroom.html#t20:02">full log from the IRC session</a>, it might be helpful if you want to try this out yourself.</p>
<p>Hopefully unsurprisingly &#8211; the Python integration is all done with PyGI, the Python bindings for GObject Introspection. I must admit that it was a slight challenge getting everything working smoothly, but we&#8217;re there now. I want to give <em>mad props</em> to the pygobject- and the GObject Introspection teams. Without their enduring help we wouldn&#8217;t have got to this point. So thanks guys, you rock!</p>
<p>So lets get down to business. How does this work, what does it look like?</p>
<h4>Setting up a Development Environment</h4>
<p>First you need to make sure you have the required development packages installed (you can just click the links to install them if you want):</p>
<blockquote><p>sudo apt-get install <a href="apt:gir1.2-unity-3.0">gir1.2-unity-3.0</a> <a href="apt:gir1.2-dee-0.5">gir1.2-dee-0.5</a> <a href="apt:gir1.2-dbusmenu-glib-0.4">gir1.2-dbusmenu-glib-0.4</a></p></blockquote>
<p>Now, unfortunately not everything you need is packaged just yet. Namely you may need to install the so called <em>Python overrides</em> for the Dee library. Check if you have this file on your system:</p>
<blockquote><p>/usr/lib/pymodules/python2.7/gi/overrides/Dee.py</p></blockquote>
<p>If you don&#8217;t have that file it means you&#8217;re in in the vicinity of the writing of this blog post, in the time dimension; and thus must install it manually. Here&#8217;s how. Download <a href="http://bazaar.launchpad.net/~unity-team/dee/trunk/view/head:/bindings/python/Dee.py">Dee.py</a> and copy it to the right location for PyGI to pick it up:</p>
<blockquote><p>sudo cp Dee.py /usr/lib/pymodules/python2.7/gi/overrides/</p></blockquote>
<p>With that in place we&#8217;re ready to hack.</p>
<h4>Writing a Place in Python</h4>
<p>The easiest way to start is to check out <a href="https://code.launchpad.net/~unity-team/unity-place-sample/unity-place-python">lp:~unity-team/unity-place-sample/unity-place-python</a>:</p>
<blockquote><p>bzr branch lp:~unity-team/unity-place-sample/unity-place-python</p></blockquote>
<p>And then closely follow the <a href="http://bazaar.launchpad.net/~unity-team/unity-place-sample/unity-place-python/view/head:/README">README</a>. If you read through it while having the <a href="https://wiki.ubuntu.com/Unity/Places">Unity Places spec</a> and<a href="http://irclogs.ubuntu.com/2011/03/02/%23ubuntu-classroom.html#t20:02"> IRC log from the devsession</a> at hand you should have a chance of grokking what&#8217;s going on. If you have any problems or questions don&#8217;t hesitate to ping me on IRC on the <tt>#ayatana</tt> channel on FreeNode.</p>
<p>I should also add that we&#8217;re working on getting some Python API docs for Dee, Dbusmenu, and libunity out. Watch this space!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.grillbar.org/wordpress/?feed=rss2&#038;p=544</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>Zeitgeist Hackfest Conclusions</title>
		<link>http://www.grillbar.org/wordpress/?p=536</link>
		<comments>http://www.grillbar.org/wordpress/?p=536#comments</comments>
		<pubDate>Fri, 11 Feb 2011 22:10:03 +0000</pubDate>
		<dc:creator>kamstrup</dc:creator>
				<category><![CDATA[Gnome]]></category>
		<category><![CDATA[Hacking]]></category>
		<category><![CDATA[zeitgeist]]></category>
		<category><![CDATA[aarhus]]></category>
		<category><![CDATA[hackfest]]></category>

		<guid isPermaLink="false">http://www.grillbar.org/wordpress/?p=536</guid>
		<description><![CDATA[So I didn&#8217;t really stick to my original idea of reporting each day of the Zeitgeist hackfest in Aarhus. I guess this must be a classical hackfest syndrome &#8211; you give 120% during the day and when night draws near you&#8217;re just flat out of batteries. &#8216;nough with the excuses My own pet peeve, the [...]]]></description>
			<content:encoded><![CDATA[<p>So I didn&#8217;t really stick to my original idea of reporting each day of the Zeitgeist hackfest in Aarhus. I guess this must be a classical hackfest syndrome &#8211; you give 120% during the day and when night draws near you&#8217;re just flat out of batteries. &#8216;nough with the excuses <img src='http://www.grillbar.org/wordpress/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<p>My own pet peeve, the Storage Awareness branch is inches from landing. It will allow the following kinds of new features:</p>
<ul>
<li>Exclude files from a query that are not available to the user right now. Fx, because they are on a USB stick or require internet access when you don&#8217;t have any, or</li>
<li>imagine a journal-kinda-view where you can still see files you accessed that where on drives that are no longer attached. When you click them a dialog pops up <em>&#8220;Please insert the drive &#8217;2GB SanDisk&#8217; in order to open the file &#8216;foo.txt&#8217;&#8221;</em>.</li>
<li>When you plug in a USB drive you are presented with your most recent activity related to that drive</li>
<li>List which storage devices you&#8217;ve used an when</li>
</ul>
<p><a href="http://mhr3.blogspot.com/">Michal</a> was just all over the place doing integration work on everything between glib, libzeitgeist, gedit, totem, what not. From where I sit this guy just had an <em>amazingly</em> productive week!</p>
<p><a href="http://seilo.geekyogre.com/2011/02/zeitgeist-hackfest-day-1-3/">Seif worked on the &#8220;grid plugin&#8221; for GEdit</a> which is originally Michal&#8217;s idea and something we where all pretty hyped about. Really something that I feel could make a huge difference in the user experience of many Gnome apps.</p>
<p><a href="http://twitter.com/mortenmjelva">Morten</a> did a lot of work to get Zeitgeist ready for some deep Telepathy integration, this required a lot of hard thinking and a lot of discussion (with Seif and yours truly, but don&#8217;t worry we&#8217;re all still friends <img src='http://www.grillbar.org/wordpress/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> ). Getting it &#8220;just right&#8221; was not trivial, but I think we got to a point where we have a very good battle plan on how to get all the way to working code.</p>
<p><a href="http://bloc.eurion.net/">Siegfried</a> worked on Gnome Shell integration and I think we should start seeing the fruits of that very soon now &#8211; <a href="http://people.gnome.org/~federico/news-2011-02.html#09">and Federico joined remotely</a>.</p>
<p>We also got some media coverage which, as often goes, was not entirely accurate, so <a href="http://milky.manishsinha.net/2011/02/11/a-re-introduction-to-zeitgeist/">Manish took the time to straighten out the facts</a> <img src='http://www.grillbar.org/wordpress/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<p>Once again, big thanks to our sponsors &#8211; the opportunity they have given has made a huge difference!</p>
<p><img src="http://live.gnome.org/Travel/Policy?action=AttachFile&amp;do=get&amp;target=sponsored-badge-shadow.png" alt="Sponsored by Gnome Foundation Badge" /><img src="http://www.collabora.co.uk/logos/collabora-logo-small.png" alt="Collabora logo" /></p>
<p><img src="http://enhed.au.dk/5150/png/en" alt="cs.au.dk logo" width="500" /><img class="alignnone" src="http://www.incuba-sp.dk/ajrgfx/gfx/incuba_logo.gif" alt="" width="114" height="84" /></p>
]]></content:encoded>
			<wfw:commentRss>http://www.grillbar.org/wordpress/?feed=rss2&#038;p=536</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Zeitgeist Hackfest Day 1</title>
		<link>http://www.grillbar.org/wordpress/?p=530</link>
		<comments>http://www.grillbar.org/wordpress/?p=530#comments</comments>
		<pubDate>Mon, 07 Feb 2011 21:24:53 +0000</pubDate>
		<dc:creator>kamstrup</dc:creator>
				<category><![CDATA[Gnome]]></category>
		<category><![CDATA[Hacking]]></category>
		<category><![CDATA[zeitgeist]]></category>
		<category><![CDATA[hackfest]]></category>
		<category><![CDATA[telepathy]]></category>

		<guid isPermaLink="false">http://www.grillbar.org/wordpress/?p=530</guid>
		<description><![CDATA[So. The first day of the Zeitgeist hackfest has ended. The venue at the CS department of Aarhus University worked really well. The wifi worked without a hitch and we all got keys and keycards to access the premises of the Incuba Science Park all 24 hours of the day. Awesome. We spend the first [...]]]></description>
			<content:encoded><![CDATA[<p>So. The first day of the Zeitgeist hackfest has ended. The venue at the CS department of Aarhus University worked really well. The wifi worked without a hitch and we all got keys and keycards to access the premises of the Incuba Science Park all 24 hours of the day. Awesome.</p>
<p>We spend the first 2 hours figuring out what items to focus on and who does what and Seif compiled it into a <a href="http://live.gnome.org/Hackfests/Zeitgeist2011/Assignment">list of assigments on the wiki</a>.</p>
<p>Seif, Morten, and I talked about what pieces we needed to fit together to make the Zeitgeist and Telepathy integration work perfectly. Got some nice and simple work items nailed down that&#8217;ll take us a long way.</p>
<p>While we did that Michal updated the <tt>zeitgeist-datahub</tt> to listen for the new DBus signal emitted by <tt>GDesktopAppInfo</tt> when they are launched. He also worked with Colin Walters on getting a<a href="https://bugzilla.gnome.org/show_bug.cgi?id=641395"> nifty little patch that adds some extra info to the DBus signal</a> that will make Zeitgeist even more clever when logging your app usage patterns. Uh&#8230; And Michal is brewing up something awesome for you as well, but I shall not steal his thunder <img src='http://www.grillbar.org/wordpress/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<p>My personal little project was to update and make my <a href="http://www.grillbar.org/wordpress/?p=443">&#8220;Storage Awareness&#8221; branch</a> from a while back ready to merge to trunk. There are some kinks to iron out before it&#8217;s ready, but I&#8217;m most thrilled about the prospect of getting this done.</p>
<p>Oh! And there is a <a href="http://twitter.com/search?q=%23zeitgeisthackfest">#zeitgeisthackfest</a> hashtag if you wanna bigbrother us on Twitter <img src='http://www.grillbar.org/wordpress/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.grillbar.org/wordpress/?feed=rss2&#038;p=530</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Zeitgeist Hackfest</title>
		<link>http://www.grillbar.org/wordpress/?p=527</link>
		<comments>http://www.grillbar.org/wordpress/?p=527#comments</comments>
		<pubDate>Sun, 06 Feb 2011 23:05:24 +0000</pubDate>
		<dc:creator>kamstrup</dc:creator>
				<category><![CDATA[desktop search]]></category>
		<category><![CDATA[Gnome]]></category>
		<category><![CDATA[Hacking]]></category>
		<category><![CDATA[unity]]></category>
		<category><![CDATA[zeitgeist]]></category>
		<category><![CDATA[hackfest]]></category>

		<guid isPermaLink="false">http://www.grillbar.org/wordpress/?p=527</guid>
		<description><![CDATA[Prepping up for the Zeitgeist hackfest which is kicking off tomorrow in Aarhus, Denmark. You&#8217;ve probably not heard a lot about this event before this late moment &#8211; that&#8217;s because it has all happened a bit fast. As we where internally discussing the possibilities of a hackfest a bit back, it quickly became evident that [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://zeitgeist-project.com/wp-content/themes/zeitgeist3/images/logo.png" alt="Zeitgeist logo" /></p>
<p>Prepping up for the Zeitgeist hackfest which is kicking off tomorrow in Aarhus, Denmark. You&#8217;ve probably not heard a lot about this event before this late moment &#8211; that&#8217;s because it has all happened a bit fast. As we where internally discussing the possibilities of a hackfest a bit back, it quickly became evident that we needed it hold it <em>Very Soon Now</em> (TM) if we wanted all the core maintainers to have a chance of showing up.</p>
<p>I was wincing a bit because we recently expanded our family (can you believe I have three kids now..? I&#8217;m not sure I can) and I wasn&#8217;t very keen on traveling more than I already do with <a href="http://ubuntu.com">my work</a>. <a href="http://seilo.geekyogre.com/">Seif</a>, being the man of action that he is, didn&#8217;t let that put him off an arranged that we could hold the hackfest conveniently close to my home. Not only that, but he pretty much did all of the necessary arrangements for getting a cool venue, accommodation, and not least &#8211; getting some sponsors to help us out. <em>Seif &#8211; this one is to you &#8211; you rock man!</em></p>
<p>The sponsors are the <a href="http://www.gnome.org/">GNOME Foundation</a> and <a href="http://collabora.co.uk">Collabora</a>, and the venue will be the <a href="http://cs.au.dk/">CS Department at Aarhus University</a>, in the <a href="http://www.incuba-sp.dk/">Incuba Science Park</a>. All have been incredibly helpful despite our short notice. Thanks to everyone involved!</p>
<p><img src="http://live.gnome.org/Travel/Policy?action=AttachFile&amp;do=get&amp;target=sponsored-badge-shadow.png" alt="Sponsored by Gnome Foundation Badge" /><img src="http://www.collabora.co.uk/logos/collabora-logo-small.png" alt="Collabora logo" /></p>
<p><img src="http://enhed.au.dk/5150/png/en" alt="cs.au.dk logo" width="500" /><img class="alignnone" src="http://www.incuba-sp.dk/ajrgfx/gfx/incuba_logo.gif" alt="" width="114" height="84" /></p>
<p>I&#8217;m gonna have to hold the suspension a bit about what we intend to do with this precious opportunity we&#8217;ve been given. I&#8217;m just too tired right now &#8211; but my plan is to have a short daily log posted on my blog each day. So by the end of this week you should all hopefully have an idea <img src='http://www.grillbar.org/wordpress/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' />  Stay tuned.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.grillbar.org/wordpress/?feed=rss2&#038;p=527</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

