![]() |
LeechCraft
0.6.70-10870-g558588d6ec
Modular cross-platform feature rich live environment.
|
Aids in adding actions to notifications. More...
#include "notificationactionhandler.h"
Public Types | |
typedef std::function< void()> | Callback_t |
Type of functions used as actions in the handler. More... | |
Public Slots | |
void | notificationActionTriggered (int) |
Public Member Functions | |
UTIL_XPC_API | NotificationActionHandler (Entity &entity, QObject *=0) |
Creates the handler on the given entity. More... | |
UTIL_XPC_API void | AddFunction (const QString &name, Callback_t action) |
Adds an action with the given name. More... | |
UTIL_XPC_API void | AddDependentObject (QObject *object) |
Adds an object as a dependent object. More... | |
Aids in adding actions to notifications.
This class is used to easily add actions to notification entities created via MakeNotification() or MakeAN() functions. The usage is quite simple and best illustrated by an example:
The entity this handler is created upon takes ownership of the object, so when the last instance of the entity is destroyed this object is destroyed itself. The object should never be explicitly deleted.
Some actions don't make sense if some other object is destroyed after emitting the entity but before the user has reacted to the event. For example, a user in an IRC channel writes to us a message then leaves. In this case the "Reply" action will be invalid and useless.
To avoid this NotificationActionHandler supports dependent objects — objects whose destruction will render its actions useless. Dependent objects are added via the AddDependentObject() method and their lifetime is tracked automatically.
Definition at line 73 of file notificationactionhandler.h.
typedef std::function<void ()> LeechCraft::Util::NotificationActionHandler::Callback_t |
Type of functions used as actions in the handler.
Definition at line 81 of file notificationactionhandler.h.
LeechCraft::Util::NotificationActionHandler::NotificationActionHandler | ( | Entity & | entity, |
QObject * | = 0 |
||
) |
Creates the handler on the given entity.
The entity takes the ownership of the handler.
[in] | entity | The entity to add actions to. |
Definition at line 37 of file notificationactionhandler.cpp.
References LeechCraft::Entity::Additional_.
void LeechCraft::Util::NotificationActionHandler::AddDependentObject | ( | QObject * | object | ) |
Adds an object as a dependent object.
[in] | object | The object actions in this handler depend upon. |
Definition at line 50 of file notificationactionhandler.cpp.
void LeechCraft::Util::NotificationActionHandler::AddFunction | ( | const QString & | name, |
Callback_t | action | ||
) |
Adds an action with the given name.
This function adds an action to this entity. It will be shown under the given name to the user, and when the user selects it, action will be invoked.
[in] | name | The human-readable name of the action. |
[in] | action | The functor to invoke when the user selects the action. |
Definition at line 43 of file notificationactionhandler.cpp.
References LeechCraft::Entity::Additional_.
|
slot |
Definition at line 55 of file notificationactionhandler.cpp.