Changeset 10986


Ignore:
Timestamp:
Jul 9, 2010, 8:53:38 PM (12 years ago)
Author:
charles
Message:

(trunk) some units formatter cleanup.

Location:
trunk
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/gtk/details.c

    r10939 r10986  
    1212
    1313#include <assert.h>
    14 #include <math.h> /* ceil() */
    1514#include <stddef.h>
    1615#include <stdio.h> /* sscanf */
     
    11931192                const tr_peer_stat  * peer )
    11941193{
    1195     char up_speed[64];
    1196     char down_speed[64];
    1197     char up_count[64];
    1198     char down_count[64];
    1199     char blocks_to_peer[64];
    1200     char blocks_to_client[64];
    1201     char cancelled_by_peer[64];
    1202     char cancelled_by_client[64];
     1194    char up_speed[64] = { '\0' };
     1195    char down_speed[64] = { '\0' };
     1196    char up_count[64] = { '\0' };
     1197    char down_count[64] = { '\0' };
     1198    char blocks_to_peer[64] = { '\0' };
     1199    char blocks_to_client[64] = { '\0' };
     1200    char cancelled_by_peer[64] = { '\0' };
     1201    char cancelled_by_client[64] = { '\0' };
    12031202
    12041203    if( peer->rateToPeer_KBps > 0.01 )
    12051204        tr_formatter_speed_KBps( up_speed, peer->rateToPeer_KBps, sizeof( up_speed ) );
    1206     else
    1207         *up_speed = '\0';
    12081205
    12091206    if( peer->rateToClient_KBps > 0 )
    12101207        tr_formatter_speed_KBps( down_speed, peer->rateToClient_KBps, sizeof( down_speed ) );
    1211     else
    1212         *down_speed = '\0';
    12131208
    12141209    if( peer->pendingReqsToPeer > 0 )
    12151210        g_snprintf( down_count, sizeof( down_count ), "%d", peer->pendingReqsToPeer );
    1216     else
    1217         *down_count = '\0';
    12181211
    12191212    if( peer->pendingReqsToClient > 0 )
    12201213        g_snprintf( up_count, sizeof( down_count ), "%d", peer->pendingReqsToClient );
    1221     else
    1222         *up_count = '\0';
    12231214
    12241215    if( peer->blocksToPeer > 0 )
    12251216        g_snprintf( blocks_to_peer, sizeof( blocks_to_peer ), "%"PRIu32, peer->blocksToPeer );
    1226     else
    1227         *blocks_to_peer = '\0';
    12281217
    12291218    if( peer->blocksToClient > 0 )
    12301219        g_snprintf( blocks_to_client, sizeof( blocks_to_client ), "%"PRIu32, peer->blocksToClient );
    1231     else
    1232         *blocks_to_client = '\0';
    12331220
    12341221    if( peer->cancelsToPeer > 0 )
    12351222        g_snprintf( cancelled_by_client, sizeof( cancelled_by_client ), "%"PRIu32, peer->cancelsToPeer );
    1236     else
    1237         *cancelled_by_client = '\0';
    12381223
    12391224    if( peer->cancelsToClient > 0 )
    12401225        g_snprintf( cancelled_by_peer, sizeof( cancelled_by_peer ), "%"PRIu32, peer->cancelsToClient );
    1241     else
    1242         *cancelled_by_peer = '\0';
    12431226
    12441227    gtk_list_store_set( store, iter,
     
    14081391            gtk_tree_model_get_iter( model, &iter, p );
    14091392            if( speeds_KBps[j] > 0 )
    1410                 tr_formatter_speed_Bps( buf, speeds_KBps[j], sizeof( buf ) );
     1393                tr_formatter_speed_KBps( buf, speeds_KBps[j], sizeof( buf ) );
    14111394            else
    14121395                *buf = '\0';
  • trunk/gtk/tr-window.c

    r10980 r10986  
    404404    int i, n;
    405405    GtkWidget *w, *m;
    406     const int speeds[] = { 5, 10, 20, 30, 40, 50, 75, 100, 150, 200, 250, 500, 750 };
     406    const int speeds_KBps[] = { 5, 10, 20, 30, 40, 50, 75, 100, 150, 200, 250, 500, 750 };
    407407
    408408    m = gtk_menu_new( );
     
    425425    gtk_menu_shell_append( GTK_MENU_SHELL( m ), w );
    426426
    427     for( i=0, n=G_N_ELEMENTS(speeds); i<n; ++i )
     427    for( i=0, n=G_N_ELEMENTS(speeds_KBps); i<n; ++i )
    428428    {
    429429        char buf[128];
    430         tr_strlspeed( buf, speeds[i] * speed_K, sizeof( buf ) );
     430        tr_formatter_speed_KBps( buf, speeds_KBps[i], sizeof( buf ) );
    431431        w = gtk_menu_item_new_with_label( buf );
    432432        g_object_set_data( G_OBJECT( w ), DIRECTION_KEY, GINT_TO_POINTER( dir ) );
    433         g_object_set_data( G_OBJECT( w ), SPEED_KEY, GINT_TO_POINTER( speeds[i] ) );
     433        g_object_set_data( G_OBJECT( w ), SPEED_KEY, GINT_TO_POINTER( speeds_KBps[i] ) );
    434434        g_signal_connect( w, "activate", G_CALLBACK(onSpeedSet), p );
    435435        gtk_menu_shell_append( GTK_MENU_SHELL( m ), w );
  • trunk/gtk/util.c

    r10955 r10986  
    161161    else
    162162        tr_formatter_size_B( buf, bytes, buflen );
    163 
    164     return buf;
    165 }
    166 
    167 char*
    168 tr_strlspeed( char * buf, int bytes_per_second, size_t buflen )
    169 {
    170     if( bytes_per_second < 1 )
    171         g_strlcpy( buf, _( "None" ), buflen );
    172     else
    173         tr_formatter_speed_Bps( buf, bytes_per_second, buflen );
    174163
    175164    return buf;
  • trunk/gtk/util.h

    r10955 r10986  
    6666char* tr_strlsize( char * buf, guint64  size, size_t buflen );
    6767
    68 /* return a human-readable string for the transfer rate given in Bps. */
    69 char* tr_strlspeed( char * buf, int bytes_per_second, size_t buflen );
    70 
    7168/* return a human-readable string for the given ratio. */
    7269char* tr_strlratio( char * buf, double ratio, size_t buflen );
  • trunk/libtransmission/utils.c

    r10977 r10986  
    16441644
    16451645char*
    1646 tr_formatter_speed_Bps( char * buf, uint64_t bytes_per_second, size_t buflen )
     1646tr_formatter_speed_KBps( char * buf, double KBps, size_t buflen )
    16471647{
    16481648    const double K = speed_units.units[TR_FMT_KB].value;
    1649     double speed = bytes_per_second / K;
     1649    double speed = KBps;
    16501650
    16511651    if( speed <= 999.95 ) /* 0.0 KB to 999.9 KB */
  • trunk/libtransmission/utils.h

    r10963 r10986  
    573573                                               const char * gb, const char * tb );
    574574
    575 /* format a speed into a user-readable string. */
    576575extern unsigned int tr_speed_K;
    577 char* tr_formatter_speed_Bps( char * buf, uint64_t Bps, size_t buflen );
    578 static inline char* tr_formatter_speed_KBps( char * buf, double KBps, size_t buflen ) { return tr_formatter_speed_Bps( buf, KBps * tr_speed_K, buflen ); }
    579 static inline char* tr_formatter_speed_MBps( char * buf, double MBps, size_t buflen ) { return tr_formatter_speed_Bps( buf, MBps * tr_speed_K * tr_speed_K, buflen ); }
    580 static inline char* tr_formatter_speed_GBps( char * buf, double GBps, size_t buflen ) { return tr_formatter_speed_Bps( buf, GBps * tr_speed_K * tr_speed_K * tr_speed_K, buflen ); }
    581 
    582 /* format a memory size into a user-readable string. */
    583576extern unsigned int tr_mem_K;
     577extern unsigned int tr_size_K;
     578
     579/* format a speed from KBps into a user-readable string. */
     580char* tr_formatter_speed_KBps( char * buf, double KBps, size_t buflen );
     581
     582/* format a memory size from bytes into a user-readable string. */
    584583char* tr_formatter_mem_B( char * buf, uint64_t bytes, size_t buflen );
    585 static inline char* tr_formatter_mem_KB( char * buf, double KBps, size_t buflen ) { return tr_formatter_mem_B( buf, KBps * tr_mem_K, buflen ); }
     584
     585/* format a memory size from MB into a user-readable string. */
    586586static inline char* tr_formatter_mem_MB( char * buf, double MBps, size_t buflen ) { return tr_formatter_mem_B( buf, MBps * tr_mem_K * tr_mem_K, buflen ); }
    587 static inline char* tr_formatter_mem_GB( char * buf, double GBps, size_t buflen ) { return tr_formatter_mem_B( buf, GBps * tr_mem_K * tr_mem_K * tr_mem_K, buflen ); }
    588 
    589 /* format a file size into a user-readable string. */
    590 extern unsigned int tr_size_K;
     587
     588/* format a file size from bytes into a user-readable string. */
    591589char* tr_formatter_size_B( char * buf, uint64_t bytes, size_t buflen );
    592 static inline char* tr_formatter_size_KB( char * buf, double KBps, size_t buflen ) { return tr_formatter_size_B( buf, KBps * tr_size_K, buflen ); }
    593 static inline char* tr_formatter_size_MB( char * buf, double MBps, size_t buflen ) { return tr_formatter_size_B( buf, MBps * tr_size_K * tr_size_K, buflen ); }
    594 static inline char* tr_formatter_size_GB( char * buf, double GBps, size_t buflen ) { return tr_formatter_size_B( buf, GBps * tr_size_K * tr_size_K * tr_size_K, buflen ); }
    595590
    596591
  • trunk/qt/formatter.cc

    r10957 r10986  
    123123    else {
    124124        char buf[128];
    125         tr_formatter_speed_KBps( buf, speed.Bps( ), sizeof( buf ) );
     125        tr_formatter_speed_KBps( buf, speed.KBps( ), sizeof( buf ) );
    126126        return buf;
    127127    }
Note: See TracChangeset for help on using the changeset viewer.