Move URL/title handling to AbstractTab

This commit is contained in:
Florian Bruhin 2016-07-11 14:36:57 +02:00
parent a470bfc3f3
commit 5d6eedcd49
4 changed files with 10 additions and 16 deletions

View File

@ -497,6 +497,12 @@ class AbstractTab(QWidget):
self._load_status = val
self.load_status_changed.emit(val.name)
@pyqtSlot(QUrl)
def _on_url_changed(self, url):
"""Update title when URL has changed and no title is available."""
if url.isValid() and not self.title():
self.title_changed.emit(url().toDisplayString())
@pyqtSlot()
def _on_load_started(self):
self._progress = 0
@ -518,6 +524,8 @@ class AbstractTab(QWidget):
else:
self._set_load_status(usertypes.LoadStatus.error)
self.load_finished.emit(ok)
if not self.title():
self.title_changed.emit(self.url().toDisplayString())
@pyqtSlot(int)
def _on_load_progress(self, perc):

View File

@ -261,6 +261,7 @@ class WebEngineTab(browsertab.AbstractTab):
self.backend = usertypes.Backend.QtWebEngine
def openurl(self, url):
self.title_changed.emit(url.toDisplayString())
self._widget.load(url)
def url(self):

View File

@ -467,6 +467,7 @@ class WebKitTab(browsertab.AbstractTab):
self.backend = usertypes.Backend.QtWebKit
def openurl(self, url):
self.title_changed.emit(url.toDisplayString())
self._widget.openurl(url)
def url(self):

View File

@ -96,7 +96,6 @@ class WebView(QWebView):
mode_manager.left.connect(self.on_mode_left)
if config.get('input', 'rocker-gestures'):
self.setContextMenuPolicy(Qt.PreventContextMenu)
self.urlChanged.connect(self.on_url_changed)
objreg.get('config').changed.connect(self.on_config_changed)
@pyqtSlot()
@ -287,9 +286,6 @@ class WebView(QWebView):
url: The URL to load as QUrl
"""
qtutils.ensure_valid(url)
urlstr = url.toDisplayString()
log.webview.debug("New title: {}".format(urlstr))
self.titleChanged.emit(urlstr)
self.load(url)
if url.scheme() == 'qute':
frame = self.page().mainFrame()
@ -308,16 +304,6 @@ class WebView(QWebView):
bridge = objreg.get('js-bridge')
frame.addToJavaScriptWindowObject('qute', bridge)
@pyqtSlot('QUrl')
def on_url_changed(self, url):
"""Update title when URL has changed.
If the URL is invalid, we just ignore it here.
"""
if url.isValid():
if not self.title():
self.titleChanged.emit(self.url().toDisplayString())
@pyqtSlot('QMouseEvent')
def on_mouse_event(self, evt):
"""Post a new mouse event from a hintmanager."""
@ -334,8 +320,6 @@ class WebView(QWebView):
See https://github.com/The-Compiler/qutebrowser/issues/84
"""
ok = not self.page().error_occurred
if not self.title():
self.titleChanged.emit(self.url().toDisplayString())
self._handle_auto_insert_mode(ok)
def _handle_auto_insert_mode(self, ok):