From 065dbafd753438b35bbb03f0f481e74b0b3a4d4a Mon Sep 17 00:00:00 2001 From: Janne Sakko Date: Fri, 17 Jun 2011 16:09:55 +0300 Subject: [PATCH] Fixes: NB#276863 - [TASK] Notifications timestamps and sorting in lock screen. RevBy: Vesa Halttunen Details: Introduces a new dbus API for adding, removing and updating notifications. Old dbus API for notifications is deprecated. --- .../genericnotificationparameterfactory.h | 17 ++ src/libnotificationsystem/notification.cpp | 1 - src/libnotificationsystem/notification.h | 1 - .../notificationgroup.cpp | 1 - .../dbusinterfacenotificationsource.cpp | 54 +++++ .../dbusinterfacenotificationsource.h | 135 ++++++++++-- .../notifications/mnotificationproxy.cpp | 64 +++++- .../notifications/mnotificationproxy.h | 55 +++++ .../notifications/notificationmanager.cpp | 16 +- .../notifications/notificationmanager.h | 10 + .../notifications/notificationmanager.xml | 55 ++++- .../notifications/notificationsource.cpp | 3 +- .../notifications/notificationsource.h | 2 +- .../ut_dbusinterfacenotificationsource.cpp | 199 +++++++++++++++++- .../ut_dbusinterfacenotificationsource.h | 15 ++ .../ut_notificationmanager.cpp | 126 +++++++++-- .../ut_notificationmanager.h | 8 + 17 files changed, 706 insertions(+), 56 deletions(-) diff --git a/src/libnotificationsystem/genericnotificationparameterfactory.h b/src/libnotificationsystem/genericnotificationparameterfactory.h index ed6fa59c..b8a5ec16 100644 --- a/src/libnotificationsystem/genericnotificationparameterfactory.h +++ b/src/libnotificationsystem/genericnotificationparameterfactory.h @@ -71,6 +71,13 @@ class GenericNotificationParameterFactory return QString("identifier"); } + /*! + * Returns keyname of the timestamp parameter + */ + static QString timestampKey() { + return QString("timestamp"); + } + /*! * Creates a NotificationParameter with the given event type. * @@ -130,6 +137,16 @@ class GenericNotificationParameterFactory static NotificationParameter createIdentifierParameter(const QString &identifier) { return NotificationParameter(identifierKey(), QVariant(identifier)); } + + /*! + * Creates a NotificationParameter with timestamp value + * + * \param timestamp timestamp parameter of notification + * \return the related NotificationParameter + */ + static NotificationParameter createTimestampParameter(uint timestamp) { + return NotificationParameter(timestampKey(), QVariant(timestamp)); + } }; #endif // GENERICNOTIFICATIONPARAMETERFACTORY_H diff --git a/src/libnotificationsystem/notification.cpp b/src/libnotificationsystem/notification.cpp index 87e76228..691f24f5 100644 --- a/src/libnotificationsystem/notification.cpp +++ b/src/libnotificationsystem/notification.cpp @@ -86,7 +86,6 @@ int Notification::timeout() const return timeout_; } - QDataStream &operator<<(QDataStream &datastream, const Notification ¬ification) { datastream << notification.notificationId_; diff --git a/src/libnotificationsystem/notification.h b/src/libnotificationsystem/notification.h index 70b17804..c283039e 100644 --- a/src/libnotificationsystem/notification.h +++ b/src/libnotificationsystem/notification.h @@ -123,7 +123,6 @@ class Notification */ int timeout() const; - friend QDataStream &operator<<(QDataStream &, const Notification &); friend QDataStream &operator>>(QDataStream &, Notification &); diff --git a/src/libnotificationsystem/notificationgroup.cpp b/src/libnotificationsystem/notificationgroup.cpp index 3b4da7b9..0517ff1d 100644 --- a/src/libnotificationsystem/notificationgroup.cpp +++ b/src/libnotificationsystem/notificationgroup.cpp @@ -65,7 +65,6 @@ void NotificationGroup::updateParameters(const NotificationParameters ¶meter parameters_.update(parameters); } - QDataStream &operator<<(QDataStream &datastream, const NotificationGroup ¬ificationGroup) { datastream << notificationGroup.groupId_; diff --git a/src/systemui/notifications/dbusinterfacenotificationsource.cpp b/src/systemui/notifications/dbusinterfacenotificationsource.cpp index 672327bf..819b3d04 100644 --- a/src/systemui/notifications/dbusinterfacenotificationsource.cpp +++ b/src/systemui/notifications/dbusinterfacenotificationsource.cpp @@ -20,6 +20,8 @@ #include "dbusinterfacenotificationsource.h" #include "dbusinterfacenotificationsourceadaptor.h" #include "mnotificationproxy.h" +#include "notificationwidgetparameterfactory.h" +#include "genericnotificationparameterfactory.h" Q_DECLARE_METATYPE(MNotificationProxy) Q_DECLARE_METATYPE(MNotificationWithIdentifierProxy) @@ -29,6 +31,11 @@ Q_DECLARE_METATYPE(QList) Q_DECLARE_METATYPE(QList) Q_DECLARE_METATYPE(QList) Q_DECLARE_METATYPE(QList) +Q_DECLARE_METATYPE(QList) +Q_DECLARE_METATYPE(MNotificationProxyWithParameters) +Q_DECLARE_METATYPE(QList) +Q_DECLARE_METATYPE(MNotificationGroupProxyWithParameters) +Q_DECLARE_METATYPE(QList) DBusInterfaceNotificationSource::DBusInterfaceNotificationSource(NotificationManagerInterface &interface) : NotificationSource(interface) @@ -46,6 +53,11 @@ DBusInterfaceNotificationSource::DBusInterfaceNotificationSource(NotificationMan qDBusRegisterMetaType >(); qDBusRegisterMetaType(); qDBusRegisterMetaType >(); + qDBusRegisterMetaType >(); + qDBusRegisterMetaType(); + qDBusRegisterMetaType >(); + qDBusRegisterMetaType(); + qDBusRegisterMetaType >(); new DBusInterfaceNotificationSourceAdaptor(this); } @@ -178,3 +190,45 @@ uint DBusInterfaceNotificationSource::notificationCountInGroup(uint notification { return manager.notificationCountInGroup(notificationUserId, groupId); } + +uint DBusInterfaceNotificationSource::addNotification(uint notificationUserId, uint groupId, const NotificationParameters ¶meters) +{ + return manager.addNotification(notificationUserId, parameters, groupId); +} + +bool DBusInterfaceNotificationSource::updateNotification(uint notificationUserId, uint notificationId, const NotificationParameters ¶meters) +{ + return manager.updateNotification(notificationUserId, notificationId, parameters); +} + +uint DBusInterfaceNotificationSource::addGroup(uint notificationUserId, const NotificationParameters ¶meters) +{ + return manager.addGroup(notificationUserId, parameters); +} + +bool DBusInterfaceNotificationSource::updateGroup(uint notificationUserId, uint groupId, const NotificationParameters ¶meters) +{ + return manager.updateGroup(notificationUserId, groupId, parameters); +} + +QList DBusInterfaceNotificationSource::notificationListWithNotificationParameters(uint notificationUserId) +{ + QList userNotifications; + + foreach (const Notification ¬ification, manager.notificationList(notificationUserId)) { + userNotifications.append(MNotificationProxyWithParameters(notification)); + } + + return userNotifications; +} + +QList DBusInterfaceNotificationSource::notificationGroupListWithNotificationParameters(uint notificationUserId) +{ + QList userGroups; + + foreach (const NotificationGroup &group, manager.notificationGroupList(notificationUserId)) { + userGroups.append(MNotificationGroupProxyWithParameters(group)); + } + + return userGroups; +} diff --git a/src/systemui/notifications/dbusinterfacenotificationsource.h b/src/systemui/notifications/dbusinterfacenotificationsource.h index 1b64bc92..7ea63842 100644 --- a/src/systemui/notifications/dbusinterfacenotificationsource.h +++ b/src/systemui/notifications/dbusinterfacenotificationsource.h @@ -66,8 +66,10 @@ class DBusInterfaceNotificationSource : public QObject, public NotificationSourc * \param groupId the ID of the notification group to put the notification in * \param eventType the event type of the notification * \return the ID of the new notification + * + * \deprecated This method is deprecated, you should use addNotification(NotificationParameters parameters) instead */ - uint addNotification(uint notificationUserId, uint groupId, const QString &eventType); + uint Q_DECL_DEPRECATED addNotification(uint notificationUserId, uint groupId, const QString &eventType); /*! * Adds a new notification. @@ -81,8 +83,10 @@ class DBusInterfaceNotificationSource : public QObject, public NotificationSourc * \param imageURI the ID of the icon to be used in the notification * \param count the number of items inside this notification * \return the ID of the new notification + * + * \deprecated This method is deprecated, you should use addNotification(NotificationParameters parameters) instead */ - uint addNotification(uint notificationUserId, uint groupId, const QString &eventType, const QString &summary, const QString &body, const QString &action, const QString &imageURI, uint count); + uint Q_DECL_DEPRECATED addNotification(uint notificationUserId, uint groupId, const QString &eventType, const QString &summary, const QString &body, const QString &action, const QString &imageURI, uint count); /*! * Adds a new notification. @@ -97,8 +101,10 @@ class DBusInterfaceNotificationSource : public QObject, public NotificationSourc * \param count the number of items inside this notification * \param identifier the user supplied identifier * \return the ID of the new notification + * + * \deprecated This method is deprecated, you should use addNotification(NotificationParameters parameters) instead */ - uint addNotification(uint notificationUserId, uint groupId, const QString &eventType, const QString &summary, const QString &body, const QString &action, const QString &imageURI, uint count, const QString &identifier); + uint Q_DECL_DEPRECATED addNotification(uint notificationUserId, uint groupId, const QString &eventType, const QString &summary, const QString &body, const QString &action, const QString &imageURI, uint count, const QString &identifier); /*! * Updates an existing notification. @@ -107,8 +113,10 @@ class DBusInterfaceNotificationSource : public QObject, public NotificationSourc * \param notificationId the ID of the notification to be updated * \param eventType the event type of the notification * \return true if the update succeeded, false otherwise + * + * \deprecated This method is deprecated, you should use updateNotification(NotificationParameters parameters) instead */ - bool updateNotification(uint notificationUserId, uint notificationId, const QString &eventType); + bool Q_DECL_DEPRECATED updateNotification(uint notificationUserId, uint notificationId, const QString &eventType); /*! * Updates an existing notification. @@ -122,8 +130,10 @@ class DBusInterfaceNotificationSource : public QObject, public NotificationSourc * \param imageURI the ID of the icon to be used in the notification * \param count the number of items inside this notification * \return true if the update succeeded, false otherwise + * + * \deprecated This method is deprecated, you should use updateNotification(NotificationParameters parameters) instead */ - bool updateNotification(uint notificationUserId, uint notificationId, const QString &eventType, const QString &summary, const QString &body, const QString &action, const QString &imageURI, uint count); + bool Q_DECL_DEPRECATED updateNotification(uint notificationUserId, uint notificationId, const QString &eventType, const QString &summary, const QString &body, const QString &action, const QString &imageURI, uint count); /*! * Updates an existing notification. @@ -138,8 +148,10 @@ class DBusInterfaceNotificationSource : public QObject, public NotificationSourc * \param count the number of items inside this notification * \param identifier the user supplied identifier * \return true if the update succeeded, false otherwise + * + * \deprecated This method is deprecated, you should use updateNotification(NotificationParameters parameters) instead */ - bool updateNotification(uint notificationUserId, uint notificationId, const QString &eventType, const QString &summary, const QString &body, const QString &action, const QString &imageURI, uint count, const QString &identifier); + bool Q_DECL_DEPRECATED updateNotification(uint notificationUserId, uint notificationId, const QString &eventType, const QString &summary, const QString &body, const QString &action, const QString &imageURI, uint count, const QString &identifier); /*! * Removes a notification. @@ -156,8 +168,10 @@ class DBusInterfaceNotificationSource : public QObject, public NotificationSourc * \param notificationUserId the ID of the user of notifications * \param eventType the event type of the notification * \return the ID of the new notification group + * + * \deprecated This method is deprecated, you should use addGroup(NotificationParameters parameters) instead */ - uint addGroup(uint notificationUserId, const QString &eventType); + uint Q_DECL_DEPRECATED addGroup(uint notificationUserId, const QString &eventType); /*! * Adds a new notification group. @@ -170,8 +184,10 @@ class DBusInterfaceNotificationSource : public QObject, public NotificationSourc * \param imageURI the ID of the icon to be used in the notification * \param count the number of items inside this group * \return the ID of the new notification group + * + * \deprecated This method is deprecated, you should use addGroup(NotificationParameters parameters) instead */ - uint addGroup(uint notificationUserId, const QString &eventType, const QString &summary, const QString &body, const QString &action, const QString &imageURI, uint count); + uint Q_DECL_DEPRECATED addGroup(uint notificationUserId, const QString &eventType, const QString &summary, const QString &body, const QString &action, const QString &imageURI, uint count); /*! * Adds a new notification group. @@ -185,8 +201,10 @@ class DBusInterfaceNotificationSource : public QObject, public NotificationSourc * \param count the number of items inside this group * \param identifier the user supplied identifier * \return the ID of the new notification group + * + * \deprecated This method is deprecated, you should use addGroup(NotificationParameters parameters) instead */ - uint addGroup(uint notificationUserId, const QString &eventType, const QString &summary, const QString &body, const QString &action, const QString &imageURI, uint count, const QString &identifier); + uint Q_DECL_DEPRECATED addGroup(uint notificationUserId, const QString &eventType, const QString &summary, const QString &body, const QString &action, const QString &imageURI, uint count, const QString &identifier); /*! * Updates an existing notification group. @@ -195,8 +213,10 @@ class DBusInterfaceNotificationSource : public QObject, public NotificationSourc * \param groupId the ID of the notification group to be updated * \param eventType the event type of the notification * \return true if the update succeeded, false otherwise + * + * \deprecated This method is deprecated, you should use updateGroup(NotificationParameters parameters) instead */ - bool updateGroup(uint notificationUserId, uint groupId, const QString &eventType); + bool Q_DECL_DEPRECATED updateGroup(uint notificationUserId, uint groupId, const QString &eventType); /*! * Updates an existing notification group. @@ -210,8 +230,10 @@ class DBusInterfaceNotificationSource : public QObject, public NotificationSourc * \param imageURI the ID of the icon to be used in the notification * \param count the number of items inside this group * \return true if the update succeeded, false otherwise + * + * \deprecated This method is deprecated, you should use updateGroup(NotificationParameters parameters) instead */ - bool updateGroup(uint notificationUserId, uint groupId, const QString &eventType, const QString &summary, const QString &body, const QString &action, const QString &imageURI, uint count); + bool Q_DECL_DEPRECATED updateGroup(uint notificationUserId, uint groupId, const QString &eventType, const QString &summary, const QString &body, const QString &action, const QString &imageURI, uint count); /*! * Updates an existing notification group. @@ -226,8 +248,10 @@ class DBusInterfaceNotificationSource : public QObject, public NotificationSourc * \param count the number of items inside this group * \param identifier the user supplied identifier * \return true if the update succeeded, false otherwise + * + * \deprecated This method is deprecated, you should use updateGroup(NotificationParameters parameters) instead */ - bool updateGroup(uint notificationUserId, uint groupId, const QString &eventType, const QString &summary, const QString &body, const QString &action, const QString &imageURI, uint count, const QString &identifier); + bool Q_DECL_DEPRECATED updateGroup(uint notificationUserId, uint groupId, const QString &eventType, const QString &summary, const QString &body, const QString &action, const QString &imageURI, uint count, const QString &identifier); /*! * Removes a notification group and all notifications in the group. @@ -251,32 +275,40 @@ class DBusInterfaceNotificationSource : public QObject, public NotificationSourc * * \param notificationUserId the ID of the user of notifications * \return list of notifications that belong to notificationUserId + * + * \deprecated This method is deprecated, you should use notificationListWithNotificationParameters(uint notificationUserId) instead */ - QList notificationList(uint notificationUserId); + QList Q_DECL_DEPRECATED notificationList(uint notificationUserId); /*! * Returns list of notifications with associated identifiers by user id * * \param notificationUserId the ID of the user of notifications * \return list of notifications with associated identifiers that belong to notificationUserId + * + * \deprecated This method is deprecated, you should use notificationListWithNotificationParameters(uint notificationUserId) instead */ - QList notificationListWithIdentifiers(uint notificationUserId); + QList Q_DECL_DEPRECATED notificationListWithIdentifiers(uint notificationUserId); /*! * Returns list of notification groups by user id * * \param notificationUserId the ID of the user of notifications * \return list of notification groups that belong to notificationUserId + * + * \deprecated This method is deprecated, you should use notificationGroupListAsNotificationParameters(uint notificationUserId) instead */ - QList notificationGroupList(uint notificationUserId); + QList Q_DECL_DEPRECATED notificationGroupList(uint notificationUserId); /*! * Returns list of notification groups with associated identifiers by user id * * \param notificationUserId the ID of the user of notifications * \return list of notification groups with associated identifiers that belong to notificationUserId + * + * \deprecated This method is deprecated, you should use notificationGroupListAsNotificationParameters(uint notificationUserId) instead */ - QList notificationGroupListWithIdentifiers(uint notificationUserId); + QList Q_DECL_DEPRECATED notificationGroupListWithIdentifiers(uint notificationUserId); /*! * Returns amount of notifications in a given group @@ -286,6 +318,77 @@ class DBusInterfaceNotificationSource : public QObject, public NotificationSourc * \return amount of notifications in given group */ uint notificationCountInGroup(uint notificationUserId, uint groupId); + + /*! + * Adds a new notification. + * + * Notification is created with NotificationParametes, a hash of key-value pairs + * that represents the information the notification holds. + * + * Notification can be added to group if groupId key is supplied. + * + * \param notificationUserId the ID of the user of notifications + * \param groupId the group ID + * \param parameters hash of key-value pairs that's used to create notification + * \return the ID of the new notification + */ + uint addNotification(uint notificationUserId, uint groupId, const NotificationParameters ¶meters); + + /*! + * Updates an existing notification. + * + * Notification is updated with NotificationParameters. + * Keys that are specified are replaced and others are not changed. + * Except of timestamp key that is changed to set to system's current time if not specified. + * + * \param notificationUserId the ID of the user of notifications + * \param notificationId the ID of the notification to be updated + * \param parameters a hash of key-value pairs that's used to update notification + * \return true if the update succeeded, false otherwise + */ + bool updateNotification(uint notificationUserId, uint notificationId, const NotificationParameters ¶meters); + + /*! + * Adds a new notification group. + * + * NotificationGroup is created with NotificationParametes, a hash of key-value pairs + * that represents the information the notification group holds. + * + * \param notificationUserId the ID of the user of notifications + * \param parameters a hash of key-value pairs that's used to create notification group + * \return the ID of the new notification group + */ + uint addGroup(uint notificationUserId, const NotificationParameters ¶meters); + + /*! + * Updates an existing notification group. + * + * NotificationGorup is updated with NotificationParameters. + * Keys that are specified are replaced and others are not changed. + * Except of timestamp key that is changed to set to system's current time if not specified. + * + * \param notificationUserId the ID of the user of notifications + * \param groupId the group ID + * \param parameters a hash of key-value pairts that's used to update group + * \return true if the update succeeded, false otherwise + */ + bool updateGroup(uint notificationUserId, uint groupId, const NotificationParameters ¶meters); + + /*! + * Returns list of notifications by user id + * + * \param notificationUserId the ID of the user of notifications + * \return list of notifications as that belong to notificationUserId + */ + QList notificationListWithNotificationParameters(uint notificationUserId); + + /*! + * Returns list of notification groups by user id + * + * \param notificationUserId the ID of the user of notifications + * \return list of notification groups that belong to notificationUserId + */ + QList notificationGroupListWithNotificationParameters(uint notificationUserId); }; #endif // DBUSINTERFACENOTIFICATIONSOURCE_H diff --git a/src/systemui/notifications/mnotificationproxy.cpp b/src/systemui/notifications/mnotificationproxy.cpp index f84ea1b5..11ccb59f 100644 --- a/src/systemui/notifications/mnotificationproxy.cpp +++ b/src/systemui/notifications/mnotificationproxy.cpp @@ -16,7 +16,6 @@ ** of this file. ** ****************************************************************************/ - #include #include "notification.h" @@ -256,3 +255,66 @@ const QDBusArgument &operator>>(const QDBusArgument &argument, MNotificationGrou return argument; } + +MNotificationProxyWithParameters::MNotificationProxyWithParameters() +: notificationId(0), + groupId(0), + parameters(NotificationParameters()) +{ +} + +MNotificationProxyWithParameters::MNotificationProxyWithParameters(const Notification ¬ification) +{ + notificationId = notification.notificationId(); + groupId = notification.groupId(); + parameters = notification.parameters(); +} + +QDBusArgument &operator<<(QDBusArgument &argument, const MNotificationProxyWithParameters ¬ification) +{ + argument.beginStructure(); + argument << notification.notificationId; + argument << notification.groupId; + argument << notification.parameters; + argument.endStructure(); + return argument; +} + +const QDBusArgument &operator>>(const QDBusArgument &argument, MNotificationProxyWithParameters ¬ification) +{ + argument.beginStructure(); + argument >> notification.notificationId; + argument >> notification.groupId; + argument >> notification.parameters; + argument.endStructure(); + return argument; +} +MNotificationGroupProxyWithParameters::MNotificationGroupProxyWithParameters() +: groupId(0), + parameters(NotificationParameters()) +{ +} + +MNotificationGroupProxyWithParameters::MNotificationGroupProxyWithParameters(const NotificationGroup &group) +{ + groupId = group.groupId(); + parameters = group.parameters(); +} + +QDBusArgument &operator<<(QDBusArgument &argument, const MNotificationGroupProxyWithParameters &group) +{ + argument.beginStructure(); + argument << group.groupId; + argument << group.parameters; + argument.endStructure(); + return argument; +} + +const QDBusArgument &operator>>(const QDBusArgument &argument, MNotificationGroupProxyWithParameters &group) +{ + argument.beginStructure(); + argument >> group.groupId; + argument >> group.parameters; + argument.endStructure(); + return argument; +} diff --git a/src/systemui/notifications/mnotificationproxy.h b/src/systemui/notifications/mnotificationproxy.h index e8f860a4..e27a824d 100644 --- a/src/systemui/notifications/mnotificationproxy.h +++ b/src/systemui/notifications/mnotificationproxy.h @@ -176,4 +176,59 @@ class MNotificationGroupWithIdentifierProxy : public MNotificationGroupProxy QDBusArgument &operator<<(QDBusArgument &, const MNotificationGroupWithIdentifierProxy &); const QDBusArgument &operator>>(const QDBusArgument &, MNotificationGroupWithIdentifierProxy &); +/*! + * \brief A proxy class for serializing Notification as MNotification + */ +class MNotificationProxyWithParameters +{ +public: + /*! + * Empty constructor. Initializes the values to defaults. + */ + MNotificationProxyWithParameters(); + + /*! + * Constructor. + * + * \param notification A Notification object to initialize the data from + */ + MNotificationProxyWithParameters(const Notification ¬ification); + + // The id of the notification + uint notificationId; + // The group id of notification. + uint groupId; + // Parameters of notification. + NotificationParameters parameters; +}; + +QDBusArgument &operator<<(QDBusArgument &, const MNotificationProxyWithParameters &); +const QDBusArgument &operator>>(const QDBusArgument &, MNotificationProxyWithParameters &); + +/*! + * \brief A proxy class for serializing NotificationGorup as MNotificationGroup + */ +class MNotificationGroupProxyWithParameters +{ +public: + /*! + * Empty constructor. Initializes the values to defaults. + */ + MNotificationGroupProxyWithParameters(); + + /*! + * Constructor. + * + * \param notification A Notification object to initialize the data from + */ + MNotificationGroupProxyWithParameters(const NotificationGroup ¬ification); + + // Id of the group + uint groupId; + // Parameters of group. + NotificationParameters parameters; +}; + +QDBusArgument &operator<<(QDBusArgument &, const MNotificationGroupProxyWithParameters &); +const QDBusArgument &operator>>(const QDBusArgument &, MNotificationGroupProxyWithParameters &); #endif diff --git a/src/systemui/notifications/notificationmanager.cpp b/src/systemui/notifications/notificationmanager.cpp index 05269610..d559cfa2 100644 --- a/src/systemui/notifications/notificationmanager.cpp +++ b/src/systemui/notifications/notificationmanager.cpp @@ -270,7 +270,7 @@ uint NotificationManager::addNotification(uint notificationUserId, const Notific uint notificationId = nextAvailableNotificationID(); NotificationParameters fullParameters(appendEventTypeParameters(parameters)); - fullParameters.add("timestamp", QDateTime::currentDateTimeUtc().toTime_t()); + fullParameters.add(GenericNotificationParameterFactory::timestampKey(), timestamp(parameters)); Notification::NotificationType notificationType = determineType(fullParameters); if (notificationType == Notification::SystemEvent) { // Consider all system notifications not to be persistent @@ -299,7 +299,7 @@ bool NotificationManager::updateNotification(uint notificationUserId, uint notif if (ni != notificationContainer.end()) { NotificationParameters fullParameters(parameters); - fullParameters.add("timestamp", QDateTime::currentDateTimeUtc().toTime_t()); + fullParameters.add(GenericNotificationParameterFactory::timestampKey(), timestamp(parameters)); (*ni).updateParameters(fullParameters); saveNotifications(); @@ -379,7 +379,7 @@ bool NotificationManager::removeNotificationsInGroup(uint groupId) uint NotificationManager::addGroup(uint notificationUserId, const NotificationParameters ¶meters) { NotificationParameters fullParameters(appendEventTypeParameters(parameters)); - fullParameters.add("timestamp", QDateTime::currentDateTimeUtc().toTime_t()); + fullParameters.add(GenericNotificationParameterFactory::timestampKey(), timestamp(parameters)); uint groupID = nextAvailableGroupID(); NotificationGroup group(groupID, notificationUserId, fullParameters); @@ -400,8 +400,7 @@ bool NotificationManager::updateGroup(uint notificationUserId, uint groupId, con if (gi != groupContainer.end()) { NotificationParameters fullParameters(parameters); - fullParameters.add("timestamp", QDateTime::currentDateTimeUtc().toTime_t()); - + fullParameters.add(GenericNotificationParameterFactory::timestampKey(), timestamp(parameters)); gi->updateParameters(fullParameters); saveStateData(); @@ -667,3 +666,10 @@ bool NotificationManager::isPersistent(const NotificationParameters ¶meters) return isPersistent; } + +uint NotificationManager::timestamp(const NotificationParameters ¶meters) +{ + uint timestamp = parameters.value(GenericNotificationParameterFactory::timestampKey()).toUInt(); + return timestamp == 0 ? QDateTime::currentDateTimeUtc().toTime_t() : timestamp; +} + diff --git a/src/systemui/notifications/notificationmanager.h b/src/systemui/notifications/notificationmanager.h index bf15c55a..3c5e6309 100644 --- a/src/systemui/notifications/notificationmanager.h +++ b/src/systemui/notifications/notificationmanager.h @@ -295,6 +295,16 @@ private slots: */ bool isPersistent(const NotificationParameters ¶meters); + /*! + * Extracts timestamp information of notification from the notification parameters. + * If there is not timestamp information or timestamp is 0 current local time is + * used as a timestamp + * + * \param parameters NotificationParameters + * \return timestamp in UNIX time + */ + uint timestamp(const NotificationParameters ¶meters); + //! Hash of all notifications keyed by notification IDs QHash notificationContainer; diff --git a/src/systemui/notifications/notificationmanager.xml b/src/systemui/notifications/notificationmanager.xml index cf023b4b..5f0cada9 100644 --- a/src/systemui/notifications/notificationmanager.xml +++ b/src/systemui/notifications/notificationmanager.xml @@ -8,6 +8,7 @@ + @@ -18,6 +19,7 @@ + @@ -29,12 +31,14 @@ + + @@ -46,6 +50,7 @@ + @@ -58,6 +63,7 @@ + @@ -69,6 +75,7 @@ + @@ -80,6 +87,7 @@ + @@ -92,12 +100,14 @@ + + @@ -109,6 +119,7 @@ + @@ -121,6 +132,7 @@ + @@ -136,26 +148,67 @@ + + + + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/systemui/notifications/notificationsource.cpp b/src/systemui/notifications/notificationsource.cpp index e193ccbc..0bf0f6b1 100644 --- a/src/systemui/notifications/notificationsource.cpp +++ b/src/systemui/notifications/notificationsource.cpp @@ -26,7 +26,7 @@ NotificationSource::NotificationSource(NotificationManagerInterface &m) { } -NotificationParameters NotificationSource::notificationParameters(const QString &eventType, const QString &summary, const QString &body, const QString &action, const QString &imageURI, uint count, const QString &identifier) +NotificationParameters NotificationSource::notificationParameters(const QString &eventType, const QString &summary, const QString &body, const QString &action, const QString &imageURI, uint count, const QString &identifier, uint timestamp) { NotificationParameters parameters; parameters.add(GenericNotificationParameterFactory::createEventTypeParameter(eventType)); @@ -47,6 +47,7 @@ NotificationParameters NotificationSource::notificationParameters(const QString if (!identifier.isEmpty()) { parameters.add(GenericNotificationParameterFactory::createIdentifierParameter(identifier)); } + parameters.add(GenericNotificationParameterFactory::createTimestampParameter(timestamp)); return parameters; } diff --git a/src/systemui/notifications/notificationsource.h b/src/systemui/notifications/notificationsource.h index c5be84e5..dca74b6f 100644 --- a/src/systemui/notifications/notificationsource.h +++ b/src/systemui/notifications/notificationsource.h @@ -39,7 +39,7 @@ class NotificationSource NotificationSource(NotificationManagerInterface &manager); //! Creates NotificationParameters from a set of simple API parameters - NotificationParameters notificationParameters(const QString &eventType, const QString &summary = QString(), const QString &body = QString(), const QString &action = QString(), const QString &imageURI = QString(), uint count = 1, const QString &identifier = QString()); + NotificationParameters notificationParameters(const QString &eventType, const QString &summary = QString(), const QString &body = QString(), const QString &action = QString(), const QString &imageURI = QString(), uint count = 1, const QString &identifier = QString(), uint timestamp = 0); protected: //! NotificationManagerInterface object used with this NotificationSource diff --git a/tests/ut_dbusinterfacenotificationsource/ut_dbusinterfacenotificationsource.cpp b/tests/ut_dbusinterfacenotificationsource/ut_dbusinterfacenotificationsource.cpp index 004bcb49..3272294c 100644 --- a/tests/ut_dbusinterfacenotificationsource/ut_dbusinterfacenotificationsource.cpp +++ b/tests/ut_dbusinterfacenotificationsource/ut_dbusinterfacenotificationsource.cpp @@ -144,6 +144,38 @@ QList DBusInterfaceNotificationSourceAdap return l; } + +uint DBusInterfaceNotificationSourceAdaptor::addGroup(uint, NotificationParameters) +{ + return 1; +} +uint DBusInterfaceNotificationSourceAdaptor::addNotification(uint, uint, NotificationParameters) +{ + return 1; +} + +bool DBusInterfaceNotificationSourceAdaptor::updateGroup(uint, uint, NotificationParameters) +{ + return true; +} + +bool DBusInterfaceNotificationSourceAdaptor::updateNotification(uint, uint, NotificationParameters) +{ + return true; +} + +QList < MNotificationProxyWithParameters > DBusInterfaceNotificationSourceAdaptor::notificationListWithNotificationParameters(uint notificationUserId) +{ + Q_UNUSED(notificationUserId); + return QList(); +} + +QList < MNotificationGroupProxyWithParameters> DBusInterfaceNotificationSourceAdaptor::notificationGroupListWithNotificationParameters(uint notificationUserId) +{ + Q_UNUSED(notificationUserId); + return QList(); +} + void Ut_DBusInterfaceNotificationSource::initTestCase() { } @@ -186,6 +218,8 @@ const bool CALL_TO_NOTIFICATION_MANAGER_DOES_NOT_SUCCEED = false; const uint NEW_NOTIFICATION_ID = 9; const uint NEW_GROUP_ID = 11; +const uint TIMESTAMP = 123456789; + void Ut_DBusInterfaceNotificationSource::testAddNotification() { source->addNotification(1, 2, "event"); @@ -205,7 +239,7 @@ void Ut_DBusInterfaceNotificationSource::testAddNotification() QCOMPARE(params.value(NotificationWidgetParameterFactory::imageIdKey()), QVariant("imageURI")); QCOMPARE(params.value(NotificationWidgetParameterFactory::actionKey()), QVariant("action")); - source->addNotification(5, 6, "event", "summary", "body", "action", "imageURI", 42); + source->addNotification(5, 6, "event", "summary", "body", "action", "imageURI", 42, 0); QCOMPARE(gDefaultNotificationManagerStub.stubLastCallTo("addNotification").parameter(0), (uint)5); QCOMPARE(gDefaultNotificationManagerStub.stubLastCallTo("addNotification").parameter(2), (uint)6); params = gDefaultNotificationManagerStub.stubLastCallTo("addNotification").parameter(1); @@ -248,7 +282,7 @@ void Ut_DBusInterfaceNotificationSource::testUpdateNotificationWithIdentifier() gDefaultNotificationManagerStub.stubSetReturnValue("addNotification", NEW_NOTIFICATION_ID); gDefaultNotificationManagerStub.stubSetReturnValue("updateNotification", CALL_TO_NOTIFICATION_MANAGER_SUCCEEDS); - uint id = source->addNotification(USER_ID, NOTIFICATION_GROUP_ID1, EVENT, SUMMARY, BODY, ACTION, IMAGE, COUNT); + uint id = source->addNotification(USER_ID, NOTIFICATION_GROUP_ID1, EVENT, SUMMARY, BODY, ACTION, IMAGE, COUNT, 0); QCOMPARE(source->updateNotification(USER_ID, id, EVENT, SUMMARY, BODY, ACTION, IMAGE, COUNT, IDENTIFIER), CALL_TO_NOTIFICATION_MANAGER_SUCCEEDS); NotificationParameters params = gDefaultNotificationManagerStub.stubLastCallTo("updateNotification").parameter(2); @@ -322,7 +356,7 @@ void Ut_DBusInterfaceNotificationSource::testUpdateGroupWithIdentifier() gDefaultNotificationManagerStub.stubSetReturnValue("addGroup", NEW_GROUP_ID); gDefaultNotificationManagerStub.stubSetReturnValue("updateGroup", CALL_TO_NOTIFICATION_MANAGER_SUCCEEDS); - uint id = source->addGroup(USER_ID, EVENT, SUMMARY, BODY, ACTION, IMAGE, COUNT); + uint id = source->addGroup(USER_ID, EVENT, SUMMARY, BODY, ACTION, IMAGE, COUNT, 0); QCOMPARE(source->updateGroup(USER_ID, id, EVENT, SUMMARY, BODY, ACTION, IMAGE, COUNT, IDENTIFIER), CALL_TO_NOTIFICATION_MANAGER_SUCCEEDS); NotificationParameters params = gDefaultNotificationManagerStub.stubLastCallTo("updateGroup").parameter(2); @@ -449,11 +483,11 @@ void Ut_DBusInterfaceNotificationSource::testNotificationGroupListWithIdentifier void Ut_DBusInterfaceNotificationSource::testUpdateGroupWithEmptyStrings() { - source->updateGroup(3, 4, "event", "summary", "body", "action", "imageURI", 42); + source->updateGroup(3, 4, "event", "summary", "body", "action", "imageURI", 42, 0); NotificationParameters params = gDefaultNotificationManagerStub.stubLastCallTo("updateGroup").parameter(2); QCOMPARE(params.value(NotificationWidgetParameterFactory::summaryKey()), QVariant("summary")); - source->updateGroup(3, 4, "event", "", "", "", "", 42); + source->updateGroup(3, 4, "event", "", "", "", "", 42, 0); params = gDefaultNotificationManagerStub.stubLastCallTo("updateGroup").parameter(2); QCOMPARE(params.value(GenericNotificationParameterFactory::eventTypeKey()), QVariant("event")); QCOMPARE(params.value(GenericNotificationParameterFactory::countKey()), QVariant("42")); @@ -469,4 +503,159 @@ void Ut_DBusInterfaceNotificationSource::testNotificationCountInGroup() QCOMPARE(gDefaultNotificationManagerStub.stubCallCount("notificationCountInGroup"), 1); } +NotificationParameters createDefaultNotificationParameters() +{ + NotificationParameters parameters; + parameters.add(GenericNotificationParameterFactory::createEventTypeParameter(EVENT)); + parameters.add(NotificationWidgetParameterFactory::createSummaryParameter(SUMMARY)); + parameters.add(NotificationWidgetParameterFactory::createBodyParameter(BODY)); + parameters.add(NotificationWidgetParameterFactory::createActionParameter(ACTION)); + parameters.add(NotificationWidgetParameterFactory::createImageIdParameter(IMAGE)); + parameters.add(GenericNotificationParameterFactory::createCountParameter(COUNT)); + parameters.add(GenericNotificationParameterFactory::createIdentifierParameter(IDENTIFIER)); + parameters.add(GenericNotificationParameterFactory::createTimestampParameter(TIMESTAMP)); + return parameters; +} + +void Ut_DBusInterfaceNotificationSource::testAddNotificationWithNotificationParameters() +{ + source->addNotification(USER_ID, NOTIFICATION_GROUP_ID1, createDefaultNotificationParameters()); + + QCOMPARE(gDefaultNotificationManagerStub.stubLastCallTo("addNotification").parameter(0), USER_ID); + NotificationParameters parametersGivenToManager = gDefaultNotificationManagerStub.stubLastCallTo("addNotification").parameter(1); + + QCOMPARE(parametersGivenToManager.value(GenericNotificationParameterFactory::eventTypeKey()).toString(), EVENT); + QCOMPARE(parametersGivenToManager.value(NotificationWidgetParameterFactory::summaryKey()).toString(), SUMMARY); + QCOMPARE(parametersGivenToManager.value(NotificationWidgetParameterFactory::bodyKey()).toString(), BODY); + QCOMPARE(parametersGivenToManager.value(NotificationWidgetParameterFactory::actionKey()).toString(), ACTION); + QCOMPARE(parametersGivenToManager.value(NotificationWidgetParameterFactory::imageIdKey()).toString(), IMAGE); + QCOMPARE(parametersGivenToManager.value(GenericNotificationParameterFactory::countKey()).toUInt(), COUNT); + QCOMPARE(parametersGivenToManager.value(GenericNotificationParameterFactory::identifierKey()).toString(), IDENTIFIER); + QCOMPARE(parametersGivenToManager.value(GenericNotificationParameterFactory::timestampKey()).toUInt(), TIMESTAMP); + QCOMPARE(gDefaultNotificationManagerStub.stubLastCallTo("addNotification").parameter(2), NOTIFICATION_GROUP_ID1); +} + +void Ut_DBusInterfaceNotificationSource::testUpdateNotificationWithNotificationParameters() +{ + source->updateNotification(USER_ID, NOTIFICATION_ID1, createDefaultNotificationParameters()); + + QCOMPARE(gDefaultNotificationManagerStub.stubLastCallTo("updateNotification").parameter(0), USER_ID); + QCOMPARE(gDefaultNotificationManagerStub.stubLastCallTo("updateNotification").parameter(1), NOTIFICATION_ID1); + + NotificationParameters parametersGivenToManager = gDefaultNotificationManagerStub.stubLastCallTo("updateNotification").parameter(2); + + QCOMPARE(parametersGivenToManager.value(GenericNotificationParameterFactory::eventTypeKey()).toString(), EVENT); + QCOMPARE(parametersGivenToManager.value(NotificationWidgetParameterFactory::summaryKey()).toString(), SUMMARY); + QCOMPARE(parametersGivenToManager.value(NotificationWidgetParameterFactory::bodyKey()).toString(), BODY); + QCOMPARE(parametersGivenToManager.value(NotificationWidgetParameterFactory::actionKey()).toString(), ACTION); + QCOMPARE(parametersGivenToManager.value(NotificationWidgetParameterFactory::imageIdKey()).toString(), IMAGE); + QCOMPARE(parametersGivenToManager.value(GenericNotificationParameterFactory::countKey()).toUInt(), COUNT); + QCOMPARE(parametersGivenToManager.value(GenericNotificationParameterFactory::identifierKey()).toString(), IDENTIFIER); + QCOMPARE(parametersGivenToManager.value(GenericNotificationParameterFactory::timestampKey()).toUInt(), TIMESTAMP); +} + +void Ut_DBusInterfaceNotificationSource::testRemoveNotificationWithNotificationParameters() +{ + source->removeNotification(USER_ID, NOTIFICATION_ID1); + QCOMPARE(gDefaultNotificationManagerStub.stubLastCallTo("removeNotification").parameter(0), USER_ID); + QCOMPARE(gDefaultNotificationManagerStub.stubLastCallTo("removeNotification").parameter(1), NOTIFICATION_ID1); +} + +void Ut_DBusInterfaceNotificationSource::testAddGroupWithNotificationParameters() +{ + source->addGroup(USER_ID, createDefaultNotificationParameters()); + + QCOMPARE(gDefaultNotificationManagerStub.stubLastCallTo("addGroup").parameter(0), USER_ID); + + NotificationParameters parametersGivenToManager = gDefaultNotificationManagerStub.stubLastCallTo("addGroup").parameter(1); + + QCOMPARE(parametersGivenToManager.value(GenericNotificationParameterFactory::eventTypeKey()).toString(), EVENT); + QCOMPARE(parametersGivenToManager.value(NotificationWidgetParameterFactory::summaryKey()).toString(), SUMMARY); + QCOMPARE(parametersGivenToManager.value(NotificationWidgetParameterFactory::bodyKey()).toString(), BODY); + QCOMPARE(parametersGivenToManager.value(NotificationWidgetParameterFactory::actionKey()).toString(), ACTION); + QCOMPARE(parametersGivenToManager.value(NotificationWidgetParameterFactory::imageIdKey()).toString(), IMAGE); + QCOMPARE(parametersGivenToManager.value(GenericNotificationParameterFactory::countKey()).toUInt(), COUNT); + QCOMPARE(parametersGivenToManager.value(GenericNotificationParameterFactory::identifierKey()).toString(), IDENTIFIER); + QCOMPARE(parametersGivenToManager.value(GenericNotificationParameterFactory::timestampKey()).toUInt(), TIMESTAMP); +} + +void Ut_DBusInterfaceNotificationSource::testUpdateGroupWithNotificationParameters() +{ + source->updateGroup(USER_ID, NOTIFICATION_GROUP_ID1, createDefaultNotificationParameters()); + + QCOMPARE(gDefaultNotificationManagerStub.stubLastCallTo("updateGroup").parameter(0), USER_ID); + QCOMPARE(gDefaultNotificationManagerStub.stubLastCallTo("updateGroup").parameter(1), NOTIFICATION_GROUP_ID1); + + NotificationParameters parametersGivenToManager = gDefaultNotificationManagerStub.stubLastCallTo("updateGroup").parameter(2); + + QCOMPARE(parametersGivenToManager.value(GenericNotificationParameterFactory::eventTypeKey()).toString(), EVENT); + QCOMPARE(parametersGivenToManager.value(NotificationWidgetParameterFactory::summaryKey()).toString(), SUMMARY); + QCOMPARE(parametersGivenToManager.value(NotificationWidgetParameterFactory::bodyKey()).toString(), BODY); + QCOMPARE(parametersGivenToManager.value(NotificationWidgetParameterFactory::actionKey()).toString(), ACTION); + QCOMPARE(parametersGivenToManager.value(NotificationWidgetParameterFactory::imageIdKey()).toString(), IMAGE); + QCOMPARE(parametersGivenToManager.value(GenericNotificationParameterFactory::countKey()).toUInt(), COUNT); + QCOMPARE(parametersGivenToManager.value(GenericNotificationParameterFactory::identifierKey()).toString(), IDENTIFIER); + QCOMPARE(parametersGivenToManager.value(GenericNotificationParameterFactory::timestampKey()).toUInt(), TIMESTAMP); +} + +void Ut_DBusInterfaceNotificationSource::testRemoveGroupWithNotificationParameters() +{ + source->removeGroup(USER_ID, NOTIFICATION_GROUP_ID1); + QCOMPARE(gDefaultNotificationManagerStub.stubLastCallTo("removeGroup").parameter(0), USER_ID); + QCOMPARE(gDefaultNotificationManagerStub.stubLastCallTo("removeGroup").parameter(1), NOTIFICATION_GROUP_ID1); +} + +void Ut_DBusInterfaceNotificationSource::testReturningNotificationsWithNotificationParameters() +{ + QList expectedResults; + NotificationParameters params = createDefaultNotificationParameters(); + expectedResults.append(Notification(NOTIFICATION_ID1, NOTIFICATION_GROUP_ID1, USER_ID, params, Notification::ApplicationEvent, 0)); + expectedResults.append(Notification(NOTIFICATION_ID2, NOTIFICATION_GROUP_ID2, USER_ID, params, Notification::ApplicationEvent, 0)); + gNotificationManagerStub->stubSetReturnValue("notificationList", expectedResults); + + QList receivedResults = source->notificationListWithNotificationParameters(USER_ID); + + QCOMPARE(gDefaultNotificationManagerStub.stubCallCount("notificationList"), 1); + QCOMPARE(gDefaultNotificationManagerStub.stubLastCallTo("notificationList").parameter(0), USER_ID); + QCOMPARE(receivedResults.count(), 2); + + MNotificationProxyWithParameters notification1 = receivedResults.at(0); + QCOMPARE(notification1.notificationId, NOTIFICATION_ID1); + QCOMPARE(notification1.groupId, NOTIFICATION_GROUP_ID1); + QCOMPARE(notification1.parameters.value(GenericNotificationParameterFactory::eventTypeKey()).toString(), EVENT); + QCOMPARE(notification1.parameters.value(NotificationWidgetParameterFactory::summaryKey()).toString(), SUMMARY); + + + MNotificationProxyWithParameters notification2 = receivedResults.at(1); + QCOMPARE(notification2.notificationId, NOTIFICATION_ID2); + QCOMPARE(notification2.groupId, NOTIFICATION_GROUP_ID2); + QCOMPARE(notification2.parameters.value(GenericNotificationParameterFactory::eventTypeKey()).toString(), EVENT); + QCOMPARE(notification2.parameters.value(NotificationWidgetParameterFactory::summaryKey()).toString(), SUMMARY); +} + +void Ut_DBusInterfaceNotificationSource::testReturningNotificationGroupsWithNotificationParameters() +{ + QList expectedResults; + NotificationParameters params = createDefaultNotificationParameters(); + expectedResults.append(NotificationGroup(NOTIFICATION_GROUP_ID1, USER_ID, params)); + expectedResults.append(NotificationGroup(NOTIFICATION_GROUP_ID2, USER_ID, params)); + gNotificationManagerStub->stubSetReturnValue("notificationGroupList", expectedResults); + + QList receivedResults = source->notificationGroupListWithNotificationParameters(USER_ID); + + QCOMPARE(gDefaultNotificationManagerStub.stubCallCount("notificationGroupList"), 1); + QCOMPARE(gDefaultNotificationManagerStub.stubLastCallTo("notificationGroupList").parameter(0), USER_ID); + QCOMPARE(receivedResults.count(), 2); + + MNotificationGroupProxyWithParameters notification1 = receivedResults.at(0); + QCOMPARE(notification1.groupId, NOTIFICATION_GROUP_ID1); + QCOMPARE(notification1.parameters.value(GenericNotificationParameterFactory::eventTypeKey()).toString(), EVENT); + QCOMPARE(notification1.parameters.value(NotificationWidgetParameterFactory::summaryKey()).toString(), SUMMARY); + + MNotificationGroupProxyWithParameters notification2 = receivedResults.at(1); + QCOMPARE(notification2.groupId, NOTIFICATION_GROUP_ID2); + QCOMPARE(notification2.parameters.value(GenericNotificationParameterFactory::eventTypeKey()).toString(), EVENT); + QCOMPARE(notification2.parameters.value(NotificationWidgetParameterFactory::summaryKey()).toString(), SUMMARY); +} + QTEST_APPLESS_MAIN(Ut_DBusInterfaceNotificationSource) diff --git a/tests/ut_dbusinterfacenotificationsource/ut_dbusinterfacenotificationsource.h b/tests/ut_dbusinterfacenotificationsource/ut_dbusinterfacenotificationsource.h index 5b64a369..f4a5216d 100644 --- a/tests/ut_dbusinterfacenotificationsource/ut_dbusinterfacenotificationsource.h +++ b/tests/ut_dbusinterfacenotificationsource/ut_dbusinterfacenotificationsource.h @@ -71,6 +71,21 @@ private slots: //Test updating group with empty strings void testUpdateGroupWithEmptyStrings(); void testNotificationCountInGroup(); + // Test addNotification with NotificationParameters + void testAddNotificationWithNotificationParameters(); + // Test addUpdateNotification with NotificationParameters + void testUpdateNotificationWithNotificationParameters(); + // Test addRemoveNotification with NotificationParameters + void testRemoveNotificationWithNotificationParameters(); + // Test addGroup with NotificationParameters + void testAddGroupWithNotificationParameters(); + // Test updateGroup with NotificationParameters + void testUpdateGroupWithNotificationParameters(); + // Test removeGroup with NotificationParameters + void testRemoveGroupWithNotificationParameters(); + // Test the query of notifications + void testReturningNotificationsWithNotificationParameters(); + void testReturningNotificationGroupsWithNotificationParameters(); private: // Notification manager interface used by the test subject diff --git a/tests/ut_notificationmanager/ut_notificationmanager.cpp b/tests/ut_notificationmanager/ut_notificationmanager.cpp index fa5ff4cd..d9b57e67 100644 --- a/tests/ut_notificationmanager/ut_notificationmanager.cpp +++ b/tests/ut_notificationmanager/ut_notificationmanager.cpp @@ -52,6 +52,7 @@ quint32 gLastUserId; #define PERSISTENT GenericNotificationParameterFactory::persistentKey() #define UNSEEN GenericNotificationParameterFactory::unseenKey() #define IDENTIFIER GenericNotificationParameterFactory::identifierKey() +#define TIMESTAMP GenericNotificationParameterFactory::timestampKey() #define SUMMARY NotificationWidgetParameterFactory::summaryKey() #define BODY NotificationWidgetParameterFactory::bodyKey() @@ -118,6 +119,7 @@ void DBusInterfaceNotificationSink::removeGroup(uint) void DBusInterfaceNotificationSink::sendCurrentNotifications(const DBusInterface&) const { } + // QDateTime stub static uint qDateTimeToTime_t = 0; uint QDateTime::toTime_t () const @@ -366,7 +368,6 @@ void Ut_NotificationManager::testAddNotification() // Create three notifications - two with a content link and one without NotificationParameters parameters0; parameters0.add(IMAGE, "icon0"); - qDateTimeToTime_t = 123; uint id0 = manager->addNotification(0, parameters0); NotificationParameters parameters1; @@ -377,7 +378,6 @@ void Ut_NotificationManager::testAddNotification() NotificationParameters parameters2; parameters2.add(ICON, "buttonicon2"); - qDateTimeToTime_t = 12345; uint id2 = manager->addNotification(0, parameters2); // Verify that timer was not started @@ -398,7 +398,6 @@ void Ut_NotificationManager::testAddNotification() QCOMPARE(n.parameters().value(IMAGE).toString(), QString("icon0")); QCOMPARE(n.type(), Notification::ApplicationEvent); QCOMPARE(n.timeout(), 0); - QCOMPARE(n.parameters().value("timestamp").toUInt(), (uint)123); arguments = spy.takeFirst(); n = qvariant_cast(arguments.at(0)); @@ -414,7 +413,6 @@ void Ut_NotificationManager::testAddNotification() QCOMPARE(n.groupId(), (uint)0); QCOMPARE(n.parameters().value(ICON).toString(), QString("buttonicon2")); QCOMPARE(n.type(), Notification::ApplicationEvent); - QCOMPARE(n.parameters().value("timestamp").toUInt(), (uint)12345); QCOMPARE(n.timeout(), 0); // Verify that the IDs are unique @@ -455,7 +453,6 @@ void Ut_NotificationManager::testNotificationsAndGroupsAreUpdatedWhenEventTypeIs parameters.add(EVENT_TYPE, "testType"); manager->addNotification(0, parameters); - qDateTimeToTime_t = 123; uint groupId = manager->addGroup(0, parameters); // Create a notification and a group of a different notification type. @@ -496,20 +493,17 @@ void Ut_NotificationManager::testUpdateNotification() NotificationParameters parameters0; parameters0.add(IMAGE, "icon0"); - qDateTimeToTime_t = 123; uint id0 = manager->addNotification(0, parameters0); // Update the notification NotificationParameters parameters1; parameters1.add(BODY, "body1"); - qDateTimeToTime_t = 12345; manager->updateNotification(0, id0, parameters1); // Test that the relevant signals are sent QCOMPARE(spy.count(), 2); QList arguments = spy.takeFirst(); Notification n = qvariant_cast(arguments.at(0)); - QCOMPARE(n.parameters().value("timestamp").toUInt(), (uint)123); arguments = spy.takeFirst(); n = qvariant_cast(arguments.at(0)); @@ -518,7 +512,6 @@ void Ut_NotificationManager::testUpdateNotification() QCOMPARE(n.parameters().value(BODY).toString(), QString("body1")); QCOMPARE(n.type(), Notification::ApplicationEvent); QCOMPARE(n.timeout(), 0); - QCOMPARE(n.parameters().value("timestamp").toUInt(), (uint)12345); } @@ -593,12 +586,10 @@ void Ut_NotificationManager::testAddGroup() NotificationParameters inParameters1; inParameters1.add(IMAGE, "icon1"); - qDateTimeToTime_t = 123; uint id1 = manager->addGroup(0, inParameters1); NotificationParameters inParameters2; inParameters2.add(BODY, "body2"); - qDateTimeToTime_t = 12345; uint id2 = manager->addGroup(0, inParameters2); // Check that we didn't get invalid numbers @@ -615,13 +606,11 @@ void Ut_NotificationManager::testAddGroup() QCOMPARE(arguments.at(0).toUInt(), id1); NotificationParameters outParameters1 = arguments.at(1).value(); QCOMPARE(outParameters1.value(IMAGE).toString(), QString("icon1")); - QCOMPARE(outParameters1.value("timestamp").toUInt(), (uint)123); arguments = addGroupSpy.takeFirst(); QCOMPARE(arguments.at(0).toUInt(), id2); NotificationParameters outParameters2 = arguments.at(1).value(); QCOMPARE(outParameters2.value(BODY).toString(), QString("body2")); - QCOMPARE(outParameters2.value("timestamp").toUInt(), (uint)12345); } void Ut_NotificationManager::testWhenNotificationGroupIsAddedThenTheNotificationGroupIsFilledWithEventTypeData() @@ -648,13 +637,10 @@ void Ut_NotificationManager::testUpdateGroup() NotificationParameters inParameters1; inParameters1.add(IMAGE, "icon1"); - qDateTimeToTime_t = 123; uint id1 = manager->addGroup(0, inParameters1); - NotificationParameters inParameters2; inParameters2.add(BODY, "body2"); - qDateTimeToTime_t = 12345; manager->updateGroup(0, id1, inParameters2); QCOMPARE(updateGroupSpy.count(), 2); @@ -662,15 +648,12 @@ void Ut_NotificationManager::testUpdateGroup() QList arguments = updateGroupSpy.takeFirst(); QCOMPARE(arguments.at(0).toUInt(), id1); NotificationParameters outParameters = arguments.at(1).value(); - QCOMPARE(outParameters.value("timestamp").toUInt(), (uint)123); arguments = updateGroupSpy.takeFirst(); QCOMPARE(arguments.at(0).toUInt(), id1); outParameters = arguments.at(1).value(); QCOMPARE(outParameters.value(BODY).toString(), QString("body2")); QCOMPARE(outParameters.value(IMAGE).toString(), QString("icon1")); - QVERIFY(outParameters.value("timestamp").toUInt() > 0); - QCOMPARE(outParameters.value("timestamp").toUInt(), (uint)12345); } void Ut_NotificationManager::testUpdateNonexistingGroup() @@ -775,19 +758,16 @@ void Ut_NotificationManager::testAddNotificationInGroup() NotificationParameters gparameters1; gparameters1.add(IMAGE, "gicon1"); - qDateTimeToTime_t = 123; uint groupId = manager->addGroup(0, gparameters1); QCOMPARE(groupSpy.count(), 1); QList arguments = groupSpy.takeFirst(); NotificationParameters outParameters = arguments.at(1).value(); - QCOMPARE(outParameters.value("timestamp").toUInt(), (uint)123); QSignalSpy addSpy(manager, SIGNAL(notificationUpdated(Notification))); NotificationParameters parameters0; parameters0.add(IMAGE, "icon0"); - qDateTimeToTime_t = 12345; uint id0 = manager->addNotification(0, parameters0, groupId); QCOMPARE(addSpy.count(), 1); @@ -796,7 +776,6 @@ void Ut_NotificationManager::testAddNotificationInGroup() QCOMPARE(n.notificationId(), id0); QCOMPARE(n.groupId(), groupId); QCOMPARE(n.parameters().value(IMAGE).toString(), QString("icon0")); - QCOMPARE(n.parameters().value("timestamp").toUInt(), (uint)12345); } void Ut_NotificationManager::testAddNotificationInNonexistingGroup() @@ -1820,4 +1799,105 @@ void Ut_NotificationManager::testSystemBannersWhenQueuedMaintainTheirOrder() QCOMPARE(n.notificationId(), idsystem2); } +void Ut_NotificationManager::testAddNotificationWithAndWithoutTimestamp() +{ + QSignalSpy spy(manager, SIGNAL(notificationUpdated(Notification))); + + uint userId = 1; + uint timestamp = 12345678; + qDateTimeToTime_t = 123; + NotificationParameters params; + params.add(TIMESTAMP, timestamp); + manager->addNotification(userId, params); + manager->addNotification(userId, NotificationParameters()); + + QCOMPARE(spy.count(), 2); + + // First notification has timestamp in NotificationParameters + QList arguments = spy.takeFirst(); + Notification notification = qvariant_cast(arguments.at(0)); + QCOMPARE(notification.parameters().value(TIMESTAMP).toUInt(), timestamp); + + // Second notification has a zero timestamp in NotificatinParameters, + // so current time is used as a timestamp + arguments = spy.takeFirst(); + notification = qvariant_cast(arguments.at(0)); + QCOMPARE(notification.parameters().value(TIMESTAMP).toUInt(), qDateTimeToTime_t); +} + +void Ut_NotificationManager::testThatTimestampOfNotificationIsUpdatedWhenNotificationUpdates() +{ + QSignalSpy spy(manager, SIGNAL(notificationUpdated(Notification))); + + uint timestamp = 12345678; + qDateTimeToTime_t = 123; + + uint notificationId = manager->addNotification(0, NotificationParameters()); + + NotificationParameters params; + params.add(TIMESTAMP, timestamp); + manager->updateNotification(0, notificationId, params); + + QCOMPARE(spy.count(), 2); + + QList arguments = spy.takeFirst(); + Notification notification = qvariant_cast(arguments.at(0)); + QCOMPARE(notification.parameters().value(TIMESTAMP).toUInt(), qDateTimeToTime_t); + QCOMPARE(notification.notificationId(), notificationId); + + arguments = spy.takeFirst(); + notification = qvariant_cast(arguments.at(0)); + QCOMPARE(notification.parameters().value(TIMESTAMP).toUInt(), timestamp); + QCOMPARE(notification.notificationId(), notificationId); +} + +void Ut_NotificationManager::testAddGroupWithAndWithoutTimestamp() +{ + QSignalSpy spy(manager, SIGNAL(groupUpdated(uint, const NotificationParameters&))); + + uint userId = 1; + uint timestamp = 12345678; + qDateTimeToTime_t = 123; + NotificationParameters params; + params.add(TIMESTAMP, timestamp); + manager->addGroup(userId, params); + manager->addGroup(userId, NotificationParameters()); + + QCOMPARE(spy.count(), 2); + + // First notification has timestamp in NotificationParameters + QList arguments = spy.takeFirst(); + NotificationParameters notificationParams = qvariant_cast(arguments.at(1)); + QCOMPARE(notificationParams.value(TIMESTAMP).toUInt(), timestamp); + + // Second notification has a zero timestamp in NotificationParameters, + // so current time is used as a timestamp + arguments = spy.takeFirst(); + notificationParams = qvariant_cast(arguments.at(1)); + QCOMPARE(notificationParams.value(TIMESTAMP).toUInt(), qDateTimeToTime_t); +} + +void Ut_NotificationManager::testThatTimestampOfGroupIsUpdatedWhenGroupIsUpdated() +{ + QSignalSpy spy(manager, SIGNAL(groupUpdated(uint, const NotificationParameters&))); + + uint timestamp = 12345678; + qDateTimeToTime_t = 123; + + uint groupId = manager->addGroup(0, NotificationParameters()); + + NotificationParameters params; + params.add(TIMESTAMP, timestamp); + manager->updateGroup(0, groupId, params); + + QCOMPARE(spy.count(), 2); + + QList arguments = spy.takeFirst(); + QCOMPARE(arguments.at(0).toUInt(), groupId); + + arguments = spy.takeFirst(); + QCOMPARE(qvariant_cast(arguments.at(1)).value(TIMESTAMP).toUInt(), timestamp); + QCOMPARE(arguments.at(0).toUInt(), groupId); +} + QTEST_MAIN(Ut_NotificationManager) diff --git a/tests/ut_notificationmanager/ut_notificationmanager.h b/tests/ut_notificationmanager/ut_notificationmanager.h index e08c530f..e3173bc8 100644 --- a/tests/ut_notificationmanager/ut_notificationmanager.h +++ b/tests/ut_notificationmanager/ut_notificationmanager.h @@ -157,6 +157,14 @@ private slots: void testNotificationsAndGroupsAreUpdatedWhenEventTypeIsUpdated(); void testNotificationCountInGroup(); void testPruningNonPersistentNotificationsOnBoot(); + // Test adding notification with and without user specified timestamp + void testAddNotificationWithAndWithoutTimestamp(); + // Test that timestamp of notification is updated + void testThatTimestampOfNotificationIsUpdatedWhenNotificationUpdates(); + // Test adding group with and without user specified timestamp + void testAddGroupWithAndWithoutTimestamp(); + // Test that timestamp of group is updated when group is updated + void testThatTimestampOfGroupIsUpdatedWhenGroupIsUpdated(); }; #endif // UT_NOTIFICATIONMANAGER_H