#include <modest-attachment-view.h>
#include <modest-platform.h>
#include <modest-text-utils.h>
+#include <modest-tny-mime-part.h>
#include <tny-msg.h>
-#include <tny-camel-mem-stream.h>
#include <modest-mail-operation.h>
#include <modest-mail-operation-queue.h>
#include <modest-runtime.h>
GtkWidget *filename_view;
GtkWidget *size_view;
- guint get_size_idle_id;
+ gboolean detect_size;
TnyStream *get_size_stream;
guint64 size;
};
+#ifdef MODEST_TOOLKIT_HILDON2
+#define UNKNOWN_FILE_ICON "filemanager_unknown_file"
+#else
#define UNKNOWN_FILE_ICON "qgn_list_gene_unknown_file"
+#endif
#define MODEST_ATTACHMENT_VIEW_GET_PRIVATE(o) \
(G_TYPE_INSTANCE_GET_PRIVATE ((o), MODEST_TYPE_ATTACHMENT_VIEW, ModestAttachmentViewPrivate))
static void update_filename_request (ModestAttachmentView *self);
+static void update_size_label (ModestAttachmentView *self)
+{
+ ModestAttachmentViewPrivate *priv = MODEST_ATTACHMENT_VIEW_GET_PRIVATE (self);
+ gchar *size_str;
+ gchar *label_text;
+
+ size_str = modest_text_utils_get_display_size (priv->size);
+ label_text = g_strdup_printf (" (%s)", size_str);
+ g_free (size_str);
+ gtk_label_set_text (GTK_LABEL (priv->size_view), label_text);
+ g_free (label_text);
+}
static gboolean
idle_get_mime_part_size_cb (gpointer userdata)
{
ModestAttachmentView *view = (ModestAttachmentView *) userdata;
- ModestAttachmentViewPrivate *priv = MODEST_ATTACHMENT_VIEW_GET_PRIVATE (view);
- gchar *size_str;
- gchar *label_text;
gdk_threads_enter ();
if (GTK_WIDGET_VISIBLE (view)) {
- size_str = modest_text_utils_get_display_size (priv->size);
- label_text = g_strdup_printf (" (%s)", size_str);
- g_free (size_str);
- gtk_label_set_text (GTK_LABEL (priv->size_view), label_text);
- g_free (label_text);
+ update_size_label (view);
}
gdk_threads_leave ();
{
ModestAttachmentView *view = (ModestAttachmentView *) thr_user_data;
ModestAttachmentViewPrivate *priv = MODEST_ATTACHMENT_VIEW_GET_PRIVATE (view);
- TnyStream *stream;
gsize total = 0;
gssize result = 0;
- stream = modest_count_stream_new();
- result = tny_mime_part_decode_to_stream (priv->mime_part, stream, NULL);
- total = modest_count_stream_get_count(MODEST_COUNT_STREAM (stream));
+ result = tny_mime_part_decode_to_stream (priv->mime_part, priv->get_size_stream, NULL);
+ total = modest_count_stream_get_count(MODEST_COUNT_STREAM (priv->get_size_stream));
if (total == 0) {
- modest_count_stream_reset_count(MODEST_COUNT_STREAM (stream));
- result = tny_mime_part_write_to_stream (priv->mime_part, stream, NULL);
- total = modest_count_stream_get_count(MODEST_COUNT_STREAM (stream));
+ modest_count_stream_reset_count(MODEST_COUNT_STREAM (priv->get_size_stream));
+ result = tny_mime_part_write_to_stream (priv->mime_part, priv->get_size_stream, NULL);
+ total = modest_count_stream_get_count(MODEST_COUNT_STREAM (priv->get_size_stream));
}
/* if there was an error, don't set the size (this is pretty uncommon) */
priv->size = (guint64)total;
g_idle_add (idle_get_mime_part_size_cb, g_object_ref (view));
}
-
- g_object_unref (stream);
g_object_unref (view);
return NULL;
}
+void
+modest_attachment_view_set_detect_size (ModestAttachmentView *self, gboolean detect_size)
+{
+ ModestAttachmentViewPrivate *priv = MODEST_ATTACHMENT_VIEW_GET_PRIVATE (self);
+
+ priv->detect_size = detect_size;
+
+}
+
+void
+modest_attachment_view_set_size (ModestAttachmentView *self, guint64 size)
+{
+ ModestAttachmentViewPrivate *priv;
+
+ g_return_if_fail (MODEST_IS_ATTACHMENT_VIEW (self));
+ priv = MODEST_ATTACHMENT_VIEW_GET_PRIVATE (self);
+
+ if (!priv->detect_size) {
+ priv->size = size;
+ update_size_label (self);
+ } else {
+ g_assert ("Shouldn't set the size of the attachment view if detect size is enabled");
+ }
+}
+
+guint64
+modest_attachment_view_get_size (ModestAttachmentView *self)
+{
+ ModestAttachmentViewPrivate *priv;
+
+ g_return_val_if_fail (MODEST_IS_ATTACHMENT_VIEW (self), 0);
+ priv = MODEST_ATTACHMENT_VIEW_GET_PRIVATE (self);
+
+ return priv->size;
+}
+
static TnyMimePart *
modest_attachment_view_get_part (TnyMimePartView *self)
{
g_object_unref (priv->mime_part);
}
- priv->mime_part = mime_part;
+ priv->mime_part = g_object_ref (mime_part);
priv->size = 0;
priv->is_purged = tny_mime_part_is_purged (mime_part);
if (TNY_IS_MSG (mime_part)) {
TnyHeader *header = tny_msg_get_header (TNY_MSG (mime_part));
if (TNY_IS_HEADER (header)) {
- filename = g_strdup (tny_header_get_subject (header));
- if (filename == NULL || filename[0] == '\0')
+ filename = g_strdup (tny_mime_part_get_filename (mime_part));
+ if (!filename)
+ filename = tny_header_dup_subject (header);
+ if (filename == NULL || filename[0] == '\0') {
+ if (filename)
+ g_free (filename);
filename = g_strdup (_("mail_va_no_subject"));
- if (priv->is_purged)
+ }
+ if (priv->is_purged) {
file_icon_name = modest_platform_get_file_icon_name (NULL, NULL, NULL);
- else
- file_icon_name =
- modest_platform_get_file_icon_name (
- NULL, tny_mime_part_get_content_type (mime_part), NULL);
+ } else {
+ gchar *header_content_type;
+ header_content_type = modest_tny_mime_part_get_content_type (mime_part);
+ if ((g_str_has_prefix (header_content_type, "message/rfc822") ||
+ g_str_has_prefix (header_content_type, "multipart/") ||
+ g_str_has_prefix (header_content_type, "text/"))) {
+ file_icon_name =
+ modest_platform_get_file_icon_name (
+ NULL, tny_mime_part_get_content_type (mime_part), NULL);
+ } else {
+ file_icon_name =
+ modest_platform_get_file_icon_name (
+ NULL, header_content_type, NULL);
+ }
+ g_free (header_content_type);
+ }
g_object_unref (header);
}
} else {
file_icon_name = modest_platform_get_file_icon_name (NULL, NULL, NULL);
} else {
file_icon_name = modest_platform_get_file_icon_name (
- filename, tny_mime_part_get_content_type (mime_part), NULL);
+ filename, modest_tny_mime_part_get_content_type (mime_part), NULL);
show_size = TRUE;
}
}
gtk_label_set_text (GTK_LABEL (priv->size_view), "");
- if (show_size) {
- tny_camel_mem_stream_get_type ();
+ if (show_size && priv->detect_size) {
g_object_ref (self);
+ if (!priv->get_size_stream)
+ priv->get_size_stream = modest_count_stream_new ();
g_thread_create (get_mime_part_size_thread, self, FALSE, NULL);
}
priv->mime_part = NULL;
}
- if (priv->get_size_idle_id != 0) {
- g_source_remove (priv->get_size_idle_id);
- priv->get_size_idle_id = 0;
- }
-
- if (priv->get_size_stream != NULL) {
- g_object_unref (priv->get_size_stream);
- priv->get_size_stream = NULL;
- }
+ if (priv->get_size_stream)
+ modest_count_stream_reset_count(MODEST_COUNT_STREAM (priv->get_size_stream));
priv->size = 0;
* Return value: a new #ModestAttachmentView instance implemented for Gtk+
**/
GtkWidget*
-modest_attachment_view_new (TnyMimePart *mime_part)
+modest_attachment_view_new (TnyMimePart *mime_part, gboolean detect_size)
{
ModestAttachmentView *self = g_object_new (MODEST_TYPE_ATTACHMENT_VIEW,
NULL);
+ modest_attachment_view_set_detect_size (self, detect_size);
+
modest_attachment_view_set_part (TNY_MIME_PART_VIEW (self), mime_part);
return GTK_WIDGET (self);
PangoContext *context;
GtkWidget *box = NULL;
+#ifdef MODEST_TOOLKIT_HILDON2
+ PangoAttrList *attr_list;
+ attr_list = pango_attr_list_new ();
+ pango_attr_list_insert (attr_list, pango_attr_underline_new (PANGO_UNDERLINE_SINGLE));
+#endif
+
priv->mime_part = NULL;
priv->icon = gtk_image_new ();
priv->filename_view = gtk_label_new ("");
gtk_misc_set_alignment (GTK_MISC (priv->size_view), 0.0, 0.5);
gtk_misc_set_alignment (GTK_MISC (priv->filename_view), 0.0, 0.5);
- priv->get_size_idle_id = 0;
+#ifdef MODEST_TOOLKIT_HILDON2
+ gtk_label_set_attributes (GTK_LABEL (priv->filename_view), attr_list);
+ gtk_label_set_attributes (GTK_LABEL (priv->size_view), attr_list);
+#endif
+
priv->get_size_stream = NULL;
priv->size = 0;
+ priv->detect_size = TRUE;
box = gtk_hbox_new (FALSE, 0);
gtk_box_pack_start (GTK_BOX (box), priv->icon, FALSE, FALSE, 0);
gtk_event_box_set_visible_window (GTK_EVENT_BOX (instance), TRUE);
gtk_widget_set_events (GTK_WIDGET (instance), 0);
+#ifdef MODEST_TOOLKIT_HILDON2
+ pango_attr_list_unref (attr_list);
+#endif
+
GTK_WIDGET_UNSET_FLAGS (GTK_WIDGET (instance), GTK_CAN_FOCUS);
return;
{
ModestAttachmentViewPrivate *priv = MODEST_ATTACHMENT_VIEW_GET_PRIVATE (object);
- if (priv->get_size_idle_id) {
- g_source_remove (priv->get_size_idle_id);
- priv->get_size_idle_id = 0;
- }
-
if (priv->get_size_stream != NULL) {
g_object_unref (priv->get_size_stream);
priv->get_size_stream = NULL;
{
TnyMimePartViewIface *klass = (TnyMimePartViewIface *)g;
- klass->get_part_func = modest_attachment_view_get_part;
- klass->set_part_func = modest_attachment_view_set_part;
- klass->clear_func = modest_attachment_view_clear;
+ klass->get_part = modest_attachment_view_get_part;
+ klass->set_part = modest_attachment_view_set_part;
+ klass->clear = modest_attachment_view_clear;
return;
}