qube_manager.py 46 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224
  1. #!/usr/bin/python3
  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-Górecki
  7. # <marmarek@invisiblethingslab.com>
  8. # Copyright (C) 2017 Wojtek Porczyk <woju@invisiblethingslab.com>
  9. #
  10. # This program is free software; you can redistribute it and/or
  11. # modify it under the terms of the GNU General Public License
  12. # as published by the Free Software Foundation; either version 2
  13. # of the License, or (at your option) any later version.
  14. #
  15. # This program is distributed in the hope that it will be useful,
  16. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. # GNU General Public License for more details.
  19. #
  20. # You should have received a copy of the GNU Lesser General Public License along
  21. # with this program; if not, see <http://www.gnu.org/licenses/>.
  22. #
  23. #
  24. import sys
  25. import os
  26. import os.path
  27. import subprocess
  28. import time
  29. from datetime import datetime, timedelta
  30. import traceback
  31. from qubesadmin import Qubes
  32. from qubesadmin import exc
  33. from PyQt4 import QtGui # pylint: disable=import-error
  34. from PyQt4 import QtCore # pylint: disable=import-error
  35. from . import ui_qubemanager # pylint: disable=no-name-in-module
  36. from . import thread_monitor
  37. from . import table_widgets
  38. from . import settings
  39. from . import global_settings
  40. from . import restore
  41. from . import backup
  42. from . import log_dialog
  43. import threading
  44. from qubesmanager.about import AboutDialog
  45. class SearchBox(QtGui.QLineEdit):
  46. def __init__(self, parent=None):
  47. super(SearchBox, self).__init__(parent)
  48. self.focusing = False
  49. def focusInEvent(self, e): # pylint: disable=invalid-name
  50. super(SearchBox, self).focusInEvent(e)
  51. self.selectAll()
  52. self.focusing = True
  53. def mousePressEvent(self, e): # pylint: disable=invalid-name
  54. super(SearchBox, self).mousePressEvent(e)
  55. if self.focusing:
  56. self.selectAll()
  57. self.focusing = False
  58. class VmRowInTable(object):
  59. # pylint: disable=too-few-public-methods
  60. def __init__(self, vm, row_no, table):
  61. self.vm = vm
  62. self.row_no = row_no
  63. # TODO: replace a various different widgets with a more generic
  64. # VmFeatureWidget or VMPropertyWidget
  65. table_widgets.row_height = VmManagerWindow.row_height
  66. table.setRowHeight(row_no, VmManagerWindow.row_height)
  67. self.type_widget = table_widgets.VmTypeWidget(vm)
  68. table.setCellWidget(row_no, VmManagerWindow.columns_indices['Type'],
  69. self.type_widget)
  70. table.setItem(row_no, VmManagerWindow.columns_indices['Type'],
  71. self.type_widget.table_item)
  72. self.label_widget = table_widgets.VmLabelWidget(vm)
  73. table.setCellWidget(row_no, VmManagerWindow.columns_indices['Label'],
  74. self.label_widget)
  75. table.setItem(row_no, VmManagerWindow.columns_indices['Label'],
  76. self.label_widget.table_item)
  77. self.name_widget = table_widgets.VmNameItem(vm)
  78. table.setItem(row_no, VmManagerWindow.columns_indices['Name'],
  79. self.name_widget)
  80. self.info_widget = table_widgets.VmInfoWidget(vm)
  81. table.setCellWidget(row_no, VmManagerWindow.columns_indices['State'],
  82. self.info_widget)
  83. table.setItem(row_no, VmManagerWindow.columns_indices['State'],
  84. self.info_widget.table_item)
  85. self.template_widget = table_widgets.VmTemplateItem(vm)
  86. table.setItem(row_no, VmManagerWindow.columns_indices['Template'],
  87. self.template_widget)
  88. self.netvm_widget = table_widgets.VmNetvmItem(vm)
  89. table.setItem(row_no, VmManagerWindow.columns_indices['NetVM'],
  90. self.netvm_widget)
  91. self.size_widget = table_widgets.VmSizeOnDiskItem(vm)
  92. table.setItem(row_no, VmManagerWindow.columns_indices['Size'],
  93. self.size_widget)
  94. self.internal_widget = table_widgets.VmInternalItem(vm)
  95. table.setItem(row_no, VmManagerWindow.columns_indices['Internal'],
  96. self.internal_widget)
  97. self.ip_widget = table_widgets.VmIPItem(vm)
  98. table.setItem(row_no, VmManagerWindow.columns_indices['IP'],
  99. self.ip_widget)
  100. self.include_in_backups_widget = \
  101. table_widgets.VmIncludeInBackupsItem(vm)
  102. table.setItem(row_no, VmManagerWindow.columns_indices[
  103. 'Backups'], self.include_in_backups_widget)
  104. self.last_backup_widget = table_widgets.VmLastBackupItem(vm)
  105. table.setItem(row_no, VmManagerWindow.columns_indices[
  106. 'Last backup'], self.last_backup_widget)
  107. def update(self, update_size_on_disk=False):
  108. """
  109. Update info in a single VM row
  110. :param update_size_on_disk: should disk utilization be updated? the
  111. widget will extract the data from VM object
  112. :return: None
  113. """
  114. self.info_widget.update_vm_state(self.vm)
  115. if update_size_on_disk:
  116. self.size_widget.update()
  117. vm_shutdown_timeout = 20000 # in msec
  118. vm_restart_check_timeout = 1000 # in msec
  119. class VmShutdownMonitor(QtCore.QObject):
  120. def __init__(self, vm, shutdown_time=vm_shutdown_timeout,
  121. check_time=vm_restart_check_timeout,
  122. and_restart=False, caller=None):
  123. QtCore.QObject.__init__(self)
  124. self.vm = vm
  125. self.shutdown_time = shutdown_time
  126. self.check_time = check_time
  127. self.and_restart = and_restart
  128. self.shutdown_started = datetime.now()
  129. self.caller = caller
  130. def restart_vm_if_needed(self):
  131. if self.and_restart and self.caller:
  132. self.caller.start_vm(self.vm)
  133. def check_again_later(self):
  134. # noinspection PyTypeChecker,PyCallByClass
  135. QtCore.QTimer.singleShot(self.check_time, self.check_if_vm_has_shutdown)
  136. def timeout_reached(self):
  137. actual = datetime.now() - self.shutdown_started
  138. allowed = timedelta(milliseconds=self.shutdown_time)
  139. return actual > allowed
  140. def check_if_vm_has_shutdown(self):
  141. vm = self.vm
  142. vm_is_running = vm.is_running()
  143. try:
  144. vm_start_time = datetime.fromtimestamp(float(vm.start_time))
  145. except (AttributeError, TypeError, ValueError):
  146. vm_start_time = None
  147. if vm_is_running and vm_start_time \
  148. and vm_start_time < self.shutdown_started:
  149. if self.timeout_reached():
  150. reply = QtGui.QMessageBox.question(
  151. None, self.tr("Qube Shutdown"),
  152. self.tr(
  153. "The Qube <b>'{0}'</b> hasn't shutdown within the last "
  154. "{1} seconds, do you want to kill it?<br>").format(
  155. vm.name, self.shutdown_time / 1000),
  156. self.tr("Kill it!"),
  157. self.tr("Wait another {0} seconds...").format(
  158. self.shutdown_time / 1000))
  159. if reply == 0:
  160. try:
  161. vm.kill()
  162. except exc.QubesVMNotStartedError:
  163. # the VM shut down while the user was thinking about
  164. # shutting it down
  165. pass
  166. self.restart_vm_if_needed()
  167. else:
  168. self.shutdown_started = datetime.now()
  169. self.check_again_later()
  170. else:
  171. self.check_again_later()
  172. else:
  173. if vm_is_running:
  174. # Due to unknown reasons, Xen sometimes reports that a domain
  175. # is running even though its start-up timestamp is not valid.
  176. # Make sure that "restart_vm_if_needed" is not called until
  177. # the domain has been completely shut down according to Xen.
  178. self.check_again_later()
  179. return
  180. self.restart_vm_if_needed()
  181. class VmManagerWindow(ui_qubemanager.Ui_VmManagerWindow, QtGui.QMainWindow):
  182. # pylint: disable=too-many-instance-attributes
  183. row_height = 30
  184. column_width = 200
  185. search = ""
  186. # suppress saving settings while initializing widgets
  187. settings_loaded = False
  188. columns_indices = {"Type": 0,
  189. "Label": 1,
  190. "Name": 2,
  191. "State": 3,
  192. "Template": 4,
  193. "NetVM": 5,
  194. "Size": 6,
  195. "Internal": 7,
  196. "IP": 8,
  197. "Backups": 9,
  198. "Last backup": 10,
  199. }
  200. def __init__(self, qt_app, qubes_app, parent=None):
  201. # pylint: disable=unused-argument
  202. super(VmManagerWindow, self).__init__()
  203. self.setupUi(self)
  204. self.manager_settings = QtCore.QSettings(self)
  205. self.qubes_app = qubes_app
  206. self.qt_app = qt_app
  207. self.searchbox = SearchBox()
  208. self.searchbox.setValidator(QtGui.QRegExpValidator(
  209. QtCore.QRegExp("[a-zA-Z0-9-]*", QtCore.Qt.CaseInsensitive), None))
  210. self.searchContainer.addWidget(self.searchbox)
  211. self.connect(self.table, QtCore.SIGNAL("itemSelectionChanged()"),
  212. self.table_selection_changed)
  213. self.table.setColumnWidth(0, self.column_width)
  214. self.sort_by_column = "Type"
  215. self.sort_order = QtCore.Qt.AscendingOrder
  216. self.vms_list = []
  217. self.vms_in_table = {}
  218. self.frame_width = 0
  219. self.frame_height = 0
  220. self.move(self.x(), 0)
  221. self.columns_actions = {
  222. self.columns_indices["Type"]: self.action_vm_type,
  223. self.columns_indices["Label"]: self.action_label,
  224. self.columns_indices["Name"]: self.action_name,
  225. self.columns_indices["State"]: self.action_state,
  226. self.columns_indices["Template"]: self.action_template,
  227. self.columns_indices["NetVM"]: self.action_netvm,
  228. self.columns_indices["Size"]: self.action_size_on_disk,
  229. self.columns_indices["Internal"]: self.action_internal,
  230. self.columns_indices["IP"]: self
  231. .action_ip, self.columns_indices["Backups"]: self
  232. .action_backups, self.columns_indices["Last backup"]: self
  233. .action_last_backup
  234. }
  235. self.visible_columns_count = len(self.columns_indices)
  236. self.table.setColumnWidth(self.columns_indices["State"], 80)
  237. self.table.setColumnWidth(self.columns_indices["Name"], 150)
  238. self.table.setColumnWidth(self.columns_indices["Label"], 40)
  239. self.table.setColumnWidth(self.columns_indices["Type"], 40)
  240. self.table.setColumnWidth(self.columns_indices["Size"], 100)
  241. self.table.setColumnWidth(self.columns_indices["Internal"], 60)
  242. self.table.setColumnWidth(self.columns_indices["IP"], 100)
  243. self.table.setColumnWidth(self.columns_indices["Backups"], 60)
  244. self.table.setColumnWidth(self.columns_indices["Last backup"], 90)
  245. self.table.horizontalHeader().setResizeMode(
  246. QtGui.QHeaderView.Interactive)
  247. self.table.horizontalHeader().setStretchLastSection(True)
  248. self.table.sortItems(self.columns_indices[self.sort_by_column],
  249. self.sort_order)
  250. self.context_menu = QtGui.QMenu(self)
  251. self.context_menu.addAction(self.action_settings)
  252. self.context_menu.addAction(self.action_editfwrules)
  253. self.context_menu.addAction(self.action_appmenus)
  254. self.context_menu.addAction(self.action_set_keyboard_layout)
  255. self.context_menu.addSeparator()
  256. self.context_menu.addAction(self.action_updatevm)
  257. self.context_menu.addAction(self.action_run_command_in_vm)
  258. self.context_menu.addAction(self.action_resumevm)
  259. self.context_menu.addAction(self.action_startvm_tools_install)
  260. self.context_menu.addAction(self.action_pausevm)
  261. self.context_menu.addAction(self.action_shutdownvm)
  262. self.context_menu.addAction(self.action_restartvm)
  263. self.context_menu.addAction(self.action_killvm)
  264. self.context_menu.addSeparator()
  265. self.context_menu.addAction(self.action_clonevm)
  266. self.context_menu.addAction(self.action_removevm)
  267. self.context_menu.addSeparator()
  268. self.context_menu.addMenu(self.logs_menu)
  269. self.context_menu.addSeparator()
  270. self.tools_context_menu = QtGui.QMenu(self)
  271. self.tools_context_menu.addAction(self.action_toolbar)
  272. self.tools_context_menu.addAction(self.action_menubar)
  273. self.connect(
  274. self.table.horizontalHeader(),
  275. QtCore.SIGNAL("sortIndicatorChanged(int, Qt::SortOrder)"),
  276. self.sort_indicator_changed)
  277. self.connect(self.table,
  278. QtCore.SIGNAL("customContextMenuRequested(const QPoint&)"),
  279. self.open_context_menu)
  280. self.connect(self.menubar,
  281. QtCore.SIGNAL("customContextMenuRequested(const QPoint&)"),
  282. lambda pos: self.open_tools_context_menu(self.menubar,
  283. pos))
  284. self.connect(self.toolbar,
  285. QtCore.SIGNAL("customContextMenuRequested(const QPoint&)"),
  286. lambda pos: self.open_tools_context_menu(self.toolbar,
  287. pos))
  288. self.connect(self.logs_menu, QtCore.SIGNAL("triggered(QAction *)"),
  289. self.show_log)
  290. self.connect(self.searchbox,
  291. QtCore.SIGNAL("textChanged(const QString&)"),
  292. self.do_search)
  293. self.table.setContentsMargins(0, 0, 0, 0)
  294. self.centralwidget.layout().setContentsMargins(0, 0, 0, 0)
  295. self.layout().setContentsMargins(0, 0, 0, 0)
  296. self.connect(self.action_menubar, QtCore.SIGNAL("toggled(bool)"),
  297. self.showhide_menubar)
  298. self.connect(self.action_toolbar, QtCore.SIGNAL("toggled(bool)"),
  299. self.showhide_toolbar)
  300. self.load_manager_settings()
  301. # disabling the table for the duration of filling speeds up the process
  302. # immensely. Yes, really.
  303. self.table.setDisabled(True)
  304. self.fill_table()
  305. self.table.setEnabled(True)
  306. self.update_size_on_disk = False
  307. self.shutdown_monitor = {}
  308. def load_manager_settings(self):
  309. # visible columns
  310. self.visible_columns_count = 0
  311. for col in self.columns_indices:
  312. col_no = self.columns_indices[col]
  313. visible = self.manager_settings.value(
  314. 'columns/%s' % col,
  315. defaultValue="true")
  316. self.columns_actions[col_no].setChecked(visible == "true")
  317. self.visible_columns_count += 1
  318. self.sort_by_column = str(
  319. self.manager_settings.value("view/sort_column",
  320. defaultValue=self.sort_by_column))
  321. self.sort_order = QtCore.Qt.SortOrder(
  322. self.manager_settings.value("view/sort_order",
  323. defaultValue=self.sort_order))
  324. self.table.sortItems(self.columns_indices[self.sort_by_column],
  325. self.sort_order)
  326. if not self.manager_settings.value("view/menubar_visible",
  327. defaultValue=True):
  328. self.action_menubar.setChecked(False)
  329. if not self.manager_settings.value("view/toolbar_visible",
  330. defaultValue=True):
  331. self.action_toolbar.setChecked(False)
  332. self.settings_loaded = True
  333. def get_vms_list(self):
  334. return [vm for vm in self.qubes_app.domains]
  335. def update_single_row(self, vm):
  336. # this fuction should be used to update a row that already exists
  337. # to add a row, one needs to use the update_table function - the
  338. # whole table needs to be redrawn (and sorted)
  339. if vm in self.qubes_app.domains:
  340. self.vms_in_table[vm.qid].update()
  341. else:
  342. self.update_table()
  343. def fill_table(self):
  344. # save current selection
  345. row_index = self.table.currentRow()
  346. selected_qid = -1
  347. if row_index != -1:
  348. vm_item = self.table.item(row_index, self.columns_indices["Name"])
  349. if vm_item:
  350. selected_qid = vm_item.qid
  351. self.table.setSortingEnabled(False)
  352. self.table.clearContents()
  353. vms_list = self.get_vms_list()
  354. vms_in_table = {}
  355. self.table.setRowCount(len(vms_list))
  356. row_no = 0
  357. for vm in vms_list:
  358. vm_row = VmRowInTable(vm, row_no, self.table)
  359. vms_in_table[vm.qid] = vm_row
  360. row_no += 1
  361. if row_no % 5 == 0:
  362. self.qt_app.processEvents()
  363. self.vms_list = vms_list
  364. self.vms_in_table = vms_in_table
  365. if selected_qid in vms_in_table.keys():
  366. self.table.setCurrentItem(
  367. self.vms_in_table[selected_qid].name_widget)
  368. self.table.setSortingEnabled(True)
  369. self.showhide_vms()
  370. def showhide_vms(self):
  371. if not self.search:
  372. for row_no in range(self.table.rowCount()):
  373. self.table.setRowHidden(row_no, False)
  374. else:
  375. for row_no in range(self.table.rowCount()):
  376. widget = self.table.cellWidget(row_no,
  377. self.columns_indices["State"])
  378. show = (self.search in widget.vm.name)
  379. self.table.setRowHidden(row_no, not show)
  380. @QtCore.pyqtSlot(str)
  381. def do_search(self, search):
  382. self.search = str(search)
  383. self.showhide_vms()
  384. # noinspection PyArgumentList
  385. @QtCore.pyqtSlot(name='on_action_search_triggered')
  386. def action_search_triggered(self):
  387. self.searchbox.setFocus()
  388. def update_table(self):
  389. # disabling the table speeds up the process of filling it
  390. self.table.setDisabled(True)
  391. self.fill_table()
  392. self.table.setEnabled(True)
  393. # TODO: instead of manually refreshing the entire table, use dbus events
  394. # reapply sorting
  395. if self.sort_by_column:
  396. self.table.sortByColumn(self.columns_indices[self.sort_by_column])
  397. self.table_selection_changed()
  398. # noinspection PyPep8Naming
  399. def sort_indicator_changed(self, column, order):
  400. self.sort_by_column = [name for name in self.columns_indices if
  401. self.columns_indices[name] == column][0]
  402. self.sort_order = order
  403. if self.settings_loaded:
  404. self.manager_settings.setValue('view/sort_column',
  405. self.sort_by_column)
  406. self.manager_settings.setValue('view/sort_order', self.sort_order)
  407. self.manager_settings.sync()
  408. def table_selection_changed(self):
  409. vm = self.get_selected_vm()
  410. if vm is not None and vm in self.qubes_app.domains:
  411. # TODO: add boot from device to menu and add windows tools there
  412. # Update available actions:
  413. self.action_settings.setEnabled(vm.klass != 'AdminVM')
  414. self.action_removevm.setEnabled(
  415. vm.klass != 'AdminVM' and not vm.is_running())
  416. self.action_clonevm.setEnabled(vm.klass != 'AdminVM')
  417. self.action_resumevm.setEnabled(
  418. not vm.is_running() or vm.get_power_state() == "Paused")
  419. self.action_pausevm.setEnabled(
  420. vm.is_running() and vm.get_power_state() != "Paused"
  421. and vm.klass != 'AdminVM')
  422. self.action_shutdownvm.setEnabled(
  423. vm.is_running() and vm.get_power_state() != "Paused"
  424. and vm.klass != 'AdminVM')
  425. self.action_restartvm.setEnabled(
  426. vm.is_running() and vm.get_power_state() != "Paused"
  427. and vm.klass != 'AdminVM'
  428. and (vm.klass != 'DispVM' or not vm.auto_cleanup))
  429. self.action_killvm.setEnabled(
  430. (vm.get_power_state() == "Paused" or vm.is_running())
  431. and vm.klass != 'AdminVM')
  432. self.action_appmenus.setEnabled(
  433. vm.klass != 'AdminVM' and vm.klass != 'DispVM'
  434. and not vm.features.get('internal', False))
  435. self.action_editfwrules.setEnabled(vm.klass != 'AdminVM')
  436. self.action_updatevm.setEnabled(getattr(vm, 'updateable', False)
  437. or vm.qid == 0)
  438. self.action_run_command_in_vm.setEnabled(
  439. not vm.get_power_state() == "Paused" and vm.qid != 0)
  440. self.action_set_keyboard_layout.setEnabled(
  441. vm.qid != 0 and
  442. vm.get_power_state() != "Paused" and vm.is_running())
  443. self.update_single_row(vm)
  444. else:
  445. self.action_settings.setEnabled(False)
  446. self.action_removevm.setEnabled(False)
  447. self.action_clonevm.setEnabled(False)
  448. self.action_resumevm.setEnabled(False)
  449. self.action_pausevm.setEnabled(False)
  450. self.action_shutdownvm.setEnabled(False)
  451. self.action_restartvm.setEnabled(False)
  452. self.action_killvm.setEnabled(False)
  453. self.action_appmenus.setEnabled(False)
  454. self.action_editfwrules.setEnabled(False)
  455. self.action_updatevm.setEnabled(False)
  456. self.action_run_command_in_vm.setEnabled(False)
  457. self.action_set_keyboard_layout.setEnabled(False)
  458. # noinspection PyArgumentList
  459. @QtCore.pyqtSlot(name='on_action_createvm_triggered')
  460. def action_createvm_triggered(self): # pylint: disable=no-self-use
  461. subprocess.check_call('qubes-vm-create')
  462. def get_selected_vm(self):
  463. # vm selection relies on the VmInfo widget's value used
  464. # for sorting by VM name
  465. row_index = self.table.currentRow()
  466. if row_index != -1:
  467. vm_item = self.table.item(row_index, self.columns_indices["Name"])
  468. # here is possible race with update_table timer so check
  469. # if really got the item
  470. if vm_item is None:
  471. return None
  472. qid = vm_item.qid
  473. assert self.vms_in_table[qid] is not None
  474. vm = self.vms_in_table[qid].vm
  475. return vm
  476. else:
  477. return None
  478. # noinspection PyArgumentList
  479. @QtCore.pyqtSlot(name='on_action_removevm_triggered')
  480. def action_removevm_triggered(self):
  481. vm = self.get_selected_vm()
  482. if vm.klass == 'TemplateVM':
  483. dependent_vms = 0
  484. for single_vm in self.qubes_app.domains:
  485. if getattr(single_vm, 'template', None) == vm:
  486. dependent_vms += 1
  487. if dependent_vms > 0:
  488. QtGui.QMessageBox.warning(
  489. None, self.tr("Warning!"),
  490. self.tr("This Template Qube cannot be removed, "
  491. "because there is at least one Qube that is based "
  492. "on it.<br><small>If you want to remove this "
  493. "Template Qube and all the Qubes based on it, you "
  494. "should first remove each individual Qube that "
  495. "uses this template.</small>"))
  496. return
  497. (requested_name, ok) = QtGui.QInputDialog.getText(
  498. None, self.tr("Qube Removal Confirmation"),
  499. self.tr("Are you sure you want to remove the Qube <b>'{0}'</b>"
  500. "?<br> All data on this Qube's private storage will be "
  501. "lost!<br><br>Type the name of the Qube (<b>{1}</b>) below "
  502. "to confirm:").format(vm.name, vm.name))
  503. if not ok:
  504. # user clicked cancel
  505. return
  506. elif requested_name != vm.name:
  507. # name did not match
  508. QtGui.QMessageBox.warning(
  509. None,
  510. self.tr("Qube removal confirmation failed"),
  511. self.tr(
  512. "Entered name did not match! Not removing "
  513. "{0}.").format(vm.name))
  514. return
  515. else:
  516. # remove the VM
  517. t_monitor = thread_monitor.ThreadMonitor()
  518. thread = threading.Thread(target=self.do_remove_vm,
  519. args=(vm, self.qubes_app, t_monitor))
  520. thread.daemon = True
  521. thread.start()
  522. progress = QtGui.QProgressDialog(
  523. self.tr(
  524. "Removing Qube: <b>{0}</b>...").format(vm.name), "", 0, 0)
  525. progress.setCancelButton(None)
  526. progress.setModal(True)
  527. progress.show()
  528. while not t_monitor.is_finished():
  529. self.qt_app.processEvents()
  530. time.sleep(0.1)
  531. progress.hide()
  532. if t_monitor.success:
  533. pass
  534. else:
  535. QtGui.QMessageBox.warning(None, self.tr("Error removing Qube!"),
  536. self.tr("ERROR: {0}").format(
  537. t_monitor.error_msg))
  538. self.update_table()
  539. @staticmethod
  540. def do_remove_vm(vm, qubes_app, t_monitor):
  541. try:
  542. del qubes_app.domains[vm.name]
  543. except exc.QubesException as ex:
  544. t_monitor.set_error_msg(str(ex))
  545. t_monitor.set_finished()
  546. # noinspection PyArgumentList
  547. @QtCore.pyqtSlot(name='on_action_clonevm_triggered')
  548. def action_clonevm_triggered(self):
  549. vm = self.get_selected_vm()
  550. name_number = 1
  551. name_format = vm.name + '-clone-%d'
  552. while name_format % name_number in self.qubes_app.domains.keys():
  553. name_number += 1
  554. (clone_name, ok) = QtGui.QInputDialog.getText(
  555. self, self.tr('Qubes clone Qube'),
  556. self.tr('Enter name for Qube <b>{}</b> clone:').format(vm.name),
  557. text=(name_format % name_number))
  558. if not ok or clone_name == "":
  559. return
  560. t_monitor = thread_monitor.ThreadMonitor()
  561. thread = threading.Thread(target=self.do_clone_vm,
  562. args=(vm, self.qubes_app,
  563. clone_name, t_monitor))
  564. thread.daemon = True
  565. thread.start()
  566. progress = QtGui.QProgressDialog(
  567. self.tr("Cloning Qube <b>{0}</b> to <b>{1}</b>...").format(
  568. vm.name, clone_name), "", 0, 0)
  569. progress.setCancelButton(None)
  570. progress.setModal(True)
  571. progress.show()
  572. while not t_monitor.is_finished():
  573. self.qt_app.processEvents()
  574. time.sleep(0.2)
  575. progress.hide()
  576. if not t_monitor.success:
  577. QtGui.QMessageBox.warning(
  578. None,
  579. self.tr("Error while cloning Qube"),
  580. self.tr("Exception while cloning:<br>{0}").format(
  581. t_monitor.error_msg))
  582. self.update_table()
  583. @staticmethod
  584. def do_clone_vm(src_vm, qubes_app, dst_name, t_monitor):
  585. dst_vm = None
  586. try:
  587. dst_vm = qubes_app.clone_vm(src_vm, dst_name)
  588. except exc.QubesException as ex:
  589. t_monitor.set_error_msg(str(ex))
  590. if dst_vm:
  591. pass
  592. t_monitor.set_finished()
  593. # noinspection PyArgumentList
  594. @QtCore.pyqtSlot(name='on_action_resumevm_triggered')
  595. def action_resumevm_triggered(self):
  596. vm = self.get_selected_vm()
  597. if vm.get_power_state() in ["Paused", "Suspended"]:
  598. try:
  599. vm.unpause()
  600. except exc.QubesException as ex:
  601. QtGui.QMessageBox.warning(
  602. None, self.tr("Error unpausing Qube!"),
  603. self.tr("ERROR: {0}").format(ex))
  604. return
  605. self.start_vm(vm)
  606. self.update_single_row(vm)
  607. def start_vm(self, vm):
  608. if vm.is_running():
  609. return
  610. t_monitor = thread_monitor.ThreadMonitor()
  611. thread = threading.Thread(target=self.do_start_vm,
  612. args=(vm, t_monitor))
  613. thread.daemon = True
  614. thread.start()
  615. while not t_monitor.is_finished():
  616. self.qt_app.processEvents()
  617. time.sleep(0.1)
  618. if not t_monitor.success:
  619. QtGui.QMessageBox.warning(
  620. None,
  621. self.tr("Error starting Qube!"),
  622. self.tr("ERROR: {0}").format(t_monitor.error_msg))
  623. self.update_single_row(vm)
  624. @staticmethod
  625. def do_start_vm(vm, t_monitor):
  626. try:
  627. vm.start()
  628. except exc.QubesException as ex:
  629. t_monitor.set_error_msg(str(ex))
  630. t_monitor.set_finished()
  631. return
  632. t_monitor.set_finished()
  633. # noinspection PyArgumentList
  634. @QtCore.pyqtSlot(name='on_action_startvm_tools_install_triggered')
  635. # TODO: replace with boot from device
  636. def action_startvm_tools_install_triggered(self):
  637. # pylint: disable=invalid-name
  638. pass
  639. @QtCore.pyqtSlot(name='on_action_pausevm_triggered')
  640. def action_pausevm_triggered(self):
  641. vm = self.get_selected_vm()
  642. try:
  643. vm.pause()
  644. self.update_single_row(vm)
  645. except exc.QubesException as ex:
  646. QtGui.QMessageBox.warning(
  647. None,
  648. self.tr("Error pausing Qube!"),
  649. self.tr("ERROR: {0}").format(ex))
  650. return
  651. # noinspection PyArgumentList
  652. @QtCore.pyqtSlot(name='on_action_shutdownvm_triggered')
  653. def action_shutdownvm_triggered(self):
  654. vm = self.get_selected_vm()
  655. reply = QtGui.QMessageBox.question(
  656. None, self.tr("Qube Shutdown Confirmation"),
  657. self.tr("Are you sure you want to power down the Qube"
  658. " <b>'{0}'</b>?<br><small>This will shutdown all the "
  659. "running applications within this Qube.</small>").format(
  660. vm.name), QtGui.QMessageBox.Yes | QtGui.QMessageBox.Cancel)
  661. self.qt_app.processEvents()
  662. if reply == QtGui.QMessageBox.Yes:
  663. self.shutdown_vm(vm)
  664. self.update_single_row(vm)
  665. def shutdown_vm(self, vm, shutdown_time=vm_shutdown_timeout,
  666. check_time=vm_restart_check_timeout, and_restart=False):
  667. try:
  668. vm.shutdown()
  669. except exc.QubesException as ex:
  670. QtGui.QMessageBox.warning(
  671. None,
  672. self.tr("Error shutting down Qube!"),
  673. self.tr("ERROR: {0}").format(ex))
  674. return
  675. self.shutdown_monitor[vm.qid] = VmShutdownMonitor(vm, shutdown_time,
  676. check_time,
  677. and_restart, self)
  678. # noinspection PyCallByClass,PyTypeChecker
  679. QtCore.QTimer.singleShot(check_time, self.shutdown_monitor[
  680. vm.qid].check_if_vm_has_shutdown)
  681. # noinspection PyArgumentList
  682. @QtCore.pyqtSlot(name='on_action_restartvm_triggered')
  683. def action_restartvm_triggered(self):
  684. vm = self.get_selected_vm()
  685. reply = QtGui.QMessageBox.question(
  686. None, self.tr("Qube Restart Confirmation"),
  687. self.tr("Are you sure you want to restart the Qube <b>'{0}'</b>?"
  688. "<br><small>This will shutdown all the running "
  689. "applications within this Qube.</small>").format(vm.name),
  690. QtGui.QMessageBox.Yes | QtGui.QMessageBox.Cancel)
  691. self.qt_app.processEvents()
  692. if reply == QtGui.QMessageBox.Yes:
  693. # in case the user shut down the VM in the meantime
  694. if vm.is_running():
  695. self.shutdown_vm(vm, and_restart=True)
  696. else:
  697. self.start_vm(vm)
  698. self.update_single_row(vm)
  699. # noinspection PyArgumentList
  700. @QtCore.pyqtSlot(name='on_action_killvm_triggered')
  701. def action_killvm_triggered(self):
  702. vm = self.get_selected_vm()
  703. if not (vm.is_running() or vm.is_paused()):
  704. info = self.tr("Qube <b>'{0}'</b> is not running. Are you "
  705. "absolutely sure you want to try to kill it?<br>"
  706. "<small>This will end <b>(not shutdown!)</b> all "
  707. "the running applications within this "
  708. "Qube.</small>").format(vm.name)
  709. else:
  710. info = self.tr("Are you sure you want to kill the Qube "
  711. "<b>'{0}'</b>?<br><small>This will end <b>(not "
  712. "shutdown!)</b> all the running applications within "
  713. "this Qube.</small>").format(vm.name)
  714. reply = QtGui.QMessageBox.question(
  715. None, self.tr("Qube Kill Confirmation"), info,
  716. QtGui.QMessageBox.Yes | QtGui.QMessageBox.Cancel,
  717. QtGui.QMessageBox.Cancel)
  718. self.qt_app.processEvents()
  719. if reply == QtGui.QMessageBox.Yes:
  720. try:
  721. vm.kill()
  722. except exc.QubesException as ex:
  723. QtGui.QMessageBox.critical(
  724. None, self.tr("Error while killing Qube!"),
  725. self.tr(
  726. "<b>An exception ocurred while killing {0}.</b><br>"
  727. "ERROR: {1}").format(vm.name, ex))
  728. return
  729. # noinspection PyArgumentList
  730. @QtCore.pyqtSlot(name='on_action_settings_triggered')
  731. def action_settings_triggered(self):
  732. vm = self.get_selected_vm()
  733. if vm:
  734. settings_window = settings.VMSettingsWindow(
  735. vm, self.qt_app, "basic")
  736. settings_window.exec_()
  737. self.update_single_row(vm)
  738. # noinspection PyArgumentList
  739. @QtCore.pyqtSlot(name='on_action_appmenus_triggered')
  740. def action_appmenus_triggered(self):
  741. vm = self.get_selected_vm()
  742. if vm:
  743. settings_window = settings.VMSettingsWindow(
  744. vm, self.qt_app, "applications")
  745. settings_window.exec_()
  746. # noinspection PyArgumentList
  747. @QtCore.pyqtSlot(name='on_action_refresh_list_triggered')
  748. def action_refresh_list_triggered(self):
  749. self.qubes_app.domains.clear_cache()
  750. self.update_table()
  751. # noinspection PyArgumentList
  752. @QtCore.pyqtSlot(name='on_action_updatevm_triggered')
  753. def action_updatevm_triggered(self):
  754. vm = self.get_selected_vm()
  755. if not vm.is_running():
  756. reply = QtGui.QMessageBox.question(
  757. None, self.tr("Qube Update Confirmation"),
  758. self.tr(
  759. "<b>{0}</b><br>The Qube has to be running to be updated."
  760. "<br>Do you want to start it?<br>").format(vm.name),
  761. QtGui.QMessageBox.Yes | QtGui.QMessageBox.Cancel)
  762. if reply != QtGui.QMessageBox.Yes:
  763. return
  764. self.qt_app.processEvents()
  765. t_monitor = thread_monitor.ThreadMonitor()
  766. thread = threading.Thread(target=self.do_update_vm,
  767. args=(vm, t_monitor))
  768. thread.daemon = True
  769. thread.start()
  770. progress = QtGui.QProgressDialog(
  771. self.tr(
  772. "<b>{0}</b><br>Please wait for the updater to "
  773. "launch...").format(vm.name), "", 0, 0)
  774. progress.setCancelButton(None)
  775. progress.setModal(True)
  776. progress.show()
  777. while not t_monitor.is_finished():
  778. self.qt_app.processEvents()
  779. time.sleep(0.2)
  780. progress.hide()
  781. if vm.qid != 0:
  782. if not t_monitor.success:
  783. QtGui.QMessageBox.warning(
  784. None,
  785. self.tr("Error on Qube update!"),
  786. self.tr("ERROR: {0}").format(t_monitor.error_msg))
  787. self.update_single_row(vm)
  788. @staticmethod
  789. def do_update_vm(vm, t_monitor):
  790. try:
  791. if vm.qid == 0:
  792. subprocess.check_call(
  793. ["/usr/bin/qubes-dom0-update", "--clean", "--gui"])
  794. else:
  795. if not vm.is_running():
  796. vm.start()
  797. vm.run_service("qubes.InstallUpdatesGUI",
  798. user="root", wait=False)
  799. except (ChildProcessError, exc.QubesException) as ex:
  800. t_monitor.set_error_msg(str(ex))
  801. t_monitor.set_finished()
  802. return
  803. t_monitor.set_finished()
  804. # noinspection PyArgumentList
  805. @QtCore.pyqtSlot(name='on_action_run_command_in_vm_triggered')
  806. def action_run_command_in_vm_triggered(self):
  807. # pylint: disable=invalid-name
  808. vm = self.get_selected_vm()
  809. (command_to_run, ok) = QtGui.QInputDialog.getText(
  810. self, self.tr('Qubes command entry'),
  811. self.tr('Run command in <b>{}</b>:').format(vm.name))
  812. if not ok or command_to_run == "":
  813. return
  814. t_monitor = thread_monitor.ThreadMonitor()
  815. thread = threading.Thread(target=self.do_run_command_in_vm, args=(
  816. vm, command_to_run, t_monitor))
  817. thread.daemon = True
  818. thread.start()
  819. while not t_monitor.is_finished():
  820. self.qt_app.processEvents()
  821. time.sleep(0.2)
  822. if not t_monitor.success:
  823. QtGui.QMessageBox.warning(
  824. None, self.tr("Error while running command"),
  825. self.tr("Exception while running command:<br>{0}").format(
  826. t_monitor.error_msg))
  827. @staticmethod
  828. def do_run_command_in_vm(vm, command_to_run, t_monitor):
  829. try:
  830. vm.run(command_to_run)
  831. except (ChildProcessError, exc.QubesException) as ex:
  832. t_monitor.set_error_msg(str(ex))
  833. t_monitor.set_finished()
  834. # noinspection PyArgumentList
  835. @QtCore.pyqtSlot(name='on_action_set_keyboard_layout_triggered')
  836. def action_set_keyboard_layout_triggered(self):
  837. # pylint: disable=invalid-name
  838. vm = self.get_selected_vm()
  839. vm.run('qubes-change-keyboard-layout')
  840. # noinspection PyArgumentList
  841. @QtCore.pyqtSlot(name='on_action_editfwrules_triggered')
  842. def action_editfwrules_triggered(self):
  843. vm = self.get_selected_vm()
  844. settings_window = settings.VMSettingsWindow(vm, self.qt_app, "firewall")
  845. settings_window.exec_()
  846. # noinspection PyArgumentList
  847. @QtCore.pyqtSlot(name='on_action_global_settings_triggered')
  848. def action_global_settings_triggered(self): # pylint: disable=invalid-name
  849. global_settings_window = global_settings.GlobalSettingsWindow(
  850. self.qt_app,
  851. self.qubes_app)
  852. global_settings_window.exec_()
  853. # noinspection PyArgumentList
  854. @QtCore.pyqtSlot(name='on_action_show_network_triggered')
  855. def action_show_network_triggered(self):
  856. pass
  857. # TODO: revive for 4.1
  858. # network_notes_dialog = NetworkNotesDialog()
  859. # network_notes_dialog.exec_()
  860. # noinspection PyArgumentList
  861. @QtCore.pyqtSlot(name='on_action_restore_triggered')
  862. def action_restore_triggered(self):
  863. restore_window = restore.RestoreVMsWindow(self.qt_app, self.qubes_app)
  864. restore_window.exec_()
  865. # noinspection PyArgumentList
  866. @QtCore.pyqtSlot(name='on_action_backup_triggered')
  867. def action_backup_triggered(self):
  868. backup_window = backup.BackupVMsWindow(self.qt_app, self.qubes_app)
  869. backup_window.exec_()
  870. # noinspection PyArgumentList
  871. @QtCore.pyqtSlot(name='on_action_exit_triggered')
  872. def action_exit_triggered(self):
  873. self.close()
  874. def showhide_menubar(self, checked):
  875. self.menubar.setVisible(checked)
  876. if not checked:
  877. self.context_menu.addAction(self.action_menubar)
  878. else:
  879. self.context_menu.removeAction(self.action_menubar)
  880. if self.settings_loaded:
  881. self.manager_settings.setValue('view/menubar_visible', checked)
  882. self.manager_settings.sync()
  883. def showhide_toolbar(self, checked):
  884. self.toolbar.setVisible(checked)
  885. if not checked:
  886. self.context_menu.addAction(self.action_toolbar)
  887. else:
  888. self.context_menu.removeAction(self.action_toolbar)
  889. if self.settings_loaded:
  890. self.manager_settings.setValue('view/toolbar_visible', checked)
  891. self.manager_settings.sync()
  892. def showhide_column(self, col_num, show):
  893. self.table.setColumnHidden(col_num, not show)
  894. val = 1 if show else -1
  895. self.visible_columns_count += val
  896. if self.visible_columns_count == 1:
  897. # disable hiding the last one
  898. for col in self.columns_actions:
  899. if self.columns_actions[col].isChecked():
  900. self.columns_actions[col].setEnabled(False)
  901. break
  902. elif self.visible_columns_count == 2 and val == 1:
  903. # enable hiding previously disabled column
  904. for col in self.columns_actions:
  905. if not self.columns_actions[col].isEnabled():
  906. self.columns_actions[col].setEnabled(True)
  907. break
  908. if self.settings_loaded:
  909. col_name = [name for name in self.columns_indices if
  910. self.columns_indices[name] == col_num][0]
  911. self.manager_settings.setValue('columns/%s' % col_name, show)
  912. self.manager_settings.sync()
  913. def on_action_vm_type_toggled(self, checked):
  914. self.showhide_column(self.columns_indices['Type'], checked)
  915. def on_action_label_toggled(self, checked):
  916. self.showhide_column(self.columns_indices['Label'], checked)
  917. def on_action_name_toggled(self, checked):
  918. self.showhide_column(self.columns_indices['Name'], checked)
  919. def on_action_state_toggled(self, checked):
  920. self.showhide_column(self.columns_indices['State'], checked)
  921. def on_action_internal_toggled(self, checked):
  922. self.showhide_column(self.columns_indices['Internal'], checked)
  923. def on_action_ip_toggled(self, checked):
  924. self.showhide_column(self.columns_indices['IP'], checked)
  925. def on_action_backups_toggled(self, checked):
  926. self.showhide_column(self.columns_indices['Backups'], checked)
  927. def on_action_last_backup_toggled(self, checked):
  928. self.showhide_column(self.columns_indices['Last backup'], checked)
  929. def on_action_template_toggled(self, checked):
  930. self.showhide_column(self.columns_indices['Template'], checked)
  931. def on_action_netvm_toggled(self, checked):
  932. self.showhide_column(self.columns_indices['NetVM'], checked)
  933. def on_action_size_on_disk_toggled(self, checked):
  934. self.showhide_column(self.columns_indices['Size'], checked)
  935. # noinspection PyArgumentList
  936. @QtCore.pyqtSlot(name='on_action_about_qubes_triggered')
  937. def action_about_qubes_triggered(self): # pylint: disable=no-self-use
  938. about = AboutDialog()
  939. about.exec_()
  940. def createPopupMenu(self): # pylint: disable=invalid-name
  941. menu = QtGui.QMenu()
  942. menu.addAction(self.action_toolbar)
  943. menu.addAction(self.action_menubar)
  944. return menu
  945. def open_tools_context_menu(self, widget, point):
  946. self.tools_context_menu.exec_(widget.mapToGlobal(point))
  947. @QtCore.pyqtSlot('const QPoint&')
  948. def open_context_menu(self, point):
  949. vm = self.get_selected_vm()
  950. # logs menu
  951. self.logs_menu.clear()
  952. if vm.qid == 0:
  953. logfiles = ["/var/log/xen/console/hypervisor.log"]
  954. else:
  955. logfiles = [
  956. "/var/log/xen/console/guest-" + vm.name + ".log",
  957. "/var/log/xen/console/guest-" + vm.name + "-dm.log",
  958. "/var/log/qubes/guid." + vm.name + ".log",
  959. "/var/log/qubes/qrexec." + vm.name + ".log",
  960. ]
  961. menu_empty = True
  962. for logfile in logfiles:
  963. if os.path.exists(logfile):
  964. action = self.logs_menu.addAction(QtGui.QIcon(":/log.png"),
  965. logfile)
  966. action.setData(logfile)
  967. menu_empty = False
  968. self.logs_menu.setEnabled(not menu_empty)
  969. self.context_menu.exec_(self.table.mapToGlobal(point))
  970. @QtCore.pyqtSlot('QAction *')
  971. def show_log(self, action):
  972. log = str(action.data())
  973. log_dlg = log_dialog.LogDialog(self.qt_app, log)
  974. log_dlg.exec_()
  975. # Bases on the original code by:
  976. # Copyright (c) 2002-2007 Pascal Varet <p.varet@gmail.com>
  977. def handle_exception(exc_type, exc_value, exc_traceback):
  978. filename, line, dummy, dummy = traceback.extract_tb(exc_traceback).pop()
  979. filename = os.path.basename(filename)
  980. error = "%s: %s" % (exc_type.__name__, exc_value)
  981. strace = ""
  982. stacktrace = traceback.extract_tb(exc_traceback)
  983. while stacktrace:
  984. (filename, line, func, txt) = stacktrace.pop()
  985. strace += "----\n"
  986. strace += "line: %s\n" % txt
  987. strace += "func: %s\n" % func
  988. strace += "line no.: %d\n" % line
  989. strace += "file: %s\n" % filename
  990. msg_box = QtGui.QMessageBox()
  991. msg_box.setDetailedText(strace)
  992. msg_box.setIcon(QtGui.QMessageBox.Critical)
  993. msg_box.setWindowTitle("Houston, we have a problem...")
  994. msg_box.setText("Whoops. A critical error has occured. "
  995. "This is most likely a bug in Qubes Manager.<br><br>"
  996. "<b><i>%s</i></b>" % error +
  997. "<br/>at line <b>%d</b><br/>of file %s.<br/><br/>"
  998. % (line, filename))
  999. msg_box.exec_()
  1000. def main():
  1001. qt_app = QtGui.QApplication(sys.argv)
  1002. qt_app.setOrganizationName("The Qubes Project")
  1003. qt_app.setOrganizationDomain("http://qubes-os.org")
  1004. qt_app.setApplicationName("Qube Manager")
  1005. qt_app.setWindowIcon(QtGui.QIcon.fromTheme("qubes-manager"))
  1006. sys.excepthook = handle_exception
  1007. qubes_app = Qubes()
  1008. manager_window = VmManagerWindow(qt_app, qubes_app)
  1009. manager_window.show()
  1010. timer = QtCore.QTimer()
  1011. timer.singleShot(1, manager_window.update_table)
  1012. qt_app.exec_()
  1013. if __name__ == "__main__":
  1014. main()