1#ifndef MISC_UTILS_NOTIFICATION_H
2#define MISC_UTILS_NOTIFICATION_H
12QT_FORWARD_DECLARE_CLASS(QDBusPendingCallWatcher)
14class OrgFreedesktopNotificationsInterface;
63 const QString &
title()
const;
67 const QString &
icon()
const;
70 const QImage
image()
const;
82 const QStringList &
actions()
const;
84 const QVariantMap &
hints()
const;
86 QVariant
hint(
const QString &name)
const;
87 QVariant
hint(
const QString &name,
const QString &fallbackNames...)
const;
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"));
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;
bool supportsPercistence() const
bool supportsAnimatedIcon() const
bool supportsImages() const
bool supportsLinks() const
bool supportsMarkup() const
bool supportsSound() const
bool supportsActionIcons() const
bool supportsIcon() const
bool supportsActions() const
bool supportsBody() const
void deleteOnCloseOrError()
Makes the notification object delete itself when the notification has been closed or an error occurre...
QString message
Returns the assigned message.
bool update(const QString &line)
Updates the message and shows/updates the notification.
void shown()
Emitted when the notification could be shown successful.
void setUrgency(quint8 urgency)
Sets the urgency level (0 = low, 1 = normal, 2 = critical).
bool isVisible() const
Returns whether the notification is (still) visible.
bool isPending() const
Returns whether the notification is about to be shown after calling show() or update() but has not be...
const QImage image() const
Returns the image.
int urgency() const
Returns the urgency level (0 = low, 1 = normal, 2 = critical).
void setApplicationName(const QString &applicationName)
Sets the application name to be used.
void setIcon(const QString &icon)
Sets the icon name.
static bool queryCapabilities(const std::function< void(Capabilities &&capabilities)> &callback)
void actionInvoked(const QString &action)
Emitted when action has been invoked.
void setCategory(const QString &category)
Sets the category.
QString category() const
Returns the category.
QStringList actions
Returns the assigned actions.
DBusNotification(const QString &title, NotificationIcon icon=NotificationIcon::Information, int timeout=10000, QObject *parent=nullptr)
Creates a new notification (which is not shown instantly).
const QString imagePath() const
Returns the image path.
void setTitle(const QString &title)
const QVariantMap & hints() const
static bool isAvailable()
Returns whether the notification D-Bus daemon is running.
bool isResident() const
Returns whether the notification will remain visible after an action has been clicked.
void setActions(const QStringList &actions)
Sets the actions for the notification.
void closed(NotificationCloseReason reason)
Emitted when the notification has been closed.
void setImagePath(const QString &imagePath)
Sets the image path.
void error()
Emitted when the notification couldn't be shown.
int timeout
Returns the number of milliseconds the notification will be visible after calling show().
void setResident(bool resident)
Sets whether the notification will remain visible after an action has been clicked.
bool hide()
Hides the notification (if still visible).
QVariant hint(const QString &name) const
Returns the hint with the specified name.
void setImage(const QImage &image)
Sets the image.
void setTimeout(int timeout)
Sets the number of milliseconds the notification will be visible after calling show().
void setMessage(const QString &message)
Sets the message to be shown.
bool show()
Shows the notification.
#define QT_UTILITIES_EXPORT
Marks the symbol to be exported by the qtutilities library.