diff --git a/src/calibre/gui2/actions/device.py b/src/calibre/gui2/actions/device.py index 8faf9f1717..8d08f53f0a 100644 --- a/src/calibre/gui2/actions/device.py +++ b/src/calibre/gui2/actions/device.py @@ -25,7 +25,7 @@ class ShareConnMenu(QMenu): # {{{ config_email = pyqtSignal() toggle_server = pyqtSignal() - toggle_smartdevice = pyqtSignal() + control_smartdevice = pyqtSignal() dont_add_to = frozenset(['context-menu-device']) def __init__(self, parent=None): @@ -58,11 +58,11 @@ class ShareConnMenu(QMenu): # {{{ _('Start Content Server')) self.toggle_server_action.triggered.connect(lambda x: self.toggle_server.emit()) - self.toggle_smartdevice_action = \ + self.control_smartdevice_action = \ self.addAction(QIcon(I('devices/galaxy_s3.png')), - _('Start Smart Device Connections')) - self.toggle_smartdevice_action.triggered.connect(lambda x: - self.toggle_smartdevice.emit()) + _('Control Smart Device Connections')) + self.control_smartdevice_action.triggered.connect(lambda x: + self.control_smartdevice.emit()) self.addSeparator() self.email_actions = [] @@ -87,14 +87,8 @@ class ShareConnMenu(QMenu): # {{{ text = _('Stop Content Server') + ' [%s]'%get_external_ip() self.toggle_server_action.setText(text) - def smartdevice_state_changed(self, accepting): - if accepting: - self.toggle_smartdevice_action.setText(_('Stop Smart Device Connections')) - else: - self.toggle_smartdevice_action.setText(_('Start Smart Device Connections')) - def hide_smartdevice_menus(self): - self.toggle_smartdevice_action.setVisible(False) + self.control_smartdevice_action.setVisible(False) def build_email_entries(self, sync_menu): from calibre.gui2.device import DeviceAction @@ -174,7 +168,7 @@ class ConnectShareAction(InterfaceAction): def genesis(self): self.share_conn_menu = ShareConnMenu(self.gui) self.share_conn_menu.toggle_server.connect(self.toggle_content_server) - self.share_conn_menu.toggle_smartdevice.connect(self.toggle_smartdevice) + self.share_conn_menu.control_smartdevice.connect(self.control_smartdevice) self.share_conn_menu.config_email.connect(partial( self.gui.iactions['Preferences'].do_config, initial_plugin=('Sharing', 'Email'))) @@ -220,14 +214,9 @@ class ConnectShareAction(InterfaceAction): self.gui.content_server = None self.stopping_msg.accept() - def toggle_smartdevice(self): + def control_smartdevice(self): sd_dialog = SmartdeviceDialog(self.gui) sd_dialog.exec_() - self.share_conn_menu.smartdevice_state_changed( - self.gui.device_manager.is_running('smartdevice')) - - def smartdevice_state_changed(self, running): - self.share_conn_menu.smartdevice_state_changed(running) def check_smartdevice_menus(self): if not self.gui.device_manager.is_enabled('smartdevice'): diff --git a/src/calibre/gui2/dialogs/smartdevice.py b/src/calibre/gui2/dialogs/smartdevice.py index 63c49a5fc7..15b40d1077 100644 --- a/src/calibre/gui2/dialogs/smartdevice.py +++ b/src/calibre/gui2/dialogs/smartdevice.py @@ -22,47 +22,45 @@ class SmartdeviceDialog(QDialog, Ui_Dialog): 'answer yes. If you do not, the app will not work. It will ' 'be unable to connect to calibre.')) - self.passwd_msg.setText( + self.password_box.setToolTip('
' + _('Use a password if calibre is running on a network that ' 'is not secure. For example, if you run calibre on a laptop, ' 'use that laptop in an airport, and want to connect your ' - 'smart device to calibre, you should use a password.')) + 'smart device to calibre, you should use a password.') + '
') - self.auto_start_msg.setText( + self.run_box.setToolTip('' + + _('Check this box to allow calibre to accept connections from the ' + 'smart device. Uncheck the box to prevent connections.') + '
') + + self.autostart_box.setToolTip('' + _('Check this box if you want calibre to automatically start the ' 'smart device interface when calibre starts. You should not do ' 'this if you are using a network that is not secure and you ' - 'are not setting a password.')) + 'are not setting a password.') + '
') self.connect(self.show_password, SIGNAL('stateChanged(int)'), self.toggle_password) + self.autostart_box.stateChanged.connect(self.autostart_changed) self.device_manager = parent.device_manager + if self.device_manager.is_running('smartdevice'): + self.run_box.setChecked(True) + else: + self.run_box.setChecked(False) + if self.device_manager.get_option('smartdevice', 'autostart'): self.autostart_box.setChecked(True) + self.run_box.setChecked(True) + self.run_box.setEnabled(False) + pw = self.device_manager.get_option('smartdevice', 'password') if pw: self.password_box.setText(pw) - if self.device_manager.is_running('smartdevice'): - self.start_button.setEnabled(False) - self.stop_button.setEnabled(True) + def autostart_changed(self): + if self.autostart_box.isChecked(): + self.run_box.setChecked(True) + self.run_box.setEnabled(False) else: - self.start_button.setEnabled(True) - self.stop_button.setEnabled(False) - self.start_button.clicked.connect(self.start_button_clicked) - self.stop_button.clicked.connect(self.stop_button_clicked) - self.cancel_button.clicked.connect(self.cancel_button_clicked) - self.OK_button.clicked.connect(self.accept) - - def start_button_clicked(self): - self.device_manager.start_plugin('smartdevice') - self.accept() - - def stop_button_clicked(self): - self.device_manager.stop_plugin('smartdevice') - self.accept() - - def cancel_button_clicked(self): - QDialog.reject(self) + self.run_box.setEnabled(True) def toggle_password(self, state): if state == Qt.Unchecked: @@ -75,4 +73,9 @@ class SmartdeviceDialog(QDialog, Ui_Dialog): unicode(self.password_box.text())) self.device_manager.set_option('smartdevice', 'autostart', self.autostart_box.isChecked()) + if self.run_box.isChecked(): + self.device_manager.start_plugin('smartdevice') + else: + self.device_manager.stop_plugin('smartdevice') + QDialog.accept(self) diff --git a/src/calibre/gui2/dialogs/smartdevice.ui b/src/calibre/gui2/dialogs/smartdevice.ui index 26795249be..97b4b71c00 100644 --- a/src/calibre/gui2/dialogs/smartdevice.ui +++ b/src/calibre/gui2/dialogs/smartdevice.ui @@ -18,7 +18,7 @@