From: Tollef Fog Heen Date: Tue, 16 Oct 2007 18:05:22 +0000 (+0200) Subject: Misc cleanups X-Git-Tag: 0.1~34 X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=439009fe8694968421a0b9a9eaed193133964855;p=eweouz Misc cleanups - rename dump_as_rfc822 to dump_as_vcard - implement filtering so we ordinarily only print those fieldswe are interested in. --- diff --git a/src/dump-addressbook.c b/src/dump-addressbook.c index a70e2db..3aa9c95 100644 --- a/src/dump-addressbook.c +++ b/src/dump-addressbook.c @@ -3,34 +3,68 @@ #include #include -void dump_as_rfc822(EContact *contact) +void dump_as_vcard(EContact *contact, int dump_all) { GList *attrs; int i; - attrs = e_contact_get_attributes(contact, E_CONTACT_PHONE_MOBILE); - printf("\t\tCONTACT: %s\n", e_contact_get(contact, E_CONTACT_FULL_NAME)); - if (! attrs) { - fprintf(stderr, "Could not get phone attributes for contact\n"); - return; - } + + attrs = e_vcard_get_attributes(&contact->parent); for (i = 0; i < g_list_length(attrs); i++) { - EVCardAttribute *attr = (EVCardAttribute *) g_list_nth_data(attrs, i); + EVCardAttribute *attr = (EVCardAttribute *) + g_list_nth_data(attrs, i); int j; - + char *attr_name = e_vcard_attribute_get_name(attr); + + if (!dump_all && + strcmp(attr_name, "TEL") != 0 && + strcmp(attr_name, "FN") != 0 && + strcmp(attr_name, "BDAY") != 0 && + strcmp(attr_name, "ORG") != 0 && + strcmp(attr_name, "TEL") != 0 && + strcmp(attr_name, "EMAIL") != 0 && + strcmp(attr_name, "NOTE") != 0 && + strcmp(attr_name, "NICKNAME") != 0 + ) { + continue; + } + + if (strcmp(attr_name, "N") == 0 || + strcmp(attr_name, "ADR") == 0) { + continue; + } + if (e_vcard_attribute_is_single_valued(attr)) { - printf("\t\tphone: %s\n", e_vcard_attribute_get_value(attr)); + char *av = e_vcard_attribute_get_value(attr); + printf("%s: %s\n", + attr_name, + av); } else { GList *vals = e_vcard_attribute_get_values(attr); - - if (! vals) { - continue; - } - + for (j = 0; j < g_list_length(vals); j++) { - printf("\t\tphone: %s\n", (char*) g_list_nth(vals, j)); + char *av = g_list_nth(vals, j); + + printf("%s: %s\n", + attr_name, + av); } } } + +/* char *name = e_contact_get(contact, E_CONTACT_FULL_NAME); + char *nickname = e_contact_get(contact, E_CONTACT_NICKNAME); + + printf("Name: %s\n", name); + + if (nickname && strcmp("", nickname) != 0) { + printf("Nickname: %s\n", nickname); + } + + free(name); + free(nickname); + +*/ + } int main(int argc, char **argv) @@ -70,7 +104,7 @@ int main(int argc, char **argv) e_book_get_contacts(book, query, &contacts, &error); for (c = contacts; c; c = c->next) { - dump_as_rfc822(E_CONTACT(c->data)); + dump_as_vcard(E_CONTACT(c->data), 1); } } }