Global settings dialog.

This commit is contained in:
Agnieszka Kostrzewa 2012-03-15 00:22:06 +01:00
parent 1d06bd12fa
commit 4c182080a9
3 changed files with 238 additions and 75 deletions

View File

@ -17,7 +17,7 @@
<item row="0" column="0">
<widget class="QGroupBox" name="groupBox">
<property name="enabled">
<bool>false</bool>
<bool>true</bool>
</property>
<property name="title">
<string>System defaults</string>
@ -37,7 +37,7 @@
</widget>
</item>
<item row="0" column="1">
<widget class="QComboBox" name="updateVMcombo"/>
<widget class="QComboBox" name="update_vm_combo"/>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_2">
@ -47,7 +47,7 @@
</widget>
</item>
<item row="1" column="1">
<widget class="QComboBox" name="clockVMcombo"/>
<widget class="QComboBox" name="clock_vm_combo"/>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_3">
@ -57,7 +57,7 @@
</widget>
</item>
<item row="2" column="1">
<widget class="QComboBox" name="defaultNetVMcombo"/>
<widget class="QComboBox" name="default_netvm_combo"/>
</item>
<item row="3" column="0">
<widget class="QLabel" name="label_4">
@ -73,7 +73,7 @@
</widget>
</item>
<item row="3" column="1">
<widget class="QComboBox" name="defaultTemplateVMCombo"/>
<widget class="QComboBox" name="default_template_combo"/>
</item>
</layout>
</widget>
@ -81,81 +81,78 @@
<item row="0" column="1">
<widget class="QGroupBox" name="groupBox_3">
<property name="enabled">
<bool>false</bool>
<bool>true</bool>
</property>
<property name="title">
<string>Default memory settings</string>
</property>
<widget class="QLabel" name="label_6">
<property name="geometry">
<rect>
<x>11</x>
<y>26</y>
<width>134</width>
<height>16</height>
</rect>
</property>
<property name="text">
<string>Minimal VM's memory:</string>
</property>
</widget>
<widget class="QLabel" name="label_7">
<property name="geometry">
<rect>
<x>11</x>
<y>57</y>
<width>139</width>
<height>16</height>
</rect>
</property>
<property name="text">
<string>dom0 memory margin:</string>
</property>
</widget>
<widget class="QSpinBox" name="minVMmem">
<property name="geometry">
<rect>
<x>156</x>
<y>26</y>
<width>121</width>
<height>25</height>
</rect>
</property>
<property name="suffix">
<string> MB</string>
</property>
<property name="maximum">
<number>999999999</number>
</property>
<property name="singleStep">
<number>10</number>
</property>
</widget>
<widget class="QSpinBox" name="dom0memMargin">
<property name="geometry">
<rect>
<x>156</x>
<y>57</y>
<width>121</width>
<height>25</height>
</rect>
</property>
<property name="suffix">
<string> MB</string>
</property>
<property name="maximum">
<number>999999999</number>
</property>
<property name="singleStep">
<number>50</number>
</property>
</widget>
<layout class="QGridLayout" name="gridLayout_2">
<item row="0" column="0">
<widget class="QLabel" name="label_6">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>Minimal VM's memory:</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QSpinBox" name="min_vm_mem">
<property name="enabled">
<bool>false</bool>
</property>
<property name="suffix">
<string> MB</string>
</property>
<property name="maximum">
<number>999999999</number>
</property>
<property name="singleStep">
<number>10</number>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_7">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>dom0 memory margin:</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QSpinBox" name="dom0_mem_margin">
<property name="enabled">
<bool>false</bool>
</property>
<property name="suffix">
<string> MB</string>
</property>
<property name="maximum">
<number>999999999</number>
</property>
<property name="singleStep">
<number>50</number>
</property>
</widget>
</item>
<item row="2" column="0" colspan="2">
<widget class="QCheckBox" name="dispvm_in_memory">
<property name="text">
<string>Keep dispVM in memory</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item row="1" column="0" colspan="2">
<widget class="QGroupBox" name="groupBox_2">
<property name="enabled">
<bool>false</bool>
<bool>true</bool>
</property>
<property name="title">
<string>Kernel</string>
@ -169,7 +166,7 @@
</widget>
</item>
<item row="0" column="1">
<widget class="QComboBox" name="comboBox_5"/>
<widget class="QComboBox" name="default_kernel_combo"/>
</item>
</layout>
</widget>

View File

@ -30,6 +30,7 @@ from qubes.qubes import QubesVmCollection
from qubes.qubes import QubesException
from qubes.qubes import QubesDaemonPidfile
from qubes.qubes import QubesHost
from qubes.qubes import qubes_kernels_base_dir
import qubesmanager.resources_rc
@ -42,18 +43,183 @@ from operator import itemgetter
from ui_globalsettingsdlg import *
dont_keep_dvm_in_memory_path = '/var/lib/qubes/dvmdata/dont_use_shm'
class GlobalSettingsWindow(Ui_GlobalSettings, QDialog):
def __init__(self, parent=None):
def __init__(self, app, qvm_collection, parent=None):
super(GlobalSettingsWindow, self).__init__(parent)
self.app = app
self.qvm_collection = qvm_collection
self.setupUi(self)
self.connect(self.buttonBox, SIGNAL("accepted()"), self.save_and_apply)
self.connect(self.buttonBox, SIGNAL("rejected()"), self.reject)
self.__init_system_defaults__()
self.__init_kernel_defaults__()
self.__init_mem_defaults__()
def __init_system_defaults__(self):
#updatevm and clockvm
all_vms = [vm for vm in self.qvm_collection.values() if not vm.internal]
self.updatevm_idx = -1
current_update_vm = self.qvm_collection.get_updatevm_vm()
for (i, vm) in enumerate(all_vms):
text = vm.name
if vm is current_update_vm:
self.updatevm_idx = i
text += " (current)"
self.update_vm_combo.insertItem(i, text)
self.update_vm_combo.insertItem(len(all_vms), "none")
if current_update_vm is None:
self.updatevm_idx = len(all_vms)
self.update_vm_combo.setCurrentIndex(self.updatevm_idx)
#clockvm
self.clockvm_idx = -1
current_clock_vm = self.qvm_collection.get_clockvm_vm()
for (i, vm) in enumerate(all_vms):
text = vm.name
if vm is current_clock_vm:
self.clockvm_idx = i
text += " (current)"
self.clock_vm_combo.insertItem(i, text)
self.clock_vm_combo.insertItem(len(all_vms), "none")
if current_clock_vm is None:
self.clockvm_idx = len(all_vms)
self.clock_vm_combo.setCurrentIndex(self.clockvm_idx)
#default netvm
netvms = [vm for vm in all_vms if vm.is_netvm()]
self.netvm_idx = -1
current_netvm = self.qvm_collection.get_default_netvm()
for (i, vm) in enumerate(netvms):
text = vm.name
if vm is current_netvm:
self.netvm_idx = i
text += " (current)"
self.default_netvm_combo.insertItem(i, text)
if current_netvm is not None:
self.default_netvm_combo.setCurrentIndex(self.netvm_idx)
#default template
templates = [vm for vm in all_vms if vm.is_template()]
self.template_idx = -1
current_template = self.qvm_collection.get_default_template()
for (i, vm) in enumerate(templates):
text = vm.name
if vm is current_template:
self.template_idx = i
text += " (current)"
self.default_template_combo.insertItem(i, text)
if current_template is not None:
self.default_template_combo.setCurrentIndex(self.template_idx)
def __apply_system_defaults__(self):
#upatevm
if self.update_vm_combo.currentIndex() != self.updatevm_idx:
updatevm_name = self.update_vm_combo.currentText()
updatevm_name = updatevm_name.split(' ')[0]
updatevm = self.qvm_collection.get_vm_by_name(updatevm_name)
self.qvm_collection.set_updatevm_vm(updatevm)
self.anything_changed = True
#clockvm
if self.clock_vm_combo.currentIndex() != self.clockvm_idx:
clockvm_name = self.clock_vm_combo.currentText()
clockvm_name = clockvm_name.split(' ')[0]
clockvm = self.qvm_collection.get_vm_by_name(clockvm_name)
self.qvm_collection.set_clockvm_vm(clockvm)
self.anything_changed = True
#default netvm
if self.default_netvm_combo.currentIndex() != self.netvm_idx:
name = self.default_netvm_combo.currentText()
name = name.split(' ')[0]
vm = self.qvm_collection.get_vm_by_name(name)
self.qvm_collection.set_default_netvm(vm)
self.anything_changed = True
#default template
if self.default_template_combo.currentIndex() != self.template_idx:
name = self.default_template_combo.currentText()
name = name.split(' ')[0]
vm = self.qvm_collection.get_vm_by_name(name)
self.qvm_collection.set_default_template(vm)
self.anything_changed = True
def __init_kernel_defaults__(self):
kernel_list = []
for k in os.listdir(qubes_kernels_base_dir):
kernel_list.append(k)
self.kernel_idx = 0
for (i, k) in enumerate(kernel_list):
text = k
if k == self.qvm_collection.get_default_kernel():
text += " (current)"
self.kernel_idx = i
self.default_kernel_combo.insertItem(i,text)
self.default_kernel_combo.setCurrentIndex(self.kernel_idx)
def __apply_kernel_defaults__(self):
if self.default_kernel_combo.currentIndex() != self.kernel_idx:
kernel = self.default_kernel_combo.currentText()
kernel = kernel.split(' ')[0]
self.qvm_collection.set_default_kernel(kernel)
self.anything_changed = True
def __init_mem_defaults__(self):
#keep dispvm in memory
exists = os.path.exists(dont_keep_dvm_in_memory_path)
self.dispvm_in_memory.setChecked( not exists)
def __apply_mem_defaults__(self):
#keep dispvm in memory
was_checked = not os.path.exists(dont_keep_dvm_in_memory_path)
if was_checked != self.dispvm_in_memory.isChecked():
if was_checked:
#touch file
open(dont_keep_dvm_in_memory_path, 'w').close()
else:
#rm file
os.remove(dont_keep_dvm_in_memory_path)
self.anything_changed = True
def reject(self):
self.done(0)
def save_and_apply(self):
pass
self.qvm_collection.lock_db_for_writing()
self.anything_changed = False
self.__apply_system_defaults__()
self.__apply_kernel_defaults__()
self.__apply_mem_defaults__()
if self.anything_changed == True:
self.qvm_collection.save()
self.qvm_collection.unlock_db()
# Bases on the original code by:
# Copyright (c) 2002-2007 Pascal Varet <p.varet@gmail.com>

View File

@ -1119,7 +1119,7 @@ class VmManagerWindow(Ui_VmManagerWindow, QMainWindow):
@pyqtSlot(name='on_action_global_settings_triggered')
def action_global_settings_triggered(self):
global_settings_window = GlobalSettingsWindow()
global_settings_window = GlobalSettingsWindow(app, self.qvm_collection)
global_settings_window.exec_()