cleanup in iter compare function (thx SF)

This commit is contained in:
Yann Leboulanger 2005-12-13 13:27:04 +00:00
parent ee0f764df0
commit b2d6cd9919
1 changed files with 31 additions and 29 deletions

View File

@ -2361,9 +2361,8 @@ _('If "%s" accepts this request you will know his or her status.') %jid)
name2 = model[iter2][C_NAME] name2 = model[iter2][C_NAME]
if not name1 or not name2: if not name1 or not name2:
return 0 return 0
else: name1 = name1.decode('utf-8')
name1 = name1.decode('utf-8') name2 = name2.decode('utf-8')
name2 = name2.decode('utf-8')
type1 = model[iter1][C_TYPE] type1 = model[iter1][C_TYPE]
type2 = model[iter2][C_TYPE] type2 = model[iter2][C_TYPE]
if type1 == 'group': if type1 == 'group':
@ -2377,40 +2376,43 @@ _('If "%s" accepts this request you will know his or her status.') %jid)
return -1 return -1
account1 = model[iter1][C_ACCOUNT] account1 = model[iter1][C_ACCOUNT]
account2 = model[iter2][C_ACCOUNT] account2 = model[iter2][C_ACCOUNT]
if account1 and account2: if not account1 or not account2:
account1 = account1.decode('utf-8') return 0
account2 = account2.decode('utf-8') account1 = account1.decode('utf-8')
jid1 = model[iter1][C_JID].decode('utf-8') account2 = account2.decode('utf-8')
jid2 = model[iter2][C_JID].decode('utf-8') jid1 = model[iter1][C_JID].decode('utf-8')
jid2 = model[iter2][C_JID].decode('utf-8')
if type1 == 'contact':
luser1 = gajim.contacts[account1][jid1]
name1 = luser1[0].name
if type2 == 'contact':
luser2 = gajim.contacts[account2][jid2]
name2 = luser2[0].name
# We first compare by show if sort_by_show is True # We first compare by show if sort_by_show is True
if type1 == 'contact' and type2 == 'contact' and \ if type1 == 'contact' and type2 == 'contact' and \
gajim.config.get('sort_by_show'): gajim.config.get('sort_by_show'):
if account1 and account2: # We an have contact without account cshow = {'online':0, 'chat': 1, 'away': 2, 'xa': 3, 'dnd': 4,
# during a short time ... why? 'invisible': 5, 'offline': 6, 'not in the roster': 7, 'error': 8}
luser1 = gajim.contacts[account1][jid1] s = self.get_show(luser1)
luser2 = gajim.contacts[account2][jid2] if s in cshow:
cshow = {'online':0, 'chat': 1, 'away': 2, 'xa': 3, 'dnd': 4, show1 = cshow[s]
'invisible': 5, 'offline': 6, 'not in the roster': 7, 'error': 8} else:
s = self.get_show(luser1) show1 = 9
if s in cshow: s = self.get_show(luser2)
show1 = cshow[s] if s in cshow:
else: show2 = cshow[s]
show1 = 9 else:
s = self.get_show(luser2) show2 = 9
if s in cshow: if show1 < show2:
show2 = cshow[s] return -1
else: elif show1 > show2:
show2 = 9 return 1
if show1 < show2:
return -1
elif show1 > show2:
return 1
# We compare names # We compare names
if name1.lower() < name2.lower(): if name1.lower() < name2.lower():
return -1 return -1
if name2.lower() < name1.lower(): if name2.lower() < name1.lower():
return 1 return 1
if type1 == 'contact' and type2 == 'contact' and account1 and account2: if type1 == 'contact' and type2 == 'contact':
# We compare account names # We compare account names
if account1.lower() < account2.lower(): if account1.lower() < account2.lower():
return -1 return -1