Debian Codegraph @

tests/mocks/Lomiri/Notifications/MockNotification.cpp

raw
1 /*
2 * Copyright 2015 Canonical Ltd.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as published by
6 * the Free Software Foundation; version 3.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authors:
17 * Mirco Mueller <[email protected]>
18 */
19
20 #include "MockNotification.h"
21
22 #include <QDebug>
23
24 struct MockNotificationPrivate {
25 int id;
26 QString summary;
27 QString body;
28 int value;
29 MockNotification::Type type;
30 MockNotification::Urgency urgency = MockNotification::Urgency::Low;
31 QString icon;
32 QString secondaryIcon;
33 QStringList actions;
34 ActionModel* actionsModel;
35 QVariantMap hints;
36 bool fullscreen = false;
37 };
38
39 MockNotification::MockNotification(QObject *parent) : QObject(parent), p(new MockNotificationPrivate()) {
40 p->actionsModel = new ActionModel();
41 }
42
43 MockNotification::~MockNotification() {
44 delete p->actionsModel;
45 }
46
47 QString MockNotification::getSummary() const {
48 return p->summary;
49 }
50
51 void MockNotification::setSummary(const QString &summary) {
52 if(p->summary != summary) {
53 p->summary = summary;
54 Q_EMIT summaryChanged(p->summary);
55 Q_EMIT dataChanged(p->id);
56 }
57 }
58
59 QString MockNotification::getBody() const {
60 return p->body;
61 }
62
63 void MockNotification::setBody(const QString &body) {
64 if(p->body != body) {
65 p->body = body;
66 Q_EMIT bodyChanged(p->body);
67 Q_EMIT dataChanged(p->id);
68 }
69 }
70
71 int MockNotification::getID() const {
72 return p->id;
73 }
74
75 void MockNotification::setID(const int id) {
76 p->id = id;
77 }
78
79 int MockNotification::getValue() const {
80 return p->value;
81 }
82
83 void MockNotification::setValue(int value) {
84 if(p->value != value) {
85 p->value = value;
86 Q_EMIT valueChanged(p->value);
87 Q_EMIT dataChanged(p->id);
88 }
89 }
90
91 QString MockNotification::getIcon() const {
92 return p->icon;
93 }
94
95 void MockNotification::setIcon(const QString &icon) {
96 if (icon.startsWith(" ") || icon.size() == 0) {
97 p->icon = nullptr;
98 }
99 else {
100 p->icon = icon;
101
102 if (icon.indexOf("/") == -1) {
103 p->icon.prepend("image://theme/");
104 }
105 }
106
107 Q_EMIT iconChanged(p->icon);
108 Q_EMIT dataChanged(p->id);
109 }
110
111 QString MockNotification::getSecondaryIcon() const {
112 return p->secondaryIcon;
113 }
114
115 void MockNotification::setSecondaryIcon(const QString &secondaryIcon) {
116 if (secondaryIcon.startsWith(" ") || secondaryIcon.size() == 0) {
117 p->secondaryIcon = nullptr;
118 }
119 else {
120 p->secondaryIcon = secondaryIcon;
121
122 if (secondaryIcon.indexOf("/") == -1) {
123 p->secondaryIcon.prepend("image://theme/");
124 }
125 }
126
127 Q_EMIT secondaryIconChanged(p->secondaryIcon);
128 Q_EMIT dataChanged(p->id);
129 }
130
131 MockNotification::Type MockNotification::getType() const {
132 return p->type;
133 }
134
135 void MockNotification::setType(Type type) {
136 if(p->type != type) {
137 p->type = type;
138 Q_EMIT typeChanged(p->type);
139 }
140 }
141
142 ActionModel* MockNotification::getActions() const {
143 return p->actionsModel;
144 }
145
146 QStringList MockNotification::rawActions() const {
147 return p->actions;
148 }
149
150 void MockNotification::setActions(const QStringList &actions) {
151 if(p->actions != actions) {
152 p->actions = actions;
153 Q_EMIT actionsChanged(p->actions);
154
155 for (int i = 0; i < p->actions.size(); i += 2) {
156 p->actionsModel->append(p->actions[i], p->actions[i+1]);
157 }
158 }
159 }
160
161 QVariantMap MockNotification::getHints() const {
162 return p->hints;
163 }
164
165 void MockNotification::setHints(const QVariantMap& hints) {
166 if (p->hints != hints) {
167 p->hints = hints;
168 Q_EMIT hintsChanged(p->hints);
169 }
170 }
171
172 void MockNotification::invokeAction(const QString &action) {
173 for(int i=0; i<p->actions.size(); i++) {
174 if(p->actions[i] == action) {
175 Q_EMIT actionInvoked(action);
176 qDebug() << "Info: invoked action" << action;
177 return;
178 }
179 }
180 fprintf(stderr, "Error: tried to invoke action not in actionList.\n");
181 }
182
183 void MockNotification::close() {
184 Q_EMIT completed(p->id);
185 }
186
187 bool MockNotification::fullscreen() const
188 {
189 return p->fullscreen;
190 }
191
192 void MockNotification::setFullscreen(bool fullscreen)
193 {
194 if (p->fullscreen == fullscreen)
195 return;
196
197 p->fullscreen = fullscreen;
198 Q_EMIT fullscreenChanged(fullscreen);
199 }
200
201 MockNotification::Urgency MockNotification::getUrgency() const
202 {
203 return p->urgency;
204 }
205
206 void MockNotification::setUrgency(Urgency newUrgency)
207 {
208 if(p->urgency != newUrgency) {
209 p->urgency = newUrgency;
210 }
211 Q_EMIT urgencyChanged(newUrgency);
212 }