Added handling for supported services to VM settings

Slight change to layout of services tab, made it hopefully
less confusing. Dropdown will now list services supported by this
VM and its template, not just an assortment of hardcoded services.
This commit is contained in:
Marta Marczykowska-Górecka 2019-12-11 00:44:48 +01:00
parent 250cfd4966
commit 5f86660305
No known key found for this signature in database
GPG Key ID: 9A752C30B26FD04B
2 changed files with 105 additions and 72 deletions

View File

@ -209,8 +209,6 @@ class VMSettingsWindow(ui_settingsdlg.Ui_SettingsDialog, QtWidgets.QDialog):
####### services tab
self.__init_services_tab__()
self.service_line_edit.lineEdit().returnPressed.connect(
self.__add_service__)
self.add_srv_button.clicked.connect(self.__add_service__)
self.remove_srv_button.clicked.connect(self.__remove_service__)
@ -1074,35 +1072,49 @@ class VMSettingsWindow(ui_settingsdlg.Ui_SettingsDialog, QtWidgets.QDialog):
self.services_list.addItem(item)
self.new_srv_dict[service] = self.vm.features[feature]
# add suggested services
self.service_line_edit.addItem('clocksync')
self.service_line_edit.addItem('crond')
self.service_line_edit.addItem('cups')
self.service_line_edit.addItem('disable-default-route')
self.service_line_edit.addItem('disable-dns-server')
self.service_line_edit.addItem('network-manager')
self.service_line_edit.addItem('qubes-firewall')
self.service_line_edit.addItem('qubes-network')
self.service_line_edit.addItem('qubes-update-check')
self.service_line_edit.addItem('qubes-updates-proxy')
self.service_line_edit.addItem('qubes-yum-proxy')
self.service_line_edit.addItem('updates-proxy-setup')
self.service_line_edit.addItem('yum-proxy-setup')
self.service_line_edit.addItem("")
supported_services = []
service_prefix = "supported-service."
for feature in self.vm.features:
if feature.startswith(service_prefix):
supported_services.append(feature[len(service_prefix):])
if getattr(self.vm, "template", None):
for feature in self.vm.template.features:
if feature.startswith(service_prefix):
supported_services.add(feature[len(service_prefix):])
for service in sorted(supported_services):
self.service_line_edit.addItem(service)
self.service_line_edit.addItem(self.tr('(custom...)'))
self.service_line_edit.setEditText("")
def __add_service__(self):
srv = str(self.service_line_edit.currentText()).strip()
if srv != "":
if self.service_line_edit.currentIndex() == \
len(self.service_line_edit) - 1:
(custom_name, ok) = QtWidgets.QInputDialog.getText(
self, self.tr("Custom service name"),
self.tr(
"Name of the service:"))
if ok:
srv = custom_name.strip()
else:
return
if srv in self.new_srv_dict:
QtWidgets.QMessageBox.information(
self,
'',
self.tr('Service already on the list!'))
else:
item = QtWidgets.QListWidgetItem(srv)
item.setCheckState(ui_settingsdlg.QtCore.Qt.Checked)
self.services_list.addItem(item)
self.new_srv_dict[srv] = True
return
item = QtWidgets.QListWidgetItem(srv)
item.setCheckState(ui_settingsdlg.QtCore.Qt.Checked)
self.services_list.addItem(item)
self.new_srv_dict[srv] = True
def __remove_service__(self):
item = self.services_list.currentItem()

View File

@ -29,7 +29,7 @@
<locale language="English" country="UnitedStates"/>
</property>
<property name="currentIndex">
<number>1</number>
<number>5</number>
</property>
<widget class="QWidget" name="basic_tab">
<property name="locale">
@ -1433,47 +1433,85 @@ The qube must be running to disable seamless mode; this setting is not persisten
<string>Services</string>
</attribute>
<layout class="QGridLayout" name="gridLayout_5">
<item row="6" column="1">
<spacer name="verticalSpacer_5">
<property name="orientation">
<enum>Qt::Vertical</enum>
<item row="8" column="0" rowspan="2">
<widget class="QListWidget" name="services_list">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Minimum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</widget>
</item>
<item row="5" column="0" rowspan="2">
<widget class="QListWidget" name="services_list"/>
</item>
<item row="7" column="0" colspan="2">
<item row="11" column="0" colspan="2">
<widget class="QLabel" name="label_7">
<property name="text">
<string>Checked services will be turned on.</string>
</property>
</widget>
</item>
<item row="8" column="0" colspan="2">
<widget class="QLabel" name="label_8">
<property name="text">
<string>Unchecked services will be turned off.</string>
</property>
</widget>
</item>
<item row="9" column="0" colspan="2">
<item row="13" column="0" colspan="2">
<widget class="QLabel" name="label_9">
<property name="text">
<string>Unlisted services will follow default settings.</string>
</property>
</widget>
</item>
<item row="5" column="1">
<item row="12" column="0" colspan="2">
<widget class="QLabel" name="label_8">
<property name="text">
<string>Unchecked services will be turned off.</string>
</property>
</widget>
</item>
<item row="2" column="0">
<layout class="QHBoxLayout" name="horizontalLayout_7">
<item>
<widget class="QLabel" name="label_6">
<property name="text">
<string>Select a service:</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="service_line_edit">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip">
<string>Services listed here are explicitly supported by the qube. Additional services may be added with the '+' button on the right.</string>
</property>
<property name="currentText">
<string/>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="add_srv_button">
<property name="text">
<string>Add</string>
</property>
<property name="icon">
<iconset resource="../resources.qrc">
<normaloff>:/add.png</normaloff>:/add.png</iconset>
</property>
<property name="iconSize">
<size>
<width>24</width>
<height>24</height>
</size>
</property>
</widget>
</item>
</layout>
</item>
<item row="10" column="0">
<widget class="QPushButton" name="remove_srv_button">
<property name="text">
<string/>
<string>Remove service</string>
</property>
<property name="icon">
<iconset resource="../resources.qrc">
@ -1487,32 +1525,18 @@ The qube must be running to disable seamless mode; this setting is not persisten
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QComboBox" name="service_line_edit">
<property name="toolTip">
<string>Services listed here are only base Qubes services - other services may be installed and implemented.</string>
<item row="9" column="1">
<spacer name="verticalSpacer_5">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="editable">
<bool>true</bool>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QPushButton" name="add_srv_button">
<property name="text">
<string/>
</property>
<property name="icon">
<iconset resource="../resources.qrc">
<normaloff>:/add.png</normaloff>:/add.png</iconset>
</property>
<property name="iconSize">
<property name="sizeHint" stdset="0">
<size>
<width>24</width>
<height>24</height>
<width>20</width>
<height>40</height>
</size>
</property>
</widget>
</spacer>
</item>
</layout>
</widget>
@ -1568,10 +1592,7 @@ The qube must be running to disable seamless mode; this setting is not persisten
<tabstop>temp_full_access_time</tabstop>
<tabstop>no_strict_reset_button</tabstop>
<tabstop>refresh_apps_button</tabstop>
<tabstop>service_line_edit</tabstop>
<tabstop>add_srv_button</tabstop>
<tabstop>services_list</tabstop>
<tabstop>remove_srv_button</tabstop>
</tabstops>
<resources>
<include location="../resources.qrc"/>