mirror of
https://github.com/transmission/transmission
synced 2024-12-31 20:16:57 +00:00
add stats dialog to the gtk+ client
This commit is contained in:
parent
0997148fbd
commit
dbc9a4aabe
9 changed files with 168 additions and 7 deletions
|
@ -19,6 +19,7 @@ noinst_HEADERS = \
|
|||
logo.h \
|
||||
makemeta-ui.h \
|
||||
msgwin.h \
|
||||
stats.h \
|
||||
torrent-inspector.h \
|
||||
tr_cell_renderer_progress.h \
|
||||
tr_core.h \
|
||||
|
@ -41,6 +42,7 @@ transmission_SOURCES = \
|
|||
main.c \
|
||||
makemeta-ui.c \
|
||||
msgwin.c \
|
||||
stats.c \
|
||||
torrent-inspector.c \
|
||||
tr_cell_renderer_progress.c \
|
||||
tr_core.c \
|
||||
|
|
|
@ -70,6 +70,7 @@ static GtkActionEntry entries[] =
|
|||
{ "add-torrent", GTK_STOCK_OPEN, NULL, NULL, N_("Open Torrent"), G_CALLBACK(action_cb) },
|
||||
{ "start-torrent", GTK_STOCK_MEDIA_PLAY,
|
||||
N_("_Start"), "<control>S", NULL, G_CALLBACK(action_cb) },
|
||||
{ "show-stats", NULL, N_("_Statistics"), NULL, NULL, G_CALLBACK(action_cb) },
|
||||
{ "verify-torrent", NULL,
|
||||
N_("_Verify Local Data"), NULL, NULL, G_CALLBACK(action_cb) },
|
||||
{ "pause-torrent", GTK_STOCK_MEDIA_PAUSE,
|
||||
|
|
13
gtk/main.c
13
gtk/main.c
|
@ -41,6 +41,7 @@
|
|||
#include "ipc.h"
|
||||
#include "makemeta-ui.h"
|
||||
#include "msgwin.h"
|
||||
#include "stats.h"
|
||||
#include "torrent-inspector.h"
|
||||
#include "tr_cell_renderer_progress.h"
|
||||
#include "tr_core.h"
|
||||
|
@ -697,10 +698,8 @@ prefschanged( TrCore * core UNUSED, const char * key, gpointer data )
|
|||
void
|
||||
setpex( tr_torrent * tor, void * arg )
|
||||
{
|
||||
gboolean * val;
|
||||
|
||||
val = arg;
|
||||
tr_torrentDisablePex( tor, !(*val) );
|
||||
const gboolean * val = arg;
|
||||
tr_torrentDisablePex( tor, !*val );
|
||||
}
|
||||
|
||||
gboolean
|
||||
|
@ -860,6 +859,12 @@ doAction ( const char * action_name, gpointer user_data )
|
|||
{
|
||||
makeaddwind( data->wind, data->core );
|
||||
}
|
||||
else if (!strcmp (action_name, "show-stats"))
|
||||
{
|
||||
GtkWidget * dialog = stats_dialog_create( data->wind,
|
||||
data->core );
|
||||
gtk_widget_show( dialog );
|
||||
}
|
||||
else if (!strcmp (action_name, "start-torrent"))
|
||||
{
|
||||
GtkTreeSelection * s = tr_window_get_selection(data->wind);
|
||||
|
|
128
gtk/stats.c
Normal file
128
gtk/stats.c
Normal file
|
@ -0,0 +1,128 @@
|
|||
/*
|
||||
* This file Copyright (C) 2007 Charles Kerr <charles@rebelbase.com>
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* $Id:$
|
||||
*/
|
||||
|
||||
#include <glib/gi18n.h>
|
||||
#include <gtk/gtk.h>
|
||||
#include "hig.h"
|
||||
#include "stats.h"
|
||||
#include "tr_core.h"
|
||||
|
||||
struct stat_ui
|
||||
{
|
||||
GtkWidget * one_up_lb;
|
||||
GtkWidget * one_down_lb;
|
||||
GtkWidget * one_ratio_lb;
|
||||
GtkWidget * one_time_lb;
|
||||
GtkWidget * all_up_lb;
|
||||
GtkWidget * all_down_lb;
|
||||
GtkWidget * all_ratio_lb;
|
||||
GtkWidget * all_time_lb;
|
||||
GtkWidget * all_sessions_lb;
|
||||
TrCore * core;
|
||||
};
|
||||
|
||||
static void
|
||||
setLabel( GtkWidget * w, char * ownme )
|
||||
{
|
||||
gtk_label_set_text( GTK_LABEL(w), ownme );
|
||||
g_free( ownme );
|
||||
}
|
||||
|
||||
static void
|
||||
setLabelFromRatio( GtkWidget * w, double d )
|
||||
{
|
||||
char * str = ( (int)d == TR_RATIO_NA )
|
||||
? g_strdup_printf( _("None" ) )
|
||||
: g_strdup_printf( "%.1f%%", d );
|
||||
setLabel( w, str );
|
||||
}
|
||||
|
||||
static gboolean
|
||||
updateStats( gpointer gdata )
|
||||
{
|
||||
struct stat_ui * ui = gdata;
|
||||
tr_session_stats one, all;
|
||||
tr_getSessionStats( ui->core->handle, &one );
|
||||
tr_getCumulativeSessionStats( ui->core->handle, &all );
|
||||
|
||||
setLabel( ui->one_up_lb, readablesize( one.uploadedBytes ) );
|
||||
setLabel( ui->one_down_lb, readablesize( one.downloadedBytes ) );
|
||||
setLabel( ui->one_time_lb, readabletime( one.secondsActive ) );
|
||||
setLabelFromRatio( ui->one_ratio_lb, one.ratio );
|
||||
setLabel( ui->all_sessions_lb, g_strdup_printf( _("Started %d times"), (int)all.sessionCount ) );
|
||||
setLabel( ui->all_up_lb, readablesize( all.uploadedBytes ) );
|
||||
setLabel( ui->all_down_lb, readablesize( all.downloadedBytes ) );
|
||||
setLabel( ui->all_time_lb, readabletime( all.secondsActive ) );
|
||||
setLabelFromRatio( ui->all_ratio_lb, all.ratio );
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static void
|
||||
dialogResponse( GtkDialog * dialog, gint response UNUSED, gpointer unused UNUSED )
|
||||
{
|
||||
g_source_remove( GPOINTER_TO_UINT( g_object_get_data( G_OBJECT(dialog), "TrTimer" ) ) );
|
||||
gtk_widget_destroy( GTK_WIDGET( dialog ) );
|
||||
}
|
||||
|
||||
GtkWidget*
|
||||
stats_dialog_create( GtkWindow * parent, TrCore * core )
|
||||
{
|
||||
guint i;
|
||||
int row = 0;
|
||||
GtkWidget * d;
|
||||
GtkWidget * t;
|
||||
GtkWidget * l;
|
||||
struct stat_ui * ui = g_new0( struct stat_ui, 1 );
|
||||
|
||||
d = gtk_dialog_new_with_buttons( _("Statistics"),
|
||||
parent,
|
||||
GTK_DIALOG_DESTROY_WITH_PARENT,
|
||||
GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE,
|
||||
NULL );
|
||||
t = hig_workarea_create( );
|
||||
gtk_box_pack_start_defaults( GTK_BOX(GTK_DIALOG(d)->vbox), t );
|
||||
ui->core = core;
|
||||
|
||||
hig_workarea_add_section_title( t, &row, _( "Current Session" ) );
|
||||
hig_workarea_add_section_spacer( t, row, 4 );
|
||||
l = ui->one_up_lb = gtk_label_new( NULL );
|
||||
hig_workarea_add_row( t, &row, _("Uploaded:"), l, NULL );
|
||||
l = ui->one_down_lb = gtk_label_new( NULL );
|
||||
hig_workarea_add_row( t, &row, _("Downloaded:"), l, NULL );
|
||||
l = ui->one_ratio_lb = gtk_label_new( NULL );
|
||||
hig_workarea_add_row( t, &row, _("Ratio:"), l, NULL );
|
||||
l = ui->one_time_lb = gtk_label_new( NULL );
|
||||
hig_workarea_add_row( t, &row, _("Duration:"), l, NULL );
|
||||
hig_workarea_add_section_divider( t, &row );
|
||||
hig_workarea_add_section_title( t, &row, _("Cumulative") );
|
||||
hig_workarea_add_section_spacer( t, row, 5 );
|
||||
l = ui->all_sessions_lb = gtk_label_new( _("Program started %d times") );
|
||||
hig_workarea_add_label_w( t, row++, l );
|
||||
l = ui->all_up_lb = gtk_label_new( NULL );
|
||||
hig_workarea_add_row( t, &row, _("Uploaded:"), l, NULL );
|
||||
l = ui->all_down_lb = gtk_label_new( NULL );
|
||||
hig_workarea_add_row( t, &row, _("Downloaded:"), l, NULL );
|
||||
l = ui->all_ratio_lb = gtk_label_new( NULL );
|
||||
hig_workarea_add_row( t, &row, _("Ratio:"), l, NULL );
|
||||
l = ui->all_time_lb = gtk_label_new( NULL );
|
||||
hig_workarea_add_row( t, &row, _("Duration:"), l, NULL );
|
||||
hig_workarea_finish( t, &row );
|
||||
gtk_widget_show_all( t );
|
||||
|
||||
updateStats( ui );
|
||||
g_object_set_data_full( G_OBJECT(d), "data", ui, g_free );
|
||||
g_signal_connect( d, "response", G_CALLBACK(dialogResponse), NULL );
|
||||
i = g_timeout_add( 1000, updateStats, ui );
|
||||
g_object_set_data( G_OBJECT(d), "TrTimer", GUINT_TO_POINTER(i) );
|
||||
return d;
|
||||
}
|
23
gtk/stats.h
Normal file
23
gtk/stats.h
Normal file
|
@ -0,0 +1,23 @@
|
|||
/*
|
||||
* This file Copyright (C) 2007 Charles Kerr <charles@rebelbase.com>
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* $Id:$
|
||||
*/
|
||||
|
||||
#ifndef __TR_GTK_STATS_H__
|
||||
#define __TR_GTK_STATS_H__
|
||||
|
||||
#include <gtk/gtkwidget.h>
|
||||
#include <gtk/gtkwindow.h>
|
||||
#include "tr_core.h"
|
||||
|
||||
GtkWidget* stats_dialog_create( GtkWindow * parent,
|
||||
TrCore * core );
|
||||
|
||||
#endif
|
|
@ -664,7 +664,7 @@ static GtkWidget* peer_page_new ( TrTorrent * gtor )
|
|||
gtk_widget_set_usize (w, 0u, GUI_PAD);
|
||||
gtk_box_pack_start (GTK_BOX(vbox), w, FALSE, FALSE, 0);
|
||||
|
||||
g_snprintf (name, sizeof(name), "<b>%s</b>", _("Peers"));
|
||||
g_snprintf (name, sizeof(name), "<b>%s</b>", _("Connected Peers"));
|
||||
l = gtk_label_new (NULL);
|
||||
gtk_misc_set_alignment (GTK_MISC(l), 0.0f, 0.5f);
|
||||
gtk_label_set_markup (GTK_LABEL(l), name);
|
||||
|
|
|
@ -92,8 +92,8 @@ formatname( GtkTreeViewColumn * col UNUSED, GtkCellRenderer * rend,
|
|||
}
|
||||
else if( TR_STATUS_DOWNLOAD & status )
|
||||
{
|
||||
bottom = g_strdup_printf( ngettext( "Downloading from %i of %i peer",
|
||||
"Downloading from %i of %i peers",
|
||||
bottom = g_strdup_printf( ngettext( "Downloading from %i of %i connections",
|
||||
"Downloading from %i of %i connections",
|
||||
tpeers ), dpeers, tpeers );
|
||||
}
|
||||
else
|
||||
|
|
1
gtk/ui.h
1
gtk/ui.h
|
@ -23,6 +23,7 @@ const char * fallback_ui_file =
|
|||
" </menu>\n"
|
||||
" <menu action='help-menu'>\n"
|
||||
" <menuitem action='toggle-message-log'/>\n"
|
||||
" <menuitem action='show-stats'/>\n"
|
||||
" <separator/>\n"
|
||||
" <menuitem action='show-about-dialog'/>\n"
|
||||
" </menu>\n"
|
||||
|
|
|
@ -9,6 +9,7 @@ gtk/ipc.c
|
|||
gtk/main.c
|
||||
gtk/makemeta-ui.c
|
||||
gtk/msgwin.c
|
||||
gtk/stats.c
|
||||
gtk/torrent-inspector.c
|
||||
gtk/tr_cell_renderer_progress.c
|
||||
gtk/tr_core.c
|
||||
|
|
Loading…
Reference in a new issue