diff --git a/qubesmanager/appmenu_select.py b/qubesmanager/appmenu_select.py index 9c56d47..5544ce9 100755 --- a/qubesmanager/appmenu_select.py +++ b/qubesmanager/appmenu_select.py @@ -69,38 +69,19 @@ class ThreadMonitor(QObject): self.event_finished.set() -class AppmenuSelectWindow(QDialog): - row_height = 20 - - def __init__(self, vm, parent=None): - super(AppmenuSelectWindow, self).__init__(parent) - - self.gridLayout = QGridLayout(self) - - self.buttonBox = QDialogButtonBox(self) - self.buttonBox.setStandardButtons(QDialogButtonBox.Cancel|QDialogButtonBox.Ok) - self.connect(self.buttonBox, SIGNAL("accepted()"), self.save_and_apply) - self.connect(self.buttonBox, SIGNAL("rejected()"), self.reject) - - self.app_list = MultiSelectWidget(self) +class AppmenuSelectManager: + def __init__(self, vm, apps_multiselect, parent=None): + self.app_list = apps_multiselect # this is a multiselect wiget - self.gridLayout.addWidget(self.app_list, 0, 0, 1, 1) - self.gridLayout.addWidget(self.buttonBox, 1, 0, 1, 1) - self.vm = vm if self.vm.template_vm: self.source_vm = self.vm.template_vm else: self.source_vm = self.vm - self.setWindowTitle("Qubes Appmenus for %s" % vm.name) - self.resize(600,600) self.fill_apps_list() - def reject(self): - self.done(0) - def fill_apps_list(self): template_dir = self.source_vm.appmenus_templates_dir @@ -146,73 +127,8 @@ class AppmenuSelectWindow(QDialog): whitelisted.close() - def save_and_apply(self): + def save_appmenu_select_changes(self): self.save_list_of_selected() subprocess.check_call([qubes_appmenu_remove_cmd, self.vm.name]) subprocess.check_call([qubes_appmenu_create_cmd, self.source_vm.appmenus_templates_dir, self.vm.name]) - self.done(0) - -# Bases on the original code by: -# Copyright (c) 2002-2007 Pascal Varet - -def handle_exception( exc_type, exc_value, exc_traceback ): - import sys - import os.path - import traceback - - filename, line, dummy, dummy = traceback.extract_tb( exc_traceback ).pop() - filename = os.path.basename( filename ) - error = "%s: %s" % ( exc_type.__name__, exc_value ) - - QMessageBox.critical(None, "Houston, we have a problem...", - "Whoops. A critical error has occured. This is most likely a bug " - "in Qubes Appmenu Select application.

" - "%s" % error + - "at line %d of file %s.

" - % ( line, filename )) - - #sys.exit(1) - -def main(): - - - global qubes_host - qubes_host = QubesHost() - - global app - app = QApplication(sys.argv) - app.setOrganizationName("The Qubes Project") - app.setOrganizationDomain("http://qubes-os.org") - app.setApplicationName("Qubes Appmenu Select") - app.setWindowIcon(QIcon(":/qubes.png")) - - sys.excepthook = handle_exception - - qvm_collection = QubesVmCollection() - qvm_collection.lock_db_for_reading() - qvm_collection.load() - qvm_collection.unlock_db() - - vm = None - - if len(sys.argv) > 1: - vm = qvm_collection.get_vm_by_name(sys.argv[1]) - if vm is None or vm.qid not in qvm_collection: - QMessageBox.critical(None, "Qubes Appmenu Select Error", - "A VM with the name '{0}' does not exist in the system.".format(sys.argv[1])) - sys.exit(1) - else: - vms_list = [vm.name for vm in qvm_collection.values() if (vm.is_appvm() or vm.is_template())] - vmname = QInputDialog.getItem(None, "Select VM", "Select VM:", vms_list, editable = False) - if not vmname[1]: - sys.exit(1) - vm = qvm_collection.get_vm_by_name(vmname[0]) - - global manager_window - select_window = AppmenuSelectWindow(vm) - - select_window.show() - - app.exec_() - app.exit() diff --git a/qubesmanager/global_settings.py b/qubesmanager/global_settings.py index 373ddff..340210b 100644 --- a/qubesmanager/global_settings.py +++ b/qubesmanager/global_settings.py @@ -94,7 +94,7 @@ def main(): qvm_collection.unlock_db() global global_window - global_window = GlobalSetingsWindow() + global_window = GlobalSettingsWindow() global_window.show() diff --git a/qubesmanager/main.py b/qubesmanager/main.py index a5d67a1..442348b 100755 --- a/qubesmanager/main.py +++ b/qubesmanager/main.py @@ -38,7 +38,6 @@ from qubes import qubesutils import qubesmanager.resources_rc import ui_newappvmdlg from ui_mainwindow import * -from appmenu_select import AppmenuSelectWindow from settings import VMSettingsWindow from restore import RestoreVMsWindow from backup import BackupVMsWindow @@ -1136,15 +1135,16 @@ class VmManagerWindow(Ui_VmManagerWindow, QMainWindow): @pyqtSlot(name='on_action_settings_triggered') def action_settings_triggered(self): vm = self.get_selected_vm() - settings_window = VMSettingsWindow(vm, 1) + settings_window = VMSettingsWindow(vm, app, "basic") settings_window.exec_() @pyqtSlot(name='on_action_appmenus_triggered') def action_appmenus_triggered(self): vm = self.get_selected_vm() - select_window = AppmenuSelectWindow(vm) - select_window.exec_() + settings_window = VMSettingsWindow(vm, app, "applications") + settings_window.exec_() + @pyqtSlot(name='on_action_updatevm_triggered') def action_updatevm_triggered(self): diff --git a/qubesmanager/multiselectwidget.py b/qubesmanager/multiselectwidget.py index 46c7cf2..fbedf72 100644 --- a/qubesmanager/multiselectwidget.py +++ b/qubesmanager/multiselectwidget.py @@ -46,10 +46,3 @@ class MultiSelectWidget(Ui_MultiSelectWidget, QWidget): self.available_list.clear() self.selected_list.clear() - - -if __name__ == "__main__": - app = QtGui.QApplication(sys.argv) - ui = MultiSelectWidget() - ui.show() - sys.exit(app.exec_()) diff --git a/qubesmanager/settings.py b/qubesmanager/settings.py index b7ce7e1..be52243 100644 --- a/qubesmanager/settings.py +++ b/qubesmanager/settings.py @@ -45,17 +45,25 @@ from operator import itemgetter from ui_settingsdlg import * from multiselectwidget import * - +from appmenu_select import * class VMSettingsWindow(Ui_SettingsDialog, QDialog): + tabs_indices = {"basic": 0, + "advanced": 1, + "firewall": 2, + "devices": 3, + "applications": 4, + "services": 5,} - def __init__(self, vm, init_page=0, parent=None): + def __init__(self, vm, app, init_page="basic", parent=None): super(VMSettingsWindow, self).__init__(parent) self.setupUi(self) - if init_page in range(self.tabWidget.count()): - self.tabWidget.setCurrentIndex(init_page) + if init_page in self.tabs_indices: + idx = self.tabs_indices[init_page] + assert (idx in range(self.tabWidget.count())) + self.tabWidget.setCurrentIndex(idx) self.connect(self.buttonBox, SIGNAL("accepted()"), self.save_and_apply) self.connect(self.buttonBox, SIGNAL("rejected()"), self.reject) @@ -66,22 +74,49 @@ class VMSettingsWindow(Ui_SettingsDialog, QDialog): self.apps_layout.addWidget(self.app_list) self.devices_layout.addWidget(self.dev_list) + self.app = app self.vm = vm if self.vm.template_vm: self.source_vm = self.vm.template_vm else: self.source_vm = self.vm - - - #self.fill_apps_list() - #self.fill_devices_list() + + self.AppListManager = AppmenuSelectManager(self.vm, self.app_list) def reject(self): self.done(0) - def save_and_apply(self): + #needed not to close the dialog before applying changes + def accept(self): pass + def save_and_apply(self): + thread_monitor = ThreadMonitor() + thread = threading.Thread (target=self.__save_changes__, args=(thread_monitor,)) + thread.daemon = True + thread.start() + + progress = QProgressDialog ("Applying settings to {0}...".format(self.vm.name), "", 0, 0) + progress.setCancelButton(None) + progress.setModal(True) + progress.show() + + while not thread_monitor.is_finished(): + self.app.processEvents() + time.sleep (0.1) + + progress.hide() + + if not thread_monitor.success: + QMessageBox.warning (None, "Error while changing settings for {0}!", "ERROR: {1}".format(self.vm.namethread_monitor.error_msg)) + + self.done(0) + + def __save_changes__(self, thread_monitor): + self.AppListManager.save_appmenu_select_changes() + thread_monitor.set_finished() + + # Bases on the original code by: # Copyright (c) 2002-2007 Pascal Varet @@ -102,8 +137,6 @@ def handle_exception( exc_type, exc_value, exc_traceback ): % ( line, filename )) - - def main(): global qubes_host @@ -137,8 +170,9 @@ def main(): sys.exit(1) vm = qvm_collection.get_vm_by_name(vmname[0]) + global settings_window - settings_window = VMSettingsWindow(vm) + settings_window = VMSettingsWindow(vm, app, "basic") settings_window.show() @@ -146,6 +180,5 @@ def main(): app.exit() - if __name__ == "__main__": main()