Qt Utilities
6.0.1
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)
38 bool supportsBody()
const;
39 bool supportsLinks()
const;
40 bool supportsMarkup()
const;
41 bool supportsImages()
const;
42 bool supportsIcon()
const;
43 bool supportsActions()
const;
44 bool supportsAnimatedIcon()
const;
45 bool supportsActionIcons()
const;
46 bool supportsSound()
const;
47 bool supportsPercistence()
const;
55 explicit DBusNotification(
const QString &title,
const QString &icon,
int timeout = 10000, QObject *parent =
nullptr);
58 static bool isAvailable();
59 const QString &applicationName()
const;
60 void setApplicationName(
const QString &applicationName);
61 const QString &title()
const;
62 void setTitle(
const QString &title);
63 const QString &message()
const;
64 void setMessage(
const QString &message);
65 const QString &icon()
const;
66 void setIcon(
const QString &icon);
68 const QImage image()
const;
69 void setImage(
const QImage &image);
70 const QString imagePath()
const;
71 void setImagePath(
const QString &imagePath);
73 void setTimeout(
int timeout);
75 void setUrgency(quint8 urgency);
76 bool isResident()
const;
77 void setResident(
bool resident);
78 QString category()
const;
79 void setCategory(
const QString &category);
80 const QStringList &actions()
const;
81 void setActions(
const QStringList &actions);
82 const QVariantMap &hints()
const;
84 QVariant hint(
const QString &name)
const;
85 QVariant hint(
const QString &name,
const QString &fallbackNames...)
const;
86 bool isVisible()
const;
87 void deleteOnCloseOrError();
88 static bool queryCapabilities(
const std::function<
void(
Capabilities &&capabilities)> &callback);
92 bool show(
const QString &message);
93 bool update(
const QString &line);
104 void actionInvoked(
const QString &action);
107 void handleNotifyResult(QDBusPendingCallWatcher *);
108 static void handleNotificationClosed(uint
id, uint reason);
109 static void handleActionInvoked(uint
id,
const QString &action);
112 static void initInterface();
115 QDBusPendingCallWatcher *m_watcher;
116 QString m_applicationName;
121 QStringList m_actions;
123 static OrgFreedesktopNotificationsInterface *s_dbusInterface;
132 : QSet<QString>(capabilities.toSet())
144 return contains(QStringLiteral(
"body"));
149 return contains(QStringLiteral(
"body-hyperlinks"));
154 return contains(QStringLiteral(
"body-markup"));
159 return contains(QStringLiteral(
"body-images"));
164 return contains(QStringLiteral(
"icon-static")) || supportsAnimatedIcon();
169 return contains(QStringLiteral(
"actions"));
174 return contains(QStringLiteral(
"icon-multi"));
179 return contains(QStringLiteral(
"action-icons"));
184 return contains(QStringLiteral(
"sound"));
189 return contains(QStringLiteral(
"persistence"));
198 return m_applicationName;
255 return m_hints[name];
263 const auto variant(m_hints[name]);
264 return variant.isNull() ? this->
hint(fallbackNames) : variant;
273 return hint(QStringLiteral(
"image-data"), QStringLiteral(
"image_path")).toString();
283 m_hints[QStringLiteral(
"image-path")] =
imagePath;
301 return m_hints[QStringLiteral(
"urgency")].toInt();
309 m_hints[QStringLiteral(
"urgency")] =
urgency;
317 return m_hints[QStringLiteral(
"resident")].toBool();
325 m_hints[QStringLiteral(
"resident")] = resident;
334 return m_hints[QStringLiteral(
"category")].toString();
343 m_hints[QStringLiteral(
"category")] =
category;
386 #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
const QString & icon() 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.
const QString & applicationName() const
const QStringList & actions() const
void setTitle(const QString &title)
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.
const QString & message() const
bool supportsSound() const
const QString & title() const
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