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 title READ title WRITE setTitle)
25 Q_PROPERTY(QString message READ message WRITE setMessage)
26 Q_PROPERTY(QString icon READ icon WRITE setIcon)
27 Q_PROPERTY(
int timeout READ timeout WRITE setTimeout)
28 Q_PROPERTY(QStringList actions READ actions WRITE setActions)
29 Q_PROPERTY(
bool visible READ isVisible)
37 bool supportsBody()
const;
38 bool supportsLinks()
const;
39 bool supportsMarkup()
const;
40 bool supportsImages()
const;
41 bool supportsIcon()
const;
42 bool supportsActions()
const;
43 bool supportsAnimatedIcon()
const;
44 bool supportsActionIcons()
const;
45 bool supportsSound()
const;
46 bool supportsPercistence()
const;
54 explicit DBusNotification(
const QString &title,
const QString &icon,
int timeout = 10000, QObject *parent =
nullptr);
57 static bool isAvailable();
58 const QString &title()
const;
59 void setTitle(
const QString &title);
60 const QString &message()
const;
61 void setMessage(
const QString &message);
62 const QString &icon()
const;
63 void setIcon(
const QString &icon);
65 const QImage image()
const;
66 void setImage(
const QImage &image);
67 const QString imagePath()
const;
68 void setImagePath(
const QString &imagePath);
70 void setTimeout(
int timeout);
71 const QStringList &actions()
const;
72 void setActions(
const QStringList &actions);
73 const QVariantMap &hints()
const;
75 QVariant hint(
const QString &name)
const;
76 QVariant hint(
const QString &name,
const QString &fallbackNames...)
const;
77 bool isVisible()
const;
78 void deleteOnCloseOrError();
79 static bool queryCapabilities(
const std::function<
void(
Capabilities &&capabilities)> &callback);
83 bool show(
const QString &message);
84 bool update(
const QString &line);
95 void actionInvoked(
const QString &action);
98 void handleNotifyResult(QDBusPendingCallWatcher *);
99 static void handleNotificationClosed(uint
id, uint reason);
100 static void handleActionInvoked(uint
id,
const QString &action);
103 static void initInterface();
106 QDBusPendingCallWatcher *m_watcher;
111 QStringList m_actions;
113 static OrgFreedesktopNotificationsInterface *s_dbusInterface;
122 : QSet<QString>(capabilities.toSet())
134 return contains(QStringLiteral(
"body"));
139 return contains(QStringLiteral(
"body-hyperlinks"));
144 return contains(QStringLiteral(
"body-markup"));
149 return contains(QStringLiteral(
"body-images"));
154 return contains(QStringLiteral(
"icon-static")) || supportsAnimatedIcon();
159 return contains(QStringLiteral(
"actions"));
164 return contains(QStringLiteral(
"icon-multi"));
169 return contains(QStringLiteral(
"action-icons"));
174 return contains(QStringLiteral(
"sound"));
179 return contains(QStringLiteral(
"persistence"));
227 return m_hints[name];
235 const auto variant(m_hints[name]);
236 return variant.isNull() ? this->
hint(fallbackNames) : variant;
245 return hint(QStringLiteral(
"image-data"), QStringLiteral(
"image_path")).toString();
255 m_hints[QStringLiteral(
"image-path")] =
imagePath;
308 #endif // MISC_UTILS_NOTIFICATION_H void setIcon(const QString &icon)
Sets the icon name.
void setActions(const QStringList &actions)
Sets the actions for the notification.
const QString & title() const
const QString imagePath() const
Returns the image path.
bool supportsSound() const
bool supportsIcon() const
void setMessage(const QString &message)
Sets the message to be shown.
bool supportsLinks() const
QVariant hint(const QString &name) const
Returns the hint with the specified name.
bool supportsImages() const
#define QT_UTILITIES_EXPORT
Marks the symbol to be exported by the qtutilities library.
bool isVisible() const
Returns whether the notification is (still) visible.
void setTitle(const QString &title)
bool supportsAnimatedIcon() const
void setTimeout(int timeout)
Sets the number of milliseconds the notification will be visible after calling show().
const QStringList & actions() const
const QVariantMap & hints() const
bool supportsBody() const
bool supportsActionIcons() const
The DBusNotification class emits D-Bus notifications.
void setImagePath(const QString &imagePath)
Sets the image path.
bool supportsPercistence() const
bool supportsMarkup() const
bool supportsActions() const
const QString & icon() const
const QString & message() const