Give info for changes in the update callback from ObtLinkBase
authorDana Jansens <danakj@orodu.net>
Thu, 27 Jan 2011 22:29:25 +0000 (17:29 -0500)
committerDana Jansens <danakj@orodu.net>
Sun, 16 Oct 2011 22:54:04 +0000 (18:54 -0400)
Also provide a function to access all ObtLink objects in a given category.

obt/linkbase.c
obt/linkbase.h

index 28f617f3ddb21d2818d3e37b29079a7a909e95f5..3e244f18e65a384905bae921ba42dd7cda933e93 100644 (file)
@@ -176,6 +176,10 @@ static void update(ObtWatch *w, const gchar *base_path,
 
             ObtLink *link = it->data;
 
+            if (self->update_func)
+                self->update_func(
+                    self, OBT_LINKBASE_REMOVED, link, self->update_data);
+
             if (obt_link_type(link) == OBT_LINK_TYPE_APPLICATION) {
                 const GQuark *cats;
                 gulong i, n;
@@ -208,6 +212,10 @@ static void update(ObtWatch *w, const gchar *base_path,
 
             ObtLink *link = it->data;
 
+            if (self->update_func)
+                self->update_func(
+                    self, OBT_LINKBASE_REMOVED, link, self->update_data);
+
             if (obt_link_type(link) == OBT_LINK_TYPE_APPLICATION) {
                 const GQuark *cats;
                 gulong i, n;
@@ -252,6 +260,11 @@ static void update(ObtWatch *w, const gchar *base_path,
                 ObtLinkBaseEntry *e = g_slice_new(ObtLinkBaseEntry);
                 e->priority = *priority;
                 e->link = link;
+
+                if (self->update_func)
+                    self->update_func(
+                        self, OBT_LINKBASE_ADDED, link, self->update_data);
+
                 list = g_slist_insert_before(list, it, e);
 
                 /* this will free 'id' */
@@ -271,9 +284,6 @@ static void update(ObtWatch *w, const gchar *base_path,
     }
 
     g_free(id);
-
-    if (self->update_func)
-        self->update_func(self, self->update_data);
 }
 
 ObtLinkBase* obt_linkbase_new(ObtPaths *paths, const gchar *locale,
@@ -395,3 +405,12 @@ void obt_linkbase_set_update_func(ObtLinkBase *lb, ObtLinkBaseUpdateFunc func,
     lb->update_func = func;
     lb->update_data = data;
 }
+
+GSList *obt_linkbase_category(ObtLinkBase *lb, GQuark category)
+{
+    ObtLinkBaseCategory *cat;
+
+    cat = g_hash_table_lookup(lb->categories, &category);
+    if (!cat) return NULL;
+    else      return cat->links;
+}
index 386d3c2fe47f3419fd50753eec8056de8835f7fd..9d7b1debe5212973a9cfb73a3b2aa338ea84348f 100644 (file)
@@ -25,9 +25,19 @@ struct _ObtPaths;
 
 G_BEGIN_DECLS
 
+struct _ObtLink;
+
 typedef struct _ObtLinkBase ObtLinkBase;
 
-typedef void (*ObtLinkBaseUpdateFunc)(ObtLinkBase *lb, gpointer data);
+typedef enum {
+    OBT_LINKBASE_ADDED,
+    OBT_LINKBASE_REMOVED,
+} ObtLinkBaseUpdateType;
+
+typedef void (*ObtLinkBaseUpdateFunc)(ObtLinkBase *lb,
+                                      ObtLinkBaseUpdateType type,
+                                      struct _ObtLink *link,
+                                      gpointer data);
 
 /*! Create a new database of ObtLinks.
   @param paths An ObtPaths structure.
@@ -43,6 +53,9 @@ void obt_linkbase_unref(ObtLinkBase *lb);
 void obt_linkbase_set_update_func(ObtLinkBase *lb, ObtLinkBaseUpdateFunc func,
                                   gpointer data);
 
+/*! Returns a list of all known ObtLink* which belong in the given category. */
+GSList *obt_linkbase_category(ObtLinkBase *lb, GQuark category);
+
 G_END_DECLS
 
 #endif