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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
|
/*
* Copyright (C) 2013 Canonical, Ltd.
*
* Authors:
* Jussi Pakkanen <jussi.pakkanen@canonical.com>
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 3, as published
* by the Free Software Foundation.
*
* This library is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "NotificationClient.h"
#include "NotificationServer.h"
#include <QStringList>
#include <QDBusReply>
NotificationClient::NotificationClient(QObject *parent) : QObject(parent),
service(DBUS_SERVICE_NAME, DBUS_PATH, DBUS_INTERFACE) {
}
NotificationClient::~NotificationClient() {
}
NotificationID NotificationClient::sendNotification(Notification::Type ntype, Notification::Urgency urg, const QString &summary, const QString &body) {
QString app_name("client test");
unsigned int replaces_id = 0;
QString app_icon("/usr/share/icons/unity-icon-theme/search/16/search_field.png");
QStringList actions;
QMap<QString, QVariant> hints;
hints["urgency"] = (char)urg;
if(ntype == Notification::Type::Confirmation) {
hints[SYNCH_HINT] = "yes";
}
if(ntype == Notification::Type::SnapDecision) {
QStringList snaps;
snaps.push_back("Ok");
snaps.push_back("ok_id");
snaps.push_back("Cancel");
snaps.push_back("cancel_id");
hints[SNAP_HINT] = snaps;
}
if(ntype == Notification::Type::Interactive) {
hints[INTERACTIVE_HINT] = "targetapp";
}
int timeout = 5000;
QDBusReply<unsigned int> result = service.call("Notify",
app_name, replaces_id, app_icon, summary, body, actions, hints, timeout);
if(!result.isValid()) {
return (NotificationID) -1;
}
return result.value();
}
NotificationID NotificationClient::appendText(NotificationID id, const QString &text) {
QString app_name("append");
QString app_icon;
QString summary;
QStringList actions;
QMap<QString, QVariant> hints;
hints[APPEND_HINT] = QVariant(true);
int timeout = 5000;
QDBusReply<unsigned int> result = service.call("Notify",
app_name, id, app_icon, summary, text, actions, hints, timeout);
if(!result.isValid()) {
return (NotificationID) -1;
}
return result.value();
}
void NotificationClient::NotificationClosed(NotificationID id, unsigned int reason) {
Q_EMIT closed(id, reason);
QString msg("Got NotificationClosed signal for notification ");
msg += QString::number(id, 10);
msg += ".\n";
Q_EMIT eventHappened(msg);
}
void NotificationClient::ActionInvoked(NotificationID id, const QString &key) {
Q_EMIT invoked(id, key);
QString msg("Got ActionInvoked signal for notification ");
msg += QString::number(id, 10);
msg += " event \"";
msg += key;
msg += "\".\n";
Q_EMIT eventHappened(msg);
}
|