better indentation

This commit is contained in:
Yann Leboulanger 2007-01-31 11:31:07 +00:00
parent 24ea9fe5a3
commit 5fc442b6f5
2 changed files with 70 additions and 69 deletions

View file

@ -1070,12 +1070,14 @@ class ConnectionVcard:
self.get_metacontacts() self.get_metacontacts()
del self.awaiting_answers[id] del self.awaiting_answers[id]
def _vCardCB(self, con, vc): def _vCardCB(self, con, vc):
'''Called when we receive a vCard '''Called when we receive a vCard
Parse the vCard and send it to plugins''' Parse the vCard and send it to plugins'''
if not vc.getTag('vCard'): if not vc.getTag('vCard'):
return return
if not vc.getTag('vCard').getNamespace() == common.xmpp.NS_VCARD:
return
frm_iq = vc.getFrom() frm_iq = vc.getFrom()
our_jid = gajim.get_jid_from_account(self.name) our_jid = gajim.get_jid_from_account(self.name)
resource = '' resource = ''
@ -1084,75 +1086,74 @@ class ConnectionVcard:
frm, resource = gajim.get_room_and_nick_from_fjid(who) frm, resource = gajim.get_room_and_nick_from_fjid(who)
else: else:
who = frm = our_jid who = frm = our_jid
if vc.getTag('vCard').getNamespace() == common.xmpp.NS_VCARD: card = vc.getChildren()[0]
card = vc.getChildren()[0] vcard = self.node_to_dict(card)
vcard = self.node_to_dict(card) photo_decoded = None
photo_decoded = None if vcard.has_key('PHOTO') and isinstance(vcard['PHOTO'], dict) and \
if vcard.has_key('PHOTO') and isinstance(vcard['PHOTO'], dict) and \ vcard['PHOTO'].has_key('BINVAL'):
vcard['PHOTO'].has_key('BINVAL'): photo = vcard['PHOTO']['BINVAL']
photo = vcard['PHOTO']['BINVAL'] try:
try: photo_decoded = base64.decodestring(photo)
photo_decoded = base64.decodestring(photo) avatar_sha = sha.sha(photo_decoded).hexdigest()
avatar_sha = sha.sha(photo_decoded).hexdigest() except:
except:
avatar_sha = ''
else:
avatar_sha = '' 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: 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 vcard['jid'] = frm
self.save_vcard_to_hd(who, card) vcard['resource'] = resource
# Save the decoded avatar to a separate file too, and generate files for dbus notifications if frm == our_jid:
puny_jid = helpers.sanitize_filename(frm) self.dispatch('MYVCARD', vcard)
puny_nick = None # we re-send our presence with sha if has changed and if we are
begin_path = os.path.join(gajim.AVATAR_PATH, puny_jid) # not invisible
if frm in self.room_jids: if self.vcard_sha == avatar_sha:
puny_nick = helpers.sanitize_filename(resource) return
# create folder if needed self.vcard_sha = avatar_sha
if not os.path.isdir(begin_path): if STATUS_LIST[self.connected] == 'invisible':
os.mkdir(begin_path, 0700) return
begin_path = os.path.join(begin_path, puny_nick) sshow = helpers.get_xmpp_show(STATUS_LIST[self.connected])
if photo_decoded: p = common.xmpp.Presence(typ = None, priority = self.priority,
avatar_file = begin_path + '_notif_size_colored.png' show = sshow, status = self.status)
if frm == our_jid and avatar_sha != self.vcard_sha: p = self.add_sha(p)
gajim.interface.save_avatar_files(frm, photo_decoded, puny_nick) self.connection.send(p)
elif frm != our_jid and (not os.path.exists(avatar_file) or \ else:
not self.vcard_shas.has_key(frm) or \ self.dispatch('VCARD', vcard)
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)
class ConnectionHandlers(ConnectionVcard, ConnectionBytestream, ConnectionDisco, ConnectionCommands, ConnectionPubSub): class ConnectionHandlers(ConnectionVcard, ConnectionBytestream, ConnectionDisco, ConnectionCommands, ConnectionPubSub):
def __init__(self): def __init__(self):
@ -1653,7 +1654,7 @@ class ConnectionHandlers(ConnectionVcard, ConnectionBytestream, ConnectionDisco,
errmsg, errcode)) errmsg, errcode))
if not ptype or ptype == 'unavailable': if not ptype or ptype == 'unavailable':
if gajim.config.get('log_contact_status_changes') and self.name\ 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) gc_c = gajim.contacts.get_gc_contact(self.name, jid_stripped, resource)
st = status or '' st = status or ''
if gc_c: if gc_c:

View file

@ -615,13 +615,13 @@ class FileTransfersTooltip(BaseTooltip):
label.set_alignment(0, 0) label.set_alignment(0, 0)
label.set_markup(property[0]) label.set_markup(property[0])
ft_table.attach(label, 1, 2, current_row, current_row + 1, 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 = gtk.Label()
label.set_alignment(0, 0) label.set_alignment(0, 0)
label.set_line_wrap(True) label.set_line_wrap(True)
label.set_markup(property[1]) label.set_markup(property[1])
ft_table.attach(label, 2, 3, current_row, current_row + 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) self.win.add(ft_table)