Commit cb66d7d2 authored by Andrew den Exter's avatar Andrew den Exter

Merge branch 'jb50443' into 'master'

Remove uses of the deprecated x-nemo-hidden notification hint.

See merge request !39
parents 250c180e 6f4a98a0
This diff is collapsed.
/******************************************************************************
**
** 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 <john.brooks@jolla.com>
**
** 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 <QObject>
#include <QString>
#include <QMetaType>
#include <QTimer>
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<PersonalNotification*> 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 *&notification);
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<PersonalNotification*> mNotifications;
QTimer updateTimer;
friend class Ut_NotificationManager;
QStringList contactNames();
QString notificationGroupText();
int countConversations();
};
} // namespace
#endif // NOTIFICATIONGROUP_H
This diff is collapsed.
......@@ -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:
void syncNotifications();
int pendingEventCount();
void clearPendingEvents(const NotificationGroup &group);
void removeNotPendingEvents(const NotificationGroup &group);
bool isFilteredInbox();
QString filteredInboxAccountPath();
......@@ -178,9 +161,9 @@ private:
private:
static NotificationManager* m_pInstance;
QHash<EventGroupProperties, NotificationGroup*> m_Groups;
bool m_Initialised;
QList<PersonalNotification*> m_notifications;
QList<PersonalNotification*> m_unresolvedNotifications;
CommHistory::ContactResolver *m_contactResolver;
......@@ -198,15 +181,6 @@ private:
#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
......@@ -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,36 @@
using namespace RTComLogger;
using namespace CommHistory;
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 +79,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 +112,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,40 +142,24 @@ 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->clearPreviewSummary();
m_notification->clearPreviewBody();
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()
......@@ -270,12 +274,8 @@ QDateTime PersonalNotification::timestamp() const
bool PersonalNotification::hidden() const
{
return m_hidden;
}
bool PersonalNotification::restored() const
{
return m_restored;
// Deprecated but still needed for serialization compatibilty.
return false;
}
void PersonalNotification::setRemoteUid(const QString& remoteUid)
......@@ -358,12 +358,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
......@@ -391,11 +388,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;
}
......@@ -115,7 +115,6 @@ public:
QString smsReplaceNumber() const;
QDateTime timestamp() const;
bool hidden() const;
bool restored() const;
void setRemoteUid(const QString& remoteUid);
void setAccount(const QString& account);
......
......@@ -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 \
......
......@@ -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)
......@@ -57,7 +57,6 @@ private:
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);
};
}
......
......@@ -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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment