diff options
| author | Tomasz Sterna <tomek@xiaoka.com> | 2014-07-18 00:59:33 +0200 |
|---|---|---|
| committer | Tomasz Sterna <tomek@xiaoka.com> | 2014-07-18 00:59:33 +0200 |
| commit | 524a0a854c4cafad8ccbc645a858029bf97a045e (patch) | |
| tree | 3db75d07ea01f6647b975e7991325d381ed60b1b /daemon/watchcommands.cpp | |
| parent | 7d8f121652ceecc371a5f73986e2ef8fc2f1e4be (diff) | |
Implemented Music ControlRELASE_0.6
Diffstat (limited to 'daemon/watchcommands.cpp')
| -rw-r--r-- | daemon/watchcommands.cpp | 86 |
1 files changed, 83 insertions, 3 deletions
diff --git a/daemon/watchcommands.cpp b/daemon/watchcommands.cpp index 1df811a..9cd95b5 100644 --- a/daemon/watchcommands.cpp +++ b/daemon/watchcommands.cpp @@ -1,15 +1,17 @@ #include "watchcommands.h" +#include <QDBusConnection> +#include <QDBusMessage> +#include <QDBusReply> + using namespace watch; WatchCommands::WatchCommands(WatchConnector *watch, QObject *parent) : QObject(parent), watch(watch) {} -void WatchCommands::processMessage(uint endpoint, uint datalen, QByteArray data) +void WatchCommands::processMessage(uint endpoint, QByteArray data) { - Q_UNUSED(datalen); - logger()->debug() << __FUNCTION__ << endpoint << "/" << data.length(); switch (endpoint) { case WatchConnector::watchPHONE_VERSION: @@ -22,6 +24,7 @@ void WatchCommands::processMessage(uint endpoint, uint datalen, QByteArray data) break; case WatchConnector::watchMUSIC_CONTROL: logger()->debug() << "MUSIC_CONTROL" << data.toHex(); + musicControl(WatchConnector::MusicControl(data.at(0))); break; default: @@ -37,3 +40,80 @@ void WatchCommands::onMprisMetadataChanged(QVariantMap metadata) logger()->debug() << __FUNCTION__ << track << album << artist; watch->sendMusicNowPlaying(track, album, artist); } + +void WatchCommands::musicControl(WatchConnector::MusicControl operation) +{ + logger()->debug() << "Operation:" << operation; + + QString mpris = parent()->property("mpris").toString(); + if (mpris.isEmpty()) { + logger()->debug() << "No mpris interface active"; + return; + } + + QString method; + + switch(operation) { + case WatchConnector::musicPLAY_PAUSE: + method = "PlayPause"; + break; + case WatchConnector::musicPAUSE: + method = "Pause"; + break; + case WatchConnector::musicPLAY: + method = "Play"; + break; + case WatchConnector::musicNEXT: + method = "Next"; + break; + case WatchConnector::musicPREVIOUS: + method = "Previous"; + break; + case WatchConnector::musicVOLUME_UP: + case WatchConnector::musicVOLUME_DOWN: { + QDBusReply<QDBusVariant> VolumeReply = QDBusConnection::sessionBus().call( + QDBusMessage::createMethodCall(mpris, "/org/mpris/MediaPlayer2", "org.freedesktop.DBus.Properties", "Get") + << "org.mpris.MediaPlayer2.Player" << "Volume"); + if (VolumeReply.isValid()) { + double volume = VolumeReply.value().variant().toDouble(); + if (operation == WatchConnector::musicVOLUME_UP) { + volume += 0.1; + } + else { + volume -= 0.1; + } + logger()->debug() << "Setting volume" << volume; + QDBusError err = QDBusConnection::sessionBus().call( + QDBusMessage::createMethodCall(mpris, "/org/mpris/MediaPlayer2", "org.freedesktop.DBus.Properties", "Set") + << "org.mpris.MediaPlayer2.Player" << "Volume" << QVariant::fromValue(QDBusVariant(volume))); + if (err.isValid()) { + logger()->error() << err.message(); + } + } + else { + logger()->error() << VolumeReply.error().message(); + } + } + return; + case WatchConnector::musicGET_NOW_PLAYING: + onMprisMetadataChanged(parent()->property("mprisMetadata").toMap()); + return; + + case WatchConnector::musicSEND_NOW_PLAYING: + logger()->warn() << "Operation" << operation << "not supported"; + return; + } + + if (method.isEmpty()) { + logger()->error() << "Requested unsupported operation" << operation; + return; + } + + logger()->debug() << operation << "->" << method; + + QDBusError err = QDBusConnection::sessionBus().call( + QDBusMessage::createMethodCall(mpris, "/org/mpris/MediaPlayer2", "org.mpris.MediaPlayer2.Player", method)); + if (err.isValid()) { + logger()->error() << err.message(); + } +} |
