Changeset View
Changeset View
Standalone View
Standalone View
plugins/mpriscontrol/mpriscontrolplugin.cpp
Show First 20 Lines • Show All 90 Lines • ▼ Show 20 Line(s) | 77 | { | |||
---|---|---|---|---|---|
91 | qCDebug(KDECONNECT_PLUGIN_MPRIS) << "Mpris addPlayer" << service << "->" << uniqueName; | 91 | qCDebug(KDECONNECT_PLUGIN_MPRIS) << "Mpris addPlayer" << service << "->" << uniqueName; | ||
92 | sendPlayerList(); | 92 | sendPlayerList(); | ||
93 | 93 | | |||
94 | OrgFreedesktopDBusPropertiesInterface* freedesktopInterface = new OrgFreedesktopDBusPropertiesInterface(service, QStringLiteral("/org/mpris/MediaPlayer2"), QDBusConnection::sessionBus(), this); | 94 | OrgFreedesktopDBusPropertiesInterface* freedesktopInterface = new OrgFreedesktopDBusPropertiesInterface(service, QStringLiteral("/org/mpris/MediaPlayer2"), QDBusConnection::sessionBus(), this); | ||
95 | connect(freedesktopInterface, &OrgFreedesktopDBusPropertiesInterface::PropertiesChanged, this, &MprisControlPlugin::propertiesChanged); | 95 | connect(freedesktopInterface, &OrgFreedesktopDBusPropertiesInterface::PropertiesChanged, this, &MprisControlPlugin::propertiesChanged); | ||
96 | 96 | | |||
97 | OrgMprisMediaPlayer2PlayerInterface* mprisInterface0 = new OrgMprisMediaPlayer2PlayerInterface(service, QStringLiteral("/org/mpris/MediaPlayer2"), QDBusConnection::sessionBus()); | 97 | OrgMprisMediaPlayer2PlayerInterface* mprisInterface0 = new OrgMprisMediaPlayer2PlayerInterface(service, QStringLiteral("/org/mpris/MediaPlayer2"), QDBusConnection::sessionBus()); | ||
98 | connect(mprisInterface0, &OrgMprisMediaPlayer2PlayerInterface::Seeked, this, &MprisControlPlugin::seeked); | 98 | connect(mprisInterface0, &OrgMprisMediaPlayer2PlayerInterface::Seeked, this, &MprisControlPlugin::seeked); | ||
99 | | ||||
100 | // init with current status | ||||
101 | QVariantMap properties { | ||||
102 | { QStringLiteral("Volume"), mprisInterface0->volume() }, | ||||
103 | { QStringLiteral("Metadata"), mprisInterface0->metadata() }, | ||||
104 | { QStringLiteral("PlaybackStatus"), mprisInterface0->playbackStatus() }, | ||||
105 | { QStringLiteral("CanPause"), mprisInterface0->canPause() }, | ||||
106 | { QStringLiteral("CanPlay"), mprisInterface0->canPlay() }, | ||||
107 | { QStringLiteral("CanGoNext"), mprisInterface0->canGoNext() }, | ||||
108 | { QStringLiteral("CanGoPrevious"), mprisInterface0->canGoPrevious() }, | ||||
109 | { QStringLiteral("CanSeek"), mprisInterface0->canSeek() }, | ||||
110 | }; | ||||
111 | Q_EMIT freedesktopInterface->PropertiesChanged(QString()/*ignored*/, properties, QStringList()/*ignored*/); | ||||
99 | } | 112 | } | ||
100 | 113 | | |||
101 | void MprisControlPlugin::seeked(qlonglong position){ | 114 | void MprisControlPlugin::seeked(qlonglong position){ | ||
102 | //qCDebug(KDECONNECT_PLUGIN_MPRIS) << "Seeked in player"; | 115 | //qCDebug(KDECONNECT_PLUGIN_MPRIS) << "Seeked in player"; | ||
103 | OrgFreedesktopDBusPropertiesInterface* interface = (OrgFreedesktopDBusPropertiesInterface*)sender(); | 116 | OrgFreedesktopDBusPropertiesInterface* interface = (OrgFreedesktopDBusPropertiesInterface*)sender(); | ||
104 | const QString& service = interface->service(); | 117 | const QString& service = interface->service(); | ||
105 | const QString& player = playerList.key(service); | 118 | const QString& player = playerList.key(service); | ||
106 | 119 | | |||
107 | NetworkPacket np(PACKET_TYPE_MPRIS, { | 120 | NetworkPacket np(PACKET_TYPE_MPRIS, { | ||
108 | {"pos", position/1000}, //Send milis instead of nanos | 121 | {"pos", position/1000}, //Send milis instead of nanos | ||
109 | {"player", player} | 122 | {"player", player} | ||
110 | }); | 123 | }); | ||
111 | sendPacket(np); | 124 | sendPacket(np); | ||
112 | } | 125 | } | ||
113 | 126 | | |||
114 | void MprisControlPlugin::propertiesChanged(const QString& propertyInterface, const QVariantMap& properties) | 127 | void MprisControlPlugin::propertiesChanged(const QString& propertyInterface, const QVariantMap& properties) | ||
115 | { | 128 | { | ||
116 | Q_UNUSED(propertyInterface); | 129 | Q_UNUSED(propertyInterface); | ||
117 | 130 | | |||
131 | // temporary for finding which information is sent to remote | ||||
132 | qDebug() << "KDECONNECT MPRIS UPDATE" << properties; | ||||
133 | | ||||
118 | NetworkPacket np(PACKET_TYPE_MPRIS); | 134 | NetworkPacket np(PACKET_TYPE_MPRIS); | ||
119 | bool somethingToSend = false; | 135 | bool somethingToSend = false; | ||
120 | if (properties.contains(QStringLiteral("Volume"))) { | 136 | if (properties.contains(QStringLiteral("Volume"))) { | ||
121 | int volume = (int) (properties[QStringLiteral("Volume")].toDouble()*100); | 137 | int volume = (int) (properties[QStringLiteral("Volume")].toDouble()*100); | ||
122 | if (volume != prevVolume) { | 138 | if (volume != prevVolume) { | ||
123 | np.set(QStringLiteral("volume"),volume); | 139 | np.set(QStringLiteral("volume"),volume); | ||
124 | prevVolume = volume; | 140 | prevVolume = volume; | ||
125 | somethingToSend = true; | 141 | somethingToSend = true; | ||
▲ Show 20 Lines • Show All 167 Lines • Show Last 20 Lines |