From ec04a1a2741b2e4ce497673e01527d8e97e1cdaa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20St=C3=B6sel?= Date: Thu, 13 Sep 2012 21:52:15 +0200 Subject: [PATCH] Fix race condition by introducing switch_page (old, new) So there's no confusion which one is the new, current tab. --- extensions/delayed-load.vala | 18 +++++++++--------- extensions/history-list.vala | 17 +++++++---------- midori/marshal.list | 1 + midori/midori-browser.c | 27 +++++++++++++++++++++++++++ midori/midori.vapi | 1 + 5 files changed, 45 insertions(+), 19 deletions(-) diff --git a/extensions/delayed-load.vala b/extensions/delayed-load.vala index 895296ee..6f6f2545 100644 --- a/extensions/delayed-load.vala +++ b/extensions/delayed-load.vala @@ -132,17 +132,17 @@ namespace DelayedLoad { } } - private void tab_changed (GLib.Object window, GLib.ParamSpec pspec) { - Midori.Browser browser = window as Midori.Browser; - Midori.View? view = browser.tab as Midori.View; + private void tab_changed (Midori.View? old_view, Midori.View? new_view) { + if (new_view != null) { + Midori.App app = get_app (); + Midori.Browser browser = app.browser; - if (view != null) { - Katze.Item item = view.get_proxy_item (); + Katze.Item item = new_view.get_proxy_item (); item.ref(); int64 delay = item.get_meta_integer ("delay"); - if (delay == -2 && view.progress < 1.0) { - this.schedule_reload (browser, view); + if (delay == -2 && new_view.progress < 1.0) { + this.schedule_reload (browser, new_view); } } } @@ -176,11 +176,11 @@ namespace DelayedLoad { } private void browser_added (Midori.Browser browser) { - browser.notify["tab"].connect (this.tab_changed); + browser.switch_tab.connect_after (this.tab_changed); } private void browser_removed (Midori.Browser browser) { - browser.notify["tab"].disconnect (this.tab_changed); + browser.switch_tab.disconnect (this.tab_changed); } public void activated (Midori.App app) { diff --git a/extensions/history-list.vala b/extensions/history-list.vala index 44af649f..83aee2c2 100644 --- a/extensions/history-list.vala +++ b/extensions/history-list.vala @@ -462,7 +462,7 @@ namespace HistoryList { tab_added (browser, tab); browser.add_tab.connect (tab_added); browser.remove_tab.connect (tab_removed); - browser.notify["tab"].connect (this.tab_changed); + browser.switch_tab.connect (this.tab_changed); } void browser_removed (Midori.Browser browser) { @@ -491,7 +491,7 @@ namespace HistoryList { browser.add_tab.disconnect (tab_added); browser.remove_tab.disconnect (tab_removed); - browser.notify["tab"].disconnect (this.tab_changed); + browser.switch_tab.disconnect (this.tab_changed); } void tab_added (Midori.Browser browser, Midori.View view) { @@ -520,21 +520,18 @@ namespace HistoryList { } } - void tab_changed (GLib.Object window, GLib.ParamSpec pspec) { + void tab_changed (Midori.View? old_view, Midori.View? new_view) { if(this.ignoreNextChange) { this.ignoreNextChange = false; } else { - Midori.Browser browser = window as Midori.Browser; - Midori.View view = null; - Midori.View last_view = null; - browser.get ("tab", ref view); - - last_view = browser.get_data ("history-list-last-change"); + Midori.Browser browser = history_window as Midori.Browser; + Midori.View? last_view + = browser.get_data ("history-list-last-change"); if (last_view != null) { this.tab_list_resort (browser, last_view); } - browser.set_data ("history-list-last-change", view); + browser.set_data ("history-list-last-change", new_view); } } diff --git a/midori/marshal.list b/midori/marshal.list index b0808f8a..df8bfd3f 100644 --- a/midori/marshal.list +++ b/midori/marshal.list @@ -6,6 +6,7 @@ OBJECT:OBJECT VOID:BOOLEAN,STRING VOID:OBJECT,ENUM,BOOLEAN VOID:OBJECT,INT,INT +VOID:OBJECT,OBJECT VOID:POINTER,INT VOID:STRING,BOOLEAN VOID:STRING,INT,STRING diff --git a/midori/midori-browser.c b/midori/midori-browser.c index dc1c1f36..cec7517c 100644 --- a/midori/midori-browser.c +++ b/midori/midori-browser.c @@ -145,6 +145,7 @@ enum ADD_TAB, REMOVE_TAB, MOVE_TAB, + SWITCH_TAB, ACTIVATE_ACTION, ADD_DOWNLOAD, SEND_NOTIFICATION, @@ -1884,6 +1885,28 @@ midori_browser_class_init (MidoriBrowserClass* class) G_TYPE_NONE, 3, GTK_TYPE_NOTEBOOK, G_TYPE_INT, G_TYPE_INT); + /** + * MidoriBrowser::switch-tab: + * @browser: the object on which the signal is emitted + * @old_view: the previous tab + * @new_view: the new tab + * + * Emitted when a tab is switched. + * There's no guarantee what the current tab is. + * + * Since: 0.4.7 + */ + signals[SWITCH_TAB] = g_signal_new ( + "switch-tab", + G_TYPE_FROM_CLASS (class), + (GSignalFlags)(G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION), + 0, + 0, + NULL, + midori_cclosure_marshal_VOID__OBJECT_OBJECT, + G_TYPE_NONE, 2, + G_TYPE_POINTER, G_TYPE_POINTER); + signals[ACTIVATE_ACTION] = g_signal_new ( "activate-action", G_TYPE_FROM_CLASS (class), @@ -5107,7 +5130,10 @@ midori_browser_switched_tab (MidoriBrowser* browser, } if (new_view == NULL) + { + g_signal_emit (browser, signals[SWITCH_TAB], 0, old_widget, new_view); return; + } g_return_if_fail (MIDORI_IS_VIEW (new_view)); @@ -5123,6 +5149,7 @@ midori_browser_switched_tab (MidoriBrowser* browser, if (browser->proxy_array) katze_item_set_meta_integer (KATZE_ITEM (browser->proxy_array), "current", new_page); g_object_notify (G_OBJECT (browser), "tab"); + g_signal_emit (browser, signals[SWITCH_TAB], 0, old_widget, new_view); _midori_browser_set_statusbar_text (browser, new_view, NULL); _midori_browser_update_interface (browser, new_view); diff --git a/midori/midori.vapi b/midori/midori.vapi index 3e984b07..62688c7b 100644 --- a/midori/midori.vapi +++ b/midori/midori.vapi @@ -82,6 +82,7 @@ namespace Midori { public signal void add_tab (View tab); [HasEmitter] public signal void remove_tab (View tab); + public signal void switch_tab (View? old_view, View? new_view); [HasEmitter] public signal void activate_action (string name); public signal void add_download (GLib.Object download);