soylent r254 - trunk/libsoylent/example
- From: svenp svn gnome org
- To: svn-commits-list gnome org
- Subject: soylent r254 - trunk/libsoylent/example
- Date: Wed, 30 Jul 2008 16:39:23 +0000 (UTC)
Author: svenp
Date: Wed Jul 30 16:39:23 2008
New Revision: 254
URL: http://svn.gnome.org/viewvc/soylent?rev=254&view=rev
Log:
added example utility functions
added an example for listing attributes
added stubs for people, signal and attribute-handler examples
Added:
trunk/libsoylent/example/example-attribute-handlers.c
trunk/libsoylent/example/example-create-person.c
trunk/libsoylent/example/example-list.c
trunk/libsoylent/example/example-watch-book.c
Modified:
trunk/libsoylent/example/Makefile.am
trunk/libsoylent/example/example.c
trunk/libsoylent/example/example.h
Modified: trunk/libsoylent/example/Makefile.am
==============================================================================
--- trunk/libsoylent/example/Makefile.am (original)
+++ trunk/libsoylent/example/Makefile.am Wed Jul 30 16:39:23 2008
@@ -4,7 +4,11 @@
example_SOURCES = \
example.h \
- example.c
+ example.c \
+ example-list.c \
+ example-create-person.c \
+ example-attribute-handlers.c \
+ example-watch-book.c
example_CFLAGS = $(WARN_CFLAGS) $(EXAMPLE_CFLAGS)
example_LDADD = $(top_builddir)/libsoylent/libsoylent.la $(EXAMPLE_LIBS)
Added: trunk/libsoylent/example/example-attribute-handlers.c
==============================================================================
Added: trunk/libsoylent/example/example-create-person.c
==============================================================================
--- (empty file)
+++ trunk/libsoylent/example/example-create-person.c Wed Jul 30 16:39:23 2008
@@ -0,0 +1,55 @@
+/*
+ * libsoylent - people management
+ *
+ * Copyright (C) 2008 Sven Pfaller, Noya <kalterregen gmx net>
+ * Copyright (C) 2008 Travis Reitter <treitter-dev netdrain com>
+ * Copyright (C) 2008 Rob Taylor <rob taylor codethink co uk>
+ * Copyright (C) 2008 Chris Lord <chris o-hand com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/*
+ *
+ */
+
+#include "example.h"
+#include "libsoylent/soylent.h"
+
+void
+create_person (void)
+{
+ GError *error = NULL;
+
+ /* initialize libsoylent */
+ if (!sl_init (&error))
+ {
+ example_error (error);
+ }
+
+ /* create a new person with the nick-name "Tim" */
+ SlPerson *tim = sl_person_new ("Tim");
+
+ /* TODO: add some attributes here... */
+
+ /* store the person in the default addressbook */
+ if (!sl_book_add_person (SL_BOOK_DEFAULT, tim, &error))
+ {
+ example_error (error);
+ }
+
+ g_object_unref (tim);
+ sl_cleanup ();
+}
Added: trunk/libsoylent/example/example-list.c
==============================================================================
--- (empty file)
+++ trunk/libsoylent/example/example-list.c Wed Jul 30 16:39:23 2008
@@ -0,0 +1,80 @@
+/*
+ * libsoylent - people management
+ *
+ * Copyright (C) 2008 Sven Pfaller, Noya <kalterregen gmx net>
+ * Copyright (C) 2008 Travis Reitter <treitter-dev netdrain com>
+ * Copyright (C) 2008 Rob Taylor <rob taylor codethink co uk>
+ * Copyright (C) 2008 Chris Lord <chris o-hand com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/*
+ * This example shows how to print a list of all attributes of all people in the
+ * default addressbook.
+ */
+
+/* TODO: better handling of value printing */
+
+#include "example.h"
+#include "libsoylent/soylent.h"
+
+void
+list (void)
+{
+ GError *error = NULL;
+
+ /* initialize libsoylent */
+ if (!sl_init (&error))
+ {
+ example_error (error);
+ }
+
+ /* iterate through all people in the default addressbook */
+ GList *people = sl_book_get_people (SL_BOOK_DEFAULT);
+ for (; people != NULL; people = people->next)
+ {
+
+ /* print nick of Âperson */
+ SlPerson *person = people->data;
+ g_print ("--- %s ---\n", sl_person_get_nick (person));
+
+ /* iterate through all attributes of Âperson */
+ GList *attributes = sl_person_get_attributes (person);
+ for (; attributes != NULL; attributes = attributes->next)
+ {
+
+ /* print attribute name */
+ SlAttribute *attr = attributes->data;
+ g_print (" * %s\n", sl_attribute_get_name (attr));
+
+ /* iterate through all values of Âattr */
+ GList *values = sl_attribute_get_all (attr);
+ int i;
+ int length = sl_attribute_get_value_count (attr);
+ for (i = 0; i < length; i++)
+ {
+
+ /* print the value (along with the index) */
+ g_print (" * [%d] %s\n", i, (gchar *) values->data);
+ values = values->next;
+ }
+ }
+
+ g_print ("\n");
+ }
+
+ sl_cleanup ();
+}
Added: trunk/libsoylent/example/example-watch-book.c
==============================================================================
Modified: trunk/libsoylent/example/example.c
==============================================================================
--- trunk/libsoylent/example/example.c (original)
+++ trunk/libsoylent/example/example.c Wed Jul 30 16:39:23 2008
@@ -26,9 +26,23 @@
#include <stdlib.h>
#include <glib.h>
+void
+example_error (GError *error)
+{
+ g_print ("error: %s", error->message);
+ exit (EXIT_FAILURE);
+}
+
int
main (int argc, char **argv)
{
- g_print ("Hello World\n");
+ /* You can uncomment the functions below to execute examples. Uncomment only
+ * one function at once. Be aware that the examples modify the default
+ * addressbook. */
+
+ /*list ();*/
+
+ create_person ();
+
return EXIT_SUCCESS;
}
Modified: trunk/libsoylent/example/example.h
==============================================================================
--- trunk/libsoylent/example/example.h (original)
+++ trunk/libsoylent/example/example.h Wed Jul 30 16:39:23 2008
@@ -20,3 +20,10 @@
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
+
+#include <glib.h>
+
+void example_error (GError *error);
+
+void list (void);
+void create_person (void);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]