From be0ac280e925305e62ca779db1d684eea20b401d Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Mon, 24 Dec 2007 17:25:52 +0000 Subject: [PATCH] (gtk) add a filter/total count at the bottom of the main window. --- gtk/tr_window.c | 45 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 44 insertions(+), 1 deletion(-) diff --git a/gtk/tr_window.c b/gtk/tr_window.c index 426746069..99aa41b4a 100644 --- a/gtk/tr_window.c +++ b/gtk/tr_window.c @@ -80,6 +80,7 @@ typedef struct GtkWidget * ul_lb; GtkWidget * dl_lb; GtkWidget * stats_lb; + GtkWidget * gutter_lb; GtkTreeSelection * selection; GtkCellRenderer * renderer; GtkTreeViewColumn * column; @@ -337,10 +338,14 @@ is_row_visible( GtkTreeModel * model, && checkFilterText( p->filter_text_mode, tr_torrentInfo( tor ), p->filter_text ); } +static void updateTorrentCount( PrivateData * p ); + static void refilter( PrivateData * p ) { gtk_tree_model_filter_refilter( GTK_TREE_MODEL_FILTER( p->filter_model ) ); + + updateTorrentCount( p ); } static void @@ -438,6 +443,10 @@ tr_window_new( GtkUIManager * ui_manager, TrCore * core ) N_("Name"), N_("Files"), N_("Tracker") }; + p->filter_mode = FILTER_MODE_ALL; + p->filter_text_mode = FILTER_TEXT_MODE_NAME; + p->filter_text = NULL; + /* make the window */ self = gtk_window_new (GTK_WINDOW_TOPLEVEL); g_object_set_data_full(G_OBJECT(self), PRIVATE_DATA_KEY, p, privateFree ); @@ -561,6 +570,12 @@ tr_window_new( GtkUIManager * ui_manager, TrCore * core ) gtk_widget_set_usize (w, 0u, 6u); gtk_box_pack_start( GTK_BOX(vbox), w, FALSE, FALSE, 0 ); + /* status */ + h = gtk_hbox_new( FALSE, GUI_PAD ); + w = p->gutter_lb = gtk_label_new( "N transfers" ); + gtk_box_pack_start_defaults( GTK_BOX(h), w ); + gtk_box_pack_start( GTK_BOX(vbox), h, FALSE, FALSE, 0 ); + /* show all but the window */ gtk_widget_show_all( vbox ); @@ -577,6 +592,30 @@ tr_window_new( GtkUIManager * ui_manager, TrCore * core ) return self; } +static void +updateTorrentCount( PrivateData * p ) +{ + if( p && p->core ) + { + char buf[128]; + const int torrentCount = gtk_tree_model_iter_n_children( tr_core_model( p->core ), NULL ); + const int visibleCount = gtk_tree_model_iter_n_children( p->filter_model, NULL ); + + if( torrentCount != visibleCount ) + g_snprintf( buf, sizeof( buf ), ngettext( _( "%d of %d Transfer" ), + _( "%d of %d Transfers" ), + torrentCount ), + visibleCount, torrentCount ); + else + g_snprintf( buf, sizeof( buf ), ngettext( _( "%d Transfer" ), + _( "%d Transfers" ), + torrentCount ), + torrentCount ); + gtk_label_set_text( GTK_LABEL( p->gutter_lb ), buf ); + } +} + + void tr_window_update( TrWindow * self ) { @@ -590,15 +629,19 @@ tr_window_update( TrWindow * self ) { char * pch; float u, d; - char up[32], down[32], buf[64]; + char up[32], down[32], buf[128]; struct tr_session_stats stats; + /* update the speeds */ tr_torrentRates( handle, &d, &u ); tr_strlspeed( buf, d, sizeof( buf ) ); gtk_label_set_text( GTK_LABEL( p->dl_lb ), buf ); tr_strlspeed( buf, u, sizeof( buf ) ); gtk_label_set_text( GTK_LABEL( p->ul_lb ), buf ); + updateTorrentCount( p ); + + /* update the stats */ pch = pref_string_get( PREF_KEY_STATUS_BAR_STATS ); if( !strcmp( pch, "session-ratio" ) ) { tr_getSessionStats( handle, &stats );