Changeset 4338


Ignore:
Timestamp:
Dec 26, 2007, 6:38:33 AM (14 years ago)
Author:
charles
Message:

(gtk) fix wrong units in the s stats dialog. plug small memory leak.

Location:
trunk/gtk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/gtk/stats.c

    r4217 r4338  
    6060    setLabel( ui->one_up_lb, tr_strlsize( buf, one.uploadedBytes, sizeof(buf) ) );
    6161    setLabel( ui->one_down_lb, tr_strlsize( buf, one.downloadedBytes, sizeof(buf) ) );
    62     setLabel( ui->one_time_lb, tr_strlsize( buf, one.secondsActive, sizeof(buf) ) );
     62    setLabel( ui->one_time_lb, tr_strltime( buf, one.secondsActive, sizeof(buf) ) );
    6363    setLabelFromRatio( ui->one_ratio_lb, one.ratio );
    6464    setLabel( ui->all_sessions_lb, g_strdup_printf( _("Started %d times"), (int)all.sessionCount ) );
    6565    setLabel( ui->all_up_lb, tr_strlsize( buf, all.uploadedBytes, sizeof(buf) ) );
    6666    setLabel( ui->all_down_lb, tr_strlsize( buf, all.downloadedBytes, sizeof(buf) ) );
    67     setLabel( ui->all_time_lb, readabletime( all.secondsActive ) );
     67    setLabel( ui->all_time_lb, tr_strltime( buf, all.secondsActive, sizeof(buf) ) );
    6868    setLabelFromRatio( ui->all_ratio_lb, all.ratio );
    6969
  • trunk/gtk/tr_torrent.c

    r4306 r4338  
    310310                top = g_strdup_printf( _("Stalled (%.1f%%)"), prog );
    311311            else {
    312                 char * timestr = readabletime(eta);
     312                char timestr[128];
     313                tr_strltime( timestr, eta, sizeof( timestr ) );
    313314                top = g_strdup_printf( _("%s remaining (%.1f%%)"), timestr, prog );
    314                 g_free(timestr);
    315315            }
    316316            break;
  • trunk/gtk/util.c

    r4273 r4338  
    9292#define DAYS(s)                 ((s) / 60 / 60 / 24 % 7)
    9393
    94 char *
    95 readabletime(int secs) {
    96   if(60 > secs)
    97     return g_strdup_printf(_("%i %s"),
    98       SECONDS(secs), ngettext("sec", "secs", SECONDS(secs)));
    99   else if(60 * 60 > secs)
    100     return g_strdup_printf(_("%i %s %i %s"),
    101       MINUTES(secs), ngettext("min", "mins", MINUTES(secs)),
    102       SECONDS(secs), ngettext("sec", "secs", SECONDS(secs)));
    103   else if(60 * 60 * 24 > secs)
    104     return g_strdup_printf(_("%i %s %i %s"),
    105       HOURS(secs),   ngettext("hr", "hrs", HOURS(secs)),
    106       MINUTES(secs), ngettext("min", "mins", MINUTES(secs)));
    107   else
    108     return g_strdup_printf(_("%i %s %i %s"),
    109       DAYS(secs),    ngettext("day", "days", DAYS(secs)),
    110       HOURS(secs),   ngettext("hr", "hrs", HOURS(secs)));
     94char*
     95tr_strltime( char * buf, int secs, size_t buflen )
     96{
     97    if( secs < 60 )
     98    {
     99        g_snprintf( buf, buflen, _( "%i %s" ),
     100                    SECONDS(secs), ngettext("sec", "secs", SECONDS(secs)));
     101    }
     102    else if( secs < 60*60 )
     103    {
     104        g_snprintf( buf, buflen, _("%i %s %i %s"),
     105                    MINUTES(secs), ngettext("min", "mins", MINUTES(secs)),
     106                    SECONDS(secs), ngettext("sec", "secs", SECONDS(secs)));
     107    }
     108    else if( secs < 60*60*24 )
     109    {
     110        g_snprintf( buf, buflen, _("%i %s %i %s"),
     111                    HOURS(secs),   ngettext("hr", "hrs", HOURS(secs)),
     112                    MINUTES(secs), ngettext("min", "mins", MINUTES(secs)));
     113    }
     114    else
     115    {
     116        g_snprintf( buf, buflen, _("%i %s %i %s"),
     117                    DAYS(secs),  ngettext("day", "days", DAYS(secs)),
     118                    HOURS(secs), ngettext("hr", "hrs", HOURS(secs)));
     119    }
     120
     121    return buf;
    111122}
    112123
  • trunk/gtk/util.h

    r4210 r4338  
    5151char* tr_strlspeed (char * buf, double KiBps, size_t buflen );
    5252
    53 /* return a human-readable string for the time given in seconds.
    54    the string must be g_free()d */
    55 char *
    56 readabletime(int secs);
     53/* return a human-readable string for the time given in seconds. */
     54char* tr_strltime( char * buf, int secs, size_t buflen );
    5755
    5856char *
Note: See TracChangeset for help on using the changeset viewer.