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: https://phabricator.kde.org/D11017
This commit is contained in:
parent
22d14de018
commit
33c2a100b1
2 changed files with 44 additions and 0 deletions
|
@ -225,12 +225,54 @@ void MprisControlPlugin::removePlayer(const QString& serviceName)
|
|||
sendPlayerList();
|
||||
}
|
||||
|
||||
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());
|
||||
sendPacket(answer);
|
||||
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("playerList"),playerList.keys());
|
||||
np.set(QStringLiteral("supportAlbumArtPayload"), true);
|
||||
sendPacket(np);
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue