X-Git-Url: http://git.maemo.org/git/?p=modest;a=blobdiff_plain;f=src%2Fwidgets%2Fmodest-header-view-render.c;h=de70f8ff632a03d34671dae5c22ad11d29c6be0d;hp=2031c5d35c70766e2153aca927d1be39262ab157;hb=592de36d3410bfccb171aed2f6d88d364a59541c;hpb=b54ca9c03e98c7cf3baa11d452cee75f6bb79d9c diff --git a/src/widgets/modest-header-view-render.c b/src/widgets/modest-header-view-render.c index 2031c5d..de70f8f 100644 --- a/src/widgets/modest-header-view-render.c +++ b/src/widgets/modest-header-view-render.c @@ -27,77 +27,63 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ - #include #include #include #include #include #include +#include +#include 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 - */ -static GdkPixbuf* get_pixbuf_for_flag (TnyHeaderFlags flag) { /* optimization */ - static GdkPixbuf *deleted_pixbuf = NULL; - static GdkPixbuf *seen_pixbuf = NULL; - static GdkPixbuf *unread_pixbuf = NULL; - static GdkPixbuf *attachments_pixbuf = NULL; + static GdkPixbuf *deleted_pixbuf = NULL; + static GdkPixbuf *seen_pixbuf = NULL; + static GdkPixbuf *unread_pixbuf = NULL; + static GdkPixbuf *attachments_pixbuf = NULL; + static GdkPixbuf *high_pixbuf = NULL; + static GdkPixbuf *low_pixbuf = NULL; switch (flag) { case TNY_HEADER_FLAG_DELETED: if (G_UNLIKELY(!deleted_pixbuf)) - deleted_pixbuf = get_cached_icon (MODEST_HEADER_ICON_DELETED); + deleted_pixbuf = modest_platform_get_icon (MODEST_HEADER_ICON_DELETED); return deleted_pixbuf; case TNY_HEADER_FLAG_SEEN: if (G_UNLIKELY(!seen_pixbuf)) - seen_pixbuf = get_cached_icon (MODEST_HEADER_ICON_READ); + seen_pixbuf = modest_platform_get_icon (MODEST_HEADER_ICON_READ); return seen_pixbuf; case TNY_HEADER_FLAG_ATTACHMENTS: if (G_UNLIKELY(!attachments_pixbuf)) - attachments_pixbuf = get_cached_icon (MODEST_HEADER_ICON_ATTACH); + attachments_pixbuf = modest_platform_get_icon (MODEST_HEADER_ICON_ATTACH); return attachments_pixbuf; + case TNY_HEADER_FLAG_HIGH_PRIORITY: + if (G_UNLIKELY(!high_pixbuf)) + high_pixbuf = modest_platform_get_icon (MODEST_HEADER_ICON_HIGH_PRIORITY); + return high_pixbuf; + case TNY_HEADER_FLAG_LOW_PRIORITY: + if (G_UNLIKELY(!low_pixbuf)) + low_pixbuf = modest_platform_get_icon (MODEST_HEADER_ICON_LOW_PRIORITY); + return low_pixbuf; default: if (G_UNLIKELY(!unread_pixbuf)) - unread_pixbuf = get_cached_icon (MODEST_HEADER_ICON_UNREAD); + unread_pixbuf = modest_platform_get_icon (MODEST_HEADER_ICON_UNREAD); return unread_pixbuf; } } +static void +set_common_flags (GtkCellRenderer *renderer, TnyHeaderFlags flags) +{ + g_object_set (G_OBJECT(renderer), + "weight", (flags & TNY_HEADER_FLAG_SEEN) ? PANGO_WEIGHT_NORMAL: PANGO_WEIGHT_ULTRABOLD, + "strikethrough", (flags & TNY_HEADER_FLAG_DELETED) ? TRUE:FALSE, + NULL); +} + void _modest_header_view_msgtype_cell_data (GtkTreeViewColumn *column, GtkCellRenderer *renderer, @@ -142,11 +128,7 @@ _modest_header_view_header_cell_data (GtkTreeViewColumn *column, GtkCellRender gtk_tree_model_get (tree_model, iter, TNY_GTK_HEADER_LIST_MODEL_FLAGS_COLUMN, &flags, -1); - - g_object_set (G_OBJECT(renderer), - "weight", (flags & TNY_HEADER_FLAG_SEEN) ? 400: 800, - "strikethrough", (flags & TNY_HEADER_FLAG_DELETED) ? TRUE:FALSE, - NULL); + set_common_flags (renderer, flags); } @@ -157,7 +139,7 @@ _modest_header_view_date_cell_data (GtkTreeViewColumn *column, GtkCellRenderer { TnyHeaderFlags flags; guint date, date_col; - gchar *display_date; + gchar *display_date = NULL; gboolean received = GPOINTER_TO_INT(user_data); if (received) @@ -171,16 +153,12 @@ _modest_header_view_date_cell_data (GtkTreeViewColumn *column, GtkCellRenderer -1); display_date = modest_text_utils_get_display_date (date); - 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", display_date, - NULL); + g_object_set (G_OBJECT(renderer), "text", display_date, NULL); + + set_common_flags (renderer, flags); g_free (display_date); } - void _modest_header_view_sender_receiver_cell_data (GtkTreeViewColumn *column, GtkCellRenderer *renderer, GtkTreeModel *tree_model, GtkTreeIter *iter, gboolean is_sender) @@ -202,13 +180,9 @@ _modest_header_view_sender_receiver_cell_data (GtkTreeViewColumn *column, GtkC g_object_set (G_OBJECT(renderer), "text", modest_text_utils_get_display_address (address), - "weight", - (flags & TNY_HEADER_FLAG_SEEN) ? 400 : 800, - "style", - (flags & TNY_HEADER_FLAG_DELETED)?PANGO_STYLE_ITALIC:PANGO_STYLE_NORMAL, NULL); - - g_free (address); + g_free (address); + set_common_flags (renderer, flags); } /* * this for both incoming and outgoing mail, depending on the the user_data @@ -219,11 +193,22 @@ void _modest_header_view_compact_header_cell_data (GtkTreeViewColumn *column, GtkCellRenderer *renderer, GtkTreeModel *tree_model, GtkTreeIter *iter, gpointer user_data) { - GObject *rendobj; TnyHeaderFlags flags; - gchar *address, *subject, *header, *display_date; + gchar *address, *subject, *header; time_t date; gboolean is_incoming; + GtkCellRenderer *recipient_cell, *date_cell, *subject_cell, + *attach_cell, *priority_cell, + *recipient_box, *subject_box; + gchar *display_date = NULL, *tmp_date = NULL; + + recipient_box = GTK_CELL_RENDERER (g_object_get_data (G_OBJECT (renderer), "recpt-box-renderer")); + subject_box = GTK_CELL_RENDERER (g_object_get_data (G_OBJECT (renderer), "subject-box-renderer")); + priority_cell = GTK_CELL_RENDERER (g_object_get_data (G_OBJECT (subject_box), "priority-renderer")); + subject_cell = GTK_CELL_RENDERER (g_object_get_data (G_OBJECT (subject_box), "subject-renderer")); + attach_cell = GTK_CELL_RENDERER (g_object_get_data (G_OBJECT (recipient_box), "attach-renderer")); + recipient_cell = GTK_CELL_RENDERER (g_object_get_data (G_OBJECT (recipient_box), "recipient-renderer")); + date_cell = GTK_CELL_RENDERER (g_object_get_data (G_OBJECT (recipient_box), "date-renderer")); is_incoming = GPOINTER_TO_INT(user_data); /* GPOINTER_TO_BOOLEAN is not available * in older versions of glib...*/ @@ -242,22 +227,48 @@ _modest_header_view_compact_header_cell_data (GtkTreeViewColumn *column, GtkCe TNY_GTK_HEADER_LIST_MODEL_SUBJECT_COLUMN, &subject, TNY_GTK_HEADER_LIST_MODEL_DATE_SENT_TIME_T_COLUMN, &date, -1); - - rendobj = G_OBJECT(renderer); - display_date = modest_text_utils_get_display_date (date); - header = g_strdup_printf ("%s %s\n%s", - modest_text_utils_get_display_address (address), - display_date, subject); - g_free (address); + + /* flags */ + if (flags & TNY_HEADER_FLAG_ATTACHMENTS) + g_object_set (G_OBJECT (attach_cell), "pixbuf", + get_pixbuf_for_flag (TNY_HEADER_FLAG_ATTACHMENTS), + NULL); + else + g_object_set (G_OBJECT (attach_cell), "pixbuf", + NULL, NULL); + if (flags & TNY_HEADER_FLAG_PRIORITY) + g_object_set (G_OBJECT (priority_cell), "pixbuf", + get_pixbuf_for_flag (flags & TNY_HEADER_FLAG_PRIORITY), + NULL); + else + g_object_set (G_OBJECT (priority_cell), "pixbuf", + NULL, NULL); + header = g_markup_printf_escaped ("%s", (subject && strlen (subject)) ? subject : _("mail_va_no_subject")); g_free (subject); + g_object_set (G_OBJECT (subject_cell), "markup", header, NULL); + set_common_flags (subject_cell, flags); + + header = g_markup_printf_escaped ("%s", modest_text_utils_get_display_address (address)); + g_free (address); + g_object_set (G_OBJECT (recipient_cell), "markup", header, NULL); + + g_object_set (G_OBJECT (recipient_cell), "markup", header, NULL); + set_common_flags (recipient_cell, flags); + + /* in some rare cases, mail might have no Date: field. it case, + * don't show the date, instead of bogus 1/1/1970 + */ + if (date) + tmp_date = modest_text_utils_get_display_date (date); + else + tmp_date = g_strdup (""); + + display_date = g_strdup_printf ("%s", tmp_date); + g_object_set (G_OBJECT (date_cell), "markup", display_date, NULL); + g_free (tmp_date); g_free (display_date); + set_common_flags (date_cell, flags); - g_object_set (G_OBJECT(renderer), - "text", header, - "weight", (flags & TNY_HEADER_FLAG_SEEN) ? 400: 800, - "style", (flags & TNY_HEADER_FLAG_DELETED) ? - PANGO_STYLE_ITALIC : PANGO_STYLE_NORMAL, - NULL); g_free (header); } @@ -278,12 +289,31 @@ _modest_header_view_size_cell_data (GtkTreeViewColumn *column, GtkCellRenderer 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); + g_object_set (G_OBJECT(renderer), "text", size_str, NULL); + set_common_flags (renderer, flags); + g_free (size_str); } + +void +_modest_header_view_status_cell_data (GtkTreeViewColumn *column, GtkCellRenderer *renderer, + GtkTreeModel *tree_model, GtkTreeIter *iter, + gpointer user_data) +{ + TnyHeaderFlags flags; + //guint status; + gchar *status_str; + + gtk_tree_model_get (tree_model, iter, + TNY_GTK_HEADER_LIST_MODEL_FLAGS_COLUMN, &flags, + // TNY_GTK_HEADER_LIST_MODEL_MESSAGE_SIZE_COLUMN, &status, + -1); + + status_str = g_strdup(_("mcen_li_outbox_waiting")); + + g_object_set (G_OBJECT(renderer), "text", status_str, NULL); + set_common_flags (renderer, flags); + + g_free (status_str); + } +