extragear/multimedia/amarok
Seb Ruiz
ruiz at kde.org
Wed Mar 11 11:27:30 UTC 2009
SVN commit 938120 by seb:
Show ipod covers in the collection. I've removed KTemporaryFile usage
because it fucks with everything (keeps overwriting the same file,
causing race conditions). I've had to resort to using Amarok's own save
directory as an interim solution saving the data in order to convert
between a GdkPixbuf and a QPixmap. I'm also finding a bit of a heisenbug
with covers being shown garbled, and I think it might be a problem with
either my ipod or libgpod. Testing appreciated.
CCMAIL: amarok at kde.org
M +1 -0 ChangeLog
M +34 -22 src/collection/ipodcollection/handler/IpodHandler.cpp
M +2 -8 src/collection/ipodcollection/handler/IpodHandler.h
--- trunk/extragear/multimedia/amarok/ChangeLog #938119:938120
@@ -5,6 +5,7 @@
VERSION 2.1
FEATURES:
+ * Covers are shown for iPod collections.
* Phonon multimedia system can be configured directly from Amarok.
* Cover art can now be disabled in the collection browser.
* Scrobble tracks from streams that have title and artist metadata
--- trunk/extragear/multimedia/amarok/src/collection/ipodcollection/handler/IpodHandler.cpp #938119:938120
@@ -1,6 +1,7 @@
/**************************************************************************
* Ported to Collection Framework: *
* copyright : (C) 2008 Alejandro Wainzinger <aikawarazuni at gmail.com>
+ * copyright : (C) 2009 Seb Ruiz <ruiz at kde.org>
*
* Original Work: *
* copyright : (C) 2005, 2006 by Martin Aumueller <aumuell at reserv.at>
@@ -36,12 +37,12 @@
#include "File.h" // for KIO file handling
+#include <KCodecs> // KMD5
#include <KIO/Job>
#include <KIO/CopyJob>
#include <KIO/DeleteJob>
#include <KIO/Scheduler>
#include "kjob.h"
-#include <KTemporaryFile>
#include <threadweaver/ThreadWeaver.h>
#include <KUrl>
@@ -1273,35 +1274,46 @@
#ifdef GDK_FOUND
+QByteArray
+IpodHandler::md5sum( const QString& artist, const QString& album ) const
+{
+ KMD5 context( artist.toLower().toLocal8Bit() + album.toLower().toLocal8Bit() );
+ return context.hexDigest();
+}
+
void
IpodHandler::getCoverArt( Itdb_Track *ipodtrack, Meta::IpodTrackPtr track )
{
- KTemporaryFile tempImageFile;
+ if( itdb_track_has_thumbnails( ipodtrack ) )
+ {
+ const QString artist = track->artist() ? track->artist()->name() : QString();
+ const QString album = track->album() ? track->album()->name() : QString();
+ const QString imageKey = md5sum( artist, album );
+ const QString tempImagePath = Amarok::saveLocation("albumcovers/tmp/ipod/") + imageKey + ".jpg";
- tempImageFile.setSuffix( ".png" ); // default suffix jpeg
- QFileInfo tempImageFileInfo( tempImageFile ); // get info for path
- QString tempImagePath = tempImageFileInfo.absoluteFilePath(); // path
+ GdkPixbuf *gpixbuf = (GdkPixbuf*) itdb_artwork_get_pixbuf( m_device, ipodtrack->artwork, 200, 200 );
- GdkPixbuf *gpixbuf = NULL;
+ if( gpixbuf )
+ {
+ // temporarily save to file
+ GError *error = 0;
+ const bool success = gdk_pixbuf_save( gpixbuf, QFile::encodeName( tempImagePath ), "jpeg", &error, ( char* ) NULL );
- // pull image out of ipod
+ if( !success && error )
+ {
+ debug() << "Couldn't read artwork from file, blame GNOME shite: " << error->message;
+ g_error_free( error );
+ return;
+ }
+ else if( !success )
+ return;
- // NOTE: 0x01 = has, 0x02 = has not
+ QPixmap pixmap( tempImagePath );
+ track->album()->setImage( pixmap );
- if( ipodtrack->has_artwork == 0x01 )
- gpixbuf = (GdkPixbuf*) itdb_artwork_get_pixbuf( m_device, ipodtrack->artwork, -1, -1 );
-
- if(gpixbuf != NULL)
- {
- // temporarily save to file
- gdk_pixbuf_save( gpixbuf, QFile::encodeName( tempImagePath ), "png", NULL, ( char* ) NULL );
-
- // pull temporary file's image out as QImage
- QPixmap pixmap( tempImagePath );
- track->album()->setImage( pixmap );
-
- // fix memleak
- gdk_pixbuf_unref ( gpixbuf );
+ // free stupid gnome shit
+ gdk_pixbuf_unref ( gpixbuf );
+ }
}
}
--- trunk/extragear/multimedia/amarok/src/collection/ipodcollection/handler/IpodHandler.h #938119:938120
@@ -1,6 +1,7 @@
/***************************************************************************
* Ported to Collection Framework: *
* copyright : (C) 2008 Alejandro Wainzinger <aikawarazuni at gmail.com>
+ * copyright : (C) 2009 Seb Ruiz <ruiz at kde.org>
* Original Work: *
* copyright : (C) 2005, 2006 by Martin Aumueller <aumuell at reserv.at>
@@ -82,17 +83,10 @@
Q_OBJECT
public:
- /**
- * Constructor
- */
IpodHandler( IpodCollection *mc, const QString& mountPoint, QObject* parent );
- /**
- * Destructor
- */
~IpodHandler();
/* Get Methods */
-
QString mountPoint() const { return m_mountPoint; }
QMap<Meta::TrackPtr, QString> tracksFailed() const { return m_tracksFailed; }
/**
@@ -131,7 +125,6 @@
bool initializeIpod();
private:
-
/* Handler's Main Methods */
/**
@@ -163,6 +156,7 @@
/* Cover Art functions */
#ifdef GDK_FOUND
+ QByteArray md5sum( const QString& artist, const QString& album ) const;
void getCoverArt( Itdb_Track *ipodtrack, Meta::IpodTrackPtr track );
#endif
void setCoverArt( Itdb_Track *ipodtrack, const QPixmap &image );
More information about the Amarok
mailing list