Home · All Namespaces · All Classes
Public Slots | Signals | Public Member Functions | Protected Slots

NotificationManager Class Reference

#include <notificationmanager.h>

Inheritance diagram for NotificationManager:
Inheritance graph
[legend]
Collaboration diagram for NotificationManager:
Collaboration graph
[legend]

List of all members.

Public Slots

uint addNotification (uint notificationUserId, const NotificationParameters &parameters=NotificationParameters(), uint groupId=0)
 REIMPLEMENTATION
bool updateNotification (uint notificationUserId, uint notificationId, const NotificationParameters &parameters=NotificationParameters())
bool removeNotification (uint notificationUserId, uint notificationId)
uint addGroup (uint notificationUserId, const NotificationParameters &parameters=NotificationParameters())
bool updateGroup (uint notificationUserId, uint groupId, const NotificationParameters &parameters=NotificationParameters())
bool removeGroup (uint notificationUserId, uint groupId)
uint notificationUserId ()
QList< uint > notificationIdList (uint notificationUserId)
QList< MNotificationProxynotificationList (uint notificationUserId)
QList
< MNotificationWithIdentifierProxy
notificationListWithIdentifiers (uint notificationUserId)
QList< MNotificationGroupProxynotificationGroupList (uint notificationUserId)
QList
< MNotificationGroupWithIdentifierProxy
notificationGroupListWithIdentifiers (uint notificationUserId)
bool removeNotification (uint notificationId)
 
bool removeNotificationsInGroup (uint groupId)
void removeNotificationsAndGroupsWithEventType (const QString &eventType)
void updateNotificationsWithEventType (const QString &eventType)
 Update event type data of all notifications with the specified event type.

Signals

void notificationUpdated (const Notification &notification)
void notificationRemoved (uint notificationId)
void groupUpdated (uint groupId, const NotificationParameters &parameters)
void groupRemoved (uint groupId)
void notificationRestored (const Notification &notification)

Public Member Functions

 NotificationManager (int relayInterval=3000, uint maxWaitQueueSize=100)
virtual ~NotificationManager ()
void restorePersistentData ()

Protected Slots

void relayNextNotification ()
void removeUnseenFlags (bool ignore)

Detailed Description

The NotificationManager allows a program to display a notification, update the contents of a notification and cancel a notification.

Definition at line 48 of file notificationmanager.h.


Constructor & Destructor Documentation

NotificationManager::NotificationManager ( int  relayInterval = 3000,
uint  maxWaitQueueSize = 100 
)

Creates a new NotificationManager.

Parameters:
relayInterval Time interval in milliseconds between relaying submitted notifications from this NotificationManager onwards to entities connected to notificationUpdated() signal. If this timeout is zero this NotificationManager will pass through all notifications sent using displayNotification() immediatelly. If this interval is negative the relay interval is infinite. Its then on the responsibility of a derived class to call relayNextNotification() when next notification should be relayed.
maxWaitQueueSize The maximum amount of notifications that can be store in this NotificationManager's wait queue awaiting their turn to be relayed to entities connected to notificationUpdated(). Any incoming notification sent through addNotification() when wait queue is full is dropped.

Definition at line 48 of file notificationmanager.cpp.

                                                                                 :
    notifications(),
    groups(),
    maxWaitQueueSize(maxWaitQueueSize),
    notificationInProgress(false),
    relayInterval(relayInterval),
    context(new ContextFrameworkContext()),
    lastUsedNotificationUserId(0),
    persistentDataRestored(false)
#ifdef HAVE_AEGIS_CRYPTO
    , persistentStorage(new aegis::storage("com.meego.core.MNotificationManager", aegis::storage::vis_private, aegis::storage::prot_encrypted))
#endif
{
    dBusSource = new DBusInterfaceNotificationSource(*this);
    dBusSink = new DBusInterfaceNotificationSink;

    connect(this, SIGNAL(groupUpdated(uint, const NotificationParameters &)), dBusSink, SLOT(addGroup(uint, const NotificationParameters &)));
    connect(this, SIGNAL(groupRemoved(uint)), dBusSink, SLOT(removeGroup(uint)));
    connect(this, SIGNAL(notificationRemoved(uint)), dBusSink, SLOT(removeNotification(uint)));
    connect(this, SIGNAL(notificationRestored(const Notification &)), dBusSink, SLOT(addNotification(const Notification &)));
    connect(this, SIGNAL(notificationUpdated(const Notification &)), dBusSink, SLOT(addNotification(const Notification &)));
    connect(dBusSink, SIGNAL(notificationRemovalRequested(uint)), this, SLOT(removeNotification(uint)));
    connect(dBusSink, SIGNAL(notificationGroupClearingRequested(uint)), this, SLOT(removeNotificationsInGroup(uint)));

    waitQueueTimer.setSingleShot(true);
    connect(&waitQueueTimer, SIGNAL(timeout()), this, SLOT(relayNextNotification()));

    if (!QDir::root().exists(PERSISTENT_DATA_PATH)) {
        // No data to restore exists yet
        persistentDataRestored = true;
    }

    //Initialize the event type store
    initializeEventTypeStore();

    // Connect to D-Bus and register the DBus source as an object
    QDBusConnection::sessionBus().registerService("com.meego.core.MNotificationManager");
    QDBusConnection::sessionBus().registerObject("/notificationmanager", dBusSource);
    QDBusConnection::sessionBus().registerObject("/notificationsinkmanager", dBusSink);
}

Here is the call graph for this function:

NotificationManager::~NotificationManager (  )  [virtual]

Destroys the NotificationManager.

Definition at line 89 of file notificationmanager.cpp.

{
    delete dBusSource;
    delete dBusSink;
    delete context;
}


Member Function Documentation

uint NotificationManager::addGroup ( uint  notificationUserId,
const NotificationParameters parameters = NotificationParameters() 
) [virtual, slot]

Adds a new notification group. Later on notifications can be added to this group.

Parameters:
notificationUserId the ID of the user of notifications
parameters Parameters for the notification group
Returns:
the new group id.

Implements NotificationManagerInterface.

Definition at line 368 of file notificationmanager.cpp.

{
    bool persistent = determinePersistence(parameters);
    restorePersistentData();

    NotificationParameters fullParameters(appendEventTypeParameters(parameters));

    uint groupID = nextAvailableGroupID();
    NotificationGroup group(groupID, notificationUserId, fullParameters);
    groups.insert(groupID, group);

    if (persistent) {
        persistentGroups.insert(groupID);
    }

    saveStateData();

    emit groupUpdated(groupID, fullParameters);

    return groupID;
}

Here is the call graph for this function:

uint NotificationManager::addNotification ( uint  notificationUserId,
const NotificationParameters parameters = NotificationParameters(),
uint  groupId = 0 
) [virtual, slot]

REIMPLEMENTATION

Implements NotificationManagerInterface.

Definition at line 257 of file notificationmanager.cpp.

{
    restorePersistentData();

    if (groupId == 0 || groups.contains(groupId)) {
        bool persistent = determinePersistence(parameters);
        uint notificationId = nextAvailableNotificationID();

        NotificationParameters fullParameters(appendEventTypeParameters(parameters));
        fullParameters.add("timestamp", QDateTime::currentDateTimeUtc());
        Notification notification(notificationId, groupId, notificationUserId, fullParameters, determineType(fullParameters), relayInterval);

        // Mark the notification used
        notifications.insert(notificationId, notification);

        // If a group is persistent, all the notifications in the group are persistent too
        if (persistent || persistentGroups.contains(groupId)) {
            persistentNotifications.insert(notificationId);
            savePersistentNotifications();
        }

        submitNotification(notification);

        return notificationId;
    }

    return 0;
}

Here is the call graph for this function:

void NotificationManager::groupRemoved ( uint  groupId  )  [signal]

A signal for notifying that a notification group has been removed.

Parameters:
groupId the ID of the notification group to be removed
void NotificationManager::groupUpdated ( uint  groupId,
const NotificationParameters parameters 
) [signal]

A signal for notifying that the contents of a notification group has changed. The group can be a new group or a pre-existing group.

Parameters:
groupId The ID of the notification group
parameters NotificationParameters for the group
QList< MNotificationGroupProxy > NotificationManager::notificationGroupList ( uint  notificationUserId  )  [virtual, slot]

Returns list of notification groups by user id

Parameters:
notificationUserId the ID of the user of notifications
Returns:
list of notification groups that belong to notificationUserId

Implements NotificationManagerInterface.

Definition at line 500 of file notificationmanager.cpp.

{
    QList<MNotificationGroupProxy> userGroups;

    foreach(const NotificationGroup & group, groups) {
        if (group.userId() == notificationUserId) {
            MNotificationGroupProxy mnotificationgroup(group);
            userGroups.append(mnotificationgroup);
        }
    }

    return userGroups;
}

Here is the call graph for this function:

QList< MNotificationGroupWithIdentifierProxy > NotificationManager::notificationGroupListWithIdentifiers ( uint  notificationUserId  )  [virtual, slot]

Returns list of notification groups with identifiers by user id

Parameters:
notificationUserId the ID of the user of notifications
Returns:
list of notification groups with identifiers that belong to notificationUserId

Implements NotificationManagerInterface.

Definition at line 514 of file notificationmanager.cpp.

{
    QList<MNotificationGroupWithIdentifierProxy> userGroups;

    foreach(const NotificationGroup & group, groups) {
        if (group.userId() == notificationUserId) {
            MNotificationGroupWithIdentifierProxy mnotificationgroup(group);
            userGroups.append(mnotificationgroup);
        }
    }

    return userGroups;
}

Here is the call graph for this function:

QList< uint > NotificationManager::notificationIdList ( uint  notificationUserId  )  [virtual, slot]

Returns list of notification ids by user id

Parameters:
notificationUserId the ID of the user of notifications
Returns:
list of notification ids that belong to notificationUserId

Implements NotificationManagerInterface.

Definition at line 458 of file notificationmanager.cpp.

{
    QList<uint> listOfNotificationIds;

    foreach(const Notification & notification, notifications) {
        if (notification.userId() == notificationUserId) {
            listOfNotificationIds.append(notification.notificationId());
        }
    }

    return listOfNotificationIds;
}

Here is the call graph for this function:

QList< MNotificationProxy > NotificationManager::notificationList ( uint  notificationUserId  )  [virtual, slot]

Returns list of notifications by user id

Parameters:
notificationUserId the ID of the user of notifications
Returns:
list of notifications that belong to notificationUserId

Implements NotificationManagerInterface.

Definition at line 472 of file notificationmanager.cpp.

{
    QList<MNotificationProxy> userNotifications;

    foreach(const Notification & notification, notifications) {
        if (notification.userId() == notificationUserId) {
            MNotificationProxy mnotification(notification);
            userNotifications.append(mnotification);
        }
    }

    return userNotifications;
}

Here is the call graph for this function:

QList< MNotificationWithIdentifierProxy > NotificationManager::notificationListWithIdentifiers ( uint  notificationUserId  )  [virtual, slot]

Returns list of notifications with identifiers by user id

Parameters:
notificationUserId the ID of the user of notifications
Returns:
list of notifications with identifiers that belong to notificationUserId

Implements NotificationManagerInterface.

Definition at line 486 of file notificationmanager.cpp.

{
    QList<MNotificationWithIdentifierProxy> userNotificationsWithIdentifers;

    foreach(const Notification & notification, notifications) {
        if (notification.userId() == notificationUserId) {
            MNotificationWithIdentifierProxy mnotification(notification);
            userNotificationsWithIdentifers.append(mnotification);
        }
    }

    return userNotificationsWithIdentifers;
}

Here is the call graph for this function:

void NotificationManager::notificationRemoved ( uint  notificationId  )  [signal]

A signal for notifying that a certain notification has been removed.

Parameters:
notificationId the ID of the notification to be removed
void NotificationManager::notificationRestored ( const Notification notification  )  [signal]

A signal for notifying that a pre-existing notification has been restored from the persistent storage.

Parameters:
notification the data of the notification
void NotificationManager::notificationUpdated ( const Notification notification  )  [signal]

A signal for notifying that the contents of a notification has changed. The notification can be a new notification or a pre-existing notification.

Parameters:
notification the data of the notification
uint NotificationManager::notificationUserId (  )  [virtual, slot]

Returns a user ID for the notification system. The user ID has to be supplied with every notification system call.

Returns:
a user ID for the notification system

Implements NotificationManagerInterface.

Definition at line 448 of file notificationmanager.cpp.

{
    restorePersistentData();

    lastUsedNotificationUserId++;
    saveStateData();

    return lastUsedNotificationUserId;
}

Here is the call graph for this function:

void NotificationManager::relayNextNotification (  )  [protected, slot]

Slot called to relay next notification from the notifications queue of this NotificationManager. This slot is called automatically periodically with the given relay interval if the relay interval is given in the constructor. If negative relay interval was specified in the constructor of this NotificationManager then this slot has to be called manually by an inherited NotificationManager. Every call to this slot will relay the first notification in the notification queue. This will initiate the sequence of emitting the addNotification() signal of this object and invoke any entity connected to this NotificationManager.

Definition at line 528 of file notificationmanager.cpp.

{
    notificationInProgress = false;
    if (!waitQueue.isEmpty()) {
        submitNotification(waitQueue.takeFirst());
    }
}

bool NotificationManager::removeGroup ( uint  notificationUserId,
uint  groupId 
) [virtual, slot]

Removes a notification group.

Parameters:
notificationUserId the ID of the user of notifications
groupId The ID of the notification group to be removed.
Returns:
true if the removal succeeded, false otherwise

Implements NotificationManagerInterface.

Definition at line 411 of file notificationmanager.cpp.

{
    restorePersistentData();

    if (groups.remove(groupId)) {
        foreach(const Notification & notification, notifications) {
            if (notification.groupId() == groupId) {
                removeNotification(notificationUserId, notification.notificationId());
            }
        }

        if (persistentGroups.contains(groupId)) {
            persistentGroups.remove(groupId);
        }

        saveStateData();

        emit groupRemoved(groupId);

        return true;
    } else {
        return false;
    }
}

Here is the call graph for this function:

bool NotificationManager::removeNotification ( uint  notificationUserId,
uint  notificationId 
) [virtual, slot]

Removes a notification.

Parameters:
notificationUserId the ID of the user of notifications
notificationId The ID of the notification to be removed.
Returns:
true if the removal succeeded, false otherwise

Implements NotificationManagerInterface.

Definition at line 317 of file notificationmanager.cpp.

{
    Q_UNUSED(notificationUserId);

    return removeNotification(notificationId);
}

bool NotificationManager::removeNotification ( uint  notificationId  )  [slot]

Removes a notification. This slot is for the sinks so they can remove notifications without needing to know the notification user ID.

Parameters:
notificationId The ID of the notification to be removed.
Returns:
true if the removal succeeded, false otherwise

Definition at line 324 of file notificationmanager.cpp.

{
    restorePersistentData();

    if (notifications.contains(notificationId)) {
        // Mark the notification unused
        notifications.take(notificationId);

        if (persistentNotifications.contains(notificationId)) {
            persistentNotifications.remove(notificationId);
            savePersistentNotifications();
        }

        int waitQueueIndex = findNotificationFromWaitQueue(notificationId);
        if (waitQueueIndex >= 0) {
            waitQueue.removeAt(waitQueueIndex);
        } else {
            // Inform the sinks about the removal
            emit notificationRemoved(notificationId);
        }

        return true;
    } else {
        return false;
    }
}

Here is the call graph for this function:

void NotificationManager::removeNotificationsAndGroupsWithEventType ( const QString &  eventType  )  [slot]

Removes all notifications and groups with the specified event type

Parameters:
eventType the event type of the notifications and groups to remove

Definition at line 230 of file notificationmanager.cpp.

{
    foreach(const Notification &notification, notifications) {
        if(notification.parameters().value(GenericNotificationParameterFactory::eventTypeKey()).
           toString() == eventType) {
            removeNotification(notification.notificationId());
        }
    }

    foreach(const NotificationGroup &group, groups) {
        if(group.parameters().value(GenericNotificationParameterFactory::eventTypeKey()).
           toString() == eventType) {
            removeGroup(0, group.groupId());
        }
    }
}

Here is the call graph for this function:

bool NotificationManager::removeNotificationsInGroup ( uint  groupId  )  [slot]

Removes all notifications from a group. This slot is for the sinks so they can remove notifications without needing to know the notification user ID.

Parameters:
groupId The ID of the group from which notifications should be removed.
Returns:
true if the removal succeeded, false otherwise

Definition at line 351 of file notificationmanager.cpp.

{
    QList<uint> notificationIds;

    foreach(const Notification & notification, notifications.values()) {
        if (notification.groupId() == groupId) {
            notificationIds.append(notification.notificationId());
        }
    }

    bool result = !notificationIds.isEmpty();
    foreach(uint notificationId, notificationIds) {
        result &= removeNotification(notificationId);
    }
    return result;
}

Here is the call graph for this function:

void NotificationManager::removeUnseenFlags ( bool  ignore  )  [protected, slot]

Slot for setting unseen flags of all notifications to false.

Parameters:
ignore true if ignore the call false to remove the flags

Definition at line 626 of file notificationmanager.cpp.

{
    if (!ignore) {
        QHash<uint, Notification>::iterator it = notifications.begin();
        while (it != notifications.end()) {
            NotificationParameters newParameters = (*it).parameters();
            newParameters.add(GenericNotificationParameterFactory::unseenKey(), QVariant(false));
            (*it).setParameters(newParameters);
            ++it;
        }
        // Change the states in the filestore
        savePersistentNotifications();
    }
}

Here is the call graph for this function:

void NotificationManager::restorePersistentData (  ) 

Restore persistent data.

Restores the saved groups and persistent notifications and sends the respective notificationUpdated and groupUpdated signals.

Definition at line 158 of file notificationmanager.cpp.

{
#ifdef HAVE_AEGIS_CRYPTO
    if (!persistentDataRestored && ensurePersistentDataPath()) {
        RAWDATA_PTR data;
        size_t dataLength;

        // The persistent storage automatically verifies the data.
        // If the data is corrupted or tampered with, the previous state
        // is lost and there's nothing we can do.
        persistentDataRestored = true;

        if (persistentStorage->contains_file(STATE_DATA_FILE_NAME.toAscii()) &&
                persistentStorage->get_file(STATE_DATA_FILE_NAME.toAscii(), &data, &dataLength) == 0) {

            QBuffer buffer;
            buffer.setData((char *)data, dataLength);
            buffer.open(QIODevice::ReadOnly);
            persistentStorage->release_buffer(data);

            QDataStream stream(&buffer);

            stream >> lastUsedNotificationUserId;
            stream >> persistentGroups;

            NotificationGroup group;

            while (!stream.atEnd()) {
                stream >> group;
                groups.insert(group.groupId(), group);
                emit groupUpdated(group.groupId(), group.parameters());
            }
        }

        if (persistentStorage->contains_file(NOTIFICATIONS_FILE_NAME.toAscii()) &&
                persistentStorage->get_file(NOTIFICATIONS_FILE_NAME.toAscii(), &data, &dataLength) == 0) {

            QBuffer buffer;
            buffer.setData((char *)data, dataLength);
            buffer.open(QIODevice::ReadOnly);
            persistentStorage->release_buffer(data);

            QDataStream stream(&buffer);

            Notification notification;

            while (!stream.atEnd()) {
                stream >> notification;
                notifications.insert(notification.notificationId(), notification);
                // Notifications in the persistent storage must have been persistent before
                persistentNotifications.insert(notification.notificationId());
                emit notificationRestored(notification);
            }
        }
    }
#endif
}

Here is the call graph for this function:

bool NotificationManager::updateGroup ( uint  notificationUserId,
uint  groupId,
const NotificationParameters parameters = NotificationParameters() 
) [virtual, slot]

Updates the contents of a notification group.

Parameters:
notificationUserId the ID of the user of notifications
groupId The ID of the notification group to be updated
parameters Parameters for the notification group
Returns:
true if the update succeeded, false otherwise

Implements NotificationManagerInterface.

Definition at line 390 of file notificationmanager.cpp.

{
    Q_UNUSED(notificationUserId);

    restorePersistentData();

    QHash<uint, NotificationGroup>::iterator gi = groups.find(groupId);

    if (gi != groups.end()) {
        gi->updateParameters(parameters);

        saveStateData();

        emit groupUpdated(groupId, gi->parameters());

        return true;
    } else {
        return false;
    }
}

Here is the call graph for this function:

bool NotificationManager::updateNotification ( uint  notificationUserId,
uint  notificationId,
const NotificationParameters parameters = NotificationParameters() 
) [virtual, slot]

Updates a notification.

Parameters:
notificationUserId the ID of the user of notifications
notificationId The ID of the notification to be updated
parameters Parameters for the notification
Returns:
true if the update succeeded, false otherwise

Implements NotificationManagerInterface.

Definition at line 286 of file notificationmanager.cpp.

{
    Q_UNUSED(notificationUserId);

    restorePersistentData();

    QHash<uint, Notification>::iterator ni = notifications.find(notificationId);

    if (ni != notifications.end()) {
        (*ni).updateParameters(parameters);

        // Also checks if the notification's group is persistent
        if (persistentNotifications.contains(notificationId) ||
                persistentGroups.contains((*ni).groupId())) {
            savePersistentNotifications();
        }

        int waitQueueIndex = findNotificationFromWaitQueue(notificationId);
        if (waitQueueIndex >= 0) {
            waitQueue[waitQueueIndex].updateParameters(parameters);
        } else {
            // Inform the sinks about the update
            emit notificationUpdated(notifications.value(notificationId));
        }

        return true;
    } else {
        return false;
    }
}

Here is the call graph for this function:

void NotificationManager::updateNotificationsWithEventType ( const QString &  eventType  )  [slot]

Update event type data of all notifications with the specified event type.

Sends a notificationUpdated(Notification &) signal for all notifications of specified type so that sinks can update the event type data from the event type store

Parameters:
eventType the event type of the notifications to update

Definition at line 247 of file notificationmanager.cpp.

{
    foreach(const Notification &notification, notifications) {
        if(notification.parameters().value(GenericNotificationParameterFactory::eventTypeKey()).
           toString() == eventType) {
            updateNotification(notification.userId(), notification.notificationId(), notification.parameters());
        }
    }
}

Here is the call graph for this function:


The documentation for this class was generated from the following files:

Copyright © 2010 Nokia Corporation Generated on Thu Nov 4 2010 18:19:35
Doxygen 1.7.1
MeeGo Touch