diff options
Diffstat (limited to 'daemon/manager.cpp')
| -rw-r--r-- | daemon/manager.cpp | 53 |
1 files changed, 52 insertions, 1 deletions
diff --git a/daemon/manager.cpp b/daemon/manager.cpp index efa5a28..41617e4 100644 --- a/daemon/manager.cpp +++ b/daemon/manager.cpp @@ -11,7 +11,7 @@ Manager::Manager(watch::WatchConnector *watch, DBusConnector *dbus, VoiceCallMan { connect(settings, SIGNAL(valueChanged(QString)), SLOT(onSettingChanged(const QString&))); connect(settings, SIGNAL(valuesChanged()), SLOT(onSettingsChanged())); - connect(settings, SIGNAL(silentWhenConnectedChanged()), SLOT(onSettingsChanged())); + //connect(settings, SIGNAL(silentWhenConnectedChanged(bool)), SLOT(onSilentWhenConnectedChanged(bool))); // We don't need to handle presence changes, so report them separately and ignore them QMap<QString, QString> parameters; @@ -50,6 +50,10 @@ Manager::Manager(watch::WatchConnector *watch, DBusConnector *dbus, VoiceCallMan connect(dbus, SIGNAL(pebbleChanged()), adaptor, SIGNAL(pebbleChanged())); connect(watch, SIGNAL(connectedChanged()), adaptor, SIGNAL(connectedChanged())); + QString currentProfile = getCurrentProfile(); + defaultProfile = currentProfile.isEmpty() ? "ambience" : currentProfile; + connect(watch, SIGNAL(connectedChanged()), SLOT(applyProfile())); + // Music Control interface session.connect("", "/org/mpris/MediaPlayer2", "org.freedesktop.DBus.Properties", "PropertiesChanged", @@ -257,3 +261,50 @@ void Manager::setMprisMetadata(QVariantMap metadata) mprisMetadata = metadata; emit mprisMetadataChanged(mprisMetadata); } + +QString Manager::getCurrentProfile() +{ + QDBusReply<QString> profile = QDBusConnection::sessionBus().call( + QDBusMessage::createMethodCall("com.nokia.profiled", "/com/nokia/profiled", "com.nokia.profiled", "get_profile")); + if (profile.isValid()) { + QString currentProfile = profile.value(); + logger()->debug() << "Got profile" << currentProfile; + return currentProfile; + } + + logger()->error() << profile.error().message(); + return QString(); +} + +void Manager::applyProfile() +{ + QString currentProfile = getCurrentProfile(); + QString newProfile; + + if (settings->property("silentWhenConnected").toBool()) { + if (watch->isConnected() && currentProfile != "silent") { + newProfile = "silent"; + defaultProfile = currentProfile; + } + if (!watch->isConnected() && currentProfile == "silent" && defaultProfile != "silent") { + newProfile = defaultProfile; + } + } + else if (currentProfile != defaultProfile) { + newProfile = defaultProfile; + } + + if (!newProfile.isEmpty()) { + QDBusReply<bool> res = QDBusConnection::sessionBus().call( + QDBusMessage::createMethodCall("com.nokia.profiled", "/com/nokia/profiled", "com.nokia.profiled", "set_profile") + << newProfile); + if (res.isValid()) { + if (!res.value()) { + logger()->error() << "Unable to set profile" << newProfile; + } + } + else { + logger()->error() << res.error().message(); + } + } +} |
