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
|
2012-05-06 20:55:52 +02:00
|
|
|
import fcntl
|
2012-05-11 12:50:45 +02:00
|
|
|
import errno
|
2010-05-11 16:51:31 +02:00
|
|
|
from PyQt4.QtCore import *
|
|
|
|
from PyQt4.QtGui import *
|
2014-05-15 23:49:02 +02:00
|
|
|
from PyQt4.QtDBus import QDBus,QDBusVariant, QDBusMessage
|
2013-04-13 02:54:24 +02:00
|
|
|
from PyQt4.QtDBus import QDBusConnection
|
|
|
|
from PyQt4.QtDBus import QDBusInterface,QDBusAbstractAdaptor
|
2010-05-11 16:51:31 +02:00
|
|
|
|
|
|
|
from qubes.qubes import QubesVmCollection
|
|
|
|
from qubes.qubes import QubesException
|
2013-03-16 21:07:53 +01:00
|
|
|
from qubes.qubes import system_path,vm_files
|
2010-05-11 16:51:31 +02:00
|
|
|
from qubes.qubes import QubesVmLabels
|
|
|
|
from qubes.qubes import dry_run
|
|
|
|
from qubes.qubes import QubesDaemonPidfile
|
2010-09-16 18:49:36 +02:00
|
|
|
from qubes.qubes import QubesHost
|
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
|
|
|
|
|
2014-02-23 01:32:50 +01:00
|
|
|
try:
|
|
|
|
from qubes.qubes import QubesHVm
|
|
|
|
except ImportError:
|
|
|
|
pass
|
2012-07-12 13:32:45 +02:00
|
|
|
from qubes import qubes
|
2011-10-31 21:46:35 +01:00
|
|
|
from qubes import qubesutils
|
2010-05-11 16:51:31 +02:00
|
|
|
|
2012-01-24 16:49:14 +01:00
|
|
|
import qubesmanager.resources_rc
|
2010-05-11 16:51:31 +02:00
|
|
|
import ui_newappvmdlg
|
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
|
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 *
|
2010-05-11 16:51:31 +02:00
|
|
|
|
|
|
|
from pyinotify import WatchManager, Notifier, ThreadedNotifier, EventsCodes, ProcessEvent
|
|
|
|
|
|
|
|
import subprocess
|
|
|
|
import time
|
2011-05-12 19:08:15 +02:00
|
|
|
from datetime import datetime,timedelta
|
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
|
|
|
|
2011-10-31 21:47:51 +01:00
|
|
|
update_suggestion_interval = 14 # 14 days
|
|
|
|
|
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
|
|
|
|
|
2013-03-12 15:56:40 +01:00
|
|
|
class QubesManagerFileWatcher(ProcessEvent):
|
2010-05-11 16:51:31 +02:00
|
|
|
def __init__ (self, update_func):
|
|
|
|
self.update_func = update_func
|
2011-03-07 16:48:53 +01:00
|
|
|
|
2011-03-14 22:17:28 +01: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()
|
|
|
|
|
2013-12-02 04:03:05 +01:00
|
|
|
def process_IN_MOVED_TO (self, event):
|
|
|
|
if event.pathname == system_path["qubes_store_filename"]:
|
|
|
|
self.update_func()
|
|
|
|
|
2013-03-12 15:56:40 +01:00
|
|
|
def process_IN_CLOSE_WRITE (self, event):
|
|
|
|
if event.path == qubes_clipboard_info_file:
|
|
|
|
src_info_file = open (qubes_clipboard_info_file, 'r')
|
|
|
|
src_vmname = src_info_file.readline().strip('\n')
|
|
|
|
if src_vmname == "":
|
2014-03-11 02:10:11 +01:00
|
|
|
trayIcon.showMessage(
|
|
|
|
"Qubes Clipboard has been copied to the VM and wiped.<i/>\n"
|
2013-03-12 15:56:40 +01:00
|
|
|
"<small>Trigger a paste operation (e.g. Ctrl-v) to insert it into an application.</small>",
|
2014-03-11 02:10:11 +01:00
|
|
|
msecs=3000)
|
2013-03-12 15:56:40 +01:00
|
|
|
else:
|
2014-03-11 02:10:11 +01:00
|
|
|
trayIcon.showMessage(
|
|
|
|
"Qubes Clipboard fetched from VM: <b>'{0}'</b>\n"
|
|
|
|
"<small>Press Ctrl-Shift-v to copy this clipboard onto dest VM's clipboard.</small>".format(src_vmname),
|
|
|
|
msecs=3000)
|
2013-03-12 15:56:40 +01:00
|
|
|
src_info_file.close()
|
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)
|
|
|
|
wm.add_watch(qubes_clipboard_info_file, EventsCodes.OP_FLAGS.get('IN_CLOSE_WRITE'))
|
2014-06-10 01:15:26 +02:00
|
|
|
elif event.name == os.path.basename(table_widgets\
|
|
|
|
.qubes_dom0_updates_stat_file):
|
|
|
|
trayIcon.showMessage("Qubes dom0 updates available.", msecs=0)
|
2010-05-11 16:51:31 +02:00
|
|
|
|
2012-03-21 13:27:10 +01:00
|
|
|
|
2014-03-10 04:28:30 +01:00
|
|
|
|
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
|
2014-03-31 03:44:01 +02:00
|
|
|
prefmem_graph_hue = 70
|
2012-02-13 18:19:54 +01:00
|
|
|
|
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
|
2010-05-11 16:51:31 +02:00
|
|
|
table.setRowHeight (row_no, VmManagerWindow.row_height)
|
|
|
|
|
2012-04-23 10:58:26 +02:00
|
|
|
self.type_widget = VmTypeWidget(vm)
|
|
|
|
table.setCellWidget(row_no, VmManagerWindow.columns_indices['Type'], self.type_widget)
|
|
|
|
table.setItem(row_no, VmManagerWindow.columns_indices['Type'], self.type_widget.tableItem)
|
|
|
|
|
2012-03-21 13:27:10 +01:00
|
|
|
self.label_widget = VmLabelWidget(vm)
|
|
|
|
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)
|
|
|
|
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)
|
2012-07-05 01:06:22 +02:00
|
|
|
table.setCellWidget(row_no, VmManagerWindow.columns_indices['State'], self.info_widget)
|
2012-03-21 13:27:10 +01:00
|
|
|
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)
|
2012-03-21 13:27:10 +01: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)
|
2012-03-21 13:27:10 +01:00
|
|
|
table.setItem(row_no, VmManagerWindow.columns_indices['NetVM'], self.netvm_widget)
|
2012-01-22 18:45:41 +01:00
|
|
|
|
2012-07-05 01:06:22 +02:00
|
|
|
self.cpu_usage_widget = VmUsageBarWidget(0, 100, "%v %",
|
2012-04-20 16:56:51 +02:00
|
|
|
lambda vm, val: val if vm.last_running else 0, vm, 0, self.cpu_graph_hue)
|
2012-03-21 13:27:10 +01:00
|
|
|
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)
|
2011-03-07 16:48:19 +01:00
|
|
|
|
2012-04-20 16:56:51 +02:00
|
|
|
self.load_widget = ChartWidget(vm, lambda vm, val: val if vm.last_running else 0, self.cpu_graph_hue, 0 )
|
2012-03-21 13:27:10 +01:00
|
|
|
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)
|
2012-01-22 18:45:41 +01:00
|
|
|
|
2012-07-05 01:06:22 +02:00
|
|
|
self.mem_usage_widget = VmUsageBarWidget(0, qubes_host.memory_total/1024, "%v MB",
|
2013-02-19 03:32:03 +01:00
|
|
|
lambda vm, val: vm.get_mem()/1024, vm, 0, self.mem_graph_hue)
|
2012-03-21 13:27:10 +01:00
|
|
|
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)
|
2012-02-06 20:22:11 +01:00
|
|
|
|
2013-02-19 03:32:03 +01:00
|
|
|
self.mem_widget = ChartWidget(vm, lambda vm, val: vm.get_mem()*100/qubes_host.memory_total, self.mem_graph_hue, 0)
|
2012-03-21 13:27:10 +01:00
|
|
|
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
|
|
|
|
2014-03-31 03:44:01 +02:00
|
|
|
self.prefmem_usage_widget = VmUsageBarWidget(0, qubes_host.memory_total/1024, "%v MB",
|
|
|
|
lambda vm, val: vm.last_prefmem/1024, vm, 0,
|
|
|
|
self.prefmem_graph_hue)
|
|
|
|
table.setCellWidget(row_no,
|
|
|
|
VmManagerWindow.columns_indices['Req MEM'],
|
|
|
|
self.prefmem_usage_widget)
|
|
|
|
table.setItem(row_no,
|
|
|
|
VmManagerWindow.columns_indices['Req MEM'],
|
|
|
|
self.prefmem_usage_widget.tableItem)
|
|
|
|
|
|
|
|
self.prefmem_widget = \
|
|
|
|
ChartWidget(vm,
|
|
|
|
lambda vm, val: vm .last_prefmem*100/qubes_host\
|
|
|
|
.memory_total, self.prefmem_graph_hue, 0)
|
|
|
|
table.setCellWidget(row_no,
|
|
|
|
VmManagerWindow.columns_indices['Req MEM Graph'],
|
|
|
|
self.prefmem_widget)
|
|
|
|
table.setItem(row_no,
|
|
|
|
VmManagerWindow.columns_indices['Req MEM Graph'],
|
|
|
|
self.prefmem_widget.tableItem)
|
|
|
|
|
|
|
|
|
2012-04-27 17:04:35 +02:00
|
|
|
self.size_widget = VmSizeOnDiskItem(vm)
|
|
|
|
table.setItem(row_no, VmManagerWindow.columns_indices['Size'], self.size_widget)
|
|
|
|
|
2013-03-05 10:40:04 +01:00
|
|
|
self.internal_widget = VmInternalItem(vm)
|
|
|
|
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)
|
|
|
|
table.setItem(row_no, VmManagerWindow.columns_indices['IP'], self.ip_widget)
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
2012-11-06 06:50:14 +01:00
|
|
|
def update(self, blk_visible = None, cpu_load = None, update_size_on_disk = False, rec_visible = None):
|
|
|
|
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)
|
2014-03-31 03:44:01 +02:00
|
|
|
self.prefmem_widget.update_load(self.vm, None)
|
|
|
|
self.prefmem_usage_widget.update_load(self.vm, None)
|
2012-04-27 17:04:35 +02:00
|
|
|
if update_size_on_disk == True:
|
|
|
|
self.size_widget.update()
|
2010-05-11 16:51:31 +02:00
|
|
|
|
2012-05-11 22:52:27 +02:00
|
|
|
|
|
|
|
|
2010-05-11 16:51:31 +02:00
|
|
|
|
2012-05-13 16:56:27 +02:00
|
|
|
vm_shutdown_timeout = 20000 # in msec
|
2010-05-11 16:51:31 +02:00
|
|
|
|
|
|
|
class VmShutdownMonitor(QObject):
|
2012-05-13 16:56:27 +02:00
|
|
|
def __init__(self, vm, shutdown_time = vm_shutdown_timeout):
|
2010-05-11 16:51:31 +02:00
|
|
|
self.vm = vm
|
2012-05-13 16:56:27 +02:00
|
|
|
self.shutdown_time = shutdown_time
|
2010-05-11 16:51:31 +02:00
|
|
|
|
|
|
|
def check_if_vm_has_shutdown(self):
|
|
|
|
vm = self.vm
|
2011-09-30 20:39:39 +02:00
|
|
|
vm_start_time = vm.get_start_time()
|
2013-02-23 16:18:43 +01:00
|
|
|
if not vm.is_running() or (vm_start_time and vm_start_time >= datetime.now() - timedelta(0,self.shutdown_time/1000)):
|
2010-05-11 16:51:31 +02:00
|
|
|
return
|
|
|
|
|
2011-03-07 16:48:53 +01:00
|
|
|
reply = QMessageBox.question(None, "VM Shutdown",
|
2012-05-13 16:56:27 +02:00
|
|
|
"The VM <b>'{0}'</b> hasn't shutdown within the last {1} seconds, do you want to kill it?<br>".format(vm.name, self.shutdown_time/1000),
|
|
|
|
"Kill it!", "Wait another {0} seconds...".format(self.shutdown_time/1000))
|
2010-05-11 16:51:31 +02:00
|
|
|
if reply == 0:
|
|
|
|
vm.force_shutdown()
|
|
|
|
else:
|
2012-05-13 16:56:27 +02:00
|
|
|
QTimer.singleShot (self.shutdown_time, self.check_if_vm_has_shutdown)
|
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
|
2010-05-11 16:51:31 +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
|
2012-08-04 04:13:16 +02:00
|
|
|
# suppress saving settings while initializing widgets
|
|
|
|
settings_loaded = False
|
2012-04-23 10:58:26 +02:00
|
|
|
columns_indices = { "Type": 0,
|
|
|
|
"Label": 1,
|
|
|
|
"Name": 2,
|
|
|
|
"State": 3,
|
|
|
|
"Template": 4,
|
|
|
|
"NetVM": 5,
|
|
|
|
"CPU": 6,
|
|
|
|
"CPU Graph": 7,
|
|
|
|
"MEM": 8,
|
2012-04-27 17:04:35 +02:00
|
|
|
"MEM Graph": 9,
|
2014-03-31 03:44:01 +02:00
|
|
|
"Req MEM": 10,
|
|
|
|
"Req MEM Graph": 11,
|
|
|
|
"Size": 12,
|
|
|
|
"Internal": 13,
|
|
|
|
"IP": 14,
|
|
|
|
"Backups": 15,
|
|
|
|
"Last backup": 16,
|
2014-03-10 04:27:52 +01:00
|
|
|
}
|
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
|
2014-03-31 03:44:01 +02:00
|
|
|
self.meminfo_changed = {}
|
2014-03-31 18:36:00 +02:00
|
|
|
self.blk_manager = blk_manager
|
2014-03-31 01:17:27 +02:00
|
|
|
self.blk_manager.tray_message_func = trayIcon.showMessage
|
2012-04-13 01:08:36 +02:00
|
|
|
self.qubes_watch.setup_block_watch(self.blk_manager.block_devs_event)
|
2014-03-31 03:44:01 +02:00
|
|
|
self.qubes_watch.setup_meminfo_watch(self.meminfo_update_event)
|
2012-04-13 01:08:36 +02:00
|
|
|
self.blk_watch_thread = threading.Thread(target=self.qubes_watch.watch_loop)
|
|
|
|
self.blk_watch_thread.daemon = True
|
|
|
|
self.blk_watch_thread.start()
|
|
|
|
|
2010-05-11 16:51:31 +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
|
|
|
|
|
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
|
|
|
|
|
|
|
self.columns_actions = {}
|
|
|
|
self.columns_actions[ self.columns_indices["Type"] ] = self.action_vm_type
|
|
|
|
self.columns_actions[ self.columns_indices["Label"] ] = self.action_label
|
|
|
|
self.columns_actions[ self.columns_indices["Name"] ] = self.action_name
|
|
|
|
self.columns_actions[ self.columns_indices["State"] ] = self.action_state
|
|
|
|
self.columns_actions[ self.columns_indices["Template"] ] = self.action_template
|
|
|
|
self.columns_actions[ self.columns_indices["NetVM"] ] = self.action_netvm
|
|
|
|
self.columns_actions[ self.columns_indices["CPU"] ] = self.action_cpu
|
|
|
|
self.columns_actions[ self.columns_indices["CPU Graph"] ] = self.action_cpu_graph
|
|
|
|
self.columns_actions[ self.columns_indices["MEM"] ] = self.action_mem
|
|
|
|
self.columns_actions[ self.columns_indices["MEM Graph"] ] = self.action_mem_graph
|
2014-03-31 03:44:01 +02:00
|
|
|
self.columns_actions[ self.columns_indices["Req MEM"] ] = self\
|
|
|
|
.action_prefmem
|
|
|
|
self.columns_actions[ self.columns_indices["Req MEM Graph"] ] = self\
|
|
|
|
.action_prefmem_graph
|
2012-04-27 17:04:35 +02:00
|
|
|
self.columns_actions[ self.columns_indices["Size"] ] = self.action_size_on_disk
|
2013-03-05 10:40:04 +01:00
|
|
|
self.columns_actions[ self.columns_indices["Internal"] ] = self.action_internal
|
2014-03-10 04:27:52 +01:00
|
|
|
self.columns_actions[ self.columns_indices["IP"] ] = self\
|
|
|
|
.action_ip
|
|
|
|
self.columns_actions[ self.columns_indices["Backups"] ] = self\
|
|
|
|
.action_backups
|
2014-03-10 04:28:30 +01:00
|
|
|
self.columns_actions[ self.columns_indices["Last backup"] ] = self\
|
|
|
|
.action_last_backup
|
2012-07-05 01:06:22 +02:00
|
|
|
|
2014-02-23 00:44:08 +01:00
|
|
|
self.visible_columns_count = len(self.columns_indices)
|
2012-01-24 20:59:44 +01:00
|
|
|
self.table.setColumnHidden( self.columns_indices["NetVM"], True)
|
2012-04-26 16:32:40 +02:00
|
|
|
self.action_netvm.setChecked(False)
|
2012-01-24 20:59:44 +01:00
|
|
|
self.table.setColumnHidden( self.columns_indices["CPU Graph"], True)
|
2012-04-26 16:32:40 +02:00
|
|
|
self.action_cpu_graph.setChecked(False)
|
2012-01-24 20:59:44 +01:00
|
|
|
self.table.setColumnHidden( self.columns_indices["MEM Graph"], True)
|
2012-04-26 16:32:40 +02:00
|
|
|
self.action_mem_graph.setChecked(False)
|
2014-03-31 03:44:01 +02:00
|
|
|
self.action_prefmem.setChecked(False)
|
|
|
|
self.action_prefmem_graph.setChecked(False)
|
2012-04-27 17:04:35 +02:00
|
|
|
self.table.setColumnHidden( self.columns_indices["Size"], True)
|
|
|
|
self.action_size_on_disk.setChecked(False)
|
2013-03-05 11:10:25 +01:00
|
|
|
self.table.setColumnHidden( self.columns_indices["Internal"], True)
|
|
|
|
self.action_internal.setChecked(False)
|
2014-03-10 04:27:52 +01:00
|
|
|
self.table.setColumnHidden( self.columns_indices["IP"], True)
|
|
|
|
self.action_ip.setChecked(False)
|
|
|
|
self.table.setColumnHidden( self.columns_indices["Backups"], True)
|
|
|
|
self.action_backups.setChecked(False)
|
2014-03-10 04:28:30 +01:00
|
|
|
self.table.setColumnHidden( self.columns_indices["Last backup"], True)
|
|
|
|
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
|
|
|
|
2012-08-04 04:12:39 +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)
|
|
|
|
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()
|
|
|
|
|
2012-03-06 20:05:35 +01:00
|
|
|
self.connect(self.table.horizontalHeader(), SIGNAL("sortIndicatorChanged(int, Qt::SortOrder)"), self.sortIndicatorChanged)
|
2012-02-14 19:00:50 +01:00
|
|
|
self.connect(self.table, SIGNAL("customContextMenuRequested(const QPoint&)"), self.open_context_menu)
|
2013-02-15 16:06:54 +01:00
|
|
|
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))
|
2012-02-14 19:00:50 +01:00
|
|
|
self.connect(self.blk_menu, SIGNAL("triggered(QAction *)"), self.attach_dettach_device_triggered)
|
2012-04-23 19:01:22 +02:00
|
|
|
self.connect(self.logs_menu, SIGNAL("triggered(QAction *)"), self.show_log)
|
2012-02-08 19:02:35 +01:00
|
|
|
|
2012-02-05 18:41:41 +01:00
|
|
|
self.table.setContentsMargins(0,0,0,0)
|
|
|
|
self.centralwidget.layout().setContentsMargins(0,0,0,0)
|
|
|
|
self.layout().setContentsMargins(0,0,0,0)
|
2012-07-05 01:06:22 +02:00
|
|
|
|
2012-03-06 18:45:47 +01:00
|
|
|
self.connect(self.action_menubar, SIGNAL("toggled(bool)"), self.showhide_menubar)
|
|
|
|
self.connect(self.action_toolbar, SIGNAL("toggled(bool)"), self.showhide_toolbar)
|
|
|
|
|
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()
|
2011-04-02 15:48:48 +02:00
|
|
|
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]
|
|
|
|
visible = self.manager_settings.value(col, defaultValue=not self.table.isColumnHidden(col_no)).toBool()
|
|
|
|
self.columns_actions[col_no].setChecked(visible)
|
|
|
|
self.manager_settings.endGroup()
|
|
|
|
self.show_inactive_vms = self.manager_settings.value("view/show_inactive_vms", defaultValue=False).toBool()
|
2013-03-05 11:21:16 +01:00
|
|
|
self.show_internal_vms = self.manager_settings.value("view/show_internal_vms", defaultValue=False).toBool()
|
2012-08-04 04:13:16 +02:00
|
|
|
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():
|
|
|
|
self.action_menubar.setChecked(False)
|
|
|
|
if not self.manager_settings.value("view/toolbar_visible", defaultValue=True).toBool():
|
|
|
|
self.action_toolbar.setChecked(False)
|
|
|
|
x = self.manager_settings.value('position/x', defaultValue=-1).toInt()[0]
|
|
|
|
y = self.manager_settings.value('position/y', defaultValue=-1).toInt()[0]
|
|
|
|
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
|
|
|
|
2012-03-28 12:45:31 +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...
|
2012-07-05 01:06:22 +02:00
|
|
|
desktop_height -= self.row_height #UGLY! to somehow ommit taskbar...
|
|
|
|
|
2012-03-28 12:45:31 +02:00
|
|
|
W = self.table.horizontalHeader().length() +\
|
|
|
|
self.table.verticalScrollBar().width() +\
|
|
|
|
2*self.table.frameWidth() +1
|
|
|
|
|
|
|
|
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():
|
2012-04-26 16:32:40 +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():
|
2012-04-26 16:32:40 +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
|
|
|
|
if W >= desktop_width:
|
|
|
|
available_space -= self.table.horizontalScrollBar().height()
|
|
|
|
H += self.table.horizontalScrollBar().height()
|
|
|
|
default_rows = int(available_space/self.row_height)
|
2012-02-05 18:41:41 +01:00
|
|
|
|
2012-05-29 17:05:34 +02:00
|
|
|
if self.show_inactive_vms:
|
|
|
|
n = self.table.rowCount()
|
|
|
|
else:
|
|
|
|
n = self.running_vms_count
|
2013-03-05 13:12:31 +01:00
|
|
|
if self.show_internal_vms:
|
|
|
|
if self.show_inactive_vms:
|
|
|
|
n = self.table.rowCount()
|
|
|
|
else:
|
|
|
|
n = self.running_vms_count
|
|
|
|
elif self.show_inactive_vms:
|
|
|
|
n = self.table.rowCount() - self.internal_vms_count
|
|
|
|
else:
|
|
|
|
n = self.running_vms_count
|
2012-07-05 01:06:22 +02:00
|
|
|
|
2012-03-28 12:45:31 +02:00
|
|
|
if n > default_rows:
|
|
|
|
H += default_rows*self.row_height
|
|
|
|
self.table.verticalScrollBar().show()
|
|
|
|
else:
|
|
|
|
H += n*self.row_height
|
|
|
|
self.table.verticalScrollBar().hide()
|
|
|
|
W -= self.table.verticalScrollBar().width()
|
2012-03-26 11:48:49 +02:00
|
|
|
|
2012-03-28 12:45:31 +02:00
|
|
|
W = min(desktop_width, W)
|
2012-07-05 01:06:22 +02:00
|
|
|
|
2012-03-28 12:45:31 +02:00
|
|
|
self.centralwidget.setFixedHeight(H)
|
|
|
|
|
|
|
|
H += mainwindow_to_add
|
|
|
|
|
|
|
|
self.setMaximumHeight(H)
|
|
|
|
self.setMinimumHeight(H)
|
|
|
|
|
|
|
|
self.table.setFixedWidth(W)
|
|
|
|
self.centralwidget.setFixedWidth(W)
|
|
|
|
# don't change the following two lines to setFixedWidth!
|
|
|
|
self.setMaximumWidth(W)
|
|
|
|
self.setMinimumWidth(W)
|
|
|
|
|
|
|
|
|
|
|
|
def moveEvent(self, event):
|
|
|
|
super(VmManagerWindow, self).moveEvent(event)
|
|
|
|
screen_number = app.desktop().screenNumber(self)
|
|
|
|
if self.screen_number != screen_number:
|
|
|
|
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
|
|
|
|
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()
|
2012-04-23 19:55:16 +02:00
|
|
|
vm.last_running = vm.last_power_state in ["Running", "Transient"]
|
2014-03-31 03:44:01 +02:00
|
|
|
vm.last_prefmem = vm.get_prefmem()
|
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)
|
|
|
|
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:
|
2013-03-05 10:40:04 +01:00
|
|
|
#if vm.internal:
|
|
|
|
# continue
|
2012-02-14 19:00:50 +01:00
|
|
|
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():
|
|
|
|
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
|
|
|
|
2013-03-05 13:12:31 +01:00
|
|
|
self.showhide_vms(True, True)
|
2012-06-19 00:17:22 +02:00
|
|
|
self.set_table_geom_size()
|
2013-03-05 13:12:31 +01:00
|
|
|
if (not self.show_inactive_vms) or (not self.show_internal_vms):
|
|
|
|
self.showhide_vms(self.show_inactive_vms, self.show_internal_vms)
|
2012-05-29 17:05:34 +02:00
|
|
|
self.set_table_geom_size()
|
|
|
|
|
2013-03-05 13:12:31 +01:00
|
|
|
def showhide_vms(self, show_inactive, show_internal):
|
|
|
|
if show_inactive and show_internal:
|
2012-05-29 17:05:34 +02:00
|
|
|
row_no = 0
|
|
|
|
while row_no < self.table.rowCount():
|
|
|
|
self.table.setRowHidden(row_no, False)
|
|
|
|
row_no += 1
|
|
|
|
else:
|
|
|
|
row_no = 0
|
|
|
|
while row_no < self.table.rowCount():
|
|
|
|
widget = self.table.cellWidget(row_no, self.columns_indices["State"])
|
|
|
|
running = widget.vm.last_running
|
2013-03-05 11:29:49 +01:00
|
|
|
internal = widget.vm.internal
|
2013-03-05 13:12:31 +01:00
|
|
|
if not (show_inactive or running) or not (show_internal or not internal):
|
2013-03-05 11:29:49 +01:00
|
|
|
self.table.setRowHidden(row_no, True)
|
2013-04-13 04:13:34 +02:00
|
|
|
else:
|
|
|
|
self.table.setRowHidden(row_no, False)
|
2013-03-05 11:29:49 +01:00
|
|
|
row_no += 1
|
|
|
|
|
2014-03-31 03:44:01 +02:00
|
|
|
def meminfo_update_event(self, domain_id):
|
|
|
|
self.meminfo_changed[int(domain_id)] = True
|
|
|
|
|
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 \
|
|
|
|
self.vm_errors.get(vm.qid, "")\
|
|
|
|
.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
|
2012-04-23 19:55:16 +02:00
|
|
|
vm.last_running = (state in ["Running", "Transient"])
|
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
|
|
|
|
if state == "Running" and not vm.qubes_manager_state[QMVmState.AudioRecAvailable]:
|
|
|
|
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)
|
2014-03-31 03:44:01 +02:00
|
|
|
if self.meminfo_changed.get(vm.xid, True):
|
|
|
|
vm.last_prefmem = vm.get_prefmem()
|
|
|
|
self.meminfo_changed[vm.xid] = False
|
2012-03-28 12:45:31 +02:00
|
|
|
|
|
|
|
if self.screen_changed == True:
|
|
|
|
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()
|
2012-02-08 18:21:15 +01:00
|
|
|
update_devs=True
|
2010-05-11 16:51:31 +02:00
|
|
|
|
2012-05-29 17:05:34 +02:00
|
|
|
if (not self.show_inactive_vms) and some_vms_have_changed_power_state:
|
2013-03-05 13:12:31 +01:00
|
|
|
self.showhide_vms(True, True)
|
|
|
|
self.showhide_vms(False, self.show_internal_vms)
|
2012-05-29 17:05:34 +02:00
|
|
|
self.set_table_geom_size()
|
2012-03-28 12:45:31 +02:00
|
|
|
|
2012-08-04 04:12:39 +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
|
|
|
|
if update_devs == True:
|
|
|
|
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:
|
|
|
|
rows_with_blk.append( self.blk_manager.attached_devs[d]['attached_to']['vm'])
|
2012-04-13 01:08:36 +02:00
|
|
|
self.blk_manager.blk_lock.release()
|
2012-02-14 19:00:50 +01:00
|
|
|
|
2012-05-30 13:54:19 +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) = \
|
|
|
|
qubes_host.measure_cpu_usage(self.last_measure_results,
|
|
|
|
self.last_measure_time)
|
|
|
|
|
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:
|
|
|
|
cur_cpu_load = self.last_measure_results[vm_row.vm.xid]['cpu_usage']
|
|
|
|
else:
|
|
|
|
cur_cpu_load = 0
|
2012-02-14 19:00:50 +01:00
|
|
|
|
2012-07-05 01:06:22 +02:00
|
|
|
if rows_with_blk != None:
|
2012-02-14 19:00:50 +01:00
|
|
|
if vm_row.vm.name in rows_with_blk:
|
|
|
|
blk_visible = True
|
|
|
|
else:
|
|
|
|
blk_visible = False
|
2012-07-05 01:06:22 +02:00
|
|
|
|
2012-11-06 06:50:14 +01: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():
|
2012-02-14 19:00:50 +01:00
|
|
|
if rows_with_blk != None:
|
|
|
|
if vm_row.vm.name in rows_with_blk:
|
|
|
|
blk_visible = True
|
|
|
|
else:
|
|
|
|
blk_visible = False
|
|
|
|
|
2012-11-06 06:50:14 +01: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
|
|
|
|
2013-03-05 10:40:04 +01:00
|
|
|
if self.sort_by_column in ["CPU", "CPU Graph", "MEM", "MEM Graph", "State", "Size", "Internal" ]:
|
2012-08-04 04:12:39 +02:00
|
|
|
# "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
|
|
|
|
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()
|
2012-02-14 19:00:50 +01:00
|
|
|
if msg != None and len(msg) > 0:
|
2014-05-12 15:33:18 +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
|
|
|
|
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
|
|
|
|
2013-04-13 02:54:24 +02:00
|
|
|
if not session_bus.connect(QString(), # service
|
|
|
|
QString(), # path
|
|
|
|
QString("org.QubesOS.Audio"), # interface
|
|
|
|
QString("RecAllowedChanged"), # name
|
|
|
|
self.recAllowedChanged): # slot
|
|
|
|
print session_bus.lastError().message()
|
2012-03-27 10:36:58 +02:00
|
|
|
|
2012-03-06 20:05:35 +01:00
|
|
|
def sortIndicatorChanged(self, column, order):
|
2012-08-04 04:12:39 +02:00
|
|
|
self.sort_by_column = [name for name in self.columns_indices.keys() if self.columns_indices[name] == column][0]
|
|
|
|
self.sort_order = order
|
2012-08-04 04:13:16 +02:00
|
|
|
if self.settings_loaded:
|
|
|
|
self.manager_settings.setValue('view/sort_column', self.sort_by_column)
|
|
|
|
self.manager_settings.setValue('view/sort_order', self.sort_order)
|
|
|
|
self.manager_settings.sync()
|
2012-07-05 01:06:22 +02:00
|
|
|
|
2010-05-11 16:51:31 +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()
|
|
|
|
|
2012-02-08 18:21:15 +01:00
|
|
|
if vm != None:
|
|
|
|
# Update available actions:
|
2012-06-19 00:24:13 +02:00
|
|
|
self.action_settings.setEnabled(vm.qid != 0)
|
2012-04-20 16:56:51 +02:00
|
|
|
self.action_removevm.setEnabled(not vm.installed_by_rpm and not (vm.last_running))
|
2012-08-07 02:01:15 +02:00
|
|
|
self.action_clonevm.setEnabled(not (vm.last_running) and not vm.is_netvm())
|
2012-04-20 16:56:51 +02:00
|
|
|
self.action_resumevm.setEnabled(not vm.last_running)
|
2014-02-23 01:32:50 +01:00
|
|
|
try:
|
|
|
|
self.action_startvm_tools_install.setVisible(isinstance(vm,
|
|
|
|
QubesHVm))
|
|
|
|
except NameError:
|
|
|
|
# ignore non existing QubesHVm
|
|
|
|
pass
|
|
|
|
self.action_startvm_tools_install.setEnabled(not vm.last_running)
|
2012-04-20 16:56:51 +02:00
|
|
|
self.action_pausevm.setEnabled(vm.last_running and vm.qid != 0)
|
|
|
|
self.action_shutdownvm.setEnabled(vm.last_running and vm.qid != 0)
|
2013-02-19 03:32:49 +01:00
|
|
|
self.action_killvm.setEnabled((vm.last_running or vm.last_power_state == "Paused") and vm.qid != 0)
|
2012-02-08 18:21:15 +01:00
|
|
|
self.action_appmenus.setEnabled(not vm.is_netvm())
|
|
|
|
self.action_editfwrules.setEnabled(vm.is_networked() and not (vm.is_netvm() and not vm.is_proxyvm()))
|
|
|
|
self.action_updatevm.setEnabled(vm.is_updateable() or vm.qid == 0)
|
2013-04-13 04:10:13 +02:00
|
|
|
self.action_toggle_audio_input.setEnabled(vm.qubes_manager_state[QMVmState.AudioRecAvailable])
|
2013-02-19 03:33:01 +01:00
|
|
|
self.action_run_command_in_vm.setEnabled(not vm.last_power_state == "Paused" and vm.qid != 0)
|
2012-04-24 17:48:10 +02:00
|
|
|
self.action_set_keyboard_layout.setEnabled(vm.qid != 0 and vm.last_running)
|
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)
|
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
|
|
|
|
2010-05-11 16:51:31 +02:00
|
|
|
|
2011-03-07 16:48:19 +01:00
|
|
|
|
2010-05-11 16:51:31 +02:00
|
|
|
def closeEvent (self, event):
|
2011-04-10 22:44:38 +02:00
|
|
|
if event.spontaneous(): # There is something borked in Qt, as the logic here is inverted on X11
|
|
|
|
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
|
|
|
|
2012-07-05 01:06:22 +02:00
|
|
|
|
2010-05-11 16:51:31 +02:00
|
|
|
def get_selected_vm(self):
|
2012-02-07 12:48:53 +01: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"])
|
|
|
|
# here is possible race with update_table timer so check if really got the item
|
|
|
|
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:
|
2011-03-07 16:48:53 +01:00
|
|
|
QMessageBox.warning (None, "Warning!",
|
2010-05-11 16:51:31 +02:00
|
|
|
"This Template VM cannot be removed, because there is at 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 this template.</small>")
|
|
|
|
|
|
|
|
return
|
|
|
|
|
2011-03-07 16:48:53 +01:00
|
|
|
reply = QMessageBox.question(None, "VM Removal Confirmation",
|
2010-05-11 16:51:31 +02:00
|
|
|
"Are you sure you want to remove the VM <b>'{0}'</b>?<br>"
|
|
|
|
"<small>All data on this VM's private storage will be lost!</small>".format(vm.name),
|
|
|
|
QMessageBox.Yes | QMessageBox.Cancel)
|
|
|
|
|
|
|
|
|
|
|
|
if reply == QMessageBox.Yes:
|
|
|
|
|
|
|
|
thread_monitor = ThreadMonitor()
|
|
|
|
thread = threading.Thread (target=self.do_remove_vm, args=(vm, thread_monitor))
|
|
|
|
thread.daemon = True
|
|
|
|
thread.start()
|
|
|
|
|
|
|
|
progress = QProgressDialog ("Removing VM: <b>{0}</b>...".format(vm.name), "", 0, 0)
|
|
|
|
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()
|
|
|
|
time.sleep (0.1)
|
|
|
|
|
|
|
|
progress.hide()
|
|
|
|
|
|
|
|
if thread_monitor.success:
|
2012-07-05 00:49:10 +02:00
|
|
|
trayIcon.showMessage ("VM '{0}' has been removed.".format(vm.name), msecs=3000)
|
2010-05-11 16:51:31 +02:00
|
|
|
else:
|
2011-03-09 17:52:04 +01:00
|
|
|
QMessageBox.warning (None, "Error removing VM!", "ERROR: {0}".format(thread_monitor.error_msg))
|
2010-05-11 16:51:31 +02:00
|
|
|
|
|
|
|
def do_remove_vm (self, vm, thread_monitor):
|
|
|
|
try:
|
|
|
|
self.qvm_collection.lock_db_for_writing()
|
|
|
|
self.qvm_collection.load()
|
2012-07-05 01:11:39 +02:00
|
|
|
vm = self.qvm_collection[vm.qid]
|
2010-05-11 16:51:31 +02:00
|
|
|
|
|
|
|
#TODO: the following two conditions should really be checked by qvm_collection.pop() overload...
|
2012-03-02 00:16:12 +01:00
|
|
|
if vm.is_template() and self.qvm_collection.default_template_qid == vm.qid:
|
|
|
|
self.qvm_collection.default_template_qid = None
|
|
|
|
if vm.is_netvm() and self.qvm_collection.default_netvm_qid == vm.qid:
|
|
|
|
self.qvm_collection.default_netvm_qid = None
|
2010-05-11 16:51:31 +02:00
|
|
|
|
|
|
|
self.qvm_collection.pop(vm.qid)
|
|
|
|
self.qvm_collection.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:
|
|
|
|
thread_monitor.set_error_msg (str(ex))
|
|
|
|
finally:
|
|
|
|
self.qvm_collection.unlock_db()
|
|
|
|
|
|
|
|
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
|
|
|
|
|
2013-02-12 01:06:32 +01:00
|
|
|
(clone_name, ok) = QInputDialog.getText(self, 'Qubes clone VM',
|
|
|
|
'Enter name for VM <b>'+vm.name+'</b> clone:', text=name_format % name_number)
|
|
|
|
if not ok or clone_name == "":
|
2012-07-12 13:32:45 +02:00
|
|
|
return
|
|
|
|
|
|
|
|
thread_monitor = ThreadMonitor()
|
2013-02-12 01:06:32 +01: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()
|
|
|
|
|
|
|
|
progress = QProgressDialog ("Cloning VM <b>{0}</b> to <b>{1}</b>...".format(vm.name, clone_name), "", 0, 0)
|
|
|
|
progress.setCancelButton(None)
|
|
|
|
progress.setModal(True)
|
|
|
|
progress.show()
|
|
|
|
|
|
|
|
while not thread_monitor.is_finished():
|
|
|
|
app.processEvents()
|
|
|
|
time.sleep (0.2)
|
|
|
|
|
|
|
|
progress.hide()
|
|
|
|
|
|
|
|
if not thread_monitor.success:
|
|
|
|
QMessageBox.warning (None, "Error while cloning VM", "Exception while cloning:<br>{0}".format(thread_monitor.error_msg))
|
|
|
|
|
|
|
|
|
|
|
|
def do_clone_vm(self, vm, dst_name, thread_monitor):
|
2013-12-14 02:55:41 +01:00
|
|
|
dst_vm = None
|
2012-07-12 13:32:45 +02:00
|
|
|
try:
|
|
|
|
self.qvm_collection.lock_db_for_writing()
|
|
|
|
self.qvm_collection.load()
|
|
|
|
src_vm = self.qvm_collection[vm.qid]
|
|
|
|
|
2013-12-14 02:55:41 +01:00
|
|
|
dst_vm = self.qvm_collection.add_new_vm(src_vm.__class__.__name__,
|
2013-11-21 04:21:47 +01:00
|
|
|
name=dst_name, template=src_vm.template,
|
2013-12-14 02:55:41 +01:00
|
|
|
installed_by_rpm=False)
|
2012-07-12 13:32:45 +02:00
|
|
|
|
|
|
|
dst_vm.clone_attrs(src_vm)
|
|
|
|
dst_vm.clone_disk_files (src_vm=src_vm, verbose=False)
|
|
|
|
self.qvm_collection.save()
|
|
|
|
self.qvm_collection.unlock_db()
|
|
|
|
except Exception as ex:
|
|
|
|
if dst_vm:
|
|
|
|
self.qvm_collection.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
|
|
|
self.qvm_collection.unlock_db()
|
|
|
|
thread_monitor.set_error_msg(str(ex))
|
|
|
|
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()
|
|
|
|
assert not vm.is_running()
|
|
|
|
|
2011-03-27 17:41:03 +02:00
|
|
|
if vm.is_paused():
|
|
|
|
try:
|
2013-04-13 03:12:58 +02:00
|
|
|
vm.unpause()
|
2011-03-27 17:41:03 +02:00
|
|
|
except Exception as ex:
|
|
|
|
QMessageBox.warning (None, "Error unpausing VM!", "ERROR: {0}".format(ex))
|
|
|
|
return
|
|
|
|
|
2011-04-01 00:46:51 +02:00
|
|
|
thread_monitor = ThreadMonitor()
|
|
|
|
thread = threading.Thread (target=self.do_start_vm, args=(vm, thread_monitor))
|
|
|
|
thread.daemon = True
|
|
|
|
thread.start()
|
|
|
|
|
2012-07-05 00:49:10 +02:00
|
|
|
trayIcon.showMessage ("Starting '{0}'...".format(vm.name), msecs=3000)
|
2011-04-01 00:46:51 +02:00
|
|
|
|
|
|
|
while not thread_monitor.is_finished():
|
|
|
|
app.processEvents()
|
|
|
|
time.sleep (0.1)
|
|
|
|
|
|
|
|
if thread_monitor.success:
|
2012-07-05 00:49:10 +02:00
|
|
|
trayIcon.showMessage ("VM '{0}' has been started.".format(vm.name), msecs=3000)
|
2011-04-01 00:46:51 +02:00
|
|
|
else:
|
2012-07-05 00:49:10 +02:00
|
|
|
trayIcon.showMessage ("Error starting VM <b>'{0}'</b>: {1}".format(vm.name, thread_monitor.error_msg ), msecs=3000)
|
2012-07-05 01:08:10 +02:00
|
|
|
self.set_error(vm.qid, "Error starting VM: %s" % thread_monitor.error_msg)
|
2011-04-01 00:46:51 +02:00
|
|
|
|
|
|
|
def do_start_vm(self, vm, thread_monitor):
|
2011-03-02 14:42:11 +01:00
|
|
|
try:
|
|
|
|
vm.verify_files()
|
|
|
|
xid = 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()
|
|
|
|
|
|
|
|
thread_monitor = ThreadMonitor()
|
|
|
|
thread = threading.Thread (target=self.do_start_vm_tools_install,
|
|
|
|
args=(vm, thread_monitor))
|
|
|
|
thread.daemon = True
|
|
|
|
thread.start()
|
|
|
|
|
|
|
|
trayIcon.showMessage ("Starting '{0}'...".format(vm.name), msecs=3000)
|
|
|
|
|
|
|
|
while not thread_monitor.is_finished():
|
|
|
|
app.processEvents()
|
|
|
|
time.sleep (0.1)
|
|
|
|
|
|
|
|
if thread_monitor.success:
|
|
|
|
trayIcon.showMessage ("VM '{0}' has been started. Start Qubes "
|
|
|
|
"Tools installation from attached CD"
|
|
|
|
.format(vm.name), msecs=3000)
|
|
|
|
else:
|
|
|
|
trayIcon.showMessage ("Error starting VM <b>'{0}'</b>: {1}".format(vm.name, thread_monitor.error_msg ), msecs=3000)
|
|
|
|
self.set_error(vm.qid, "Error starting VM: %s" % thread_monitor.error_msg)
|
|
|
|
|
|
|
|
def do_start_vm_tools_install(self, vm, thread_monitor):
|
|
|
|
prev_drive = vm.drive
|
|
|
|
try:
|
|
|
|
vm.verify_files()
|
|
|
|
vm.drive = 'cdrom:dom0:/usr/lib/qubes/qubes-windows-tools.iso'
|
|
|
|
xid = vm.start()
|
|
|
|
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:
|
|
|
|
QMessageBox.warning (None, "Error pausing VM!", "ERROR: {0}".format(ex))
|
|
|
|
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)
|
|
|
|
|
2011-03-07 16:48:53 +01:00
|
|
|
reply = QMessageBox.question(None, "VM Shutdown Confirmation",
|
2010-05-11 16:51:31 +02:00
|
|
|
"Are you sure you want to power down the VM <b>'{0}'</b>?<br>"
|
|
|
|
"<small>This will shutdown all the running applications within this VM.</small>".format(vm.name),
|
|
|
|
QMessageBox.Yes | QMessageBox.Cancel)
|
|
|
|
|
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)
|
|
|
|
|
|
|
|
|
2012-05-13 16:56:27 +02:00
|
|
|
def shutdown_vm(self, vm, shutdown_time = vm_shutdown_timeout):
|
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:
|
|
|
|
QMessageBox.warning (None, "Error shutting down VM!", "ERROR: {0}".format(ex))
|
|
|
|
return
|
|
|
|
|
2012-07-05 00:49:10 +02:00
|
|
|
trayIcon.showMessage ("VM '{0}' is shutting down...".format(vm.name), msecs=3000)
|
2012-03-29 23:26:16 +02:00
|
|
|
|
2012-05-13 16:56:27 +02:00
|
|
|
self.shutdown_monitor[vm.qid] = VmShutdownMonitor (vm, shutdown_time)
|
|
|
|
QTimer.singleShot (shutdown_time, self.shutdown_monitor[vm.qid].check_if_vm_has_shutdown)
|
2010-05-11 16:51:31 +02:00
|
|
|
|
2012-03-23 09:12:30 +01:00
|
|
|
|
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
|
|
|
|
|
|
|
reply = QMessageBox.question(None, "VM Kill Confirmation",
|
|
|
|
"Are you sure you want to kill the VM <b>'{0}'</b>?<br>"
|
|
|
|
"<small>This will end <b>(not shutdown!)</b> all the running applications within this VM.</small>".format(vm.name),
|
|
|
|
QMessageBox.Yes | QMessageBox.Cancel, QMessageBox.Cancel)
|
|
|
|
|
|
|
|
app.processEvents()
|
|
|
|
|
|
|
|
if reply == QMessageBox.Yes:
|
|
|
|
try:
|
|
|
|
vm.force_shutdown()
|
|
|
|
except Exception as ex:
|
|
|
|
QMessageBox.critical (None, "Error while killing VM!", "<b>An exception ocurred while killing {0}.</b><br>ERROR: {1}".format(vm.name, ex))
|
|
|
|
return
|
|
|
|
|
2012-07-05 00:49:10 +02:00
|
|
|
trayIcon.showMessage ("VM '{0}' killed!".format(vm.name), msecs=3000)
|
2012-04-22 18:32:50 +02:00
|
|
|
|
|
|
|
|
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()
|
2012-02-13 13:50:30 +01: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-31 14:29:13 +01: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()
|
2012-02-13 13:50:30 +01: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] = (
|
|
|
|
session_bus.interface().isServiceRegistered('org.QubesOS.Audio.%s' % vm.name).value())
|
|
|
|
if vm.qubes_manager_state[QMVmState.AudioRecAvailable]:
|
|
|
|
vm.qubes_manager_state[QMVmState.AudioRecAllowed] = self.get_audio_rec_allowed(vm.name)
|
|
|
|
else:
|
|
|
|
vm.qubes_manager_state[QMVmState.AudioRecAllowed] = False
|
|
|
|
|
2013-04-13 02:54:24 +02:00
|
|
|
def get_audio_rec_allowed(self, vmname):
|
|
|
|
properties = QDBusInterface('org.QubesOS.Audio.%s' % vmname,
|
|
|
|
'/org/qubesos/audio', 'org.freedesktop.DBus.Properties', session_bus)
|
|
|
|
|
|
|
|
current_audio = properties.call('Get', 'org.QubesOS.Audio', 'RecAllowed')
|
|
|
|
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,
|
|
|
|
'/org/qubesos/audio', 'org.freedesktop.DBus.Properties', session_bus)
|
|
|
|
properties.call('Set', 'org.QubesOS.Audio', 'RecAllowed',
|
|
|
|
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():
|
|
|
|
reply = QMessageBox.question(None, "VM Update Confirmation",
|
2012-04-26 00:16:54 +02:00
|
|
|
"<b>{0}</b><br>The VM has to be running to be updated.<br>Do you want to start it?<br>".format(vm.name),
|
2011-10-31 21:46:35 +01:00
|
|
|
QMessageBox.Yes | QMessageBox.Cancel)
|
|
|
|
if reply != QMessageBox.Yes:
|
|
|
|
return
|
2012-07-05 00:49:10 +02:00
|
|
|
trayIcon.showMessage ("Starting '{0}'...".format(vm.name), msecs=3000)
|
2011-03-13 18:43:55 +01:00
|
|
|
|
|
|
|
app.processEvents()
|
|
|
|
|
2011-10-31 21:46:35 +01:00
|
|
|
thread_monitor = ThreadMonitor()
|
|
|
|
thread = threading.Thread (target=self.do_update_vm, args=(vm, thread_monitor))
|
|
|
|
thread.daemon = True
|
|
|
|
thread.start()
|
|
|
|
|
2012-04-26 00:16:54 +02:00
|
|
|
progress = QProgressDialog ("<b>{0}</b><br>Please wait for the updater to launch...".format(vm.name), "", 0, 0)
|
|
|
|
progress.setCancelButton(None)
|
|
|
|
progress.setModal(True)
|
|
|
|
progress.show()
|
|
|
|
|
2011-10-31 21:46:35 +01:00
|
|
|
while not thread_monitor.is_finished():
|
|
|
|
app.processEvents()
|
|
|
|
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:
|
2011-12-18 14:03:16 +01:00
|
|
|
QMessageBox.warning (None, "Error VM update!", "ERROR: {0}".format(thread_monitor.error_msg))
|
2011-10-31 21:46:35 +01:00
|
|
|
|
|
|
|
def do_update_vm(self, vm, thread_monitor):
|
|
|
|
try:
|
2011-12-18 14:03:16 +01:00
|
|
|
if vm.qid == 0:
|
2012-06-19 22:58:49 +02:00
|
|
|
subprocess.check_call (["/usr/bin/qubes-dom0-update", "--clean", "--gui"])
|
2011-12-18 14:03:16 +01:00
|
|
|
else:
|
2014-05-12 15:34:24 +02:00
|
|
|
vm_run_common_args = {
|
|
|
|
'verbose': False,
|
|
|
|
'autostart': True,
|
|
|
|
'notify_function': lambda lvl, msg: trayIcon\
|
|
|
|
.showMessage(msg, msecs=3000) }
|
|
|
|
vm.run("yum clean expire-cache", user='root', wait=True,
|
|
|
|
**vm_run_common_args)
|
|
|
|
vm.run("gpk-update-viewer;service qubes-update-check start -P",
|
|
|
|
**vm_run_common_args)
|
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()
|
|
|
|
|
2013-02-12 01:06:32 +01:00
|
|
|
(command_to_run, ok) = QInputDialog.getText(self, 'Qubes command entry',
|
|
|
|
'Run command in <b>'+vm.name+'</b>:')
|
|
|
|
if not ok or command_to_run == "":
|
|
|
|
return
|
2012-05-11 12:50:45 +02:00
|
|
|
thread_monitor = ThreadMonitor()
|
2013-02-12 01:06:32 +01:00
|
|
|
thread = threading.Thread (target=self.do_run_command_in_vm, args=(vm, str(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()
|
|
|
|
time.sleep (0.2)
|
|
|
|
|
|
|
|
if not thread_monitor.success:
|
|
|
|
QMessageBox.warning (None, "Error while running command", "Exception while running command:<br>{0}".format(thread_monitor.error_msg))
|
|
|
|
|
|
|
|
|
2013-02-12 01:06:32 +01:00
|
|
|
def do_run_command_in_vm(self, vm, command_to_run, thread_monitor):
|
|
|
|
try:
|
|
|
|
vm.run(command_to_run, verbose=False, autostart=True,
|
|
|
|
notify_function=lambda lvl, msg: trayIcon.showMessage(msg, msecs=3000) )
|
|
|
|
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()
|
2012-11-13 04:43:53 +01: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
|
|
|
|
2013-03-05 13:12:31 +01:00
|
|
|
self.showhide_vms(self.show_inactive_vms, self.show_internal_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:
|
|
|
|
self.manager_settings.setValue('view/show_inactive_vms', self.show_inactive_vms)
|
|
|
|
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()
|
|
|
|
|
2013-03-05 13:12:31 +01:00
|
|
|
self.showhide_vms(self.show_inactive_vms, self.show_internal_vms)
|
2013-03-05 11:21:16 +01:00
|
|
|
self.set_table_geom_size()
|
|
|
|
if self.settings_loaded:
|
|
|
|
self.manager_settings.setValue('view/show_internal_vms', self.show_internal_vms)
|
|
|
|
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()
|
2012-02-13 17:47:12 +01: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_()
|
|
|
|
|
2012-01-24 20:59:44 +01:00
|
|
|
|
2012-01-31 14:29:13 +01:00
|
|
|
@pyqtSlot(name='on_action_restore_triggered')
|
|
|
|
def action_restore_triggered(self):
|
2012-02-22 06:09:25 +01: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):
|
2012-03-29 23:26:16 +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):
|
2012-01-22 18:45:41 +01: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:
|
|
|
|
#disable hiding the last one
|
|
|
|
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:
|
|
|
|
#enable hiding previously disabled column
|
|
|
|
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:
|
|
|
|
col_name = [name for name in self.columns_indices.keys() if self.columns_indices[name] == col_num][0]
|
|
|
|
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):
|
|
|
|
self.showhide_column( self.columns_indices['Type'], checked)
|
|
|
|
|
|
|
|
def on_action_label_toggled(self, checked):
|
|
|
|
self.showhide_column( self.columns_indices['Label'], checked)
|
|
|
|
|
|
|
|
def on_action_name_toggled(self, checked):
|
|
|
|
self.showhide_column( self.columns_indices['Name'], checked)
|
|
|
|
|
|
|
|
def on_action_state_toggled(self, checked):
|
2012-03-26 11:48:49 +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):
|
|
|
|
self.showhide_column( self.columns_indices['Internal'], checked)
|
|
|
|
|
2014-03-10 04:27:52 +01:00
|
|
|
def on_action_ip_toggled(self, checked):
|
|
|
|
self.showhide_column( self.columns_indices['IP'], checked)
|
|
|
|
|
|
|
|
def on_action_backups_toggled(self, checked):
|
|
|
|
self.showhide_column( self.columns_indices['Backups'], checked)
|
|
|
|
|
2014-03-10 04:28:30 +01:00
|
|
|
def on_action_last_backup_toggled(self, checked):
|
|
|
|
self.showhide_column( self.columns_indices['Last backup'], checked)
|
|
|
|
|
2012-04-26 16:32:40 +02:00
|
|
|
def on_action_template_toggled(self, checked):
|
2012-03-26 11:48:49 +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):
|
2012-03-26 11:48:49 +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):
|
2012-03-26 11:48:49 +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):
|
2012-07-05 01:06:22 +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):
|
2012-07-05 01:06:22 +02:00
|
|
|
self.showhide_column( self.columns_indices['MEM'], checked)
|
|
|
|
|
2012-04-26 16:32:40 +02:00
|
|
|
def on_action_mem_graph_toggled(self, checked):
|
2012-03-26 11:48:49 +02:00
|
|
|
self.showhide_column( self.columns_indices['MEM Graph'], checked)
|
2012-01-22 18:45:41 +01:00
|
|
|
|
2014-03-31 03:44:01 +02:00
|
|
|
def on_action_prefmem_toggled(self, checked):
|
|
|
|
self.showhide_column( self.columns_indices['Req MEM'], checked)
|
|
|
|
|
|
|
|
def on_action_prefmem_graph_toggled(self, checked):
|
|
|
|
self.showhide_column( self.columns_indices['Req MEM Graph'], checked)
|
|
|
|
|
2012-04-27 17:04:35 +02:00
|
|
|
def on_action_size_on_disk_toggled(self, checked):
|
|
|
|
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):
|
2013-04-25 16:09:03 +02:00
|
|
|
release_file = open('/etc/qubes-release', 'r')
|
|
|
|
release = release_file.read()
|
|
|
|
release_file.close()
|
|
|
|
QMessageBox.about(self, "About...", "<b>Qubes OS</b><br><br>%s" % release)
|
2012-04-26 17:46:41 +02:00
|
|
|
|
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-03-06 18:45:47 +01:00
|
|
|
|
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()
|
|
|
|
|
|
|
|
#logs menu
|
2012-04-24 12:06:08 +02:00
|
|
|
self.logs_menu.clear()
|
|
|
|
if vm.qid == 0:
|
|
|
|
text = "/var/log/xen/console/hypervisor.log"
|
|
|
|
action = self.logs_menu.addAction(QIcon(":/log.png"), text)
|
|
|
|
action.setData(QVariant(text))
|
2012-04-23 19:01:22 +02:00
|
|
|
self.logs_menu.setEnabled(True)
|
2012-04-24 12:06:08 +02:00
|
|
|
else:
|
|
|
|
menu_empty = True
|
|
|
|
text = "/var/log/xen/console/guest-"+vm.name+".log"
|
|
|
|
if os.path.exists(text):
|
|
|
|
action = self.logs_menu.addAction(QIcon(":/log.png"), text)
|
|
|
|
action.setData(QVariant(text))
|
|
|
|
menu_empty = False
|
|
|
|
|
|
|
|
text = "/var/log/xen/console/guest-"+vm.name+"-dm.log"
|
|
|
|
if os.path.exists(text):
|
|
|
|
action = self.logs_menu.addAction(QIcon(":/log.png"), text)
|
|
|
|
action.setData(QVariant(text))
|
|
|
|
menu_empty = False
|
|
|
|
|
2013-10-18 03:40:21 +02:00
|
|
|
text = "/var/log/qubes/guid."+vm.name+".log"
|
|
|
|
if os.path.exists(text):
|
|
|
|
action = self.logs_menu.addAction(QIcon(":/log.png"), text)
|
|
|
|
action.setData(QVariant(text))
|
|
|
|
menu_empty = False
|
|
|
|
|
|
|
|
text = "/var/log/qubes/qrexec."+vm.name+".log"
|
|
|
|
if os.path.exists(text):
|
|
|
|
action = self.logs_menu.addAction(QIcon(":/log.png"), text)
|
|
|
|
action.setData(QVariant(text))
|
|
|
|
menu_empty = False
|
|
|
|
|
2012-04-24 12:06:08 +02: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()
|
2012-02-14 19:00:50 +01:00
|
|
|
if len(self.blk_manager.attached_devs) > 0 :
|
|
|
|
for d in self.blk_manager.attached_devs:
|
|
|
|
if self.blk_manager.attached_devs[d]['attached_to']['vm'] == vm.name:
|
2012-04-23 19:01:22 +02:00
|
|
|
text = "Detach " + d + " " + unicode(self.blk_manager.attached_devs[d]['size']) + " " + self.blk_manager.attached_devs[d]['desc']
|
|
|
|
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
|
|
|
|
if d[-1].isdigit() and d[0:-1] in self.blk_manager.current_blk:
|
|
|
|
continue
|
2012-04-23 19:01:22 +02:00
|
|
|
text = "Attach " + d + " " + unicode(self.blk_manager.free_devs[d]['size']) + " " + self.blk_manager.free_devs[d]['desc']
|
|
|
|
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()
|
|
|
|
QMessageBox.critical(None, "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()
|
|
|
|
|
|
|
|
action_showmanager = self.createAction ("Open VM Manager", slot=show_manager, icon="qubes")
|
|
|
|
action_backup = self.createAction ("Make backup")
|
|
|
|
action_preferences = self.createAction ("Preferences")
|
|
|
|
action_set_netvm = self.createAction ("Set default NetVM", icon="networking")
|
|
|
|
action_sys_info = self.createAction ("System Info", icon="dom0")
|
|
|
|
action_exit = self.createAction ("Exit", slot=exit_app)
|
|
|
|
|
|
|
|
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)
|
|
|
|
self.blk_menu.setTitle("Block devices")
|
|
|
|
action_blk_menu = self.createAction("Block devices")
|
|
|
|
action_blk_menu.setMenu(self.blk_menu)
|
|
|
|
|
|
|
|
self.addActions (self.menu, (action_showmanager,
|
|
|
|
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)
|
|
|
|
|
|
|
|
self.connect (self, SIGNAL("activated (QSystemTrayIcon::ActivationReason)"), self.icon_clicked)
|
|
|
|
|
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",
|
|
|
|
"/org/freedesktop/Notifications",
|
|
|
|
"org.freedesktop.Notifications", session_bus)
|
2014-05-05 02:15:37 +02:00
|
|
|
srv_info = self.tray_notifier.call("GetServerInformation")
|
2014-05-15 23:49:02 +02:00
|
|
|
if srv_info.type() == QDBusMessage.ReplyMessage and len(srv_info
|
|
|
|
.arguments()) > 1:
|
|
|
|
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):
|
|
|
|
self.showMessage("Qubes dom0 updates available.", msecs=0)
|
|
|
|
|
|
|
|
|
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(
|
|
|
|
lambda a, d=dev: self.attach_device_triggered(a, dev))
|
|
|
|
for vm in sorted(manager_window.qvm_collection.values(),
|
|
|
|
key=lambda x: x.name):
|
|
|
|
if not vm.is_running():
|
|
|
|
continue
|
|
|
|
if vm.qid == 0:
|
|
|
|
# skip dom0 to prevent (fatal) mistakes
|
|
|
|
continue
|
|
|
|
action = blk_vm_menu.addAction(QIcon(":/add.png"), vm.name)
|
|
|
|
action.setData(QVariant(vm))
|
|
|
|
return blk_vm_menu
|
|
|
|
|
|
|
|
self.blk_menu.clear()
|
|
|
|
self.blk_menu.setEnabled(True)
|
|
|
|
|
|
|
|
self.blk_manager.blk_lock.acquire()
|
|
|
|
if len(self.blk_manager.attached_devs) > 0 :
|
|
|
|
for d in self.blk_manager.attached_devs:
|
|
|
|
vm = self.blk_manager.qvm_collection.get_vm_by_name(
|
|
|
|
self.blk_manager.attached_devs[d]['attached_to']['vm']
|
|
|
|
)
|
|
|
|
text = "Detach %s %s (%s) from %s" % (
|
|
|
|
d,
|
|
|
|
self.blk_manager.attached_devs[d]['desc'],
|
|
|
|
unicode(self.blk_manager.attached_devs[d]['size']),
|
|
|
|
vm.name)
|
|
|
|
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
|
|
|
|
text = "Attach %s %s %s" % (
|
|
|
|
d,
|
|
|
|
unicode(self.blk_manager.free_devs[d]['size']),
|
|
|
|
self.blk_manager.free_devs[d]['desc']
|
|
|
|
)
|
|
|
|
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()
|
|
|
|
QMessageBox.critical(None, "Block attach/detach error!", str(e))
|
|
|
|
|
|
|
|
@pyqtSlot('QAction *')
|
|
|
|
def dettach_device_triggered(self, action):
|
|
|
|
dev = str(action.data().toString())
|
|
|
|
vm = self.blk_manager.qvm_collection.get_vm_by_name(
|
|
|
|
self.blk_manager.attached_devs[dev]['attached_to']['vm']
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
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()
|
|
|
|
QMessageBox.critical(None, "Block attach/detach error!", str(e))
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
def addActions(self, target, actions):
|
|
|
|
for action in actions:
|
|
|
|
if action is None:
|
|
|
|
target.addSeparator()
|
|
|
|
else:
|
|
|
|
target.addAction(action)
|
|
|
|
|
2012-07-05 00:49:10 +02:00
|
|
|
def showMessage(self, message, msecs):
|
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,
|
|
|
|
"/usr/share/qubes/icons/qubes.png", "Qubes VM Manager",
|
|
|
|
message, v_actions, QVariant.fromMap({}), msecs)
|
2010-05-11 16:51:31 +02:00
|
|
|
|
|
|
|
def createAction(self, text, slot=None, shortcut=None, icon=None,
|
|
|
|
tip=None, checkable=False, signal="triggered()"):
|
|
|
|
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
|
|
|
|
|
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()
|
|
|
|
|
2012-03-28 21:36:59 +02:00
|
|
|
def get_frame_size():
|
|
|
|
w = 0
|
|
|
|
h = 0
|
2014-05-22 15:07:35 +02:00
|
|
|
cmd = ['/usr/bin/xprop', '-name', 'Qubes VM Manager', '|', 'grep', '_NET_FRAME_EXTENTS']
|
2012-03-28 21:36:59 +02:00
|
|
|
xprop = subprocess.Popen(cmd, stdout = subprocess.PIPE)
|
|
|
|
for l in xprop.stdout:
|
|
|
|
line = l.split('=')
|
|
|
|
if len(line) == 2:
|
|
|
|
line = line[1].strip().split(',')
|
|
|
|
if len(line) == 4:
|
|
|
|
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
|
2012-03-28 21:36:59 +02:00
|
|
|
#in case of some weird window managers we have to assume sth...
|
|
|
|
if w<= 0:
|
|
|
|
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
|
|
|
|
|
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()
|
2012-05-19 07:42:57 +02:00
|
|
|
#print manager_window.frame_width, " x ", manager_window.frame_height
|
|
|
|
manager_window.set_table_geom_size()
|
2010-05-11 16:51:31 +02:00
|
|
|
|
2012-05-19 07:42:57 +02:00
|
|
|
def bring_manager_to_front():
|
2012-07-05 01:06:22 +02:00
|
|
|
|
2011-03-10 18:09:52 +01:00
|
|
|
if manager_window.isVisible():
|
2014-05-22 15:07:35 +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
|
|
|
|
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',
|
|
|
|
'/org/qubesos/QubesManager', 'org.qubesos.QubesManager', system_bus)
|
|
|
|
qubes_manager.call('show_manager')
|
2010-05-11 16:51:31 +02:00
|
|
|
|
|
|
|
def exit_app():
|
|
|
|
notifier.stop()
|
|
|
|
app.exit()
|
|
|
|
|
|
|
|
# Bases on the original code by:
|
|
|
|
# Copyright (c) 2002-2007 Pascal Varet <p.varet@gmail.com>
|
|
|
|
|
|
|
|
def handle_exception( exc_type, exc_value, exc_traceback ):
|
|
|
|
import sys
|
|
|
|
import os.path
|
|
|
|
import traceback
|
|
|
|
|
|
|
|
filename, line, dummy, dummy = traceback.extract_tb( exc_traceback ).pop()
|
|
|
|
filename = os.path.basename( filename )
|
|
|
|
error = "%s: %s" % ( exc_type.__name__, exc_value )
|
|
|
|
|
2012-03-14 14:00:49 +01:00
|
|
|
strace = ""
|
|
|
|
stacktrace = traceback.extract_tb( exc_traceback )
|
|
|
|
while len(stacktrace) > 0:
|
|
|
|
(filename, line, func, txt) = stacktrace.pop()
|
|
|
|
strace += "----\n"
|
|
|
|
strace += "line: %s\n" %txt
|
|
|
|
strace += "func: %s\n" %func
|
|
|
|
strace += "line no.: %d\n" %line
|
|
|
|
strace += "file: %s\n" %filename
|
|
|
|
|
|
|
|
msg_box = QMessageBox()
|
|
|
|
msg_box.setDetailedText(strace)
|
|
|
|
msg_box.setIcon(QMessageBox.Critical)
|
|
|
|
msg_box.setWindowTitle( "Houston, we have a problem...")
|
|
|
|
msg_box.setText("Whoops. A critical error has occured. This is most likely a bug "
|
|
|
|
"in Qubes Manager.<br><br>"
|
|
|
|
"<b><i>%s</i></b>" % error +
|
|
|
|
"<br/>at line <b>%d</b><br/>of file %s.<br/><br/>"
|
|
|
|
% ( line, filename ))
|
2012-07-05 01:06:22 +02:00
|
|
|
|
2012-03-14 14:00:49 +01:00
|
|
|
msg_box.exec_()
|
|
|
|
|
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
|
|
|
|
|
|
|
def main():
|
|
|
|
# Avoid starting more than one instance of the app
|
|
|
|
lock = QubesDaemonPidfile ("qubes-manager")
|
|
|
|
if lock.pidfile_exists():
|
2012-05-15 09:11:25 +02:00
|
|
|
if lock.read_pid() == os.getpid():
|
|
|
|
pass
|
|
|
|
elif lock.pidfile_is_stale():
|
2010-05-11 16:51:31 +02:00
|
|
|
lock.remove_pidfile()
|
|
|
|
print "Removed stale pidfile (has the previous daemon instance crashed?)."
|
|
|
|
else:
|
2012-07-24 23:46:03 +02:00
|
|
|
show_running_manager_via_dbus()
|
2010-05-11 16:51:31 +02:00
|
|
|
exit (0)
|
|
|
|
|
|
|
|
lock.create_pidfile()
|
|
|
|
|
2012-05-15 09:11:25 +02:00
|
|
|
signal.signal(signal.SIGHUP, sighup_handler)
|
|
|
|
|
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")
|
|
|
|
app.setWindowIcon(QIcon(":/qubes.png"))
|
2014-04-30 15:03:09 +02:00
|
|
|
app.setAttribute(Qt.AA_DontShowIconsInMenus, False)
|
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-03-31 18:38:17 +02:00
|
|
|
trayIcon = QubesTrayIcon(QIcon(":/qubes.png"), 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
|
2013-03-12 15:56:40 +01:00
|
|
|
notifier = ThreadedNotifier(wm, QubesManagerFileWatcher(manager_window.mark_table_for_update))
|
2010-05-11 16:51:31 +02:00
|
|
|
notifier.start()
|
2013-03-16 21:07:53 +01:00
|
|
|
wm.add_watch(system_path["qubes_store_filename"], EventsCodes.OP_FLAGS.get('IN_MODIFY'))
|
2013-12-02 04:03:05 +01:00
|
|
|
wm.add_watch(os.path.dirname(system_path["qubes_store_filename"]), EventsCodes.OP_FLAGS.get('IN_MOVED_TO'))
|
2013-03-12 15:56:40 +01:00
|
|
|
wm.add_watch(qubes_clipboard_info_file, EventsCodes.OP_FLAGS.get('IN_CLOSE_WRITE'))
|
2013-10-18 03:33:56 +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
|
|
|
|
2012-07-05 01:10:01 +02:00
|
|
|
global system_bus
|
2013-04-13 02:54:24 +02:00
|
|
|
system_bus = QDBusConnection.systemBus()
|
|
|
|
system_bus.registerService('org.qubesos.QubesManager')
|
|
|
|
system_bus.registerObject(dbus_object_path, manager_window)
|
2012-07-05 01:10:01 +02:00
|
|
|
|
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
|
|
|
|
2012-10-16 04:28:57 +02:00
|
|
|
lock.remove_pidfile()
|
2010-05-11 16:51:31 +02:00
|
|
|
trayIcon = None
|
2012-10-16 04:28:57 +02:00
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|