[epiphany/gnome-3-6] Make sure windows are properly closed when quitting from the shell menu



commit 9faafcfd15c4ea8adbb9178b321db4a5a6f0dc8e
Author: Carlos Garcia Campos <cgarcia igalia com>
Date:   Thu Sep 27 10:15:15 2012 +0200

    Make sure windows are properly closed when quitting from the shell menu
    
    https://bugzilla.gnome.org/show_bug.cgi?id=679844
    
    Conflicts:
    
    	src/ephy-shell.c
    
    We need this for the gear menu changes to build.

 doc/reference/epiphany-sections.txt |    1 +
 src/ephy-session.c                  |   37 +++++++++
 src/ephy-session.h                  |    2 +
 src/ephy-window.c                   |  140 ++++++++++++++++++++---------------
 src/ephy-window.h                   |    2 +
 5 files changed, 121 insertions(+), 61 deletions(-)
---
diff --git a/doc/reference/epiphany-sections.txt b/doc/reference/epiphany-sections.txt
index ae89084..5163dd4 100644
--- a/doc/reference/epiphany-sections.txt
+++ b/doc/reference/epiphany-sections.txt
@@ -227,4 +227,5 @@ ephy_window_set_zoom
 ephy_window_activate_location
 ephy_window_get_is_print_preview
 ephy_window_get_context_event
+ephy_window_close
 </SECTION>
diff --git a/src/ephy-session.c b/src/ephy-session.c
index ac4c328..9f44d7e 100644
--- a/src/ephy-session.c
+++ b/src/ephy-session.c
@@ -1236,6 +1236,43 @@ ephy_session_get_active_window (EphySession *session)
 }
 
 /**
+ * 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 c083ab3..392c061 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-window.c b/src/ephy-window.c
index 9b3cc42..dd85df7 100644
--- a/src/ephy-window.c
+++ b/src/ephy-window.c
@@ -988,67 +988,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)
@@ -4228,3 +4169,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 51e9c61..8ce845d 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



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]