Skip to content

Commit

Permalink
Fixes: NB#272599 - System banners should be prioritized over short ev…
Browse files Browse the repository at this point in the history
…ent banners (a.k.a. notification previews)

RevBy: Ran Nyman
  • Loading branch information
Sachin Kundu committed Jul 25, 2011
1 parent c64af5b commit 924e89d
Show file tree
Hide file tree
Showing 5 changed files with 102 additions and 1 deletion.
1 change: 1 addition & 0 deletions debian/changelog
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
system-ui (1.1.2~1) unstable; urgency=low

* [UNRELEASED]
* Fixes: NB#272599 - System banners should be prioritized over short event banners (a.k.a. notification previews)

-- Vesa Halttunen <[email protected]> Mon, 25 Jul 2011 15:03:45 +0300

Expand Down
20 changes: 19 additions & 1 deletion src/systemui/notifications/notificationmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -554,6 +554,24 @@ Notification::NotificationType NotificationManager::determineType(const Notifica
return classStr == SYSTEM_EVENT_ID ? Notification::SystemEvent : Notification::ApplicationEvent;
}

int NotificationManager::insertPosition(const Notification &notification)
{
int pos = 0;
const NotificationParameters parameters = notification.parameters();
if(parameters.value("class") != QString("system")) {
return waitQueue.size();
} else {
for(pos = 0; pos < waitQueue.count(); ++pos) {
if (waitQueue.at(pos).parameters().value("class") == QString("system")) {
continue;
} else {
return pos;
}
}
return pos;
}
}

void NotificationManager::submitNotification(const Notification &notification)
{
if (!notificationInProgress) {
Expand All @@ -570,7 +588,7 @@ void NotificationManager::submitNotification(const Notification &notification)
} else {
// Store new notification in the notification wait queue
if ((uint)waitQueue.size() < maxWaitQueueSize) {
waitQueue.append(notification);
waitQueue.insert(insertPosition(notification), notification);
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions src/systemui/notifications/notificationmanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,9 @@ private slots:
//! Whether store initialization is subsequent after initialization in boot
bool subsequentStart;

//! Returns the position where notification should be inserted in the queue, depending upon type of notification
int insertPosition(const Notification &notification);

#ifdef UNIT_TEST
friend class Ut_NotificationManager;
#endif
Expand Down
75 changes: 75 additions & 0 deletions tests/ut_notificationmanager/ut_notificationmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1672,4 +1672,79 @@ void Ut_NotificationManager::testPruningNonPersistentNotificationsOnBoot()
QCOMPARE(spy.count(), 1);
}


void Ut_NotificationManager::testSytemNotificationArePrepended()
{
delete manager;
manager = new TestNotificationManager(-1);
QSignalSpy spy(manager, SIGNAL(notificationUpdated(Notification)));

NotificationParameters parameters0;
parameters0.add(IMAGE, "icon0");
uint idnotification = manager->addNotification(0, parameters0);

NotificationParameters parameters1;
parameters1.add(BODY, "body1");
manager->addNotification(0, parameters1);

NotificationParameters parameters2;
parameters2.add(CLASS, "system");
uint idsystem = manager->addNotification(0, parameters2);

// Check that notification sink was signaled with one notification.
QCOMPARE(spy.count(), 1);
QList<QVariant> arguments = spy.takeFirst();
Notification n = qvariant_cast<Notification>(arguments.at(0));
QCOMPARE(n.notificationId(), idnotification);

// Relay next notification
manager->relayNextNotification();

QCOMPARE(spy.count(), 1);
arguments = spy.takeFirst();
n = qvariant_cast<Notification>(arguments.at(0));
// Inserting in order, application application system and expecting in order application system application
QCOMPARE(n.notificationId(), idsystem);
}

void Ut_NotificationManager::testSystemBannersWhenQueuedMaintainTheirOrder()
{
delete manager;
manager = new TestNotificationManager(-1);
QSignalSpy spy(manager, SIGNAL(notificationUpdated(Notification)));

NotificationParameters parameters0;
parameters0.add(CLASS, "system");
uint idsystem0 = manager->addNotification(0, parameters0);

NotificationParameters parameters1;
parameters1.add(CLASS, "system");
uint idsystem1 = manager->addNotification(0, parameters1);

NotificationParameters parameters2;
parameters2.add(CLASS, "system");
uint idsystem2 = manager->addNotification(0, parameters2);

QCOMPARE(spy.count(), 1);
QList<QVariant> arguments = spy.takeFirst();
Notification n = qvariant_cast<Notification>(arguments.at(0));
QCOMPARE(n.notificationId(), idsystem0);

// Relay next notification
manager->relayNextNotification();

QCOMPARE(spy.count(), 1);
arguments = spy.takeFirst();
n = qvariant_cast<Notification>(arguments.at(0));
QCOMPARE(n.notificationId(), idsystem1);

// Relay next notification
manager->relayNextNotification();

QCOMPARE(spy.count(), 1);
arguments = spy.takeFirst();
n = qvariant_cast<Notification>(arguments.at(0));
QCOMPARE(n.notificationId(), idsystem2);
}

QTEST_MAIN(Ut_NotificationManager)
4 changes: 4 additions & 0 deletions tests/ut_notificationmanager/ut_notificationmanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,10 @@ private slots:
void testRemovingGroupsWithEventType();
// Test removal of unseen flags from notifications
void testRemovalOfUnseenFlags();
// Test that system notifications are input always at the front of the queue
void testSytemNotificationArePrepended();
// Test when system banners are queued, they follow the order in which they are added
void testSystemBannersWhenQueuedMaintainTheirOrder();

// Test that relevant signals are connected to the DBus sink
void testDBusNotificationSinkConnections();
Expand Down

0 comments on commit 924e89d

Please sign in to comment.