refacter gajim-remote code, don't use unrepr
(0.23 is not supported) get cached vcards, instead of signaling server
This commit is contained in:
parent
32bfde61e2
commit
a13945e062
|
@ -228,20 +228,10 @@ class GajimRemote:
|
||||||
if self.command == 'contact_info':
|
if self.command == 'contact_info':
|
||||||
if self.argv_len < 3:
|
if self.argv_len < 3:
|
||||||
send_error(_('Missing argument "contact_jid"'))
|
send_error(_('Missing argument "contact_jid"'))
|
||||||
try:
|
|
||||||
id = self.sbus.add_signal_receiver(self.show_vcard_info,
|
|
||||||
'VcardInfo', INTERFACE, SERVICE, OBJ_PATH)
|
|
||||||
except Exception, e:
|
|
||||||
raise exceptions.ServiceNotAvailable
|
|
||||||
|
|
||||||
res = self.call_remote_method()
|
res = self.call_remote_method()
|
||||||
self.print_result(res)
|
self.print_result(res)
|
||||||
|
|
||||||
if self.command == 'contact_info':
|
|
||||||
gobject.timeout_add(10000, self.gobject_quit) # wait 10 sec for response
|
|
||||||
self.loop = gobject.MainLoop()
|
|
||||||
self.loop.run()
|
|
||||||
|
|
||||||
def print_result(self, res):
|
def print_result(self, res):
|
||||||
''' Print retrieved result to the output '''
|
''' Print retrieved result to the output '''
|
||||||
if res is not None:
|
if res is not None:
|
||||||
|
@ -261,18 +251,17 @@ class GajimRemote:
|
||||||
print account
|
print account
|
||||||
elif self.command == 'account_info':
|
elif self.command == 'account_info':
|
||||||
if res:
|
if res:
|
||||||
print self.print_info(0, self.unrepr(res)[0])
|
print self.print_info(0, res, True)
|
||||||
elif self.command == 'list_contacts':
|
elif self.command == 'list_contacts':
|
||||||
for single_res in res:
|
for account_dict in res:
|
||||||
accounts = self.unrepr(single_res)
|
print self.print_info(0, account_dict, True)
|
||||||
for account_dict in accounts:
|
|
||||||
print self.print_info(0, account_dict)
|
|
||||||
elif self.command == 'prefs_list':
|
elif self.command == 'prefs_list':
|
||||||
prefs_dict = self.unrepr(res)
|
pref_keys = res.keys()
|
||||||
pref_keys = prefs_dict[0].keys()
|
|
||||||
pref_keys.sort()
|
pref_keys.sort()
|
||||||
for pref_key in pref_keys:
|
for pref_key in pref_keys:
|
||||||
print pref_key, '=', prefs_dict[0][pref_key]
|
print pref_key, '=', res[pref_key]
|
||||||
|
elif self.command == 'contact_info':
|
||||||
|
print self.print_info(0, res, True)
|
||||||
elif res:
|
elif res:
|
||||||
print res
|
print res
|
||||||
|
|
||||||
|
@ -348,8 +337,8 @@ class GajimRemote:
|
||||||
str += '\n'
|
str += '\n'
|
||||||
return str
|
return str
|
||||||
|
|
||||||
def print_info(self, level, prop_dict):
|
def print_info(self, level, prop_dict, encode_return = False):
|
||||||
''' return formated string from serialized vcard data '''
|
''' return formated string from data structure '''
|
||||||
if prop_dict is None or not isinstance(prop_dict, (dict, list, tuple)):
|
if prop_dict is None or not isinstance(prop_dict, (dict, list, tuple)):
|
||||||
return ''
|
return ''
|
||||||
ret_str = ''
|
ret_str = ''
|
||||||
|
@ -359,9 +348,9 @@ class GajimRemote:
|
||||||
for val in prop_dict:
|
for val in prop_dict:
|
||||||
if val is None:
|
if val is None:
|
||||||
ret_str +='\t'
|
ret_str +='\t'
|
||||||
elif isinstance(val, (str, int)):
|
elif isinstance(val, int):
|
||||||
ret_str +='\t' + str(val)
|
ret_str +='\t' + str(val)
|
||||||
elif isinstance(val, unicode):
|
elif isinstance(val, (str, unicode)):
|
||||||
ret_str +='\t' + val
|
ret_str +='\t' + val
|
||||||
elif isinstance(val, (list, tuple)):
|
elif isinstance(val, (list, tuple)):
|
||||||
res = ''
|
res = ''
|
||||||
|
@ -385,166 +374,17 @@ class GajimRemote:
|
||||||
for items in val:
|
for items in val:
|
||||||
res += self.print_info(level+1, items)
|
res += self.print_info(level+1, items)
|
||||||
if res != '':
|
if res != '':
|
||||||
if isinstance(res, str):
|
|
||||||
res = res.decode(PREFERRED_ENCODING)
|
|
||||||
ret_str += '%s%s: \n%s' % (spacing, key, res)
|
ret_str += '%s%s: \n%s' % (spacing, key, res)
|
||||||
elif isinstance(val, dict):
|
elif isinstance(val, dict):
|
||||||
res = self.print_info(level+1, val)
|
res = self.print_info(level+1, val)
|
||||||
if res != '':
|
if res != '':
|
||||||
ret_str += '%s%s: \n%s' % (spacing, key, res)
|
ret_str += '%s%s: \n%s' % (spacing, key, res)
|
||||||
|
if (encode_return):
|
||||||
# utf-8 string come from gajim
|
try:
|
||||||
# FIXME: why we have strings instead of unicode?
|
ret_str = ret_str.encode(PREFERRED_ENCODING)
|
||||||
if isinstance(ret_str, str):
|
except:
|
||||||
return ret_str
|
pass
|
||||||
return ret_str.encode(PREFERRED_ENCODING)
|
return ret_str
|
||||||
|
|
||||||
def unrepr(self, serialized_data):
|
|
||||||
''' works the same as eval, but only for structural values,
|
|
||||||
not functions! e.g. dicts, lists, strings, tuples '''
|
|
||||||
if not serialized_data:
|
|
||||||
return (None, '')
|
|
||||||
value = serialized_data.strip()
|
|
||||||
first_char = value[0]
|
|
||||||
is_unicode = False
|
|
||||||
is_int = False
|
|
||||||
|
|
||||||
if first_char == 'u':
|
|
||||||
is_unicode = True
|
|
||||||
value = value[1:]
|
|
||||||
first_char = value[0]
|
|
||||||
elif '0123456789.'.find(first_char) != -1:
|
|
||||||
is_int = True
|
|
||||||
_str = first_char
|
|
||||||
if first_char == '.':
|
|
||||||
is_float = True
|
|
||||||
else:
|
|
||||||
is_float = False
|
|
||||||
for i in xrange(len(value) - 1):
|
|
||||||
chr = value[i+1]
|
|
||||||
if chr == '.':
|
|
||||||
is_float = True
|
|
||||||
elif '0123456789'.find(chr) == -1:
|
|
||||||
break
|
|
||||||
_str += chr
|
|
||||||
if is_float:
|
|
||||||
return (float(_str), value[len(_str):])
|
|
||||||
else:
|
|
||||||
return (int(_str), value[len(_str):])
|
|
||||||
elif first_char == 'N':
|
|
||||||
if value[1:4] == 'one':
|
|
||||||
return (None, value[4:])
|
|
||||||
else:
|
|
||||||
return (None, '')
|
|
||||||
if first_char == "'" or first_char == '"': # handle strings and unicode
|
|
||||||
if len(value) < 2:
|
|
||||||
return ('',value[1:])
|
|
||||||
_str = ''
|
|
||||||
previous_slash = False
|
|
||||||
slashes = 0
|
|
||||||
for i in xrange(len(value) - 1):
|
|
||||||
chr = value[i+1]
|
|
||||||
if previous_slash:
|
|
||||||
previous_slash = False
|
|
||||||
if chr == '\\':
|
|
||||||
_str += '\\'
|
|
||||||
elif chr == 'n':
|
|
||||||
_str += '\n'
|
|
||||||
elif chr == 't':
|
|
||||||
_str += '\t'
|
|
||||||
elif chr == 'r':
|
|
||||||
_str += '\r'
|
|
||||||
elif chr == 'b':
|
|
||||||
_str += '\b'
|
|
||||||
elif chr == '\'':
|
|
||||||
_str += '\''
|
|
||||||
elif chr == '\"':
|
|
||||||
_str += '\"'
|
|
||||||
elif chr in ('u', 'x') and is_unicode:
|
|
||||||
slashes -= 1
|
|
||||||
_str += '\\' + chr
|
|
||||||
else:
|
|
||||||
_str += chr
|
|
||||||
elif chr == first_char:
|
|
||||||
break
|
|
||||||
elif chr == '\\':
|
|
||||||
previous_slash = True
|
|
||||||
slashes += 1
|
|
||||||
else:
|
|
||||||
_str += chr
|
|
||||||
substr_len = len(_str) + 2 + slashes
|
|
||||||
if is_unicode and _str:
|
|
||||||
_str = _str.decode('unicode-escape').encode('utf-8')
|
|
||||||
return (_str, value[substr_len :])
|
|
||||||
elif first_char == '{': # dict
|
|
||||||
_dict = {}
|
|
||||||
if value[1] == '}':
|
|
||||||
return ({}, value[2:])
|
|
||||||
while True:
|
|
||||||
if value[1] == '}':
|
|
||||||
break
|
|
||||||
key, next = self.unrepr(value[1:])
|
|
||||||
if not isinstance(key, (str, unicode)):
|
|
||||||
send_error('Wrong string: %s' % value)
|
|
||||||
next = next.strip()
|
|
||||||
if not next or next[0] != ':':
|
|
||||||
send_error('Wrong string: %s' % (value))
|
|
||||||
val, next = self.unrepr(next[1:])
|
|
||||||
if isinstance(key, str):
|
|
||||||
key = key.decode(PREFERRED_ENCODING)
|
|
||||||
if isinstance(val, str):
|
|
||||||
val = val.decode(PREFERRED_ENCODING)
|
|
||||||
_dict[key] = val
|
|
||||||
next = next.strip()
|
|
||||||
if not next:
|
|
||||||
break
|
|
||||||
if next[0] == ',':
|
|
||||||
value = next
|
|
||||||
elif next[0] == '}':
|
|
||||||
break
|
|
||||||
else:
|
|
||||||
break
|
|
||||||
return (_dict, next[1:])
|
|
||||||
elif first_char in ('[', '('): # return list
|
|
||||||
_tuple = []
|
|
||||||
if value[1] == ']':
|
|
||||||
return ([], value[2:])
|
|
||||||
while True:
|
|
||||||
if value[1] == ']':
|
|
||||||
break
|
|
||||||
val, next = self.unrepr(value[1:])
|
|
||||||
next = next.strip()
|
|
||||||
if not next:
|
|
||||||
send_error('Wrong string: %s' % val)
|
|
||||||
if isinstance(val, str):
|
|
||||||
val = val.decode('utf-8')
|
|
||||||
_tuple.append(val)
|
|
||||||
next = next.strip()
|
|
||||||
if not next:
|
|
||||||
break
|
|
||||||
if next[0] == ',':
|
|
||||||
value = next
|
|
||||||
elif next[0] in (']', ')'):
|
|
||||||
break
|
|
||||||
return (_tuple, next[1:])
|
|
||||||
|
|
||||||
def show_vcard_info(self, *args, **keyword):
|
|
||||||
''' write user vcart in a formated output '''
|
|
||||||
props_dict = None
|
|
||||||
if _version[1] >= 30:
|
|
||||||
props_dict = self.unrepr(args[0])
|
|
||||||
else:
|
|
||||||
if args and len(args) >= 5:
|
|
||||||
props_dict = self.unrepr(args[4].get_args_list()[0])
|
|
||||||
if props_dict:
|
|
||||||
print self.print_info(0,props_dict[0])
|
|
||||||
# remove_signal_receiver is broken in lower versions (< 0.35),
|
|
||||||
# so we leave the leak - nothing can be done
|
|
||||||
if _version[1] >= 41:
|
|
||||||
self.sbus.remove_signal_receiver(self.show_vcard_info, 'VcardInfo',
|
|
||||||
INTERFACE, SERVICE, OBJ_PATH)
|
|
||||||
|
|
||||||
self.loop.quit()
|
|
||||||
|
|
||||||
def check_arguments(self):
|
def check_arguments(self):
|
||||||
''' Make check if all necessary arguments are given '''
|
''' Make check if all necessary arguments are given '''
|
||||||
|
@ -556,21 +396,14 @@ class GajimRemote:
|
||||||
'Type "%s help %s" for more info') %
|
'Type "%s help %s" for more info') %
|
||||||
(args[argv_len][0], BASENAME, self.command))
|
(args[argv_len][0], BASENAME, self.command))
|
||||||
|
|
||||||
def gobject_quit(self):
|
|
||||||
if _version[1] >= 41:
|
|
||||||
self.sbus.remove_signal_receiver(self.show_vcard_info, 'VcardInfo',
|
|
||||||
INTERFACE, SERVICE, OBJ_PATH)
|
|
||||||
self.loop.quit()
|
|
||||||
|
|
||||||
def call_remote_method(self):
|
def call_remote_method(self):
|
||||||
''' calls self.method with arguments from sys.argv[2:] '''
|
''' calls self.method with arguments from sys.argv[2:] '''
|
||||||
try:
|
try:
|
||||||
sys.argv.pop(0)
|
# make console arguments unicode
|
||||||
sys.argv.pop(0)
|
args = [dbus.String(i.decode(PREFERRED_ENCODING)) for i in sys.argv[2:]]
|
||||||
res = self.method(*sys.argv)
|
res = self.method(*args)
|
||||||
return res
|
return res
|
||||||
except Exception, e:
|
except Exception:
|
||||||
print str(e)
|
|
||||||
raise exceptions.ServiceNotAvailable
|
raise exceptions.ServiceNotAvailable
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
|
@ -47,7 +47,7 @@ if dbus_support.supported:
|
||||||
import dbus.service
|
import dbus.service
|
||||||
import dbus.glib # cause dbus 0.35+ doesn't return signal replies without it
|
import dbus.glib # cause dbus 0.35+ doesn't return signal replies without it
|
||||||
DbusPrototype = dbus.service.Object
|
DbusPrototype = dbus.service.Object
|
||||||
elif dbus_support.version >= (0, 20, 0):
|
elif dbus_support.version >= (0, 30, 0):
|
||||||
DbusPrototype = dbus.Object
|
DbusPrototype = dbus.Object
|
||||||
else: #dbus is not defined
|
else: #dbus is not defined
|
||||||
DbusPrototype = str
|
DbusPrototype = str
|
||||||
|
@ -67,7 +67,7 @@ class Remote:
|
||||||
if dbus_support.version[1] >= 41:
|
if dbus_support.version[1] >= 41:
|
||||||
service = dbus.service.BusName(SERVICE, bus=session_bus)
|
service = dbus.service.BusName(SERVICE, bus=session_bus)
|
||||||
self.signal_object = SignalObject(service)
|
self.signal_object = SignalObject(service)
|
||||||
elif dbus_support.version[1] <= 40 and dbus_support.version[1] >= 20:
|
else:
|
||||||
service=dbus.Service(SERVICE, session_bus)
|
service=dbus.Service(SERVICE, session_bus)
|
||||||
self.signal_object = SignalObject(service)
|
self.signal_object = SignalObject(service)
|
||||||
|
|
||||||
|
@ -113,18 +113,11 @@ class SignalObject(DbusPrototype):
|
||||||
|
|
||||||
def raise_signal(self, signal, arg):
|
def raise_signal(self, signal, arg):
|
||||||
''' raise a signal, with a single string message '''
|
''' raise a signal, with a single string message '''
|
||||||
if dbus_support.version[1] >= 30:
|
from dbus import dbus_bindings
|
||||||
from dbus import dbus_bindings
|
message = dbus_bindings.Signal(OBJ_PATH, INTERFACE, signal)
|
||||||
message = dbus_bindings.Signal(OBJ_PATH, INTERFACE, signal)
|
i = message.get_iter(True)
|
||||||
i = message.get_iter(True)
|
i.append(arg)
|
||||||
i.append(arg)
|
self._connection.send(message)
|
||||||
self._connection.send(message)
|
|
||||||
else:
|
|
||||||
self.emit_signal(INTERFACE, signal, arg)
|
|
||||||
|
|
||||||
# signals
|
|
||||||
def VcardInfo(self, *vcard):
|
|
||||||
pass
|
|
||||||
|
|
||||||
def get_status(self, *args):
|
def get_status(self, *args):
|
||||||
'''get_status(account = None)
|
'''get_status(account = None)
|
||||||
|
@ -137,7 +130,7 @@ class SignalObject(DbusPrototype):
|
||||||
return helpers.get_global_show()
|
return helpers.get_global_show()
|
||||||
# return show for the given account
|
# return show for the given account
|
||||||
index = gajim.connections[account].connected
|
index = gajim.connections[account].connected
|
||||||
return STATUS_LIST[index]
|
return dbus.String(STATUS_LIST[index])
|
||||||
|
|
||||||
def get_status_message(self, *args):
|
def get_status_message(self, *args):
|
||||||
'''get_status(account = None)
|
'''get_status(account = None)
|
||||||
|
@ -150,7 +143,7 @@ class SignalObject(DbusPrototype):
|
||||||
return str(helpers.get_global_status())
|
return str(helpers.get_global_status())
|
||||||
# return show for the given account
|
# return show for the given account
|
||||||
status = gajim.connections[account].status
|
status = gajim.connections[account].status
|
||||||
return str(status)
|
return dbus.String(status)
|
||||||
|
|
||||||
|
|
||||||
def get_account_and_contact(self, account, jid):
|
def get_account_and_contact(self, account, jid):
|
||||||
|
@ -286,8 +279,8 @@ class SignalObject(DbusPrototype):
|
||||||
gajim.interface.systray.handle_first_event()
|
gajim.interface.systray.handle_first_event()
|
||||||
|
|
||||||
def contact_info(self, *args):
|
def contact_info(self, *args):
|
||||||
''' get vcard info for a contact. This method returns nothing.
|
''' get vcard info for a contact. Return cached value of the vcard.
|
||||||
You have to register the 'VcardInfo' signal to get the real vcard. '''
|
'''
|
||||||
[jid] = self._get_real_arguments(args, 1)
|
[jid] = self._get_real_arguments(args, 1)
|
||||||
if not isinstance(jid, unicode):
|
if not isinstance(jid, unicode):
|
||||||
jid = unicode(jid)
|
jid = unicode(jid)
|
||||||
|
@ -295,15 +288,12 @@ class SignalObject(DbusPrototype):
|
||||||
# FIXME: raise exception for missing argument (0.3+)
|
# FIXME: raise exception for missing argument (0.3+)
|
||||||
return None
|
return None
|
||||||
|
|
||||||
accounts = gajim.contacts.get_accounts()
|
cached_vcard = gajim.connections.values()[0].get_cached_vcard(jid)
|
||||||
|
if cached_vcard:
|
||||||
|
return self._get_dbus_struct(cached_vcard)
|
||||||
|
|
||||||
for account in accounts:
|
# return empty dict
|
||||||
contact = gajim.contacts.get_first_contact_from_jid(account, jid)
|
return dbus.Dictionary({}, signature="sv")
|
||||||
if contact:
|
|
||||||
self.vcard_account = account
|
|
||||||
gajim.connections[account].request_vcard(jid)
|
|
||||||
break
|
|
||||||
return None
|
|
||||||
|
|
||||||
def list_accounts(self, *args):
|
def list_accounts(self, *args):
|
||||||
''' list register accounts '''
|
''' list register accounts '''
|
||||||
|
@ -311,7 +301,7 @@ class SignalObject(DbusPrototype):
|
||||||
if result and len(result) > 0:
|
if result and len(result) > 0:
|
||||||
result_array = []
|
result_array = []
|
||||||
for account in result:
|
for account in result:
|
||||||
result_array.append(account)
|
result_array.append(dbus.String(account))
|
||||||
return result_array
|
return result_array
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
@ -322,17 +312,17 @@ class SignalObject(DbusPrototype):
|
||||||
# account is invalid
|
# account is invalid
|
||||||
return None
|
return None
|
||||||
account = gajim.connections[for_account]
|
account = gajim.connections[for_account]
|
||||||
result = {}
|
result = dbus.Dictionary({}, signature="ss")
|
||||||
index = account.connected
|
index = account.connected
|
||||||
result['status'] = STATUS_LIST[index]
|
result['status'] = dbus.String(STATUS_LIST[index])
|
||||||
result['name'] = account.name
|
result['name'] = dbus.String(account.name)
|
||||||
result['jid'] = gajim.get_jid_from_account(account.name)
|
result['jid'] = dbus.String(gajim.get_jid_from_account(account.name))
|
||||||
result['message'] = account.status
|
result['message'] = dbus.String(account.status)
|
||||||
result['priority'] = unicode(gajim.config.get_per('accounts',
|
result['priority'] = dbus.String(unicode(gajim.config.get_per('accounts',
|
||||||
account.name, 'priority'))
|
account.name, 'priority')))
|
||||||
result['resource'] = unicode(gajim.config.get_per('accounts',
|
result['resource'] = dbus.String(unicode(gajim.config.get_per('accounts',
|
||||||
account.name, 'resource'))
|
account.name, 'resource')))
|
||||||
return repr(result)
|
return result
|
||||||
|
|
||||||
def list_contacts(self, *args):
|
def list_contacts(self, *args):
|
||||||
''' list all contacts in the roster. If the first argument is specified,
|
''' list all contacts in the roster. If the first argument is specified,
|
||||||
|
@ -349,8 +339,8 @@ class SignalObject(DbusPrototype):
|
||||||
for account in accounts_to_search:
|
for account in accounts_to_search:
|
||||||
if account in accounts:
|
if account in accounts:
|
||||||
for jid in gajim.contacts.get_jid_list(account):
|
for jid in gajim.contacts.get_jid_list(account):
|
||||||
item = self._serialized_contacts(gajim.contacts.get_contact(
|
item = self._contacts_as_dbus_structure(
|
||||||
account, jid))
|
gajim.contacts.get_contact(account, jid))
|
||||||
if item:
|
if item:
|
||||||
result.append(item)
|
result.append(item)
|
||||||
else:
|
else:
|
||||||
|
@ -374,7 +364,7 @@ class SignalObject(DbusPrototype):
|
||||||
win.window.focus(long(time()))
|
win.window.focus(long(time()))
|
||||||
|
|
||||||
def prefs_list(self, *args):
|
def prefs_list(self, *args):
|
||||||
prefs_dict = {}
|
prefs_dict = dbus.Dictionary({}, signature="ss")
|
||||||
def get_prefs(data, name, path, value):
|
def get_prefs(data, name, path, value):
|
||||||
if value is None:
|
if value is None:
|
||||||
return
|
return
|
||||||
|
@ -383,9 +373,9 @@ class SignalObject(DbusPrototype):
|
||||||
for node in path:
|
for node in path:
|
||||||
key += node + "#"
|
key += node + "#"
|
||||||
key += name
|
key += name
|
||||||
prefs_dict[key] = unicode(value[1])
|
prefs_dict[dbus.String(key)] = dbus.String(value[1])
|
||||||
gajim.config.foreach(get_prefs)
|
gajim.config.foreach(get_prefs)
|
||||||
return repr(prefs_dict)
|
return prefs_dict
|
||||||
|
|
||||||
def prefs_store(self, *args):
|
def prefs_store(self, *args):
|
||||||
try:
|
try:
|
||||||
|
@ -453,28 +443,53 @@ class SignalObject(DbusPrototype):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def _get_real_arguments(self, args, desired_length):
|
def _get_real_arguments(self, args, desired_length):
|
||||||
# supresses the first 'message' argument, which is set in dbus 0.23
|
''' extend, or descend the length of args to match desired_length
|
||||||
if dbus_support.version[1] == 20:
|
'''
|
||||||
args=args[1:]
|
args = list(args)
|
||||||
|
for i in range(len(args)):
|
||||||
|
if args[i]:
|
||||||
|
args[i] = unicode(args[i])
|
||||||
|
else:
|
||||||
|
args[i] = None
|
||||||
if desired_length > 0:
|
if desired_length > 0:
|
||||||
args = list(args)
|
|
||||||
args.extend([None] * (desired_length - len(args)))
|
args.extend([None] * (desired_length - len(args)))
|
||||||
args = args[:desired_length]
|
args = args[:desired_length]
|
||||||
return args
|
return args
|
||||||
|
|
||||||
def _serialized_contacts(self, contacts):
|
def _get_dbus_struct(self, obj):
|
||||||
''' get info from list of Contact objects and create a serialized
|
''' recursively go through all the items and replace
|
||||||
dict for sending it over dbus '''
|
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):
|
||||||
|
''' get info from list of Contact objects and create dbus dict '''
|
||||||
if not contacts:
|
if not contacts:
|
||||||
return None
|
return None
|
||||||
prim_contact = None # primary contact
|
prim_contact = None # primary contact
|
||||||
for contact in contacts:
|
for contact in contacts:
|
||||||
if prim_contact == None or contact.priority > prim_contact.priority:
|
if prim_contact == None or contact.priority > prim_contact.priority:
|
||||||
prim_contact = contact
|
prim_contact = contact
|
||||||
contact_dict = {}
|
contact_dict = dbus.Dictionary({}, key_type=dbus.String, value_type=dbus.Variant)
|
||||||
contact_dict['name'] = prim_contact.name
|
contact_dict['name'] = dbus.Variant(dbus.String(prim_contact.name))
|
||||||
contact_dict['show'] = prim_contact.show
|
contact_dict['show'] = dbus.Variant(dbus.String(prim_contact.show))
|
||||||
contact_dict['jid'] = prim_contact.jid
|
contact_dict['jid'] = dbus.Variant(dbus.String(prim_contact.jid))
|
||||||
if prim_contact.keyID:
|
if prim_contact.keyID:
|
||||||
keyID = None
|
keyID = None
|
||||||
if len(prim_contact.keyID) == 8:
|
if len(prim_contact.keyID) == 8:
|
||||||
|
@ -485,10 +500,10 @@ class SignalObject(DbusPrototype):
|
||||||
contact_dict['openpgp'] = keyID
|
contact_dict['openpgp'] = keyID
|
||||||
contact_dict['resources'] = []
|
contact_dict['resources'] = []
|
||||||
for contact in contacts:
|
for contact in contacts:
|
||||||
contact_dict['resources'].append(tuple([contact.resource,
|
resource_props = [dbus.String(contact.resource), contact.priority, dbus.String(contact.status)]
|
||||||
contact.priority, contact.status]))
|
contact_dict['resources'].append(tuple(resource_props))
|
||||||
return repr(contact_dict)
|
contact_dict['resources'] = dbus.Variant(contact_dict['resources'])
|
||||||
|
return contact_dict
|
||||||
|
|
||||||
if dbus_support.version[1] >= 30 and dbus_support.version[1] <= 40:
|
if dbus_support.version[1] >= 30 and dbus_support.version[1] <= 40:
|
||||||
method = dbus.method
|
method = dbus.method
|
||||||
|
@ -497,26 +512,24 @@ class SignalObject(DbusPrototype):
|
||||||
method = dbus.service.method
|
method = dbus.service.method
|
||||||
signal = dbus.service.signal
|
signal = dbus.service.signal
|
||||||
|
|
||||||
if dbus_support.version[1] >= 30:
|
# prevent using decorators, because they are not supported
|
||||||
# prevent using decorators, because they are not supported
|
# on python < 2.4
|
||||||
# on python < 2.4
|
# FIXME: use decorators when python2.3 (and dbus 0.23) is OOOOOOLD
|
||||||
# FIXME: use decorators when python2.3 (and dbus 0.23) is OOOOOOLD
|
toggle_roster_appearance = method(INTERFACE)(toggle_roster_appearance)
|
||||||
toggle_roster_appearance = method(INTERFACE)(toggle_roster_appearance)
|
list_contacts = method(INTERFACE)(list_contacts)
|
||||||
list_contacts = method(INTERFACE)(list_contacts)
|
list_accounts = method(INTERFACE)(list_accounts)
|
||||||
list_accounts = method(INTERFACE)(list_accounts)
|
show_next_unread = method(INTERFACE)(show_next_unread)
|
||||||
show_next_unread = method(INTERFACE)(show_next_unread)
|
change_status = method(INTERFACE)(change_status)
|
||||||
change_status = method(INTERFACE)(change_status)
|
open_chat = method(INTERFACE)(open_chat)
|
||||||
open_chat = method(INTERFACE)(open_chat)
|
contact_info = method(INTERFACE)(contact_info)
|
||||||
contact_info = method(INTERFACE)(contact_info)
|
send_message = method(INTERFACE)(send_message)
|
||||||
send_message = method(INTERFACE)(send_message)
|
send_file = method(INTERFACE)(send_file)
|
||||||
send_file = method(INTERFACE)(send_file)
|
prefs_list = method(INTERFACE)(prefs_list)
|
||||||
VcardInfo = signal(INTERFACE)(VcardInfo)
|
prefs_put = method(INTERFACE)(prefs_put)
|
||||||
prefs_list = method(INTERFACE)(prefs_list)
|
prefs_del = method(INTERFACE)(prefs_del)
|
||||||
prefs_put = method(INTERFACE)(prefs_put)
|
prefs_store = method(INTERFACE)(prefs_store)
|
||||||
prefs_del = method(INTERFACE)(prefs_del)
|
remove_contact = method(INTERFACE)(remove_contact)
|
||||||
prefs_store = method(INTERFACE)(prefs_store)
|
add_contact = method(INTERFACE)(add_contact)
|
||||||
remove_contact = method(INTERFACE)(remove_contact)
|
get_status = method(INTERFACE)(get_status)
|
||||||
add_contact = method(INTERFACE)(add_contact)
|
get_status_message = method(INTERFACE)(get_status_message)
|
||||||
get_status = method(INTERFACE)(get_status)
|
account_info = method(INTERFACE)(account_info)
|
||||||
get_status_message = method(INTERFACE)(get_status_message)
|
|
||||||
account_info = method(INTERFACE)(account_info)
|
|
||||||
|
|
Loading…
Reference in New Issue