[Xfce4-commits] <midori:master> Remove midori_browser_foreach in favour of GList

Christian Dywan noreply at xfce.org
Sun Dec 16 15:12:02 CET 2012


Updating branch refs/heads/master
         to c0d44612ccedeba833a0a20780d5764711114b6f (commit)
       from b1a7d3f5231c439fbdc2aa0249c715608f63dc3e (commit)

commit c0d44612ccedeba833a0a20780d5764711114b6f
Author: Christian Dywan <christian at twotoasts.de>
Date:   Sun Dec 16 13:59:46 2012 +0100

    Remove midori_browser_foreach in favour of GList
    
    Iterating a list is less tempting into hacks and faster,
    more importantly 1 code path for 1 feature is more maintainable.

 extensions/addons.c                  |   34 +++++++--------------
 extensions/formhistory/formhistory.c |   29 +++++++++---------
 extensions/mouse-gestures.c          |   20 +++++-------
 extensions/tab-panel.c               |   14 ++------
 midori/midori-browser.c              |   54 +++++++--------------------------
 midori/midori-browser.h              |    5 ---
 midori/midori-view.c                 |   17 ++++------
 7 files changed, 57 insertions(+), 116 deletions(-)

diff --git a/extensions/addons.c b/extensions/addons.c
index 3242e71..08c14b1 100644
--- a/extensions/addons.c
+++ b/extensions/addons.c
@@ -1518,29 +1518,18 @@ addons_add_tab_cb (MidoriBrowser* browser,
 }
 
 static void
-addons_add_tab_foreach_cb (MidoriView*      view,
-                           MidoriBrowser*   browser,
-                           MidoriExtension* extension)
-{
-    addons_add_tab_cb (browser, view, extension);
-}
-
-static void
-addons_deactivate_tabs (MidoriView*      view,
-                        MidoriExtension* extension)
-{
-    GtkWidget* web_view = midori_view_get_web_view (view);
-    g_signal_handlers_disconnect_by_func (
-        web_view, addons_context_ready_cb, extension);
-}
-
-static void
 addons_browser_destroy (MidoriBrowser*   browser,
                         MidoriExtension* extension)
 {
     GtkWidget* scripts, *styles;
-
-    midori_browser_foreach (browser, (GtkCallback)addons_deactivate_tabs, extension);
+    GList* tabs = midori_browser_get_tabs (browser);
+    for (; tabs; tabs = g_list_next (tabs))
+    {
+        GtkWidget* web_view = midori_view_get_web_view (tabs->data);
+        g_signal_handlers_disconnect_by_func (
+            web_view, addons_context_ready_cb, extension);
+    }
+    g_list_free (tabs);
     g_signal_handlers_disconnect_by_func (browser, addons_add_tab_cb, extension);
 
     scripts = (GtkWidget*)g_object_get_data (G_OBJECT (browser), "scripts-addons");
@@ -1620,9 +1609,10 @@ addons_app_add_browser_cb (MidoriApp*       app,
 {
     GtkWidget* panel;
     GtkWidget* scripts, *styles;
-
-    midori_browser_foreach (browser,
-          (GtkCallback)addons_add_tab_foreach_cb, extension);
+    GList* tabs = midori_browser_get_tabs (browser);
+    for (; tabs; tabs = g_list_next (tabs))
+        addons_add_tab_cb (browser, tabs->data, extension);
+    g_list_free (tabs);
     g_signal_connect (browser, "add-tab",
         G_CALLBACK (addons_add_tab_cb), extension);
     panel = katze_object_get_object (browser, "panel");
diff --git a/extensions/formhistory/formhistory.c b/extensions/formhistory/formhistory.c
index d999cd4..510a135 100644
--- a/extensions/formhistory/formhistory.c
+++ b/extensions/formhistory/formhistory.c
@@ -416,13 +416,6 @@ formhistory_add_tab_cb (MidoriBrowser*   browser,
 }
 
 static void
-formhistory_add_tab_foreach_cb (MidoriView*      view,
-                                MidoriExtension* extension)
-{
-    formhistory_add_tab_cb (NULL, view, extension);
-}
-
-static void
 formhistory_app_add_browser_cb (MidoriApp*       app,
                                 MidoriBrowser*   browser,
                                 MidoriExtension* extension)
@@ -446,8 +439,10 @@ formhistory_app_add_browser_cb (MidoriApp*       app,
 
     if (midori_extension_get_boolean (extension, "always-load"))
     {
-        midori_browser_foreach (browser,
-            (GtkCallback)formhistory_add_tab_foreach_cb, extension);
+        GList* tabs = midori_browser_get_tabs (browser);
+        for (; tabs; tabs = g_list_next (tabs))
+            formhistory_add_tab_cb (browser, tabs->data, extension);
+        g_list_free (tabs);
         g_signal_connect (browser, "add-tab",
             G_CALLBACK (formhistory_add_tab_cb), extension);
     }
@@ -487,8 +482,10 @@ formhistory_deactivate_cb (MidoriExtension* extension,
         extension, formhistory_deactivate_cb, browser);
     g_signal_handlers_disconnect_by_func (
         app, formhistory_app_add_browser_cb, extension);
-    midori_browser_foreach (browser,
-        (GtkCallback)formhistory_deactivate_tab, extension);
+    GList* tabs = midori_browser_get_tabs (browser);
+    for (; tabs; tabs = g_list_next (tabs))
+        formhistory_deactivate_tab (tabs->data, extension);
+    g_list_free (tabs);
 
     g_object_set_data (G_OBJECT (browser), "FormHistoryExtension", NULL);
     action = gtk_action_group_get_action (action_group, "FormHistoryToggleState");
@@ -589,18 +586,20 @@ formhistory_preferences_response_cb (GtkWidget*       dialog,
             browsers = katze_object_get_object (app, "browsers");
             KATZE_ARRAY_FOREACH_ITEM (browser, browsers)
             {
-                midori_browser_foreach (browser,
-                    (GtkCallback)formhistory_deactivate_tab, extension);
+                GList* tabs = midori_browser_get_tabs (browser);
+                for (; tabs; tabs = g_list_next (tabs))
+                    formhistory_deactivate_tab (tabs->data, extension);
                 g_signal_handlers_disconnect_by_func (
                     browser, formhistory_add_tab_cb, extension);
 
                 if (new_state)
                 {
-                    midori_browser_foreach (browser,
-                        (GtkCallback)formhistory_add_tab_foreach_cb, extension);
+                    for (; tabs; tabs = g_list_next (tabs))
+                        formhistory_add_tab_cb (browser, tabs->data, extension);
                     g_signal_connect (browser, "add-tab",
                         G_CALLBACK (formhistory_add_tab_cb), extension);
                 }
+                g_list_free (tabs);
             }
         }
     }
diff --git a/extensions/mouse-gestures.c b/extensions/mouse-gestures.c
index b1f5b28..3941594 100644
--- a/extensions/mouse-gestures.c
+++ b/extensions/mouse-gestures.c
@@ -221,20 +221,14 @@ mouse_gestures_deactivate_cb (MidoriExtension* extension,
                               MidoriBrowser*   browser);
 
 static void
-mouse_gestures_add_tab_foreach_cb (MidoriView*      view,
-                                   MidoriBrowser*   browser,
-                                   MidoriExtension* extension)
-{
-    mouse_gestures_add_tab_cb (browser, view, extension);
-}
-
-static void
 mouse_gestures_app_add_browser_cb (MidoriApp*       app,
                                    MidoriBrowser*   browser,
                                    MidoriExtension* extension)
 {
-    midori_browser_foreach (browser,
-          (GtkCallback)mouse_gestures_add_tab_foreach_cb, extension);
+    GList* tabs = midori_browser_get_tabs (browser);
+    for (; tabs; tabs = g_list_next (tabs))
+        mouse_gestures_add_tab_cb (browser, tabs->data, extension);
+    g_list_free (tabs);
     g_signal_connect (browser, "add-tab",
         G_CALLBACK (mouse_gestures_add_tab_cb), extension);
     g_signal_connect (extension, "deactivate",
@@ -269,9 +263,11 @@ mouse_gestures_deactivate_cb (MidoriExtension* extension,
         app, mouse_gestures_app_add_browser_cb, extension);
     g_signal_handlers_disconnect_by_func (
        browser, mouse_gestures_add_tab_cb, extension);
-    midori_browser_foreach (browser,
-        (GtkCallback)mouse_gestures_deactivate_tabs, browser);
 
+    GList* tabs = midori_browser_get_tabs (browser);
+    for (; tabs; tabs = g_list_next (tabs))
+        mouse_gestures_deactivate_tabs (tabs->data, browser);
+    g_list_free (tabs);
     g_free (gesture);
 }
 
diff --git a/extensions/tab-panel.c b/extensions/tab-panel.c
index c0cc143..9b1ed68 100644
--- a/extensions/tab-panel.c
+++ b/extensions/tab-panel.c
@@ -467,14 +467,6 @@ tab_panel_browser_add_tab_cb (MidoriBrowser*   browser,
 }
 
 static void
-tab_panel_browser_foreach_cb (GtkWidget*       view,
-                              MidoriExtension* extension)
-{
-    tab_panel_browser_add_tab_cb (midori_browser_get_for_widget (view),
-                                  view, extension);
-}
-
-static void
 tab_panel_browser_remove_tab_cb (MidoriBrowser*   browser,
                                  GtkWidget*       view,
                                  MidoriExtension* extension)
@@ -590,8 +582,10 @@ tab_panel_app_add_browser_cb (MidoriApp*       app,
         midori_panel_set_current_page (MIDORI_PANEL (panel), i);
     g_object_unref (panel);
 
-    midori_browser_foreach (browser,
-        (GtkCallback)tab_panel_browser_foreach_cb, treeview);
+    GList* tabs = midori_browser_get_tabs (browser);
+    for (; tabs; tabs = g_list_next (tabs))
+        tab_panel_browser_add_tab_cb (browser, tabs->data, extension);
+    g_list_free (tabs);
 
     g_signal_connect_after (browser, "add-tab",
         G_CALLBACK (tab_panel_browser_add_tab_cb), extension);
diff --git a/midori/midori-browser.c b/midori/midori-browser.c
index ff91db6..d615022 100644
--- a/midori/midori-browser.c
+++ b/midori/midori-browser.c
@@ -1668,35 +1668,6 @@ _midori_browser_add_tab (MidoriBrowser* browser,
     _midori_browser_update_actions (browser);
 }
 
-/**
- * midori_browser_foreach:
- * @browser: a #MidoriBrowser
- * @callback: a #GtkCallback
- * @callback_data: custom data
- *
- * Calls the specified callback for each view contained
- * in the browser.
- *
- * Since: 0.1.7
- **/
-void
-midori_browser_foreach (MidoriBrowser* browser,
-                        GtkCallback    callback,
-                        gpointer       callback_data)
-{
-    g_return_if_fail (MIDORI_IS_BROWSER (browser));
-
-    #ifdef HAVE_GRANITE
-    /* FIXME */
-    if (GTK_IS_BIN (browser->notebook))
-        gtk_container_foreach (GTK_CONTAINER (gtk_bin_get_child (GTK_BIN (
-            browser->notebook))), callback, callback_data);
-    else
-    #endif
-    gtk_container_foreach (GTK_CONTAINER (browser->notebook),
-                           callback, callback_data);
-}
-
 static void
 _midori_browser_quit (MidoriBrowser* browser)
 {
@@ -4606,20 +4577,17 @@ _action_tab_duplicate_activate (GtkAction*     action,
 }
 
 static void
-midori_browser_close_other_tabs_cb (GtkWidget* view,
-                                    gpointer   data)
-{
-    GtkWidget* remaining_view = data;
-    if (view != remaining_view)
-        gtk_widget_destroy (view);
-}
-
-static void
 _action_tab_close_other_activate (GtkAction*     action,
                                   MidoriBrowser* browser)
 {
     GtkWidget* view = midori_browser_get_current_tab (browser);
-    midori_browser_foreach (browser, midori_browser_close_other_tabs_cb, view);
+    GList* tabs = midori_browser_get_tabs (browser);
+    for (; tabs; tabs = g_list_next (tabs))
+    {
+        if (tabs->data != view)
+            gtk_widget_destroy (tabs->data);
+    }
+    g_list_free (tabs);
 }
 
 static const gchar* credits_authors[] =
@@ -5100,7 +5068,7 @@ midori_browser_notebook_button_press_event_after_cb (GtkNotebook*    notebook,
     else if (event->type == GDK_BUTTON_PRESS && MIDORI_EVENT_CONTEXT_MENU (event))
     {
         GtkWidget* menu = gtk_menu_new ();
-        GList* tabs = gtk_container_get_children (GTK_CONTAINER (notebook));
+        GList* tabs = midori_browser_get_tabs (browser);
         GtkWidget* menuitem = sokoke_action_create_popup_menu_item (
             gtk_action_group_get_action (browser->action_group, "TabNew"));
         gint i = 0;
@@ -7059,8 +7027,10 @@ midori_browser_set_property (GObject*      object,
         _midori_browser_update_settings (browser);
         g_signal_connect (browser->settings, "notify",
             G_CALLBACK (midori_browser_settings_notify), browser);
-        midori_browser_foreach (browser,
-            (GtkCallback) midori_view_set_settings, browser->settings);
+        GList* tabs = midori_browser_get_tabs (browser);
+        for (; tabs; tabs = g_list_next (tabs))
+            midori_view_set_settings (tabs->data, browser->settings);
+        g_list_free (tabs);
         break;
     case PROP_BOOKMARKS:
         midori_browser_set_bookmarks (browser, g_value_get_object (value));
diff --git a/midori/midori-browser.h b/midori/midori-browser.h
index 43d7461..16f3868 100644
--- a/midori/midori-browser.h
+++ b/midori/midori-browser.h
@@ -82,11 +82,6 @@ void
 midori_browser_close_tab              (MidoriBrowser*     browser,
                                        GtkWidget*         widget);
 
-void
-midori_browser_foreach                (MidoriBrowser*     browser,
-                                       GtkCallback        callback,
-                                       gpointer           callback_data);
-
 gint
 midori_browser_add_item               (MidoriBrowser*     browser,
                                        KatzeItem*         item);
diff --git a/midori/midori-view.c b/midori/midori-view.c
index 9a581b8..dbac434 100644
--- a/midori/midori-view.c
+++ b/midori/midori-view.c
@@ -4362,20 +4362,17 @@ midori_view_duplicate (MidoriView* view)
 }
 
 static void
-midori_view_browser_close_tabs_cb (GtkWidget* view,
-                                   gpointer   data)
-{
-    GtkWidget* remaining_view = data;
-    if (view != remaining_view)
-         midori_browser_close_tab (midori_browser_get_for_widget (view), view);
-}
-
-static void
 midori_view_tab_label_menu_close_other_tabs_cb (GtkWidget* menuitem,
                                                 GtkWidget* view)
 {
     MidoriBrowser* browser = midori_browser_get_for_widget (view);
-    midori_browser_foreach (browser, midori_view_browser_close_tabs_cb, view);
+    GList* tabs = midori_browser_get_tabs (browser);
+    for (; tabs; tabs = g_list_next (tabs))
+    {
+        if (tabs->data != view)
+            gtk_widget_destroy (tabs->data);
+    }
+    g_list_free (tabs);
 }
 
 static void


More information about the Xfce4-commits mailing list