From fe810c5ad0884a8625c3fdbe264d3b574404dafe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marta=20Marczykowska-G=C3=B3recka?= Date: Fri, 29 Mar 2019 17:01:15 +0100 Subject: [PATCH 1/2] Fixed inconsisted icon in Qube Manager messages Now success will not be accompanied by a 'warning' icon. fixes QubesOS/qubes-issues#4922 --- qubesmanager/common_threads.py | 4 ++++ qubesmanager/qube_manager.py | 21 +++++++++++++++++---- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/qubesmanager/common_threads.py b/qubesmanager/common_threads.py index 4f35539..99d50ca 100644 --- a/qubesmanager/common_threads.py +++ b/qubesmanager/common_threads.py @@ -30,12 +30,14 @@ class RemoveVMThread(QtCore.QThread): QtCore.QThread.__init__(self) self.vm = vm self.msg = None + self.is_error = False def run(self): try: del self.vm.app.domains[self.vm.name] except (exc.QubesException, KeyError) as ex: self.msg = ("Error removing qube!", str(ex)) + self.is_error = True # pylint: disable=too-few-public-methods @@ -45,6 +47,7 @@ class CloneVMThread(QtCore.QThread): self.src_vm = src_vm self.dst_name = dst_name self.msg = None + self.is_error = False def run(self): try: @@ -52,3 +55,4 @@ class CloneVMThread(QtCore.QThread): self.msg = ("Sucess", "The qube was cloned sucessfully.") except exc.QubesException as ex: self.msg = ("Error while cloning qube!", str(ex)) + self.is_error = True diff --git a/qubesmanager/qube_manager.py b/qubesmanager/qube_manager.py index 83720ab..d2f15cf 100644 --- a/qubesmanager/qube_manager.py +++ b/qubesmanager/qube_manager.py @@ -254,12 +254,14 @@ class StartVMThread(QtCore.QThread): QtCore.QThread.__init__(self) self.vm = vm self.msg = None + self.is_error = False def run(self): try: self.vm.start() except exc.QubesException as ex: self.msg = ("Error starting Qube!", str(ex)) + self.is_error = True # pylint: disable=too-few-public-methods @@ -268,6 +270,7 @@ class UpdateVMThread(QtCore.QThread): QtCore.QThread.__init__(self) self.vm = vm self.msg = None + self.is_error = False def run(self): try: @@ -298,6 +301,7 @@ class UpdateVMThread(QtCore.QThread): user="root", wait=False) except (ChildProcessError, exc.QubesException) as ex: self.msg = ("Error on qube update!", str(ex)) + self.is_error = True # pylint: disable=too-few-public-methods @@ -307,12 +311,14 @@ class RunCommandThread(QtCore.QThread): self.vm = vm self.command_to_run = command_to_run self.msg = None + self.is_error = False def run(self): try: self.vm.run(self.command_to_run) except (ChildProcessError, exc.QubesException) as ex: self.msg = ("Error while running command!", str(ex)) + self.is_error = True class VmManagerWindow(ui_qubemanager.Ui_VmManagerWindow, QtGui.QMainWindow): @@ -515,10 +521,17 @@ class VmManagerWindow(ui_qubemanager.Ui_VmManagerWindow, QtGui.QMainWindow): if thread.msg: (title, msg) = thread.msg - QtGui.QMessageBox.warning( - None, - self.tr(title), - self.tr(msg)) + if thread.is_error: + QtGui.QMessageBox.warning( + None, + self.tr(title), + self.tr(msg)) + else: + QtGui.QMessageBox.information( + None, + self.tr(title), + self.tr(msg)) + self.threads_list.remove(thread) return From 6e10daa3094016e5adf1f5b679ab458b07c9799e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marta=20Marczykowska-G=C3=B3recka?= Date: Wed, 3 Apr 2019 20:34:01 +0200 Subject: [PATCH 2/2] Refactored QThread classes for more clarity and less code duplication --- qubesmanager/common_threads.py | 21 +++++++++--------- qubesmanager/qube_manager.py | 39 +++++++++------------------------- 2 files changed, 20 insertions(+), 40 deletions(-) diff --git a/qubesmanager/common_threads.py b/qubesmanager/common_threads.py index 99d50ca..58c60a8 100644 --- a/qubesmanager/common_threads.py +++ b/qubesmanager/common_threads.py @@ -25,34 +25,33 @@ from qubesadmin import exc # pylint: disable=too-few-public-methods -class RemoveVMThread(QtCore.QThread): +class QubesThread(QtCore.QThread): def __init__(self, vm): QtCore.QThread.__init__(self) self.vm = vm self.msg = None - self.is_error = False + self.msg_is_success = False + +# pylint: disable=too-few-public-methods +class RemoveVMThread(QubesThread): def run(self): try: del self.vm.app.domains[self.vm.name] except (exc.QubesException, KeyError) as ex: self.msg = ("Error removing qube!", str(ex)) - self.is_error = True # pylint: disable=too-few-public-methods -class CloneVMThread(QtCore.QThread): - def __init__(self, src_vm, dst_name): - QtCore.QThread.__init__(self) - self.src_vm = src_vm +class CloneVMThread(QubesThread): + def __init__(self, vm, dst_name): + super(CloneVMThread, self).__init__(vm) self.dst_name = dst_name - self.msg = None - self.is_error = False def run(self): try: - self.src_vm.app.clone_vm(self.src_vm, self.dst_name) + self.vm.app.clone_vm(self.vm, self.dst_name) self.msg = ("Sucess", "The qube was cloned sucessfully.") + self.msg_is_success = True except exc.QubesException as ex: self.msg = ("Error while cloning qube!", str(ex)) - self.is_error = True diff --git a/qubesmanager/qube_manager.py b/qubesmanager/qube_manager.py index d2f15cf..81cd366 100644 --- a/qubesmanager/qube_manager.py +++ b/qubesmanager/qube_manager.py @@ -249,29 +249,16 @@ class VmShutdownMonitor(QtCore.QObject): # pylint: disable=too-few-public-methods -class StartVMThread(QtCore.QThread): - def __init__(self, vm): - QtCore.QThread.__init__(self) - self.vm = vm - self.msg = None - self.is_error = False - +class StartVMThread(common_threads.QubesThread): def run(self): try: self.vm.start() except exc.QubesException as ex: self.msg = ("Error starting Qube!", str(ex)) - self.is_error = True # pylint: disable=too-few-public-methods -class UpdateVMThread(QtCore.QThread): - def __init__(self, vm): - QtCore.QThread.__init__(self) - self.vm = vm - self.msg = None - self.is_error = False - +class UpdateVMThread(common_threads.QubesThread): def run(self): try: if self.vm.qid == 0: @@ -301,24 +288,19 @@ class UpdateVMThread(QtCore.QThread): user="root", wait=False) except (ChildProcessError, exc.QubesException) as ex: self.msg = ("Error on qube update!", str(ex)) - self.is_error = True # pylint: disable=too-few-public-methods -class RunCommandThread(QtCore.QThread): +class RunCommandThread(common_threads.QubesThread): def __init__(self, vm, command_to_run): - QtCore.QThread.__init__(self) - self.vm = vm + super(RunCommandThread, self).__init__(vm) self.command_to_run = command_to_run - self.msg = None - self.is_error = False def run(self): try: self.vm.run(self.command_to_run) except (ChildProcessError, exc.QubesException) as ex: self.msg = ("Error while running command!", str(ex)) - self.is_error = True class VmManagerWindow(ui_qubemanager.Ui_VmManagerWindow, QtGui.QMainWindow): @@ -521,17 +503,16 @@ class VmManagerWindow(ui_qubemanager.Ui_VmManagerWindow, QtGui.QMainWindow): if thread.msg: (title, msg) = thread.msg - if thread.is_error: - QtGui.QMessageBox.warning( - None, - self.tr(title), - self.tr(msg)) - else: + if thread.msg_is_success: QtGui.QMessageBox.information( None, self.tr(title), self.tr(msg)) - + else: + QtGui.QMessageBox.warning( + None, + self.tr(title), + self.tr(msg)) self.threads_list.remove(thread) return