Initialization speedups
[modest] / src / dbus_api / modest-dbus-callbacks.c
index ee307d1..ee4419a 100644 (file)
@@ -33,6 +33,7 @@
 #include "modest-account-mgr-helpers.h"
 #include "modest-tny-account.h"
 #include "modest-ui-actions.h"
+
 #include "modest-search.h"
 #include "widgets/modest-msg-edit-window.h"
 #include "modest-tny-msg.h"
@@ -40,6 +41,9 @@
 #include <libgnomevfs/gnome-vfs-utils.h>
 #include <stdio.h>
 #include <string.h>
+#include <glib/gstdio.h>
+#include <libgnomevfs/gnome-vfs-mime.h>
+#include <tny-fs-stream.h>
 
 #include <tny-list.h>
 #include <tny-iterator.h>
@@ -61,7 +65,7 @@ typedef struct
        gchar *bcc;
        gchar *subject;
        gchar *body;
-       GSList *attachments;
+       gchar *attachments;
 } ComposeMailIdleData;
 
 static gboolean
@@ -393,10 +397,15 @@ static gint on_mail_to(GArray * arguments, gpointer data, osso_rpc_t * retval)
 }
 
 
+
+
+
 static gboolean
 on_idle_compose_mail(gpointer user_data)
 {
        ComposeMailIdleData *idle_data = (ComposeMailIdleData*)user_data;
+       gchar **list = NULL;
+       gint i = 0;
 
        /* Get the TnyTransportAccount so we can instantiate a mail operation: */
        ModestAccountMgr *account_mgr = modest_runtime_get_account_mgr();
@@ -412,18 +421,18 @@ on_idle_compose_mail(gpointer user_data)
        }
        
        if (!account) {
-               g_printerr ("modest: failed to get tny account folder'\n", account_name);
+               g_printerr ("modest: failed to get tny account folder'%s'\n", account_name);
        } else {
                gchar * from = modest_account_mgr_get_from_string (account_mgr,
                                                                  account_name);
                if (!from) {
                        g_printerr ("modest: no from address for account '%s'\n", account_name);
                } else {
-                       
+       
                        /* Create the message: */
                        TnyMsg *msg  = modest_tny_msg_new (idle_data->to, from, 
                                idle_data->cc, idle_data->bcc, idle_data->subject, idle_data->body, 
-                               idle_data->attachments);
+                               NULL); /* NULL because m_t_m_n doesn't use it */
                                
                        if (!msg) {
                                g_printerr ("modest: failed to create message\n");
@@ -439,6 +448,14 @@ on_idle_compose_mail(gpointer user_data)
                                        tny_folder_add_msg (folder, msg, NULL); /* TODO: check err */
                
                                        ModestWindow *win = modest_msg_edit_window_new (msg, account_name);
+
+                                       list = g_strsplit(idle_data->attachments, ",", 0);
+                                       for (i=0; list[i] != NULL; i++) {
+                                               modest_msg_edit_window_attach_file_noninteractive(
+                                                               (ModestMsgEditWindow *)win, list[i]);
+                                       }
+                                       g_strfreev(list);
+                                       
                                        gtk_widget_show_all (GTK_WIDGET (win));
                                
                                        g_object_unref (G_OBJECT(folder));
@@ -466,8 +483,7 @@ on_idle_compose_mail(gpointer user_data)
 
 static gint on_compose_mail(GArray * arguments, gpointer data, osso_rpc_t * retval)
 {
-       gchar **list = NULL;
-       gint i = 0;
+
        
        if (arguments->len != MODEST_DEBUS_COMPOSE_MAIL_ARGS_COUNT)
        return OSSO_ERROR;
@@ -492,17 +508,9 @@ static gint on_compose_mail(GArray * arguments, gpointer data, osso_rpc_t * retv
        idle_data->body = g_strdup (val.value.s);
        
        val = g_array_index(arguments, osso_rpc_t, MODEST_DEBUS_COMPOSE_MAIL_ARG_ATTACHMENTS);
-       gchar *attachments_str = g_strdup (val.value.s);
+       idle_data->attachments = g_strdup (val.value.s);
 
-       list = g_strsplit(attachments_str, ",", 0);
-       for (i=0; list[i] != NULL; i++) {
-               idle_data->attachments = g_slist_append(idle_data->attachments, g_strdup(list[i]));
-       }
-       g_strfreev(list);
-
-       
-       /* printf("  debug: to=%s\n", idle_data->to); */
-       g_idle_add(on_idle_compose_mail, (gpointer)idle_data);
+       g_idle_add(on_idle_compose_mail, (gpointer)idle_data);
        
        /* Note that we cannot report failures during sending, 
         * because that would be asynchronous. */
@@ -758,6 +766,34 @@ static gint on_send_receive(GArray * arguments, gpointer data, osso_rpc_t * retv
         * because that would be asynchronous. */
        return OSSO_OK;
 }
+
+static gboolean
+on_idle_open_default_inbox(gpointer user_data)
+{
+       ModestWindow *win = 
+               modest_window_mgr_get_main_window (modest_runtime_get_window_mgr ());
+
+       /* Get the folder view */
+       GtkWidget *folder_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (win),
+                                                          MODEST_WIDGET_TYPE_FOLDER_VIEW);
+       modest_folder_view_select_first_inbox_or_local (
+               MODEST_FOLDER_VIEW (folder_view));
+       
+       return FALSE; /* Do not call this callback again. */
+}
+
+static gint on_open_default_inbox(GArray * arguments, gpointer data, osso_rpc_t * retval)
+{
+    /* Use g_idle to context-switch into the application's thread: */
+
+    /* This method has no arguments. */
+       
+       g_idle_add(on_idle_open_default_inbox, NULL);
+       
+       /* Note that we cannot report failures during send/receive, 
+        * because that would be asynchronous. */
+       return OSSO_OK;
+}
                       
 /* Callback for normal D-BUS messages */
 gint modest_dbus_req_handler(const gchar * interface, const gchar * method,
@@ -780,6 +816,8 @@ gint modest_dbus_req_handler(const gchar * interface, const gchar * method,
                return on_compose_mail (arguments, data, retval);
        } else if (g_ascii_strcasecmp(method, MODEST_DBUS_METHOD_DELETE_MESSAGE) == 0) {
                return on_delete_message (arguments,data, retval);
+       } else if (g_ascii_strcasecmp(method, MODEST_DBUS_METHOD_OPEN_DEFAULT_INBOX) == 0) {
+               return on_open_default_inbox (arguments, data, retval);
        }
        else { 
                /* We need to return INVALID here so
@@ -1014,6 +1052,7 @@ modest_dbus_req_filter (DBusConnection *con,
                DBUS_HANDLER_RESULT_NOT_YET_HANDLED);
 }
 
+
 void
 modest_osso_cb_hw_state_handler(osso_hw_state_t *state, gpointer data)
 {