[epiphany] Use GtkApplication method to get the list of windows



commit b23b0b805fd475246018b0d7441fe3a9a5cd2303
Author: Xan Lopez <xan igalia com>
Date:   Fri Feb 8 17:14:02 2013 +0100

    Use GtkApplication method to get the list of windows
    
    We have one in EphyShell, but should be redundant (since we stopped
    tracking non-EphyWindow windows some time ago).

 src/ephy-session.c        |    8 ++--
 src/ephy-shell.c          |   73 ++++-----------------------------------------
 src/ephy-shell.h          |    2 -
 tests/ephy-session-test.c |   25 ++++++++-------
 4 files changed, 23 insertions(+), 85 deletions(-)
---
diff --git a/src/ephy-session.c b/src/ephy-session.c
index 9fa15be..d4b9a68 100644
--- a/src/ephy-session.c
+++ b/src/ephy-session.c
@@ -378,7 +378,7 @@ ephy_session_tab_closed (EphySession *session,
 		g_object_notify (G_OBJECT (session), "can-undo-tab-closed");
 
 	LOG ("Added: %s to the list (%d elements)",
-	     address, g_queue_get_legth (priv->closed_tabs));
+	     address, g_queue_get_length (priv->closed_tabs));
 }
 
 gboolean
@@ -717,7 +717,7 @@ save_data_new (EphySession *session,
 	data->session = g_object_ref (session);
 	data->save_file = get_session_file (filename);
 
-	windows = ephy_shell_get_windows (shell);
+	windows = gtk_application_get_windows (GTK_APPLICATION (shell));
 	for (w = windows; w != NULL ; w = w->next)
 	{
 		SessionWindow *session_window;
@@ -726,7 +726,6 @@ save_data_new (EphySession *session,
 		if (session_window)
 			data->windows = g_list_prepend (data->windows, session_window);
 	}
-	g_list_free (windows);
 	data->windows = g_list_reverse (data->windows);
 
 	return data;
@@ -1632,9 +1631,10 @@ ephy_session_clear (EphySession *session)
 	g_return_if_fail (EPHY_IS_SESSION (session));
 
 	shell = ephy_shell_get_default ();
-	windows = ephy_shell_get_windows (shell);
+	windows = g_list_copy (gtk_application_get_windows (GTK_APPLICATION (shell)));
 	for (p = windows; p; p = p->next)
 		gtk_widget_destroy (GTK_WIDGET (p->data));
+	g_list_free (windows);
 	g_queue_foreach (session->priv->closed_tabs,
 			 (GFunc)closed_tab_free, NULL);
 	g_queue_clear (session->priv->closed_tabs);
diff --git a/src/ephy-shell.c b/src/ephy-shell.c
index 6da0900..29f7d79 100644
--- a/src/ephy-shell.c
+++ b/src/ephy-shell.c
@@ -455,50 +455,6 @@ ephy_shell_before_emit (GApplication *application,
                                                               platform_data);
 }
 
-static gboolean
-window_focus_in_event_cb (EphyWindow *window,
-                          GdkEventFocus *event,
-                          EphyShell *shell)
-{
-  LOG ("focus-in-event for window %p", window);
-
-  g_return_val_if_fail (g_list_find (shell->priv->windows, window) != NULL, FALSE);
-
-  /* move the active window to the front of the list */
-  shell->priv->windows = g_list_remove (shell->priv->windows, window);
-  shell->priv->windows = g_list_prepend (shell->priv->windows, window);
-
-  return GDK_EVENT_PROPAGATE;
-}
-
-static void
-ephy_shell_window_added (GtkApplication *application,
-                         GtkWindow *window)
-{
-  EphyShell *shell = EPHY_SHELL (application);
-
-  if (EPHY_IS_WINDOW (window)) {
-    shell->priv->windows = g_list_append (shell->priv->windows, window);
-    g_signal_connect (window, "focus-in-event",
-                      G_CALLBACK (window_focus_in_event_cb),
-                      shell);
-  }
-
-  GTK_APPLICATION_CLASS (ephy_shell_parent_class)->window_added (application, window);
-}
-
-static void
-ephy_shell_window_removed (GtkApplication *application,
-                           GtkWindow *window)
-{
-  EphyShell *shell = EPHY_SHELL (application);
-
-  if (EPHY_IS_WINDOW (window))
-    shell->priv->windows = g_list_remove (shell->priv->windows, window);
-
-  GTK_APPLICATION_CLASS (ephy_shell_parent_class)->window_removed (application, window);
-}
-
 static GObject *
 ephy_shell_get_lockdown (EphyShell *shell)
 {
@@ -536,7 +492,6 @@ ephy_shell_class_init (EphyShellClass *klass)
 {
   GObjectClass *object_class = G_OBJECT_CLASS (klass);
   GApplicationClass *application_class = G_APPLICATION_CLASS (klass);
-  GtkApplicationClass *gtk_application_class = GTK_APPLICATION_CLASS (klass);
   EphyEmbedShellClass *embed_shell_class = EPHY_EMBED_SHELL_CLASS (klass);
 
   object_class->dispose = ephy_shell_dispose;
@@ -548,9 +503,6 @@ ephy_shell_class_init (EphyShellClass *klass)
   application_class->before_emit = ephy_shell_before_emit;
   application_class->add_platform_data = ephy_shell_add_platform_data;
 
-  gtk_application_class->window_added = ephy_shell_window_added;
-  gtk_application_class->window_removed = ephy_shell_window_removed;
-
   embed_shell_class->get_embed_single = impl_get_embed_single;
 
   g_type_class_add_private (object_class, sizeof(EphyShellPrivate));
@@ -709,12 +661,6 @@ ephy_shell_dispose (GObject *object)
   g_clear_object (&priv->bookmarks);
   g_clear_object (&priv->network_monitor);
 
-  if (priv->windows != NULL) {
-    LOG ("Free browser window list");
-    g_list_free (priv->windows);
-    priv->windows = NULL;
-  }
-
   if (priv->open_uris_idle_id > 0)  {
     g_source_remove (priv->open_uris_idle_id);
     priv->open_uris_idle_id = 0;
@@ -1106,20 +1052,15 @@ ephy_shell_set_startup_context (EphyShell *shell,
   shell->priv->startup_context = ctx;
 }
 
-GList *
-ephy_shell_get_windows (EphyShell *shell)
-{
-  g_return_val_if_fail (EPHY_IS_SHELL (shell), NULL);
-
-  return g_list_copy (shell->priv->windows);
-}
-
 guint
 ephy_shell_get_n_windows (EphyShell *shell)
 {
+  GList *list;
+
   g_return_val_if_fail (EPHY_IS_SHELL (shell), 0);
 
-  return g_list_length (shell->priv->windows);
+  list = gtk_application_get_windows (GTK_APPLICATION (shell));
+  return g_list_length (list);
 }
 
 EphyWindow*
@@ -1134,7 +1075,7 @@ ephy_shell_get_main_window (EphyShell *shell)
   /* Select the window with most tabs in the current workspace as the window to
    * use for opening a new tab on, if that turns out to be the case.
    */
-  windows = ephy_shell_get_windows (shell);
+  windows = gtk_application_get_windows (GTK_APPLICATION (shell));
 
   for (iter = windows; iter != NULL; iter = iter->next) {
     EphyWindow *candidate = EPHY_WINDOW (iter->data);
@@ -1155,8 +1096,6 @@ ephy_shell_get_main_window (EphyShell *shell)
       window = candidate;
   }
 
-  g_list_free (windows);
-
   return window;
 }
 
@@ -1170,7 +1109,7 @@ ephy_shell_close_all_windows (EphyShell *shell)
 
   ephy_session_close (ephy_shell_get_session (shell));
 
-  windows = shell->priv->windows;
+  windows = gtk_application_get_windows (GTK_APPLICATION (shell));
   while (windows) {
     EphyWindow *window = EPHY_WINDOW (windows->data);
 
diff --git a/src/ephy-shell.h b/src/ephy-shell.h
index d6f246a..f65083a 100644
--- a/src/ephy-shell.h
+++ b/src/ephy-shell.h
@@ -174,8 +174,6 @@ GObject         *ephy_shell_get_pdm_dialog               (EphyShell *shell);
 
 GObject         *ephy_shell_get_prefs_dialog             (EphyShell *shell);
 
-GList           *ephy_shell_get_windows                  (EphyShell *shell);
-
 guint           ephy_shell_get_n_windows                (EphyShell *shell);
 
 EphyWindow     *ephy_shell_get_main_window              (EphyShell *shell);
diff --git a/tests/ephy-session-test.c b/tests/ephy-session-test.c
index fc425d0..fb1ec63 100644
--- a/tests/ephy-session-test.c
+++ b/tests/ephy-session-test.c
@@ -86,7 +86,7 @@ test_ephy_session_load (void)
     ret = load_session_from_string (session, session_data);
     g_assert (ret);
 
-    l = ephy_shell_get_windows (ephy_shell_get_default ());
+    l = gtk_application_get_windows (GTK_APPLICATION (ephy_shell_get_default ()));
     g_assert (l);
     g_assert_cmpint (g_list_length (l), ==, 1);
 
@@ -119,12 +119,12 @@ test_ephy_session_clear (void)
   session = EPHY_SESSION (ephy_shell_get_session (ephy_shell_get_default ()));
   load_session_from_string (session, session_data_many_windows);
 
-  l = ephy_shell_get_windows (ephy_shell_get_default ());
+  l = gtk_application_get_windows (GTK_APPLICATION (ephy_shell_get_default ()));
   gtk_widget_destroy (GTK_WIDGET (l->data));
 
   ephy_session_clear (session);
 
-  g_assert (ephy_shell_get_windows (ephy_shell_get_default ()) == NULL);
+  g_assert (gtk_application_get_windows (GTK_APPLICATION (ephy_shell_get_default ())) == NULL);
   g_assert (ephy_session_get_can_undo_tab_closed (session) == FALSE);
 }
 
@@ -153,7 +153,7 @@ test_ephy_session_load_empty_session (void)
     while (g_main_context_pending (NULL))
       g_main_context_iteration (NULL, FALSE);
 
-    l = ephy_shell_get_windows (ephy_shell_get_default ());
+    l = gtk_application_get_windows (GTK_APPLICATION (ephy_shell_get_default ()));
     g_assert (l);
     g_assert_cmpint (g_list_length (l), ==, 1);
 
@@ -181,7 +181,7 @@ test_ephy_session_load_many_windows (void)
     ret = load_session_from_string (session, session_data_many_windows);
     g_assert (ret);
 
-    l = ephy_shell_get_windows (ephy_shell_get_default ());
+    l = gtk_application_get_windows (GTK_APPLICATION (ephy_shell_get_default ()));
     g_assert (l);
     g_assert_cmpint (g_list_length (l), ==, 2);
 
@@ -214,7 +214,8 @@ open_uris_after_loading_session (const char** uris, int final_num_windows)
     ret = load_session_from_string (session, session_data_many_windows);
     g_assert (ret);
 
-    l = ephy_shell_get_windows (ephy_shell_get_default ());
+    l = gtk_application_get_windows (GTK_APPLICATION (ephy_shell_get_default ()));
+
     g_assert (l);
     g_assert_cmpint (g_list_length (l), ==, 2);
 
@@ -237,7 +238,7 @@ open_uris_after_loading_session (const char** uris, int final_num_windows)
     while (gtk_events_pending ())
         gtk_main_iteration_do (FALSE);
 
-    l = ephy_shell_get_windows (ephy_shell_get_default ());
+    l = gtk_application_get_windows (GTK_APPLICATION (ephy_shell_get_default ()));
     g_assert (l);
     g_assert_cmpint (g_list_length (l), ==, 2);
 
@@ -253,7 +254,7 @@ open_uris_after_loading_session (const char** uris, int final_num_windows)
     /* We should still have 2 windows here, since the new URI should be
      * in a new tab of an existing window.
      */
-    l = ephy_shell_get_windows (ephy_shell_get_default ());
+    l = gtk_application_get_windows (GTK_APPLICATION (ephy_shell_get_default ()));
     g_assert (l);
     g_assert_cmpint (g_list_length (l), ==, final_num_windows);
 
@@ -298,7 +299,7 @@ test_ephy_session_restore_tabs (void)
   /* Nothing to restore, again. */
   g_assert (ephy_session_get_can_undo_tab_closed (session) == FALSE);
 
-  l = ephy_shell_get_windows (ephy_shell_get_default ());
+  l = gtk_application_get_windows (GTK_APPLICATION (ephy_shell_get_default ()));
   embed = ephy_embed_container_get_active_child (EPHY_EMBED_CONTAINER (l->data));
   url = g_strdup (ephy_web_view_get_address (ephy_embed_get_web_view (embed)));
   gtk_widget_destroy (GTK_WIDGET (embed));
@@ -325,19 +326,19 @@ test_ephy_session_restore_tabs (void)
   ret = load_session_from_string (session, session_data_many_windows);
   g_assert (ret);
 
-  l = ephy_shell_get_windows (ephy_shell_get_default ());
+  l = gtk_application_get_windows (GTK_APPLICATION (ephy_shell_get_default ()));
   n_windows = g_list_length (l);
   /* We need more than one window for the next test to make sense. */
   g_assert_cmpint (n_windows, >, 1);
   gtk_widget_destroy (GTK_WIDGET (l->data));
   /* One window is gone. */
-  g_assert_cmpint (n_windows, ==, g_list_length (ephy_shell_get_windows (ephy_shell_get_default())) + 1);
+  g_assert_cmpint (n_windows, ==, g_list_length (gtk_application_get_windows (GTK_APPLICATION (ephy_shell_get_default()))) + 1);
   g_assert (ephy_session_get_can_undo_tab_closed (session) == TRUE);
   ephy_session_undo_close_tab (session);
   while (gtk_events_pending ())
     gtk_main_iteration_do (FALSE);
   /* We have the same amount of windows than before destroying one. */
-  g_assert_cmpint (n_windows, ==, g_list_length (ephy_shell_get_windows (ephy_shell_get_default())));
+  g_assert_cmpint (n_windows, ==, g_list_length (gtk_application_get_windows (GTK_APPLICATION (ephy_shell_get_default()))));
 
   ephy_session_clear (session);
 }


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