Wt  4.13.0
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Static Public Member Functions | List of all members
Wt::WNotification Class Reference

A class that represent a notification. More...

#include <Wt/WNotification.h>

Inheritance diagram for Wt::WNotification:
[legend]

Public Types

enum class  Permission { Default , Granted , Denied }
 Enumeration representing the permission status of notifications. More...
 
- Public Types inherited from Wt::WObject
typedef void(WObject::* Method) ()
 Typedef for a WObject method without arguments.
 

Public Member Functions

 WNotification (const WString &title=WString(), const WString &body=WString())
 Creates a new notification.
 
void setTitle (const WString &title)
 Sets the title of the notification.
 
WString title () const
 Returns the title of the notification.
 
void setBody (const WString &body)
 Sets the body of the notification.
 
WString body () const
 Returns the body of the notification.
 
void setIcon (const WLink &iconLink)
 Sets the link to the notification's icon.
 
WLink icon () const
 Returns the link to the notification's icon.
 
void setBadge (const WLink &badgeLink)
 Sets the link to the notification's badge.
 
WLink badge () const
 Returns the link to the notification's badge.
 
void setSilent (bool enable=true)
 Sets whether the notification should be silent or not.
 
bool silent () const
 Returns whether the notification should be silent or not.
 
void setRequireInteraction (bool enable=true)
 Sets whether the notification require interaction to become inactive or not.
 
bool requireInteraction () const
 Returns whether the notification require interaction to become inactive or not.
 
void send ()
 Sends the notification.
 
void close ()
 Closes the notification.
 
JSignalclicked ()
 Signal emitted when the notification is clicked.
 
JSignalclosed ()
 Signal emitted when the notification is closed.
 
JSignalshown ()
 Signal emitted when the notification is shown.
 
JSignalerror ()
 Signal emitted when the notification was not shown due to an error.
 
- Public Member Functions inherited from Wt::WObject
void addChild (std::unique_ptr< WObject > child)
 Add a child WObject whose lifetime is determined by this WObject.
 
template<typename Child >
ChildaddChild (std::unique_ptr< Child > child)
 Add a child WObject, returning a raw pointer.
 
std::unique_ptr< WObjectremoveChild (WObject *child)
 Remove a child WObject, so its lifetime is no longer determined by this WObject.
 
template<typename Child >
std::unique_ptr< ChildremoveChild (Child *child)
 Remove a child WObject, so its lifetime is no longer determined by this WObject.
 
virtual const std::string id () const
 Returns the (unique) identifier for this object.
 
virtual void setObjectName (const std::string &name)
 Sets an object name.
 
virtual std::string objectName () const
 Returns the object name.
 
void resetLearnedSlots ()
 Resets learned stateless slot implementations.
 
template<class T >
void resetLearnedSlot (void(T::*method)())
 Resets a learned stateless slot implementation.
 
template<class T >
WStatelessSlot * implementStateless (void(T::*method)())
 Declares a slot to be stateless and learn client-side behaviour on first invocation.
 
template<class T >
WStatelessSlot * implementStateless (void(T::*method)(), void(T::*undoMethod)())
 Declares a slot to be stateless and learn client-side behaviour in advance.
 
void isNotStateless ()
 Marks the current function as not stateless.
 
template<class T >
WStatelessSlot * implementJavaScript (void(T::*method)(), const std::string &jsCode)
 Provides a JavaScript implementation for a method.
 
virtual bool resendFormData ()
 Returns whether the form data should be resent.
 
- Public Member Functions inherited from Wt::Core::observable
 observable () noexcept
 Default constructor.
 
virtual ~observable ()
 Destructor.
 
template<typename... Args, typename C >
auto bindSafe (void(C::*method)(Args...)) noexcept
 Protects a method call against object destruction.
 
template<typename... Args, typename C >
auto bindSafe (void(C::*method)(Args...) const) const noexcept
 Protects a const method call against object destruction.
 
template<typename Function >
auto bindSafe (const Function &function) noexcept
 Protects a function against object destruction.
 

Static Public Member Functions

static void setDefaultIcon (const WLink &iconLink)
 Sets the link to the notifications default icon.
 
static WLink defaultIcon ()
 Returns the link to the notifications default icon.
 
static void setDefaultBadge (const WLink &badgeLink)
 Sets the link to the notifications default badge.
 
static WLink defaultBadge ()
 Returns the link to the notifications default badge.
 
static bool supported ()
 Returns whether the user supports notifications or not.
 
static void askPermission ()
 Ask permission to send notifications to the user.
 
static Permission permission ()
 Returns the status of the permission to send notifications.
 
static Signal< Permission > & permissionUpdated ()
 Signal emitted when the permission to send notification has been updated.
 

Additional Inherited Members

- Protected Member Functions inherited from Wt::WObject
virtual WStatelessSlot * getStateless (Method method)
 On-demand stateless slot implementation.
 

Detailed Description

A class that represent a notification.

A notification is a message sent to the user that can be read from outside the webpage. For a page to be allowed to send notifications, permission must be explicitly given by the user to the application. The permission can be asked to the user with askPermission() or will be asked automatically the first time send() is called in the application. It is possible to listen to the permissionUpdated() signal to react to the user granting or denying permission to send notifications.

If the user has previously granted permission to the page to display notifications, the browser will remember it, and Wt will not ask for that permission again.

The WNotification will not be sent to the user if the permission has not yet been granted. Instead, the notification will wait for the user to accept notifications before being sent. This will however not happen if the notification was closed or destroyed.

A WNotification represents a notification with a tag. The value of this tag is the id of the WNotification. If the same WNotification is sent multiple times, this will update the notification instead of creating a new one, as long as it was not closed.

You can react to a notification being closed or clicked by listening to the closed() and clicked() signals, this does however require that the WNotification has not been destroyed before the event happens.

Notifications can have an icon and a badge. Those can be set using setIcon() and setBadge(), but since these are likely the same for all the notifications sent by your application, it is possible to set a default icon and a default badge for all notifications with setDefaultIcon() and setDefaultBadge().

See also
send(), close()
Note
Sending notifications requires that:
  • JavaScript is enabled
  • the browser supports notifications
  • HTTPS is used

Member Enumeration Documentation

◆ Permission

Enumeration representing the permission status of notifications.

For an application to show notifications, it must first ask the authorization of the user. This enumeration represent the different possible permisson status that the application can have.

Enumerator
Default 

Permission not yet denied or granted by the user. Notifications won't be displayed.

Granted 

Permission granted by the user. Notifications can be displayed.

Denied 

Permission denied by the user. Notifications won't be displayed.

Constructor & Destructor Documentation

◆ WNotification()

Wt::WNotification::WNotification ( const WString title = WString(),
const WString body = WString() 
)
explicit

Creates a new notification.

Creates a new notification with the given title and body.

Member Function Documentation

◆ askPermission()

void Wt::WNotification::askPermission ( )
static

Ask permission to send notifications to the user.

This ask permission to the user to send notifications. This will only be done once per application. More calls to this function will not do anything.

See also
permissionUpdated()
Note
Browsers ignores this if the permission is already denied or granted.

◆ badge()

WLink Wt::WNotification::badge ( ) const

Returns the link to the notification's badge.

Returns the link to the notification's badge.

By default, the badge is set to the default badge.

See also
setBadge(), setDefaultBadge()

◆ body()

WString Wt::WNotification::body ( ) const

Returns the body of the notification.

Returns the body of the notification or an empty string if the notification has no body.

See also
setBody()

◆ close()

void Wt::WNotification::close ( )

Closes the notification.

Closes the notification. This does nothing if the notification was not sent or was already closed.

See also
send()

◆ defaultBadge()

static WLink Wt::WNotification::defaultBadge ( )
static

Returns the link to the notifications default badge.

See also
setDefaultBadge()

◆ defaultIcon()

static WLink Wt::WNotification::defaultIcon ( )
static

Returns the link to the notifications default icon.

See also
setDefaultIcon()

◆ icon()

WLink Wt::WNotification::icon ( ) const

Returns the link to the notification's icon.

Returns the link to the notification's icon or a null link if the notification uses the default icon.

By default, the icon is set to the default icon.

See also
setIcon()

◆ permission()

WNotification::Permission Wt::WNotification::permission ( )
static

Returns the status of the permission to send notifications.

See also
askPermission()

◆ permissionUpdated()

Signal< WNotification::Permission > & Wt::WNotification::permissionUpdated ( )
static

Signal emitted when the permission to send notification has been updated.

Signal emitted when the permission to send notification has been updated. This happens when the user answered to askPermission(), and the new permission status is given by the signal as parameter to all connected functions.

See also
askPermission()

◆ requireInteraction()

bool Wt::WNotification::requireInteraction ( ) const

Returns whether the notification require interaction to become inactive or not.

See also
setRequireInteraction()

◆ send()

void Wt::WNotification::send ( )

Sends the notification.

Sends the notification to the user. This only happens if the permission to send notification has been granted by the user.

In case the user has not denied or granted notification to the user, the first call to send will instead ask for permission to send notification. The notification will then be sent after the user granted permission to send notification, unless this notification was closed or destroyed.

Calling send() multiple times on the same notification will not create multiple notification but replace the previous with the new one, as long as the previous one has not been closed. This means that the user will not be notified again for this notification unless the previous one has been closed.

See also
close()

◆ setBadge()

void Wt::WNotification::setBadge ( const WLink badgeLink)

Sets the link to the notification's badge.

This sets the link to the notification's badge which is the image displayed when there is not enough space to display the notification.

By default, the badge is set to the default badge.

See also
setDefaultBadge()

◆ setBody()

void Wt::WNotification::setBody ( const WString body)

Sets the body of the notification.

This sets the body of the notification.

By default, the notification has no body, which is represented by an empty string.

◆ setDefaultBadge()

void Wt::WNotification::setDefaultBadge ( const WLink badgeLink)
static

Sets the link to the notifications default badge.

By default, this is a null link which means no default badge is used.

See also
setBadge()

◆ setDefaultIcon()

void Wt::WNotification::setDefaultIcon ( const WLink iconLink)
static

Sets the link to the notifications default icon.

By default, this is a null link which means no default icon is used.

See also
setIcon()

◆ setIcon()

void Wt::WNotification::setIcon ( const WLink iconLink)

Sets the link to the notification's icon.

This sets the link to the notification's icon which is the image displayed on the left of the notification.

By default, the icon is set to the default icon.

See also
setDefaultIcon()

◆ setRequireInteraction()

void Wt::WNotification::setRequireInteraction ( bool  enable = true)

Sets whether the notification require interaction to become inactive or not.

This sets whether the notification should remain active until the user click's on it or dismiss it.

By default, this is set to false.

◆ setSilent()

void Wt::WNotification::setSilent ( bool  enable = true)

Sets whether the notification should be silent or not.

This sets whether the notification should be silent or not. A silent notification will not make any noise or vibration.

By default, the notification is not silent.

Note
A non silent notification may still make no noise or vibration as it will respect the user's configuration.

◆ setTitle()

void Wt::WNotification::setTitle ( const WString title)

Sets the title of the notification.

This sets the title of the notification.

By default, the title is an empty string.

◆ silent()

bool Wt::WNotification::silent ( ) const

Returns whether the notification should be silent or not.

See also
setSilent()

◆ title()

WString Wt::WNotification::title ( ) const

Returns the title of the notification.

See also
setTitle()