Qt Utilities
6.0.2
Common Qt related C++ classes and routines used by my applications such as dialogs, widgets and models
|
The DBusNotification class emits D-Bus notifications. More...
#include <dbusnotification.h>
Classes | |
class | Capabilities |
Public Slots | |
bool | show () |
Shows the notification. More... | |
bool | show (const QString &message) |
Updates the message and shows/updates the notification. More... | |
bool | update (const QString &line) |
Updates the message and shows/updates the notification. More... | |
bool | hide () |
Hides the notification (if still visible). More... | |
Signals | |
void | shown () |
Emitted when the notification could be shown successful. More... | |
void | error () |
Emitted when the notification couldn't be shown. More... | |
void | closed (NotificationCloseReason reason) |
Emitted when the notification has been closed. More... | |
void | actionInvoked (const QString &action) |
Emitted when action has been invoked. More... | |
Public Member Functions | |
DBusNotification (const QString &title, NotificationIcon icon=NotificationIcon::Information, int timeout=10000, QObject *parent=nullptr) | |
Creates a new notification (which is not shown instantly). More... | |
DBusNotification (const QString &title, const QString &icon, int timeout=10000, QObject *parent=nullptr) | |
Creates a new notification (which is not shown instantly). More... | |
~DBusNotification () override | |
Closes the notification if still shown and delete the object. More... | |
const QString & | applicationName () const |
void | setApplicationName (const QString &applicationName) |
Sets the application name to be used. More... | |
const QString & | title () const |
void | setTitle (const QString &title) |
const QString & | message () const |
void | setMessage (const QString &message) |
Sets the message to be shown. More... | |
const QString & | icon () const |
void | setIcon (const QString &icon) |
Sets the icon name. More... | |
void | setIcon (NotificationIcon icon) |
Sets the icon to one of the pre-defined notification icons. More... | |
const QImage | image () const |
Returns the image. More... | |
void | setImage (const QImage &image) |
Sets the image. More... | |
const QString | imagePath () const |
Returns the image path. More... | |
void | setImagePath (const QString &imagePath) |
Sets the image path. More... | |
int | timeout () const |
void | setTimeout (int timeout) |
Sets the number of milliseconds the notification will be visible after calling show(). More... | |
int | urgency () const |
Returns the urgency level (0 = low, 1 = normal, 2 = critical). More... | |
void | setUrgency (quint8 urgency) |
Sets the urgency level (0 = low, 1 = normal, 2 = critical). More... | |
bool | isResident () const |
Returns whether the notification will remain visible after an action has been clicked. More... | |
void | setResident (bool resident) |
Sets whether the notification will remain visible after an action has been clicked. More... | |
QString | category () const |
Returns the category. More... | |
void | setCategory (const QString &category) |
Sets the category. More... | |
const QStringList & | actions () const |
void | setActions (const QStringList &actions) |
Sets the actions for the notification. More... | |
const QVariantMap & | hints () const |
QVariantMap & | hints () |
QVariant | hint (const QString &name) const |
Returns the hint with the specified name. More... | |
QVariant | hint (const QString &name, const QString &fallbackNames...) const |
Returns the hint with the specified name. More... | |
bool | isVisible () const |
Returns whether the notification is (still) visible. More... | |
void | deleteOnCloseOrError () |
Makes the notification object delete itself when the notification has been closed or an error occurred. More... | |
Static Public Member Functions | |
static bool | isAvailable () |
Returns whether the notification D-Bus daemon is running. More... | |
static bool | queryCapabilities (const std::function< void(Capabilities &&capabilities)> &callback) |
Properties | |
QString | applicationName |
Returns the application name to be used. More... | |
QString | title |
QString | message |
Returns the assigned message. More... | |
QString | icon |
Returns the icon name. More... | |
int | timeout |
Returns the number of milliseconds the notification will be visible after calling show(). More... | |
QStringList | actions |
Returns the actions for the notification. More... | |
bool | visible |
The DBusNotification class emits D-Bus notifications.
D-Bus notifications are only available if the library has been compiled with support for it by specifying CMake option DBUS_NOTIFICATIONS
. If support is available, the macro QT_UTILITIES_SUPPORT_DBUS_NOTIFICATIONS
is defined.
Usage
First create a new instance. The constructor allows to set basic parameters. To set more parameters, use setter methods. Call show() to actually show the notification. This method can also be used to update the currently shown notification (it will not be updated automatically by just using the setter methods).
Instances of this class share static data. So do not call the member functions from different threads without proper synchronization - even if using different instances. The destructor is safe to call, though.
Definition at line 22 of file dbusnotification.h.
|
explicit |
Creates a new notification (which is not shown instantly).
Definition at line 155 of file dbusnotification.cpp.
|
explicit |
Creates a new notification (which is not shown instantly).
Definition at line 169 of file dbusnotification.cpp.
|
override |
Closes the notification if still shown and delete the object.
Definition at line 197 of file dbusnotification.cpp.
|
signal |
Emitted when action has been invoked.
const QStringList& QtUtilities::DBusNotification::actions | ( | ) | const |
const QString& QtUtilities::DBusNotification::applicationName | ( | ) | const |
|
inline |
Returns the category.
Definition at line 332 of file dbusnotification.h.
|
signal |
Emitted when the notification has been closed.
void QtUtilities::DBusNotification::deleteOnCloseOrError | ( | ) |
Makes the notification object delete itself when the notification has been closed or an error occurred.
Definition at line 261 of file dbusnotification.cpp.
|
signal |
Emitted when the notification couldn't be shown.
|
slot |
Hides the notification (if still visible).
Definition at line 356 of file dbusnotification.cpp.
|
inline |
Returns the hint with the specified name.
Definition at line 253 of file dbusnotification.h.
|
inline |
Returns the hint with the specified name.
If no hint is present, the fallbackNames are tried in the specified order.
Definition at line 261 of file dbusnotification.h.
|
inline |
Definition at line 375 of file dbusnotification.h.
|
inline |
Definition at line 370 of file dbusnotification.h.
const QString& QtUtilities::DBusNotification::icon | ( | ) | const |
const QImage QtUtilities::DBusNotification::image | ( | ) | const |
Returns the image.
Definition at line 241 of file dbusnotification.cpp.
|
inline |
Returns the image path.
Definition at line 271 of file dbusnotification.h.
|
static |
Returns whether the notification D-Bus daemon is running.
Definition at line 212 of file dbusnotification.cpp.
|
inline |
Returns whether the notification will remain visible after an action has been clicked.
Definition at line 315 of file dbusnotification.h.
|
inline |
Returns whether the notification is (still) visible.
Definition at line 380 of file dbusnotification.h.
const QString& QtUtilities::DBusNotification::message | ( | ) | const |
|
static |
Definition at line 329 of file dbusnotification.cpp.
|
inline |
Sets the actions for the notification.
Sets the list of available actions.
QStringList({QStringLiteral("first_id"), tr("First action"), QStringLiteral("second_id"), tr("Second action"), ...})
Definition at line 365 of file dbusnotification.h.
|
inline |
Sets the application name to be used.
Definition at line 205 of file dbusnotification.h.
|
inline |
Sets the category.
Definition at line 341 of file dbusnotification.h.
|
inline |
Sets the icon name.
Definition at line 245 of file dbusnotification.h.
void QtUtilities::DBusNotification::setIcon | ( | NotificationIcon | icon | ) |
Sets the icon to one of the pre-defined notification icons.
Definition at line 221 of file dbusnotification.cpp.
void QtUtilities::DBusNotification::setImage | ( | const QImage & | image | ) |
Sets the image.
Definition at line 252 of file dbusnotification.cpp.
|
inline |
Sets the image path.
Definition at line 281 of file dbusnotification.h.
|
inline |
|
inline |
Sets whether the notification will remain visible after an action has been clicked.
Definition at line 323 of file dbusnotification.h.
|
inline |
Sets the number of milliseconds the notification will be visible after calling show().
Definition at line 291 of file dbusnotification.h.
|
inline |
Definition at line 215 of file dbusnotification.h.
|
inline |
Sets the urgency level (0 = low, 1 = normal, 2 = critical).
Definition at line 307 of file dbusnotification.h.
|
slot |
Shows the notification.
Definition at line 274 of file dbusnotification.cpp.
|
slot |
Updates the message and shows/updates the notification.
Definition at line 297 of file dbusnotification.cpp.
|
signal |
Emitted when the notification could be shown successful.
int QtUtilities::DBusNotification::timeout | ( | ) | const |
const QString& QtUtilities::DBusNotification::title | ( | ) | const |
|
slot |
Updates the message and shows/updates the notification.
Definition at line 315 of file dbusnotification.cpp.
|
inline |
Returns the urgency level (0 = low, 1 = normal, 2 = critical).
Definition at line 299 of file dbusnotification.h.
|
inlinereadwrite |
Returns the actions for the notification.
Returns the assigned actions.
The actions are a list of action IDs and action names. The ID is returned by the actionInvoked() signal if an action is triggered. The action name is the user-visible name of the notification.
Example: { QStringLiteral("dismiss"), tr("Dismiss notification"), QStringLiteral("details"), tr("Show details") }
Definition at line 29 of file dbusnotification.h.
|
inlinereadwrite |
Returns the application name to be used.
Definition at line 24 of file dbusnotification.h.
|
inlinereadwrite |
Returns the icon name.
Definition at line 27 of file dbusnotification.h.
|
inlinereadwrite |
Returns the assigned message.
Definition at line 26 of file dbusnotification.h.
|
inlinereadwrite |
Returns the number of milliseconds the notification will be visible after calling show().
Definition at line 28 of file dbusnotification.h.
|
inlinereadwrite |
Definition at line 25 of file dbusnotification.h.
|
read |
Definition at line 30 of file dbusnotification.h.