From 7b1e665186857c4803995ee090103b30a0cd3186 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Wed, 9 Oct 2019 16:26:38 +0530 Subject: [PATCH] Viewer: Show nicer error message for DRMed books Fixes #1847468 [Error when reading DRM protected file from amazon](https://bugs.launchpad.net/calibre/+bug/1847468) --- src/calibre/gui2/viewer/ui.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/calibre/gui2/viewer/ui.py b/src/calibre/gui2/viewer/ui.py index 8949c8a5ed..c8ea46f6eb 100644 --- a/src/calibre/gui2/viewer/ui.py +++ b/src/calibre/gui2/viewer/ui.py @@ -19,6 +19,7 @@ from PyQt5.Qt import ( from calibre import prints from calibre.customize.ui import available_input_formats from calibre.gui2 import choose_files, error_dialog +from calibre.gui2.dialogs.drm_error import DRMErrorMessage from calibre.gui2.image_popup import ImagePopup from calibre.gui2.main_window import MainWindow from calibre.gui2.viewer.annotations import ( @@ -320,9 +321,14 @@ class EbookViewer(MainWindow): open_at, self.pending_open_at = self.pending_open_at, None if not ok: self.setWindowTitle(self.base_window_title) - error_dialog(self, _('Loading book failed'), _( - 'Failed to open the book at {0}. Click "Show details" for more info.').format(data['pathtoebook']), - det_msg=data['tb'], show=True) + tb = data['tb'] + last_line = tuple(tb.strip().splitlines())[-1] + if last_line.startswith('calibre.ebooks.DRMError'): + DRMErrorMessage(self).exec_() + else: + error_dialog(self, _('Loading book failed'), _( + 'Failed to open the book at {0}. Click "Show details" for more info.').format(data['pathtoebook']), + det_msg=data['tb'], show=True) self.web_view.show_home_page() return set_book_path(data['base'], data['pathtoebook'])