summaryrefslogtreecommitdiff
path: root/daemon/manager.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'daemon/manager.cpp')
-rw-r--r--daemon/manager.cpp82
1 files changed, 76 insertions, 6 deletions
diff --git a/daemon/manager.cpp b/daemon/manager.cpp
index 0a5d722..ec0d21b 100644
--- a/daemon/manager.cpp
+++ b/daemon/manager.cpp
@@ -6,7 +6,7 @@
#include <QtContacts/QContactPhoneNumber>
Manager::Manager(watch::WatchConnector *watch, DBusConnector *dbus, VoiceCallManager *voice, NotificationManager *notifications) :
- QObject(0), watch(watch), dbus(dbus), voice(voice), notifications(notifications),
+ QObject(0), watch(watch), dbus(dbus), voice(voice), notifications(notifications), commands(new WatchCommands(watch, this)),
notification(MNotification::DeviceEvent)
{
// We don't need to handle presence changes, so report them separately and ignore them
@@ -17,6 +17,8 @@ Manager::Manager(watch::WatchConnector *watch, DBusConnector *dbus, VoiceCallMan
numberFilter.setDetailType(QContactDetail::TypePhoneNumber, QContactPhoneNumber::FieldNumber);
numberFilter.setMatchFlags(QContactFilter::MatchPhoneNumber);
+ connect(watch, SIGNAL(connectedChanged()), SLOT(onConnectedChanged()));
+
connect(voice, SIGNAL(activeVoiceCallChanged()), SLOT(onActiveVoiceCallChanged()));
connect(voice, SIGNAL(error(const QString &)), SLOT(onVoiceError(const QString &)));
@@ -24,8 +26,8 @@ Manager::Manager(watch::WatchConnector *watch, DBusConnector *dbus, VoiceCallMan
connect(notifications, SIGNAL(emailNotify(const QString &,const QString &,const QString &)), SLOT(onEmailNotify(const QString &,const QString &,const QString &)));
connect(notifications, SIGNAL(smsNotify(const QString &,const QString &)), SLOT(onSmsNotify(const QString &,const QString &)));
- connect(watch, SIGNAL(hangup()), SLOT(hangupAll()));
- connect(watch, SIGNAL(connectedChanged()), SLOT(onConnectedChanged()));
+ connect(watch, SIGNAL(messageDecoded(uint,uint,QByteArray)), commands, SLOT(processMessage(uint,uint,QByteArray)));
+ connect(commands, SIGNAL(hangup()), SLOT(hangupAll()));
// Set BT icon for notification
notification.setImage("icon-system-bluetooth-device");
@@ -38,11 +40,18 @@ Manager::Manager(watch::WatchConnector *watch, DBusConnector *dbus, VoiceCallMan
PebbledProxy *proxy = new PebbledProxy(this);
PebbledAdaptor *adaptor = new PebbledAdaptor(proxy);
- QDBusConnection connection = QDBusConnection::sessionBus();
- connection.registerObject("/", proxy);
- connection.registerService("org.pebbled");
+ QDBusConnection session = QDBusConnection::sessionBus();
+ session.registerObject("/", proxy);
+ session.registerService("org.pebbled");
connect(dbus, SIGNAL(pebbleChanged()), adaptor, SIGNAL(pebbleChanged()));
connect(watch, SIGNAL(connectedChanged()), adaptor, SIGNAL(connectedChanged()));
+
+ // Music Control interface
+ session.connect("", "/org/mpris/MediaPlayer2",
+ "org.freedesktop.DBus.Properties", "PropertiesChanged",
+ this, SLOT(onMprisPropertiesChanged(QString,QMap<QString,QVariant>,QStringList)));
+
+ connect(this, SIGNAL(mprisMetadataChanged(QVariantMap)), commands, SLOT(onMprisMetadataChanged(QVariantMap)));
}
void Manager::onPebbleChanged()
@@ -69,6 +78,22 @@ void Manager::onConnectedChanged()
if (!notification.publish()) {
logger()->debug() << "Failed publishing notification";
}
+
+ if (watch->isConnected()) {
+ QString mpris = this->mpris();
+ if (not mpris.isEmpty()) {
+ QDBusReply<QDBusVariant> Metadata = QDBusConnection::sessionBus().call(
+ QDBusMessage::createMethodCall(mpris, "/org/mpris/MediaPlayer2", "org.freedesktop.DBus.Properties", "Get")
+ << "org.mpris.MediaPlayer2.Player" << "Metadata");
+ if (Metadata.isValid()) {
+ setMprisMetadata(Metadata.value().variant().value<QDBusArgument>());
+ }
+ else {
+ logger()->error() << Metadata.error().message();
+ setMprisMetadata(QVariantMap());
+ }
+ }
+ }
}
void Manager::onActiveVoiceCallChanged()
@@ -173,3 +198,48 @@ void Manager::hangupAll()
handler->hangup();
}
}
+
+void Manager::onMprisPropertiesChanged(QString interface, QMap<QString,QVariant> changed, QStringList invalidated)
+{
+ qDebug() << interface << changed << invalidated;
+
+ if (changed.contains("Metadata")) {
+ setMprisMetadata(changed.value("Metadata").value<QDBusArgument>());
+ }
+
+ if (changed.contains("PlaybackStatus")) {
+ QString PlaybackStatus = changed.value("PlaybackStatus").toString();
+ if (PlaybackStatus == "Stopped") {
+ setMprisMetadata(QVariantMap());
+ }
+ }
+
+ lastSeenMpris = message().service();
+}
+
+QString Manager::mpris()
+{
+ const QStringList &services = dbus->services();
+ if (not lastSeenMpris.isEmpty() && services.contains(lastSeenMpris))
+ return lastSeenMpris;
+
+ foreach (QString service,services)
+ if (service.startsWith("org.mpris.MediaPlayer2."))
+ return service;
+
+ return QString();
+}
+
+void Manager::setMprisMetadata(QDBusArgument metadata)
+{
+ if (metadata.currentType() == QDBusArgument::MapType) {
+ metadata >> mprisMetadata;
+ emit mprisMetadataChanged(mprisMetadata);
+ }
+}
+
+void Manager::setMprisMetadata(QVariantMap metadata)
+{
+ mprisMetadata = metadata;
+ emit mprisMetadataChanged(mprisMetadata);
+}