Improved error messages and a critical bug fix.

This commit is contained in:
Charles Haley 2012-08-23 20:38:56 +02:00
parent 12c6515478
commit aae85f9328
2 changed files with 23 additions and 7 deletions

View File

@ -976,7 +976,7 @@ class SMART_DEVICE_APP(DeviceConfig, DevicePlugin):
except: except:
message = _('Invalid port in options: %s')% \ message = _('Invalid port in options: %s')% \
self.settings().extra_customization[self.OPT_PORT_NUMBER] self.settings().extra_customization[self.OPT_PORT_NUMBER]
self.debug(message) self._debug(message)
self.listen_socket.close() self.listen_socket.close()
self.listen_socket = None self.listen_socket = None
self.is_connected = False self.is_connected = False
@ -984,7 +984,7 @@ class SMART_DEVICE_APP(DeviceConfig, DevicePlugin):
port = self._attach_to_port(opt_port) port = self._attach_to_port(opt_port)
if port == 0: if port == 0:
message = 'Failed to connect to port %d'%opt_port message = _('Failed to connect to port %d. Try a different value.')%opt_port
self._debug(message) self._debug(message)
self.listen_socket.close() self.listen_socket.close()
self.listen_socket = None self.listen_socket = None

View File

@ -33,13 +33,12 @@ class SmartdeviceDialog(QDialog, Ui_Dialog):
_('Check this box if you want calibre to use a fixed network ' _('Check this box if you want calibre to use a fixed network '
'port. Normally you will not need to do this. However, if ' 'port. Normally you will not need to do this. However, if '
'your device consistently fails to connect to calibre, ' 'your device consistently fails to connect to calibre, '
'try checking this box.') + '</p>') 'try checking this box and entering a number.') + '</p>')
self.fixed_port.setToolTip('<p>' + self.fixed_port.setToolTip('<p>' +
_('A port number must be a 4-digit integer less than 32,000. No ' _('Try 9090. If calibre says that it fails to connect '
'two network applications on the same computer can use ' 'to the port, try another number. Yu can use any number between '
'the same port number. If calibre says that it fails to connect ' '8,000 and 32,000.') + '</p>')
'to the port, try a different number.') + '</p>')
self.show_password.stateChanged[int].connect(self.toggle_password) self.show_password.stateChanged[int].connect(self.toggle_password)
self.use_fixed_port.stateChanged[int].connect(self.use_fixed_port_changed) self.use_fixed_port.stateChanged[int].connect(self.use_fixed_port_changed)
@ -75,6 +74,23 @@ class SmartdeviceDialog(QDialog, Ui_Dialog):
Qt.Unchecked else QLineEdit.Normal) Qt.Unchecked else QLineEdit.Normal)
def accept(self): def accept(self):
port = unicode(self.fixed_port.text())
if not port:
error_dialog(self, _('Invalid port number'),
_('You must provide a port number.'), show=True)
return
try:
port = int(port)
except:
error_dialog(self, _('Invalid port number'),
_('The port must be a number between 8000 and 32000.'), show=True)
return
if port < 8000 or port > 32000:
error_dialog(self, _('Invalid port number'),
_('The port must be a number between 8000 and 32000.'), show=True)
return
self.device_manager.set_option('smartdevice', 'password', self.device_manager.set_option('smartdevice', 'password',
unicode(self.password_box.text())) unicode(self.password_box.text()))
self.device_manager.set_option('smartdevice', 'autostart', self.device_manager.set_option('smartdevice', 'autostart',