Skip to content

Commit

Permalink
Fixes: NB#249391 - [TASK] Notifier improvement
Browse files Browse the repository at this point in the history
Bug: NB#249391 - [TASK] Notifier improvement
RevBy: Juha Juutinen
  • Loading branch information
Vesa Halttunen committed Jul 11, 2011
1 parent a4f4d2a commit ba0babc
Show file tree
Hide file tree
Showing 49 changed files with 1,003 additions and 994 deletions.
7 changes: 3 additions & 4 deletions src/extensions/screenlock/lockscreenstatusareaview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
#include "statusindicator.h"
#include "contextframeworkcontext.h"
#include "x11wrapper.h"
#include "notificationstatusindicator.h"
#include "screenlockextension.h"
#include <QGraphicsLinearLayout>
#include <QX11Info>
Expand All @@ -42,7 +41,7 @@ LockScreenStatusAreaView::LockScreenStatusAreaView(StatusArea *controller) :
profileIndicator(new ProfileStatusIndicator(contextFrameworkContext, controller)),
callIndicator(new CallStatusIndicator(contextFrameworkContext, controller)),
alarmIndicator(new AlarmStatusIndicator(contextFrameworkContext, controller)),
notifierIndicator(new NotificationStatusIndicator(controller)),
notificationStatusIndicator(new NotificationStatusIndicator(controller)),
callForwardingIndicator(new CallForwardingStatusIndicator(contextFrameworkContext, controller)),
transferStatusIndicator(new TransferStatusIndicator(controller)),
orientationChangeSignalConnected(false)
Expand All @@ -51,7 +50,7 @@ LockScreenStatusAreaView::LockScreenStatusAreaView(StatusArea *controller) :
connect(phoneNetworkTypeIndicator, SIGNAL(networkAvailabilityChanged(bool)), phoneSignalStrengthIndicator, SLOT(setDisplay(bool)));

// Connect notification signals
connect(ScreenLockExtension::instance(), SIGNAL(notifierSinkActive(bool)), notifierIndicator, SLOT(setActive(bool)));
connect(ScreenLockExtension::instance(), SIGNAL(notificationStatusIndicatorIconIdChanged(QString)), notificationStatusIndicator, SLOT(setIconID(QString)));

// Put indicators into the layout
QGraphicsLinearLayout *layout = new QGraphicsLinearLayout(Qt::Horizontal);
Expand All @@ -62,7 +61,7 @@ LockScreenStatusAreaView::LockScreenStatusAreaView(StatusArea *controller) :
layout->addItem(phoneNetworkIndicator);
layout->addItem(phoneNetworkTypeIndicator);
layout->addStretch();
layout->addItem(notifierIndicator);
layout->addItem(notificationStatusIndicator);
layout->addItem(transferStatusIndicator);
layout->addItem(callForwardingIndicator);
layout->addItem(bluetoothIndicator);
Expand Down
4 changes: 2 additions & 2 deletions src/extensions/screenlock/lockscreenstatusareaview.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@ private slots:
//! Alarm indicator
StatusIndicator *alarmIndicator;

//! Notification notifier
StatusIndicator *notifierIndicator;
//! Notification indicator
StatusIndicator *notificationStatusIndicator;

//! Call forwarding indicator
StatusIndicator *callForwardingIndicator;
Expand Down
2 changes: 0 additions & 2 deletions src/extensions/screenlock/screenlock.pro
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ HEADERS += ../../systemui/contextframeworkcontext.h \
../../systemui/statusarea/clock.h \
../../systemui/statusarea/clockmodel.h \
../../systemui/statusarea/statusarea.h \
../../systemui/statusarea/notificationstatusindicator.h \
../../systemui/statusindicatormenu/notificationarea.h \
../../systemui/statusindicatormenu/notificationareamodel.h \
../../systemui/notifications/notificationareasink.h \
Expand All @@ -79,7 +78,6 @@ SOURCES += ../../systemui/contextframeworkcontext.cpp \
../../systemui/statusarea/statusindicator.cpp \
../../systemui/statusarea/clock.cpp \
../../systemui/statusarea/statusarea.cpp \
../../systemui/statusarea/notificationstatusindicator.cpp \
../../systemui/statusindicatormenu/notificationarea.cpp \
../../systemui/notifications/notificationareasink.cpp \
../../systemui/notifications/widgetnotificationsink.cpp \
Expand Down
4 changes: 2 additions & 2 deletions src/extensions/screenlock/screenlockextension.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ class ScreenLockExtension : public QObject, public ScreenLockExtensionInterface
NotificationManagerInterface *notificationManagerInterface();

signals:
//! Signal for relaying notifier sink activity
void notifierSinkActive(bool active);
//! Signal for relaying notification status indicator sink activity
void notificationStatusIndicatorIconIdChanged(QString iconId);

//! Signal for relaying unlocking
void unlocked();
Expand Down
4 changes: 2 additions & 2 deletions src/systemui/notifications/notifications.pri
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ HEADERS += \
$$SYSTEMUI_NOTIFICATIONS_SRC_DIR/mcompositornotificationsink.h \
$$SYSTEMUI_NOTIFICATIONS_SRC_DIR/ngfnotificationsink.h \
$$SYSTEMUI_NOTIFICATIONS_SRC_DIR/ngfadapter.h \
$$SYSTEMUI_NOTIFICATIONS_SRC_DIR/notifiernotificationsink.h \
$$SYSTEMUI_NOTIFICATIONS_SRC_DIR/notificationstatusindicatorsink.h \
$$SYSTEMUI_NOTIFICATIONS_SRC_DIR/eventtypestore.h \
$$SYSTEMUI_NOTIFICATIONS_SRC_DIR/notificationmanager.h \
$$SYSTEMUI_NOTIFICATIONS_SRC_DIR/notificationsource.h \
Expand All @@ -32,7 +32,7 @@ SOURCES += \
$$SYSTEMUI_NOTIFICATIONS_SRC_DIR/mcompositornotificationsink.cpp \
$$SYSTEMUI_NOTIFICATIONS_SRC_DIR/ngfnotificationsink.cpp \
$$SYSTEMUI_NOTIFICATIONS_SRC_DIR/ngfadapter.cpp \
$$SYSTEMUI_NOTIFICATIONS_SRC_DIR/notifiernotificationsink.cpp \
$$SYSTEMUI_NOTIFICATIONS_SRC_DIR/notificationstatusindicatorsink.cpp \
$$SYSTEMUI_NOTIFICATIONS_SRC_DIR/eventtypestore.cpp \
$$SYSTEMUI_NOTIFICATIONS_SRC_DIR/notificationmanager.cpp \
$$SYSTEMUI_NOTIFICATIONS_SRC_DIR/notificationsource.cpp \
Expand Down
209 changes: 209 additions & 0 deletions src/systemui/notifications/notificationstatusindicatorsink.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,209 @@
/***************************************************************************
**
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation ([email protected])
**
** This file is part of systemui.
**
** If you have questions regarding the use of this file, please contact
** Nokia at [email protected].
**
** 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
** and appearing in the file LICENSE.LGPL included in the packaging
** of this file.
**
****************************************************************************/

#include "notificationstatusindicatorsink.h"
#include <notificationwidgetparameterfactory.h>
#include <notificationmanagerinterface.h>

NotificationStatusIndicatorSink::NotificationStatusIndicatorSink(QObject *parent) :
NotificationSink(parent)
{
}

NotificationStatusIndicatorSink::~NotificationStatusIndicatorSink()
{
foreach (NotificationData *data, dataForNotification.values()) {
delete data;
}

foreach (NotificationData *data, dataForGroup.values()) {
delete data;
}
}

void NotificationStatusIndicatorSink::addNotification(const Notification &notification)
{
// Only application events are shown in the status indicator
if (notification.type() == Notification::ApplicationEvent) {
int notificationId = notification.notificationId();
int groupId = notification.groupId();
QString iconId = notification.parameters().value("statusAreaIconId").toString();
int priority = notification.parameters().value("priority").toInt();

if (iconId.isEmpty()) {
iconId = "icon-s-status-notifier";
}

updateNotificationData(notificationId, iconId, priority);

if (!groupForNotification.contains(notificationId)) {
// Add the notification to the known notifications
groupForNotification.insert(notificationId, groupId);

if (groupId > 0) {
addNotificationToGroup(notificationId, groupId);
} else {
addStandaloneNotification(notificationId, iconId, priority);
}
}
}
}

void NotificationStatusIndicatorSink::removeNotification(uint notificationId)
{
int groupId = groupForNotification.value(notificationId, -1);
if (groupId != -1 && notificationsForGroup.contains(groupId)) {
removeNotificationFromGroup(notificationId, groupId);
} else {
removeStandaloneNotification(notificationId);
}

// Remove the notification from the known notifications
groupForNotification.remove(notificationId);
}

void NotificationStatusIndicatorSink::addGroup(uint groupId, const NotificationParameters &parameters)
{
QString iconId = parameters.value("statusAreaIconId").toString();
int priority = parameters.value("priority").toInt();

if (iconId.isEmpty()) {
iconId = "icon-s-status-notifier";
}

updateGroupData(groupId, iconId, priority);

// Add the group to the known groups if it's not known yet
if (!notificationsForGroup.contains(groupId)) {
notificationsForGroup.insert(groupId, QList<int>());

// Create data for the group
NotificationData *data = new NotificationData;
data->first = iconId;
data->second = priority;
dataForGroup.insert(groupId, data);
}
}

void NotificationStatusIndicatorSink::removeGroup(uint groupId)
{
NotificationData *data = dataForGroup.value(groupId, NULL);
if (data != NULL) {
if (!notificationsForGroup.value(groupId).isEmpty()) {
// The notification group had notifications in it: check whether this changes the most important notification
datas.removeAll(data);
checkMostImportantNotification();
}
dataForGroup.remove(groupId);
delete data;
}

// Remove the group from the known groups
notificationsForGroup.remove(groupId);
}

void NotificationStatusIndicatorSink::addStandaloneNotification(int notificationId, const QString &iconId, int priority)
{
// Create data for the notification
NotificationData *data = new NotificationData;
data->first = iconId;
data->second = priority;
dataForNotification.insert(notificationId, data);
datas.prepend(data);
checkMostImportantNotification();
}

void NotificationStatusIndicatorSink::removeStandaloneNotification(int notificationId)
{
// Standalone notification: remove the notification data
NotificationData *data = dataForNotification.value(notificationId, NULL);
if (data != NULL) {
datas.removeAll(data);
checkMostImportantNotification();
dataForNotification.remove(notificationId);
delete data;
}
}

void NotificationStatusIndicatorSink::addNotificationToGroup(int notificationId, int groupId)
{
// Add the notification to the list of notifications for the group
notificationsForGroup[groupId].append(notificationId);

NotificationData *data = dataForGroup.value(groupId, NULL);
if (data != NULL) {
if (notificationsForGroup[groupId].count() == 1) {
// First notification in the group: check whether this changes the most important notification
datas.prepend(data);
checkMostImportantNotification();
}
}
}

void NotificationStatusIndicatorSink::removeNotificationFromGroup(int notificationId, int groupId)
{
// Notification belongs to a group: remove the notification from the group
notificationsForGroup[groupId].removeAll(notificationId);

if (notificationsForGroup[groupId].isEmpty()) {
// No more notifications in the group: check whether this changes the most important notification
NotificationData *data = dataForGroup.value(groupId, NULL);
if (data != NULL) {
datas.removeAll(data);
checkMostImportantNotification();
}
}
}

void NotificationStatusIndicatorSink::updateNotificationData(int notificationId, const QString &iconId, int priority)
{
NotificationData *data = dataForNotification.value(notificationId, NULL);
if (data != NULL) {
// Icon ID set: update data
data->first = iconId;
data->second = priority;
checkMostImportantNotification();
}
}

void NotificationStatusIndicatorSink::updateGroupData(int groupId, const QString &iconId, int priority)
{
NotificationData *data = dataForGroup.value(groupId, NULL);
if (data != NULL) {
// Icon ID set: update data
data->first = iconId;
data->second = priority;
checkMostImportantNotification();
}
}

void NotificationStatusIndicatorSink::checkMostImportantNotification()
{
QString iconId;
int highestPriority = -1;

foreach (NotificationData *data, datas) {
if (data->second > highestPriority) {
iconId = data->first;
highestPriority = data->second;
}
}

emit iconIdChanged(iconId);
}
Loading

0 comments on commit ba0babc

Please sign in to comment.