From 680f599f3204bfcc82cfa4a5f40a2ad4e45a5e1c Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sun, 31 Aug 2014 14:01:05 +0530 Subject: [PATCH] View specific format window: If a conversion finishes in the background making a new format available, update the window. Fixes #1363416 [[Feature Request] eBook conversion jobs should automatically update the book's "View specific format" window upon job completion](https://bugs.launchpad.net/calibre/+bug/1363416) --- src/calibre/gui2/actions/convert.py | 1 + src/calibre/gui2/actions/view.py | 10 ++++++---- src/calibre/gui2/dialogs/choose_format.py | 7 +++++++ src/calibre/gui2/ui.py | 1 + 4 files changed, 15 insertions(+), 4 deletions(-) diff --git a/src/calibre/gui2/actions/convert.py b/src/calibre/gui2/actions/convert.py index 3421d2596b..20daaed007 100644 --- a/src/calibre/gui2/actions/convert.py +++ b/src/calibre/gui2/actions/convert.py @@ -259,6 +259,7 @@ class ConvertAction(InterfaceAction): with open(temp_files[-1].name, 'rb') as data: db.add_format(book_id, fmt, data, index_is_id=True) + self.gui.book_converted.emit(book_id, fmt) self.gui.status_bar.show_message(job.description + (' completed'), 2000) finally: diff --git a/src/calibre/gui2/actions/view.py b/src/calibre/gui2/actions/view.py index 3aff423c50..29d09bb8b5 100644 --- a/src/calibre/gui2/actions/view.py +++ b/src/calibre/gui2/actions/view.py @@ -158,8 +158,8 @@ class ViewAction(InterfaceAction): db = self.gui.library_view.model().db rows = [r.row() for r in rows] - formats = [db.formats(row) for row in rows] - formats = [list(f.upper().split(',')) if f else None for f in formats] + book_ids = [db.id(r) for r in rows] + formats = [[x.upper() for x in db.new_api.formats(book_id)] for book_id in book_ids] all_fmts = set([]) for x in formats: if x: @@ -171,7 +171,9 @@ class ViewAction(InterfaceAction): return d = ChooseFormatDialog(self.gui, _('Choose the format to view'), list(sorted(all_fmts))) + self.gui.book_converted.connect(d.book_converted) if d.exec_() == d.Accepted: + formats = [[x.upper() for x in db.new_api.formats(book_id)] for book_id in book_ids] fmt = d.format() orig_num = len(rows) rows = [rows[i] for i in range(len(rows)) if formats[i] and fmt in @@ -184,6 +186,7 @@ class ViewAction(InterfaceAction): _('Not all the selected books were available in' ' the %s format. You should convert' ' them first.')%fmt, show=True) + self.gui.book_converted.disconnect(d.book_converted) def _view_check(self, num, max_=3): if num <= max_: @@ -283,8 +286,7 @@ class ViewAction(InterfaceAction): self.persistent_files.append(pt) pt.close() self.gui.device_manager.view_book( - Dispatcher(self.book_downloaded_for_viewing), - path, pt.name) + Dispatcher(self.book_downloaded_for_viewing), path, pt.name) def _view_books(self, rows): if not rows or len(rows) == 0: diff --git a/src/calibre/gui2/dialogs/choose_format.py b/src/calibre/gui2/dialogs/choose_format.py index 713c986c64..44df11e12e 100644 --- a/src/calibre/gui2/dialogs/choose_format.py +++ b/src/calibre/gui2/dialogs/choose_format.py @@ -22,6 +22,13 @@ class ChooseFormatDialog(QDialog, Ui_ChooseFormatDialog): self.formats.setCurrentRow(0) self._format = None + def book_converted(self, book_id, fmt): + fmt = fmt.upper() + if fmt not in self._formats: + self._formats.append(fmt) + self.formats.addItem(QListWidgetItem( + file_icon_provider().icon_from_ext(fmt.lower()), fmt.upper())) + def activated_slot(self, *args): self.accept() diff --git a/src/calibre/gui2/ui.py b/src/calibre/gui2/ui.py index ee9cd006a1..d2ec5ee38a 100644 --- a/src/calibre/gui2/ui.py +++ b/src/calibre/gui2/ui.py @@ -142,6 +142,7 @@ class Main(MainWindow, MainWindowMixin, DeviceMixin, EmailMixin, # {{{ 'The main GUI' proceed_requested = pyqtSignal(object, object) + book_converted = pyqtSignal(object, object) def __init__(self, opts, parent=None, gui_debug=None): global _gui