-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathnotifier.cpp
129 lines (105 loc) · 3.69 KB
/
notifier.cpp
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
/*
Hanghish
Copyright (C) 2015 Daniele Rogora
This file is part of Hangish.
Hangish is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Hangish 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 hangish. If not, see <http://www.gnu.org/licenses/>
*/
#include "notifier.h"
#include "adaptor.h"
static const char *SERVICE = "harbour.hangish";
static const char *PATH = "/";
Notifier::Notifier(QObject *parent, ContactsModel *contacts) :
QObject(parent)
{
cModel = contacts;
myParent = parent;
lastId = 0;
new HangishAdaptor(this);
QDBusConnection connection = QDBusConnection::sessionBus();
if (!connection.registerService(SERVICE)) {
qDebug() << "Failed to register DBus service";
return;
}
if (!connection.registerObject(PATH, this)) {
qDebug() << "Failed to register DBus object";
return;
}
}
void Notifier::wakeUp()
{
emit notificationPushed("foo");
}
void Notifier::test()
{
qDebug() << "test succeeded!";
}
void Notifier::notificationPushedIntf(const QString &convId)
{
emit notificationPushed(convId);
}
void Notifier::closeAllNotifications()
{
foreach (Notification *n, activeNotifications) {
n->close();
delete n;
}
activeNotifications.clear();
emit deletedNotifications();
}
void Notifier::showNotification(QString preview, QString summary, QString body, QString sender, int num, QString convId)
{
//if acs == 2 another client is active, don't fire notification!
if (activeClientState == OTHER_CLIENT_IS_ACTIVE) {
qDebug() << "There's another client active, dropping notification!";
return;
}
//Check notification aspect
Notification *n = new Notification(myParent);
n->setCategory("x-nemo.messaging.im");
// I may want to personalize the notification, need to create and publish a custom hangish.ini in /usr/share/ngfd/events.d/
// ... or, else, I could hope that everyone that uses hangish also uses sailogram, and
// borrow their notification... Maybe harbours would be ok with this :)
n->setHintValue("x-nemo-feedback", "chat_exists");
n->setHintValue("x-nemo-preview-icon", "harbour-hangish");
//n->setHintValue("x-nemo-priority", 100);
//n->setHintValue("lowPowerModeIconId", "hangish-notif-icon");
//n->setHintValue("statusAreaIconId", "hangish-notif-icon");
n->setItemCount(1);
n->setBody(body);
n->setPreviewBody(preview);
n->setSummary(cModel->getContactDName(sender));
n->setTimestamp(QDateTime::currentDateTime());
n->setRemoteDBusCallServiceName("harbour.hangish");
n->setRemoteDBusCallObjectPath("/");
n->setRemoteDBusCallInterface("harbour.hangish");
n->setRemoteDBusCallMethodName("notificationPushedIntf");
n->setRemoteDBusCallArguments(QVariantList() << convId);
emit showNotificationForCover(num);
n->publish();
lastId = n->replacesId();
qDebug() << "pubbed " << n->replacesId();
activeNotifications.append(n);
}
void Notifier::activeClientUpdate(int state)
{
activeClientState = state;
if (activeClientState == OTHER_CLIENT_IS_ACTIVE)
closeAllNotifications();
}
bool Notifier::isAnotherClientActive()
{
return activeClientState == OTHER_CLIENT_IS_ACTIVE;
}
bool Notifier::amITheActiveClient()
{
return activeClientState == IS_ACTIVE_CLIENT;
}