Do not restart Modest every X minutes
authorSergio Villar Senín <svillar@igalia.com>
Fri, 4 Dec 2009 15:20:32 +0000 (16:20 +0100)
committerSergio Villar Senín <svillar@igalia.com>
Wed, 9 Dec 2009 09:14:25 +0000 (10:14 +0100)
Fixes NB#149093

src/dbus_api/modest-dbus-callbacks.c
src/hildon2/com.nokia.modest.service.in
src/hildon2/modest.desktop.in
src/modest-main.c
src/modest-runtime.c
src/widgets/modest-window-mgr.c

index 7a5ecd1..3d24c2a 100644 (file)
@@ -1532,17 +1532,14 @@ modest_dbus_req_handler(const gchar * interface, const gchar * method,
        if (g_ascii_strcasecmp (method, MODEST_DBUS_METHOD_MAIL_TO) == 0) {
                if (arguments->len != MODEST_DBUS_MAIL_TO_ARGS_COUNT)
                        goto param_error;
        if (g_ascii_strcasecmp (method, MODEST_DBUS_METHOD_MAIL_TO) == 0) {
                if (arguments->len != MODEST_DBUS_MAIL_TO_ARGS_COUNT)
                        goto param_error;
-               modest_runtime_set_allow_shutdown (TRUE);
                return on_mail_to (arguments, data, retval);
        } else if (g_ascii_strcasecmp (method, MODEST_DBUS_METHOD_OPEN_MESSAGE) == 0) {
                if (arguments->len != MODEST_DBUS_OPEN_MESSAGE_ARGS_COUNT)
                        goto param_error;
                return on_mail_to (arguments, data, retval);
        } else if (g_ascii_strcasecmp (method, MODEST_DBUS_METHOD_OPEN_MESSAGE) == 0) {
                if (arguments->len != MODEST_DBUS_OPEN_MESSAGE_ARGS_COUNT)
                        goto param_error;
-               modest_runtime_set_allow_shutdown (TRUE);
                return on_open_message (arguments, data, retval);
        } else if (g_ascii_strcasecmp (method, MODEST_DBUS_METHOD_OPEN_ACCOUNT) == 0) {
                if (arguments->len != MODEST_DBUS_OPEN_ACCOUNT_ARGS_COUNT)
                        goto param_error;
                return on_open_message (arguments, data, retval);
        } else if (g_ascii_strcasecmp (method, MODEST_DBUS_METHOD_OPEN_ACCOUNT) == 0) {
                if (arguments->len != MODEST_DBUS_OPEN_ACCOUNT_ARGS_COUNT)
                        goto param_error;
-               modest_runtime_set_allow_shutdown (TRUE);
                return on_open_account (arguments, data, retval);
        } else if (g_ascii_strcasecmp (method, MODEST_DBUS_METHOD_SEND_RECEIVE) == 0) {
                if (arguments->len != 0)
                return on_open_account (arguments, data, retval);
        } else if (g_ascii_strcasecmp (method, MODEST_DBUS_METHOD_SEND_RECEIVE) == 0) {
                if (arguments->len != 0)
@@ -1555,7 +1552,6 @@ modest_dbus_req_handler(const gchar * interface, const gchar * method,
        } else if (g_ascii_strcasecmp (method, MODEST_DBUS_METHOD_COMPOSE_MAIL) == 0) {
                if (arguments->len != MODEST_DBUS_COMPOSE_MAIL_ARGS_COUNT)
                        goto param_error;
        } else if (g_ascii_strcasecmp (method, MODEST_DBUS_METHOD_COMPOSE_MAIL) == 0) {
                if (arguments->len != MODEST_DBUS_COMPOSE_MAIL_ARGS_COUNT)
                        goto param_error;
-               modest_runtime_set_allow_shutdown (TRUE);
                return on_compose_mail (arguments, data, retval);
        } else if (g_ascii_strcasecmp (method, MODEST_DBUS_METHOD_DELETE_MESSAGE) == 0) {
                if (arguments->len != MODEST_DBUS_DELETE_MESSAGE_ARGS_COUNT)
                return on_compose_mail (arguments, data, retval);
        } else if (g_ascii_strcasecmp (method, MODEST_DBUS_METHOD_DELETE_MESSAGE) == 0) {
                if (arguments->len != MODEST_DBUS_DELETE_MESSAGE_ARGS_COUNT)
@@ -1564,17 +1560,14 @@ modest_dbus_req_handler(const gchar * interface, const gchar * method,
        } else if (g_ascii_strcasecmp (method, MODEST_DBUS_METHOD_OPEN_DEFAULT_INBOX) == 0) {
                if (arguments->len != 0)
                        goto param_error;
        } else if (g_ascii_strcasecmp (method, MODEST_DBUS_METHOD_OPEN_DEFAULT_INBOX) == 0) {
                if (arguments->len != 0)
                        goto param_error;
-               modest_runtime_set_allow_shutdown (TRUE);
                return on_open_default_inbox (arguments, data, retval);
        } else if (g_ascii_strcasecmp (method, MODEST_DBUS_METHOD_TOP_APPLICATION) == 0) {
                if (arguments->len != 0)
                        goto param_error;
                return on_open_default_inbox (arguments, data, retval);
        } else if (g_ascii_strcasecmp (method, MODEST_DBUS_METHOD_TOP_APPLICATION) == 0) {
                if (arguments->len != 0)
                        goto param_error;
-               modest_runtime_set_allow_shutdown (TRUE);
                return on_top_application (arguments, data, retval);
        } else if (g_ascii_strcasecmp (method, MODEST_DBUS_METHOD_OPEN_EDIT_ACCOUNTS_DIALOG) == 0) {
                if (arguments->len != 0)
                        goto param_error;
                return on_top_application (arguments, data, retval);
        } else if (g_ascii_strcasecmp (method, MODEST_DBUS_METHOD_OPEN_EDIT_ACCOUNTS_DIALOG) == 0) {
                if (arguments->len != 0)
                        goto param_error;
-               modest_runtime_set_allow_shutdown (TRUE);
                return on_open_edit_accounts_dialog (arguments, data, retval);
        } else {
                /* We need to return INVALID here so
                return on_open_edit_accounts_dialog (arguments, data, retval);
        } else {
                /* We need to return INVALID here so
index c4698b3..2d125bd 100644 (file)
@@ -1,4 +1,4 @@
 [D-BUS Service]
 Name=com.nokia.modest
 [D-BUS Service]
 Name=com.nokia.modest
-Exec=@prefix@/bin/modest -t 30
+Exec=@prefix@/bin/modest
 
 
index 5405f4e..0ed12b2 100644 (file)
@@ -4,7 +4,7 @@ Version=@PACKAGE_VERSION@
 Type=Application
 Name=mcen_ap_name
 Comment=mcen_ap_name_thumb
 Type=Application
 Name=mcen_ap_name
 Comment=mcen_ap_name_thumb
-Exec=@prefix@/bin/modest -t 30
+Exec=@prefix@/bin/modest
 X-Text-Domain=modest
 
 X-Osso-Service=com.nokia.modest
 X-Text-Domain=modest
 
 X-Osso-Service=com.nokia.modest
index a74f619..ed753dd 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 = 0;
 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;
@@ -124,13 +120,6 @@ on_window_list_empty (ModestWindowMgr *window_mgr,
                g_idle_add_full (G_PRIORITY_LOW, on_idle_exit_modest, user_data, NULL);
 }
 
                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[])
 {
@@ -138,7 +127,6 @@ main (int argc, char *argv[])
         * because we wait for the top_application D-Bus method to
         * be called. But that's annoying when starting from the
         * command line.: */
         * because we wait for the top_application D-Bus method to
         * be called. But that's annoying when starting from the
         * command line.: */
-       gboolean show_ui_without_top_application_method = FALSE;
        int retval  = 0;
        MainSignalHandlers *handlers;
        ModestTnyAccountStore *acc_store;
        int retval  = 0;
        MainSignalHandlers *handlers;
        ModestTnyAccountStore *acc_store;
@@ -158,9 +146,7 @@ main (int argc, char *argv[])
        }
        g_option_context_free (context);
 
        }
        g_option_context_free (context);
 
-       show_ui_without_top_application_method = show_ui;
-
-       if (!show_ui_without_top_application_method) {
+       if (!show_ui) {
                g_print ("modest: use 'modest -s' to start from cmdline  with UI\n");
        }
 
                g_print ("modest: use 'modest -s' to start from cmdline  with UI\n");
        }
 
@@ -224,10 +210,9 @@ main (int argc, char *argv[])
         * The UI will be shown later (or just after starting if no otehr D-Bus method was used),
         * when we receive the "top_application" D-Bus method.
         */
         * The UI will be shown later (or just after starting if no otehr D-Bus method was used),
         * when we receive the "top_application" D-Bus method.
         */
-       if (show_ui_without_top_application_method) {
+       if (show_ui) {
                ModestWindow *window;
 
                ModestWindow *window;
 
-               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) {
@@ -237,11 +222,6 @@ 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 {
-               if (shutdown_timeout > 0) {
-                       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 4e98990..f3ec8b6 100644 (file)
@@ -58,7 +58,7 @@ static ModestTnyAccountStore  *_account_store  = NULL;
 static GSList *_sig_handlers = NULL;
 
 /* will modest shut down when window list and mail op queue are empty? */
 static GSList *_sig_handlers = NULL;
 
 /* will modest shut down when window list and mail op queue are empty? */
-static gboolean _allow_shutdown = TRUE;
+static gboolean _allow_shutdown = FALSE;
 
 /*
  * private functions declared in modest-runtime-priv.h -
 
 /*
  * private functions declared in modest-runtime-priv.h -
index cb28697..fa198e3 100644 (file)
@@ -538,16 +538,25 @@ modest_window_mgr_register_window (ModestWindowMgr *self,
                                   ModestWindow *window,
                                   ModestWindow *parent)
 {
                                   ModestWindow *window,
                                   ModestWindow *parent)
 {
-       /* If this is the first registered window then reset the
-          status of the TnyDevice as it might be forced to be offline
-          when modest is running in the background (see
-          modest_tny_account_store_new()) */
-       if (modest_window_mgr_get_num_windows (self) == 0) {
+       gboolean no_windows, retval;
+
+       no_windows = (modest_window_mgr_get_num_windows (self) == 0);
+
+       retval = MODEST_WINDOW_MGR_GET_CLASS (self)->register_window (self, window, parent);
+
+       if  (no_windows) {
+               /* If this is the first registered window then reset the
+                  status of the TnyDevice as it might be forced to be offline
+                  when modest is running in the background (see
+                  modest_tny_account_store_new()) */
                if (tny_device_is_forced (modest_runtime_get_device ()))
                        tny_device_reset (modest_runtime_get_device ());
                if (tny_device_is_forced (modest_runtime_get_device ()))
                        tny_device_reset (modest_runtime_get_device ());
-       }
 
 
-       return MODEST_WINDOW_MGR_GET_CLASS (self)->register_window (self, window, parent);
+               /* Do also allow modest to shutdown when the
+                  application is closed */
+               modest_runtime_set_allow_shutdown (TRUE);
+       }
+       return retval;
 }
 
 static gboolean
 }
 
 static gboolean
@@ -587,7 +596,7 @@ modest_window_mgr_register_window_default (ModestWindowMgr *self,
                        (MODEST_MSG_VIEW_WINDOW (window));
 
                MODEST_DEBUG_BLOCK(g_debug ("registering window for %s", uid ? uid : "<none>"););
                        (MODEST_MSG_VIEW_WINDOW (window));
 
                MODEST_DEBUG_BLOCK(g_debug ("registering window for %s", uid ? uid : "<none>"););
-               
+
                if (has_uid (priv->preregistered_uids, uid)) {
                        priv->preregistered_uids = 
                                remove_uid (priv->preregistered_uids,
                if (has_uid (priv->preregistered_uids, uid)) {
                        priv->preregistered_uids = 
                                remove_uid (priv->preregistered_uids,
@@ -597,7 +606,7 @@ modest_window_mgr_register_window_default (ModestWindowMgr *self,
        } else if (MODEST_IS_MSG_EDIT_WINDOW(window)) {
                const gchar *uid = modest_msg_edit_window_get_message_uid
                        (MODEST_MSG_EDIT_WINDOW (window));
        } else if (MODEST_IS_MSG_EDIT_WINDOW(window)) {
                const gchar *uid = modest_msg_edit_window_get_message_uid
                        (MODEST_MSG_EDIT_WINDOW (window));
-               
+
                MODEST_DEBUG_BLOCK(g_debug ("registering window for %s", uid););
 
                priv->preregistered_uids = 
                MODEST_DEBUG_BLOCK(g_debug ("registering window for %s", uid););
 
                priv->preregistered_uids =