From 8a0f2b1d218280905f5409294c897eaee8acfeb7 Mon Sep 17 00:00:00 2001 From: TingPing Date: Tue, 15 Apr 2014 04:05:18 -0400 Subject: Use glib to format filesize in dccgui --- src/fe-gtk/dccgui.c | 21 +++++---------------- 1 file changed, 5 insertions(+), 16 deletions(-) (limited to 'src') diff --git a/src/fe-gtk/dccgui.c b/src/fe-gtk/dccgui.c index 562fe9e5..6d6a033d 100644 --- a/src/fe-gtk/dccgui.c +++ b/src/fe-gtk/dccgui.c @@ -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 -- cgit 1.4.1