diff --git a/obexd/plugins/phonebook-tracker.c b/obexd/plugins/phonebook-tracker.c
index 277290c..3367e49 100644
--- a/obexd/plugins/phonebook-tracker.c
+++ b/obexd/plugins/phonebook-tracker.c
#define TRACKER_DEFAULT_CONTACT_ME "http://www.semanticdesktop.org/ontologies/2007/03/22/nco#default-contact-me"
#define CONTACTS_ID_COL 38
#define PULL_QUERY_COL_AMOUNT 39
+#define COUNT_QUERY_COL_AMOUNT 1
#define COL_HOME_NUMBER 0
#define COL_HOME_EMAIL 7
#define COL_WORK_NUMBER 8
"<%s> nco:hasPhoneNumber ?t . " \
"} "
+#define CONTACTS_COUNT_QUERY \
+ "SELECT COUNT(?c) " \
+ "WHERE {" \
+ "?c a nco:PersonContact ." \
+ "FILTER (regex(str(?c), \"contact:\") || " \
+ "regex(str(?c), \"nco#default-contact-me\"))" \
+ "}"
+
+#define MISSED_CALLS_COUNT_QUERY \
+ "SELECT COUNT(?call) WHERE {" \
+ "?c a nco:Contact ;" \
+ "nco:hasPhoneNumber ?h ." \
+ "?call a nmo:Call ;" \
+ "nmo:isSent false ;" \
+ "nmo:from ?c ;" \
+ "nmo:isAnswered false ." \
+ "}"
+
+#define INCOMING_CALLS_COUNT_QUERY \
+ "SELECT COUNT(?call) WHERE {" \
+ "?c a nco:Contact ;" \
+ "nco:hasPhoneNumber ?h ." \
+ "?call a nmo:Call ;" \
+ "nmo:isSent false ;" \
+ "nmo:from ?c ;" \
+ "nmo:isAnswered true ." \
+ "}"
+
+#define OUTGOING_CALLS_COUNT_QUERY \
+ "SELECT COUNT(?call) WHERE {" \
+ "?c a nco:Contact ;" \
+ "nco:hasPhoneNumber ?h ." \
+ "?call a nmo:Call ;" \
+ "nmo:isSent true ;" \
+ "nmo:to ?c ." \
+ "}"
+
+#define COMBINED_CALLS_COUNT_QUERY \
+ "SELECT COUNT(?call) WHERE {" \
+ "{" \
+ "?c a nco:Contact ;" \
+ "nco:hasPhoneNumber ?h ." \
+ "?call a nmo:Call ;" \
+ "nmo:isSent true ;" \
+ "nmo:to ?c ." \
+ "}UNION {" \
+ "?c a nco:Contact ;" \
+ "nco:hasPhoneNumber ?h ." \
+ "?call a nmo:Call ;" \
+ "nmo:from ?c ." \
+ "}" \
+ "}"
+
typedef void (*reply_list_foreach_t) (char **reply, int num_fields,
void *user_data);
return NULL;
}
+static const char *name2count_query(const char *name)
+{
+ if (g_str_equal(name, "telecom/pb.vcf"))
+ return CONTACTS_COUNT_QUERY;
+ else if (g_str_equal(name, "telecom/ich.vcf"))
+ return INCOMING_CALLS_COUNT_QUERY;
+ else if (g_str_equal(name, "telecom/och.vcf"))
+ return OUTGOING_CALLS_COUNT_QUERY;
+ else if (g_str_equal(name, "telecom/mch.vcf"))
+ return MISSED_CALLS_COUNT_QUERY;
+ else if (g_str_equal(name, "telecom/cch.vcf"))
+ return COMBINED_CALLS_COUNT_QUERY;
+
+ return NULL;
+}
+
static gboolean folder_is_valid(const char *folder)
{
if (folder == NULL)
return vcards;
}
+static void pull_contacts_size (char **reply, int num_fields, void *user_data)
+{
+ struct phonebook_data *data = user_data;
+
+ if (num_fields < 0) {
+ data->cb(NULL, 0, num_fields, 0, data->user_data);
+ goto fail;
+ }
+
+ if (reply != NULL) {
+ data->index = atoi(reply[0]);
+ return;
+ }
+
+ data->cb(NULL, 0, data->index, 0, data->user_data);
+
+fail:
+ g_free(data);
+}
+
static void pull_contacts(char **reply, int num_fields, void *user_data)
{
struct phonebook_data *data = user_data;
{
struct phonebook_data *data;
const char *query;
+ reply_list_foreach_t pull_cb;
+ int col_amount;
DBG("name %s", name);
- query = name2query(name);
+ if (params->maxlistcount == 0) {
+ query = name2count_query(name);
+ col_amount = COUNT_QUERY_COL_AMOUNT;
+ pull_cb = pull_contacts_size;
+ } else {
+ query = name2query(name);
+ col_amount = PULL_QUERY_COL_AMOUNT;
+ pull_cb = pull_contacts;
+ }
+
if (query == NULL)
return -ENOENT;
data->user_data = user_data;
data->cb = cb;
- return query_tracker(query, PULL_QUERY_COL_AMOUNT, pull_contacts, data);
+ return query_tracker(query, col_amount, pull_cb, data);
}
int phonebook_get_entry(const char *folder, const char *id,