Additional contact's field handled in VCARD structure
PATCH 1/1 Additional contact's field handled in VCARD structure
After pulling contacts some fields weren't present in downloaded VCARD structure in spite of that these fields existed (not empty).
I added handling fields: BDAY, NICKNAME, URL, PHOTO and three fields grouped under ORG tag (Company, Department, Job Title).
To solve this problem extending number of columns and queries of database was needed especially. Of course fields mentioned above were added to phonebook_contact structure as char * type to save gained data
--- plugins/phonebook-tracker.c | 102 ++++++++++++++++++++++++++---------------- plugins/vcard.c | 96 ++++++++++++++++++++++++++++++++++++++++ plugins/vcard.h | 7 +++ 3 files changed, 166 insertions(+), 39 deletions(-)
plugins/phonebook-tracker.c +63 -39
@@ -43,14 +43,14 @@#define TRACKER_RESOURCES_INTERFACE "org.freedesktop.Tracker1.Resources"#define TRACKER_DEFAULT_CONTACT_ME "http://www.semanticdesktop.org/ontologies/2007/03/22/nco#default-contact-me" -#define CONTACTS_ID_COL 20 -#define PULL_QUERY_COL_AMOUNT 21 +#define CONTACTS_ID_COL 27 +#define PULL_QUERY_COL_AMOUNT 28#define COL_HOME_NUMBER 0#define COL_WORK_NUMBER 8#define COL_FAX_NUMBER 16 -#define COL_DATE 17 -#define COL_SENT 18 -#define COL_ANSWERED 19 +#define COL_DATE 24 +#define COL_SENT 25 +#define COL_ANSWERED 26#define CONTACTS_QUERY_ALL \ "SELECT ?v nco:fullname(?c) " \
@@ -59,8 +59,10 @@"nco:nameHonorificSuffix(?c) nco:emailAddress(?e) " \"nco:phoneNumber(?w) nco:pobox(?p) nco:extendedAddress(?p) " \"nco:streetAddress(?p) nco:locality(?p) nco:region(?p) " \ -"nco:postalcode(?p) nco:country(?p) ?f \"NOTACALL\" \"false\" " \ -"\"false\" ?c " \ +"nco:postalcode(?p) nco:country(?p) ?f nco:birthDate(?c) " \ +"nco:nickname(?c) nco:websiteUrl(?c) nco:photo(?c) " \ +"nco:fullname(?o) nco:department(?a) nco:role(?a) " \ +"\"NOTACALL\" \"false\" \"false\" ?c " \"WHERE { " \"?c a nco:PersonContact . " \"OPTIONAL { ?c nco:hasPhoneNumber ?h . \
@@ -75,9 +77,9 @@"}" \"OPTIONAL { ?c nco:hasEmailAddress ?e . } " \"OPTIONAL { ?c nco:hasPostalAddress ?p . } " \ -"OPTIONAL { " \ -"?c nco:hasAffiliation ?a . " \ -"?a nco:hasPhoneNumber ?w . " \ +"OPTIONAL { ?c nco:hasAffiliation ?a . " \ +"OPTIONAL { ?a nco:hasPhoneNumber ?w . } " \ +"OPTIONAL { ?a nco:org ?o . } " \"} " \"}"
@@ -102,8 +104,11 @@"nco:nameHonorificSuffix(?c) nco:emailAddress(?e) " \"nco:phoneNumber(?w) nco:pobox(?p) nco:extendedAddress(?p) " \"nco:streetAddress(?p) nco:locality(?p) nco:region(?p) " \ -"nco:postalcode(?p) nco:country(?p) ?f nmo:receivedDate(?call) " \ -"nmo:isSent(?call) nmo:isAnswered(?call) ?c " \ +"nco:postalcode(?p) nco:country(?p) ?f nco:birthDate(?c) " \ +"nco:nickname(?c) nco:websiteUrl(?c) nco:photo(?c) " \ +"nco:fullname(?o) nco:department(?a) nco:role(?a) " \ +"nmo:receivedDate(?call) nmo:isSent(?call) " \ +"nmo:isAnswered(?call) ?c " \"WHERE { " \"?call a nmo:Call ; " \"nmo:from ?c ; " \
@@ -118,9 +123,9 @@"} " \"OPTIONAL { ?c nco:hasEmailAddress ?e . } " \"OPTIONAL { ?c nco:hasPostalAddress ?p . } " \ -"OPTIONAL { " \ -"?c nco:hasAffiliation ?a . " \ -"?a nco:hasPhoneNumber ?w . " \ +"OPTIONAL { ?c nco:hasAffiliation ?a . " \ +"OPTIONAL { ?a nco:hasPhoneNumber ?w . } " \ +"OPTIONAL { ?a nco:org ?o . } " \"} " \"} ORDER BY DESC(nmo:receivedDate(?call))"
@@ -145,8 +150,11 @@"nco:nameHonorificSuffix(?c) nco:emailAddress(?e) " \"nco:phoneNumber(?w) nco:pobox(?p) nco:extendedAddress(?p) " \"nco:streetAddress(?p) nco:locality(?p) nco:region(?p) " \ -"nco:postalcode(?p) nco:country(?p) ?f nmo:receivedDate(?call) " \ -"nmo:isSent(?call) nmo:isAnswered(?call) ?c " \ +"nco:postalcode(?p) nco:country(?p) ?f nco:birthDate(?c) " \ +"nco:nickname(?c) nco:websiteUrl(?c) nco:photo(?c) " \ +"nco:fullname(?o) nco:department(?a) nco:role(?a) " \ +"nmo:receivedDate(?call) nmo:isSent(?call) " \ +"nmo:isAnswered(?call) ?c " \"WHERE { " \"?call a nmo:Call ; " \"nmo:from ?c ; " \
@@ -161,9 +169,9 @@"} " \"OPTIONAL { ?c nco:hasEmailAddress ?e . } " \"OPTIONAL { ?c nco:hasPostalAddress ?p . } " \ -"OPTIONAL { " \ -"?c nco:hasAffiliation ?a . " \ -"?a nco:hasPhoneNumber ?w . " \ +"OPTIONAL { ?c nco:hasAffiliation ?a . " \ +"OPTIONAL { ?a nco:hasPhoneNumber ?w . } " \ +"OPTIONAL { ?a nco:org ?o . } " \"} " \"} ORDER BY DESC(nmo:receivedDate(?call))"
@@ -188,8 +196,11 @@"nco:nameHonorificSuffix(?c) nco:emailAddress(?e) " \"nco:phoneNumber(?w) nco:pobox(?p) nco:extendedAddress(?p) " \"nco:streetAddress(?p) nco:locality(?p) nco:region(?p) " \ -"nco:postalcode(?p) nco:country(?p) ?f nmo:receivedDate(?call) " \ -"nmo:isSent(?call) nmo:isAnswered(?call) ?c " \ +"nco:postalcode(?p) nco:country(?p) ?f nco:birthDate(?c) " \ +"nco:nickname(?c) nco:websiteUrl(?c) nco:photo(?c) " \ +"nco:fullname(?o) nco:department(?a) nco:role(?a) " \ +"nmo:receivedDate(?call) nmo:isSent(?call) " \ +"nmo:isAnswered(?call) ?c " \"WHERE { " \"?call a nmo:Call ; " \"nmo:to ?c ; " \
@@ -203,9 +214,9 @@"} " \"OPTIONAL { ?c nco:hasEmailAddress ?e . } " \"OPTIONAL { ?c nco:hasPostalAddress ?p . } " \ -"OPTIONAL { " \ -"?c nco:hasAffiliation ?a . " \ -"?a nco:hasPhoneNumber ?w . " \ +"OPTIONAL { ?c nco:hasAffiliation ?a . " \ +"OPTIONAL { ?a nco:hasPhoneNumber ?w . } " \ +"OPTIONAL { ?a nco:org ?o . } " \"} " \"} ORDER BY DESC(nmo:sentDate(?call))"
@@ -229,8 +240,11 @@"nco:nameHonorificSuffix(?c) nco:emailAddress(?e) " \"nco:phoneNumber(?w) nco:pobox(?p) nco:extendedAddress(?p) " \"nco:streetAddress(?p) nco:locality(?p) nco:region(?p) " \ -"nco:postalcode(?p) nco:country(?p) ?f nmo:receivedDate(?call) " \ -"nmo:isSent(?call) nmo:isAnswered(?call) ?c " \ +"nco:postalcode(?p) nco:country(?p) ?f nco:birthDate(?c) " \ +"nco:nickname(?c) nco:websiteUrl(?c) nco:photo(?c) " \ +"nco:fullname(?o) nco:department(?a) nco:role(?a) " \ +"nmo:receivedDate(?call) nmo:isSent(?call) " \ +"nmo:isAnswered(?call) ?c " \"WHERE { " \"{ " \"?call a nmo:Call ; " \
@@ -245,9 +259,9 @@"} " \"OPTIONAL { ?c nco:hasEmailAddress ?e . } " \"OPTIONAL { ?c nco:hasPostalAddress ?p . } " \ -"OPTIONAL { " \ -"?c nco:hasAffiliation ?a . " \ -"?a nco:hasPhoneNumber ?w . " \ +"OPTIONAL { ?c nco:hasAffiliation ?a . " \ +"OPTIONAL { ?a nco:hasPhoneNumber ?w . } " \ +"OPTIONAL { ?a nco:org ?o . } " \"} " \"} UNION { " \"?call a nmo:Call ; " \
@@ -262,9 +276,9 @@"} " \"OPTIONAL { ?c nco:hasEmailAddress ?e . } " \"OPTIONAL { ?c nco:hasPostalAddress ?p . } " \ -"OPTIONAL { " \ -"?c nco:hasAffiliation ?a . " \ -"?a nco:hasPhoneNumber ?w . " \ +"OPTIONAL { ?c nco:hasAffiliation ?a . " \ +"OPTIONAL { ?a nco:hasPhoneNumber ?w . } " \ +"OPTIONAL { ?a nco:org ?o . } " \"} " \"} } ORDER BY DESC(nmo:receivedDate(?call))"
@@ -295,8 +309,10 @@"nco:nameHonorificSuffix(<%s>) nco:emailAddress(?e) " \"nco:phoneNumber(?w) nco:pobox(?p) nco:extendedAddress(?p) " \"nco:streetAddress(?p) nco:locality(?p) nco:region(?p) " \ -"nco:postalcode(?p) nco:country(?p) ?f \"NOTACALL\" \"false\" " \ -"\"false\" <%s> " \ +"nco:postalcode(?p) nco:country(?p) ?f nco:birthDate(<%s>) " \ +"nco:nickname(<%s>) nco:websiteUrl(<%s>) nco:photo(<%s>) " \ +"nco:fullname(?o) nco:department(?a) nco:role(?a) " \ +"\"NOTACALL\" \"false\" \"false\" <%s> " \"WHERE { " \"<%s> a nco:Contact . " \"OPTIONAL { <%s> nco:hasPhoneNumber ?h . \
@@ -311,9 +327,9 @@"}" \"OPTIONAL { <%s> nco:hasEmailAddress ?e . } " \"OPTIONAL { <%s> nco:hasPostalAddress ?p . } " \ -"OPTIONAL { " \ -"<%s> nco:hasAffiliation ?a . " \ -"?a nco:hasPhoneNumber ?w . " \ +"OPTIONAL { <%s> nco:hasAffiliation ?a . " \ +"OPTIONAL { ?a nco:hasPhoneNumber ?w . } " \ +"OPTIONAL { ?a nco:org ?o . } " \"} " \"}"
@@ -741,6 +757,13 @@ add_entry: contact->region =g_strdup (reply[13 ]); contact->postal =g_strdup (reply[14 ]); contact->country =g_strdup (reply[15 ]); + contact->birthday =g_strdup (reply[17 ]); + contact->nickname =g_strdup (reply[18 ]); + contact->website =g_strdup (reply[19 ]); + contact->photo =g_strdup (reply[20 ]); + contact->company =g_strdup (reply[21 ]); + contact->department =g_strdup (reply[22 ]); + contact->title =g_strdup (reply[23 ]);set_call_type (contact, reply[COL_DATE ], reply[COL_SENT ], reply[COL_ANSWERED ]);
@@ -941,7 +964,8 @@ int phonebook_get_entry(const char *folder, const char *id, data->vcardentry = TRUE; query =g_strdup_printf (CONTACTS_QUERY_FROM_URI , id, id, id, id, id, - id, id, id, id, id, id, id); + id, id, id, id, id, id, id, + id, id, id, id); ret =query_tracker (query,PULL_QUERY_COL_AMOUNT , pull_contacts, data);
plugins/vcard.c +96 -0
114 lines not on this page · raw message
plugins/vcard.h +7 -0
@@ -55,6 +55,13 @@ struct phonebook_contact {char *region;char *postal;char *country; +char *birthday; +char *nickname; +char *website; +char *photo; +char *company; +char *department; +char *title;char *datetime;int calltype; };
Signature · 1 line
1.6.3.3
Hi Rafal,
Quoted 8 lines · Rafal Michalski
After pulling contacts some fields weren't present in downloaded VCARD structure in spite of that these fields existed (not empty).
I added handling fields: BDAY, NICKNAME, URL, PHOTO and three fields grouped under ORG tag (Company, Department, Job Title).
To solve this problem extending number of columns and queries of database was needed especially. Of course fields mentioned above were added tophonebook_contactstructure as char * type to save gained data
First of all, could we try to get the commit message format consistent with the rest of the git tree. I.e. keep the summary line as "Add handling of ..." and don't speak in the first person, i.e. instead of "I added ..." write "This patch adds ...". Just look at the commit history of bluez and obexd if you need examples.
It's a rather small patch, but if possible could you still split it into smaller chunks. When your commit message says "This patch adds X and Y and Z" it's a good hint that there should be a separate patch for each feature, epecially if the features arent interdependent.
Review
Quoted 1 line
(quoted diff) +1
-0+ "nco:postalcode(?p) nco:country(?p) ?f nco:birthDate(?c) " \
There's an extra space before the tab at the end of the line.
Review
Quoted 1 line
(quoted diff) +1
-0+ "nmo:receivedDate(?call) nmo:isSent(?call) " \
Same here.
Review
Quoted 1 line
(quoted diff) +1
-0+ "nco:postalcode(?p) nco:country(?p) ?f nco:birthDate(?c) " \
And here.
Review
Quoted 1 line
(quoted diff) +1
-0+ "nmo:receivedDate(?call) nmo:isSent(?call) " \
And here.
Enable whitespace visualisation in your editor to catch these. If you need hints for how to do this in vim (which I use myself) let me know.
plugins/vcard.c static void vcard_printf_email(GString *vcards, const char *email) · line 283
Quoted 10 lines
plugins/vcard.c +10
-0+static void vcard_printf_bday (GString *vcards,const char *birthday) +{ +int len =0 ; + +if (birthday) + len =strlen (birthday); + +if (len) +vcard_printf (vcards,"BDAY:%s" , birthday); +}
Instead of structuring the logic like this, could you simply do:
if (birthday == NULL || strlen(birthday) == 0) return; vcard_printf(...);
The same applies for your other printf functions (though in some of them you'll need to preserve the len variable for calling the add_slash function).
Quoted 17 lines
plugins/vcard.c +17
-0+static void vcard_printf_nickname (GString *vcards,const char *nickname) +{ +int len =0 ; + +if (nickname) + len =strlen (nickname); + +if (len) { +char field[LEN_MAX ]; +add_slash (field, nickname,LEN_MAX , len); +vcard_printf (vcards,"NICKNAME:%s" , field); + } +} + +static void vcard_printf_url (GString *vcards,const char *website) +{ +int len =0 ;
plugins/vcard.c static void vcard_printf_email(GString *vcards, const char *email) · line 311
Quoted 10 lines
plugins/vcard.c +10
-0+ +if (website) + len =strlen (website); + +if (len) { +char field[LEN_MAX ]; +add_slash (field, website,LEN_MAX , len); +vcard_printf (vcards,"URL;TYPE=INTERNET:%s" , field); + } +}
These functions look very similar in logic. Are there others in the existing code too? If so, you might want to consider creating a generalized function which takes the type and value as input parameters instead of having a separate function for each type.
Johan