Skip to content

Commit

Permalink
Merge pull request #89 from matthewvogt/mer-1056
Browse files Browse the repository at this point in the history
[commhistory-daemon] Reflect ofono voicemail waiting in notification. Contributes to MER#1056
  • Loading branch information
matthewvogt committed Jun 4, 2015
2 parents cfb76d9 + 9e09c19 commit 6b9cc70
Show file tree
Hide file tree
Showing 6 changed files with 96 additions and 11 deletions.
7 changes: 7 additions & 0 deletions data/notifications/x-nemo.messaging.voicemail-waiting.conf
@@ -0,0 +1,7 @@
appIcon=icon-lock-voicemail
x-nemo-icon=icon-lock-voicemail
x-nemo-preview-icon=icon-lock-voicemail
x-nemo-user-removable=false
x-nemo-feedback=sms
x-nemo-priority=120
x-nemo-led-disabled-without-body-and-summary=false
8 changes: 8 additions & 0 deletions src/constants.h
Expand Up @@ -55,6 +55,11 @@ namespace RTComLogger {
#define VOICEMAIL_METHOD QLatin1String("voicemail")
#define REPLACE_TYPE QLatin1String("sms-replace-number")

#define VOICEMAIL_WAITING_SERVICE QLatin1String("com.jolla.voicecall.ui")
#define VOICEMAIL_WAITING_OBJECT_PATH QLatin1String("/")
#define VOICEMAIL_WAITING_INTERFACE QLatin1String("com.jolla.voicecall.ui")
#define VOICEMAIL_WAITING_METHOD QLatin1String("openUrl")

// Custom hints for identifying notifications
#define ACCOUNT_PATH_HINT QLatin1String("x-org-nemomobile-qmlmessages.account.path")
#define CONTACT_ID_HINT QLatin1String("x-org-nemomobile-qmlmessages.contact.id")
Expand Down Expand Up @@ -112,6 +117,9 @@ static const int _eventTypesCount = sizeof(_eventTypes) / sizeof(EventTypes);
// Custom system info notification types for commhistoryd:
const QString ErrorCategory = "x-nemo.messaging.error";
const QString StrongErrorCategory = "x-nemo.messaging.error.strong";

const QString voicemailWaitingCategory = "x-nemo.messaging.voicemail-waiting";

}

#endif //#define CONSTANTS_H
3 changes: 3 additions & 0 deletions src/locstrings.h
Expand Up @@ -76,6 +76,9 @@
//% "Voicemail"
#define txt_qtn_call_type_voicemail qtTrId("qtn_call_type_voicemail")

//% "Tap to listen"
#define txt_qtn_voicemail_prompt qtTrId("qtn_voicemail_prompt")

//% "Multimedia message was delivered to %1"
#define txt_qtn_msg_notification_delivered(STR) qtTrId("qtn_mms_info_delivered").arg(STR)
//% "Multimedia message was read by %1"
Expand Down
82 changes: 72 additions & 10 deletions src/notificationmanager.cpp
Expand Up @@ -63,6 +63,7 @@ NotificationManager::NotificationManager(QObject* parent)
, m_GroupModel(0)
, m_ngfClient(0)
, m_ngfEvent(0)
, m_messageWaiting(0)
{
}

Expand Down Expand Up @@ -90,6 +91,9 @@ void NotificationManager::init()
connect(m_ngfClient, SIGNAL(eventFailed(quint32)), SLOT(slotNgfEventFinished(quint32)));
connect(m_ngfClient, SIGNAL(eventCompleted(quint32)), SLOT(slotNgfEventFinished(quint32)));

m_messageWaiting = new QOfonoMessageWaiting(this);
connect(m_messageWaiting, SIGNAL(voicemailWaitingChanged(bool)), SLOT(slotVoicemailWaitingChanged(bool)));

// Loads old state
syncNotifications();

Expand Down Expand Up @@ -535,17 +539,10 @@ QString NotificationManager::notificationText(const CommHistory::Event& event, c
return text;
}

static QVariantMap dbusAction(const QString &name, const QString &service, const QString &path, const QString &iface,
const QString &method, const QVariantList &arguments = QVariantList())
static QVariant dbusAction(const QString &name, const QString &service, const QString &path, const QString &iface,
const QString &method, const QVariantList &arguments = QVariantList())
{
QVariantMap action;
action.insert(QStringLiteral("name"), name);
action.insert(QStringLiteral("service"), service);
action.insert(QStringLiteral("path"), path);
action.insert(QStringLiteral("iface"), iface);
action.insert(QStringLiteral("method"), method);
action.insert(QStringLiteral("arguments"), arguments);
return action;
return Notification::remoteAction(name, QString(), service, path, iface, method, arguments);
}

void NotificationManager::setNotificationProperties(Notification *notification, PersonalNotification *pn, bool grouped)
Expand Down Expand Up @@ -771,3 +768,68 @@ void NotificationManager::slotNgfEventFinished(quint32 id)
m_ngfEvent = 0;
}

void NotificationManager::slotVoicemailWaitingChanged(bool waiting)
{
uint currentId = 0;

// See if there is a current notification for voicemail waiting
QList<QObject*> notifications = Notification::notifications();
foreach (QObject *o, notifications) {
Notification *n = static_cast<Notification*>(o);
if (n->category() == voicemailWaitingCategory) {
if (waiting) {
// The notification is already present; do nothing
currentId = n->replacesId();
} else {
// Close this notification
n->close();
}
}
}
qDeleteAll(notifications);
notifications.clear();

if (waiting && (currentId == 0)) {
const int messageCount(m_messageWaiting->voicemailMessageCount());
const QString voicemailNumber(m_messageWaiting->voicemailMailboxNumber());

// Publish a new voicemail-waiting notification
Notification voicemailNotification;

voicemailNotification.setAppName(NotificationGroup::groupName(PersonalNotification::Voicemail));
voicemailNotification.setCategory(voicemailWaitingCategory);

voicemailNotification.setPreviewSummary(txt_qtn_call_voicemail_notification(messageCount));
voicemailNotification.setPreviewBody(txt_qtn_voicemail_prompt);

voicemailNotification.setSummary(voicemailNotification.previewSummary());
voicemailNotification.setBody(voicemailNotification.previewBody());

voicemailNotification.setItemCount(messageCount);

QString service;
QString path;
QString iface;
QString method;
QVariantList args;
if (!voicemailNumber.isEmpty()) {
service = VOICEMAIL_WAITING_SERVICE;
path = VOICEMAIL_WAITING_OBJECT_PATH;
iface = VOICEMAIL_WAITING_INTERFACE;
method = VOICEMAIL_WAITING_METHOD;
args.append(QVariant(QVariantList() << QString(QStringLiteral("tel://")) + voicemailNumber));
} else {
service = CALL_HISTORY_SERVICE_NAME;
path = CALL_HISTORY_OBJECT_PATH;
iface = CALL_HISTORY_INTERFACE;
method = CALL_HISTORY_METHOD;
args.append(CALL_HISTORY_PARAMETER);
}

voicemailNotification.setRemoteActions(QVariantList() << dbusAction("default", service, path, iface, method, args)
<< dbusAction("app", service, path, iface, method, args));

voicemailNotification.publish();
}
}

5 changes: 5 additions & 0 deletions src/notificationmanager.h
Expand Up @@ -34,6 +34,8 @@
#include <QMultiHash>
#include <QModelIndex>

#include <qofonomessagewaiting.h>

#include <CommHistory/Event>
#include <CommHistory/Group>
#include <CommHistory/GroupModel>
Expand Down Expand Up @@ -145,6 +147,7 @@ private Q_SLOTS:
void slotContactRemoved(quint32 localId);
void slotContactUnknown(const QPair<QString,QString> &address);
void slotClassZeroError(const QDBusError &error);
void slotVoicemailWaitingChanged(bool waiting);

private:
NotificationManager( QObject* parent = 0);
Expand Down Expand Up @@ -184,6 +187,8 @@ private Q_SLOTS:
Ngf::Client *m_ngfClient;
quint32 m_ngfEvent;

QOfonoMessageWaiting *m_messageWaiting;

#ifdef UNIT_TEST
friend class Ut_NotificationManager;
#endif
Expand Down
2 changes: 1 addition & 1 deletion tests/tests.pri
Expand Up @@ -30,7 +30,7 @@ TEMPLATE = app
INCLUDEPATH += . .. \
../../src

PKGCONFIG += mlite5 commhistory-qt5 nemonotifications-qt5
PKGCONFIG += mlite5 commhistory-qt5 nemonotifications-qt5 qofono-qt5

COMMHISTORYDSRCDIR = ../../src
DEPENDPATH += $${INCLUDEPATH}
Expand Down

0 comments on commit 6b9cc70

Please sign in to comment.