From cfd11bb46b0e93903135c127b955e657d7f2b33d Mon Sep 17 00:00:00 2001 From: Tomasz Sterna Date: Fri, 18 Jul 2014 23:47:12 +0200 Subject: Implemented settings skeleton and notifications --- daemon/manager.cpp | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) (limited to 'daemon/manager.cpp') diff --git a/daemon/manager.cpp b/daemon/manager.cpp index a2365b4..3214cdc 100644 --- a/daemon/manager.cpp +++ b/daemon/manager.cpp @@ -5,10 +5,14 @@ #include #include -Manager::Manager(watch::WatchConnector *watch, DBusConnector *dbus, VoiceCallManager *voice) : +Manager::Manager(watch::WatchConnector *watch, DBusConnector *dbus, VoiceCallManager *voice, Settings *settings) : QObject(0), watch(watch), dbus(dbus), voice(voice), commands(new WatchCommands(watch, this)), - notification(MNotification::DeviceEvent) + settings(settings), notification(MNotification::DeviceEvent) { + connect(settings, SIGNAL(valueChanged(QString)), SLOT(onSettingChanged(const QString&))); + connect(settings, SIGNAL(valuesChanged()), 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 parameters; parameters.insert(QString::fromLatin1("mergePresenceChanges"), QString::fromLatin1("false")); @@ -54,6 +58,16 @@ Manager::Manager(watch::WatchConnector *watch, DBusConnector *dbus, VoiceCallMan connect(this, SIGNAL(mprisMetadataChanged(QVariantMap)), commands, SLOT(onMprisMetadataChanged(QVariantMap))); } +void Manager::onSettingChanged(const QString &key) +{ + logger()->debug() << __FUNCTION__ << key << ":" << settings->property(qPrintable(key)); +} + +void Manager::onSettingsChanged() +{ + logger()->warn() << __FUNCTION__ << "Not implemented!"; +} + void Manager::onPebbleChanged() { const QVariantMap & pebble = dbus->pebble(); -- cgit v1.2.3 From 2441492fa9e64f1782395f64015194b486c67808 Mon Sep 17 00:00:00 2001 From: Tomasz Sterna Date: Mon, 21 Jul 2014 00:11:39 +0200 Subject: Implemented SilentWhenConnected --- daemon/manager.cpp | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ daemon/manager.h | 4 ++++ 2 files changed, 56 insertions(+) (limited to 'daemon/manager.cpp') diff --git a/daemon/manager.cpp b/daemon/manager.cpp index 3214cdc..e97da41 100644 --- a/daemon/manager.cpp +++ b/daemon/manager.cpp @@ -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", @@ -61,6 +65,7 @@ Manager::Manager(watch::WatchConnector *watch, DBusConnector *dbus, VoiceCallMan void Manager::onSettingChanged(const QString &key) { logger()->debug() << __FUNCTION__ << key << ":" << settings->property(qPrintable(key)); + if (key == "silentWhenConnected") applyProfile(); } void Manager::onSettingsChanged() @@ -269,3 +274,50 @@ void Manager::setMprisMetadata(QVariantMap metadata) mprisMetadata = metadata; emit mprisMetadataChanged(mprisMetadata); } + +QString Manager::getCurrentProfile() +{ + QDBusReply 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 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(); + } + } +} diff --git a/daemon/manager.h b/daemon/manager.h index 64dbcce..89b8e2b 100644 --- a/daemon/manager.h +++ b/daemon/manager.h @@ -47,6 +47,8 @@ class Manager : QContactDetailFilter numberFilter; GroupManager *conversations; + QString defaultProfile; + QString lastSeenMpris; public: @@ -54,6 +56,7 @@ public: Q_INVOKABLE QString findPersonByNumber(QString number); Q_INVOKABLE void processUnreadMessages(GroupObject *group); + Q_INVOKABLE QString getCurrentProfile(); Q_INVOKABLE QString mpris(); QVariantMap mprisMetadata; QVariantMap getMprisMetadata() { return mprisMetadata; } @@ -63,6 +66,7 @@ signals: public slots: void hangupAll(); + void applyProfile(); protected slots: void onSettingChanged(const QString &key); -- cgit v1.2.3