KNotification

Search for usage in LXR

#include <KNotification>

Inheritance diagram for KNotification:

Public Types

typedef QPair< QString, QStringContext
 
typedef QList< ContextContextList
 
enum  NotificationFlag {
  RaiseWidgetOnActivation = 0x01, CloseOnTimeout = 0x00, Persistent = 0x02, CloseWhenWidgetActivated = 0x04,
  LoopSound = 0x08, SkipGrouping = 0x10, DefaultEvent = 0xF000
}
 
typedef QFlags< NotificationFlagNotificationFlags
 
enum  StandardEvent { Notification, Warning, Error, Catastrophe }
 
enum  Urgency {
  DefaultUrgency = -1, LowUrgency = 10, NormalUrgency = 50, HighUrgency = 70,
  CriticalUrgency = 90
}
 

Properties

QStringList actions
 
bool autoDelete
 
QString componentName
 
QString defaultAction
 
QString eventId
 
NotificationFlags flags
 
QVariantMap hints
 
QString iconName
 
QString text
 
QString title
 
Urgency urgency
 
QList< QUrlurls
 
QString xdgActivationToken
 
- Properties inherited from QObject
 objectName
 

Signals

void action1Activated ()
 
void action2Activated ()
 
void action3Activated ()
 
void actionsChanged ()
 
void activated ()
 
void activated (unsigned int action)
 
void autoDeleteChanged ()
 
void closed ()
 
void componentNameChanged ()
 
void defaultActionChanged ()
 
void defaultActivated ()
 
void eventIdChanged ()
 
void flagsChanged ()
 
void hintsChanged ()
 
void iconNameChanged ()
 
void ignored ()
 
void textChanged ()
 
void titleChanged ()
 
void urgencyChanged ()
 
void urlsChanged ()
 
void xdgActivationTokenChanged ()
 

Public Slots

void activate (unsigned int action=0)
 
void close ()
 
void deref ()
 
QVariantMap hints () const
 
void raiseWidget ()
 
void ref ()
 
void sendEvent ()
 
Q_INVOKABLE void setHint (const QString &hint, const QVariant &value)
 
void setHints (const QVariantMap &hints)
 
void update ()
 

Public Member Functions

 KNotification (const QString &eventId)
 
 KNotification (const QString &eventId, const NotificationFlags &flags, QObject *parent=nullptr)
 
 KNotification (const QString &eventId, QWidget *widget, const NotificationFlags &flags=CloseOnTimeout)
 
QStringList actions () const
 
void addContext (const Context &context)
 
void addContext (const QString &context_key, const QString &context_value)
 
QString appName () const
 
QString componentName () const
 
ContextList contexts () const
 
QString defaultAction () const
 
virtual bool event (QEvent *e)
 
QString eventId () const
 
NotificationFlags flags () const
 
QString iconName () const
 
int id ()
 
bool isAutoDelete () const
 
QPixmap pixmap () const
 
KNotificationReplyActionreplyAction () const
 
void setActions (const QStringList &actions)
 
void setAutoDelete (bool autoDelete)
 
void setComponentName (const QString &componentName)
 
void setContexts (const ContextList &contexts)
 
void setDefaultAction (const QString &defaultAction)
 
void setEventId (const QString &eventId)
 
void setFlags (const NotificationFlags &flags)
 
void setIconName (const QString &icon)
 
void setPixmap (const QPixmap &pix)
 
void setReplyAction (std::unique_ptr< KNotificationReplyAction > replyAction)
 
void setText (const QString &text)
 
void setTitle (const QString &title)
 
void setUrgency (Urgency urgency)
 
void setUrls (const QList< QUrl > &urls)
 
void setWidget (QWidget *widget)
 
QString text () const
 
QString title () const
 
Urgency urgency () const
 
QList< QUrlurls () const
 
QWidgetwidget () const
 
QString xdgActivationToken () const
 
- Public Member Functions inherited from QObject
 QObject (QObject *parent)
 
bool blockSignals (bool block)
 
const QObjectListchildren () const const
 
QMetaObject::Connection connect (const QObject *sender, const char *signal, const char *method, Qt::ConnectionType type) const const
 
void deleteLater ()
 
void destroyed (QObject *obj)
 
bool disconnect (const char *signal, const QObject *receiver, const char *method) const const
 
bool disconnect (const QObject *receiver, const char *method) const const
 
void dumpObjectInfo ()
 
void dumpObjectInfo () const const
 
void dumpObjectTree ()
 
void dumpObjectTree () const const
 
QList< QByteArraydynamicPropertyNames () const const
 
virtual bool event (QEvent *e)
 
findChild (const QString &name, Qt::FindChildOptions options) const const
 
QList< T > findChildren (const QRegExp &regExp, Qt::FindChildOptions options) const const
 
QList< T > findChildren (const QRegularExpression &re, Qt::FindChildOptions options) const const
 
QList< T > findChildren (const QString &name, Qt::FindChildOptions options) const const
 
bool inherits (const char *className) const const
 
void installEventFilter (QObject *filterObj)
 
bool isWidgetType () const const
 
bool isWindowType () const const
 
void killTimer (int id)
 
virtual const QMetaObjectmetaObject () const const
 
void moveToThread (QThread *targetThread)
 
QString objectName () const const
 
void objectNameChanged (const QString &objectName)
 
QObjectparent () const const
 
QVariant property (const char *name) const const
 
 Q_CLASSINFO (Name, Value)
 
 Q_DISABLE_COPY (Class)
 
 Q_DISABLE_COPY_MOVE (Class)
 
 Q_DISABLE_MOVE (Class)
 
 Q_EMIT Q_EMIT
 
 Q_ENUM (...)
 
 Q_ENUM_NS (...)
 
 Q_ENUMS (...)
 
 Q_FLAG (...)
 
 Q_FLAG_NS (...)
 
 Q_FLAGS (...)
 
 Q_GADGET Q_GADGET
 
 Q_INTERFACES (...)
 
 Q_INVOKABLE Q_INVOKABLE
 
 Q_NAMESPACE Q_NAMESPACE
 
 Q_NAMESPACE_EXPORT (EXPORT_MACRO)
 
 Q_OBJECT Q_OBJECT
 
 Q_PROPERTY (...)
 
 Q_REVISION Q_REVISION
 
 Q_SET_OBJECT_NAME (Object)
 
 Q_SIGNAL Q_SIGNAL
 
 Q_SIGNALS Q_SIGNALS
 
 Q_SLOT Q_SLOT
 
 Q_SLOTS Q_SLOTS
 
qFindChild (const QObject *obj, const QString &name)
 
QList< T > qFindChildren (const QObject *obj, const QRegExp &regExp)
 
QList< T > qFindChildren (const QObject *obj, const QString &name)
 
qobject_cast (const QObject *object)
 
qobject_cast (QObject *object)
 
 QT_NO_NARROWING_CONVERSIONS_IN_CONNECT QT_NO_NARROWING_CONVERSIONS_IN_CONNECT
 
void removeEventFilter (QObject *obj)
 
void setObjectName (const QString &name)
 
void setParent (QObject *parent)
 
bool setProperty (const char *name, const QVariant &value)
 
bool signalsBlocked () const const
 
int startTimer (int interval, Qt::TimerType timerType)
 
int startTimer (std::chrono::milliseconds time, Qt::TimerType timerType)
 
QThreadthread () const const
 

Static Public Member Functions

static void beep (const QString &reason=QString(), QWidget *widget=nullptr)
 
static KNotificationevent (const QString &eventId, const QString &text=QString(), const QPixmap &pixmap=QPixmap(), QWidget *widget=nullptr, const NotificationFlags &flags=CloseOnTimeout, const QString &componentName=QString())
 
static KNotificationevent (const QString &eventId, const QString &title, const QString &text, const QPixmap &pixmap=QPixmap(), QWidget *widget=nullptr, const NotificationFlags &flags=CloseOnTimeout, const QString &componentName=QString())
 
static KNotificationevent (const QString &eventId, const QString &title, const QString &text, const QString &iconName, QWidget *widget=nullptr, const NotificationFlags &flags=CloseOnTimeout, const QString &componentName=QString())
 
static KNotificationevent (StandardEvent eventId, const QString &text=QString(), const QPixmap &pixmap=QPixmap(), QWidget *widget=nullptr, const NotificationFlags &flags=CloseOnTimeout)
 
static KNotificationevent (StandardEvent eventId, const QString &title, const QString &text, const QPixmap &pixmap, QWidget *widget=nullptr, const NotificationFlags &flags=CloseOnTimeout)
 
static KNotificationevent (StandardEvent eventId, const QString &title, const QString &text, const QString &iconName, QWidget *widget=nullptr, const NotificationFlags &flags=CloseOnTimeout)
 
static KNotificationevent (StandardEvent eventId, const QString &title, const QString &text, QWidget *widget=nullptr, const NotificationFlags &flags=CloseOnTimeout)
 
- Static Public Member Functions inherited from QObject
QMetaObject::Connection connect (const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
 
QMetaObject::Connection connect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method, Qt::ConnectionType type)
 
QMetaObject::Connection connect (const QObject *sender, PointerToMemberFunction signal, const QObject *context, Functor functor, Qt::ConnectionType type)
 
QMetaObject::Connection connect (const QObject *sender, PointerToMemberFunction signal, const QObject *receiver, PointerToMemberFunction method, Qt::ConnectionType type)
 
QMetaObject::Connection connect (const QObject *sender, PointerToMemberFunction signal, Functor functor)
 
bool disconnect (const QMetaObject::Connection &connection)
 
bool disconnect (const QObject *sender, const char *signal, const QObject *receiver, const char *method)
 
bool disconnect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method)
 
bool disconnect (const QObject *sender, PointerToMemberFunction signal, const QObject *receiver, PointerToMemberFunction method)
 
QString tr (const char *sourceText, const char *disambiguation, int n)
 
QString trUtf8 (const char *sourceText, const char *disambiguation, int n)
 

Protected Member Functions

bool eventFilter (QObject *watched, QEvent *event) override
 
- Protected Member Functions inherited from QObject
virtual void childEvent (QChildEvent *event)
 
virtual void connectNotify (const QMetaMethod &signal)
 
virtual void customEvent (QEvent *event)
 
virtual void disconnectNotify (const QMetaMethod &signal)
 
bool isSignalConnected (const QMetaMethod &signal) const const
 
int receivers (const char *signal) const const
 
QObjectsender () const const
 
int senderSignalIndex () const const
 
virtual void timerEvent (QTimerEvent *event)
 

Static Protected Member Functions

static QString standardEventToEventId (StandardEvent event)
 
static QString standardEventToIconName (StandardEvent event)
 

Additional Inherited Members

- Public Attributes inherited from QObject
typedef QObjectList
 

Detailed Description

KNotification is the main class for creating notifications.

Definition at line 32 of file knotification.h.

Member Typedef Documentation

◆ Context

Sometimes the user may want different notifications for the same event, depending the source of the event.

Example, you want to be notified for mails that arrive in your folder "personal inbox" but not for those in "spam" folder

A notification context is a pair of two strings. The first string is a key from what the context is. example "group" or "filter" (not translated). The second is the id of the context. In our example, the group id or the filter id in the applications. These strings are the ones present in the config file, and are in theory not shown in the user interface.

The order of contexts in the list is is important, the most important context should be placed first. They are processed in that order when the notification occurs.

See also
event

Definition at line 119 of file knotification.h.

◆ NotificationFlags

Stores a combination of NotificationFlag values.

Definition at line 181 of file knotification.h.

Member Enumeration Documentation

◆ NotificationFlag

See also
NotificationFlags
Enumerator
RaiseWidgetOnActivation 

When the notification is activated, raise the notification's widget.

This will change the desktop, raise the window, and switch to the tab.

Todo:
doesn't work yet
CloseOnTimeout 

The notification will be automatically closed after a timeout.

(this is the default)

Persistent 

The notification will NOT be automatically closed after a timeout.

You will have to track the notification, and close it with the close function manually when the event is done, otherwise there will be a memory leak

CloseWhenWidgetActivated 

The notification will be automatically closed if the widget() becomes activated.

If the widget is already activated when the notification occurs, the notification will be closed after a small timeout.

This only works if the widget is the toplevel widget

Todo:
make it work with tabulated widget
LoopSound 

The audio plugin will loop the sound until the notification is closed.

SkipGrouping 

Sends a hint to Plasma to skip grouping for this notification.

Since
5.18
DefaultEvent 

The event is a standard kde event, and not an event of the application

Definition at line 125 of file knotification.h.

◆ StandardEvent

default events you can use in the event function

Definition at line 187 of file knotification.h.

◆ Urgency

The urgency of a notification.

Since
5.58
See also
setUrgency

Definition at line 200 of file knotification.h.

Property Documentation

◆ actions

QStringList KNotification::actions
readwrite

Set the list of actions shown in the popup.

The strings passed in that QStringList will be used as labels for those actions, so ideally they should be wrapped in i18n() or tr() calls. In Plasma workspace, these will be shown as buttons inside the notification popup.

The visual representation of actions however depends on the notification server

Parameters
actionsList of strings used as action labels
Since
5.88

Definition at line 64 of file knotification.h.

◆ autoDelete

bool KNotification::autoDelete
readwrite

Sets whether this notification object will be automatically deleted after closing.

This is on by default for C++, and off by default for QML.

Since
5.88
5.88

Definition at line 89 of file knotification.h.

◆ componentName

QString KNotification::componentName
readwrite

The componentData is used to determine the location of the config file.

If no componentName is set, the app name is used by default

Parameters
componentNamethe new component name
Since
5.88

Definition at line 74 of file knotification.h.

◆ defaultAction

QString KNotification::defaultAction
readwrite

Set a default action that will be triggered when the notification is activated (typically, by clicking on the notification popup).

The default action should raise a window belonging to the application that sent it.

The string will be used as a label for the action, so ideally it should be wrapped in i18n() or tr() calls.

The visual representation of actions depends on the notification server. In Plasma and Gnome desktops, the actions are performed by clicking on the notification popup, and the label is not presented to the user.

Parameters
actionLabel of the default action. The label might or might not be displayed to the user by the notification server, depending on the implementation. Passing an empty string disables the default action.
Since
5.31
5.88

Definition at line 59 of file knotification.h.

◆ eventId

QString KNotification::eventId
readwrite

Set the event id, if not already passed to the constructor.

Since
5.88
5.88

Definition at line 39 of file knotification.h.

◆ flags

KNotification::NotificationFlags KNotification::flags
readwrite

Set the notification flags.

These must be set before calling sendEvent()

Since
5.88

Definition at line 69 of file knotification.h.

◆ hints

QVariantMap KNotification::hints
readwrite

Since
5.57 Adds a custom hint to the notification. Those are key-value pairs that can be interpreted by the respective notification backend to trigger additional, non-standard features.
Parameters
hintthe hint's key
valuethe hint's value
Since
5.101

Definition at line 98 of file knotification.h.

◆ iconName

QString KNotification::iconName
readwrite

Set the icon that will be shown in the popup.

Parameters
iconthe icon
Since
5.4
5.88

Definition at line 54 of file knotification.h.

◆ text

QString KNotification::text
readwrite

Set the notification text that will appear in the popup.

In Plasma workspace, the text is shown in a QML label which uses Text.StyledText, ie. it supports a small subset of HTML entities (mostly just formatting tags)

If the notifications server does not advertise "body-markup" capability, all HTML tags are stripped before sending it to the server

Parameters
textThe text to display in the notification popup
Since
5.88

Definition at line 49 of file knotification.h.

◆ title

QString KNotification::title
readwrite

Set the title of the notification popup.

If no title is set, the application name will be used.

Parameters
titleThe title of the notification
Since
4.3
5.88

Definition at line 44 of file knotification.h.

◆ urgency

KNotification::Urgency KNotification::urgency
readwrite

Sets the urgency of the notification.

This defines the importance of the notification. For example, a track change in a media player would be a low urgency. "You have new mail" would be normal urgency. "Your battery level is low" would be a critical urgency.

Use critical notifications with care as they might be shown even when giving a presentation or when notifications are turned off.

Parameters
urgencyThe urgency.
Since
5.58
5.88

Definition at line 84 of file knotification.h.

◆ urls

QList< QUrl > KNotification::urls
readwrite

Sets URLs associated with this notification.

For example, a screenshot application might want to provide the URL to the file that was just taken so the notification service can show a preview.

Note
This feature might not be supported by the user's notification service
Parameters
urlsA list of URLs
Since
5.29
5.88

Definition at line 79 of file knotification.h.

◆ xdgActivationToken

QString KNotification::xdgActivationToken
read
Since
5.90

Definition at line 93 of file knotification.h.

Constructor & Destructor Documentation

◆ KNotification() [1/3]

KNotification::KNotification ( const QString eventId,
QWidget widget,
const NotificationFlags flags = CloseOnTimeout 
)
explicit

Create a new notification.

You have to use sendEvent to show the notification.

The pointer is automatically deleted when the event is closed.

Make sure you use one of the NotificationFlags CloseOnTimeOut or CloseWhenWidgetActivated, if not, you have to close the notification yourself.

Parameters
eventIdis the name of the event
widgetis a widget where the notification reports to
flagsis a bitmask of NotificationFlag
Deprecated:
Since 5.75, use other constructor and call setWidget() explicitly

Definition at line 41 of file knotification.cpp.

◆ KNotification() [2/3]

KNotification::KNotification ( const QString eventId)
inlineexplicit

Create a new notification.

You have to use sendEvent to show the notification.

The pointer is automatically deleted when the event is closed.

The NotificationFlags is set to CloseOnTimeout.

Parameters
eventIdis the name of the event
Since
5.75

Definition at line 242 of file knotification.h.

◆ KNotification() [3/3]

KNotification::KNotification ( const QString eventId,
const NotificationFlags flags,
QObject parent = nullptr 
)
explicit

Create a new notification.

You have to use sendEvent to show the notification.

The pointer is automatically deleted when the event is closed.

Make sure you use one of the NotificationFlags CloseOnTimeOut or CloseWhenWidgetActivated, if not, you have to close the notification yourself.

Since
4.4
Parameters
eventIdis the name of the event
flagsis a bitmask of NotificationFlag
parentparent object

Definition at line 61 of file knotification.cpp.

Member Function Documentation

◆ action1Activated

void KNotification::action1Activated ( )
signal

Convenience signal that is emitted when the first action is activated.

◆ action2Activated

void KNotification::action2Activated ( )
signal

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

◆ action3Activated

void KNotification::action3Activated ( )
signal

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

◆ actions()

QStringList KNotification::actions ( ) const
Returns
the list of actions

◆ actionsChanged

void KNotification::actionsChanged ( )
signal

Emitted when actions changed.

Since
5.88

◆ activate

void KNotification::activate ( unsigned int  action = 0)
slot

Activate the action specified action If the action is zero, then the default action is activated.

Definition at line 324 of file knotification.cpp.

◆ activated [1/2]

void KNotification::activated ( )
signal

Emitted only when the default activation has occurred.

Deprecated:
Since 5.67, use defaultActivated() instead

◆ activated [2/2]

void KNotification::activated ( unsigned int  action)
signal

Emitted when an action has been activated.

The parameter passed by the signal is the index of the action in the QStringList set by setActions() call.

Parameters
actionwill be 0 if the default action was activated, or the index of the action in the actions QStringList

◆ addContext() [1/2]

void KNotification::addContext ( const Context context)

append a context at the list of contexts, see KNotification::Context

Parameters
contextthe context which is added

Definition at line 252 of file knotification.cpp.

◆ addContext() [2/2]

void KNotification::addContext ( const QString context_key,
const QString context_value 
)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Parameters
context_keyis the key of the context
context_valueis the value of the context

Definition at line 257 of file knotification.cpp.

◆ appName()

QString KNotification::appName ( ) const

appname used for the D-Bus object

Definition at line 522 of file knotification.cpp.

◆ autoDeleteChanged

void KNotification::autoDeleteChanged ( )
signal

Emitted when autoDelete changed.

Since
5.88

◆ beep()

void KNotification::beep ( const QString reason = QString(),
QWidget widget = nullptr 
)
static

This is a simple substitution for QApplication::beep()

Parameters
reasona short text explaining what has happened (may be empty)
widgetthe widget the notification refers to

Definition at line 498 of file knotification.cpp.

◆ close

void KNotification::close ( )
slot

Close the notification without activating it.

This will delete the notification.

Definition at line 350 of file knotification.cpp.

◆ closed

void KNotification::closed ( )
signal

Emitted when the notification is closed.

Can be closed either by the user clicking the close button, the timeout running out or when an action was triggered.

◆ componentName()

QString KNotification::componentName ( ) const

Returns the component name used to determine the location of the configuration file.

Since
5.88

◆ componentNameChanged

void KNotification::componentNameChanged ( )
signal

Emitted when componentName changed.

Since
5.88

◆ contexts()

KNotification::ContextList KNotification::contexts ( ) const
Returns
the list of contexts, see KNotification::Context

Definition at line 242 of file knotification.cpp.

◆ defaultAction()

QString KNotification::defaultAction ( ) const
Returns
the default action, or an empty string if not set
Since
5.31

◆ defaultActionChanged

void KNotification::defaultActionChanged ( )
signal

Emitted when defaultAction changed.

Since
5.88

◆ defaultActivated

void KNotification::defaultActivated ( )
signal

Emitted when the default action has been activated.

Since
5.67

◆ deref

void KNotification::deref ( )
slot

Remove a reference made with ref().

If the ref counter hits zero, the notification will be closed and deleted.

See also
ref

Definition at line 488 of file knotification.cpp.

◆ event() [1/7]

KNotification * KNotification::event ( const QString eventId,
const QString text = QString(),
const QPixmap pixmap = QPixmap(),
QWidget widget = nullptr,
const NotificationFlags flags = CloseOnTimeout,
const QString componentName = QString() 
)
static

emit a standard event

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

This will emit a standard event

Parameters
eventIdis the name of the event
textis the text of the notification to show in the popup.
pixmapis a picture which may be shown in the popup.
widgetis a widget where the notification reports to
flagsis a bitmask of NotificationFlag
componentNameused to determine the location of the config file. by default, plasma_workspace is used

Definition at line 432 of file knotification.cpp.

◆ event() [2/7]

KNotification * KNotification::event ( const QString eventId,
const QString title,
const QString text,
const QPixmap pixmap = QPixmap(),
QWidget widget = nullptr,
const NotificationFlags flags = CloseOnTimeout,
const QString componentName = QString() 
)
static

emit an event

This method creates the KNotification, setting every parameter, and fire the event. You don't need to call sendEvent

A popup may be displayed or a sound may be played, depending the config.

Returns
a KNotification . You may use that pointer to connect some signals or slot. the pointer is automatically deleted when the event is closed.

Make sure you use one of the CloseOnTimeOut or CloseWhenWidgetActivated, if not, you have to close yourself the notification.

Parameters
eventIdis the name of the event
titleis title of the notification to show in the popup.
textis the text of the notification to show in the popup.
pixmapis a picture which may be shown in the popup.
widgetis a widget where the notification reports to
flagsis a bitmask of NotificationFlag
componentNameused to determine the location of the config file. by default, appname is used
Since
4.4

Definition at line 412 of file knotification.cpp.

◆ event() [3/7]

KNotification * KNotification::event ( const QString eventId,
const QString title,
const QString text,
const QString iconName,
QWidget widget = nullptr,
const NotificationFlags flags = CloseOnTimeout,
const QString componentName = QString() 
)
static

emit a standard event with the possibility of setting an icon by icon name

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

This will emit a standard event

Parameters
eventIdis the name of the event
titleis title of the notification to show in the popup.
textis the text of the notification to show in the popup
iconNamea Freedesktop compatible icon name to be shown in the popup
widgetis a widget where the notification reports to
flagsis a bitmask of NotificationFlag
componentNameused to determine the location of the config file. by default, plasma_workspace is used
Since
5.4

Definition at line 453 of file knotification.cpp.

◆ event() [4/7]

KNotification * KNotification::event ( StandardEvent  eventId,
const QString text = QString(),
const QPixmap pixmap = QPixmap(),
QWidget widget = nullptr,
const NotificationFlags flags = CloseOnTimeout 
)
static

emit a standard event

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

This will emit a standard event

Parameters
eventIdis the name of the event
textis the text of the notification to show in the popup
pixmapis a picture which may be shown in the popup
widgetis a widget where the notification reports to
flagsis a bitmask of NotificationFlag

Definition at line 448 of file knotification.cpp.

◆ event() [5/7]

KNotification * KNotification::event ( StandardEvent  eventId,
const QString title,
const QString text,
const QPixmap pixmap,
QWidget widget = nullptr,
const NotificationFlags flags = CloseOnTimeout 
)
static

emit a standard event

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

This will emit a standard event

Parameters
eventIdis the name of the event
titleis title of the notification to show in the popup.
textis the text of the notification to show in the popup
pixmapis a picture which may be shown in the popup
widgetis a widget where the notification reports to
flagsis a bitmask of NotificationFlag
Since
4.4

Definition at line 443 of file knotification.cpp.

◆ event() [6/7]

KNotification * KNotification::event ( StandardEvent  eventId,
const QString title,
const QString text,
const QString iconName,
QWidget widget = nullptr,
const NotificationFlags flags = CloseOnTimeout 
)
static

emit a standard event with the possibility of setting an icon by icon name

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

This will emit a standard event with a custom icon

Parameters
eventIdthe type of the standard (not app-defined) event
titleis title of the notification to show in the popup.
textis the text of the notification to show in the popup
iconNamea Freedesktop compatible icon name to be shown in the popup
widgetis a widget where the notification reports to
flagsis a bitmask of NotificationFlag
Since
5.9

Definition at line 474 of file knotification.cpp.

◆ event() [7/7]

KNotification * KNotification::event ( StandardEvent  eventId,
const QString title,
const QString text,
QWidget widget = nullptr,
const NotificationFlags flags = CloseOnTimeout 
)
static

emit a standard event

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

This will emit a standard event with its standard icon

Parameters
eventIdthe type of the standard (not app-defined) event
titleis title of the notification to show in the popup.
textis the text of the notification to show in the popup
widgetis a widget where the notification reports to
flagsis a bitmask of NotificationFlag
Since
5.9

Definition at line 479 of file knotification.cpp.

◆ eventFilter()

bool KNotification::eventFilter ( QObject watched,
QEvent event 
)
overrideprotectedvirtual

reimplemented for internal reasons

Reimplemented from QObject.

Definition at line 557 of file knotification.cpp.

◆ eventId()

QString KNotification::eventId ( ) const
Returns
the name of the event

◆ eventIdChanged

void KNotification::eventIdChanged ( )
signal

Emitted when eventId changed.

Since
5.88

◆ flags()

NotificationFlags KNotification::flags ( ) const
Returns
the notification flags.

◆ flagsChanged

void KNotification::flagsChanged ( )
signal

Emitted when flags changed.

Since
5.88

◆ hints

QVariantMap KNotification::hints ( ) const
slot
Since
5.57 Returns the custom hints set by setHint()

◆ hintsChanged

void KNotification::hintsChanged ( )
signal

Emitted when hints changes.

Since
5.101

◆ iconName()

QString KNotification::iconName ( ) const
Returns
the icon shown in the popup
See also
setIconName
Since
5.4

◆ iconNameChanged

void KNotification::iconNameChanged ( )
signal

Emitted when iconName changed.

Since
5.88

◆ id()

int KNotification::id ( )

the id given by the notification manager

Definition at line 514 of file knotification.cpp.

◆ ignored

void KNotification::ignored ( )
signal

The notification has been ignored.

◆ isAutoDelete()

bool KNotification::isAutoDelete ( ) const

Returns whether this notification object will be automatically deleted after closing.

Since
5.88

Definition at line 537 of file knotification.cpp.

◆ pixmap()

QPixmap KNotification::pixmap ( ) const
Returns
the pixmap shown in the popup
See also
setPixmap

Definition at line 172 of file knotification.cpp.

◆ raiseWidget

void KNotification::raiseWidget ( )
slot

Raise the widget.

This will change the desktop, activate the window, and the tab if needed.

Deprecated:
since 5.67, use QWindow raise + requestActivate instead.

Definition at line 370 of file knotification.cpp.

◆ ref

void KNotification::ref ( )
slot

The notification will automatically be closed if all presentations are finished.

if you want to show your own presentation in your application, you should use this function, so it will not be automatically closed when there is nothing to show.

Don't forget to deref, or the notification may be never closed if there is no timeout.

See also
deref

Definition at line 484 of file knotification.cpp.

◆ replyAction()

KNotificationReplyAction * KNotification::replyAction ( ) const
Returns
the inline reply action.
Since
5.81

Definition at line 205 of file knotification.cpp.

◆ sendEvent

void KNotification::sendEvent ( )
slot

Send the notification to the server.

This will cause all the configured plugins to execute their actions on this notification (eg. a sound will play, a popup will show, a command will be executed etc).

Definition at line 503 of file knotification.cpp.

◆ setActions()

void KNotification::setActions ( const QStringList actions)

Set the list of actions shown in the popup.

The strings passed in that QStringList will be used as labels for those actions, so ideally they should be wrapped in i18n() or tr() calls. In Plasma workspace, these will be shown as buttons inside the notification popup.

The visual representation of actions however depends on the notification server

Parameters
actionsList of strings used as action labels

Definition at line 191 of file knotification.cpp.

◆ setAutoDelete()

void KNotification::setAutoDelete ( bool  autoDelete)

Sets whether this notification object will be automatically deleted after closing.

This is on by default for C++, and off by default for QML.

Since
5.88

Definition at line 542 of file knotification.cpp.

◆ setComponentName()

void KNotification::setComponentName ( const QString componentName)

The componentData is used to determine the location of the config file.

If no componentName is set, the app name is used by default

Parameters
componentNamethe new component name

Definition at line 286 of file knotification.cpp.

◆ setContexts()

void KNotification::setContexts ( const ContextList contexts)

set the list of contexts, see KNotification::Context

The list of contexts must be set before calling sendEvent;

Definition at line 247 of file knotification.cpp.

◆ setDefaultAction()

void KNotification::setDefaultAction ( const QString defaultAction)

Set a default action that will be triggered when the notification is activated (typically, by clicking on the notification popup).

The default action should raise a window belonging to the application that sent it.

The string will be used as a label for the action, so ideally it should be wrapped in i18n() or tr() calls.

The visual representation of actions depends on the notification server. In Plasma and Gnome desktops, the actions are performed by clicking on the notification popup, and the label is not presented to the user.

Parameters
actionLabel of the default action. The label might or might not be displayed to the user by the notification server, depending on the implementation. Passing an empty string disables the default action.
Since
5.31

Definition at line 223 of file knotification.cpp.

◆ setEventId()

void KNotification::setEventId ( const QString eventId)

Set the event id, if not already passed to the constructor.

Since
5.88

Definition at line 91 of file knotification.cpp.

◆ setFlags()

void KNotification::setFlags ( const NotificationFlags flags)

Set the notification flags.

These must be set before calling sendEvent()

Definition at line 267 of file knotification.cpp.

◆ setHint

void KNotification::setHint ( const QString hint,
const QVariant value 
)
slot
Since
5.57 Adds a custom hint to the notification. Those are key-value pairs that can be interpreted by the respective notification backend to trigger additional, non-standard features.
Parameters
hintthe hint's key
valuethe hint's value

Definition at line 614 of file knotification.cpp.

◆ setHints

void KNotification::setHints ( const QVariantMap &  hints)
slot
Since
5.101 Set custom hints on the notification.
See also
setHint

Definition at line 633 of file knotification.cpp.

◆ setIconName()

void KNotification::setIconName ( const QString icon)

Set the icon that will be shown in the popup.

Parameters
iconthe icon
Since
5.4

Definition at line 153 of file knotification.cpp.

◆ setPixmap()

void KNotification::setPixmap ( const QPixmap pix)

Set the pixmap that will be shown in the popup.

If you want to use an icon from the icon theme use setIconName instead.

Parameters
pixthe pixmap

Definition at line 177 of file knotification.cpp.

◆ setReplyAction()

void KNotification::setReplyAction ( std::unique_ptr< KNotificationReplyAction replyAction)

Add an inline reply action to the notification.

On supported platforms this lets the user type a reply to a notification, such as replying to a chat message, from the notification popup, for example:

KNotification *notification = new KNotification(QStringLiteral("notification"));
...
auto replyAction = std::make_unique<KNotificationReplyAction>(i18nc("@action:button", "Reply"));
replyAction->setPlaceholderText(i18nc("@info:placeholder", "Reply to Dave..."));
qDebug() << "you replied with" << text;
});
notification->setReplyAction(std::move(replyAction));
Parameters
replyActionthe reply action to set
Since
5.81

Definition at line 210 of file knotification.cpp.

◆ setText()

void KNotification::setText ( const QString text)

Set the notification text that will appear in the popup.

In Plasma workspace, the text is shown in a QML label which uses Text.StyledText, ie. it supports a small subset of HTML entities (mostly just formatting tags)

If the notifications server does not advertise "body-markup" capability, all HTML tags are stripped before sending it to the server

Parameters
textThe text to display in the notification popup

Definition at line 139 of file knotification.cpp.

◆ setTitle()

void KNotification::setTitle ( const QString title)

Set the title of the notification popup.

If no title is set, the application name will be used.

Parameters
titleThe title of the notification
Since
4.3

Definition at line 125 of file knotification.cpp.

◆ setUrgency()

void KNotification::setUrgency ( Urgency  urgency)

Sets the urgency of the notification.

This defines the importance of the notification. For example, a track change in a media player would be a low urgency. "You have new mail" would be normal urgency. "Your battery level is low" would be a critical urgency.

Use critical notifications with care as they might be shown even when giving a presentation or when notifications are turned off.

Parameters
urgencyThe urgency.
Since
5.58

Definition at line 310 of file knotification.cpp.

◆ setUrls()

void KNotification::setUrls ( const QList< QUrl > &  urls)

Sets URLs associated with this notification.

For example, a screenshot application might want to provide the URL to the file that was just taken so the notification service can show a preview.

Note
This feature might not be supported by the user's notification service
Parameters
urlsA list of URLs
Since
5.29

Definition at line 299 of file knotification.cpp.

◆ setWidget()

void KNotification::setWidget ( QWidget widget)

Set the widget associated to the notification.

The notification is reparented to the new widget.

See also
widget()
Parameters
widgetthe new widget

Definition at line 114 of file knotification.cpp.

◆ text()

QString KNotification::text ( ) const
Returns
the notification text
See also
setText

◆ textChanged

void KNotification::textChanged ( )
signal

Emitted when text changed.

Since
5.88

◆ title()

QString KNotification::title ( ) const
Returns
the notification title
See also
setTitle
Since
4.3

◆ titleChanged

void KNotification::titleChanged ( )
signal

Emitted when title changed.

Since
5.88

◆ update

void KNotification::update ( )
slot

update the texts, the icon, and the actions of one existing notification

Definition at line 550 of file knotification.cpp.

◆ urgency()

Urgency KNotification::urgency ( ) const

The urgency of the notification.

Since
5.58

◆ urgencyChanged

void KNotification::urgencyChanged ( )
signal

Emitted when urgency changed.

Since
5.88

◆ urls()

QList<QUrl> KNotification::urls ( ) const

URLs associated with this notification.

Since
5.29

◆ urlsChanged

void KNotification::urlsChanged ( )
signal

Emitted when urls changed.

Since
5.88

◆ widget()

QWidget * KNotification::widget ( ) const

the widget associated to the notification

If the widget is destroyed, the notification will be automatically canceled. If the widget is activated, the notification will be automatically closed if the NotificationFlags specify that

When the notification is activated, the widget might be raised. Depending on the configuration, the taskbar entry of the window containing the widget may blink.

Definition at line 109 of file knotification.cpp.

◆ xdgActivationToken()

QString KNotification::xdgActivationToken ( ) const

Returns the activation token to use to activate a window.

Since
5.90

◆ xdgActivationTokenChanged

void KNotification::xdgActivationTokenChanged ( )
signal

Emitted when xdgActivationToken changes.

Since
5.90

The documentation for this class was generated from the following files:
KNotificationReplyAction * replyAction() const
void setReplyAction(std::unique_ptr< KNotificationReplyAction > replyAction)
Add an inline reply action to the notification.
QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
void replied(const QString &text)
Emitted when the user has submitted a reply.
KNotification(const QString &eventId, QWidget *widget, const NotificationFlags &flags=CloseOnTimeout)
Create a new notification.
QString text
Set the notification text that will appear in the popup.
Definition: knotification.h:49
void setPlaceholderText(const QString &placeholderText)
Set the placeholder text for the inline reply text field, for example "Reply to Konqi....
QString i18nc(const char *context, const char *text, const TYPE &arg...)
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Mon May 8 2023 03:49:15 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.