diff --git a/src/plugins/export/ExportVCard.py b/src/plugins/export/ExportVCard.py index b82b4aacb..e66105646 100644 --- a/src/plugins/export/ExportVCard.py +++ b/src/plugins/export/ExportVCard.py @@ -49,7 +49,7 @@ log = logging.getLogger(".ExportVCard") from gen.ggettext import gettext as _ from ExportOptions import WriterOptionBox import const -from gen.lib import Date +from gen.lib import Date, Person from gen.lib.urltype import UrlType from gen.lib.eventtype import EventType from gen.display.name import displayer as _nd @@ -169,6 +169,7 @@ class VCardWriter(object): self.write_name(prname) self.write_sortstring(prname) self.write_nicknames(person, prname) + self.write_gender(person) self.write_birthdate(person) self.write_addresses(person) self.write_urls(person) @@ -250,6 +251,18 @@ class VCardWriter(object): if len(nicknames) > 0: self.writeln("NICKNAME:%s" % (','.join(self.esc(nicknames)))) + def write_gender(self, person): + """Write the X-GENDER property of a VCard (X- dropped in 4.0, we're at 3.0).""" + gender = person.get_gender() + gender_value = '' + if gender == Person.MALE: + gender_value = 'Male' + elif gender == Person.FEMALE: + gender_value = 'Female' + log.info("gender: %s -> %s" % (gender, gender_value)) + if gender_value: + self.writeln("X-GENDER:%s" % (gender_value)) + def write_birthdate(self, person): """Write the BDAY property of a VCard.""" birth_ref = person.get_birth_ref() diff --git a/src/plugins/import/ImportVCard.py b/src/plugins/import/ImportVCard.py index c2aa98f6f..47f56d40d 100644 --- a/src/plugins/import/ImportVCard.py +++ b/src/plugins/import/ImportVCard.py @@ -279,6 +279,10 @@ class VCardParser(object): self.add_url(fields, line_parts[1]) elif property_name == "EMAIL": self.add_email(fields, line_parts[1]) + elif property_name == "X-GENDER" or property_name == "GENDER": + # VCard 3.0 only has X-GENDER, GENDER is 4.0 syntax, + # but we want to be robust here. + self.add_gender(fields, line_parts[1]) elif property_name == "PRODID": # Included cause VCards made by Gramps have this prop. pass @@ -510,3 +514,17 @@ class VCardParser(object): url.set_type(gen.lib.UrlType(gen.lib.UrlType.EMAIL)) url.set_path(self.unesc(email)) self.person.add_url(url) + + def add_gender(self, fields, data): + """Read the GENDER property of a VCard.""" + gender_value = data.strip() + if gender_value: + gender_value = gender_value.upper() + gender_value = gender_value[0] + if gender_value == 'M': + gender = gen.lib.Person.MALE + elif gender_value == 'F': + gender = gen.lib.Person.FEMALE + else: + return + self.person.set_gender(gender)