diff options
author | Niels De Graef <nielsdegraef@gmail.com> | 2023-03-03 09:28:41 +0100 |
---|---|---|
committer | Niels De Graef <nielsdegraef@gmail.com> | 2023-03-03 09:28:41 +0100 |
commit | bf3bd7d5955a3b7154ba600d9450ed2cc18afd47 (patch) | |
tree | 9c8dc66cd1694a2eab6b4db676379072d82c3db6 | |
parent | 84c6659cf8c0ef973ed0eaae921034c9a1491322 (diff) | |
download | gnome-contacts-bf3bd7d5955a3b7154ba600d9450ed2cc18afd47.tar.gz |
vcard: Parse TITLE/ORG propertiesnielsdg/role-vcard-support
So when we import vCard files that have those properites, we don't
forget about them.
-rw-r--r-- | src/io/contacts-io-vcard-parser.vala | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/src/io/contacts-io-vcard-parser.vala b/src/io/contacts-io-vcard-parser.vala index 3db9f56..fee20ee 100644 --- a/src/io/contacts-io-vcard-parser.vala +++ b/src/io/contacts-io-vcard-parser.vala @@ -52,6 +52,7 @@ public class Contacts.Io.VCardParser : Contacts.Io.Parser { debug ("Got %u attributes in this vcard", vcard_attrs.length ()); var contact = new Contact.empty (); + // For the structure of this switch-case, see RFC 6350 foreach (unowned E.VCardAttribute attr in vcard_attrs) { switch (attr.get_name ()) { // Identification Properties @@ -83,6 +84,13 @@ public class Contacts.Io.VCardParser : Contacts.Io.Parser { case E.EVC_EMAIL: handle_email (contact, attr); break; + // Organizational Properties + case E.EVC_TITLE: + handle_title (contact, attr); + break; + case E.EVC_ORG: + handle_org (contact, attr); + break; // Explanatory Properties case E.EVC_NOTE: handle_note (contact, attr); @@ -208,6 +216,49 @@ public class Contacts.Io.VCardParser : Contacts.Io.Parser { add_params (child, attr); } + private void handle_title (Contact contact, E.VCardAttribute attr) { + var title = attr.get_value (); + if (title == null || title == "") + return; + + // NOTE: we have handle this specially, since properties like + // TITLE, ORG etc can occur multiple times but there's no way to link them + // to each other. Just add a OrgRole once and ignore the others for now + var chunk = (BinChunk) contact.get_most_relevant_chunk ("roles", true); + if (chunk != null) { + var orgrole = (Contacts.OrgRole) chunk.get_item (0); + if (orgrole.role.title == "") + orgrole.role.title = title; + return; + } + + var child = add_chunk_child_for_property (contact, "roles"); + ((Contacts.OrgRole) child).role.title = title; + add_params (child, attr); + } + + private void handle_org (Contact contact, E.VCardAttribute attr) { + unowned var values = attr.get_values (); + unowned var org = values.data; + if (org == null || org == "") + return; + + // NOTE: we have handle this specially, since properties like + // TITLE, ORG etc can occur multiple times but there's no way to link them + // to each other. Just add a OrgRole once and ignore the others for now + var chunk = (BinChunk) contact.get_most_relevant_chunk ("roles", true); + if (chunk != null) { + var orgrole = (Contacts.OrgRole) chunk.get_item (0); + if (orgrole.role.organisation_name == "") + orgrole.role.organisation_name = org; + return; + } + + var child = add_chunk_child_for_property (contact, "roles"); + ((Contacts.OrgRole) child).role.organisation_name = org; + add_params (child, attr); + } + private void handle_note (Contact contact, E.VCardAttribute attr) { var note = attr.get_value (); if (note == null || note == "") |