From 7c38dabc8bd9cebc089042e746e28ea549337347 Mon Sep 17 00:00:00 2001 From: Charles Haley <> Date: Thu, 2 Aug 2012 09:34:28 +0200 Subject: [PATCH] Change color of dot on smartdevice menu. Add a port option to the smartdevice. --- .../devices/smart_device_app/driver.py | 23 ++++++++++++++++--- src/calibre/gui2/actions/device.py | 9 ++++++-- 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/src/calibre/devices/smart_device_app/driver.py b/src/calibre/devices/smart_device_app/driver.py index 8277ab7a2d..046ae1a05a 100644 --- a/src/calibre/devices/smart_device_app/driver.py +++ b/src/calibre/devices/smart_device_app/driver.py @@ -113,6 +113,11 @@ class SMART_DEVICE_APP(DeviceConfig, DevicePlugin): _('Security password') + ':::
' + _('Enter a password that the device app must use to connect to calibre') + '
', '', + _('Use fixed network port') + ':::' + + _('If checked, use the port number in the "Port" box, otherwise ' + 'the driver will pick a random port') + '
', + _('Port') + ':::' + + _('Enter the port number the driver is to use if the "fixed port" box is checked') + '
', _('Print extra debug information') + ':::' + _('Check this box if requested when reporting problems') + '
', ] @@ -121,11 +126,14 @@ class SMART_DEVICE_APP(DeviceConfig, DevicePlugin): '', '', '', + False, '9090', False, ] OPT_AUTOSTART = 0 OPT_PASSWORD = 2 - OPT_EXTRA_DEBUG = 4 + OPT_USE_PORT = 4 + OPT_PORT_NUMBER = 5 + OPT_EXTRA_DEBUG = 6 def __init__(self, path): self.sync_lock = threading.RLock() @@ -809,8 +817,17 @@ class SMART_DEVICE_APP(DeviceConfig, DevicePlugin): self._debug('creation of listen socket failed') return - for i in xrange(100): # try up to 100 random port numbers - port = random.randint(8192, 32000) + i = 0 + while i < 100: # try up to 100 random port numbers + if self.settings().extra_customization[self.OPT_USE_PORT]: + i = 100 + try: + port = int(self.settings().extra_customization[self.OPT_PORT_NUMBER]) + except: + port = 0 + else: + i += 1 + port = random.randint(8192, 32000) try: self._debug('try port', port) self.listen_socket.bind(('', port)) diff --git a/src/calibre/gui2/actions/device.py b/src/calibre/gui2/actions/device.py index d9b3dadba7..1151d1976a 100644 --- a/src/calibre/gui2/actions/device.py +++ b/src/calibre/gui2/actions/device.py @@ -237,9 +237,14 @@ class ConnectShareAction(InterfaceAction): self.share_conn_menu.hide_smartdevice_menus() def set_smartdevice_action_state(self): + from calibre.utils.mdns import get_external_ip running = self.gui.device_manager.is_running('smartdevice') + if not running: + text = self.share_conn_menu.DEVICE_MSGS[0] + else: + text = self.share_conn_menu.DEVICE_MSGS[1] + ' [%s]'%get_external_ip() + icon = 'green' if running else 'red' ac = self.share_conn_menu.control_smartdevice_action - text, icon = (1, 'green') if running else (0, 'red') ac.setIcon(QIcon(I('dot_%s.png'%icon))) - ac.setText(self.share_conn_menu.DEVICE_MSGS[text]) + ac.setText(text)