mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Change color of dot on smartdevice menu. Add a port option to the smartdevice.
This commit is contained in:
parent
3621313895
commit
7c38dabc8b
@ -113,6 +113,11 @@ class SMART_DEVICE_APP(DeviceConfig, DevicePlugin):
|
||||
_('Security password') + ':::<p>' +
|
||||
_('Enter a password that the device app must use to connect to calibre') + '</p>',
|
||||
'',
|
||||
_('Use fixed network port') + ':::<p>' +
|
||||
_('If checked, use the port number in the "Port" box, otherwise '
|
||||
'the driver will pick a random port') + '</p>',
|
||||
_('Port') + ':::<p>' +
|
||||
_('Enter the port number the driver is to use if the "fixed port" box is checked') + '</p>',
|
||||
_('Print extra debug information') + ':::<p>' +
|
||||
_('Check this box if requested when reporting problems') + '</p>',
|
||||
]
|
||||
@ -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))
|
||||
|
@ -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)
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user