summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorJorg Schuler <jcsjcs@users.sourceforge.net>2005-09-19 10:30:50 +0000
committerJorg Schuler <jcsjcs@users.sourceforge.net>2005-09-19 10:30:50 +0000
commitd5215748b2ccd40a92cd3ffbcd1dcf907c797798 (patch)
treeb98944ba47d504e70fdb04bf7f858c7be365b4d7 /tests
parent4289045ca3ccab8a59754bc68ff150649c381b95 (diff)
downloadlibgpod-d5215748b2ccd40a92cd3ffbcd1dcf907c797798.tar.gz
libgpod-d5215748b2ccd40a92cd3ffbcd1dcf907c797798.tar.xz
libgpod-d5215748b2ccd40a92cd3ffbcd1dcf907c797798.zip
* applied patch provided by Christophe Fergeau <teuf at gnome.org>
for artwork database support (read-only). git-svn-id: https://gtkpod.svn.sf.net/svnroot/gtkpod/libgpod/trunk@1093 f01d2545-417e-4e96-918e-98f8d0dbbcb6
Diffstat (limited to 'tests')
-rw-r--r--tests/Makefile.am14
-rw-r--r--tests/test-covers.c125
2 files changed, 138 insertions, 1 deletions
diff --git a/tests/Makefile.am b/tests/Makefile.am
index a436696..8875c65 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -1,7 +1,19 @@
-noinst_PROGRAMS=test-itdb
+if HAVE_GDKPIXBUF
+TESTTHUMBS=test-thumbnails
+else
+TESTTHUMBS=
+endif
+
+noinst_PROGRAMS=test-itdb $(TESTTHUMBS)
INCLUDES=$(LIBGPOD_CFLAGS) -I$(top_srcdir)/src -DPACKAGE_LOCALE_DIR=\""$(prefix)/$(DATADIRNAME)/locale"\"
LIBS=$(LIBGPOD_LIBS)
test_itdb_SOURCES = itdb_main.c
test_itdb_LDADD = $(top_builddir)/src/libgpod.la
+
+if HAVE_GDKPIXBUF
+test_thumbnails_SOURCES = test-covers.c
+test_thumbnails_CFLAGS = $(GDKPIXBUF_CFLAGS) $(AM_CFLAGS)
+test_thumbnails_LDADD = $(top_builddir)/src/libgpod.la $(GDKPIXBUF_LIBS)
+endif
diff --git a/tests/test-covers.c b/tests/test-covers.c
new file mode 100644
index 0000000..e7e1fca
--- /dev/null
+++ b/tests/test-covers.c
@@ -0,0 +1,125 @@
+/* Copyright (c) 2005, Christophe Fergeau <teuf@gnome.org>
+ * All rights reserved.
+
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * * Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * * Neither the name of the <ORGANIZATION> nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "itdb.h"
+
+#include <locale.h>
+#include <gdk-pixbuf/gdk-pixbuf.h>
+
+static GdkPixbuf *
+ipod_image_to_gdk_pixbuf (Itdb_Image *image)
+{
+ GdkPixbuf *result;
+ guchar *pixels;
+
+ pixels = itdb_image_get_rgb_data (image);
+ if (pixels == NULL) {
+ return NULL;
+ }
+ result = gdk_pixbuf_new_from_data (pixels, GDK_COLORSPACE_RGB, FALSE,
+ 8, image->width, image->height,
+ image->width * 3,
+ (GdkPixbufDestroyNotify)g_free,
+ NULL);
+ return result;
+}
+
+
+static void
+save_itdb_image (Itdb_Image *image, const char *filename)
+{
+ GdkPixbuf *thumb;
+
+ thumb = ipod_image_to_gdk_pixbuf (image);
+ if (thumb != NULL) {
+ gdk_pixbuf_save (thumb, filename, "png", NULL, NULL);
+ gdk_pixbuf_unref (thumb);
+ g_print ("Saved %s\n", filename);
+ }
+}
+static void
+save_song_thumbnails (Itdb_Track *song)
+{
+ if (song->full_size_thumbnail != NULL) {
+ gchar *filename;
+
+ filename = g_strdup_printf ("/tmp/fullsize%016llx.png",
+ song->dbid);
+ save_itdb_image (song->full_size_thumbnail,filename);
+ g_free (filename);
+ }
+
+ if (song->now_playing_thumbnail != NULL) {
+ gchar *filename;
+
+ filename = g_strdup_printf ("/tmp/nowplaying%016llx.png",
+ song->dbid);
+ save_itdb_image (song->now_playing_thumbnail, filename);
+ g_free (filename);
+ }
+}
+
+
+static void
+save_thumbnails (Itdb_iTunesDB *db)
+{
+ GList *it;
+
+ for (it = db->tracks; it != NULL; it = it->next) {
+ Itdb_Track *song;
+
+ song = (Itdb_Track *)it->data;
+ save_song_thumbnails (song);
+ }
+}
+
+int
+main (int argc, char **argv)
+{
+ Itdb_iTunesDB *db;
+
+
+ if (argc < 2) {
+ g_print ("Usage: %s mountpoint\n", argv[0]);
+ return 1;
+ }
+
+ setlocale (LC_ALL, "");
+ g_type_init ();
+ db = itdb_parse (argv[1], NULL);
+ if (db == NULL) {
+ g_print ("Error reading iPod database\n");
+ return 1;
+ }
+
+ g_print ("========== ArtworkDB ==========\n");
+ save_thumbnails (db);
+ itdb_free (db);
+
+ return 0;
+}