Add a button to download custom recipes to the dialog used for creating recipes. Fixes #1868209 [[Enhancement] Add a Download news button](https://bugs.launchpad.net/calibre/+bug/1868209)

This commit is contained in:
Kovid Goyal 2020-03-24 09:35:01 +05:30
parent 93d05c6a8e
commit 51ecd372f2
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
3 changed files with 35 additions and 2 deletions

View File

@ -281,9 +281,9 @@ def add_news(cache, path, arg, dbapi=None):
if mi.series_index is None: if mi.series_index is None:
mi.series_index = cache._get_next_series_num_for(mi.series) mi.series_index = cache._get_next_series_num_for(mi.series)
mi.tags = [_('News')] mi.tags = [_('News')]
if arg['add_title_tag']: if arg.get('add_title_tag'):
mi.tags += [arg['title']] mi.tags += [arg['title']]
if arg['custom_tags']: if arg.get('custom_tags'):
mi.tags += arg['custom_tags'] mi.tags += arg['custom_tags']
if mi.pubdate is None: if mi.pubdate is None:
mi.pubdate = utcnow() mi.pubdate = utcnow()

View File

@ -48,6 +48,21 @@ class FetchNewsAction(InterfaceAction):
self.gui.library_view.model().delete_books_by_id, self.gui.library_view.model().delete_books_by_id,
type=Qt.QueuedConnection) type=Qt.QueuedConnection)
def download_custom_recipe(self, title, urn):
arg = {'title': title, 'urn': urn, 'username': None, 'password': None}
func, args, desc, fmt, temp_files = fetch_scheduled_recipe(arg)
job = self.gui.job_manager.run_job(
Dispatcher(self.custom_recipe_fetched), func, args=args, description=desc)
self.conversion_jobs[job] = (temp_files, fmt, arg)
self.gui.status_bar.show_message(_('Fetching news from ')+arg['title'], 2000)
def custom_recipe_fetched(self, job):
temp_files, fmt, arg = self.conversion_jobs.pop(job)
fname = temp_files[0].name
if job.failed:
return self.gui.job_exception(job)
self.gui.library_view.model().add_news(fname, arg)
def download_scheduled_recipe(self, arg): def download_scheduled_recipe(self, arg):
func, args, desc, fmt, temp_files = \ func, args, desc, fmt, temp_files = \
fetch_scheduled_recipe(arg) fetch_scheduled_recipe(arg)

View File

@ -38,6 +38,11 @@ class CustomRecipeModel(QAbstractListModel): # {{{
if row > -1 and row < self.rowCount(): if row > -1 and row < self.rowCount():
return self.recipe_model.custom_recipe_collection[row].get('title', '') return self.recipe_model.custom_recipe_collection[row].get('title', '')
def urn(self, index):
row = index.row()
if row > -1 and row < self.rowCount():
return self.recipe_model.custom_recipe_collection[row].get('id')
def has_title(self, title): def has_title(self, title):
for x in self.recipe_model.custom_recipe_collection: for x in self.recipe_model.custom_recipe_collection:
if x.get('title', False) == title: if x.get('title', False) == title:
@ -194,6 +199,10 @@ class RecipeList(QWidget): # {{{
b.clicked.connect(self.remove) b.clicked.connect(self.remove)
b.setSizePolicy(QSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed)) b.setSizePolicy(QSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed))
l.addWidget(b) l.addWidget(b)
self.download_button = b = QPushButton(QIcon(I('download-metadata.png')), _('&Download this recipe'), w)
b.clicked.connect(self.download)
b.setSizePolicy(QSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed))
l.addWidget(b)
self.select_row() self.select_row()
v.selectionModel().currentRowChanged.connect(self.recipe_selected) v.selectionModel().currentRowChanged.connect(self.recipe_selected)
@ -247,6 +256,15 @@ class RecipeList(QWidget): # {{{
if self.model.rowCount() == 0: if self.model.rowCount() == 0:
self.stacks.setCurrentIndex(0) self.stacks.setCurrentIndex(0)
def download(self):
idx = self.view.currentIndex()
if idx.isValid():
urn = self.model.urn(idx)
title = self.model.title(idx)
from calibre.gui2.ui import get_gui
gui = get_gui()
gui.iactions['Fetch News'].download_custom_recipe(title, urn)
def has_title(self, title): def has_title(self, title):
return self.model.has_title(title) return self.model.has_title(title)