Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/pr/166'
Browse files Browse the repository at this point in the history
* origin/pr/166:
  Refactored QThread classes for more clarity and less code duplication
  Fixed inconsisted icon in Qube Manager messages
  • Loading branch information
marmarek committed Apr 4, 2019
2 parents f4d0417 + 6e10daa commit 6585ab4
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 27 deletions.
17 changes: 10 additions & 7 deletions qubesmanager/common_threads.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,16 @@ def busy_cursor():


# 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.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]
Expand All @@ -50,16 +54,15 @@ def run(self):


# 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

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))
34 changes: 14 additions & 20 deletions qubesmanager/qube_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,12 +264,7 @@ def check_if_vm_has_shutdown(self):


# pylint: disable=too-few-public-methods
class StartVMThread(QtCore.QThread):
def __init__(self, vm):
QtCore.QThread.__init__(self)
self.vm = vm
self.msg = None

class StartVMThread(common_threads.QubesThread):
def run(self):
try:
self.vm.start()
Expand All @@ -278,12 +273,7 @@ def run(self):


# pylint: disable=too-few-public-methods
class UpdateVMThread(QtCore.QThread):
def __init__(self, vm):
QtCore.QThread.__init__(self)
self.vm = vm
self.msg = None

class UpdateVMThread(common_threads.QubesThread):
def run(self):
try:
if self.vm.qid == 0:
Expand Down Expand Up @@ -316,12 +306,10 @@ def run(self):


# 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

def run(self):
try:
Expand Down Expand Up @@ -533,10 +521,16 @@ def clear_threads(self):

if thread.msg:
(title, msg) = thread.msg
QtGui.QMessageBox.warning(
None,
self.tr(title),
self.tr(msg))
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
Expand Down

0 comments on commit 6585ab4

Please sign in to comment.