vcard is now fixed: we use lists for ADR, TEL EMAIL entry cause we can have several
This commit is contained in:
parent
a1858c9517
commit
ce07cfe759
|
@ -174,12 +174,20 @@ class Connection:
|
|||
if vc.getTag('vCard').getNamespace() == common.xmpp.NS_VCARD:
|
||||
card = vc.getChildren()[0]
|
||||
for info in card.getChildren():
|
||||
if info.getChildren() == []:
|
||||
vcard[info.getName()] = info.getData()
|
||||
else:
|
||||
vcard[info.getName()] = {}
|
||||
name = info.getName()
|
||||
if name in ['ADR', 'TEL', 'EMAIL']: # we can have several
|
||||
if not vcard.has_key(name):
|
||||
vcard[name] = []
|
||||
entry = {}
|
||||
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:
|
||||
self.myVCardID.remove(vc.getID())
|
||||
self.dispatch('MYVCARD', vcard)
|
||||
|
@ -893,22 +901,20 @@ class Connection:
|
|||
def send_vcard(self, vcard):
|
||||
if not self.connection:
|
||||
return
|
||||
print vcard
|
||||
iq = common.xmpp.Iq(typ = 'set')
|
||||
iq2 = iq.setTag(common.xmpp.NS_VCARD + ' vCard')
|
||||
for i in vcard.keys():
|
||||
for i in vcard:
|
||||
if i == 'jid':
|
||||
continue
|
||||
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)
|
||||
for j in vcard[i]:
|
||||
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:
|
||||
iq2.addChild(i).setData(vcard[i])
|
||||
self.connection.send(iq)
|
||||
|
|
24
src/vcard.py
24
src/vcard.py
|
@ -135,7 +135,6 @@ class Vcard_window:
|
|||
|
||||
def set_values(self, vcard):
|
||||
for i in vcard.keys():
|
||||
if type(vcard[i]) == type({}):
|
||||
if i == 'PHOTO':
|
||||
img_decoded = None
|
||||
if vcard[i].has_key('BINVAL'):
|
||||
|
@ -161,13 +160,16 @@ class Vcard_window:
|
|||
image = self.xml.get_widget('PHOTO_image')
|
||||
image.set_from_pixbuf(pixbuf)
|
||||
continue
|
||||
add_on = ''
|
||||
if i == 'ADR' or i == 'TEL' or i == 'EMAIL':
|
||||
for entry in vcard[i]:
|
||||
add_on = '_HOME'
|
||||
if 'WORK' in vcard[i]:
|
||||
if 'WORK' in entry:
|
||||
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():
|
||||
self.set_value(i + add_on + '_' + j + '_entry', vcard[i][j])
|
||||
self.set_value(i + '_' + j + '_entry', vcard[i][j])
|
||||
else:
|
||||
if i == 'DESC':
|
||||
self.xml.get_widget('DESC_textview').get_buffer().set_text(
|
||||
|
@ -242,6 +244,19 @@ class Vcard_window:
|
|||
'''Add an information to the vCard dictionary'''
|
||||
entries = entry.split('_')
|
||||
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:
|
||||
if not loc.has_key(entries[0]):
|
||||
loc[entries[0]] = {}
|
||||
|
@ -306,6 +321,7 @@ class Vcard_window:
|
|||
for e in entries:
|
||||
self.xml.get_widget(e + '_entry').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)
|
||||
else:
|
||||
Error_dialog(_('You are not connected to the server'),
|
||||
|
|
Loading…
Reference in New Issue