summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorTingPing <tingping@tingping.se>2014-04-15 04:05:18 -0400
committerTingPing <tingping@tingping.se>2014-04-15 04:05:18 -0400
commit8a0f2b1d218280905f5409294c897eaee8acfeb7 (patch)
treeed5bbcc8d3d608f44c4234ffcac6de653efbef76
parent660b860ddd20b2cd0d507c2f2f94a92da20ee153 (diff)
Use glib to format filesize in dccgui
-rw-r--r--src/fe-gtk/dccgui.c21
1 files changed, 5 insertions, 16 deletions
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