~doctormo/dexter-rolodex/data-agnostic-cleanup

« back to all changes in this revision

Viewing changes to dexter/backend/utilities.py

  • Committer: Allen Lowe
  • Date: 2010-12-23 20:51:36 UTC
  • Revision ID: lallenlowe@gmail.com-20101223205136-vz6jmgjtyhb1sguo
made progress on bug 685069, im nicks have been implemented on the backend

Show diffs side-by-side

added added

removed removed

Lines of Context:
127
127
        notes = []
128
128
        emails = []
129
129
        addresses = []
 
130
        imnicks = []
130
131
        phones = []
131
132
 
132
133
        if hasattr(card, 'n'):
205
206
                    else:
206
207
                        phone_type = "Home"
207
208
                    phones.append((child.value.strip(), phone_type))
 
209
            if child.name == u'X-JABBER':
 
210
                if hasattr(child, 'value'):
 
211
                    nick_type = u"Jabber"
 
212
                    imnicks.append((child.value.strip(), nick_type))
208
213
        q.put([first_name, middle_name, last_name, organization, birthday, photo_path,
209
 
                emails, phones, addresses, notes], True, 2)
 
214
                emails, phones, addresses, imnicks, notes], True, 2)
210
215
 
211
216
 
212
217
def merge_contacts(contacts, dbus):
213
218
    GetEmails = dbus.get_dbus_method("GetEmails")
214
219
    GetPhones = dbus.get_dbus_method("GetPhones")
215
220
    GetAddresses = dbus.get_dbus_method("GetAddresses")
 
221
    GetIMNicks = dbus.get_dbus_method("GetIMNicks")
216
222
    GetNotes = dbus.get_dbus_method("GetNotes")
217
223
    CreateContact = dbus.get_dbus_method("CreateContact", dbus_interface='org.elementary.dexterserver')
218
224
    DeleteContact = dbus.get_dbus_method("DeleteContact")
225
231
    emails = []
226
232
    phones = []
227
233
    addresses = []
 
234
    imnicks = []
228
235
    note = u""
229
236
    for contact in contacts:
230
237
        if contact["first_name"] != "None":
274
281
                    address_exists = True
275
282
            if not address_exists:
276
283
                addresses.append(address)
 
284
        for imnick in GetIMNicks(int(contact["id"])):
 
285
            imnick_exists = False
 
286
            for item in imnicks:
 
287
                if imnick[0] == item[0]:
 
288
                    imnick_exists = True
 
289
            if not imnick_exists:
 
290
                imnicks.append(imnick)
277
291
        for anote in GetNotes(int(contact["id"])):
278
292
            if anote and anote.strip() != "None" and anote.strip() != "":
279
293
                note += (anote.strip() + "\n")
283
297
        data = {"first" : firstnames, "middle" : middlenames, "last" : lastnames,
284
298
                "org" : organizations, "birthday" : birthdays,
285
299
                "photo" : photo_path, "emails" : emails, "phones" : phones,
286
 
                "addresses" : addresses, "notes" : [note]}
 
300
                "addresses" : addresses, "imnicks" : imnicks, "notes" : [note]}
287
301
        return data
288
302
    else:
289
303
        if not firstnames:
298
312
            birthdays = ["None"]
299
313
        new_id = CreateContact(firstnames[0], middlenames[0], lastnames[0], 
300
314
                               organizations[0], birthdays[0], photo_path,
301
 
                               emails, phones, addresses, [note])
 
315
                               emails, phones, addresses, imnicks, [note])
302
316
        return int(new_id)