Merge branch 'history-clear' of https://github.com/EliteTK/qutebrowser into EliteTK-history-clear
This commit is contained in:
commit
21d53b0265
@ -25,6 +25,7 @@ import collections
|
|||||||
from PyQt5.QtCore import pyqtSignal, QUrl
|
from PyQt5.QtCore import pyqtSignal, QUrl
|
||||||
from PyQt5.QtWebKit import QWebHistoryInterface
|
from PyQt5.QtWebKit import QWebHistoryInterface
|
||||||
|
|
||||||
|
from qutebrowser.commands import cmdutils
|
||||||
from qutebrowser.utils import utils, objreg, standarddir, log
|
from qutebrowser.utils import utils, objreg, standarddir, log
|
||||||
from qutebrowser.config import config
|
from qutebrowser.config import config
|
||||||
from qutebrowser.misc import lineparser
|
from qutebrowser.misc import lineparser
|
||||||
@ -72,10 +73,12 @@ class WebHistory(QWebHistoryInterface):
|
|||||||
arg: The new HistoryEntry.
|
arg: The new HistoryEntry.
|
||||||
item_added: Emitted after a new HistoryEntry is added.
|
item_added: Emitted after a new HistoryEntry is added.
|
||||||
arg: The new HistoryEntry.
|
arg: The new HistoryEntry.
|
||||||
|
cleared: Emitted after the history is cleared.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
add_completion_item = pyqtSignal(HistoryEntry)
|
add_completion_item = pyqtSignal(HistoryEntry)
|
||||||
item_added = pyqtSignal(HistoryEntry)
|
item_added = pyqtSignal(HistoryEntry)
|
||||||
|
cleared = pyqtSignal()
|
||||||
async_read_done = pyqtSignal()
|
async_read_done = pyqtSignal()
|
||||||
|
|
||||||
def __init__(self, parent=None):
|
def __init__(self, parent=None):
|
||||||
@ -169,6 +172,16 @@ class WebHistory(QWebHistoryInterface):
|
|||||||
self._lineparser.save()
|
self._lineparser.save()
|
||||||
self._saved_count = len(self._new_history)
|
self._saved_count = len(self._new_history)
|
||||||
|
|
||||||
|
@cmdutils.register(name='history-clear', instance='web-history')
|
||||||
|
def clear(self):
|
||||||
|
"""Clear all history entries."""
|
||||||
|
self._lineparser.clear()
|
||||||
|
self._history_dict.clear()
|
||||||
|
self._temp_history.clear()
|
||||||
|
self._new_history.clear()
|
||||||
|
self._saved_count = 0
|
||||||
|
self.cleared.emit()
|
||||||
|
|
||||||
def addHistoryEntry(self, url_string):
|
def addHistoryEntry(self, url_string):
|
||||||
"""Called by WebKit when an URL should be added to the history.
|
"""Called by WebKit when an URL should be added to the history.
|
||||||
|
|
||||||
|
@ -76,6 +76,7 @@ class UrlCompletionModel(base.BaseCompletionModel):
|
|||||||
for entry in history:
|
for entry in history:
|
||||||
self._add_history_entry(entry)
|
self._add_history_entry(entry)
|
||||||
self._history.add_completion_item.connect(self.on_history_item_added)
|
self._history.add_completion_item.connect(self.on_history_item_added)
|
||||||
|
self._history.cleared.connect(self.on_history_cleared)
|
||||||
|
|
||||||
objreg.get('config').changed.connect(self.reformat_timestamps)
|
objreg.get('config').changed.connect(self.reformat_timestamps)
|
||||||
|
|
||||||
@ -130,6 +131,10 @@ class UrlCompletionModel(base.BaseCompletionModel):
|
|||||||
else:
|
else:
|
||||||
self._add_history_entry(entry)
|
self._add_history_entry(entry)
|
||||||
|
|
||||||
|
@pyqtSlot()
|
||||||
|
def on_history_cleared(self):
|
||||||
|
self._history_cat.removeRows(0, self._history_cat.rowCount())
|
||||||
|
|
||||||
def _remove_item(self, data, category, column):
|
def _remove_item(self, data, category, column):
|
||||||
"""Helper function for on_quickmark_removed and on_bookmark_removed.
|
"""Helper function for on_quickmark_removed and on_bookmark_removed.
|
||||||
|
|
||||||
|
@ -125,6 +125,10 @@ class BaseLineParser(QObject):
|
|||||||
"""Save the history to disk."""
|
"""Save the history to disk."""
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
|
def clear(self):
|
||||||
|
"""Clear the contents of the file."""
|
||||||
|
raise NotImplementedError
|
||||||
|
|
||||||
|
|
||||||
class AppendLineParser(BaseLineParser):
|
class AppendLineParser(BaseLineParser):
|
||||||
|
|
||||||
@ -183,6 +187,15 @@ class AppendLineParser(BaseLineParser):
|
|||||||
self.new_data = []
|
self.new_data = []
|
||||||
self._after_save()
|
self._after_save()
|
||||||
|
|
||||||
|
def clear(self):
|
||||||
|
do_save = self._prepare_save()
|
||||||
|
if not do_save:
|
||||||
|
return
|
||||||
|
with self._open('w') as f:
|
||||||
|
pass
|
||||||
|
self.new_data = []
|
||||||
|
self._after_save()
|
||||||
|
|
||||||
|
|
||||||
class LineParser(BaseLineParser):
|
class LineParser(BaseLineParser):
|
||||||
|
|
||||||
@ -237,6 +250,9 @@ class LineParser(BaseLineParser):
|
|||||||
self._opened = False
|
self._opened = False
|
||||||
self._after_save()
|
self._after_save()
|
||||||
|
|
||||||
|
def clear(self):
|
||||||
|
self.data = []
|
||||||
|
self.save()
|
||||||
|
|
||||||
class LimitLineParser(LineParser):
|
class LimitLineParser(LineParser):
|
||||||
|
|
||||||
@ -289,3 +305,7 @@ class LimitLineParser(LineParser):
|
|||||||
with qtutils.savefile_open(self._configfile, self._binary) as f:
|
with qtutils.savefile_open(self._configfile, self._binary) as f:
|
||||||
self._write(f, self.data[-limit:])
|
self._write(f, self.data[-limit:])
|
||||||
self._after_save()
|
self._after_save()
|
||||||
|
|
||||||
|
def clear(self):
|
||||||
|
self.data = []
|
||||||
|
self.save()
|
||||||
|
Loading…
Reference in New Issue
Block a user