From be1dc747b54d75f3c206e00f320ee3b62fb308c5 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sun, 18 May 2008 09:32:37 -0700 Subject: [PATCH] Fix bug that sometimes breaks adding books to newly purchased PRS500 --- src/calibre/devices/prs500/books.py | 1 + src/calibre/gui2/main.py | 39 +++++++++++++++++++++-------- 2 files changed, 29 insertions(+), 11 deletions(-) diff --git a/src/calibre/devices/prs500/books.py b/src/calibre/devices/prs500/books.py index 5308a7dcc7..db25e7d14c 100644 --- a/src/calibre/devices/prs500/books.py +++ b/src/calibre/devices/prs500/books.py @@ -155,6 +155,7 @@ class BookList(_BookList): src = src.decode('latin1') except UnicodeDecodeError: src = src.decode('cp1252') + src = src.replace('For help visit %s.kovidgoyal.net
')%(__appname__, __appname__) + self.vanity_template += _('%s: %s by Kovid Goyal %%(version)s
%%(device)s

')%(__appname__, __version__) self.latest_version = ' ' self.vanity.setText(self.vanity_template%dict(version=' ', device=' ')) self.device_info = ' ' @@ -198,6 +206,13 @@ class Main(MainWindow, Ui_MainWindow): self.news_menu.set_custom_feeds(self.library_view.model().db.get_feeds()) + def another_instance_wants_to_talk(self, msg): + if msg.startswith('launched:'): + self.setWindowState(self.windowState() & ~Qt.WindowMinimized|Qt.WindowActive) + self.show() + self.raise_() + self.activateWindow() + def current_view(self): '''Convenience method that returns the currently visible view ''' @@ -258,7 +273,8 @@ class Main(MainWindow, Ui_MainWindow): Called once metadata has been read for all books on the device. ''' if exception: - if 'not well-formed' in str(exception): + print exception, type(exception) + if isinstance(exception, ExpatError): error_dialog(self, _('Device database corrupted'), _('''

The database of books on the reader is corrupted. Try the following: @@ -701,10 +717,6 @@ class Main(MainWindow, Ui_MainWindow): warning_dialog(self, 'Could not convert some books', msg).exec_() - - - - def set_conversion_defaults(self, checked): d = LRFSingleDialog(self, None, None) d.exec_() @@ -1057,13 +1069,18 @@ def main(args=sys.argv): app = QApplication(args) QCoreApplication.setOrganizationName(ORG_NAME) QCoreApplication.setApplicationName(APP_UID) - if not singleinstance('mainGUI'): + single_instance = None if SingleApplication is None else SingleApplication('calibre GUI') + if not singleinstance('calibre GUI'): + if single_instance is not None and single_instance.is_running() and \ + single_instance.send_message('launched:'+''.join(sys.argv)): + return 0 + QMessageBox.critical(None, 'Cannot Start '+__appname__, '

%s is already running.

'%__appname__) return 1 initialize_file_icon_provider() try: - main = Main() + main = Main(single_instance) except DatabaseLocked, err: QMessageBox.critical(None, 'Cannot Start '+__appname__, '

Another program is using the database.
Perhaps %s is already running?
If not try deleting the file %s'%(__appname__, err.lock_file_path))