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()
|
config_email = pyqtSignal()
|
||||||
toggle_server = pyqtSignal()
|
toggle_server = pyqtSignal()
|
||||||
toggle_smartdevice = pyqtSignal()
|
control_smartdevice = pyqtSignal()
|
||||||
dont_add_to = frozenset(['context-menu-device'])
|
dont_add_to = frozenset(['context-menu-device'])
|
||||||
|
|
||||||
def __init__(self, parent=None):
|
def __init__(self, parent=None):
|
||||||
@ -58,11 +58,11 @@ class ShareConnMenu(QMenu): # {{{
|
|||||||
_('Start Content Server'))
|
_('Start Content Server'))
|
||||||
self.toggle_server_action.triggered.connect(lambda x:
|
self.toggle_server_action.triggered.connect(lambda x:
|
||||||
self.toggle_server.emit())
|
self.toggle_server.emit())
|
||||||
self.toggle_smartdevice_action = \
|
self.control_smartdevice_action = \
|
||||||
self.addAction(QIcon(I('devices/galaxy_s3.png')),
|
self.addAction(QIcon(I('devices/galaxy_s3.png')),
|
||||||
_('Start Smart Device Connections'))
|
_('Control Smart Device Connections'))
|
||||||
self.toggle_smartdevice_action.triggered.connect(lambda x:
|
self.control_smartdevice_action.triggered.connect(lambda x:
|
||||||
self.toggle_smartdevice.emit())
|
self.control_smartdevice.emit())
|
||||||
self.addSeparator()
|
self.addSeparator()
|
||||||
|
|
||||||
self.email_actions = []
|
self.email_actions = []
|
||||||
@ -87,14 +87,8 @@ class ShareConnMenu(QMenu): # {{{
|
|||||||
text = _('Stop Content Server') + ' [%s]'%get_external_ip()
|
text = _('Stop Content Server') + ' [%s]'%get_external_ip()
|
||||||
self.toggle_server_action.setText(text)
|
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):
|
def hide_smartdevice_menus(self):
|
||||||
self.toggle_smartdevice_action.setVisible(False)
|
self.control_smartdevice_action.setVisible(False)
|
||||||
|
|
||||||
def build_email_entries(self, sync_menu):
|
def build_email_entries(self, sync_menu):
|
||||||
from calibre.gui2.device import DeviceAction
|
from calibre.gui2.device import DeviceAction
|
||||||
@ -174,7 +168,7 @@ class ConnectShareAction(InterfaceAction):
|
|||||||
def genesis(self):
|
def genesis(self):
|
||||||
self.share_conn_menu = ShareConnMenu(self.gui)
|
self.share_conn_menu = ShareConnMenu(self.gui)
|
||||||
self.share_conn_menu.toggle_server.connect(self.toggle_content_server)
|
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.share_conn_menu.config_email.connect(partial(
|
||||||
self.gui.iactions['Preferences'].do_config,
|
self.gui.iactions['Preferences'].do_config,
|
||||||
initial_plugin=('Sharing', 'Email')))
|
initial_plugin=('Sharing', 'Email')))
|
||||||
@ -220,14 +214,9 @@ class ConnectShareAction(InterfaceAction):
|
|||||||
self.gui.content_server = None
|
self.gui.content_server = None
|
||||||
self.stopping_msg.accept()
|
self.stopping_msg.accept()
|
||||||
|
|
||||||
def toggle_smartdevice(self):
|
def control_smartdevice(self):
|
||||||
sd_dialog = SmartdeviceDialog(self.gui)
|
sd_dialog = SmartdeviceDialog(self.gui)
|
||||||
sd_dialog.exec_()
|
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):
|
def check_smartdevice_menus(self):
|
||||||
if not self.gui.device_manager.is_enabled('smartdevice'):
|
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 '
|
'answer yes</b>. If you do not, the app will not work. It will '
|
||||||
'be unable to connect to calibre.'))
|
'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 '
|
_('Use a password if calibre is running on a network that '
|
||||||
'is not secure. For example, if you run calibre on a laptop, '
|
'is not secure. For example, if you run calibre on a laptop, '
|
||||||
'use that laptop in an airport, and want to connect your '
|
'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 '
|
_('Check this box if you want calibre to automatically start the '
|
||||||
'smart device interface when calibre starts. You should not do '
|
'smart device interface when calibre starts. You should not do '
|
||||||
'this if you are using a network that is not secure and you '
|
'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.connect(self.show_password, SIGNAL('stateChanged(int)'), self.toggle_password)
|
||||||
|
self.autostart_box.stateChanged.connect(self.autostart_changed)
|
||||||
|
|
||||||
self.device_manager = parent.device_manager
|
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'):
|
if self.device_manager.get_option('smartdevice', 'autostart'):
|
||||||
self.autostart_box.setChecked(True)
|
self.autostart_box.setChecked(True)
|
||||||
|
self.run_box.setChecked(True)
|
||||||
|
self.run_box.setEnabled(False)
|
||||||
|
|
||||||
pw = self.device_manager.get_option('smartdevice', 'password')
|
pw = self.device_manager.get_option('smartdevice', 'password')
|
||||||
if pw:
|
if pw:
|
||||||
self.password_box.setText(pw)
|
self.password_box.setText(pw)
|
||||||
|
|
||||||
if self.device_manager.is_running('smartdevice'):
|
def autostart_changed(self):
|
||||||
self.start_button.setEnabled(False)
|
if self.autostart_box.isChecked():
|
||||||
self.stop_button.setEnabled(True)
|
self.run_box.setChecked(True)
|
||||||
|
self.run_box.setEnabled(False)
|
||||||
else:
|
else:
|
||||||
self.start_button.setEnabled(True)
|
self.run_box.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):
|
def toggle_password(self, state):
|
||||||
if state == Qt.Unchecked:
|
if state == Qt.Unchecked:
|
||||||
@ -75,4 +73,9 @@ class SmartdeviceDialog(QDialog, Ui_Dialog):
|
|||||||
unicode(self.password_box.text()))
|
unicode(self.password_box.text()))
|
||||||
self.device_manager.set_option('smartdevice', 'autostart',
|
self.device_manager.set_option('smartdevice', 'autostart',
|
||||||
self.autostart_box.isChecked())
|
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)
|
QDialog.accept(self)
|
||||||
|
@ -18,7 +18,7 @@
|
|||||||
<normaloff>:/images/mimetypes/unknown.png</normaloff>:/images/mimetypes/unknown.png</iconset>
|
<normaloff>:/images/mimetypes/unknown.png</normaloff>:/images/mimetypes/unknown.png</iconset>
|
||||||
</property>
|
</property>
|
||||||
<layout class="QGridLayout">
|
<layout class="QGridLayout">
|
||||||
<item row="0" column="1" colspan="2">
|
<item row="0" column="0" colspan="2">
|
||||||
<widget class="QLabel" name="msg">
|
<widget class="QLabel" name="msg">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>TextLabel</string>
|
<string>TextLabel</string>
|
||||||
@ -43,16 +43,6 @@
|
|||||||
<property name="echoMode">
|
<property name="echoMode">
|
||||||
<enum>QLineEdit::Password</enum>
|
<enum>QLineEdit::Password</enum>
|
||||||
</property>
|
</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">
|
<property name="sizePolicy">
|
||||||
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
|
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
|
||||||
<horstretch>100</horstretch>
|
<horstretch>100</horstretch>
|
||||||
@ -69,61 +59,77 @@
|
|||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="3" column="1">
|
<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">
|
<widget class="QCheckBox" name="autostart_box">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>&Auto-start</string>
|
<string>&Automatically allow connections at startup</string>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="3" column="2" >
|
<item row="5" column="1">
|
||||||
<widget class="QLabel" name="auto_start_msg">
|
<widget class="QLabel" name="label_43">
|
||||||
<property name="wordWrap">
|
<property name="sizePolicy">
|
||||||
<bool>true</bool>
|
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
|
||||||
|
<horstretch>0</horstretch>
|
||||||
|
<verstretch>100</verstretch>
|
||||||
|
</sizepolicy>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="4" column="1" colspan="2">
|
|
||||||
<widget class="QLabel" name="auto_start_msg">
|
<item row="6" column="1">
|
||||||
<property name="text">
|
<widget class="QDialogButtonBox" name="buttonBox">
|
||||||
<string>All the buttons except Cancel will save the above settings</string>
|
<property name="orientation">
|
||||||
|
<enum>Qt::Horizontal</enum>
|
||||||
|
</property>
|
||||||
|
<property name="standardButtons">
|
||||||
|
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</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>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
<resources>
|
<resources>
|
||||||
<include location="../../../../resources/images.qrc"/>
|
<include location="../../../../resources/images.qrc"/>
|
||||||
</resources>
|
</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>
|
</ui>
|
||||||
|
@ -342,7 +342,6 @@ class Main(MainWindow, MainWindowMixin, DeviceMixin, EmailMixin, # {{{
|
|||||||
if self.device_manager.get_option('smartdevice', 'autostart'):
|
if self.device_manager.get_option('smartdevice', 'autostart'):
|
||||||
try:
|
try:
|
||||||
self.device_manager.start_plugin('smartdevice')
|
self.device_manager.start_plugin('smartdevice')
|
||||||
smartdevice_actions.smartdevice_state_changed(True)
|
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user