fixed show vcard info

This commit is contained in:
Dimitur Kirov 2005-09-06 13:17:10 +00:00
parent d90801de18
commit c99093c203
3 changed files with 23 additions and 42 deletions

View File

@ -38,10 +38,11 @@ _ = i18n._
i18n.init()
def send_error(error_message):
''' Writes error message to stderr and exits '''
sys.stderr.write(error_message + '\n')
sys.stderr.flush()
sys.exit(1)
''' Writes error message to stderr and exits '''
sys.stderr.write(error_message + '\n')
sys.stderr.flush()
sys.exit(1)
try:
import dbus
except:
@ -155,7 +156,6 @@ using this account'), False)
sys.argv[1] not in self.commands.keys(): # no args or bad args
send_error(self.compose_help())
self.command = sys.argv[1]
if self.command == 'help':
if self.argv_len == 3:
print self.help_on_command(sys.argv[2])
@ -172,7 +172,7 @@ using this account'), False)
try:
id = self.sbus.add_signal_receiver(self.show_vcard_info,
'VcardInfo', INTERFACE, SERVICE, OBJ_PATH)
except:
except Exception, e:
send_error(_('Service not available'))
res = self.call_remote_method()
@ -222,7 +222,7 @@ Please specify account for sending the message.') % sys.argv[2])
self.service = self.sbus.get_service(SERVICE)
interface = self.service.get_object(OBJ_PATH, INTERFACE)
else:
send_error(_('Unknown D-Bus version: %s') % _version)
send_error(_('Unknown D-Bus version: %s') % _version[1])
# get the function asked
self.method = interface.__getattr__(self.command)
@ -296,6 +296,8 @@ Please specify account for sending the message.') % sys.argv[2])
res += self.print_info(level+1, items)
if res != '':
ret_str += '\t' + res
elif type(val) == dict:
ret_str += self.print_info(level+1, val)
ret_str = '%s(%s)\n' % (spacing, ret_str[1:])
elif isinstance(prop_dict, dict):
for key in prop_dict.keys():
@ -315,8 +317,6 @@ Please specify account for sending the message.') % sys.argv[2])
res = self.print_info(level+1, val)
if res != '':
ret_str += '%s%s: \n%s' % (spacing, key, res)
else:
self.send_warning(_('Unknown type %s ') % type(val))
return ret_str
def unrepr(self, serialized_data):
@ -441,13 +441,12 @@ Please specify account for sending the message.') % sys.argv[2])
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(show_vcard_info, 'VcardInfo',
self.sbus.remove_signal_receiver(self.show_vcard_info, 'VcardInfo',
INTERFACE, SERVICE, OBJ_PATH)
gtk.main_quit()
@ -463,7 +462,7 @@ Type "%s help %s" for more info') % (args[argv_len][0], BASENAME, self.command))
def gtk_quit(self):
if _version[1] >= 41:
self.sbus.remove_signal_receiver(show_vcard_info, 'VcardInfo',
self.sbus.remove_signal_receiver(self.show_vcard_info, 'VcardInfo',
INTERFACE, SERVICE, OBJ_PATH)
gtk.main_quit()
@ -488,5 +487,6 @@ Type "%s help %s" for more info') % (args[argv_len][0], BASENAME, self.command))
send_error(_('Service not available'))
return None
if __name__ == '__main__':
GajimRemote()

View File

@ -159,7 +159,6 @@ class Interface:
gajim.connections[account].build_http_auth_answer(data[2], answer)
def handle_event_error_answer(self, account, array):
#('ERROR_ANSWER', account, (id, jid_from. errmsg, errcode))
id, jid_from, errmsg, errcode = array
if unicode(errcode) in ['403', '406'] and id:
# show the error dialog
@ -186,10 +185,10 @@ class Interface:
(jid_from, file_props))
conn.disconnect_transfer(file_props)
return
#('ERROR_ANSWER', account, (id, jid_from. errmsg, errcode))
if jid_from in self.windows[account]['gc']:
self.windows[account]['gc'][jid_from].print_conversation(
_('Error %s: %s') % (array[2], array[1]), jid_from)
'Error %s: %s' % (array[2], array[1]), jid_from)
def handle_event_con_type(self, account, con_type):
# ('CON_TYPE', account, con_type) which can be 'ssl', 'tls', 'tcp'
@ -200,8 +199,6 @@ class Interface:
def handle_event_status(self, account, status): # OUR status
#('STATUS', account, status)
if status == 'connecting':
self.roster.set_connecting_state(account)
if status != 'offline':
gobject.timeout_add(30000, self.allow_notif, account)
else:
@ -384,10 +381,9 @@ class Interface:
not gajim.contacts[account].has_key(jid):
return
# Handle chat states
contact = gajim.get_first_contact_instance_from_jid(account, jid)
if self.windows[account]['chats'].has_key(jid):
chat_win = self.windows[account]['chats'][jid]
contact = gajim.get_first_contact_instance_from_jid(account, jid)
if chatstate is not None: # he sent us reply, so he supports jep85
if contact.chatstate == 'ask': # we were jep85 disco?
contact.chatstate = 'active' # no more
@ -396,10 +392,6 @@ class Interface:
else:
# got no valid jep85 answer, peer does not support it
contact.chatstate = False
else:
# Brand new message, incoming.
if chatstate == 'active':
contact.chatstate = chatstate
if not array[1]: #empty message text
return
@ -618,6 +610,7 @@ class Interface:
array['resource']]
if win:
win.set_avatar(array)
self.remote.raise_signal('VcardInfo', (account, array))
def handle_event_os_info(self, account, array):
win = None

View File

@ -278,8 +278,9 @@ class SignalObject(DbusPrototype):
You have to register the 'VcardInfo' signal to get the real vcard. '''
if self.disabled:
return
[jid] = self._get_real_arguments(args, 1)
if not isinstance(jid, unicode):
jid = unicode(jid)
if not jid:
# FIXME: raise exception for missing argument (0.3+)
return None
@ -287,10 +288,8 @@ class SignalObject(DbusPrototype):
accounts = gajim.contacts.keys()
for account in accounts:
if gajim.contacts[account].has_key(jid):
if gajim.contacts[account].__contains__(jid):
self.vcard_account = account
gajim.connections[account].register_handler('VCARD',
self._receive_vcard)
gajim.connections[account].request_vcard(jid)
break
return None
@ -302,7 +301,10 @@ class SignalObject(DbusPrototype):
if gajim.contacts:
result = gajim.contacts.keys()
if result and len(result) > 0:
return result
result_array = []
for account in result:
result_array.append(account.encode('utf-8'))
return result_array
return None
@ -324,7 +326,6 @@ class SignalObject(DbusPrototype):
result.append(item)
else:
# 'for_account: is not recognised:',
# FIXME: there can be a return status for this [0.3+]
return None
else:
for account in gajim.contacts:
@ -358,19 +359,6 @@ class SignalObject(DbusPrototype):
return True
return False
def _receive_vcard(self,account, array):
if self.vcard_account:
gajim.connections[self.vcard_account].unregister_handler('VCARD',
self._receive_vcard)
self.unregistered_vcard = None
if self.disabled:
return
if _version[1] >=30:
self.VcardInfo(repr(array))
else:
self.emit_signal(INTERFACE, 'VcardInfo',
repr(array))
def _get_real_arguments(self, args, desired_length):
# supresses the first 'message' argument, which is set in dbus 0.23
if _version[1] == 20: