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