From 458968d37fbd8dbb4add865ec85f7e87090b643a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marta=20Marczykowska-G=C3=B3recka?= Date: Fri, 3 Nov 2017 22:20:34 +0100 Subject: [PATCH] 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. --- qubesmanager/settings.py | 47 ++++++++++++++++++++++++++++++++++++++++ ui/settingsdlg.ui | 19 +++++++++++++--- 2 files changed, 63 insertions(+), 3 deletions(-) diff --git a/qubesmanager/settings.py b/qubesmanager/settings.py index b42fdd8..7ed89a0 100755 --- a/qubesmanager/settings.py +++ b/qubesmanager/settings.py @@ -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? ' + '
All VM settings and data will be irrevocably' + ' deleted.
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): diff --git a/ui/settingsdlg.ui b/ui/settingsdlg.ui index 1d711c1..38156c6 100644 --- a/ui/settingsdlg.ui +++ b/ui/settingsdlg.ui @@ -7,7 +7,7 @@ 0 0 773 - 573 + 581 @@ -29,7 +29,7 @@ - 2 + 0 @@ -170,7 +170,7 @@ - + Qt::Vertical @@ -373,6 +373,19 @@ + + + + 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; + + + Delete VM + + +