]> err.no Git - eweouz/commitdiff
Reindent, reorganise
authorTollef Fog Heen <tfheen@err.no>
Tue, 16 Oct 2007 16:40:57 +0000 (18:40 +0200)
committerTollef Fog Heen <tfheen@err.no>
Tue, 16 Oct 2007 16:40:57 +0000 (18:40 +0200)
src/dump-addressbook.c

index bdd63e68abdd39161164d9f95e6bbc53660474b7..4943206b1fc6d5b6e79467f613186cae51c6acb9 100644 (file)
@@ -3,47 +3,76 @@
 #include <gconf/gconf.h>
 #include <glib.h>
 
-int main(int argc, char **argv) {
-  EBook *book;
-  ESourceList *source_list;
-  ESourceGroup *group;
-  ESource *source;
-  GSList *groups;
-  EBookQuery *query;
-  GList *contacts;
-  EContact *contact;
-  GSList *sources;
-  GSList *g, *s;
-  GList *c;
-
-  int i;
-  GError *error = NULL;
-
-  fprintf(stderr,"%d\n", e_book_get_addressbooks(&source_list, &error));
-  if (error != NULL) {
-    fprintf(stderr, "%s\n", error->message);
-  }
-  groups = e_source_list_peek_groups(source_list);
-  for (g = groups; g; g = g->next) {
-
-    group = E_SOURCE_GROUP (g->data);
-    fprintf(stderr, "SOURCE GROUP: %s\n", e_source_group_peek_base_uri(group));
-    sources = e_source_group_peek_sources(group);
-    
-    for (s = sources ; s; s = s->next) {
-      source = E_SOURCE(s->data);
-      book = e_book_new(source, &error);
-      e_book_open(book, TRUE, &error);
-      fprintf(stderr, "\tSOURCE: %s\n", e_source_peek_name(source));
-      //      query = e_book_query_any_field_contains("");
-      query = e_book_query_field_exists(E_CONTACT_FULL_NAME);
-      e_book_get_contacts(book, query, &contacts, &error);
-
-      for (c = contacts; c; c = c->next) {
+void dump_as_rfc822(EContact *c) 
+{
+       GList *attrs;
+       int i;
+       
        contact = E_CONTACT(c->data);
-       fprintf(stderr, "\t\tCONTACT: %s\n", e_contact_get(contact, E_CONTACT_FULL_NAME));
-      }
-      
-    }
-  }
+       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");
+               continue;
+       }
+       for (i = 0; i < g_list_length(attrs); i++) {
+               EVCardAttribute *attr = (EVCardAttribute *) g_list_nth_data(attrs, i);
+               int j;
+               
+               if (e_vcard_attribute_is_single_valued(attr)) {
+                       printf("\t\tphone: %s\n", e_vcard_attribute_get_value(attr));
+               } 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));
+                       }
+               }
+       }
+}
+
+int main(int argc, char **argv) {
+       EBook *book;
+       ESourceList *source_list;
+       ESourceGroup *group;
+       ESource *source;
+       GSList *groups;
+       EBookQuery *query;
+       GList *contacts;
+       EContact *contact;
+       GSList *sources;
+       GSList *g, *s;
+       GList *c;
+       GError *error = NULL;
+
+       printf("%d\n", e_book_get_addressbooks(&source_list, &error));
+
+       if (error != NULL) {
+               fprintf(stderr, "%s\n", error->message);
+       }
+
+       groups = e_source_list_peek_groups(source_list);
+       for (g = groups; g; g = g->next) {
+
+               group = E_SOURCE_GROUP (g->data);
+               printf("SOURCE GROUP: %s\n", e_source_group_peek_base_uri(group));
+               sources = e_source_group_peek_sources(group);
+
+               for (s = sources ; s; s = s->next) {
+                       source = E_SOURCE(s->data);
+                       book = e_book_new(source, &error);
+                       e_book_open(book, TRUE, &error);
+                       printf("\tSOURCE: %s\n", e_source_peek_name(source));
+                       //      query = e_book_query_any_field_contains("");
+                       query = e_book_query_field_exists(E_CONTACT_FULL_NAME);
+                       e_book_get_contacts(book, query, &contacts, &error);
+
+                       for (c = contacts; c; c = c->next) {
+                       }
+               }
+       }
 }