1
0
Fork 0
mirror of https://github.com/transmission/transmission synced 2024-12-24 16:52:39 +00:00

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

This commit is contained in:
Charles Kerr 2010-09-22 16:44:38 +00:00
parent b63d64e0e3
commit 60132d3781
4 changed files with 60 additions and 44 deletions

View 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" ) )
{

View 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

View 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;
sscanf( SHORT_VERSION_STRING, "%d.%d", &major, &minor );
return g_strdup_printf( fmt, major, minor / 10 );
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 );
}
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 );
}
}

View 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 );
/***
****