From 8927fc9555dbba94b338cc3a600f183a32e61b74 Mon Sep 17 00:00:00 2001 From: Sergio Villar Senin Date: Mon, 19 Oct 2009 16:57:54 +0200 Subject: [PATCH 1/1] Fixes NB#143352, add a DBus API to request inmmediate Send&Receive (like manual send&receive) --- configure.ac | 3 +- debian/control | 17 ++-- libmodest-dbus-client/configure.ac | 4 +- libmodest-dbus-client/debian/changelog | 9 +- libmodest-dbus-client/src/libmodest-dbus-api.h | 8 ++ .../src/libmodest-dbus-client-1.0.pc.in | 2 +- libmodest-dbus-client/src/libmodest-dbus-client.c | 25 +++++ libmodest-dbus-client/src/libmodest-dbus-client.h | 30 +++++- src/dbus_api/modest-dbus-callbacks.c | 96 +++++++++++++++++--- tests/dbus_api/test_update_account.c | 31 ++++++- 10 files changed, 197 insertions(+), 28 deletions(-) diff --git a/configure.ac b/configure.ac index c86a333..ff00998 100644 --- a/configure.ac +++ b/configure.ac @@ -120,7 +120,8 @@ else AC_MSG_ERROR([install gtkhtml 3.8 or newer]) fi - +PKG_CHECK_MODULES(LIBMODEST_DBUS_CLIENT,libmodest-dbus-client-1.0 >= 3.1.0) +re.ac dnl # GLib/Gobject/Gtk/Gconf => mandatory PKG_CHECK_MODULES(MODEST_GSTUFF,glib-2.0 >= 2.6 gobject-2.0 gtk+-2.0 >= 2.6 gconf-2.0 gnome-vfs-2.0 libgtkhtml-${gtk_html_version} libtinymail-1.0 libtinymail-camel-1.0 libtinymail-gnomevfs-1.0 libtinymailui-1.0 libtinymailui-gtk-1.0) diff --git a/debian/control b/debian/control index 545a5e2..e67d69e 100644 --- a/debian/control +++ b/debian/control @@ -2,18 +2,19 @@ Source: modest Section: mail Priority: optional Maintainer: Moises Martinez -Build-Depends: debhelper (>= 4.0.0), cdbs, libmodest-dbus-client-dev, gnome-common, gtkhtml3.14-dev, libconic0-dev, libhildon1-dev, libdbus-1-dev, - libdbus-glib-1-dev, libebook-dev, osso-af-settings, libedataserver-dev, libhildonnotify-dev, libgconf2-dev, - libglib2.0-dev, libosso-gnomevfs2-dev, libhildonmime-dev, libtinymail-1.0-0-dev, libtinymail-camel-1.0-0-dev, - libtinymail-maemo-1.0-0-dev, libtinymailui-1.0-0-dev, libtinymail-gnomevfs-1.0-0-dev, libtinymailui-gtk-1.0-0-dev, wpeditor0, - wpeditor-dev, modest-providers-data | maemo-providers-data, libalarm-dev, gtk-doc-tools, libhildonnotify-dev, libnotify-dev, - microb-engine-dev, mce-dev, maemo-launcher-dev, libhildonfm2-dev +Build-Depends: debhelper (>= 4.0.0), cdbs, libmodest-dbus-client-dev (>= 3.1.0), gnome-common, gtkhtml3.14-dev, + libconic0-dev, libhildon1-dev, libdbus-1-dev, libdbus-glib-1-dev, libebook-dev, osso-af-settings, libedataserver-dev, + libhildonnotify-dev, libgconf2-dev, libglib2.0-dev, libosso-gnomevfs2-dev, libhildonmime-dev, libtinymail-1.0-0-dev, + libtinymail-camel-1.0-0-dev, libtinymail-maemo-1.0-0-dev, libtinymailui-1.0-0-dev, libtinymail-gnomevfs-1.0-0-dev, + libtinymailui-gtk-1.0-0-dev, wpeditor0, wpeditor-dev, modest-providers-data | maemo-providers-data, libalarm-dev, + gtk-doc-tools, libhildonnotify-dev, libnotify-dev, microb-engine-dev, mce-dev, maemo-launcher-dev, libhildonfm2-dev Standards-Version: 3.6.0 Package: modest Architecture: any -Depends: ${shlibs:Depends}, ${misc:Depends}, ${launcher:Depends}, libmodest-dbus-client, modest-providers-data, modest-l10n-mr | modest-l10n-mr0, - osso-icons-theme, operator-wizard-settings, osso-countries-l10n-mr | osso-countries-l10n-mr0, microb-engine +Depends: ${shlibs:Depends}, ${misc:Depends}, ${launcher:Depends}, libmodest-dbus-client (>= 3.1.0), + modest-providers-data, modest-l10n-mr | modest-l10n-mr0, osso-icons-theme, operator-wizard-settings, + osso-countries-l10n-mr | osso-countries-l10n-mr0, microb-engine Description: an e-mail client for platforms with modest resources e-mail client for osso diff --git a/libmodest-dbus-client/configure.ac b/libmodest-dbus-client/configure.ac index db54332..c2ff6fb 100644 --- a/libmodest-dbus-client/configure.ac +++ b/libmodest-dbus-client/configure.ac @@ -26,12 +26,12 @@ # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -AC_INIT([modest],[3.0],[http://maemo.org]) +AC_INIT([libmodestclient],[3.1.0],[http://maemo.org]) AC_CONFIG_HEADERS([config.h]) m4_define([modest_api_major_version], [1]) m4_define([modest_api_minor_version], [99]) -m4_define([modest_api_micro_version], [0]) +m4_define([modest_api_micro_version], [1]) m4_define([modest_api_version], [modest_api_major_version.modest_api_minor_version.modest_api_micro_version]) diff --git a/libmodest-dbus-client/debian/changelog b/libmodest-dbus-client/debian/changelog index f0ac5b3..4d9fe0c 100644 --- a/libmodest-dbus-client/debian/changelog +++ b/libmodest-dbus-client/debian/changelog @@ -1,4 +1,11 @@ -libmodest-dbus-client (3.0.17-rc33) unstable; urgency=low +libmodest-dbus-client (4:3.1.0-0) unstable; urgency=low + + * Week 42, 2009 - second release + * Add API method SendReceiveFull + + -- Moises Martinez Wed, 16 Oct 2009 11:18:00 +0200 + +libmodest-dbus-client (4:1.0.0-2) unstable; urgency=low * Initial import diff --git a/libmodest-dbus-client/src/libmodest-dbus-api.h b/libmodest-dbus-client/src/libmodest-dbus-api.h index 0f84496..86159d0 100644 --- a/libmodest-dbus-client/src/libmodest-dbus-api.h +++ b/libmodest-dbus-client/src/libmodest-dbus-api.h @@ -64,6 +64,14 @@ enum ModestDbusOpenAccountArguments #define MODEST_DBUS_METHOD_SEND_RECEIVE "SendReceive" +#define MODEST_DBUS_METHOD_SEND_RECEIVE_FULL "SendReceiveFull" +enum ModestDbusSendReceiveFullArguments +{ + MODEST_DBUS_SEND_RECEIVE_FULL_ARG_ACCOUNT_ID, + MODEST_DBUS_SEND_RECEIVE_FULL_ARG_MANUAL, + MODEST_DBUS_SEND_RECEIVE_FULL_ARGS_COUNT +}; + #define MODEST_DBUS_METHOD_COMPOSE_MAIL "ComposeMail" enum ModestDbusComposeMailArguments { diff --git a/libmodest-dbus-client/src/libmodest-dbus-client-1.0.pc.in b/libmodest-dbus-client/src/libmodest-dbus-client-1.0.pc.in index 930b644..c11ea8b 100644 --- a/libmodest-dbus-client/src/libmodest-dbus-client-1.0.pc.in +++ b/libmodest-dbus-client/src/libmodest-dbus-client-1.0.pc.in @@ -5,7 +5,7 @@ includedir=@includedir@ Name: libmodest-dbus-client-1.0 Description: Some library. -Requires: glib-2.0 dbus-1 +Requires: glib-2.0 dbus-1 libosso Version: @VERSION@ Libs: -L${libdir} -lmodest-dbus-client-1.0 Cflags: -I${includedir}/libmodest-dbus-client-1.0 diff --git a/libmodest-dbus-client/src/libmodest-dbus-client.c b/libmodest-dbus-client/src/libmodest-dbus-client.c index 43f5c9e..88ac781 100644 --- a/libmodest-dbus-client/src/libmodest-dbus-client.c +++ b/libmodest-dbus-client/src/libmodest-dbus-client.c @@ -205,6 +205,31 @@ libmodest_dbus_client_send_and_receive (osso_context_t *osso_context) } gboolean +libmodest_dbus_client_send_and_receive_full (osso_context_t *osso_context, + const gchar *account, + gboolean manual) +{ + osso_rpc_t retval = { 0 }; + const osso_return_t ret = osso_rpc_run_with_defaults(osso_context, + MODEST_DBUS_NAME, + MODEST_DBUS_METHOD_SEND_RECEIVE_FULL, &retval, + DBUS_TYPE_STRING, account, + DBUS_TYPE_BOOLEAN, manual, + DBUS_TYPE_INVALID); + + if (ret != OSSO_OK) { + printf("debug: %s: osso_rpc_run() failed.\n", __FUNCTION__); + return FALSE; + } else { + printf("debug: %s: osso_rpc_run() succeeded.\n", __FUNCTION__); + } + + osso_rpc_free_val(&retval); + + return TRUE; +} + +gboolean libmodest_dbus_client_open_default_inbox (osso_context_t *osso_context) { osso_rpc_t retval = { 0 }; diff --git a/libmodest-dbus-client/src/libmodest-dbus-client.h b/libmodest-dbus-client/src/libmodest-dbus-client.h index 03ac5d8..e0aa53a 100644 --- a/libmodest-dbus-client/src/libmodest-dbus-client.h +++ b/libmodest-dbus-client/src/libmodest-dbus-client.h @@ -87,15 +87,41 @@ gboolean libmodest_dbus_client_open_message (osso_context_t *osso_context, * libmodest_dbus_client_send_and_receive: * @osso_context: a valid osso_context instance * - * send/receive messages + * send/receive messages automatically for all accounts. This is equivalent + * to the call + * libmodest_dbus_client_send_and_receive_full (@osso_context, %NULL, %TRUE) * - * Returns: TRUE upon success, FALSE otherwise + * Returns: %TRUE upon success, %FALSE otherwise */ gboolean libmodest_dbus_client_send_and_receive (osso_context_t *osso_context); /** + * libmodest_dbus_client_send_and_receive_full: + * @osso_context: a valid osso_context instance + * @account: the account name, or %NULL to do a send receive on all accounts. + * @manual: a #gboolean + * + * send/receive messages. If @manual is %TRUE, the send receive request + * will start immediately. If @manual if %FALSE, it may wait for IP heartbeat + * if enabled. + * + * If Modest is built without heartbeat support, then the result of the call + * will be the same independently of @manual value (always immediate start). + * + * The call will apply to @account only, unless @account is %NULL, that means + * send receive will be performed on all accounts. + * + * Returns: %TRUE upon success, %FALSE otherwise + */ +gboolean libmodest_dbus_client_send_and_receive_full (osso_context_t *osso_context, + const gchar *account, + gboolean manual); + + + +/** * libmodest_dbus_client_open_default_inbox: * @osso_context: a valid osso_context instance * diff --git a/src/dbus_api/modest-dbus-callbacks.c b/src/dbus_api/modest-dbus-callbacks.c index 64bca8e..7450644 100644 --- a/src/dbus_api/modest-dbus-callbacks.c +++ b/src/dbus_api/modest-dbus-callbacks.c @@ -922,13 +922,28 @@ on_delete_message (GArray *arguments, gpointer data, osso_rpc_t *retval) return OSSO_OK; } +typedef struct _SendReceivePerformerData { + gchar *account_id; + gboolean manual; + ModestMailOperation *mail_op; +} SendReceivePerformerData; + +static void send_receive_performer_data_free (SendReceivePerformerData *data) +{ + if (data->mail_op) { + g_object_unref (data->mail_op); + } + g_free (data->account_id); + g_slice_free (SendReceivePerformerData, data); +} + static gboolean on_idle_send_receive(gpointer user_data) { gboolean auto_update; - ModestMailOperation *mail_op = (ModestMailOperation *) user_data; + SendReceivePerformerData *data = (SendReceivePerformerData *) user_data; ModestConnectedVia connect_when; - + gboolean right_connection = FALSE; gdk_threads_enter (); /* CHECKED */ @@ -948,17 +963,25 @@ on_idle_send_receive(gpointer user_data) same as the one specified by the user */ if (connect_when == MODEST_CONNECTED_VIA_ANY || connect_when == modest_platform_get_current_connection ()) { - modest_ui_actions_do_send_receive_all (NULL, FALSE, FALSE, FALSE); + right_connection = TRUE; } } else { /* Disable auto update */ modest_platform_set_update_interval (0); } + if ((auto_update && right_connection) || data->manual) { + if (data->account_id) { + modest_ui_actions_do_send_receive (data->account_id, data->manual, FALSE, data->manual, NULL); + } else { + modest_ui_actions_do_send_receive_all (NULL, data->manual, FALSE, data->manual); + } + } + modest_mail_operation_queue_remove (modest_runtime_get_mail_operation_queue (), - mail_op); + data->mail_op); - g_object_unref (mail_op); + send_receive_performer_data_free (data); gdk_threads_leave (); /* CHECKED */ @@ -1165,17 +1188,24 @@ on_send_receive_performer(gboolean canceled, TnyAccount *account, gpointer user_data) { - ModestMailOperation *mail_op; + SendReceivePerformerData *data = (SendReceivePerformerData *) user_data; - if (err || canceled) { + if (err || canceled || data == NULL) { g_idle_add (notify_error_in_dbus_callback, NULL); + if (data) { + send_receive_performer_data_free (data); + } return; } - mail_op = modest_mail_operation_new (NULL); + data->mail_op = modest_mail_operation_new (NULL); modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), - mail_op); - modest_heartbeat_add (on_idle_send_receive, mail_op); + data->mail_op); + if (data->manual) { + g_idle_add (on_idle_send_receive, data); + } else { + modest_heartbeat_add (on_idle_send_receive, data); + } } @@ -1183,11 +1213,49 @@ static gint on_send_receive(GArray *arguments, gpointer data, osso_rpc_t * retval) { TnyDevice *device = modest_runtime_get_device (); + SendReceivePerformerData *srp_data; + + srp_data = g_slice_new0 (SendReceivePerformerData); + srp_data->account_id = NULL; + srp_data->manual = FALSE; + srp_data->mail_op = NULL; if (!tny_device_is_online (device)) - modest_platform_connect_and_perform (NULL, FALSE, NULL, on_send_receive_performer, NULL); + modest_platform_connect_and_perform (NULL, FALSE, NULL, on_send_receive_performer, srp_data); else - on_send_receive_performer (FALSE, NULL, NULL, NULL, NULL); + on_send_receive_performer (FALSE, NULL, NULL, NULL, srp_data); + + return OSSO_OK; +} + +static gint +on_send_receive_full (GArray *arguments, gpointer data, osso_rpc_t * retval) +{ + osso_rpc_t val; + gchar *account_id; + gboolean manual; + TnyDevice *device; + SendReceivePerformerData *srp_data; + + val = g_array_index (arguments, osso_rpc_t, MODEST_DBUS_SEND_RECEIVE_FULL_ARG_ACCOUNT_ID); + account_id = g_strdup (val.value.s); + val = g_array_index (arguments, osso_rpc_t, MODEST_DBUS_SEND_RECEIVE_FULL_ARG_MANUAL); + manual = val.value.b; + + srp_data = g_slice_new0 (SendReceivePerformerData); + srp_data->manual = manual; + if (account_id && account_id[0] != '\0') { + srp_data->account_id = account_id; + } else { + srp_data->account_id = NULL; + g_free (account_id); + } + srp_data->mail_op = NULL; + device = modest_runtime_get_device (); + if (!tny_device_is_online (device)) + modest_platform_connect_and_perform (NULL, FALSE, NULL, on_send_receive_performer, srp_data); + else + on_send_receive_performer (FALSE, NULL, NULL, NULL, srp_data); return OSSO_OK; } @@ -1431,6 +1499,10 @@ modest_dbus_req_handler(const gchar * interface, const gchar * method, if (arguments->len != 0) goto param_error; return on_send_receive (arguments, data, retval); + } else if (g_ascii_strcasecmp (method, MODEST_DBUS_METHOD_SEND_RECEIVE_FULL) == 0) { + if (arguments->len != MODEST_DBUS_SEND_RECEIVE_FULL_ARGS_COUNT) + goto param_error; + return on_send_receive_full (arguments, data, retval); } else if (g_ascii_strcasecmp (method, MODEST_DBUS_METHOD_COMPOSE_MAIL) == 0) { if (arguments->len != MODEST_DBUS_COMPOSE_MAIL_ARGS_COUNT) goto param_error; diff --git a/tests/dbus_api/test_update_account.c b/tests/dbus_api/test_update_account.c index 29c62fe..96f57a8 100644 --- a/tests/dbus_api/test_update_account.c +++ b/tests/dbus_api/test_update_account.c @@ -1,11 +1,36 @@ #include #include #include +#include +#include + +static gboolean manual = FALSE; +static gchar *account_id = NULL; + +static GOptionEntry option_entries [] = +{ + { "manual", 'm', 0, G_OPTION_ARG_NONE, &manual, "Manual send receive, so behave as interactive.", NULL }, + { "account", 'a', 0, G_OPTION_ARG_STRING, &account_id, "Account to perform send receive into", NULL }, + { NULL } +}; + int main (int argc, char *argv[]) { osso_context_t *osso_context; + GOptionContext *context; + gboolean result; + GError *error = NULL; + + context = g_option_context_new ("- Modest email client"); + g_option_context_add_main_entries (context, option_entries, NULL); + if (!g_option_context_parse (context, &argc, &argv, &error)) { + g_print ("option parsing failed: %s\n", error->message); + g_option_context_free (context); + exit (1); + } + g_option_context_free (context); osso_context = osso_initialize ("test_update_account", "0.0.1", @@ -17,5 +42,9 @@ main (int argc, char *argv[]) return -1; } - return libmodest_dbus_client_send_and_receive (osso_context); + result = libmodest_dbus_client_send_and_receive_full (osso_context, account_id, manual); + g_free (account_id); + + return result; + } -- 1.7.9.5