From 8fbea00975a9778865b774a66eb71ac2ccdbb622 Mon Sep 17 00:00:00 2001 From: Marek Marczykowski Date: Thu, 5 Jul 2012 01:10:01 +0200 Subject: [PATCH] dbus interface for error icon notify (#615) --- org.qubesos.QubesManager.conf | 15 +++++++++++ org.qubesos.QubesManager.xml | 19 +++++++++++++ qubesmanager/main.py | 50 +++++++++++++++++++++++++++++++++++ rpm_spec/qmgr.spec | 6 +++++ 4 files changed, 90 insertions(+) create mode 100644 org.qubesos.QubesManager.conf create mode 100644 org.qubesos.QubesManager.xml diff --git a/org.qubesos.QubesManager.conf b/org.qubesos.QubesManager.conf new file mode 100644 index 0000000..5bc7dad --- /dev/null +++ b/org.qubesos.QubesManager.conf @@ -0,0 +1,15 @@ + + + + + + + + + + + + + diff --git a/org.qubesos.QubesManager.xml b/org.qubesos.QubesManager.xml new file mode 100644 index 0000000..bd0cd22 --- /dev/null +++ b/org.qubesos.QubesManager.xml @@ -0,0 +1,19 @@ + + + + + + + + + + + + + + + + + + + diff --git a/qubesmanager/main.py b/qubesmanager/main.py index 5df12fe..013b591 100755 --- a/qubesmanager/main.py +++ b/qubesmanager/main.py @@ -26,6 +26,8 @@ import signal import fcntl import errno import dbus +import dbus.service +from dbus.mainloop.qt import DBusQtMainLoop from PyQt4.QtCore import * from PyQt4.QtGui import * @@ -62,6 +64,9 @@ qubes_guid_path = '/usr/bin/qubes_guid' update_suggestion_interval = 14 # 14 days +dbus_object_path = '/org/qubesos/QubesManager' +dbus_interface = 'org.qubesos.QubesManager' + power_order = Qt.DescendingOrder update_order = Qt.AscendingOrder @@ -1810,6 +1815,42 @@ class QubesTrayIcon(QSystemTrayIcon): action.setCheckable(True) return action +class QubesDbusNotify(dbus.service.Object): + def __init__(self, bus, manager_window): + # export to system bus (instead of session) to make possible + # communication from outside of session (eg. from qmemman) + dbus.service.Object.__init__(self, bus, dbus_object_path) + self.manager_window = manager_window + + @dbus.service.method(dbus_interface=dbus_interface, + in_signature='ss', out_signature='') + def notify_error(self, vmname, message): + vm = self.manager_window.qvm_collection.get_vm_by_name(vmname) + if vm: + self.manager_window.set_error(vm.qid, message) + else: + # ignore VM-not-found error + pass + @dbus.service.method(dbus_interface=dbus_interface, + in_signature='ss', out_signature='') + def clear_error_exact(self, vmname, message): + vm = self.manager_window.qvm_collection.get_vm_by_name(vmname) + if vm: + self.manager_window.clear_error_exact(vm.qid, message) + else: + # ignore VM-not-found error + pass + + @dbus.service.method(dbus_interface=dbus_interface, + in_signature='s', out_signature='') + def clear_error(self, vmname): + vm = self.manager_window.qvm_collection.get_vm_by_name(vmname) + if vm: + self.manager_window.clear_error(vm.qid, message) + else: + # ignore VM-not-found error + pass + def get_frame_size(): w = 0 h = 0 @@ -1923,6 +1964,10 @@ def main(): sys.excepthook = handle_exception + # setup dbus connection + DBusQtMainLoop(set_as_default=True) + + global manager_window manager_window = VmManagerWindow() wm = WatchManager() @@ -1933,6 +1978,11 @@ def main(): notifier.start() wdd = wm.add_watch(qubes_store_filename, mask) + global system_bus + system_bus = dbus.SystemBus() + name = dbus.service.BusName('org.qubesos.QubesManager', system_bus) + dbus_notifier = QubesDbusNotify(system_bus, manager_window) + global trayIcon trayIcon = QubesTrayIcon(QIcon(":/qubes.png")) trayIcon.show() diff --git a/rpm_spec/qmgr.spec b/rpm_spec/qmgr.spec index d2d1b80..e382e3d 100644 --- a/rpm_spec/qmgr.spec +++ b/rpm_spec/qmgr.spec @@ -13,6 +13,7 @@ License: GPL URL: http://fixme Requires: python, PyQt4, qubes-core-dom0 > 1.7.23, kdebase Requires: pmount, cryptsetup, wmctrl +Requires: dbus BuildRequires: PyQt4-devel AutoReq: 0 @@ -64,6 +65,9 @@ cp qubes-manager.desktop $RPM_BUILD_ROOT/usr/share/applications mkdir -p $RPM_BUILD_ROOT/etc/xdg/autostart/ cp qubes-manager.desktop $RPM_BUILD_ROOT/etc/xdg/autostart/ +install -D org.qubesos.QubesManager.conf $RPM_BUILD_ROOT/etc/dbus-1/system.d/org.qubesos.QubesManager.conf +install -D org.qubesos.QubesManager.xml $RPM_BUILD_ROOT/usr/share/dbus-1/interfaces/org.qubesos.QubesManager.xml + %post update-desktop-database &> /dev/null || : killall -1 qubes-manager || : @@ -152,3 +156,5 @@ rm -rf $RPM_BUILD_ROOT /usr/share/applications/qubes-manager.desktop /etc/xdg/autostart/qubes-manager.desktop +/etc/dbus-1/system.d/org.qubesos.QubesManager.conf +/usr/share/dbus-1/interfaces/org.qubesos.QubesManager.xml