2009-12-23

Messing up with Vala (again)

First some good news. I didn't look close enough into the possibilities offered by Automake 1.11 when I first wrote the post about building Vala projects. Automake 1.11 is all about making releases without the end-users having to compile Vala! Just like it is written in the Automake documentation. From now on I will always apply this wherever it is possible.

I updated the Xfce4 Vala bindings with libraries from the 4.7 stack. In there I have updated the panel plugin example, and as you can see the Automake file is extremely short. When there is a SOURCES defined with a Vala file, Automake will create targets for each compiled program or library with Vala compilation, and generate one vala.stamp file per target. This has its pros and cons. In the case of the Notes plugin, this disallowed me to have a mix of only C written software and Vala inside the same directory. In reality I used to have a single main file for the panel plugin to compile to C either for the 4.7 version or prior. Automake makes the Vala specific targets visible outside the scope of the "if PANEL47 ... else ... end" block. I ended up with self-compiled Vala for each target in maintainer mode only, as previously, which is a small overhead for the specific targets.

Other nice thing about Vala is that bindings are just files. I compiled the Notes plugin for the Xfce 4.6 panel on my netbook just to verify everything is alright but unfortunately there were some problems. I bumped the required version of Vala to 0.7.8 which has GTK+ bindings for 2.18 already while I only have GTK+ 2.16 available. The simple thing to do was to download the GTK+ bindings from the version of Vala I used previously and copy them into a location of the project (or system wide).  As long as the Vala compiler knows where to pick them up (with "--vapidir=") it will choose them and not the ones provided by default. This makes it awesomely easy to provide customized bindings for example.

Vala can always be very time consuming, but I still like it! Just like git merge by the way.

2009-10-22

Console keyboard layout and beep

Two quite annoying bits to remember so lets blog 'hem. Under a tty the keyboard may have a bad layout, I know perfectly changing it under X with setxkbmap but I usually Google for the console. The answer is loadkeys. Running loadkeys -d will print the current map file that gives an idea where to find the maps. Switching the map works like loadkeys /lib/kbd/keymaps/.../fr-latin1.map.gz, in other words just pass the map file. Now to come to the other annoying command to remember is the ability to cut off the beep. It works with setterm -blength 0.

Update: passing the locale directly to loadkeys works (thanks Boris), neither the help output nor the man page mentions this.

2009-10-13

Fast Python debugging with Vim

So I just needed to test some lines of Gtk+ code and preferably with Python. I love the interpreter (just as well as irb) but debugging even small Gtk+ pieces is not very attractive in the end. Therefore I jumped into Vim, typed my small script, and then executed the command ":%!python -". Only problem is that after the command exits it replaces the content of the Vim buffer with the console output that contains Python debugging messages as well, a quick press on "u" reverts this but maybe there is a cleaner way.

2009-10-11

MP3 support on Moblin (part 2)

Part 1 showed the easy way. Now the hard way to get MP3 support is to provide it yourself by building plugins for GStreamer. Having an RPM build environment is a prerequesite. The earlier blog entry shows how to set it up and also has an example to build and install libmad which will be useful in this example and I won't repeat it here.

Download the gstreamer-plugins-ugly source package. Put it inside the SRPMS directory and run the rpm -i command on it to unarchive its content.

Open a text editor and edit the spec file available under SPECS. The package names vary between Moblin, Fedora and RPM Fusion and this needs to be fixed in the header. And in this example only the plugin libmad will be build so that's why many lines will be commented. In fact the only build dependencies will be libmad, libid3tag and liboil. I have put the diff on Snipt. To apply it use the patch command like patch -p0 < gstreamer-plugins-ugly.spec.diff. Don't miss the patch(1) man page to know about the -p option.

Now build binary packages with the command rpmbuild -bb SPECS/gstreamer-plugins-ugly.spec. Wait a minute and you should have a ready to install gst-plugins-ugly package within the RPMS directory.

You can more or less repeat this task for DivX and other video codecs support. For that you'll have to build the GStreamer FFmpeg plugin (gstreamer-ffmpeg source package). Of course FFmpeg depends on many many libraries and you'll have to build them at first.

Update: Regarding FFmpeg, it can be build from the RPM source package without external requirements, in fact it doesn't have any hard dependencies. Or you can even compile the gstreamer-ffmpeg plugin only with the internal FFmpeg sources since it is optionaly linked to an external FFmpeg library. In both cases the provided SPEC files have to be modified.

RPM build environment on Moblin

I once set up an RPM build environment on my netbook to build missing packages, often small tools. There are many docs to do that, for myself I browsed the Fedora project wiki. If you are looking for RPMish stuff you are in the right place there.

Preparation

The package rpmdevtools provides scripts for the packager, one of them is rpmdev-setuptree. This tool will set up automatically the build directory for keeping source packages, spec files, etc. You can run this command now. Within your home, it will create an rpmbuild directory and a hidden .rpmmacros file. You can move the rpmbuild directory where ever you want but you will have to fix the variable %_topdir in the hidden rpmmacros file.

That's already about it.

Build example

Lets take a small example to show the use of the RPM build environment. Download the source package libmad from RPM Fusion. Copy it to the subdirectory SRPMS and then unarchive it with the command rpm -i SRPMS/libmad-[version].src.rpm. And finally you can build the binary packages with the command rpmbuild -bb SPECS/libmad.spec. The rpmbuild command is provided by the rpm-build package.

By now you can install the packages within the subdirectory RPMS, libmad-[version].rpm and the -devel package, if you wish to build the source package madplay to play MP3s from command line :-)

External sources

MP3 support on Moblin (part 1)

The easiest way to add support for MP3 is by installing a pre-build RPM package. Fluendo has one available for free. The reason Moblin isn't distributing a decoder is of legal issues, however one might get them by "legal" ways where that term will vary amongst different juridictions. It clearly is an annoying topic to raise up! If you buy a laptop you can expect to have MP3 support since the sellers have ways to collect royalties. At least that's what I learned from the Moblin mailing-list.

Installing an RPM is done by running the simple command "rpm -i [package]" with the super user.

2009-09-03

Build a project with Vala

This post is about using Vala in a project but in the end provide the C code for the releases. I think that this is very essential and that releasing source code to be build from Vala is wrong. Vala will always rewrite the code to GObjects in C, but has already proven that compiling the same code from two different versions of Vala will fail. So when you are doing releases with Vala you will break your releases sooner or later. Another good point is when the Vala code is compiled on top of patched vapi files, doing only C compilation with the releases will drop the requirement to apply them.

I'll take as example the Autotools, if you are using a different tool-chain you can surely adapt it. The idea is simple, the Vala sources are only compiled in maintainer mode. When you compile the application from the development branch you will usually have a script called autogen.sh to build the configure script that will automatically be executed with the parameter --enable-maintainer-mode. When providing the distribution tarball that is created with make distcheck, the configure script will not be run with that parameter (except if specified by hand) and the source files to build from will be filled in with the C filenames.

The example below is very generic and can be copy/pasted but should be adapted.

Autoconf script

1. The initialization of Automake and the maintainer mode in the autoconf script. The Automake version is checked for 1.11 which is the first version that comes with Vala support. The extra dist-bzip2 argument is there to provide an extra bzipped distribution tarball as you guessed it.
AM_INIT_AUTOMAKE([1.11 dist-bzip2])
AM_MAINTAINER_MODE()
2. The check for Vala only on maintainer mode. The AM_PROG_VALAC defines the variable VALAC that can be reused inside the Makefile.am files and accepts an optional version check.
if test "x$USE_MAINTAINER_MODE" = "xyes" ; then
AM_PROG_VALAC([0.7.4])
if test "x$VALAC" = "x" ; then
AC_MSG_ERROR([Cannot find the "valac" compiler in your PATH])
fi
fi
3. It is possible to sum up the build configuration at the end of the autoconf script.
echo
echo "Build Configuration:"
echo
echo "* Maintainer Mode: $USE_MAINTAINER_MODE"
if test "x$USE_MAINTAINER_MODE" = "xyes" ; then
echo
echo " * Vala: $VALAC"
echo
fi

Automake script

1. The declaration of the Vala sources and their respective compiled C sources.
product_VALASOURCES = \
obj1.vala \
obj2.vala \
main.vala

product_VALABUILTSOURCES = $(product_VALASOURCES:.vala=.c) product.h
2. Use the special BUILT_SOURCES variable to build given targets before running a dist with e.g. make distcheck. This usually done in maintainer mode, as in this case to be sure the releases won't have anything to do with Vala.
if MAINTAINER_MODE
PACKAGES = --pkg=gtk+-2.0
BUILT_SOURCES = vala.stamp
vala.stamp: $(product_VALASOURCES)
$(VALAC) --vapidir=$(srcdir) $(PACKAGES) $^ -C -H product.h
touch $@
endif
3. The final sources for the product are filled in with the generated Vala sources. The Vala sources are not passed to any SOURCES which is why they are passed to the special EXTRA_DIST variable.
product_SOURCES = \
random-source.c \
random-header.h \
$(product_VALABUILTSOURCES)

EXTRA_DIST = $(product_VALASOURCES)
if MAINTAINER_MODE
CLEANFILES = \
$(BUILT_SOURCES) \
$(product_VALABUILTSOURCES)
endif

That's it

There are many existent Vala projects nowadays from where you can pick up new ideas, and this post is just an example amongst many others. The full example is available in the xfce4-vala bindings.

Update: I corrected some mistakes seen in green in the script portions. If VALAC is unset the configure script must quit otherwise the resulting Makefiles will have empty commands instead of /usr/bin/valac. Also the generated header file must be passed to product_VALABUILTSOURCES otherwise it would have been left out from distributions as it wans't passed to any product_SOURCES nor EXTRA_DIST variables.

2009-07-28

Slim dropped from the Debian archive

I can make it official now, the Debian package Slim is going to be removed from their archive, even though the bugs are fixed for both Debian stable and unstable, in the end the package has to be taken off where that part of that story is fuzzy.

Now it is time to switch to qingy or gdm... or xdm.

As of a last effort I updated the two packages and put them on Alioth. Check the changes files if you want more information.

2009-07-12

Notes, notebook, tabs

The notes plugin features a notebook since the port to Xfce 4.4 and in the last release I hide the tabs and gave a try to a new navigation bar. Seems you like the tabs so no worries it will be back in the next release.

Update: Revision 7717 has an option to show the tabs.

2009-06-15

Run command, not alias

To execute a command and not its alias there are some ways. I just figured the nicest out there.

Say grep is aliases to "grep --color -Hn". This can be annoying in case the output must be send through a pipe to another command because it always prints the source and the line number.

One way of avoiding the alias is to pass the full path, e.g. "/bin/grep". Another way is to quote the command e.g. "'grep'" and the quicker and nicest way is to put the two quotes before the command e.g. "''grep".

2009-05-08

Making use of loop devices on Linux

This post is about the loop devices on Linux.

The loop devices are a possibility under Linux to mount regular files. It is often used to mount an iso image, but it can also be used to play with Raid, LVM, or a file system.

To use the loop devices it is mandatory to load the loop module: ”modprobe loop”. This will create the loop devices /dev/loop0, /dev/loop1, etc.

Remark: work inside a tmpfs like /dev/shm to gain speed when running tests.

File-System
Creating a file-system out of a file, plus being able to mount it, works as follow:
  1. Create a file of a hundred mega-bytes:
    • dd bs=1M count=100 if=/dev/zero of=output
  2. Format the file:
    • mkfs.ext2 output
  3. Mount the file with a loop device:
    • mkdir loop-mount
    • mount -o loop output loop-mount
    • When using the option ”-o loop” the first available loop device is taken. It is possible to select the loop device to use by giving the option ”-o loop=/dev/loop0”.
To check that the device is perfectly mounted, run ”mount”. It displays a line like that one:
/dev/shm/output on /dev/shm/loop-mount type ext2 (rw,loop=/dev/loop0)
It is possible to create files and directories within loop-mount, then unmount the device and remount it back.

Raid
Using loop devices is very convenient when training with Raid for instance. To create usable devices for a Raid, it works as for a file-system, except that instead of mounting the file as a loop device they must be setup with the tool ”losetup” that is part of the Linux utilities. In fact, it is not possible to prepare devices for a Raid that are already mounted, and losetup makes a loop device in /dev/ ready to be mounted in a way that it is possible to run ”mount /dev/loop0 mount-point” instead of ”mount -o loop file mount-point”.

Preparing a Raid5 works as follow:
  1. Create 3 files:
    • dd bs=1M count=100 if=/dev/zero of=0
    • dd bs=1M count=100 if=/dev/zero of=1
    • dd bs=1M count=100 if=/dev/zero of=2
  2. Format the files:
    • mkfs.ext2 0
    • mkfs.ext2 1
    • mkfs.ext2 2
  3. Setup loop devices:
    • losetup /dev/loop0 0
    • losetup /dev/loop1 1
    • losetup /dev/loop2 2
  4. Prepare the Raid5 device:
    • mdadm --create --verbose /dev/md0 --level=5 --raid-devices=3 /dev/loop0 /dev/loop1 /dev/loop2
  5. Mount the Raid5 device:
    • mount /dev/md0 mount-point

2009-04-17

Moblin Day 1+2

It's the second time I'm testing Moblin. The first time was with Alpha1, but now with Alpha2 I decided to install it. One main reason I kept Alpha2 was because of the availability of Xfce 4.6 ;-) Apart from that the experience is really great and it does boot fast. I turn the netbook on and after 1-2 seconds I already see an image on top of the Xorg session. It feels like hibernation but it's not :-)

The first day
I stumbled over the bug #1088 when I entered my key for the Wifi access. Of course I obviously had to type it wrong... One way to fix this was to clean up the configuration file of connman, within /var/lib/connman/. Otherwise nothing alarming.

After that I themed a little bit the desktop, like the awesome Nodoka-Midnight theme. Next I quickly figured the package manager, yum, and I headed toward a system upgrade. This step took a very long time, up to 3 hours. Alpha2 is as of today around 1 month old and there were over 300 packages to download. That took around 700 actions for yum like installing, updating and cleaning up.

Once the upgrade was done I installed the necessary devel packages to compile xfce4-gvfs-mount and xfce4-clipman-plugin both respectively from git and subversion. The Install/Remove Software GUI (gpk-application) is very nice, better than what I knew from Synaptic. Amongst the Moblin packages I found xfce-software-development which eases a little bit the selection of packages to install.

Well, one issue at the post upgrade was the default background disappearing, so I found out that it came from the package xfce4-desktop-branding-moblin. I'm kinda attached to that background now, I like the electronic-circuit like board, so I managed to copy/paste it. It's called moblin-energy-blue-1024x600.png.

The second day
A few issues:
- Firefox crashes "a lot".
- The gvfs-fuse-daemon is missing.
- Impossible to play MP3 or Divx.

I dunno how to fix Firefox and there are no appearing bug reports. I tried out the official binary provided by Mozilla and it crashes the same ways. GMail is crashing, Twitter is crashing when reloading the page after giving an up-to-date state, https on xfce.org, etc. So this is annoying. I will try to get a backtrace and install Midori since Moblin has a recent version of WebKit GTK+.

Now about the Gvfs topic, I was first fighting with an old build of xfce4-gvfs-mount on my home partition to finally notice that the gvfs mount was useless as gvfs-fuse-daemon was missing by default on the system. This means I can only access the files the hard way by using the gvfs programs to copy, list or delete files. I had to install the package gvfs-fuse.

And finally, the Moblin repository doesn't provide decoders for MP3 or Divx. Those are provided with the set of ugly plugins for GStreamer and is not available.
Hence I downloaded and installed the following packages from Fedora 10: a52dec, libmad, libmpeg2, lame-libs, libmpeg3 and of course gstreamer-plugins-ugly. The gstreamer-plugins-ugly package depends on a little more libraries but I didn't find them and I am already covered with the libs I downloaded.

Last but not least, I miss Wesnoth and the Xfce Power Manager :-)

Update: Screenshots

Update: Actually to get Totem to read Divx I needed to install gstreamer-ffmpeg! I have a dozen of rpms in a directory.

2009-04-16

Xfce Clipman Plugin 1.0.0

This post is about the latest release of Xfce Clipman Plugin, a Clipboard Manager for the Xfce desktop. I turn it more technical than for end-users. I hope people interested into GTK+, GObjects or Xfce panel plugins will like to read it. The release is going to happen very soon now.

The first major change concerns the plugin being entirely rewritten by using GObjects and Xfconf, this means cleaner, better understandable, maintainable code, etc. There is the "main function" (for sack of clarity) and four objects. A collector which listens to clipboard changes and put them in the history, the history is also an object, a menu (on top of GtkMenu) that displays the history and allows to clear it, and finally another object which is part of a new feature for the clipboard manager.

Now having my objects it's just about instantiating them in the main function and binding them to Xfconf. If there is something missing in an object it is just about modifying a particular aspect of it.

The goal of using Xfconf is to have a less cluttered code for settings, and to make good use of property bindings against the objects. For instance, the object History has a maximum count of items, and being bind against Xfconf, it is possible to run an external command with xfconf-query to change that setting, without having to call a public setter function. Binding a property is a one function call.

Following this major change is the settings dialog. I have written it from scratch with Glade, a UI designer for GTK+, by which I can easily modify and beautify the dialog without having to fight with lines of code several hours a day. In fact it takes a few seconds to change a label and up to 5 minutes to design a goddamn dialog. Glade makes an increased use of memory however, but stop thinking of this when you know you have 1MB times 1000 installed on your system — I have currently 1GB on a netbook and 2GB on a quite-fanless Atom-based workstation but I use only around 300MB in general. If you still fear about having an application that uses only 2 but 5MB with Glade, well I can't help you! From what I have read, the built-in UI designer of GTK+, named GtkBuilder, needs less memory, but the Glade to GtkBuilder conversions are going to happen with Xfce 4.8.

Now about the new feature introduced into this major release. It is called "Actions" which is the fourth object by the way. An action is a match between a text selection and regexes to let you execute specific commands. For example the action "Image" can match text with image filenames and let you choose commands between "View with Ristretto" and "Edit with Gimp". I wrote something simple in the settings dialog to add new actions that is inspired from the Thunar User Custom Actions interface.

Finally, I made other changes that are more geeky than useful, like I made a bundle out of the plugin. The plugin is now installed under the binary directory instead of the common place holder for panel plugins but can still be added inside a panel with the "Add Item" menu action. As you might understand, it can be executed as well now, and if you do so it will run inside the notification area. An item is installed in the applications menu to be able to start it (under the category Utility), and as it is possible to run outside the panel, I added a autostart file.

That's it already. If you have questions, don't mind. If you wanna discuss the Actions/regex feature go ahead. More importantly, I hope you'll take a glimpse at the code.

If you are interested into panel plugins, have a look at the wiki. The panel plugins amongst the goodies are a good way to get to know code and start with something.

Update: ANN: xfce4-clipman-plugin version 1.0.0 released

2009-04-10

IMAP Client

Lately I got a very broken GMail in my mail client Claws. I didn't check my mails for a few days and I got about 300 mails waiting for me. When I did the checkout it stopped at about 150 mails, then at around 250, reporting an error about timeout. Finally I got all the mails, but all the on-coming times I downloaded the mails it always restarted at 125 of 128 mails instead of 0 of 8 mails... The mail notification applets were also kind-of broken. And all of this was by using POP.

So I thought about un/rechecking that option, and actually I had the opportunity to switch that thing off and use IMAP instead. Which I did.

First impression ever, it's awesome. All the actions done in any IMAP client is synchronised in the web client, would it be moving a mail to a directory, create a directory, or mark a mail as unread. However, to be working perfectly with the web interface GMail, the client has to be tweaked.

When I started to use Claws as usual, I figured some problems, not that annoying, for instance that it creates its own Sent, Draft and Queued directories -- apparently I can't get rid of them. However more annoying, when composing a mail, as you compose, it saves a copy to Queued, and every time it saves a new copy the old one is archived in GMails "All messages". This means for long mails that you can have a thread of around 20 copies of your mail being more and more complete. I looked around in Claws, every little corner, but I didn't find anything. The only option left is to place the Sent, Draft and Queued messages in another directory. First I tried to put them in the predefined directories of GMail but it kept on putting them in the default place holders. Then I thought I had not really time to deal with these annoyances, I switched to another mail client. While writing this entry, I "debugged" and figured I can save the messages to a local directory, just like it works with the other mail client. In the end, I have a working and good mail client with Claws.

So today I retried Thunderbird, and with respect to IMAP, it does a real good job. It is possible to trash the mails permanently which means for GMail there is always a copy in "All messages". In fact I don't need yet another Trash directory in my mail client, as it is only a new and useless directory for the web client. More importantly, for Sent messages it can place it where I want and it works. And what I used in Claws to send messages with another email address -- creating an SMTP only account -- can be found in the "Identity Settings" of an account.

Which one to choose now? Claws has a status icon for the notification area, and Thunderbird -- even if possible -- will either come with a built-in one or provided by an extension perhaps with bugs. I will try one and the other I guess, and keep the one I finally prefer. It's IMAP now anyway, all what I do in one client is seen in the other clients ;-)

Update: Now this can sound surprising, Thunderbird is able to load a directory of 95000+ mails in a second (of course you have to wait to download them all the first time). Claws is lagging at this a lot, even with less like 40000+, it takes about a minute and more to display the mails.

2009-03-11

Refresh the Xfce background

In Xfce 4.4 there was a little hack that worked to refresh the background. I managed to get the same result for Xfce 4.6 with the following "hack":
#!/bin/sh
if [ -z "${DBUS_SESSION_BUS_ADDRESS}" ] ; then
        . ${HOME}/.dbus/session-bus/`ls -rt ${HOME}/.dbus/session-bus/ | tail -1`
        export DBUS_SESSION_BUS_ADDRESS
fi
PATH=/usr/local/bin:${PATH}
MONITOR=${1:-0}
PROPERTY="/backdrop/screen0/monitor${MONITOR}/image-path"
IMAGE_PATH=`xfconf-query -c xfce4-desktop -p ${PROPERTY}`
xfconf-query -c xfce4-desktop -p ${PROPERTY} -s ""
xfconf-query -c xfce4-desktop -p ${PROPERTY} -s "${IMAGE_PATH}"
Now when will this be useful? Barely never. Still enjoy it :-)

Update: script snipped updated to run within a cronjob.

Vala Notes Plugin

Or better, there is Vala in the Notes plugin. It's been a long time I thought about a hypertext view widget for the notes plugin, so it can highlight links and open them on click, and doing this in pure C/GObject is quite a PITA because there is a lot to take care about (more lines of code), and then you didn't start thinking about the whole functions of the object. Now this is retro with the presence of Vala. I played with Vala some time ago, doing some very rudimentary hello worlds, and I never had a chance to really write something in Vala, untill two days ago. I started to write a very dummy object on top of GtkTextView that implements the simple undo/redo feature I wrote inside notes.c and it was very fast and easy to backport from the C code to Vala, and this gave me a very good start with Vala (now that was one Vala too much, wasn't it? anyway...). Yesterday I added skel functions to support hyperlinks which I finished today. Finally I integrated the Vala object inside the notes plugin in a way that it compiles to C code when you are in MAINTAINER_MODE, which means for end-users they won't need Vala but only gcc.

Now for those interested into Vala, here is the file I played with: hypertext.vala. This source contains at the end of the HypertextView class, another class that contains a main function so it can be compiled to a binary. This proves how easy it is to test a class, and all you need to do is to run the following command: valac --pkg=gtk+-2.0 hypertextview.vala && ./hypertextview.
There are many samples available with the source of Vala and on Gnome Live. The tutorial covers important points, the FAQ too, but the documentation is a little less interesting if you already know GObject IMHO.
One important thing I learned about Vala was the difference between the out and ref arguments.

If you have a hard time at finding the right method definitions, look into /usr/share/vala/vapi/gtk+-2.0.vapi for instance for GTK+. There you can quickly find any function name you now from the C API, for instance if you want to have a look at gtk_text_view_get_iter_at_location search for get_iter_at_location. By scrolling up you will see that you are in the class Gtk.TextView. Vapis are very easy to read.

I am very interested into porting the objects of the Xfmpc project to Vala, and then start trying out the plugin sample (loading modules during runtime)... I hope my fellow will like that idea :-)

Now for the people interested to develop Vala classes with VIM I have some tips. First follow these instructions in order to get Vala syntax. Then I suggest you install the Tag List plugin, and to get it working with Vala you will need to add the following lines to your vimrc configuration:
" Work-around Tag List
let tlist_vala_settings='c#;d:macro;t:typedef;n:namespace;c:class;'.
\ 'E:event;g:enum;s:struct;i:interface;'.
\ 'p:properties;m:method'
If you don't know about folding then you miss a lot of VIM culture, in fact you can fold/unfold brackets by going over a bracket and typing zf% in command mode. And that's all folk, thanks for reading til here.

2009-03-05

./shoutcast-radio

Just like my older post about a "./jamendo-player", this time I am definitely more interested into good online radio stations. And SHOUTcast is the best that comes to my mind! It's been there for years, Winamp is the best music experience ever, and both have been promoting each other even though I don't know/remember what their relation are.

The good things about their widget is that it saves the recent radios and it also has a list of favorites but this one isn't working as-is with the code. It is possible to search for radios and to browse by genre. All of this stuff is saved under ~/.macromedia/Flash_Player/#SharedObjects/<random>/ct.yourminis.com/.



So of course I couldn't resist but embed their available Flash widget inside a window :-) Again the code is very short, it's just about loading — well not a URL this time — an HTML string cause the Flash application all alone doesn't work out, it needs parameters passed outside. I didn't include the callbacks to handle "_blank" links, which means it is not possible to open any links, but this is useless as the widget is fully functionnal.

You can download the source code here.

Here are some installation instructions:
  1. Look into main.c
  2. The first line of main.c is a comment with a command to compile
  3. If you want a menu item in you desktop menu:
    1. Edit the Exec keys in shoutcast-radio.desktop
    2. Copy the desktop file to ${XDG_DATA_HOME:-~/.local/share}/applications
  4. If you don't have a gnome-radio icon, copy gnome-radio.png to ~/.icons/
By the way, I'm linking on the Xfce blog. Why? Cause there might be Xfce users interested into a simple to compile radio application. At least I hope some of you will enjoy it, more than the jamendo thingy :)

Update: The favorites actually do work, it just that the favorite button isn't always clickable.

2009-02-19

Colored Notes

I passed the last night to hack on a gtkrc snippet for the Notes plugin, because I couldn't find my sleep well. So being borred I killed a little bit the time to have a colored notes window :-) I know it was possible since always, I just never carred to do it. Using colors showed one annoying problem which are the icons. They don't fit always once you go away from the default gtk theme colors. In consequence I switched them to bold text labels with minus, plus and times. One other thing I didn't succeed with was to theme the menu that is available on the top right corner or Ctrl+M.

Finally the result is nice.

The snippet is the following:
gtk_color_scheme = "notes_fg_color:#E8E58C\nnotes_bg_color:#77741D\nnotes_base_color:#EBE88C\nnotes_text_color:#6B6A4A\nnotes_selected_bg_color:#ACA94E\nnotes_selected_fg_color:#E8E58C"

style "notes-default"
{
xthickness = 2
ythickness = 2

fg[NORMAL] = @notes_fg_color
fg[ACTIVE] = @notes_fg_color
fg[PRELIGHT] = @notes_fg_color
fg[SELECTED] = @notes_selected_fg_color
fg[INSENSITIVE] = shade (3.0,@notes_fg_color)

bg[NORMAL] = @notes_bg_color
bg[ACTIVE] = shade (1.0233,@notes_bg_color)
bg[PRELIGHT] = mix(0.90, shade (1.1,@notes_bg_color), @notes_selected_bg_color)
bg[SELECTED] = @notes_selected_bg_color
bg[INSENSITIVE] = shade (1.03,@notes_bg_color)

base[NORMAL] = @notes_base_color
base[ACTIVE] = shade (0.65,@notes_base_color)
base[PRELIGHT] = @notes_base_color
base[SELECTED] = @notes_selected_bg_color
base[INSENSITIVE] = shade (1.025,@notes_bg_color)

text[NORMAL] = @notes_text_color
text[ACTIVE] = shade (0.95,@notes_base_color)
text[PRELIGHT] = @notes_text_color
text[SELECTED] = @notes_selected_fg_color
text[INSENSITIVE] = mix (0.675,shade (0.95,@notes_bg_color),@notes_fg_color)
}

widget "xfce4-notes-plugin*" style:highest "notes-default"
widget "xfce4-notes-plugin*.*GtkMenu*" style:highest "notes-default"
widget "xfce4-notes-plugin*.*GtkMenuItem*" style:highest "notes-default"
# TODO Set the colors for the menu
The shade() and mix() functions are specific to either Clearlooks or Aurora. But this can be fixed. Actually I didn't include a default rc style inside the notes plugin, in fact this snippet can be saved for instance as notesrc inside your current theme and you add include "notesrc" in the gtkrc file.

All for the sharing, please enjoy.

Update: The shade() and mix() functions are a feature from GTK+ 2.10 just like gtk_color_scheme.

Update: I released a new version 1.6.4 that has a configurable background color setting.

2009-01-19

Fix bitmap^Whorrible fonts

You have horrible fonts in Firefox and don't know how to fix it? It is fairy simple:
cd /etc/fonts/conf.d
cp ../conf.avail/70-no-bitmaps.conf .
And this is it. Restart X.

2009-01-09

./jamendo-player

I was enough bored from my (small) music collection that I wanted to listen to something new, without actually caring what it is. I know Jamendo has a big load of music with artists uploading music under creative commons licence. So I went on their website to have a look, and they have "widgets". They are a small flash application not bigger than 200x300, but I actually didn't find any link to open such a widget inside an external window, except some lost links on some pages. In conclusion it was enough annoying to get an external player that I fired up vim and wrote a 20 lines C program.

/* gcc `pkg-config --cflags --libs webkit-1.0` main.c -o jamendo-player */

#include <gtk/gtk.h>
#include <webkit/webkit.h>

#define URL_FORMAT "http://widgets.jamendo.com/fr/playlist/?playertype=2008&playlist_id=%s"

int main (int argc, char *argv[])
{
GtkWidget *window;
GtkWidget *webview;
gchar *url;
gchar *playlist_id = argv[1];
if (argc < 2)
{
playlist_id = g_strdup ("65196");
g_message ("Loading the default playlist %s", playlist_id);
}
url = g_strdup_printf (URL_FORMAT, playlist_id);
gtk_init (&argc, &argv);
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
g_signal_connect (window, "delete-event", G_CALLBACK (gtk_main_quit), NULL);
gtk_window_set_icon_name (GTK_WINDOW (window), "multimedia-player");
gtk_window_set_title (GTK_WINDOW (window), "Jamendo Player");
gtk_window_set_resizable (GTK_WINDOW (window), FALSE);
webview = webkit_web_view_new ();
gtk_widget_set_size_request (webview, 200, 300);
gtk_container_add (GTK_CONTAINER (window), webview);
webkit_web_view_open (WEBKIT_WEB_VIEW (webview), url);
gtk_widget_show_all (window);
gtk_main ();
return 0;
}


The result is pleasing, the flash application has nice colors, and is something I would never be able to do with GTK+ :-)

If you like the code, feel free to extend it and send patches, I will enjoy any contribution. For now I will just leave a desktop file inside my applications directory to open it when I am bored again of my music :-p

Update: I hacked a little on the program to handle the links inside the Flash application. This means it is possible to change the playlist, which was one the thing that started to annoy me very much.

However, this update requires WebKit 1.0.3 and GLib 2.16.



This time I'm making the code available here instead of pasting it as it has grown up to 120 lines.