From 4e20f776bcfc8ebd100a9ed1c4e8bb62148e49e2 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sun, 2 Sep 2012 00:06:54 +0530 Subject: [PATCH] When vieweing a book on the device by clicking in the book details panel, first copy the book off the device, this allows it to work for the smart device driver and the MTP driver --- src/calibre/gui2/actions/view.py | 18 ++++++++++-------- src/calibre/gui2/book_details.py | 7 ++++--- src/calibre/gui2/init.py | 2 ++ 3 files changed, 16 insertions(+), 11 deletions(-) diff --git a/src/calibre/gui2/actions/view.py b/src/calibre/gui2/actions/view.py index 43e9dad5c4..5a7a991607 100644 --- a/src/calibre/gui2/actions/view.py +++ b/src/calibre/gui2/actions/view.py @@ -256,6 +256,15 @@ class ViewAction(InterfaceAction): db.prefs['gui_view_history'] = history[:vh] self.build_menus(db) + def view_device_book(self, path): + pt = PersistentTemporaryFile('_view_device_book'+\ + os.path.splitext(path)[1]) + self.persistent_files.append(pt) + pt.close() + self.gui.device_manager.view_book( + Dispatcher(self.book_downloaded_for_viewing), + path, pt.name) + def _view_books(self, rows): if not rows or len(rows) == 0: self._launch_viewer() @@ -270,12 +279,5 @@ class ViewAction(InterfaceAction): else: paths = self.gui.current_view().model().paths(rows) for path in paths: - pt = PersistentTemporaryFile('_viewer_'+\ - os.path.splitext(path)[1]) - self.persistent_files.append(pt) - pt.close() - self.gui.device_manager.view_book(\ - Dispatcher(self.book_downloaded_for_viewing), - path, pt.name) - + self.view_device_book(path) diff --git a/src/calibre/gui2/book_details.py b/src/calibre/gui2/book_details.py index bf5fbe77bd..f03015f4ad 100644 --- a/src/calibre/gui2/book_details.py +++ b/src/calibre/gui2/book_details.py @@ -19,8 +19,8 @@ from calibre.ebooks.metadata import fmt_sidx from calibre.ebooks.metadata.sources.identify import urls_from_identifiers from calibre.constants import filesystem_encoding from calibre.library.comments import comments_to_html -from calibre.gui2 import (config, open_local_file, open_url, pixmap_to_data, - gprefs, rating_font) +from calibre.gui2 import (config, open_url, pixmap_to_data, gprefs, + rating_font) from calibre.utils.icu import sort_key from calibre.utils.formatter import EvalFormatter from calibre.utils.date import is_date_undefined @@ -569,6 +569,7 @@ class BookDetails(QWidget): # {{{ files_dropped = pyqtSignal(object, object) cover_changed = pyqtSignal(object, object) cover_removed = pyqtSignal(object) + view_device_book = pyqtSignal(object) # Drag 'n drop {{{ DROPABBLE_EXTENSIONS = IMAGE_EXTENSIONS+BOOK_EXTENSIONS @@ -643,7 +644,7 @@ class BookDetails(QWidget): # {{{ id_, fmt = val.split(':') self.view_specific_format.emit(int(id_), fmt) elif typ == 'devpath': - open_local_file(val) + self.view_device_book.emit(val) else: try: open_url(QUrl(link, QUrl.TolerantMode)) diff --git a/src/calibre/gui2/init.py b/src/calibre/gui2/init.py index a82dfec7fc..338a558f29 100644 --- a/src/calibre/gui2/init.py +++ b/src/calibre/gui2/init.py @@ -269,6 +269,8 @@ class LayoutMixin(object): # {{{ self.iactions['Remove Books'].remove_format_by_id) self.book_details.save_specific_format.connect( self.iactions['Save To Disk'].save_library_format_by_ids) + self.book_details.view_device_book.connect( + self.iactions['View'].view_device_book) m = self.library_view.model() if m.rowCount(None) > 0: