2007-05-03 Murray Cumming <murrayc@murrayc.com>
authorMurray Cumming <murrayc@murrayc.com>
Thu, 3 May 2007 09:58:39 +0000 (09:58 +0000)
committerMurray Cumming <murrayc@murrayc.com>
Thu, 3 May 2007 09:58:39 +0000 (09:58 +0000)
* 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

ChangeLog2
configure.ac
libmodest-dbus-client/libmodest-dbus-client.c
libmodest-dbus-client/libmodest-dbus-client.h
src/dbus_api/modest-dbus-api.h
src/dbus_api/modest-dbus-callbacks.c
src/gnome/modest-platform.c
src/maemo/modest-platform.c
src/modest-platform.h

index 880d60b..296f1e9 100644 (file)
@@ -1,3 +1,27 @@
+2007-05-03  Murray Cumming  <murrayc@murrayc.com>
+
+       * 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  <murrayc@murrayc.com>
 
        * src/dbus_api/modest-dbus-callbacks.c:
 2007-05-02  Murray Cumming  <murrayc@murrayc.com>
 
        * src/dbus_api/modest-dbus-callbacks.c:
index dfd783c..628cbab 100644 (file)
@@ -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(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
    
     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         
    
         AC_DEFINE_UNQUOTED(MODEST_HILDON_VERSION_0, 1, ["The Hildon version we support."])   
     fi         
    
index 55e03c3..7108838 100644 (file)
@@ -101,4 +101,25 @@ libmodest_dbus_client_open_message (osso_context_t *osso_context, const gchar *m
        return TRUE;
 }
 
        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;
+}
+
 
 
index dd75681..7d3eaa1 100644 (file)
 #include <stdio.h>
 
 gboolean
 #include <stdio.h>
 
 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 
        
 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 
 
 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__ */
 
 #endif /* __LIBMODEST_DBUS_CLIENT_H__ */
index 8381d71..76ea882 100644 (file)
@@ -66,5 +66,7 @@ enum ModestDbusOpenMessageArguments
        MODEST_DEBUS_OPEN_MESSAGE_ARGS_COUNT
 };
 
        MODEST_DEBUS_OPEN_MESSAGE_ARGS_COUNT
 };
 
+#define MODEST_DBUS_METHOD_SEND_RECEIVE "SendReceive"
+
 #endif /* __MODEST_DBUS_API__ */
 
 #endif /* __MODEST_DBUS_API__ */
 
index ab7e1d8..044978b 100644 (file)
@@ -32,6 +32,7 @@
 #include "modest-account-mgr.h"
 #include "modest-account-mgr-helpers.h"
 #include "modest-tny-account.h"
 #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 <libgnomevfs/gnome-vfs-utils.h>
 #include "widgets/modest-msg-edit-window.h"
 #include "modest-tny-msg.h"
 #include <libgnomevfs/gnome-vfs-utils.h>
@@ -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;
 }
         * 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,
                       
 /* 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);
                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;
        }
        else
                return OSSO_ERROR;
index 462c422..9b80c90 100644 (file)
@@ -192,3 +192,8 @@ gboolean modest_platform_connect_and_wait (GtkWindow *parent_window)
        return TRUE;
 }
 
        return TRUE;
 }
 
+gboolean modest_platform_set_update_interval (guint minutes)
+{
+       /* TODO. */
+}
+
index b286c8f..691da5d 100644 (file)
@@ -38,6 +38,7 @@
 
 #include <dbus_api/modest-dbus-callbacks.h>
 #include <libosso.h>
 
 #include <dbus_api/modest-dbus-callbacks.h>
 #include <libosso.h>
+#include <alarmd/alarm_event.h> /* For alarm_event_add(), etc. */
 #include <tny-maemo-conic-device.h>
 #include <tny-folder.h>
 #include <gtk/gtkicontheme.h>
 #include <tny-maemo-conic-device.h>
 #include <tny-folder.h>
 #include <gtk/gtkicontheme.h>
@@ -45,6 +46,8 @@
 #include <gtk/gtkmain.h>
 #include <string.h>
 
 #include <gtk/gtkmain.h>
 #include <string.h>
 
+static cookie_t alarm_cookie = 0;
+
 gboolean
 modest_platform_init (void)
 {      
 gboolean
 modest_platform_init (void)
 {      
@@ -67,9 +70,6 @@ modest_platform_init (void)
                        return OSSO_ERROR;
        }
 
                        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,
        /* 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;
 }
 
        return TRUE;
 }
 
@@ -630,3 +639,57 @@ modest_platform_run_sort_dialog (GtkWindow *parent_window,
        /* Free */
        gtk_widget_destroy (GTK_WIDGET (dialog));
 }
        /* 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;
+}
+
index ded8eea..d42bdbc 100644 (file)
@@ -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.
 /*
  * 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.
  * 
  * 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);
 
  */            
 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__ */
 G_END_DECLS
 
 #endif /* __MODEST_PLATFORM_UTILS_H__ */