on b46e4cb help sign in
unity8/tests/mocks/Unity/Launcher/MockLauncherModel.cpp
102 lines 3.5 kB history raw
1/*
2 * Copyright 2013 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 * Michael Zanetti <michael.zanetti@canonical.com>
18 */
20#include "MockLauncherModel.h"
21#include "MockLauncherItem.h"
23MockLauncherModel::MockLauncherModel(QObject* parent): LauncherModelInterface(parent)
25 LauncherItemInterface *item = new MockLauncherItem("/usr/share/applications/phone-app.desktop", "Phone", "phone-app");
26 m_list.append(item);
27 item = new MockLauncherItem("/usr/share/applications/camera-app.desktop", "Camera", "camera");
28 m_list.append(item);
29 item = new MockLauncherItem("/usr/share/applications/gallery-app.desktop", "Gallery", "gallery");
30 m_list.append(item);
31 item = new MockLauncherItem("/usr/share/applications/facebook-webapp.desktop", "Facebook", "facebook");
32 m_list.append(item);
33 item = new MockLauncherItem("/usr/share/applications/webbrowser-app.desktop", "Browser", "browser");
34 m_list.append(item);
35 item = new MockLauncherItem("/usr/share/applications/twitter-webapp.desktop", "Twitter", "twitter");
36 m_list.append(item);
37 item = new MockLauncherItem("/usr/share/applications/gmail-webapp.desktop", "GMail", "gmail");
38 m_list.append(item);
39 item = new MockLauncherItem("/usr/share/applications/ubuntu-weather-app.desktop", "Weather", "weather");
40 m_list.append(item);
41 item = new MockLauncherItem("/usr/share/applications/notes-app.desktop", "Notepad", "notepad");
42 m_list.append(item);
43 item = new MockLauncherItem("/usr/share/applications/ubuntu-calendar-app.desktop","Calendar", "calendar");
44 m_list.append(item);
47MockLauncherModel::~MockLauncherModel()
49 while (!m_list.empty())
50 {
51 m_list.takeFirst()->deleteLater();
52 }
55// cppcheck-suppress unusedFunction
56int MockLauncherModel::rowCount(const QModelIndex& parent) const
58 Q_UNUSED(parent)
59 return m_list.count();
62QVariant MockLauncherModel::data(const QModelIndex& index, int role) const
64 LauncherItemInterface *item = m_list.at(index.row());
65 switch(role)
66 {
67 case RoleDesktopFile:
68 return item->desktopFile();
69 case RoleName:
70 return item->name();
71 case RoleIcon:
72 return item->icon();
73 case RoleFavorite:
74 return item->favorite();
75 case RoleRunning:
76 return item->running();
77 case RoleRecent:
78 return item->recent();
79 case RoleProgress:
80 return item->progress();
81 case RoleCount:
82 return item->count();
83 }
85 return QVariant();
88unity::shell::launcher::LauncherItemInterface *MockLauncherModel::get(int index) const
90 if (index < 0 || index >= m_list.count())
91 {
92 return 0;
93 }
94 return m_list.at(index);
97void MockLauncherModel::move(int oldIndex, int newIndex)
99 beginMoveRows(QModelIndex(), oldIndex, oldIndex, QModelIndex(), newIndex);
100 m_list.move(oldIndex, newIndex);
101 endMoveRows();