Implement the smartdevice control dialog.

This commit is contained in:
Charles Haley 2012-07-24 16:42:59 +02:00
parent 76c0892b51
commit b2f1c6294b
3 changed files with 210 additions and 7 deletions

View File

@ -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'))

View File

@ -0,0 +1,78 @@
__license__ = 'GPL v3'
__copyright__ = '2008, Kovid Goyal <kovid at kovidgoyal.net>'
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. <B>Please '
'answer yes</b>. 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)

View File

@ -0,0 +1,129 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Dialog</class>
<widget class="QDialog" name="Dialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>600</width>
<height>209</height>
</rect>
</property>
<property name="windowTitle">
<string>Smart device control</string>
</property>
<property name="windowIcon">
<iconset resource="../../../../resources/images.qrc">
<normaloff>:/images/mimetypes/unknown.png</normaloff>:/images/mimetypes/unknown.png</iconset>
</property>
<layout class="QGridLayout">
<item row="0" column="1" colspan="2">
<widget class="QLabel" name="msg">
<property name="text">
<string>TextLabel</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>&amp;Password:</string>
</property>
<property name="buddy">
<cstring>password_box</cstring>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QLineEdit" name="password_box">
<property name="echoMode">
<enum>QLineEdit::Password</enum>
</property>
</widget>
</item>
<item row="1" column="2" >
<widget class="QLabel" name="passwd_msg">
<property name="text">
<string>TextLabel</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>100</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QCheckBox" name="show_password">
<property name="text">
<string>&amp;Show password</string>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QCheckBox" name="autostart_box">
<property name="text">
<string>&amp;Auto-start</string>
</property>
</widget>
</item>
<item row="3" column="2" >
<widget class="QLabel" name="auto_start_msg">
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
<item row="4" column="1" colspan="2">
<widget class="QLabel" name="auto_start_msg">
<property name="text">
<string>All the buttons except Cancel will save the above settings</string>
</property>
</widget>
</item>
<item row="5" column="1" colspan="2">
<layout class="QHBoxLayout">
<item>
<widget class="QPushButton" name="start_button">
<property name="text">
<string>Start interface</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="stop_button">
<property name="text">
<string>Stop interface</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="OK_button">
<property name="text">
<string>OK</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="cancel_button">
<property name="text">
<string>Cancel</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
<resources>
<include location="../../../../resources/images.qrc"/>
</resources>
</ui>