Qt Utilities
6.3.0
Common Qt related C++ classes and routines used by my applications such as dialogs, widgets and models
|
Go to the documentation of this file. 1 #ifndef MISC_UTILS_NOTIFICATION_H
2 #define MISC_UTILS_NOTIFICATION_H
12 QT_FORWARD_DECLARE_CLASS(QDBusPendingCallWatcher)
14 class OrgFreedesktopNotificationsInterface;
24 Q_PROPERTY(QString applicationName READ applicationName WRITE setApplicationName)
25 Q_PROPERTY(QString title READ title WRITE setTitle)
26 Q_PROPERTY(QString message READ message WRITE setMessage)
27 Q_PROPERTY(QString icon READ icon WRITE setIcon)
28 Q_PROPERTY(
int timeout READ timeout WRITE setTimeout)
29 Q_PROPERTY(QStringList actions READ actions WRITE setActions)
30 Q_PROPERTY(
bool visible READ isVisible)
31 Q_PROPERTY(
bool pending READ isPending)
40 bool supportsBody()
const;
41 bool supportsLinks()
const;
42 bool supportsMarkup()
const;
43 bool supportsImages()
const;
44 bool supportsIcon()
const;
45 bool supportsActions()
const;
46 bool supportsAnimatedIcon()
const;
47 bool supportsActionIcons()
const;
48 bool supportsSound()
const;
49 bool supportsPercistence()
const;
56 const QString &title,
NotificationIcon icon = NotificationIcon::Information,
int timeout = 10000, QObject *parent =
nullptr);
57 explicit DBusNotification(
const QString &title,
const QString &icon,
int timeout = 10000, QObject *parent =
nullptr);
60 static bool isAvailable();
61 const QString &applicationName()
const;
62 void setApplicationName(
const QString &applicationName);
63 const QString &title()
const;
64 void setTitle(
const QString &title);
65 const QString &message()
const;
66 void setMessage(
const QString &message);
67 const QString &icon()
const;
68 void setIcon(
const QString &icon);
70 const QImage image()
const;
71 void setImage(
const QImage &image);
72 const QString imagePath()
const;
73 void setImagePath(
const QString &imagePath);
75 void setTimeout(
int timeout);
77 void setUrgency(quint8 urgency);
78 bool isResident()
const;
79 void setResident(
bool resident);
80 QString category()
const;
81 void setCategory(
const QString &category);
82 const QStringList &actions()
const;
83 void setActions(
const QStringList &actions);
84 const QVariantMap &hints()
const;
86 QVariant hint(
const QString &name)
const;
87 QVariant hint(
const QString &name,
const QString &fallbackNames...)
const;
88 bool isVisible()
const;
89 bool isPending()
const;
90 void deleteOnCloseOrError();
91 static bool queryCapabilities(
const std::function<
void(
Capabilities &&capabilities)> &callback);
95 bool show(
const QString &message);
96 bool update(
const QString &line);
110 void handleNotifyResult(QDBusPendingCallWatcher *);
111 static void handleNotificationClosed(
IDType id, uint reason);
112 static void handleActionInvoked(
IDType id,
const QString &action);
115 static void initInterface();
118 QDBusPendingCallWatcher *m_watcher;
119 QString m_applicationName;
124 QStringList m_actions;
126 static OrgFreedesktopNotificationsInterface *s_dbusInterface;
135 #if QT_VERSION < QT_VERSION_CHECK(5, 14, 0)
136 : QSet<QString>(capabilities.toSet())
138 : QSet<QString>(capabilities.begin(), capabilities.end())
151 return contains(QStringLiteral(
"body"));
156 return contains(QStringLiteral(
"body-hyperlinks"));
161 return contains(QStringLiteral(
"body-markup"));
166 return contains(QStringLiteral(
"body-images"));
171 return contains(QStringLiteral(
"icon-static")) || supportsAnimatedIcon();
176 return contains(QStringLiteral(
"actions"));
181 return contains(QStringLiteral(
"icon-multi"));
186 return contains(QStringLiteral(
"action-icons"));
191 return contains(QStringLiteral(
"sound"));
196 return contains(QStringLiteral(
"persistence"));
205 return m_applicationName;
262 return m_hints[name];
270 const auto variant(m_hints[name]);
271 return variant.isNull() ? this->
hint(fallbackNames) : variant;
280 return hint(QStringLiteral(
"image-data"), QStringLiteral(
"image_path")).toString();
290 m_hints[QStringLiteral(
"image-path")] =
imagePath;
308 return m_hints[QStringLiteral(
"urgency")].toInt();
316 m_hints[QStringLiteral(
"urgency")] =
urgency;
324 return m_hints[QStringLiteral(
"resident")].toBool();
332 m_hints[QStringLiteral(
"resident")] = resident;
341 return m_hints[QStringLiteral(
"category")].toString();
350 m_hints[QStringLiteral(
"category")] =
category;
393 #endif // MISC_UTILS_NOTIFICATION_H
void setUrgency(quint8 urgency)
Sets the urgency level (0 = low, 1 = normal, 2 = critical).
QString category() const
Returns the category.
The DBusNotification class emits D-Bus notifications.
const QString imagePath() const
Returns the image path.
bool supportsMarkup() const
void setCategory(const QString &category)
Sets the category.
void setMessage(const QString &message)
Sets the message to be shown.
bool isVisible() const
Returns whether the notification is (still) visible.
void setTitle(const QString &title)
void shown()
Emitted when the notification could be shown successful.
int urgency() const
Returns the urgency level (0 = low, 1 = normal, 2 = critical).
bool supportsImages() const
void setActions(const QStringList &actions)
Sets the actions for the notification.
void setResident(bool resident)
Sets whether the notification will remain visible after an action has been clicked.
bool supportsAnimatedIcon() const
void setTimeout(int timeout)
Sets the number of milliseconds the notification will be visible after calling show().
#define QT_UTILITIES_EXPORT
Marks the symbol to be exported by the qtutilities library.
QString message
Returns the assigned message.
int timeout
Returns the number of milliseconds the notification will be visible after calling show().
QStringList actions
Returns the assigned actions.
bool supportsSound() const
void error()
Emitted when the notification couldn't be shown.
void closed(NotificationCloseReason reason)
Emitted when the notification has been closed.
void actionInvoked(const QString &action)
Emitted when action has been invoked.
void setImagePath(const QString &imagePath)
Sets the image path.
void setIcon(const QString &icon)
Sets the icon name.
bool isResident() const
Returns whether the notification will remain visible after an action has been clicked.
QVariant hint(const QString &name) const
Returns the hint with the specified name.
bool supportsActions() const
void setApplicationName(const QString &applicationName)
Sets the application name to be used.
bool supportsLinks() const
bool supportsIcon() const
bool supportsActionIcons() const
bool supportsBody() const
bool supportsPercistence() const
const QVariantMap & hints() const