X-Git-Url: http://git.maemo.org/git/?a=blobdiff_plain;f=src%2Fdbus_api%2Fmodest-dbus-callbacks.c;h=1a948a73827b5020fe425ebd1d57140119f5a630;hb=856d7ab2997effafe72148fe34a0aa461856ce07;hp=f4813ad5f98acef98380f9eca729719e5f810f8a;hpb=e471e521c0a544c1d1fe346ba1ce11c0781b56ae;p=modest diff --git a/src/dbus_api/modest-dbus-callbacks.c b/src/dbus_api/modest-dbus-callbacks.c index f4813ad..1a948a7 100644 --- a/src/dbus_api/modest-dbus-callbacks.c +++ b/src/dbus_api/modest-dbus-callbacks.c @@ -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 #include #include +#include +#include +#include #include #include @@ -61,7 +65,7 @@ typedef struct gchar *bcc; gchar *subject; gchar *body; - GSList *attachments; + gchar *attachments; } ComposeMailIdleData; static gboolean @@ -100,6 +104,7 @@ on_idle_send_mail(gpointer user_data) modest_mail_operation_send_new_mail (mail_operation, transport_account, + NULL, from, /* from */ idle_data->to, idle_data->cc, idle_data->bcc, idle_data->subject, idle_data->body, /* plain_body */ @@ -392,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(); @@ -411,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"); @@ -438,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)); @@ -465,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; @@ -491,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. */ @@ -512,12 +521,11 @@ static gint on_compose_mail(GArray * arguments, gpointer data, osso_rpc_t * retv static TnyMsg * find_message_by_url (const char *uri, TnyAccount **ac_out) { - ModestTnyAccountStore *astore; TnyAccount *account; TnyFolder *folder; TnyMsg *msg; - + GError *err = NULL; account = NULL; msg = NULL; folder = NULL; @@ -527,39 +535,47 @@ find_message_by_url (const char *uri, TnyAccount **ac_out) if (astore == NULL) { return NULL; } - - g_debug ("Got AccountStore, lets go"); account = tny_account_store_find_account (TNY_ACCOUNT_STORE (astore), uri); if (account == NULL) { + g_debug ("%s: tny_account_store_find_account() failed.\n", __FUNCTION__); return NULL; } - g_debug ("Found account"); + g_debug ("%s: Found account.\n", __FUNCTION__); if ( ! TNY_IS_STORE_ACCOUNT (account)) { goto out; } - g_debug ("Account is store account"); + g_debug ("%s: Account is store account.\n", __FUNCTION__); *ac_out = account; folder = tny_store_account_find_folder (TNY_STORE_ACCOUNT (account), uri, - NULL); + &err); if (folder == NULL) { + g_debug ("%s: tny_store_account_find_folder() failed.\n", __FUNCTION__); goto out; } - g_debug ("Found folder"); + g_debug ("%s: Found folder. (%s)\n", __FUNCTION__, uri); - msg = tny_folder_find_msg (folder, uri, NULL); + msg = tny_folder_find_msg (folder, uri, &err); + + if (!msg) { + g_debug ("%s: tny_folder_find_msg() failed (%s).\n", + __FUNCTION__, err->message); + } out: + if (err) + g_error_free (err); + if (account && !msg) { g_object_unref (account); *ac_out = NULL; @@ -585,14 +601,15 @@ on_idle_open_message (gpointer user_data) uri = (char *) user_data; - g_debug ("Trying to find msg by url: %s", uri); + g_debug ("%s: Trying to find msg by url: %s", __FUNCTION__, uri); msg = find_message_by_url (uri, &account); g_free (uri); if (msg == NULL) { + g_debug (" %s: message not found.", __FUNCTION__); return FALSE; } - g_debug ("Found message"); + g_debug (" %s: Found message.", __FUNCTION__); header = tny_msg_get_header (msg); account_name = tny_account_get_name (account); @@ -757,6 +774,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, @@ -764,8 +809,8 @@ gint modest_dbus_req_handler(const gchar * interface, const gchar * method, osso_rpc_t * retval) { - g_debug ("modest_dbus_req_handler()\n"); - g_debug ("debug: method received: %s\n", method); + g_debug ("debug: %s\n", __FUNCTION__); + g_debug ("debug: %s: method received: %s\n", __FUNCTION__, method); if (g_ascii_strcasecmp(method, MODEST_DBUS_METHOD_SEND_MAIL) == 0) { return on_send_mail (arguments, data, retval); @@ -779,6 +824,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 @@ -802,7 +849,7 @@ gint modest_dbus_req_handler(const gchar * interface, const gchar * method, DBUS_STRUCT_END_CHAR_AS_STRING static DBusMessage * -search_result_to_messsage (DBusMessage *reply, +search_result_to_message (DBusMessage *reply, GList *hits) { DBusMessageIter iter; @@ -817,41 +864,28 @@ search_result_to_messsage (DBusMessage *reply, for (hit_iter = hits; hit_iter; hit_iter = hit_iter->next) { DBusMessageIter struct_iter; - TnyFolder *tf; - TnyHeader *header; - TnyHeaderFlags flags; - char *msg_url = ""; - const char *subject = ""; - const char *folder = ""; - const char *sender = ""; - guint64 size = 0; - gboolean has_attachemnt = FALSE; - gboolean is_unread = FALSE; - gint64 ts = 0; - char *furl; - const char *uid; - - g_debug ("Marshalling hit ...(%s)", - TNY_IS_HEADER (hit_iter->data) ? "yes" : "no"); - - header = TNY_HEADER (hit_iter->data); - tf = tny_header_get_folder (header); - furl = tny_folder_get_url_string (tf); - - uid = tny_header_get_uid (header); - msg_url = g_strdup_printf ("%s/%s", furl, uid); - - subject = tny_header_get_subject (header); - folder = furl; - sender = tny_header_get_from (header); - size = tny_header_get_message_size (header); - - flags = tny_header_get_flags (header); - has_attachemnt = flags & TNY_HEADER_FLAG_ATTACHMENTS; - is_unread = ! (flags & TNY_HEADER_FLAG_SEEN); - ts = tny_header_get_date_received (header); - - g_debug ("Adding hit: %s", msg_url); + ModestSearchHit *hit; + char *msg_url; + const char *subject; + const char *folder; + const char *sender; + guint64 size; + gboolean has_attachment; + gboolean is_unread; + gint64 ts; + + hit = (ModestSearchHit *) hit_iter->data; + + msg_url = hit->msgid; + subject = hit->subject; + folder = hit->folder; + sender = hit->sender; + size = hit->msize; + has_attachment = hit->has_attachment; + is_unread = hit->is_unread; + ts = hit->timestamp; + + g_debug ("DEBUG: %s: Adding hit: %s", __FUNCTION__, msg_url); dbus_message_iter_open_container (&array_iter, DBUS_TYPE_STRUCT, @@ -880,7 +914,7 @@ search_result_to_messsage (DBusMessage *reply, dbus_message_iter_append_basic (&struct_iter, DBUS_TYPE_BOOLEAN, - &has_attachemnt); + &has_attachment); dbus_message_iter_append_basic (&struct_iter, DBUS_TYPE_BOOLEAN, @@ -893,12 +927,12 @@ search_result_to_messsage (DBusMessage *reply, dbus_message_iter_close_container (&array_iter, &struct_iter); + g_free (hit->msgid); + g_free (hit->subject); + g_free (hit->folder); + g_free (hit->sender); - g_free (msg_url); - g_free (furl); - - /* Also unref the header, we don't need it anymore */ - g_object_unref (header); + g_slice_free (ModestSearchHit, hit); } dbus_message_iter_close_container (&iter, &array_iter); @@ -954,7 +988,9 @@ modest_dbus_req_filter (DBusConnection *con, end_date = (time_t) ed_v; memset (&search, 0, sizeof (search)); +#ifdef MODEST_HAVE_OGS search.query = query; +#endif search.before = start_date; search.after = end_date; search.flags = 0; @@ -996,16 +1032,14 @@ modest_dbus_req_filter (DBusConnection *con, #ifdef MODEST_HAVE_OGS search.flags |= MODEST_SEARCH_USE_OGS; -#endif - g_debug ("Starting search for %s", search.query); - +#endif hits = modest_search_all_accounts (&search); reply = dbus_message_new_method_return (message); - search_result_to_messsage (reply, hits); - + search_result_to_message (reply, hits); + if (reply == NULL) { g_warning ("Could not create reply"); } @@ -1016,6 +1050,8 @@ modest_dbus_req_filter (DBusConnection *con, dbus_message_unref (reply); } + g_list_free (hits); + } @@ -1024,6 +1060,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) {