[libmediaart] cache: Add media_art_get_file()
- From: Carlos Garnacho <carlosg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libmediaart] cache: Add media_art_get_file()
- Date: Mon, 7 Oct 2013 16:18:05 +0000 (UTC)
commit 69c7d63fbcca866324a271ab19f1789a33ee60aa
Author: Carlos Garnacho <carlosg gnome org>
Date: Mon Oct 7 17:48:41 2013 +0200
cache: Add media_art_get_file()
This call is similar to media_art_get_path(), but using GFiles
for in/out path parameters. This older function now internally
uses the just added one, so internally operations happen on
GFiles.
libmediaart/cache.c | 113 +++++++++++++++++++++++++++++++++++----------------
libmediaart/cache.h | 8 ++++
2 files changed, 86 insertions(+), 35 deletions(-)
---
diff --git a/libmediaart/cache.c b/libmediaart/cache.c
index 641dcee..e2592b6 100644
--- a/libmediaart/cache.c
+++ b/libmediaart/cache.c
@@ -197,34 +197,41 @@ media_art_checksum_for_data (GChecksumType checksum_type,
}
/**
- * media_art_get_path:
+ * media_art_get_file:
* @artist: the artist
* @title: the title
- * @prefix: the prefix, for example "album"
- * @uri: (allow-none): the uri of the file or %NULL
- * @path: (out) (transfer full) (allow-none): the location to store the local
- * path or %NULL
- * @local_uri: (out) (transfer full) (allow-none): the location to store the
- * local uri or %NULL
+ * @prefix: the prefix for cache files, for example "album"
+ * @file: (allow-none): the file or %NULL
+ * @cache_file: (out) (transfer full) (allow-none): the location to store
+ * a #GFile pointing to the user cache path, or %NULL
+ * @local_file: (out) (transfer full) (allow-none): the location to store
+ * a #GFile pointing to a cache file in the same filesystem than @file,
+ * or %NULL.
*
- * Get the path to media art for a given resource. Newly allocated data in
- * @path and @local_uri must be freed with g_free().
+ * Gets the files pointing to cache files suitable for storing the media
+ * art provided by the @artist, @title and @file arguments. @cache_file
+ * will point to a location in the XDG user cache directory, meanwhile
+ * @local_file will point to a cache file that resides in the same
+ * filesystem than @file.
+ *
+ * When done, both #GFile<!-- -->s must be freed with g_object_unref if
+ * non-%NULL.
*
* Since: 0.2.0
*/
void
-media_art_get_path (const gchar *artist,
+media_art_get_file (const gchar *artist,
const gchar *title,
const gchar *prefix,
- const gchar *uri,
- gchar **path,
- gchar **local_uri)
+ GFile *file,
+ GFile **cache_file,
+ GFile **local_file)
{
const gchar *space_checksum = "7215ee9c7d9dc229d2921a40e899ec5f";
const gchar *a, *b;
gchar *art_filename;
- gchar *dir;
+ gchar *dir, *filename;
gchar *artist_down, *title_down;
gchar *artist_stripped, *title_stripped;
gchar *artist_norm, *title_norm;
@@ -232,12 +239,12 @@ media_art_get_path (const gchar *artist,
/* http://live.gnome.org/MediaArtStorageSpec */
- if (path) {
- *path = NULL;
+ if (cache_file) {
+ *cache_file = NULL;
}
- if (local_uri) {
- *local_uri = NULL;
+ if (local_file) {
+ *local_file = NULL;
}
if (!artist && !title) {
@@ -294,31 +301,23 @@ media_art_get_path (const gchar *artist,
g_free (title_norm);
}
- if (path) {
- *path = g_build_filename (dir, art_filename, NULL);
+ if (cache_file) {
+ filename = g_build_filename (dir, art_filename, NULL);
+ *cache_file = g_file_new_for_path (filename);
+ g_free (filename);
}
- if (local_uri) {
- gchar *local_dir;
- GFile *file, *parent;
-
- if (strstr (uri, "://")) {
- file = g_file_new_for_uri (uri);
- } else {
- file = g_file_new_for_path (uri);
- }
+ if (local_file) {
+ GFile *parent;
parent = g_file_get_parent (file);
if (parent) {
- local_dir = g_file_get_uri (parent);
-
- /* This is a URI, don't use g_build_filename here */
- *local_uri = g_strdup_printf ("%s/.mediaartlocal/%s", local_dir, art_filename);
+ filename = g_build_filename (".mediaartlocal", art_filename, NULL);
+ *local_file = g_file_resolve_relative_path (parent, filename);
+ g_free (filename);
- g_free (local_dir);
g_object_unref (parent);
}
- g_object_unref (file);
}
g_free (dir);
@@ -326,6 +325,50 @@ media_art_get_path (const gchar *artist,
}
/**
+ * media_art_get_path:
+ * @artist: the artist
+ * @title: the title
+ * @prefix: the prefix, for example "album"
+ * @uri: (allow-none): the uri of the file or %NULL
+ * @path: (out) (transfer full) (allow-none): the location to store the local
+ * path or %NULL
+ * @local_uri: (out) (transfer full) (allow-none): the location to store the
+ * local uri or %NULL
+ *
+ * Get the path to media art for a given resource. Newly allocated data in
+ * @path and @local_uri must be freed with g_free().
+ *
+ * Since: 0.2.0
+ */
+void
+media_art_get_path (const gchar *artist,
+ const gchar *title,
+ const gchar *prefix,
+ const gchar *uri,
+ gchar **path,
+ gchar **local_uri)
+{
+ GFile *file = NULL, *cache_file = NULL, *local_file = NULL;
+
+ if (uri) {
+ file = g_file_new_for_uri (uri);
+ }
+
+ media_art_get_file (artist, title, prefix, file,
+ (path) ? &cache_file : NULL,
+ (local_uri) ? &local_file : NULL);
+ if (path) {
+ *path = cache_file ? g_file_get_path (cache_file) : NULL;
+ }
+
+ if (local_uri) {
+ *local_uri = local_file ? g_file_get_uri (local_file) : NULL;
+ }
+
+ g_object_unref (file);
+}
+
+/**
* media_art_remove:
* @artist: artist the media art belongs to
* @album: (allow-none): album the media art belongs or %NULL
diff --git a/libmediaart/cache.h b/libmediaart/cache.h
index 6fc185e..a3c2eea 100644
--- a/libmediaart/cache.h
+++ b/libmediaart/cache.h
@@ -21,6 +21,7 @@
#define __LIBMEDIAART_CACHE_H__
#include <glib.h>
+#include <gio/gio.h>
#if !defined (__LIBMEDIAART_INSIDE__) && !defined (LIBMEDIAART_COMPILATION)
#error "Only <libmediaart/mediaart.h> must be included directly."
@@ -37,6 +38,13 @@ void media_art_get_path (const gchar *artist,
gchar **path,
gchar **local_uri);
+void media_art_get_file (const gchar *artist,
+ const gchar *title,
+ const gchar *prefix,
+ GFile *file,
+ GFile **cache_file,
+ GFile **local_file);
+
gboolean media_art_remove (const gchar *artist,
const gchar *album);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]