]> granicus.if.org Git - transmission/commitdiff
(trunk gtk) #3543 'wrong link in the about window' -- separate gtr_open_file() from...
authorCharles Kerr <charles@transmissionbt.com>
Wed, 22 Sep 2010 16:44:38 +0000 (16:44 +0000)
committerCharles Kerr <charles@transmissionbt.com>
Wed, 22 Sep 2010 16:44:38 +0000 (16:44 +0000)
gtk/main.c
gtk/tr-prefs.c
gtk/util.c
gtk/util.h

index 155d2a4ba28c2392008cf3d685e01bce0e6b706c..4735a4416ac81eced3583d17dc6ef3cac62f1acc 100644 (file)
@@ -1394,11 +1394,9 @@ updatemodel( gpointer gdata )
 }
 
 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
@@ -1412,17 +1410,17 @@ about( GtkWindow * parent )
         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,
@@ -1615,7 +1613,7 @@ doAction( const char * action_name, gpointer user_data )
     }
     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" ) )
     {
@@ -1742,9 +1740,7 @@ doAction( const char * action_name, gpointer user_data )
     }
     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" ) )
     {
index 8f690ab6a661ef304215dedfaefa8ffb5a40085d..2b0511a45fb2f06f2e9797dc37ed7be0c9a9f77f 100644 (file)
@@ -39,11 +39,9 @@ response_cb( GtkDialog *     dialog,
 {
     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 )
@@ -717,15 +715,13 @@ onWhitelistSelectionChanged( GtkTreeSelection * sel UNUSED,
 }
 
 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
index 4bb46da21f81612fe3b249a9a124664288514ddb..890ef40ddf951f5d35a413220e49a0eb2afbf173 100644 (file)
@@ -464,43 +464,65 @@ gtr_file_trash_or_remove( const char * filename )
     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 );
     }
 }
 
index 7038b9da26c7d066b882a42f0bfe73dcbc2ef4fa..8751fdba8ad31a7964f1e1615d770f4259dbab73 100644 (file)
@@ -109,13 +109,15 @@ gtr_lockfile_state_t gtr_lockfile( const char * filename );
 ****
 ***/
 
+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 );
 
 /***
 ****