diff --git a/data/notifications/x-nemo.call.missed.conf b/data/notifications/x-nemo.call.missed.conf index 8c74b92..1b9268d 100644 --- a/data/notifications/x-nemo.call.missed.conf +++ b/data/notifications/x-nemo.call.missed.conf @@ -1,7 +1,4 @@ -appIcon=icon-lock-missed-call -urgency=2 -x-nemo-icon=icon-lock-missed-call +app_icon=icon-lock-missed-call +x-nemo-display-on=true x-nemo-priority=120 -x-nemo-max-content-lines=1 x-nemo-feedback=call_exists -x-nemo-led-disabled-without-body-and-summary=false diff --git a/data/notifications/x-nemo.call.missed.group.conf b/data/notifications/x-nemo.call.missed.group.conf index 8c74b92..1b9268d 100644 --- a/data/notifications/x-nemo.call.missed.group.conf +++ b/data/notifications/x-nemo.call.missed.group.conf @@ -1,7 +1,4 @@ -appIcon=icon-lock-missed-call -urgency=2 -x-nemo-icon=icon-lock-missed-call +app_icon=icon-lock-missed-call +x-nemo-display-on=true x-nemo-priority=120 -x-nemo-max-content-lines=1 x-nemo-feedback=call_exists -x-nemo-led-disabled-without-body-and-summary=false diff --git a/data/notifications/x-nemo.messaging.authorizationrequest.conf b/data/notifications/x-nemo.messaging.authorizationrequest.conf index ce9f231..252ad09 100644 --- a/data/notifications/x-nemo.messaging.authorizationrequest.conf +++ b/data/notifications/x-nemo.messaging.authorizationrequest.conf @@ -1,6 +1,4 @@ -appIcon=icon-lock-sms -x-nemo-icon=icon-lock-invitation -x-nemo-preview-icon=icon-s-status-invitation-pending +app_icon=icon-s-status-invitation-pending x-nemo-feedback=default x-nemo-user-removable=false x-nemo-priority=90 diff --git a/data/notifications/x-nemo.messaging.error.conf b/data/notifications/x-nemo.messaging.error.conf index 74bba23..2e9957f 100644 --- a/data/notifications/x-nemo.messaging.error.conf +++ b/data/notifications/x-nemo.messaging.error.conf @@ -1,3 +1,3 @@ -appIcon=icon-lock-information -urgency=2 +app_icon=icon-lock-information +x-nemo-display-on=true transient=true diff --git a/data/notifications/x-nemo.messaging.error.strong.conf b/data/notifications/x-nemo.messaging.error.strong.conf index 954839f..8ba348c 100644 --- a/data/notifications/x-nemo.messaging.error.strong.conf +++ b/data/notifications/x-nemo.messaging.error.strong.conf @@ -1,4 +1,4 @@ -appIcon=icon-lock-information -urgency=2 +app_icon=icon-lock-information +x-nemo-display-on=true transient=true x-nemo-feedback=warning_strong diff --git a/data/notifications/x-nemo.messaging.group.conf b/data/notifications/x-nemo.messaging.group.conf index 3b6a2a0..0270109 100644 --- a/data/notifications/x-nemo.messaging.group.conf +++ b/data/notifications/x-nemo.messaging.group.conf @@ -1,6 +1,4 @@ -appIcon=icon-lock-sms -urgency=2 -x-nemo-icon=icon-lock-sms +app_icon=icon-lock-sms +x-nemo-display-on=true x-nemo-priority=120 x-nemo-feedback=sms_exists -x-nemo-led-disabled-without-body-and-summary=false diff --git a/data/notifications/x-nemo.messaging.group.preview.conf b/data/notifications/x-nemo.messaging.group.preview.conf index fbe3425..a022973 100644 --- a/data/notifications/x-nemo.messaging.group.preview.conf +++ b/data/notifications/x-nemo.messaging.group.preview.conf @@ -1,7 +1,6 @@ -appIcon=icon-lock-sms +app_icon=icon-lock-sms transient=true -urgency=2 -x-nemo-preview-icon=icon-lock-sms +x-nemo-display-on=true x-nemo-priority=120 x-nemo-feedback=sms x-nemo-display-on=true diff --git a/data/notifications/x-nemo.messaging.im.conf b/data/notifications/x-nemo.messaging.im.conf index d86fe71..a6bb246 100644 --- a/data/notifications/x-nemo.messaging.im.conf +++ b/data/notifications/x-nemo.messaging.im.conf @@ -1,7 +1,4 @@ -appIcon=icon-lock-sms -urgency=2 -x-nemo-icon=icon-lock-sms +app_icon=icon-lock-sms +x-nemo-display-on=true x-nemo-priority=120 -x-nemo-max-content-lines=6 x-nemo-feedback=chat_exists -x-nemo-led-disabled-without-body-and-summary=false diff --git a/data/notifications/x-nemo.messaging.im.preview.conf b/data/notifications/x-nemo.messaging.im.preview.conf index 0fb30b3..120474d 100644 --- a/data/notifications/x-nemo.messaging.im.preview.conf +++ b/data/notifications/x-nemo.messaging.im.preview.conf @@ -1,7 +1,6 @@ -appIcon=icon-lock-sms +app_icon=icon-lock-sms transient=true -urgency=2 -x-nemo-preview-icon=icon-lock-sms +x-nemo-display-on=true x-nemo-priority=120 x-nemo-feedback=chat x-nemo-display-on=true diff --git a/data/notifications/x-nemo.messaging.mms.conf b/data/notifications/x-nemo.messaging.mms.conf index bf2033b..0270109 100644 --- a/data/notifications/x-nemo.messaging.mms.conf +++ b/data/notifications/x-nemo.messaging.mms.conf @@ -1,7 +1,4 @@ -appIcon=icon-lock-sms -urgency=2 -x-nemo-icon=icon-lock-sms +app_icon=icon-lock-sms +x-nemo-display-on=true x-nemo-priority=120 -x-nemo-max-content-lines=6 x-nemo-feedback=sms_exists -x-nemo-led-disabled-without-body-and-summary=false diff --git a/data/notifications/x-nemo.messaging.mms.preview.conf b/data/notifications/x-nemo.messaging.mms.preview.conf index fbe3425..a022973 100644 --- a/data/notifications/x-nemo.messaging.mms.preview.conf +++ b/data/notifications/x-nemo.messaging.mms.preview.conf @@ -1,7 +1,6 @@ -appIcon=icon-lock-sms +app_icon=icon-lock-sms transient=true -urgency=2 -x-nemo-preview-icon=icon-lock-sms +x-nemo-display-on=true x-nemo-priority=120 x-nemo-feedback=sms x-nemo-display-on=true diff --git a/data/notifications/x-nemo.messaging.sms.conf b/data/notifications/x-nemo.messaging.sms.conf index bf2033b..0270109 100644 --- a/data/notifications/x-nemo.messaging.sms.conf +++ b/data/notifications/x-nemo.messaging.sms.conf @@ -1,7 +1,4 @@ -appIcon=icon-lock-sms -urgency=2 -x-nemo-icon=icon-lock-sms +app_icon=icon-lock-sms +x-nemo-display-on=true x-nemo-priority=120 -x-nemo-max-content-lines=6 x-nemo-feedback=sms_exists -x-nemo-led-disabled-without-body-and-summary=false diff --git a/data/notifications/x-nemo.messaging.sms.preview.conf b/data/notifications/x-nemo.messaging.sms.preview.conf index fbe3425..a022973 100644 --- a/data/notifications/x-nemo.messaging.sms.preview.conf +++ b/data/notifications/x-nemo.messaging.sms.preview.conf @@ -1,7 +1,6 @@ -appIcon=icon-lock-sms +app_icon=icon-lock-sms transient=true -urgency=2 -x-nemo-preview-icon=icon-lock-sms +x-nemo-display-on=true x-nemo-priority=120 x-nemo-feedback=sms x-nemo-display-on=true diff --git a/data/notifications/x-nemo.messaging.voicemail-SMS.conf b/data/notifications/x-nemo.messaging.voicemail-SMS.conf index 3b6a2a0..0270109 100644 --- a/data/notifications/x-nemo.messaging.voicemail-SMS.conf +++ b/data/notifications/x-nemo.messaging.voicemail-SMS.conf @@ -1,6 +1,4 @@ -appIcon=icon-lock-sms -urgency=2 -x-nemo-icon=icon-lock-sms +app_icon=icon-lock-sms +x-nemo-display-on=true x-nemo-priority=120 x-nemo-feedback=sms_exists -x-nemo-led-disabled-without-body-and-summary=false diff --git a/data/notifications/x-nemo.messaging.voicemail-SMS.preview.conf b/data/notifications/x-nemo.messaging.voicemail-SMS.preview.conf index fbe3425..a022973 100644 --- a/data/notifications/x-nemo.messaging.voicemail-SMS.preview.conf +++ b/data/notifications/x-nemo.messaging.voicemail-SMS.preview.conf @@ -1,7 +1,6 @@ -appIcon=icon-lock-sms +app_icon=icon-lock-sms transient=true -urgency=2 -x-nemo-preview-icon=icon-lock-sms +x-nemo-display-on=true x-nemo-priority=120 x-nemo-feedback=sms x-nemo-display-on=true diff --git a/data/notifications/x-nemo.messaging.voicemail-waiting.conf b/data/notifications/x-nemo.messaging.voicemail-waiting.conf index e678c02..8326124 100644 --- a/data/notifications/x-nemo.messaging.voicemail-waiting.conf +++ b/data/notifications/x-nemo.messaging.voicemail-waiting.conf @@ -1,9 +1,5 @@ -appIcon=icon-lock-voicemail -x-nemo-icon=icon-lock-voicemail -x-nemo-preview-icon=icon-lock-voicemail +app_icon=icon-lock-voicemail x-nemo-priority=120 -x-nemo-max-content-lines=1 x-nemo-user-removable=false x-nemo-feedback=sms,sms_exists -x-nemo-led-disabled-without-body-and-summary=false x-nemo-display-on=true diff --git a/data/notifications/x-nemo.messaging.voicemail.conf b/data/notifications/x-nemo.messaging.voicemail.conf index df36467..8c9c963 100644 --- a/data/notifications/x-nemo.messaging.voicemail.conf +++ b/data/notifications/x-nemo.messaging.voicemail.conf @@ -1,8 +1,5 @@ -appIcon=icon-lock-voicemail -urgency=2 -x-nemo-icon=icon-lock-voicemail +app_icon=icon-lock-voicemail +x-nemo-display-on=true x-nemo-user-removable=false x-nemo-priority=120 -x-nemo-max-content-lines=1 x-nemo-feedback=sms_exists -x-nemo-led-disabled-without-body-and-summary=false diff --git a/data/notifications/x-nemo.messaging.voicemail.group.conf b/data/notifications/x-nemo.messaging.voicemail.group.conf index 2728096..6265dd1 100644 --- a/data/notifications/x-nemo.messaging.voicemail.group.conf +++ b/data/notifications/x-nemo.messaging.voicemail.group.conf @@ -1,8 +1,5 @@ -appIcon=icon-lock-voicemail -urgency=2 -x-nemo-icon=icon-lock-voicemail +app_icon=icon-lock-voicemail +x-nemo-display-on=true x-nemo-priority=120 x-nemo-user-removable=false -x-nemo-max-content-lines=1 x-nemo-feedback=sms_exists -x-nemo-led-disabled-without-body-and-summary=false diff --git a/data/notifications/x-nemo.messaging.voicemail.group.preview.conf b/data/notifications/x-nemo.messaging.voicemail.group.preview.conf index baff219..ab26b53 100644 --- a/data/notifications/x-nemo.messaging.voicemail.group.preview.conf +++ b/data/notifications/x-nemo.messaging.voicemail.group.preview.conf @@ -1,7 +1,6 @@ -appIcon=icon-lock-voicemail +app_icon=icon-lock-voicemail transient=true -urgency=2 -x-nemo-preview-icon=icon-lock-voicemail +x-nemo-display-on=true x-nemo-priority=120 x-nemo-feedback=sms x-nemo-display-on=true diff --git a/data/notifications/x-nemo.messaging.voicemail.preview.conf b/data/notifications/x-nemo.messaging.voicemail.preview.conf index baff219..ab26b53 100644 --- a/data/notifications/x-nemo.messaging.voicemail.preview.conf +++ b/data/notifications/x-nemo.messaging.voicemail.preview.conf @@ -1,7 +1,6 @@ -appIcon=icon-lock-voicemail +app_icon=icon-lock-voicemail transient=true -urgency=2 -x-nemo-preview-icon=icon-lock-voicemail +x-nemo-display-on=true x-nemo-priority=120 x-nemo-feedback=sms x-nemo-display-on=true diff --git a/rpm/commhistory-daemon.spec b/rpm/commhistory-daemon.spec index 8e68ec3..96d828c 100644 --- a/rpm/commhistory-daemon.spec +++ b/rpm/commhistory-daemon.spec @@ -11,7 +11,7 @@ BuildRequires: pkgconfig(Qt5DBus) BuildRequires: pkgconfig(Qt5Contacts) BuildRequires: pkgconfig(Qt5Versit) BuildRequires: pkgconfig(Qt5Test) -BuildRequires: pkgconfig(commhistory-qt5) >= 1.9.33 +BuildRequires: pkgconfig(commhistory-qt5) >= 1.10.1.1 BuildRequires: pkgconfig(contactcache-qt5) BuildRequires: pkgconfig(qtcontacts-sqlite-qt5-extensions) BuildRequires: pkgconfig(TelepathyQt5) @@ -20,16 +20,17 @@ BuildRequires: pkgconfig(mlocale5) BuildRequires: pkgconfig(mce) BuildRequires: pkgconfig(ngf-qt5) BuildRequires: pkgconfig(qt5-boostable) -BuildRequires: pkgconfig(nemonotifications-qt5) >= 1.0.5 +BuildRequires: pkgconfig(nemonotifications-qt5) > 1.2.1 BuildRequires: qt5-qttools BuildRequires: qt5-qttools-linguist BuildRequires: libqofono-qt5-devel >= 0.89 BuildRequires: libqofonoext-devel BuildRequires: python3-base BuildRequires: systemd -Requires: libcommhistory-qt5 >= 1.9.33 +Requires: libcommhistory-qt5 >= 1.10.1.1 Requires: libqofono-qt5 >= 0.66 Requires: mapplauncherd-qt5 +Requires: nemo-qml-plugin-notifications-qt5 >= 1.2.1.1 Obsoletes: smshistory <= 0.1.8 Provides: smshistory > 0.1.8 diff --git a/src/constants.h b/src/constants.h index 1f8f84f..af5371c 100644 --- a/src/constants.h +++ b/src/constants.h @@ -24,10 +24,6 @@ #ifndef CONSTANTS_H #define CONSTANTS_H -#include - -namespace RTComLogger { - // Used to generate duiremoteaction strings #define OBJECT_PATH QLatin1String("/") @@ -55,10 +51,10 @@ 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") +#define VOICECALL_SERVICE QLatin1String("com.jolla.voicecall.ui") +#define VOICECALL_OBJECT_PATH QLatin1String("/") +#define VOICECALL_INTERFACE QLatin1String("com.jolla.voicecall.ui") +#define VOICECALL_DIAL_METHOD QLatin1String("dial") // Custom hints for identifying notifications #define ACCOUNT_PATH_HINT QLatin1String("x-org-nemomobile-qmlmessages.account.path") @@ -96,30 +92,4 @@ namespace RTComLogger { #define VOICEMAIL_CONTACT_VMID_DIR QLatin1String("contacts") #define VOICEMAIL_CONTACT_VMID_FILE QLatin1String("vmid") -// events -struct EventTypes { - int type; - const char* event; -}; - -static const EventTypes _eventTypes[] = -{ - {CommHistory::Event::IMEvent, "x-nemo.messaging.im"}, - {CommHistory::Event::SMSEvent, "x-nemo.messaging.sms"}, - {CommHistory::Event::MMSEvent, "x-nemo.messaging.mms"}, - {CommHistory::Event::CallEvent, "x-nemo.call.missed"}, - {CommHistory::Event::VoicemailEvent,"x-nemo.messaging.voicemail"}, - {VOICEMAIL_SMS_EVENT_TYPE, "x-nemo.messaging.voicemail-SMS"} -}; - -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 diff --git a/src/locstrings.h b/src/locstrings.h index 82983fc..3dcc4c1 100644 --- a/src/locstrings.h +++ b/src/locstrings.h @@ -61,10 +61,10 @@ #define txt_qtn_msg_contact_card_label qtTrId("qtn_msg_contact_card_label") //% "%1 | %2" #define txt_qtn_msg_notification_new_vcard(STR) qtTrId("qtn_msg_received_contact_card").arg(txt_qtn_msg_contact_card_label).arg(STR) -//% "Show Messages" -#define txt_qtn_msg_notification_show_messages qtTrId("txt_qtn_msg_notification_show_messages") //% "Reply" #define txt_qtn_msg_notification_reply qtTrId("qtn_msg_notification_reply") +//% "Call" +#define txt_qtn_msg_notification_call qtTrId("qtn_msg_notification_call") //% "%n attachment(s)" #define txt_qtn_mms_notification_attachment(NUM) qtTrId("qtn_mms_notification_attachment", NUM) //% "%1 | %2" @@ -79,15 +79,15 @@ #define txt_qtn_call_type_private qtTrId("qtn_call_type_private") //% "Voicemail" #define txt_qtn_call_type_voicemail qtTrId("qtn_call_type_voicemail") -//% "Show call history" -#define txt_qtn_call_notification_show_call_history qtTrId("txt_qtn_call_notification_show_call_history") +//% "Call back" +#define txt_qtn_call_notification_call_back qtTrId("txt_qtn_call_notification_call_back") +//% "Send message" +#define txt_qtn_call_notification_send_message qtTrId("txt_qtn_call_notification_send_message") //% "Tap to listen" #define txt_qtn_voicemail_prompt qtTrId("qtn_voicemail_prompt") //% "Call voicemail" #define txt_qtn_voicemail_notification_call qtTrId("txt_qtn_voicemail_notification_call") -//% "Show voicemail" -#define txt_qtn_voicemail_notification_show_voicemail qtTrId("txt_qtn_voicemail_notification_show_voicemail") //% "Multimedia message was delivered to %1" #define txt_qtn_msg_notification_delivered(STR) qtTrId("qtn_mms_info_delivered").arg(STR) diff --git a/src/notificationgroup.cpp b/src/notificationgroup.cpp deleted file mode 100644 index 70ff1a7..0000000 --- a/src/notificationgroup.cpp +++ /dev/null @@ -1,368 +0,0 @@ -/****************************************************************************** -** -** This file is part of commhistory-daemon. -** -** Copyright (C) 2013 Jolla Ltd. -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -** Contact: John Brooks -** -** This library is free software; you can redistribute it and/or modify it -** under the terms of the GNU Lesser General Public License version 2.1 as -** published by the Free Software Foundation. -** -** This library 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 Lesser General Public -** License for more details. -** -** You should have received a copy of the GNU Lesser General Public License -** along with this library; if not, write to the Free Software Foundation, Inc., -** 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -** -******************************************************************************/ - -#include "notificationgroup.h" -#include "personalnotification.h" -#include "notificationmanager.h" -#include "locstrings.h" -#include "constants.h" -#include "debug.h" - -#include - -#include - -#include -#include - -using namespace RTComLogger; - -ML10N::MLocale mLocale; - -NotificationGroup::NotificationGroup(PersonalNotification::EventCollection collection, const QString &localUid, const QString &remoteUid, QObject *parent) - : QObject(parent), m_collection(collection), m_localUid(localUid), m_remoteUid(remoteUid), mGroup(0) -{ - updateTimer.setInterval(0); - updateTimer.setSingleShot(true); - connect(&updateTimer, SIGNAL(timeout()), SLOT(updateGroup())); - - connect(this, SIGNAL(changed()), SLOT(updateGroupLater())); -} - -NotificationGroup::~NotificationGroup() -{ - qDeleteAll(mNotifications); - delete mGroup; -} - -QString NotificationGroup::groupType(int eventType) -{ - for (int i = 0; i < _eventTypesCount; i++) { - if (_eventTypes[i].type == eventType) - return QLatin1String(_eventTypes[i].event); - } - return QString(); -} - -int NotificationGroup::eventType(const QString &groupType) -{ - for (int i = 0; i < _eventTypesCount; i++) { - if (_eventTypes[i].event == groupType) - return _eventTypes[i].type; - } - return -1; -} - -QString NotificationGroup::groupName(PersonalNotification::EventCollection collection) -{ - switch (collection) { - case PersonalNotification::Voicemail: - return txt_qtn_msg_voicemail_group; - - case PersonalNotification::Voice: - return txt_qtn_msg_missed_calls_group; - - case PersonalNotification::Messaging: - return txt_qtn_msg_notifications_group; - } - - return QString(); -} - -QString NotificationGroup::groupCategory(PersonalNotification::EventCollection collection) -{ - switch (collection) { - case PersonalNotification::Voicemail: - return QStringLiteral("x-nemo.messaging.voicemail.group"); - - case PersonalNotification::Voice: - return QStringLiteral("x-nemo.call.missed.group"); - - case PersonalNotification::Messaging: - return QStringLiteral("x-nemo.messaging.group"); - } - - return QString(); -} - -PersonalNotification::EventCollection NotificationGroup::collection() const -{ - return m_collection; -} - -const QString &NotificationGroup::localUid() const -{ - return m_localUid; -} - -const QString &NotificationGroup::remoteUid() const -{ - return m_remoteUid; -} - -Notification *NotificationGroup::notification() -{ - if (!mGroup && !mNotifications.isEmpty()) - updateGroup(); - return mGroup; -} - -QList NotificationGroup::notifications() const -{ - return mNotifications; -} - -void NotificationGroup::updateGroup() -{ - if (mNotifications.isEmpty()) { - removeGroup(); - return; - } - - // Publish group notification, not including preview banners/sounds. - if (!mGroup) { - mGroup = new Notification(this); - connect(mGroup, SIGNAL(closed(uint)), SLOT(onClosed(uint))); - } - - mGroup->setAppName(groupName(m_collection)); - mGroup->setCategory(groupCategory(m_collection)); - mGroup->setSummary(mLocale.joinStringList(contactNames())); - mGroup->setBody(notificationGroupText()); - mGroup->setItemCount(mNotifications.size()); - - // This group is only visible if the members are hidden - const bool membersHidden(mNotifications[0]->hidden()); - mGroup->setHintValue("x-nemo-hidden", !membersHidden); - - const bool grouped(countConversations() > 1); - NotificationManager::instance()->setNotificationProperties(mGroup, mNotifications[0], grouped); - - // Find the most recent timestamp from grouped notifications - QDateTime groupTimestamp; - bool allRestored = true; - - foreach (PersonalNotification *pn, mNotifications) { - // Are all members restored from storage? - allRestored &= pn->restored(); - - if (pn->hasPendingEvents()) { - // Publish this notification to ensure it has a timestamp - pn->publishNotification(); - } - - QDateTime timestamp(pn->timestamp()); - if (groupTimestamp.isNull() || timestamp > groupTimestamp) { - groupTimestamp = timestamp; - } - } - mGroup->setTimestamp(groupTimestamp); - - // Show preview banner for this group update unless we've just restored from storage - // (missed calls have no preview as the incoming call dialog was just shown) - if ((m_collection != PersonalNotification::Voice) && membersHidden && !allRestored) { - Notification preview; - - preview.setAppName(mGroup->appName()); - preview.setCategory(mGroup->category() + QStringLiteral(".preview")); - preview.setPreviewSummary(mGroup->summary()); - preview.setPreviewBody(mGroup->body()); - - NotificationManager::instance()->setNotificationProperties(&preview, mNotifications[0], grouped); - - preview.publish(); - - DEBUG() << preview.replacesId() << preview.category() << preview.previewSummary() << preview.previewBody(); - } - - mGroup->publish(); - - DEBUG() << mGroup->replacesId() << mGroup->category() << mGroup->summary() << mGroup->body() << mGroup->hintValue("x-nemo-hidden"); -} - -void NotificationGroup::updateGroupLater() -{ - updateTimer.start(); -} - -QStringList NotificationGroup::contactNames() -{ - QStringList names; - QList > details; - - foreach (PersonalNotification *pn, mNotifications) { - // events are ordered from most recent to oldest - const QString &name(pn->notificationName()); - const CommHistory::Recipient &recipient(pn->recipient()); - - QList >::iterator it = details.begin(), end = details.end(); - for ( ; it != end; ++it) { - if (recipient.matches((*it).first)) { - // These events have the same recipient - use the longer name (this is for - // the case where both names are variants of the same phone number) - if (name.length() > (*it).second.length()) { - (*it).second = name; - } - break; - } - } - if (it == details.end()) { - details.append(qMakePair(recipient, name)); - } - } - - // Reverse the order of the notifications - QList >::const_iterator begin = details.begin(), it = details.end(); - while (it != begin) { - --it; - names.append((*it).second); - } - - return names; -} - -int NotificationGroup::countConversations() -{ - QSet > seen; - foreach (PersonalNotification *pn, mNotifications) - seen.insert(qMakePair(pn->account(), pn->remoteUid())); - return seen.count(); -} - -QString NotificationGroup::notificationGroupText() -{ - QString message; - int notifications = mNotifications.size(); - if (!notifications) - return QString(); - - switch (m_collection) - { - case PersonalNotification::Messaging: - { - if (notifications > 1) - message = txt_qtn_msg_notification_new_message(notifications); - else - message = mNotifications[0]->notificationText(); - break; - } - case PersonalNotification::Voice: - { - message = txt_qtn_call_missed(notifications); - break; - } - case PersonalNotification::Voicemail: - { - // The amount of new / not listened voicemails - message = mNotifications[0]->notificationText(); - break; - } - default: - break; - } - - return message; -} - -void NotificationGroup::removeGroup() -{ - if (mGroup) { - mGroup->close(); - mGroup->deleteLater(); - mGroup = 0; - } - - while (!mNotifications.isEmpty()) - removeNotification(mNotifications.first()); -} - -void NotificationGroup::addNotification(PersonalNotification *notification) -{ - if (mNotifications.contains(notification)) - return; - - // If notification->hasPendingEvents, the updateGroup slot will also publish the notification - connect(notification, SIGNAL(hasPendingEventsChanged(bool)), SLOT(onNotificationChanged())); - connect(notification, SIGNAL(notificationClosed(PersonalNotification*)), SLOT(onNotificationClosed(PersonalNotification*))); - mNotifications.append(notification); - - // Only missed call and voicemail notifications are grouped - if (m_collection == PersonalNotification::Voice || - m_collection == PersonalNotification::Voicemail) { - if (mNotifications.count() > 1) { - // Hide the member notification - notification->setHidden(true); - - // Also hide the first member, which would not have been hidden on addition - mNotifications.first()->setHidden(true); - } else { - // Ensure the notification is visible - notification->setHidden(false); - } - } - - emit changed(); -} - -bool NotificationGroup::removeNotification(PersonalNotification *¬ification) -{ - if (mNotifications.removeOne(notification)) { - notification->removeNotification(); - notification->deleteLater(); - notification = 0; - - if (m_collection == PersonalNotification::Voice || - m_collection == PersonalNotification::Voicemail) { - if (mNotifications.count() == 1) { - // Un-hide the member notification - mNotifications.first()->setHidden(false); - } - } - - emit changed(); - return true; - } - - return false; -} - -void NotificationGroup::onNotificationChanged() -{ - PersonalNotification *pn = qobject_cast(sender()); - if (!pn || !mNotifications.contains(pn)) - return; - - if (pn->hasPendingEvents()) - emit changed(); -} - -void NotificationGroup::onNotificationClosed(PersonalNotification *notification) -{ - removeNotification(notification); -} - -void NotificationGroup::onClosed(uint /*reason*/) -{ - removeGroup(); -} - diff --git a/src/notificationgroup.h b/src/notificationgroup.h deleted file mode 100644 index b700dcd..0000000 --- a/src/notificationgroup.h +++ /dev/null @@ -1,113 +0,0 @@ -/****************************************************************************** -** -** This file is part of commhistory-daemon. -** -** Copyright (C) 2013 Jolla Ltd. -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -** Contact: John Brooks -** -** This library is free software; you can redistribute it and/or modify it -** under the terms of the GNU Lesser General Public License version 2.1 as -** published by the Free Software Foundation. -** -** This library 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 Lesser General Public -** License for more details. -** -** You should have received a copy of the GNU Lesser General Public License -** along with this library; if not, write to the Free Software Foundation, Inc., -** 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -** -******************************************************************************/ - -#ifndef NOTIFICATIONGROUP_H -#define NOTIFICATIONGROUP_H - -#include "personalnotification.h" - -#include -#include -#include -#include - -class Notification; - -namespace CommHistory { - class Event; -} - -namespace RTComLogger { - -class NotificationGroup : public QObject -{ - Q_OBJECT - -public: - NotificationGroup(PersonalNotification::EventCollection collection, const QString &localUid, const QString &remoteUid, QObject *parent = 0); - virtual ~NotificationGroup(); - - static QString groupType(int eventType); - static int eventType(const QString &groupType); - - static QString groupName(PersonalNotification::EventCollection collection); - static QString groupCategory(PersonalNotification::EventCollection collection); - - PersonalNotification::EventCollection collection() const; - const QString &localUid() const; - const QString &remoteUid() const; - - Notification *notification(); - QList notifications() const; - - /* Add a notification to this group - * - * Ownership and management of the notification are assumed. If marked as pending, the - * notification will be emitted automatically. Changes to the notification will be handled - * automatically. */ - void addNotification(PersonalNotification *notification); - - /* Remove a notification - * - * The notification will be unpublished and its instance deleted. The group may be empty - * afterwards, in which case it will also be unpublished. Caller should delete this instance - * when empty afterwards, if desired. */ - bool removeNotification(PersonalNotification *¬ification); - -public slots: - /* Update the group's message text and publish it if necessary. Should not need to be called - * manually; the group will be updated after all relevant changes to notifications. */ - void updateGroup(); - void updateGroupLater(); - - /* Remove the group and all notifications. Equivalent to calling removeNotification for each - * notification. */ - void removeGroup(); - -signals: - /* Emitted when the group or any notification within it has changed */ - void changed(); - -private slots: - void onNotificationChanged(); - void onNotificationClosed(PersonalNotification *); - void onClosed(uint); - -private: - PersonalNotification::EventCollection m_collection; - QString m_localUid; - QString m_remoteUid; - Notification *mGroup; - QList mNotifications; - QTimer updateTimer; - - friend class Ut_NotificationManager; - - QStringList contactNames(); - QString notificationGroupText(); - int countConversations(); -}; - -} // namespace - -#endif // NOTIFICATIONGROUP_H diff --git a/src/notificationmanager.cpp b/src/notificationmanager.cpp index b15d3f3..7366651 100644 --- a/src/notificationmanager.cpp +++ b/src/notificationmanager.cpp @@ -2,6 +2,7 @@ ** ** This file is part of commhistory-daemon. ** +** Copyright (C) 2020 Open Mobile Platform LLC. ** Copyright (C) 2013-2016 Jolla Ltd. ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). ** Contact: John Brooks @@ -57,6 +58,7 @@ NotificationManager* NotificationManager::m_pInstance = 0; static const QString NgfdEventSms("sms"); static const QString NgfdEventChat("chat"); +static const QString voicemailWaitingCategory = "x-nemo.messaging.voicemail-waiting"; // constructor // @@ -73,7 +75,7 @@ NotificationManager::NotificationManager(QObject* parent) NotificationManager::~NotificationManager() { qDeleteAll(interfaces.values()); - qDeleteAll(m_Groups); + qDeleteAll(m_notifications); qDeleteAll(m_unresolvedNotifications); } @@ -193,12 +195,7 @@ bool NotificationManager::updateEditedEvent(const CommHistory::Event& event, con } } - EventGroupProperties groupProperties(eventGroup(PersonalNotification::collection(event.type()), event.recipients().value(0))); - NotificationGroup *eventGroup = m_Groups.value(groupProperties); - if (!eventGroup) - return false; - - foreach (PersonalNotification *pn, eventGroup->notifications()) { + foreach (PersonalNotification *pn, m_notifications) { if (pn->eventToken() == event.messageToken()) { pn->setNotificationText(text); return true; @@ -208,6 +205,38 @@ bool NotificationManager::updateEditedEvent(const CommHistory::Event& event, con return false; } +static PersonalNotification *findNotification( + QList *notifications, const CommHistory::Event& event) +{ + const CommHistory::Recipient recipient = event.recipients().value(0); + + auto it = std::find_if( + notifications->begin(), + notifications->end(), + [&](PersonalNotification *notification) { + return notification->eventType() == event.type() && notification->recipient().matches(recipient); + }); + + return it != notifications->end() ? *it : nullptr; +} + +static void amendCallNotification( + PersonalNotification *personal, const CommHistory::Event& event, const QString &text) +{ + personal->setEventToken(event.messageToken()); + + Notification *notification = personal->notification(); + + notification->setItemCount(qMax(1, notification->itemCount()) + 1); + notification->setTimestamp(QDateTime::currentDateTime()); + + if (event.type() == CommHistory::Event::CallEvent) { + personal->setNotificationText(txt_qtn_call_missed(notification->itemCount())); + } else { + personal->setNotificationText(text); + } +} + void NotificationManager::showNotification(const CommHistory::Event& event, const QString& channelTargetId, CommHistory::Group::ChatType chatType, @@ -243,8 +272,9 @@ void NotificationManager::showNotification(const CommHistory::Event& event, // try to update notifications for existing event QString text(notificationText(event, details)); - if (event.isValid() && updateEditedEvent(event, text)) + if (event.isValid() && updateEditedEvent(event, text)) { return; + } // Get MUC topic from group QString chatName; @@ -263,6 +293,28 @@ void NotificationManager::showNotification(const CommHistory::Event& event, } } + if (event.type() == CommHistory::Event::CallEvent + || event.type() == CommHistory::Event::VoicemailEvent) { + if (PersonalNotification *personal = findNotification(&m_unresolvedNotifications, event)) { + amendCallNotification(personal, event, text); + + return; + } else if (PersonalNotification *personal = findNotification(&m_notifications, event)) { + amendCallNotification(personal, event, text); + + if (event.type() == CommHistory::Event::CallEvent) { + Notification *notification = personal->notification(); + + notification->clearPreviewSummary(); + notification->clearPreviewBody(); + } + + personal->publishNotification(); + + return; + } + } + PersonalNotification *notification = new PersonalNotification(event.recipients().value(0).remoteUid(), event.localUid(), event.type(), channelTargetId, chatType); notification->setNotificationText(text); @@ -346,59 +398,51 @@ bool NotificationManager::isCurrentlyObservedByUI(const CommHistory::Event& even return false; } -void NotificationManager::removeNotifications(const QString &accountPath, const QList &removeTypes) +static void deleteNotifications( + QList *notifications, QList::iterator eraseFrom) { - DEBUG() << Q_FUNC_INFO << "Removing notifications of account " << accountPath; - - QSet updatedGroups; - - // remove matched notifications and update group - foreach (NotificationGroup *group, m_Groups) { - if (group->localUid() != accountPath) { - continue; + if (eraseFrom != notifications->end()) { + for (auto it = eraseFrom; it != notifications->end(); ++it) { + PersonalNotification *notification = *it; + notification->removeNotification(); + notification->deleteLater(); } - foreach (PersonalNotification *notification, group->notifications()) { - if (removeTypes.isEmpty() || removeTypes.contains(notification->eventType())) { - DEBUG() << Q_FUNC_INFO << "Removing notification: accountPath: " << notification->account() << " remoteUid: " << notification->remoteUid(); - group->removeNotification(notification); - } - } + notifications->erase(eraseFrom, notifications->end()); } +} - for (QList::iterator it = m_unresolvedNotifications.begin(); - it != m_unresolvedNotifications.end(); ) { - if ((*it)->account() == accountPath) { - delete *it; - it = m_unresolvedNotifications.erase(it); - } else - it++; - } +static void removeListNotifications( + QList *notifications, const QString &accountPath, const QList &removeTypes) +{ + auto eraseFrom = std::find_if(notifications->begin(), notifications->end(), [&](PersonalNotification *notification) { + return notification->account() == accountPath && removeTypes.contains(notification->eventType()); + }); + + deleteNotifications(notifications, eraseFrom); } -void NotificationManager::removeConversationNotifications(const CommHistory::Recipient &recipient, - CommHistory::Group::ChatType chatType) +void NotificationManager::removeNotifications(const QString &accountPath, const QList &removeTypes) { - QHash::const_iterator it = m_Groups.constBegin(), end = m_Groups.constEnd(); - for ( ; it != end; ++it) { - NotificationGroup *group(it.value()); + DEBUG() << Q_FUNC_INFO << "Removing notifications of account " << accountPath; - foreach (PersonalNotification *notification, group->notifications()) { - if (notification->collection() != PersonalNotification::Messaging || - notification->chatType() != chatType) - continue; + // remove matched notifications + removeListNotifications(&m_notifications, accountPath, removeTypes); + removeListNotifications(&m_unresolvedNotifications, accountPath, removeTypes); +} - // For p-to-p chat we use remote uid for comparison and for MUC we use target (channel) id: - bool match(false); - if (chatType == CommHistory::Group::ChatTypeP2P) - match = recipient.matches(notification->recipient()); - else - match = recipient.matches(Recipient(notification->account(), notification->targetId())); +void NotificationManager::removeConversationNotifications(const CommHistory::Recipient &recipient, + CommHistory::Group::ChatType chatType) +{ + auto eraseFrom = std::find_if(m_notifications.begin(), m_notifications.end(), [&](PersonalNotification *notification) { + return notification->collection() == PersonalNotification::Messaging + && notification->chatType() == chatType + && (chatType == CommHistory::Group::ChatTypeP2P + ? recipient.matches(notification->recipient()) + : recipient.matches(Recipient(notification->account(), notification->targetId()))); + }); - if (match) - group->removeNotification(notification); - } - } + deleteNotifications(&m_notifications, eraseFrom); } void NotificationManager::slotObservedConversationsChanged(const QList &conversations) @@ -452,25 +496,28 @@ void NotificationManager::removeNotificationTypes(const QList &types) { DEBUG() << Q_FUNC_INFO << types; - foreach (NotificationGroup *group, m_Groups) { - foreach (PersonalNotification *notification, group->notifications()) { - if (types.contains(notification->eventType())) { - group->removeNotification(notification); - } - } - } + auto eraseFrom = std::find_if(m_notifications.begin(), m_notifications.end(), [&](PersonalNotification *notification) { + return types.contains(notification->eventType()); + }); + + deleteNotifications(&m_notifications, eraseFrom); } void NotificationManager::addNotification(PersonalNotification *notification) { - EventGroupProperties groupProperties(eventGroup(notification->collection(), CommHistory::Recipient(notification->account(), notification->remoteUid()))); - NotificationGroup *group = m_Groups.value(groupProperties); - if (!group) { - group = new NotificationGroup(groupProperties.collection, notification->account(), notification->remoteUid(), this); - m_Groups.insert(groupProperties, group); - } + if (!m_notifications.contains(notification)) { + connect(notification, &PersonalNotification::hasPendingEventsChanged, this, [notification](bool hasEvents) { + if (hasEvents) { + notification->publishNotification(); + } + }); + + if (notification->hasPendingEvents()) { + notification->publishNotification(); + } - group->addNotification(notification); + m_notifications.append(notification); + } } int NotificationManager::pendingEventCount() @@ -563,36 +610,67 @@ void NotificationManager::setNotificationProperties(Notification *notification, case PersonalNotification::Messaging: if (pn->eventType() != VOICEMAIL_SMS_EVENT_TYPE && grouped) { + // Default action: show the inbox remoteActions.append(dbusAction("default", - txt_qtn_msg_notification_show_messages, + QString(), MESSAGING_SERVICE_NAME, OBJECT_PATH, MESSAGING_INTERFACE, SHOW_INBOX_METHOD)); } else { + // Default action: show the message remoteActions.append(dbusAction("default", - txt_qtn_msg_notification_reply, + QString(), MESSAGING_SERVICE_NAME, OBJECT_PATH, MESSAGING_INTERFACE, START_CONVERSATION_METHOD, QVariantList() << pn->account() << pn->targetId() - << static_cast(pn->chatType()))); + << false)); + } + + if (pn->eventType() == CommHistory::Event::IMEvent + || pn->eventType() == CommHistory::Event::SMSEvent + || pn->eventType() == CommHistory::Event::MMSEvent) { + + if (pn->eventType() == CommHistory::Event::IMEvent || pn->hasPhoneNumber()) { + // Named action: "Reply" + remoteActions.append(dbusAction(QString(), + txt_qtn_msg_notification_reply, + MESSAGING_SERVICE_NAME, + OBJECT_PATH, + MESSAGING_INTERFACE, + START_CONVERSATION_METHOD, + QVariantList() << pn->account() + << pn->targetId() + << true)); + } + } + + if (pn->eventType() == CommHistory::Event::SMSEvent + || pn->eventType() == CommHistory::Event::MMSEvent + || pn->eventType() == VOICEMAIL_SMS_EVENT_TYPE) { + if (pn->hasPhoneNumber()) { + // Named action: "Call" + remoteActions.append(dbusAction(QString(), + txt_qtn_msg_notification_call, + VOICECALL_SERVICE, + VOICECALL_OBJECT_PATH, + VOICECALL_INTERFACE, + VOICECALL_DIAL_METHOD, + QVariantList() << pn->remoteUid())); + } } - remoteActions.append(dbusAction("app", - QString(), - MESSAGING_SERVICE_NAME, - OBJECT_PATH, - MESSAGING_INTERFACE, - SHOW_INBOX_METHOD)); break; case PersonalNotification::Voice: + // Missed calls. + // Default action: show Call History remoteActions.append(dbusAction("default", - txt_qtn_call_notification_show_call_history, + QString(), CALL_HISTORY_SERVICE_NAME, CALL_HISTORY_OBJECT_PATH, CALL_HISTORY_INTERFACE, @@ -605,12 +683,34 @@ void NotificationManager::setNotificationProperties(Notification *notification, CALL_HISTORY_INTERFACE, CALL_HISTORY_METHOD, QVariantList() << CALL_HISTORY_PARAMETER)); + + if (pn->hasPhoneNumber()) { + remoteActions.append(dbusAction(QString(), + txt_qtn_call_notification_call_back, + VOICECALL_SERVICE, + VOICECALL_OBJECT_PATH, + VOICECALL_INTERFACE, + VOICECALL_DIAL_METHOD, + QVariantList() << pn->remoteUid())); + + remoteActions.append(dbusAction(QString(), + txt_qtn_call_notification_send_message, + MESSAGING_SERVICE_NAME, + OBJECT_PATH, + MESSAGING_INTERFACE, + START_CONVERSATION_METHOD, + QVariantList() << pn->account() + << pn->targetId() + << true)); + } + break; case PersonalNotification::Voicemail: + // Default action: show voicemail remoteActions.append(dbusAction("default", - txt_qtn_voicemail_notification_show_voicemail, + QString(), CALL_HISTORY_SERVICE_NAME, VOICEMAIL_OBJECT_PATH, VOICEMAIL_INTERFACE, @@ -646,12 +746,10 @@ void NotificationManager::slotContactChanged(const RecipientList &recipients) DEBUG() << Q_FUNC_INFO << recipients; // Check all existing notifications and update if necessary - foreach (NotificationGroup *group, m_Groups) { - foreach (PersonalNotification *notification, group->notifications()) { - if (recipients.contains(notification->recipient())) { - DEBUG() << "Contact changed for notification" << notification->account() << notification->remoteUid() << notification->contactId(); - notification->updateRecipientData(); - } + foreach (PersonalNotification *notification, m_notifications) { + if (recipients.contains(notification->recipient())) { + DEBUG() << "Contact changed for notification" << notification->account() << notification->remoteUid() << notification->contactId(); + notification->updateRecipientData(); } } } @@ -661,12 +759,10 @@ void NotificationManager::slotContactInfoChanged(const RecipientList &recipients DEBUG() << Q_FUNC_INFO << recipients; // Check all existing notifications and update if necessary - foreach (NotificationGroup *group, m_Groups) { - foreach (PersonalNotification *notification, group->notifications()) { - if (recipients.contains(notification->recipient())) { - DEBUG() << "Contact info changed for notification" << notification->account() << notification->remoteUid() << notification->contactId(); - notification->updateRecipientData(); - } + foreach (PersonalNotification *notification, m_notifications) { + if (recipients.contains(notification->recipient())) { + DEBUG() << "Contact info changed for notification" << notification->account() << notification->remoteUid() << notification->contactId(); + notification->updateRecipientData(); } } } @@ -720,8 +816,6 @@ void NotificationManager::slotGroupDataChanged(const QModelIndex &topLeft, const { DEBUG() << Q_FUNC_INFO; - QSet updatedGroups; - // Update MUC notifications if MUC topic has changed for (int i = topLeft.row(); i <= bottomRight.row(); i++) { QModelIndex row = m_GroupModel->index(i, 0); @@ -729,26 +823,20 @@ void NotificationManager::slotGroupDataChanged(const QModelIndex &topLeft, const if (group.isValid()) { const Recipient &groupRecipient(group.recipients().value(0)); - foreach (NotificationGroup *g, m_Groups) { - if (g->localUid() != groupRecipient.localUid()) { - continue; - } - - foreach (PersonalNotification *pn, g->notifications()) { - // If notification is for MUC and matches to changed group... - if (!pn->chatName().isEmpty()) { - const Recipient notificationRecipient(pn->account(), pn->targetId()); - if (notificationRecipient.matches(groupRecipient)) { - QString newChatName; - if (group.chatName().isEmpty() && pn->chatName() != txt_qtn_msg_group_chat) - newChatName = txt_qtn_msg_group_chat; - else if (group.chatName() != pn->chatName()) - newChatName = group.chatName(); - - if (!newChatName.isEmpty()) { - DEBUG() << Q_FUNC_INFO << "Changing chat name to" << newChatName; - pn->setChatName(newChatName); - } + foreach (PersonalNotification *pn, m_notifications) { + // If notification is for MUC and matches to changed group... + if (pn->account() == groupRecipient.localUid() && !pn->chatName().isEmpty()) { + const Recipient notificationRecipient(pn->account(), pn->targetId()); + if (notificationRecipient.matches(groupRecipient)) { + QString newChatName; + if (group.chatName().isEmpty() && pn->chatName() != txt_qtn_msg_group_chat) + newChatName = txt_qtn_msg_group_chat; + else if (group.chatName() != pn->chatName()) + newChatName = group.chatName(); + + if (!newChatName.isEmpty()) { + DEBUG() << Q_FUNC_INFO << "Changing chat name to" << newChatName; + pn->setChatName(newChatName); } } } @@ -801,7 +889,7 @@ void NotificationManager::slotVoicemailWaitingChanged() // Publish a new voicemail-waiting notification Notification voicemailNotification; - voicemailNotification.setAppName(NotificationGroup::groupName(PersonalNotification::Voicemail)); + voicemailNotification.setAppName(txt_qtn_msg_voicemail_group); voicemailNotification.setCategory(voicemailWaitingCategory); // If ofono reports zero voicemail messages, we don't know the real number; report 1 as a fallback @@ -809,25 +897,21 @@ void NotificationManager::slotVoicemailWaitingChanged() voicemailNotification.setPreviewBody(txt_qtn_voicemail_prompt); voicemailNotification.setSummary(voicemailNotification.previewSummary()); - voicemailNotification.setBody(voicemailNotification.previewBody()); voicemailNotification.setItemCount(voicemailCount); - QString displayName; QString service; QString path; QString iface; QString method; QVariantList args; if (!voicemailNumber.isEmpty()) { - displayName = txt_qtn_voicemail_notification_call; - service = VOICEMAIL_WAITING_SERVICE; - path = VOICEMAIL_WAITING_OBJECT_PATH; - iface = VOICEMAIL_WAITING_INTERFACE; - method = VOICEMAIL_WAITING_METHOD; + service = VOICECALL_SERVICE; + path = VOICECALL_OBJECT_PATH; + iface = VOICECALL_INTERFACE; + method = VOICECALL_DIAL_METHOD; args.append(QVariant(QVariantList() << QString(QStringLiteral("tel://")) + voicemailNumber)); } else { - displayName = txt_qtn_call_notification_show_call_history; service = CALL_HISTORY_SERVICE_NAME; path = CALL_HISTORY_OBJECT_PATH; iface = CALL_HISTORY_INTERFACE; @@ -835,7 +919,7 @@ void NotificationManager::slotVoicemailWaitingChanged() args.append(CALL_HISTORY_PARAMETER); } - voicemailNotification.setRemoteActions(QVariantList() << dbusAction("default", displayName, service, path, iface, method, args) + voicemailNotification.setRemoteActions(QVariantList() << dbusAction("default", QString(), service, path, iface, method, args) << dbusAction("app", QString(), service, path, iface, method, args)); voicemailNotification.setReplacesId(currentId); diff --git a/src/notificationmanager.h b/src/notificationmanager.h index a572016..3f61f33 100644 --- a/src/notificationmanager.h +++ b/src/notificationmanager.h @@ -46,7 +46,6 @@ // our includes #include "commhistoryservice.h" -#include "notificationgroup.h" #include "personalnotification.h" namespace Ngf { @@ -68,20 +67,6 @@ class NotificationManager : public QObject public: typedef CommHistory::RecipientList RecipientList; - struct EventGroupProperties { - PersonalNotification::EventCollection collection; - CommHistory::Recipient recipient; - - bool operator== (const EventGroupProperties &other) const { return (collection == other.collection && recipient.matches(other.recipient)); } - }; - - static EventGroupProperties eventGroup(PersonalNotification::EventCollection c, const CommHistory::Recipient &recipient) { - EventGroupProperties properties; - properties.collection = c; - properties.recipient = recipient; - return properties; - } - /*! * \param QObject parent object * \returns Notification manager singleton @@ -166,8 +151,6 @@ private Q_SLOTS: void syncNotifications(); int pendingEventCount(); - void clearPendingEvents(const NotificationGroup &group); - void removeNotPendingEvents(const NotificationGroup &group); bool isFilteredInbox(); QString filteredInboxAccountPath(); @@ -178,9 +161,9 @@ private Q_SLOTS: private: static NotificationManager* m_pInstance; - QHash m_Groups; bool m_Initialised; + QList m_notifications; QList m_unresolvedNotifications; CommHistory::ContactResolver *m_contactResolver; @@ -198,15 +181,6 @@ private Q_SLOTS: #endif }; -inline uint qHash(const NotificationManager::EventGroupProperties &properties, uint seed) -{ - using ::qHash; - // EventGroups are ultimately equivalent by the contacts they resolve to, so we should use - // contact ID as the hash differentiator. UID pairs that do not resolve to a contact will - // therefore all hash to the same value, which will be inefficient, but work correctly - return qHash(properties.collection, seed) ^ qHash(properties.recipient.contactId(), seed); -} - } // namespace RTComLogger #endif // NOTIFICATIONMANAGER_H diff --git a/src/personalnotification.cpp b/src/personalnotification.cpp index 627ebee..dea5dd0 100644 --- a/src/personalnotification.cpp +++ b/src/personalnotification.cpp @@ -23,7 +23,6 @@ #include "personalnotification.h" #include "notificationmanager.h" -#include "notificationgroup.h" #include "locstrings.h" #include "constants.h" #include "debug.h" @@ -34,12 +33,54 @@ using namespace RTComLogger; using namespace CommHistory; +// events +struct EventTypes { + int type; + const char* event; +}; + +static const EventTypes _eventTypes[] = +{ + {CommHistory::Event::IMEvent, "x-nemo.messaging.im"}, + {CommHistory::Event::SMSEvent, "x-nemo.messaging.sms"}, + {CommHistory::Event::MMSEvent, "x-nemo.messaging.mms"}, + {CommHistory::Event::CallEvent, "x-nemo.call.missed"}, + {CommHistory::Event::VoicemailEvent,"x-nemo.messaging.voicemail"}, + {VOICEMAIL_SMS_EVENT_TYPE, "x-nemo.messaging.voicemail-SMS"} +}; + +static const int _eventTypesCount = sizeof(_eventTypes) / sizeof(EventTypes); + +static QString groupType(int eventType) +{ + for (int i = 0; i < _eventTypesCount; i++) { + if (_eventTypes[i].type == eventType) + return QLatin1String(_eventTypes[i].event); + } + return QString(); +} + +static QString groupName(PersonalNotification::EventCollection collection) +{ + switch (collection) { + case PersonalNotification::Voicemail: + return txt_qtn_msg_voicemail_group; + + case PersonalNotification::Voice: + return txt_qtn_msg_missed_calls_group; + + case PersonalNotification::Messaging: + return txt_qtn_msg_notifications_group; + } + + return QString(); +} + + PersonalNotification::PersonalNotification(QObject* parent) : QObject(parent), m_eventType(CommHistory::Event::UnknownType), m_chatType(CommHistory::Group::ChatTypeP2P), m_hasPendingEvents(false), - m_hidden(false), - m_restored(false), m_notification(0) { } @@ -56,8 +97,6 @@ PersonalNotification::PersonalNotification(const QString& remoteUid, m_eventType(eventType), m_targetId(channelTargetId), m_chatType(chatType), m_notificationText(lastNotification), m_hasPendingEvents(true), - m_hidden(false), - m_restored(false), m_notification(0), m_recipient(account, remoteUid) { @@ -91,7 +130,6 @@ bool PersonalNotification::restore(Notification *n) m_notification = n; m_recipient = Recipient(account(), remoteUid()); - m_restored = true; connect(m_notification, SIGNAL(closed(uint)), SLOT(onClosed(uint))); return true; } @@ -122,38 +160,25 @@ void PersonalNotification::publishNotification() m_notification->setTimestamp(QDateTime::currentDateTimeUtc()); } - m_notification->setAppName(NotificationGroup::groupName(collection())); - m_notification->setCategory(NotificationGroup::groupType(m_eventType)); + m_notification->setAppName(groupName(collection())); + m_notification->setCategory(groupType(m_eventType)); m_notification->setHintValue("x-commhistoryd-data", serialized().toBase64()); - m_notification->setHintValue("x-nemo-hidden", m_hidden); m_notification->setSummary(name); m_notification->setBody(notificationText()); + m_notification->setIcon(m_recipient.contactAvatarUrl().toString()); NotificationManager::instance()->setNotificationProperties(m_notification, this, false); - // Show preview banner for notifications not previously reported - // (missed calls have no preview as the incoming call dialog was just shown) - if ((collection() != Voice) && !m_hidden && m_notification->replacesId() == 0) { - Notification preview; - - preview.setAppName(m_notification->appName()); - preview.setCategory(m_notification->category() + QStringLiteral(".preview")); - preview.setPreviewSummary(m_notification->summary()); - preview.setPreviewBody(m_notification->body()); - - NotificationManager::instance()->setNotificationProperties(&preview, this, false); - - preview.publish(); - - DEBUG() << preview.replacesId() << preview.category() << preview.previewSummary() << preview.previewBody(); + if (collection() == Voice) { + m_notification->clearPreviewSummary(); + m_notification->clearPreviewBody(); } m_notification->publish(); setHasPendingEvents(false); - m_restored = false; - DEBUG() << m_notification->replacesId() << m_notification->category() << m_notification->summary() << m_notification->body() << m_notification->hintValue("x-nemo-hidden"); + DEBUG() << m_notification->replacesId() << m_notification->category() << m_notification->summary() << m_notification->body(); } void PersonalNotification::removeNotification() @@ -268,12 +293,21 @@ QDateTime PersonalNotification::timestamp() const bool PersonalNotification::hidden() const { - return m_hidden; + // Deprecated but still needed for serialization compatibilty. + return false; } -bool PersonalNotification::restored() const +bool PersonalNotification::hasPhoneNumber() const { - return m_restored; + switch (m_eventType) { + case CommHistory::Event::SMSEvent: + case CommHistory::Event::MMSEvent: + case CommHistory::Event::CallEvent: + case VOICEMAIL_SMS_EVENT_TYPE: + return CommHistory::normalizePhoneNumber(m_remoteUid, true).length() > 0; + default: + return false; + } } void PersonalNotification::setRemoteUid(const QString& remoteUid) @@ -356,12 +390,9 @@ void PersonalNotification::setSmsReplaceNumber(const QString &number) } } -void PersonalNotification::setHidden(bool hide) +void PersonalNotification::setHidden(bool) { - if (m_hidden != hide) { - m_hidden = hide; - setHasPendingEvents(true); - } + // Deprecated but still needed for serialization compatibilty. } const Recipient &PersonalNotification::recipient() const @@ -389,11 +420,6 @@ QDataStream& operator>>(QDataStream &in, RTComLogger::PersonalNotification &key) { key.deSerialize(in, key); - // Hidden property is not in the serialization from earlier forms - if (!key.property("hidden").isValid()) { - key.setProperty("hidden", QVariant::fromValue(false)); - } - return in; } diff --git a/src/personalnotification.h b/src/personalnotification.h index 08ac8a6..01c16f6 100644 --- a/src/personalnotification.h +++ b/src/personalnotification.h @@ -115,7 +115,8 @@ class PersonalNotification : public QObject, public Serialisable QString smsReplaceNumber() const; QDateTime timestamp() const; bool hidden() const; - bool restored() const; + + bool hasPhoneNumber() const; void setRemoteUid(const QString& remoteUid); void setAccount(const QString& account); diff --git a/src/src.pro b/src/src.pro index 0c250fd..86cd38e 100644 --- a/src/src.pro +++ b/src/src.pro @@ -57,7 +57,6 @@ HEADERS += logger.h \ loggerclientobserver.h \ notificationmanager.h \ serialisable.h \ - notificationgroup.h \ personalnotification.h \ commhistoryifadaptor.h \ commhistoryservice.h \ @@ -86,7 +85,6 @@ SOURCES += main.cpp \ loggerclientobserver.cpp \ notificationmanager.cpp \ serialisable.cpp \ - notificationgroup.cpp \ personalnotification.cpp \ commhistoryifadaptor.cpp \ commhistoryservice.cpp \ diff --git a/src/textchannellistener.cpp b/src/textchannellistener.cpp index cfb0845..b9bd5c3 100644 --- a/src/textchannellistener.cpp +++ b/src/textchannellistener.cpp @@ -116,6 +116,8 @@ QTCONTACTS_USE_NAMESPACE QTVERSIT_USE_NAMESPACE namespace { +const QString ErrorCategory = "x-nemo.messaging.error"; +const QString StrongErrorCategory = "x-nemo.messaging.error.strong"; CommHistory::Event::PropertySet deliveryHandlingProperties = CommHistory::Event::PropertySet() << CommHistory::Event::Id @@ -197,6 +199,18 @@ QString subscriberIdentity(const Tp::MessagePart &header) return partValue(header, SUBSCRIBER_IDENTITY_HEADER_KEY); } +void showErrorNote(const QString &errorMsg, const QString &category = ErrorCategory) +{ + if (!errorMsg.isEmpty()) { + Notification notification; + notification.setAppName(txt_qtn_msg_errors_group); + notification.setCategory(category); + notification.setBody(errorMsg); + notification.setPreviewBody(errorMsg); + notification.publish(); + } +} + } // anonymous namespace QMultiHash TextChannelListener::m_pendingMessageIds; @@ -1120,18 +1134,6 @@ void TextChannelListener::handleMessageFailed(const Tp::ReceivedMessage &message } } -void TextChannelListener::showErrorNote(const QString &errorMsg, const QString &category) -{ - if (!errorMsg.isEmpty()) { - Notification notification; - notification.setAppName(txt_qtn_msg_errors_group); - notification.setCategory(category); - notification.setBody(errorMsg); - notification.setPreviewBody(errorMsg); - notification.publish(); - } -} - CommHistory::Event::EventType TextChannelListener::eventType() const { CommHistory::Event::EventType type = CommHistory::Event::UnknownType; diff --git a/src/textchannellistener.h b/src/textchannellistener.h index ccb121a..007a865 100644 --- a/src/textchannellistener.h +++ b/src/textchannellistener.h @@ -146,7 +146,6 @@ private Q_SLOTS: void handleMessageFailed(const Tp::ReceivedMessage &message, const CommHistory::Event &event); void sendGroupChatEvent(const QString &message); - void showErrorNote(const QString &errorMsg, const QString &category = ErrorCategory); void updateCurrentGroup(int start, int end, const QModelIndex &parent = QModelIndex()); // attempt to read original message from delivery report diff --git a/tests/ut_notificationmanager/ut_notificationmanager.cpp b/tests/ut_notificationmanager/ut_notificationmanager.cpp index a9946a0..813ab80 100644 --- a/tests/ut_notificationmanager/ut_notificationmanager.cpp +++ b/tests/ut_notificationmanager/ut_notificationmanager.cpp @@ -55,7 +55,7 @@ Ut_NotificationManager::~Ut_NotificationManager() void Ut_NotificationManager::initTestCase() { nm = NotificationManager::instance(); - nm->m_Groups.clear(); + nm->m_notifications.clear(); } /*! @@ -98,6 +98,7 @@ CommHistory::Event Ut_NotificationManager::createEvent(CommHistory::Event::Event event.setGroupId(1); } else if (type == CommHistory::Event::CallEvent) { event.setIsMissedCall(true); + event.setMessageToken(QString::number(eventId)); } event.setId(eventId); @@ -106,21 +107,13 @@ CommHistory::Event Ut_NotificationManager::createEvent(CommHistory::Event::Event PersonalNotification *Ut_NotificationManager::getNotification(const CommHistory::Event &event) { - NotificationManager::EventGroupProperties groupProperties(NotificationManager::eventGroup(PersonalNotification::collection(event.type()), event.recipients().value(0))); - NotificationGroup *group = nm->m_Groups.value(groupProperties); - foreach (PersonalNotification *pn, group->notifications()) { + foreach (PersonalNotification *pn, nm->m_notifications) { if (pn->eventToken() == event.messageToken()) return pn; } return 0; } -NotificationGroup *Ut_NotificationManager::getGroup(const CommHistory::Event &event) -{ - NotificationManager::EventGroupProperties groupProperties(NotificationManager::eventGroup(PersonalNotification::collection(event.type()), event.recipients().value(0))); - return nm->m_Groups.value(groupProperties); -} - void Ut_NotificationManager::testShowNotification() { CommHistory::Event event = createEvent(CommHistory::Event::IMEvent, CONTACT_1_REMOTE_ID); @@ -137,67 +130,62 @@ void Ut_NotificationManager::testShowNotification() Notification *n = pn->notification(); QTRY_VERIFY(n); QTRY_VERIFY(n->replacesId() > 0); - - NotificationGroup *group = getGroup(event); - Notification *groupNotification = group->notification(); - QVERIFY(groupNotification); - QVERIFY(groupNotification->replacesId() > 0); } void Ut_NotificationManager::groupNotifications() { - CommHistory::Event event = createEvent(CommHistory::Event::SMSEvent, "12345678", RING_ACCOUNT_PATH "account0"); + CommHistory::Event event = createEvent(CommHistory::Event::CallEvent, "12345678", RING_ACCOUNT_PATH "account0"); nm->showNotification(event, "12345678"); QTRY_COMPARE(nm->pendingEventCount(), 0); - NotificationGroup *group1 = getGroup(event); - QVERIFY(group1 != 0); - QCOMPARE(group1->contactNames(), QStringList() << QString("12345678")); + PersonalNotification *notification1 = getNotification(event); + QVERIFY(notification1 != 0); + QCOMPARE(notification1->notificationText(), txt_qtn_call_missed(1)); - event = createEvent(CommHistory::Event::SMSEvent, "23456789", RING_ACCOUNT_PATH "account0"); + event = createEvent(CommHistory::Event::CallEvent, "23456789", RING_ACCOUNT_PATH "account0"); nm->showNotification(event, "23456789"); QTRY_COMPARE(nm->pendingEventCount(), 0); - NotificationGroup *group2 = getGroup(event); - QVERIFY(group2 != 0); - QVERIFY(group2 != group1); - QCOMPARE(group2->contactNames(), QStringList() << QString("23456789")); + PersonalNotification *notification2 = getNotification(event); + QVERIFY(notification2 != 0); + QVERIFY(notification2 != notification1); + QCOMPARE(notification2->notificationText(), txt_qtn_call_missed(1)); - event = createEvent(CommHistory::Event::SMSEvent, "+0123456789", RING_ACCOUNT_PATH "account0"); + event = createEvent(CommHistory::Event::CallEvent, "+0123456789", RING_ACCOUNT_PATH "account0"); nm->showNotification(event, "+0123456789"); QTRY_COMPARE(nm->pendingEventCount(), 0); - NotificationGroup *group3 = getGroup(event); - QVERIFY(group3 != 0); - QCOMPARE(group3, group2); - QCOMPARE(group3->contactNames(), QStringList() << QString("+0123456789")); + PersonalNotification *notification3 = getNotification(event); + QVERIFY(notification3 != 0); + QCOMPARE(notification3, notification2); + QCOMPARE(notification3->notificationText(), txt_qtn_call_missed(2)); - event = createEvent(CommHistory::Event::SMSEvent, "23456789", RING_ACCOUNT_PATH "account1"); + event = createEvent(CommHistory::Event::CallEvent, "23456789", RING_ACCOUNT_PATH "account1"); nm->showNotification(event, "23456789"); QTRY_COMPARE(nm->pendingEventCount(), 0); - NotificationGroup *group4 = getGroup(event); - QVERIFY(group4 != 0); - QCOMPARE(group4, group2); - QCOMPARE(group4->contactNames(), QStringList() << QString("+0123456789")); + PersonalNotification *notification4 = getNotification(event); + QVERIFY(notification4 != 0); + QCOMPARE(notification4, notification2); + QCOMPARE(notification4->notificationText(), txt_qtn_call_missed(3)); - event = createEvent(CommHistory::Event::SMSEvent, "+1012345678", RING_ACCOUNT_PATH "account1"); + event = createEvent(CommHistory::Event::CallEvent, "+1012345678", RING_ACCOUNT_PATH "account1"); nm->showNotification(event, "+1012345678"); QTRY_COMPARE(nm->pendingEventCount(), 0); - NotificationGroup *group5 = getGroup(event); - QVERIFY(group5 != 0); - QCOMPARE(group5, group1); - QCOMPARE(group5->contactNames(), QStringList() << QString("+1012345678")); + PersonalNotification *notification5 = getNotification(event); + QVERIFY(notification5 != 0); + QCOMPARE(notification5, notification1); + QCOMPARE(notification5->notificationText(), txt_qtn_call_missed(2)); - event = createEvent(CommHistory::Event::SMSEvent, "012345678", RING_ACCOUNT_PATH "account1"); + event = createEvent(CommHistory::Event::CallEvent, "012345678", RING_ACCOUNT_PATH "account1"); nm->showNotification(event, "012345678"); QTRY_COMPARE(nm->pendingEventCount(), 0); - NotificationGroup *group6 = getGroup(event); - QVERIFY(group6 != 0); - QCOMPARE(group6, group1); - QCOMPARE(group6->contactNames(), QStringList() << QString("+1012345678")); + PersonalNotification *notification6 = getNotification(event); + QVERIFY(notification6 != 0); + QCOMPARE(notification6, notification1); + QCOMPARE(notification6->notificationText(), txt_qtn_call_missed(3)); } QTEST_MAIN(Ut_NotificationManager) diff --git a/tests/ut_notificationmanager/ut_notificationmanager.h b/tests/ut_notificationmanager/ut_notificationmanager.h index d7d97e5..e34621d 100644 --- a/tests/ut_notificationmanager/ut_notificationmanager.h +++ b/tests/ut_notificationmanager/ut_notificationmanager.h @@ -57,7 +57,6 @@ private Q_SLOTS: CommHistory::Event createEvent(CommHistory::Event::EventType type, const QString &remoteUid, const QString &localUid); PersonalNotification *getNotification(const CommHistory::Event &event); - NotificationGroup *getGroup(const CommHistory::Event &event); }; } diff --git a/tests/ut_notificationmanager/ut_notificationmanager.pro b/tests/ut_notificationmanager/ut_notificationmanager.pro index b457eed..45db1f5 100644 --- a/tests/ut_notificationmanager/ut_notificationmanager.pro +++ b/tests/ut_notificationmanager/ut_notificationmanager.pro @@ -37,12 +37,10 @@ TARGET = ut_notificationmanager PKGCONFIG += mlocale5 TelepathyQt5 ngf-qt5 nemonotifications-qt5 TEST_SOURCES += $$COMMHISTORYDSRCDIR/notificationmanager.cpp \ - $$COMMHISTORYDSRCDIR/notificationgroup.cpp \ $$COMMHISTORYDSRCDIR/personalnotification.cpp \ $$COMMHISTORYDSRCDIR/serialisable.cpp \ $$COMMHISTORYDSRCDIR/commhistoryservice.cpp TEST_HEADERS += $$COMMHISTORYDSRCDIR/notificationmanager.h \ - $$COMMHISTORYDSRCDIR/notificationgroup.h \ $$COMMHISTORYDSRCDIR/personalnotification.h \ $$COMMHISTORYDSRCDIR/serialisable.h \ $$COMMHISTORYDSRCDIR/commhistoryservice.h