Set proper "other body" title in msg view window.
authorJose Dapena Paz <jdapena@igalia.com>
Fri, 22 May 2009 09:04:44 +0000 (11:04 +0200)
committerJose Dapena Paz <jdapena@igalia.com>
Fri, 22 May 2009 10:48:44 +0000 (12:48 +0200)
src/gnome/modest-msg-view-window.c
src/hildon2/modest-hildon2-window-mgr.c
src/hildon2/modest-msg-view-window.c
src/maemo/modest-msg-view-window.c
src/widgets/modest-msg-view-window.h
src/widgets/modest-window-mgr.c

index cd2ff16..3f4cfec 100644 (file)
@@ -65,6 +65,7 @@ struct _ModestMsgViewWindowPrivate {
        GtkWidget   *msg_view;
 
        gchar *msg_uid;
+       TnyMimePart *other_body;
 };
 
 #define MODEST_MSG_VIEW_WINDOW_GET_PRIVATE(o)      (G_TYPE_INSTANCE_GET_PRIVATE((o), \
@@ -153,6 +154,7 @@ modest_msg_view_window_init (ModestMsgViewWindow *obj)
        priv->menubar  = NULL;
        priv->msg_view = NULL;
        priv->msg_uid  = NULL;
+       priv->other_body = NULL;
 }
 
 
@@ -168,6 +170,7 @@ init_window (ModestMsgViewWindow *obj, TnyMsg *msg, TnyMimePart *other_body)
 
        priv->msg_view = GTK_WIDGET (tny_platform_factory_new_msg_view (modest_tny_platform_factory_get_instance ()));
        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);
@@ -195,6 +198,11 @@ modest_msg_view_window_finalize (GObject *obj)
 
        priv = MODEST_MSG_VIEW_WINDOW_GET_PRIVATE(obj);
 
+       if (priv->other_body != NULL) {
+               g_object_unref (priv->other_body);
+               priv->other_body = NULL;
+       }
+
        G_OBJECT_CLASS(parent_class)->finalize (obj);
 }
 
@@ -208,6 +216,17 @@ on_delete_event (GtkWidget *widget, GdkEvent *event, ModestMsgViewWindow *self)
 }
 
 
+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_with_other_body (TnyMsg *msg, 
                                            TnyMimePart *other_body,
@@ -289,8 +308,19 @@ modest_msg_view_window_new_with_other_body (TnyMsg *msg,
        restore_settings (MODEST_WINDOW(obj));
 
        header = tny_msg_get_header (msg);
-       if (header)
-               subject = tny_header_dup_subject (header);
+       if (other_body) {
+               gchar *description;
+
+               description = modest_tny_mime_part_get_header_value (other_body, "Content-Description");
+               if (description) {
+                       g_strstrip (description);
+                       subject = description;
+               }
+       } else {
+               if (header)
+                       subject = tny_header_dup_subject (header);
+       }
+
        
        if (subject != NULL)
                gtk_window_set_title (GTK_WINDOW (obj), subject);
index 3cfc695..052d071 100644 (file)
@@ -481,29 +481,30 @@ modest_hildon2_window_mgr_register_window (ModestWindowMgr *self,
        if (MODEST_IS_MSG_VIEW_WINDOW (window)) {
                gchar *uid;
                TnyHeader *header;
+
+               uid = g_strdup (modest_msg_view_window_get_message_uid (MODEST_MSG_VIEW_WINDOW (window)));
+               
                header = modest_msg_view_window_get_header (MODEST_MSG_VIEW_WINDOW (window));
 
-               if (header) {
+               if (uid == NULL)
                        uid = modest_tny_folder_get_header_unique_id (header);
-
-                       /* Embedded messages do not have uid */
-                       if (uid) {
-                               if (g_list_find_custom (priv->window_list, uid, (GCompareFunc) compare_msguids)) {
-                                       g_debug ("%s found another view window showing the same header", __FUNCTION__);
-                                       g_free (uid);
-                                       g_object_unref (header);
-                                       return FALSE;
-                               }
+               /* Embedded messages do not have uid */
+               if (uid) {
+                       if (g_list_find_custom (priv->window_list, uid, (GCompareFunc) compare_msguids)) {
+                               g_debug ("%s found another view window showing the same header", __FUNCTION__);
                                g_free (uid);
-                       } else {
-                               if (g_list_find_custom (priv->window_list, header, (GCompareFunc) compare_headers)) {
-                                       g_debug ("%s found another view window showing the same header", __FUNCTION__);
-                                       g_object_unref (header);
-                                       return FALSE;
-                               }
+                               g_object_unref (header);
+                               return FALSE;
+                       }
+                       g_free (uid);
+               } else {
+                       if (g_list_find_custom (priv->window_list, header, (GCompareFunc) compare_headers)) {
+                               g_debug ("%s found another view window showing the same header", __FUNCTION__);
+                               g_object_unref (header);
+                               return FALSE;
                        }
-                       g_object_unref (header);
                }
+               g_object_unref (header);
        }
 
        /* Do not go backwards */
index 110f09e..01d7157 100644 (file)
@@ -117,7 +117,7 @@ struct _ModestMsgViewWindowPrivate {
        GtkWidget *remove_attachment_banner;
 
        gchar *msg_uid;
-       gboolean is_other_body;
+       TnyMimePart *other_body;
 
        GSList *sighandlers;
 };
@@ -449,7 +449,7 @@ modest_msg_view_window_init (ModestMsgViewWindow *obj)
        priv->purge_timeout = 0;
        priv->remove_attachment_banner = NULL;
        priv->msg_uid = NULL;
-       priv->is_other_body = FALSE;
+       priv->other_body = NULL;
        
        priv->sighandlers = NULL;
        
@@ -612,6 +612,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;
@@ -1042,6 +1047,17 @@ 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_with_other_body (TnyMsg *msg, 
                                            TnyMimePart *other_body,
@@ -1061,7 +1077,7 @@ modest_msg_view_window_new_with_other_body (TnyMsg *msg,
                                          modest_account_name, mailbox, msg_uid);
 
        if (other_body) {
-               priv->is_other_body = TRUE;
+               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);
@@ -1349,9 +1365,6 @@ modest_msg_view_window_get_header (ModestMsgViewWindow *self)
        g_return_val_if_fail (MODEST_IS_MSG_VIEW_WINDOW (self), NULL);
        priv = MODEST_MSG_VIEW_WINDOW_GET_PRIVATE (self);
 
-       if (priv->is_other_body)
-               return NULL;
-
        /* If the message was not obtained from a treemodel,
         * for instance if it was opened directly by the search UI:
         */
@@ -2559,27 +2572,40 @@ modest_msg_view_window_view_attachment (ModestMsgViewWindow *window,
                        modest_platform_information_banner (NULL, NULL, _("mail_ib_file_operation_failed"));
        } else if (!modest_tny_mime_part_is_msg (mime_part)) {
                ModestWindowMgr *mgr;
-               mgr = modest_runtime_get_window_mgr ();
                ModestWindow *msg_win = NULL;
                TnyMsg *current_msg;
-
-               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 ());
+               gboolean found;
+               TnyHeader *header;
 
                current_msg = modest_msg_view_window_get_message (MODEST_MSG_VIEW_WINDOW (window));
-               msg_win = modest_msg_view_window_new_with_other_body (TNY_MSG (current_msg), TNY_MIME_PART (mime_part),
-                                                                     account, mailbox, attachment_uid);
-               g_object_unref (current_msg);
-
-               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));
+               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_warning ("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;
@@ -3076,7 +3102,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);
index 6681d22..ebaad0c 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;
@@ -1065,6 +1072,17 @@ 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_with_other_body (TnyMsg *msg, 
                                            TnyMimePart *part,
@@ -1084,6 +1102,7 @@ modest_msg_view_window_new_with_other_body (TnyMsg *msg,
                modest_account_name, msg_uid);
 
        if (other_body) {
+               priv->other_body = g_object_ref (other_body);
                modest_msg_view_set_msg_with_other_body (TNY_MSG_VIEW (priv->msg_view), msg, other_body);
        } else {
                tny_msg_view_set_msg (TNY_MSG_VIEW (priv->msg_view), msg);
@@ -3093,7 +3112,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);
index a3d9cdd..5d6e6e2 100644 (file)
@@ -125,6 +125,16 @@ ModestWindow*   modest_msg_view_window_new_with_other_body         (TnyMsg *msg,
                                                                   const gchar *msg_uid);
 
 /**
+ * modest_msg_view_window_is_other_body:
+ * @self: a #ModestMsgViewWindow
+ *
+ * tells if the view window is showing other body
+ *
+ * Returns: %TRUE if showing "not first body"
+ */
+gboolean modest_msg_view_window_is_other_body (ModestMsgViewWindow *self);
+
+/**
  * modest_msg_view_window_new_with_header_model:
  * @msg: an #TnyMsg instance
  * @modest_account_name: the account name 
index f4ab915..a410589 100644 (file)
@@ -379,11 +379,12 @@ modest_window_mgr_register_header (ModestWindowMgr *self,  TnyHeader *header, co
        g_return_if_fail (TNY_IS_HEADER(header));
                
        priv = MODEST_WINDOW_MGR_GET_PRIVATE (self);
-       uid = modest_tny_folder_get_header_unique_id (header);
-
-       if (uid == NULL)
+       if (alt_uid != NULL) {
                uid = g_strdup (alt_uid);
-       
+       } else {
+               uid = modest_tny_folder_get_header_unique_id (header);
+       }
+
        if (!has_uid (priv->preregistered_uids, uid)) {
                MODEST_DEBUG_BLOCK(g_debug ("registering new uid %s", uid););
                priv->preregistered_uids = append_uid (priv->preregistered_uids, uid);