Monday, August 07, 2006

URL handler for GtkAboutDialog

I have been doing some coding for gnusim8085 for some time. Yesterday Sridhar asked me if there was a way for the website link in 'About' dialog to be clickable. I was already looking for something that would accomplish it.

Although there is an API gtk_about_dialog_set_url_hook() which will hook a function with the dialog for handling of urls, I didn't have idea what the function should look like. I have devhelp installed on my machine and API reference of GTK+. But it was missing sample code for this particular thing.
Finally I hunted down the solution by downloading gedit source. Turned out that I just needed to call another gnome function. I am giving it here for all those who may need it.

1. Declare and define a function in the file which defines the major part of UI of your application.


-- interface.h --
void activate_url (GtkAboutDialog *about, const gchar *url, gpointer data);

-- interface.c --
void
activate_url (GtkAboutDialog *about, const gchar *url, gpointer data)
{
gnome_url_show_on_screen (url, NULL, NULL);
}

2. Hook up the above mentioned function for url handling in dialogs.

-- main.c --

int main (int argc, char *argv[]) {
..
..

/* hook up url handler */
gtk_about_dialog_set_url_hook (activate_url, NULL, NULL);
..
..
}

1 comment:

Anonymous said...

The alternative, with a few downsides, is to use the GtkHtml widget.