Fetch news: Add a sub-menu to the right click menu of the Fetch news button that shows recently downloaded news sources. See #2119557 ([Enhancement] Star news)

This commit is contained in:
Kovid Goyal 2025-08-20 20:43:54 +05:30
parent d1e0953a21
commit ad6ead026e
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -11,6 +11,7 @@ import textwrap
from collections import OrderedDict
from contextlib import suppress
from datetime import timedelta
from functools import lru_cache, partial
from qt.core import (
QAction,
@ -52,6 +53,7 @@ from calibre import force_unicode
from calibre.gui2 import config as gconf
from calibre.gui2 import error_dialog, gprefs
from calibre.gui2.search_box import SearchBox2
from calibre.utils.config import JSONConfig
from calibre.utils.date import utcnow
from calibre.utils.localization import canonicalize_lang, get_lang
from calibre.utils.network import internet_connected
@ -59,6 +61,11 @@ from calibre.web.feeds.recipes.model import RecipeModel
from polyglot.builtins import iteritems
@lru_cache(2)
def sprefs():
return JSONConfig('recipe-scheduler')
def convert_day_time_schedule(val):
day_of_week, hour, minute = val
if day_of_week == -1:
@ -640,6 +647,10 @@ class Scheduler(QObject):
QIcon.ic('download-metadata.png'),
_('Download all scheduled news sources'),
self.download_all_scheduled)
self.recent_menu = m = QMenu(_('Redownload...'))
m.addAction('dummy')
m.aboutToShow.connect(self.populate_recent_menu)
self.news_menu.addMenu(m)
self.timer = QTimer(self)
self.timer.start(int(self.INTERVAL * 60 * 1000))
@ -647,6 +658,20 @@ class Scheduler(QObject):
self.oldest = gconf['oldest_news']
QTimer.singleShot(5 * 1000, self.oldest_check)
def populate_recent_menu(self):
m: QMenu = self.recent_menu
m.clear()
p = sprefs()
history = p.get('history', ())
if history:
for arg in reversed(history):
ac = QAction(arg['title'], m)
m.addAction(ac)
ac.triggered.connect(partial(self.download, arg['urn']))
else:
nrdnac = QAction(_('No recently downloaded news'), m)
m.addAction(nrdnac)
@property
def db(self):
from calibre.gui2.ui import get_gui
@ -719,6 +744,13 @@ class Scheduler(QObject):
def recipe_downloaded(self, arg):
self.lock.lock()
p = sprefs()
history = p.get('history', [])
history = [a for a in history if a['urn'] != arg['urn']]
history.append(arg)
if len(history) > (limit := 20):
history = history[len(history)-limit:]
p.set('history', history)
try:
self.recipe_model.update_last_downloaded(arg['urn'])
self.download_queue.remove(arg['urn'])