From 3ad970f76f2ede63152cdfd3b5c882aa80aad3cc Mon Sep 17 00:00:00 2001 From: Carlos Garcia Campos Date: Thu, 27 Sep 2012 10:15:15 +0200 Subject: Make sure windows are properly closed when quitting from the shell menu https://bugzilla.gnome.org/show_bug.cgi?id=679844 --- src/ephy-session.c | 37 ++++++++++++++ src/ephy-session.h | 2 + src/ephy-shell.c | 5 +- src/ephy-window.c | 140 ++++++++++++++++++++++++++++++----------------------- src/ephy-window.h | 2 + 5 files changed, 121 insertions(+), 65 deletions(-) (limited to 'src') diff --git a/src/ephy-session.c b/src/ephy-session.c index ac4c328a3..9f44d7e0f 100644 --- a/src/ephy-session.c +++ b/src/ephy-session.c @@ -1235,6 +1235,43 @@ ephy_session_get_active_window (EphySession *session) return window; } +/** + * ephy_session_close_all_windows: + * @session: a #EphySession + * + * Try to close all browser windows. A window might refuse to + * close if there are ongoing download operations or unsubmitted + * modifed forms. + * + * Returns: %TRUE if all windows were closed, or %FALSE otherwise + **/ +gboolean +ephy_session_close_all_windows (EphySession *session) +{ + GList *l; + gboolean retval = TRUE; + + g_return_val_if_fail (EPHY_IS_SESSION (session), FALSE); + + ephy_session_close (session); + + for (l = session->priv->windows; l != NULL; l = l->next) + { + EphyWindow *window = EPHY_WINDOW (l->data); + + if (ephy_window_close (window)) + { + gtk_widget_destroy (GTK_WIDGET (window)); + } + else + { + retval = FALSE; + } + } + + return retval; +} + /** * ephy_session_queue_command: * @session: a #EphySession diff --git a/src/ephy-session.h b/src/ephy-session.h index c083ab3d8..392c0612b 100644 --- a/src/ephy-session.h +++ b/src/ephy-session.h @@ -88,6 +88,8 @@ void ephy_session_close (EphySession *session); GList *ephy_session_get_windows (EphySession *session); +gboolean ephy_session_close_all_windows (EphySession *session); + void ephy_session_queue_command (EphySession *session, EphySessionCommand op, const char *arg, diff --git a/src/ephy-shell.c b/src/ephy-shell.c index 7bd305ea2..88f843e40 100644 --- a/src/ephy-shell.c +++ b/src/ephy-shell.c @@ -238,11 +238,8 @@ quit_application (GSimpleAction *action, GVariant *parameter, gpointer user_data) { - if (!g_settings_get_boolean (EPHY_SETTINGS_LOCKDOWN, - EPHY_PREFS_LOCKDOWN_QUIT)) { - ephy_session_close (EPHY_SESSION (ephy_shell_get_session (ephy_shell))); + if (ephy_session_close_all_windows (EPHY_SESSION (ephy_shell_get_session (ephy_shell)))) g_application_quit (g_application_get_default ()); - } } static GActionEntry app_entries[] = { diff --git a/src/ephy-window.c b/src/ephy-window.c index 898c7d754..d2afac0dd 100644 --- a/src/ephy-window.c +++ b/src/ephy-window.c @@ -970,67 +970,8 @@ static gboolean ephy_window_delete_event (GtkWidget *widget, GdkEventAny *event) { - EphyWindow *window = EPHY_WINDOW (widget); - EphySession *session; - EphyEmbed *modified_embed = NULL; - GList *tabs, *l, *windows; - guint number_windows; - gboolean modified = FALSE; - - /* We ignore the delete_event if the disable_quit lockdown has been set - */ - if (g_settings_get_boolean (EPHY_SETTINGS_LOCKDOWN, - EPHY_PREFS_LOCKDOWN_QUIT)) return TRUE; - - tabs = impl_get_children (EPHY_EMBED_CONTAINER (window)); - for (l = tabs; l != NULL; l = l->next) - { - EphyEmbed *embed = (EphyEmbed *) l->data; - - g_return_val_if_fail (EPHY_IS_EMBED (embed), FALSE); - - if (ephy_web_view_has_modified_forms (ephy_embed_get_web_view (embed))) - { - modified = TRUE; - modified_embed = embed; - break; - } - } - g_list_free (tabs); - - if (modified) - { - /* jump to the first tab with modified forms */ - impl_set_active_child (EPHY_EMBED_CONTAINER (window), - modified_embed); - - if (confirm_close_with_modified_forms (window) == FALSE) - { - /* stop window close */ - return TRUE; - } - } - - - if (window_has_ongoing_downloads (window) && confirm_close_with_downloads (window) == FALSE) - { - /* stop window close */ - return TRUE; - } - - /* If this is the last window, save its state in the session. */ - session = EPHY_SESSION (ephy_shell_get_session (ephy_shell)); - windows = ephy_session_get_windows (session); - number_windows = g_list_length (windows); - g_list_free (windows); - - if (number_windows == 1) - { - ephy_session_close (session); - } - - /* See bug #114689 */ - gtk_widget_hide (widget); + if (!ephy_window_close (EPHY_WINDOW (widget))) + return TRUE; /* proceed with window close */ if (GTK_WIDGET_CLASS (ephy_window_parent_class)->delete_event) @@ -4165,3 +4106,80 @@ ephy_window_get_location_controller (EphyWindow *window) return window->priv->location_controller; } + +/** + * ephy_window_close: + * @window: an #EphyWindow + * + * Try to close the window. The window might refuse to close + * if there are ongoing download operations or unsubmitted + * modifed forms. + * + * Returns: %TRUE if the window is closed, or %FALSE otherwise + **/ +gboolean +ephy_window_close (EphyWindow *window) +{ + EphySession *session; + EphyEmbed *modified_embed = NULL; + GList *tabs, *l, *windows; + guint number_windows; + gboolean modified = FALSE; + + /* We ignore the delete_event if the disable_quit lockdown has been set + */ + if (g_settings_get_boolean (EPHY_SETTINGS_LOCKDOWN, + EPHY_PREFS_LOCKDOWN_QUIT)) return FALSE; + + tabs = impl_get_children (EPHY_EMBED_CONTAINER (window)); + for (l = tabs; l != NULL; l = l->next) + { + EphyEmbed *embed = (EphyEmbed *) l->data; + + g_return_val_if_fail (EPHY_IS_EMBED (embed), FALSE); + + if (ephy_web_view_has_modified_forms (ephy_embed_get_web_view (embed))) + { + modified = TRUE; + modified_embed = embed; + break; + } + } + g_list_free (tabs); + + if (modified) + { + /* jump to the first tab with modified forms */ + impl_set_active_child (EPHY_EMBED_CONTAINER (window), + modified_embed); + + if (confirm_close_with_modified_forms (window) == FALSE) + { + /* stop window close */ + return FALSE; + } + } + + + if (window_has_ongoing_downloads (window) && confirm_close_with_downloads (window) == FALSE) + { + /* stop window close */ + return FALSE; + } + + /* If this is the last window, save its state in the session. */ + session = EPHY_SESSION (ephy_shell_get_session (ephy_shell)); + windows = ephy_session_get_windows (session); + number_windows = g_list_length (windows); + g_list_free (windows); + + if (number_windows == 1) + { + ephy_session_close (session); + } + + /* See bug #114689 */ + gtk_widget_hide (GTK_WIDGET (window)); + + return TRUE; +} diff --git a/src/ephy-window.h b/src/ephy-window.h index 51e9c61d1..8ce845de2 100644 --- a/src/ephy-window.h +++ b/src/ephy-window.h @@ -74,6 +74,8 @@ void ephy_window_set_zoom (EphyWindow *window, void ephy_window_activate_location (EphyWindow *window); const char *ephy_window_get_location (EphyWindow *window); +gboolean ephy_window_close (EphyWindow *window); + G_END_DECLS #endif -- cgit v1.2.3