summaryrefslogtreecommitdiff
path: root/daemon
diff options
context:
space:
mode:
authorAndrew Branson <andrew.branson@cern.ch>2015-04-17 16:56:00 +0200
committerAndrew Branson <andrew.branson@cern.ch>2015-04-17 19:11:42 +0200
commit8da20a7c3088aee2b04d45feeee8ca0753dc260e (patch)
tree70dc3a2d091ca82f77a9a20e3ce7f1cddd825526 /daemon
parentd9f2e79eff8744bd5bd422133117693d42ee52da (diff)
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.
Diffstat (limited to 'daemon')
-rw-r--r--daemon/manager.cpp2
-rw-r--r--daemon/musicmanager.cpp109
-rw-r--r--daemon/musicmanager.h5
-rw-r--r--daemon/settings.h3
4 files changed, 106 insertions, 13 deletions
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 <QDBusConnection>
#include <QDBusConnectionInterface>
#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<QDBusVariant> 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<QDBusVariant> 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<QDBusVariant> 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 <QDBusContext>
#include <QDBusServiceWatcher>
#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();