[PATCH plugins 09/14] youtube: add GrlNet



Signed-off-by: Víctor Manuel Jáquez Leal <vjaquez igalia com>
---
 configure.ac              |    6 ++--
 src/youtube/Makefile.am   |    6 ++--
 src/youtube/grl-youtube.c |   54 +++++++++++++++++++++++++++++---------------
 3 files changed, 41 insertions(+), 25 deletions(-)

diff --git a/configure.ac b/configure.ac
index 8a699ff..32227cc 100644
--- a/configure.ac
+++ b/configure.ac
@@ -317,8 +317,8 @@ AC_ARG_ENABLE(youtube,
         [
                 case "$enableval" in
                      yes)
-                        if test "x$HAVE_GIO" = "xno"; then
-                           AC_MSG_ERROR([GIO not found, install it or use --disable-youtube])
+                        if test "x$HAVE_GRLNET" = "xno"; then
+                           AC_MSG_ERROR([grilo-net not found, install it or use --disable-youtube])
                         fi
                         if test "x$HAVE_XML" = "xno"; then
                            AC_MSG_ERROR([xml2 not found, install it or use --disable-youtube])
@@ -330,7 +330,7 @@ AC_ARG_ENABLE(youtube,
                 esac
         ],
         [
-                if test "x$HAVE_GIO" = "xyes" -a "x$HAVE_XML" = "xyes"; then
+                if test "x$HAVE_GRLNET" = "xyes" -a "x$HAVE_XML" = "xyes"; then
                    if test "x$HAVE_GDATA" = "xyes"; then
                      enable_youtube=yes
                    else
diff --git a/src/youtube/Makefile.am b/src/youtube/Makefile.am
index 83e4e47..7f230c2 100644
--- a/src/youtube/Makefile.am
+++ b/src/youtube/Makefile.am
@@ -9,21 +9,21 @@ lib_LTLIBRARIES = libgrlyoutube.la
 
 libgrlyoutube_la_CFLAGS =	\
 	$(DEPS_CFLAGS)		\
-	$(GIO_CFLAGS)		\
+	$(GRLNET_CFLAGS)	\
 	$(XML_CFLAGS) 		\
 	$(GTHREAD_CFLAGS)	\
 	$(GDATA_CFLAGS)
 
 libgrlyoutube_la_LIBADD =	\
 	$(DEPS_LIBS)		\
-	$(GIO_LIBS)		\
+	$(GRLNET_LIBS)		\
 	$(XML_LIBS) 		\
 	$(GTHREAD_LIBS)		\
 	$(GDATA_LIBS)
 
 libgrlyoutube_la_SOURCES = grl-youtube.c grl-youtube.h
 
-libdir=$(GRL_PLUGINS_DIR)
+libdir = $(GRL_PLUGINS_DIR)
 youtubexmldir	= $(GRL_PLUGINS_CONF_DIR)
 youtubexml_DATA	= $(YOUTUBE_PLUGIN_ID).xml
 
diff --git a/src/youtube/grl-youtube.c b/src/youtube/grl-youtube.c
index 5b02d9a..9e05a06 100644
--- a/src/youtube/grl-youtube.c
+++ b/src/youtube/grl-youtube.c
@@ -25,7 +25,7 @@
 #endif
 
 #include <grilo.h>
-#include <gio/gio.h>
+#include <net/grl-net.h>
 #include <gdata/gdata.h>
 #include <string.h>
 
@@ -173,7 +173,10 @@ typedef enum {
 
 struct _GrlYoutubeSourcePriv {
   GDataService *service;
+
+  GrlNetWc *wc;
 };
+
 #define YOUTUBE_CLIENT_ID "grilo"
 
 static GrlYoutubeSource *grl_youtube_source_new (const gchar *api_key,
@@ -231,6 +234,8 @@ CategoryInfo feeds_dir[] = {
 
 CategoryInfo *categories_dir = NULL;
 
+static GrlYoutubeSource *ytsrc = NULL;
+
 /* =================== Youtube Plugin  =============== */
 
 gboolean
@@ -310,6 +315,8 @@ grl_youtube_source_new (const gchar *api_key, const gchar *client_id)
                                              "yt-service", service,
 					     NULL));
 
+  ytsrc = source;
+
   /* Build browse content hierarchy:
       - Query Youtube for available categories
       - Compute category childcounts
@@ -380,6 +387,9 @@ grl_youtube_source_finalize (GObject *object)
 
   self = GRL_YOUTUBE_SOURCE (object);
 
+  if (self->priv->wc)
+    g_object_unref (self->priv->wc);
+
   if (self->priv->service)
     g_object_unref (self->priv->service);
 
@@ -414,24 +424,31 @@ operation_spec_ref (OperationSpec *os)
   os->ref_count++;
 }
 
+inline static GrlNetWc *
+get_wc ()
+{
+  if (ytsrc && !ytsrc->priv->wc)
+    ytsrc->priv->wc = grl_net_wc_new ();
+
+  return ytsrc->priv->wc;
+}
+
 static void
 read_done_cb (GObject *source_object,
               GAsyncResult *res,
               gpointer user_data)
 {
   AsyncReadCb *arc = (AsyncReadCb *) user_data;
-  GError *vfs_error = NULL;
+  GError *wc_error = NULL;
   gchar *content = NULL;
 
-  g_file_load_contents_finish (G_FILE (source_object),
-                               res,
-                               &content,
-                               NULL,
-                               NULL,
-                               &vfs_error);
-  g_object_unref (source_object);
-  if (vfs_error) {
-    GRL_WARNING ("Failed to open '%s': %s", arc->url, vfs_error->message);
+  grl_net_wc_request_finish (GRL_NET_WC (source_object),
+                         res,
+                         &content,
+                         NULL,
+                         &wc_error);
+  if (wc_error) {
+    GRL_WARNING ("Failed to open '%s': %s", arc->url, wc_error->message);
     arc->callback (NULL, arc->user_data);
   } else {
     arc->callback (content, arc->user_data);
@@ -445,17 +462,19 @@ read_url_async (const gchar *url,
                 AsyncReadCbFunc callback,
                 gpointer user_data)
 {
-  GFile *uri;
   AsyncReadCb *arc;
 
-  GRL_DEBUG ("Opening async '%s'", url);
-
   arc = g_slice_new0 (AsyncReadCb);
   arc->url = g_strdup (url);
   arc->callback = callback;
   arc->user_data = user_data;
-  uri = g_file_new_for_uri (url);
-  g_file_load_contents_async (uri, NULL, read_done_cb, arc);
+
+  GRL_DEBUG ("Opening async '%s'", url);
+  grl_net_wc_request_async (get_wc (),
+                        url,
+                        NULL,
+                        read_done_cb,
+                        arc);
 }
 
 static void
@@ -517,8 +536,6 @@ set_media_url_async_read_cb (gchar *data, gpointer user_data)
   }
 
  done:
-  g_free (data);
-  
   if (url) {
     grl_media_set_url (cb_data->media, url);
     g_free (url);
@@ -731,7 +748,6 @@ build_categories_directory_read_cb (gchar *xmldata, gpointer user_data)
   parse_categories (doc, node, GDATA_SERVICE (user_data));
 
  free_resources:
-  g_free (xmldata);
   xmlFreeDoc (doc);
 }
 
-- 
1.7.1



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