From bbbc4b88c8bfb69dd652e1ffd2f6f8afdb2fe0fc Mon Sep 17 00:00:00 2001 From: Javier Date: Sun, 28 Aug 2016 20:34:07 +0200 Subject: add voicecall feature --- libwatchfish.pri | 6 ++ libwatchfish.pro | 2 +- notification.cpp | 2 + notificationmonitor.cpp | 3 +- org.nemomobile.voicecall.VoiceCall.xml | 69 ++++++++++++ org.nemomobile.voicecall.VoiceCallManager.xml | 53 +++++++++ voicecallcontroller.cpp | 148 ++++++++++++++++++++++++++ voicecallcontroller.h | 60 +++++++++++ voicecallcontroller_p.h | 72 +++++++++++++ 9 files changed, 413 insertions(+), 2 deletions(-) create mode 100644 org.nemomobile.voicecall.VoiceCall.xml create mode 100644 org.nemomobile.voicecall.VoiceCallManager.xml create mode 100644 voicecallcontroller.cpp create mode 100644 voicecallcontroller.h create mode 100644 voicecallcontroller_p.h diff --git a/libwatchfish.pri b/libwatchfish.pri index 6ff0728..8a256c2 100644 --- a/libwatchfish.pri +++ b/libwatchfish.pri @@ -23,3 +23,9 @@ contains(WATCHFISH_FEATURES, calendar) { HEADERS += $$PWD/calendarsource.h $$PWD/calendarsource_p.h $$PWD/calendarevent.h SOURCES += $$PWD/calendarsource.cpp $$PWD/calendarevent.cpp } + +contains(WATCHFISH_FEATURES, voicecall) { + HEADERS += $$PWD/voicecallcontroller.h $$PWD/voicecallcontroller_p.h + SOURCES += $$PWD/voicecallcontroller.cpp + DBUS_INTERFACES += org.nemomobile.voicecall.VoiceCallManager.xml org.nemomobile.voicecall.VoiceCall.xml +} diff --git a/libwatchfish.pro b/libwatchfish.pro index 18313a4..246eda2 100644 --- a/libwatchfish.pro +++ b/libwatchfish.pro @@ -4,5 +4,5 @@ TEMPLATE = lib CONFIG += staticlib QT += dbus -WATCHFISH_FEATURES = notificationmonitor walltime music calendar +WATCHFISH_FEATURES = notificationmonitor walltime music calendar voicecall include(libwatchfish.pri) diff --git a/notification.cpp b/notification.cpp index d0addbd..76d9be7 100644 --- a/notification.cpp +++ b/notification.cpp @@ -57,6 +57,8 @@ Notification::Notification(uint id, QObject *parent) : QObject(parent), d_ptr(ne { Q_D(Notification); d->id = id; + d->urgency = 0; + d->transient = false; } Notification::~Notification() diff --git a/notificationmonitor.cpp b/notificationmonitor.cpp index 60e226a..85acc2d 100644 --- a/notificationmonitor.cpp +++ b/notificationmonitor.cpp @@ -101,7 +101,8 @@ void NotificationMonitorPrivate::processIncomingNotification(quint32 id, const P n = new Notification(id, q); } - n->setAppId(proto.appId); + n->setAppId(proto.appId); + n->setAppName(proto.appName); n->setSummary(proto.summary); n->setBody(proto.body); n->setIcon(proto.appIcon); diff --git a/org.nemomobile.voicecall.VoiceCall.xml b/org.nemomobile.voicecall.VoiceCall.xml new file mode 100644 index 0000000..6693af2 --- /dev/null +++ b/org.nemomobile.voicecall.VoiceCall.xml @@ -0,0 +1,69 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/org.nemomobile.voicecall.VoiceCallManager.xml b/org.nemomobile.voicecall.VoiceCallManager.xml new file mode 100644 index 0000000..cfdbae5 --- /dev/null +++ b/org.nemomobile.voicecall.VoiceCallManager.xml @@ -0,0 +1,53 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/voicecallcontroller.cpp b/voicecallcontroller.cpp new file mode 100644 index 0000000..5e3487e --- /dev/null +++ b/voicecallcontroller.cpp @@ -0,0 +1,148 @@ +/* + * libwatchfish - library with common functionality for SailfishOS smartwatch connector programs. + * Copyright (C) 2016 Javier S. Pedro + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "voicecallcontroller.h" +#include "voicecallcontroller_p.h" + +namespace watchfish +{ + +Q_LOGGING_CATEGORY(voiceCallControllerCat, "watchfish-VoiceCallController") + +VoiceCallControllerPrivate::VoiceCallControllerPrivate(VoiceCallController *q) + : vcm(new OrgNemomobileVoicecallVoiceCallManagerInterface("org.nemomobile.voicecall", + "/", QDBusConnection::sessionBus(), this)), + activeCall(0), + curInCall(false), curRinging(false), + q_ptr(q) +{ + connect(vcm, &OrgNemomobileVoicecallVoiceCallManagerInterface::activeVoiceCallChanged, + this, &VoiceCallControllerPrivate::handleActiveVoiceCallChanged); + handleActiveVoiceCallChanged(); +} + +VoiceCallControllerPrivate::~VoiceCallControllerPrivate() +{ + delete activeCall; +} + +void VoiceCallControllerPrivate::handleActiveVoiceCallChanged() +{ + delete activeCall; + QString id = vcm->activeVoiceCall(); + qCDebug(voiceCallControllerCat) << "Active voice call changed" << id; + if (!id.isEmpty()) { + activeCall = new OrgNemomobileVoicecallVoiceCallInterface("org.nemomobile.voicecall", + QString("/calls/%1").arg(id), vcm->connection(), this); + connect(activeCall, &OrgNemomobileVoicecallVoiceCallInterface::statusChanged, + this, &VoiceCallControllerPrivate::handleActiveVoiceCallStatusChanged); + connect(activeCall, &OrgNemomobileVoicecallVoiceCallInterface::lineIdChanged, + this, &VoiceCallControllerPrivate::handleActiveVoiceCallLineIdChanged); + VoiceCallStatus status = static_cast(activeCall->status()); + setCallerId(activeCall->lineId()); + setCallStatus(status); + qDebug() << "Status of new call:" << status << curCallerId; + } else { + activeCall = 0; + setCallStatus(STATUS_NULL); + setCallerId(QString()); + } +} + +void VoiceCallControllerPrivate::handleActiveVoiceCallStatusChanged(int status, const QString &statusText) +{ + qCDebug(voiceCallControllerCat) << "Status changed:" << status << statusText; + setCallStatus(static_cast(status)); +} + +void VoiceCallControllerPrivate::handleActiveVoiceCallLineIdChanged(const QString &lineId) +{ + qCDebug(voiceCallControllerCat) << "LineID changed:" << lineId; + setCallerId(lineId); +} + +void VoiceCallControllerPrivate::setCallStatus(VoiceCallStatus status) +{ + Q_Q(VoiceCallController); + const bool oldInCall = curInCall, oldRinging = curRinging; + switch (status) { + case STATUS_INCOMING: + curInCall = true; + curRinging = true; + break; + case STATUS_ACTIVE: + case STATUS_HELD: + case STATUS_DIALING: + case STATUS_ALERTING: + case STATUS_WAITING: + curInCall = true; + curRinging = false; + break; + case STATUS_DISCONNECTED: + case STATUS_NULL: + default: + curInCall = false; + curRinging = false; + break; + } + if (oldInCall != curInCall) { + emit q->inCallChanged(); + } + if (oldRinging != curRinging) { + emit q->ringingChanged(); + } +} + +void VoiceCallControllerPrivate::setCallerId(const QString &callerId) +{ + Q_Q(VoiceCallController); + if (callerId != curCallerId) { + curCallerId = callerId; + emit q->callerIdChanged(); + } +} + +VoiceCallController::VoiceCallController(QObject *parent) + : QObject(parent), d_ptr(new VoiceCallControllerPrivate(this)) +{ +} + +VoiceCallController::~VoiceCallController() +{ + delete d_ptr; +} + +bool VoiceCallController::inCall() const +{ + Q_D(const VoiceCallController); + return d->curInCall; +} + +bool VoiceCallController::ringing() const +{ + Q_D(const VoiceCallController); + return d->curRinging; +} + +QString VoiceCallController::callerId() const +{ + Q_D(const VoiceCallController); + return d->curCallerId; +} + +} diff --git a/voicecallcontroller.h b/voicecallcontroller.h new file mode 100644 index 0000000..c374a41 --- /dev/null +++ b/voicecallcontroller.h @@ -0,0 +1,60 @@ +/* + * libwatchfish - library with common functionality for SailfishOS smartwatch connector programs. + * Copyright (C) 2016 Javier S. Pedro + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef WATCHFISH_VOICECALLCONTROLLER_H +#define WATCHFISH_VOICECALLCONTROLLER_H + +#include + +namespace watchfish +{ + +Q_DECLARE_LOGGING_CATEGORY(voiceCallControllerCat) + +class VoiceCallControllerPrivate; + +class VoiceCallController : public QObject +{ + Q_OBJECT + Q_DECLARE_PRIVATE(VoiceCallController) + + Q_PROPERTY(bool inCall READ inCall NOTIFY inCallChanged) + Q_PROPERTY(bool ringing READ ringing NOTIFY ringingChanged) + Q_PROPERTY(QString callerId READ callerId NOTIFY callerIdChanged) + +public: + explicit VoiceCallController(QObject *parent = 0); + ~VoiceCallController(); + + bool inCall() const; + bool ringing() const; + + QString callerId() const; + +signals: + void inCallChanged(); + void ringingChanged(); + void callerIdChanged(); + +private: + VoiceCallControllerPrivate * const d_ptr; +}; + +} + +#endif // WATCHFISH_VOICECALLCONTROLLER_H diff --git a/voicecallcontroller_p.h b/voicecallcontroller_p.h new file mode 100644 index 0000000..624e615 --- /dev/null +++ b/voicecallcontroller_p.h @@ -0,0 +1,72 @@ +/* + * libwatchfish - library with common functionality for SailfishOS smartwatch connector programs. + * Copyright (C) 2016 Javier S. Pedro + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef WATCHFISH_VOICECALLCONTROLLER_P_H +#define WATCHFISH_VOICECALLCONTROLLER_P_H + +#include "voicecallcontroller.h" +#include "voicecall_interface.h" +#include "voicecallmanager_interface.h" + +namespace watchfish +{ + +enum VoiceCallStatus { + STATUS_NULL, + STATUS_ACTIVE, + STATUS_HELD, + STATUS_DIALING, + STATUS_ALERTING, + STATUS_INCOMING, + STATUS_WAITING, + STATUS_DISCONNECTED +}; + +class VoiceCallControllerPrivate : public QObject +{ + Q_OBJECT + +public: + explicit VoiceCallControllerPrivate(VoiceCallController *q); + ~VoiceCallControllerPrivate(); + +public slots: + void handleActiveVoiceCallChanged(); + void handleActiveVoiceCallStatusChanged(int status, const QString &statusName); + void handleActiveVoiceCallLineIdChanged(const QString &lineId); + +public: + OrgNemomobileVoicecallVoiceCallManagerInterface *vcm; + OrgNemomobileVoicecallVoiceCallInterface *activeCall; + + bool curInCall; + bool curRinging; + QString curCallerId; + + void setCallStatus(VoiceCallStatus status); + void setCallerId(const QString &callerId); + +private: + VoiceCallController * const q_ptr; + Q_DECLARE_PUBLIC(VoiceCallController) +}; + +} + +#endif // WATCHFISH_VOICECALLCONTROLLER_P_H + -- cgit v1.2.3