Changeset View
Changeset View
Standalone View
Standalone View
plugins/mpriscontrol/mpriscontrolplugin.cpp
Show First 20 Lines • Show All 219 Lines • ▼ Show 20 Line(s) | 210 | { | |||
---|---|---|---|---|---|
220 | const QString& playerName = it.key(); | 220 | const QString& playerName = it.key(); | ||
221 | qCDebug(KDECONNECT_PLUGIN_MPRIS) << "Mpris removePlayer" << serviceName << "->" << playerName; | 221 | qCDebug(KDECONNECT_PLUGIN_MPRIS) << "Mpris removePlayer" << serviceName << "->" << playerName; | ||
222 | 222 | | |||
223 | playerList.erase(it); | 223 | playerList.erase(it); | ||
224 | 224 | | |||
225 | sendPlayerList(); | 225 | sendPlayerList(); | ||
226 | } | 226 | } | ||
227 | 227 | | |||
228 | bool MprisControlPlugin::sendAlbumArt(const NetworkPacket& np) | ||||
229 | { | ||||
230 | const QString player = np.get<QString>(QStringLiteral("player")); | ||||
231 | auto it = playerList.find(player); | ||||
232 | bool valid_player = (it != playerList.end()); | ||||
233 | if (!valid_player) { | ||||
234 | return false; | ||||
235 | } | ||||
236 | | ||||
237 | //Get mpris information | ||||
238 | auto& mprisInterface = *it.value().mediaPlayer2PlayerInterface(); | ||||
239 | QVariantMap nowPlayingMap = mprisInterface.metadata(); | ||||
240 | | ||||
241 | //Check if the supplied album art url indeed belongs to this mpris player | ||||
242 | QUrl playerAlbumArtUrl{nowPlayingMap[QStringLiteral("mpris:artUrl")].toString()}; | ||||
243 | QString requestedAlbumArtUrl = np.get<QString>(QStringLiteral("albumArtUrl")); | ||||
244 | if (!playerAlbumArtUrl.isValid() || playerAlbumArtUrl != QUrl(requestedAlbumArtUrl)) { | ||||
245 | return false; | ||||
246 | } | ||||
247 | | ||||
248 | //Only support sending local files | ||||
249 | if (playerAlbumArtUrl.scheme() != "file") { | ||||
250 | return false; | ||||
251 | } | ||||
252 | | ||||
253 | //Open the file to send | ||||
254 | QSharedPointer<QFile> art{new QFile(playerAlbumArtUrl.toLocalFile())}; | ||||
255 | | ||||
256 | //Send the album art as payload | ||||
257 | NetworkPacket answer(PACKET_TYPE_MPRIS); | ||||
258 | answer.set(QStringLiteral("transferringAlbumArt"), true); | ||||
259 | answer.set(QStringLiteral("player"), player); | ||||
260 | answer.set(QStringLiteral("albumArtUrl"), requestedAlbumArtUrl); | ||||
261 | answer.setPayload(art, art->size()); | ||||
262 | sendPacket(answer); | ||||
263 | return true; | ||||
264 | } | ||||
265 | | ||||
228 | bool MprisControlPlugin::receivePacket (const NetworkPacket& np) | 266 | bool MprisControlPlugin::receivePacket (const NetworkPacket& np) | ||
229 | { | 267 | { | ||
230 | if (np.has(QStringLiteral("playerList"))) { | 268 | if (np.has(QStringLiteral("playerList"))) { | ||
231 | return false; //Whoever sent this is an mpris client and not an mpris control! | 269 | return false; //Whoever sent this is an mpris client and not an mpris control! | ||
232 | } | 270 | } | ||
233 | 271 | | |||
272 | if (np.has(QStringLiteral("albumArtUrl"))) { | ||||
273 | return sendAlbumArt(np); | ||||
274 | } | ||||
275 | | ||||
234 | //Send the player list | 276 | //Send the player list | ||
235 | const QString player = np.get<QString>(QStringLiteral("player")); | 277 | const QString player = np.get<QString>(QStringLiteral("player")); | ||
236 | auto it = playerList.find(player); | 278 | auto it = playerList.find(player); | ||
237 | bool valid_player = (it != playerList.end()); | 279 | bool valid_player = (it != playerList.end()); | ||
238 | if (!valid_player || np.get<bool>(QStringLiteral("requestPlayerList"))) { | 280 | if (!valid_player || np.get<bool>(QStringLiteral("requestPlayerList"))) { | ||
239 | sendPlayerList(); | 281 | sendPlayerList(); | ||
240 | if (!valid_player) { | 282 | if (!valid_player) { | ||
241 | return true; | 283 | return true; | ||
▲ Show 20 Lines • Show All 63 Lines • ▼ Show 20 Line(s) | |||||
305 | 347 | | |||
306 | return true; | 348 | return true; | ||
307 | } | 349 | } | ||
308 | 350 | | |||
309 | void MprisControlPlugin::sendPlayerList() | 351 | void MprisControlPlugin::sendPlayerList() | ||
310 | { | 352 | { | ||
311 | NetworkPacket np(PACKET_TYPE_MPRIS); | 353 | NetworkPacket np(PACKET_TYPE_MPRIS); | ||
312 | np.set(QStringLiteral("playerList"),playerList.keys()); | 354 | np.set(QStringLiteral("playerList"),playerList.keys()); | ||
355 | np.set(QStringLiteral("supportAlbumArtPayload"), true); | ||||
313 | sendPacket(np); | 356 | sendPacket(np); | ||
314 | } | 357 | } | ||
315 | 358 | | |||
316 | void MprisControlPlugin::mprisPlayerMetadataToNetworkPacket(NetworkPacket& np, const QVariantMap& nowPlayingMap) const { | 359 | void MprisControlPlugin::mprisPlayerMetadataToNetworkPacket(NetworkPacket& np, const QVariantMap& nowPlayingMap) const { | ||
317 | QString title = nowPlayingMap[QStringLiteral("xesam:title")].toString(); | 360 | QString title = nowPlayingMap[QStringLiteral("xesam:title")].toString(); | ||
318 | QString artist = nowPlayingMap[QStringLiteral("xesam:artist")].toString(); | 361 | QString artist = nowPlayingMap[QStringLiteral("xesam:artist")].toString(); | ||
319 | QString album = nowPlayingMap[QStringLiteral("xesam:album")].toString(); | 362 | QString album = nowPlayingMap[QStringLiteral("xesam:album")].toString(); | ||
320 | QString albumArtUrl = nowPlayingMap[QStringLiteral("mpris:artUrl")].toString(); | 363 | QString albumArtUrl = nowPlayingMap[QStringLiteral("mpris:artUrl")].toString(); | ||
Show All 19 Lines |