diff --git a/qubesmanager/about.py b/qubesmanager/about.py index da3f398..f8b9b03 100644 --- a/qubesmanager/about.py +++ b/qubesmanager/about.py @@ -30,8 +30,8 @@ from . import ui_about # pylint: disable=no-name-in-module # pylint: disable=too-few-public-methods class AboutDialog(ui_about.Ui_AboutDialog, QDialog): - def __init__(self): - super().__init__() + def __init__(self, parent=None): + super().__init__(parent) self.setupUi(self) @@ -40,15 +40,13 @@ class AboutDialog(ui_about.Ui_AboutDialog, QDialog): self.release.setText(release_file.read()) self.ok.clicked.connect(self.accept) - self.releaseNotes.clicked.connect(on_release_notes_clicked) - self.informationNotes.clicked.connect(on_information_notes_clicked) + self.releaseNotes.clicked.connect(self.on_release_notes_clicked) + self.informationNotes.clicked.connect(self.on_information_notes_clicked) + def on_release_notes_clicked(self): + release_notes_dialog = ReleaseNotesDialog(self) + release_notes_dialog.exec_() -def on_release_notes_clicked(): - release_notes_dialog = ReleaseNotesDialog() - release_notes_dialog.exec_() - - -def on_information_notes_clicked(): - information_notes_dialog = InformationNotesDialog() - information_notes_dialog.exec_() + def on_information_notes_clicked(self): + information_notes_dialog = InformationNotesDialog(self) + information_notes_dialog.exec_() diff --git a/qubesmanager/bootfromdevice.py b/qubesmanager/bootfromdevice.py index e73493d..ddd939e 100644 --- a/qubesmanager/bootfromdevice.py +++ b/qubesmanager/bootfromdevice.py @@ -23,22 +23,24 @@ from . import utils from . import ui_bootfromdevice # pylint: disable=no-name-in-module from PyQt5 import QtWidgets, QtGui # pylint: disable=import-error from qubesadmin import tools -from qubesadmin.tools import qvm_start from qubesadmin import exc +from qubesadmin.tools import qvm_start class VMBootFromDeviceWindow(ui_bootfromdevice.Ui_BootDialog, QtWidgets.QDialog): - def __init__(self, vm, qapp, qubesapp=None, parent=None): + def __init__(self, vm, qapp, qubesapp=None, parent=None, new_vm=False): super().__init__(parent) self.vm = vm self.qapp = qapp self.qubesapp = qubesapp + self.cdrom_location = None + self.new_vm = new_vm self.setupUi(self) self.setWindowTitle( - self.tr("Boot {vm} from device").format(vm=self.vm.name)) + self.tr("Boot {vm} from device").format(vm=self.vm)) self.buttonBox.accepted.connect(self.save_and_apply) self.buttonBox.rejected.connect(self.reject) @@ -52,14 +54,11 @@ class VMBootFromDeviceWindow(ui_bootfromdevice.Ui_BootDialog, self.qapp.setApplicationName(self.tr("Boot Qube From Device")) self.qapp.setWindowIcon(QtGui.QIcon.fromTheme("qubes-manager")) - def reject(self): - self.done(0) - def save_and_apply(self): if self.blockDeviceRadioButton.isChecked(): - cdrom_location = self.blockDeviceComboBox.currentText() + self.cdrom_location = self.blockDeviceComboBox.currentText() elif self.fileRadioButton.isChecked(): - cdrom_location = str(self.fileVM.currentData()) + \ + self.cdrom_location = str(self.fileVM.currentData()) + \ ":" + self.pathText.text() else: QtWidgets.QMessageBox.warning( @@ -70,14 +69,14 @@ class VMBootFromDeviceWindow(ui_bootfromdevice.Ui_BootDialog, # warn user if the VM is currently running self.__warn_if_running__() - - qvm_start.main(['--cdrom', cdrom_location, self.vm.name]) - - self.done(0) + self.accept() def __warn_if_running__(self): + if self.new_vm: + return + try: - if self.vm.is_running(): + if self.qubesapp.domains[self.vm].is_running(): QtWidgets.QMessageBox.warning( self, self.tr("Warning!"), @@ -107,7 +106,8 @@ class VMBootFromDeviceWindow(ui_bootfromdevice.Ui_BootDialog, ) device_choice = [] - for domain in self.vm.app.domains: + + for domain in self.qubesapp.domains: try: for device in domain.devices["block"]: device_choice.append((str(device), device)) @@ -169,8 +169,9 @@ def main(args=None): args = parser.parse_args(args) vm = args.domains.pop() - utils.run_synchronous(functools.partial(VMBootFromDeviceWindow, vm)) - + window = utils.run_synchronous(functools.partial(VMBootFromDeviceWindow, vm)) + if window.result() == 1 and window.cdrom_location is not None: + qvm_start.main(['--cdrom', window.cdrom_location, vm.name]) if __name__ == "__main__": main() diff --git a/qubesmanager/create_new_vm.py b/qubesmanager/create_new_vm.py index a95792d..e803814 100644 --- a/qubesmanager/create_new_vm.py +++ b/qubesmanager/create_new_vm.py @@ -32,6 +32,7 @@ import qubesadmin.tools import qubesadmin.exc from . import utils +from . import bootfromdevice from .ui_newappvmdlg import Ui_NewVMDlg # pylint: disable=import-error @@ -102,6 +103,7 @@ class NewVmDlg(QtWidgets.QDialog, Ui_NewVMDlg): self.thread = None self.progress = None + self.boot_dialog = None utils.initialize_widget_with_labels( widget=self.label, @@ -173,14 +175,16 @@ class NewVmDlg(QtWidgets.QDialog, Ui_NewVMDlg): self.launch_settings.stateChanged.connect(self.settings_change) self.install_system.stateChanged.connect(self.install_change) - def reject(self): - self.done(0) - def accept(self): vmclass = self.vm_type.currentData() - name = str(self.name.text()) + if self.install_system.isChecked(): + self.boot_dialog = bootfromdevice.VMBootFromDeviceWindow( + name, self.qtapp, self.app, self, True) + if not self.boot_dialog.exec_(): + return + if name in self.app.domains: QtWidgets.QMessageBox.warning( self, @@ -229,23 +233,23 @@ class NewVmDlg(QtWidgets.QDialog, Ui_NewVMDlg): self.progress.show() def create_finished(self): - self.progress.hide() - if self.thread.msg: QtWidgets.QMessageBox.warning( self, self.tr("Error creating the qube!"), self.tr("ERROR: {0}").format(self.thread.msg)) - self.done(0) - - if not self.thread.msg: + else: if self.launch_settings.isChecked(): subprocess.check_call(['qubes-vm-settings', str(self.name.text())]) if self.install_system.isChecked(): - subprocess.check_call( - ['qubes-vm-boot-from-device', str(self.name.text())]) + qubesadmin.tools.qvm_start.main( + ['--cdrom', self.boot_dialog.cdrom_location, + self.name.text()]) + + self.progress.hide() + self.done(0) def type_change(self): template = self.template_vm.currentData() diff --git a/qubesmanager/informationnotes.py b/qubesmanager/informationnotes.py index 4383aac..755be5b 100644 --- a/qubesmanager/informationnotes.py +++ b/qubesmanager/informationnotes.py @@ -29,8 +29,8 @@ import subprocess class InformationNotesDialog(ui_informationnotes.Ui_InformationNotesDialog, QDialog): # pylint: disable=too-few-public-methods - def __init__(self): - super().__init__() + def __init__(self, parent=None): + super().__init__(parent) self.setupUi(self) details = subprocess.check_output( diff --git a/qubesmanager/qube_manager.py b/qubesmanager/qube_manager.py index bde0775..15b37a1 100644 --- a/qubesmanager/qube_manager.py +++ b/qubesmanager/qube_manager.py @@ -1273,7 +1273,8 @@ class VmManagerWindow(ui_qubemanager.Ui_VmManagerWindow, QMainWindow): @pyqtSlot(name='on_action_createvm_triggered') def action_createvm_triggered(self): with common_threads.busy_cursor(): - create_window = create_new_vm.NewVmDlg(self.qt_app, self.qubes_app) + create_window = create_new_vm.NewVmDlg( + self.qt_app, self.qubes_app, self) create_window.exec_() # noinspection PyArgumentList @@ -1519,8 +1520,7 @@ class VmManagerWindow(ui_qubemanager.Ui_VmManagerWindow, QMainWindow): try: with common_threads.busy_cursor(): settings_window = settings.VMSettingsWindow( - vm, init_page=tab, qapp=self.qt_app, - qubesapp=self.qubes_app) + vm, tab, self.qt_app, self.qubes_app, self) settings_window.show() self.settings_windows[vm.name] = settings_window except exc.QubesException as ex: @@ -1623,7 +1623,8 @@ class VmManagerWindow(ui_qubemanager.Ui_VmManagerWindow, QMainWindow): with common_threads.busy_cursor(): global_settings_window = global_settings.GlobalSettingsWindow( self.qt_app, - self.qubes_app) + self.qubes_app, + self) global_settings_window.show() self.settings_windows['global_settings_window'] = global_settings_window @@ -1646,7 +1647,7 @@ class VmManagerWindow(ui_qubemanager.Ui_VmManagerWindow, QMainWindow): def action_restore_triggered(self): with common_threads.busy_cursor(): restore_window = restore.RestoreVMsWindow(self.qt_app, - self.qubes_app) + self.qubes_app, self) restore_window.exec_() # noinspection PyArgumentList @@ -1696,7 +1697,7 @@ class VmManagerWindow(ui_qubemanager.Ui_VmManagerWindow, QMainWindow): # noinspection PyArgumentList @pyqtSlot(name='on_action_about_qubes_triggered') def action_about_qubes_triggered(self): # pylint: disable=no-self-use - about = AboutDialog() + about = AboutDialog(self) about.exec_() def createPopupMenu(self): # pylint: disable=invalid-name diff --git a/qubesmanager/releasenotes.py b/qubesmanager/releasenotes.py index b91fb57..7c30caf 100644 --- a/qubesmanager/releasenotes.py +++ b/qubesmanager/releasenotes.py @@ -27,8 +27,8 @@ from . import ui_releasenotes # pylint: disable=no-name-in-module class ReleaseNotesDialog(ui_releasenotes.Ui_ReleaseNotesDialog, QDialog): # pylint: disable=too-few-public-methods - def __init__(self): - super().__init__() + def __init__(self, parent=None): + super().__init__(parent) self.setupUi(self) diff --git a/qubesmanager/settings.py b/qubesmanager/settings.py index 3612d0d..10aef1d 100644 --- a/qubesmanager/settings.py +++ b/qubesmanager/settings.py @@ -30,8 +30,10 @@ import traceback from qubesadmin.tools import QubesArgumentParser from qubesadmin import devices from qubesadmin import utils as admin_utils +from qubesadmin.tools import qvm_start import qubesadmin.exc +from . import bootfromdevice from . import utils from . import multiselectwidget from . import common_threads @@ -1023,8 +1025,12 @@ class VMSettingsWindow(ui_settingsdlg.Ui_SettingsDialog, QtWidgets.QDialog): self.check_mem_changes() def boot_from_cdrom_button_pressed(self): - self.save_and_apply() - subprocess.check_call(['qubes-vm-boot-from-device', self.vm.name]) + boot_dialog = bootfromdevice.VMBootFromDeviceWindow( + self.vm.name, self.qapp, self.qubesapp, self) + if boot_dialog.exec_(): + self.save_and_apply() + qvm_start.main( + ['--cdrom', boot_dialog.cdrom_location, self.vm.name]) def virt_mode_changed(self, new_idx): # pylint: disable=unused-argument self.update_pv_warning() diff --git a/qubesmanager/template_manager.py b/qubesmanager/template_manager.py index 6ed44e0..4536df6 100644 --- a/qubesmanager/template_manager.py +++ b/qubesmanager/template_manager.py @@ -35,7 +35,7 @@ class TemplateManagerWindow( def __init__(self, qt_app, qubes_app, dispatcher, parent=None): # pylint: disable=unused-argument - super().__init__() + super().__init__(parent) self.setupUi(self) self.qubes_app = qubes_app diff --git a/qubesmanager/utils.py b/qubesmanager/utils.py index 6b7d828..aa50006 100644 --- a/qubesmanager/utils.py +++ b/qubesmanager/utils.py @@ -564,3 +564,5 @@ def run_synchronous(window_class): qt_app.exec_() qt_app.exit() + + return window diff --git a/ui/bootfromdevice.ui b/ui/bootfromdevice.ui index 741ad91..943019c 100644 --- a/ui/bootfromdevice.ui +++ b/ui/bootfromdevice.ui @@ -6,7 +6,7 @@ 0 0 - 600 + 610 170 @@ -27,16 +27,34 @@ Boot qube from device - + 0 30 581 - 72 + 74 + + 6 + + + 6 + + + 6 + + + 6 + + + 0 + + + 6 +