[sound-juicer] Make SjMetadata.list_albums() cancellable



commit b6764bb2644b8a436fae111ce0ab4ce8d7deedda
Author: Phillip Wood <phillip wood dunelm org uk>
Date:   Sun Jul 26 14:08:26 2015 +0100

    Make SjMetadata.list_albums() cancellable
    
    This will allow us to avoid unnecessary MusicBrainz queries. To simplify
    things for classes implementing this interface the wrapper ensures the
    vfunc is always called with a valid GCancellable and GError.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=753554

 libjuicer/sj-metadata-getter.c       |    4 ++--
 libjuicer/sj-metadata-gvfs.c         |    2 +-
 libjuicer/sj-metadata-musicbrainz5.c |    5 ++++-
 libjuicer/sj-metadata.c              |   27 +++++++++++++++++++++++++--
 libjuicer/sj-metadata.h              |    6 +++---
 5 files changed, 35 insertions(+), 9 deletions(-)
---
diff --git a/libjuicer/sj-metadata-getter.c b/libjuicer/sj-metadata-getter.c
index 64fc37f..b6a9967 100644
--- a/libjuicer/sj-metadata-getter.c
+++ b/libjuicer/sj-metadata-getter.c
@@ -218,9 +218,9 @@ lookup_cd (SjMetadataGetter *mdg)
                              NULL);
     bind_http_proxy_settings (metadata);
     if (priv->url == NULL)
-      albums = sj_metadata_list_albums (metadata, &priv->url, &error);
+      albums = sj_metadata_list_albums (metadata, &priv->url, NULL, &error);
     else
-      albums = sj_metadata_list_albums (metadata, NULL, &error);
+      albums = sj_metadata_list_albums (metadata, NULL, NULL, &error);
 
     if (albums != NULL) {
       SjMetadataGetterSignal *signal;
diff --git a/libjuicer/sj-metadata-gvfs.c b/libjuicer/sj-metadata-gvfs.c
index f80480b..15767c4 100644
--- a/libjuicer/sj-metadata-gvfs.c
+++ b/libjuicer/sj-metadata-gvfs.c
@@ -75,7 +75,7 @@ device_to_cdda_uri (const char *device)
 }
 
 static GList *
-gvfs_list_albums (SjMetadata *metadata, char **url, GError **error)
+gvfs_list_albums (SjMetadata *metadata, char **url, GCancellable *cancellable, GError **error)
 {
   SjMetadataGvfsPrivate *priv;
   GList *albums = NULL;
diff --git a/libjuicer/sj-metadata-musicbrainz5.c b/libjuicer/sj-metadata-musicbrainz5.c
index cfa711a..3f9d18b 100644
--- a/libjuicer/sj-metadata-musicbrainz5.c
+++ b/libjuicer/sj-metadata-musicbrainz5.c
@@ -860,7 +860,10 @@ make_album_from_release (SjMetadataMusicbrainz5 *self,
  * Virtual methods
  */
 static GList *
-mb5_list_albums (SjMetadata *metadata, char **url, GError **error)
+mb5_list_albums (SjMetadata    *metadata,
+                 char         **url,
+                 GCancellable  *cancellable,
+                 GError       **error)
 {
   SjMetadataMusicbrainz5 *self;
   SjMetadataMusicbrainz5Private *priv;
diff --git a/libjuicer/sj-metadata.c b/libjuicer/sj-metadata.c
index 4bd25c9..d356b22 100644
--- a/libjuicer/sj-metadata.c
+++ b/libjuicer/sj-metadata.c
@@ -32,6 +32,7 @@
 
 #include "sj-metadata.h"
 #include "sj-error.h"
+#include "sj-structures.h"
 
 enum {
   METADATA,
@@ -132,9 +133,31 @@ sj_metadata_set_cdrom (SjMetadata *metadata, const char* device)
 }
 
 GList *
-sj_metadata_list_albums (SjMetadata *metadata, char **url, GError **error)
+sj_metadata_list_albums (SjMetadata *metadata, char **url, GCancellable *cancellable, GError **error)
 {
-  return SJ_METADATA_GET_CLASS (metadata)->list_albums (metadata, url, error);
+  GError *err = NULL;
+  GCancellable *cancel;
+  GList *albums = NULL;
+
+  if (cancellable != NULL) {
+    if (g_cancellable_set_error_if_cancelled (cancellable, &err))
+      goto out;
+    cancel = cancellable;
+  } else {
+    cancel = g_cancellable_new ();
+  }
+  albums = SJ_METADATA_GET_CLASS (metadata)->list_albums (metadata, url, cancel, &err);
+  if (cancellable == NULL) {
+    g_object_unref (cancel);
+  } else if (err == NULL &&
+             g_cancellable_set_error_if_cancelled (cancellable, &err)) {
+    g_list_free_full (albums, (GDestroyNotify) album_details_free);
+    albums = NULL;
+  }
+ out:
+  if (err != NULL)
+    g_propagate_error (error, err);
+  return albums;
 }
 
 char *
diff --git a/libjuicer/sj-metadata.h b/libjuicer/sj-metadata.h
index 61fa4fc..ce16fd2 100644
--- a/libjuicer/sj-metadata.h
+++ b/libjuicer/sj-metadata.h
@@ -19,7 +19,7 @@
 #ifndef SJ_METADATA_H
 #define SJ_METADATA_H
 
-#include <glib-object.h>
+#include <gio/gio.h>
 #include <glib.h>
 
 G_BEGIN_DECLS
@@ -39,12 +39,12 @@ struct _SjMetadataClass
   GTypeInterface g_iface;
 
   /* Virtual Table */
-  GList * (*list_albums) (SjMetadata *metadata, char **url, GError **error);
+  GList * (*list_albums) (SjMetadata *metadata, char **url, GCancellable *cancellable, GError **error);
 };
 
 GType sj_metadata_get_type (void);
 void sj_metadata_set_cdrom (SjMetadata *metadata, const char* device);
-GList * sj_metadata_list_albums (SjMetadata *metadata, char **url, GError **error);
+GList * sj_metadata_list_albums (SjMetadata *metadata, char **url, GCancellable *cancellable, GError 
**error);
 
 char * sj_metadata_helper_scan_disc_number (const char *album_title, int *disc_number);
 gboolean sj_metadata_helper_check_media (const char *cdrom, GError **error);


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