LeechCraft
0.6.70-15082-g543737046d
Modular cross-platform feature rich live environment.
|
Aids in adding actions to notifications. More...
#include "notificationactionhandler.h"
Public Types | |
using | Callback_t = std::function< void()> |
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 *=nullptr) |
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 57 of file notificationactionhandler.h.
using LC::Util::NotificationActionHandler::Callback_t = std::function<void ()> |
Type of functions used as actions in the handler.
Definition at line 71 of file notificationactionhandler.h.
|
explicit |
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 20 of file notificationactionhandler.cpp.
References LC::Entity::Additional_.
void LC::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 34 of file notificationactionhandler.cpp.
void LC::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 26 of file notificationactionhandler.cpp.
|
slot |
Definition at line 39 of file notificationactionhandler.cpp.