settings.py 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. #!/usr/bin/python2.6
  2. #
  3. # The Qubes OS Project, http://www.qubes-os.org
  4. #
  5. # Copyright (C) 2012 Agnieszka Kostrzewa <agnieszka.kostrzewa@gmail.com>
  6. # Copyright (C) 2012 Marek Marczykowski <marmarek@mimuw.edu.pl>
  7. #
  8. # This program is free software; you can redistribute it and/or
  9. # modify it under the terms of the GNU General Public License
  10. # as published by the Free Software Foundation; either version 2
  11. # of the License, or (at your option) any later version.
  12. #
  13. # This program is distributed in the hope that it will be useful,
  14. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. # GNU General Public License for more details.
  17. #
  18. # You should have received a copy of the GNU General Public License
  19. # along with this program; if not, write to the Free Software
  20. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  21. #
  22. #
  23. import sys
  24. import os
  25. from PyQt4.QtCore import *
  26. from PyQt4.QtGui import *
  27. from qubes.qubes import QubesVmCollection
  28. from qubes.qubes import QubesException
  29. from qubes.qubes import qubes_appmenu_create_cmd
  30. from qubes.qubes import qubes_appmenu_remove_cmd
  31. from qubes.qubes import QubesDaemonPidfile
  32. from qubes.qubes import QubesHost
  33. from qubes.qubes import qrexec_client_path
  34. import qubesmanager.resources_rc
  35. from pyinotify import WatchManager, Notifier, ThreadedNotifier, EventsCodes, ProcessEvent
  36. import subprocess
  37. import time
  38. import threading
  39. from operator import itemgetter
  40. from ui_settingsdlg import *
  41. from multiselectwidget import *
  42. class VMSettingsWindow(Ui_SettingsDialog, QDialog):
  43. def __init__(self, vm, init_page=0, parent=None):
  44. super(VMSettingsWindow, self).__init__(parent)
  45. self.setupUi(self)
  46. if init_page in range(self.tabWidget.count()):
  47. self.tabWidget.setCurrentIndex(init_page)
  48. self.connect(self.buttonBox, SIGNAL("accepted()"), self.save_and_apply)
  49. self.connect(self.buttonBox, SIGNAL("rejected()"), self.reject)
  50. self.app_list = MultiSelectWidget(self)
  51. self.dev_list = MultiSelectWidget(self)
  52. self.apps_layout.addWidget(self.app_list)
  53. self.devices_layout.addWidget(self.dev_list)
  54. self.vm = vm
  55. if self.vm.template_vm:
  56. self.source_vm = self.vm.template_vm
  57. else:
  58. self.source_vm = self.vm
  59. #self.fill_apps_list()
  60. #self.fill_devices_list()
  61. def reject(self):
  62. self.done(0)
  63. def save_and_apply(self):
  64. pass
  65. # Bases on the original code by:
  66. # Copyright (c) 2002-2007 Pascal Varet <p.varet@gmail.com>
  67. def handle_exception( exc_type, exc_value, exc_traceback ):
  68. import sys
  69. import os.path
  70. import traceback
  71. filename, line, dummy, dummy = traceback.extract_tb( exc_traceback ).pop()
  72. filename = os.path.basename( filename )
  73. error = "%s: %s" % ( exc_type.__name__, exc_value )
  74. QMessageBox.critical(None, "Houston, we have a problem...",
  75. "Whoops. A critical error has occured. This is most likely a bug "
  76. "in Qubes VM Settings application.<br><br>"
  77. "<b><i>%s</i></b>" % error +
  78. "at <b>line %d</b> of file <b>%s</b>.<br/><br/>"
  79. % ( line, filename ))
  80. def main():
  81. global qubes_host
  82. qubes_host = QubesHost()
  83. global app
  84. app = QApplication(sys.argv)
  85. app.setOrganizationName("The Qubes Project")
  86. app.setOrganizationDomain("http://qubes-os.org")
  87. app.setApplicationName("Qubes VM Settings")
  88. sys.excepthook = handle_exception
  89. qvm_collection = QubesVmCollection()
  90. qvm_collection.lock_db_for_reading()
  91. qvm_collection.load()
  92. qvm_collection.unlock_db()
  93. vm = None
  94. if len(sys.argv) > 1:
  95. vm = qvm_collection.get_vm_by_name(sys.argv[1])
  96. if vm is None or vm.qid not in qvm_collection:
  97. QMessageBox.critical(None, "Qubes VM Settings Error",
  98. "A VM with the name '{0}' does not exist in the system.".format(sys.argv[1]))
  99. sys.exit(1)
  100. else:
  101. vms_list = [vm.name for vm in qvm_collection.values() if (vm.is_appvm() or vm.is_template())]
  102. vmname = QInputDialog.getItem(None, "Select VM", "Select VM:", vms_list, editable = False)
  103. if not vmname[1]:
  104. sys.exit(1)
  105. vm = qvm_collection.get_vm_by_name(vmname[0])
  106. global settings_window
  107. settings_window = VMSettingsWindow(vm)
  108. settings_window.show()
  109. app.exec_()
  110. app.exit()
  111. if __name__ == "__main__":
  112. main()