From 9ab2dde8abbceff778db77d72cbaa77c5112e31b Mon Sep 17 00:00:00 2001 From: Jonas Kvinge Date: Tue, 1 Sep 2020 01:04:01 +0200 Subject: [PATCH] Read tumbnails from itdb tracks --- src/core/song.cpp | 35 ++++++++++++++++++++++++++--------- src/core/song.h | 2 +- 2 files changed, 27 insertions(+), 10 deletions(-) diff --git a/src/core/song.cpp b/src/core/song.cpp index baace42d8..79f85e062 100644 --- a/src/core/song.cpp +++ b/src/core/song.cpp @@ -26,6 +26,15 @@ #include #include +#ifdef HAVE_LIBGPOD +# include +# include +#endif + +#ifdef HAVE_LIBMTP +# include +#endif + #include #include #include @@ -46,14 +55,6 @@ #include #include -#ifdef HAVE_LIBGPOD -#include -#endif - -#ifdef HAVE_LIBMTP -#include -#endif - #include "core/logging.h" #include "core/messagehandler.h" #include "core/iconloader.h" @@ -1061,7 +1062,7 @@ void Song::InitArtManual() { } #ifdef HAVE_LIBGPOD -void Song::InitFromItdb(const Itdb_Track *track, const QString &prefix) { +void Song::InitFromItdb(Itdb_Track *track, const QString &prefix) { d->valid_ = true; @@ -1104,6 +1105,22 @@ void Song::InitFromItdb(const Itdb_Track *track, const QString &prefix) { d->skipcount_ = track->skipcount; d->lastplayed_ = track->time_played; + if (itdb_track_has_thumbnails(track)) { + GdkPixbuf *pixbuf = static_cast(itdb_track_get_thumbnail(track, -1, -1)); + if (pixbuf) { + gchar *buffer = nullptr; + gsize buffer_size = 0; + GError *error = nullptr; + gdk_pixbuf_save_to_buffer(pixbuf, &buffer, &buffer_size, "jpeg", &error, nullptr); + if (buffer) { + const QByteArray data = QByteArray::fromRawData(buffer, buffer_size); + d->image_.loadFromData(data, "JPEG"); + g_free(buffer); + } + g_object_unref(pixbuf); + } + } + } void Song::ToItdb(Itdb_Track *track) const { diff --git a/src/core/song.h b/src/core/song.h index cefd46a11..9ee81917b 100644 --- a/src/core/song.h +++ b/src/core/song.h @@ -164,7 +164,7 @@ class Song { bool MergeFromSimpleMetaBundle(const Engine::SimpleMetaBundle &bundle); #ifdef HAVE_LIBGPOD - void InitFromItdb(const _Itdb_Track *track, const QString &prefix); + void InitFromItdb(_Itdb_Track *track, const QString &prefix); void ToItdb(_Itdb_Track *track) const; #endif