emit signal as structures, instead of strings
(gajim may die with older dbus - it is not completely tested)
This commit is contained in:
parent
a13945e062
commit
d513b7372b
1 changed files with 33 additions and 24 deletions
|
@ -59,6 +59,36 @@ SERVICE = 'org.gajim.dbus'
|
||||||
STATUS_LIST = ['offline', 'connecting', 'online', 'chat', 'away', 'xa', 'dnd',
|
STATUS_LIST = ['offline', 'connecting', 'online', 'chat', 'away', 'xa', 'dnd',
|
||||||
'invisible']
|
'invisible']
|
||||||
|
|
||||||
|
def get_dbus_struct(obj):
|
||||||
|
''' recursively go through all the items and replace
|
||||||
|
them with their casted dbus equivalents
|
||||||
|
'''
|
||||||
|
if obj is None:
|
||||||
|
return dbus.Variant(0)
|
||||||
|
if isinstance(obj, (unicode, str)):
|
||||||
|
return dbus.String(obj)
|
||||||
|
if isinstance(obj, int):
|
||||||
|
return dbus.Int32(obj)
|
||||||
|
if isinstance(obj, float):
|
||||||
|
return dbus.Double(obj)
|
||||||
|
if isinstance(obj, bool):
|
||||||
|
return dbus.Boolean(obj)
|
||||||
|
if isinstance(obj, (list, tuple)):
|
||||||
|
result = [dbus.Variant(get_dbus_struct(i)) for i in obj]
|
||||||
|
if result == []:
|
||||||
|
return dbus.Variant(0)
|
||||||
|
return result
|
||||||
|
if isinstance(obj, dict):
|
||||||
|
result = dbus.Dictionary({}, signature="sv")
|
||||||
|
for key, value in obj.items():
|
||||||
|
result[dbus.String(key)] = dbus.Variant(get_dbus_struct(
|
||||||
|
value))
|
||||||
|
if result == {}:
|
||||||
|
return dbus.Variant(0)
|
||||||
|
return result
|
||||||
|
# unknown type
|
||||||
|
return dbus.Variant(0)
|
||||||
|
|
||||||
class Remote:
|
class Remote:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.signal_object = None
|
self.signal_object = None
|
||||||
|
@ -73,7 +103,8 @@ class Remote:
|
||||||
|
|
||||||
def raise_signal(self, signal, arg):
|
def raise_signal(self, signal, arg):
|
||||||
if self.signal_object:
|
if self.signal_object:
|
||||||
self.signal_object.raise_signal(signal, repr(arg))
|
self.signal_object.raise_signal(signal,
|
||||||
|
get_dbus_struct(arg))
|
||||||
|
|
||||||
|
|
||||||
class SignalObject(DbusPrototype):
|
class SignalObject(DbusPrototype):
|
||||||
|
@ -290,7 +321,7 @@ class SignalObject(DbusPrototype):
|
||||||
|
|
||||||
cached_vcard = gajim.connections.values()[0].get_cached_vcard(jid)
|
cached_vcard = gajim.connections.values()[0].get_cached_vcard(jid)
|
||||||
if cached_vcard:
|
if cached_vcard:
|
||||||
return self._get_dbus_struct(cached_vcard)
|
return get_dbus_struct(cached_vcard)
|
||||||
|
|
||||||
# return empty dict
|
# return empty dict
|
||||||
return dbus.Dictionary({}, signature="sv")
|
return dbus.Dictionary({}, signature="sv")
|
||||||
|
@ -456,28 +487,6 @@ class SignalObject(DbusPrototype):
|
||||||
args = args[:desired_length]
|
args = args[:desired_length]
|
||||||
return args
|
return args
|
||||||
|
|
||||||
def _get_dbus_struct(self, obj):
|
|
||||||
''' recursively go through all the items and replace
|
|
||||||
them with their casted dbus equivalents
|
|
||||||
'''
|
|
||||||
if obj is None:
|
|
||||||
return dbus.String('')
|
|
||||||
if isinstance(obj, (unicode, str)):
|
|
||||||
return dbus.String(obj)
|
|
||||||
if isinstance(obj, int):
|
|
||||||
return dbus.UInt32(obj)
|
|
||||||
if isinstance(obj, float):
|
|
||||||
return dbus.Double(obj)
|
|
||||||
if isinstance(obj, (list, tuple)):
|
|
||||||
return [self._get_dbus_struct(i) for i in obj]
|
|
||||||
if isinstance(obj, dict):
|
|
||||||
result = dbus.Dictionary({}, signature="sv")
|
|
||||||
for key, value in obj.items():
|
|
||||||
result[dbus.String(key)] = self._get_dbus_struct(value)
|
|
||||||
return result
|
|
||||||
# unknown type
|
|
||||||
return dbus.Variant(obj)
|
|
||||||
|
|
||||||
def _contacts_as_dbus_structure(self, contacts):
|
def _contacts_as_dbus_structure(self, contacts):
|
||||||
''' get info from list of Contact objects and create dbus dict '''
|
''' get info from list of Contact objects and create dbus dict '''
|
||||||
if not contacts:
|
if not contacts:
|
||||||
|
|
Loading…
Add table
Reference in a new issue