2013-01-23 15:55:14 +01:00
|
|
|
#!/usr/bin/python2
|
2010-05-11 16:51:31 +02:00
|
|
|
#
|
|
|
|
# The Qubes OS Project, http://www.qubes-os.org
|
|
|
|
#
|
|
|
|
# Copyright (C) 2010 Joanna Rutkowska <joanna@invisiblethingslab.com>
|
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or
|
|
|
|
# modify it under the terms of the GNU General Public License
|
|
|
|
# as published by the Free Software Foundation; either version 2
|
|
|
|
# of the License, or (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program; if not, write to the Free Software
|
|
|
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
#
|
|
|
|
#
|
|
|
|
|
|
|
|
import sys
|
2011-10-31 21:47:51 +01:00
|
|
|
import os
|
2013-10-18 03:33:56 +02:00
|
|
|
import os.path
|
2012-05-15 09:11:25 +02:00
|
|
|
import signal
|
2015-05-03 18:46:39 +02:00
|
|
|
import subprocess
|
|
|
|
import time
|
|
|
|
from datetime import datetime, timedelta
|
|
|
|
|
2010-05-11 16:51:31 +02:00
|
|
|
from PyQt4.QtGui import *
|
2015-05-03 18:46:39 +02:00
|
|
|
from PyQt4.QtDBus import QDBusVariant, QDBusMessage
|
2013-04-13 02:54:24 +02:00
|
|
|
from PyQt4.QtDBus import QDBusConnection
|
2015-05-03 18:46:39 +02:00
|
|
|
from PyQt4.QtDBus import QDBusInterface, QDBusAbstractAdaptor
|
|
|
|
from pyinotify import WatchManager, ThreadedNotifier, EventsCodes, \
|
|
|
|
ProcessEvent
|
2010-05-11 16:51:31 +02:00
|
|
|
|
|
|
|
from qubes.qubes import QubesVmCollection
|
|
|
|
from qubes.qubes import QubesException
|
2015-05-03 18:46:39 +02:00
|
|
|
from qubes.qubes import system_path
|
2010-05-11 16:51:31 +02:00
|
|
|
from qubes.qubes import QubesDaemonPidfile
|
2010-09-16 18:49:36 +02:00
|
|
|
from qubes.qubes import QubesHost
|
2015-10-01 22:34:49 +02:00
|
|
|
from qubesmanager.about import AboutDialog
|
2014-03-31 01:17:27 +02:00
|
|
|
import table_widgets
|
|
|
|
from block import QubesBlockDevicesManager
|
|
|
|
from table_widgets import VmTypeWidget, VmLabelWidget, VmNameItem, \
|
|
|
|
VmInfoWidget, VmTemplateItem, VmNetvmItem, VmUsageBarWidget, ChartWidget, \
|
|
|
|
VmSizeOnDiskItem, VmInternalItem, VmIPItem, VmIncludeInBackupsItem, \
|
|
|
|
VmLastBackupItem
|
2015-05-03 18:46:39 +02:00
|
|
|
from qubes.qubes import QubesHVm
|
2011-10-31 21:46:35 +01:00
|
|
|
from qubes import qubesutils
|
2012-01-22 18:45:41 +01:00
|
|
|
from ui_mainwindow import *
|
2012-05-11 22:52:27 +02:00
|
|
|
from create_new_vm import NewVmDlg
|
2012-01-31 14:29:13 +01:00
|
|
|
from settings import VMSettingsWindow
|
|
|
|
from restore import RestoreVMsWindow
|
|
|
|
from backup import BackupVMsWindow
|
2012-01-31 17:29:00 +01:00
|
|
|
from global_settings import GlobalSettingsWindow
|
2017-01-28 04:15:58 +01:00
|
|
|
from networknotes import NetworkNotesDialog
|
2012-05-10 13:46:55 +02:00
|
|
|
from log_dialog import LogDialog
|
2012-02-20 07:56:38 +01:00
|
|
|
from thread_monitor import *
|
2016-11-27 01:12:51 +01:00
|
|
|
from clipboard import *
|
2010-05-11 16:51:31 +02:00
|
|
|
|
2015-05-03 17:11:23 +02:00
|
|
|
|
2013-03-19 13:22:31 +01:00
|
|
|
qubes_clipboard_info_file = "/var/run/qubes/qubes-clipboard.bin.source"
|
2011-03-02 14:42:11 +01:00
|
|
|
|
2015-05-03 17:11:23 +02:00
|
|
|
update_suggestion_interval = 14 # 14 days
|
2011-10-31 21:47:51 +01:00
|
|
|
|
2012-07-05 01:10:01 +02:00
|
|
|
dbus_object_path = '/org/qubesos/QubesManager'
|
|
|
|
dbus_interface = 'org.qubesos.QubesManager'
|
2012-07-24 23:46:03 +02:00
|
|
|
system_bus = None
|
2012-11-06 06:50:14 +01:00
|
|
|
session_bus = None
|
2012-07-05 01:10:01 +02:00
|
|
|
|
2012-03-27 10:36:58 +02:00
|
|
|
|
2013-04-13 04:10:13 +02:00
|
|
|
class QMVmState:
|
|
|
|
ErrorMsg = 1
|
|
|
|
AudioRecAvailable = 2
|
|
|
|
AudioRecAllowed = 3
|
|
|
|
|
2015-05-03 17:11:23 +02:00
|
|
|
|
2013-03-12 15:56:40 +01:00
|
|
|
class QubesManagerFileWatcher(ProcessEvent):
|
2015-05-03 18:42:59 +02:00
|
|
|
def __init__(self, update_func, **kargs):
|
|
|
|
super(QubesManagerFileWatcher, self).__init__(**kargs)
|
2010-05-11 16:51:31 +02:00
|
|
|
self.update_func = update_func
|
2011-03-07 16:48:53 +01:00
|
|
|
|
2015-05-03 17:11:23 +02:00
|
|
|
def process_IN_MODIFY(self, event):
|
2013-03-16 21:07:53 +01:00
|
|
|
if event.path == system_path["qubes_store_filename"]:
|
2013-03-12 15:56:40 +01:00
|
|
|
self.update_func()
|
|
|
|
|
2015-05-03 17:11:23 +02:00
|
|
|
def process_IN_MOVED_TO(self, event):
|
2013-12-02 04:03:05 +01:00
|
|
|
if event.pathname == system_path["qubes_store_filename"]:
|
|
|
|
self.update_func()
|
|
|
|
|
2015-05-03 18:42:59 +02:00
|
|
|
# noinspection PyMethodMayBeStatic
|
2015-05-03 17:11:23 +02:00
|
|
|
def process_IN_CLOSE_WRITE(self, event):
|
2013-03-12 15:56:40 +01:00
|
|
|
if event.path == qubes_clipboard_info_file:
|
2015-05-03 17:11:23 +02:00
|
|
|
src_info_file = open(qubes_clipboard_info_file, 'r')
|
2013-03-12 15:56:40 +01:00
|
|
|
src_vmname = src_info_file.readline().strip('\n')
|
|
|
|
if src_vmname == "":
|
2017-02-19 21:46:52 +01:00
|
|
|
trayIcon.showMessage(app.tr(
|
2014-03-11 02:10:11 +01:00
|
|
|
"Qubes Clipboard has been copied to the VM and wiped.<i/>\n"
|
2015-05-03 17:11:23 +02:00
|
|
|
"<small>Trigger a paste operation (e.g. Ctrl-v) to insert "
|
2017-01-22 05:42:38 +01:00
|
|
|
"it into an application.</small>"),
|
2014-03-11 02:10:11 +01:00
|
|
|
msecs=3000)
|
2013-03-12 15:56:40 +01:00
|
|
|
else:
|
2017-02-19 21:46:52 +01:00
|
|
|
trayIcon.showMessage(unicode(app.tr(
|
2014-03-11 02:10:11 +01:00
|
|
|
"Qubes Clipboard fetched from VM: <b>'{0}'</b>\n"
|
2017-05-28 17:49:34 +02:00
|
|
|
"Copied <b>{1}</b> to the clipboard.\n"
|
2015-05-03 17:11:23 +02:00
|
|
|
"<small>Press Ctrl-Shift-v to copy this clipboard into dest"
|
2017-02-06 04:20:13 +01:00
|
|
|
" VM's clipboard.</small>")).format(
|
2017-05-28 17:49:34 +02:00
|
|
|
src_vmname, get_qubes_clipboard_formatted_size()),
|
|
|
|
msecs=3000)
|
2017-05-28 18:12:25 +02:00
|
|
|
src_info_file.close()
|
2015-05-03 17:11:23 +02:00
|
|
|
|
2013-10-18 03:33:56 +02:00
|
|
|
def process_IN_CREATE(self, event):
|
|
|
|
if event.name == os.path.basename(qubes_clipboard_info_file):
|
|
|
|
event.path = qubes_clipboard_info_file
|
|
|
|
self.process_IN_CLOSE_WRITE(event)
|
2015-05-03 17:11:23 +02:00
|
|
|
wm.add_watch(qubes_clipboard_info_file,
|
|
|
|
EventsCodes.OP_FLAGS.get('IN_CLOSE_WRITE'))
|
|
|
|
elif event.name == os.path.basename(table_widgets
|
|
|
|
.qubes_dom0_updates_stat_file):
|
2017-02-19 21:46:52 +01:00
|
|
|
trayIcon.showMessage(app.tr("Qubes dom0 updates available."),
|
2017-01-22 05:42:38 +01:00
|
|
|
msecs=0)
|
2010-05-11 16:51:31 +02:00
|
|
|
|
2012-03-21 13:27:10 +01:00
|
|
|
|
2016-12-19 00:11:45 +01:00
|
|
|
class SearchBox(QLineEdit):
|
|
|
|
def __init__(self, parent=None):
|
|
|
|
super(SearchBox, self).__init__(parent)
|
|
|
|
self.focusing = False
|
|
|
|
|
|
|
|
def focusInEvent(self, e):
|
|
|
|
super(SearchBox, self).focusInEvent(e)
|
|
|
|
self.selectAll()
|
|
|
|
self.focusing = True
|
|
|
|
|
|
|
|
def mousePressEvent(self, e):
|
|
|
|
super(SearchBox, self).mousePressEvent(e)
|
|
|
|
if self.focusing:
|
|
|
|
self.selectAll()
|
|
|
|
self.focusing = False
|
|
|
|
|
|
|
|
|
2010-05-11 16:51:31 +02:00
|
|
|
class VmRowInTable(object):
|
2012-02-13 18:19:54 +01:00
|
|
|
cpu_graph_hue = 210
|
|
|
|
mem_graph_hue = 120
|
|
|
|
|
2012-02-08 18:21:15 +01:00
|
|
|
def __init__(self, vm, row_no, table, block_manager):
|
2010-05-11 16:51:31 +02:00
|
|
|
self.vm = vm
|
|
|
|
self.row_no = row_no
|
|
|
|
|
2014-03-31 01:17:27 +02:00
|
|
|
table_widgets.row_height = VmManagerWindow.row_height
|
2015-05-03 17:11:23 +02:00
|
|
|
table.setRowHeight(row_no, VmManagerWindow.row_height)
|
2010-05-11 16:51:31 +02:00
|
|
|
|
2012-04-23 10:58:26 +02:00
|
|
|
self.type_widget = VmTypeWidget(vm)
|
2015-05-03 17:11:23 +02:00
|
|
|
table.setCellWidget(row_no, VmManagerWindow.columns_indices['Type'],
|
|
|
|
self.type_widget)
|
|
|
|
table.setItem(row_no, VmManagerWindow.columns_indices['Type'],
|
|
|
|
self.type_widget.tableItem)
|
2012-04-23 10:58:26 +02:00
|
|
|
|
2012-03-21 13:27:10 +01:00
|
|
|
self.label_widget = VmLabelWidget(vm)
|
2015-05-03 17:11:23 +02:00
|
|
|
table.setCellWidget(row_no, VmManagerWindow.columns_indices['Label'],
|
|
|
|
self.label_widget)
|
|
|
|
table.setItem(row_no, VmManagerWindow.columns_indices['Label'],
|
|
|
|
self.label_widget.tableItem)
|
2012-03-20 22:59:48 +01:00
|
|
|
|
2012-03-21 13:27:10 +01:00
|
|
|
self.name_widget = VmNameItem(vm)
|
2015-05-03 17:11:23 +02:00
|
|
|
table.setItem(row_no, VmManagerWindow.columns_indices['Name'],
|
|
|
|
self.name_widget)
|
2010-05-11 16:51:31 +02:00
|
|
|
|
2012-03-21 13:27:10 +01:00
|
|
|
self.info_widget = VmInfoWidget(vm)
|
2015-05-03 17:11:23 +02:00
|
|
|
table.setCellWidget(row_no, VmManagerWindow.columns_indices['State'],
|
|
|
|
self.info_widget)
|
|
|
|
table.setItem(row_no, VmManagerWindow.columns_indices['State'],
|
|
|
|
self.info_widget.tableItem)
|
2012-02-05 18:41:41 +01:00
|
|
|
|
2012-02-06 20:22:11 +01:00
|
|
|
self.template_widget = VmTemplateItem(vm)
|
2015-05-03 17:11:23 +02:00
|
|
|
table.setItem(row_no, VmManagerWindow.columns_indices['Template'],
|
|
|
|
self.template_widget)
|
2012-07-05 01:06:22 +02:00
|
|
|
|
2012-02-06 20:22:11 +01:00
|
|
|
self.netvm_widget = VmNetvmItem(vm)
|
2015-05-03 17:11:23 +02:00
|
|
|
table.setItem(row_no, VmManagerWindow.columns_indices['NetVM'],
|
|
|
|
self.netvm_widget)
|
|
|
|
|
|
|
|
self.cpu_usage_widget = VmUsageBarWidget(
|
|
|
|
0, 100, "%v %",
|
|
|
|
lambda v, val: val if v.last_running else 0,
|
|
|
|
vm, 0, self.cpu_graph_hue)
|
|
|
|
table.setCellWidget(row_no, VmManagerWindow.columns_indices['CPU'],
|
|
|
|
self.cpu_usage_widget)
|
|
|
|
table.setItem(row_no, VmManagerWindow.columns_indices['CPU'],
|
|
|
|
self.cpu_usage_widget.tableItem)
|
|
|
|
|
|
|
|
self.load_widget = ChartWidget(
|
|
|
|
vm,
|
|
|
|
lambda v, val: val if v.last_running else 0,
|
|
|
|
self.cpu_graph_hue, 0)
|
|
|
|
table.setCellWidget(row_no,
|
|
|
|
VmManagerWindow.columns_indices['CPU Graph'],
|
|
|
|
self.load_widget)
|
|
|
|
table.setItem(row_no, VmManagerWindow.columns_indices['CPU Graph'],
|
|
|
|
self.load_widget.tableItem)
|
|
|
|
|
|
|
|
self.mem_usage_widget = VmUsageBarWidget(
|
|
|
|
0, qubes_host.memory_total / 1024, "%v MB",
|
|
|
|
lambda v, val: v.get_mem() / 1024,
|
|
|
|
vm, 0, self.mem_graph_hue)
|
|
|
|
table.setCellWidget(row_no, VmManagerWindow.columns_indices['MEM'],
|
|
|
|
self.mem_usage_widget)
|
|
|
|
table.setItem(row_no, VmManagerWindow.columns_indices['MEM'],
|
|
|
|
self.mem_usage_widget.tableItem)
|
|
|
|
|
|
|
|
self.mem_widget = ChartWidget(
|
|
|
|
vm, lambda v, val: v.get_mem() * 100 / qubes_host.memory_total,
|
|
|
|
self.mem_graph_hue, 0)
|
|
|
|
table.setCellWidget(row_no,
|
|
|
|
VmManagerWindow.columns_indices['MEM Graph'],
|
|
|
|
self.mem_widget)
|
|
|
|
table.setItem(row_no, VmManagerWindow.columns_indices['MEM Graph'],
|
|
|
|
self.mem_widget.tableItem)
|
2010-09-16 18:49:36 +02:00
|
|
|
|
2012-04-27 17:04:35 +02:00
|
|
|
self.size_widget = VmSizeOnDiskItem(vm)
|
2015-05-03 17:11:23 +02:00
|
|
|
table.setItem(row_no, VmManagerWindow.columns_indices['Size'],
|
|
|
|
self.size_widget)
|
2012-04-27 17:04:35 +02:00
|
|
|
|
2013-03-05 10:40:04 +01:00
|
|
|
self.internal_widget = VmInternalItem(vm)
|
2015-05-03 17:11:23 +02:00
|
|
|
table.setItem(row_no, VmManagerWindow.columns_indices['Internal'],
|
|
|
|
self.internal_widget)
|
2012-04-27 17:04:35 +02:00
|
|
|
|
2014-03-10 04:27:52 +01:00
|
|
|
self.ip_widget = VmIPItem(vm)
|
2015-05-03 17:11:23 +02:00
|
|
|
table.setItem(row_no, VmManagerWindow.columns_indices['IP'],
|
|
|
|
self.ip_widget)
|
2014-03-10 04:27:52 +01:00
|
|
|
|
|
|
|
self.include_in_backups_widget = VmIncludeInBackupsItem(vm)
|
|
|
|
table.setItem(row_no, VmManagerWindow.columns_indices[
|
|
|
|
'Backups'], self.include_in_backups_widget)
|
|
|
|
|
2014-03-10 04:28:30 +01:00
|
|
|
self.last_backup_widget = VmLastBackupItem(vm)
|
|
|
|
table.setItem(row_no, VmManagerWindow.columns_indices[
|
|
|
|
'Last backup'], self.last_backup_widget)
|
|
|
|
|
2015-05-03 17:11:23 +02:00
|
|
|
def update(self, blk_visible=None, cpu_load=None, update_size_on_disk=False,
|
|
|
|
rec_visible=None):
|
2015-10-10 20:09:47 +02:00
|
|
|
"""
|
|
|
|
Update info in a single VM row
|
|
|
|
:param blk_visible: if not None, show/hide block icon, otherwise
|
|
|
|
don't change its visibility
|
|
|
|
:param cpu_load: current CPU load (if applicable), in percents
|
|
|
|
:param update_size_on_disk: should disk utilization be updated? the
|
|
|
|
widget will extract the data from VM object
|
|
|
|
:param rec_visible: if not None, show/hide mic icon, otherwise don't
|
|
|
|
change its visibility
|
|
|
|
:return: None
|
|
|
|
"""
|
2012-11-06 06:50:14 +01:00
|
|
|
self.info_widget.update_vm_state(self.vm, blk_visible, rec_visible)
|
2011-06-02 01:15:24 +02:00
|
|
|
if cpu_load is not None:
|
2012-01-22 18:45:41 +01:00
|
|
|
self.cpu_usage_widget.update_load(self.vm, cpu_load)
|
|
|
|
self.mem_usage_widget.update_load(self.vm, None)
|
2011-06-02 01:15:24 +02:00
|
|
|
self.load_widget.update_load(self.vm, cpu_load)
|
2012-02-06 20:22:11 +01:00
|
|
|
self.mem_widget.update_load(self.vm, None)
|
2015-05-03 17:11:23 +02:00
|
|
|
if update_size_on_disk:
|
2012-04-27 17:04:35 +02:00
|
|
|
self.size_widget.update()
|
2010-05-11 16:51:31 +02:00
|
|
|
|
2012-05-11 22:52:27 +02:00
|
|
|
|
2015-05-03 17:11:23 +02:00
|
|
|
vm_shutdown_timeout = 20000 # in msec
|
2016-06-05 21:19:18 +02:00
|
|
|
vm_restart_check_timeout= 1000 # in msec
|
2012-05-11 22:52:27 +02:00
|
|
|
|
2010-05-11 16:51:31 +02:00
|
|
|
|
|
|
|
class VmShutdownMonitor(QObject):
|
2016-06-05 21:19:18 +02:00
|
|
|
def __init__(self, vm, shutdown_time=vm_shutdown_timeout, check_time=vm_restart_check_timeout, and_restart=False, caller=None):
|
2015-05-03 17:11:23 +02:00
|
|
|
QObject.__init__(self)
|
2010-05-11 16:51:31 +02:00
|
|
|
self.vm = vm
|
2012-05-13 16:56:27 +02:00
|
|
|
self.shutdown_time = shutdown_time
|
2016-06-05 21:19:18 +02:00
|
|
|
self.check_time = check_time
|
|
|
|
self.and_restart = and_restart
|
|
|
|
self.shutdown_started = datetime.now()
|
|
|
|
self.caller = caller
|
2010-05-11 16:51:31 +02:00
|
|
|
|
2017-05-13 20:17:58 +02:00
|
|
|
def restart_vm_if_needed(self):
|
|
|
|
if self.and_restart and self.caller:
|
|
|
|
self.caller.start_vm(self.vm)
|
|
|
|
|
|
|
|
def check_again_later(self):
|
|
|
|
# noinspection PyTypeChecker,PyCallByClass
|
|
|
|
QTimer.singleShot(self.check_time, self.check_if_vm_has_shutdown)
|
|
|
|
|
|
|
|
def timeout_reached(self):
|
|
|
|
actual = datetime.now() - self.shutdown_started
|
|
|
|
allowed = timedelta(milliseconds=self.shutdown_time)
|
|
|
|
|
|
|
|
return actual > allowed
|
|
|
|
|
2010-05-11 16:51:31 +02:00
|
|
|
def check_if_vm_has_shutdown(self):
|
|
|
|
vm = self.vm
|
2017-05-13 20:17:58 +02:00
|
|
|
vm_is_running = vm.is_running()
|
2011-09-30 20:39:39 +02:00
|
|
|
vm_start_time = vm.get_start_time()
|
2017-05-13 20:17:58 +02:00
|
|
|
if vm_is_running and vm_start_time and vm_start_time < self.shutdown_started:
|
|
|
|
if self.timeout_reached():
|
2016-07-01 03:09:27 +02:00
|
|
|
reply = QMessageBox.question(
|
2017-01-22 05:42:38 +01:00
|
|
|
None, self.tr("VM Shutdown"),
|
2017-02-06 04:20:13 +01:00
|
|
|
unicode(self.tr("The VM <b>'{0}'</b> hasn't shutdown within the last "
|
|
|
|
"{1} seconds, do you want to kill it?<br>")).format(
|
2016-07-01 03:09:27 +02:00
|
|
|
vm.name, self.shutdown_time / 1000),
|
2017-01-22 05:42:38 +01:00
|
|
|
self.tr("Kill it!"),
|
2017-02-06 04:20:13 +01:00
|
|
|
unicode(self.tr("Wait another {0} seconds...")).format(
|
2016-07-01 03:09:27 +02:00
|
|
|
self.shutdown_time / 1000))
|
|
|
|
if reply == 0:
|
|
|
|
vm.force_shutdown()
|
2017-05-13 20:17:58 +02:00
|
|
|
self.restart_vm_if_needed()
|
2016-07-01 03:09:27 +02:00
|
|
|
else:
|
|
|
|
self.shutdown_started = datetime.now()
|
2017-05-13 20:17:58 +02:00
|
|
|
self.check_again_later()
|
2016-06-05 21:19:18 +02:00
|
|
|
else:
|
2017-05-13 20:17:58 +02:00
|
|
|
self.check_again_later()
|
2010-05-11 16:51:31 +02:00
|
|
|
else:
|
2017-05-13 20:17:58 +02:00
|
|
|
if vm_is_running:
|
|
|
|
# Due to unknown reasons, Xen sometimes reports that a domain
|
|
|
|
# is running even though its start-up timestamp is not valid.
|
|
|
|
# Make sure that "restart_vm_if_needed" is not called until
|
|
|
|
# the domain has been completely shut down according to Xen.
|
|
|
|
self.check_again_later()
|
|
|
|
return
|
|
|
|
|
|
|
|
self.restart_vm_if_needed()
|
2010-05-11 16:51:31 +02:00
|
|
|
|
2012-01-22 18:45:41 +01:00
|
|
|
class VmManagerWindow(Ui_VmManagerWindow, QMainWindow):
|
2012-01-24 20:59:44 +01:00
|
|
|
row_height = 30
|
2012-02-05 18:41:41 +01:00
|
|
|
column_width = 200
|
2012-03-26 11:48:49 +02:00
|
|
|
min_visible_rows = 10
|
2015-05-03 17:11:23 +02:00
|
|
|
update_interval = 1000 # in msec
|
2011-04-08 20:11:31 +02:00
|
|
|
show_inactive_vms = True
|
2013-03-05 11:21:16 +01:00
|
|
|
show_internal_vms = False
|
2016-11-23 08:49:13 +01:00
|
|
|
search = ""
|
2012-08-04 04:13:16 +02:00
|
|
|
# suppress saving settings while initializing widgets
|
|
|
|
settings_loaded = False
|
2015-05-03 17:11:23 +02:00
|
|
|
columns_indices = {"Type": 0,
|
|
|
|
"Label": 1,
|
|
|
|
"Name": 2,
|
|
|
|
"State": 3,
|
|
|
|
"Template": 4,
|
|
|
|
"NetVM": 5,
|
|
|
|
"CPU": 6,
|
|
|
|
"CPU Graph": 7,
|
|
|
|
"MEM": 8,
|
|
|
|
"MEM Graph": 9,
|
|
|
|
"Size": 10,
|
|
|
|
"Internal": 11,
|
|
|
|
"IP": 12,
|
|
|
|
"Backups": 13,
|
|
|
|
"Last backup": 14,
|
|
|
|
}
|
2011-03-07 16:48:19 +01:00
|
|
|
|
2014-03-31 18:36:00 +02:00
|
|
|
def __init__(self, qvm_collection, blk_manager, parent=None):
|
2012-01-22 18:45:41 +01:00
|
|
|
super(VmManagerWindow, self).__init__()
|
|
|
|
self.setupUi(self)
|
|
|
|
self.toolbar = self.toolBar
|
2012-07-05 01:06:22 +02:00
|
|
|
|
2012-08-04 04:13:16 +02:00
|
|
|
self.manager_settings = QSettings()
|
|
|
|
|
2012-04-13 01:08:36 +02:00
|
|
|
self.qubes_watch = qubesutils.QubesWatch()
|
2014-03-31 18:36:00 +02:00
|
|
|
self.qvm_collection = qvm_collection
|
|
|
|
self.blk_manager = blk_manager
|
2014-03-31 01:17:27 +02:00
|
|
|
self.blk_manager.tray_message_func = trayIcon.showMessage
|
2015-03-30 04:59:08 +02:00
|
|
|
self.qubes_watch.setup_domain_watch(self.domain_state_changed_callback)
|
2012-04-13 01:08:36 +02:00
|
|
|
self.qubes_watch.setup_block_watch(self.blk_manager.block_devs_event)
|
2015-05-03 17:11:23 +02:00
|
|
|
self.blk_watch_thread = threading.Thread(
|
|
|
|
target=self.qubes_watch.watch_loop)
|
2012-04-13 01:08:36 +02:00
|
|
|
self.blk_watch_thread.daemon = True
|
|
|
|
self.blk_watch_thread.start()
|
|
|
|
|
2016-12-19 00:11:45 +01:00
|
|
|
self.searchbox = SearchBox()
|
2017-02-13 10:36:35 +01:00
|
|
|
self.searchbox.setValidator(QRegExpValidator(QRegExp("[a-zA-Z0-9-]*", Qt.CaseInsensitive), None))
|
2016-12-19 00:11:45 +01:00
|
|
|
self.searchContainer.addWidget(self.searchbox)
|
|
|
|
|
2015-05-03 17:11:23 +02:00
|
|
|
self.connect(self.table, SIGNAL("itemSelectionChanged()"),
|
|
|
|
self.table_selection_changed)
|
2012-07-05 01:06:22 +02:00
|
|
|
|
2012-02-05 18:41:41 +01:00
|
|
|
self.table.setColumnWidth(0, self.column_width)
|
2012-03-27 10:36:58 +02:00
|
|
|
|
2012-08-04 04:12:39 +02:00
|
|
|
self.sort_by_column = "Type"
|
|
|
|
self.sort_order = Qt.AscendingOrder
|
2012-03-27 10:36:58 +02:00
|
|
|
|
2012-03-28 12:45:31 +02:00
|
|
|
self.screen_number = -1
|
|
|
|
self.screen_changed = False
|
|
|
|
|
2015-05-03 18:42:59 +02:00
|
|
|
self.vms_list = []
|
|
|
|
self.vms_in_table = {}
|
|
|
|
self.reload_table = False
|
2012-05-29 17:05:34 +02:00
|
|
|
self.running_vms_count = 0
|
2013-03-05 13:12:31 +01:00
|
|
|
self.internal_vms_count = 0
|
2012-05-29 17:05:34 +02:00
|
|
|
|
2012-07-05 01:08:10 +02:00
|
|
|
self.vm_errors = {}
|
2012-11-06 06:50:14 +01:00
|
|
|
self.vm_rec = {}
|
2012-07-05 01:08:10 +02:00
|
|
|
|
2012-03-28 12:45:31 +02:00
|
|
|
self.frame_width = 0
|
|
|
|
self.frame_height = 0
|
|
|
|
|
|
|
|
self.move(self.x(), 0)
|
2012-04-26 16:32:40 +02:00
|
|
|
|
2015-05-03 18:42:59 +02:00
|
|
|
self.columns_actions = {
|
|
|
|
self.columns_indices["Type"]: self.action_vm_type,
|
|
|
|
self.columns_indices["Label"]: self.action_label,
|
|
|
|
self.columns_indices["Name"]: self.action_name,
|
|
|
|
self.columns_indices["State"]: self.action_state,
|
|
|
|
self.columns_indices["Template"]: self.action_template,
|
|
|
|
self.columns_indices["NetVM"]: self.action_netvm,
|
|
|
|
self.columns_indices["CPU"]: self.action_cpu,
|
|
|
|
self.columns_indices["CPU Graph"]: self.action_cpu_graph,
|
|
|
|
self.columns_indices["MEM"]: self.action_mem,
|
|
|
|
self.columns_indices["MEM Graph"]: self.action_mem_graph,
|
|
|
|
self.columns_indices["Size"]: self.action_size_on_disk,
|
|
|
|
self.columns_indices["Internal"]: self.action_internal,
|
|
|
|
self.columns_indices["IP"]: self
|
|
|
|
.action_ip, self.columns_indices["Backups"]: self
|
|
|
|
.action_backups, self.columns_indices["Last backup"]: self
|
2014-03-10 04:28:30 +01:00
|
|
|
.action_last_backup
|
2015-05-03 18:42:59 +02:00
|
|
|
}
|
2012-07-05 01:06:22 +02:00
|
|
|
|
2014-02-23 00:44:08 +01:00
|
|
|
self.visible_columns_count = len(self.columns_indices)
|
2017-01-29 02:25:17 +01:00
|
|
|
self.table.setColumnHidden(self.columns_indices["CPU"], True)
|
|
|
|
self.action_cpu.setChecked(False)
|
2015-05-03 17:11:23 +02:00
|
|
|
self.table.setColumnHidden(self.columns_indices["CPU Graph"], True)
|
2012-04-26 16:32:40 +02:00
|
|
|
self.action_cpu_graph.setChecked(False)
|
2015-05-03 17:11:23 +02:00
|
|
|
self.table.setColumnHidden(self.columns_indices["MEM Graph"], True)
|
2012-04-26 16:32:40 +02:00
|
|
|
self.action_mem_graph.setChecked(False)
|
2015-05-03 17:11:23 +02:00
|
|
|
self.table.setColumnHidden(self.columns_indices["Size"], True)
|
2012-04-27 17:04:35 +02:00
|
|
|
self.action_size_on_disk.setChecked(False)
|
2015-05-03 17:11:23 +02:00
|
|
|
self.table.setColumnHidden(self.columns_indices["Internal"], True)
|
2013-03-05 11:10:25 +01:00
|
|
|
self.action_internal.setChecked(False)
|
2015-05-03 17:11:23 +02:00
|
|
|
self.table.setColumnHidden(self.columns_indices["IP"], True)
|
2014-03-10 04:27:52 +01:00
|
|
|
self.action_ip.setChecked(False)
|
2015-05-03 17:11:23 +02:00
|
|
|
self.table.setColumnHidden(self.columns_indices["Backups"], True)
|
2014-03-10 04:27:52 +01:00
|
|
|
self.action_backups.setChecked(False)
|
2015-05-03 17:11:23 +02:00
|
|
|
self.table.setColumnHidden(self.columns_indices["Last backup"], True)
|
2014-03-10 04:28:30 +01:00
|
|
|
self.action_last_backup.setChecked(False)
|
2012-04-26 16:32:40 +02:00
|
|
|
|
2012-03-20 22:59:48 +01:00
|
|
|
self.table.setColumnWidth(self.columns_indices["State"], 80)
|
2012-03-21 13:27:10 +01:00
|
|
|
self.table.setColumnWidth(self.columns_indices["Name"], 150)
|
2012-04-23 10:58:26 +02:00
|
|
|
self.table.setColumnWidth(self.columns_indices["Label"], 40)
|
|
|
|
self.table.setColumnWidth(self.columns_indices["Type"], 40)
|
2012-04-27 17:04:35 +02:00
|
|
|
self.table.setColumnWidth(self.columns_indices["Size"], 100)
|
2013-03-05 10:40:04 +01:00
|
|
|
self.table.setColumnWidth(self.columns_indices["Internal"], 60)
|
2014-03-10 04:27:52 +01:00
|
|
|
self.table.setColumnWidth(self.columns_indices["IP"], 100)
|
|
|
|
self.table.setColumnWidth(self.columns_indices["Backups"], 60)
|
2014-03-10 04:28:30 +01:00
|
|
|
self.table.setColumnWidth(self.columns_indices["Last backup"], 90)
|
2012-03-06 10:45:59 +01:00
|
|
|
|
|
|
|
self.table.horizontalHeader().setResizeMode(QHeaderView.Fixed)
|
2012-07-05 01:06:22 +02:00
|
|
|
|
2015-05-03 17:11:23 +02:00
|
|
|
self.table.sortItems(self.columns_indices[self.sort_by_column],
|
|
|
|
self.sort_order)
|
2012-02-06 20:22:11 +01:00
|
|
|
|
2012-02-14 19:00:50 +01:00
|
|
|
self.context_menu = QMenu(self)
|
2012-07-12 16:24:40 +02:00
|
|
|
|
2012-04-26 17:46:41 +02:00
|
|
|
self.context_menu.addAction(self.action_settings)
|
2012-02-14 19:00:50 +01:00
|
|
|
self.context_menu.addAction(self.action_editfwrules)
|
2012-07-12 16:24:40 +02:00
|
|
|
self.context_menu.addAction(self.action_appmenus)
|
|
|
|
self.context_menu.addAction(self.action_set_keyboard_layout)
|
|
|
|
self.context_menu.addMenu(self.blk_menu)
|
2012-11-06 06:50:14 +01:00
|
|
|
self.context_menu.addAction(self.action_toggle_audio_input)
|
2012-07-12 16:24:40 +02:00
|
|
|
self.context_menu.addSeparator()
|
|
|
|
|
2012-02-14 19:00:50 +01:00
|
|
|
self.context_menu.addAction(self.action_updatevm)
|
2012-05-11 12:50:45 +02:00
|
|
|
self.context_menu.addAction(self.action_run_command_in_vm)
|
2012-07-12 16:24:40 +02:00
|
|
|
self.context_menu.addAction(self.action_resumevm)
|
2014-02-23 01:32:50 +01:00
|
|
|
self.context_menu.addAction(self.action_startvm_tools_install)
|
2012-07-12 16:24:40 +02:00
|
|
|
self.context_menu.addAction(self.action_pausevm)
|
|
|
|
self.context_menu.addAction(self.action_shutdownvm)
|
2016-06-05 21:19:18 +02:00
|
|
|
self.context_menu.addAction(self.action_restartvm)
|
2012-07-12 16:24:40 +02:00
|
|
|
self.context_menu.addAction(self.action_killvm)
|
|
|
|
self.context_menu.addSeparator()
|
|
|
|
|
|
|
|
self.context_menu.addAction(self.action_clonevm)
|
|
|
|
self.context_menu.addAction(self.action_removevm)
|
|
|
|
self.context_menu.addSeparator()
|
|
|
|
|
2012-04-23 19:01:22 +02:00
|
|
|
self.context_menu.addMenu(self.logs_menu)
|
2012-03-20 18:36:48 +01:00
|
|
|
self.context_menu.addSeparator()
|
2012-02-14 19:00:50 +01:00
|
|
|
|
2013-02-15 16:06:54 +01:00
|
|
|
self.tools_context_menu = QMenu(self)
|
|
|
|
self.tools_context_menu.addAction(self.action_toolbar)
|
|
|
|
self.tools_context_menu.addAction(self.action_menubar)
|
|
|
|
|
2012-04-26 17:46:41 +02:00
|
|
|
self.table_selection_changed()
|
|
|
|
|
2015-05-03 17:11:23 +02:00
|
|
|
self.connect(
|
|
|
|
self.table.horizontalHeader(),
|
|
|
|
SIGNAL("sortIndicatorChanged(int, Qt::SortOrder)"),
|
|
|
|
self.sortIndicatorChanged)
|
|
|
|
self.connect(self.table,
|
|
|
|
SIGNAL("customContextMenuRequested(const QPoint&)"),
|
|
|
|
self.open_context_menu)
|
|
|
|
self.connect(self.menubar,
|
|
|
|
SIGNAL("customContextMenuRequested(const QPoint&)"),
|
|
|
|
lambda pos: self.open_tools_context_menu(self.menubar,
|
|
|
|
pos))
|
|
|
|
self.connect(self.toolBar,
|
|
|
|
SIGNAL("customContextMenuRequested(const QPoint&)"),
|
|
|
|
lambda pos: self.open_tools_context_menu(self.toolBar,
|
|
|
|
pos))
|
|
|
|
self.connect(self.blk_menu, SIGNAL("triggered(QAction *)"),
|
|
|
|
self.attach_dettach_device_triggered)
|
|
|
|
self.connect(self.logs_menu, SIGNAL("triggered(QAction *)"),
|
|
|
|
self.show_log)
|
|
|
|
|
2016-11-23 08:49:13 +01:00
|
|
|
self.connect(self.searchbox, SIGNAL("textChanged(const QString&)"),
|
|
|
|
self.do_search)
|
|
|
|
|
2015-05-03 17:11:23 +02:00
|
|
|
self.table.setContentsMargins(0, 0, 0, 0)
|
|
|
|
self.centralwidget.layout().setContentsMargins(0, 0, 0, 0)
|
|
|
|
self.layout().setContentsMargins(0, 0, 0, 0)
|
|
|
|
|
|
|
|
self.connect(self.action_menubar, SIGNAL("toggled(bool)"),
|
|
|
|
self.showhide_menubar)
|
|
|
|
self.connect(self.action_toolbar, SIGNAL("toggled(bool)"),
|
|
|
|
self.showhide_toolbar)
|
2012-03-06 18:45:47 +01:00
|
|
|
|
2012-11-06 06:50:14 +01:00
|
|
|
self.register_dbus_watches()
|
|
|
|
|
2012-08-04 04:13:16 +02:00
|
|
|
self.load_manager_settings()
|
|
|
|
|
|
|
|
self.action_showallvms.setChecked(self.show_inactive_vms)
|
2013-03-05 11:21:16 +01:00
|
|
|
self.action_showinternalvms.setChecked(self.show_internal_vms)
|
2012-08-04 04:13:16 +02:00
|
|
|
|
|
|
|
self.fill_table()
|
|
|
|
|
2011-04-02 15:48:48 +02:00
|
|
|
self.counter = 0
|
2012-04-27 17:04:35 +02:00
|
|
|
self.update_size_on_disk = False
|
2011-04-02 15:48:48 +02:00
|
|
|
self.shutdown_monitor = {}
|
2011-06-02 01:15:24 +02:00
|
|
|
self.last_measure_results = {}
|
|
|
|
self.last_measure_time = time.time()
|
2015-05-03 17:11:23 +02:00
|
|
|
# noinspection PyCallByClass,PyTypeChecker
|
|
|
|
QTimer.singleShot(self.update_interval, self.update_table)
|
2010-05-11 16:51:31 +02:00
|
|
|
|
2013-04-13 02:54:24 +02:00
|
|
|
QubesDbusNotifyServerAdaptor(self)
|
|
|
|
|
2012-08-04 04:13:16 +02:00
|
|
|
def load_manager_settings(self):
|
|
|
|
# visible columns
|
|
|
|
self.manager_settings.beginGroup("columns")
|
|
|
|
for col in self.columns_indices.keys():
|
|
|
|
col_no = self.columns_indices[col]
|
2015-05-03 17:11:23 +02:00
|
|
|
visible = self.manager_settings.value(
|
|
|
|
col,
|
|
|
|
defaultValue=not self.table.isColumnHidden(col_no)).toBool()
|
2012-08-04 04:13:16 +02:00
|
|
|
self.columns_actions[col_no].setChecked(visible)
|
|
|
|
self.manager_settings.endGroup()
|
2015-05-03 17:11:23 +02:00
|
|
|
self.show_inactive_vms = self.manager_settings.value(
|
|
|
|
"view/show_inactive_vms", defaultValue=False).toBool()
|
|
|
|
self.show_internal_vms = self.manager_settings.value(
|
|
|
|
"view/show_internal_vms", defaultValue=False).toBool()
|
|
|
|
self.sort_by_column = str(
|
|
|
|
self.manager_settings.value("view/sort_column",
|
|
|
|
defaultValue=self.sort_by_column).toString())
|
|
|
|
self.sort_order = Qt.SortOrder(
|
|
|
|
self.manager_settings.value("view/sort_order",
|
|
|
|
defaultValue=self.sort_order).toInt()[
|
|
|
|
0])
|
|
|
|
self.table.sortItems(self.columns_indices[self.sort_by_column],
|
|
|
|
self.sort_order)
|
|
|
|
if not self.manager_settings.value("view/menubar_visible",
|
|
|
|
defaultValue=True).toBool():
|
2012-08-04 04:13:16 +02:00
|
|
|
self.action_menubar.setChecked(False)
|
2015-05-03 17:11:23 +02:00
|
|
|
if not self.manager_settings.value("view/toolbar_visible",
|
|
|
|
defaultValue=True).toBool():
|
2012-08-04 04:13:16 +02:00
|
|
|
self.action_toolbar.setChecked(False)
|
2015-05-03 17:11:23 +02:00
|
|
|
x = self.manager_settings.value('position/x', defaultValue=-1).toInt()[
|
|
|
|
0]
|
|
|
|
y = self.manager_settings.value('position/y', defaultValue=-1).toInt()[
|
|
|
|
0]
|
2012-08-04 04:13:16 +02:00
|
|
|
if x != -1 or y != -1:
|
|
|
|
self.move(x, y)
|
|
|
|
self.settings_loaded = True
|
2012-03-06 18:45:47 +01:00
|
|
|
|
2012-02-05 18:41:41 +01:00
|
|
|
def show(self):
|
|
|
|
super(VmManagerWindow, self).show()
|
2012-03-28 12:45:31 +02:00
|
|
|
self.screen_number = app.desktop().screenNumber(self)
|
2012-02-05 18:41:41 +01:00
|
|
|
|
2012-03-28 12:45:31 +02:00
|
|
|
def set_table_geom_size(self):
|
2010-05-11 16:51:31 +02:00
|
|
|
|
2015-05-03 17:11:23 +02:00
|
|
|
desktop_width = app.desktop().availableGeometry(
|
|
|
|
self).width() - self.frame_width # might be wrong...
|
|
|
|
desktop_height = app.desktop().availableGeometry(
|
|
|
|
self).height() - self.frame_height # might be wrong...
|
|
|
|
desktop_height -= self.row_height # UGLY! to somehow ommit taskbar...
|
2012-07-05 01:06:22 +02:00
|
|
|
|
2015-05-03 18:42:59 +02:00
|
|
|
w = self.table.horizontalHeader().length() + \
|
|
|
|
self.table.verticalScrollBar().width() + \
|
|
|
|
2 * self.table.frameWidth() + 1
|
2012-03-28 12:45:31 +02:00
|
|
|
|
2015-05-03 18:42:59 +02:00
|
|
|
h = self.table.horizontalHeader().height() + \
|
|
|
|
2 * self.table.frameWidth()
|
2010-05-11 16:51:31 +02:00
|
|
|
|
2012-03-06 18:45:47 +01:00
|
|
|
mainwindow_to_add = 0
|
2012-03-28 12:45:31 +02:00
|
|
|
|
|
|
|
available_space = desktop_height
|
2012-03-06 18:45:47 +01:00
|
|
|
if self.menubar.isVisible():
|
2015-05-03 17:11:23 +02:00
|
|
|
menubar_height = (self.menubar.sizeHint().height() +
|
|
|
|
self.menubar.contentsMargins().top() +
|
|
|
|
self.menubar.contentsMargins().bottom())
|
2012-03-28 12:45:31 +02:00
|
|
|
available_space -= menubar_height
|
|
|
|
mainwindow_to_add += menubar_height
|
2012-03-06 18:45:47 +01:00
|
|
|
if self.toolbar.isVisible():
|
2015-05-03 17:11:23 +02:00
|
|
|
toolbar_height = (self.toolbar.sizeHint().height() +
|
|
|
|
self.toolbar.contentsMargins().top() +
|
|
|
|
self.toolbar.contentsMargins().bottom())
|
2012-03-28 12:45:31 +02:00
|
|
|
available_space -= toolbar_height
|
|
|
|
mainwindow_to_add += toolbar_height
|
2015-05-03 18:42:59 +02:00
|
|
|
if w >= desktop_width:
|
2012-03-28 12:45:31 +02:00
|
|
|
available_space -= self.table.horizontalScrollBar().height()
|
2015-05-03 18:42:59 +02:00
|
|
|
h += self.table.horizontalScrollBar().height()
|
2016-11-23 08:49:13 +01:00
|
|
|
|
|
|
|
# account for search box height
|
|
|
|
available_space -= self.searchbox.height()
|
|
|
|
h += self.searchbox.height()
|
|
|
|
|
2015-05-03 17:11:23 +02:00
|
|
|
default_rows = int(available_space / self.row_height)
|
2012-02-05 18:41:41 +01:00
|
|
|
|
2016-11-23 08:49:13 +01:00
|
|
|
n = sum(not self.table.isRowHidden(row) for row in
|
|
|
|
xrange(self.table.rowCount()))
|
2012-07-05 01:06:22 +02:00
|
|
|
|
2012-03-28 12:45:31 +02:00
|
|
|
if n > default_rows:
|
2015-05-03 18:42:59 +02:00
|
|
|
h += default_rows * self.row_height
|
2012-03-28 12:45:31 +02:00
|
|
|
self.table.verticalScrollBar().show()
|
|
|
|
else:
|
2015-05-03 18:42:59 +02:00
|
|
|
h += n * self.row_height
|
2012-03-28 12:45:31 +02:00
|
|
|
self.table.verticalScrollBar().hide()
|
2015-05-03 18:42:59 +02:00
|
|
|
w -= self.table.verticalScrollBar().width()
|
2012-03-26 11:48:49 +02:00
|
|
|
|
2015-05-03 18:42:59 +02:00
|
|
|
w = min(desktop_width, w)
|
2012-07-05 01:06:22 +02:00
|
|
|
|
2015-05-03 18:42:59 +02:00
|
|
|
self.centralwidget.setFixedHeight(h)
|
2012-03-28 12:45:31 +02:00
|
|
|
|
2015-05-03 18:42:59 +02:00
|
|
|
h += mainwindow_to_add
|
2012-03-28 12:45:31 +02:00
|
|
|
|
2015-05-03 18:42:59 +02:00
|
|
|
self.setMaximumHeight(h)
|
|
|
|
self.setMinimumHeight(h)
|
2012-03-28 12:45:31 +02:00
|
|
|
|
2015-05-03 18:42:59 +02:00
|
|
|
self.table.setFixedWidth(w)
|
|
|
|
self.centralwidget.setFixedWidth(w)
|
2012-03-28 12:45:31 +02:00
|
|
|
# don't change the following two lines to setFixedWidth!
|
2015-05-03 18:42:59 +02:00
|
|
|
self.setMaximumWidth(w)
|
|
|
|
self.setMinimumWidth(w)
|
2012-03-28 12:45:31 +02:00
|
|
|
|
|
|
|
def moveEvent(self, event):
|
|
|
|
super(VmManagerWindow, self).moveEvent(event)
|
|
|
|
screen_number = app.desktop().screenNumber(self)
|
|
|
|
if self.screen_number != screen_number:
|
2015-05-03 17:11:23 +02:00
|
|
|
self.screen_changed = True
|
|
|
|
self.screen_number = screen_number
|
2012-08-04 04:13:16 +02:00
|
|
|
if self.settings_loaded:
|
|
|
|
self.manager_settings.setValue('position/x', self.x())
|
|
|
|
self.manager_settings.setValue('position/y', self.y())
|
|
|
|
# do not sync for performance reasons
|
2012-03-26 11:48:49 +02:00
|
|
|
|
2015-05-03 17:11:23 +02:00
|
|
|
def domain_state_changed_callback(self, name=None, uuid=None):
|
2015-03-30 04:59:08 +02:00
|
|
|
if name is not None:
|
|
|
|
vm = self.qvm_collection.get_vm_by_name(name)
|
|
|
|
if vm:
|
|
|
|
vm.refresh()
|
|
|
|
|
2010-05-11 16:51:31 +02:00
|
|
|
def get_vms_list(self):
|
|
|
|
self.qvm_collection.lock_db_for_reading()
|
|
|
|
self.qvm_collection.load()
|
|
|
|
self.qvm_collection.unlock_db()
|
|
|
|
|
2012-05-29 17:05:34 +02:00
|
|
|
running_count = 0
|
2013-03-05 13:12:31 +01:00
|
|
|
internal_count = 0
|
2012-05-29 17:05:34 +02:00
|
|
|
|
2011-04-02 15:27:40 +02:00
|
|
|
vms_list = [vm for vm in self.qvm_collection.values()]
|
|
|
|
for vm in vms_list:
|
2012-04-20 16:56:51 +02:00
|
|
|
vm.last_power_state = vm.get_power_state()
|
2015-05-04 01:29:20 +02:00
|
|
|
vm.last_running = vm.is_running()
|
2012-05-29 17:05:34 +02:00
|
|
|
if vm.last_running:
|
|
|
|
running_count += 1
|
2013-03-05 13:12:31 +01:00
|
|
|
if vm.internal:
|
|
|
|
internal_count += 1
|
2013-04-13 04:10:13 +02:00
|
|
|
vm.qubes_manager_state = {}
|
|
|
|
self.update_audio_rec_info(vm)
|
2015-05-03 17:11:23 +02:00
|
|
|
vm.qubes_manager_state[QMVmState.ErrorMsg] = self.vm_errors[
|
|
|
|
vm.qid] if vm.qid in self.vm_errors else None
|
2010-05-11 16:51:31 +02:00
|
|
|
|
2012-05-29 17:05:34 +02:00
|
|
|
self.running_vms_count = running_count
|
2013-03-05 13:12:31 +01:00
|
|
|
self.internal_vms_count = internal_count
|
2012-05-29 17:05:34 +02:00
|
|
|
return vms_list
|
2010-05-11 16:51:31 +02:00
|
|
|
|
|
|
|
def fill_table(self):
|
2013-10-18 04:20:19 +02:00
|
|
|
# save current selection
|
|
|
|
row_index = self.table.currentRow()
|
|
|
|
selected_qid = -1
|
|
|
|
if row_index != -1:
|
|
|
|
vm_item = self.table.item(row_index, self.columns_indices["Name"])
|
|
|
|
if vm_item:
|
|
|
|
selected_qid = vm_item.qid
|
|
|
|
|
2012-02-06 20:22:11 +01:00
|
|
|
self.table.setSortingEnabled(False)
|
|
|
|
self.table.clearContents()
|
2010-05-11 16:51:31 +02:00
|
|
|
vms_list = self.get_vms_list()
|
|
|
|
self.table.setRowCount(len(vms_list))
|
2012-07-05 01:06:22 +02:00
|
|
|
|
2012-02-07 12:48:53 +01:00
|
|
|
vms_in_table = {}
|
2010-05-11 16:51:31 +02:00
|
|
|
|
2011-04-02 15:27:40 +02:00
|
|
|
row_no = 0
|
|
|
|
for vm in vms_list:
|
2015-05-03 17:11:23 +02:00
|
|
|
# if vm.internal:
|
|
|
|
# continue
|
|
|
|
vm_row = VmRowInTable(vm, row_no, self.table, self.blk_manager)
|
2012-02-13 13:50:30 +01:00
|
|
|
vms_in_table[vm.qid] = vm_row
|
2012-07-05 01:06:22 +02:00
|
|
|
|
2011-04-02 15:27:40 +02:00
|
|
|
row_no += 1
|
2010-05-11 16:51:31 +02:00
|
|
|
|
2011-04-02 15:27:40 +02:00
|
|
|
self.table.setRowCount(row_no)
|
2010-05-11 16:51:31 +02:00
|
|
|
self.vms_list = vms_list
|
|
|
|
self.vms_in_table = vms_in_table
|
|
|
|
self.reload_table = False
|
2013-10-18 04:20:19 +02:00
|
|
|
if selected_qid in vms_in_table.keys():
|
2015-05-03 17:11:23 +02:00
|
|
|
self.table.setCurrentItem(
|
|
|
|
self.vms_in_table[selected_qid].name_widget)
|
2012-02-06 20:22:11 +01:00
|
|
|
self.table.setSortingEnabled(True)
|
2012-05-29 17:05:34 +02:00
|
|
|
|
2016-11-23 08:49:13 +01:00
|
|
|
self.showhide_vms()
|
2012-06-19 00:17:22 +02:00
|
|
|
self.set_table_geom_size()
|
2012-05-29 17:05:34 +02:00
|
|
|
|
2016-11-23 08:49:13 +01:00
|
|
|
def showhide_vms(self):
|
|
|
|
if self.show_inactive_vms and self.show_internal_vms and not self.search:
|
2016-11-22 09:38:37 +01:00
|
|
|
for row_no in xrange(self.table.rowCount()):
|
2012-05-29 17:05:34 +02:00
|
|
|
self.table.setRowHidden(row_no, False)
|
|
|
|
else:
|
2016-11-22 09:38:37 +01:00
|
|
|
for row_no in xrange(self.table.rowCount()):
|
2015-05-03 17:11:23 +02:00
|
|
|
widget = self.table.cellWidget(row_no,
|
|
|
|
self.columns_indices["State"])
|
2012-05-29 17:05:34 +02:00
|
|
|
running = widget.vm.last_running
|
2013-03-05 11:29:49 +01:00
|
|
|
internal = widget.vm.internal
|
2016-11-23 08:49:13 +01:00
|
|
|
name = widget.vm.name
|
|
|
|
|
|
|
|
show = (running or self.show_inactive_vms) and \
|
|
|
|
(not internal or self.show_internal_vms) and \
|
|
|
|
(self.search in widget.vm.name or not self.search)
|
|
|
|
self.table.setRowHidden(row_no, not show)
|
|
|
|
|
|
|
|
@pyqtSlot(str)
|
|
|
|
def do_search(self, search):
|
2017-01-23 18:14:38 +01:00
|
|
|
self.search = str(search)
|
2016-11-23 08:49:13 +01:00
|
|
|
self.showhide_vms()
|
|
|
|
self.set_table_geom_size()
|
2013-03-05 11:29:49 +01:00
|
|
|
|
2016-12-14 23:29:44 +01:00
|
|
|
@pyqtSlot(name='on_action_search_triggered')
|
|
|
|
def action_search_triggered(self):
|
|
|
|
self.searchbox.setFocus()
|
|
|
|
|
2010-05-11 16:51:31 +02:00
|
|
|
def mark_table_for_update(self):
|
|
|
|
self.reload_table = True
|
|
|
|
|
|
|
|
# When calling update_table() directly, always use out_of_schedule=True!
|
|
|
|
def update_table(self, out_of_schedule=False):
|
2012-03-28 12:45:31 +02:00
|
|
|
|
2012-05-29 19:00:21 +02:00
|
|
|
update_devs = self.update_block_devices() or out_of_schedule
|
2012-05-30 13:54:19 +02:00
|
|
|
reload_table = self.reload_table
|
|
|
|
|
2011-04-02 16:27:18 +02:00
|
|
|
if manager_window.isVisible():
|
|
|
|
some_vms_have_changed_power_state = False
|
|
|
|
for vm in self.vms_list:
|
2012-04-20 16:56:51 +02:00
|
|
|
state = vm.get_power_state()
|
2011-04-02 16:27:18 +02:00
|
|
|
if vm.last_power_state != state:
|
2014-03-24 03:45:55 +01:00
|
|
|
if state == "Running" and \
|
2015-05-03 17:11:23 +02:00
|
|
|
self.vm_errors.get(vm.qid, "") \
|
2014-03-24 03:45:55 +01:00
|
|
|
.startswith("Error starting VM:"):
|
|
|
|
self.clear_error(vm.qid)
|
2012-05-29 17:05:34 +02:00
|
|
|
prev_running = vm.last_running
|
2011-04-02 16:27:18 +02:00
|
|
|
vm.last_power_state = state
|
2015-05-04 01:29:20 +02:00
|
|
|
vm.last_running = vm.is_running()
|
2013-04-13 04:10:13 +02:00
|
|
|
self.update_audio_rec_info(vm)
|
2012-05-29 17:05:34 +02:00
|
|
|
if not prev_running and vm.last_running:
|
|
|
|
self.running_vms_count += 1
|
|
|
|
some_vms_have_changed_power_state = True
|
2012-07-05 01:08:10 +02:00
|
|
|
# Clear error state when VM just started
|
|
|
|
self.clear_error(vm.qid)
|
2012-05-29 17:05:34 +02:00
|
|
|
elif prev_running and not vm.last_running:
|
2012-11-06 06:50:14 +01:00
|
|
|
# FIXME: remove when recAllowed state will be preserved
|
2012-11-09 21:01:38 +01:00
|
|
|
if self.vm_rec.has_key(vm.name):
|
|
|
|
self.vm_rec.pop(vm.name)
|
2012-05-29 17:05:34 +02:00
|
|
|
self.running_vms_count -= 1
|
|
|
|
some_vms_have_changed_power_state = True
|
2014-01-23 16:41:01 +01:00
|
|
|
else:
|
|
|
|
# pulseaudio agent register itself some time after VM
|
|
|
|
# startup
|
2015-05-03 17:11:23 +02:00
|
|
|
if state == "Running" and not vm.qubes_manager_state[
|
|
|
|
QMVmState.AudioRecAvailable]:
|
2014-01-23 16:41:01 +01:00
|
|
|
self.update_audio_rec_info(vm)
|
2014-03-24 03:45:55 +01:00
|
|
|
if self.vm_errors.get(vm.qid, "") == \
|
|
|
|
"Error starting VM: Cannot execute qrexec-daemon!" \
|
|
|
|
and vm.is_qrexec_running():
|
|
|
|
self.clear_error(vm.qid)
|
2012-03-28 12:45:31 +02:00
|
|
|
|
2015-05-03 18:42:59 +02:00
|
|
|
if self.screen_changed:
|
2012-03-28 12:45:31 +02:00
|
|
|
reload_table = True
|
|
|
|
self.screen_changed = False
|
|
|
|
|
2012-05-29 17:05:34 +02:00
|
|
|
if reload_table:
|
2011-04-02 16:27:18 +02:00
|
|
|
self.fill_table()
|
2015-05-03 17:11:23 +02:00
|
|
|
update_devs = True
|
2010-05-11 16:51:31 +02:00
|
|
|
|
2015-05-03 17:11:23 +02:00
|
|
|
if not self.show_inactive_vms and \
|
|
|
|
some_vms_have_changed_power_state:
|
2016-11-23 08:49:13 +01:00
|
|
|
self.showhide_vms()
|
2012-05-29 17:05:34 +02:00
|
|
|
self.set_table_geom_size()
|
2012-03-28 12:45:31 +02:00
|
|
|
|
2015-05-03 17:11:23 +02:00
|
|
|
if self.sort_by_column == \
|
|
|
|
"State" and some_vms_have_changed_power_state:
|
|
|
|
self.table.sortItems(self.columns_indices[self.sort_by_column],
|
|
|
|
self.sort_order)
|
2012-03-23 09:12:30 +01:00
|
|
|
|
2012-02-14 19:00:50 +01:00
|
|
|
blk_visible = None
|
|
|
|
rows_with_blk = None
|
2015-05-03 18:42:59 +02:00
|
|
|
if update_devs:
|
2012-02-14 19:00:50 +01:00
|
|
|
rows_with_blk = []
|
2012-04-13 01:08:36 +02:00
|
|
|
self.blk_manager.blk_lock.acquire()
|
2012-02-14 19:00:50 +01:00
|
|
|
for d in self.blk_manager.attached_devs:
|
2015-04-14 23:11:12 +02:00
|
|
|
rows_with_blk.append(
|
|
|
|
self.blk_manager.attached_devs[d]['attached_to'][
|
|
|
|
'vm'].qid)
|
2012-04-13 01:08:36 +02:00
|
|
|
self.blk_manager.blk_lock.release()
|
2012-02-14 19:00:50 +01:00
|
|
|
|
2015-05-03 17:11:23 +02:00
|
|
|
if (not self.table.isColumnHidden(self.columns_indices['Size'])) and \
|
|
|
|
self.counter % 60 == 0 or out_of_schedule:
|
2012-04-27 17:04:35 +02:00
|
|
|
self.update_size_on_disk = True
|
|
|
|
|
2011-06-02 01:15:24 +02:00
|
|
|
if self.counter % 3 == 0 or out_of_schedule:
|
|
|
|
(self.last_measure_time, self.last_measure_results) = \
|
2015-02-09 05:05:03 +01:00
|
|
|
qubes_host.measure_cpu_usage(self.qvm_collection,
|
|
|
|
self.last_measure_results,
|
|
|
|
self.last_measure_time)
|
2011-06-02 01:15:24 +02:00
|
|
|
|
2012-02-07 12:48:53 +01:00
|
|
|
for vm_row in self.vms_in_table.values():
|
2011-06-02 01:15:24 +02:00
|
|
|
cur_cpu_load = None
|
|
|
|
if vm_row.vm.get_xid() in self.last_measure_results:
|
2015-05-03 17:11:23 +02:00
|
|
|
cur_cpu_load = self.last_measure_results[vm_row.vm.xid][
|
|
|
|
'cpu_usage']
|
2011-06-02 01:15:24 +02:00
|
|
|
else:
|
|
|
|
cur_cpu_load = 0
|
2012-02-14 19:00:50 +01:00
|
|
|
|
2015-05-03 18:42:59 +02:00
|
|
|
if rows_with_blk is not None:
|
2015-04-14 23:11:12 +02:00
|
|
|
if vm_row.vm.qid in rows_with_blk:
|
2012-02-14 19:00:50 +01:00
|
|
|
blk_visible = True
|
|
|
|
else:
|
|
|
|
blk_visible = False
|
2012-07-05 01:06:22 +02:00
|
|
|
|
2015-05-03 17:11:23 +02:00
|
|
|
vm_row.update(blk_visible=blk_visible,
|
|
|
|
cpu_load=cur_cpu_load,
|
|
|
|
update_size_on_disk=self.update_size_on_disk,
|
|
|
|
rec_visible=self.vm_rec.get(vm_row.vm.name,
|
|
|
|
False))
|
2012-03-06 20:05:35 +01:00
|
|
|
|
2011-06-02 01:15:24 +02:00
|
|
|
else:
|
2012-02-07 12:48:53 +01:00
|
|
|
for vm_row in self.vms_in_table.values():
|
2015-05-03 18:42:59 +02:00
|
|
|
if rows_with_blk is not None:
|
2015-10-10 20:09:47 +02:00
|
|
|
if vm_row.vm.qid in rows_with_blk:
|
2012-02-14 19:00:50 +01:00
|
|
|
blk_visible = True
|
|
|
|
else:
|
|
|
|
blk_visible = False
|
|
|
|
|
2015-05-03 17:11:23 +02:00
|
|
|
vm_row.update(blk_visible=blk_visible,
|
|
|
|
update_size_on_disk=self.update_size_on_disk,
|
|
|
|
rec_visible=self.vm_rec.get(vm_row.vm.name,
|
|
|
|
False))
|
2012-03-23 09:12:30 +01:00
|
|
|
|
2015-05-03 17:11:23 +02:00
|
|
|
if self.sort_by_column in ["CPU", "CPU Graph", "MEM", "MEM Graph",
|
|
|
|
"State", "Size", "Internal"]:
|
|
|
|
# "State": needed to sort after reload (fill_table sorts items
|
|
|
|
# with setSortingEnabled, but by that time the widgets values
|
|
|
|
# are not correct yet).
|
|
|
|
self.table.sortItems(self.columns_indices[self.sort_by_column],
|
|
|
|
self.sort_order)
|
2012-07-05 01:06:22 +02:00
|
|
|
|
2012-02-28 07:45:08 +01:00
|
|
|
self.table_selection_changed()
|
2010-05-11 16:51:31 +02:00
|
|
|
|
2012-04-27 17:04:35 +02:00
|
|
|
self.update_size_on_disk = False
|
2010-05-11 16:51:31 +02:00
|
|
|
if not out_of_schedule:
|
|
|
|
self.counter += 1
|
2015-05-03 17:11:23 +02:00
|
|
|
# noinspection PyCallByClass,PyTypeChecker
|
|
|
|
QTimer.singleShot(self.update_interval, self.update_table)
|
2012-07-05 01:06:22 +02:00
|
|
|
|
2012-02-08 18:21:15 +01:00
|
|
|
def update_block_devices(self):
|
2012-04-13 01:08:36 +02:00
|
|
|
res, msg = self.blk_manager.check_for_updates()
|
2015-05-03 18:42:59 +02:00
|
|
|
if msg is not None and len(msg) > 0:
|
2015-05-03 17:11:23 +02:00
|
|
|
trayIcon.showMessage('\n'.join(msg), msecs=5000)
|
2012-02-14 19:00:50 +01:00
|
|
|
return res
|
2010-05-11 16:51:31 +02:00
|
|
|
|
2015-05-03 17:11:23 +02:00
|
|
|
# noinspection PyPep8Naming
|
2013-04-13 02:54:24 +02:00
|
|
|
@pyqtSlot(bool, str)
|
2012-12-06 06:25:54 +01:00
|
|
|
def recAllowedChanged(self, state, vmname):
|
2013-04-13 02:54:24 +02:00
|
|
|
self.vm_rec[str(vmname)] = bool(state)
|
2012-11-06 06:50:14 +01:00
|
|
|
|
|
|
|
def register_dbus_watches(self):
|
|
|
|
global session_bus
|
|
|
|
|
|
|
|
if not session_bus:
|
2013-04-13 02:54:24 +02:00
|
|
|
session_bus = QDBusConnection.sessionBus()
|
2012-11-06 06:50:14 +01:00
|
|
|
|
2015-05-03 17:11:23 +02:00
|
|
|
if not session_bus.connect(QString(), # service
|
|
|
|
QString(), # path
|
|
|
|
QString("org.QubesOS.Audio"), # interface
|
|
|
|
QString("RecAllowedChanged"), # name
|
|
|
|
self.recAllowedChanged): # slot
|
2017-06-25 17:32:46 +02:00
|
|
|
print(session_bus.lastError().message())
|
2012-03-27 10:36:58 +02:00
|
|
|
|
2015-05-03 17:11:23 +02:00
|
|
|
# noinspection PyPep8Naming
|
2012-03-06 20:05:35 +01:00
|
|
|
def sortIndicatorChanged(self, column, order):
|
2015-05-03 17:11:23 +02:00
|
|
|
self.sort_by_column = [name for name in self.columns_indices.keys() if
|
|
|
|
self.columns_indices[name] == column][0]
|
2012-08-04 04:12:39 +02:00
|
|
|
self.sort_order = order
|
2012-08-04 04:13:16 +02:00
|
|
|
if self.settings_loaded:
|
2015-05-03 17:11:23 +02:00
|
|
|
self.manager_settings.setValue('view/sort_column',
|
|
|
|
self.sort_by_column)
|
2012-08-04 04:13:16 +02:00
|
|
|
self.manager_settings.setValue('view/sort_order', self.sort_order)
|
|
|
|
self.manager_settings.sync()
|
2012-07-05 01:06:22 +02:00
|
|
|
|
2015-05-03 17:11:23 +02:00
|
|
|
def table_selection_changed(self):
|
2012-01-31 14:29:13 +01:00
|
|
|
|
2010-05-11 16:51:31 +02:00
|
|
|
vm = self.get_selected_vm()
|
|
|
|
|
2015-05-03 18:42:59 +02:00
|
|
|
if vm is not None:
|
2012-02-08 18:21:15 +01:00
|
|
|
# Update available actions:
|
2012-06-19 00:24:13 +02:00
|
|
|
self.action_settings.setEnabled(vm.qid != 0)
|
2015-05-03 17:11:23 +02:00
|
|
|
self.action_removevm.setEnabled(
|
|
|
|
not vm.installed_by_rpm and not vm.last_running)
|
|
|
|
self.action_clonevm.setEnabled(
|
|
|
|
not vm.last_running and not vm.is_netvm())
|
2015-05-04 01:29:20 +02:00
|
|
|
self.action_resumevm.setEnabled(not vm.last_running or
|
|
|
|
vm.last_power_state == "Paused")
|
2014-02-23 01:32:50 +01:00
|
|
|
try:
|
2015-05-03 17:11:23 +02:00
|
|
|
self.action_startvm_tools_install.setVisible(
|
|
|
|
isinstance(vm, QubesHVm))
|
2014-02-23 01:32:50 +01:00
|
|
|
except NameError:
|
|
|
|
# ignore non existing QubesHVm
|
|
|
|
pass
|
|
|
|
self.action_startvm_tools_install.setEnabled(not vm.last_running)
|
2015-05-04 01:29:20 +02:00
|
|
|
self.action_pausevm.setEnabled(
|
|
|
|
vm.last_running and
|
|
|
|
vm.last_power_state != "Paused" and
|
|
|
|
vm.qid != 0)
|
|
|
|
self.action_shutdownvm.setEnabled(
|
|
|
|
vm.last_running and
|
|
|
|
vm.last_power_state != "Paused" and
|
|
|
|
vm.qid != 0)
|
2016-06-05 21:19:18 +02:00
|
|
|
self.action_restartvm.setEnabled(
|
|
|
|
vm.last_running and
|
|
|
|
vm.last_power_state != "Paused" and
|
2016-11-21 15:39:25 +01:00
|
|
|
vm.qid != 0 and
|
|
|
|
not vm.is_disposablevm())
|
2015-05-03 17:11:23 +02:00
|
|
|
self.action_killvm.setEnabled((vm.last_running or
|
|
|
|
vm.last_power_state == "Paused") and
|
|
|
|
vm.qid != 0)
|
2015-12-13 01:22:03 +01:00
|
|
|
self.action_appmenus.setEnabled(vm.qid != 0 and
|
|
|
|
not vm.internal and
|
2015-05-04 01:29:20 +02:00
|
|
|
not vm.is_disposablevm())
|
2015-05-03 17:11:23 +02:00
|
|
|
self.action_editfwrules.setEnabled(vm.is_networked() and not (
|
|
|
|
vm.is_netvm() and not vm.is_proxyvm()))
|
2012-02-08 18:21:15 +01:00
|
|
|
self.action_updatevm.setEnabled(vm.is_updateable() or vm.qid == 0)
|
2015-05-03 17:11:23 +02:00
|
|
|
self.action_toggle_audio_input.setEnabled(
|
|
|
|
vm.qubes_manager_state[QMVmState.AudioRecAvailable])
|
|
|
|
self.action_run_command_in_vm.setEnabled(
|
|
|
|
not vm.last_power_state == "Paused" and vm.qid != 0)
|
|
|
|
self.action_set_keyboard_layout.setEnabled(
|
2015-05-04 01:29:20 +02:00
|
|
|
vm.qid != 0 and
|
|
|
|
vm.last_running and
|
|
|
|
vm.last_power_state != "Paused")
|
2012-02-08 18:21:15 +01:00
|
|
|
else:
|
|
|
|
self.action_settings.setEnabled(False)
|
|
|
|
self.action_removevm.setEnabled(False)
|
2014-02-23 01:32:50 +01:00
|
|
|
self.action_startvm_tools_install.setVisible(False)
|
|
|
|
self.action_startvm_tools_install.setEnabled(False)
|
2012-07-12 13:32:45 +02:00
|
|
|
self.action_clonevm.setEnabled(False)
|
2012-02-08 18:21:15 +01:00
|
|
|
self.action_resumevm.setEnabled(False)
|
|
|
|
self.action_pausevm.setEnabled(False)
|
|
|
|
self.action_shutdownvm.setEnabled(False)
|
2016-06-05 21:19:18 +02:00
|
|
|
self.action_restartvm.setEnabled(False)
|
2012-04-22 18:32:50 +02:00
|
|
|
self.action_killvm.setEnabled(False)
|
2012-02-08 18:21:15 +01:00
|
|
|
self.action_appmenus.setEnabled(False)
|
|
|
|
self.action_editfwrules.setEnabled(False)
|
|
|
|
self.action_updatevm.setEnabled(False)
|
2012-11-06 06:50:14 +01:00
|
|
|
self.action_toggle_audio_input.setEnabled(False)
|
2012-05-11 12:50:45 +02:00
|
|
|
self.action_run_command_in_vm.setEnabled(False)
|
2012-04-24 17:48:10 +02:00
|
|
|
self.action_set_keyboard_layout.setEnabled(False)
|
2012-02-08 18:21:15 +01:00
|
|
|
|
2015-05-03 17:11:23 +02:00
|
|
|
def closeEvent(self, event):
|
|
|
|
# There is something borked in Qt,
|
|
|
|
# as the logic here is inverted on X11
|
|
|
|
if event.spontaneous():
|
2011-04-10 22:44:38 +02:00
|
|
|
self.hide()
|
|
|
|
event.ignore()
|
2010-05-11 16:51:31 +02:00
|
|
|
|
2012-07-05 01:08:10 +02:00
|
|
|
def set_error(self, qid, message):
|
|
|
|
for vm in self.vms_list:
|
|
|
|
if vm.qid == qid:
|
2013-04-13 04:10:13 +02:00
|
|
|
vm.qubes_manager_state[QMVmState.ErrorMsg] = message
|
2012-07-05 01:08:10 +02:00
|
|
|
# Store error in separate dict to make it immune to VM list reload
|
2014-04-24 12:58:38 +02:00
|
|
|
self.vm_errors[qid] = str(message)
|
2012-07-05 01:08:10 +02:00
|
|
|
|
|
|
|
def clear_error(self, qid):
|
|
|
|
self.vm_errors.pop(qid, None)
|
|
|
|
for vm in self.vms_list:
|
|
|
|
if vm.qid == qid:
|
2013-04-13 04:10:13 +02:00
|
|
|
vm.qubes_manager_state[QMVmState.ErrorMsg] = None
|
2012-07-05 01:08:10 +02:00
|
|
|
|
|
|
|
def clear_error_exact(self, qid, message):
|
|
|
|
for vm in self.vms_list:
|
|
|
|
if vm.qid == qid:
|
2013-04-13 04:10:13 +02:00
|
|
|
if vm.qubes_manager_state[QMVmState.ErrorMsg] == message:
|
|
|
|
vm.qubes_manager_state[QMVmState.ErrorMsg] = None
|
2012-07-05 01:08:10 +02:00
|
|
|
self.vm_errors.pop(qid, None)
|
|
|
|
|
2012-01-23 19:04:58 +01:00
|
|
|
@pyqtSlot(name='on_action_createvm_triggered')
|
|
|
|
def action_createvm_triggered(self):
|
2012-05-11 22:52:27 +02:00
|
|
|
dialog = NewVmDlg(app, self.qvm_collection, trayIcon)
|
|
|
|
dialog.exec_()
|
2010-05-11 16:51:31 +02:00
|
|
|
|
|
|
|
def get_selected_vm(self):
|
2015-05-03 17:11:23 +02:00
|
|
|
# vm selection relies on the VmInfo widget's value used
|
|
|
|
# for sorting by VM name
|
2010-05-11 16:51:31 +02:00
|
|
|
row_index = self.table.currentRow()
|
2012-02-28 07:45:08 +01:00
|
|
|
if row_index != -1:
|
2013-02-06 14:57:09 +01:00
|
|
|
vm_item = self.table.item(row_index, self.columns_indices["Name"])
|
2015-05-03 17:11:23 +02:00
|
|
|
# here is possible race with update_table timer so check
|
|
|
|
# if really got the item
|
2013-02-06 14:57:09 +01:00
|
|
|
if vm_item is None:
|
|
|
|
return None
|
|
|
|
qid = vm_item.qid
|
2012-02-13 13:50:30 +01:00
|
|
|
assert self.vms_in_table[qid] is not None
|
|
|
|
vm = self.vms_in_table[qid].vm
|
2012-02-08 18:21:15 +01:00
|
|
|
return vm
|
|
|
|
else:
|
|
|
|
return None
|
2010-05-11 16:51:31 +02:00
|
|
|
|
2012-01-23 19:04:58 +01:00
|
|
|
@pyqtSlot(name='on_action_removevm_triggered')
|
|
|
|
def action_removevm_triggered(self):
|
2012-02-05 18:41:41 +01:00
|
|
|
|
2010-05-11 16:51:31 +02:00
|
|
|
vm = self.get_selected_vm()
|
|
|
|
assert not vm.is_running()
|
|
|
|
assert not vm.installed_by_rpm
|
|
|
|
|
|
|
|
self.qvm_collection.lock_db_for_reading()
|
|
|
|
self.qvm_collection.load()
|
|
|
|
self.qvm_collection.unlock_db()
|
2012-07-05 01:11:39 +02:00
|
|
|
vm = self.qvm_collection[vm.qid]
|
|
|
|
|
2011-03-05 15:12:34 +01:00
|
|
|
if vm.is_template():
|
2010-05-11 16:51:31 +02:00
|
|
|
dependent_vms = self.qvm_collection.get_vms_based_on(vm.qid)
|
|
|
|
if len(dependent_vms) > 0:
|
2015-05-03 17:11:23 +02:00
|
|
|
QMessageBox.warning(
|
2017-01-22 05:42:38 +01:00
|
|
|
None, self.tr("Warning!"),
|
|
|
|
self.tr("This Template VM cannot be removed, because there is at "
|
2015-05-03 17:11:23 +02:00
|
|
|
"least one AppVM that is based on it.<br>"
|
|
|
|
"<small>If you want to remove this Template VM and all "
|
|
|
|
"the AppVMs based on it,"
|
|
|
|
"you should first remove each individual AppVM that uses "
|
2017-01-22 05:42:38 +01:00
|
|
|
"this template.</small>"))
|
2010-05-11 16:51:31 +02:00
|
|
|
|
|
|
|
return
|
|
|
|
|
2016-11-22 06:41:32 +01:00
|
|
|
(requested_name, ok) = QInputDialog.getText(
|
2017-01-22 05:42:38 +01:00
|
|
|
None, self.tr("VM Removal Confirmation"),
|
2017-02-06 04:20:13 +01:00
|
|
|
unicode(self.tr("Are you sure you want to remove the VM <b>'{0}'</b>?<br>"
|
2016-11-22 06:41:32 +01:00
|
|
|
"All data on this VM's private storage will be lost!<br><br>"
|
2017-02-06 04:20:13 +01:00
|
|
|
"Type the name of the VM (<b>{1}</b>) below to confirm:"))
|
2016-11-22 06:41:32 +01:00
|
|
|
.format(vm.name, vm.name))
|
2010-05-11 16:51:31 +02:00
|
|
|
|
2016-11-22 06:41:32 +01:00
|
|
|
if not ok:
|
|
|
|
# user clicked cancel
|
|
|
|
return
|
2010-05-11 16:51:31 +02:00
|
|
|
|
2016-11-22 06:41:32 +01:00
|
|
|
elif requested_name != vm.name:
|
|
|
|
# name did not match
|
2017-01-22 05:42:38 +01:00
|
|
|
QMessageBox.warning(None, self.tr("VM removal confirmation failed"),
|
2017-02-06 04:20:13 +01:00
|
|
|
unicode(self.tr("Entered name did not match! Not removing {0}.")).format(vm.name))
|
2016-11-22 06:41:32 +01:00
|
|
|
return
|
|
|
|
|
|
|
|
else:
|
|
|
|
# remove the VM
|
2010-05-11 16:51:31 +02:00
|
|
|
thread_monitor = ThreadMonitor()
|
2015-05-03 17:11:23 +02:00
|
|
|
thread = threading.Thread(target=self.do_remove_vm,
|
|
|
|
args=(vm, thread_monitor))
|
2010-05-11 16:51:31 +02:00
|
|
|
thread.daemon = True
|
|
|
|
thread.start()
|
|
|
|
|
2015-05-03 17:11:23 +02:00
|
|
|
progress = QProgressDialog(
|
2017-02-06 04:20:13 +01:00
|
|
|
unicode(self.tr("Removing VM: <b>{0}</b>...")).format(vm.name), "", 0, 0)
|
2010-05-11 16:51:31 +02:00
|
|
|
progress.setCancelButton(None)
|
|
|
|
progress.setModal(True)
|
|
|
|
progress.show()
|
2011-03-07 16:48:53 +01:00
|
|
|
|
2010-05-11 16:51:31 +02:00
|
|
|
while not thread_monitor.is_finished():
|
|
|
|
app.processEvents()
|
2015-05-03 17:11:23 +02:00
|
|
|
time.sleep(0.1)
|
2010-05-11 16:51:31 +02:00
|
|
|
|
|
|
|
progress.hide()
|
|
|
|
|
|
|
|
if thread_monitor.success:
|
2015-05-03 17:11:23 +02:00
|
|
|
trayIcon.showMessage(
|
2017-02-06 04:20:13 +01:00
|
|
|
unicode(self.tr("VM '{0}' has been removed.")).format(vm.name), msecs=3000)
|
2010-05-11 16:51:31 +02:00
|
|
|
else:
|
2017-01-22 05:42:38 +01:00
|
|
|
QMessageBox.warning(None, self.tr("Error removing VM!"),
|
2017-02-06 04:20:13 +01:00
|
|
|
unicode(self.tr("ERROR: {0}")).format(
|
2015-05-03 17:11:23 +02:00
|
|
|
thread_monitor.error_msg))
|
2010-05-11 16:51:31 +02:00
|
|
|
|
2015-05-04 01:25:55 +02:00
|
|
|
@staticmethod
|
|
|
|
def do_remove_vm(vm, thread_monitor):
|
|
|
|
qc = QubesVmCollection()
|
|
|
|
qc.lock_db_for_writing()
|
2010-05-11 16:51:31 +02:00
|
|
|
try:
|
2015-05-04 01:25:55 +02:00
|
|
|
qc.load()
|
|
|
|
vm = qc[vm.qid]
|
2010-05-11 16:51:31 +02:00
|
|
|
|
2015-05-03 17:11:23 +02:00
|
|
|
# TODO: the following two conditions should really be checked
|
|
|
|
# by qvm_collection.pop() overload...
|
|
|
|
if vm.is_template() and \
|
2015-05-04 01:25:55 +02:00
|
|
|
qc.default_template_qid == vm.qid:
|
|
|
|
qc.default_template_qid = None
|
2015-05-03 17:11:23 +02:00
|
|
|
if vm.is_netvm() and \
|
2015-05-04 01:25:55 +02:00
|
|
|
qc.default_netvm_qid == vm.qid:
|
|
|
|
qc.default_netvm_qid = None
|
2010-05-11 16:51:31 +02:00
|
|
|
|
2015-05-04 01:25:55 +02:00
|
|
|
qc.pop(vm.qid)
|
|
|
|
qc.save()
|
2014-02-23 00:46:48 +01:00
|
|
|
vm.remove_from_disk()
|
2010-05-11 16:51:31 +02:00
|
|
|
except Exception as ex:
|
2015-05-03 17:11:23 +02:00
|
|
|
thread_monitor.set_error_msg(str(ex))
|
2010-05-11 16:51:31 +02:00
|
|
|
finally:
|
2015-05-04 01:25:55 +02:00
|
|
|
qc.unlock_db()
|
2010-05-11 16:51:31 +02:00
|
|
|
|
|
|
|
thread_monitor.set_finished()
|
|
|
|
|
2012-07-12 13:32:45 +02:00
|
|
|
@pyqtSlot(name='on_action_clonevm_triggered')
|
|
|
|
def action_clonevm_triggered(self):
|
|
|
|
vm = self.get_selected_vm()
|
|
|
|
|
|
|
|
name_number = 1
|
|
|
|
name_format = vm.name + '-clone-%d'
|
|
|
|
while self.qvm_collection.get_vm_by_name(name_format % name_number):
|
|
|
|
name_number += 1
|
|
|
|
|
2015-05-03 17:11:23 +02:00
|
|
|
(clone_name, ok) = QInputDialog.getText(
|
2017-01-22 05:42:38 +01:00
|
|
|
self, self.tr('Qubes clone VM'),
|
2017-02-06 04:20:13 +01:00
|
|
|
unicode(self.tr('Enter name for VM <b>{}</b> clone:')).format(vm.name),
|
2015-05-13 04:09:10 +02:00
|
|
|
text=(name_format % name_number))
|
2013-02-12 01:06:32 +01:00
|
|
|
if not ok or clone_name == "":
|
2012-07-12 13:32:45 +02:00
|
|
|
return
|
|
|
|
|
|
|
|
thread_monitor = ThreadMonitor()
|
2015-05-03 17:11:23 +02:00
|
|
|
thread = threading.Thread(target=self.do_clone_vm,
|
|
|
|
args=(vm, str(clone_name), thread_monitor))
|
2012-07-12 13:32:45 +02:00
|
|
|
thread.daemon = True
|
|
|
|
thread.start()
|
|
|
|
|
2015-05-03 17:11:23 +02:00
|
|
|
progress = QProgressDialog(
|
2017-02-06 04:20:13 +01:00
|
|
|
unicode(self.tr("Cloning VM <b>{0}</b> to <b>{1}</b>...")).format(vm.name,
|
2015-05-03 17:11:23 +02:00
|
|
|
clone_name), "", 0,
|
|
|
|
0)
|
2012-07-12 13:32:45 +02:00
|
|
|
progress.setCancelButton(None)
|
|
|
|
progress.setModal(True)
|
|
|
|
progress.show()
|
|
|
|
|
|
|
|
while not thread_monitor.is_finished():
|
|
|
|
app.processEvents()
|
2015-05-03 17:11:23 +02:00
|
|
|
time.sleep(0.2)
|
2012-07-12 13:32:45 +02:00
|
|
|
|
|
|
|
progress.hide()
|
|
|
|
|
|
|
|
if not thread_monitor.success:
|
2017-01-22 05:42:38 +01:00
|
|
|
QMessageBox.warning(None, self.tr("Error while cloning VM"),
|
2017-02-06 04:20:13 +01:00
|
|
|
unicode(self.tr("Exception while cloning:<br>{0}")).format(
|
2015-05-03 17:11:23 +02:00
|
|
|
thread_monitor.error_msg))
|
2012-07-12 13:32:45 +02:00
|
|
|
|
2015-05-04 01:25:55 +02:00
|
|
|
@staticmethod
|
|
|
|
def do_clone_vm(vm, dst_name, thread_monitor):
|
2013-12-14 02:55:41 +01:00
|
|
|
dst_vm = None
|
2015-05-04 01:25:55 +02:00
|
|
|
qc = QubesVmCollection()
|
|
|
|
qc.lock_db_for_writing()
|
|
|
|
qc.load()
|
2012-07-12 13:32:45 +02:00
|
|
|
try:
|
2015-05-04 01:25:55 +02:00
|
|
|
src_vm = qc[vm.qid]
|
2012-07-12 13:32:45 +02:00
|
|
|
|
2015-05-04 01:25:55 +02:00
|
|
|
dst_vm = qc.add_new_vm(src_vm.__class__.__name__,
|
|
|
|
name=dst_name,
|
|
|
|
template=src_vm.template,
|
|
|
|
installed_by_rpm=False)
|
2012-07-12 13:32:45 +02:00
|
|
|
|
|
|
|
dst_vm.clone_attrs(src_vm)
|
2015-05-03 17:11:23 +02:00
|
|
|
dst_vm.clone_disk_files(src_vm=src_vm, verbose=False)
|
2015-05-04 01:25:55 +02:00
|
|
|
qc.save()
|
2012-07-12 13:32:45 +02:00
|
|
|
except Exception as ex:
|
|
|
|
if dst_vm:
|
2015-05-04 01:25:55 +02:00
|
|
|
qc.pop(dst_vm.qid)
|
2014-02-23 00:48:02 +01:00
|
|
|
dst_vm.remove_from_disk()
|
2012-07-12 13:32:45 +02:00
|
|
|
thread_monitor.set_error_msg(str(ex))
|
2015-05-04 01:25:55 +02:00
|
|
|
finally:
|
|
|
|
qc.unlock_db()
|
2012-07-12 13:32:45 +02:00
|
|
|
thread_monitor.set_finished()
|
|
|
|
|
2012-01-23 19:04:58 +01:00
|
|
|
@pyqtSlot(name='on_action_resumevm_triggered')
|
|
|
|
def action_resumevm_triggered(self):
|
2011-03-02 14:42:11 +01:00
|
|
|
vm = self.get_selected_vm()
|
|
|
|
|
2015-05-04 01:29:20 +02:00
|
|
|
if vm.get_power_state() in ["Paused", "Suspended"]:
|
2011-03-27 17:41:03 +02:00
|
|
|
try:
|
2015-05-04 01:29:20 +02:00
|
|
|
vm.resume()
|
2011-03-27 17:41:03 +02:00
|
|
|
except Exception as ex:
|
2017-01-22 05:42:38 +01:00
|
|
|
QMessageBox.warning(None, self.tr("Error unpausing VM!"),
|
2017-02-06 04:20:13 +01:00
|
|
|
unicode(self.tr("ERROR: {0}")).format(ex))
|
2011-03-27 17:41:03 +02:00
|
|
|
return
|
|
|
|
|
2016-06-05 21:19:18 +02:00
|
|
|
|
2017-06-25 17:32:46 +02:00
|
|
|
self.start_vm(vm)
|
2016-06-05 21:19:18 +02:00
|
|
|
|
|
|
|
def start_vm(self, vm):
|
2015-05-04 01:29:20 +02:00
|
|
|
assert not vm.is_running()
|
2011-04-01 00:46:51 +02:00
|
|
|
thread_monitor = ThreadMonitor()
|
2015-05-03 17:11:23 +02:00
|
|
|
thread = threading.Thread(target=self.do_start_vm,
|
|
|
|
args=(vm, thread_monitor))
|
2011-04-01 00:46:51 +02:00
|
|
|
thread.daemon = True
|
|
|
|
thread.start()
|
|
|
|
|
2017-02-06 04:20:13 +01:00
|
|
|
trayIcon.showMessage(unicode(self.tr("Starting '{0}'...")).format(vm.name), msecs=3000)
|
2011-04-01 00:46:51 +02:00
|
|
|
|
|
|
|
while not thread_monitor.is_finished():
|
|
|
|
app.processEvents()
|
2015-05-03 17:11:23 +02:00
|
|
|
time.sleep(0.1)
|
2011-04-01 00:46:51 +02:00
|
|
|
|
|
|
|
if thread_monitor.success:
|
2017-02-06 04:20:13 +01:00
|
|
|
trayIcon.showMessage(unicode(self.tr("VM '{0}' has been started.")).format(vm.name),
|
2015-05-03 17:11:23 +02:00
|
|
|
msecs=3000)
|
2011-04-01 00:46:51 +02:00
|
|
|
else:
|
2015-05-03 17:11:23 +02:00
|
|
|
trayIcon.showMessage(
|
2017-02-06 04:20:13 +01:00
|
|
|
unicode(self.tr("Error starting VM <b>'{0}'</b>: {1}")).format(
|
2015-05-03 17:11:23 +02:00
|
|
|
vm.name, thread_monitor.error_msg),
|
|
|
|
msecs=3000)
|
|
|
|
self.set_error(vm.qid,
|
2017-02-20 03:36:35 +01:00
|
|
|
unicode(self.tr("Error starting VM: %s")) % thread_monitor.error_msg)
|
2015-05-03 17:11:23 +02:00
|
|
|
|
2015-05-04 01:25:55 +02:00
|
|
|
@staticmethod
|
|
|
|
def do_start_vm(vm, thread_monitor):
|
2011-03-02 14:42:11 +01:00
|
|
|
try:
|
2015-05-03 18:42:59 +02:00
|
|
|
vm.start()
|
2011-04-01 00:46:51 +02:00
|
|
|
except Exception as ex:
|
|
|
|
thread_monitor.set_error_msg(str(ex))
|
|
|
|
thread_monitor.set_finished()
|
2011-03-02 14:42:11 +01:00
|
|
|
return
|
2011-03-07 16:48:53 +01:00
|
|
|
|
2011-04-01 00:46:51 +02:00
|
|
|
thread_monitor.set_finished()
|
2012-07-05 01:03:05 +02:00
|
|
|
|
2014-02-23 01:32:50 +01:00
|
|
|
@pyqtSlot(name='on_action_startvm_tools_install_triggered')
|
|
|
|
def action_startvm_tools_install_triggered(self):
|
|
|
|
vm = self.get_selected_vm()
|
|
|
|
assert not vm.is_running()
|
|
|
|
|
2016-06-21 02:07:22 +02:00
|
|
|
windows_tools_installed = \
|
|
|
|
os.path.exists('/usr/lib/qubes/qubes-windows-tools.iso')
|
|
|
|
if not windows_tools_installed:
|
|
|
|
msg = QMessageBox()
|
2017-01-22 05:42:38 +01:00
|
|
|
msg.warning(self, self.tr("Error starting VM!"),
|
|
|
|
self.tr("You need to install 'qubes-windows-tools' "
|
|
|
|
"package to use this option"))
|
2016-06-21 02:07:22 +02:00
|
|
|
return
|
|
|
|
|
|
|
|
|
2014-02-23 01:32:50 +01:00
|
|
|
thread_monitor = ThreadMonitor()
|
2015-05-03 17:11:23 +02:00
|
|
|
thread = threading.Thread(target=self.do_start_vm_tools_install,
|
|
|
|
args=(vm, thread_monitor))
|
2014-02-23 01:32:50 +01:00
|
|
|
thread.daemon = True
|
|
|
|
thread.start()
|
|
|
|
|
2017-02-06 04:20:13 +01:00
|
|
|
trayIcon.showMessage(unicode(self.tr("Starting '{0}'...")).format(vm.name), msecs=3000)
|
2014-02-23 01:32:50 +01:00
|
|
|
|
|
|
|
while not thread_monitor.is_finished():
|
|
|
|
app.processEvents()
|
2015-05-03 17:11:23 +02:00
|
|
|
time.sleep(0.1)
|
2014-02-23 01:32:50 +01:00
|
|
|
|
|
|
|
if thread_monitor.success:
|
2017-02-06 04:20:13 +01:00
|
|
|
trayIcon.showMessage(unicode(self.tr("VM '{0}' has been started. Start Qubes "
|
|
|
|
"Tools installation from attached CD"))
|
2015-05-03 17:11:23 +02:00
|
|
|
.format(vm.name), msecs=3000)
|
2014-02-23 01:32:50 +01:00
|
|
|
else:
|
2015-05-03 17:11:23 +02:00
|
|
|
trayIcon.showMessage(
|
2017-02-06 04:20:13 +01:00
|
|
|
unicode(self.tr("Error starting VM <b>'{0}'</b>: {1}"))
|
2015-05-03 17:11:23 +02:00
|
|
|
.format(vm.name, thread_monitor.error_msg),
|
|
|
|
msecs=3000)
|
|
|
|
self.set_error(vm.qid,
|
2017-02-20 03:36:35 +01:00
|
|
|
unicode(self.tr("Error starting VM: %s")) % thread_monitor.error_msg)
|
2015-05-03 17:11:23 +02:00
|
|
|
|
|
|
|
# noinspection PyMethodMayBeStatic
|
2014-02-23 01:32:50 +01:00
|
|
|
def do_start_vm_tools_install(self, vm, thread_monitor):
|
|
|
|
prev_drive = vm.drive
|
|
|
|
try:
|
|
|
|
vm.drive = 'cdrom:dom0:/usr/lib/qubes/qubes-windows-tools.iso'
|
2015-05-03 18:42:59 +02:00
|
|
|
vm.start()
|
2014-02-23 01:32:50 +01:00
|
|
|
except Exception as ex:
|
|
|
|
thread_monitor.set_error_msg(str(ex))
|
|
|
|
thread_monitor.set_finished()
|
|
|
|
return
|
|
|
|
finally:
|
|
|
|
vm.drive = prev_drive
|
|
|
|
|
|
|
|
thread_monitor.set_finished()
|
|
|
|
|
2012-01-23 19:04:58 +01:00
|
|
|
@pyqtSlot(name='on_action_pausevm_triggered')
|
|
|
|
def action_pausevm_triggered(self):
|
2011-03-02 14:50:21 +01:00
|
|
|
vm = self.get_selected_vm()
|
|
|
|
assert vm.is_running()
|
|
|
|
try:
|
2013-04-13 03:12:58 +02:00
|
|
|
vm.pause()
|
2011-03-02 14:50:21 +01:00
|
|
|
except Exception as ex:
|
2017-01-22 05:42:38 +01:00
|
|
|
QMessageBox.warning(None, self.tr("Error pausing VM!"),
|
2017-02-06 04:20:13 +01:00
|
|
|
unicode(self.tr("ERROR: {0}")).format(ex))
|
2011-03-02 14:50:21 +01:00
|
|
|
return
|
2010-05-11 16:51:31 +02:00
|
|
|
|
2012-01-23 19:04:58 +01:00
|
|
|
@pyqtSlot(name='on_action_shutdownvm_triggered')
|
|
|
|
def action_shutdownvm_triggered(self):
|
2010-05-11 16:51:31 +02:00
|
|
|
vm = self.get_selected_vm()
|
|
|
|
assert vm.is_running()
|
|
|
|
|
2012-05-25 13:59:58 +02:00
|
|
|
self.blk_manager.check_if_serves_as_backend(vm)
|
|
|
|
|
2015-05-03 17:11:23 +02:00
|
|
|
reply = QMessageBox.question(
|
2017-01-22 05:42:38 +01:00
|
|
|
None, self.tr("VM Shutdown Confirmation"),
|
2017-02-06 04:20:13 +01:00
|
|
|
unicode(self.tr("Are you sure you want to power down the VM <b>'{0}'</b>?<br>"
|
2015-05-03 17:11:23 +02:00
|
|
|
"<small>This will shutdown all the running applications "
|
2017-02-06 04:20:13 +01:00
|
|
|
"within this VM.</small>")).format(vm.name),
|
2015-05-03 17:11:23 +02:00
|
|
|
QMessageBox.Yes | QMessageBox.Cancel)
|
2010-05-11 16:51:31 +02:00
|
|
|
|
2010-05-12 16:44:48 +02:00
|
|
|
app.processEvents()
|
|
|
|
|
2010-05-11 16:51:31 +02:00
|
|
|
if reply == QMessageBox.Yes:
|
2012-03-29 23:26:16 +02:00
|
|
|
self.shutdown_vm(vm)
|
|
|
|
|
2016-07-01 03:09:27 +02:00
|
|
|
def shutdown_vm(self, vm, shutdown_time=vm_shutdown_timeout,
|
|
|
|
check_time=vm_restart_check_timeout, and_restart=False):
|
2012-03-29 23:26:16 +02:00
|
|
|
try:
|
2013-04-13 03:12:58 +02:00
|
|
|
vm.shutdown()
|
2012-03-29 23:26:16 +02:00
|
|
|
except Exception as ex:
|
2017-01-22 05:42:38 +01:00
|
|
|
QMessageBox.warning(None, self.tr("Error shutting down VM!"),
|
2017-02-06 04:20:13 +01:00
|
|
|
unicode(self.tr("ERROR: {0}")).format(ex))
|
2012-03-29 23:26:16 +02:00
|
|
|
return
|
|
|
|
|
2017-02-06 04:20:13 +01:00
|
|
|
trayIcon.showMessage(unicode(self.tr("VM '{0}' is shutting down...")).format(vm.name),
|
2015-05-03 17:11:23 +02:00
|
|
|
msecs=3000)
|
2010-05-11 16:51:31 +02:00
|
|
|
|
2016-07-01 03:09:27 +02:00
|
|
|
self.shutdown_monitor[vm.qid] = VmShutdownMonitor(vm, shutdown_time,
|
|
|
|
check_time, and_restart, self)
|
2015-05-03 17:11:23 +02:00
|
|
|
# noinspection PyCallByClass,PyTypeChecker
|
2016-06-05 21:19:18 +02:00
|
|
|
QTimer.singleShot(check_time, self.shutdown_monitor[
|
2015-05-03 17:11:23 +02:00
|
|
|
vm.qid].check_if_vm_has_shutdown)
|
2012-03-23 09:12:30 +01:00
|
|
|
|
2016-06-05 21:19:18 +02:00
|
|
|
@pyqtSlot(name='on_action_restartvm_triggered')
|
|
|
|
def action_restartvm_triggered(self):
|
|
|
|
vm = self.get_selected_vm()
|
|
|
|
assert vm.is_running()
|
|
|
|
|
|
|
|
self.blk_manager.check_if_serves_as_backend(vm)
|
|
|
|
|
|
|
|
reply = QMessageBox.question(
|
2017-01-22 05:42:38 +01:00
|
|
|
None, self.tr("VM Restart Confirmation"),
|
2017-02-06 04:20:13 +01:00
|
|
|
unicode(self.tr("Are you sure you want to restart the VM <b>'{0}'</b>?<br>"
|
2016-06-05 21:19:18 +02:00
|
|
|
"<small>This will shutdown all the running applications "
|
2017-02-06 04:20:13 +01:00
|
|
|
"within this VM.</small>")).format(vm.name),
|
2016-06-05 21:19:18 +02:00
|
|
|
QMessageBox.Yes | QMessageBox.Cancel)
|
|
|
|
|
|
|
|
app.processEvents()
|
|
|
|
|
|
|
|
if reply == QMessageBox.Yes:
|
|
|
|
self.shutdown_vm(vm, and_restart=True)
|
|
|
|
|
2012-04-22 18:32:50 +02:00
|
|
|
@pyqtSlot(name='on_action_killvm_triggered')
|
|
|
|
def action_killvm_triggered(self):
|
|
|
|
vm = self.get_selected_vm()
|
2013-02-19 03:32:49 +01:00
|
|
|
assert vm.is_running() or vm.is_paused()
|
2012-04-22 18:32:50 +02:00
|
|
|
|
2015-05-03 17:11:23 +02:00
|
|
|
reply = QMessageBox.question(
|
2017-01-22 05:42:38 +01:00
|
|
|
None, self.tr("VM Kill Confirmation"),
|
2017-02-06 04:20:13 +01:00
|
|
|
unicode(self.tr("Are you sure you want to kill the VM <b>'{0}'</b>?<br>"
|
2015-05-03 17:11:23 +02:00
|
|
|
"<small>This will end <b>(not shutdown!)</b> all the running "
|
2017-02-06 04:20:13 +01:00
|
|
|
"applications within this VM.</small>")).format(vm.name),
|
2015-05-03 17:11:23 +02:00
|
|
|
QMessageBox.Yes | QMessageBox.Cancel,
|
|
|
|
QMessageBox.Cancel)
|
2012-04-22 18:32:50 +02:00
|
|
|
|
|
|
|
app.processEvents()
|
|
|
|
|
|
|
|
if reply == QMessageBox.Yes:
|
|
|
|
try:
|
|
|
|
vm.force_shutdown()
|
|
|
|
except Exception as ex:
|
2015-05-03 17:11:23 +02:00
|
|
|
QMessageBox.critical(
|
2017-01-22 05:42:38 +01:00
|
|
|
None, self.tr("Error while killing VM!"),
|
2017-02-06 04:20:13 +01:00
|
|
|
unicode(self.tr("<b>An exception ocurred while killing {0}.</b><br>"
|
|
|
|
"ERROR: {1}")).format(vm.name, ex))
|
2012-04-22 18:32:50 +02:00
|
|
|
return
|
|
|
|
|
2017-02-06 04:20:13 +01:00
|
|
|
trayIcon.showMessage(unicode(self.tr("VM '{0}' killed!"))
|
|
|
|
.format(vm.name), msecs=3000)
|
2010-05-11 16:51:31 +02:00
|
|
|
|
2012-01-31 14:29:13 +01:00
|
|
|
@pyqtSlot(name='on_action_settings_triggered')
|
|
|
|
def action_settings_triggered(self):
|
|
|
|
vm = self.get_selected_vm()
|
2015-05-03 17:11:23 +02:00
|
|
|
settings_window = VMSettingsWindow(vm, app, self.qvm_collection,
|
|
|
|
"basic")
|
2012-01-31 14:29:13 +01:00
|
|
|
settings_window.exec_()
|
2012-07-05 01:06:22 +02:00
|
|
|
|
2012-01-23 19:04:58 +01:00
|
|
|
@pyqtSlot(name='on_action_appmenus_triggered')
|
|
|
|
def action_appmenus_triggered(self):
|
2011-05-25 02:28:24 +02:00
|
|
|
vm = self.get_selected_vm()
|
2015-05-03 17:11:23 +02:00
|
|
|
settings_window = VMSettingsWindow(vm, app, self.qvm_collection,
|
|
|
|
"applications")
|
2012-02-09 19:47:21 +01:00
|
|
|
settings_window.exec_()
|
|
|
|
|
2013-04-13 04:10:13 +02:00
|
|
|
def update_audio_rec_info(self, vm):
|
|
|
|
vm.qubes_manager_state[QMVmState.AudioRecAvailable] = (
|
2015-05-03 17:11:23 +02:00
|
|
|
session_bus.interface().isServiceRegistered(
|
|
|
|
'org.QubesOS.Audio.%s' % vm.name).value())
|
2013-04-13 04:10:13 +02:00
|
|
|
if vm.qubes_manager_state[QMVmState.AudioRecAvailable]:
|
2015-05-03 17:11:23 +02:00
|
|
|
vm.qubes_manager_state[
|
|
|
|
QMVmState.AudioRecAllowed] = self.get_audio_rec_allowed(vm.name)
|
2013-04-13 04:10:13 +02:00
|
|
|
else:
|
|
|
|
vm.qubes_manager_state[QMVmState.AudioRecAllowed] = False
|
|
|
|
|
2015-05-03 17:11:23 +02:00
|
|
|
# noinspection PyMethodMayBeStatic
|
2013-04-13 02:54:24 +02:00
|
|
|
def get_audio_rec_allowed(self, vmname):
|
|
|
|
properties = QDBusInterface('org.QubesOS.Audio.%s' % vmname,
|
2015-05-03 17:11:23 +02:00
|
|
|
'/org/qubesos/audio',
|
|
|
|
'org.freedesktop.DBus.Properties',
|
|
|
|
session_bus)
|
2013-04-13 02:54:24 +02:00
|
|
|
|
2015-05-03 17:11:23 +02:00
|
|
|
current_audio = properties.call('Get', 'org.QubesOS.Audio',
|
|
|
|
'RecAllowed')
|
2013-04-13 02:54:24 +02:00
|
|
|
if current_audio.type() == current_audio.ReplyMessage:
|
|
|
|
value = current_audio.arguments()[0].toPyObject().toBool()
|
|
|
|
return bool(value)
|
|
|
|
return False
|
|
|
|
|
2012-11-06 06:50:14 +01:00
|
|
|
@pyqtSlot(name='on_action_toggle_audio_input_triggered')
|
|
|
|
def action_toggle_audio_input_triggered(self):
|
|
|
|
vm = self.get_selected_vm()
|
2013-04-13 02:54:24 +02:00
|
|
|
properties = QDBusInterface('org.QubesOS.Audio.%s' % vm.name,
|
2015-05-03 17:11:23 +02:00
|
|
|
'/org/qubesos/audio',
|
|
|
|
'org.freedesktop.DBus.Properties',
|
|
|
|
session_bus)
|
2013-04-13 02:54:24 +02:00
|
|
|
properties.call('Set', 'org.QubesOS.Audio', 'RecAllowed',
|
2015-05-03 17:11:23 +02:00
|
|
|
QDBusVariant(not self.get_audio_rec_allowed(vm.name)))
|
2012-11-06 06:50:14 +01:00
|
|
|
# icon will be updated based on dbus signal
|
2011-05-25 02:28:24 +02:00
|
|
|
|
2012-01-23 19:04:58 +01:00
|
|
|
@pyqtSlot(name='on_action_updatevm_triggered')
|
|
|
|
def action_updatevm_triggered(self):
|
2011-03-02 12:51:29 +01:00
|
|
|
vm = self.get_selected_vm()
|
|
|
|
|
2011-10-31 21:46:35 +01:00
|
|
|
if not vm.is_running():
|
2015-05-03 17:11:23 +02:00
|
|
|
reply = QMessageBox.question(
|
2017-01-22 05:42:38 +01:00
|
|
|
None, self.tr("VM Update Confirmation"),
|
2017-02-06 04:20:13 +01:00
|
|
|
unicode(self.tr("<b>{0}</b><br>The VM has to be running to be updated.<br>"
|
|
|
|
"Do you want to start it?<br>")).format(vm.name),
|
2015-05-03 17:11:23 +02:00
|
|
|
QMessageBox.Yes | QMessageBox.Cancel)
|
2011-10-31 21:46:35 +01:00
|
|
|
if reply != QMessageBox.Yes:
|
|
|
|
return
|
2017-02-06 04:20:13 +01:00
|
|
|
trayIcon.showMessage(unicode(self.tr("Starting '{0}'...")).format(vm.name),
|
2015-05-03 17:11:23 +02:00
|
|
|
msecs=3000)
|
2011-03-13 18:43:55 +01:00
|
|
|
|
|
|
|
app.processEvents()
|
|
|
|
|
2011-10-31 21:46:35 +01:00
|
|
|
thread_monitor = ThreadMonitor()
|
2015-05-03 17:11:23 +02:00
|
|
|
thread = threading.Thread(target=self.do_update_vm,
|
|
|
|
args=(vm, thread_monitor))
|
2011-10-31 21:46:35 +01:00
|
|
|
thread.daemon = True
|
|
|
|
thread.start()
|
|
|
|
|
2015-05-03 17:11:23 +02:00
|
|
|
progress = QProgressDialog(
|
2017-02-19 22:51:09 +01:00
|
|
|
unicode(
|
|
|
|
self.tr("<b>{0}</b><br>Please wait for the updater to "
|
|
|
|
"launch...")).format(vm.name), "", 0, 0)
|
2012-04-26 00:16:54 +02:00
|
|
|
progress.setCancelButton(None)
|
|
|
|
progress.setModal(True)
|
|
|
|
progress.show()
|
|
|
|
|
2011-10-31 21:46:35 +01:00
|
|
|
while not thread_monitor.is_finished():
|
|
|
|
app.processEvents()
|
2015-05-03 17:11:23 +02:00
|
|
|
time.sleep(0.2)
|
2012-07-05 01:06:22 +02:00
|
|
|
|
2012-04-26 00:16:54 +02:00
|
|
|
progress.hide()
|
2011-10-31 21:46:35 +01:00
|
|
|
|
2012-07-05 01:06:22 +02:00
|
|
|
if vm.qid != 0:
|
2012-05-15 12:26:10 +02:00
|
|
|
if not thread_monitor.success:
|
2017-01-22 05:42:38 +01:00
|
|
|
QMessageBox.warning(None, self.tr("Error VM update!"),
|
2017-02-06 04:20:13 +01:00
|
|
|
unicode(self.tr("ERROR: {0}")).format(
|
2015-05-03 17:11:23 +02:00
|
|
|
thread_monitor.error_msg))
|
2011-10-31 21:46:35 +01:00
|
|
|
|
2015-05-04 01:25:55 +02:00
|
|
|
@staticmethod
|
|
|
|
def do_update_vm(vm, thread_monitor):
|
2011-10-31 21:46:35 +01:00
|
|
|
try:
|
2011-12-18 14:03:16 +01:00
|
|
|
if vm.qid == 0:
|
2015-05-03 17:11:23 +02:00
|
|
|
subprocess.check_call(
|
|
|
|
["/usr/bin/qubes-dom0-update", "--clean", "--gui"])
|
2011-12-18 14:03:16 +01:00
|
|
|
else:
|
2015-11-13 05:42:24 +01:00
|
|
|
if not vm.is_running():
|
|
|
|
trayIcon.showMessage(
|
|
|
|
"Starting the '{0}' VM...".format(vm.name),
|
|
|
|
msecs=3000)
|
|
|
|
vm.start()
|
|
|
|
vm.run_service("qubes.InstallUpdatesGUI", gui=True,
|
2017-03-13 04:43:41 +01:00
|
|
|
user="root", wait=False)
|
2011-10-31 21:46:35 +01:00
|
|
|
except Exception as ex:
|
|
|
|
thread_monitor.set_error_msg(str(ex))
|
|
|
|
thread_monitor.set_finished()
|
|
|
|
return
|
|
|
|
thread_monitor.set_finished()
|
2011-03-02 12:51:29 +01:00
|
|
|
|
2012-07-05 01:06:22 +02:00
|
|
|
|
2012-05-11 12:50:45 +02:00
|
|
|
@pyqtSlot(name='on_action_run_command_in_vm_triggered')
|
|
|
|
def action_run_command_in_vm_triggered(self):
|
|
|
|
vm = self.get_selected_vm()
|
|
|
|
|
2015-05-03 17:11:23 +02:00
|
|
|
(command_to_run, ok) = QInputDialog.getText(
|
2017-01-22 05:42:38 +01:00
|
|
|
self, self.tr('Qubes command entry'),
|
2017-02-06 04:20:13 +01:00
|
|
|
unicode(self.tr('Run command in <b>{}</b>:')).format(vm.name))
|
2013-02-12 01:06:32 +01:00
|
|
|
if not ok or command_to_run == "":
|
|
|
|
return
|
2012-05-11 12:50:45 +02:00
|
|
|
thread_monitor = ThreadMonitor()
|
2015-05-03 17:11:23 +02:00
|
|
|
thread = threading.Thread(target=self.do_run_command_in_vm, args=(
|
2016-10-03 00:11:59 +02:00
|
|
|
vm, unicode(command_to_run), thread_monitor))
|
2012-05-11 12:50:45 +02:00
|
|
|
thread.daemon = True
|
|
|
|
thread.start()
|
|
|
|
|
|
|
|
while not thread_monitor.is_finished():
|
|
|
|
app.processEvents()
|
2015-05-03 17:11:23 +02:00
|
|
|
time.sleep(0.2)
|
2012-05-11 12:50:45 +02:00
|
|
|
|
|
|
|
if not thread_monitor.success:
|
2017-01-22 05:42:38 +01:00
|
|
|
QMessageBox.warning(None, self.tr("Error while running command"),
|
2017-02-06 04:20:13 +01:00
|
|
|
unicode(self.tr("Exception while running command:<br>{0}")).format(
|
2017-01-22 05:42:38 +01:00
|
|
|
thread_monitor.error_msg))
|
2012-05-11 12:50:45 +02:00
|
|
|
|
2015-05-04 01:25:55 +02:00
|
|
|
@staticmethod
|
|
|
|
def do_run_command_in_vm(vm, command_to_run, thread_monitor):
|
2013-02-12 01:06:32 +01:00
|
|
|
try:
|
|
|
|
vm.run(command_to_run, verbose=False, autostart=True,
|
2015-05-03 17:11:23 +02:00
|
|
|
notify_function=lambda lvl, msg: trayIcon.showMessage(
|
|
|
|
msg, msecs=3000))
|
2013-02-12 01:06:32 +01:00
|
|
|
except Exception as ex:
|
|
|
|
thread_monitor.set_error_msg(str(ex))
|
2012-05-11 12:50:45 +02:00
|
|
|
thread_monitor.set_finished()
|
|
|
|
|
2012-04-24 17:48:10 +02:00
|
|
|
@pyqtSlot(name='on_action_set_keyboard_layout_triggered')
|
|
|
|
def action_set_keyboard_layout_triggered(self):
|
|
|
|
vm = self.get_selected_vm()
|
2015-05-03 17:11:23 +02:00
|
|
|
vm.run('qubes-change-keyboard-layout', verbose=False)
|
2012-04-24 17:48:10 +02:00
|
|
|
|
2012-01-23 19:04:58 +01:00
|
|
|
@pyqtSlot(name='on_action_showallvms_triggered')
|
|
|
|
def action_showallvms_triggered(self):
|
2011-04-02 15:27:40 +02:00
|
|
|
self.show_inactive_vms = self.action_showallvms.isChecked()
|
2012-05-29 17:05:34 +02:00
|
|
|
|
2016-11-23 08:49:13 +01:00
|
|
|
self.showhide_vms()
|
2012-03-28 12:45:31 +02:00
|
|
|
self.set_table_geom_size()
|
2012-08-04 04:13:16 +02:00
|
|
|
if self.settings_loaded:
|
2015-05-03 17:11:23 +02:00
|
|
|
self.manager_settings.setValue('view/show_inactive_vms',
|
|
|
|
self.show_inactive_vms)
|
2012-08-04 04:13:16 +02:00
|
|
|
self.manager_settings.sync()
|
2011-04-01 12:02:27 +02:00
|
|
|
|
2013-03-05 11:21:16 +01:00
|
|
|
@pyqtSlot(name='on_action_showinternalvms_triggered')
|
|
|
|
def action_showinternalvms_triggered(self):
|
|
|
|
self.show_internal_vms = self.action_showinternalvms.isChecked()
|
|
|
|
|
2016-11-23 08:49:13 +01:00
|
|
|
self.showhide_vms()
|
2013-03-05 11:21:16 +01:00
|
|
|
self.set_table_geom_size()
|
|
|
|
if self.settings_loaded:
|
2015-05-03 17:11:23 +02:00
|
|
|
self.manager_settings.setValue('view/show_internal_vms',
|
|
|
|
self.show_internal_vms)
|
2013-03-05 11:21:16 +01:00
|
|
|
self.manager_settings.sync()
|
|
|
|
|
2012-01-23 19:04:58 +01:00
|
|
|
@pyqtSlot(name='on_action_editfwrules_triggered')
|
|
|
|
def action_editfwrules_triggered(self):
|
2011-02-21 18:15:35 +01:00
|
|
|
vm = self.get_selected_vm()
|
2015-05-03 17:11:23 +02:00
|
|
|
settings_window = VMSettingsWindow(vm, app, self.qvm_collection,
|
|
|
|
"firewall")
|
2012-02-10 00:30:45 +01:00
|
|
|
settings_window.exec_()
|
2011-03-09 17:52:32 +01:00
|
|
|
|
2012-01-31 17:29:00 +01:00
|
|
|
@pyqtSlot(name='on_action_global_settings_triggered')
|
|
|
|
def action_global_settings_triggered(self):
|
2012-03-15 00:22:06 +01:00
|
|
|
global_settings_window = GlobalSettingsWindow(app, self.qvm_collection)
|
2012-01-31 17:29:00 +01:00
|
|
|
global_settings_window.exec_()
|
|
|
|
|
2017-01-28 04:15:58 +01:00
|
|
|
@pyqtSlot(name='on_action_show_network_triggered')
|
|
|
|
def action_show_network_triggered(self):
|
|
|
|
network_notes_dialog = NetworkNotesDialog()
|
|
|
|
network_notes_dialog.exec_()
|
|
|
|
|
2012-01-31 14:29:13 +01:00
|
|
|
@pyqtSlot(name='on_action_restore_triggered')
|
|
|
|
def action_restore_triggered(self):
|
2015-05-03 17:11:23 +02:00
|
|
|
restore_window = RestoreVMsWindow(app, self.qvm_collection,
|
|
|
|
self.blk_manager)
|
2012-01-31 14:29:13 +01:00
|
|
|
restore_window.exec_()
|
|
|
|
|
|
|
|
@pyqtSlot(name='on_action_backup_triggered')
|
|
|
|
def action_backup_triggered(self):
|
2015-05-03 17:11:23 +02:00
|
|
|
backup_window = BackupVMsWindow(app, self.qvm_collection,
|
|
|
|
self.blk_manager, self.shutdown_vm)
|
2012-01-31 14:29:13 +01:00
|
|
|
backup_window.exec_()
|
|
|
|
|
2012-03-06 18:45:47 +01:00
|
|
|
def showhide_menubar(self, checked):
|
2012-08-04 04:13:16 +02:00
|
|
|
self.menubar.setVisible(checked)
|
2012-03-28 12:45:31 +02:00
|
|
|
self.set_table_geom_size()
|
2012-03-20 18:36:48 +01:00
|
|
|
if not checked:
|
|
|
|
self.context_menu.addAction(self.action_menubar)
|
|
|
|
else:
|
|
|
|
self.context_menu.removeAction(self.action_menubar)
|
2012-08-04 04:13:16 +02:00
|
|
|
if self.settings_loaded:
|
|
|
|
self.manager_settings.setValue('view/menubar_visible', checked)
|
|
|
|
self.manager_settings.sync()
|
2012-03-06 18:45:47 +01:00
|
|
|
|
|
|
|
def showhide_toolbar(self, checked):
|
|
|
|
self.toolbar.setVisible(checked)
|
2012-03-28 12:45:31 +02:00
|
|
|
self.set_table_geom_size()
|
2012-03-20 18:36:48 +01:00
|
|
|
if not checked:
|
|
|
|
self.context_menu.addAction(self.action_toolbar)
|
|
|
|
else:
|
|
|
|
self.context_menu.removeAction(self.action_toolbar)
|
2012-08-04 04:13:16 +02:00
|
|
|
if self.settings_loaded:
|
|
|
|
self.manager_settings.setValue('view/toolbar_visible', checked)
|
|
|
|
self.manager_settings.sync()
|
2012-01-31 14:29:13 +01:00
|
|
|
|
2012-03-26 11:48:49 +02:00
|
|
|
def showhide_column(self, col_num, show):
|
2015-05-03 17:11:23 +02:00
|
|
|
self.table.setColumnHidden(col_num, not show)
|
2012-03-28 12:45:31 +02:00
|
|
|
self.set_table_geom_size()
|
2012-04-26 16:32:40 +02:00
|
|
|
val = 1 if show else -1
|
|
|
|
self.visible_columns_count += val
|
|
|
|
|
|
|
|
if self.visible_columns_count == 1:
|
2015-05-03 17:11:23 +02:00
|
|
|
# disable hiding the last one
|
2012-04-26 16:32:40 +02:00
|
|
|
for c in self.columns_actions:
|
|
|
|
if self.columns_actions[c].isChecked():
|
|
|
|
self.columns_actions[c].setEnabled(False)
|
|
|
|
break
|
|
|
|
elif self.visible_columns_count == 2 and val == 1:
|
2015-05-03 17:11:23 +02:00
|
|
|
# enable hiding previously disabled column
|
2012-04-26 16:32:40 +02:00
|
|
|
for c in self.columns_actions:
|
|
|
|
if not self.columns_actions[c].isEnabled():
|
|
|
|
self.columns_actions[c].setEnabled(True)
|
2014-02-23 00:44:08 +01:00
|
|
|
break
|
2012-04-26 16:32:40 +02:00
|
|
|
|
2012-08-04 04:13:16 +02:00
|
|
|
if self.settings_loaded:
|
2015-05-03 17:11:23 +02:00
|
|
|
col_name = [name for name in self.columns_indices.keys() if
|
|
|
|
self.columns_indices[name] == col_num][0]
|
2012-08-04 04:13:16 +02:00
|
|
|
self.manager_settings.setValue('columns/%s' % col_name, show)
|
|
|
|
self.manager_settings.sync()
|
|
|
|
|
2012-04-26 16:32:40 +02:00
|
|
|
def on_action_vm_type_toggled(self, checked):
|
2015-05-03 17:11:23 +02:00
|
|
|
self.showhide_column(self.columns_indices['Type'], checked)
|
2012-04-26 16:32:40 +02:00
|
|
|
|
|
|
|
def on_action_label_toggled(self, checked):
|
2015-05-03 17:11:23 +02:00
|
|
|
self.showhide_column(self.columns_indices['Label'], checked)
|
2012-04-26 16:32:40 +02:00
|
|
|
|
|
|
|
def on_action_name_toggled(self, checked):
|
2015-05-03 17:11:23 +02:00
|
|
|
self.showhide_column(self.columns_indices['Name'], checked)
|
2012-04-26 16:32:40 +02:00
|
|
|
|
|
|
|
def on_action_state_toggled(self, checked):
|
2015-05-03 17:11:23 +02:00
|
|
|
self.showhide_column(self.columns_indices['State'], checked)
|
2012-07-05 01:06:22 +02:00
|
|
|
|
2013-03-05 10:40:04 +01:00
|
|
|
def on_action_internal_toggled(self, checked):
|
2015-05-03 17:11:23 +02:00
|
|
|
self.showhide_column(self.columns_indices['Internal'], checked)
|
2013-03-05 10:40:04 +01:00
|
|
|
|
2014-03-10 04:27:52 +01:00
|
|
|
def on_action_ip_toggled(self, checked):
|
2015-05-03 17:11:23 +02:00
|
|
|
self.showhide_column(self.columns_indices['IP'], checked)
|
2014-03-10 04:27:52 +01:00
|
|
|
|
|
|
|
def on_action_backups_toggled(self, checked):
|
2015-05-03 17:11:23 +02:00
|
|
|
self.showhide_column(self.columns_indices['Backups'], checked)
|
2014-03-10 04:27:52 +01:00
|
|
|
|
2014-03-10 04:28:30 +01:00
|
|
|
def on_action_last_backup_toggled(self, checked):
|
2015-05-03 17:11:23 +02:00
|
|
|
self.showhide_column(self.columns_indices['Last backup'], checked)
|
2014-03-10 04:28:30 +01:00
|
|
|
|
2012-04-26 16:32:40 +02:00
|
|
|
def on_action_template_toggled(self, checked):
|
2015-05-03 17:11:23 +02:00
|
|
|
self.showhide_column(self.columns_indices['Template'], checked)
|
2012-01-22 18:45:41 +01:00
|
|
|
|
2012-04-26 16:32:40 +02:00
|
|
|
def on_action_netvm_toggled(self, checked):
|
2015-05-03 17:11:23 +02:00
|
|
|
self.showhide_column(self.columns_indices['NetVM'], checked)
|
2012-07-05 01:06:22 +02:00
|
|
|
|
2012-04-26 16:32:40 +02:00
|
|
|
def on_action_cpu_toggled(self, checked):
|
2015-05-03 17:11:23 +02:00
|
|
|
self.showhide_column(self.columns_indices['CPU'], checked)
|
2012-07-05 01:06:22 +02:00
|
|
|
|
2012-04-26 16:32:40 +02:00
|
|
|
def on_action_cpu_graph_toggled(self, checked):
|
2015-05-03 17:11:23 +02:00
|
|
|
self.showhide_column(self.columns_indices['CPU Graph'], checked)
|
2012-01-22 18:45:41 +01:00
|
|
|
|
2012-04-26 16:32:40 +02:00
|
|
|
def on_action_mem_toggled(self, checked):
|
2015-05-03 17:11:23 +02:00
|
|
|
self.showhide_column(self.columns_indices['MEM'], checked)
|
2012-07-05 01:06:22 +02:00
|
|
|
|
2012-04-26 16:32:40 +02:00
|
|
|
def on_action_mem_graph_toggled(self, checked):
|
2015-05-03 17:11:23 +02:00
|
|
|
self.showhide_column(self.columns_indices['MEM Graph'], checked)
|
2012-01-22 18:45:41 +01:00
|
|
|
|
2012-04-27 17:04:35 +02:00
|
|
|
def on_action_size_on_disk_toggled(self, checked):
|
2015-05-03 17:11:23 +02:00
|
|
|
self.showhide_column(self.columns_indices['Size'], checked)
|
2012-02-14 19:00:50 +01:00
|
|
|
|
2012-04-26 17:46:41 +02:00
|
|
|
@pyqtSlot(name='on_action_about_qubes_triggered')
|
|
|
|
def action_about_qubes_triggered(self):
|
2015-10-01 22:34:49 +02:00
|
|
|
about = AboutDialog()
|
|
|
|
about.exec_()
|
2012-07-05 01:06:22 +02:00
|
|
|
|
2012-03-06 18:45:47 +01:00
|
|
|
def createPopupMenu(self):
|
|
|
|
menu = QMenu()
|
|
|
|
menu.addAction(self.action_toolbar)
|
|
|
|
menu.addAction(self.action_menubar)
|
|
|
|
return menu
|
|
|
|
|
2013-02-15 16:06:54 +01:00
|
|
|
def open_tools_context_menu(self, widget, point):
|
|
|
|
self.tools_context_menu.exec_(widget.mapToGlobal(point))
|
|
|
|
|
2012-02-14 19:00:50 +01:00
|
|
|
@pyqtSlot('const QPoint&')
|
|
|
|
def open_context_menu(self, point):
|
|
|
|
vm = self.get_selected_vm()
|
2012-04-23 19:01:22 +02:00
|
|
|
|
|
|
|
running = vm.is_running()
|
|
|
|
|
2015-05-03 17:11:23 +02:00
|
|
|
# logs menu
|
2012-04-24 12:06:08 +02:00
|
|
|
self.logs_menu.clear()
|
2016-11-22 05:37:51 +01:00
|
|
|
|
2012-04-24 12:06:08 +02:00
|
|
|
if vm.qid == 0:
|
2016-11-22 05:37:51 +01:00
|
|
|
logfiles = ["/var/log/xen/console/hypervisor.log"]
|
2012-04-24 12:06:08 +02:00
|
|
|
else:
|
2016-11-22 05:37:51 +01:00
|
|
|
logfiles = [
|
|
|
|
"/var/log/xen/console/guest-" + vm.name + ".log",
|
|
|
|
"/var/log/xen/console/guest-" + vm.name + "-dm.log",
|
|
|
|
"/var/log/qubes/guid." + vm.name + ".log",
|
|
|
|
"/var/log/qubes/qrexec." + vm.name + ".log",
|
|
|
|
]
|
|
|
|
|
|
|
|
menu_empty = True
|
|
|
|
for logfile in logfiles:
|
|
|
|
if os.path.exists(logfile):
|
|
|
|
action = self.logs_menu.addAction(QIcon(":/log.png"), logfile)
|
|
|
|
action.setData(QVariant(logfile))
|
2013-10-18 03:40:21 +02:00
|
|
|
menu_empty = False
|
|
|
|
|
2016-11-22 05:37:51 +01:00
|
|
|
self.logs_menu.setEnabled(not menu_empty)
|
2012-07-05 01:06:22 +02:00
|
|
|
|
2012-04-23 19:01:22 +02:00
|
|
|
# blk menu
|
|
|
|
if not running:
|
2012-02-14 19:00:50 +01:00
|
|
|
self.blk_menu.setEnabled(False)
|
|
|
|
else:
|
|
|
|
self.blk_menu.clear()
|
|
|
|
self.blk_menu.setEnabled(True)
|
2012-04-13 01:08:36 +02:00
|
|
|
|
|
|
|
self.blk_manager.blk_lock.acquire()
|
2015-04-14 23:11:12 +02:00
|
|
|
if len(self.blk_manager.attached_devs) > 0:
|
2012-02-14 19:00:50 +01:00
|
|
|
for d in self.blk_manager.attached_devs:
|
2015-05-03 17:11:23 +02:00
|
|
|
if (self.blk_manager.attached_devs[d]
|
|
|
|
['attached_to']['vm'].qid == vm.qid):
|
2017-02-06 04:20:13 +01:00
|
|
|
text = unicode(self.tr("Detach {dev} {size} {desc}")).format(
|
2017-01-22 05:42:38 +01:00
|
|
|
dev=d,
|
|
|
|
size=unicode(
|
|
|
|
self.blk_manager.attached_devs[d]['size']),
|
|
|
|
desc=self.blk_manager.attached_devs[d]['desc'])
|
2015-05-03 17:11:23 +02:00
|
|
|
action = self.blk_menu.addAction(QIcon(":/remove.png"),
|
|
|
|
text)
|
2012-02-14 19:00:50 +01:00
|
|
|
action.setData(QVariant(d))
|
|
|
|
|
2012-02-20 07:56:38 +01:00
|
|
|
if len(self.blk_manager.free_devs) > 0:
|
2012-02-14 19:00:50 +01:00
|
|
|
for d in self.blk_manager.free_devs:
|
2012-02-20 07:56:38 +01:00
|
|
|
if d.startswith(vm.name):
|
|
|
|
continue
|
2012-07-13 01:42:48 +02:00
|
|
|
# skip partitions heuristic
|
2015-05-03 17:11:23 +02:00
|
|
|
if d[-1].isdigit() and \
|
|
|
|
d[0:-1] in self.blk_manager.current_blk:
|
2012-07-13 01:42:48 +02:00
|
|
|
continue
|
2017-02-06 04:20:13 +01:00
|
|
|
text = unicode(self.tr("Attach {dev} {size} {desc}")).format(
|
2017-01-22 05:42:38 +01:00
|
|
|
dev=d,
|
|
|
|
size=unicode(
|
|
|
|
self.blk_manager.free_devs[d]['size']),
|
|
|
|
desc=self.blk_manager.free_devs[d]['desc'])
|
2012-04-23 19:01:22 +02:00
|
|
|
action = self.blk_menu.addAction(QIcon(":/add.png"), text)
|
2012-02-14 19:00:50 +01:00
|
|
|
action.setData(QVariant(d))
|
|
|
|
|
2012-04-13 01:08:36 +02:00
|
|
|
self.blk_manager.blk_lock.release()
|
|
|
|
|
2012-02-14 19:00:50 +01:00
|
|
|
if self.blk_menu.isEmpty():
|
|
|
|
self.blk_menu.setEnabled(False)
|
2012-05-25 13:59:58 +02:00
|
|
|
|
2012-02-14 19:00:50 +01:00
|
|
|
self.context_menu.exec_(self.table.mapToGlobal(point))
|
|
|
|
|
2012-04-23 19:01:22 +02:00
|
|
|
@pyqtSlot('QAction *')
|
|
|
|
def show_log(self, action):
|
|
|
|
log = str(action.data().toString())
|
2012-05-10 13:17:24 +02:00
|
|
|
log_dialog = LogDialog(app, log)
|
|
|
|
log_dialog.exec_()
|
2012-04-23 19:01:22 +02:00
|
|
|
|
2012-02-14 19:00:50 +01:00
|
|
|
@pyqtSlot('QAction *')
|
|
|
|
def attach_dettach_device_triggered(self, action):
|
|
|
|
dev = str(action.data().toString())
|
|
|
|
vm = self.get_selected_vm()
|
2012-04-13 01:08:36 +02:00
|
|
|
|
|
|
|
self.blk_manager.blk_lock.acquire()
|
2013-10-02 01:10:58 +02:00
|
|
|
try:
|
|
|
|
if dev in self.blk_manager.attached_devs:
|
|
|
|
self.blk_manager.detach_device(vm, dev)
|
|
|
|
else:
|
|
|
|
self.blk_manager.attach_device(vm, dev)
|
|
|
|
self.blk_manager.blk_lock.release()
|
|
|
|
except QubesException as e:
|
|
|
|
self.blk_manager.blk_lock.release()
|
2017-01-22 05:42:38 +01:00
|
|
|
QMessageBox.critical(None,
|
|
|
|
self.tr("Block attach/detach error!"), str(e))
|
2012-02-14 19:00:50 +01:00
|
|
|
|
2012-07-05 01:06:22 +02:00
|
|
|
|
2010-05-11 16:51:31 +02:00
|
|
|
class QubesTrayIcon(QSystemTrayIcon):
|
2014-03-31 18:38:17 +02:00
|
|
|
def __init__(self, icon, blk_manager):
|
2010-05-11 16:51:31 +02:00
|
|
|
QSystemTrayIcon.__init__(self, icon)
|
|
|
|
self.menu = QMenu()
|
|
|
|
|
2017-01-22 05:42:38 +01:00
|
|
|
action_showmanager = self.create_action(
|
|
|
|
self.tr("Open VM Manager"),
|
|
|
|
slot=show_manager, icon="qubes")
|
|
|
|
action_copy = self.create_action(
|
|
|
|
self.tr("Copy Dom0 clipboard"), icon="copy",
|
|
|
|
slot=do_dom0_copy)
|
|
|
|
action_backup = self.create_action(self.tr("Make backup"))
|
|
|
|
action_preferences = self.create_action(self.tr("Preferences"))
|
|
|
|
action_set_netvm = self.create_action(self.tr("Set default NetVM"),
|
2015-05-03 18:42:59 +02:00
|
|
|
icon="networking")
|
2017-01-22 05:42:38 +01:00
|
|
|
action_sys_info = self.create_action(self.tr("System Info"), icon="dom0")
|
|
|
|
action_exit = self.create_action(self.tr("Exit"), slot=exit_app)
|
2010-05-11 16:51:31 +02:00
|
|
|
|
|
|
|
action_backup.setDisabled(True)
|
|
|
|
action_preferences.setDisabled(True)
|
|
|
|
action_set_netvm.setDisabled(True)
|
|
|
|
action_sys_info.setDisabled(True)
|
|
|
|
|
2014-03-31 18:38:17 +02:00
|
|
|
self.blk_manager = blk_manager
|
|
|
|
|
|
|
|
self.blk_menu = QMenu(self.menu)
|
2017-01-22 05:42:38 +01:00
|
|
|
self.blk_menu.setTitle(self.tr("Block devices"))
|
|
|
|
action_blk_menu = self.create_action(self.tr("Block devices"))
|
2014-03-31 18:38:17 +02:00
|
|
|
action_blk_menu.setMenu(self.blk_menu)
|
|
|
|
|
2015-05-03 18:42:59 +02:00
|
|
|
self.add_actions(self.menu, (action_showmanager,
|
2016-11-27 01:12:51 +01:00
|
|
|
action_copy,
|
2015-05-03 18:42:59 +02:00
|
|
|
action_blk_menu,
|
|
|
|
action_backup,
|
|
|
|
action_sys_info,
|
|
|
|
None,
|
|
|
|
action_preferences,
|
|
|
|
action_set_netvm,
|
|
|
|
None,
|
|
|
|
action_exit))
|
2010-05-11 16:51:31 +02:00
|
|
|
|
|
|
|
self.setContextMenu(self.menu)
|
|
|
|
|
2015-05-03 17:11:23 +02:00
|
|
|
self.connect(self,
|
|
|
|
SIGNAL("activated (QSystemTrayIcon::ActivationReason)"),
|
|
|
|
self.icon_clicked)
|
2010-05-11 16:51:31 +02:00
|
|
|
|
2014-05-15 23:49:02 +02:00
|
|
|
self.tray_notifier_type = None
|
2013-04-13 02:54:24 +02:00
|
|
|
self.tray_notifier = QDBusInterface("org.freedesktop.Notifications",
|
2015-05-03 17:11:23 +02:00
|
|
|
"/org/freedesktop/Notifications",
|
|
|
|
"org.freedesktop.Notifications",
|
|
|
|
session_bus)
|
2014-05-05 02:15:37 +02:00
|
|
|
srv_info = self.tray_notifier.call("GetServerInformation")
|
2015-05-03 17:11:23 +02:00
|
|
|
if srv_info.type() == QDBusMessage.ReplyMessage and \
|
|
|
|
len(srv_info.arguments()) > 1:
|
2014-05-15 23:49:02 +02:00
|
|
|
self.tray_notifier_type = srv_info.arguments()[1]
|
2012-04-27 12:55:54 +02:00
|
|
|
|
2014-06-10 01:15:26 +02:00
|
|
|
if os.path.exists(table_widgets.qubes_dom0_updates_stat_file):
|
2017-01-22 05:42:38 +01:00
|
|
|
self.showMessage(self.tr("Qubes dom0 updates available."), msecs=0)
|
2014-06-10 01:15:26 +02:00
|
|
|
|
2014-03-31 18:38:17 +02:00
|
|
|
def update_blk_menu(self):
|
|
|
|
global manager_window
|
|
|
|
|
|
|
|
def create_vm_submenu(dev):
|
|
|
|
blk_vm_menu = QMenu(self.blk_menu)
|
|
|
|
blk_vm_menu.triggered.connect(
|
2015-05-03 18:42:59 +02:00
|
|
|
lambda a, trig_dev=dev: self.attach_device_triggered(a,
|
|
|
|
trig_dev))
|
|
|
|
for this_vm in sorted(manager_window.qvm_collection.values(),
|
|
|
|
key=lambda x: x.name):
|
2015-05-28 02:00:23 +02:00
|
|
|
if not this_vm.is_running():
|
2014-03-31 18:38:17 +02:00
|
|
|
continue
|
2015-05-03 18:42:59 +02:00
|
|
|
if this_vm.qid == 0:
|
2014-03-31 18:38:17 +02:00
|
|
|
# skip dom0 to prevent (fatal) mistakes
|
|
|
|
continue
|
2015-05-03 18:42:59 +02:00
|
|
|
this_action = blk_vm_menu.addAction(QIcon(":/add.png"),
|
|
|
|
this_vm.name)
|
|
|
|
this_action.setData(QVariant(this_vm))
|
2014-03-31 18:38:17 +02:00
|
|
|
return blk_vm_menu
|
|
|
|
|
|
|
|
self.blk_menu.clear()
|
|
|
|
self.blk_menu.setEnabled(True)
|
|
|
|
|
|
|
|
self.blk_manager.blk_lock.acquire()
|
2015-05-03 17:11:23 +02:00
|
|
|
if len(self.blk_manager.attached_devs) > 0:
|
2014-03-31 18:38:17 +02:00
|
|
|
for d in self.blk_manager.attached_devs:
|
2015-04-14 23:11:12 +02:00
|
|
|
vm = self.blk_manager.attached_devs[d]['attached_to']['vm']
|
2017-02-06 04:20:13 +01:00
|
|
|
text = unicode(self.tr("Detach {dev} {desc} ({size}) from {vm}")).format(
|
2017-01-22 05:42:38 +01:00
|
|
|
dev=d,
|
|
|
|
desc=self.blk_manager.attached_devs[d]['desc'],
|
|
|
|
size=unicode(self.blk_manager.attached_devs[d]['size']),
|
|
|
|
vm=vm.name)
|
2014-03-31 18:38:17 +02:00
|
|
|
action = self.blk_menu.addAction(QIcon(":/remove.png"), text)
|
|
|
|
action.setData(QVariant(d))
|
|
|
|
action.triggered.connect(
|
|
|
|
lambda b, a=action: self.dettach_device_triggered(a))
|
|
|
|
|
|
|
|
if len(self.blk_manager.free_devs) > 0:
|
|
|
|
for d in self.blk_manager.free_devs:
|
|
|
|
# skip partitions heuristic
|
|
|
|
if d[-1].isdigit() and d[0:-1] in self.blk_manager.current_blk:
|
|
|
|
continue
|
2017-02-06 04:20:13 +01:00
|
|
|
text = unicode(self.tr("Attach {dev} {size} {desc}")).format(
|
2017-01-22 05:42:38 +01:00
|
|
|
dev=d,
|
|
|
|
size=unicode(self.blk_manager.free_devs[d]['size']),
|
|
|
|
desc=self.blk_manager.free_devs[d]['desc']
|
2014-03-31 18:38:17 +02:00
|
|
|
)
|
|
|
|
action = self.blk_menu.addAction(QIcon(":/add.png"), text)
|
|
|
|
action.setMenu(create_vm_submenu(d))
|
|
|
|
|
|
|
|
self.blk_manager.blk_lock.release()
|
|
|
|
|
|
|
|
if self.blk_menu.isEmpty():
|
|
|
|
self.blk_menu.setEnabled(False)
|
|
|
|
|
|
|
|
@pyqtSlot('QAction *')
|
|
|
|
def attach_device_triggered(self, action, dev):
|
|
|
|
vm = action.data().toPyObject()
|
|
|
|
|
|
|
|
self.blk_manager.blk_lock.acquire()
|
|
|
|
try:
|
|
|
|
self.blk_manager.attach_device(vm, dev)
|
|
|
|
self.blk_manager.blk_lock.release()
|
|
|
|
except QubesException as e:
|
|
|
|
self.blk_manager.blk_lock.release()
|
2017-01-22 05:42:38 +01:00
|
|
|
QMessageBox.critical(None,
|
|
|
|
self.tr("Block attach/detach error!"), str(e))
|
2014-03-31 18:38:17 +02:00
|
|
|
|
|
|
|
@pyqtSlot('QAction *')
|
|
|
|
def dettach_device_triggered(self, action):
|
|
|
|
dev = str(action.data().toString())
|
2015-04-14 23:11:12 +02:00
|
|
|
vm = self.blk_manager.attached_devs[dev]['attached_to']['vm']
|
2014-03-31 18:38:17 +02:00
|
|
|
|
|
|
|
self.blk_manager.blk_lock.acquire()
|
|
|
|
try:
|
|
|
|
self.blk_manager.detach_device(vm, dev)
|
|
|
|
self.blk_manager.blk_lock.release()
|
|
|
|
except QubesException as e:
|
|
|
|
self.blk_manager.blk_lock.release()
|
2017-01-22 05:42:38 +01:00
|
|
|
QMessageBox.critical(None,
|
|
|
|
self.tr("Block attach/detach error!"), str(e))
|
2014-03-31 18:38:17 +02:00
|
|
|
|
2010-05-11 16:51:31 +02:00
|
|
|
def icon_clicked(self, reason):
|
|
|
|
if reason == QSystemTrayIcon.Context:
|
2014-03-31 18:38:17 +02:00
|
|
|
self.update_blk_menu()
|
2010-05-11 16:51:31 +02:00
|
|
|
# Handle the right click normally, i.e. display the context menu
|
|
|
|
return
|
|
|
|
else:
|
2012-05-19 07:42:57 +02:00
|
|
|
bring_manager_to_front()
|
2010-05-11 16:51:31 +02:00
|
|
|
|
2015-05-03 18:42:59 +02:00
|
|
|
# noinspection PyMethodMayBeStatic
|
|
|
|
def add_actions(self, target, actions):
|
2010-05-11 16:51:31 +02:00
|
|
|
for action in actions:
|
|
|
|
if action is None:
|
|
|
|
target.addSeparator()
|
|
|
|
else:
|
|
|
|
target.addAction(action)
|
|
|
|
|
2015-05-03 18:42:59 +02:00
|
|
|
def showMessage(self, message, msecs, **kwargs):
|
2013-04-13 02:54:24 +02:00
|
|
|
# QtDBus bindings doesn't use introspection to get proper method
|
|
|
|
# parameters types, so must cast explicitly
|
|
|
|
v_replace_id = QVariant(0)
|
|
|
|
v_replace_id.convert(QVariant.UInt)
|
|
|
|
v_actions = QVariant([])
|
|
|
|
v_actions.convert(QVariant.StringList)
|
2014-05-12 15:33:18 +02:00
|
|
|
if self.tray_notifier_type == "KDE":
|
|
|
|
message = message.replace('\n', '<br/>\n')
|
2013-04-13 02:54:24 +02:00
|
|
|
self.tray_notifier.call("Notify", "Qubes", v_replace_id,
|
2015-05-03 17:11:23 +02:00
|
|
|
"qubes-manager", "Qubes VM Manager",
|
|
|
|
message, v_actions, QVariant.fromMap({}), msecs)
|
2010-05-11 16:51:31 +02:00
|
|
|
|
2015-05-03 18:42:59 +02:00
|
|
|
def create_action(self, text, slot=None, shortcut=None, icon=None,
|
|
|
|
tip=None, checkable=False, signal="triggered()"):
|
2010-05-11 16:51:31 +02:00
|
|
|
action = QAction(text, self)
|
|
|
|
if icon is not None:
|
|
|
|
action.setIcon(QIcon(":/%s.png" % icon))
|
|
|
|
if shortcut is not None:
|
|
|
|
action.setShortcut(shortcut)
|
|
|
|
if tip is not None:
|
|
|
|
action.setToolTip(tip)
|
|
|
|
action.setStatusTip(tip)
|
|
|
|
if slot is not None:
|
|
|
|
self.connect(action, SIGNAL(signal), slot)
|
|
|
|
if checkable:
|
|
|
|
action.setCheckable(True)
|
|
|
|
return action
|
|
|
|
|
2015-05-03 17:11:23 +02:00
|
|
|
|
2013-04-13 02:54:24 +02:00
|
|
|
class QubesDbusNotifyServerAdaptor(QDBusAbstractAdaptor):
|
|
|
|
""" This provides the DBus adaptor to the outside world"""
|
2012-07-05 01:10:01 +02:00
|
|
|
|
2013-04-13 02:54:24 +02:00
|
|
|
Q_CLASSINFO("D-Bus Interface", dbus_interface)
|
|
|
|
|
|
|
|
@pyqtSlot(str, str)
|
2012-07-05 01:10:01 +02:00
|
|
|
def notify_error(self, vmname, message):
|
2013-04-13 02:54:24 +02:00
|
|
|
vm = self.parent().qvm_collection.get_vm_by_name(vmname)
|
2012-07-05 01:10:01 +02:00
|
|
|
if vm:
|
2013-04-13 02:54:24 +02:00
|
|
|
self.parent().set_error(vm.qid, message)
|
2012-07-05 01:10:01 +02:00
|
|
|
else:
|
|
|
|
# ignore VM-not-found error
|
|
|
|
pass
|
2013-04-13 02:54:24 +02:00
|
|
|
|
|
|
|
@pyqtSlot(str, str)
|
2012-07-05 01:10:01 +02:00
|
|
|
def clear_error_exact(self, vmname, message):
|
2013-04-13 02:54:24 +02:00
|
|
|
vm = self.parent().qvm_collection.get_vm_by_name(vmname)
|
2012-07-05 01:10:01 +02:00
|
|
|
if vm:
|
2013-04-13 02:54:24 +02:00
|
|
|
self.parent().clear_error_exact(vm.qid, message)
|
2012-07-05 01:10:01 +02:00
|
|
|
else:
|
|
|
|
# ignore VM-not-found error
|
|
|
|
pass
|
|
|
|
|
2013-04-13 02:54:24 +02:00
|
|
|
@pyqtSlot(str)
|
2012-07-05 01:10:01 +02:00
|
|
|
def clear_error(self, vmname):
|
2013-04-13 02:54:24 +02:00
|
|
|
vm = self.parent().qvm_collection.get_vm_by_name(vmname)
|
2012-07-05 01:10:01 +02:00
|
|
|
if vm:
|
2013-04-13 02:54:24 +02:00
|
|
|
self.parent().clear_error(vm.qid)
|
2012-07-05 01:10:01 +02:00
|
|
|
else:
|
|
|
|
# ignore VM-not-found error
|
|
|
|
pass
|
|
|
|
|
2013-04-13 02:54:24 +02:00
|
|
|
@pyqtSlot()
|
2012-07-24 23:46:03 +02:00
|
|
|
def show_manager(self):
|
|
|
|
bring_manager_to_front()
|
|
|
|
|
2015-05-03 17:11:23 +02:00
|
|
|
|
2012-03-28 21:36:59 +02:00
|
|
|
def get_frame_size():
|
|
|
|
w = 0
|
|
|
|
h = 0
|
2015-05-03 17:11:23 +02:00
|
|
|
cmd = ['/usr/bin/xprop', '-name', 'Qubes VM Manager', '|', 'grep',
|
|
|
|
'_NET_FRAME_EXTENTS']
|
|
|
|
xprop = subprocess.Popen(cmd, stdout=subprocess.PIPE)
|
2012-03-28 21:36:59 +02:00
|
|
|
for l in xprop.stdout:
|
|
|
|
line = l.split('=')
|
|
|
|
if len(line) == 2:
|
|
|
|
line = line[1].strip().split(',')
|
|
|
|
if len(line) == 4:
|
2015-05-03 17:11:23 +02:00
|
|
|
w = int(line[0].strip()) + int(line[1].strip())
|
|
|
|
h = int(line[2].strip()) + int(line[3].strip())
|
2014-02-23 00:44:08 +01:00
|
|
|
break
|
2015-05-03 17:11:23 +02:00
|
|
|
# in case of some weird window managers we have to assume sth...
|
|
|
|
if w <= 0:
|
2012-03-28 21:36:59 +02:00
|
|
|
w = 10
|
|
|
|
if h <= 0:
|
|
|
|
h = 30
|
2012-07-05 01:06:22 +02:00
|
|
|
|
2012-03-28 21:36:59 +02:00
|
|
|
manager_window.frame_width = w
|
|
|
|
manager_window.frame_height = h
|
|
|
|
return
|
|
|
|
|
2015-05-03 17:11:23 +02:00
|
|
|
|
2010-05-11 16:51:31 +02:00
|
|
|
def show_manager():
|
|
|
|
manager_window.show()
|
2012-05-19 07:42:57 +02:00
|
|
|
manager_window.set_table_geom_size()
|
2012-06-10 01:55:01 +02:00
|
|
|
manager_window.repaint()
|
2013-12-03 00:36:48 +01:00
|
|
|
manager_window.update_table(out_of_schedule=True)
|
2012-06-10 01:55:01 +02:00
|
|
|
app.processEvents()
|
2012-05-19 07:42:57 +02:00
|
|
|
|
2012-07-05 01:06:22 +02:00
|
|
|
get_frame_size()
|
2015-05-03 17:11:23 +02:00
|
|
|
# print manager_window.frame_width, " x ", manager_window.frame_height
|
2012-05-19 07:42:57 +02:00
|
|
|
manager_window.set_table_geom_size()
|
2010-05-11 16:51:31 +02:00
|
|
|
|
2012-07-05 01:06:22 +02:00
|
|
|
|
2015-05-03 17:11:23 +02:00
|
|
|
def bring_manager_to_front():
|
2011-03-10 18:09:52 +01:00
|
|
|
if manager_window.isVisible():
|
2015-05-03 17:11:23 +02:00
|
|
|
subprocess.check_call(
|
|
|
|
['/usr/bin/wmctrl', '-R', str(manager_window.windowTitle())])
|
2012-03-28 12:45:31 +02:00
|
|
|
|
2012-05-19 07:42:57 +02:00
|
|
|
else:
|
|
|
|
show_manager()
|
2012-03-28 12:45:31 +02:00
|
|
|
|
2015-05-03 17:11:23 +02:00
|
|
|
|
2012-07-24 23:46:03 +02:00
|
|
|
def show_running_manager_via_dbus():
|
|
|
|
global system_bus
|
|
|
|
if system_bus is None:
|
2013-04-13 02:54:24 +02:00
|
|
|
system_bus = QDBusConnection.systemBus()
|
2012-07-24 23:46:03 +02:00
|
|
|
|
2013-04-13 02:54:24 +02:00
|
|
|
qubes_manager = QDBusInterface('org.qubesos.QubesManager',
|
2015-05-03 17:11:23 +02:00
|
|
|
'/org/qubesos/QubesManager',
|
|
|
|
'org.qubesos.QubesManager', system_bus)
|
2013-04-13 02:54:24 +02:00
|
|
|
qubes_manager.call('show_manager')
|
2010-05-11 16:51:31 +02:00
|
|
|
|
2015-05-03 17:11:23 +02:00
|
|
|
|
2010-05-11 16:51:31 +02:00
|
|
|
def exit_app():
|
|
|
|
notifier.stop()
|
|
|
|
app.exit()
|
|
|
|
|
2015-05-03 17:11:23 +02:00
|
|
|
|
2010-05-11 16:51:31 +02:00
|
|
|
# Bases on the original code by:
|
|
|
|
# Copyright (c) 2002-2007 Pascal Varet <p.varet@gmail.com>
|
|
|
|
|
2015-05-03 17:11:23 +02:00
|
|
|
def handle_exception(exc_type, exc_value, exc_traceback):
|
2010-05-11 16:51:31 +02:00
|
|
|
import os.path
|
|
|
|
import traceback
|
|
|
|
|
2015-05-03 17:11:23 +02:00
|
|
|
filename, line, dummy, dummy = traceback.extract_tb(exc_traceback).pop()
|
|
|
|
filename = os.path.basename(filename)
|
2015-11-09 23:19:44 +01:00
|
|
|
error = "%s: %s" % (exc_type.__name__, exc_value)
|
|
|
|
error = error.replace('QubesException: ', '')
|
2015-10-29 18:04:38 +01:00
|
|
|
message = (
|
2015-11-09 23:19:44 +01:00
|
|
|
"<b>%s</b>" % error +
|
2015-11-09 18:54:29 +01:00
|
|
|
"<br><br><i>This is most likely a bug in the Qubes Manager</i>"
|
2015-10-29 18:04:38 +01:00
|
|
|
)
|
|
|
|
is_gui_thread = threading.currentThread().getName() == "QtMainThread"
|
2012-03-14 14:00:49 +01:00
|
|
|
strace = ""
|
2015-05-03 17:11:23 +02:00
|
|
|
stacktrace = traceback.extract_tb(exc_traceback)
|
2012-03-14 14:00:49 +01:00
|
|
|
while len(stacktrace) > 0:
|
|
|
|
(filename, line, func, txt) = stacktrace.pop()
|
|
|
|
strace += "----\n"
|
2015-05-03 17:11:23 +02:00
|
|
|
strace += "line: %s\n" % txt
|
|
|
|
strace += "func: %s\n" % func
|
|
|
|
strace += "line no.: %d\n" % line
|
|
|
|
strace += "file: %s\n" % filename
|
2012-03-14 14:00:49 +01:00
|
|
|
|
2015-10-29 18:04:38 +01:00
|
|
|
if is_gui_thread:
|
|
|
|
msg_box = QMessageBox()
|
|
|
|
msg_box.setDetailedText(strace)
|
|
|
|
msg_box.setIcon(QMessageBox.Critical)
|
|
|
|
msg_box.setWindowTitle("Houston, we have a problem...")
|
|
|
|
msg_box.setText(message)
|
2012-03-14 14:00:49 +01:00
|
|
|
|
2015-10-29 18:04:38 +01:00
|
|
|
msg_box.exec_()
|
|
|
|
else:
|
2017-06-25 17:32:46 +02:00
|
|
|
print(message, file=sys.stderr)
|
2015-05-03 17:11:23 +02:00
|
|
|
|
2012-05-15 09:11:25 +02:00
|
|
|
def sighup_handler(signum, frame):
|
2013-02-15 00:49:52 +01:00
|
|
|
os.execl("/usr/bin/qubes-manager", "qubes-manager")
|
2010-05-11 16:51:31 +02:00
|
|
|
|
2015-05-03 17:11:23 +02:00
|
|
|
|
2010-05-11 16:51:31 +02:00
|
|
|
def main():
|
2012-05-15 09:11:25 +02:00
|
|
|
signal.signal(signal.SIGHUP, sighup_handler)
|
|
|
|
|
2015-07-23 07:31:48 +02:00
|
|
|
global system_bus
|
|
|
|
system_bus = QDBusConnection.systemBus()
|
|
|
|
# Avoid starting more than one instance of the app
|
|
|
|
if not system_bus.registerService('org.qubesos.QubesManager'):
|
|
|
|
show_running_manager_via_dbus()
|
|
|
|
return
|
|
|
|
|
2010-09-16 18:49:36 +02:00
|
|
|
global qubes_host
|
|
|
|
qubes_host = QubesHost()
|
|
|
|
|
2010-05-11 16:51:31 +02:00
|
|
|
global app
|
|
|
|
app = QApplication(sys.argv)
|
|
|
|
app.setOrganizationName("The Qubes Project")
|
|
|
|
app.setOrganizationDomain("http://qubes-os.org")
|
|
|
|
app.setApplicationName("Qubes VM Manager")
|
2014-07-09 18:21:56 +02:00
|
|
|
app.setWindowIcon(QIcon.fromTheme("qubes-manager"))
|
2014-04-30 15:03:09 +02:00
|
|
|
app.setAttribute(Qt.AA_DontShowIconsInMenus, False)
|
2010-05-11 16:51:31 +02:00
|
|
|
|
2017-01-22 04:43:13 +01:00
|
|
|
qt_translator = QTranslator()
|
|
|
|
locale = QLocale.system().name()
|
|
|
|
i18n_dir = os.path.join(
|
|
|
|
os.path.dirname(os.path.realpath(__file__)),
|
|
|
|
'i18n')
|
|
|
|
qt_translator.load("qubesmanager_{!s}.qm".format(locale), i18n_dir)
|
|
|
|
app.installTranslator(qt_translator)
|
|
|
|
|
2010-05-11 16:51:31 +02:00
|
|
|
sys.excepthook = handle_exception
|
|
|
|
|
2014-03-31 01:17:27 +02:00
|
|
|
global session_bus
|
|
|
|
session_bus = QDBusConnection.sessionBus()
|
|
|
|
|
2014-03-31 18:36:00 +02:00
|
|
|
qvm_collection = QubesVmCollection()
|
|
|
|
qvm_collection.lock_db_for_reading()
|
|
|
|
qvm_collection.load()
|
|
|
|
qvm_collection.unlock_db()
|
|
|
|
|
|
|
|
blk_manager = QubesBlockDevicesManager(qvm_collection)
|
|
|
|
|
2014-03-31 01:17:27 +02:00
|
|
|
global trayIcon
|
2014-07-09 18:21:56 +02:00
|
|
|
trayIcon = QubesTrayIcon(QIcon.fromTheme("qubes-manager"), blk_manager)
|
2014-03-31 01:17:27 +02:00
|
|
|
|
2010-05-11 16:51:31 +02:00
|
|
|
global manager_window
|
2014-03-31 18:36:00 +02:00
|
|
|
manager_window = VmManagerWindow(qvm_collection, blk_manager)
|
2010-05-11 16:51:31 +02:00
|
|
|
|
2013-10-18 03:33:56 +02:00
|
|
|
global wm
|
|
|
|
wm = WatchManager()
|
2010-05-11 16:51:31 +02:00
|
|
|
global notifier
|
2015-05-03 17:11:23 +02:00
|
|
|
notifier = ThreadedNotifier(wm, QubesManagerFileWatcher(
|
|
|
|
manager_window.mark_table_for_update))
|
2010-05-11 16:51:31 +02:00
|
|
|
notifier.start()
|
2015-05-03 17:11:23 +02:00
|
|
|
wm.add_watch(system_path["qubes_store_filename"],
|
|
|
|
EventsCodes.OP_FLAGS.get('IN_MODIFY'))
|
|
|
|
wm.add_watch(os.path.dirname(system_path["qubes_store_filename"]),
|
|
|
|
EventsCodes.OP_FLAGS.get('IN_MOVED_TO'))
|
2015-11-27 01:33:42 +01:00
|
|
|
if os.path.exists(qubes_clipboard_info_file):
|
|
|
|
wm.add_watch(qubes_clipboard_info_file,
|
|
|
|
EventsCodes.OP_FLAGS.get('IN_CLOSE_WRITE'))
|
2015-05-03 17:11:23 +02:00
|
|
|
wm.add_watch(os.path.dirname(qubes_clipboard_info_file),
|
|
|
|
EventsCodes.OP_FLAGS.get('IN_CREATE'))
|
2014-06-10 01:15:26 +02:00
|
|
|
wm.add_watch(os.path.dirname(table_widgets.qubes_dom0_updates_stat_file),
|
|
|
|
EventsCodes.OP_FLAGS.get('IN_CREATE'))
|
2010-05-11 16:51:31 +02:00
|
|
|
|
2013-04-13 02:54:24 +02:00
|
|
|
system_bus.registerObject(dbus_object_path, manager_window)
|
2012-07-05 01:10:01 +02:00
|
|
|
|
2015-10-29 18:04:38 +01:00
|
|
|
threading.currentThread().setName("QtMainThread")
|
2010-05-11 16:51:31 +02:00
|
|
|
trayIcon.show()
|
|
|
|
|
2012-07-19 23:20:21 +02:00
|
|
|
show_manager()
|
2010-05-11 16:51:31 +02:00
|
|
|
app.exec_()
|
2014-05-05 02:15:37 +02:00
|
|
|
|
2010-05-11 16:51:31 +02:00
|
|
|
trayIcon = None
|
2012-10-16 04:28:57 +02:00
|
|
|
|
2015-05-03 17:11:23 +02:00
|
|
|
|
2012-10-16 04:28:57 +02:00
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|