From c6f0c8a6f2284c1937759f0303de71d47d513ff4 Mon Sep 17 00:00:00 2001 From: Charles Haley <> Date: Thu, 23 Aug 2012 09:17:25 +0200 Subject: [PATCH 1/2] Use a timer to display a message if smartdevice autoconnect fails. --- src/calibre/gui2/dialogs/smartdevice.py | 22 +++++++++++----- src/calibre/gui2/ui.py | 34 +++++++++++++++++++------ 2 files changed, 41 insertions(+), 15 deletions(-) diff --git a/src/calibre/gui2/dialogs/smartdevice.py b/src/calibre/gui2/dialogs/smartdevice.py index b83db2bd18..520cf9f917 100644 --- a/src/calibre/gui2/dialogs/smartdevice.py +++ b/src/calibre/gui2/dialogs/smartdevice.py @@ -53,11 +53,13 @@ class SmartdeviceDialog(QDialog, Ui_Dialog): if pw: self.password_box.setText(pw) - use_fixed_port = self.device_manager.get_option('smartdevice', 'use_fixed_port') - port_number = self.device_manager.get_option('smartdevice', 'port_number') - self.fixed_port.setText(port_number) - self.use_fixed_port.setChecked(use_fixed_port); - if not use_fixed_port: + self.orig_fixed_port = self.device_manager.get_option('smartdevice', + 'use_fixed_port') + self.orig_port_number = self.device_manager.get_option('smartdevice', + 'port_number') + self.fixed_port.setText(self.orig_port_number) + self.use_fixed_port.setChecked(self.orig_fixed_port); + if not self.orig_fixed_port: self.fixed_port.setEnabled(False); if pw: @@ -85,8 +87,14 @@ class SmartdeviceDialog(QDialog, Ui_Dialog): message = self.device_manager.start_plugin('smartdevice') if not self.device_manager.is_running('smartdevice'): - error_dialog(self, _('Problem starting smartdevice'), - _('The snart device driver did not start. It said "%s"')%message, show=True) + error_dialog(self, _('Problem starting the wireless device'), + _('The wireless device driver did not start. It said "%s"')%message, + show=True) + self.device_manager.set_option('smartdevice', 'use_fixed_port', + self.orig_fixed_port) + self.device_manager.set_option('smartdevice', 'port_number', + self.orig_port_number) + else: QDialog.accept(self) diff --git a/src/calibre/gui2/ui.py b/src/calibre/gui2/ui.py index 67415bee9e..d9bfa069d6 100644 --- a/src/calibre/gui2/ui.py +++ b/src/calibre/gui2/ui.py @@ -339,14 +339,6 @@ class Main(MainWindow, MainWindowMixin, DeviceMixin, EmailMixin, # {{{ if config['autolaunch_server']: self.start_content_server() - smartdevice_action = self.iactions['Connect Share'] - smartdevice_action.check_smartdevice_menus() - if self.device_manager.get_option('smartdevice', 'autostart'): - try: - self.device_manager.start_plugin('smartdevice') - except: - pass - smartdevice_action.set_smartdevice_action_state() self.keyboard_interrupt.connect(self.quit, type=Qt.QueuedConnection) @@ -381,9 +373,35 @@ class Main(MainWindow, MainWindowMixin, DeviceMixin, EmailMixin, # {{{ 'the file: %s

The ' 'log will be displayed automatically.')%self.gui_debug, show=True) + smartdevice_action = self.iactions['Connect Share'] + smartdevice_action.check_smartdevice_menus() + self.sd_timer = QTimer(); + self.sd_timer.setSingleShot(True) + self.sd_timer.timeout.connect(self.start_smartdevice, type=Qt.QueuedConnection) + self.sd_timer.start(0) + def esc(self, *args): self.clear_button.click() + def start_smartdevice(self): + self.sd_timer = None + message = None + if self.device_manager.get_option('smartdevice', 'autostart'): + try: + message = self.device_manager.start_plugin('smartdevice') + except: + message = 'start smartdevice unknown exception' + prints(message) + import traceback + traceback.print_exc() + if message: + if not self.device_manager.is_running('Wireless Devices'): + error_dialog(self, _('Problem starting the wireless device'), + _('The wireless device driver did not start. ' + 'It said "%s"')%message, show=True) + smartdevice_action = self.iactions['Connect Share'] + smartdevice_action.set_smartdevice_action_state() + def start_content_server(self, check_started=True): from calibre.library.server.main import start_threaded_server from calibre.library.server import server_config From 473ebb2dbd1fd88bb989d107abb81a803329866b Mon Sep 17 00:00:00 2001 From: Charles Haley <> Date: Thu, 23 Aug 2012 09:19:09 +0200 Subject: [PATCH 2/2] ... --- src/calibre/gui2/dialogs/smartdevice.py | 1 - 1 file changed, 1 deletion(-) diff --git a/src/calibre/gui2/dialogs/smartdevice.py b/src/calibre/gui2/dialogs/smartdevice.py index 520cf9f917..1a8829323b 100644 --- a/src/calibre/gui2/dialogs/smartdevice.py +++ b/src/calibre/gui2/dialogs/smartdevice.py @@ -94,7 +94,6 @@ class SmartdeviceDialog(QDialog, Ui_Dialog): self.orig_fixed_port) self.device_manager.set_option('smartdevice', 'port_number', self.orig_port_number) - else: QDialog.accept(self)