5
5
# Copyright © 2009-2010 Siegfried-Angel Gevatter Pujals <rainct@ubuntu.com>
6
6
# Copyright © 2009 Mikkel Kamstrup Erlandsen <mikkel.kamstrup@gmail.com>
7
7
# Copyright © 2010 Seif Lotfy <seif@lotfy.com>
8
# Copyright © 2011 Markus Korn <thekorn@gmx.de>
9
10
# This program is free software: you can redistribute it and/or modify
10
11
# it under the terms of the GNU Lesser General Public License as published by
23
24
import dbus.service
27
from xml.etree import ElementTree
26
29
from zeitgeist.datamodel import TimeRange, StorageState, ResultType, NULL_EVENT
27
30
from _zeitgeist.engine.datamodel import Event, Subject
28
31
from _zeitgeist.engine import get_engine
30
33
from _zeitgeist.engine import constants
31
34
from _zeitgeist.singleton import SingletonApplication
36
class DBUSProperty(property):
38
def __init__(self, fget=None, fset=None, in_signature=None, out_signature=None):
39
assert not (fget and not out_signature), "fget needs a dbus signature"
40
assert not (fset and not in_signature), "fset needs a dbus signature"
41
assert (fget and not fset) or (fset and fget), \
42
"dbus properties needs to be either readonly or readwritable"
43
self.in_signature = in_signature
44
self.out_signature = out_signature
45
super(DBUSProperty, self).__init__(fget, fset)
33
48
class RemoteInterface(SingletonApplication):
35
50
Primary interface to the Zeitgeist engine. Used to update and query
42
57
:const:`org.gnome.zeitgeist.Engine`.
44
59
_dbus_properties = {
45
"version": property(lambda self: (0, 7, 0)),
46
"extensions": property(lambda self: list(self._engine.extensions.iter_names())),
60
"version": DBUSProperty(lambda self: (0, 7, 1), out_signature="iii"),
61
"extensions": DBUSProperty(
62
lambda self: list(self._engine.extensions.iter_names()),
357
374
@dbus.service.method(dbus_interface=dbus.PROPERTIES_IFACE,
358
375
in_signature="ss", out_signature="v")
359
376
def Get(self, interface_name, property_name):
377
if interface_name != constants.DBUS_INTERFACE:
379
"'%s' doesn't know anything about the '%s' interface" \
380
%(constants.DBUS_INTERFACE, interface_name)
361
383
return self._dbus_properties[property_name].fget(self)
362
384
except KeyError, e:
365
387
@dbus.service.method(dbus_interface=dbus.PROPERTIES_IFACE,
366
388
in_signature="ssv", out_signature="")
367
389
def Set(self, interface_name, property_name, value):
390
if interface_name != constants.DBUS_INTERFACE:
392
"'%s' doesn't know anything about the '%s' interface" \
393
%(constants.DBUS_INTERFACE, interface_name)
369
396
prop = self._dbus_properties[property_name].fset(self, value)
370
397
except (KeyError, TypeError), e:
373
400
@dbus.service.method(dbus_interface=dbus.PROPERTIES_IFACE,
374
401
in_signature="s", out_signature="a{sv}")
375
402
def GetAll(self, interface_name):
403
if interface_name != constants.DBUS_INTERFACE:
405
"'%s' doesn't know anything about the '%s' interface" \
406
%(constants.DBUS_INTERFACE, interface_name)
376
408
return dict((k, v.fget(self)) for (k,v) in self._dbus_properties.items())
410
# Instrospection Interface
412
@dbus.service.method(dbus.INTROSPECTABLE_IFACE, in_signature="", out_signature="s",
413
path_keyword="object_path", connection_keyword="connection")
414
def Introspect(self, object_path, connection):
415
data = dbus.service.Object.Introspect(self, object_path, connection)
416
xml = ElementTree.fromstring(data)
417
for iface in xml.findall("interface"):
418
if iface.attrib["name"] != constants.DBUS_INTERFACE:
420
for prop_name, prop_func in self._dbus_properties.iteritems():
421
prop = {"name": prop_name}
422
if prop_func.fset is not None:
423
prop["access"] = "readwrite"
425
prop["access"] = "read"
426
prop["type"] = prop_func.out_signature
427
iface.append(ElementTree.Element("property", prop))
428
return ElementTree.tostring(xml, encoding="UTF-8")
378
430
# Notifications interface