[PATCH 09/18] flickr: Simplify gflickr's callbacks



Share some callbacks instead defining one per method.
---
 src/flickr/gflickr.c |   29 ++++++++++++++---------------
 src/flickr/gflickr.h |   12 +++++-------
 2 files changed, 19 insertions(+), 22 deletions(-)

diff --git a/src/flickr/gflickr.c b/src/flickr/gflickr.c
index d3b4eb5..a73eac3 100644
--- a/src/flickr/gflickr.c
+++ b/src/flickr/gflickr.c
@@ -77,9 +77,8 @@ typedef void (*ParseXML) (const gchar *xml_result, gpointer user_data);
 
 typedef struct {
   ParseXML parse_xml;
-  GFlickrPhotoCb get_info_cb;
-  GFlickrPhotoListCb search_cb;
-  GFlickrTagListCb gethotlist_cb;
+  GFlickrHashTableCb hashtable_cb;
+  GFlickrListCb list_cb;
   gpointer user_data;
 } GFlickrData;
 
@@ -308,12 +307,12 @@ process_photo_result (const gchar *xml_result, gpointer user_data)
 
   /* Check result is ok */
   if (!node || !result_is_correct (node)) {
-    data->get_info_cb (NULL, NULL, data->user_data);
+    data->hashtable_cb (NULL, NULL, data->user_data);
   } else {
     node = node->xmlChildrenNode;
 
     photo = get_photo (node);
-    data->get_info_cb (NULL, photo, data->user_data);
+    data->hashtable_cb (NULL, photo, data->user_data);
     g_hash_table_unref (photo);
   }
   g_slice_free (GFlickrData, data);
@@ -334,7 +333,7 @@ process_photolist_result (const gchar *xml_result, gpointer user_data)
 
   /* Check result is ok */
   if (!node || !result_is_correct (node)) {
-    data->search_cb (NULL, NULL, data->user_data);
+    data->list_cb (NULL, NULL, data->user_data);
   } else {
     node = node->xmlChildrenNode;
 
@@ -345,7 +344,7 @@ process_photolist_result (const gchar *xml_result, gpointer user_data)
       node = node->next;
     }
 
-    data->search_cb (NULL, g_list_reverse (photolist), data->user_data);
+    data->list_cb (NULL, g_list_reverse (photolist), data->user_data);
     g_list_foreach (photolist, (GFunc) g_hash_table_unref, NULL);
     g_list_free (photolist);
   }
@@ -367,7 +366,7 @@ process_taglist_result (const gchar *xml_result, gpointer user_data)
 
   /* Check if result is OK */
   if (!node || !result_is_correct (node)) {
-    data->gethotlist_cb (NULL, NULL, data->user_data);
+    data->list_cb (NULL, NULL, data->user_data);
   } else {
     node = node->xmlChildrenNode;
 
@@ -378,7 +377,7 @@ process_taglist_result (const gchar *xml_result, gpointer user_data)
       node = node->next;
     }
 
-    data->gethotlist_cb (NULL, g_list_reverse (taglist), data->user_data);
+    data->list_cb (NULL, g_list_reverse (taglist), data->user_data);
     g_list_foreach (taglist, (GFunc) g_free, NULL);
     g_list_free (taglist);
   }
@@ -433,7 +432,7 @@ g_flickr_set_per_page (GFlickr *f, gint per_page)
 void
 g_flickr_photos_getInfo (GFlickr *f,
                          glong photo_id,
-                         GFlickrPhotoCb callback,
+                         GFlickrHashTableCb callback,
                          gpointer user_data)
 {
   gchar *auth;
@@ -467,7 +466,7 @@ g_flickr_photos_getInfo (GFlickr *f,
 
   GFlickrData *gfd = g_slice_new (GFlickrData);
   gfd->parse_xml = process_photo_result;
-  gfd->get_info_cb = callback;
+  gfd->hashtable_cb = callback;
   gfd->user_data = user_data;
 
   read_url_async (request, gfd);
@@ -479,7 +478,7 @@ g_flickr_photos_search (GFlickr *f,
                         const gchar *text,
                         const gchar *tags,
                         gint page,
-                        GFlickrPhotoListCb callback,
+                        GFlickrListCb callback,
                         gpointer user_data)
 {
   gchar *auth;
@@ -531,7 +530,7 @@ g_flickr_photos_search (GFlickr *f,
 
   GFlickrData *gfd = g_slice_new (GFlickrData);
   gfd->parse_xml = process_photolist_result;
-  gfd->search_cb = callback;
+  gfd->list_cb = callback;
   gfd->user_data = user_data;
 
   read_url_async (request, gfd);
@@ -600,7 +599,7 @@ g_flickr_photo_url_thumbnail (GFlickr *f, GHashTable *photo)
 void
 g_flickr_tags_getHotList (GFlickr *f,
                           gint count,
-                          GFlickrTagListCb callback,
+                          GFlickrListCb callback,
                           gpointer user_data)
 {
   gchar *auth;
@@ -634,7 +633,7 @@ g_flickr_tags_getHotList (GFlickr *f,
 
   GFlickrData *gfd = g_slice_new (GFlickrData);
   gfd->parse_xml = process_taglist_result;
-  gfd->gethotlist_cb = callback;
+  gfd->list_cb = callback;
   gfd->user_data = user_data;
 
   read_url_async (request, gfd);
diff --git a/src/flickr/gflickr.h b/src/flickr/gflickr.h
index f8935e7..a4b9a4f 100644
--- a/src/flickr/gflickr.h
+++ b/src/flickr/gflickr.h
@@ -73,11 +73,9 @@ struct _GFlickrClass {
 };
 
 
-typedef void (*GFlickrPhotoCb) (GFlickr *f, GHashTable *photo, gpointer user_data);
+typedef void (*GFlickrHashTableCb) (GFlickr *f, GHashTable *result, gpointer user_data);
 
-typedef void (*GFlickrPhotoListCb) (GFlickr *f, GList *photolist, gpointer user_data);
-
-typedef void (*GFlickrTagListCb) (GFlickr *f, GList *taglist, gpointer user_data);
+typedef void (*GFlickrListCb) (GFlickr *f, GList *result, gpointer user_data);
 
 GType g_flickr_get_type (void);
 
@@ -88,7 +86,7 @@ void g_flickr_set_per_page (GFlickr *f, gint per_page);
 void
 g_flickr_photos_getInfo (GFlickr *f,
                          glong photo_id,
-                         GFlickrPhotoCb callback,
+                         GFlickrHashTableCb callback,
                          gpointer user_data);
 
 void
@@ -96,7 +94,7 @@ g_flickr_photos_search (GFlickr *f,
                         const gchar *text,
                         const gchar *tags,
                         gint page,
-                        GFlickrPhotoListCb callback,
+                        GFlickrListCb callback,
                         gpointer user_data);
 
 gchar *
@@ -108,7 +106,7 @@ g_flickr_photo_url_thumbnail (GFlickr *f, GHashTable *photo);
 void
 g_flickr_tags_getHotList (GFlickr *f,
                           gint count,
-                          GFlickrTagListCb callback,
+                          GFlickrListCb callback,
                           gpointer user_data);
 
 gchar *
-- 
1.7.0.4



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]