Permalink
Browse files

Move history triggering out of WebView

  • Loading branch information...
The-Compiler committed Aug 10, 2016
1 parent eed3460 commit 77531d09df3ff891f57843a0752379017c05760c
@@ -455,6 +455,7 @@ class AbstractTab(QWidget):
url_changed = pyqtSignal(QUrl)
shutting_down = pyqtSignal()
contents_size_changed = pyqtSignal(QSizeF)
+ add_history_item = pyqtSignal(QUrl, QUrl, str) # url, requested url, title
def __init__(self, win_id, parent=None):
self.win_id = win_id
@@ -533,6 +534,13 @@ def _on_load_finished(self, ok):
if not self.title():
self.title_changed.emit(self.url().toDisplayString())
+ @pyqtSlot()
+ def _on_history_trigger(self):
+ """Emit add_history_item when triggered by backend-specific signal."""
+ url = self.url()
+ requested_url = self.url(requested=True)
+ self.add_history_item.emit(url, requested_url, self.title())
+
@pyqtSlot(int)
def _on_load_progress(self, perc):
self._progress = perc
@@ -22,7 +22,7 @@
import time
import collections
-from PyQt5.QtCore import pyqtSignal, QUrl, QObject
+from PyQt5.QtCore import pyqtSignal, pyqtSlot, QUrl, QObject
from PyQt5.QtWebKit import QWebHistoryInterface
from qutebrowser.commands import cmdutils
@@ -284,6 +284,17 @@ def clear(self):
self._saved_count = 0
self.cleared.emit()
+ @pyqtSlot(QUrl, QUrl, str)
+ def add_from_tab(self, url, requested_url, title):
+ """Add a new history entry as slot, called from a BrowserTab."""
+ no_formatting = QUrl.UrlFormattingOption(0)
+ if (requested_url.isValid() and
+ not requested_url.matches(url, no_formatting)):
+ # If the url of the page is different than the url of the link
+ # originally clicked, save them both.
+ self.add_url(requested_url, title, redirect=True)
+ self.add_url(url, title)
+
def add_url(self, url, title="", *, redirect=False, atime=None):
"""Called by WebKit when a URL should be added to the history.
@@ -634,3 +634,4 @@ def _connect_signals(self):
view.iconChanged.connect(self._on_webkit_icon_changed)
page.frameCreated.connect(self._on_frame_created)
frame.contentsSizeChanged.connect(self._on_contents_size_changed)
+ frame.initialLayoutCompleted.connect(self._on_history_trigger)
@@ -94,26 +94,11 @@ def __init__(self, win_id, tab_id, tab, parent=None):
self.setContextMenuPolicy(Qt.PreventContextMenu)
objreg.get('config').changed.connect(self.on_config_changed)
- @pyqtSlot()
- def on_initial_layout_completed(self):
- """Add url to history now that we have displayed something."""
- history = objreg.get('web-history')
- no_formatting = QUrl.UrlFormattingOption(0)
- orig_url = self.page().mainFrame().requestedUrl()
- if (orig_url.isValid() and
- not orig_url.matches(self.url(), no_formatting)):
- # If the url of the page is different than the url of the link
- # originally clicked, save them both.
- history.add_url(orig_url, self.title(), redirect=True)
- history.add_url(self.url(), self.title())
-
def _init_page(self):
"""Initialize the QWebPage used by this view."""
page = webpage.BrowserPage(self.win_id, self._tab_id, self)
self.setPage(page)
page.mainFrame().loadFinished.connect(self.on_load_finished)
- page.mainFrame().initialLayoutCompleted.connect(
- self.on_initial_layout_completed)
return page
def __repr__(self):
@@ -198,6 +198,7 @@ def _connect_tab_signals(self, tab):
tab.window_close_requested.connect(
functools.partial(self.on_window_close_requested, tab))
tab.new_tab_requested.connect(self.tabopen)
+ tab.add_history_item.connect(objreg.get('web-history').add_from_tab)
def current_url(self):
"""Get the URL of the current tab.

0 comments on commit 77531d0

Please sign in to comment.