on 00a2ef4 help sign in
unity8/tests/mocks/Unity/Notifications/MockNotification.cpp
183 lines 4.4 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};
37MockNotification::MockNotification(QObject *parent) : QObject(parent), p(new MockNotificationPrivate()) {
38 p->actionsModel = new ActionModel();
41MockNotification::~MockNotification() {
42 delete p->actionsModel;
45QString MockNotification::getSummary() const {
46 return p->summary;
49void MockNotification::setSummary(const QString &summary) {
50 if(p->summary != summary) {
51 p->summary = summary;
52 Q_EMIT summaryChanged(p->summary);
53 Q_EMIT dataChanged(p->id);
54 }
57QString MockNotification::getBody() const {
58 return p->body;
61void MockNotification::setBody(const QString &body) {
62 if(p->body != body) {
63 p->body = body;
64 Q_EMIT bodyChanged(p->body);
65 Q_EMIT dataChanged(p->id);
66 }
69int MockNotification::getID() const {
70 return p->id;
73void MockNotification::setID(const int id) {
74 p->id = id;
77int MockNotification::getValue() const {
78 return p->value;
81void MockNotification::setValue(int value) {
82 if(p->value != value) {
83 p->value = value;
84 Q_EMIT valueChanged(p->value);
85 Q_EMIT dataChanged(p->id);
86 }
89QString MockNotification::getIcon() const {
90 return p->icon;
93void MockNotification::setIcon(const QString &icon) {
94 if (icon.startsWith(" ") || icon.size() == 0) {
95 p->icon = nullptr;
96 }
97 else {
98 p->icon = icon;
100 if (icon.indexOf("/") == -1) {
101 p->icon.prepend("image://theme/");
102 }
103 }
105 Q_EMIT iconChanged(p->icon);
106 Q_EMIT dataChanged(p->id);
109QString MockNotification::getSecondaryIcon() const {
110 return p->secondaryIcon;
113void MockNotification::setSecondaryIcon(const QString &secondaryIcon) {
114 if (secondaryIcon.startsWith(" ") || secondaryIcon.size() == 0) {
115 p->secondaryIcon = nullptr;
116 }
117 else {
118 p->secondaryIcon = secondaryIcon;
120 if (secondaryIcon.indexOf("/") == -1) {
121 p->secondaryIcon.prepend("image://theme/");
122 }
123 }
125 Q_EMIT secondaryIconChanged(p->secondaryIcon);
126 Q_EMIT dataChanged(p->id);
129MockNotification::Type MockNotification::getType() const {
130 return p->type;
133void MockNotification::setType(Type type) {
134 if(p->type != type) {
135 p->type = type;
136 Q_EMIT typeChanged(p->type);
137 }
140ActionModel* MockNotification::getActions() const {
141 return p->actionsModel;
144QStringList MockNotification::rawActions() const {
145 return p->actions;
148void MockNotification::setActions(const QStringList &actions) {
149 if(p->actions != actions) {
150 p->actions = actions;
151 Q_EMIT actionsChanged(p->actions);
153 for (int i = 0; i < p->actions.size(); i += 2) {
154 p->actionsModel->append(p->actions[i], p->actions[i+1]);
155 }
156 }
159QVariantMap MockNotification::getHints() const {
160 return p->hints;
163void MockNotification::setHints(const QVariantMap& hints) {
164 if (p->hints != hints) {
165 p->hints = hints;
166 Q_EMIT hintsChanged(p->hints);
167 }
170void MockNotification::invokeAction(const QString &action) {
171 for(int i=0; i<p->actions.size(); i++) {
172 if(p->actions[i] == action) {
173 Q_EMIT actionInvoked(action);
174 qDebug() << "Info: invoked action" << action;
175 return;
176 }
177 }
178 fprintf(stderr, "Error: tried to invoke action not in actionList.\n");
181void MockNotification::close() {
182 Q_EMIT completed(p->id);