vcard is now fixed: we use lists for ADR, TEL EMAIL entry cause we can have several

This commit is contained in:
Yann Leboulanger 2005-06-07 08:50:47 +00:00
parent a1858c9517
commit ce07cfe759
2 changed files with 68 additions and 46 deletions

View File

@ -174,12 +174,20 @@ class Connection:
if vc.getTag('vCard').getNamespace() == common.xmpp.NS_VCARD: if vc.getTag('vCard').getNamespace() == common.xmpp.NS_VCARD:
card = vc.getChildren()[0] card = vc.getChildren()[0]
for info in card.getChildren(): for info in card.getChildren():
if info.getChildren() == []: name = info.getName()
vcard[info.getName()] = info.getData() if name in ['ADR', 'TEL', 'EMAIL']: # we can have several
else: if not vcard.has_key(name):
vcard[info.getName()] = {} vcard[name] = []
entry = {}
for c in info.getChildren(): for c in info.getChildren():
vcard[info.getName()][c.getName()] = c.getData() entry[c.getName()] = c.getData()
vcard[name].append(entry)
elif info.getChildren() == []:
vcard[name] = info.getData()
else:
vcard[name] = {}
for c in info.getChildren():
vcard[name][c.getName()] = c.getData()
if vc.getID() in self.myVCardID: if vc.getID() in self.myVCardID:
self.myVCardID.remove(vc.getID()) self.myVCardID.remove(vc.getID())
self.dispatch('MYVCARD', vcard) self.dispatch('MYVCARD', vcard)
@ -893,22 +901,20 @@ class Connection:
def send_vcard(self, vcard): def send_vcard(self, vcard):
if not self.connection: if not self.connection:
return return
print vcard
iq = common.xmpp.Iq(typ = 'set') iq = common.xmpp.Iq(typ = 'set')
iq2 = iq.setTag(common.xmpp.NS_VCARD + ' vCard') iq2 = iq.setTag(common.xmpp.NS_VCARD + ' vCard')
for i in vcard.keys(): for i in vcard:
if i == 'jid': if i == 'jid':
continue continue
if type(vcard[i]) == type({}): if type(vcard[i]) == type({}):
for j in vcard[i].keys():
if type(vcard[i][j]) == type({}):
iq3 = iq2.addChild(i)
iq3.addChild(j)
for k in vcard[i][j]:
iq3.addChild(k).setData(vcard[i][j][k])
else:
iq3 = iq2.addChild(i) iq3 = iq2.addChild(i)
for j in vcard[i]:
iq3.addChild(j).setData(vcard[i][j]) iq3.addChild(j).setData(vcard[i][j])
elif type(vcard[i]) == type([]):
for j in vcard[i]:
iq3 = iq2.addChild(i)
for k in j:
iq3.addChild(k).setData(j[k])
else: else:
iq2.addChild(i).setData(vcard[i]) iq2.addChild(i).setData(vcard[i])
self.connection.send(iq) self.connection.send(iq)

View File

@ -135,7 +135,6 @@ class Vcard_window:
def set_values(self, vcard): def set_values(self, vcard):
for i in vcard.keys(): for i in vcard.keys():
if type(vcard[i]) == type({}):
if i == 'PHOTO': if i == 'PHOTO':
img_decoded = None img_decoded = None
if vcard[i].has_key('BINVAL'): if vcard[i].has_key('BINVAL'):
@ -161,13 +160,16 @@ class Vcard_window:
image = self.xml.get_widget('PHOTO_image') image = self.xml.get_widget('PHOTO_image')
image.set_from_pixbuf(pixbuf) image.set_from_pixbuf(pixbuf)
continue continue
add_on = ''
if i == 'ADR' or i == 'TEL' or i == 'EMAIL': if i == 'ADR' or i == 'TEL' or i == 'EMAIL':
for entry in vcard[i]:
add_on = '_HOME' add_on = '_HOME'
if 'WORK' in vcard[i]: if 'WORK' in entry:
add_on = '_WORK' add_on = '_WORK'
for j in entry.keys():
self.set_value(i + add_on + '_' + j + '_entry', entry[j])
if type(vcard[i]) == type({}):
for j in vcard[i].keys(): for j in vcard[i].keys():
self.set_value(i + add_on + '_' + j + '_entry', vcard[i][j]) self.set_value(i + '_' + j + '_entry', vcard[i][j])
else: else:
if i == 'DESC': if i == 'DESC':
self.xml.get_widget('DESC_textview').get_buffer().set_text( self.xml.get_widget('DESC_textview').get_buffer().set_text(
@ -242,6 +244,19 @@ class Vcard_window:
'''Add an information to the vCard dictionary''' '''Add an information to the vCard dictionary'''
entries = entry.split('_') entries = entry.split('_')
loc = vcard loc = vcard
if len(entries) == 3: # We need to use lists
if not loc.has_key(entries[0]):
loc[entries[0]] = []
found = False
for e in loc[entries[0]]:
if entries[1] in e:
found = True
break
if found:
e[entries[2]] = txt
else:
loc[entries[0]].append({entries[1]: '', entries[2]: txt})
return vcard
while len(entries) > 1: while len(entries) > 1:
if not loc.has_key(entries[0]): if not loc.has_key(entries[0]):
loc[entries[0]] = {} loc[entries[0]] = {}
@ -306,6 +321,7 @@ class Vcard_window:
for e in entries: for e in entries:
self.xml.get_widget(e + '_entry').set_text('') self.xml.get_widget(e + '_entry').set_text('')
self.xml.get_widget('DESC_textview').get_buffer().set_text('') self.xml.get_widget('DESC_textview').get_buffer().set_text('')
self.xml.get_widget('PHOTO_image').set_from_pixbuf(None)
gajim.connections[self.account].request_vcard(self.jid) gajim.connections[self.account].request_vcard(self.jid)
else: else:
Error_dialog(_('You are not connected to the server'), Error_dialog(_('You are not connected to the server'),