mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Improved smartdevice control dialog
This commit is contained in:
parent
b2f1c6294b
commit
0f16e4d9c7
@ -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'):
|
||||
|
@ -22,47 +22,45 @@ class SmartdeviceDialog(QDialog, Ui_Dialog):
|
||||
'answer yes</b>. 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('<p>' +
|
||||
_('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.') + '</p>')
|
||||
|
||||
self.auto_start_msg.setText(
|
||||
self.run_box.setToolTip('<p>' +
|
||||
_('Check this box to allow calibre to accept connections from the '
|
||||
'smart device. Uncheck the box to prevent connections.') + '</p>')
|
||||
|
||||
self.autostart_box.setToolTip('<p>' +
|
||||
_('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.') + '</p>')
|
||||
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)
|
||||
|
@ -18,7 +18,7 @@
|
||||
<normaloff>:/images/mimetypes/unknown.png</normaloff>:/images/mimetypes/unknown.png</iconset>
|
||||
</property>
|
||||
<layout class="QGridLayout">
|
||||
<item row="0" column="1" colspan="2">
|
||||
<item row="0" column="0" colspan="2">
|
||||
<widget class="QLabel" name="msg">
|
||||
<property name="text">
|
||||
<string>TextLabel</string>
|
||||
@ -43,16 +43,6 @@
|
||||
<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>
|
||||
@ -69,61 +59,77 @@
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="1">
|
||||
<widget class="QCheckBox" name="run_box">
|
||||
<property name="text">
|
||||
<string>&Allow connections</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="4" column="1">
|
||||
<widget class="QCheckBox" name="autostart_box">
|
||||
<property name="text">
|
||||
<string>&Auto-start</string>
|
||||
<string>&Automatically allow connections at startup</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="2" >
|
||||
<widget class="QLabel" name="auto_start_msg">
|
||||
<property name="wordWrap">
|
||||
<bool>true</bool>
|
||||
<item row="5" column="1">
|
||||
<widget class="QLabel" name="label_43">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>100</verstretch>
|
||||
</sizepolicy>
|
||||
</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>
|
||||
|
||||
<item row="6" column="1">
|
||||
<widget class="QDialogButtonBox" name="buttonBox">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="standardButtons">
|
||||
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
|
||||
</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>
|
||||
<connections>
|
||||
<connection>
|
||||
<sender>buttonBox</sender>
|
||||
<signal>accepted()</signal>
|
||||
<receiver>Dialog</receiver>
|
||||
<slot>accept()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>248</x>
|
||||
<y>254</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>157</x>
|
||||
<y>274</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
<connection>
|
||||
<sender>buttonBox</sender>
|
||||
<signal>rejected()</signal>
|
||||
<receiver>Dialog</receiver>
|
||||
<slot>reject()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>316</x>
|
||||
<y>260</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>286</x>
|
||||
<y>274</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
</connections>
|
||||
</ui>
|
||||
|
@ -342,7 +342,6 @@ class Main(MainWindow, MainWindowMixin, DeviceMixin, EmailMixin, # {{{
|
||||
if self.device_manager.get_option('smartdevice', 'autostart'):
|
||||
try:
|
||||
self.device_manager.start_plugin('smartdevice')
|
||||
smartdevice_actions.smartdevice_state_changed(True)
|
||||
except:
|
||||
pass
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user