Changeset View
Changeset View
Standalone View
Standalone View
plugins/mprisremote/mprisremoteplugin.cpp
Show First 20 Lines • Show All 44 Lines • ▼ Show 20 Line(s) | 36 | MprisRemotePlugin::MprisRemotePlugin(QObject* parent, const QVariantList& args) | |||
---|---|---|---|---|---|
45 | , m_playerList() | 45 | , m_playerList() | ||
46 | { | 46 | { | ||
47 | } | 47 | } | ||
48 | 48 | | |||
49 | MprisRemotePlugin::~MprisRemotePlugin() | 49 | MprisRemotePlugin::~MprisRemotePlugin() | ||
50 | { | 50 | { | ||
51 | } | 51 | } | ||
52 | 52 | | |||
53 | bool MprisRemotePlugin::receivePackage(const NetworkPackage& np) | 53 | bool MprisRemotePlugin::receivePacket(const NetworkPacket& np) | ||
54 | { | 54 | { | ||
55 | if (np.type() != PACKAGE_TYPE_MPRIS) | 55 | if (np.type() != PACKET_TYPE_MPRIS) | ||
56 | return false; | 56 | return false; | ||
57 | 57 | | |||
58 | if (np.has(QStringLiteral("nowPlaying")) || np.has(QStringLiteral("volume")) || np.has(QStringLiteral("isPlaying")) || np.has(QStringLiteral("length")) || np.has(QStringLiteral("pos"))) { | 58 | if (np.has(QStringLiteral("nowPlaying")) || np.has(QStringLiteral("volume")) || np.has(QStringLiteral("isPlaying")) || np.has(QStringLiteral("length")) || np.has(QStringLiteral("pos"))) { | ||
59 | if (np.get<QString>(QStringLiteral("player")) == m_player) { | 59 | if (np.get<QString>(QStringLiteral("player")) == m_player) { | ||
60 | m_nowPlaying = np.get<QString>(QStringLiteral("nowPlaying"), m_nowPlaying); | 60 | m_nowPlaying = np.get<QString>(QStringLiteral("nowPlaying"), m_nowPlaying); | ||
61 | m_volume = np.get<int>(QStringLiteral("volume"), m_volume); | 61 | m_volume = np.get<int>(QStringLiteral("volume"), m_volume); | ||
62 | m_length = np.get<int>(QStringLiteral("length"), m_length); | 62 | m_length = np.get<int>(QStringLiteral("length"), m_length); | ||
63 | if(np.has(QStringLiteral("pos"))){ | 63 | if(np.has(QStringLiteral("pos"))){ | ||
Show All 23 Lines | |||||
87 | 87 | | |||
88 | QString MprisRemotePlugin::dbusPath() const | 88 | QString MprisRemotePlugin::dbusPath() const | ||
89 | { | 89 | { | ||
90 | return "/modules/kdeconnect/devices/" + device()->id() + "/mprisremote"; | 90 | return "/modules/kdeconnect/devices/" + device()->id() + "/mprisremote"; | ||
91 | } | 91 | } | ||
92 | 92 | | |||
93 | void MprisRemotePlugin::requestPlayerStatus() | 93 | void MprisRemotePlugin::requestPlayerStatus() | ||
94 | { | 94 | { | ||
95 | NetworkPackage np(PACKAGE_TYPE_MPRIS_REQUEST, { | 95 | NetworkPacket np(PACKET_TYPE_MPRIS_REQUEST, { | ||
96 | {"player", m_player}, | 96 | {"player", m_player}, | ||
97 | {"requestNowPlaying", true}, | 97 | {"requestNowPlaying", true}, | ||
98 | {"requestVolume", true}} | 98 | {"requestVolume", true}} | ||
99 | ); | 99 | ); | ||
100 | sendPackage(np); | 100 | sendPacket(np); | ||
101 | } | 101 | } | ||
102 | 102 | | |||
103 | void MprisRemotePlugin::requestPlayerList() | 103 | void MprisRemotePlugin::requestPlayerList() | ||
104 | { | 104 | { | ||
105 | NetworkPackage np(PACKAGE_TYPE_MPRIS_REQUEST, {{"requestPlayerList", true}}); | 105 | NetworkPacket np(PACKET_TYPE_MPRIS_REQUEST, {{"requestPlayerList", true}}); | ||
106 | sendPackage(np); | 106 | sendPacket(np); | ||
107 | } | 107 | } | ||
108 | 108 | | |||
109 | void MprisRemotePlugin::sendAction(const QString& action) | 109 | void MprisRemotePlugin::sendAction(const QString& action) | ||
110 | { | 110 | { | ||
111 | NetworkPackage np(PACKAGE_TYPE_MPRIS_REQUEST, { | 111 | NetworkPacket np(PACKET_TYPE_MPRIS_REQUEST, { | ||
112 | {"player", m_player}, | 112 | {"player", m_player}, | ||
113 | {"action", action} | 113 | {"action", action} | ||
114 | }); | 114 | }); | ||
115 | sendPackage(np); | 115 | sendPacket(np); | ||
116 | } | 116 | } | ||
117 | 117 | | |||
118 | void MprisRemotePlugin::seek(int offset) const | 118 | void MprisRemotePlugin::seek(int offset) const | ||
119 | { | 119 | { | ||
120 | NetworkPackage np(PACKAGE_TYPE_MPRIS_REQUEST, { | 120 | NetworkPacket np(PACKET_TYPE_MPRIS_REQUEST, { | ||
121 | {"player", m_player}, | 121 | {"player", m_player}, | ||
122 | {"Seek", offset}}); | 122 | {"Seek", offset}}); | ||
123 | sendPackage(np); | 123 | sendPacket(np); | ||
124 | } | 124 | } | ||
125 | 125 | | |||
126 | void MprisRemotePlugin::setVolume(int volume) | 126 | void MprisRemotePlugin::setVolume(int volume) | ||
127 | { | 127 | { | ||
128 | NetworkPackage np(PACKAGE_TYPE_MPRIS_REQUEST, { | 128 | NetworkPacket np(PACKET_TYPE_MPRIS_REQUEST, { | ||
129 | {"player", m_player}, | 129 | {"player", m_player}, | ||
130 | {"setVolume",volume} | 130 | {"setVolume",volume} | ||
131 | }); | 131 | }); | ||
132 | sendPackage(np); | 132 | sendPacket(np); | ||
133 | } | 133 | } | ||
134 | 134 | | |||
135 | void MprisRemotePlugin::setPosition(int position) | 135 | void MprisRemotePlugin::setPosition(int position) | ||
136 | { | 136 | { | ||
137 | NetworkPackage np(PACKAGE_TYPE_MPRIS_REQUEST, { | 137 | NetworkPacket np(PACKET_TYPE_MPRIS_REQUEST, { | ||
138 | {"player", m_player}, | 138 | {"player", m_player}, | ||
139 | {"SetPosition", position} | 139 | {"SetPosition", position} | ||
140 | }); | 140 | }); | ||
141 | sendPackage(np); | 141 | sendPacket(np); | ||
142 | 142 | | |||
143 | m_lastPosition = position; | 143 | m_lastPosition = position; | ||
144 | m_lastPositionTime = QDateTime::currentMSecsSinceEpoch(); | 144 | m_lastPositionTime = QDateTime::currentMSecsSinceEpoch(); | ||
145 | } | 145 | } | ||
146 | 146 | | |||
147 | void MprisRemotePlugin::setPlayer(const QString& player) | 147 | void MprisRemotePlugin::setPlayer(const QString& player) | ||
148 | { | 148 | { | ||
149 | if (m_player != player) { | 149 | if (m_player != player) { | ||
150 | m_player = player; | 150 | m_player = player; | ||
151 | requestPlayerStatus(); | 151 | requestPlayerStatus(); | ||
152 | } | 152 | } | ||
153 | } | 153 | } | ||
154 | 154 | | |||
155 | #include "mprisremoteplugin.moc" | 155 | #include "mprisremoteplugin.moc" |