<?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>Pontus Östlund &#187; GTK</title>
	<atom:link href="http://www.poppa.se/blog/tag/gtk/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.poppa.se/blog</link>
	<description>My blog about web development and such</description>
	<lastBuildDate>Mon, 16 Jan 2012 00:38:45 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>GTK TreeViewColumn with icon and text</title>
		<link>http://www.poppa.se/blog/gtk-treeviewcolumn-with-both-icon-and-text-in-the-same-column/</link>
		<comments>http://www.poppa.se/blog/gtk-treeviewcolumn-with-both-icon-and-text-in-the-same-column/#comments</comments>
		<pubDate>Mon, 21 Nov 2011 20:18:51 +0000</pubDate>
		<dc:creator>Pontus</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[CellRenderer]]></category>
		<category><![CDATA[Gnome]]></category>
		<category><![CDATA[GTK]]></category>
		<category><![CDATA[GTK3]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[TreeViewColumn]]></category>
		<category><![CDATA[Vala]]></category>

		<guid isPermaLink="false">http://www.poppa.se/blog/?p=534</guid>
		<description><![CDATA[
The other day I wanted to put both an icon and text in the same GTK+ TreeViewColumn, and I had absolutely no idea how to do that. So I Google&#8217;d and Google&#8217;d but had trouble finding any examples. I even downloaded the source code of the Gnome System Monitor &#8211; where exactly what I wanted [...]]]></description>
			<content:encoded><![CDATA[<p><a href="/blog/data/images/gtk-tvcol.png"><img src="/blog/data/images/gtk-tvcol.png/680" alt="TreeViewColumn with icon and text" /></a></p>
<p>The other day I wanted to put both an icon and text in the same <a href="http://www.gtk.org/">GTK+</a> <code>TreeViewColumn</code>, and I had absolutely no idea how to do that. So I Google&#8217;d and Google&#8217;d but had trouble finding any examples. I even downloaded the <a href="https://code.launchpad.net/gnome-system-monitor">source code</a> of the <a href="http://library.gnome.org/users/gnome-system-monitor/stable/">Gnome System Monitor</a> &#8211; where exactly what I wanted exist &#8211; but that was mostly written in C++ which I know very little of. </p>
<p>But I&#8217;m stubborn, and after a while I found and example in <a href="http://python.org/">Python</a> which I managed to interpret. Even though I know very little Python it&#8217;s not that hard to follow, and the example was short.</p>
<p>In short what&#8217;s needed is packing two <code>CellRenderer</code>s in the same <code>TreeViewColumn</code>. Quite logical when you know about it. The example below is in <a href="http://live.gnome.org/Vala">Vala</a>:</p>
<pre><code lang="vala">
var tree_view = new TreeView ();

var col = new TreeViewColumn ();
col.title = title;
col.resizable = true;

var crp = new CellRendererPixbuf ();
col.pack_start (crp, false);
col.add_attribute (crp, "pixbuf", 0);

var crt = new CellRendererText ();
col.pack_start (crt, false);
col.add_attribute (crt, "text", 1);

tree_view.insert_column (col, -1);
</code></pre>
<p>I hacked up a simple application that shows all installed programs &#8211; that has a <code>.desktop</code> entry I guess &#8211; in a list (the screenshot above). The sources is available at my <a href="https://github.com/poppa/PlayStation/tree/master/Vala/Gtk3/treeview-with-pixbuf">Github repository</a>.</p>
<p>Happy coding!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.poppa.se/blog/gtk-treeviewcolumn-with-both-icon-and-text-in-the-same-column/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Roxen Application Launcher 1.1</title>
		<link>http://www.poppa.se/blog/roxen-application-launcher-1-1/</link>
		<comments>http://www.poppa.se/blog/roxen-application-launcher-1-1/#comments</comments>
		<pubDate>Tue, 08 Nov 2011 22:28:34 +0000</pubDate>
		<dc:creator>Pontus</dc:creator>
				<category><![CDATA[Applications]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Roxen]]></category>
		<category><![CDATA[GTK]]></category>
		<category><![CDATA[GTK3]]></category>
		<category><![CDATA[RAL]]></category>
		<category><![CDATA[Ubuntu]]></category>
		<category><![CDATA[Vala]]></category>

		<guid isPermaLink="false">http://www.poppa.se/blog/?p=519</guid>
		<description><![CDATA[
There&#8217;s a new release of Roxen Application Launcher (come again?) for Linux. 
I have updated the application launcher to use GTK3 so that it builds on Ubuntu 11.10 and any other Linux distribution using GTK3. This also made it possible to drop the dependency for libunique since Gtk.Application can handle single instance applications.
I also fixed [...]]]></description>
			<content:encoded><![CDATA[<p><a href="/blog/data/images/ral-1.1.png" class="no-file"><img src="/blog/data/images/ral-1.1.png/680" alt="Screenshot of Roxen Application Launcher" /></a></p>
<p>There&#8217;s a new release of <a href="http://www.roxen.com">Roxen</a> Application Launcher (<a href="/blog/stuff/#roxen-applauncher">come again?</a>) for <a href="http://www.linux.com/">Linux</a>. </p>
<p>I have updated the application launcher to use <code>GTK3</code> so that it builds on Ubuntu 11.10 and any other Linux distribution using <code>GTK3</code>. This also made it possible to drop the dependency for <code>libunique</code> since <code>Gtk.Application</code> can handle single instance applications.</p>
<p>I also fixed a bug which made it impossible to use the appliction launcher on sites not running on port <code>80</code> or <code>443</code>.</p>
<p>So there&#8217;s no new features in this release.</p>
<p><a class="download" title="Download from Github" href="https://github.com/downloads/poppa/Roxen-Application-Launcher/roxenlauncher-1.1.tar.bz2"><span>Roxen Application Launcher 1.1</span></a></p>
<p>Sources is available at the Roxen Application Launcher <a href="https://github.com/poppa/Roxen-Application-Launcher">Github repository</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.poppa.se/blog/roxen-application-launcher-1-1/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Roxen Application Launcher 1.0.10</title>
		<link>http://www.poppa.se/blog/roxen-application-launcher-1-0-10/</link>
		<comments>http://www.poppa.se/blog/roxen-application-launcher-1-0-10/#comments</comments>
		<pubDate>Wed, 22 Jun 2011 19:24:59 +0000</pubDate>
		<dc:creator>Pontus</dc:creator>
				<category><![CDATA[Applications]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Roxen]]></category>
		<category><![CDATA[GTK]]></category>
		<category><![CDATA[RAL]]></category>
		<category><![CDATA[Vala]]></category>

		<guid isPermaLink="false">http://www.poppa.se/blog/?p=505</guid>
		<description><![CDATA[There&#8217;s a new release of Roxen Application Launcher (come again?) for Linux. 
No big news, but the GTK+ tree view of files is now sortable. The &#8220;minimize to tray&#8221; function is now actually invoked when the window is minimized rather than closed. A right click in the file list now also let you go the [...]]]></description>
			<content:encoded><![CDATA[<p>There&#8217;s a new release of <a href="http://www.roxen.com">Roxen</a> Application Launcher (<a href="/blog/stuff/#roxen-applauncher">come again?</a>) for <a href="http://www.linux.com/">Linux</a>. </p>
<p>No big news, but the GTK+ tree view of files is now sortable. The &#8220;minimize to tray&#8221; function is now actually invoked when the window is minimized rather than closed. A right click in the file list now also let you go the the file&#8217;s directory in the Sitebuilder.</p>
<p>Also fixed a bug where the locales didn&#8217;t get installed correctly and also fixed a bug which scrambled the configuration file a bit.</p>
<p><a class="download" title="Download from Github" href="https://github.com/downloads/poppa/Roxen-Application-Launcher/roxenlauncher-1.0.10.tar.bz2"><span>Roxen Application Launcher 1.0.10</span></a></p>
<p>Sources is available at the Roxen Application Launcher <a href="https://github.com/poppa/Roxen-Application-Launcher">Github repository</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.poppa.se/blog/roxen-application-launcher-1-0-10/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Notification area icons in Ubuntu 11.04</title>
		<link>http://www.poppa.se/blog/notification-area-icons-in-ubuntu-11-04/</link>
		<comments>http://www.poppa.se/blog/notification-area-icons-in-ubuntu-11-04/#comments</comments>
		<pubDate>Tue, 03 May 2011 21:46:19 +0000</pubDate>
		<dc:creator>Pontus</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Bash]]></category>
		<category><![CDATA[gsettings]]></category>
		<category><![CDATA[GTK]]></category>
		<category><![CDATA[Share]]></category>
		<category><![CDATA[Ubuntu]]></category>

		<guid isPermaLink="false">http://www.poppa.se/blog/?p=486</guid>
		<description><![CDATA[If you&#8217;r an Ubuntu user and have upgraded to 11.04 and use the new desktop environment Unity, you might have noticed that some applications that implement the GTK status icon doesn&#8217;t show up in the notification area &#8211; or tray or systray as it also may be called.
The reason for this is that Ubuntu now [...]]]></description>
			<content:encoded><![CDATA[<p>If you&#8217;r an Ubuntu user and have upgraded to 11.04 and use the new desktop environment Unity, you might have noticed that some applications that implement the GTK status icon doesn&#8217;t show up in the notification area &#8211; or tray or systray as it also may be called.</p>
<p>The reason for this is that Ubuntu now utilise a &#8220;whitelist&#8221; for which applications can be displayed in the notification area. You can (maybe not that) easily add any application to the whitelist by invoking the command <code>gsettings</code> in the following way:</p>
<pre><code lang="shell">
gsettings set com.canonical.Unity.Panel systray-whitelist ['app-1', 'app-2', 'app-3']
</code></pre>
<p>Now, this can be quite a difficult command to remember and since you will need to first grab the whitelist, alter it, and then put it back. Since I&#8217;m lame at Bash I thought it would be a nice misson to create a Bash script that makes this interference simpler, just to pick up some more Bash knowledge. So I did!</p>
<p>The script can be used like this:</p>
<pre><code lang="shell">
# Add MyApplication to whitelist
systray-whitelist add MyApplication

# Remove MyApplication from whitelist
systray-whitelist remove MyApplication

# Show applications in whitelist
systray-whitelist show
</code></pre>
<p>And that&#8217;s that.</p>
<p><a href="/blog/data/scripts/systray-whitelist" class="download">Download systray-whitelist</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.poppa.se/blog/notification-area-icons-in-ubuntu-11-04/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Roxen Application Launcher 1.0</title>
		<link>http://www.poppa.se/blog/roxen-application-launcher-1-0/</link>
		<comments>http://www.poppa.se/blog/roxen-application-launcher-1-0/#comments</comments>
		<pubDate>Sun, 12 Sep 2010 09:16:30 +0000</pubDate>
		<dc:creator>Pontus</dc:creator>
				<category><![CDATA[Applications]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Roxen]]></category>
		<category><![CDATA[Github]]></category>
		<category><![CDATA[Gnome]]></category>
		<category><![CDATA[GTK]]></category>
		<category><![CDATA[RAL]]></category>
		<category><![CDATA[Vala]]></category>

		<guid isPermaLink="false">http://www.poppa.se/blog/?p=467</guid>
		<description><![CDATA[
So I had a go at the Roxen Application Launcher (come again?) for Linux. I added a context menu &#8211; when you right click &#8211; to the file list. When you right click a file in the list you get the option to view that file in the Sitebuilder, edit it or remove it.
Other than [...]]]></description>
			<content:encoded><![CDATA[<p><a href="/blog/data/images/ral-1.0.png" class="no-file"><img src="/blog/data/images/ral-1.0.png/680" alt="Screenshot of Roxen Application Launcher with context menu" /></a></p>
<p>So I had a go at the <a href="http://www.roxen.com">Roxen</a> Application Launcher (<a href="/blog/stuff/#roxen-applauncher">come again?</a>) for <a href="http://www.linux.com/">Linux</a>. I added a context menu &#8211; when you right click &#8211; to the file list. When you right click a file in the list you get the option to view that file in the Sitebuilder, edit it or remove it.</p>
<p>Other than that there&#8217;s nothing new. And since the application seems to be very stable I decided to bump the version number to 1.0.</p>
<p>The sources is available at <a href="http://github.com/poppa/Roxen-Application-Launcher">Github</a>.</p>
<p><a href="/blog/data/roxenlauncher-1.0.tar.gz">Roxen Appliction Launcher 1.0</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.poppa.se/blog/roxen-application-launcher-1-0/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Pike project &#8211; module stub creator</title>
		<link>http://www.poppa.se/blog/pike-project-module-stub-creator/</link>
		<comments>http://www.poppa.se/blog/pike-project-module-stub-creator/#comments</comments>
		<pubDate>Thu, 19 Aug 2010 22:06:31 +0000</pubDate>
		<dc:creator>Pontus</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[GTK]]></category>
		<category><![CDATA[Pike]]></category>

		<guid isPermaLink="false">http://www.poppa.se/blog/?p=455</guid>
		<description><![CDATA[
I recently began learning how to create Pike modules in C. The Pike module C API seems great and once you&#8217;ve sorted things out the modules are easy to build and install. Non the less, when creating a C module from scratch there&#8217;s a couple of files you need and some configurations of those before [...]]]></description>
			<content:encoded><![CDATA[<p><a href="/blog/data/images/pike-project.png" class="no-file"><img src="/blog/data/images/pike-project.png/680" alt="Screenshot of Pike project" /></a></p>
<p>I recently began learning how to create <a href='http://pike.ida.liu.se/'>Pike</a> modules in C. The Pike module C API seems great and once you&#8217;ve sorted things out the modules are easy to build and install. Non the less, when creating a C module from scratch there&#8217;s a couple of files you need and some configurations of those before everything is set for go. And here comes &#8220;pike-project&#8221; into play.</p>
<p>Pike-project is a simple <a href='http://www.gtk.org/'>GTK</a> program (works as command line tool also) written in Pike it self. The program will create the basics for a running Pike C module, or a plain installable Pike module. Then it&#8217;s just starting programming.</p>
<p>The program is available at my <a href='http://github.com/poppa/Pike-Modules/blob/master/tools/pike-project'>Github repository</a>.</p>
<p>BTW! At the moment it only works on Linux I suppose.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.poppa.se/blog/pike-project-module-stub-creator/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>GTK hacking in Pike</title>
		<link>http://www.poppa.se/blog/gtk-hacking-in-pike/</link>
		<comments>http://www.poppa.se/blog/gtk-hacking-in-pike/#comments</comments>
		<pubDate>Mon, 18 Jan 2010 23:40:59 +0000</pubDate>
		<dc:creator>Pontus</dc:creator>
				<category><![CDATA[Applications]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Gnome]]></category>
		<category><![CDATA[GTK]]></category>
		<category><![CDATA[Pike]]></category>

		<guid isPermaLink="false">http://www.poppa.se/blog/?p=386</guid>
		<description><![CDATA[I&#8217;ve found out that it&#8217;s great fun programming desktop applications and of course it gets more fun the more you learn. Now I&#8217;m doing a Twitter client in Pike &#8211; my favorite programming language &#8211; mostly because I wanted to try out GTK programming in Pike. I use the good Twitter client Pino &#8211; written [...]]]></description>
			<content:encoded><![CDATA[<p><a href="/blog/data/images/tweepi.jpg" class="no-file"><img src="/blog/data/images/tweepi.jpg/220" class="alignright" alt="Tweepi, the Twitter client written in Pike" /></a>I&#8217;ve found out that it&#8217;s great fun programming desktop applications and of course it gets more fun the more you learn. Now I&#8217;m doing a <a href="http://twitter.com">Twitter</a> client in <a href="http://pike.ida.liu.se">Pike</a> &#8211; my favorite programming language &#8211; mostly because I wanted to try out <a href="http://www.gtk.org/">GTK</a> programming in Pike. I use the good Twitter client <a href="http://pino-app.appspot.com/">Pino</a> &#8211; written in <a href="http://live.gnome.org/Vala/">Vala</a> &#8211; and I have borrowed the concept and layout from it. I call it <strong>Tweepi</strong>.</p>
<p>The only major difference between Tweepi and Pino &#8211; besides they are written in different programming languages &#8211; is that Pino uses WebKit to draw the status messages where I am using good old GTK widgets &#8211; and I guess there are no bindings to WebKit in Pike for that matter <img src='http://www.poppa.se/blog/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p>One thing I noticed is that the <code>Gtk.Label</code> widget sucks at displaying longer texts that line wraps. Since the label widget handles some HTML formatting I thought that it would be suitable for displaying the status messages, but the text looked like shit, line wrapping where ever it felt like. And the <code>Gtk.TextView</code> widget doesn&#8217;t handle formatting per default so I Googled some and found that you can format text in <code>Gtk.TextView</code>s by inserting <code>Gtk.TextTag</code>s at desired positions. And since Pike has the most awesome HTML parser It was just a matter of sending the text through the parser and create some <code>Gtk.TextTag</code>s and inserting them at the same position in the text buffer. (Well, actually it wasn&#8217;t that easy but with some help from a Python class I found on the web it was doable).</p>
<p>So now I have a start at something that is a <code>Gtk.HtmlTextView</code> &#8211; actually it inherits <code>Gtk.TextView</code> but has an additional method <code>insert_html_text(string text)</code> &#8211; and albeit quite simple at the moment it&#8217;s worth continuing on. The code for the <code>HtmlTextView</code> is available at my <a href="http://github.com/poppa/Pike-Modules/blob/master/Misc.pmod/GTK2.pmod/module.pmod">Github repository</a>.</p>
<p>In general I find the GTK implementation in Pike to be pretty OK, but there exist some verbose, and tedious, stuff like getting the text from a <code>Gtk.TextView</code>: </p>
<pre><code lang="pike">
Gtk.TextBuffer b = my_textview->get_buffer();
string text = b->get_text(b->get_start_iter(), b->get_end_iter(), 0);
</code></pre>
<p>which in Vala and C# would be done like:</p>
<pre><code lang="vala">
// Vala
string text = my_textview.get_buffer().text;

// C#
string text = myTextView.Buffer.Text;
</code></pre>
<p>Anyway! Tweepi isn&#8217;t done yet but I think I have solved the most tedious stuff and it&#8217;s starting to become useful. It&#8217;ll probably be done in a couple of weeks and I will of course release the sources then.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.poppa.se/blog/gtk-hacking-in-pike/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Roxen Application Launcher 0.4.4</title>
		<link>http://www.poppa.se/blog/roxen-application-launcher-0-4-4/</link>
		<comments>http://www.poppa.se/blog/roxen-application-launcher-0-4-4/#comments</comments>
		<pubDate>Wed, 13 Jan 2010 22:58:28 +0000</pubDate>
		<dc:creator>Pontus</dc:creator>
				<category><![CDATA[Applications]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Roxen]]></category>
		<category><![CDATA[Gnome]]></category>
		<category><![CDATA[GTK]]></category>
		<category><![CDATA[RAL]]></category>
		<category><![CDATA[Vala]]></category>

		<guid isPermaLink="false">http://www.poppa.se/blog/?p=368</guid>
		<description><![CDATA[So, here&#8217;s a new release of the Roxen Application Launcher for Linux (RAL). The previous versions used my home made (sloppy so) HTTP client which didn&#8217;t handle redirects or secure connections &#8211; thank you tec for the feed back &#8211; since I had some major problems getting libsoup working with binary files like images and [...]]]></description>
			<content:encoded><![CDATA[<p>So, here&#8217;s a new release of the Roxen Application Launcher for Linux (RAL). The previous versions used my home made (sloppy so) HTTP client which didn&#8217;t handle redirects or secure connections &#8211; thank you <a href="/blog/new-roxen-application-launcher-for-linux-written-in-vala/#comments">tec</a> for the feed back &#8211; since I had some major problems getting <code>libsoup</code> working with binary files like images and such. Binary files was heavily scrambled when read from or written to disk so I made my own simple HTTP client that kept the data as a byte array to prevent some underlying libraries (GLib) from fiddling with it.</p>
<p>But I solved the <code>libsoup</code> issue so now the RAL handles redirects and secure connections. This is how I solved it:</p>
<h2>The <code>libsoup</code> issue</h2>
<p>When uploading a file back to the <a href="http://roxen.com">Roxen</a> server I use <code>IOChannel (g_io_channel in plain C)</code> instead of <code>Gio</code>. So the upload works like this:</p>
<pre><code lang="vala">
var sess = new Soup.SessionSync();
var mess = new Soup.Message("PUT", get_uri());
mess.request_headers.append("Cookie", get_cookie());
mess.request_headers.append("Translate", "f");

IOChannel ch = new IOChannel.file(local_file, "r");
ch.set_encoding(null); // Enables reading of binary data
string data;
size_t len;
ch.read_to_end(out data, out len);

mess.request_body.append(Soup.MemoryUse.COPY, data, len);
sess.send_message(mess);
</code></pre>
<p>And that seems to work like a charm!</p>
<p>When downloading data it&#8217;s a bit more tricky! Of course I tried using <code>IOChannel</code> in this case also but that made no difference. Downloaded images ended up 4 bytes long! But then I thought: You can make your own C bindings in Vala (remember the Vala compiler generates C code) through what is called Vapi files. So what I did was writing a C function that takes a <code>SoupMessageBody</code> object/struct passed from Vala and writes the data part to a file given as argument.</p>
<pre><code lang="cpp">
gboolean save_soup_data(SoupMessageBody *data, const char *file)
{
  FILE *fh;

  if ((fh = fopen(file, "w")) == NULL) {
    fprintf(stderr, "Unable to open file \"%s\" for writing!\n", file);
    return FALSE;
  }

  int wrote = fwrite(data->data, 1, data->length, fh);

  if (wrote != (int)data->length) {
    fprintf(stderr, "wrote (%d) != data->length (%d). Data may have been "
                    "truncated", wrote, (int)data->length);
  }

  fclose(fh);
  return TRUE;
}
</code></pre>
<p>And this was then made available to Vala by the following Vapi file:</p>
<pre><code lang="vala">
[CCode (cprefix = "", lower_case_cprefix = "", cheader_filename = "")]
namespace Soppa // Soppa is Swedish for Soup <img src='http://www.poppa.se/blog/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' />
{
  [CCode (cname = "save_soup_data")]
  public bool save_soup_data(Soup.MessageBody data, string file);
}
</code></pre>
<p>And this is how the actual Vala code downloading the files looks like:</p>
<pre><code lang="vala">
var sess = new Soup.SessionSync();
var mess = new Soup.Message("GET", get_uri());
mess.request_headers.append("Cookie", get_cookie());
mess.request_headers.append("Translate", "f");
sess.send_message(mess);

if (mess.status_code == Soup.KnownStatusCode.OK) {
  // Here I call the C function made available through the Vapi file
  if (Soppa.save_soup_data(mess.response_body, local_file)) {
    message("The file was downloaded and written to disk OK");
  }
  else {
    message("Failed writing data to disk!");
  }
}
</code></pre>
<p>So that&#8217;s that on that! <img src='http://www.poppa.se/blog/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<h2>The notification</h2>
<p><img src="/blog/data/images/libnotify.png" class="alignright"/> I also &#8211; just for fun &#8211; implemented a notification mechanism through <code>libnotify</code>. Since I believe that can be rather annoying it&#8217;s not activated by default but can easily be activated by a checkbox in the user interface.</p>
<h2>The packages</h2>
<p>The Roxen Application Launcher for Linux can be downloaded at the <a href="http://github.com/poppa/Roxen-Application-Launcher/downloads"><strong>download page</strong></a> at <a href="http://github.com">Github</a> where also the <a href="http://github.com/poppa/Roxen-Application-Launcher"><strong>work in progress sources</strong></a> is available or downloaded below!</p>
<p><a href="/blog/data/roxenlauncher-0.4.4.tar.gz">Roxen Application Launcher 0.4.4</a></p>
<p>Stay black!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.poppa.se/blog/roxen-application-launcher-0-4-4/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Roxen Application Launcher for Linux</title>
		<link>http://www.poppa.se/blog/roxen-application-launcher/</link>
		<comments>http://www.poppa.se/blog/roxen-application-launcher/#comments</comments>
		<pubDate>Sun, 04 May 2008 17:57:56 +0000</pubDate>
		<dc:creator>Pontus</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Roxen]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Gnome]]></category>
		<category><![CDATA[GTK]]></category>
		<category><![CDATA[Share]]></category>

		<guid isPermaLink="false">http://www.poppa.se/blog/?p=165</guid>
		<description><![CDATA[I thought I should broaden my C# knowledge a bit and you know how it is: To learn new stuff you need a real project to work on or else you will lose the fire sooner than later. So I came up with a good project that is actually useful to me: Porting Roxen&#8217;s &#8220;Application [...]]]></description>
			<content:encoded><![CDATA[<p>I thought I should broaden my C# knowledge a bit and you know how it is: To learn new stuff you need a real project to work on or else you will lose the fire sooner than later. So I came up with a good project that is actually useful to me: Porting <a href='http://www.roxen.com'>Roxen</a>&#8217;s &#8220;Application Launcher&#8221; to C#. There&#8217;s nothing wrong with the original one, written in <a href='http://pike.ida.liu.se'>Pike</a>, except that it uses <a href='http://www.gtk.org/'>GTK</a> 1 which is quite hideous (in an aesthetic meaning) compared to the newer GTK 2. And I also though it would be cool to create a panel applet (in the notification area of <a href='http://www.gnome.org'>Gnome</a> so you could put the Application Launcher in the background).</p>
<p>BTW: For those of you not knowing what the heck Roxen&#8217;s Application Launcher (AL here after) is here&#8217;s a brief explanation: Files in <a href='http://www.roxen.com/products/cms/'>Roxen CMS</a> is stored in a <a href='http://www.nongnu.org/cvs/'>CVS</a> file system which means that you don&#8217;t deal with files the way you normally do. To manage files you use a web browser interface (which is a darn good one I might add) but sometimes you actually want to edit files in your standard desktop application. And it is here the AL comes to play. You can download a file through the browser interface so that the file is opened in the AL. AL will then open the file in the desktop application you have associated with the file&#8217;s content-type. When you make your changes and saves them the AL will directly upload the changes to the server. So in short I could have said: The Application Launcher is a means to edit files on a remote Roxen server with a preferred desktop application.</p>
<h2>The obstacles</h2>
<p>I must say I&#8217;ve learned a lot from this project! </p>
<p><strong>First off:</strong> If you download a file for editing and the AL is already started you don&#8217;t want to start a new instance of AL (this is something I have never ever thought about before &#8211; in general terms, not just concerning AL) but when you do think about it you find that it&#8217;s not a piece of cake to solve. I solved it the way it is solved in the original AL. The first instance of AL that is started also starts a &#8220;socket server&#8221; that listens for incoming traffic on a given port on the local IP. When a new instance is started it first checks if it can connect to said port and if it can it sends the arguments through the socket to the first instance which then handles the request. The second instance is simply terminated when it has send the data though the socket.</p>
<p>So there I had to do some socket programming. Great fun <img src='http://www.poppa.se/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p><strong>Secondly:</strong> Stuff happens in the background of AL &#8211; data send through the socket remember &#8211; which means that nothing happens when you try to update the Graphical User Interface. (NOTE! This is the first more advanced desktop application I&#8217;ve done.) After &#8220;Google-ing&#8221; around a bit I came to know that this was a real newbie problem <img src='http://www.poppa.se/blog/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' />  The thing is that the GUI can only be updated through the same thread that started it so when using background threads  &#8211; implicitly that&#8217;s what I&#8217;m doing although handled by the asynchronous callback infrastructure of C# &#8211; you need to make sure the GUI is updated through the main thread. This is the most simple way so solve it:</p>
<pre><code lang='cs'>Gtk.Application.Invoke(delegate{
  CallFunctionToUpdateGUI();
});</code></pre>
<p>That&#8217;s not too difficult when you know it <img src='http://www.poppa.se/blog/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p><strong>Thirdly:</strong> The AL is sending data back and forth through the HTTP protocol which means we have to use some sort of HTTP client. C# has a couple of ways to do this but unfortunately they came up short, or I couldn&#8217;t use them anyway. I didn&#8217;t manage to figure out exactly why I always caught an exception saying something like: <em>A protocol violation occurred!</em>. I&#8217;m far from the only one who have fought with this and it has something to do with the headers sent from the remote server. You can invoke &#8220;unsafe header parsing&#8221; but that was to much of a hassle so I created my own little HTTP client.</p>
<p>One big annoying thing with C# is that is seems almost impossible to turn data from streams into strings without having to use any one of the <code>System.Text.Encoding.*</code> classes/objects which in my case meant that images and files in binary form got seriously fucked up. I manged to solve this my never turning the data into a string but keeping it as a <code>System.Text.Encoding.*</code> all the way from request to response to saving to disk. It was rather irritating but at the same time nice when solved (and I learned a whole bunch about <code>System.Text.Encoding.*</code>, <code>System.Text.Encoding.*</code>, <code>System.Text.Encoding.*</code> and <code>System.Text.Encoding.*</code>.)</p>
<p><strong>Finally:</strong> Of course I learned a great deal more about C# but this blog post is starting to get pretty excessive so I will round it off by saying that <a href='http://monodevelop.org'>MonoDevelop</a> is starting to become pretty darn good! I just upgraded to the latest version of <a href='http://www.ubuntu.com'>Ubuntu</a> and that also meant that I got the latest MonoDevelop and I must say it&#8217;s more stable than ever (although it occasionally crashes) and a whole bunch of new features are in place. One I havn&#8217;t used before &#8211; although it might have existed before &#8211; is the &#8220;Deployment&#8221; stuff. It creates a package with configure and make files for optimal compilation. Really smooth!</p>
<h2>Source and screens</h2>
<p>I will finish off by adding the source files and a few screen shots:</p>
<p><a href='/blog/data/roxenlauncher-0.2.tar.gz'>Roxen Application Launcher</a></p>
<p><strong>Screen shot 1: Just a standard view</strong><br />
<a href="/blog/data/images/rl/RoxenLauncher-1.png"><img src="/blog/data/images/rl/RoxenLauncher-1.png/680" alt="Roxen Application Launcher 1"/></a></p>
<p><strong>Screen shot 2: The panel applet in action</strong><br />
<a href="/blog/data/images/rl/RoxenLauncher-2.png"><img src="/blog/data/images/rl/RoxenLauncher-2.png/680" alt="Roxen Application Launcher 2"/></a></p>
<p><strong>Screen shot 3: The Application Launcher in Swedish</strong><br />
<a href="/blog/data/images/rl/RoxenLauncher-3.png"><img src="/blog/data/images/rl/RoxenLauncher-3.png/680" alt="Roxen Application Launcher 3"/></a></p>
<p><strong>Screen shot 4: Adding support for a new content type</strong><br />
<a href="/blog/data/images/rl/RoxenLauncher-4.png"><img src="/blog/data/images/rl/RoxenLauncher-4.png/680" alt="Roxen Application Launcher 4"/></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.poppa.se/blog/roxen-application-launcher/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

