}
static void
-aboutDialogActivateLink( GtkAboutDialog * dialog UNUSED,
- const gchar * link_,
- gpointer user_data UNUSED )
+onUriClicked( GtkAboutDialog * u UNUSED, const gchar * uri, gpointer u2 UNUSED )
{
- gtr_open_file( link_ );
+ gtr_open_uri( uri );
}
static void
NULL
};
- const char *website_url = "http://www.transmissionbt.com/";
+ const char * website_uri = "http://www.transmissionbt.com/";
- gtk_about_dialog_set_url_hook( aboutDialogActivateLink, NULL, NULL );
+ gtk_about_dialog_set_url_hook( onUriClicked, NULL, NULL );
gtk_show_about_dialog( parent,
"name", g_get_application_name( ),
"comments",
_( "A fast and easy BitTorrent client" ),
"version", LONG_VERSION_STRING,
- "website", website_url,
- "website-label", website_url,
+ "website", website_uri,
+ "website-label", website_uri,
"copyright",
_( "Copyright (c) The Transmission Project" ),
"logo-icon-name", MY_CONFIG_NAME,
}
else if( !strcmp( action_name, "donate" ) )
{
- gtr_open_file( "http://www.transmissionbt.com/donate.php" );
+ gtr_open_uri( "http://www.transmissionbt.com/donate.php" );
}
else if( !strcmp( action_name, "pause-all-torrents" ) )
{
}
else if( !strcmp ( action_name, "help" ) )
{
- char * url = gtr_get_help_url( );
- gtr_open_file( url );
- g_free( url );
+ gtr_open_uri( gtr_get_help_uri( ) );
}
else if( !strcmp( action_name, "toggle-main-window" ) )
{
{
if( response == GTK_RESPONSE_HELP )
{
- char * base = gtr_get_help_url( );
- char * url = g_strdup_printf( "%s/html/preferences.html", base );
- gtr_open_file( url );
- g_free( url );
- g_free( base );
+ char * uri = g_strconcat( gtr_get_help_uri(), "/html/preferences.html", NULL );
+ gtr_open_uri( uri );
+ g_free( uri );
}
if( response == GTK_RESPONSE_CLOSE )
}
static void
-onLaunchClutchCB( GtkButton * w UNUSED,
- gpointer data UNUSED )
+onLaunchClutchCB( GtkButton * w UNUSED, gpointer data UNUSED )
{
- int port = pref_int_get( TR_PREFS_KEY_RPC_PORT );
- char * url = g_strdup_printf( "http://localhost:%d/transmission/web",
- port );
+ const int port = pref_int_get( TR_PREFS_KEY_RPC_PORT );
+ char * uri = g_strdup_printf( "http://localhost:%d/transmission/web", port );
- gtr_open_file( url );
- g_free( url );
+ gtr_open_uri( uri );
+ g_free( uri );
}
static void
return 0;
}
-char*
-gtr_get_help_url( void )
+const char*
+gtr_get_help_uri( void )
{
- const char * fmt = "http://www.transmissionbt.com/help/gtk/%d.%dx";
- int major, minor;
+ static char * uri = NULL;
+
+ if( !uri )
+ {
+ int major, minor;
+ const char * fmt = "http://www.transmissionbt.com/help/gtk/%d.%dx";
+ sscanf( SHORT_VERSION_STRING, "%d.%d", &major, &minor );
+ uri = g_strdup_printf( fmt, major, minor / 10 );
+ }
- sscanf( SHORT_VERSION_STRING, "%d.%d", &major, &minor );
- return g_strdup_printf( fmt, major, minor / 10 );
+ return uri;
}
void
gtr_open_file( const char * path )
{
- if( path )
+ char * uri = NULL;
+
+#ifdef HAVE_GIO
+ GFile * file = g_file_new_for_path( path );
+ uri = g_file_get_uri( file );
+ g_object_unref( G_OBJECT( file ) );
+#else
+ if( g_path_is_absolute( path ) )
+ uri = g_strdup_printf( "file://%s", path );
+ else {
+ char * cwd = g_get_current_dir();
+ uri = g_strdup_printf( "file://%s/%s", cwd, path );
+ g_free( cwd );
+ }
+#endif
+
+ gtr_open_uri( uri );
+ g_free( uri );
+}
+
+void
+gtr_open_uri( const char * uri )
+{
+ if( uri )
{
gboolean opened = FALSE;
+
#ifdef HAVE_GIO
if( !opened )
- {
- GFile * file = g_file_new_for_path( path );
- char * uri = g_file_get_uri( file );
opened = g_app_info_launch_default_for_uri( uri, NULL, NULL );
- g_free( uri );
- g_object_unref( G_OBJECT( file ) );
- }
#endif
- if( !opened )
- {
- char * argv[] = { (char*)"xdg-open", (char*)path, NULL };
+
+ if( !opened ) {
+ char * argv[] = { (char*)"xdg-open", (char*)uri, NULL };
opened = g_spawn_async( NULL, argv, NULL, G_SPAWN_SEARCH_PATH,
NULL, NULL, NULL, NULL );
}
if( !opened )
- {
- g_message( "Unable to open \"%s\"", path );
- }
+ g_message( "Unable to open \"%s\"", uri );
}
}
****
***/
+void gtr_open_uri( const char * uri );
+
void gtr_open_file( const char * path );
gboolean gtr_dbus_add_torrent( const char * filename );
gboolean gtr_dbus_present_window( void );
-char* gtr_get_help_url( void );
+const char* gtr_get_help_uri( void );
/***
****