2007-11-27 03:29:51 +00:00
|
|
|
/*
|
2011-01-19 13:48:47 +00:00
|
|
|
* This file Copyright (C) Mnemosyne LLC
|
2007-11-27 03:29:51 +00:00
|
|
|
*
|
2010-12-27 19:18:17 +00:00
|
|
|
* This file is licensed by the GPL version 2. Works owned by the
|
2007-11-27 03:29:51 +00:00
|
|
|
* Transmission project are granted a special exemption to clause 2(b)
|
2008-09-23 19:11:04 +00:00
|
|
|
* so that the bulk of its code can remain under the MIT license.
|
2007-11-27 03:29:51 +00:00
|
|
|
* This exemption does not extend to derived works not owned by
|
|
|
|
* the Transmission project.
|
2008-09-23 19:11:04 +00:00
|
|
|
*
|
2008-03-08 04:53:11 +00:00
|
|
|
* $Id$
|
2007-11-27 03:29:51 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <glib/gi18n.h>
|
|
|
|
#include <gtk/gtk.h>
|
|
|
|
#include "hig.h"
|
|
|
|
#include "stats.h"
|
2008-02-26 19:58:03 +00:00
|
|
|
#include "tr-core.h"
|
2010-02-01 04:54:10 +00:00
|
|
|
#include "tr-prefs.h"
|
2011-03-03 01:59:25 +00:00
|
|
|
#include "util.h"
|
2007-11-27 03:29:51 +00:00
|
|
|
|
2008-04-22 14:07:42 +00:00
|
|
|
enum
|
|
|
|
{
|
2010-01-03 17:33:22 +00:00
|
|
|
TR_RESPONSE_RESET = 1
|
2008-04-22 14:07:42 +00:00
|
|
|
};
|
|
|
|
|
2007-11-27 03:29:51 +00:00
|
|
|
struct stat_ui
|
|
|
|
{
|
2008-09-23 19:11:04 +00:00
|
|
|
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;
|
2007-11-27 03:29:51 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
2011-03-04 15:49:51 +00:00
|
|
|
setLabel( GtkWidget * w, const char * str )
|
2007-11-27 03:29:51 +00:00
|
|
|
{
|
2011-01-21 16:32:27 +00:00
|
|
|
gtr_label_set_text( GTK_LABEL( w ), str );
|
2007-11-27 03:29:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2011-03-04 15:49:51 +00:00
|
|
|
setLabelFromRatio( GtkWidget * w, double d )
|
2007-11-27 03:29:51 +00:00
|
|
|
{
|
2007-12-19 12:38:36 +00:00
|
|
|
char buf[128];
|
2008-09-23 19:11:04 +00:00
|
|
|
|
2008-01-04 18:52:39 +00:00
|
|
|
tr_strlratio( buf, d, sizeof( buf ) );
|
2007-12-19 12:38:36 +00:00
|
|
|
setLabel( w, buf );
|
2007-11-27 03:29:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
updateStats( gpointer gdata )
|
|
|
|
{
|
2011-03-04 15:49:51 +00:00
|
|
|
char buf[128];
|
|
|
|
const char * fmt;
|
2007-11-27 03:29:51 +00:00
|
|
|
tr_session_stats one, all;
|
2011-03-04 15:49:51 +00:00
|
|
|
const size_t buflen = sizeof( buf );
|
|
|
|
struct stat_ui * ui = gdata;
|
2008-09-23 19:11:04 +00:00
|
|
|
|
2011-03-03 01:59:25 +00:00
|
|
|
tr_sessionGetStats( gtr_core_session( ui->core ), &one );
|
|
|
|
tr_sessionGetCumulativeStats( gtr_core_session( ui->core ), &all );
|
2007-11-27 03:29:51 +00:00
|
|
|
|
2011-03-04 15:49:51 +00:00
|
|
|
setLabel( ui->one_up_lb, tr_strlsize( buf, one.uploadedBytes, buflen ) );
|
|
|
|
setLabel( ui->one_down_lb, tr_strlsize( buf, one.downloadedBytes, buflen ) );
|
|
|
|
setLabel( ui->one_time_lb, tr_strltime( buf, one.secondsActive, buflen ) );
|
2007-11-27 03:29:51 +00:00
|
|
|
setLabelFromRatio( ui->one_ratio_lb, one.ratio );
|
2008-03-08 16:10:13 +00:00
|
|
|
|
2011-05-02 17:58:27 +00:00
|
|
|
fmt = ngettext( "Started %'d time", "Started %'d times",
|
|
|
|
(int)all.sessionCount );
|
2011-03-04 15:49:51 +00:00
|
|
|
g_snprintf( buf, buflen, fmt, (int)all.sessionCount );
|
2008-03-08 16:10:13 +00:00
|
|
|
setLabel( ui->all_sessions_lb, buf );
|
2011-03-04 15:49:51 +00:00
|
|
|
setLabel( ui->all_up_lb, tr_strlsize( buf, all.uploadedBytes, buflen ) );
|
|
|
|
setLabel( ui->all_down_lb, tr_strlsize( buf, all.downloadedBytes, buflen ) );
|
|
|
|
setLabel( ui->all_time_lb, tr_strltime( buf, all.secondsActive, buflen ) );
|
2007-11-27 03:29:51 +00:00
|
|
|
setLabelFromRatio( ui->all_ratio_lb, all.ratio );
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2008-06-05 20:41:32 +00:00
|
|
|
static void
|
2011-03-04 15:49:51 +00:00
|
|
|
dialogDestroyed( gpointer p, GObject * dialog UNUSED )
|
2008-06-05 20:41:32 +00:00
|
|
|
{
|
|
|
|
g_source_remove( GPOINTER_TO_UINT( p ) );
|
|
|
|
}
|
|
|
|
|
2007-11-27 03:29:51 +00:00
|
|
|
static void
|
2011-03-04 15:49:51 +00:00
|
|
|
dialogResponse( GtkDialog * dialog, gint response, gpointer gdata )
|
2007-11-27 03:29:51 +00:00
|
|
|
{
|
2008-04-22 14:07:42 +00:00
|
|
|
struct stat_ui * ui = gdata;
|
|
|
|
|
2010-01-03 17:33:22 +00:00
|
|
|
if( response == TR_RESPONSE_RESET )
|
2008-04-22 14:07:42 +00:00
|
|
|
{
|
2010-01-03 17:58:33 +00:00
|
|
|
const char * primary = _( "Reset your statistics?" );
|
2010-12-27 19:18:17 +00:00
|
|
|
const char * secondary = _( "These statistics are for your information only. "
|
2010-01-03 17:58:33 +00:00
|
|
|
"Resetting them doesn't affect the statistics logged by your BitTorrent trackers." );
|
|
|
|
const int flags = GTK_DIALOG_DESTROY_WITH_PARENT
|
|
|
|
| GTK_DIALOG_MODAL;
|
|
|
|
GtkWidget * w = gtk_message_dialog_new( GTK_WINDOW( dialog ),
|
|
|
|
flags,
|
|
|
|
GTK_MESSAGE_QUESTION,
|
|
|
|
GTK_BUTTONS_NONE,
|
|
|
|
"%s", primary );
|
|
|
|
gtk_dialog_add_buttons( GTK_DIALOG( w ),
|
|
|
|
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
|
|
|
|
_( "_Reset" ), TR_RESPONSE_RESET,
|
|
|
|
NULL );
|
|
|
|
gtk_message_dialog_format_secondary_text( GTK_MESSAGE_DIALOG( w ), "%s", secondary );
|
|
|
|
if( gtk_dialog_run( GTK_DIALOG( w ) ) == TR_RESPONSE_RESET )
|
|
|
|
{
|
2011-03-03 01:59:25 +00:00
|
|
|
tr_sessionClearStats( gtr_core_session( ui->core ) );
|
2010-01-03 17:58:33 +00:00
|
|
|
updateStats( ui );
|
|
|
|
}
|
|
|
|
gtk_widget_destroy( w );
|
2008-04-22 14:07:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if( response == GTK_RESPONSE_CLOSE )
|
|
|
|
gtk_widget_destroy( GTK_WIDGET( dialog ) );
|
2007-11-27 03:29:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
GtkWidget*
|
2010-12-21 19:20:58 +00:00
|
|
|
gtr_stats_dialog_new( GtkWindow * parent, TrCore * core )
|
2007-11-27 03:29:51 +00:00
|
|
|
{
|
2011-03-04 15:49:51 +00:00
|
|
|
guint i;
|
|
|
|
GtkWidget * d;
|
|
|
|
GtkWidget * t;
|
|
|
|
GtkWidget * l;
|
2011-08-13 21:08:53 +00:00
|
|
|
guint row = 0;
|
2007-11-27 03:29:51 +00:00
|
|
|
struct stat_ui * ui = g_new0( struct stat_ui, 1 );
|
|
|
|
|
2010-01-03 17:33:22 +00:00
|
|
|
d = gtk_dialog_new_with_buttons( _( "Statistics" ),
|
2007-11-27 03:29:51 +00:00
|
|
|
parent,
|
2010-12-25 02:05:15 +00:00
|
|
|
GTK_DIALOG_DESTROY_WITH_PARENT,
|
2010-01-03 17:33:22 +00:00
|
|
|
_( "_Reset" ), TR_RESPONSE_RESET,
|
2008-07-23 13:42:30 +00:00
|
|
|
GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE,
|
2007-11-27 03:29:51 +00:00
|
|
|
NULL );
|
2008-07-22 21:01:28 +00:00
|
|
|
gtk_dialog_set_default_response( GTK_DIALOG( d ),
|
|
|
|
GTK_RESPONSE_CLOSE );
|
|
|
|
gtk_dialog_set_alternative_button_order( GTK_DIALOG( d ),
|
|
|
|
GTK_RESPONSE_CLOSE,
|
2010-01-03 17:33:22 +00:00
|
|
|
TR_RESPONSE_RESET,
|
2008-07-22 21:01:28 +00:00
|
|
|
-1 );
|
2007-11-27 03:29:51 +00:00
|
|
|
t = hig_workarea_create( );
|
|
|
|
ui->core = core;
|
|
|
|
|
|
|
|
hig_workarea_add_section_title( t, &row, _( "Current Session" ) );
|
2008-09-23 19:11:04 +00:00
|
|
|
l = ui->one_up_lb = gtk_label_new( NULL );
|
2011-01-21 17:31:35 +00:00
|
|
|
gtk_label_set_single_line_mode( GTK_LABEL( l ), TRUE );
|
2008-09-23 19:11:04 +00:00
|
|
|
hig_workarea_add_row( t, &row, _( "Uploaded:" ), l, NULL );
|
|
|
|
l = ui->one_down_lb = gtk_label_new( NULL );
|
2011-01-21 17:31:35 +00:00
|
|
|
gtk_label_set_single_line_mode( GTK_LABEL( l ), TRUE );
|
2008-09-23 19:11:04 +00:00
|
|
|
hig_workarea_add_row( t, &row, _( "Downloaded:" ), l, NULL );
|
|
|
|
l = ui->one_ratio_lb = gtk_label_new( NULL );
|
2011-01-21 17:31:35 +00:00
|
|
|
gtk_label_set_single_line_mode( GTK_LABEL( l ), TRUE );
|
2008-09-23 19:11:04 +00:00
|
|
|
hig_workarea_add_row( t, &row, _( "Ratio:" ), l, NULL );
|
|
|
|
l = ui->one_time_lb = gtk_label_new( NULL );
|
2011-01-21 17:31:35 +00:00
|
|
|
gtk_label_set_single_line_mode( GTK_LABEL( l ), TRUE );
|
2008-09-23 19:11:04 +00:00
|
|
|
hig_workarea_add_row( t, &row, _( "Duration:" ), l, NULL );
|
2007-11-27 03:29:51 +00:00
|
|
|
hig_workarea_add_section_divider( t, &row );
|
2008-09-23 19:11:04 +00:00
|
|
|
hig_workarea_add_section_title( t, &row, _( "Total" ) );
|
|
|
|
l = ui->all_sessions_lb = gtk_label_new( _( "Started %'d time" ) );
|
2011-01-21 17:31:35 +00:00
|
|
|
gtk_label_set_single_line_mode( GTK_LABEL( l ), TRUE );
|
2008-09-23 19:11:04 +00:00
|
|
|
hig_workarea_add_label_w( t, row++, l );
|
|
|
|
l = ui->all_up_lb = gtk_label_new( NULL );
|
2011-01-21 17:31:35 +00:00
|
|
|
gtk_label_set_single_line_mode( GTK_LABEL( l ), TRUE );
|
2008-09-23 19:11:04 +00:00
|
|
|
hig_workarea_add_row( t, &row, _( "Uploaded:" ), l, NULL );
|
|
|
|
l = ui->all_down_lb = gtk_label_new( NULL );
|
2011-01-21 17:31:35 +00:00
|
|
|
gtk_label_set_single_line_mode( GTK_LABEL( l ), TRUE );
|
2008-09-23 19:11:04 +00:00
|
|
|
hig_workarea_add_row( t, &row, _( "Downloaded:" ), l, NULL );
|
|
|
|
l = ui->all_ratio_lb = gtk_label_new( NULL );
|
2011-01-21 17:31:35 +00:00
|
|
|
gtk_label_set_single_line_mode( GTK_LABEL( l ), TRUE );
|
2008-09-23 19:11:04 +00:00
|
|
|
hig_workarea_add_row( t, &row, _( "Ratio:" ), l, NULL );
|
|
|
|
l = ui->all_time_lb = gtk_label_new( NULL );
|
2011-01-21 17:31:35 +00:00
|
|
|
gtk_label_set_single_line_mode( GTK_LABEL( l ), TRUE );
|
2008-09-23 19:11:04 +00:00
|
|
|
hig_workarea_add_row( t, &row, _( "Duration:" ), l, NULL );
|
2007-11-27 03:29:51 +00:00
|
|
|
hig_workarea_finish( t, &row );
|
2010-12-22 03:12:47 +00:00
|
|
|
gtr_dialog_set_content( GTK_DIALOG( d ), t );
|
2007-11-27 03:29:51 +00:00
|
|
|
|
|
|
|
updateStats( ui );
|
2008-09-23 19:11:04 +00:00
|
|
|
g_object_set_data_full( G_OBJECT( d ), "data", ui, g_free );
|
|
|
|
g_signal_connect( d, "response", G_CALLBACK( dialogResponse ), ui );
|
2011-08-08 17:06:46 +00:00
|
|
|
i = gdk_threads_add_timeout_seconds( SECONDARY_WINDOW_REFRESH_INTERVAL_SECONDS, updateStats, ui );
|
2008-06-05 20:41:32 +00:00
|
|
|
g_object_weak_ref( G_OBJECT( d ), dialogDestroyed, GUINT_TO_POINTER( i ) );
|
2007-11-27 03:29:51 +00:00
|
|
|
return d;
|
|
|
|
}
|