mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-08-30 23:00:21 -04:00
Show recipe favicons in recently downloaded list and add menu entry to clear the list
This commit is contained in:
parent
ad6ead026e
commit
a8a9e5792c
@ -666,12 +666,23 @@ class Scheduler(QObject):
|
||||
if history:
|
||||
for arg in reversed(history):
|
||||
ac = QAction(arg['title'], m)
|
||||
ac.setIcon(QIcon(self.recipe_model.favicon_for_urn(arg['urn'])))
|
||||
m.addAction(ac)
|
||||
ac.triggered.connect(partial(self.download, arg['urn']))
|
||||
m.addSeparator()
|
||||
ac = QAction(_('Clear this list'), m)
|
||||
ac.setIcon(QIcon.ic('trash.png'))
|
||||
m.addAction(ac)
|
||||
ac.triggered.connect(self.clear_history)
|
||||
else:
|
||||
nrdnac = QAction(_('No recently downloaded news'), m)
|
||||
m.addAction(nrdnac)
|
||||
|
||||
def clear_history(self):
|
||||
p = sprefs()
|
||||
with suppress(KeyError):
|
||||
del p['history']
|
||||
|
||||
@property
|
||||
def db(self):
|
||||
from calibre.gui2.ui import get_gui
|
||||
|
@ -175,6 +175,7 @@ class RecipeModel(QAbstractItemModel, AdaptSQP):
|
||||
self.custom_icon = (QIcon.ic('user_profile.png'))
|
||||
self.builtin_recipe_collection = get_builtin_recipe_collection()
|
||||
self.scheduler_config = SchedulerConfig()
|
||||
self.favicon_cache = {}
|
||||
try:
|
||||
with zipfile.ZipFile(P('builtin_recipes.zip',
|
||||
allow_user_override=False), 'r') as zf:
|
||||
@ -287,6 +288,20 @@ class RecipeModel(QAbstractItemModel, AdaptSQP):
|
||||
self.root = new_root
|
||||
self.reset()
|
||||
|
||||
def favicon_for_urn(self, urn: str) -> QPixmap:
|
||||
icon = urn[8:] + '.png'
|
||||
if not (p := self.favicon_cache.get(icon)):
|
||||
p = QPixmap()
|
||||
if icon in self.favicons:
|
||||
try:
|
||||
f = P('builtin_recipes.zip', allow_user_override=False)
|
||||
with zipfile.ZipFile(f, 'r') as zf:
|
||||
p.loadFromData(zf.read(self.favicons[icon]))
|
||||
except Exception:
|
||||
pass
|
||||
self.favicon_cache[icon] = p
|
||||
return p
|
||||
|
||||
def reset(self):
|
||||
self.beginResetModel(), self.endResetModel()
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user