@@ -0,0 +1,185 @@
2+ * Copyright 2015 Canonical Ltd.
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.
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.
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/>.
17+ * Mirco Mueller <mirco.mueller@canonical.com>
20+#include "MockNotificationModel.h"
21+#include "MockNotification.h"
23+#include <unity/shell/notifications/ModelInterface.h>
29+#include <QStringListModel>
33+using namespace unity::shell::notifications;
35+struct MockNotificationModelPrivate {
36+ QList<QSharedPointer<MockNotification> > queue;
39+MockNotificationModel::MockNotificationModel(QObject *parent) : QAbstractListModel(parent), p(new MockNotificationModelPrivate) {
42+MockNotificationModel::~MockNotificationModel() {
45+int MockNotificationModel::rowCount(const QModelIndex &parent) const {
46+ return p->queue.size();
49+QVariant MockNotificationModel::data(const QModelIndex &index, int role) const {
50+ //printf("Data %d.\n", index.row());
51+ if (!index.isValid())
55+ case ModelInterface::RoleType:
56+ return QVariant(p->queue[index.row()]->getType());
58+ case ModelInterface::RoleId:
59+ return QVariant(p->queue[index.row()]->getID());
61+ case ModelInterface::RoleSummary:
62+ return QVariant(p->queue[index.row()]->getSummary());
64+ case ModelInterface::RoleBody:
65+ return QVariant(p->queue[index.row()]->getBody());
67+ case ModelInterface::RoleValue:
68+ return QVariant(p->queue[index.row()]->getValue());
70+ case ModelInterface::RoleIcon:
71+ return QVariant(p->queue[index.row()]->getIcon());
73+ case ModelInterface::RoleSecondaryIcon:
74+ return QVariant(p->queue[index.row()]->getSecondaryIcon());
76+ case ModelInterface::RoleActions:
77+ return QVariant::fromValue(p->queue[index.row()]->getActions());
79+ case ModelInterface::RoleHints:
80+ return QVariant(p->queue[index.row()]->getHints());
82+ case ModelInterface::RoleNotification:
83+ return QVariant(p->queue[index.row()]);
90+void MockNotificationModel::append(const QSharedPointer<MockNotification> &n) {
92+ //qDebug() << "append() called, count:" << p->queue.size() << ", summary: " << QString(p->queue[0]->getSummary());
95+QSharedPointer<MockNotification> MockNotificationModel::getNotification(unsigned int id) const {
96+ for(int i=0; i<p->queue.size(); i++) {
97+ if(p->queue[i]->getID() == id) {
102+ QSharedPointer<MockNotification> empty;
106+QSharedPointer<MockNotification> MockNotificationModel::getNotification(const QString &summary) const {
107+ for(int i=0; i<p->queue.size(); i++) {
108+ if(p->queue[i]->getSummary() == summary) {
113+ QSharedPointer<MockNotification> empty;
117+bool MockNotificationModel::hasNotification(unsigned int id) const {
118+ return !(getNotification(id) != nullptr);
121+void MockNotificationModel::removeNotification(const unsigned int id) {
122+ for(int i=0; i<p->queue.size(); i++) {
123+ if(p->queue[i]->getID() == id) {
124+ deleteFromVisible(i);
128+ // The ID was not found in any queue. Should it be an error case or not?
131+void MockNotificationModel::deleteFirst() {
132+ if(p->queue.empty())
134+ deleteFromVisible(0);
137+void MockNotificationModel::deleteFromVisible(int loc) {
138+ QModelIndex deletePoint = QModelIndex();
139+ beginRemoveRows(deletePoint, loc, loc);
140+ p->queue.erase(p->queue.begin() + loc);
144+MockNotification* MockNotificationModel::getRaw(const unsigned int notificationId) const {
145+ for(int i=0; i<p->queue.size(); i++) {
146+ if(p->queue[i]->getID() == notificationId) {
147+ MockNotification* n = p->queue[i].data();
148+ QQmlEngine::setObjectOwnership(n, QQmlEngine::CppOwnership);
156+int MockNotificationModel::queued() const {
157+ return p->queue.size();
160+QHash<int, QByteArray> MockNotificationModel::roleNames() const {
161+ QHash<int, QByteArray> roles;
163+ roles.insert(ModelInterface::RoleType, "type");
164+ roles.insert(ModelInterface::RoleUrgency, "urgency");
165+ roles.insert(ModelInterface::RoleId, "nid");
166+ roles.insert(ModelInterface::RoleSummary, "summary");
167+ roles.insert(ModelInterface::RoleBody, "body");
168+ roles.insert(ModelInterface::RoleValue, "value");
169+ roles.insert(ModelInterface::RoleIcon, "icon");
170+ roles.insert(ModelInterface::RoleSecondaryIcon, "secondaryIcon");
171+ roles.insert(ModelInterface::RoleActions, "actions");
172+ roles.insert(ModelInterface::RoleHints, "hints");
173+ roles.insert(ModelInterface::RoleNotification, "notification");
178+void MockNotificationModel::onDataChanged(unsigned int id) {
179+ for(int i=0; i<p->queue.size(); i++) {
180+ if(p->queue[i]->getID() == id) {
181+ Q_EMIT dataChanged(index(i, 0), index(i, 0));