2007-06-18 03:40:41 +00:00
|
|
|
/*
|
2008-01-01 17:20:20 +00:00
|
|
|
* This file Copyright (C) 2007-2008 Charles Kerr <charles@rebelbase.com>
|
2007-06-18 03:40:41 +00:00
|
|
|
*
|
|
|
|
* This file is licensed by the GPL version 2. Works owned by the
|
|
|
|
* Transmission project are granted a special exemption to clause 2(b)
|
|
|
|
* so that the bulk of its code can remain under the MIT license.
|
|
|
|
* This exemption does not extend to derived works not owned by
|
|
|
|
* the Transmission project.
|
2007-08-18 17:19:49 +00:00
|
|
|
*
|
|
|
|
* $Id$
|
2007-06-18 03:40:41 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
#include <glib/gi18n.h>
|
|
|
|
#include <gtk/gtk.h>
|
2007-07-18 23:04:26 +00:00
|
|
|
#include <libtransmission/transmission.h>
|
2007-12-19 02:46:30 +00:00
|
|
|
#include "conf.h"
|
2008-02-26 19:58:03 +00:00
|
|
|
#include "tr-core.h"
|
|
|
|
#include "tr-prefs.h"
|
2007-10-13 13:51:38 +00:00
|
|
|
#include "lock.h"
|
2008-02-07 20:27:17 +00:00
|
|
|
#include "logo.h"
|
2007-06-18 03:40:41 +00:00
|
|
|
|
2007-07-26 17:21:50 +00:00
|
|
|
#define UNUSED G_GNUC_UNUSED
|
2007-06-18 03:40:41 +00:00
|
|
|
|
|
|
|
extern void doAction (const char * action_name, gpointer user_data );
|
|
|
|
|
2007-12-19 18:42:33 +00:00
|
|
|
static TrCore * myCore = 0;
|
|
|
|
|
2007-06-18 03:40:41 +00:00
|
|
|
static GtkActionGroup * myGroup = 0;
|
|
|
|
|
2007-12-19 18:42:33 +00:00
|
|
|
static void
|
|
|
|
action_cb ( GtkAction * a, gpointer user_data )
|
2007-06-18 03:40:41 +00:00
|
|
|
{
|
|
|
|
doAction ( gtk_action_get_name(a), user_data );
|
|
|
|
}
|
|
|
|
|
|
|
|
#if !GTK_CHECK_VERSION(2,8,0)
|
2007-07-28 02:17:15 +00:00
|
|
|
#define GTK_STOCK_INFO GTK_STOCK_PROPERTIES
|
2007-06-18 03:40:41 +00:00
|
|
|
#endif
|
|
|
|
|
2007-07-30 18:11:34 +00:00
|
|
|
#if !GTK_CHECK_VERSION(2,10,0)
|
|
|
|
#define GTK_STOCK_SELECT_ALL NULL
|
|
|
|
#endif
|
|
|
|
|
2007-12-19 02:46:30 +00:00
|
|
|
static GtkRadioActionEntry sort_radio_entries[] =
|
|
|
|
{
|
|
|
|
{ "sort-by-activity", NULL, N_("Sort by _Activity"), NULL, NULL, 0 },
|
|
|
|
{ "sort-by-date-added", NULL, N_("Sort by _Date Added"), NULL, NULL, 1 },
|
|
|
|
{ "sort-by-name", NULL, N_("Sort by _Name"), NULL, NULL, 2 },
|
|
|
|
{ "sort-by-progress", NULL, N_("Sort by _Progress"), NULL, NULL, 3 },
|
2007-12-19 07:10:47 +00:00
|
|
|
{ "sort-by-state", NULL, N_("Sort by _State"), NULL, NULL, 4 },
|
|
|
|
{ "sort-by-tracker", NULL, N_("Sort by _Tracker"), NULL, NULL, 5 }
|
2007-12-19 02:46:30 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
2007-12-19 18:42:33 +00:00
|
|
|
sort_changed_cb( GtkAction * action UNUSED,
|
|
|
|
GtkRadioAction * current,
|
|
|
|
gpointer user_data UNUSED )
|
2007-12-19 02:46:30 +00:00
|
|
|
{
|
2007-12-19 18:42:33 +00:00
|
|
|
const char * key = PREF_KEY_SORT_MODE;
|
|
|
|
const int i = gtk_radio_action_get_current_value( current );
|
|
|
|
const char * val = sort_radio_entries[i].name;
|
|
|
|
tr_core_set_pref( myCore, key, val );
|
2007-12-19 02:46:30 +00:00
|
|
|
}
|
|
|
|
|
2007-09-21 16:29:09 +00:00
|
|
|
static GtkToggleActionEntry show_toggle_entries[] =
|
|
|
|
{
|
|
|
|
{ "toggle-main-window", NULL,
|
2008-02-03 02:27:12 +00:00
|
|
|
N_("_Main Window"), NULL, NULL, G_CALLBACK(action_cb), TRUE },
|
2007-11-18 02:32:46 +00:00
|
|
|
{ "toggle-message-log", NULL,
|
2008-02-03 02:27:12 +00:00
|
|
|
N_("Message _Log"), NULL, NULL, G_CALLBACK(action_cb), FALSE }
|
2007-09-21 16:29:09 +00:00
|
|
|
};
|
2007-06-18 03:40:41 +00:00
|
|
|
|
2007-12-19 18:42:33 +00:00
|
|
|
static void
|
|
|
|
toggle_pref_cb ( GtkToggleAction * action, gpointer user_data UNUSED )
|
|
|
|
{
|
|
|
|
const char * key = gtk_action_get_name( GTK_ACTION( action ) );
|
|
|
|
const gboolean val = gtk_toggle_action_get_active( action );
|
|
|
|
tr_core_set_pref_bool( myCore, key, val );
|
|
|
|
}
|
|
|
|
|
|
|
|
static GtkToggleActionEntry pref_toggle_entries[] =
|
2007-12-19 02:46:30 +00:00
|
|
|
{
|
|
|
|
{ "minimal-view", NULL,
|
2007-12-20 01:33:51 +00:00
|
|
|
N_("_Minimal View"), "<alt>M", NULL, G_CALLBACK(toggle_pref_cb), FALSE },
|
2007-12-19 18:42:33 +00:00
|
|
|
{ "sort-reversed", NULL,
|
2007-12-20 02:56:47 +00:00
|
|
|
N_("_Reverse Sort Order"), NULL, NULL, G_CALLBACK(toggle_pref_cb), FALSE },
|
2007-12-24 00:14:39 +00:00
|
|
|
{ "show-filter-bar", NULL,
|
2008-02-03 02:27:12 +00:00
|
|
|
N_("_Filter Bar"), NULL, NULL, G_CALLBACK(toggle_pref_cb), FALSE },
|
2007-12-20 02:56:47 +00:00
|
|
|
{ "show-status-bar", NULL,
|
2008-02-03 02:27:12 +00:00
|
|
|
N_("_Status Bar"), NULL, NULL, G_CALLBACK(toggle_pref_cb), FALSE },
|
2007-12-20 02:56:47 +00:00
|
|
|
{ "show-toolbar", NULL,
|
2008-02-03 02:27:12 +00:00
|
|
|
N_("_Toolbar"), NULL, NULL, G_CALLBACK(toggle_pref_cb), FALSE }
|
2007-12-19 02:46:30 +00:00
|
|
|
};
|
|
|
|
|
2007-06-18 03:40:41 +00:00
|
|
|
static GtkActionEntry entries[] =
|
|
|
|
{
|
2007-10-10 18:20:52 +00:00
|
|
|
{ "torrent-menu", NULL, N_("_Torrent"), NULL, NULL, NULL },
|
2007-12-19 02:46:30 +00:00
|
|
|
{ "view-menu", NULL, N_("_View"), NULL, NULL, NULL },
|
|
|
|
{ "sort-menu", NULL, N_("_Sort Torrents By"), NULL, NULL, NULL },
|
2007-06-18 03:40:41 +00:00
|
|
|
{ "edit-menu", NULL, N_("_Edit"), NULL, NULL, NULL },
|
|
|
|
{ "help-menu", NULL, N_("_Help"), NULL, NULL, NULL },
|
2008-02-03 17:10:03 +00:00
|
|
|
{ "open-torrent-toolbar", GTK_STOCK_OPEN, N_("_Open"), NULL,
|
|
|
|
N_("Open an existing torrent"),
|
|
|
|
G_CALLBACK(action_cb) },
|
|
|
|
{ "open-torrent-menu", GTK_STOCK_OPEN, N_("_Open..."), "<control>O",
|
|
|
|
N_("Open an existing torrent"),
|
|
|
|
G_CALLBACK(action_cb) },
|
2007-10-05 16:53:16 +00:00
|
|
|
{ "start-torrent", GTK_STOCK_MEDIA_PLAY,
|
2007-06-18 03:40:41 +00:00
|
|
|
N_("_Start"), "<control>S", NULL, G_CALLBACK(action_cb) },
|
2007-11-27 03:29:51 +00:00
|
|
|
{ "show-stats", NULL, N_("_Statistics"), NULL, NULL, G_CALLBACK(action_cb) },
|
2007-10-10 18:20:52 +00:00
|
|
|
{ "verify-torrent", NULL,
|
2007-11-18 02:55:08 +00:00
|
|
|
N_("_Verify Local Data"), NULL, NULL, G_CALLBACK(action_cb) },
|
2007-10-10 17:25:56 +00:00
|
|
|
{ "pause-torrent", GTK_STOCK_MEDIA_PAUSE,
|
2007-10-06 07:06:37 +00:00
|
|
|
N_("_Pause"), "<control>P", NULL, G_CALLBACK(action_cb) },
|
2007-06-18 03:40:41 +00:00
|
|
|
{ "remove-torrent", GTK_STOCK_REMOVE,
|
2008-02-19 03:57:03 +00:00
|
|
|
N_("_Remove"), "Delete", NULL, G_CALLBACK(action_cb) },
|
2008-03-02 15:54:58 +00:00
|
|
|
{ "delete-torrent", GTK_STOCK_DELETE,
|
|
|
|
N_("_Delete Files"), "<control>Delete", NULL, G_CALLBACK(action_cb) },
|
2008-02-03 17:10:03 +00:00
|
|
|
{ "new-torrent", GTK_STOCK_NEW, N_("_New..."), NULL,
|
|
|
|
N_("Create a new torrent"),
|
|
|
|
G_CALLBACK(action_cb) },
|
|
|
|
{ "close", GTK_STOCK_CLOSE, N_("_Close"), "<control>W",
|
|
|
|
N_("Close main window"),
|
|
|
|
G_CALLBACK(action_cb) },
|
2007-06-18 03:40:41 +00:00
|
|
|
{ "quit", GTK_STOCK_QUIT,
|
|
|
|
N_("_Quit"), "<control>Q", NULL, G_CALLBACK(action_cb) },
|
2007-07-30 15:51:37 +00:00
|
|
|
{ "select-all", GTK_STOCK_SELECT_ALL,
|
|
|
|
N_("Select _All"), "<control>A", NULL, G_CALLBACK(action_cb) },
|
|
|
|
{ "unselect-all", NULL,
|
2007-10-10 18:20:52 +00:00
|
|
|
N_("Dese_lect All"), "<shift><control>A", NULL, G_CALLBACK(action_cb) },
|
2007-06-18 03:40:41 +00:00
|
|
|
{ "edit-preferences", GTK_STOCK_PREFERENCES,
|
2007-10-10 18:20:52 +00:00
|
|
|
NULL, NULL, NULL, G_CALLBACK(action_cb) },
|
2007-10-10 18:52:08 +00:00
|
|
|
{ "show-torrent-details", GTK_STOCK_INFO,
|
2007-10-10 19:47:55 +00:00
|
|
|
N_("_Details"), "<alt>Return", N_("Torrent Details"), G_CALLBACK(action_cb) },
|
2007-06-18 03:40:41 +00:00
|
|
|
{ "show-about-dialog", GTK_STOCK_ABOUT,
|
|
|
|
N_("_About Transmission"), NULL, NULL, G_CALLBACK(action_cb) },
|
2007-10-10 18:20:52 +00:00
|
|
|
{ "update-tracker", GTK_STOCK_NETWORK,
|
2007-10-11 15:25:54 +00:00
|
|
|
N_("Ask Tracker for _More Peers"), NULL, NULL, G_CALLBACK(action_cb) }
|
2007-06-18 03:40:41 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
|
|
|
ensure_tooltip (GtkActionEntry * e)
|
|
|
|
{
|
|
|
|
if( !e->tooltip && e->label )
|
|
|
|
{
|
|
|
|
const char * src;
|
|
|
|
char *tgt;
|
|
|
|
e->tooltip = g_malloc( strlen( e->label ) + 1 );
|
|
|
|
for( src=e->label, tgt=(char*)e->tooltip; *src; ++src )
|
|
|
|
if( *src != '_' )
|
|
|
|
*tgt++ = *src;
|
2007-07-20 17:09:15 +00:00
|
|
|
*tgt++ = '\0';
|
2007-06-18 03:40:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
const guint8* raw;
|
|
|
|
const char * name;
|
|
|
|
}
|
|
|
|
BuiltinIconInfo;
|
|
|
|
|
2008-02-07 20:27:17 +00:00
|
|
|
const BuiltinIconInfo my_fallback_icons [] =
|
2007-06-18 03:40:41 +00:00
|
|
|
{
|
2008-02-07 20:27:17 +00:00
|
|
|
{ tr_icon_logo, "transmission" },
|
2008-01-16 14:55:07 +00:00
|
|
|
{ tr_icon_lock, "transmission-lock" }
|
2007-06-18 03:40:41 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
|
|
|
register_my_icons ( void )
|
|
|
|
{
|
2008-02-07 20:27:17 +00:00
|
|
|
int i;
|
|
|
|
const int n = G_N_ELEMENTS( my_fallback_icons );
|
|
|
|
GtkIconFactory * factory = gtk_icon_factory_new( );
|
|
|
|
GtkIconTheme * theme = gtk_icon_theme_get_default( );
|
|
|
|
gtk_icon_factory_add_default( factory );
|
|
|
|
|
|
|
|
for( i=0; i<n; ++i )
|
|
|
|
{
|
|
|
|
const char * name = my_fallback_icons[i].name;
|
|
|
|
|
|
|
|
if( !gtk_icon_theme_has_icon( theme, name ) )
|
|
|
|
{
|
|
|
|
int width;
|
|
|
|
GdkPixbuf * p;
|
|
|
|
GtkIconSet * icon_set;
|
|
|
|
|
|
|
|
p = gdk_pixbuf_new_from_inline( -1, my_fallback_icons[i].raw, FALSE, 0 );
|
|
|
|
width = gdk_pixbuf_get_width( p );
|
|
|
|
icon_set = gtk_icon_set_new_from_pixbuf( p );
|
|
|
|
gtk_icon_theme_add_builtin_icon( name, width, p );
|
|
|
|
gtk_icon_factory_add( factory, name, icon_set );
|
|
|
|
|
|
|
|
g_object_unref( p );
|
|
|
|
gtk_icon_set_unref( icon_set );
|
|
|
|
}
|
2007-06-18 03:40:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
g_object_unref (G_OBJECT (factory));
|
|
|
|
}
|
|
|
|
|
|
|
|
static GtkUIManager * myUIManager = NULL;
|
|
|
|
|
2007-12-19 18:42:33 +00:00
|
|
|
void
|
|
|
|
actions_set_core( TrCore * core )
|
|
|
|
{
|
|
|
|
myCore = core;
|
|
|
|
}
|
|
|
|
|
2007-06-18 03:40:41 +00:00
|
|
|
void
|
|
|
|
actions_init( GtkUIManager * ui_manager, gpointer callback_user_data )
|
|
|
|
{
|
2007-12-19 02:46:30 +00:00
|
|
|
int i, n;
|
|
|
|
int active;
|
|
|
|
char * match;
|
2007-06-18 03:40:41 +00:00
|
|
|
const int n_entries = G_N_ELEMENTS( entries );
|
|
|
|
GtkActionGroup * action_group;
|
|
|
|
|
|
|
|
myUIManager = ui_manager;
|
|
|
|
|
|
|
|
register_my_icons ();
|
|
|
|
|
|
|
|
for( i=0; i<n_entries; ++i )
|
|
|
|
ensure_tooltip (&entries[i]);
|
|
|
|
|
|
|
|
action_group = myGroup = gtk_action_group_new( "Actions" );
|
|
|
|
gtk_action_group_set_translation_domain( action_group, NULL );
|
|
|
|
|
2007-12-19 02:46:30 +00:00
|
|
|
|
|
|
|
match = pref_string_get( PREF_KEY_SORT_MODE );
|
2007-12-20 02:56:47 +00:00
|
|
|
for( i=0, n=G_N_ELEMENTS(sort_radio_entries), active=-1; active==-1 && i<n; ++i )
|
|
|
|
if( !strcmp( sort_radio_entries[i].name, match ) )
|
2007-12-19 02:46:30 +00:00
|
|
|
active = i;
|
|
|
|
|
|
|
|
gtk_action_group_add_radio_actions( action_group,
|
|
|
|
sort_radio_entries,
|
|
|
|
G_N_ELEMENTS(sort_radio_entries),
|
|
|
|
active,
|
|
|
|
G_CALLBACK(sort_changed_cb),
|
2007-12-19 18:42:33 +00:00
|
|
|
NULL );
|
2007-12-19 02:46:30 +00:00
|
|
|
|
|
|
|
gtk_action_group_add_toggle_actions( action_group,
|
|
|
|
show_toggle_entries,
|
|
|
|
G_N_ELEMENTS(show_toggle_entries),
|
|
|
|
callback_user_data );
|
|
|
|
|
2007-12-19 18:42:33 +00:00
|
|
|
for( i=0, n=G_N_ELEMENTS(pref_toggle_entries); i<n; ++i )
|
2007-12-20 01:33:51 +00:00
|
|
|
pref_toggle_entries[i].is_active =
|
|
|
|
pref_flag_get( pref_toggle_entries[i].name );
|
2007-12-19 02:46:30 +00:00
|
|
|
|
|
|
|
gtk_action_group_add_toggle_actions( action_group,
|
2007-12-19 18:42:33 +00:00
|
|
|
pref_toggle_entries,
|
|
|
|
G_N_ELEMENTS(pref_toggle_entries),
|
2007-12-19 02:46:30 +00:00
|
|
|
callback_user_data );
|
2007-09-21 16:29:09 +00:00
|
|
|
|
2007-06-18 03:40:41 +00:00
|
|
|
gtk_action_group_add_actions( action_group,
|
|
|
|
entries, n_entries,
|
|
|
|
callback_user_data );
|
|
|
|
|
|
|
|
gtk_ui_manager_insert_action_group( ui_manager, action_group, 0 );
|
|
|
|
g_object_unref (G_OBJECT(action_group));
|
2007-12-20 15:16:14 +00:00
|
|
|
g_free( match );
|
2007-06-18 03:40:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/****
|
|
|
|
*****
|
|
|
|
****/
|
|
|
|
|
|
|
|
static GHashTable * key_to_action = NULL;
|
|
|
|
|
|
|
|
static void
|
|
|
|
ensure_action_map_loaded (GtkUIManager * uim)
|
|
|
|
{
|
|
|
|
GList * l;
|
|
|
|
|
|
|
|
if ( key_to_action != NULL )
|
|
|
|
return;
|
|
|
|
|
|
|
|
key_to_action =
|
|
|
|
g_hash_table_new_full( g_str_hash, g_str_equal, g_free, NULL);
|
|
|
|
|
|
|
|
for( l=gtk_ui_manager_get_action_groups(uim); l!=NULL; l=l->next )
|
|
|
|
{
|
|
|
|
GtkActionGroup * action_group = GTK_ACTION_GROUP( l->data );
|
|
|
|
GList *ait, *actions = gtk_action_group_list_actions( action_group );
|
|
|
|
for( ait=actions; ait!=NULL; ait=ait->next )
|
|
|
|
{
|
|
|
|
GtkAction * action = GTK_ACTION( ait->data );
|
|
|
|
const char * name = gtk_action_get_name( action );
|
|
|
|
g_hash_table_insert( key_to_action, g_strdup(name), action );
|
|
|
|
}
|
|
|
|
g_list_free( actions );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static GtkAction*
|
|
|
|
get_action( const char* name )
|
|
|
|
{
|
|
|
|
ensure_action_map_loaded( myUIManager );
|
|
|
|
return ( GtkAction* ) g_hash_table_lookup( key_to_action, name );
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
action_activate ( const char * name )
|
|
|
|
{
|
|
|
|
GtkAction * action = get_action( name );
|
|
|
|
g_assert( action != NULL );
|
|
|
|
gtk_action_activate( action );
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
action_sensitize( const char * name, gboolean b )
|
|
|
|
{
|
|
|
|
GtkAction * action = get_action( name );
|
|
|
|
g_assert( action != NULL );
|
|
|
|
g_object_set( action, "sensitive", b, NULL );
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
action_toggle( const char * name, gboolean b )
|
|
|
|
{
|
|
|
|
GtkAction * action = get_action( name );
|
|
|
|
gtk_toggle_action_set_active( GTK_TOGGLE_ACTION(action), b );
|
|
|
|
}
|
|
|
|
|
|
|
|
GtkWidget*
|
|
|
|
action_get_widget( const char * path )
|
|
|
|
{
|
|
|
|
return gtk_ui_manager_get_widget( myUIManager, path );
|
|
|
|
}
|