Example #1
0
File: ui.py Project: hongquan/LaTre
	def show_phonenumbers(self, contact):
		grid = Gtk.Box.new(Gtk.Orientation.VERTICAL, 5)
		# There is a bug in libebook that using Contact.get_poperty() does not
		# retrieve all phone numbers. So we will apply a trick here.
		all_numbers = set()    # All numbers found in vcard.
		tels = contact.get_attributes(ContactField.TEL)
		all_numbers = set([t.get_value() for t in tels])

		counted = set()      # Numbers get via Contact.get_poperty()
		for p in PHONE_PROPS:
			field = p.replace('-', '_')
			fid = Contact.field_id(field)
			value = contact.get_property(p)
			if not value or value == '' or value in counted:
				continue
			counted.add(value)
			name = Contact.pretty_name(fid)
			# Add to UI
			row = self.phonenumber_to_ui(name, value)
			grid.pack_start(row, False, True, 0)

		# Check the remain numbers missed by get_property(). This part won't be needed
		# when the libebook's bug is fixed.
		remains = (t for t in tels if t.get_value() not in counted)
		for attr in remains:
			type_params = attr.get_param('TYPE')
			if 'CELL' in type_params:
				name = Contact.pretty_name(ContactField.PHONE_MOBILE)
			else:
				name = Contact.pretty_name(ContactField.PHONE_OTHER)
			value = attr.get_value()
			row = self.phonenumber_to_ui(name, value)
			grid.pack_start(row, False, True, 0)

		return grid
Example #2
0
def contacts_from_files(files):
	vcards = set()
	with concurrent.futures.ThreadPoolExecutor(max_workers=5) as e:
		fts = [e.submit(vcards_from_file, f) for f in files]
	for f in concurrent.futures.as_completed(fts):
		if f.exception() is None:
			vcs = f.result()
			vcards = vcards.union(vcs)
	contacts = [Contact.new_from_vcard(v) for v in vcards]
	return contacts
Example #3
0
def merge_contacts(existing, pending):
	''' Update existing contact with detail from new one. '''
	dif_vcardfields = get_different_fields(existing, pending)
	for vcfield in dif_vcardfields:
		if vcfield == 'TEL':
			# Mix phone numbers from pending contact to existing contact
			existing = mix_phones(existing, pending)
		else:
			# Replace other fields of existing contact with pending's ones
			try:
				field = Contact.field_id_from_vcard(vcfield)
			except ValueError:
				logging.info('Field %s seems not to be supported', vcfield)
				continue
			new_attrs = pending.get_attributes(field)
			existing.set_attributes(field, new_attrs)
	abook.modify_contact_sync(existing, None)