Skip to content

Commit

Permalink
Add handling of ORG contact's fields handled in VCARD structure
Browse files Browse the repository at this point in the history
After pulling contacts these fields weren't present in downloaded
VCARD structure in spite of that these fields existed (not empty).

This patch adds handling of fields grouped under ORG tag.
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.
  • Loading branch information
michalskir authored and Johan Hedberg committed Aug 20, 2010
1 parent 6d842bb commit 3837119
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 11 deletions.
38 changes: 27 additions & 11 deletions plugins/phonebook-tracker.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,16 @@
#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 25
#define PULL_QUERY_COL_AMOUNT 26
#define CONTACTS_ID_COL 28
#define PULL_QUERY_COL_AMOUNT 29
#define COL_HOME_NUMBER 0
#define COL_HOME_EMAIL 7
#define COL_WORK_NUMBER 8
#define COL_FAX_NUMBER 16
#define COL_WORK_EMAIL 17
#define COL_DATE 22
#define COL_SENT 23
#define COL_ANSWERED 24
#define COL_DATE 25
#define COL_SENT 26
#define COL_ANSWERED 27

#define CONTACTS_QUERY_ALL \
"SELECT ?v nco:fullname(?c) " \
Expand All @@ -63,7 +63,8 @@
"nco:streetAddress(?p) nco:locality(?p) nco:region(?p) " \
"nco:postalcode(?p) nco:country(?p) ?f nco:emailAddress(?ew) " \
"nco:birthDate(?c) nco:nickname(?c) nco:websiteUrl(?c) " \
"nco:photo(?c) " \
"nco:photo(?c) nco:fullname(?o) nco:department(?a) " \
"nco:role(?a) " \
"\"NOTACALL\" \"false\" \"false\" ?c " \
"WHERE { " \
"?c a nco:PersonContact . " \
Expand All @@ -83,6 +84,7 @@
"?c nco:hasAffiliation ?a . " \
"OPTIONAL { ?a nco:hasPhoneNumber ?w . } " \
"OPTIONAL { ?a nco:hasEmailAddress ?ew . } " \
"OPTIONAL { ?a nco:org ?o . } " \
"} " \
"}"

Expand All @@ -109,7 +111,8 @@
"nco:streetAddress(?p) nco:locality(?p) nco:region(?p) " \
"nco:postalcode(?p) nco:country(?p) ?f nco:emailAddress(?ew) " \
"nco:birthDate(?c) nco:nickname(?c) nco:websiteUrl(?c) " \
"nco:photo(?c) " \
"nco:photo(?c) nco:fullname(?o) nco:department(?a) " \
"nco:role(?a) " \
"nmo:receivedDate(?call) " \
"nmo:isSent(?call) nmo:isAnswered(?call) ?c " \
"WHERE { " \
Expand All @@ -130,6 +133,7 @@
"?c nco:hasAffiliation ?a . " \
"OPTIONAL { ?a nco:hasPhoneNumber ?w . } " \
"OPTIONAL { ?a nco:hasEmailAddress ?ew . } " \
"OPTIONAL { ?a nco:org ?o . } " \
"} " \
"} ORDER BY DESC(nmo:receivedDate(?call))"

Expand All @@ -156,7 +160,8 @@
"nco:streetAddress(?p) nco:locality(?p) nco:region(?p) " \
"nco:postalcode(?p) nco:country(?p) ?f nco:emailAddress(?ew) " \
"nco:birthDate(?c) nco:nickname(?c) nco:websiteUrl(?c) " \
"nco:photo(?c) " \
"nco:photo(?c) nco:fullname(?o) nco:department(?a) " \
"nco:role(?a) " \
"nmo:receivedDate(?call) " \
"nmo:isSent(?call) nmo:isAnswered(?call) ?c " \
"WHERE { " \
Expand All @@ -177,6 +182,7 @@
"?c nco:hasAffiliation ?a . " \
"OPTIONAL { ?a nco:hasPhoneNumber ?w . } " \
"OPTIONAL { ?a nco:hasEmailAddress ?ew . } " \
"OPTIONAL { ?a nco:org ?o . } " \
"} " \
"} ORDER BY DESC(nmo:receivedDate(?call))"

Expand All @@ -203,7 +209,8 @@
"nco:streetAddress(?p) nco:locality(?p) nco:region(?p) " \
"nco:postalcode(?p) nco:country(?p) ?f nco:emailAddress(?ew)" \
"nco:birthDate(?c) nco:nickname(?c) nco:websiteUrl(?c) " \
"nco:photo(?c) " \
"nco:photo(?c) nco:fullname(?o) nco:department(?a) " \
"nco:role(?a) " \
"nmo:receivedDate(?call) " \
"nmo:isSent(?call) nmo:isAnswered(?call) ?c " \
"WHERE { " \
Expand All @@ -223,6 +230,7 @@
"?c nco:hasAffiliation ?a . " \
"OPTIONAL { ?a nco:hasPhoneNumber ?w . } " \
"OPTIONAL { ?a nco:hasEmailAddress ?ew . } " \
"OPTIONAL { ?a nco:org ?o . } " \
"} " \
"} ORDER BY DESC(nmo:sentDate(?call))"

Expand All @@ -248,7 +256,8 @@
"nco:streetAddress(?p) nco:locality(?p) nco:region(?p) " \
"nco:postalcode(?p) nco:country(?p) ?f nco:emailAddress(?ew) " \
"nco:birthDate(?c) nco:nickname(?c) nco:websiteUrl(?c) " \
"nco:photo(?c) " \
"nco:photo(?c) nco:fullname(?o) nco:department(?a) " \
"nco:role(?a) " \
"nmo:receivedDate(?call) " \
"nmo:isSent(?call) nmo:isAnswered(?call) ?c " \
"WHERE { " \
Expand All @@ -268,6 +277,7 @@
"OPTIONAL { ?c nco:hasAffiliation ?a . " \
"OPTIONAL { ?a nco:hasPhoneNumber ?w . } " \
"OPTIONAL { ?a nco:hasEmailAddress ?ew . } " \
"OPTIONAL { ?a nco:org ?o . } " \
"} " \
"} UNION { " \
"?call a nmo:Call ; " \
Expand All @@ -285,6 +295,7 @@
"OPTIONAL { ?c nco:hasAffiliation ?a . " \
"OPTIONAL { ?a nco:hasPhoneNumber ?w . } " \
"OPTIONAL { ?a nco:hasEmailAddress ?ew . } " \
"OPTIONAL { ?a nco:org ?o . } " \
"} " \
"} } ORDER BY DESC(nmo:receivedDate(?call))"

Expand Down Expand Up @@ -317,7 +328,8 @@
"nco:streetAddress(?p) nco:locality(?p) nco:region(?p) " \
"nco:postalcode(?p) nco:country(?p) ?f nco:emailAddress(?ew)" \
"nco:birthDate(<%s>) nco:nickname(<%s>) nco:websiteUrl(<%s>) " \
"nco:photo(<%s>) " \
"nco:photo(<%s>) nco:fullname(?o) nco:department(?a) " \
"nco:role(?a) " \
"\"NOTACALL\" \"false\" \"false\" <%s> " \
"WHERE { " \
"<%s> a nco:Contact . " \
Expand All @@ -337,6 +349,7 @@
"<%s> nco:hasAffiliation ?a . " \
"OPTIONAL { ?a nco:hasPhoneNumber ?w . }" \
"OPTIONAL { ?a nco:hasEmailAddress ?ew . }" \
"OPTIONAL { ?a nco:org ?o . } " \
"} " \
"}"

Expand Down Expand Up @@ -790,6 +803,9 @@ static void pull_contacts(char **reply, int num_fields, void *user_data)
contact->nickname = g_strdup(reply[19]);
contact->website = g_strdup(reply[20]);
contact->photo = g_strdup(reply[21]);
contact->company = g_strdup(reply[22]);
contact->department = g_strdup(reply[23]);
contact->title = g_strdup(reply[24]);

set_call_type(contact, reply[COL_DATE], reply[COL_SENT],
reply[COL_ANSWERED]);
Expand Down
30 changes: 30 additions & 0 deletions plugins/vcard.c
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,30 @@ static void vcard_printf_email(GString *vcards, const char *email)
}
}

static gboolean org_fields_present(struct phonebook_contact *contact)
{
if (contact->company && strlen(contact->company))
return TRUE;

if (contact->department && strlen(contact->department))
return TRUE;

if (contact->title && strlen(contact->title))
return TRUE;

return FALSE;
}

static void vcard_printf_org(GString *vcards,
struct phonebook_contact *contact)
{
if (org_fields_present(contact) == FALSE)
return;

vcard_printf(vcards, "ORG:%s;%s;%s", contact->company,
contact->department, contact->title);
}

static void vcard_printf_adr(GString *vcards, struct phonebook_contact *contact)
{
if (address_fields_present(contact) == FALSE) {
Expand Down Expand Up @@ -418,6 +442,9 @@ void phonebook_add_contact(GString *vcards, struct phonebook_contact *contact,
if (filter & FILTER_PHOTO)
vcard_printf_tag(vcards, "PHOTO", NULL, contact->photo);

if (filter & FILTER_ORG)
vcard_printf_org(vcards, contact);

if (filter & FILTER_X_IRMC_CALL_DATETIME)
vcard_printf_datetime(vcards, contact);

Expand Down Expand Up @@ -460,6 +487,9 @@ void phonebook_contact_free(struct phonebook_contact *contact)
g_free(contact->nickname);
g_free(contact->website);
g_free(contact->photo);
g_free(contact->company);
g_free(contact->department);
g_free(contact->title);
g_free(contact->datetime);
g_free(contact);
}
3 changes: 3 additions & 0 deletions plugins/vcard.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ struct phonebook_contact {
char *nickname;
char *website;
char *photo;
char *company;
char *department;
char *title;
char *datetime;
int calltype;
};
Expand Down

0 comments on commit 3837119

Please sign in to comment.