[PATCH plugins 14/14] lastfm-albumart: use GrlNet



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

diff --git a/configure.ac b/configure.ac
index 17d1e67..a56e675 100644
--- a/configure.ac
+++ b/configure.ac
@@ -236,8 +236,8 @@ AC_ARG_ENABLE(lastfm_albumart,
         [
                 case "$enableval" in
                      yes)
-                        if test "x$HAVE_GIO" = "xno"; then
-                           AC_MSG_ERROR([GIO not found, install it or use --disable-lastfm-albumart])
+                        if test "x$HAVE_GRLNET" = "xno"; then
+                           AC_MSG_ERROR([grilo-net not found, install it or use --disable-lastfm-albumart])
                         fi
                         if test "x$HAVE_XML" = "xno"; then
                            AC_MSG_ERROR([xml2 not found, install it or use --disable-lastfm-albumart])
@@ -246,7 +246,7 @@ AC_ARG_ENABLE(lastfm_albumart,
                 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
                    enable_lastfm_albumart=yes
                 else
                    enable_lastfm_albumart=no
diff --git a/src/lastfm-albumart/Makefile.am b/src/lastfm-albumart/Makefile.am
index 757756d..66527f6 100644
--- a/src/lastfm-albumart/Makefile.am
+++ b/src/lastfm-albumart/Makefile.am
@@ -9,17 +9,17 @@ lib_LTLIBRARIES = libgrllastfm-albumart.la
 
 libgrllastfm_albumart_la_CFLAGS =	\
 	$(DEPS_CFLAGS) 			\
-	$(GIO_CFLAGS) 			\
+	$(GRLNET_CFLAGS) 		\
 	$(XML_CFLAGS)
 
 libgrllastfm_albumart_la_LIBADD =	\
 	$(DEPS_LIBS)			\
-	$(GIO_LIBS)			\
+	$(GRLNET_LIBS)			\
 	$(XML_LIBS)
 
 libgrllastfm_albumart_la_SOURCES = grl-lastfm-albumart.c grl-lastfm-albumart.h
 
-libdir=$(GRL_PLUGINS_DIR)
+libdir = $(GRL_PLUGINS_DIR)
 lastfmalbumartxmldir	= $(GRL_PLUGINS_CONF_DIR)
 lastfmalbumartxml_DATA	= $(LASTFM_ALBUMART_PLUGIN_ID).xml
 
diff --git a/src/lastfm-albumart/grl-lastfm-albumart.c b/src/lastfm-albumart/grl-lastfm-albumart.c
index c448177..60ccbe6 100644
--- a/src/lastfm-albumart/grl-lastfm-albumart.c
+++ b/src/lastfm-albumart/grl-lastfm-albumart.c
@@ -26,7 +26,7 @@
 #include "config.h"
 #endif
 
-#include <gio/gio.h>
+#include <net/grl-net.h>
 #include <libxml/parser.h>
 #include <libxml/xmlmemory.h>
 #include <libxml/xpath.h>
@@ -55,9 +55,12 @@ GRL_LOG_DOMAIN_STATIC(lastfm_albumart_log_domain);
 #define LICENSE     "LGPL"
 #define SITE        "http://www.igalia.com";
 
+static GrlNetWc *wc;
 
 static GrlLastfmAlbumartSource *grl_lastfm_albumart_source_new (void);
 
+static void grl_lastfm_albumart_source_finalize (GObject *object);
+
 static void grl_lastfm_albumart_source_resolve (GrlMetadataSource *source,
                                                 GrlMetadataSourceResolveSpec *rs);
 
@@ -113,6 +116,9 @@ grl_lastfm_albumart_source_class_init (GrlLastfmAlbumartSourceClass * klass)
   metadata_class->supported_keys = grl_lastfm_albumart_source_supported_keys;
   metadata_class->key_depends = grl_lastfm_albumart_source_key_depends;
   metadata_class->resolve = grl_lastfm_albumart_source_resolve;
+
+  GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
+  gobject_class->finalize = grl_lastfm_albumart_source_finalize;
 }
 
 static void
@@ -124,6 +130,15 @@ G_DEFINE_TYPE (GrlLastfmAlbumartSource,
                grl_lastfm_albumart_source,
                GRL_TYPE_METADATA_SOURCE);
 
+static void
+grl_lastfm_albumart_source_finalize (GObject *object)
+{
+  if (wc && GRL_IS_NET_WC (wc))
+    g_object_unref (wc);
+
+  G_OBJECT_CLASS (grl_lastfm_albumart_source_parent_class)->finalize (object);
+}
+
 /* ======================= Utilities ==================== */
 
 static gchar *
@@ -175,30 +190,27 @@ read_done_cb (GObject *source_object,
   GrlMetadataSourceResolveSpec *rs =
     (GrlMetadataSourceResolveSpec *) user_data;
   GError *error = NULL;
-  GError *vfs_error = NULL;
+  GError *wc_error = NULL;
   gchar *content = NULL;
   gchar *image = NULL;
 
-  if (!g_file_load_contents_finish (G_FILE (source_object),
-                                    res,
-                                    &content,
-                                    NULL,
-                                    NULL,
-                                    &vfs_error)) {
+  if (!grl_net_wc_request_finish (GRL_NET_WC (source_object),
+                              res,
+                              &content,
+                              NULL,
+                              &wc_error)) {
     error = g_error_new (GRL_CORE_ERROR,
                          GRL_CORE_ERROR_RESOLVE_FAILED,
                          "Failed to connect to Last.FM: '%s'",
-                         vfs_error->message);
+                         wc_error->message);
     rs->callback (rs->source, rs->media, rs->user_data, error);
-    g_error_free (vfs_error);
+    g_error_free (wc_error);
     g_error_free (error);
-    g_object_unref (source_object);
+
     return;
   }
 
-  g_object_unref (source_object);
   image = xml_get_image (content);
-  g_free (content);
   if (image) {
     grl_data_set_string (GRL_DATA (rs->media),
                          GRL_METADATA_KEY_THUMBNAIL,
@@ -212,14 +224,11 @@ read_done_cb (GObject *source_object,
 static void
 read_url_async (const gchar *url, gpointer user_data)
 {
-  GVfs *vfs;
-  GFile *uri;
-
-  vfs = g_vfs_get_default ();
+  if (!wc)
+    wc = grl_net_wc_new ();
 
   GRL_DEBUG ("Opening '%s'", url);
-  uri = g_vfs_get_file_for_uri (vfs, url);
-  g_file_load_contents_async (uri, NULL, read_done_cb, user_data);
+  grl_net_wc_request_async (wc, url, NULL, read_done_cb, user_data);
 }
 
 /* ================== API Implementation ================ */
-- 
1.7.1



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