add statistics "reset" button

This commit is contained in:
Charles Kerr 2008-04-22 14:07:42 +00:00
parent e87906e5a6
commit 0c1599608d
3 changed files with 39 additions and 6 deletions

View File

@ -16,6 +16,11 @@
#include "stats.h"
#include "tr-core.h"
enum
{
TR_RESPONSE_CLEAR = 1
};
struct stat_ui
{
GtkWidget * one_up_lb;
@ -72,10 +77,22 @@ updateStats( gpointer gdata )
}
static void
dialogResponse( GtkDialog * dialog, gint response UNUSED, gpointer unused UNUSED )
dialogResponse( GtkDialog * dialog, gint response, gpointer gdata )
{
g_source_remove( GPOINTER_TO_UINT( g_object_get_data( G_OBJECT(dialog), "TrTimer" ) ) );
gtk_widget_destroy( GTK_WIDGET( dialog ) );
struct stat_ui * ui = gdata;
if( response == TR_RESPONSE_CLEAR )
{
tr_handle * handle = tr_core_handle( ui->core );
tr_clearSessionStats( handle );
updateStats( ui );
}
if( response == GTK_RESPONSE_CLOSE )
{
g_source_remove( GPOINTER_TO_UINT( g_object_get_data( G_OBJECT(dialog), "TrTimer" ) ) );
gtk_widget_destroy( GTK_WIDGET( dialog ) );
}
}
GtkWidget*
@ -91,6 +108,7 @@ stats_dialog_create( GtkWindow * parent, TrCore * core )
d = gtk_dialog_new_with_buttons( _("Statistics"),
parent,
GTK_DIALOG_DESTROY_WITH_PARENT,
GTK_STOCK_CLEAR, TR_RESPONSE_CLEAR,
GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE,
NULL );
t = hig_workarea_create( );
@ -123,7 +141,7 @@ stats_dialog_create( GtkWindow * parent, TrCore * core )
updateStats( ui );
g_object_set_data_full( G_OBJECT(d), "data", ui, g_free );
g_signal_connect( d, "response", G_CALLBACK(dialogResponse), NULL );
g_signal_connect( d, "response", G_CALLBACK(dialogResponse), ui );
i = g_timeout_add( 1000, updateStats, ui );
g_object_set_data( G_OBJECT(d), "TrTimer", GUINT_TO_POINTER(i) );
return d;

View File

@ -10,8 +10,6 @@
* $Id$
*/
#include <string.h> /* memset */
#include "transmission.h"
#include "bencode.h"
#include "platform.h" /* tr_getConfigDir() */
@ -162,6 +160,21 @@ tr_getCumulativeSessionStats( const tr_handle * handle,
addStats( setme, &getStats(handle)->old, &current );
}
void
tr_clearSessionStats( tr_handle * handle )
{
tr_session_stats zero;
zero.uploadedBytes = 0;
zero.downloadedBytes = 0;
zero.ratio = TR_RATIO_NA;
zero.filesAdded = 0;
zero.sessionCount = 0;
zero.secondsActive = 0;
handle->sessionStats->single = handle->sessionStats->old = zero;
handle->sessionStats->startTime = time( NULL );
}
/**
***
**/

View File

@ -134,6 +134,8 @@ void tr_getSessionStats( const tr_handle * handle,
void tr_getCumulativeSessionStats( const tr_handle * handle,
tr_session_stats * setme );
void tr_clearSessionStats( tr_handle * handle );
/**
***