diff --git a/src/common/connection_handlers.py b/src/common/connection_handlers.py index f66ea1a24..d2959faff 100644 --- a/src/common/connection_handlers.py +++ b/src/common/connection_handlers.py @@ -1070,12 +1070,14 @@ class ConnectionVcard: self.get_metacontacts() del self.awaiting_answers[id] - + def _vCardCB(self, con, vc): '''Called when we receive a vCard Parse the vCard and send it to plugins''' if not vc.getTag('vCard'): return + if not vc.getTag('vCard').getNamespace() == common.xmpp.NS_VCARD: + return frm_iq = vc.getFrom() our_jid = gajim.get_jid_from_account(self.name) resource = '' @@ -1084,75 +1086,74 @@ class ConnectionVcard: frm, resource = gajim.get_room_and_nick_from_fjid(who) else: who = frm = our_jid - if vc.getTag('vCard').getNamespace() == common.xmpp.NS_VCARD: - card = vc.getChildren()[0] - vcard = self.node_to_dict(card) - photo_decoded = None - if vcard.has_key('PHOTO') and isinstance(vcard['PHOTO'], dict) and \ - vcard['PHOTO'].has_key('BINVAL'): - photo = vcard['PHOTO']['BINVAL'] - try: - photo_decoded = base64.decodestring(photo) - avatar_sha = sha.sha(photo_decoded).hexdigest() - except: - avatar_sha = '' - else: + card = vc.getChildren()[0] + vcard = self.node_to_dict(card) + photo_decoded = None + if vcard.has_key('PHOTO') and isinstance(vcard['PHOTO'], dict) and \ + vcard['PHOTO'].has_key('BINVAL'): + photo = vcard['PHOTO']['BINVAL'] + try: + photo_decoded = base64.decodestring(photo) + avatar_sha = sha.sha(photo_decoded).hexdigest() + except: avatar_sha = '' + else: + avatar_sha = '' + if avatar_sha: + card.getTag('PHOTO').setTagData('SHA', avatar_sha) + + # Save it to file + self.save_vcard_to_hd(who, card) + # Save the decoded avatar to a separate file too, and generate files for dbus notifications + puny_jid = helpers.sanitize_filename(frm) + puny_nick = None + begin_path = os.path.join(gajim.AVATAR_PATH, puny_jid) + if frm in self.room_jids: + puny_nick = helpers.sanitize_filename(resource) + # create folder if needed + if not os.path.isdir(begin_path): + os.mkdir(begin_path, 0700) + begin_path = os.path.join(begin_path, puny_nick) + if photo_decoded: + avatar_file = begin_path + '_notif_size_colored.png' + if frm == our_jid and avatar_sha != self.vcard_sha: + gajim.interface.save_avatar_files(frm, photo_decoded, puny_nick) + elif frm != our_jid and (not os.path.exists(avatar_file) or \ + not self.vcard_shas.has_key(frm) or \ + avatar_sha != self.vcard_shas[frm]): + gajim.interface.save_avatar_files(frm, photo_decoded, puny_nick) + else: + for ext in ('.jpeg', '.png', '_notif_size_bw.png', + '_notif_size_colored.png'): + path = begin_path + ext + if os.path.isfile(path): + os.remove(path) + + if frm != our_jid: if avatar_sha: - card.getTag('PHOTO').setTagData('SHA', avatar_sha) + self.vcard_shas[frm] = avatar_sha + elif self.vcard_shas.has_key(frm): + del self.vcard_shas[frm] - # Save it to file - self.save_vcard_to_hd(who, card) - # Save the decoded avatar to a separate file too, and generate files for dbus notifications - puny_jid = helpers.sanitize_filename(frm) - puny_nick = None - begin_path = os.path.join(gajim.AVATAR_PATH, puny_jid) - if frm in self.room_jids: - puny_nick = helpers.sanitize_filename(resource) - # create folder if needed - if not os.path.isdir(begin_path): - os.mkdir(begin_path, 0700) - begin_path = os.path.join(begin_path, puny_nick) - if photo_decoded: - avatar_file = begin_path + '_notif_size_colored.png' - if frm == our_jid and avatar_sha != self.vcard_sha: - gajim.interface.save_avatar_files(frm, photo_decoded, puny_nick) - elif frm != our_jid and (not os.path.exists(avatar_file) or \ - not self.vcard_shas.has_key(frm) or \ - avatar_sha != self.vcard_shas[frm]): - gajim.interface.save_avatar_files(frm, photo_decoded, puny_nick) - else: - for ext in ('.jpeg', '.png', '_notif_size_bw.png', - '_notif_size_colored.png'): - path = begin_path + ext - if os.path.isfile(path): - os.remove(path) - - if frm != our_jid: - if avatar_sha: - self.vcard_shas[frm] = avatar_sha - elif self.vcard_shas.has_key(frm): - del self.vcard_shas[frm] - - vcard['jid'] = frm - vcard['resource'] = resource - if frm == our_jid: - self.dispatch('MYVCARD', vcard) - # we re-send our presence with sha if has changed and if we are - # not invisible - if self.vcard_sha == avatar_sha: - return - self.vcard_sha = avatar_sha - if STATUS_LIST[self.connected] == 'invisible': - return - sshow = helpers.get_xmpp_show(STATUS_LIST[self.connected]) - p = common.xmpp.Presence(typ = None, priority = self.priority, - show = sshow, status = self.status) - p = self.add_sha(p) - self.connection.send(p) - else: - self.dispatch('VCARD', vcard) + vcard['jid'] = frm + vcard['resource'] = resource + if frm == our_jid: + self.dispatch('MYVCARD', vcard) + # we re-send our presence with sha if has changed and if we are + # not invisible + if self.vcard_sha == avatar_sha: + return + self.vcard_sha = avatar_sha + if STATUS_LIST[self.connected] == 'invisible': + return + sshow = helpers.get_xmpp_show(STATUS_LIST[self.connected]) + p = common.xmpp.Presence(typ = None, priority = self.priority, + show = sshow, status = self.status) + p = self.add_sha(p) + self.connection.send(p) + else: + self.dispatch('VCARD', vcard) class ConnectionHandlers(ConnectionVcard, ConnectionBytestream, ConnectionDisco, ConnectionCommands, ConnectionPubSub): def __init__(self): @@ -1653,7 +1654,7 @@ class ConnectionHandlers(ConnectionVcard, ConnectionBytestream, ConnectionDisco, errmsg, errcode)) if not ptype or ptype == 'unavailable': if gajim.config.get('log_contact_status_changes') and self.name\ - not in no_log_for and jid_stripped not in no_log_for: + not in no_log_for and jid_stripped not in no_log_for: gc_c = gajim.contacts.get_gc_contact(self.name, jid_stripped, resource) st = status or '' if gc_c: diff --git a/src/tooltips.py b/src/tooltips.py index 708c3421f..39ba33394 100644 --- a/src/tooltips.py +++ b/src/tooltips.py @@ -615,13 +615,13 @@ class FileTransfersTooltip(BaseTooltip): label.set_alignment(0, 0) label.set_markup(property[0]) ft_table.attach(label, 1, 2, current_row, current_row + 1, - gtk.FILL, gtk.FILL, 0, 0) + gtk.FILL, gtk.FILL, 0, 0) label = gtk.Label() label.set_alignment(0, 0) label.set_line_wrap(True) label.set_markup(property[1]) ft_table.attach(label, 2, 3, current_row, current_row + 1, - gtk.EXPAND | gtk.FILL, gtk.FILL, 0, 0) + gtk.EXPAND | gtk.FILL, gtk.FILL, 0, 0) self.win.add(ft_table)