dbus interface for error icon notify (#615)

This commit is contained in:
Marek Marczykowski 2012-07-05 01:10:01 +02:00
parent 3f7fd7ceb7
commit 8fbea00975
4 changed files with 90 additions and 0 deletions

View File

@ -0,0 +1,15 @@
<!DOCTYPE busconfig PUBLIC
"-//freedesktop//DTD D-BUS Bus Configuration 1.0//EN"
"http://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd">
<busconfig>
<!-- This config allows anyone to control QubesManager -->
<policy context="default">
<allow send_destination="org.qubesos.QubesManager"/>
</policy>
<policy group="qubes">
<allow own="org.qubesos.QubesManager"/>
</policy>
</busconfig>

View File

@ -0,0 +1,19 @@
<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN" "http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd">
<node>
<interface name="org.qubesos.QubesManager">
<method name="notify_error">
<arg name="vmname" type="s" direction="in"/>
<arg name="message" type="s" direction="in"/>
<annotation name="org.freedesktop.DBus.Method.NoReply" value="true"/>
</method>
<method name="clear_error_exact">
<arg name="vmname" type="s" direction="in"/>
<arg name="message" type="s" direction="in"/>
<annotation name="org.freedesktop.DBus.Method.NoReply" value="true"/>
</method>
<method name="clear_error">
<arg name="vmname" type="s" direction="in"/>
<annotation name="org.freedesktop.DBus.Method.NoReply" value="true"/>
</method>
</interface>
</node>

View File

@ -26,6 +26,8 @@ import signal
import fcntl import fcntl
import errno import errno
import dbus import dbus
import dbus.service
from dbus.mainloop.qt import DBusQtMainLoop
from PyQt4.QtCore import * from PyQt4.QtCore import *
from PyQt4.QtGui import * from PyQt4.QtGui import *
@ -62,6 +64,9 @@ qubes_guid_path = '/usr/bin/qubes_guid'
update_suggestion_interval = 14 # 14 days update_suggestion_interval = 14 # 14 days
dbus_object_path = '/org/qubesos/QubesManager'
dbus_interface = 'org.qubesos.QubesManager'
power_order = Qt.DescendingOrder power_order = Qt.DescendingOrder
update_order = Qt.AscendingOrder update_order = Qt.AscendingOrder
@ -1810,6 +1815,42 @@ class QubesTrayIcon(QSystemTrayIcon):
action.setCheckable(True) action.setCheckable(True)
return action 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(): def get_frame_size():
w = 0 w = 0
h = 0 h = 0
@ -1923,6 +1964,10 @@ def main():
sys.excepthook = handle_exception sys.excepthook = handle_exception
# setup dbus connection
DBusQtMainLoop(set_as_default=True)
global manager_window global manager_window
manager_window = VmManagerWindow() manager_window = VmManagerWindow()
wm = WatchManager() wm = WatchManager()
@ -1933,6 +1978,11 @@ def main():
notifier.start() notifier.start()
wdd = wm.add_watch(qubes_store_filename, mask) 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 global trayIcon
trayIcon = QubesTrayIcon(QIcon(":/qubes.png")) trayIcon = QubesTrayIcon(QIcon(":/qubes.png"))
trayIcon.show() trayIcon.show()

View File

@ -13,6 +13,7 @@ License: GPL
URL: http://fixme URL: http://fixme
Requires: python, PyQt4, qubes-core-dom0 > 1.7.23, kdebase Requires: python, PyQt4, qubes-core-dom0 > 1.7.23, kdebase
Requires: pmount, cryptsetup, wmctrl Requires: pmount, cryptsetup, wmctrl
Requires: dbus
BuildRequires: PyQt4-devel BuildRequires: PyQt4-devel
AutoReq: 0 AutoReq: 0
@ -64,6 +65,9 @@ cp qubes-manager.desktop $RPM_BUILD_ROOT/usr/share/applications
mkdir -p $RPM_BUILD_ROOT/etc/xdg/autostart/ mkdir -p $RPM_BUILD_ROOT/etc/xdg/autostart/
cp qubes-manager.desktop $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 %post
update-desktop-database &> /dev/null || : update-desktop-database &> /dev/null || :
killall -1 qubes-manager || : killall -1 qubes-manager || :
@ -152,3 +156,5 @@ rm -rf $RPM_BUILD_ROOT
/usr/share/applications/qubes-manager.desktop /usr/share/applications/qubes-manager.desktop
/etc/xdg/autostart/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