More refactoring of the ComposeMail DBUS handler, now everything
authorAlberto Garcia <agarcia@igalia.com>
Mon, 22 Oct 2007 14:56:42 +0000 (14:56 +0000)
committerAlberto Garcia <agarcia@igalia.com>
Mon, 22 Oct 2007 14:56:42 +0000 (14:56 +0000)
is done in modest-ui-actions

pmo-trunk-r3554

src/dbus_api/modest-dbus-callbacks.c
src/modest-ui-actions.c
src/modest-ui-actions.h

index 032b8ec..749a3ec 100644 (file)
@@ -256,69 +256,32 @@ on_idle_compose_mail(gpointer user_data)
 {
        if (!check_and_offer_account_creation ())
                return FALSE;
 {
        if (!check_and_offer_account_creation ())
                return FALSE;
-       
+       GSList *attachments = NULL;
        ComposeMailIdleData *idle_data = (ComposeMailIdleData*)user_data;
        ComposeMailIdleData *idle_data = (ComposeMailIdleData*)user_data;
-        ModestWindow *win = NULL;
-        TnyMsg *msg = NULL;
 
 
-       /* Get the TnyTransportAccount so we can instantiate a mail operation: */
-       gchar *account_name = modest_account_mgr_get_default_account(modest_runtime_get_account_mgr());
-       if (!account_name) {
-               g_printerr ("modest: no account found.\n");
-               
-               /* TODO: If the call to this D-Bus method caused the application to start
-                * then the new-account wizard will now be shown, and we need to wait 
-                * until the account exists instead of just failing.
-                */
+       /* it seems Sketch at least sends a leading ',' -- take that into account,
+        * ie strip that ,*/
+       if (idle_data->attachments && idle_data->attachments[0]==',') {
+               gchar *tmp = g_strdup (idle_data->attachments + 1);
+               g_free(idle_data->attachments);
+               idle_data->attachments = tmp;
+       }
+       if (idle_data->attachments != NULL) {
+               gchar **list = g_strsplit(idle_data->attachments, ",", 0);
+               gint i = 0;
+               for (i=0; list[i] != NULL; i++) {
+                       attachments = g_slist_append(attachments, g_strdup(list[i]));
+               }
+               g_strfreev(list);
        }
        }
+       gdk_threads_enter (); /* CHECKED */
+       modest_ui_actions_compose_msg(NULL, idle_data->to, idle_data->cc,
+                                     idle_data->bcc, idle_data->subject,
+                                     idle_data->body, attachments);
+       gdk_threads_leave (); /* CHECKED */
+       g_slist_foreach(attachments, (GFunc)g_free, NULL);
+       g_slist_free(attachments);
 
 
-        msg = modest_ui_actions_create_msg(account_name, idle_data->to, idle_data->cc,
-                                           idle_data->bcc, idle_data->subject, idle_data->body);
-        if (msg == NULL) goto cleanup;
-
-        /* This is a GDK lock because we are an idle callback and
-         * the code below is or does Gtk+ code */
-
-        gdk_threads_enter (); /* CHECKED */
-
-        win = modest_msg_edit_window_new (msg, account_name, FALSE);
-
-        /* it seems Sketch at least sends a leading ',' -- take that into account,
-         * ie strip that ,*/
-        if (idle_data->attachments && idle_data->attachments[0]==',') {
-                gchar *tmp = g_strdup (idle_data->attachments + 1);
-                g_free(idle_data->attachments);
-                idle_data->attachments = tmp;
-        }
-        if (idle_data->attachments != NULL) {
-                gchar **list = g_strsplit(idle_data->attachments, ",", 0);
-                gint i = 0;
-                for (i=0; list[i] != NULL; i++) {
-                        modest_msg_edit_window_attach_file_one(
-                                (ModestMsgEditWindow *)win, list[i]);
-                }
-                g_strfreev(list);
-        }
-
-        modest_window_mgr_register_window (modest_runtime_get_window_mgr (), win);
-        gtk_widget_show_all (GTK_WIDGET (win));
-
-        gdk_threads_leave (); /* CHECKED */
-
-cleanup:
-        if (win) g_object_unref (win);
-        if (msg) g_object_unref (msg);
-       /* Free the idle data: */
-       g_free (idle_data->to);
-       g_free (idle_data->cc);
-       g_free (idle_data->bcc);
-       g_free (idle_data->subject);
-       g_free (idle_data->body);
-       g_free (idle_data->attachments);
-       g_free (idle_data);
-       
-       g_free (account_name);
-       
        return FALSE; /* Do not call this callback again. */
 }
 
        return FALSE; /* Do not call this callback again. */
 }
 
index 006dc22..22ab39c 100644 (file)
@@ -765,22 +765,31 @@ modest_ui_actions_on_smtp_servers (GtkAction *action, ModestWindow *win)
 #endif /* MODEST_PLATFORM_MAEMO */
 }
 
 #endif /* MODEST_PLATFORM_MAEMO */
 }
 
-TnyMsg *
-modest_ui_actions_create_msg(const gchar *account_name,
-                            const gchar *to_str,
-                            const gchar *cc_str,
-                            const gchar *bcc_str,
-                            const gchar *subject_str,
-                            const gchar *body_str)
+void
+modest_ui_actions_compose_msg(ModestWindow *win,
+                             const gchar *to_str,
+                             const gchar *cc_str,
+                             const gchar *bcc_str,
+                             const gchar *subject_str,
+                             const gchar *body_str,
+                             GSList *attachments)
 {
 {
+       gchar *account_name = NULL;
        TnyMsg *msg = NULL;
        TnyAccount *account = NULL;
        TnyFolder *folder = NULL;
        gchar *from_str = NULL, *signature = NULL, *body = NULL;
        gboolean use_signature = FALSE;
        TnyMsg *msg = NULL;
        TnyAccount *account = NULL;
        TnyFolder *folder = NULL;
        gchar *from_str = NULL, *signature = NULL, *body = NULL;
        gboolean use_signature = FALSE;
+       ModestWindow *msg_win = NULL;
        ModestAccountMgr *mgr = modest_runtime_get_account_mgr();
        ModestTnyAccountStore *store = modest_runtime_get_account_store();
 
        ModestAccountMgr *mgr = modest_runtime_get_account_mgr();
        ModestTnyAccountStore *store = modest_runtime_get_account_store();
 
+       if (win) account_name = g_strdup (modest_window_get_active_account (win));
+       if (!account_name) account_name = modest_account_mgr_get_default_account(mgr);
+       if (!account_name) {
+               g_printerr ("modest: no account found\n");
+               goto cleanup;
+       }
        account = modest_tny_account_store_get_server_account (store, account_name, TNY_ACCOUNT_TYPE_STORE);
        if (!account) {
                g_printerr ("modest: failed to get tnyaccount for '%s'\n", account_name);
        account = modest_tny_account_store_get_server_account (store, account_name, TNY_ACCOUNT_TYPE_STORE);
        if (!account) {
                g_printerr ("modest: failed to get tnyaccount for '%s'\n", account_name);
@@ -810,55 +819,42 @@ modest_ui_actions_create_msg(const gchar *account_name,
                goto cleanup;
        }
 
                goto cleanup;
        }
 
+       /* Create and register edit window */
+       /* This is destroyed by TODO. */
+       msg_win = modest_msg_edit_window_new (msg, account_name, FALSE);
+       while (attachments) {
+               modest_msg_edit_window_attach_file_one((ModestMsgEditWindow *)msg_win,
+                                                      attachments->data);
+               attachments = g_slist_next(attachments);
+       }
+       modest_window_mgr_register_window (modest_runtime_get_window_mgr(), msg_win);
+
+       if (win) {
+               gtk_window_set_transient_for (GTK_WINDOW (msg_win),
+                                             GTK_WINDOW (win));
+       }
+       gtk_widget_show_all (GTK_WIDGET (msg_win));
+
 cleanup:
        g_free (from_str);
        g_free (signature);
        g_free (body);
 cleanup:
        g_free (from_str);
        g_free (signature);
        g_free (body);
+       g_free (account_name);
        if (account) g_object_unref (G_OBJECT(account));
        if (folder) g_object_unref (G_OBJECT(folder));
        if (account) g_object_unref (G_OBJECT(account));
        if (folder) g_object_unref (G_OBJECT(folder));
-
-       return msg;
+       if (msg_win) g_object_unref (G_OBJECT(msg_win));
+       if (msg) g_object_unref (G_OBJECT(msg));
 }
 
 void
 modest_ui_actions_on_new_msg (GtkAction *action, ModestWindow *win)
 {
 }
 
 void
 modest_ui_actions_on_new_msg (GtkAction *action, ModestWindow *win)
 {
-       ModestWindow *msg_win = NULL;
-       TnyMsg *msg = NULL;
-       gchar *account_name = NULL;
-       ModestWindowMgr *win_mgr;
-       ModestAccountMgr *acc_mgr = modest_runtime_get_account_mgr();
-
        /* if there are no accounts yet, just show the wizard */
        /* if there are no accounts yet, just show the wizard */
-       if (!modest_account_mgr_has_accounts (acc_mgr, TRUE)) {
+       if (!modest_account_mgr_has_accounts (modest_runtime_get_account_mgr(), TRUE)) {
                if (!modest_ui_actions_run_account_setup_wizard (win)) return;
        }
 
                if (!modest_ui_actions_run_account_setup_wizard (win)) return;
        }
 
-       account_name = g_strdup (modest_window_get_active_account (win));
-       if (!account_name) account_name = modest_account_mgr_get_default_account(acc_mgr);
-       if (!account_name) {
-               g_printerr ("modest: no account found\n");
-               goto cleanup;
-       }
-       msg = modest_ui_actions_create_msg(account_name, NULL, NULL, NULL, NULL, NULL);
-       if (msg == NULL) goto cleanup;
-
-       /* Create and register edit window */
-       /* This is destroyed by TODO. */
-       msg_win = modest_msg_edit_window_new (msg, account_name, FALSE);
-       win_mgr = modest_runtime_get_window_mgr ();
-       modest_window_mgr_register_window (win_mgr, msg_win);
-
-       if (win) {
-               gtk_window_set_transient_for (GTK_WINDOW (msg_win),
-                                             GTK_WINDOW (win));
-        }
-       gtk_widget_show_all (GTK_WIDGET (msg_win));
-
-cleanup:
-       g_free (account_name);
-       if (msg_win) g_object_unref (msg_win);
-       if (msg) g_object_unref (G_OBJECT(msg));
+       modest_ui_actions_compose_msg(win, NULL, NULL, NULL, NULL, NULL, NULL);
 }
 
 gboolean 
 }
 
 gboolean 
index 1d6d7d7..dce58d2 100644 (file)
@@ -488,21 +488,22 @@ void modest_ui_actions_on_send_queue_status_changed (ModestTnySendQueue *send_qu
                                                     gpointer user_data);
 
 /**
                                                     gpointer user_data);
 
 /**
- * Create a new TnyMsg to be used in a compose window
- * @param account_name Name of the account that will be used to send this message
+ * Opens a new message editor for composing
+ * @param win Modest main window (can be NULL)
  * @param to_str "To:" header, or NULL
  * @param cc_str "Cc:" header, or NULL
  * @param bcc_str "Bcc:" header, or NULL
  * @param subject_str Subject of the message, or NULL
  * @param body_str Body of the message (without signature), or NULL
  * @param to_str "To:" header, or NULL
  * @param cc_str "Cc:" header, or NULL
  * @param bcc_str "Bcc:" header, or NULL
  * @param subject_str Subject of the message, or NULL
  * @param body_str Body of the message (without signature), or NULL
- * @return A new TnyMsg (or NULL if an error happened)
+ * @param attachments List of file URIs to attach
  */
  */
-TnyMsg *modest_ui_actions_create_msg(const gchar *account_name,
-                                    const gchar *to_str,
-                                    const gchar *cc_str,
-                                    const gchar *bcc_str,
-                                    const gchar *subject_str,
-                                    const gchar *body_str);
+void modest_ui_actions_compose_msg(ModestWindow *win,
+                                  const gchar *to_str,
+                                  const gchar *cc_str,
+                                  const gchar *bcc_str,
+                                  const gchar *subject_str,
+                                  const gchar *body_str,
+                                  GSList *attachments);
 
 G_END_DECLS
 #endif /* __MODEST_UI_ACTIONS_H__ */
 
 G_END_DECLS
 #endif /* __MODEST_UI_ACTIONS_H__ */