(gtk) add the up/down/yin-yang icons and session stats to toolbar. add toggling of toolbar and/or statusbar.

This commit is contained in:
Charles Kerr 2007-12-20 02:56:47 +00:00
parent b079df809c
commit ffa9d6b125
6 changed files with 200 additions and 35 deletions

View File

@ -20,6 +20,7 @@
#include "tr_prefs.h" #include "tr_prefs.h"
#include "lock.h" #include "lock.h"
#include "logo.h" #include "logo.h"
#include "status-bar-icons.h"
#define UNUSED G_GNUC_UNUSED #define UNUSED G_GNUC_UNUSED
@ -101,7 +102,11 @@ static GtkToggleActionEntry pref_toggle_entries[] =
{ "minimal-view", NULL, { "minimal-view", NULL,
N_("_Minimal View"), "<alt>M", NULL, G_CALLBACK(toggle_pref_cb), FALSE }, N_("_Minimal View"), "<alt>M", NULL, G_CALLBACK(toggle_pref_cb), FALSE },
{ "sort-reversed", NULL, { "sort-reversed", NULL,
N_("_Reverse Sort Order"), NULL, NULL, G_CALLBACK(toggle_pref_cb), FALSE } N_("_Reverse Sort Order"), NULL, NULL, G_CALLBACK(toggle_pref_cb), FALSE },
{ "show-status-bar", NULL,
N_("Show _Status Bar"), NULL, NULL, G_CALLBACK(toggle_pref_cb), FALSE },
{ "show-toolbar", NULL,
N_("Show _Toolbar"), NULL, NULL, G_CALLBACK(toggle_pref_cb), FALSE }
}; };
static GtkActionEntry entries[] = static GtkActionEntry entries[] =
@ -168,7 +173,10 @@ BuiltinIconInfo;
const BuiltinIconInfo my_builtin_icons [] = const BuiltinIconInfo my_builtin_icons [] =
{ {
{ tr_icon_logo, "transmission-logo" }, { tr_icon_logo, "transmission-logo" },
{ tr_icon_lock, "transmission-lock" } { tr_icon_lock, "transmission-lock" },
{ tr_arrow_down, "tr-arrow-down" },
{ tr_arrow_up, "tr-arrow-up" },
{ tr_yin_yang, "tr-yin-yang" }
}; };
static void static void
@ -235,12 +243,9 @@ actions_init( GtkUIManager * ui_manager, gpointer callback_user_data )
match = pref_string_get( PREF_KEY_SORT_MODE ); match = pref_string_get( PREF_KEY_SORT_MODE );
for( i=0, n=G_N_ELEMENTS(sort_radio_entries), active=-1; active==-1 && i<n; ++i ) { 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 ) ) { if( !strcmp( sort_radio_entries[i].name, match ) )
g_message( "found %s in index %d", match, i );
active = i; active = i;
}
}
gtk_action_group_add_radio_actions( action_group, gtk_action_group_add_radio_actions( action_group,
sort_radio_entries, sort_radio_entries,

115
gtk/status-bar-icons.h Normal file
View File

@ -0,0 +1,115 @@
/* GdkPixbuf RGBA C-Source image dump 1-byte-run-length-encoded */
#ifdef __SUNPRO_C
#pragma align 4 (tr_arrow_down)
#endif
#ifdef __GNUC__
static const guint8 tr_arrow_down[] __attribute__ ((__aligned__ (4))) =
#else
static const guint8 tr_arrow_down[] =
#endif
{ ""
/* Pixbuf magic (0x47646b50) */
"GdkP"
/* length: header (24) + pixel_data (255) */
"\0\0\1\27"
/* pixdata_type (0x2010002) */
"\2\1\0\2"
/* rowstride (32) */
"\0\0\0\40"
/* width (8) */
"\0\0\0\10"
/* height (12) */
"\0\0\0\14"
/* pixel_data: */
"\212\377\377\377\0\1\13\13\13\377\202\14\14\14\377\1\13\13\13\377\204"
"\377\377\377\0\1\23\23\23\377\202\27\27\27\377\1\23\23\23\377\204\377"
"\377\377\0\1\31\31\31\377\202\36\36\36\377\1\31\31\31\377\204\377\377"
"\377\0\1\35\35\35\377\202\"\"\"\377\1\35\35\35\377\204\377\377\377\0"
"\1\40\40\40\377\202&&&\377\1\40\40\40\377\202\377\377\377\0\3\16\16\16"
"\237\31\31\31\377$$$\377\202)))\377\6$$$\377\31\31\31\377\16\16\16\237"
"\377\377\377@555\342+++\377\202---\377\6+++\377555\342\377\377\377@\377"
"\377\377\0\327\327\327]444\365\202111\377\2""444\365\327\327\327]\202"
"\377\377\377\0\2\377\377\377\6\251\251\251}\202333\377\2\251\251\251"
"}\377\377\377\6\203\377\377\377\0\1\377\377\377\23\202|||\237\1\377\377"
"\377\23\205\377\377\377\0\202\377\377\377&\203\377\377\377\0"};
/* GdkPixbuf RGBA C-Source image dump 1-byte-run-length-encoded */
#ifdef __SUNPRO_C
#pragma align 4 (tr_arrow_up)
#endif
#ifdef __GNUC__
static const guint8 tr_arrow_up[] __attribute__ ((__aligned__ (4))) =
#else
static const guint8 tr_arrow_up[] =
#endif
{ ""
/* Pixbuf magic (0x47646b50) */
"GdkP"
/* length: header (24) + pixel_data (249) */
"\0\0\1\21"
/* pixdata_type (0x2010002) */
"\2\1\0\2"
/* rowstride (32) */
"\0\0\0\40"
/* width (8) */
"\0\0\0\10"
/* height (12) */
"\0\0\0\14"
/* pixel_data: */
"\213\377\377\377\0\2\5\5\5`\5\5\5_\205\377\377\377\0\1\3\3\3""0\202\17"
"\17\17\377\1\3\3\3""0\203\377\377\377\0\2\1\1\1\20\23\23\23\360\202\30"
"\30\30\377\2\23\23\23\360\1\1\1\20\202\377\377\377\0\2\23\23\23\320\33"
"\33\33\377\202!!!\377\6\33\33\33\377\23\23\23\320\377\377\377\0\17\17"
"\17\237\35\35\35\377$$$\377\202&&&\377\6$$$\377\35\35\35\377\17\17\17"
"\237\377\377\377@\377\377\377f'''\377\202)))\377\3'''\377\377\377\377"
"f\377\377\377@\202\377\377\377\0\1(((\377\202---\377\1(((\377\204\377"
"\377\377\0\1)))\377\202111\377\1)))\377\204\377\377\377\0\1,,,\377\202"
"555\377\1,,,\377\204\377\377\377\0\1///\377\202888\377\1///\377\204\377"
"\377\377\0\204\377\377\377f\202\377\377\377\0"};
/* GdkPixbuf RGBA C-Source image dump 1-byte-run-length-encoded */
#ifdef __SUNPRO_C
#pragma align 4 (yin_yang)
#endif
#ifdef __GNUC__
static const guint8 tr_yin_yang[] __attribute__ ((__aligned__ (4))) =
#else
static const guint8 tr_yin_yang[] =
#endif
{ ""
/* Pixbuf magic (0x47646b50) */
"GdkP"
/* length: header (24) + pixel_data (403) */
"\0\0\1\253"
/* pixdata_type (0x2010002) */
"\2\1\0\2"
/* rowstride (40) */
"\0\0\0("
/* width (10) */
"\0\0\0\12"
/* height (12) */
"\0\0\0\14"
/* pixel_data: */
"\214\377\377\377\0\2\3\3\3@\11\11\11\300\202\14\14\14\377\2\11\11\11"
"\300\3\3\3@\202\0\0\0\0\25\377\377\377\0\10\10\10\200\20\20\20\377''"
"'\322\276\276\276y\377\377\377fmmm\204\22\22\22\342\10\10\10\200\0\0"
"\0\0\5\5\5@\24\24\24\377\30\30\30\377\322\322\322W\377\377\377\15\377"
"\377\377\0\377\377\377\40\326\326\326c\33\33\33\331\5\5\5@\33\33\33\306"
"\202\35\35\35\377\1HHH\26\203\377\377\377\0\10\377\377\377\6rrr\211\31"
"\31\31\306\34\34\34\377$$$\377!!!\377\26\26\26\301\3\3\3\40\203\377\377"
"\377\0\15\377\377\377\40\30\30\30\377!!!\377)))\377'''\377\40\40\40\377"
"\30\30\30\377\22\22\22\337\6\6\6@\377\377\377\0\0\0\0\0\33\33\33\377"
">>>\331\202,,,\377\11+++\377'''\377\"\"\"\377\35\35\35\361\377\377\377"
"\0\14\14\14P777\331\204\204\204x///\377\203111\377\10///\377+++\365\4"
"\4\4\20!!!\326\202\202\202x\377\377\377\31fff\262444\377\202555\377\17"
"\77\77\77\354kkk\245\"\"\"\321SSS\251\377\377\377\31\377\377\377\0\377"
"\377\3773\233\233\233\214MMM\331777\377444\377555\312\211\211\211}\377"
"\377\3773\0\0\0\0\202\377\377\377\0\2\377\377\377\31\377\377\377L\202"
"\377\377\377f\2\377\377\377L\377\377\377\31\202\0\0\0\0"};

View File

@ -29,6 +29,9 @@ tr_prefs_init_global( void )
{ {
cf_check_older_configs( ); cf_check_older_configs( );
pref_flag_set_default ( PREF_KEY_STATUS_BAR, TRUE );
pref_flag_set_default ( PREF_KEY_TOOLBAR, TRUE );
pref_flag_set_default ( PREF_KEY_DL_LIMIT_ENABLED, FALSE ); pref_flag_set_default ( PREF_KEY_DL_LIMIT_ENABLED, FALSE );
pref_int_set_default ( PREF_KEY_DL_LIMIT, 100 ); pref_int_set_default ( PREF_KEY_DL_LIMIT, 100 );
pref_flag_set_default ( PREF_KEY_UL_LIMIT_ENABLED, FALSE ); pref_flag_set_default ( PREF_KEY_UL_LIMIT_ENABLED, FALSE );

View File

@ -38,6 +38,8 @@ GtkWidget * tr_prefs_dialog_new( GObject * core, GtkWindow * parent );
#define PREF_KEY_SORT_MODE "sort-mode" #define PREF_KEY_SORT_MODE "sort-mode"
#define PREF_KEY_SORT_REVERSED "sort-reversed" #define PREF_KEY_SORT_REVERSED "sort-reversed"
#define PREF_KEY_MINIMAL_VIEW "minimal-view" #define PREF_KEY_MINIMAL_VIEW "minimal-view"
#define PREF_KEY_STATUS_BAR "show-status-bar"
#define PREF_KEY_TOOLBAR "show-toolbar"
void tr_prefs_init_global( void ); void tr_prefs_init_global( void );

View File

@ -52,9 +52,11 @@ typedef struct
{ {
GtkWidget * scroll; GtkWidget * scroll;
GtkWidget * view; GtkWidget * view;
GtkWidget * toolbar;
GtkWidget * status; GtkWidget * status;
GtkWidget * ul_lb; GtkWidget * ul_lb;
GtkWidget * dl_lb; GtkWidget * dl_lb;
GtkWidget * stats_lb;
GtkTreeSelection * selection; GtkTreeSelection * selection;
GtkCellRenderer * renderer; GtkCellRenderer * renderer;
GtkTreeViewColumn * column; GtkTreeViewColumn * column;
@ -144,12 +146,23 @@ realized_cb ( GtkWidget * wind, gpointer unused UNUSED )
static void static void
prefsChanged( TrCore * core UNUSED, const char * key, gpointer wind ) prefsChanged( TrCore * core UNUSED, const char * key, gpointer wind )
{ {
PrivateData * p = get_private_data( GTK_WINDOW( wind ) );
if( !strcmp( key, PREF_KEY_MINIMAL_VIEW ) ) if( !strcmp( key, PREF_KEY_MINIMAL_VIEW ) )
{ {
PrivateData * p = get_private_data( GTK_WINDOW( wind ) );
g_object_set( p->renderer, "minimal", pref_flag_get( key ), NULL ); g_object_set( p->renderer, "minimal", pref_flag_get( key ), NULL );
gtk_tree_view_column_queue_resize( p->column ); gtk_tree_view_column_queue_resize( p->column );
} }
else if( !strcmp( key, PREF_KEY_STATUS_BAR ) )
{
const gboolean isEnabled = pref_flag_get( key );
g_object_set( p->status, "visible", isEnabled, NULL );
}
else if( !strcmp( key, PREF_KEY_TOOLBAR ) )
{
const gboolean isEnabled = pref_flag_get( key );
g_object_set( p->toolbar, "visible", isEnabled, NULL );
}
} }
static void static void
@ -188,9 +201,32 @@ tr_window_new( GtkUIManager * ui_manager, TrCore * core )
gtk_box_pack_start( GTK_BOX(vbox), w, FALSE, FALSE, 0 ); gtk_box_pack_start( GTK_BOX(vbox), w, FALSE, FALSE, 0 );
/* toolbar */ /* toolbar */
w = action_get_widget( "/main-window-toolbar" ); w = p->toolbar = action_get_widget( "/main-window-toolbar" );
gtk_box_pack_start( GTK_BOX(vbox), w, FALSE, FALSE, 0 ); gtk_box_pack_start( GTK_BOX(vbox), w, FALSE, FALSE, 0 );
/* statusbar */
h = p->status = gtk_hbox_new( FALSE, GUI_PAD );
gtk_container_set_border_width( GTK_CONTAINER(h), GUI_PAD );
w = p->ul_lb = gtk_label_new( NULL );
gtk_box_pack_end( GTK_BOX(h), w, FALSE, FALSE, 0 );
w = gtk_image_new_from_stock( "tr-arrow-up", (GtkIconSize)-1 );
gtk_box_pack_end( GTK_BOX(h), w, FALSE, FALSE, 0 );
w = gtk_alignment_new( 0.0f, 0.0f, 0.0f, 0.0f );
gtk_widget_set_usize( w, GUI_PAD, 0u );
gtk_box_pack_end( GTK_BOX(h), w, FALSE, FALSE, 0 );
w = p->dl_lb = gtk_label_new( NULL );
gtk_box_pack_end( GTK_BOX(h), w, FALSE, FALSE, 0 );
w = gtk_image_new_from_stock( "tr-arrow-down", (GtkIconSize)-1 );
gtk_box_pack_end( GTK_BOX(h), w, FALSE, FALSE, 0 );
w = gtk_image_new_from_stock( "tr-yin-yang", (GtkIconSize)-1 );
gtk_box_pack_start( GTK_BOX(h), w, FALSE, FALSE, 0 );
w = p->stats_lb = gtk_label_new( NULL );
gtk_box_pack_start( GTK_BOX(h), w, FALSE, FALSE, 0 );
gtk_box_pack_start( GTK_BOX(vbox), h, FALSE, FALSE, 0 );
/* workarea */ /* workarea */
p->view = makeview( p ); p->view = makeview( p );
w = p->scroll = gtk_scrolled_window_new( NULL, NULL ); w = p->scroll = gtk_scrolled_window_new( NULL, NULL );
@ -203,21 +239,13 @@ tr_window_new( GtkUIManager * ui_manager, TrCore * core )
gtk_widget_set_usize (w, 0u, 6u); gtk_widget_set_usize (w, 0u, 6u);
gtk_box_pack_start( GTK_BOX(vbox), w, FALSE, FALSE, 0 ); gtk_box_pack_start( GTK_BOX(vbox), w, FALSE, FALSE, 0 );
/* statusbar */
h = gtk_hbox_new( FALSE, 0 );
w = p->ul_lb = gtk_label_new( NULL );
gtk_box_pack_end( GTK_BOX(h), w, FALSE, FALSE, GUI_PAD );
w = gtk_vseparator_new( );
gtk_box_pack_end( GTK_BOX(h), w, FALSE, FALSE, GUI_PAD );
w = p->dl_lb = gtk_label_new( NULL );
gtk_box_pack_end( GTK_BOX(h), w, FALSE, FALSE, GUI_PAD );
gtk_box_pack_start( GTK_BOX(vbox), h, FALSE, FALSE, 0 );
/* show all but the window */ /* show all but the window */
gtk_widget_show_all( vbox ); gtk_widget_show_all( vbox );
/* listen for prefs changes that affect the window */ /* listen for prefs changes that affect the window */
prefsChanged( core, PREF_KEY_MINIMAL_VIEW, self ); prefsChanged( core, PREF_KEY_MINIMAL_VIEW, self );
prefsChanged( core, PREF_KEY_STATUS_BAR, self );
prefsChanged( core, PREF_KEY_TOOLBAR, self );
p->core = core; p->core = core;
p->pref_handler_id = g_signal_connect( core, "prefs-changed", p->pref_handler_id = g_signal_connect( core, "prefs-changed",
G_CALLBACK(prefsChanged), self ); G_CALLBACK(prefsChanged), self );
@ -229,16 +257,21 @@ void
tr_window_update( TrWindow * self, float downspeed, float upspeed ) tr_window_update( TrWindow * self, float downspeed, float upspeed )
{ {
PrivateData * p = get_private_data( self ); PrivateData * p = get_private_data( self );
char speedStr[32]; char up[32], down[32], buf[64];
char buf[64]; struct tr_session_stats stats;
tr_handle * handle = tr_core_handle( p->core );
tr_strlspeed( speedStr, downspeed, sizeof(speedStr) ); tr_strlspeed( buf, downspeed, sizeof( buf ) );
g_snprintf( buf, sizeof(buf), _("Down: %s"), speedStr ); gtk_label_set_text( GTK_LABEL( p->dl_lb ), buf );
gtk_label_set_text( GTK_LABEL(p->dl_lb), buf );
tr_strlspeed( speedStr, upspeed, sizeof(speedStr) ); tr_strlspeed( buf, upspeed, sizeof( buf ) );
g_snprintf( buf, sizeof(buf), _("Up: %s"), speedStr ); gtk_label_set_text( GTK_LABEL( p->ul_lb ), buf );
gtk_label_set_text( GTK_LABEL(p->ul_lb), buf );
tr_getCumulativeSessionStats( handle, &stats );
tr_strlsize( up, stats.uploadedBytes, sizeof( up ) );
tr_strlsize( down, stats.downloadedBytes, sizeof( down ) );
g_snprintf( buf, sizeof( buf ), _( "Down: %s Up: %s" ), down, up );
gtk_label_set_text( GTK_LABEL( p->stats_lb ), buf );
} }
GtkTreeSelection* GtkTreeSelection*

View File

@ -15,16 +15,23 @@ const char * fallback_ui_file =
" <menuitem action='quit'/>\n" " <menuitem action='quit'/>\n"
" </menu>\n" " </menu>\n"
" <menu action='view-menu'>\n" " <menu action='view-menu'>\n"
" <menuitem action='show-torrent-details'/>\n"
" <separator/>\n"
" <menuitem action='minimal-view'/>\n" " <menuitem action='minimal-view'/>\n"
" <separator/>\n" " <separator/>\n"
" <menuitem action='sort-by-activity'/>\n" " <menu action='sort-menu'>\n"
" <menuitem action='sort-by-name'/>\n" " <menuitem action='sort-by-activity'/>\n"
" <menuitem action='sort-by-progress'/>\n" " <menuitem action='sort-by-name'/>\n"
" <menuitem action='sort-by-state'/>\n" " <menuitem action='sort-by-progress'/>\n"
" <menuitem action='sort-by-tracker'/>\n" " <menuitem action='sort-by-state'/>\n"
" <menuitem action='sort-reversed'/>\n" " <menuitem action='sort-by-tracker'/>\n"
" <separator/>\n"
" <menuitem action='sort-reversed'/>\n"
" </menu>\n"
" <separator/>\n"
" <menuitem action='show-torrent-details'/>\n"
" <separator/>\n"
" <menuitem action='show-toolbar'/>\n"
" <menuitem action='show-status-bar'/>\n"
" <separator/>\n"
" </menu>\n" " </menu>\n"
" <menu action='edit-menu'>\n" " <menu action='edit-menu'>\n"
" <menuitem action='select-all'/>\n" " <menuitem action='select-all'/>\n"