LeechCraft  0.6.70-15082-g543737046d
Modular cross-platform feature rich live environment.
LC::Util::NotificationActionHandler Class Reference

Aids in adding actions to notifications. More...

#include "notificationactionhandler.h"

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

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

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 57 of file notificationactionhandler.h.

Member Typedef Documentation

◆ Callback_t

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.

Constructor & Destructor Documentation

◆ NotificationActionHandler()

LC::Util::NotificationActionHandler::NotificationActionHandler ( Entity entity,
QObject *  = nullptr 
)
explicit

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 20 of file notificationactionhandler.cpp.

References LC::Entity::Additional_.

Member Function Documentation

◆ AddDependentObject()

void LC::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 34 of file notificationactionhandler.cpp.

◆ AddFunction()

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.

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

Definition at line 26 of file notificationactionhandler.cpp.

◆ notificationActionTriggered

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

Definition at line 39 of file notificationactionhandler.cpp.


The documentation for this class was generated from the following files:
LC::Util::MakeNotification
Entity MakeNotification(const QString &header, const QString &text, Priority priority)
An utility function to make a Entity with notification.
Definition: util.cpp:95