LeechCraft  0.6.70-10870-g558588d6ec
Modular cross-platform feature rich live environment.
LeechCraft::Util::NotificationActionHandler Class Reference

Aids in adding actions to notifications. More...

#include "notificationactionhandler.h"

+ Inheritance diagram for LeechCraft::Util::NotificationActionHandler:
+ Collaboration diagram for LeechCraft::Util::NotificationActionHandler:

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...
 

Detailed Description

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:

auto e = Util::MakeNotification ("Header", "Title", PInfo_);
auto nah = new Util::NotificationActionHandler (e);
nah->AddFunction ("Open file", [fileURL] () { QDesktopServices::openUrl (fileURL); });

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.

Note
Only one handler can be created on an entity. If multiple handlers are created, the last one is used.
See also
MakeNotification(), MakeAN().

Definition at line 73 of file notificationactionhandler.h.

Member Typedef Documentation

◆ Callback_t

Type of functions used as actions in the handler.

Definition at line 81 of file notificationactionhandler.h.

Constructor & Destructor Documentation

◆ NotificationActionHandler()

LeechCraft::Util::NotificationActionHandler::NotificationActionHandler ( Entity entity,
QObject *  = 0 
)

Creates the handler on the given entity.

The entity takes the ownership of the handler.

Parameters
[in]entityThe entity to add actions to.

Definition at line 37 of file notificationactionhandler.cpp.

References LeechCraft::Entity::Additional_.

Member Function Documentation

◆ AddDependentObject()

void LeechCraft::Util::NotificationActionHandler::AddDependentObject ( QObject *  object)

Adds an object as a dependent object.

Parameters
[in]objectThe object actions in this handler depend upon.

Definition at line 50 of file notificationactionhandler.cpp.

◆ AddFunction()

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.

Parameters
[in]nameThe human-readable name of the action.
[in]actionThe functor to invoke when the user selects the action.

Definition at line 43 of file notificationactionhandler.cpp.

References LeechCraft::Entity::Additional_.

◆ notificationActionTriggered

void LeechCraft::Util::NotificationActionHandler::notificationActionTriggered ( int  idx)
slot

Definition at line 55 of file notificationactionhandler.cpp.


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