Changed g_log levels in all app. Idea is reducing the number of debug
[modest] / src / maemo / modest-msg-view-window.c
index 4f47097..907159b 100644 (file)
@@ -237,6 +237,7 @@ struct _ModestMsgViewWindowPrivate {
        guint progress_bar_timeout;
 
        gchar *msg_uid;
+       TnyMimePart *other_body;
        
        GSList *sighandlers;
 };
@@ -478,6 +479,7 @@ modest_msg_view_window_init (ModestMsgViewWindow *obj)
        priv->purge_timeout = 0;
        priv->remove_attachment_banner = NULL;
        priv->msg_uid = NULL;
+       priv->other_body = NULL;
        
        priv->sighandlers = NULL;
        
@@ -705,6 +707,11 @@ modest_msg_view_window_finalize (GObject *obj)
           call this function before */
        modest_msg_view_window_disconnect_signals (MODEST_WINDOW (obj));
 
+       if (priv->other_body != NULL) {
+               g_object_unref (priv->other_body);
+               priv->other_body = NULL;
+       }
+
        if (priv->header_model != NULL) {
                g_object_unref (priv->header_model);
                priv->header_model = NULL;
@@ -934,6 +941,7 @@ modest_msg_view_window_construct (ModestMsgViewWindow *self,
 ModestWindow *
 modest_msg_view_window_new_with_header_model (TnyMsg *msg, 
                                              const gchar *modest_account_name,
+                                             const gchar *mailbox, /*ignored */
                                              const gchar *msg_uid,
                                              GtkTreeModel *model, 
                                              GtkTreeRowReference *row_reference)
@@ -1032,6 +1040,7 @@ modest_msg_view_window_new_with_header_model (TnyMsg *msg,
 ModestWindow *
 modest_msg_view_window_new_for_search_result (TnyMsg *msg, 
                                              const gchar *modest_account_name,
+                                             const gchar *mailbox, /*ignored*/
                                              const gchar *msg_uid)
 {
        ModestMsgViewWindow *window = NULL;
@@ -1063,10 +1072,23 @@ modest_msg_view_window_new_for_search_result (TnyMsg *msg,
        return MODEST_WINDOW(window);
 }
 
+gboolean
+modest_msg_view_window_is_other_body (ModestMsgViewWindow *self)
+{
+       ModestMsgViewWindowPrivate *priv = NULL;
+
+       g_return_val_if_fail (MODEST_IS_MSG_VIEW_WINDOW (self), FALSE);
+       priv = MODEST_MSG_VIEW_WINDOW_GET_PRIVATE (self);
+
+       return (priv->other_body != NULL);
+}
+
 ModestWindow *
-modest_msg_view_window_new_for_attachment (TnyMsg *msg, 
-                           const gchar *modest_account_name,
-                           const gchar *msg_uid)
+modest_msg_view_window_new_with_other_body (TnyMsg *msg, 
+                                           TnyMimePart *other_body,
+                                           const gchar *modest_account_name,
+                                           const gchar *mailbox, /* ignored */
+                                           const gchar *msg_uid)
 {
        GObject *obj = NULL;
        ModestMsgViewWindowPrivate *priv;       
@@ -1079,7 +1101,12 @@ modest_msg_view_window_new_for_attachment (TnyMsg *msg,
        modest_msg_view_window_construct (MODEST_MSG_VIEW_WINDOW (obj), 
                modest_account_name, msg_uid);
 
-       tny_msg_view_set_msg (TNY_MSG_VIEW (priv->msg_view), msg);
+       if (other_body) {
+               priv->other_body = g_object_ref (other_body);
+               modest_msg_view_set_msg_with_other_body (MODEST_MSG_VIEW (priv->msg_view), msg, other_body);
+       } else {
+               tny_msg_view_set_msg (TNY_MSG_VIEW (priv->msg_view), msg);
+       }
        update_window_title (MODEST_MSG_VIEW_WINDOW (obj));
 
        gtk_widget_show_all (GTK_WIDGET (obj));
@@ -1092,6 +1119,16 @@ modest_msg_view_window_new_for_attachment (TnyMsg *msg,
        return MODEST_WINDOW(obj);
 }
 
+ModestWindow *
+modest_msg_view_window_new_for_attachment (TnyMsg *msg, 
+                                          const gchar *modest_account_name,
+                                          const gchar *mailbox, /* ignored */
+                                          const gchar *msg_uid)
+{
+       return modest_msg_view_window_new_with_other_body (msg, NULL, modest_account_name, mailbox, msg_uid);
+
+}
+
 static void
 modest_msg_view_window_on_row_changed (GtkTreeModel *header_model,
                                       GtkTreePath *arg1,
@@ -1468,7 +1505,7 @@ modest_msg_view_window_find_toolbar_search (GtkWidget *widget,
 
        if ((current_search == NULL) || (strcmp (current_search, "") == 0)) {
                g_free (current_search);
-               hildon_banner_show_information (NULL, NULL, dgettext("hildon-common-strings", "ecdg_ib_find_rep_enter_text"));
+               hildon_banner_show_information (NULL, NULL, _CS("ecdg_ib_find_rep_enter_text"));
                return;
        }
 
@@ -1479,7 +1516,7 @@ modest_msg_view_window_find_toolbar_search (GtkWidget *widget,
                result = modest_isearch_view_search (MODEST_ISEARCH_VIEW (priv->msg_view),
                                                     priv->last_search);
                if (!result) {
-                       hildon_banner_show_information (NULL, NULL, dgettext("hildon-libs", "ckct_ib_find_no_matches"));
+                       hildon_banner_show_information (NULL, NULL, _HL("ckct_ib_find_no_matches"));
                        g_free (priv->last_search);
                        priv->last_search = NULL;
                } else {
@@ -1488,7 +1525,7 @@ modest_msg_view_window_find_toolbar_search (GtkWidget *widget,
                }
        } else {
                if (!modest_isearch_view_search_next (MODEST_ISEARCH_VIEW (priv->msg_view))) {
-                       hildon_banner_show_information (NULL, NULL, dgettext("hildon-libs", "ckct_ib_find_search_complete"));
+                       hildon_banner_show_information (NULL, NULL, _HL("ckct_ib_find_search_complete"));
                        g_free (priv->last_search);
                        priv->last_search = NULL;
                } else {
@@ -1547,7 +1584,7 @@ modest_msg_view_window_zoom_plus (ModestWindow *window)
        group = gtk_radio_action_get_group (zoom_radio_action);
 
        if (gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (group->data))) {
-               hildon_banner_show_information (NULL, NULL, dgettext("hildon-common-strings", "ckct_ib_max_zoom_level_reached"));
+               hildon_banner_show_information (NULL, NULL, _CS("ckct_ib_max_zoom_level_reached"));
                return FALSE;
        }
 
@@ -1579,7 +1616,8 @@ modest_msg_view_window_zoom_minus (ModestWindow *window)
                                gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (node->next->data), TRUE);
                                return TRUE;
                        } else {
-                         hildon_banner_show_information (NULL, NULL, dgettext("hildon-common-strings", "ckct_ib_min_zoom_level_reached"));
+                         hildon_banner_show_information (NULL, NULL, 
+                                                         _CS("ckct_ib_min_zoom_level_reached"));
                                return FALSE;
                        }
                        break;
@@ -2579,7 +2617,8 @@ modest_msg_view_window_view_attachment (ModestMsgViewWindow *window,
                        mime_part = (TnyMimePart *) tny_iterator_get_current (iter);
                        g_object_unref (iter);
                }
-               g_object_unref (selected_attachments);
+               if (selected_attachments)
+                 g_object_unref (selected_attachments);
 
                if (error)
                        return;
@@ -2595,7 +2634,7 @@ modest_msg_view_window_view_attachment (ModestMsgViewWindow *window,
        /* we also check for mime_part == priv->msg, as this means it's a direct attachment
         * shown as attachment, so it should behave as a file */
        window_msg = TNY_MIME_PART (tny_msg_view_get_msg (TNY_MSG_VIEW (priv->msg_view)));
-       if (!modest_tny_mime_part_is_msg (mime_part)||
+       if ((!modest_tny_mime_part_is_msg (mime_part) && tny_mime_part_get_filename (mime_part)) ||
            mime_part == window_msg) {
                gchar *filepath = NULL;
                const gchar *att_filename = tny_mime_part_get_filename (mime_part);
@@ -2632,6 +2671,42 @@ modest_msg_view_window_view_attachment (ModestMsgViewWindow *window,
                        g_free (filepath);
                if (show_error_banner)
                        modest_platform_information_banner (NULL, NULL, _("mail_ib_file_operation_failed"));
+       } else if (!modest_tny_mime_part_is_msg (mime_part)) {
+               ModestWindowMgr *mgr;
+               ModestWindow *msg_win = NULL;
+               TnyMsg *current_msg;
+               gboolean found;
+               TnyHeader *header;
+
+               current_msg = modest_msg_view_window_get_message (MODEST_MSG_VIEW_WINDOW (window));
+               mgr = modest_runtime_get_window_mgr ();
+               header = tny_msg_get_header (TNY_MSG (current_msg));
+               found = modest_window_mgr_find_registered_message_uid (mgr,
+                                                                      attachment_uid,
+                                                                      &msg_win);
+               
+               if (found) {
+                       g_debug ("window for this body is already being created");
+               } else {
+
+                       /* it's not found, so create a new window for it */
+                       modest_window_mgr_register_header (mgr, header, attachment_uid); /* register the uid before building the window */
+                       gchar *account = g_strdup (modest_window_get_active_account (MODEST_WINDOW (window)));
+                       const gchar *mailbox = modest_window_get_active_mailbox (MODEST_WINDOW (window));
+                       if (!account)
+                               account = modest_account_mgr_get_default_account (modest_runtime_get_account_mgr ());
+                       
+                       msg_win = modest_msg_view_window_new_with_other_body (TNY_MSG (current_msg), TNY_MIME_PART (mime_part),
+                                                                             account, mailbox, attachment_uid);
+                       
+                       modest_window_set_zoom (MODEST_WINDOW (msg_win),
+                                               modest_window_get_zoom (MODEST_WINDOW (window)));
+                       if (modest_window_mgr_register_window (mgr, msg_win, MODEST_WINDOW (window)))
+                               gtk_widget_show_all (GTK_WIDGET (msg_win));
+                       else
+                               gtk_widget_destroy (GTK_WIDGET (msg_win));
+               }
+               g_object_unref (current_msg);           
        } else {
                /* message attachment */
                TnyHeader *header = NULL;
@@ -2649,14 +2724,15 @@ modest_msg_view_window_view_attachment (ModestMsgViewWindow *window,
                        else 
                                /* if it's found, but there is no msg_win, it's probably in the process of being created;
                                 * thus, we don't do anything */
-                               g_warning ("window for is already being created");
+                               g_debug ("window for is already being created");
                } else { 
                        /* it's not found, so create a new window for it */
                        modest_window_mgr_register_header (mgr, header, attachment_uid); /* register the uid before building the window */
                        gchar *account = g_strdup (modest_window_get_active_account (MODEST_WINDOW (window)));
                        if (!account)
                                account = modest_account_mgr_get_default_account (modest_runtime_get_account_mgr ());
-                       msg_win = modest_msg_view_window_new_for_attachment (TNY_MSG (mime_part), account, attachment_uid);
+                       msg_win = modest_msg_view_window_new_for_attachment (TNY_MSG (mime_part), account, 
+                                                                            NULL, attachment_uid);
                        modest_window_set_zoom (MODEST_WINDOW (msg_win), 
                                                modest_window_get_zoom (MODEST_WINDOW (window)));
                        modest_window_mgr_register_window (mgr, msg_win, MODEST_WINDOW (window));
@@ -2718,10 +2794,11 @@ idle_save_mime_part_show_result (SaveMimePartInfo *info)
                if (info->result == GNOME_VFS_OK) {
                        hildon_banner_show_information (NULL, NULL, _CS("sfil_ib_saved"));
                } else if (info->result == GNOME_VFS_ERROR_NO_SPACE) {
-                       hildon_banner_show_information (NULL, NULL, dgettext("ke-recv", 
-                                                                            "cerm_device_memory_full"));
+                       hildon_banner_show_information (NULL, NULL, 
+                                                       _KR("cerm_device_memory_full"));
                } else {
-                       hildon_banner_show_information (NULL, NULL, _("mail_ib_file_operation_failed"));
+                       hildon_banner_show_information (NULL, NULL, 
+                                                       _("mail_ib_file_operation_failed"));
                }
                gdk_threads_leave (); /* CHECKED */
        }
@@ -2812,7 +2889,7 @@ save_attachments_response (GtkDialog *dialog,
 
        if (!modest_utils_folder_writable (chooser_uri)) {
                hildon_banner_show_information 
-                       (NULL, NULL, dgettext("hildon-fm", "sfil_ib_readonly_location"));
+                       (NULL, NULL, _FM("sfil_ib_readonly_location"));
        } else {
                TnyIterator *iter;
 
@@ -2824,7 +2901,7 @@ save_attachments_response (GtkDialog *dialog,
                            !tny_mime_part_is_purged (mime_part) &&
                            (tny_mime_part_get_filename (mime_part) != NULL)) {
                                SaveMimePartPair *pair;
-                                       
+
                                pair = g_slice_new0 (SaveMimePartPair);
 
                                if (tny_list_get_length (mime_parts) > 1) {
@@ -3072,7 +3149,15 @@ update_window_title (ModestMsgViewWindow *window)
        
        msg = tny_msg_view_get_msg (TNY_MSG_VIEW (priv->msg_view));
 
-       if (msg != NULL) {
+       if (priv->other_body) {
+               gchar *description;
+
+               description = modest_tny_mime_part_get_header_value (priv->other_body, "Content-Description");
+               if (description) {
+                       g_strstrip (description);
+                       subject = description;
+               }
+       } else if (msg != NULL) {
                header = tny_msg_get_header (msg);
                subject = tny_header_dup_subject (header);
                g_object_unref (header);
@@ -3137,9 +3222,9 @@ on_fetch_image_idle_refresh_view (gpointer userdata)
 {
 
        FetchImageData *fidata = (FetchImageData *) userdata;
-       g_message ("REFRESH VIEW");
+       g_debug ("REFRESH VIEW");
        if (GTK_WIDGET_DRAWABLE (fidata->msg_view)) {
-               g_message ("QUEUING DRAW");
+               g_debug ("QUEUING DRAW");
                gtk_widget_queue_draw (fidata->msg_view);
        }
        g_object_unref (fidata->msg_view);
@@ -3208,3 +3293,48 @@ on_fetch_image (ModestMsgView *msgview,
 
        return TRUE;;
 }
+
+void
+modest_msg_view_window_add_to_contacts (ModestMsgViewWindow *self)
+{
+       modest_ui_actions_on_add_to_contacts (NULL, MODEST_WINDOW (self));
+}
+
+
+void
+modest_msg_view_window_fetch_images (ModestMsgViewWindow *self)
+{
+       ModestMsgViewWindowPrivate *priv;
+       priv = MODEST_MSG_VIEW_WINDOW_GET_PRIVATE (self);
+
+       modest_msg_view_request_fetch_images (MODEST_MSG_VIEW (priv->msg_view));
+}
+
+gboolean 
+modest_msg_view_window_has_blocked_external_images (ModestMsgViewWindow *self)
+{
+       ModestMsgViewWindowPrivate *priv;
+       priv = MODEST_MSG_VIEW_WINDOW_GET_PRIVATE (self);
+
+       g_return_val_if_fail (MODEST_IS_MSG_VIEW_WINDOW (self), FALSE);
+
+       return modest_msg_view_has_blocked_external_images (MODEST_MSG_VIEW (priv->msg_view));
+}
+
+void 
+modest_msg_view_window_reload (ModestMsgViewWindow *self)
+{
+       ModestMsgViewWindowPrivate *priv;
+       TnyHeader *header;
+
+       g_return_if_fail (MODEST_IS_MSG_VIEW_WINDOW (self));
+
+       priv = MODEST_MSG_VIEW_WINDOW_GET_PRIVATE (self);
+       header = modest_msg_view_window_get_header (MODEST_MSG_VIEW_WINDOW (self));     
+
+       if (!message_reader (self, priv, header, priv->row_reference)) {
+               g_warning ("Shouldn't happen, trying to reload a message failed");
+       }
+
+       g_object_unref (header);
+}