From: Murray Cumming Date: Thu, 3 May 2007 09:58:39 +0000 (+0000) Subject: 2007-05-03 Murray Cumming X-Git-Tag: git_migration_finished~3719 X-Git-Url: http://git.maemo.org/git/?p=modest;a=commitdiff_plain;h=56fd99766e8082e2f9e34c50d209b8410cf1fbf8;ds=sidebyside 2007-05-03 Murray Cumming * configure.ac: Depend on libalarm for Maemo. * src/dbus_api/modest-dbus-api.h: * src/dbus_api/modest-dbus-callbacks.c: (on_idle_send_receive), (on_send_receive), (modest_dbus_req_handler): Handle a SEND_RECEIVE D-Bus method. * libmodest-dbus-client/libmodest-dbus-client.c: (libmodest_dbus_client_send_and_receive): * libmodest-dbus-client/libmodest-dbus-client.h: Add C convenience functions for calling the new D-Bus method. * src/modest-platform.h: * src/gnome/modest-platform.c: * src/maemo/modest-platform.c: Added modest_platform_set_update_interval(), which uses the alarmd API on Maemo. (modest_platform_init), Call modest_platform_set_update_interval(), using a hard-coded interval for now (until the global settings dialog is implemented), though I am not sure that this makes sense yet. pmo-trunk-r1742 --- diff --git a/ChangeLog2 b/ChangeLog2 index 880d60b..296f1e9 100644 --- a/ChangeLog2 +++ b/ChangeLog2 @@ -1,3 +1,27 @@ +2007-05-03 Murray Cumming + + * configure.ac: Depend on libalarm for Maemo. + + * src/dbus_api/modest-dbus-api.h: + * src/dbus_api/modest-dbus-callbacks.c: (on_idle_send_receive), + (on_send_receive), (modest_dbus_req_handler): + Handle a SEND_RECEIVE D-Bus method. + + * libmodest-dbus-client/libmodest-dbus-client.c: + (libmodest_dbus_client_send_and_receive): + * libmodest-dbus-client/libmodest-dbus-client.h: + Add C convenience functions for calling the new D-Bus method. + + * src/modest-platform.h: + * src/gnome/modest-platform.c: + * src/maemo/modest-platform.c: + Added modest_platform_set_update_interval(), which uses the + alarmd API on Maemo. + (modest_platform_init), + Call modest_platform_set_update_interval(), using a hard-coded + interval for now (until the global settings dialog is implemented), + though I am not sure that this makes sense yet. + 2007-05-02 Murray Cumming * src/dbus_api/modest-dbus-callbacks.c: diff --git a/configure.ac b/configure.ac index dfd783c..628cbab 100644 --- a/configure.ac +++ b/configure.ac @@ -92,10 +92,10 @@ if test "x$with_platform" = "xmaemo"; then PKG_CHECK_MODULES(HILDON, hildon-1 >= 0.9.9, hildon1=yes, hildon1=no) if test "$hildon1" == "yes"; then # the 'new' hildon - PKG_CHECK_MODULES(MODEST_LIBTINYMAIL_MAEMO, conic libtinymail-maemo-1.0 hildon-1 libosso libhildonmime osso-addressbook-1.0 wpeditor libossohelp libebook-1.2) + PKG_CHECK_MODULES(MODEST_LIBTINYMAIL_MAEMO, conic libtinymail-maemo-1.0 hildon-1 libosso libhildonmime osso-addressbook-1.0 wpeditor libossohelp libebook-1.2 libalarm) else # the old hildon - PKG_CHECK_MODULES(MODEST_LIBTINYMAIL_MAEMO, conic libtinymail-maemo-1.0 hildon-libs >= 0.12.0 libosso libossomime libossohelp osso-addressbook-1.0 wpeditor libebook-1.2) + PKG_CHECK_MODULES(MODEST_LIBTINYMAIL_MAEMO, conic libtinymail-maemo-1.0 hildon-libs >= 0.12.0 libosso libossomime libossohelp osso-addressbook-1.0 wpeditor libebook-1.2 libalarm) AC_DEFINE_UNQUOTED(MODEST_HILDON_VERSION_0, 1, ["The Hildon version we support."]) fi diff --git a/libmodest-dbus-client/libmodest-dbus-client.c b/libmodest-dbus-client/libmodest-dbus-client.c index 55e03c3..7108838 100644 --- a/libmodest-dbus-client/libmodest-dbus-client.c +++ b/libmodest-dbus-client/libmodest-dbus-client.c @@ -101,4 +101,25 @@ libmodest_dbus_client_open_message (osso_context_t *osso_context, const gchar *m return TRUE; } +gboolean +libmodest_dbus_client_send_and_receive (osso_context_t *osso_context) +{ + osso_rpc_t retval; + const osso_return_t ret = osso_rpc_run_with_defaults(osso_context, + MODEST_DBUS_NAME, + MODEST_DBUS_METHOD_SEND_RECEIVE, &retval, + DBUS_TYPE_INVALID); + + if (ret != OSSO_OK) { + printf("debug: osso_rpc_run() failed.\n"); + return FALSE; + } else { + printf("debug: osso_rpc_run() succeeded.\n"); + } + + osso_rpc_free_val(&retval); + + return TRUE; +} + diff --git a/libmodest-dbus-client/libmodest-dbus-client.h b/libmodest-dbus-client/libmodest-dbus-client.h index dd75681..7d3eaa1 100644 --- a/libmodest-dbus-client/libmodest-dbus-client.h +++ b/libmodest-dbus-client/libmodest-dbus-client.h @@ -35,13 +35,19 @@ #include gboolean -libmodest_dbus_client_send_mail (osso_context_t *osso_context, const gchar *to, const gchar *cc, - const gchar *bcc, const gchar* subject, const gchar* body, GSList *attachments); +libmodest_dbus_client_send_mail (osso_context_t *osso_context, const gchar *to, + const gchar *cc, const gchar *bcc, const gchar* subject, const gchar* body, + GSList *attachments); gboolean -libmodest_dbus_client_mail_to (osso_context_t *osso_context, const gchar *mailto_uri); +libmodest_dbus_client_mail_to (osso_context_t *osso_context, + const gchar *mailto_uri); gboolean -libmodest_dbus_client_open_message (osso_context_t *osso_context, const gchar *mail_uri); +libmodest_dbus_client_open_message (osso_context_t *osso_context, + const gchar *mail_uri); + +gboolean +libmodest_dbus_client_send_and_receive (osso_context_t *osso_context); #endif /* __LIBMODEST_DBUS_CLIENT_H__ */ diff --git a/src/dbus_api/modest-dbus-api.h b/src/dbus_api/modest-dbus-api.h index 8381d71..76ea882 100644 --- a/src/dbus_api/modest-dbus-api.h +++ b/src/dbus_api/modest-dbus-api.h @@ -66,5 +66,7 @@ enum ModestDbusOpenMessageArguments MODEST_DEBUS_OPEN_MESSAGE_ARGS_COUNT }; +#define MODEST_DBUS_METHOD_SEND_RECEIVE "SendReceive" + #endif /* __MODEST_DBUS_API__ */ diff --git a/src/dbus_api/modest-dbus-callbacks.c b/src/dbus_api/modest-dbus-callbacks.c index ab7e1d8..044978b 100644 --- a/src/dbus_api/modest-dbus-callbacks.c +++ b/src/dbus_api/modest-dbus-callbacks.c @@ -32,6 +32,7 @@ #include "modest-account-mgr.h" #include "modest-account-mgr-helpers.h" #include "modest-tny-account.h" +#include "modest-ui-actions.h" #include "widgets/modest-msg-edit-window.h" #include "modest-tny-msg.h" #include @@ -404,6 +405,30 @@ static gint on_open_message(GArray * arguments, gpointer data, osso_rpc_t * retv * because that would be asynchronous. */ return OSSO_OK; } + +static gboolean +on_idle_send_receive(gpointer user_data) +{ + ModestWindow* main_window = modest_window_mgr_get_main_window( + modest_runtime_get_window_mgr ()); + do_send_receive(main_window); + + return FALSE; /* Do not call this callback again. */ +} + +static gint on_send_receive(GArray * arguments, gpointer data, osso_rpc_t * retval) +{ + /* Use g_idle to context-switch into the application's thread: */ + + /* This method has no arguments. */ + + /* printf(" debug: to=%s\n", idle_data->to); */ + g_idle_add(on_idle_send_receive, 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, @@ -420,6 +445,8 @@ gint modest_dbus_req_handler(const gchar * interface, const gchar * method, return on_mail_to (arguments, data, retval); } else if (g_ascii_strcasecmp(method, MODEST_DBUS_METHOD_OPEN_MESSAGE) == 0) { return on_open_message (arguments, data, retval); + } else if (g_ascii_strcasecmp(method, MODEST_DBUS_METHOD_SEND_RECEIVE) == 0) { + return on_send_receive (arguments, data, retval); } else return OSSO_ERROR; diff --git a/src/gnome/modest-platform.c b/src/gnome/modest-platform.c index 462c422..9b80c90 100644 --- a/src/gnome/modest-platform.c +++ b/src/gnome/modest-platform.c @@ -192,3 +192,8 @@ gboolean modest_platform_connect_and_wait (GtkWindow *parent_window) return TRUE; } +gboolean modest_platform_set_update_interval (guint minutes) +{ + /* TODO. */ +} + diff --git a/src/maemo/modest-platform.c b/src/maemo/modest-platform.c index b286c8f..691da5d 100644 --- a/src/maemo/modest-platform.c +++ b/src/maemo/modest-platform.c @@ -38,6 +38,7 @@ #include #include +#include /* For alarm_event_add(), etc. */ #include #include #include @@ -45,6 +46,8 @@ #include #include +static cookie_t alarm_cookie = 0; + gboolean modest_platform_init (void) { @@ -67,9 +70,6 @@ modest_platform_init (void) return OSSO_ERROR; } - /* Register hardware event dbus callback: */ - osso_hw_set_event_cb(osso_context, NULL, modest_osso_cb_hw_state_handler, NULL); - /* Add handler for Exit D-BUS messages. * Not used because osso_application_set_exit_cb() is deprecated and obsolete: result = osso_application_set_exit_cb(osso_context, @@ -81,6 +81,15 @@ modest_platform_init (void) } */ + /* Register hardware event dbus callback: */ + osso_hw_set_event_cb(osso_context, NULL, modest_osso_cb_hw_state_handler, NULL); + + /* TODO: Get the actual update interval from gconf, + * when that preferences dialog has been implemented. + * And make sure that this is called again whenever that is changed. */ + const guint update_interval_minutes = 15; + modest_platform_set_update_interval (update_interval_minutes); + return TRUE; } @@ -630,3 +639,57 @@ modest_platform_run_sort_dialog (GtkWindow *parent_window, /* Free */ gtk_widget_destroy (GTK_WIDGET (dialog)); } + + +gboolean modest_platform_set_update_interval (guint minutes) +{ + /* Delete any existing alarm, + * because we will replace it: */ + if (alarm_cookie) { + /* TODO: What does the alarm_event_del() return value mean? */ + alarm_event_del(alarm_cookie); + alarm_cookie = 0; + } + + /* 0 means no updates: */ + if (minutes == 0) + return TRUE; + + + /* Register alarm: */ + + /* Get current time: */ + time_t time_now; + time (&time_now); + struct tm *st_time = localtime (&time_now); + + /* Add minutes to tm_min field: */ + st_time->tm_min += minutes; + + /* Set the time in alarm_event_t structure: */ + alarm_event_t event; + memset (&event, 0, sizeof (alarm_event_t)); + event.alarm_time = mktime (st_time); + + /* Specify what should happen when the alarm happens: + * It should call this D-Bus method: */ + + /* Note: I am surpised that alarmd can't just use the modest.service file + * for this. murrayc. */ + event.dbus_path = g_strdup(PREFIX "/bin/modest"); + + event.dbus_interface = g_strdup (MODEST_DBUS_IFACE); + event.dbus_service = g_strdup (MODEST_DBUS_SERVICE); + event.dbus_name = g_strdup (MODEST_DBUS_METHOD_SEND_RECEIVE); + + alarm_cookie = alarm_event_add (&event); + + if (!alarm_cookie) { + /* Error */ + printf ("Error setting alarm event. Error code: '%d'\n", alarmd_get_error ()); + return FALSE; + } + + return TRUE; +} + diff --git a/src/modest-platform.h b/src/modest-platform.h index ded8eea..d42bdbc 100644 --- a/src/modest-platform.h +++ b/src/modest-platform.h @@ -178,7 +178,7 @@ void modest_platform_run_sort_dialog (GtkWindow *parent_window, /* * modest_platform_connect_and_wait: * @parent_window: the parent #GtkWindow for any interactive or progress feedback UI. - * @return value: Whether a connection was make. + * @return value: Whether a connection was made. * * Attempts to make a connection, possibly showing interactive UI to achieve this. * This will return TRUE immediately if a connection is already open. @@ -186,6 +186,15 @@ void modest_platform_run_sort_dialog (GtkWindow *parent_window, */ gboolean modest_platform_connect_and_wait (GtkWindow *parent_window); +/** + * modest_platform_set_update_interval: + * @minutes: The number of minutes between updates, or 0 for no updates. + * + * Set the number of minutes between automatic updates of email accounts. + * The platform will cause the send/receive action to happen repeatedly. + **/ +gboolean modest_platform_set_update_interval (guint minutes); + G_END_DECLS #endif /* __MODEST_PLATFORM_UTILS_H__ */