Merge branch 'history-title' of https://github.com/toofar/qutebrowser into toofar-history-title
This commit is contained in:
commit
79e0aa2418
@ -41,18 +41,18 @@ class HistoryEntry:
|
||||
url_string: The URL which was accessed as string.
|
||||
"""
|
||||
|
||||
def __init__(self, atime, url):
|
||||
def __init__(self, atime, url, title):
|
||||
self.atime = float(atime)
|
||||
self.url = QUrl(url)
|
||||
self.url_string = url
|
||||
self.title = title
|
||||
|
||||
def __repr__(self):
|
||||
return utils.get_repr(self, constructor=True, atime=self.atime,
|
||||
url=self.url.toDisplayString())
|
||||
url=self.url.toDisplayString(), title=self.title)
|
||||
|
||||
def __str__(self):
|
||||
return '{} {}'.format(int(self.atime), self.url_string)
|
||||
|
||||
return '{} {} {}'.format(int(self.atime), self.url_string, self.title)
|
||||
|
||||
class WebHistory(QWebHistoryInterface):
|
||||
|
||||
@ -121,16 +121,20 @@ class WebHistory(QWebHistoryInterface):
|
||||
with self._lineparser.open():
|
||||
for line in self._lineparser:
|
||||
yield
|
||||
data = line.rstrip().split(maxsplit=1)
|
||||
data = line.rstrip().split(maxsplit=2)
|
||||
if not data:
|
||||
# empty line
|
||||
continue
|
||||
elif len(data) != 2:
|
||||
elif len(data) == 2:
|
||||
atime, url = data
|
||||
title = ""
|
||||
elif len(data) == 3:
|
||||
atime, url, title = data
|
||||
else:
|
||||
# other malformed line
|
||||
log.init.warning("Invalid history entry {!r}!".format(
|
||||
line))
|
||||
continue
|
||||
atime, url = data
|
||||
if atime.startswith('\0'):
|
||||
log.init.debug(
|
||||
"Removing NUL bytes from entry {!r} - see "
|
||||
@ -142,7 +146,7 @@ class WebHistory(QWebHistoryInterface):
|
||||
# information about previous hits change the items in
|
||||
# old_urls to be lists or change HistoryEntry to have a
|
||||
# list of atimes.
|
||||
entry = HistoryEntry(atime, url)
|
||||
entry = HistoryEntry(atime, url, title)
|
||||
self._add_entry(entry)
|
||||
|
||||
self._initial_read_done = True
|
||||
@ -183,6 +187,10 @@ class WebHistory(QWebHistoryInterface):
|
||||
self.cleared.emit()
|
||||
|
||||
def addHistoryEntry(self, url_string):
|
||||
"""Required for a QWebHistoryInterface impl, obseleted by add_url."""
|
||||
pass
|
||||
|
||||
def add_url(self, url_string, title=""):
|
||||
"""Called by WebKit when an URL should be added to the history.
|
||||
|
||||
Args:
|
||||
@ -192,7 +200,7 @@ class WebHistory(QWebHistoryInterface):
|
||||
return
|
||||
if config.get('general', 'private-browsing'):
|
||||
return
|
||||
entry = HistoryEntry(time.time(), url_string)
|
||||
entry = HistoryEntry(time.time(), url_string, title)
|
||||
if self._initial_read_done:
|
||||
self.add_completion_item.emit(entry)
|
||||
self._new_history.append(entry)
|
||||
|
@ -119,6 +119,7 @@ class WebView(QWebView):
|
||||
self.destroyed.connect(functools.partial(
|
||||
cfg.changed.disconnect, self.init_neighborlist))
|
||||
self.cur_url = QUrl()
|
||||
self._orig_url = QUrl()
|
||||
self.progress = 0
|
||||
self.registry = objreg.ObjectRegistry()
|
||||
self.tab_id = next(tab_id_gen)
|
||||
@ -145,6 +146,17 @@ class WebView(QWebView):
|
||||
self.loadProgress.connect(lambda p: setattr(self, 'progress', p))
|
||||
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')
|
||||
if not self._orig_url.matches(self.cur_url,
|
||||
QUrl.UrlFormattingOption(0)):
|
||||
# If the url of the page is different than the url of the link
|
||||
# originally clicked, save them both.
|
||||
history.add_url(self._orig_url.toDisplayString())
|
||||
history.add_url(self.cur_url.toDisplayString(), self.title())
|
||||
|
||||
def _init_page(self):
|
||||
"""Initialize the QWebPage used by this view."""
|
||||
page = webpage.BrowserPage(self.win_id, self.tab_id, self)
|
||||
@ -152,6 +164,8 @@ class WebView(QWebView):
|
||||
page.linkHovered.connect(self.linkHovered)
|
||||
page.mainFrame().loadStarted.connect(self.on_load_started)
|
||||
page.mainFrame().loadFinished.connect(self.on_load_finished)
|
||||
page.mainFrame().initialLayoutCompleted.connect(
|
||||
self.on_initial_layout_completed)
|
||||
page.statusBarMessage.connect(
|
||||
lambda msg: setattr(self, 'statusbar_message', msg))
|
||||
page.networkAccessManager().sslErrors.connect(
|
||||
@ -182,6 +196,8 @@ class WebView(QWebView):
|
||||
log.webview.debug("load status for {}: {}".format(repr(self), val))
|
||||
self.load_status = val
|
||||
self.load_status_changed.emit(val.name)
|
||||
if val == LoadStatus.loading:
|
||||
self._orig_url = self.cur_url
|
||||
|
||||
def _set_bg_color(self):
|
||||
"""Set the webpage background color as configured."""
|
||||
|
@ -100,7 +100,8 @@ class UrlCompletionModel(base.BaseCompletionModel):
|
||||
|
||||
def _add_history_entry(self, entry):
|
||||
"""Add a new history entry to the completion."""
|
||||
self.new_item(self._history_cat, entry.url.toDisplayString(), "",
|
||||
self.new_item(self._history_cat, entry.url.toDisplayString(),
|
||||
entry.title,
|
||||
self._fmt_atime(entry.atime), sort=int(entry.atime),
|
||||
userdata=entry.url)
|
||||
|
||||
@ -123,9 +124,11 @@ class UrlCompletionModel(base.BaseCompletionModel):
|
||||
for i in range(self._history_cat.rowCount()):
|
||||
url_item = self._history_cat.child(i, self.URL_COLUMN)
|
||||
atime_item = self._history_cat.child(i, self.TIME_COLUMN)
|
||||
title_item = self._history_cat.child(i, self.TEXT_COLUMN)
|
||||
url = url_item.data(base.Role.userdata)
|
||||
if url == entry.url:
|
||||
atime_item.setText(self._fmt_atime(entry.atime))
|
||||
title_item.setText(entry.title)
|
||||
url_item.setData(int(entry.atime), base.Role.sort)
|
||||
break
|
||||
else:
|
||||
|
Loading…
Reference in New Issue
Block a user