From 2b782aed463d9cd3b59f3d511abff67f66b2d067 Mon Sep 17 00:00:00 2001 From: Jose Dapena Paz Date: Mon, 25 May 2009 10:58:39 +0200 Subject: [PATCH] Set a timeout for prestarted mode (no shutdown before timeout finishes) * 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 | 21 +++++++++++++++++++++ src/modest-runtime.c | 15 +++++++++++++-- src/modest-runtime.h | 17 +++++++++++++++++ 3 files changed, 51 insertions(+), 2 deletions(-) diff --git a/src/modest-main.c b/src/modest-main.c index 3640252..f7bdf96 100644 --- a/src/modest-main.c +++ b/src/modest-main.c @@ -37,12 +37,16 @@ #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 }, + { "shutdown-timeout", 't', 0, G_OPTION_ARG_INT, &shutdown_timeout, "Timeout in minutes for running Modest in prestart mode", NULL }, { NULL } }; +static guint shutdown_timeout_id = 0; + 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 (); + 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 */ @@ -108,11 +115,21 @@ on_window_list_empty (ModestWindowMgr *window_mgr, { 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); } +static gboolean +shutdown_timeout_handler (gpointer userdata) +{ + modest_runtime_set_allow_shutdown (TRUE); + return FALSE; +} + int main (int argc, char *argv[]) { @@ -204,6 +221,7 @@ main (int argc, char *argv[]) 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) { @@ -213,6 +231,9 @@ main (int argc, char *argv[]) } /* 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 (); diff --git a/src/modest-runtime.c b/src/modest-runtime.c index 890b8db..4e98990 100644 --- a/src/modest-runtime.c +++ b/src/modest-runtime.c @@ -57,6 +57,9 @@ static ModestTnyAccountStore *_account_store = 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 @@ -321,6 +324,14 @@ modest_runtime_get_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; +} diff --git a/src/modest-runtime.h b/src/modest-runtime.h index c07baf2..badd6c5 100644 --- a/src/modest-runtime.h +++ b/src/modest-runtime.h @@ -251,6 +251,23 @@ ModestProtocolRegistry* modest_runtime_get_protocol_registry (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 -- 1.7.9.5