Changeset View
Changeset View
Standalone View
Standalone View
plugins/mpriscontrol/mpriscontrolplugin.cpp
Show First 20 Lines • Show All 98 Lines • ▼ Show 20 Line(s) | |||||
99 | } | 99 | } | ||
100 | 100 | | |||
101 | void MprisControlPlugin::seeked(qlonglong position){ | 101 | void MprisControlPlugin::seeked(qlonglong position){ | ||
102 | //qCDebug(KDECONNECT_PLUGIN_MPRIS) << "Seeked in player"; | 102 | //qCDebug(KDECONNECT_PLUGIN_MPRIS) << "Seeked in player"; | ||
103 | OrgFreedesktopDBusPropertiesInterface* interface = (OrgFreedesktopDBusPropertiesInterface*)sender(); | 103 | OrgFreedesktopDBusPropertiesInterface* interface = (OrgFreedesktopDBusPropertiesInterface*)sender(); | ||
104 | const QString& service = interface->service(); | 104 | const QString& service = interface->service(); | ||
105 | const QString& player = playerList.key(service); | 105 | const QString& player = playerList.key(service); | ||
106 | 106 | | |||
107 | NetworkPackage np(PACKAGE_TYPE_MPRIS, { | 107 | NetworkPacket np(PACKET_TYPE_MPRIS, { | ||
108 | {"pos", position/1000}, //Send milis instead of nanos | 108 | {"pos", position/1000}, //Send milis instead of nanos | ||
109 | {"player", player} | 109 | {"player", player} | ||
110 | }); | 110 | }); | ||
111 | sendPackage(np); | 111 | sendPacket(np); | ||
112 | } | 112 | } | ||
113 | 113 | | |||
114 | void MprisControlPlugin::propertiesChanged(const QString& propertyInterface, const QVariantMap& properties) | 114 | void MprisControlPlugin::propertiesChanged(const QString& propertyInterface, const QVariantMap& properties) | ||
115 | { | 115 | { | ||
116 | Q_UNUSED(propertyInterface); | 116 | Q_UNUSED(propertyInterface); | ||
117 | 117 | | |||
118 | NetworkPackage np(PACKAGE_TYPE_MPRIS); | 118 | NetworkPacket np(PACKET_TYPE_MPRIS); | ||
119 | bool somethingToSend = false; | 119 | bool somethingToSend = false; | ||
120 | if (properties.contains(QStringLiteral("Volume"))) { | 120 | if (properties.contains(QStringLiteral("Volume"))) { | ||
121 | int volume = (int) (properties[QStringLiteral("Volume")].toDouble()*100); | 121 | int volume = (int) (properties[QStringLiteral("Volume")].toDouble()*100); | ||
122 | if (volume != prevVolume) { | 122 | if (volume != prevVolume) { | ||
123 | np.set(QStringLiteral("volume"),volume); | 123 | np.set(QStringLiteral("volume"),volume); | ||
124 | prevVolume = volume; | 124 | prevVolume = volume; | ||
125 | somethingToSend = true; | 125 | somethingToSend = true; | ||
126 | } | 126 | } | ||
127 | } | 127 | } | ||
128 | if (properties.contains(QStringLiteral("Metadata"))) { | 128 | if (properties.contains(QStringLiteral("Metadata"))) { | ||
129 | QDBusArgument bullshit = qvariant_cast<QDBusArgument>(properties[QStringLiteral("Metadata")]); | 129 | QDBusArgument bullshit = qvariant_cast<QDBusArgument>(properties[QStringLiteral("Metadata")]); | ||
130 | QVariantMap nowPlayingMap; | 130 | QVariantMap nowPlayingMap; | ||
131 | bullshit >> nowPlayingMap; | 131 | bullshit >> nowPlayingMap; | ||
132 | 132 | | |||
133 | mprisPlayerMetadataToNetworkPackage(np, nowPlayingMap); | 133 | mprisPlayerMetadataToNetworkPacket(np, nowPlayingMap); | ||
134 | somethingToSend = true; | 134 | somethingToSend = true; | ||
135 | } | 135 | } | ||
136 | if (properties.contains(QStringLiteral("PlaybackStatus"))) { | 136 | if (properties.contains(QStringLiteral("PlaybackStatus"))) { | ||
137 | bool playing = (properties[QStringLiteral("PlaybackStatus")].toString() == QLatin1String("Playing")); | 137 | bool playing = (properties[QStringLiteral("PlaybackStatus")].toString() == QLatin1String("Playing")); | ||
138 | np.set(QStringLiteral("isPlaying"), playing); | 138 | np.set(QStringLiteral("isPlaying"), playing); | ||
139 | somethingToSend = true; | 139 | somethingToSend = true; | ||
140 | } | 140 | } | ||
141 | if (properties.contains(QStringLiteral("CanPause"))) { | 141 | if (properties.contains(QStringLiteral("CanPause"))) { | ||
Show All 23 Lines | 162 | if (somethingToSend) { | |||
165 | const QString& player = playerList.key(service); | 165 | const QString& player = playerList.key(service); | ||
166 | np.set(QStringLiteral("player"), player); | 166 | np.set(QStringLiteral("player"), player); | ||
167 | // Always also update the position | 167 | // Always also update the position | ||
168 | OrgMprisMediaPlayer2PlayerInterface mprisInterface(service, QStringLiteral("/org/mpris/MediaPlayer2"), QDBusConnection::sessionBus()); | 168 | OrgMprisMediaPlayer2PlayerInterface mprisInterface(service, QStringLiteral("/org/mpris/MediaPlayer2"), QDBusConnection::sessionBus()); | ||
169 | if (mprisInterface.canSeek()) { | 169 | if (mprisInterface.canSeek()) { | ||
170 | long long pos = mprisInterface.position(); | 170 | long long pos = mprisInterface.position(); | ||
171 | np.set(QStringLiteral("pos"), pos/1000); //Send milis instead of nanos | 171 | np.set(QStringLiteral("pos"), pos/1000); //Send milis instead of nanos | ||
172 | } | 172 | } | ||
173 | sendPackage(np); | 173 | sendPacket(np); | ||
174 | } | 174 | } | ||
175 | } | 175 | } | ||
176 | 176 | | |||
177 | void MprisControlPlugin::removePlayer(const QString& ifaceName) | 177 | void MprisControlPlugin::removePlayer(const QString& ifaceName) | ||
178 | { | 178 | { | ||
179 | const QString identity = playerList.key(ifaceName); | 179 | const QString identity = playerList.key(ifaceName); | ||
180 | qCDebug(KDECONNECT_PLUGIN_MPRIS) << "Mpris removePlayer" << ifaceName << "->" << identity; | 180 | qCDebug(KDECONNECT_PLUGIN_MPRIS) << "Mpris removePlayer" << ifaceName << "->" << identity; | ||
181 | playerList.remove(identity); | 181 | playerList.remove(identity); | ||
182 | sendPlayerList(); | 182 | sendPlayerList(); | ||
183 | } | 183 | } | ||
184 | 184 | | |||
185 | bool MprisControlPlugin::receivePackage (const NetworkPackage& np) | 185 | bool MprisControlPlugin::receivePacket (const NetworkPacket& np) | ||
186 | { | 186 | { | ||
187 | if (np.has(QStringLiteral("playerList"))) { | 187 | if (np.has(QStringLiteral("playerList"))) { | ||
188 | return false; //Whoever sent this is an mpris client and not an mpris control! | 188 | return false; //Whoever sent this is an mpris client and not an mpris control! | ||
189 | } | 189 | } | ||
190 | 190 | | |||
191 | //Send the player list | 191 | //Send the player list | ||
192 | const QString player = np.get<QString>(QStringLiteral("player")); | 192 | const QString player = np.get<QString>(QStringLiteral("player")); | ||
193 | bool valid_player = playerList.contains(player); | 193 | bool valid_player = playerList.contains(player); | ||
Show All 27 Lines | |||||
221 | if (np.has(QStringLiteral("SetPosition"))){ | 221 | if (np.has(QStringLiteral("SetPosition"))){ | ||
222 | qlonglong position = np.get<qlonglong>(QStringLiteral("SetPosition"),0)*1000; | 222 | qlonglong position = np.get<qlonglong>(QStringLiteral("SetPosition"),0)*1000; | ||
223 | qlonglong seek = position - mprisInterface.position(); | 223 | qlonglong seek = position - mprisInterface.position(); | ||
224 | //qCDebug(KDECONNECT_PLUGIN_MPRIS) << "Setting position by seeking" << seek << "to" << playerList[player]; | 224 | //qCDebug(KDECONNECT_PLUGIN_MPRIS) << "Setting position by seeking" << seek << "to" << playerList[player]; | ||
225 | mprisInterface.Seek(seek); | 225 | mprisInterface.Seek(seek); | ||
226 | } | 226 | } | ||
227 | 227 | | |||
228 | //Send something read from the mpris interface | 228 | //Send something read from the mpris interface | ||
229 | NetworkPackage answer(PACKAGE_TYPE_MPRIS); | 229 | NetworkPacket answer(PACKET_TYPE_MPRIS); | ||
230 | bool somethingToSend = false; | 230 | bool somethingToSend = false; | ||
231 | if (np.get<bool>(QStringLiteral("requestNowPlaying"))) { | 231 | if (np.get<bool>(QStringLiteral("requestNowPlaying"))) { | ||
232 | QVariantMap nowPlayingMap = mprisInterface.metadata(); | 232 | QVariantMap nowPlayingMap = mprisInterface.metadata(); | ||
233 | mprisPlayerMetadataToNetworkPackage(answer, nowPlayingMap); | 233 | mprisPlayerMetadataToNetworkPacket(answer, nowPlayingMap); | ||
234 | 234 | | |||
235 | qlonglong pos = mprisInterface.position(); | 235 | qlonglong pos = mprisInterface.position(); | ||
236 | answer.set(QStringLiteral("pos"), pos/1000); | 236 | answer.set(QStringLiteral("pos"), pos/1000); | ||
237 | 237 | | |||
238 | bool playing = (mprisInterface.playbackStatus() == QLatin1String("Playing")); | 238 | bool playing = (mprisInterface.playbackStatus() == QLatin1String("Playing")); | ||
239 | answer.set(QStringLiteral("isPlaying"), playing); | 239 | answer.set(QStringLiteral("isPlaying"), playing); | ||
240 | 240 | | |||
241 | answer.set(QStringLiteral("canPause"), mprisInterface.canPause()); | 241 | answer.set(QStringLiteral("canPause"), mprisInterface.canPause()); | ||
242 | answer.set(QStringLiteral("canPlay"), mprisInterface.canPlay()); | 242 | answer.set(QStringLiteral("canPlay"), mprisInterface.canPlay()); | ||
243 | answer.set(QStringLiteral("canGoNext"), mprisInterface.canGoNext()); | 243 | answer.set(QStringLiteral("canGoNext"), mprisInterface.canGoNext()); | ||
244 | answer.set(QStringLiteral("canGoPrevious"), mprisInterface.canGoPrevious()); | 244 | answer.set(QStringLiteral("canGoPrevious"), mprisInterface.canGoPrevious()); | ||
245 | answer.set(QStringLiteral("canSeek"), mprisInterface.canSeek()); | 245 | answer.set(QStringLiteral("canSeek"), mprisInterface.canSeek()); | ||
246 | 246 | | |||
247 | somethingToSend = true; | 247 | somethingToSend = true; | ||
248 | } | 248 | } | ||
249 | if (np.get<bool>(QStringLiteral("requestVolume"))) { | 249 | if (np.get<bool>(QStringLiteral("requestVolume"))) { | ||
250 | int volume = (int)(mprisInterface.volume() * 100); | 250 | int volume = (int)(mprisInterface.volume() * 100); | ||
251 | answer.set(QStringLiteral("volume"),volume); | 251 | answer.set(QStringLiteral("volume"),volume); | ||
252 | somethingToSend = true; | 252 | somethingToSend = true; | ||
253 | } | 253 | } | ||
254 | if (somethingToSend) { | 254 | if (somethingToSend) { | ||
255 | answer.set(QStringLiteral("player"), player); | 255 | answer.set(QStringLiteral("player"), player); | ||
256 | sendPackage(answer); | 256 | sendPacket(answer); | ||
257 | } | 257 | } | ||
258 | 258 | | |||
259 | return true; | 259 | return true; | ||
260 | } | 260 | } | ||
261 | 261 | | |||
262 | void MprisControlPlugin::sendPlayerList() | 262 | void MprisControlPlugin::sendPlayerList() | ||
263 | { | 263 | { | ||
264 | NetworkPackage np(PACKAGE_TYPE_MPRIS); | 264 | NetworkPacket np(PACKET_TYPE_MPRIS); | ||
265 | np.set(QStringLiteral("playerList"),playerList.keys()); | 265 | np.set(QStringLiteral("playerList"),playerList.keys()); | ||
266 | sendPackage(np); | 266 | sendPacket(np); | ||
267 | } | 267 | } | ||
268 | 268 | | |||
269 | void MprisControlPlugin::mprisPlayerMetadataToNetworkPackage(NetworkPackage& np, const QVariantMap& nowPlayingMap) const { | 269 | void MprisControlPlugin::mprisPlayerMetadataToNetworkPacket(NetworkPacket& np, const QVariantMap& nowPlayingMap) const { | ||
270 | QString title = nowPlayingMap[QStringLiteral("xesam:title")].toString(); | 270 | QString title = nowPlayingMap[QStringLiteral("xesam:title")].toString(); | ||
271 | QString artist = nowPlayingMap[QStringLiteral("xesam:artist")].toString(); | 271 | QString artist = nowPlayingMap[QStringLiteral("xesam:artist")].toString(); | ||
272 | QString album = nowPlayingMap[QStringLiteral("xesam:album")].toString(); | 272 | QString album = nowPlayingMap[QStringLiteral("xesam:album")].toString(); | ||
273 | QString albumArtUrl = nowPlayingMap[QStringLiteral("mpris:artUrl")].toString(); | 273 | QString albumArtUrl = nowPlayingMap[QStringLiteral("mpris:artUrl")].toString(); | ||
274 | QString nowPlaying = title; | 274 | QString nowPlaying = title; | ||
275 | if (!artist.isEmpty()) { | 275 | if (!artist.isEmpty()) { | ||
276 | nowPlaying = artist + " - " + title; | 276 | nowPlaying = artist + " - " + title; | ||
277 | } | 277 | } | ||
Show All 15 Lines |