summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Branson <andrew.branson@cern.ch>2015-04-19 17:46:58 +0200
committerAndrew Branson <andrew.branson@cern.ch>2015-04-19 17:46:58 +0200
commit84b7cb05ece51d88eef5b637f1e897e77f496de1 (patch)
treedd48e39b01ff098c9e1059acceb0b36127f15b37
parent5d19559e50830d4237111e0876c810d3c3ab6361 (diff)
Remove MPRIS volume check
-rw-r--r--app/qml/pages/ManagerPage.qml4
-rw-r--r--app/translations/pebble-es.ts4
-rw-r--r--app/translations/pebble-pl.ts4
-rw-r--r--app/translations/pebble.ts4
-rw-r--r--daemon/musicmanager.cpp195
-rw-r--r--daemon/musicmanager.h1
6 files changed, 78 insertions, 134 deletions
diff --git a/app/qml/pages/ManagerPage.qml b/app/qml/pages/ManagerPage.qml
index 0c393a3..7fb7369 100644
--- a/app/qml/pages/ManagerPage.qml
+++ b/app/qml/pages/ManagerPage.qml
@@ -134,8 +134,8 @@ Page {
}
}
TextSwitch {
- text: qsTr("Alter system volume")
- description: qsTr("Pebble music volume buttons change the system volume when the music player cannot")
+ text: qsTr("Control main volume")
+ description: qsTr("Pebble music volume buttons change the main phone volume directly instead of through the music player.")
checked: settings.useSystemVolume
automaticCheck: true
onClicked: {
diff --git a/app/translations/pebble-es.ts b/app/translations/pebble-es.ts
index 7ee4e71..38a8cc4 100644
--- a/app/translations/pebble-es.ts
+++ b/app/translations/pebble-es.ts
@@ -267,12 +267,12 @@ Si esto tarda mucho, comprueba que el reloj esté emparejado correctamente.</tra
</message>
<message>
<location filename="../qml/pages/ManagerPage.qml" line="137"/>
- <source>Alter system volume</source>
+ <source>Control main volume</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/pages/ManagerPage.qml" line="138"/>
- <source>Pebble music volume buttons change the system volume when the music player cannot</source>
+ <source>Pebble music volume buttons change the main phone volume directly instead of through the music player.</source>
<translation type="unfinished"></translation>
</message>
<message>
diff --git a/app/translations/pebble-pl.ts b/app/translations/pebble-pl.ts
index 1999ab6..11285ee 100644
--- a/app/translations/pebble-pl.ts
+++ b/app/translations/pebble-pl.ts
@@ -287,12 +287,12 @@ Jeśli nie zostaje znaleziony sprawdź czy jest w zasięgu i czy jest sparowany
</message>
<message>
<location filename="../qml/pages/ManagerPage.qml" line="137"/>
- <source>Alter system volume</source>
+ <source>Control main volume</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/pages/ManagerPage.qml" line="138"/>
- <source>Pebble music volume buttons change the system volume when the music player cannot</source>
+ <source>Pebble music volume buttons change the main phone volume directly instead of through the music player.</source>
<translation type="unfinished"></translation>
</message>
<message>
diff --git a/app/translations/pebble.ts b/app/translations/pebble.ts
index 9d7ffe1..cd7ba8b 100644
--- a/app/translations/pebble.ts
+++ b/app/translations/pebble.ts
@@ -254,12 +254,12 @@ If it can&apos;t be found please check it&apos;s available and paired in Bluetoo
</message>
<message>
<location filename="../qml/pages/ManagerPage.qml" line="137"/>
- <source>Alter system volume</source>
+ <source>Control main volume</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/pages/ManagerPage.qml" line="138"/>
- <source>Pebble music volume buttons change the system volume when the music player cannot</source>
+ <source>Pebble music volume buttons change the main phone volume directly instead of through the music player.</source>
<translation type="unfinished"></translation>
</message>
<message>
diff --git a/daemon/musicmanager.cpp b/daemon/musicmanager.cpp
index e3bb30c..11ff6fd 100644
--- a/daemon/musicmanager.cpp
+++ b/daemon/musicmanager.cpp
@@ -5,7 +5,7 @@
MusicManager::MusicManager(WatchConnector *watch, Settings *settings, QObject *parent)
: QObject(parent), l(metaObject()->className()),
- watch(watch), _watcher(new QDBusServiceWatcher(this)), _pulseBus(NULL), settings(settings),_maxVolume(0), mprisVolumeWorks(false)
+ watch(watch), _watcher(new QDBusServiceWatcher(this)), _pulseBus(NULL), settings(settings),_maxVolume(0)
{
QDBusConnection bus = QDBusConnection::sessionBus();
QDBusConnectionInterface *bus_iface = bus.interface();
@@ -93,56 +93,6 @@ 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()
@@ -200,37 +150,73 @@ void MusicManager::handleMusicControl(WatchConnector::MusicControl operation)
qCDebug(l) << "operation from watch:" << operation;
QVariant useSystemVolumeVar = settings->property("useSystemVolume");
bool useSystemVolume = (useSystemVolumeVar.isValid() && useSystemVolumeVar.toBool());
- qCDebug(l) << "useSystemVolume: " << useSystemVolume;
- qCDebug(l) << "mprisVolumeWorks: " << mprisVolumeWorks;
+
+ // System volume controls
+ if (useSystemVolume && _pulseBus != NULL &&
+ (operation == WatchConnector::musicVOLUME_UP || operation == WatchConnector::musicVOLUME_DOWN)) {
+ // Query current volume
+ QDBusMessage call = QDBusMessage::createMethodCall("com.Meego.MainVolume2", "/com/meego/mainvolume2",
+ "org.freedesktop.DBus.Properties", "Get");
+ call << "com.Meego.MainVolume2" << "CurrentStep";
+
+ QDBusReply<QDBusVariant> volumeReply = _pulseBus->call(call);
+ if (volumeReply.isValid()) {
+ // Decide the new value for volume, taking limits into account
+ uint volume = volumeReply.value().variant().toUInt();
+ uint newVolume;
+ qCDebug(l) << "Current volume: " << volumeReply.value().variant().toUInt();
+ if (operation == WatchConnector::musicVOLUME_UP && volume < _maxVolume-1 ) {
+ newVolume = volume + 1;
+ }
+ else if (operation == WatchConnector::musicVOLUME_DOWN && volume > 0) {
+ newVolume = volume - 1;
+ }
+ else {
+ qCDebug(l) << "Volume already at limit";
+ newVolume = volume;
+ }
+
+ // If we have a new volume level, change it
+ if (newVolume != volume) {
+ qCDebug(l) << "Setting volume: " << newVolume;
+
+ call = QDBusMessage::createMethodCall("com.Meego.MainVolume2", "/com/meego/mainvolume2",
+ "org.freedesktop.DBus.Properties", "Set");
+ call << "com.Meego.MainVolume2" << "CurrentStep" << QVariant::fromValue(QDBusVariant(newVolume));
+
+ QDBusError err = _pulseBus->call(call);
+ if (err.isValid()) {
+ qCWarning(l) << err.message();
+ }
+ }
+ }
+ }
//Don't allow any music operations if there's no MPRIS player, unless we are allowed to control the system volume and it's a volume command
- if (_curService.isEmpty() &&
- !((operation == WatchConnector::musicVOLUME_UP || operation == WatchConnector::musicVOLUME_DOWN) && useSystemVolume)) {
+ else if (_curService.isEmpty()) {
qCDebug(l) << "can't do any music operation, no mpris interface active";
return;
}
+ else {
+ switch (operation) {
+ case WatchConnector::musicPLAY_PAUSE:
+ callMprisMethod("PlayPause");
+ break;
+ case WatchConnector::musicPAUSE:
+ callMprisMethod("Pause");
+ break;
+ case WatchConnector::musicPLAY:
+ callMprisMethod("Play");
+ break;
+ case WatchConnector::musicNEXT:
+ callMprisMethod("Next");
+ break;
+ case WatchConnector::musicPREVIOUS:
+ callMprisMethod("Previous");
+ break;
- switch (operation) {
- case WatchConnector::musicPLAY_PAUSE:
- callMprisMethod("PlayPause");
- break;
- case WatchConnector::musicPAUSE:
- callMprisMethod("Pause");
- break;
- case WatchConnector::musicPLAY:
- callMprisMethod("Play");
- break;
- case WatchConnector::musicNEXT:
- callMprisMethod("Next");
- break;
- case WatchConnector::musicPREVIOUS:
- callMprisMethod("Previous");
- break;
-
- case WatchConnector::musicVOLUME_UP:
- case WatchConnector::musicVOLUME_DOWN: {
-
- if (mprisVolumeWorks || !useSystemVolume) {
+ case WatchConnector::musicVOLUME_UP:
+ case WatchConnector::musicVOLUME_DOWN: {
QDBusConnection bus = QDBusConnection::sessionBus();
QDBusMessage call = QDBusMessage::createMethodCall(_curService, "/org/mpris/MediaPlayer2",
"org.freedesktop.DBus.Properties", "Get");
@@ -256,58 +242,17 @@ void MusicManager::handleMusicControl(WatchConnector::MusicControl operation)
} 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");
- call << "com.Meego.MainVolume2" << "CurrentStep";
-
- QDBusReply<QDBusVariant> volumeReply = _pulseBus->call(call);
- if (volumeReply.isValid()) {
- // Decide the new value for volume, taking limits into account
- uint volume = volumeReply.value().variant().toUInt();
- uint newVolume;
- qCDebug(l) << "Current volume: " << volumeReply.value().variant().toUInt();
- if (operation == WatchConnector::musicVOLUME_UP && volume < _maxVolume-1 ) {
- newVolume = volume + 1;
- }
- else if (operation == WatchConnector::musicVOLUME_DOWN && volume > 0) {
- newVolume = volume - 1;
- }
- else {
- qCDebug(l) << "Volume already at limit";
- newVolume = volume;
- }
-
- // If we have a new volume level, change it
- if (newVolume != volume) {
- qCDebug(l) << "Setting volume: " << newVolume;
+ break;
+ }
- call = QDBusMessage::createMethodCall("com.Meego.MainVolume2", "/com/meego/mainvolume2",
- "org.freedesktop.DBus.Properties", "Set");
- call << "com.Meego.MainVolume2" << "CurrentStep" << QVariant::fromValue(QDBusVariant(newVolume));
+ case WatchConnector::musicGET_NOW_PLAYING:
+ sendCurrentMprisMetadata();
+ break;
- QDBusError err = _pulseBus->call(call);
- if (err.isValid()) {
- qCWarning(l) << err.message();
- }
- }
- } else {
- qCWarning(l) << volumeReply.error().message();
- }
- }
- else {
- qCDebug(l) << "No volume control mechanism";
+ default:
+ qCWarning(l) << "Operation" << operation << "not supported";
+ break;
}
- break;
- }
- case WatchConnector::musicGET_NOW_PLAYING:
- sendCurrentMprisMetadata();
- break;
-
- default:
- qCWarning(l) << "Operation" << operation << "not supported";
- break;
}
}
diff --git a/daemon/musicmanager.h b/daemon/musicmanager.h
index 087dd2a..81947e9 100644
--- a/daemon/musicmanager.h
+++ b/daemon/musicmanager.h
@@ -36,7 +36,6 @@ private:
QDBusConnection *_pulseBus;
Settings *settings;
uint _maxVolume;
- bool mprisVolumeWorks;
};
#endif // MUSICMANAGER_H