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>
32using namespace unity::shell::notifications;
34MockNotificationModel::MockNotificationModel(QObject *parent) : QAbstractListModel(parent) {
37MockNotificationModel::~MockNotificationModel() {
40int MockNotificationModel::rowCount(const QModelIndex &parent) const {
41 return m_queue.size();
44int MockNotificationModel::getCount() const {
45 return m_queue.size();
48QVariant MockNotificationModel::data(const QModelIndex &index, int role) const {
53 case ModelInterface::RoleType:
54 return QVariant(m_queue[index.row()]->getType());
56 case ModelInterface::RoleId:
57 return QVariant(m_queue[index.row()]->getID());
59 case ModelInterface::RoleSummary:
60 return QVariant(m_queue[index.row()]->getSummary());
62 case ModelInterface::RoleBody:
63 return QVariant(m_queue[index.row()]->getBody());
65 case ModelInterface::RoleValue:
66 return QVariant(m_queue[index.row()]->getValue());
68 case ModelInterface::RoleIcon:
69 return QVariant(m_queue[index.row()]->getIcon());
71 case ModelInterface::RoleSecondaryIcon:
72 return QVariant(m_queue[index.row()]->getSecondaryIcon());
74 case ModelInterface::RoleActions:
75 return QVariant::fromValue(m_queue[index.row()]->getActions());
77 case ModelInterface::RoleHints:
78 return QVariant(m_queue[index.row()]->getHints());
80 case ModelInterface::RoleNotification:
81 return QVariant::fromValue(m_queue[index.row()]);
88void MockNotificationModel::append(MockNotification* n) {
89 int location = m_queue.size();
90 QModelIndex insertionPoint = QModelIndex();
91 beginInsertRows(insertionPoint, location, location);
92 m_queue.insert(location, n);
96MockNotification* MockNotificationModel::getNotification(unsigned int id) const {
97 for(int i=0; i < m_queue.size(); i++) {
98 if(m_queue[i]->getID() == id) {
106MockNotification* MockNotificationModel::getNotification(const QString &summary) const {
107 for(int i=0; i < m_queue.size(); i++) {
108 if(m_queue[i]->getSummary() == summary) {
116bool MockNotificationModel::hasNotification(unsigned int id) const {
117 return !(getNotification(id) != nullptr);
120void MockNotificationModel::remove(const unsigned int id) {
121 for(int i = 0; i < m_queue.size(); i++) {
122 if(m_queue[i]->getID() == id) {
123 deleteFromVisible(i);
127 // The ID was not found in any queue. Should it be an error case or not?
130void MockNotificationModel::deleteFirst() {
133 deleteFromVisible(0);
136void MockNotificationModel::deleteFromVisible(int loc) {
137 QModelIndex deletePoint = QModelIndex();
138 beginRemoveRows(deletePoint, loc, loc);
139 m_queue.erase(m_queue.begin() + loc);
143MockNotification* MockNotificationModel::getRaw(const unsigned int notificationId) const {
144 for(int i = 0; i < m_queue.size(); i++) {
145 if(m_queue[i]->getID() == notificationId) {
146 MockNotification* n = m_queue[i];
154int MockNotificationModel::queued() const {
155 return m_queue.size();
158QHash<int, QByteArray> MockNotificationModel::roleNames() const {
159 QHash<int, QByteArray> roles;
161 roles.insert(ModelInterface::RoleType, "type");
162 roles.insert(ModelInterface::RoleUrgency, "urgency");
163 roles.insert(ModelInterface::RoleId, "nid");
164 roles.insert(ModelInterface::RoleSummary, "summary");
165 roles.insert(ModelInterface::RoleBody, "body");
166 roles.insert(ModelInterface::RoleValue, "value");
167 roles.insert(ModelInterface::RoleIcon, "icon");
168 roles.insert(ModelInterface::RoleSecondaryIcon, "secondaryIcon");
169 roles.insert(ModelInterface::RoleActions, "actions");
170 roles.insert(ModelInterface::RoleHints, "hints");
171 roles.insert(ModelInterface::RoleNotification, "notification");
176void MockNotificationModel::onDataChanged(unsigned int id) {
177 for(int i = 0; i < m_queue.size(); i++) {
178 if(m_queue[i]->getID() == id) {
179 Q_EMIT dataChanged(index(i, 0), index(i, 0));
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list