From e2cc48381d4fa53c5c7e92a10f7aec88fc6fcbba Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Mon, 23 May 2011 11:08:14 -0600 Subject: [PATCH] Nicer error message when user attempts to set title/author via Edit metadata dialog and one of the files is open in another program. --- src/calibre/gui2/metadata/basic_widgets.py | 34 ++++++++++++++++++---- 1 file changed, 28 insertions(+), 6 deletions(-) diff --git a/src/calibre/gui2/metadata/basic_widgets.py b/src/calibre/gui2/metadata/basic_widgets.py index d662256def..d58ac4a379 100644 --- a/src/calibre/gui2/metadata/basic_widgets.py +++ b/src/calibre/gui2/metadata/basic_widgets.py @@ -88,11 +88,22 @@ class TitleEdit(EnLineEdit): def commit(self, db, id_): title = self.current_val - if self.COMMIT: - getattr(db, 'set_'+ self.TITLE_ATTR)(id_, title, notify=False) - else: - getattr(db, 'set_'+ self.TITLE_ATTR)(id_, title, notify=False, - commit=False) + try: + if self.COMMIT: + getattr(db, 'set_'+ self.TITLE_ATTR)(id_, title, notify=False) + else: + getattr(db, 'set_'+ self.TITLE_ATTR)(id_, title, notify=False, + commit=False) + except (IOError, OSError) as err: + if getattr(err, 'errno', -1) == 13: # Permission denied + import traceback + fname = err.filename if err.filename else 'file' + error_dialog(self, _('Permission denied'), + _('Could not open %s. Is it being used by another' + ' program?')%fname, det_msg=traceback.format_exc(), + show=True) + return False + raise return True @dynamic_property @@ -225,8 +236,19 @@ class AuthorsEdit(MultiCompleteComboBox): def commit(self, db, id_): authors = self.current_val - self.books_to_refresh |= db.set_authors(id_, authors, notify=False, + try: + self.books_to_refresh |= db.set_authors(id_, authors, notify=False, allow_case_change=True) + except (IOError, OSError) as err: + if getattr(err, 'errno', -1) == 13: # Permission denied + import traceback + fname = err.filename if err.filename else 'file' + error_dialog(self, _('Permission denied'), + _('Could not open %s. Is it being used by another' + ' program?')%fname, det_msg=traceback.format_exc(), + show=True) + return False + raise return True @dynamic_property