Commit 33c2a100 authored by Matthijs Tijink's avatar Matthijs Tijink

Support file url album art - Desktop

Summary: If the android code sees a file url, and album art is needed, it will start a request to transfer the album art. This code does some sanity checks to prevent abuse and then transfers the album art.

Test Plan: Art is transferred succesfully.

Reviewers: #kde_connect, nicolasfella, albertvaka

Reviewed By: #kde_connect, albertvaka

Subscribers: nicolasfella, albertvaka

Differential Revision:
parent 22d14de0
......@@ -225,12 +225,54 @@ void MprisControlPlugin::removePlayer(const QString& serviceName)
bool MprisControlPlugin::sendAlbumArt(const NetworkPacket& np)
const QString player = np.get<QString>(QStringLiteral("player"));
auto it = playerList.find(player);
bool valid_player = (it != playerList.end());
if (!valid_player) {
return false;
//Get mpris information
auto& mprisInterface = *it.value().mediaPlayer2PlayerInterface();
QVariantMap nowPlayingMap = mprisInterface.metadata();
//Check if the supplied album art url indeed belongs to this mpris player
QUrl playerAlbumArtUrl{nowPlayingMap[QStringLiteral("mpris:artUrl")].toString()};
QString requestedAlbumArtUrl = np.get<QString>(QStringLiteral("albumArtUrl"));
if (!playerAlbumArtUrl.isValid() || playerAlbumArtUrl != QUrl(requestedAlbumArtUrl)) {
return false;
//Only support sending local files
if (playerAlbumArtUrl.scheme() != "file") {
return false;
//Open the file to send
QSharedPointer<QFile> art{new QFile(playerAlbumArtUrl.toLocalFile())};
//Send the album art as payload
NetworkPacket answer(PACKET_TYPE_MPRIS);
answer.set(QStringLiteral("transferringAlbumArt"), true);
answer.set(QStringLiteral("player"), player);
answer.set(QStringLiteral("albumArtUrl"), requestedAlbumArtUrl);
answer.setPayload(art, art->size());
return true;
bool MprisControlPlugin::receivePacket (const NetworkPacket& np)
if (np.has(QStringLiteral("playerList"))) {
return false; //Whoever sent this is an mpris client and not an mpris control!
if (np.has(QStringLiteral("albumArtUrl"))) {
return sendAlbumArt(np);
//Send the player list
const QString player = np.get<QString>(QStringLiteral("player"));
auto it = playerList.find(player);
......@@ -310,6 +352,7 @@ void MprisControlPlugin::sendPlayerList()
NetworkPacket np(PACKET_TYPE_MPRIS);
np.set(QStringLiteral("supportAlbumArtPayload"), true);
......@@ -76,6 +76,7 @@ private:
void removePlayer(const QString& serviceName);
void sendPlayerList();
void mprisPlayerMetadataToNetworkPacket(NetworkPacket& np, const QVariantMap& nowPlayingMap) const;
bool sendAlbumArt(const NetworkPacket& np);
QHash<QString, MprisPlayer> playerList;
int prevVolume;
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment