1
# -.- coding: utf-8 -.-
5
# Copyright © 2009 Mikkel Kamstrup Erlandsen <mikkel.kamstrup@gmail.com>
6
# Copyright © 2009 Markus Korn <thekorn@gmx.de>
7
# Copyright © 2009 Seif Lotfy <seif@lotfy.com>
8
# Copyright © 2009-2010 Siegfried-Angel Gevatter Pujals <rainct@ubuntu.com>
10
# This program is free software: you can redistribute it and/or modify
11
# it under the terms of the GNU Lesser General Public License as published by
12
# the Free Software Foundation, either version 2.1 of the License, or
13
# (at your option) any later version.
15
# This program is distributed in the hope that it will be useful,
16
# but WITHOUT ANY WARRANTY; without even the implied warranty of
17
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18
# GNU Lesser General Public License for more details.
20
# You should have received a copy of the GNU Lesser General Public License
21
# along with this program. If not, see <http://www.gnu.org/licenses/>.
23
from zeitgeist.datamodel import Event as OrigEvent, Subject as OrigSubject, \
24
DataSource as OrigDataSource
26
class Event(OrigEvent):
31
Return an unicode representation of the given object.
32
If obj is None, return an empty string.
34
return unicode(obj) if obj is not None else u""
36
def _make_dbus_sendable(self):
38
Ensure that all fields in the event struct are non-None
40
for n, value in enumerate(self[0]):
41
self[0][n] = self._to_unicode(value)
42
for subject in self[1]:
43
for n, value in enumerate(subject):
44
subject[n] = self._to_unicode(value)
45
# The payload require special handling, since it is binary data
46
# If there is indeed data here, we must not unicode encode it!
49
elif isinstance(self[2], unicode):
50
self[2] = str(self[2])
55
Ensure that an Event instance is a Plain Old Python Object (popo),
56
without DBus wrappings etc.
59
popo.append(map(unicode, ev[0]))
60
popo.append([map(unicode, subj) for subj in ev[1]])
61
# We need the check here so that if D-Bus gives us an empty
62
# byte array we don't serialize the text "dbus.Array(...)".
63
popo.append(str(ev[2]) if ev[2] else u'')
66
class Subject(OrigSubject):
69
class DataSource(OrigDataSource):
72
def get_plain(datasource):
73
for plaintype, props in {
74
unicode: (DataSource.Name, DataSource.Description),
75
lambda x: map(Event.get_plain, x): (DataSource.EventTemplates,),
76
bool: (DataSource.Running, DataSource.Enabled),
77
int: (DataSource.LastSeen,),
80
datasource[prop] = plaintype(datasource[prop])
81
return tuple(datasource)