-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnotificationutill.h
executable file
·54 lines (47 loc) · 1.59 KB
/
notificationutill.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#ifndef NOTIFICATIONUTILL_H
#define NOTIFICATIONUTILL_H
#include <QDBusInterface>
#include <QDebug>
/**
* @brief The NotificationUtill class
*/
class NotificationUtill
{
public:
NotificationUtill();
public:
static void Notify(const QString &app_name, const QString &app_icon,
const QString &summary, const QString &body,
int expire_timeout)
{
QDBusInterface dbus("org.freedesktop.Notifications",
"/org/freedesktop/Notifications",
"org.freedesktop.Notifications");
if (!dbusFreedesktopIsValid()) {
qDebug() << "QDBusInterface is not valid!";
return ;
}
QList<QVariant> args;
args.append(app_name); // Application Name
args.append(0123U); // Replaces ID (0U)
args.append(app_icon); // Notification Icon
args.append( summary); // Summary
args.append(body); // Body
args.append(QStringList()); // Actions
args.append(QVariantMap());
args.append(expire_timeout);
dbus.callWithArgumentList(QDBus::NoBlock, "Notify", args);
}
static bool dbusFreedesktopIsValid()
{
QDBusInterface dbus("org.freedesktop.Notifications",
"/org/freedesktop/Notifications",
"org.freedesktop.Notifications");
if (!dbus.isValid()) {
qDebug() << "QDBusInterface is not valid!";
return false;
}
return true;
}
};
#endif // NOTIFICATIONUTILL_H