Set a timeout for prestarted mode (no shutdown before timeout finishes)
authorJose Dapena Paz <jdapena@igalia.com>
Mon, 25 May 2009 08:58:39 +0000 (10:58 +0200)
committerJose Dapena Paz <jdapena@igalia.com>
Mon, 25 May 2009 11:07:10 +0000 (13:07 +0200)
* src/modest-runtime.[ch]: added methods to access a boolean "allow_shutdown".
  Modest shutdown that happens on having empty window list and mail op queue
  will not happen if this is False.
* src/modest-main.c: only shutdown modest if allow_shutdown is false. Also
  set a timeout of 30 minutes (and allow CLI parameters to change this value).

src/modest-main.c
src/modest-runtime.c
src/modest-runtime.h

index 3640252..f7bdf96 100644 (file)
 #include "modest-ui-actions.h"
 
 static gboolean show_ui = FALSE;
 #include "modest-ui-actions.h"
 
 static gboolean show_ui = FALSE;
+static gint shutdown_timeout = 30;
 static GOptionEntry option_entries [] =
 {
        { "show-ui", 's', 0, G_OPTION_ARG_NONE, &show_ui, "Show UI immediately, so no wait for DBUS activation", NULL },
 static GOptionEntry option_entries [] =
 {
        { "show-ui", 's', 0, G_OPTION_ARG_NONE, &show_ui, "Show UI immediately, so no wait for DBUS activation", NULL },
+       { "shutdown-timeout", 't', 0, G_OPTION_ARG_INT, &shutdown_timeout, "Timeout in minutes for running Modest in prestart mode", NULL },
        { NULL }
 };
 
        { NULL }
 };
 
+static guint shutdown_timeout_id = 0;
+
 typedef struct {
        gulong queue_handler;
        gulong window_list_handler;
 typedef struct {
        gulong queue_handler;
        gulong window_list_handler;
@@ -95,6 +99,9 @@ on_queue_empty (ModestMailOperationQueue *queue,
 {
        ModestWindowMgr *mgr = modest_runtime_get_window_mgr ();
 
 {
        ModestWindowMgr *mgr = modest_runtime_get_window_mgr ();
 
+       if (!modest_runtime_get_allow_shutdown ())
+               return;
+
        /* Exit if the queue is empty and there are no more
           windows. We can exit as well if the main window is hidden
           and it's the only one */
        /* Exit if the queue is empty and there are no more
           windows. We can exit as well if the main window is hidden
           and it's the only one */
@@ -108,11 +115,21 @@ on_window_list_empty (ModestWindowMgr *window_mgr,
 {
        ModestMailOperationQueue *queue = modest_runtime_get_mail_operation_queue ();
 
 {
        ModestMailOperationQueue *queue = modest_runtime_get_mail_operation_queue ();
 
+       if (!modest_runtime_get_allow_shutdown ())
+               return;
+
        /* Exit if there are no more windows and the queue is empty */
        if (modest_mail_operation_queue_num_elements (queue) == 0)
                g_idle_add_full (G_PRIORITY_LOW, on_idle_exit_modest, user_data, NULL);
 }
 
        /* Exit if there are no more windows and the queue is empty */
        if (modest_mail_operation_queue_num_elements (queue) == 0)
                g_idle_add_full (G_PRIORITY_LOW, on_idle_exit_modest, user_data, NULL);
 }
 
+static gboolean
+shutdown_timeout_handler (gpointer userdata)
+{
+       modest_runtime_set_allow_shutdown (TRUE);
+       return FALSE;
+}
+
 int
 main (int argc, char *argv[])
 {
 int
 main (int argc, char *argv[])
 {
@@ -204,6 +221,7 @@ main (int argc, char *argv[])
                ModestWindow *window;
                ModestWindowMgr *mgr;
 
                ModestWindow *window;
                ModestWindowMgr *mgr;
 
+               modest_runtime_set_allow_shutdown (TRUE);
                mgr = modest_runtime_get_window_mgr();
                window = modest_window_mgr_show_initial_window (mgr);
                if (!window) {
                mgr = modest_runtime_get_window_mgr();
                window = modest_window_mgr_show_initial_window (mgr);
                if (!window) {
@@ -213,6 +231,9 @@ main (int argc, char *argv[])
                }
                /* Remove new mail notifications if exist */
                modest_platform_remove_new_mail_notifications (FALSE);
                }
                /* Remove new mail notifications if exist */
                modest_platform_remove_new_mail_notifications (FALSE);
+       } else {
+               modest_runtime_set_allow_shutdown (FALSE);
+               shutdown_timeout_id = g_timeout_add_seconds (shutdown_timeout * 60, shutdown_timeout_handler, NULL);
        }
 
        gtk_main ();
        }
 
        gtk_main ();
index 890b8db..4e98990 100644 (file)
@@ -57,6 +57,9 @@ static ModestTnyAccountStore  *_account_store  = NULL;
 /* Signal handlers for the send queues */
 static GSList *_sig_handlers = NULL;
 
 /* Signal handlers for the send queues */
 static GSList *_sig_handlers = NULL;
 
+/* will modest shut down when window list and mail op queue are empty? */
+static gboolean _allow_shutdown = TRUE;
+
 /*
  * private functions declared in modest-runtime-priv.h -
  * only to be called from modest-init.c 
 /*
  * private functions declared in modest-runtime-priv.h -
  * only to be called from modest-init.c 
@@ -321,6 +324,14 @@ modest_runtime_get_debug_flags ()
        return debug_flags;
 }
 
        return debug_flags;
 }
 
+gboolean 
+modest_runtime_get_allow_shutdown (void)
+{
+       return _allow_shutdown;
+}
 
 
-
-
+void 
+modest_runtime_set_allow_shutdown (gboolean allow)
+{
+       _allow_shutdown = allow;
+}
index c07baf2..badd6c5 100644 (file)
@@ -251,6 +251,23 @@ ModestProtocolRegistry* modest_runtime_get_protocol_registry (void);
  **/
 ModestPluginFactory * modest_runtime_get_plugin_factory (void);
 
  **/
 ModestPluginFactory * modest_runtime_get_plugin_factory (void);
 
+/**
+ * modest_runtime_get_allow_shutdown:
+ *
+ * tell if Modest will shutdown when window list and mail op queue are empty
+ *
+ * Returns: %TRUE if modest shutdown is allowed, %FALSE otherwise
+ */
+gboolean modest_runtime_get_allow_shutdown (void);
+
+/**
+ * modest_runtime_get_allow_shutdown:
+ * @allow: a #gboolean
+ *
+ * set if Modest will shutdown when window list and mail op queue are empty
+ *
+ */
+void modest_runtime_set_allow_shutdown (gboolean allow);
 
 G_END_DECLS
 
 
 G_END_DECLS