From a2f3490aca4588a171f4f82e6d12d7d60cb2a6bc Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Thu, 13 Oct 2016 09:58:00 +0530 Subject: [PATCH] Edit Book: Add a tool to download external resources (images/stylesheets/etc) that are not included in the book. Fixes #1620058 [[Enhancement] External image links](https://bugs.launchpad.net/calibre/+bug/1620058) --- src/calibre/gui2/tweak_book/boss.py | 19 +++++++++++++++++++ src/calibre/gui2/tweak_book/ui.py | 5 ++++- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/src/calibre/gui2/tweak_book/boss.py b/src/calibre/gui2/tweak_book/boss.py index 86136a05ae..41d850d194 100644 --- a/src/calibre/gui2/tweak_book/boss.py +++ b/src/calibre/gui2/tweak_book/boss.py @@ -583,6 +583,25 @@ class Boss(QObject): return self.show_current_diff() + def get_external_resources(self): + if not self.ensure_book(_('You must first open a book in order to transform styles.')): + return + from calibre.gui2.tweak_book.download import DownloadResources + with BusyCursor(): + self.add_savepoint(_('Before get external resources')) + try: + d = DownloadResources(self.gui) + d.exec_() + except Exception: + self.rewind_savepoint() + raise + if d.resources_replaced: + self.apply_container_update_to_gui() + if d.show_diff: + self.show_current_diff() + else: + self.rewind_savepoint() + def manage_fonts(self): self.commit_all_editors_to_container() self.gui.manage_fonts.display() diff --git a/src/calibre/gui2/tweak_book/ui.py b/src/calibre/gui2/tweak_book/ui.py index 74f03c251c..5e48630376 100644 --- a/src/calibre/gui2/tweak_book/ui.py +++ b/src/calibre/gui2/tweak_book/ui.py @@ -399,7 +399,9 @@ class Main(MainWindow): 'Check external links in the book')) self.action_compress_images = treg('compress-image.png', _('Compress &images losslessly'), self.boss.compress_images, 'compress-images', (), _( 'Compress images losslessly')) - self.action_transform_styles = treg('wizard.png', _('Transform &styles'), self.boss.transform_styles, 'transform-styles', (), _( + self.action_transform_styles = treg('wizard.png', _('Transform &styles'), self.boss.transform_styles, 'get-external-resources', (), _( + 'Download external resources in the book (images/stylesheets/etc/ that are not included in the book)')) + self.action_get_ext_resources = treg('download-metadata.png', _('Get external &resources'), self.boss.get_external_resources, 'transform-styles', (), _( 'Transform styles used in the book')) def ereg(icon, text, target, sid, keys, description): @@ -564,6 +566,7 @@ class Main(MainWindow): e.addAction(self.action_filter_css) e.addAction(self.action_spell_check_book) e.addAction(self.action_check_external_links) + e.addAction(self.action_get_ext_resources) e.addAction(self.action_check_book) e.addAction(self.action_reports)