From 8da20a7c3088aee2b04d45feeee8ca0753dc260e Mon Sep 17 00:00:00 2001 From: Andrew Branson Date: Fri, 17 Apr 2015 16:56:00 +0200 Subject: Test MPRIS volume control to see if the setting changes when we alter it. If it fails, use system volume instead, if enabled by config property. --- app/qml/pages/ManagerPage.qml | 10 ++++ app/translations/pebble-es.ts | 70 +++++++++++++++------------ app/translations/pebble-pl.ts | 70 +++++++++++++++------------ app/translations/pebble.ts | 70 +++++++++++++++------------ daemon/manager.cpp | 2 +- daemon/musicmanager.cpp | 109 +++++++++++++++++++++++++++++++++++++----- daemon/musicmanager.h | 5 +- daemon/settings.h | 3 ++ 8 files changed, 236 insertions(+), 103 deletions(-) diff --git a/app/qml/pages/ManagerPage.qml b/app/qml/pages/ManagerPage.qml index 894797d..0c393a3 100644 --- a/app/qml/pages/ManagerPage.qml +++ b/app/qml/pages/ManagerPage.qml @@ -11,6 +11,7 @@ Page { path: "/org/pebbled/settings" property bool silentWhenConnected: false property bool transliterateMessage: false + property bool useSystemVolume: true property bool incomingCallNotification: true property bool notificationsCommhistoryd: true property bool notificationsMissedCall: true @@ -132,6 +133,15 @@ Page { settings.silentWhenConnected = !settings.silentWhenConnected; } } + TextSwitch { + text: qsTr("Alter system volume") + description: qsTr("Pebble music volume buttons change the system volume when the music player cannot") + checked: settings.useSystemVolume + automaticCheck: true + onClicked: { + settings.useSystemVolume = !settings.useSystemVolume; + } + } TextSwitch { text: qsTr("Transliterate messages") description: qsTr("Messages are transliterated to ASCII before sending to Pebble") diff --git a/app/translations/pebble-es.ts b/app/translations/pebble-es.ts index 6bdb778..7ee4e71 100644 --- a/app/translations/pebble-es.ts +++ b/app/translations/pebble-es.ts @@ -174,154 +174,164 @@ ManagerPage - + Pebble Appstore - + About Acerca de - + Pebble Manager - + Waiting for watch... If it can't be found please check it's available and paired in Bluetooth settings. Buscando el reloj Si esto tarda mucho, comprueba que el reloj esté emparejado correctamente. - + Service Servicio - + Enabled Habilitado - + Automatic startup Inicio automático - + Manual startup Inicio manual - + Active Activo - + Running Ejecutándose - + Dead Detenido - + Connection Conexión - + Connected Conectado - + Disconnected Desconectado - + Settings Configuración - + Forward phone calls Transferir llamadas - + Silent when connected Modo silencio automático - + Sets phone profile to "silent" when Pebble is connected Activa el modo silencio cuando se conecte un Pebble - + + Alter system volume + + + + + Pebble music volume buttons change the system volume when the music player cannot + + + + Transliterate messages Transliterar mensajes - + Messages are transliterated to ASCII before sending to Pebble Codifica los mensajes entrates a ASCII antes de enviarlos a Pebble - + Notifications Notificaciones - + Messaging Mensajería - + SMS and IM SMS y chat - + Missed call Llamadas perdidas - + Emails Correos electrónicos - + Mitakuuluu - + Twitter Twitter - + Facebook Facebook - + Other notifications Resto de notificaciones - + All notifications Todas las notificaciones diff --git a/app/translations/pebble-pl.ts b/app/translations/pebble-pl.ts index ebe4f1a..1999ab6 100644 --- a/app/translations/pebble-pl.ts +++ b/app/translations/pebble-pl.ts @@ -194,154 +194,164 @@ ManagerPage - + Pebble Appstore Pebble Appstore - + About Informacje - + Pebble Manager Pebble Manager - + Waiting for watch... If it can't be found please check it's available and paired in Bluetooth settings. Oczekiwanie na zegarek... Jeśli nie zostaje znaleziony sprawdź czy jest w zasięgu i czy jest sparowany w ustawieniach Bluetooth. - + Service Usługa - + Enabled Włączona - + Automatic startup Start automatyczny - + Manual startup Start ręczny - + Active Aktywna - + Running Pracuje - + Dead Martwa - + Connection Połączenie - + Connected Połączony - + Disconnected Rozłączony - + Settings Ustawienia - + Forward phone calls Przekazuj telefony - + Silent when connected Cichy gdy połączony - + Sets phone profile to "silent" when Pebble is connected Ustawia "cichy" profil telefonu gdy Pebble jest połączony - + + Alter system volume + + + + + Pebble music volume buttons change the system volume when the music player cannot + + + + Transliterate messages Transliteracja wiadomości - + Messages are transliterated to ASCII before sending to Pebble Wiadomości są transliterowane do ASCII przed wysłaniem do Pebble - + Notifications Powiadomienia - + Messaging Wiadomości - + SMS and IM SMS i IM - + Missed call Ominięte telefony - + Emails Emaile - + Mitakuuluu Mitakuuluu - + Twitter Twitter - + Facebook Facebook - + Other notifications Pozostałe powiadomienia - + All notifications Wszystkie powiadomienia diff --git a/app/translations/pebble.ts b/app/translations/pebble.ts index 24f2352..9d7ffe1 100644 --- a/app/translations/pebble.ts +++ b/app/translations/pebble.ts @@ -162,153 +162,163 @@ ManagerPage - + Pebble Appstore - + About - + Pebble Manager - + Waiting for watch... If it can't be found please check it's available and paired in Bluetooth settings. - + Service - + Enabled - + Automatic startup - + Manual startup - + Active - + Running - + Dead - + Connection - + Connected - + Disconnected - + Settings - + Forward phone calls - + Silent when connected - + Sets phone profile to "silent" when Pebble is connected - + + Alter system volume + + + + + Pebble music volume buttons change the system volume when the music player cannot + + + + Transliterate messages - + Messages are transliterated to ASCII before sending to Pebble - + Notifications - + Messaging - + SMS and IM - + Missed call - + Emails - + Mitakuuluu - + Twitter - + Facebook - + Other notifications - + All notifications diff --git a/daemon/manager.cpp b/daemon/manager.cpp index 02a4021..567316e 100644 --- a/daemon/manager.cpp +++ b/daemon/manager.cpp @@ -16,7 +16,7 @@ Manager::Manager(Settings *settings, QObject *parent) : bank(new BankManager(watch, upload, apps, this)), voice(new VoiceCallManager(settings, this)), notifications(new NotificationManager(settings, this)), - music(new MusicManager(watch, this)), + music(new MusicManager(watch, settings, this)), datalog(new DataLogManager(watch, this)), appmsg(new AppMsgManager(apps, watch, this)), js(new JSKitManager(watch, apps, appmsg, settings, this)), diff --git a/daemon/musicmanager.cpp b/daemon/musicmanager.cpp index b9b217f..f51daeb 100644 --- a/daemon/musicmanager.cpp +++ b/daemon/musicmanager.cpp @@ -1,10 +1,11 @@ #include #include #include "musicmanager.h" +#include "settings.h" -MusicManager::MusicManager(WatchConnector *watch, QObject *parent) +MusicManager::MusicManager(WatchConnector *watch, Settings *settings, QObject *parent) : QObject(parent), l(metaObject()->className()), - watch(watch), _watcher(new QDBusServiceWatcher(this)), _pulseBus(NULL), _maxVolume(0) + watch(watch), _watcher(new QDBusServiceWatcher(this)), _pulseBus(NULL), settings(settings),_maxVolume(0), mprisVolumeWorks(true) { QDBusConnection bus = QDBusConnection::sessionBus(); QDBusConnectionInterface *bus_iface = bus.interface(); @@ -54,6 +55,7 @@ MusicManager::MusicManager(WatchConnector *watch, QObject *parent) QDBusReply volumeMaxReply = _pulseBus->call(call); if (volumeMaxReply.isValid()) { _maxVolume = volumeMaxReply.value().variant().toUInt(); + qCDebug(l) << "Max volume: " << _maxVolume; } else { qCWarning(l) << "Could not read volume max, cannot adjust volume: " << volumeMaxReply.error().message(); @@ -68,13 +70,17 @@ MusicManager::MusicManager(WatchConnector *watch, QObject *parent) // If the watch disconnects, we will send the current metadata when it comes back. connect(watch, &WatchConnector::connectedChanged, this, &MusicManager::handleWatchConnected); + + qCDebug(l) << "Constructor done"; } MusicManager::~MusicManager() { - qCDebug(l) << "Disconnecting from PulseAudio P2P DBus"; - QDBusConnection::disconnectFromBus("org.PulseAudio1"); - delete(_pulseBus); + if (_pulseBus != NULL) { + qCDebug(l) << "Disconnecting from PulseAudio P2P DBus"; + QDBusConnection::disconnectFromBus("org.PulseAudio1"); + delete(_pulseBus); + } } void MusicManager::switchToService(const QString &service) @@ -89,6 +95,56 @@ void MusicManager::switchToService(const QString &service) _watcher->setWatchedServices(QStringList(_curService)); } } + + // Check if this service has working volume control + mprisVolumeWorks = false; + + if (_curService.isEmpty()) return; + + // Read current volume level from MPRIS + QDBusConnection bus = QDBusConnection::sessionBus(); + QDBusMessage call = QDBusMessage::createMethodCall(_curService, "/org/mpris/MediaPlayer2", + "org.freedesktop.DBus.Properties", "Get"); + call << "org.mpris.MediaPlayer2.Player" << "Volume"; + QDBusReply volumeReply = bus.call(call); + if (!volumeReply.isValid()) { + qCWarning(l) << volumeReply.error().message(); + return; + } + double volume = volumeReply.value().variant().toDouble(); + // Tweak it by 10% and set it + double newVolume = volume + (volume == 1.0?-0.1:0.1); + qCDebug(l) << "Volume control test: changing " << volume << " to " << newVolume; + call = QDBusMessage::createMethodCall(_curService, "/org/mpris/MediaPlayer2", + "org.freedesktop.DBus.Properties", "Set"); + call << "org.mpris.MediaPlayer2.Player" << "Volume" << QVariant::fromValue(QDBusVariant(newVolume)); + QDBusError err = QDBusConnection::sessionBus().call(call); + if (err.isValid()) { + qCWarning(l) << err.message(); + } + + // Read the new volume level to check if it's changed + call = QDBusMessage::createMethodCall(_curService, "/org/mpris/MediaPlayer2", + "org.freedesktop.DBus.Properties", "Get"); + call << "org.mpris.MediaPlayer2.Player" << "Volume"; + volumeReply = bus.call(call); + double actualNewVolume = volumeReply.value().variant().toDouble(); + qCDebug(l) << "Volume control test: new volume read as " << actualNewVolume; + if (actualNewVolume == newVolume) { // !!MPRIS vol works!! + qCDebug(l) << "Volume control test: MPRIS volume control worked. Restoring old volume level and enabling MPRIS volume control"; + mprisVolumeWorks = true; + call = QDBusMessage::createMethodCall(_curService, "/org/mpris/MediaPlayer2", + "org.freedesktop.DBus.Properties", "Set"); + call << "org.mpris.MediaPlayer2.Player" << "Volume" << QVariant::fromValue(QDBusVariant(volume)); + err = QDBusConnection::sessionBus().call(call); + if (err.isValid()) { + qCWarning(l) << err.message(); + } + return; + } + else if (actualNewVolume == volume){ + qCDebug(l) << "Volume control test: MPRIS volume control has no effect."; + } } void MusicManager::fetchMetadataFromService() @@ -146,7 +202,7 @@ void MusicManager::handleMusicControl(WatchConnector::MusicControl operation) qCDebug(l) << "operation from watch:" << operation; if (_curService.isEmpty() && - operation != WatchConnector::musicVOLUME_UP && operation != WatchConnector::musicVOLUME_DOWN) { + ((operation != WatchConnector::musicVOLUME_UP && operation != WatchConnector::musicVOLUME_DOWN) || mprisVolumeWorks)) { qCDebug(l) << "can't do any music operation, no mpris interface active"; return; } @@ -169,8 +225,37 @@ void MusicManager::handleMusicControl(WatchConnector::MusicControl operation) break; case WatchConnector::musicVOLUME_UP: - case WatchConnector::musicVOLUME_DOWN: - if (_pulseBus != NULL) { + case WatchConnector::musicVOLUME_DOWN: { + QVariant useSystemVolumeVar = settings->property("useSystemVolume"); + bool useSystemVolume = (useSystemVolumeVar.isValid() && useSystemVolumeVar.toBool()); + qCDebug(l) << "useSystemVolume: " << useSystemVolume; + if (mprisVolumeWorks || !useSystemVolume) { + QDBusConnection bus = QDBusConnection::sessionBus(); + QDBusMessage call = QDBusMessage::createMethodCall(_curService, "/org/mpris/MediaPlayer2", + "org.freedesktop.DBus.Properties", "Get"); + call << "org.mpris.MediaPlayer2.Player" << "Volume"; + QDBusReply volumeReply = bus.call(call); + if (volumeReply.isValid()) { + double volume = volumeReply.value().variant().toDouble(); + if (operation == WatchConnector::musicVOLUME_UP) { + volume += 0.1; + } + else { + volume -= 0.1; + } + qCDebug(l) << "Setting volume" << volume; + + call = QDBusMessage::createMethodCall(_curService, "/org/mpris/MediaPlayer2", "org.freedesktop.DBus.Properties", "Set"); + call << "org.mpris.MediaPlayer2.Player" << "Volume" << QVariant::fromValue(QDBusVariant(volume)); + + QDBusError err = QDBusConnection::sessionBus().call(call); + if (err.isValid()) { + qCWarning(l) << err.message(); + } + } else { + qCWarning(l) << volumeReply.error().message(); + } + } else if (_pulseBus != NULL) { // Query current volume QDBusMessage call = QDBusMessage::createMethodCall("com.Meego.MainVolume2", "/com/meego/mainvolume2", "org.freedesktop.DBus.Properties", "Get"); @@ -210,9 +295,11 @@ void MusicManager::handleMusicControl(WatchConnector::MusicControl operation) qCWarning(l) << volumeReply.error().message(); } } - break; - - + else { + qCDebug(l) << "No volume control mechanism"; + } + break; + } case WatchConnector::musicGET_NOW_PLAYING: sendCurrentMprisMetadata(); break; diff --git a/daemon/musicmanager.h b/daemon/musicmanager.h index 4ad03a8..087dd2a 100644 --- a/daemon/musicmanager.h +++ b/daemon/musicmanager.h @@ -5,6 +5,7 @@ #include #include #include "watchconnector.h" +#include "settings.h" class MusicManager : public QObject, protected QDBusContext { @@ -12,7 +13,7 @@ class MusicManager : public QObject, protected QDBusContext QLoggingCategory l; public: - explicit MusicManager(WatchConnector *watch, QObject *parent = 0); + explicit MusicManager(WatchConnector *watch, Settings *settings, QObject *parent = 0); virtual ~MusicManager(); private: @@ -33,7 +34,9 @@ private: QString _curService; QVariantMap _curMetadata; QDBusConnection *_pulseBus; + Settings *settings; uint _maxVolume; + bool mprisVolumeWorks; }; #endif // MUSICMANAGER_H diff --git a/daemon/settings.h b/daemon/settings.h index 90e25e2..688b211 100644 --- a/daemon/settings.h +++ b/daemon/settings.h @@ -9,6 +9,7 @@ class Settings : public MDConfGroup Q_PROPERTY(bool silentWhenConnected MEMBER silentWhenConnected NOTIFY silentWhenConnectedChanged) Q_PROPERTY(bool transliterateMessage MEMBER transliterateMessage NOTIFY transliterateMessageChanged) + Q_PROPERTY(bool useSystemVolume MEMBER useSystemVolume NOTIFY useSystemVolumeChanged) Q_PROPERTY(bool incomingCallNotification MEMBER incomingCallNotification NOTIFY incomingCallNotificationChanged) Q_PROPERTY(bool notificationsCommhistoryd MEMBER notificationsCommhistoryd NOTIFY notificationsCommhistorydChanged) Q_PROPERTY(bool notificationsMissedCall MEMBER notificationsMissedCall NOTIFY notificationsMissedCallChanged) @@ -22,6 +23,7 @@ class Settings : public MDConfGroup bool silentWhenConnected; bool transliterateMessage; + bool useSystemVolume; bool incomingCallNotification; bool notificationsCommhistoryd; bool notificationsMissedCall; @@ -41,6 +43,7 @@ public: signals: void silentWhenConnectedChanged(); void transliterateMessageChanged(); + void useSystemVolumeChanged(); void incomingCallNotificationChanged(); void notificationsCommhistorydChanged(); void notificationsMissedCallChanged(); -- cgit v1.2.3