Commit 1d76434d authored by Michael Pyne's avatar Michael Pyne

Add trackCover method to JuK's D-Bus Collection interface.

svn path=/trunk/KDE/kdemultimedia/juk/; revision=923034
parent 24866caa
......@@ -15,10 +15,19 @@
#include "dbuscollectionproxy.h"
#include <QtCore/QStringList>
#include <QtCore/QFile>
#include <QtGui/QPixmap>
#include <QtDBus/QDBusConnection>
#include <KTemporaryFile>
#include <kdebug.h>
#include "collectionadaptor.h"
#include "playlistcollection.h"
#include "covermanager.h"
#include "collectionlist.h"
#include "coverinfo.h"
#include "filehandle.h"
DBusCollectionProxy::DBusCollectionProxy (QObject *parent, PlaylistCollection *collection) :
QObject(parent), m_collection(collection)
......@@ -93,3 +102,42 @@ void DBusCollectionProxy::removeTrack(const QString &playlist, const QStringList
{
m_collection->removeTrack(playlist, files);
}
QString DBusCollectionProxy::trackCover(const QString &track)
{
coverKey id = CoverManager::idForTrack(track);
if(id != CoverManager::NoMatch) {
CoverDataPtr coverData = CoverManager::coverInfo(id);
return coverData->path;
}
// No cover, let's see if one is embedded.
CollectionListItem *collectionItem = CollectionList::instance()->lookup(track);
if(!collectionItem)
return QString();
CoverInfo *coverInfo = collectionItem->file().coverInfo();
if(!coverInfo)
return QString();
QPixmap cover = coverInfo->pixmap(CoverInfo::FullSize);
if(cover.isNull())
return QString();
// We have a cover, extract it and save it to a temporary file.
KTemporaryFile tempFile;
tempFile.setSuffix(".png");
tempFile.setAutoRemove(false);
if(!tempFile.open()) {
kError() << "Unable to open temporary file for embedded cover art.";
return QString();
}
cover.save(&tempFile, "PNG");
return tempFile.fileName();
}
// vim: set et sw=4 tw=0 sta:
......@@ -46,6 +46,14 @@ public slots: // Expose to D-Bus
void remove();
void removeTrack(const QString &playlist, const QStringList &files);
/**
* Returns the path to the cover art for the given file. Returns the empty
* string if the track has no cover art. Some tracks have embedded cover
* art -- in this case JuK returns the path to a temporary file with the
* extracted cover art.
*/
QString trackCover(const QString &track);
private:
PlaylistCollection *m_collection;
};
......
<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN"
"http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd">
<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN" "http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd">
<node>
<interface name="org.kde.juk.collection">
<method name="playlists">
<arg type="as" direction="out"/>
</method>
<method name="openFile">
<arg name="file" type="s" direction="in"/>
</method>
......@@ -19,31 +15,39 @@
<arg name="playlist" type="s" direction="in"/>
<arg name="files" type="as" direction="in"/>
</method>
<method name="createPlaylist">
<arg name="list" type="s" direction="in"/>
</method>
<method name="remove"/>
<method name="removeTrack">
<arg name="playlist" type="s" direction="in"/>
<arg name="files" type="as" direction="in"/>
</method>
<method name="visiblePlaylist">
<arg type="s" direction="out"/>
</method>
<method name="playingPlaylist">
<arg type="s" direction="out"/>
</method>
<method name="setPlaylist">
<arg name="playlist" type="s" direction="in"/>
<method name="playlists">
<arg type="as" direction="out"/>
</method>
<method name="playlistTracks">
<arg name="playlist" type="s" direction="in"/>
<arg type="as" direction="out"/>
<arg name="playlist" type="s" direction="in"/>
</method>
<method name="trackProperty">
<arg type="s" direction="out"/>
<arg name="file" type="s" direction="in"/>
<arg name="property" type="s" direction="in"/>
</method>
<method name="createPlaylist">
<arg name="name" type="s" direction="in"/>
</method>
<method name="setPlaylist">
<arg name="name" type="s" direction="in"/>
</method>
<method name="remove">
</method>
<method name="removeTrack">
<arg name="playlist" type="s" direction="in"/>
<arg name="files" type="as" direction="in"/>
</method>
<method name="trackCover">
<arg type="s" direction="out"/>
<arg name="track" type="s" direction="in"/>
</method>
</interface>
</node>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment