Added Remove VM button
Button added on the basic tab of VM Settings. Button active only when VM is shutdown; furthermore, requires the user to enter full VM name to confirm.
This commit is contained in:
parent
f0e363a054
commit
458968d37f
@ -86,6 +86,7 @@ class VMSettingsWindow(Ui_SettingsDialog, QDialog):
|
||||
###### basic tab
|
||||
self.__init_basic_tab__()
|
||||
self.rename_vm_button.clicked.connect(self.rename_vm)
|
||||
self.delete_vm_button.clicked.connect(self.remove_vm)
|
||||
|
||||
###### advanced tab
|
||||
self.__init_advanced_tab__()
|
||||
@ -237,6 +238,11 @@ class VMSettingsWindow(Ui_SettingsDialog, QDialog):
|
||||
self.vmname.setValidator(QRegExpValidator(QRegExp("[a-zA-Z0-9-]*", Qt.CaseInsensitive), None))
|
||||
self.vmname.setEnabled(False)
|
||||
self.rename_vm_button.setEnabled(not self.vm.is_running())
|
||||
self.delete_vm_button.setEnabled(not self.vm.is_running())
|
||||
|
||||
if self.vm.is_running():
|
||||
self.delete_vm_button.setText(self.tr('Delete VM '
|
||||
'(cannot delete a running VM)'))
|
||||
|
||||
if self.vm.qid == 0:
|
||||
self.vmlabel.setVisible(False)
|
||||
@ -435,6 +441,47 @@ class VMSettingsWindow(Ui_SettingsDialog, QDialog):
|
||||
|
||||
self.done(0)
|
||||
|
||||
def _remove_vm(self, t_monitor):
|
||||
try:
|
||||
del self.vm.app.domains[self.vm.name]
|
||||
|
||||
except Exception as ex:
|
||||
t_monitor.set_error_msg(str(ex))
|
||||
|
||||
t_monitor.set_finished()
|
||||
|
||||
def remove_vm(self):
|
||||
|
||||
answer, ok = QInputDialog.getText(self, self.tr('Delete VM')
|
||||
, self.tr('Are you absolutely sure you want to delete this VM? '
|
||||
'<br \> All VM settings and data will be irrevocably'
|
||||
' deleted. <br \> If you are sure, please enter this '
|
||||
'VM\'s name below.'))
|
||||
|
||||
|
||||
if ok and answer == self.vm.name:
|
||||
t_monitor = thread_monitor.ThreadMonitor()
|
||||
thread = threading.Thread(target=self._remove_vm,
|
||||
args=(t_monitor,))
|
||||
thread.daemon = True
|
||||
thread.start()
|
||||
|
||||
while not t_monitor.is_finished():
|
||||
self.qapp.processEvents()
|
||||
time.sleep(0.1)
|
||||
|
||||
if not t_monitor.success:
|
||||
QMessageBox.warning(None,
|
||||
self.tr("Error deleting the VM!"),
|
||||
self.tr("ERROR: {}").format(
|
||||
t_monitor.error_msg))
|
||||
|
||||
self.done(0)
|
||||
|
||||
else:
|
||||
QMessageBox.warning(None, self.tr("Removal cancelled")
|
||||
, self.tr("The VM will not be removed."))
|
||||
|
||||
######### advanced tab
|
||||
|
||||
def __init_advanced_tab__(self):
|
||||
|
@ -7,7 +7,7 @@
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>773</width>
|
||||
<height>573</height>
|
||||
<height>581</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
@ -29,7 +29,7 @@
|
||||
<locale language="English" country="UnitedStates"/>
|
||||
</property>
|
||||
<property name="currentIndex">
|
||||
<number>2</number>
|
||||
<number>0</number>
|
||||
</property>
|
||||
<widget class="QWidget" name="basic_tab">
|
||||
<property name="locale">
|
||||
@ -170,7 +170,7 @@
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="5" column="0">
|
||||
<item row="6" column="0">
|
||||
<spacer name="verticalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
@ -373,6 +373,19 @@
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="4" column="1">
|
||||
<widget class="QPushButton" name="delete_vm_button">
|
||||
<property name="styleSheet">
|
||||
<string notr="true">background-color: qlineargradient(spread:pad, x1:1, y1:1, x2:1, y2:0, stop:0 rgba(255, 179, 179, 255), stop:1 rgba(255, 108, 108, 255));
|
||||
border-color: rgb(170, 0, 0);
|
||||
border-style: solid;
|
||||
border-width: 1px;</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Delete VM</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<widget class="QWidget" name="advanced_tab">
|
||||
|
Loading…
Reference in New Issue
Block a user