Fixes NB#143352, add a DBus API to request inmmediate Send&Receive (like manual send...
authorSergio Villar Senin <svillar@igalia.com>
Mon, 19 Oct 2009 14:57:54 +0000 (16:57 +0200)
committerSergio Villar Senin <svillar@igalia.com>
Mon, 19 Oct 2009 14:57:54 +0000 (16:57 +0200)
12 files changed:
configure.ac
debian/control
libmodest-dbus-client/configure.ac
libmodest-dbus-client/debian/changelog
libmodest-dbus-client/src/libmodest-dbus-api.h
libmodest-dbus-client/src/libmodest-dbus-client-1.0.pc.in
libmodest-dbus-client/src/libmodest-dbus-client.c
libmodest-dbus-client/src/libmodest-dbus-client.h
src/dbus_api/modest-dbus-callbacks.c
tests/dbus_api/Makefile.am
tests/dbus_api/test_top_application.c
tests/dbus_api/test_update_account.c

index 8466f94..0df4256 100644 (file)
@@ -120,7 +120,7 @@ else
 fi
 
 
-PKG_CHECK_MODULES(LIBMODEST_DBUS_CLIENT,libmodest-dbus-client-1.0) 
+PKG_CHECK_MODULES(LIBMODEST_DBUS_CLIENT,libmodest-dbus-client-1.0 >= 3.1.0)
 
 
 dnl # GLib/Gobject/Gtk/Gconf => mandatory
index 545a5e2..e67d69e 100644 (file)
@@ -2,18 +2,19 @@ Source: modest
 Section: mail
 Priority: optional
 Maintainer: Moises Martinez <moises.martinez@nokia.com>
-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
 
index f8c13ae..c2ff6fb 100644 (file)
 # 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.1],[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])
 
 
index c510bcb..6f247ff 100644 (file)
@@ -1,3 +1,10 @@
+libmodest-dbus-client (4:3.1.0-0) unstable; urgency=low
+
+  * Week 42, 2009 - second release
+  * Add API method SendReceiveFull
+
+ -- Moises Martinez <moises.martinez@nokia.com>  Wed, 16 Oct 2009 11:18:00 +0200
+
 libmodest-dbus-client (4:1.0.0-2) unstable; urgency=low
 
   * Week 42, 2009 - first release
index 0f84496..86159d0 100644 (file)
@@ -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
 {
index 930b644..c11ea8b 100644 (file)
@@ -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
index 43f5c9e..88ac781 100644 (file)
@@ -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 };
index 03ac5d8..e0aa53a 100644 (file)
@@ -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
  *
index 64bca8e..7450644 100644 (file)
@@ -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;
index acdd8bd..4f57bb8 100644 (file)
@@ -1,5 +1,6 @@
 INCLUDES=\
        @CHECK_CFLAGS@ \
+       $(LIBMODEST_DBUS_CLIENT_CFLAGS) \
        $(MODEST_GSTUFF_CFLAGS)\
        $(MODEST_LIBTINYMAIL_GNOME_DESKTOP_CFLAGS) \
        $(MODEST_LIBTINYMAIL_MAEMO_CFLAGS) \
@@ -11,6 +12,7 @@ INCLUDES=\
 
 objects=\
        @CHECK_LIBS@ \
+       $(LIBMODEST_DBUS_CLIENT_LIBS)
        $(MODEST_GSTUFF_LIBS) \
        $(MODEST_PLATFORM_LIBS) \
        $(MODEST_TOOLKIT_LIBS) \
index 7db8cc0..934cdce 100644 (file)
@@ -1,4 +1,4 @@
-#include <src/dbus_api/modest-dbus-api.h>
+#include <libmodest-dbus-client/libmodest-dbus-api.h>
 #include <libosso.h>
 #include <stdio.h>
 
index 1d9e1f2..ad9fe12 100644 (file)
@@ -1,10 +1,35 @@
 #include <libmodest-dbus-client/libmodest-dbus-client.h>
 #include <stdio.h>
+#include <stdlib.h>
+#include <glib.h>
+
+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",
@@ -16,5 +41,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;
+
 }