[balsa] Human-friendly IMAP quota information.



commit 5b2284aa32ae46a6b4b5ab446298b44230c9e570
Author: Pawel Salek <pawsa0 gmail com>
Date:   Wed Mar 3 22:39:56 2010 +0100

    Human-friendly IMAP quota information.
    
    * libbalsa/misc.[hc]:
    * libbalsa/mailbox.c: make libbalsa_size_to_gchar() a common function.
    * src/folder-conf.c: use it for displaying IMAP quota.

 ChangeLog          |    6 ++++++
 libbalsa/mailbox.c |   21 ---------------------
 libbalsa/misc.c    |   28 ++++++++++++++++++++++++++++
 libbalsa/misc.h    |    2 ++
 src/folder-conf.c  |   11 ++++++++---
 5 files changed, 44 insertions(+), 24 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 2d997ba..c48791e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2010-03-03  Albrecht DreÃ?
+
+	* libbalsa/misc.[hc]:
+	* libbalsa/mailbox.c: make libbalsa_size_to_gchar() a common function.
+	* src/folder-conf.c: use it for displaying IMAP quota.
+
 2010-03-03  Peter Bloomfield
 
 	* libbalsa/message.c (libbalsa_message_change_flags): check
diff --git a/libbalsa/mailbox.c b/libbalsa/mailbox.c
index 18588b4..f9faa17 100644
--- a/libbalsa/mailbox.c
+++ b/libbalsa/mailbox.c
@@ -2866,27 +2866,6 @@ mbox_model_get_path(GtkTreeModel * tree_model, GtkTreeIter * iter)
 static GdkPixbuf *status_icons[LIBBALSA_MESSAGE_STATUS_ICONS_NUM];
 static GdkPixbuf *attach_icons[LIBBALSA_MESSAGE_ATTACH_ICONS_NUM];
 
-static gchar *
-libbalsa_size_to_gchar(glong length)
-{
-    gchar retsize[32];
-
-    /* length is long */
-    if (length <= 32768) {
-        g_snprintf (retsize, sizeof(retsize), "%ld", length);
-    } else if (length <= (100*1024)) {
-        float tmp = (float)length/1024.0;
-        g_snprintf (retsize, sizeof(retsize), "%.1fK", tmp);
-    } else if (length <= (1024*1024)) {
-        g_snprintf (retsize, sizeof(retsize), "%ldK", length/1024);
-    } else {
-        float tmp = (float)length/(1024.0*1024.0);
-        g_snprintf (retsize, sizeof(retsize), "%.1fM", tmp);
-    }
-
-    return g_strdup(retsize);
-}
-
 #ifdef BALSA_USE_THREADS
 /* Protects access to mailbox->msgnos_pending; may be locked 
  * with or without the gdk lock, so WE MUST NOT GRAB THE GDK LOCK WHILE
diff --git a/libbalsa/misc.c b/libbalsa/misc.c
index 7d78f2a..319fa8e 100644
--- a/libbalsa/misc.c
+++ b/libbalsa/misc.c
@@ -1311,3 +1311,31 @@ libbalsa_path_is_below_dir(const gchar * path, const gchar * dir)
 
     return dir[len - 1] == G_DIR_SEPARATOR || path[len] == G_DIR_SEPARATOR;
 }
+
+gchar *
+libbalsa_size_to_gchar(guint64 length)
+{
+    gchar retsize[32];
+
+    /* length is long */
+    if (length <= 32768) {
+        g_snprintf (retsize, sizeof(retsize), "%" G_GUINT64_FORMAT, length);
+    } else if (length <= 100*1024) {
+        float tmp = (float)length/1024.0;
+        g_snprintf (retsize, sizeof(retsize), "%.1fK", tmp);
+    } else if (length <= (1024*1024)) {
+        g_snprintf (retsize, sizeof(retsize),
+                    "%" G_GUINT64_FORMAT "K", length/1024);
+    } else if (length <= (100*1024*1024)) {
+        float tmp = (float)length/(1024.0*1024.0);
+        g_snprintf (retsize, sizeof(retsize), "%.1fM", tmp);
+    } else if (length <= (1024*1024*1024)) {
+        g_snprintf (retsize, sizeof(retsize),
+                    "%" G_GUINT64_FORMAT "M", length/(1024*1024));
+    } else {
+        float tmp = (float)length/(1024.0*1024.0*1024.0);
+        g_snprintf (retsize, sizeof(retsize), "%.1fG", tmp);
+    }
+
+    return g_strdup(retsize);
+}
diff --git a/libbalsa/misc.h b/libbalsa/misc.h
index ef0dbe3..bd95855 100644
--- a/libbalsa/misc.h
+++ b/libbalsa/misc.h
@@ -185,6 +185,8 @@ gboolean libbalsa_ldap_exists(const gchar *server);
 
 gboolean libbalsa_path_is_below_dir(const gchar * path, const gchar * dir);
 
+gchar *libbalsa_size_to_gchar(guint64 length);
+
 gchar * libbalsa_text_to_html(const gchar * title, const gchar * body, const gchar * lang);
 GString * libbalsa_html_encode_hyperlinks(GString * paragraph);
 
diff --git a/src/folder-conf.c b/src/folder-conf.c
index c618b18..6de6307 100644
--- a/src/folder-conf.c
+++ b/src/folder-conf.c
@@ -945,10 +945,15 @@ folder_conf_imap_sub_node(BalsaMailboxNode * mn)
                 quotas = g_strdup(_("the server does not support quotas"));
             else if (max == 0 && used == 0)
                 quotas = g_strdup(_("no limits"));
-            else
-                quotas = g_strdup_printf(_("%lu kB of %lu kB (%.1f%%) used"),
-                                         used, max,
+            else {
+                gchar *use_str = libbalsa_size_to_gchar(used * G_GUINT64_CONSTANT(1024));
+                gchar *max_str = libbalsa_size_to_gchar(max * G_GUINT64_CONSTANT(1024));
+
+                quotas = g_strdup_printf(_("%s of %s (%.1f%%) used"), use_str, max_str,
                                          100.0 * (float) used / (float) max);
+                g_free(use_str);
+                g_free(max_str);
+            }
         }
         label = gtk_label_new(quotas);
         gtk_misc_set_alignment(GTK_MISC(label), 0.0, 0.5);



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]