<?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; Mono</title>
	<atom:link href="http://www.poppa.se/blog/tag/mono/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>New Roxen Application Launcher for Linux written in Vala</title>
		<link>http://www.poppa.se/blog/new-roxen-application-launcher-for-linux-written-in-vala/</link>
		<comments>http://www.poppa.se/blog/new-roxen-application-launcher-for-linux-written-in-vala/#comments</comments>
		<pubDate>Sun, 20 Dec 2009 20:21:04 +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[Mono]]></category>
		<category><![CDATA[RAL]]></category>
		<category><![CDATA[Vala]]></category>

		<guid isPermaLink="false">http://www.poppa.se/blog/?p=301</guid>
		<description><![CDATA[A couple of weeks ago I stumbled upon a fairly new programming language named Vala. I thought it looked promising and since Vala is developed by the GNOME project &#8211; with the purpose of making software development for, primarily, GNOME easier &#8211; and I&#8217;m an avid GNOME user I wanted to look deeper into the [...]]]></description>
			<content:encoded><![CDATA[<p>A couple of weeks ago I stumbled upon a fairly new programming language named <a href="http://live.gnome.org/Vala/">Vala</a>. I thought it looked promising and since Vala is developed by the <a href="http://www.gnome.org/">GNOME</a> project &#8211; with the purpose of making software development for, primarily, GNOME easier &#8211; and I&#8217;m an avid GNOME user I wanted to look deeper into the world of Vala.</p>
<p>I, and most programmers I believe, work in that way that I need a real and useful project when learning a new programming language. So I thought why not re-writing the <a href="/blog/stuff/#roxen-applauncher">Roxen Application Launcher</a> I wrote in C#/Mono a couple of years ago in Vala &#8211; which by the way is syntactically very, very similar to C# and Java. I&#8217;d gotten tired of always having to fiddle with the C# code with every new version of Mono since something always broke when Mono was updated so a re-write wasn&#8217;t going to be totally pointless. The good thing about Vala is that the Vala compiler generates C code and that&#8217;s what you compile the program from. Fast code and hopefully more mature and stable libraries that won&#8217;t break backwards compatibility with every new release.</p>
<h2>What about Vala</h2>
<p>So, on I went about it and I think that Vala is a really promising language. It&#8217;s still a very young language so some library bindings isn&#8217;t behaving exactly as expected and the documentation isn&#8217;t directly redundant &#8211; although the <a href="http://references.valadoc.org/">Vala reference documentation site</a> isn&#8217;t half bad. But since Vala pretty much is a wrapper for, or binding to, the underlying C libraries you can find answers to your questions that way. All in all I think Vala has a promising future: Way more simple than C and almost as fast and light on memory (remember the Vala compiler generates C code) and way faster than C#/Mono and free from any Microsoft associations <img src='http://www.poppa.se/blog/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> .</p>
<h2>What about the Roxen Application Launcher</h2>
<p>In this new version I utilize <a href="http://en.wikipedia.org/wiki/GConf">GConf</a> for storing application settings. I also made use of &#8211; for the first time &#8211; the <a href="http://en.wikipedia.org/wiki/GNU_Build_Tools">GNU Build Tools</a> for compilation which also makes it easier to distribute and for others to compile from the sources. This also means that the distributed version compiles from the C sources and not the Vala sources so there&#8217;s no need for the Vala compiler to build the program.</p>
<p>Other than that there&#8217;s nothing fancy about it. The Vala sources is available at my <a href="http://github.com/poppa/Roxen-Application-Launcher">Github repository</a>. </p>
<p><a href="/blog/data/roxenlauncher-0.4.2.tar.gz">Roxen Appliction Launcher 0.4.2</a></p>
<h3>Screenshots</h3>
<p>The screenshots is showing the Swedish translation.</p>
<p><strong>List of downloaded files</strong><br />
<a href="/blog/data/images/ral-vala-1.png"><img src="/blog/data/images/ral-vala-1.png/680" alt="Screenshot 1 of the Roxen Application Launcher" /></a></p>
<p><strong>Adding support for new file type</strong><br />
<a href="/blog/data/images/ral-vala-2.png"><img src="/blog/data/images/ral-vala-2.png/680" alt="Screenshot 2 of the Roxen Application Launcher" /></a></p>
<p><strong>The GNOME status icon</strong><br />
<a href="/blog/data/images/ral-vala-3.png"><img src="/blog/data/images/ral-vala-3.png/680" alt="Screenshot 3 of the Roxen Application Launcher" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.poppa.se/blog/new-roxen-application-launcher-for-linux-written-in-vala/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Vala &#8211; the new programming language for Gnome</title>
		<link>http://www.poppa.se/blog/vala-the-new-programming-language-for-gnome/</link>
		<comments>http://www.poppa.se/blog/vala-the-new-programming-language-for-gnome/#comments</comments>
		<pubDate>Sun, 25 Oct 2009 21:29:59 +0000</pubDate>
		<dc:creator>Pontus</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Gnome]]></category>
		<category><![CDATA[Mono]]></category>
		<category><![CDATA[Vala]]></category>

		<guid isPermaLink="false">http://www.poppa.se/blog/?p=268</guid>
		<description><![CDATA[This Friday when I read the last issue (in Sweden) of Linux Format there was an article on a new programming language named Vala. The goal for Vala is to provide a modern programming language for, primarily, developing Gnome applications. There is of course Mono, but Vala doesn&#8217;t run in a virtual machine but is [...]]]></description>
			<content:encoded><![CDATA[<p>This Friday when I read the last issue (in Sweden) of <a href="http://www.linuxformat.co.uk/">Linux Format</a> there was an article on a new programming language named <a href="http://live.gnome.org/Vala/">Vala</a>. The goal for Vala is to provide a modern programming language for, primarily, developing <a href="http://www.gnome.org/">Gnome</a> applications. There is of course <a href="http://www.mono-project.com/">Mono</a>, but Vala doesn&#8217;t run in a virtual machine but is complied to machine code. But Vala resembles C# syntactically and has borrowed a lot of concepts from C#.</p>
<p>From what I understand Vala code is first translated into plain old C code, and then compiled with the ordinary GCC compiler. The benefit is that you don&#8217;t have to get head aches about memory management and so forth.</p>
<p>Vala seems pretty interesting and I downloaded it and compiled it without any difficulties. There are precompiled packages for most Linux distros &#8211; it&#8217;s available in the Ubuntu repository &#8211; but since Vala is new and still under development the distro packages is far behind in version.</p>
<p>There&#8217;s also <a href="http://www.valaide.org/">a Vala IDE</a> and <a href="http://live.gnome.org/Vala/#head-6c397c4077ef096e78ea90d62f6d511a82e1e9ea">plugins for GEdit, Anjuta and Eclipse</a>. </p>
<p>Anyway, just to try Vala out I made a little program &#8211; using <a href="http://www.valaide.org/">Val(a)ide</a> &#8211; that changes the desktop wallpaper on a per interval basis. Send the program a path to a directory with images and the background will change among those images every <code>*nth</code> minutes.</p>
<p>This program needs <a href="http://live.gnome.org/Libgee"><code>libgee</code></a> which at the moment needs to be added manually.</p>
<p><code>Compile: valac --pkg gconf-2.0 --pkg gee-1.0 --pkg gio-2.0 main.vala -o wallpaper-iterator</code></p>
<pre><code lang="vala">
/* main.vala
 *
 * Copyright (C) 2009 Pontus Östlund <spam@poppa.se>
 *
 * No license what so ever. Do what ever you like...
 *
 * Author:
 * 	Pontus Östlund <spam@poppa.se>
 */

// GLib isn't really neccessary since it's imported automatically
using GLib, Gee, GConf;

/**
 * User defined exception types
 */
errordomain IOError {
	FILE_NOT_FOUND,
	NOT_A_DIRECTORY
}

/**
 * Main class
 */
public class Main
{
	/**
	 * Used as reference in option parser
	 */
	static int arg_delay;

	/**
	 * Application command line options
	 */
	const OptionEntry[] options = {
		{ "delay", 'd', 0, OptionArg.INT, ref arg_delay,
			"Number of minutes to wait before swapping background", null },
		{ null }
	};

	/**
	 * Main method
	 *
	 * @param args
	 *  Command line arguments
	 */
  public static int main (string[] args)
  {
		try {
			var opt = new OptionContext("\"/path/to/wallpapers\"");
			opt.set_help_enabled(true);
			opt.add_main_entries(options, null);
			opt.parse(ref args);
		}
		catch (GLib.Error e) {
			stderr.printf("Error: %s\n", e.message);
			stderr.printf("Run '%s --help' to see a full list of available "+
			              "options\n", args[0]);
			return 1;
		}

		if (args.length < 2) {
			stderr.printf("Missing argument!\n");
			stderr.printf("Run '%s --help' for usage\n", args[0]);
			return 1;
		}

		// Default time before changing background is 30 minutes
		int delay = arg_delay > 0 ? arg_delay*60 : 60*30;

		try {
			WallpaperIterator bg = new WallpaperIterator(args[1], delay);
			bg.run();
			bg.stop();
		}
		catch (IOError e) {
			stderr.printf("Error: %s\n", e.message);
			return 1;
		}
		finally {
			stderr.printf("Finally block reached!\n");
		}

    return 0;
  }
}

/**
 * Class that handles changeing of desktop wallpapers on a per interval way
 */
public class WallpaperIterator : GLib.Object
{
	/**
	 * Number of seconds to wait before changeing wallpaper
	 */
	private int delay = 0;
	/**
	 * Current index in the images list
	 */
	private int index = 0;
	/**
	 * List of images to change between
	 */
	private ArrayList<string> files = new ArrayList<string>();
	/**
	 * List of allowed content types
	 */
	private ArrayList<string> allow = new ArrayList<string>();
	/**
	 * GConf client object
	 */
	private GConf.Client gclient = null;
	/**
	 * GConf registry where the background image is set
	 */
	private string gconf_key = "/desktop/gnome/background/picture_filename";
	/**
	 * Background being used when the application is started
	 */
	private string default_bg = null;

	/**
	 * Constructor
	 *
	 * @param dir
	 *  The directory to collect wallpapers in
	 * @param delay
	 *  Time to wait - in seconds - before swapping wallpaper
	 */
	public WallpaperIterator(string dir, int delay)
		throws IOError
	{
		assert(delay > 0);

		allow.add("image/jpeg");
		allow.add("image/png");

		var f = File.new_for_path(dir);

		if (!f.query_exists(null))
			throw new IOError.FILE_NOT_FOUND(" \"%s\" doesn't exits!".printf(dir));

		if (f.query_file_type(0, null) != FileType.DIRECTORY) {
			throw new IOError.NOT_A_DIRECTORY(" \"%s\" is not a directory!"
			                                  .printf(dir));
		}

		collect(f.get_path());

		if (files.size < 2) {
			warning("Not enough images found for this application to be useful!\n");
			return;
		}

		this.delay = delay;
	}

	/**
	 * Run the application. Starts a MainLoop
	 */
	public void run()
	{
		gclient = GConf.Client.get_default();
		default_bg = gclient.get_string(gconf_key);

		MainLoop loop = new MainLoop(null, false);
		var time = new TimeoutSource(delay*1000);
		time.set_callback(() => { swap(); });
		time.attach(loop.get_context());
		loop.run();
	}

	/**
	 * Stop the application. Tries to reset the background
	 */
	public void stop()
	{
		try {
			if (default_bg != null)
				gclient.set_string(gconf_key, default_bg);
		}
		catch (GLib.Error e) {
			warning("Failed to restore background!\n");
		}
	}

	/**
	 * Does the actual background swapping
	 */
	private void swap()
	{
		if (index >= files.size) {
			debug("Restart...\n");
			index = 0;
		}

		debug("Callback...%-2d (%s)\n", index, files[index]);

		try {
			gclient.set_string(gconf_key, files[index]);
		}
		catch (GLib.Error e) {
			warning("Failed to set background: %s\n", e.message);
		}
		index++;
	}

	/**
	 * Collect images
	 *
	 * @param path
	 */
	private void collect(string path)
	{
		try {
			var dir = File.new_for_path(path).enumerate_children(
				"standard::name,standard::type,standard::content-type",
				0, null
			);

			FileInfo fi;
			string fp;
			while ((fi = dir.next_file(null)) != null) {
				fp = path + "/" + fi.get_name();
				if (fi.get_file_type() == FileType.DIRECTORY)
					collect(fp);
				else {
					if (fi.get_content_type() in allow)
						files.add(fp);
					else
						warning("Skipping \"%s\" due to unallowed content type\n", fp);
				}
			}
		}
		catch (GLib.Error e) {
			warning("Error: %s\n", e.message);
		}
	}
}
</code></pre>
<p>I think Vala looks promising and I will try it out trying to write a more complex application when I find the time.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.poppa.se/blog/vala-the-new-programming-language-for-gnome/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Gnome Font Manager</title>
		<link>http://www.poppa.se/blog/gnome-font-manager/</link>
		<comments>http://www.poppa.se/blog/gnome-font-manager/#comments</comments>
		<pubDate>Sun, 11 May 2008 20:34:32 +0000</pubDate>
		<dc:creator>Pontus</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Gnome]]></category>
		<category><![CDATA[Mono]]></category>

		<guid isPermaLink="false">http://www.poppa.se/blog/?p=174</guid>
		<description><![CDATA[One thing I miss on Linux Gnome is font manager. Not just a font viewer but a proper manager like the old Adobe Type Manager. So I thought: Well, lets create one then! It might be that it already exist some font managers for Linux/Gnome but as always; this will be a good project for [...]]]></description>
			<content:encoded><![CDATA[<p>One thing I miss on Linux <a href='http://www.gnome.org'>Gnome</a> is font manager. Not just a font viewer but a proper manager like the old <a href='http://www.adobe.com/uk/products/atmlight/'>Adobe Type Manager</a>. So I thought: Well, lets create one then! It might be that it already exist some font managers for Linux/Gnome but as always; this will be a good project for learning new stuff so I really don&#8217;t care if there are 1000 font managers out there <img src='http://www.poppa.se/blog/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<h2>Font parsing</h2>
<p>The first thing to do, and that I have done, is porting my <a href='http://plib.poppa.se/doc/index.php?__plibmodule=Graphics.Font'>font parser</a> from <a href='http://plib.poppa.se'>PLib</a> to C#. That was no major head ache. There are at least to different font classes available in C# <a href='http://www.mono-project.com'>Mono</a> (`System.Drawing.Font` and `Pango.Font`) but they don&#8217;t give all information about the font that I want. </p>
<p>Worth mentioning is that I heavily used the Mono <a href='http://www.mono-project.com/Mono_DataConvert'>DataConverter</a> class to unpack the binary strings in the fonts. The <a href='http://php.net/unpack'><code>unpack()</code></a> function in <a href='http://www.php.net'>PHP</a> is just tremendous and there doesn&#8217;t seem to be a native alike in C#. But thanks to <a href='http://en.wikipedia.org/wiki/Miguel_de_Icaza'>Miguel de Icasa</a>&#8217;s DataConverter it went quite alright. </p>
<h2>Font preview</h2>
<p>The next thing to do was figuring out how to create the font previews. And I figured it out <img src='http://www.poppa.se/blog/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' />  First I though of using the console program <code>gnome-thumbnail-font</code> to create the previews but I had to throw that one into the bin since it doesn&#8217;t seem to handle multi line text. Since I&#8217;ve never used the graphics functions in C# before I came to the conclusion that I had to create the previews all by my self. It was quite easy finding good examples on the net of how to create text images with C#. A couple of hours later that problem was also solved (as you can see in the screen shot below). And man the graphics stuff in C# is fast. The preview images are generated instantly!</p>
<h2>Next step</h2>
<p>I have a lot left to do before this is a useful program but we&#8217;re heading there. One feature I&#8217;m planning on implementing is the ability to create your own font sets that you can activate/deactivate.</p>
<p>And I will probably come up with some more stuff to add, but that will be a later head ache!</p>
<p><strong>Screen shot: Gnome Font Manager</strong><br />
<a href="/blog/data/images/gnome-font-manager.png"><img src="/blog/data/images/gnome-font-manager.png/680" alt="Gnome Font Manager"/></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.poppa.se/blog/gnome-font-manager/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
	</channel>
</rss>

