From 5fef356ff3fbcb76a5ec44a81a8d54d29a42f25d Mon Sep 17 00:00:00 2001 From: Javier Date: Mon, 23 Mar 2015 03:28:00 +0100 Subject: initial import --- saltoqd/voicecallmanager.cpp | 73 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 saltoqd/voicecallmanager.cpp (limited to 'saltoqd/voicecallmanager.cpp') diff --git a/saltoqd/voicecallmanager.cpp b/saltoqd/voicecallmanager.cpp new file mode 100644 index 0000000..3ef9223 --- /dev/null +++ b/saltoqd/voicecallmanager.cpp @@ -0,0 +1,73 @@ +#include +#include "voicecallmanager.h" +#include "voicecallmanager_interface.h" + +static OrgNemomobileVoicecallVoiceCallManagerInterface *vcm = NULL; + +VoiceCallManager::VoiceCallManager(ToqManager *toq) : + QObject(toq), _toq(toq) +{ + if (!vcm) { + vcm = new OrgNemomobileVoicecallVoiceCallManagerInterface("org.nemomobile.voicecall", + "/", + QDBusConnection::sessionBus()); + } + + _toq->setEndpointListener(ToqConnection::VoiceCallEndpoint, this); +} + +void VoiceCallManager::handleMessage(const ToqConnection::Message &msg) +{ + Q_ASSERT(msg.destination == ToqConnection::VoiceCallEndpoint); + switch (msg.type) { + case 15: + handleGetPhoneStatusMessage(msg); + break; + default: + qWarning() << "Unknown message" << msg.type; + break; + } +} + +void VoiceCallManager::setSilentMode(bool silent) +{ + setProfile(silent ? "silent" : "ambience"); +} + +void VoiceCallManager::handleGetPhoneStatusMessage(const ToqConnection::Message &msg) +{ + QJsonObject obj; + obj.insert("service", int(1)); + obj.insert("call_status", int(0)); + obj.insert("call_setup_status", int(0)); + obj.insert("silence_mode", getCurrentProfile() == "silent" ? 1 : 0); + + _toq->sendReply(msg, 0x400F, obj); +} + +QString VoiceCallManager::getCurrentProfile() +{ + QDBusConnection bus = QDBusConnection::sessionBus(); + QDBusReply resp = bus.call(QDBusMessage::createMethodCall("com.nokia.profiled", + "/com/nokia/profiled", + "com.nokia.profiled", + "get_profile")); + if (resp.isValid()) { + return resp.value(); + } else { + qWarning() << resp.error().message(); + return QString(); + } +} + +void VoiceCallManager::setProfile(const QString &name) +{ + QDBusConnection bus = QDBusConnection::sessionBus(); + QDBusReply resp = bus.call(QDBusMessage::createMethodCall("com.nokia.profiled", + "/com/nokia/profiled", + "com.nokia.profiled", + "set_profile") << name); + if (!resp.isValid()) { + qWarning() << resp.error().message(); + } +} -- cgit v1.2.3