From 81c65dbe974e857cb98fd61e939e228f61d0fbf5 Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Wed, 5 Feb 2014 15:17:58 +0100 Subject: [PATCH] Handle title changes correctly --- qutebrowser/app.py | 1 + qutebrowser/widgets/browser.py | 21 ++++++++------------- 2 files changed, 9 insertions(+), 13 deletions(-) diff --git a/qutebrowser/app.py b/qutebrowser/app.py index 283746fc0..b87ac0910 100644 --- a/qutebrowser/app.py +++ b/qutebrowser/app.py @@ -284,6 +284,7 @@ class QuteBrowser(QApplication): # pages tab = self.mainwindow.tabs.currentWidget() tab.setUrl(QUrl('about:pyeval')) + tab.titleChanged.emit('about:pyeval') tab.setContent(out.encode('UTF-8'), 'text/plain') def crash(self): diff --git a/qutebrowser/widgets/browser.py b/qutebrowser/widgets/browser.py index 738d8c4a3..78994ff6d 100644 --- a/qutebrowser/widgets/browser.py +++ b/qutebrowser/widgets/browser.py @@ -57,6 +57,7 @@ class TabbedBrowser(TabWidget): Also connect all the signals we need to _filter_signals. """ + logging.debug("Opening {}".format(url)) url = utils.qurl(url) tab = BrowserTab(self) tab.openurl(url) @@ -70,10 +71,6 @@ class TabbedBrowser(TabWidget): self._filter_factory(self.cur_statusbar_message)) tab.scroll_pos_changed.connect( self._filter_factory(self.cur_scroll_perc_changed)) - # FIXME should we really bind this to loadStarted? Sometimes the URL - # isn't set correctly at this point, e.g. when doing - # setContent(..., baseUrl=QUrl('foo')) - tab.loadStarted.connect(self._loadStarted_handler) tab.titleChanged.connect(self._titleChanged_handler) # FIXME sometimes this doesn't load tab.open_tab.connect(self.tabopen) @@ -312,16 +309,11 @@ class TabbedBrowser(TabWidget): Slot for the titleChanged signal of any tab. """ + logging.debug('title changed to "{}"'.format(text)) if text: self.setTabText(self.indexOf(self.sender()), text) - - def _loadStarted_handler(self): - """Set url as the title of a tab after it loaded. - - Slot for the loadStarted signal of any tab. - """ - s = self.sender() - self.setTabText(self.indexOf(s), s.url().toString()) + else: + logging.debug('ignoring title change') def _filter_factory(self, signal): """Returns a partial functon calling _filter_signals with a signal.""" @@ -394,7 +386,10 @@ class BrowserTab(QWebView): url -- The URL to load, as string or QUrl. """ - return self.load(utils.qurl(url)) + qurl = utils.qurl(url) + logging.debug('New title: {}'.format(qurl.url())) + self.titleChanged.emit(qurl.url()) + return self.load(qurl) def link_handler(self, url): """Handle a link.