example-list

   1 #include "example.h"
   2 #include "libsoylent/soylent.h"
   3 
   4 void
   5 list (void)
   6 {
   7   GError *error = NULL;
   8   
   9   /* initialize libsoylent */
  10   if (!sl_init (&error))
  11     {
  12       example_error (error);
  13     }
  14   
  15   /* iterate through all people in the default addressbook */
  16   GList *people = sl_book_get_people (SL_BOOK_DEFAULT);
  17   for (; people != NULL; people = people->next)
  18     {
  19       
  20       /* print nick of ´person´ */
  21       SlPerson *person = people->data;
  22       g_print ("--- %s ---\n", sl_person_get_nick (person));
  23       
  24       /* iterate through all attributes of ´person´ */
  25       GList *attributes = sl_person_get_attributes (person);
  26       for (; attributes != NULL; attributes = attributes->next)
  27         {
  28           
  29           /* print attribute name */
  30           SlAttribute *attr = attributes->data;
  31           const gchar *attrname = sl_attribute_get_name (attr);
  32           g_print (" * %s\n", attrname);
  33           
  34           /* iterate through all values of ´attr´ */
  35           GList *values = sl_attribute_get_all (attr);
  36           int i;
  37           int length = sl_attribute_get_value_count (attr);
  38           for (i = 0; i < length; i++)
  39             {
  40               
  41               /* print the value (along with the index) */
  42               gchar *str = sl_attribute_to_string (attrname, values->data);
  43               g_print ("   * [%d] %s\n", i, str);
  44               g_free (str);
  45               values = values->next;
  46             }
  47         }
  48       
  49       g_print ("\n");
  50     }
  51   
  52   sl_cleanup ();
  53 }

Projects/Soylent/libsoylent/example-list (last edited 2013-11-22 19:18:57 by WilliamJonMcCann)