Compare history items based on QUrl.

This commit is contained in:
Florian Bruhin 2015-03-16 07:42:10 +01:00
parent 693ea0c312
commit 503060881a
2 changed files with 12 additions and 5 deletions

View File

@ -29,7 +29,8 @@ from PyQt5.QtGui import QStandardItemModel, QStandardItem
from qutebrowser.utils import usertypes, qtutils
Role = usertypes.enum('Role', ['sort'], start=Qt.UserRole, is_int=True)
Role = usertypes.enum('Role', ['sort', 'userdata'], start=Qt.UserRole,
is_int=True)
class BaseCompletionModel(QStandardItemModel):
@ -60,7 +61,8 @@ class BaseCompletionModel(QStandardItemModel):
self.appendRow(cat)
return cat
def new_item(self, cat, name, desc='', misc=None, sort=None):
def new_item(self, cat, name, desc='', misc=None, sort=None,
userdata=None):
"""Add a new item to a category.
Args:
@ -69,6 +71,7 @@ class BaseCompletionModel(QStandardItemModel):
desc: The description of the item.
misc: Misc text to display.
sort: Data for the sort role (int).
userdata: User data to be added for the first column.
Return:
A (nameitem, descitem, miscitem) tuple.
@ -88,6 +91,8 @@ class BaseCompletionModel(QStandardItemModel):
cat.setChild(idx, 2, miscitem)
if sort is not None:
nameitem.setData(sort, Role.sort)
if userdata is not None:
nameitem.setData(userdata, Role.userdata)
return nameitem, descitem, miscitem
def flags(self, index):

View File

@ -68,7 +68,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._fmt_atime(entry.atime), sort=int(entry.atime))
self._fmt_atime(entry.atime), sort=int(entry.atime),
userdata=entry.url)
@config.change_filter('completion', 'timestamp-format')
def reformat_timestamps(self):
@ -82,14 +83,15 @@ class UrlCompletionModel(base.BaseCompletionModel):
@pyqtSlot(object)
def on_history_item_added(self, entry):
"""Slot called when a new history item was added."""
if entry.url:
if entry.url_string:
if self._history.historyContains(entry.url_string):
for i in range(self._history_cat.rowCount()):
name_item = self._history_cat.child(i, 0)
atime_item = self._history_cat.child(i, 2)
if not name_item:
continue
if name_item.text() == entry.url:
url = name_item.data(base.Role.userdata)
if url == entry.url:
atime_item.setText(self._fmt_atime(entry.atime))
name_item.setData(int(entry.atime), base.Role.sort)
break