9
9
# This program is free software: you can redistribute it and/or modify
10
10
# it under the terms of the GNU Lesser General Public License as published by
11
# the Free Software Foundation, either version 3 of the License, or
11
# the Free Software Foundation, either version 2.1 of the License, or
12
12
# (at your option) any later version.
14
14
# This program is distributed in the hope that it will be useful,
147
147
dbus_interface=dbus.PROPERTIES_IFACE)(self.INTERFACE_NAME,
150
def get_extension(cls, name, path):
150
def extensions(self):
151
"""Returns active extensions"""
152
dbus_interface = self.__shared_state["dbus_interface"]
153
return dbus_interface._disconnection_safe(lambda:
154
dbus_interface.proxy.get_dbus_method("Get",
155
dbus_interface=dbus.PROPERTIES_IFACE)(self.INTERFACE_NAME,
158
def get_extension(cls, name, path, busname=None):
151
159
""" Returns an interface to the given extension.
154
162
>> reg = get_extension("DataSourceRegistry", "data_source_registry")
155
163
>> reg.RegisterDataSource(...)
166
busname = "org.gnome.zeitgeist.%s" % busname
168
busname = cls.BUS_NAME
157
169
if not name in cls.__shared_state["extension_interfaces"]:
158
170
interface_name = "org.gnome.zeitgeist.%s" % name
159
171
object_path = "/org/gnome/zeitgeist/%s" % path
160
proxy = dbus.SessionBus().get_object(cls.BUS_NAME, object_path)
172
proxy = dbus.SessionBus().get_object(busname, object_path)
161
173
iface = _DBusInterface(proxy, interface_name, object_path)
162
iface.BUS_NAME = cls.BUS_NAME
174
iface.BUS_NAME = busname
163
175
iface.INTERFACE_NAME = interface_name
164
176
iface.OBJECT_PATH = object_path
165
177
cls.__shared_state["extension_interfaces"][name] = iface
287
299
always the right thing to do. If you really want to do synchronous
288
300
DBus calls use the raw DBus API found in the ZeitgeistDBusInterface class.
304
def get_event_and_extra_arguments(arguments):
305
""" some methods of :class:`ZeitgeistClient` take a variable
306
number of arguments, where one part of the arguments are used
307
to build one :class:`Event` instance and the other part
308
is forwarded to another method. This function returns an event
309
and the remaining arguments."""
311
for arg in _FIND_EVENTS_FOR_TEMPLATES_ARGS:
313
kwargs[arg] = arguments.pop(arg)
314
ev = Event.new_for_values(**arguments)
290
317
def __init__ (self):
291
318
self._iface = ZeitgeistDBusInterface()
292
319
self._registry = self._iface.get_extension("DataSourceRegistry",
308
335
"Reply handler not callable, found %s" % reply_handler)
309
336
return self._void_reply_handler
311
340
def get_version(self):
312
341
return [int(i) for i in self._iface.version()]
343
def get_extensions(self):
344
return [unicode(i) for i in self._iface.extensions()]
314
348
def insert_event (self, event, ids_reply_handler=None, error_handler=None):
493
527
allowed keywords are the same as the ones allowed by
494
528
:meth:`Event.new_for_values() <zeitgeist.datamodel.Event.new_for_values>`.
496
ev = Event.new_for_values(**kwargs)
530
ev, arguments = self.get_event_and_extra_arguments(kwargs)
498
531
self.find_event_ids_for_templates([ev],
499
532
ids_reply_handler,
502
535
def find_events_for_templates (self,
591
624
allowed keywords are the same as the ones allowed by
592
625
:meth:`Event.new_for_values() <zeitgeist.datamodel.Event.new_for_values>`.
594
ev = Event.new_for_values(**kwargs)
595
# we need a clean dict of arguments to find_event_for_templates
598
for arg in ("timerange", "storage_state", "num_events",
599
"result_type", "error_handler"):
601
arguments[arg] = kwargs[arg]
627
ev, arguments = self.get_event_and_extra_arguments(kwargs)
603
628
self.find_events_for_templates([ev],
604
629
events_reply_handler,