[Xfce4-commits] <midori:master> Avoid midori_browser_get_nth_tab in tab loops

Christian Dywan noreply at xfce.org
Mon Nov 5 23:20:01 CET 2012


Updating branch refs/heads/master
         to 5431f5884bdf4ca0d174ddf543072c784ea13abd (commit)
       from 3eb4b70d5a8ef68b5b2213eedc85ded64db18875 (commit)

commit 5431f5884bdf4ca0d174ddf543072c784ea13abd
Author: Christian Dywan <christian at twotoasts.de>
Date:   Mon Nov 5 23:17:15 2012 +0100

    Avoid midori_browser_get_nth_tab in tab loops

 extensions/adblock.c       |   17 ++++++++++-------
 extensions/colorful-tabs.c |   23 +++++++++++++----------
 extensions/copy-tabs.c     |    1 +
 midori/main.c              |    8 +++++---
 midori/midori-browser.c    |    5 +++++
 5 files changed, 34 insertions(+), 20 deletions(-)

diff --git a/extensions/adblock.c b/extensions/adblock.c
index 62f8fc7..71664b2 100644
--- a/extensions/adblock.c
+++ b/extensions/adblock.c
@@ -1108,6 +1108,7 @@ adblock_app_add_browser_cb (MidoriApp*       app,
 {
     GtkWidget* statusbar;
     GtkWidget* image;
+    GList* children;
     GtkWidget* view;
     gint i;
 
@@ -1119,9 +1120,10 @@ adblock_app_add_browser_cb (MidoriApp*       app,
     g_object_set_data_full (G_OBJECT (browser), "status-image", image,
                             (GDestroyNotify)gtk_widget_destroy);
 
-    i = 0;
-    while((view = midori_browser_get_nth_tab(browser, i++)))
-        adblock_add_tab_cb (browser, MIDORI_VIEW (view), extension);
+    children = midori_browser_get_tabs (MIDORI_BROWSER (browser));
+    for (; children; children = g_list_next (children))
+        adblock_add_tab_cb (browser, children->data, extension);
+    g_list_free (children);
 
     g_signal_connect (browser, "add-tab",
         G_CALLBACK (adblock_add_tab_cb), extension);
@@ -1726,7 +1728,7 @@ static void
 adblock_deactivate_cb (MidoriExtension* extension,
                        MidoriBrowser*   browser)
 {
-    gint i;
+    GList* children;
     GtkWidget* view;
     MidoriApp* app = midori_extension_get_app (extension);
     MidoriWebSettings* settings = katze_object_get_object (app, "settings");
@@ -1742,9 +1744,10 @@ adblock_deactivate_cb (MidoriExtension* extension,
     g_signal_handlers_disconnect_by_func (
         browser, adblock_remove_tab_cb, extension);
 
-    i = 0;
-    while((view = midori_browser_get_nth_tab(browser, i++)))
-        adblock_deactivate_tabs (MIDORI_VIEW (view), browser, extension);
+    children = midori_browser_get_tabs (MIDORI_BROWSER (browser));
+    for (; children; children = g_list_next (children))
+        adblock_deactivate_tabs (children->data, browser, extension);
+    g_list_free (children);
 
     adblock_destroy_db ();
     midori_web_settings_remove_style (settings, "adblock-blockcss");
diff --git a/extensions/colorful-tabs.c b/extensions/colorful-tabs.c
index 0468286..569d3ab 100644
--- a/extensions/colorful-tabs.c
+++ b/extensions/colorful-tabs.c
@@ -136,7 +136,7 @@ static void
 colorful_tabs_deactivate_cb (MidoriExtension* extension,
                              MidoriBrowser*   browser)
 {
-    guint i;
+    GList* children;
     GtkWidget* view;
     MidoriApp* app = midori_extension_get_app (extension);
 
@@ -146,17 +146,19 @@ colorful_tabs_deactivate_cb (MidoriExtension* extension,
         browser, colorful_tabs_browser_add_tab_cb, extension);
     g_signal_handlers_disconnect_by_func (
         extension, colorful_tabs_deactivate_cb, browser);
-    i = 0;
-    while ((view = midori_browser_get_nth_tab (browser, i++)))
+
+    children = midori_browser_get_tabs (MIDORI_BROWSER (browser));
+    for (; children; children = g_list_next (children))
     {
-        GtkWidget* label = midori_view_get_proxy_tab_label (MIDORI_VIEW (view));
+        GtkWidget* label = midori_view_get_proxy_tab_label (children->data);
         gtk_event_box_set_visible_window (GTK_EVENT_BOX (label), FALSE);
         gtk_widget_modify_bg (label, GTK_STATE_NORMAL, NULL);
         gtk_widget_modify_bg (label, GTK_STATE_ACTIVE, NULL);
         colorful_tabs_modify_fg (label, NULL);
         g_signal_handlers_disconnect_by_func (
-            view, colorful_tabs_view_notify_uri_cb, extension);
+            children->data, colorful_tabs_view_notify_uri_cb, extension);
     }
+    g_list_free (children);
 }
 
 static void
@@ -164,12 +166,13 @@ colorful_tabs_app_add_browser_cb (MidoriApp*       app,
                                   MidoriBrowser*   browser,
                                   MidoriExtension* extension)
 {
-    guint i;
-    GtkWidget* view;
+    GList* children;
+
+    children = midori_browser_get_tabs (MIDORI_BROWSER (browser));
+    for (; children; children = g_list_next (children))
+        colorful_tabs_browser_add_tab_cb (browser, children->data, extension);
+    g_list_free (children);
 
-    i = 0;
-    while ((view = midori_browser_get_nth_tab (browser, i++)))
-        colorful_tabs_browser_add_tab_cb (browser, view, extension);
     g_signal_connect (browser, "add-tab",
         G_CALLBACK (colorful_tabs_browser_add_tab_cb), extension);
     g_signal_connect (extension, "deactivate",
diff --git a/extensions/copy-tabs.c b/extensions/copy-tabs.c
index 8dc1e49..8c349a4 100644
--- a/extensions/copy-tabs.c
+++ b/extensions/copy-tabs.c
@@ -28,6 +28,7 @@ copy_tabs_apply_cb (GtkWidget*     menuitem,
     }
     gtk_clipboard_set_text (clipboard, text->str, -1);
     g_string_free (text, TRUE);
+    g_list_free (children);
 }
 
 static void
diff --git a/midori/main.c b/midori/main.c
index 9c5cf10..32e5800 100644
--- a/midori/main.c
+++ b/midori/main.c
@@ -1547,14 +1547,16 @@ midori_inactivity_timeout (gpointer data)
         XScreenSaverQueryInfo (xdisplay, RootWindow (xdisplay, 0), mit_info);
         if (mit_info->idle / 1000 > mit->timeout)
         {
-            guint i = 0;
+            GList* children;
             GtkWidget* view;
             KatzeArray* history = katze_object_get_object (mit->browser, "history");
             KatzeArray* trash = katze_object_get_object (mit->browser, "trash");
             GList* data_items = sokoke_register_privacy_item (NULL, NULL, NULL);
 
-            while ((view = midori_browser_get_nth_tab (mit->browser, i++)))
-                midori_browser_close_tab (mit->browser, view);
+            children = midori_browser_get_tabs (mit->browser);
+            for (; children; children = g_list_next (children))
+                midori_browser_close_tab (mit->browser, children->data);
+            g_list_free (children);
             midori_browser_set_current_uri (mit->browser, mit->uri);
             /* Clear all private data */
             if (history != NULL)
diff --git a/midori/midori-browser.c b/midori/midori-browser.c
index 1211567..0514258 100644
--- a/midori/midori-browser.c
+++ b/midori/midori-browser.c
@@ -8025,7 +8025,12 @@ midori_browser_get_tabs (MidoriBrowser* browser)
 {
     g_return_val_if_fail (MIDORI_IS_BROWSER (browser), NULL);
 
+    #ifdef HAVE_GRANITE
+    /* FIXME: granite doesn't correctly implemented gtk.container */
+    return granite_widgets_dynamic_notebook_get_children (GRANITE_WIDGETS_DYNAMIC_NOTEBOOK (browser->notebook));
+    #else
     return gtk_container_get_children (GTK_CONTAINER (browser->notebook));
+    #endif
 }
 
 /**


More information about the Xfce4-commits mailing list