on 44dae67 help sign in
unity8/tests/mocks/Unity/Notifications/MockNotification.cpp
175 lines 4.3 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"
22struct MockNotificationPrivate {
23 unsigned int id;
24 QString summary;
25 QString body;
26 int value;
27 MockNotification::Type type;
28 QString icon;
29 QString secondaryIcon;
30 QStringList actions;
31 ActionModel* actionsModel;
32 QVariantMap hints;
33};
35MockNotification::MockNotification(QObject *parent) : QObject(parent), p(new MockNotificationPrivate()) {
36 p->actionsModel = new ActionModel();
39MockNotification::~MockNotification() {
42QString MockNotification::getSummary() const {
43 return p->summary;
46void MockNotification::setSummary(const QString &summary) {
47 if(p->summary != summary) {
48 p->summary = summary;
49 Q_EMIT summaryChanged(p->summary);
50 Q_EMIT dataChanged(p->id);
51 }
54QString MockNotification::getBody() const {
55 return p->body;
58void MockNotification::setBody(const QString &body) {
59 if(p->body != body) {
60 p->body = body;
61 Q_EMIT bodyChanged(p->body);
62 Q_EMIT dataChanged(p->id);
63 }
66unsigned int MockNotification::getID() const {
67 return p->id;
70void MockNotification::setID(const unsigned int id) {
71 p->id = id;
74int MockNotification::getValue() const {
75 return p->value;
78void MockNotification::setValue(int value) {
79 if(p->value != value) {
80 p->value = value;
81 Q_EMIT valueChanged(p->value);
82 Q_EMIT dataChanged(p->id);
83 }
86QString MockNotification::getIcon() const {
87 return p->icon;
90void MockNotification::setIcon(const QString &icon) {
91 if (icon.startsWith(" ") || icon.size() == 0) {
92 p->icon = nullptr;
93 }
94 else {
95 p->icon = icon;
97 if (icon.indexOf("/") == -1) {
98 p->icon.prepend("image://theme/");
99 }
100 }
102 Q_EMIT iconChanged(p->icon);
103 Q_EMIT dataChanged(p->id);
106QString MockNotification::getSecondaryIcon() const {
107 return p->secondaryIcon;
110void MockNotification::setSecondaryIcon(const QString &secondaryIcon) {
111 if (secondaryIcon.startsWith(" ") || secondaryIcon.size() == 0) {
112 p->secondaryIcon = nullptr;
113 }
114 else {
115 p->secondaryIcon = secondaryIcon;
117 if (secondaryIcon.indexOf("/") == -1) {
118 p->secondaryIcon.prepend("image://theme/");
119 }
120 }
122 Q_EMIT secondaryIconChanged(p->secondaryIcon);
123 Q_EMIT dataChanged(p->id);
126MockNotification::Type MockNotification::getType() const {
127 return p->type;
130void MockNotification::setType(Type type) {
131 if(p->type != type) {
132 p->type = type;
133 Q_EMIT typeChanged(p->type);
134 }
137ActionModel* MockNotification::getActions() const {
138 return p->actionsModel;
141void MockNotification::setActions(const QStringList &actions) {
142 if(p->actions != actions) {
143 p->actions = actions;
144 Q_EMIT actionsChanged(p->actions);
146 for (int i = 0; i < p->actions.size(); i += 2) {
147 p->actionsModel->insertAction(p->actions[i], p->actions[i+1]);
148 }
149 }
152QVariantMap MockNotification::getHints() const {
153 return p->hints;
156void MockNotification::setHints(const QVariantMap& hints) {
157 if (p->hints != hints) {
158 p->hints = hints;
159 Q_EMIT hintsChanged(p->hints);
160 }
163void MockNotification::invokeAction(const QString &action) {
164 for(int i=0; i<p->actions.size(); i++) {
165 if(p->actions[i] == action) {
166 Q_EMIT completed(p->id);
167 return;
168 }
169 }
170 fprintf(stderr, "Error: tried to invoke action not in actionList.\n");
173void MockNotification::close() {
174 Q_EMIT completed(p->id);