+
+
+static gint
+on_dbus_method_dump_send_queues (DBusConnection *con, DBusMessage *message)
+{
+ gchar *str;
+
+ DBusMessage *reply;
+ dbus_uint32_t serial = 0;
+
+ GSList *account_names, *cursor;
+
+ str = g_strdup("\nsend queues\n"
+ "===========\n");
+
+ cursor = account_names = modest_account_mgr_account_names
+ (modest_runtime_get_account_mgr(), TRUE); /* only enabled accounts */
+
+ while (cursor) {
+ TnyAccount *acc;
+ gchar *tmp, *accname = (gchar*)cursor->data;
+
+ tmp = g_strdup_printf ("%s", str);
+ g_free (str);
+ str = tmp;
+
+ /* transport */
+ acc = modest_tny_account_store_get_server_account (
+ modest_runtime_get_account_store(), accname,
+ TNY_ACCOUNT_TYPE_TRANSPORT);
+ if (TNY_IS_ACCOUNT(acc)) {
+ gchar *tmp, *url = tny_account_get_url_string (acc);
+ ModestTnySendQueue *sendqueue =
+ modest_runtime_get_send_queue (TNY_TRANSPORT_ACCOUNT(acc), TRUE);
+ gchar *queue_str = modest_tny_send_queue_to_string (sendqueue);
+
+ tmp = g_strdup_printf ("%s[%s]: '%s': %s\n%s",
+ str, accname, tny_account_get_id (acc), url,
+ queue_str);
+ g_free(queue_str);
+ g_free (url);
+ g_free (str);
+ str = tmp;
+
+ g_object_unref (acc);
+ }
+
+ cursor = g_slist_next (cursor);
+ }
+ modest_account_mgr_free_account_names (account_names);
+
+ g_printerr (str);
+
+ reply = dbus_message_new_method_return (message);
+ if (reply) {
+ dbus_message_append_args (reply,
+ DBUS_TYPE_STRING, &str,
+ DBUS_TYPE_INVALID);
+ dbus_connection_send (con, reply, &serial);
+ dbus_connection_flush (con);
+ dbus_message_unref (reply);
+ }
+ g_free (str);
+
+ /* Let modest die */
+ g_idle_add (notify_error_in_dbus_callback, NULL);
+
+ return OSSO_OK;
+}
+
+
+static gint
+on_dbus_method_dump_operation_queue (DBusConnection *con, DBusMessage *message)
+{
+ gchar *str;
+ gchar *op_queue_str;
+
+ DBusMessage *reply;
+ dbus_uint32_t serial = 0;
+
+ /* operations queue; */
+ op_queue_str = modest_mail_operation_queue_to_string
+ (modest_runtime_get_mail_operation_queue ());
+
+ str = g_strdup_printf ("\noperation queue\n"
+ "===============\n"
+ "status: %s\n"
+ "%s\n",
+ tny_device_is_online (modest_runtime_get_device ()) ? "online" : "offline",
+ op_queue_str);
+ g_free (op_queue_str);
+
+ g_printerr (str);
+
+ reply = dbus_message_new_method_return (message);
+ if (reply) {
+ dbus_message_append_args (reply,
+ DBUS_TYPE_STRING, &str,
+ DBUS_TYPE_INVALID);
+ dbus_connection_send (con, reply, &serial);
+ dbus_connection_flush (con);
+ dbus_message_unref (reply);
+ }
+ g_free (str);
+
+ /* Let modest die */
+ g_idle_add (notify_error_in_dbus_callback, NULL);
+
+ return OSSO_OK;
+}
+
+
+
+static gint
+on_dbus_method_dump_accounts (DBusConnection *con, DBusMessage *message)
+{
+ gchar *str;
+
+ DBusMessage *reply;
+ dbus_uint32_t serial = 0;
+
+ GSList *account_names, *cursor;
+
+ str = g_strdup ("\naccounts\n========\n");
+
+ cursor = account_names = modest_account_mgr_account_names
+ (modest_runtime_get_account_mgr(), TRUE); /* only enabled accounts */
+
+ while (cursor) {
+ TnyAccount *acc;
+ gchar *tmp, *accname = (gchar*)cursor->data;
+
+ tmp = g_strdup_printf ("%s[%s]\n", str, accname);
+ g_free (str);
+ str = tmp;
+
+ /* store */
+ acc = modest_tny_account_store_get_server_account (
+ modest_runtime_get_account_store(), accname,
+ TNY_ACCOUNT_TYPE_STORE);
+ if (TNY_IS_ACCOUNT(acc)) {
+ gchar *tmp, *url = tny_account_get_url_string (acc);
+ tmp = g_strdup_printf ("%sstore : '%s': %s (refs: %d)\n",
+ str, tny_account_get_id (acc), url,
+ ((GObject*)acc)->ref_count-1);
+ g_free (str);
+ str = tmp;
+ g_free (url);
+ g_object_unref (acc);
+ }
+
+ /* transport */
+ acc = modest_tny_account_store_get_server_account (
+ modest_runtime_get_account_store(), accname,
+ TNY_ACCOUNT_TYPE_TRANSPORT);
+ if (TNY_IS_ACCOUNT(acc)) {
+ gchar *tmp, *url = tny_account_get_url_string (acc);
+ tmp = g_strdup_printf ("%stransport: '%s': %s (refs: %d)\n",
+ str, tny_account_get_id (acc), url,
+ ((GObject*)acc)->ref_count-1);
+ g_free (str);
+ str = tmp;
+ g_free (url);
+ g_object_unref (acc);
+ }
+
+ cursor = g_slist_next (cursor);
+ }
+
+ modest_account_mgr_free_account_names (account_names);
+
+ g_printerr (str);
+
+ reply = dbus_message_new_method_return (message);
+ if (reply) {
+ dbus_message_append_args (reply,
+ DBUS_TYPE_STRING, &str,
+ DBUS_TYPE_INVALID);
+ dbus_connection_send (con, reply, &serial);
+ dbus_connection_flush (con);
+ dbus_message_unref (reply);
+ }
+ g_free (str);
+
+ /* Let modest die */
+ g_idle_add (notify_error_in_dbus_callback, NULL);
+
+ return OSSO_OK;
+}
+
+static void
+on_send_receive_performer(gboolean canceled,
+ GError *err,
+ GtkWindow *parent_window,
+ TnyAccount *account,
+ gpointer user_data)
+{
+ ModestConnectedVia connect_when;
+
+ if (err || canceled) {
+ g_idle_add (notify_error_in_dbus_callback, NULL);
+ return;
+ }
+
+ connect_when = modest_conf_get_int (modest_runtime_get_conf (),
+ MODEST_CONF_UPDATE_WHEN_CONNECTED_BY, NULL);
+
+ /* Perform a send and receive if the user selected to connect
+ via any mean or if the current connection method is the
+ same as the one specified by the user */
+ if (connect_when == MODEST_CONNECTED_VIA_ANY ||
+ connect_when == modest_platform_get_current_connection ()) {
+ g_idle_add (on_idle_send_receive, NULL);
+ } else {
+ /* We need this to allow modest to finish */
+ g_idle_add (notify_error_in_dbus_callback, NULL);
+ }
+}
+
+
+static gint
+on_send_receive(GArray *arguments, gpointer data, osso_rpc_t * retval)