Ximba Radio: Developing a GTK+/Glade GUI to XM Satellite Radio

They say Glade can make desktop application prototyping a quick and painless process. To scratch my own itch with XM Satellite Radio on my PC, I decided to see exactly how fast and painless.

Keeping track of individual widgets became necessary for multiple reasons. First, some icons change dynamically depending on varying states of the program. Second, many windows are displayed only temporarily and creating and destroying them is overkill. It's far easier to create them once and then simply hide and display them as needed. Finally, Glade-generated CLists need to be updated at runtime. The variables that hold the widget IDs are scoped only within the interface.c file, which means functions outside this Glade-generated file can't make changes easily to those widgets.

To solve this problem I set a realize signal for every widget I need access to at runtime. Glade lets you specify the name of the variable to be defined in interface.c. The callback associated with the realize signal is passed that variable value as the object parameter. In the callback, the value is saved in a global variable defined in xr.h, the single header file I created for this project. All globals are scoped using #ifdefs, with #defines specified at the top of the C module, as shown in the two code snippets of Listings 2 and 3.

Figure 8. Realize signals are used to pass the widget ID to a callback that saves the ID in a global variable.

One problem with this methodology is defining at what point a widget ID becomes available. The callback for the realize signal is called only right before the widget actually becomes visible. Sometimes you need access to that widget ID before this happens. Fortunately, this is solved easily. The widget is created in interface.c before the signal handlers are set up. A signal handler is a function that associates a callback with some event.

Because of this, the locally named variables all have valid values by the time a realize signal is configured. It therefore becomes possible to set multiple callbacks for a single widget, all of which are set to the realize signal for that widget, which saves the widget IDs of other widgets. For example, the main window widget for Ximba Radio has realize callbacks set for it that save the widget IDs of all the predefined CList widgets in the Channel Listing window; there are four such widgets. This is required because, initially, those CLists are not visible even after the main window is made visible, and I need to start updating the lists right away. If I didn't use the main window to save the widget IDs of the CLists, I wouldn't be able to start updating them with channel information until those lists were displayed at least once.

Figure 9. Right before the main window is displayed, the widget IDs of its CList subwindows are saved in global variables by multiple callbacks.

Dynamic changes to widgets also require saving the widget ID. One example of this is the state icon for Ximba Radio. To change the state icon I needed to use only GTK+ stock icons and save the widget ID of the Glade-generated GtkImage widget. When the user changes the program state—either by disconnecting from the dæmon or enabling or disabling the mute—the state icon is changed easily with a single GTK+ function call, as shown in Listing 4. The complete set of GTK+ stock icons is listed in the on-line GTK+ documentation.



Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

XM Satellite Radio

medium readings's picture

In a little under four years, his show went from 47 stations to more than 200 (it's now at 350) and XM satellite radio. In 2006, when he began a TV gig on ...

Re: Ximba Radio: Developing a GTK+/Glade GUI to XM Satellite Rad

Anonymous's picture

Is it possible to download the sourcecode for Ximba? I'm a current subscriber to XM Radio for my car and would like to have this for my PC in the future. Thanks!!

Re: Ximba Radio: Developing a GTK+/Glade GUI to XM Satellite Rad

Anonymous's picture

Try going to the Authors website

Usability and design of Gnome Applications

Anonymous's picture

some suggestions on how to make your application fit in better with other Gnome applications.

a menubar with only two top level menus is a waste of prime real estate

if at all possible add in some more menus like perhaps
an edit menu with undo, redo, cut, copy, paste, select all, preferences
a view menu, with ...
a Radio menu with ...

a row of buttons! you really should use a real toolbar.
not only will it look better but it will allow users to choose to have text labels or not

the Ximba Radio graphic is nice but wouldn't it be better to save it for the About Dialog rather (with useful version and author information) than having such loud branding?

good luck

- Alan