Use glib to format filesize in dccgui

This commit is contained in:
TingPing 2014-04-15 04:05:18 -04:00
parent 660b860ddd
commit 8a0f2b1d21
1 changed files with 5 additions and 16 deletions

View File

@ -103,26 +103,15 @@ static short view_mode; /* 1=download 2=upload 3=both */
#define VIEW_UPLOAD 2
#define VIEW_BOTH 3
#define KILOBYTE 1024
#define MEGABYTE (KILOBYTE * 1024)
#define GIGABYTE (MEGABYTE * 1024)
static void
proper_unit (DCC_SIZE size, char *buf, int buf_len)
{
if (size <= KILOBYTE)
{
snprintf (buf, buf_len, "%"DCC_SFMT"B", size);
}
else if (size > KILOBYTE && size <= MEGABYTE)
{
snprintf (buf, buf_len, "%"DCC_SFMT"kB", size / KILOBYTE);
}
else
{
snprintf (buf, buf_len, "%.2fMB", (float)size / MEGABYTE);
}
gchar *formated_str = g_format_size ((guint64)size);
g_strlcpy (buf, formated_str, buf_len);
g_free (formated_str);
}
static void