on bionic help sign in
unity8/tests/mocks/Unity/Notifications/MockNotification.cpp
198 lines 4.7 kB history 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 <mirco.mueller@canonical.com>
18 */
20#include "MockNotification.h"
22#include <QDebug>
24struct MockNotificationPrivate {
25 int id;
26 QString summary;
27 QString body;
28 int value;
29 MockNotification::Type type;
30 QString icon;
31 QString secondaryIcon;
32 QStringList actions;
33 ActionModel* actionsModel;
34 QVariantMap hints;
35 bool fullscreen = false;
36};
38MockNotification::MockNotification(QObject *parent) : QObject(parent), p(new MockNotificationPrivate()) {
39 p->actionsModel = new ActionModel();
42MockNotification::~MockNotification() {
43 delete p->actionsModel;
46QString MockNotification::getSummary() const {
47 return p->summary;
50void MockNotification::setSummary(const QString &summary) {
51 if(p->summary != summary) {
52 p->summary = summary;
53 Q_EMIT summaryChanged(p->summary);
54 Q_EMIT dataChanged(p->id);
55 }
58QString MockNotification::getBody() const {
59 return p->body;
62void MockNotification::setBody(const QString &body) {
63 if(p->body != body) {
64 p->body = body;
65 Q_EMIT bodyChanged(p->body);
66 Q_EMIT dataChanged(p->id);
67 }
70int MockNotification::getID() const {
71 return p->id;
74void MockNotification::setID(const int id) {
75 p->id = id;
78int MockNotification::getValue() const {
79 return p->value;
82void MockNotification::setValue(int value) {
83 if(p->value != value) {
84 p->value = value;
85 Q_EMIT valueChanged(p->value);
86 Q_EMIT dataChanged(p->id);
87 }
90QString MockNotification::getIcon() const {
91 return p->icon;
94void MockNotification::setIcon(const QString &icon) {
95 if (icon.startsWith(" ") || icon.size() == 0) {
96 p->icon = nullptr;
97 }
98 else {
99 p->icon = icon;
101 if (icon.indexOf("/") == -1) {
102 p->icon.prepend("image://theme/");
103 }
104 }
106 Q_EMIT iconChanged(p->icon);
107 Q_EMIT dataChanged(p->id);
110QString MockNotification::getSecondaryIcon() const {
111 return p->secondaryIcon;
114void MockNotification::setSecondaryIcon(const QString &secondaryIcon) {
115 if (secondaryIcon.startsWith(" ") || secondaryIcon.size() == 0) {
116 p->secondaryIcon = nullptr;
117 }
118 else {
119 p->secondaryIcon = secondaryIcon;
121 if (secondaryIcon.indexOf("/") == -1) {
122 p->secondaryIcon.prepend("image://theme/");
123 }
124 }
126 Q_EMIT secondaryIconChanged(p->secondaryIcon);
127 Q_EMIT dataChanged(p->id);
130MockNotification::Type MockNotification::getType() const {
131 return p->type;
134void MockNotification::setType(Type type) {
135 if(p->type != type) {
136 p->type = type;
137 Q_EMIT typeChanged(p->type);
138 }
141ActionModel* MockNotification::getActions() const {
142 return p->actionsModel;
145QStringList MockNotification::rawActions() const {
146 return p->actions;
149void MockNotification::setActions(const QStringList &actions) {
150 if(p->actions != actions) {
151 p->actions = actions;
152 Q_EMIT actionsChanged(p->actions);
154 for (int i = 0; i < p->actions.size(); i += 2) {
155 p->actionsModel->append(p->actions[i], p->actions[i+1]);
156 }
157 }
160QVariantMap MockNotification::getHints() const {
161 return p->hints;
164void MockNotification::setHints(const QVariantMap& hints) {
165 if (p->hints != hints) {
166 p->hints = hints;
167 Q_EMIT hintsChanged(p->hints);
168 }
171void MockNotification::invokeAction(const QString &action) {
172 for(int i=0; i<p->actions.size(); i++) {
173 if(p->actions[i] == action) {
174 Q_EMIT actionInvoked(action);
175 qDebug() << "Info: invoked action" << action;
176 return;
177 }
178 }
179 fprintf(stderr, "Error: tried to invoke action not in actionList.\n");
182void MockNotification::close() {
183 Q_EMIT completed(p->id);
186bool MockNotification::fullscreen() const
188 return p->fullscreen;
191void MockNotification::setFullscreen(bool fullscreen)
193 if (p->fullscreen == fullscreen)
194 return;
196 p->fullscreen = fullscreen;
197 Q_EMIT fullscreenChanged(fullscreen);