Skip to content

Commit

Permalink
Fixes: NB#297027 - Notification group does not show the real latest t…
Browse files Browse the repository at this point in the history
…imestamp

RevBy: Vesa Halttunen
  • Loading branch information
Eetu Lehmusvuo committed Jan 20, 2012
1 parent 0451772 commit 73c1a3d
Show file tree
Hide file tree
Showing 7 changed files with 252 additions and 25 deletions.
1 change: 1 addition & 0 deletions debian/changelog
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ system-ui (1.3.1~1) unstable; urgency=low

* [UNRELEASED]
* Fixes: NB#295751 - Device shows OS update message after SSU from PR1 40-4 to PR2 50-5
* Fixes: NB#297027 - Notification group does not show the real latest timestamp

-- Vesa Halttunen <[email protected]> Mon, 16 Jan 2012 14:07:50 +0200

Expand Down
4 changes: 2 additions & 2 deletions src/systemui/notifications/notificationareasink.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
** of this file.
**
****************************************************************************/

#include "notificationareasink.h"
#include "notificationwidgetparameterfactory.h"
#include "notificationmanagerinterface.h"
Expand Down Expand Up @@ -77,6 +78,7 @@ void NotificationAreaSink::updateNotification(MBanner *infoBanner, const Notific
infoBanner->setProperty(SUBTITLE_TEXT_PROPERTY, infoBannerTitleText(parameters));
infoBanner->setProperty(GENERIC_TEXT_PROPERTY, infoBannerGenericText(parameters));
infoBanner->setProperty(USER_REMOVABLE_PROPERTY, determineUserRemovability(parameters));
infoBanner->setBannerTimeStamp(QDateTime::fromTime_t(parameters.value("timestamp").toUInt()));

updatePrefixForNotificationGroupBannerTimestamp(infoBanner, parameters.value("count").toUInt());

Expand Down Expand Up @@ -179,7 +181,6 @@ void NotificationAreaSink::addNotificationToGroup(const Notification &notificati
// Seems like the infoBanner is NULL. So it means that the group banner was removed, but group is alive. Recreate the banner.
infoBanner = createGroupBanner(groupId, notificationGroupParameters.value(groupId));
}
infoBanner->setBannerTimeStamp(QDateTime::fromTime_t(notification.parameters().value("timestamp").toUInt()));

if (infoBanner != NULL && infoBanner->parentItem() == NULL) {
// Add the group to the notification area if this is the first notification to the group
Expand All @@ -198,7 +199,6 @@ void NotificationAreaSink::addStandAloneNotification(const Notification &notific
if (infoBanner != NULL) {
// If the notification is already in the map, only update it
updateNotification(infoBanner, notification.parameters());
infoBanner->setBannerTimeStamp(QDateTime::fromTime_t(notification.parameters().value("timestamp").toUInt()));
} else {
infoBanner = createInfoBanner(notification);
setupInfoBanner(infoBanner, notification.parameters());
Expand Down
41 changes: 36 additions & 5 deletions src/systemui/notifications/notificationmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,8 @@ uint NotificationManager::addNotification(uint notificationUserId, const Notific

submitNotification(notification);

updateGroupTimestampFromNotifications(groupId);

return notificationId;
}
return 0;
Expand Down Expand Up @@ -312,6 +314,8 @@ bool NotificationManager::updateNotification(uint notificationUserId, uint notif
emit notificationUpdated(notificationContainer.value(notificationId));
}

updateGroupTimestampFromNotifications((*ni).groupId());

return true;
} else {
return false;
Expand All @@ -333,7 +337,7 @@ bool NotificationManager::removeNotification(uint notificationId)
{
if (notificationContainer.contains(notificationId)) {
// Mark the notification unused
notificationContainer.take(notificationId);
const Notification removedNotification = notificationContainer.take(notificationId);

saveNotifications();

Expand All @@ -353,6 +357,8 @@ bool NotificationManager::removeNotification(uint notificationId)
}
}

updateGroupTimestampFromNotifications(removedNotification.groupId());

return true;
} else {
return false;
Expand All @@ -373,13 +379,13 @@ bool NotificationManager::removeNotificationsInGroup(uint groupId)
foreach(uint notificationId, notificationIds) {
result &= removeNotification(notificationId);
}

return result;
}

uint NotificationManager::addGroup(uint notificationUserId, const NotificationParameters &parameters)
{
NotificationParameters fullParameters(appendEventTypeParameters(parameters));
fullParameters.add(GenericNotificationParameterFactory::timestampKey(), timestamp(parameters));

uint groupID = nextAvailableGroupID();
NotificationGroup group(groupID, notificationUserId, fullParameters);
Expand All @@ -399,9 +405,7 @@ bool NotificationManager::updateGroup(uint notificationUserId, uint groupId, con
QHash<uint, NotificationGroup>::iterator gi = groupContainer.find(groupId);

if (gi != groupContainer.end()) {
NotificationParameters fullParameters(parameters);
fullParameters.add(GenericNotificationParameterFactory::timestampKey(), timestamp(parameters));
gi->updateParameters(fullParameters);
gi->updateParameters(parameters);

saveStateData();

Expand Down Expand Up @@ -673,3 +677,30 @@ uint NotificationManager::timestamp(const NotificationParameters &parameters)
return timestamp == 0 ? QDateTime::currentDateTimeUtc().toTime_t() : timestamp;
}

void NotificationManager::updateGroupTimestampFromNotifications(uint groupId)
{
if (groupId != 0 && groupContainer.contains(groupId)) {
NotificationGroup group = groupContainer.value(groupId);
NotificationParameters groupParameters = group.parameters();
uint oldGroupTimestamp = groupParameters.value(GenericNotificationParameterFactory::timestampKey()).toUInt();

// Check the latest notification timestamp of the group's notifications
uint newGroupTimestamp = 0;
QHash<uint, Notification>::const_iterator notificationIterator;
for (notificationIterator = notificationContainer.begin(); notificationIterator != notificationContainer.end(); notificationIterator++) {
if ((*notificationIterator).groupId() == groupId) {
uint notificationTimestamp = (*notificationIterator).parameters().value(GenericNotificationParameterFactory::timestampKey()).toUInt();
if (newGroupTimestamp < notificationTimestamp) {
newGroupTimestamp = notificationTimestamp;
}
}
}

if (oldGroupTimestamp != newGroupTimestamp) {
// Update the group timestamp
groupParameters.add(GenericNotificationParameterFactory::timestampKey(), newGroupTimestamp);
group.updateParameters(groupParameters);
updateGroup(group.userId(), group.groupId(), group.parameters());
}
}
}
6 changes: 6 additions & 0 deletions src/systemui/notifications/notificationmanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,12 @@ private slots:
*/
uint timestamp(const NotificationParameters &parameters);

/*! Updates the given group's timestamp according to the latest timestamp of group's notifications.
*
* \param groupId The id of the group of which timestamp should be updated
*/
void updateGroupTimestampFromNotifications(uint groupId);

//! Hash of all notifications keyed by notification IDs
QHash<uint, Notification> notificationContainer;

Expand Down
13 changes: 7 additions & 6 deletions tests/ut_notificationareasink/ut_notificationareasink.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -340,9 +340,10 @@ void Ut_NotificationAreaSink::testAddNotificationToGroup()
TestNotificationParameters parameters1("title1", "subtitle1", "icon1", "content1", 12345);
emit addNotification(Notification(0, 1, 2, parameters1, Notification::ApplicationEvent, 1000));

QCOMPARE(timestamps[1].toTime_t(), (uint)12345);
QCOMPARE(addSpy.count(), 1);
QCOMPARE(notifications.count(), 1);
// Group timestamp shouldn't change in sink when notification added (that is handled in notification manager)
QCOMPARE(timestamps.count(), 1);
}

void Ut_NotificationAreaSink::testAddNewNotificationToGroupUpdatesNotificationArea()
Expand Down Expand Up @@ -370,7 +371,7 @@ void Ut_NotificationAreaSink::testWhenAddingNewNotificationToGroupThatHasBeenPre
const QString NOTIFICATION_ICON("notificationIcon");
const QString NOTIFICATION_ACTION("notificationAction");

TestNotificationParameters groupParameters(GROUP_SUMMARY, GROUP_BODY, GROUP_ICON, GROUP_ACTION);
TestNotificationParameters groupParameters(GROUP_SUMMARY, GROUP_BODY, GROUP_ICON, GROUP_ACTION, 123);
emit addGroup(GROUP_ID, groupParameters);
TestNotificationParameters notificationParameters(NOTIFICATION_SUMMARY, NOTIFICATION_BODY, NOTIFICATION_ICON, NOTIFICATION_ACTION, 12345);
emit addNotification(Notification(NOTIFICATION_ID, GROUP_ID, 2, notificationParameters, Notification::ApplicationEvent, 1000));
Expand All @@ -386,8 +387,8 @@ void Ut_NotificationAreaSink::testWhenAddingNewNotificationToGroupThatHasBeenPre
MBanner *banner = bannerCatcher.banners.at(0);
// The banner should have the notification group's data
QCOMPARE(banner->title(), GROUP_BODY);
// The banner should have the timestamp of the previous notification
QCOMPARE(timestamps[0].toTime_t(), (uint)12345);
// The banner should have the timestamp of the group
QCOMPARE(timestamps[0].toTime_t(), (uint)123);
}

void Ut_NotificationAreaSink::testUpdateGroup()
Expand All @@ -410,14 +411,14 @@ void Ut_NotificationAreaSink::testUpdateGroup()

emit addGroup(1, parameters1);

// The stub is now aware of the banner so updates go to the first occurrence of the banner. Timestamp should not get set.
// The stub is now aware of the banner so updates go to the first occurrence of the banner. Timestamp should get updated.
QCOMPARE(titles.length(), 2);
QCOMPARE(titles[0], QString("subtitle1"));
QCOMPARE(subtitles.length(), 2);
QCOMPARE(subtitles[0], QString("title1"));
QCOMPARE(buttonIcons.length(), 1);
QCOMPARE(buttonIcons[0], QString("buttonicon1"));
QCOMPARE(timestamps[0].toTime_t(), (uint)12345);
QCOMPARE(timestamps[0].toTime_t(), (uint)123456);
// TODO: even though contents.length is 2, there's only 1 action in the mnotification
// clearing of the actions should be stubbed somehow...
QCOMPARE(contents.length(), 2);
Expand Down
Loading

0 comments on commit 73c1a3d

Please sign in to comment.