settings: add 'drive' setting to advanced tab (#712)

This commit is contained in:
Marek Marczykowski-Górecki 2014-02-17 00:53:47 +01:00
parent 8e0a441dfe
commit 17107a7012
2 changed files with 227 additions and 47 deletions

View File

@ -47,7 +47,7 @@ from ui_settingsdlg import *
from multiselectwidget import *
from appmenu_select import *
from firewall import *
from backup_utils import get_path_for_vm
class VMSettingsWindow(Ui_SettingsDialog, QDialog):
tabs_indices = {"basic": 0,
@ -90,6 +90,7 @@ class VMSettingsWindow(Ui_SettingsDialog, QDialog):
self.include_in_balancing.stateChanged.connect(self.include_in_balancing_state_changed)
self.connect(self.init_mem, SIGNAL("valueChanged(int)"), self.init_mem_changed)
self.connect(self.max_mem_size, SIGNAL("editingFinished()"), self.max_mem_size_changed)
self.drive_path_button.clicked.connect(self.drive_path_button_pressed)
###### firewall tab
if self.tabWidget.isTabEnabled(self.tabs_indices["firewall"]):
@ -484,6 +485,37 @@ class VMSettingsWindow(Ui_SettingsDialog, QDialog):
else:
self.kernel_opts.setText(self.vm.kernelopts)
if not hasattr(self.vm, "drive"):
self.drive_groupbox.setVisible(False)
else:
self.drive_groupbox.setVisible(True)
self.drive_groupbox.setChecked(self.vm.drive is not None)
self.drive_running_warning.setVisible(self.vm.is_running())
self.drive_type.addItems(["hd", "cdrom"])
self.drive_type.setCurrentIndex(0)
vm_list = [vm for vm in self.qvm_collection.values() if not vm
.internal and vm.qid != self.vm.qid]
# default to dom0 (in case of nonexisting vm already set...)
self.drive_domain_idx = 0
for (i, vm) in enumerate(sorted(vm_list, key=lambda v: v.name)):
if vm.qid == 0:
self.drive_domain_idx = i
self.drive_domain.insertItem(i, vm.name)
if self.vm.drive is not None:
(drv_type, drv_domain, drv_path) = self.vm.drive.split(":")
if drv_type == "cdrom":
self.drive_type.setCurrentIndex(1)
else:
self.drive_type.setCurrentIndex(0)
for i in xrange(self.drive_domain.count()):
if drv_domain == self.drive_domain.itemText(i):
self.drive_domain_idx = i
self.drive_path.setText(drv_path)
self.drive_domain.setCurrentIndex(self.drive_domain_idx)
def __apply_advanced_tab__(self):
msg = []
@ -526,9 +558,46 @@ class VMSettingsWindow(Ui_SettingsDialog, QDialog):
except Exception as ex:
msg.append(str(ex))
if hasattr(self.vm, "drive") and self.drive_groupbox.isVisible():
try:
if not self.drive_groupbox.isChecked():
if self.vm.drive != None:
self.vm.drive = None
self.anything_changed = True
else:
new_domain = str(self.drive_domain.currentText())
if self.drive_domain.currentIndex() == self.drive_domain_idx:
# strip "(current)"
new_domain = new_domain.split(' ')[0]
drive = "%s:%s:%s" % (
str(self.drive_type.currentText()),
new_domain,
str(self.drive_path.text())
)
if self.vm.drive != drive:
self.vm.drive = drive
self.anything_changed = True
except Exception as ex:
msg.append(str(ex))
return msg
def drive_path_button_pressed(self):
if self.drive_domain.currentText() in ["dom0", "dom0 (current)"]:
file_dialog = QFileDialog()
file_dialog.setReadOnly(True)
new_path = file_dialog.getOpenFileName(self, "Select drive image",
str(self.drive_path.text()))
else:
drv_domain = str(self.drive_domain.currentText())
if drv_domain.count("(current)") > 0:
drv_domain = drv_domain.split(' ')[0]
backend_vm = self.qvm_collection.get_vm_by_name(drv_domain)
if backend_vm:
new_path = get_path_for_vm(backend_vm, "qubes.SelectFile")
if new_path:
self.drive_path.setText(new_path)
######## devices tab
def __init_devices_tab__(self):
self.dev_list = MultiSelectWidget(self)

View File

@ -320,11 +320,161 @@
<string>Advanced</string>
</attribute>
<layout class="QGridLayout" name="gridLayout_9">
<item row="0" column="0">
<item row="0" column="1" rowspan="2" colspan="2">
<layout class="QVBoxLayout" name="verticalLayout_4">
<property name="sizeConstraint">
<enum>QLayout::SetDefaultConstraint</enum>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QGroupBox" name="kernel_groupbox">
<property name="enabled">
<bool>true</bool>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="title">
<string>Kernel</string>
</property>
<layout class="QFormLayout" name="formLayout_9">
<property name="fieldGrowthPolicy">
<enum>QFormLayout::AllNonFixedFieldsGrow</enum>
</property>
<item row="0" column="0">
<widget class="QLabel" name="label_19">
<property name="text">
<string>Kernel:</string>
</property>
<property name="buddy">
<cstring>kernel</cstring>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QComboBox" name="kernel"/>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_20">
<property name="text">
<string>Kernel opts:</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QLabel" name="kernel_opts">
<property name="font">
<font>
<weight>50</weight>
<bold>false</bold>
</font>
</property>
<property name="text">
<string>[]</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="drive_groupbox">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="title">
<string>Additional drive</string>
</property>
<property name="checkable">
<bool>true</bool>
</property>
<property name="checked">
<bool>true</bool>
</property>
<layout class="QGridLayout" name="gridLayout_18">
<item row="5" column="1">
<widget class="QLineEdit" name="drive_path"/>
</item>
<item row="4" column="1">
<widget class="QComboBox" name="drive_domain"/>
</item>
<item row="5" column="0">
<widget class="QLabel" name="label_52">
<property name="text">
<string>Path:</string>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QComboBox" name="drive_type"/>
</item>
<item row="4" column="0">
<widget class="QLabel" name="label_53">
<property name="text">
<string>Backend domain:</string>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="label_51">
<property name="text">
<string>Type:</string>
</property>
</widget>
</item>
<item row="5" column="2">
<widget class="QToolButton" name="drive_path_button">
<property name="text">
<string>...</string>
</property>
</widget>
</item>
<item row="6" column="0" colspan="3">
<widget class="QLabel" name="drive_running_warning">
<property name="enabled">
<bool>true</bool>
</property>
<property name="font">
<font>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="styleSheet">
<string notr="true">color: rgb(255, 0, 0);</string>
</property>
<property name="text">
<string>New drive will be used only at next VM startup</string>
</property>
<property name="textFormat">
<enum>Qt::AutoText</enum>
</property>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</item>
<item row="0" column="0" rowspan="2">
<widget class="QGroupBox" name="groupBox_2">
<property name="enabled">
<bool>true</bool>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="title">
<string>Memory/CPU</string>
</property>
@ -469,49 +619,7 @@
</layout>
</widget>
</item>
<item row="0" column="1">
<widget class="QGroupBox" name="kernel_groupbox">
<property name="enabled">
<bool>true</bool>
</property>
<property name="title">
<string>Kernel</string>
</property>
<layout class="QFormLayout" name="formLayout_2">
<item row="0" column="0">
<widget class="QLabel" name="label_19">
<property name="text">
<string>Kernel:</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QComboBox" name="kernel"/>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_20">
<property name="text">
<string>Kernel opts:</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QLabel" name="kernel_opts">
<property name="font">
<font>
<weight>50</weight>
<bold>false</bold>
</font>
</property>
<property name="text">
<string>[]</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item row="1" column="0" colspan="2">
<item row="3" column="0" colspan="3">
<widget class="QGroupBox" name="groupBox_11">
<property name="enabled">
<bool>true</bool>
@ -520,6 +628,9 @@
<string>Paths</string>
</property>
<layout class="QFormLayout" name="formLayout">
<property name="fieldGrowthPolicy">
<enum>QFormLayout::AllNonFixedFieldsGrow</enum>
</property>
<item row="0" column="0">
<widget class="QLabel" name="label_21">
<property name="text">
@ -605,7 +716,7 @@
</layout>
</widget>
</item>
<item row="2" column="1">
<item row="4" column="0">
<spacer name="verticalSpacer_2">
<property name="orientation">
<enum>Qt::Vertical</enum>
@ -613,7 +724,7 @@
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>88</height>
<height>40</height>
</size>
</property>
</spacer>