forked from nemomobile/mlite
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmnotificationgroup.cpp
143 lines (126 loc) · 4.81 KB
/
mnotificationgroup.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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
/***************************************************************************
**
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation ([email protected])
**
** This file is part of libmeegotouch.
**
** If you have questions regarding the use of this file, please contact
** Nokia at [email protected].
**
** This library is free software; you can redistribute it and/or
** modify it under the terms of the GNU Lesser General Public
** License version 2.1 as published by the Free Software Foundation
** and appearing in the file LICENSE.LGPL included in the packaging
** of this file.
**
****************************************************************************/
#include "mnotificationmanagerproxy.h"
#include "mnotificationgroup.h"
#include "mnotificationgroup_p.h"
MNotificationGroupPrivate::MNotificationGroupPrivate() : MNotificationPrivate()
{
}
MNotificationGroup::MNotificationGroup() :
MNotification(*new MNotificationGroupPrivate)
{
}
MNotificationGroup::MNotificationGroup(const QString &eventType, const QString &summary, const QString &body) :
MNotification(*new MNotificationGroupPrivate)
{
Q_D(MNotificationGroup);
d->eventType = eventType;
d->summary = summary;
d->body = body;
}
MNotificationGroup::MNotificationGroup(const MNotificationGroup &group) :
MNotification(*new MNotificationGroupPrivate)
{
*this = group;
}
MNotificationGroup::~MNotificationGroup()
{
}
MNotificationGroup::MNotificationGroup(uint id) :
MNotification(*new MNotificationGroupPrivate)
{
Q_D(MNotificationGroup);
d->id = id;
}
QVariantHash MNotificationGroupPrivate::hints() const
{
QVariantHash hints;
hints.insert("category", eventType);
hints.insert("x-nemo-item-count", count);
hints.insert("x-nemo-timestamp", userSetTimestamp);
hints.insert("x-nemo-legacy-type", "MNotificationGroup");
hints.insert("x-nemo-legacy-summary", summary);
hints.insert("x-nemo-legacy-body", body);
hints.insert("x-nemo-user-closeable", false);
if (!identifier.isEmpty()) {
hints.insert("x-nemo-legacy-identifier", identifier);
}
if (!action.isEmpty()) {
hints.insert("x-nemo-remote-action-default", action);
}
return hints;
}
uint MNotificationGroup::notificationCount()
{
int count = 0;
if (notificationManager()->GetCapabilities().value().contains("x-nemo-get-notifications")) {
QList<MNotification> list = notificationManager()->GetNotifications(QFileInfo(QCoreApplication::arguments()[0]).fileName());
foreach(const MNotification ¬ification, list) {
if (notification.property("legacyType").toString() == "MNotification" && notification.groupId() == id()) {
count++;
}
}
} else {
qWarning("Notification manager does not support GetNotifications(). The application may misbehave.");
}
return count;
}
QList<MNotificationGroup *> MNotificationGroup::notificationGroups()
{
QList<MNotificationGroup *> notificationGroupList;
if (notificationManager()->GetCapabilities().value().contains("x-nemo-get-notifications")) {
QList<MNotification> list = notificationManager()->GetNotifications(QFileInfo(QCoreApplication::arguments()[0]).fileName());
foreach(const MNotification ¬ification, list) {
if (notification.property("legacyType").toString() == "MNotificationGroup") {
notificationGroupList.append(new MNotificationGroup(static_cast<const MNotificationGroup &>(notification)));
}
}
} else {
qWarning("Notification manager does not support GetNotifications(). The application may misbehave.");
}
return notificationGroupList;
}
void MNotificationGroup::setTimestamp(const QDateTime &)
{
}
bool MNotificationGroup::publish()
{
return publish(QString(), QString());
}
bool MNotificationGroup::publish(const QString &previewSummary, const QString &previewBody)
{
Q_D(MNotificationGroup);
QVariantHash hints = d->hints();
QString summary;
QString body;
if (d->id != 0 && notificationCount() > 0) {
// Only already published groups may have notifications in them and thus should have a visual representation
summary = hints.value("x-nemo-legacy-summary").toString();
body = hints.value("x-nemo-legacy-body").toString();
// Allow a notification belonging to this group to show a preview banner
if (!previewSummary.isEmpty()) {
hints.insert("x-nemo-preview-summary", previewSummary);
}
if (!previewBody.isEmpty()) {
hints.insert("x-nemo-preview-body", previewBody);
}
}
d->id = notificationManager()->Notify(QFileInfo(QCoreApplication::arguments()[0]).fileName(), d->id, d->image, summary, body, QStringList(), hints, -1);
return d->id != 0;
}