mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
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:
parent
93d05c6a8e
commit
51ecd372f2
@ -281,9 +281,9 @@ def add_news(cache, path, arg, dbapi=None):
|
||||
if mi.series_index is None:
|
||||
mi.series_index = cache._get_next_series_num_for(mi.series)
|
||||
mi.tags = [_('News')]
|
||||
if arg['add_title_tag']:
|
||||
if arg.get('add_title_tag'):
|
||||
mi.tags += [arg['title']]
|
||||
if arg['custom_tags']:
|
||||
if arg.get('custom_tags'):
|
||||
mi.tags += arg['custom_tags']
|
||||
if mi.pubdate is None:
|
||||
mi.pubdate = utcnow()
|
||||
|
@ -48,6 +48,21 @@ class FetchNewsAction(InterfaceAction):
|
||||
self.gui.library_view.model().delete_books_by_id,
|
||||
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):
|
||||
func, args, desc, fmt, temp_files = \
|
||||
fetch_scheduled_recipe(arg)
|
||||
|
@ -38,6 +38,11 @@ class CustomRecipeModel(QAbstractListModel): # {{{
|
||||
if row > -1 and row < self.rowCount():
|
||||
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):
|
||||
for x in self.recipe_model.custom_recipe_collection:
|
||||
if x.get('title', False) == title:
|
||||
@ -194,6 +199,10 @@ class RecipeList(QWidget): # {{{
|
||||
b.clicked.connect(self.remove)
|
||||
b.setSizePolicy(QSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed))
|
||||
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()
|
||||
v.selectionModel().currentRowChanged.connect(self.recipe_selected)
|
||||
@ -247,6 +256,15 @@ class RecipeList(QWidget): # {{{
|
||||
if self.model.rowCount() == 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):
|
||||
return self.model.has_title(title)
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user