* Makefile.am:
[modest] / src / modest-text-utils.c
index 9d26aed..9d09413 100644 (file)
@@ -33,6 +33,7 @@
 #include <stdlib.h>
 #include <glib/gi18n.h>
 #include <regex.h>
+#include <modest-tny-platform-factory.h>
 #include "modest-text-utils.h"
 
 
@@ -491,7 +492,6 @@ modest_text_utils_quote_plain_text (const gchar *text,
        gint indent, breakpoint, rem_indent = 0;
        GString *q, *l, *remaining;
        gsize len;
-       gchar *tmp;
 
        /* remaining will store the rest of the line if we have to break it */
        q = g_string_new (cite);
@@ -757,17 +757,43 @@ modest_text_utils_utf8_strcmp (const gchar* s1, const gchar *s2, gboolean insens
        return result;
 }
 
+static GHashTable*
+get_display_date_cache (void)
+{
+       TnyPlatformFactory *fakt;
+       ModestCacheMgr     *cache_mgr;
+
+       fakt = modest_tny_platform_factory_get_instance ();
+       
+       cache_mgr =  modest_tny_platform_factory_get_cache_mgr_instance
+               (MODEST_TNY_PLATFORM_FACTORY(fakt));
+       
+       return modest_cache_mgr_get_cache (cache_mgr,
+                                          MODEST_CACHE_MGR_CACHE_TYPE_DATE_STRING);
+}
+
+
 
 const gchar*
 modest_text_utils_get_display_date (time_t date)
 {
+       static GHashTable *date_cache = NULL;
+
        struct tm date_tm, now_tm; 
        time_t now;
 
        const gint buf_size = 64; 
        static gchar date_buf[64]; /* buf_size is not ... */
        static gchar now_buf[64];  /* ...const enough... */
+       gchar* cached_val;
        
+       if (G_UNLIKELY(!date_cache))
+               date_cache = get_display_date_cache ();
+       
+       cached_val = g_hash_table_lookup (date_cache, &date);
+       if (cached_val)
+               return cached_val;
+                                                   
        now = time (NULL);
        
        localtime_r(&now, &now_tm);
@@ -781,8 +807,11 @@ modest_text_utils_get_display_date (time_t date)
        /* if this is today, get the time instead of the date */
        if (strcmp (date_buf, now_buf) == 0)
                strftime (date_buf, buf_size, _("%X"), &date_tm); 
-               
-       return date_buf;
+
+       cached_val = g_strdup(date_buf);
+       g_hash_table_insert (date_cache, (gpointer)&date, (gpointer)cached_val);
+       
+       return cached_val;
 }
 
 gboolean 
@@ -841,3 +870,29 @@ modest_text_utils_validate_email_address (const gchar *email_address)
 
        return (count >= 1) ? TRUE : FALSE;
 }
+
+
+
+
+gchar *
+modest_text_utils_get_display_size (gint size)
+{
+       const int KB=1024;
+       const int MB=1024 * KB;
+       const int GB=1024 * MB;
+       const int TB=1024 * GB;
+       const int PB=1024 * TB;
+
+       if (size < KB)
+               return g_strdup_printf (_("%0.2f Kb"), (double)size / KB);
+       else if (size < MB)
+               return g_strdup_printf (_("%d Kb"), size / KB);
+       else if (size < GB)
+               return g_strdup_printf (_("%d Mb"), size / MB);
+       else if (size < TB)
+               return g_strdup_printf (_("%d Gb"), size/ GB);
+       else if (size < PB)
+               return g_strdup_printf (_("%d Tb"), size/ TB);
+       else
+               return g_strdup_printf (_("Very big"));
+}