1. example-watch-book
1 #include "example.h"
2 #include "libsoylent/soylent.h"
3
4 #include <glib.h>
5
6 static void person_added (SlBook *book, SlPerson *person, gboolean on_purpose, gpointer user_data);
7 static void person_removed (SlBook *book, SlPerson *person, gboolean on_purpose, gpointer user_data);
8 static void person_attribute_added (SlBook *book, SlPerson *person, SlAttribute *attr, gboolean on_purpose, gpointer user_data);
9 static void person_attribute_removed (SlBook *book, SlPerson *person, SlAttribute *attr, gboolean on_purpose, gpointer user_data);
10 static void person_attribute_modified (SlBook *book, SlPerson *person, SlAttribute *attr, GList *old_values, gboolean on_purpose, gpointer user_data);
11
12 static void person_added (SlBook *book, SlPerson *person, gboolean on_purpose,
13 gpointer user_data)
14 {
15 g_print ("person \"%s\" added\n", sl_person_get_nick (person));
16 }
17
18 static void person_removed (SlBook *book, SlPerson *person, gboolean on_purpose,
19 gpointer user_data)
20 {
21 g_print ("person \"%s\" removed\n", sl_person_get_nick (person));
22 }
23
24 static void person_attribute_added (SlBook *book, SlPerson *person,
25 SlAttribute *attr, gboolean on_purpose, gpointer user_data)
26 {
27 g_print ("attribute \"%s\" added to \"%s\"\n", sl_attribute_get_name (attr), sl_person_get_nick (person));
28 }
29
30 static void person_attribute_removed (SlBook *book, SlPerson *person,
31 SlAttribute *attr, gboolean on_purpose, gpointer user_data)
32 {
33 g_print ("attribute \"%s\" removed from \"%s\"\n", sl_attribute_get_name (attr), sl_person_get_nick (person));
34 }
35
36 static void person_attribute_modified (SlBook *book, SlPerson *person,
37 SlAttribute *attr, GList *old_values, gboolean on_purpose, gpointer user_data)
38 {
39 g_print ("attribute \"%s\" from \"%s\" modified\n", sl_attribute_get_name (attr), sl_person_get_nick (person));
40 }
41
42 void
43 watch_book (void)
44 {
45 GError *error = NULL;
46
47 /* initialize libsoylent */
48 if (!sl_init (&error))
49 {
50 example_error (error);
51 }
52
53 g_object_connect (SL_BOOK_DEFAULT,
54 "signal::person-added", person_added, NULL,
55 "signal::person-removed", person_removed, NULL,
56 "signal::person-attribute-added", person_attribute_added, NULL,
57 "signal::person-attribute-removed", person_attribute_removed, NULL,
58 "signal::person-attribute-modified", person_attribute_modified, NULL,
59 NULL);
60
61 GMainLoop *main_loop = g_main_loop_new (NULL, FALSE);
62 g_main_loop_run (main_loop);
63
64 sl_cleanup ();
65 }