* src/widgets/modest-msg-edit-window.h,
authorJose Dapena Paz <jdapena@igalia.com>
Wed, 1 Aug 2007 07:26:51 +0000 (07:26 +0000)
committerJose Dapena Paz <jdapena@igalia.com>
Wed, 1 Aug 2007 07:26:51 +0000 (07:26 +0000)
  src/maemo/modest-msg-edit-window.c:
        * New method (modest_msg_edit_window_get_message_uid), that
          gets the message uid of the current draft or outbox message
          the mail was openend from.
* src/widgets/modest-window-mgr.c:
        * Modify all the message register methods, to add support for
          also registering edit windows (fixes NB#64714).

pmo-trunk-r2882

src/maemo/modest-msg-edit-window.c
src/widgets/modest-msg-edit-window.h
src/widgets/modest-window-mgr.c

index 28aaef3..4ca1f4d 100644 (file)
@@ -252,6 +252,8 @@ struct _ModestMsgEditWindowPrivate {
 
        TnyMsg      *draft_msg;
        TnyMsg      *outbox_msg;
 
        TnyMsg      *draft_msg;
        TnyMsg      *outbox_msg;
+       gchar       *msg_uid;
+
        gboolean    sent;
 };
 
        gboolean    sent;
 };
 
@@ -355,6 +357,7 @@ modest_msg_edit_window_init (ModestMsgEditWindow *obj)
 
        priv->draft_msg = NULL;
        priv->outbox_msg = NULL;
 
        priv->draft_msg = NULL;
        priv->outbox_msg = NULL;
+       priv->msg_uid = NULL;
        priv->clipboard_change_handler_id = 0;
        priv->sent = FALSE;
 
        priv->clipboard_change_handler_id = 0;
        priv->sent = FALSE;
 
@@ -632,6 +635,10 @@ modest_msg_edit_window_finalize (GObject *obj)
                g_object_unref (priv->outbox_msg);
                priv->outbox_msg = NULL;
        }
                g_object_unref (priv->outbox_msg);
                priv->outbox_msg = NULL;
        }
+       if (priv->msg_uid != NULL) {
+               g_free (priv->msg_uid);
+               priv->msg_uid = NULL;
+       }
 
        /* This had to stay alive for as long as the combobox that used it: */
        modest_pair_list_free (priv->from_field_protos);
 
        /* This had to stay alive for as long as the combobox that used it: */
        modest_pair_list_free (priv->from_field_protos);
@@ -852,6 +859,11 @@ set_msg (ModestMsgEditWindow *self, TnyMsg *msg, gboolean preserve_is_rich)
        text_buffer_can_undo (priv->text_buffer, FALSE, self);
        text_buffer_can_redo (priv->text_buffer, FALSE, self);
 
        text_buffer_can_undo (priv->text_buffer, FALSE, self);
        text_buffer_can_redo (priv->text_buffer, FALSE, self);
 
+       if (priv->msg_uid) {
+               g_free (priv->msg_uid);
+               priv->msg_uid = NULL;
+       }
+
        /* we should set a reference to the incoming message if it is a draft */
        msg_folder = tny_msg_get_folder (msg);
        if (msg_folder) {               
        /* we should set a reference to the incoming message if it is a draft */
        msg_folder = tny_msg_get_folder (msg);
        if (msg_folder) {               
@@ -861,6 +873,7 @@ set_msg (ModestMsgEditWindow *self, TnyMsg *msg, gboolean preserve_is_rich)
                                priv->draft_msg = g_object_ref(msg);
                        if (type == TNY_FOLDER_TYPE_OUTBOX)
                                priv->outbox_msg = g_object_ref(msg);
                                priv->draft_msg = g_object_ref(msg);
                        if (type == TNY_FOLDER_TYPE_OUTBOX)
                                priv->outbox_msg = g_object_ref(msg);
+                       priv->msg_uid = modest_tny_folder_get_header_unique_id (header);
                }
                g_object_unref (msg_folder);
        }
                }
                g_object_unref (msg_folder);
        }
@@ -3100,6 +3113,11 @@ modest_msg_edit_window_set_draft (ModestMsgEditWindow *window,
                header = tny_msg_get_header (draft);
                if (TNY_IS_HEADER (header))
                        modest_window_mgr_register_header (mgr, header);
                header = tny_msg_get_header (draft);
                if (TNY_IS_HEADER (header))
                        modest_window_mgr_register_header (mgr, header);
+               if (priv->msg_uid) {
+                       g_free (priv->msg_uid);
+                       priv->msg_uid = NULL;
+               }
+               priv->msg_uid = modest_tny_folder_get_header_unique_id (header);
        }
 
        priv->draft_msg = draft;
        }
 
        priv->draft_msg = draft;
@@ -3135,3 +3153,14 @@ modest_msg_edit_window_add_part (ModestMsgEditWindow *window,
        gtk_widget_show_all (priv->attachments_caption);
        gtk_text_buffer_set_modified (priv->text_buffer, TRUE);
 }
        gtk_widget_show_all (priv->attachments_caption);
        gtk_text_buffer_set_modified (priv->text_buffer, TRUE);
 }
+
+const gchar*    
+modest_msg_edit_window_get_message_uid (ModestMsgEditWindow *window)
+{
+       ModestMsgEditWindowPrivate *priv;
+
+       g_return_val_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window), NULL);        
+       priv = MODEST_MSG_EDIT_WINDOW_GET_PRIVATE (window);
+
+       return priv->msg_uid;
+}
index 6e28271..132d87d 100644 (file)
@@ -371,6 +371,17 @@ void            modest_msg_edit_window_set_sent            (ModestMsgEditWindow
  */
 void            modest_msg_edit_window_set_draft           (ModestMsgEditWindow *window,
                                                            TnyMsg *draft);
  */
 void            modest_msg_edit_window_set_draft           (ModestMsgEditWindow *window,
                                                            TnyMsg *draft);
+/**
+ * modest_msg_edit_window_get_message_uid:
+ * @msg: an #ModestMsgEditWindow instance
+ * 
+ * gets the unique identifier for the message in this msg editor.
+ * This is the identifier of the draft or outbox message the editor was
+ * opened from. If it's a new message, then it returns %NULL
+ * 
+ * Returns: the id of the #TnyMsg being shown, or NULL in case of error
+ */
+const gchar*    modest_msg_edit_window_get_message_uid (ModestMsgEditWindow *window);
 
 G_END_DECLS
 
 
 G_END_DECLS
 
index 9a8c103..d0d8b27 100644 (file)
@@ -283,11 +283,15 @@ compare_msguids (ModestWindow *win,
 {
        const gchar *msg_uid;
 
 {
        const gchar *msg_uid;
 
-       if (!MODEST_IS_MSG_VIEW_WINDOW (win))
+       if ((!MODEST_IS_MSG_EDIT_WINDOW (win)) && (!MODEST_IS_MSG_VIEW_WINDOW (win)))
                return 1;
 
        /* Get message uid from msg window */
                return 1;
 
        /* Get message uid from msg window */
-       msg_uid = modest_msg_view_window_get_message_uid (MODEST_MSG_VIEW_WINDOW (win));
+       if (MODEST_IS_MSG_EDIT_WINDOW (win)) {
+               msg_uid = modest_msg_edit_window_get_message_uid (MODEST_MSG_EDIT_WINDOW (win));
+       } else {
+               msg_uid = modest_msg_view_window_get_message_uid (MODEST_MSG_VIEW_WINDOW (win));
+       }
        
        if (msg_uid && uid &&!strcmp (msg_uid, uid))
                return 0;
        
        if (msg_uid && uid &&!strcmp (msg_uid, uid))
                return 0;
@@ -325,7 +329,8 @@ modest_window_mgr_find_registered_header (ModestWindowMgr *self, TnyHeader *head
        if (item) {
                has_window = TRUE;
                if (win) {
        if (item) {
                has_window = TRUE;
                if (win) {
-                       if (!MODEST_IS_MSG_VIEW_WINDOW(item->data))
+                       if ((!MODEST_IS_MSG_VIEW_WINDOW(item->data)) && 
+                           (!MODEST_IS_MSG_EDIT_WINDOW (item->data)))
                                g_debug ("not a valid window!");
                        else {
                                g_debug ("found a window");
                                g_debug ("not a valid window!");
                        else {
                                g_debug ("found a window");
@@ -385,6 +390,19 @@ modest_window_mgr_register_window (ModestWindowMgr *self,
                        remove_uid (priv->preregistered_uids,
                                    modest_msg_view_window_get_message_uid
                                    (MODEST_MSG_VIEW_WINDOW (window)));
                        remove_uid (priv->preregistered_uids,
                                    modest_msg_view_window_get_message_uid
                                    (MODEST_MSG_VIEW_WINDOW (window)));
+       } else if (MODEST_IS_MSG_EDIT_WINDOW(window)) {
+               const gchar *uid = modest_msg_edit_window_get_message_uid
+                       (MODEST_MSG_EDIT_WINDOW (window));
+
+               g_debug ("registering window for %s", uid);
+                               
+               if (!has_uid (priv->preregistered_uids, uid)) 
+                       g_debug ("weird: no uid for window (%s)", uid);
+
+               priv->preregistered_uids = 
+                       remove_uid (priv->preregistered_uids,
+                                   modest_msg_edit_window_get_message_uid
+                                   (MODEST_MSG_EDIT_WINDOW (window)));
        }
        
        /* Add to list. Keep a reference to the window */
        }
        
        /* Add to list. Keep a reference to the window */