diff --git a/gramps/plugins/export/exportvcard.py b/gramps/plugins/export/exportvcard.py index 68ea9ca6e..d40a473a2 100644 --- a/gramps/plugins/export/exportvcard.py +++ b/gramps/plugins/export/exportvcard.py @@ -52,7 +52,7 @@ _ = glocale.translation.gettext from gramps.gui.plug.export import WriterOptionBox from gramps.gen.const import PROGRAM_NAME from gramps.version import VERSION -from gramps.gen.lib import Date +from gramps.gen.lib import Date, Person from gramps.gen.lib.urltype import UrlType from gramps.gen.lib.eventtype import EventType from gramps.gen.display.name import displayer as _nd @@ -171,6 +171,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) @@ -252,6 +253,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/gramps/plugins/importer/importvcard.py b/gramps/plugins/importer/importvcard.py index bc7b54b2d..74daa3084 100644 --- a/gramps/plugins/importer/importvcard.py +++ b/gramps/plugins/importer/importvcard.py @@ -278,6 +278,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 @@ -509,3 +513,17 @@ class VCardParser(object): url.set_type(UrlType(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)