#include <modest-header-view.h>
#include <modest-header-view-priv.h>
#include <modest-icon-names.h>
-#include <modest-icon-factory.h>
#include <modest-text-utils.h>
+#include <modest-runtime.h>
#include <glib/gi18n.h>
+static GdkPixbuf*
+get_cached_icon (const gchar *name)
+{
+ GError *err = NULL;
+ gpointer pixbuf;
+ gpointer orig_key;
+ static GHashTable *icon_cache = NULL;
+
+ g_return_val_if_fail (name, NULL);
+
+ if (G_UNLIKELY(!icon_cache))
+ icon_cache = modest_cache_mgr_get_cache (modest_runtime_get_cache_mgr(),
+ MODEST_CACHE_MGR_CACHE_TYPE_PIXBUF);
+
+ if (!icon_cache || !g_hash_table_lookup_extended (icon_cache, name, &orig_key,&pixbuf)) {
+ pixbuf = (gpointer)gdk_pixbuf_new_from_file (name, &err);
+ if (!pixbuf) {
+ g_printerr ("modest: error in icon factory while loading '%s': %s\n",
+ name, err->message);
+ g_error_free (err);
+ }
+ /* if we cannot find it, we still insert (if we have a cache), so we get the error
+ * only once */
+ if (icon_cache)
+ g_hash_table_insert (icon_cache, g_strdup(name),(gpointer)pixbuf);
+ }
+ return GDK_PIXBUF(pixbuf);
+}
+
+
/*
* optimization
switch (flag) {
case TNY_HEADER_FLAG_DELETED:
if (G_UNLIKELY(!deleted_pixbuf))
- deleted_pixbuf = modest_icon_factory_get_icon (MODEST_HEADER_ICON_DELETED);
+ deleted_pixbuf = get_cached_icon (MODEST_HEADER_ICON_DELETED);
return deleted_pixbuf;
case TNY_HEADER_FLAG_SEEN:
if (G_UNLIKELY(!seen_pixbuf))
- seen_pixbuf = modest_icon_factory_get_icon (MODEST_HEADER_ICON_READ);
+ seen_pixbuf = get_cached_icon (MODEST_HEADER_ICON_READ);
return seen_pixbuf;
case TNY_HEADER_FLAG_ATTACHMENTS:
if (G_UNLIKELY(!attachments_pixbuf))
- attachments_pixbuf = modest_icon_factory_get_icon (MODEST_HEADER_ICON_ATTACH);
+ attachments_pixbuf = get_cached_icon (MODEST_HEADER_ICON_ATTACH);
return attachments_pixbuf;
default:
if (G_UNLIKELY(!unread_pixbuf))
- unread_pixbuf = modest_icon_factory_get_icon (MODEST_HEADER_ICON_UNREAD);
+ unread_pixbuf = get_cached_icon (MODEST_HEADER_ICON_UNREAD);
return unread_pixbuf;
}
}
-static const gchar*
-get_display_date (time_t date)
-{
- static guint cached_date = 0;
- static const gchar* cached_date_str = NULL;
-
- /* optimization; if the date didn't changed, just reuse the old date str*/
- if (cached_date == date)
- return cached_date_str;
- else {
- cached_date = date;
- return cached_date_str = modest_text_utils_get_display_date (date);
- }
-}
-
-
void
_modest_header_view_msgtype_cell_data (GtkTreeViewColumn *column, GtkCellRenderer *renderer,
GtkTreeModel *tree_model, GtkTreeIter *iter, gpointer user_data)
"weight", (flags & TNY_HEADER_FLAG_SEEN) ? 400: 800,
"style", (flags & TNY_HEADER_FLAG_DELETED) ?
PANGO_STYLE_ITALIC : PANGO_STYLE_NORMAL,
- "text", get_display_date (date),
+ "text", modest_text_utils_get_display_date (date),
NULL);
}
rendobj = G_OBJECT(renderer);
header = g_strdup_printf ("%s %s\n%s",
modest_text_utils_get_display_address (address),
- get_display_date (date),
+ modest_text_utils_get_display_date (date),
subject);
g_free (address);
g_free (subject);
gpointer user_data)
{
TnyHeaderFlags flags;
- guint size;
- gchar *size_str;
- const gchar* unit;
-
- gtk_tree_model_get (tree_model, iter,
+ guint size;
+ gchar *size_str;
+
+ gtk_tree_model_get (tree_model, iter,
TNY_GTK_HEADER_LIST_MODEL_FLAGS_COLUMN, &flags,
TNY_GTK_HEADER_LIST_MODEL_MESSAGE_SIZE_COLUMN, &size,
- -1);
-
- if (size < 1024*1024) {
- unit = _("Kb");
- size /= 1024;
- } else if (size < 1024*1024*1024) {
- unit = _("Mb");
- size /= (1024*1024);
- } else {
- unit = _("Gb");
- size /= (1024*1024*1024);
- }
-
- size_str = g_strdup_printf ("%d %s", size, unit);
-
- g_object_set (G_OBJECT(renderer),
- "weight", (flags & TNY_HEADER_FLAG_SEEN) ? 400: 800,
- "style", (flags & TNY_HEADER_FLAG_DELETED) ?
- PANGO_STYLE_ITALIC : PANGO_STYLE_NORMAL,
- "text", size_str,
+ -1);
+
+ size_str = modest_text_utils_get_display_size (size);
+
+ g_object_set (G_OBJECT(renderer),
+ "weight", (flags & TNY_HEADER_FLAG_SEEN) ? 400: 800,
+ "style", (flags & TNY_HEADER_FLAG_DELETED) ?
+ PANGO_STYLE_ITALIC : PANGO_STYLE_NORMAL,
+ "text", size_str,
NULL);
g_free (size_str);