mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Also add cover download to context menu of book info popup
This commit is contained in:
parent
1e2e6bc9bf
commit
f2f2518cbb
@ -236,6 +236,20 @@ def init_find_in_tag_browser(menu, ac, field, value):
|
||||
menu.addAction(ac)
|
||||
|
||||
|
||||
def download_cover(parent, book_id, current_cover_pixmap):
|
||||
from calibre.ebooks.metadata.sources.update import update_sources
|
||||
from calibre.gui2.ui import get_gui
|
||||
update_sources()
|
||||
from calibre.gui2.metadata.single_download import CoverFetch
|
||||
db = get_gui().current_db.new_api
|
||||
title = db.field_for('title', book_id)
|
||||
authors = db.field_for('authors', book_id)
|
||||
identifiers = db.field_for('identifiers', book_id, default_value={})
|
||||
d = CoverFetch(current_cover_pixmap, parent)
|
||||
if d.start(title, authors, identifiers) == QDialog.DialogCode.Accepted:
|
||||
return d.cover_pixmap
|
||||
|
||||
|
||||
def get_icon_path(f, prefix):
|
||||
from calibre.library.field_metadata import category_icon_map
|
||||
custom_icons = gprefs['tags_browser_category_icons']
|
||||
@ -944,19 +958,9 @@ class CoverView(QWidget): # {{{
|
||||
self.update_cover(pmap)
|
||||
|
||||
def download_cover(self):
|
||||
from calibre.ebooks.metadata.sources.update import update_sources
|
||||
from calibre.gui2.ui import get_gui
|
||||
update_sources()
|
||||
from calibre.gui2.metadata.single_download import CoverFetch
|
||||
book_id = self.data.get('id')
|
||||
db = get_gui().current_db.new_api
|
||||
title = db.field_for('title', book_id)
|
||||
authors = db.field_for('authors', book_id)
|
||||
identifiers = db.field_for('identifiers', book_id, default_value={})
|
||||
d = CoverFetch(self.pixmap, self)
|
||||
if d.start(title, authors, identifiers) == QDialog.DialogCode.Accepted:
|
||||
if d.cover_pixmap is not None:
|
||||
self.update_cover(d.cover_pixmap)
|
||||
pmap = download_cover(self, self.data.get('id'), self.pixmap)
|
||||
if pmap is not None:
|
||||
self.update_cover(pmap)
|
||||
|
||||
def save_cover(self):
|
||||
from calibre.gui2.ui import get_gui
|
||||
|
@ -48,6 +48,7 @@ class Cover(CoverView):
|
||||
open_with_requested = pyqtSignal(object)
|
||||
choose_open_with_requested = pyqtSignal()
|
||||
copy_to_clipboard_requested = pyqtSignal()
|
||||
download_cover = pyqtSignal()
|
||||
|
||||
def __init__(self, parent, show_size=False):
|
||||
CoverView.__init__(self, parent, show_size=show_size)
|
||||
@ -58,6 +59,8 @@ class Cover(CoverView):
|
||||
def build_context_menu(self):
|
||||
ans = CoverView.build_context_menu(self)
|
||||
create_open_cover_with_menu(self, ans)
|
||||
download = ans.addAction(QIcon.ic('download-metadata.png'), _('Download cover'))
|
||||
download.triggered.connect(self.download_cover)
|
||||
return ans
|
||||
|
||||
def open_with(self, entry):
|
||||
@ -192,6 +195,7 @@ class BookInfo(QDialog, DropMixin):
|
||||
|
||||
self.cover = Cover(self, show_size=gprefs['bd_overlay_cover_size'])
|
||||
self.cover.copy_to_clipboard_requested.connect(self.copy_cover_to_clipboard)
|
||||
self.cover.download_cover.connect(self.download_cover)
|
||||
self.cover.resizeEvent = self.cover_view_resized
|
||||
self.cover.cover_changed.connect(self.cover_changed)
|
||||
self.cover.open_with_requested.connect(self.open_with)
|
||||
@ -426,6 +430,13 @@ class BookInfo(QDialog, DropMixin):
|
||||
if self.cover_pixmap is not None:
|
||||
QApplication.instance().clipboard().setPixmap(self.cover_pixmap)
|
||||
|
||||
def download_cover(self):
|
||||
from calibre.gui2.book_details import download_cover
|
||||
if self.current_row is not None:
|
||||
book_id = self.view.model().id(self.current_row)
|
||||
if pmap := download_cover(self, book_id, self.cover_pixmap):
|
||||
self.cover_changed(pmap)
|
||||
|
||||
def update_cover_tooltip(self):
|
||||
tt = ''
|
||||
if self.marked:
|
||||
|
Loading…
x
Reference in New Issue
Block a user