Although the previous release, using GTK3, came quite recently this release has some new things.
GSettings
I dumped the “keyfile” solution for the application settings in favour to GSettings. So the settings is no longer stored in a file in the application directory but rather in the system’s application settings backend. GSettings is part of GIO – the GNOME networking library – and since RAL depends on GIO no new dependency is needed. The upside is that I could put a file of source code in the bin! Plus, it’s fun learning new stuff!
Editors and content types
Previously I have kept an editor – name and command line – for every content type. Anders at Roxen thought it’d be better if editors and content types were separated. I’ve thought about that before but never bothered to do anything about it.
But now, along with GTK3, there’s a new (I think) AppInfo class and the new AppChooserButton and AppChooserDialog widgets so I thought it’d be cool to use those. So selecting an editor for a new content type is way more simple now, and it also looks nicer. Plus we get the icon for the editor in the content type list under the “Applications” tab
Simple logging
I also implemented some simple logging which can be viewed under the new “Logging” tab. This will be worked upon and at the moment not very useful information is written to the log, but at least it’s a start.
Default icons
The icons in the notification popup – which only are three to the number – is now fetched from the user’s default icon theme. They we’re bundled before.
SOUP all the way
Previously I have used a little hack for saving downloaded files to disk. The problem was that the Vapi bindings for libsoup casted the data to a string which totally scrambled binary content like images and such. My solution was to write a simple C-function which took a SoupMessageBody struct as argument and then wrote that to diskt always keeping the uint8[] type of the content.
I bug reported this way back and it’s now fixed in Vala so I dumped my solution and am now using Vala all the way. Gone is one C and one Vapi file.
While at it I changed from using blocking functions in libsoup to the async ones. You never really noticed blocking calls was used before, but right is right. Right?
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’d and Google’d but had trouble finding any examples. I even downloaded the source code of the Gnome System Monitor – where exactly what I wanted exist – but that was mostly written in C++ which I know very little of.
But I’m stubborn, and after a while I found and example in Python which I managed to interpret. Even though I know very little Python it’s not that hard to follow, and the example was short.
In short what’s needed is packing two CellRenderers in the same TreeViewColumn. Quite logical when you know about it. The example below is in Vala:
15 lines of 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);
I hacked up a simple application that shows all installed programs – that has a .desktop entry I guess – in a list (the screenshot above). The sources is available at my Github repository.
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 a bug which made it impossible to use the appliction launcher on sites not running on port 80 or 443.
No big news, but the GTK+ tree view of files is now sortable. The “minimize to tray” 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’s directory in the Sitebuilder.
Also fixed a bug where the locales didn’t get installed correctly and also fixed a bug which scrambled the configuration file a bit.
If you’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’t show up in the notification area – or tray or systray as it also may be called.
The reason for this is that Ubuntu now utilise a “whitelist” 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 gsettings in the following way:
1 lines of Bash
gsettings set com.canonical.Unity.Panel systray-whitelist ['app-1','app-2','app-3']
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’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!
This is not the latest version of Roxen Application Launcher. You'll find the latest version at the download page.
In this release of Roxen Application Launcher (come again?) for Linux I’ve gotten rid of a few dependencies, namely: gconf, libgee and libgnome. The reason I dumped gconf and libgnome was to make it easier to install in KDE. I’ve verified it installs in KDE, although I noticed the translation doesn’t work and the Roxen SVG logo doesn’t show up in the window top border.
Roxen Application Launcher in KDE
Libgee is a collections API written in Vala and since I used a newer version than what is available in most package managers, and I’m not sure all Linux distros provide libgee, I decided to dump it and implement the same functionality with the generic collection classes in Vala. And since the collections used in RAL is quite simple that worked out just fine.
I have also tried to implement bundled download, which is only used in Roxen Editorial Portal. Since I don’t have access to such an installation I haven’t been able to verify it works as expected. I re-implemented the same behavior as in the launcher written in Pike by the Roxen guys.
Oh, and if you already have an installation of my RAL your previously downloaded files and settings will not be available to the new install. Since I dumped gconf I now store the settings in a plain text file and I have put the RAL application directory in ~/.conf/roxenlauncher since ~/.conf is where you should put application specific data according to freedesktop.org. In previous versions of RAL I stored application data in ~/.roxenlauncher so if you want your previously downloaded files copy ~/.roxenlauncher/files to ~/.conf/roxenlauncher/files.
This is not the latest version of Roxen Application Launcher. You'll find the latest version at the download page.
So I had a go at the Roxen Application Launcher (come again?) for Linux. I added a context menu – when you right click – 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 that there’s nothing new. And since the application seems to be very stable I decided to bump the version number to 1.0.
This is not the latest version of Roxen Application Launcher. You'll find the latest version at the download page.
Okey, here comes an update of my Roxen Application Launcher (come again?) for Linux.
There’s no major changes to this release. The connection to the Roxen server is now stored in a shared object so that it can use a “keep-alive” connection. Not that I think it matters a great deal.
There’s now an option to change the behavior of the applications window close button so that it hides the application to the tray – or notification area as it’s called in Gnome – rather than closes the application.
I’ve found out that it’s great fun programming desktop applications and of course it gets more fun the more you learn. Now I’m doing a Twitter client in Pike – my favorite programming language – mostly because I wanted to try out GTK programming in Pike. I use the good Twitter client Pino – written in Vala – and I have borrowed the concept and layout from it. I call it Tweepi.
The only major difference between Tweepi and Pino – besides they are written in different programming languages – is that Pino uses WebKit to draw the status messages where I am using good old GTK widgets – and I guess there are no bindings to WebKit in Pike for that matter
One thing I noticed is that the Gtk.Label 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 Gtk.TextView widget doesn’t handle formatting per default so I Googled some and found that you can format text in Gtk.TextViews by inserting Gtk.TextTags 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 Gtk.TextTags and inserting them at the same position in the text buffer. (Well, actually it wasn’t that easy but with some help from a Python class I found on the web it was doable).
So now I have a start at something that is a Gtk.HtmlTextView – actually it inherits Gtk.TextView but has an additional method insert_html_text(string text) – and albeit quite simple at the moment it’s worth continuing on. The code for the HtmlTextView is available at my Github repository.
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 Gtk.TextView:
2 lines of Pike
Gtk.TextBuffer b = my_textview->get_buffer();
string text = b->get_text(b->get_start_iter(), b->get_end_iter(),0);
which in Vala and C# would be done like:
5 lines of Vala
// Vala
string text = my_textview.get_buffer().text;
// C#
string text = myTextView.Buffer.Text;
Anyway! Tweepi isn’t done yet but I think I have solved the most tedious stuff and it’s starting to become useful. It’ll probably be done in a couple of weeks and I will of course release the sources then.
This is not the latest version of Roxen Application Launcher. You'll find the latest version at the download page.
So, here’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’t handle redirects or secure connections – thank you tec for the feed back – since I had some major problems getting libsoup 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.
But I solved the libsoup issue so now the RAL handles redirects and secure connections. This is how I solved it:
The libsoup issue
When uploading a file back to the Roxen server I use IOChannel (g_io_channel in plain C) instead of Gio. So the upload works like this:
When downloading data it’s a bit more tricky! Of course I tried using IOChannel 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 SoupMessageBody object/struct passed from Vala and writes the data part to a file given as argument.
message("The file was downloaded and written to disk OK");
}
else{
message("Failed writing data to disk!");
}
}
So that’s that on that!
The notification
I also – just for fun – implemented a notification mechanism through libnotify. Since I believe that can be rather annoying it’s not activated by default but can easily be activated by a checkbox in the user interface.
For those of us tweeting – or sharing web addresses in general – these long addresses with extensive query strings you wan’t to share isn’t too user friendly. So we have Bit.ly, among others, that lets you shorten a URL – or give it an alias if you like – and also gives you statistics on how many clicks it has and if it’s shared on Twitter and what not.
Since I’m on the quest of learning the programming language Vala I though why not making a Bit.ly desktop client for GNOME. So I did!
The desktop client
There’s really nothing extraordinary about it, in fact it’s quite simple. Put a long URL in the input field and hit “OK”. You’ll get the shortened URL back in the same input field.
NOTE! The screenshots is showing the Swedish translation but the interface is orginally in English.
Shortening a long URL
The shortened URL
To use the application you will of course need a Bit.ly account. The first time Bitlyfier is launched it will ask for your Bit.ly account settings. Just fill in your username and API key (it’s found on your account page at http://bit.ly/account).
Bitlyfier account settings
The command line interface
For the hacker you, Bitlyfier can also be used as a command line tool. These are the options:
-n, --no-gui Sets the application in command line mode
-g, --gconf Invokes setting username and apikey
NOTE! You should quote the value of the ‘-s’ flag. If the URL to be shortened
contains a querystring with ampersands the URL will be truncated if it’s not
quoted.
The Bitly API class I’ve written can of course be used standalone (it’s located in src/bitly.vala in the sources package downloadable below). Here’s an example of usage:
This is not the latest version of Roxen Application Launcher. You'll find the latest version at the download page.
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 – with the purpose of making software development for, primarily, GNOME easier – and I’m an avid GNOME user I wanted to look deeper into the world of Vala.
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 Roxen Application Launcher I wrote in C#/Mono a couple of years ago in Vala – which by the way is syntactically very, very similar to C# and Java. I’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’t going to be totally pointless. The good thing about Vala is that the Vala compiler generates C code and that’s what you compile the program from. Fast code and hopefully more mature and stable libraries that won’t break backwards compatibility with every new release.
What about Vala
So, on I went about it and I think that Vala is a really promising language. It’s still a very young language so some library bindings isn’t behaving exactly as expected and the documentation isn’t directly redundant – although the Vala reference documentation site isn’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 .
What about the Roxen Application Launcher
In this new version I utilize GConf for storing application settings. I also made use of – for the first time – the GNU Build Tools 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’s no need for the Vala compiler to build the program.
Other than that there’s nothing fancy about it. The Vala sources is available at my Github repository.
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’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#.
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’t have to get head aches about memory management and so forth.
Vala seems pretty interesting and I downloaded it and compiled it without any difficulties. There are precompiled packages for most Linux distros – it’s available in the Ubuntu repository – but since Vala is new and still under development the distro packages is far behind in version.
Anyway, just to try Vala out I made a little program – using Val(a)ide – 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 *nth minutes.
This program needs libgee which at the moment needs to be added manually.
I just created an updated version of Roxen Launcher. I got an error report from one who tried to build the application:
./ApplCon.cs(232,24): error CS0122:
‘System.Net.Sockets.TcpListener.Server’ is inaccessible due
to its protection level
An explanation of the error can be found at MSDN. The reason seems to be due to TcpListener.Server being a protected property but I tried to access it as public. The strange thing is that I didn’t get an error about it nor on my machine at home or at work. Now I created a derived class of TcpListener.Server so that I can access the protected property.
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 learning new stuff so I really don’t care if there are 1000 font managers out there
Font parsing
The first thing to do, and that I have done, is porting my font parser from PLib to C#. That was no major head ache. There are at least to different font classes available in C# Mono (`System.Drawing.Font` and `Pango.Font`) but they don’t give all information about the font that I want.
Worth mentioning is that I heavily used the Mono DataConverter class to unpack the binary strings in the fonts. The unpack() function in PHP is just tremendous and there doesn’t seem to be a native alike in C#. But thanks to Miguel de Icasa’s DataConverter it went quite alright.
Font preview
The next thing to do was figuring out how to create the font previews. And I figured it out First I though of using the console program gnome-thumbnail-font to create the previews but I had to throw that one into the bin since it doesn’t seem to handle multi line text. Since I’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!
Next step
I have a lot left to do before this is a useful program but we’re heading there. One feature I’m planning on implementing is the ability to create your own font sets that you can activate/deactivate.
And I will probably come up with some more stuff to add, but that will be a later head ache!
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’s “Application Launcher” to C#. There’s nothing wrong with the original one, written in Pike, except that it uses GTK 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 Gnome so you could put the Application Launcher in the background).
BTW: For those of you not knowing what the heck Roxen’s Application Launcher (AL here after) is here’s a brief explanation: Files in Roxen CMS is stored in a CVS file system which means that you don’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’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.
The obstacles
I must say I’ve learned a lot from this project!
First off: If you download a file for editing and the AL is already started you don’t want to start a new instance of AL (this is something I have never ever thought about before – in general terms, not just concerning AL) but when you do think about it you find that it’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 “socket server” 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.
So there I had to do some socket programming. Great fun
Secondly: Stuff happens in the background of AL – data send through the socket remember – which means that nothing happens when you try to update the Graphical User Interface. (NOTE! This is the first more advanced desktop application I’ve done.) After “Google-ing” around a bit I came to know that this was a real newbie problem The thing is that the GUI can only be updated through the same thread that started it so when using background threads – implicitly that’s what I’m doing although handled by the asynchronous callback infrastructure of C# – you need to make sure the GUI is updated through the main thread. This is the most simple way so solve it:
3 lines of C#
Gtk.Application.Invoke(delegate{
CallFunctionToUpdateGUI();
});
That’s not too difficult when you know it
Thirdly: 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’t use them anyway. I didn’t manage to figure out exactly why I always caught an exception saying something like: A protocol violation occurred!. I’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 “unsafe header parsing” but that was to much of a hassle so I created my own little HTTP client.
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 System.Text.Encoding.* 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 System.Text.Encoding.* 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 System.Text.Encoding.*, System.Text.Encoding.*, System.Text.Encoding.* and System.Text.Encoding.*.)
Finally: 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 MonoDevelop is starting to become pretty darn good! I just upgraded to the latest version of Ubuntu and that also meant that I got the latest MonoDevelop and I must say it’s more stable than ever (although it occasionally crashes) and a whole bunch of new features are in place. One I havn’t used before – although it might have existed before – is the “Deployment” stuff. It creates a package with configure and make files for optimal compilation. Really smooth!
Source and screens
I will finish off by adding the source files and a few screen shots:
When working with revision controlled stuff you sometimes add loads of new files to an already existing repository. Then when you are about to check in the next revision you have forgotten where all the new files are and you probably don’t feel like writing svn add thefile too many times. This is of course no problem if you’r using a decent SVN client – like Tortoise SVN on Windows – but I prefer the command line so the solution was writing a script that adds all new files in a directory structure to the SVN repository.
There are “one liners” for this but I wanted a bit more flexibility and ease of use so I wrote the a script that also lets you define regexp patterns for files you don’t want to add even if they exist in the directory structure.
This is how to use it:
7 lines of Bash
# Add all new files
svnadd path/to/repository/
# Add all new files except those matching the regexp
svnadd -s ".*.txt|tmp/.*" path/to/repository/
# Add all new files except those matching the regexp in
# the file defined by the "-f" flag
svnadd -f regexp.txt path/to/repository/
Quite easy! If you don’t feel like remembering the pattern for files to skip, put the regexp in a file and use the svn add thefile flag.
Sometimes you regret running a 64-bit processor, but as almost always anything ca be fixed. The Zend Studio installer complains about finding some lib files:
8 lines of Plain text
Configuring the installer for this system's environment...
nawk: error while loading shared libraries: libm.so.6: cannot open shared object file: No such file or directory
dirname: error while loading shared libraries: libc.so.6: cannot open shared object file: No such file or directory
/bin/ls: error while loading shared libraries: librt.so.1: cannot open shared object file: No such file or directory
basename: error while loading shared libraries: libc.so.6: cannot open shared object file: No such file or directory
dirname: error while loading shared libraries: libc.so.6: cannot open shared object file: No such file or directory
basename: error while loading shared libraries: libc.so.6: cannot open shared object file: No such file or directory
hostname: error while loading shared libraries: libc.so.6: cannot open shared object file: No such file or directory
Of course there’s a fix for this, and this is how to do it (please change the version numbers according to your version):
Okey, when Zend Studio has been installed we need to redo these steps but for the executable ZDE file which is located in the bin directory of the directory where ZDE was installed. I installed it in my home directory so the path for me is:
1 lines of Plain text
/home/poppa/ZendStudio-5.2.0/bin/ZDE
Okey, so lets go to that directory and make a copy of ZDE and then:
1 lines of Bash
cat ZDE.bak |sed"s/export LD_ASSUME_KERNEL/#xport LD_ASSUME_KERNEL/"> ZDE
And now we’re fit to go (hopefully)!
If you by any chance during any of these steps get complaints about the xxx/bin/java not being found it can be fixed by explicitly declaring the path to Java: