From b2f1c6294b2b68bd7ae21cf54d9707f8b5a4a74c Mon Sep 17 00:00:00 2001 From: Charles Haley <> Date: Tue, 24 Jul 2012 16:42:59 +0200 Subject: [PATCH] Implement the smartdevice control dialog. --- src/calibre/gui2/actions/device.py | 10 +- src/calibre/gui2/dialogs/smartdevice.py | 78 ++++++++++++++ src/calibre/gui2/dialogs/smartdevice.ui | 129 ++++++++++++++++++++++++ 3 files changed, 210 insertions(+), 7 deletions(-) create mode 100644 src/calibre/gui2/dialogs/smartdevice.py create mode 100644 src/calibre/gui2/dialogs/smartdevice.ui diff --git a/src/calibre/gui2/actions/device.py b/src/calibre/gui2/actions/device.py index afbf2584ed..8faf9f1717 100644 --- a/src/calibre/gui2/actions/device.py +++ b/src/calibre/gui2/actions/device.py @@ -14,6 +14,7 @@ from calibre.utils.smtp import config as email_config from calibre.constants import iswindows, isosx from calibre.customize.ui import is_disabled from calibre.devices.bambook.driver import BAMBOOK +from calibre.gui2.dialogs.smartdevice import SmartdeviceDialog from calibre.gui2 import info_dialog class ShareConnMenu(QMenu): # {{{ @@ -220,13 +221,8 @@ class ConnectShareAction(InterfaceAction): self.stopping_msg.accept() def toggle_smartdevice(self): - info_dialog(self.gui, _('Foobar'), - _('Start server bla bla blah...'), - show_copy_button=False, show=True) - if self.gui.device_manager.is_running('smartdevice'): - self.gui.device_manager.stop_plugin('smartdevice') - else: - self.gui.device_manager.start_plugin('smartdevice') + sd_dialog = SmartdeviceDialog(self.gui) + sd_dialog.exec_() self.share_conn_menu.smartdevice_state_changed( self.gui.device_manager.is_running('smartdevice')) diff --git a/src/calibre/gui2/dialogs/smartdevice.py b/src/calibre/gui2/dialogs/smartdevice.py new file mode 100644 index 0000000000..63c49a5fc7 --- /dev/null +++ b/src/calibre/gui2/dialogs/smartdevice.py @@ -0,0 +1,78 @@ +__license__ = 'GPL v3' +__copyright__ = '2008, Kovid Goyal ' +import re +from PyQt4.QtGui import QDialog, QLineEdit +from PyQt4.QtCore import SIGNAL, Qt + +from calibre.gui2.dialogs.smartdevice_ui import Ui_Dialog +from calibre.gui2 import dynamic + +class SmartdeviceDialog(QDialog, Ui_Dialog): + + def __init__(self, parent): + QDialog.__init__(self, parent) + Ui_Dialog.__init__(self) + self.setupUi(self) + + self.msg.setText( + _('This dialog starts and stops the smart device app interface. ' + 'When you start the interface, you might see some messages from ' + 'your computer\'s firewall or anti-virus manager asking you ' + 'if it is OK for calibre to connect to the network. Please ' + 'answer yes. If you do not, the app will not work. It will ' + 'be unable to connect to calibre.')) + + self.passwd_msg.setText( + _('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.')) + + self.auto_start_msg.setText( + _('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.')) + self.connect(self.show_password, SIGNAL('stateChanged(int)'), self.toggle_password) + + self.device_manager = parent.device_manager + if self.device_manager.get_option('smartdevice', 'autostart'): + self.autostart_box.setChecked(True) + 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) + 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) + + def toggle_password(self, state): + if state == Qt.Unchecked: + self.password_box.setEchoMode(QLineEdit.Password) + else: + self.password_box.setEchoMode(QLineEdit.Normal) + + def accept(self): + self.device_manager.set_option('smartdevice', 'password', + unicode(self.password_box.text())) + self.device_manager.set_option('smartdevice', 'autostart', + self.autostart_box.isChecked()) + QDialog.accept(self) diff --git a/src/calibre/gui2/dialogs/smartdevice.ui b/src/calibre/gui2/dialogs/smartdevice.ui new file mode 100644 index 0000000000..26795249be --- /dev/null +++ b/src/calibre/gui2/dialogs/smartdevice.ui @@ -0,0 +1,129 @@ + + + Dialog + + + + 0 + 0 + 600 + 209 + + + + Smart device control + + + + :/images/mimetypes/unknown.png:/images/mimetypes/unknown.png + + + + + + TextLabel + + + true + + + + + + + &Password: + + + password_box + + + + + + + QLineEdit::Password + + + + + + + TextLabel + + + true + + + + 100 + 0 + + + + + + + + &Show password + + + + + + + &Auto-start + + + + + + + true + + + + + + + All the buttons except Cancel will save the above settings + + + + + + + + + Start interface + + + + + + + Stop interface + + + + + + + OK + + + + + + + Cancel + + + + + + + + + + +