Adjust the number of decimals shown with sizes based on the number size,
 as is done with the ratio.
This commit is contained in:
Josh Elsasser
2006-02-24 14:07:38 +00:00
parent 2466d6e3bc
commit ceefe97ce2
4 changed files with 17 additions and 14 deletions

View File

@@ -417,9 +417,9 @@ makeinfowind(GtkWindow *parent, tr_handle_t *tr, int id) {
INFOLINEA(table, ii, _("Tracker:"), g_strdup_printf("http://%s:%i", INFOLINEA(table, ii, _("Tracker:"), g_strdup_printf("http://%s:%i",
sb[id].info.trackerAddress, sb[id].info.trackerPort)); sb[id].info.trackerAddress, sb[id].info.trackerPort));
INFOLINE(table, ii, _("Announce:"), sb[id].info.trackerAnnounce); INFOLINE(table, ii, _("Announce:"), sb[id].info.trackerAnnounce);
INFOLINEA(table, ii, _("Piece Size:"), readablesize(sb[id].info.pieceSize, 1)); INFOLINEA(table, ii, _("Piece Size:"), readablesize(sb[id].info.pieceSize));
INFOLINEF(table, ii, "%i", _("Pieces:"), sb[id].info.pieceCount); INFOLINEF(table, ii, "%i", _("Pieces:"), sb[id].info.pieceCount);
INFOLINEA(table, ii, _("Total Size:"), readablesize(sb[id].info.totalSize, 1)); INFOLINEA(table, ii, _("Total Size:"), readablesize(sb[id].info.totalSize));
if(0 > sb[id].seeders) if(0 > sb[id].seeders)
INFOLINE(table, ii, _("Seeders:"), _("?")); INFOLINE(table, ii, _("Seeders:"), _("?"));
else else
@@ -432,8 +432,8 @@ makeinfowind(GtkWindow *parent, tr_handle_t *tr, int id) {
INFOSEP(table, ii); INFOSEP(table, ii);
INFOLINE(table, ii, _("Directory:"), sb[id].folder); INFOLINE(table, ii, _("Directory:"), sb[id].folder);
INFOLINEA(table, ii, _("Downloaded:"), readablesize(sb[id].downloaded, 1)); INFOLINEA(table, ii, _("Downloaded:"), readablesize(sb[id].downloaded));
INFOLINEA(table, ii, _("Uploaded:"), readablesize(sb[id].uploaded, 1)); INFOLINEA(table, ii, _("Uploaded:"), readablesize(sb[id].uploaded));
INFOSEP(table, ii); INFOSEP(table, ii);

View File

@@ -682,7 +682,7 @@ dfname(GtkTreeViewColumn *col SHUTUP, GtkCellRenderer *rend,
upeers = 0; upeers = 0;
if(0 > dpeers) if(0 > dpeers)
dpeers = 0; dpeers = 0;
mb = readablesize(size, 1); mb = readablesize(size);
prog *= 100; prog *= 100;
if(status & TR_STATUS_CHECK) if(status & TR_STATUS_CHECK)
@@ -744,12 +744,12 @@ dfprog(GtkTreeViewColumn *col SHUTUP, GtkCellRenderer *rend,
else if(1.0 < prog) else if(1.0 < prog)
prog = 1.0; prog = 1.0;
ulstr = readablesize(ul * 1024.0, 2); ulstr = readablesize(ul * 1024.0);
if(1.0 == prog) { if(1.0 == prog) {
dlstr = ratiostr(down, up); dlstr = ratiostr(down, up);
str = g_strdup_printf(_("Ratio: %s\nUL: %s/s"), dlstr, ulstr); str = g_strdup_printf(_("Ratio: %s\nUL: %s/s"), dlstr, ulstr);
} else { } else {
dlstr = readablesize(dl * 1024.0, 2); dlstr = readablesize(dl * 1024.0);
str = g_strdup_printf(_("DL: %s/s\nUL: %s/s"), dlstr, ulstr); str = g_strdup_printf(_("DL: %s/s\nUL: %s/s"), dlstr, ulstr);
} }
marked = g_markup_printf_escaped("<small>%s</small>", str); marked = g_markup_printf_escaped("<small>%s</small>", str);
@@ -796,8 +796,8 @@ updatemodel(gpointer gdata) {
/* update the status bar */ /* update the status bar */
tr_torrentRates(data->tr, &up, &down); tr_torrentRates(data->tr, &up, &down);
downstr = readablesize(down * 1024.0, 2); downstr = readablesize(down * 1024.0);
upstr = readablesize(up * 1024.0, 2); upstr = readablesize(up * 1024.0);
str = g_strdup_printf(_(" Total DL: %s/s Total UL: %s/s"), str = g_strdup_printf(_(" Total DL: %s/s Total UL: %s/s"),
upstr, downstr); upstr, downstr);
gtk_statusbar_pop(data->bar, 0); gtk_statusbar_pop(data->bar, 0);

View File

@@ -36,6 +36,8 @@
#include "util.h" #include "util.h"
#define BESTDECIMAL(d) (10.0 > (d) ? 2 : (100.0 > (d) ? 1 : 0))
static void static void
sigexithandler(int sig); sigexithandler(int sig);
static void static void
@@ -64,7 +66,7 @@ static const char *sizestrs[] = {
}; };
char * char *
readablesize(guint64 size, int decimals) { readablesize(guint64 size) {
unsigned int ii; unsigned int ii;
double small = size; double small = size;
@@ -76,7 +78,8 @@ readablesize(guint64 size, int decimals) {
ii++; ii++;
} }
return g_strdup_printf("%.*f %s", decimals, small, gettext(sizestrs[ii])); return g_strdup_printf("%.*f %s", BESTDECIMAL(small), small,
gettext(sizestrs[ii]));
} }
char * char *

View File

@@ -48,10 +48,10 @@ typedef void (*callbackfunc_t)(void*);
gboolean gboolean
strbool(const char *str); strbool(const char *str);
/* return a human-readable string for the size given in bytes with the /* return a human-readable string for the size given in bytes.
requested number of decimal places. the string must be g_free()d */ the string must be g_free()d */
char * char *
readablesize(guint64 size, int decimals); readablesize(guint64 size);
/* returns a string representing the download ratio. /* returns a string representing the download ratio.
the string must be g_free()d */ the string must be g_free()d */