Changeset 4322


Ignore:
Timestamp:
Dec 24, 2007, 7:12:52 PM (14 years ago)
Author:
charles
Message:

(gtk) minor filter improvement

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/gtk/tr_window.c

    r4319 r4322  
    616616}
    617617
     618static void
     619updateStats( PrivateData * p )
     620{
     621    char * pch;
     622    char up[32], down[32], buf[128];
     623    struct tr_session_stats stats;
     624    tr_handle * handle = tr_core_handle( p->core );
     625
     626    /* update the stats */
     627    pch = pref_string_get( PREF_KEY_STATUS_BAR_STATS );
     628    if( !strcmp( pch, "session-ratio" ) ) {
     629        tr_getSessionStats( handle, &stats );
     630        g_snprintf( buf, sizeof(buf), _("Ratio: %.1f"), stats.ratio );
     631    } else if( !strcmp( pch, "session-transfer" ) ) {
     632        tr_getSessionStats( handle, &stats );
     633        tr_strlsize( up, stats.uploadedBytes, sizeof( up ) );
     634        tr_strlsize( down, stats.downloadedBytes, sizeof( down ) );
     635        g_snprintf( buf, sizeof( buf ), _( "Down: %s  Up: %s" ), down, up );
     636    } else if( !strcmp( pch, "total-transfer" ) ) {
     637        tr_getCumulativeSessionStats( handle, &stats );
     638        tr_strlsize( up, stats.uploadedBytes, sizeof( up ) );
     639        tr_strlsize( down, stats.downloadedBytes, sizeof( down ) );
     640        g_snprintf( buf, sizeof( buf ), _( "Down: %s  Up: %s" ), down, up );
     641    } else { /* default is total-ratio */
     642        tr_getCumulativeSessionStats( handle, &stats );
     643        g_snprintf( buf, sizeof(buf), _("Ratio: %.1f"), stats.ratio );
     644    }
     645    g_free( pch );
     646    gtk_label_set_text( GTK_LABEL( p->stats_lb ), buf );
     647}
     648
     649static void
     650updateSpeeds( PrivateData * p )
     651{
     652    char buf[128];
     653    float u, d;
     654    tr_handle * handle = tr_core_handle( p->core );
     655
     656    tr_torrentRates( handle, &d, &u );
     657    tr_strlspeed( buf, d, sizeof( buf ) );
     658    gtk_label_set_text( GTK_LABEL( p->dl_lb ), buf );
     659    tr_strlspeed( buf, u, sizeof( buf ) );
     660    gtk_label_set_text( GTK_LABEL( p->ul_lb ), buf );
     661}
     662
    618663
    619664void
     
    621666{
    622667    PrivateData * p = get_private_data( self );
    623     tr_handle * handle = NULL;
    624 
    625     if( p && p->core )
    626         handle = tr_core_handle( p->core );
    627 
    628     if( handle )
    629     {
    630         char * pch;
    631         float u, d;
    632         char up[32], down[32], buf[128];
    633         struct tr_session_stats stats;
    634 
    635         /* update the speeds */
    636         tr_torrentRates( handle, &d, &u );
    637         tr_strlspeed( buf, d, sizeof( buf ) );
    638         gtk_label_set_text( GTK_LABEL( p->dl_lb ), buf );
    639         tr_strlspeed( buf, u, sizeof( buf ) );
    640         gtk_label_set_text( GTK_LABEL( p->ul_lb ), buf );
    641 
     668    if( p && p->core && tr_core_handle(p->core) )
     669    {
     670        updateSpeeds( p );
    642671        updateTorrentCount( p );
    643 
    644         /* update the stats */
    645         pch = pref_string_get( PREF_KEY_STATUS_BAR_STATS );
    646         if( !strcmp( pch, "session-ratio" ) ) {
    647             tr_getSessionStats( handle, &stats );
    648             g_snprintf( buf, sizeof(buf), _("Ratio: %.1f"), stats.ratio );
    649         } else if( !strcmp( pch, "session-transfer" ) ) {
    650             tr_getSessionStats( handle, &stats );
    651             tr_strlsize( up, stats.uploadedBytes, sizeof( up ) );
    652             tr_strlsize( down, stats.downloadedBytes, sizeof( down ) );
    653             g_snprintf( buf, sizeof( buf ), _( "Down: %s  Up: %s" ), down, up );
    654         } else if( !strcmp( pch, "total-transfer" ) ) {
    655             tr_getCumulativeSessionStats( handle, &stats );
    656             tr_strlsize( up, stats.uploadedBytes, sizeof( up ) );
    657             tr_strlsize( down, stats.downloadedBytes, sizeof( down ) );
    658             g_snprintf( buf, sizeof( buf ), _( "Down: %s  Up: %s" ), down, up );
    659         } else { /* default is total-ratio */
    660             tr_getCumulativeSessionStats( handle, &stats );
    661             g_snprintf( buf, sizeof(buf), _("Ratio: %.1f"), stats.ratio );
    662         }
    663         g_free( pch );
    664         gtk_label_set_text( GTK_LABEL( p->stats_lb ), buf );
     672        updateStats( p );
     673        refilter( p );
    665674    }
    666675}
Note: See TracChangeset for help on using the changeset viewer.