Changeset 11253


Ignore:
Timestamp:
Sep 22, 2010, 4:44:38 PM (12 years ago)
Author:
charles
Message:

(trunk gtk) #3543 'wrong link in the about window' -- separate gtr_open_file() from gtr_open_uri()

Location:
trunk/gtk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/gtk/main.c

    r11215 r11253  
    13951395
    13961396static void
    1397 aboutDialogActivateLink( GtkAboutDialog * dialog    UNUSED,
    1398                          const gchar *              link_,
    1399                          gpointer         user_data UNUSED )
    1400 {
    1401     gtr_open_file( link_ );
     1397onUriClicked( GtkAboutDialog * u UNUSED, const gchar * uri, gpointer u2 UNUSED )
     1398{
     1399    gtr_open_uri( uri );
    14021400}
    14031401
     
    14131411    };
    14141412
    1415     const char *website_url = "http://www.transmissionbt.com/";
    1416 
    1417     gtk_about_dialog_set_url_hook( aboutDialogActivateLink, NULL, NULL );
     1413    const char * website_uri = "http://www.transmissionbt.com/";
     1414
     1415    gtk_about_dialog_set_url_hook( onUriClicked, NULL, NULL );
    14181416
    14191417    gtk_show_about_dialog( parent,
     
    14221420                           _( "A fast and easy BitTorrent client" ),
    14231421                           "version", LONG_VERSION_STRING,
    1424                            "website", website_url,
    1425                            "website-label", website_url,
     1422                           "website", website_uri,
     1423                           "website-label", website_uri,
    14261424                           "copyright",
    14271425                           _( "Copyright (c) The Transmission Project" ),
     
    16161614    else if( !strcmp( action_name, "donate" ) )
    16171615    {
    1618         gtr_open_file( "http://www.transmissionbt.com/donate.php" );
     1616        gtr_open_uri( "http://www.transmissionbt.com/donate.php" );
    16191617    }
    16201618    else if( !strcmp( action_name, "pause-all-torrents" ) )
     
    17431741    else if( !strcmp ( action_name, "help" ) )
    17441742    {
    1745         char * url = gtr_get_help_url( );
    1746         gtr_open_file( url );
    1747         g_free( url );
     1743        gtr_open_uri( gtr_get_help_uri( ) );
    17481744    }
    17491745    else if( !strcmp( action_name, "toggle-main-window" ) )
  • trunk/gtk/tr-prefs.c

    r11132 r11253  
    4040    if( response == GTK_RESPONSE_HELP )
    4141    {
    42         char * base = gtr_get_help_url( );
    43         char * url = g_strdup_printf( "%s/html/preferences.html", base );
    44         gtr_open_file( url );
    45         g_free( url );
    46         g_free( base );
     42        char * uri = g_strconcat( gtr_get_help_uri(), "/html/preferences.html", NULL );
     43        gtr_open_uri( uri );
     44        g_free( uri );
    4745    }
    4846
     
    718716
    719717static void
    720 onLaunchClutchCB( GtkButton * w UNUSED,
    721                   gpointer data UNUSED )
    722 {
    723     int    port = pref_int_get( TR_PREFS_KEY_RPC_PORT );
    724     char * url = g_strdup_printf( "http://localhost:%d/transmission/web",
    725                                   port );
    726 
    727     gtr_open_file( url );
    728     g_free( url );
     718onLaunchClutchCB( GtkButton * w UNUSED, gpointer data UNUSED )
     719{
     720    const int port = pref_int_get( TR_PREFS_KEY_RPC_PORT );
     721    char * uri = g_strdup_printf( "http://localhost:%d/transmission/web", port );
     722
     723    gtr_open_uri( uri );
     724    g_free( uri );
    729725}
    730726
  • trunk/gtk/util.c

    r11216 r11253  
    465465}
    466466
    467 char*
    468 gtr_get_help_url( void )
    469 {
    470     const char * fmt = "http://www.transmissionbt.com/help/gtk/%d.%dx";
    471     int          major, minor;
    472 
    473     sscanf( SHORT_VERSION_STRING, "%d.%d", &major, &minor );
    474     return g_strdup_printf( fmt, major, minor / 10 );
     467const char*
     468gtr_get_help_uri( void )
     469{
     470    static char * uri = NULL;
     471
     472    if( !uri )
     473    {
     474        int major, minor;
     475        const char * fmt = "http://www.transmissionbt.com/help/gtk/%d.%dx";
     476        sscanf( SHORT_VERSION_STRING, "%d.%d", &major, &minor );
     477        uri = g_strdup_printf( fmt, major, minor / 10 );
     478    }
     479
     480    return uri;
    475481}
    476482
     
    478484gtr_open_file( const char * path )
    479485{
    480     if( path )
     486    char * uri = NULL;
     487
     488#ifdef HAVE_GIO
     489    GFile * file = g_file_new_for_path( path );
     490    uri = g_file_get_uri( file );
     491    g_object_unref( G_OBJECT( file ) );
     492#else
     493    if( g_path_is_absolute( path ) )
     494        uri = g_strdup_printf( "file://%s", path );
     495    else {
     496        char * cwd = g_get_current_dir();
     497        uri = g_strdup_printf( "file://%s/%s", cwd, path );
     498        g_free( cwd );
     499    }
     500#endif
     501
     502    gtr_open_uri( uri );
     503    g_free( uri );
     504}
     505
     506void
     507gtr_open_uri( const char * uri )
     508{
     509    if( uri )
    481510    {
    482511        gboolean opened = FALSE;
     512
    483513#ifdef HAVE_GIO
    484514        if( !opened )
    485         {
    486             GFile * file = g_file_new_for_path( path );
    487             char *  uri = g_file_get_uri( file );
    488515            opened = g_app_info_launch_default_for_uri( uri, NULL, NULL );
    489             g_free( uri );
    490             g_object_unref( G_OBJECT( file ) );
    491         }
    492 #endif
    493         if( !opened )
    494         {
    495             char * argv[] = { (char*)"xdg-open", (char*)path, NULL };
     516#endif
     517
     518        if( !opened ) {
     519            char * argv[] = { (char*)"xdg-open", (char*)uri, NULL };
    496520            opened = g_spawn_async( NULL, argv, NULL, G_SPAWN_SEARCH_PATH,
    497521                                    NULL, NULL, NULL, NULL );
     
    499523
    500524        if( !opened )
    501         {
    502             g_message( "Unable to open \"%s\"", path );
    503         }
     525            g_message( "Unable to open \"%s\"", uri );
    504526    }
    505527}
  • trunk/gtk/util.h

    r11132 r11253  
    110110***/
    111111
     112void        gtr_open_uri( const char * uri );
     113
    112114void        gtr_open_file( const char * path );
    113115
     
    116118gboolean    gtr_dbus_present_window( void );
    117119
    118 char*       gtr_get_help_url( void );
     120const char* gtr_get_help_uri( void );
    119121
    120122/***
Note: See TracChangeset for help on using the changeset viewer.