Add methods to create a reply to calendar message and open it in editor
authorJosé Dapena Paz <jdapena@igalia.com>
Thu, 17 Dec 2009 16:29:39 +0000 (17:29 +0100)
committerJosé Dapena Paz <jdapena@igalia.com>
Mon, 18 Jan 2010 15:49:56 +0000 (16:49 +0100)
src/modest-tny-msg.c
src/modest-tny-msg.h
src/modest-ui-actions.c
src/modest-ui-actions.h

index e0c303a..e76be4d 100644 (file)
@@ -1405,6 +1405,36 @@ modest_tny_msg_create_reply_msg (TnyMsg *msg,
        return new_msg;
 }
 
+TnyMsg*
+modest_tny_msg_create_reply_calendar_msg (TnyMsg *msg,
+                                         TnyHeader *header,
+                                         const gchar *from,
+                                         const gchar *signature,
+                                         TnyList *headers)
+{
+       TnyMsg *new_msg = NULL;
+       TnyIterator *iterator;
+
+       g_return_val_if_fail (msg && TNY_IS_MSG(msg), NULL);
+
+       new_msg = modest_tny_msg_create_reply_msg (msg, header, from, signature,  
+                                                  MODEST_TNY_MSG_REPLY_TYPE_QUOTE, MODEST_TNY_MSG_REPLY_MODE_SENDER);
+
+       iterator = tny_list_create_iterator (headers);
+       while (!tny_iterator_is_done (iterator)) {
+               TnyPair *pair = TNY_PAIR (tny_iterator_get_current (iterator));
+
+               tny_mime_part_set_header_pair (TNY_MIME_PART (new_msg),
+                                              tny_pair_get_name (pair),
+                                              tny_pair_get_value (pair));
+               g_object_unref (pair);
+               tny_iterator_next (iterator);
+       }
+       g_object_unref (iterator);
+
+       return new_msg;
+}
+
 
 static gboolean
 is_ascii(const gchar *s)
index b28c026..bc9d81c 100644 (file)
@@ -164,6 +164,24 @@ TnyMsg*       modest_tny_msg_create_forward_msg   (TnyMsg *msg,
                                                   ModestTnyMsgForwardType forward_type);
 
 /**
+ * modest_tny_msg_create_reply_calendar_msg:
+ * @msg: a valid #TnyMsg instance, or %NULL
+ * @header: a valid #TnyHeader instance, or %NULL
+ * @from: the sender of the forwarded mail
+ * @signature: signature to add to the reply message
+ * @headers: #TnyList of #TnyPair with the headers to add
+ * 
+ * Creates a new message to reply to a calendar event
+ * 
+ * Returns: Returns: a new #TnyMsg, or NULL in case of error
+ **/
+TnyMsg*       modest_tny_msg_create_reply_calendar_msg     (TnyMsg *msg,
+                                                           TnyHeader *header,
+                                                           const gchar *from,
+                                                           const gchar *signature,
+                                                           TnyList *headers);
+
+/**
  * modest_tny_msg_create_reply_msg:
  * @msg: a valid #TnyMsg instance, or %NULL
  * @header: a valid #TnyHeader instance, or %NULL
index 95591bb..724f487 100644 (file)
@@ -2233,6 +2233,68 @@ reply_forward (ReplyForwardAction action, ModestWindow *win)
 }
 
 void
+modest_ui_actions_reply_calendar (ModestWindow *win, TnyMsg *msg, TnyList *header_pairs)
+{
+       gchar *from;
+       gchar *recipient;
+       gchar *signature;
+       gboolean use_signature;
+       TnyMsg *new_msg;
+       GtkWidget *msg_win;
+       gdouble parent_zoom;
+       const gchar *account_name;
+       const gchar *mailbox;
+       TnyHeader *msg_header;
+       ModestWindowMgr *mgr;
+
+       g_return_if_fail (MODEST_IS_MSG_VIEW_WINDOW(win));
+
+       /* we check for low-mem; in that case, show a warning, and don't allow
+        * reply/forward (because it could potentially require a lot of memory */
+       if (modest_platform_check_memory_low (MODEST_WINDOW(win), TRUE))
+               return;
+
+       account_name = modest_window_get_active_account (MODEST_WINDOW (win));
+       mailbox = modest_window_get_active_mailbox (MODEST_WINDOW (win));
+       from = modest_account_mgr_get_from_string (modest_runtime_get_account_mgr(),
+                                                  account_name, mailbox);
+       recipient = modest_text_utils_get_email_address (from);
+       signature = modest_account_mgr_get_signature_from_recipient (modest_runtime_get_account_mgr(), 
+                                                                    recipient, 
+                                                                    &use_signature);
+       g_free (recipient);
+
+       msg_header = tny_msg_get_header (msg);
+       new_msg =
+               modest_tny_msg_create_reply_calendar_msg (msg, msg_header, from,
+                                                         (use_signature) ? signature : NULL,
+                                                         header_pairs);
+       g_object_unref (msg_header);
+
+       g_free (from);
+       g_free (signature);
+
+       if (!new_msg) {
+               g_warning ("%s: failed to create message\n", __FUNCTION__);
+               goto cleanup;
+       }
+
+       msg_win = (GtkWidget *) modest_msg_edit_window_new (new_msg, account_name, mailbox, FALSE);
+       mgr = modest_runtime_get_window_mgr ();
+       modest_window_mgr_register_window (mgr, MODEST_WINDOW (msg_win), (ModestWindow *) win);
+
+       parent_zoom = modest_window_get_zoom (MODEST_WINDOW (win));
+       modest_window_set_zoom (MODEST_WINDOW (msg_win), parent_zoom);
+
+       /* Show edit window */
+       gtk_widget_show_all (GTK_WIDGET (msg_win));
+
+cleanup:
+       if (new_msg)
+               g_object_unref (G_OBJECT (new_msg));
+}
+
+void
 modest_ui_actions_on_reply (GtkAction *action, ModestWindow *win)
 {
        g_return_if_fail (MODEST_IS_WINDOW(win));
index 65d8417..b305525 100644 (file)
@@ -79,6 +79,8 @@ void     modest_ui_actions_on_open           (GtkAction *action, ModestWindow *w
 
 void     modest_ui_actions_on_reply         (GtkAction *action, ModestWindow *win);
 
+void     modest_ui_actions_reply_calendar (ModestWindow *win, TnyMsg *msg, TnyList *header_pairs);
+
 void     modest_ui_actions_on_forward       (GtkAction *action, ModestWindow *win);
 
 void     modest_ui_actions_on_sort          (GtkAction *action, ModestWindow *window);