on d52dc2c help sign in
unity8/tests/mocks/Unity/Launcher/MockAppDrawerModel.cpp
98 lines 3.8 kB history raw
1/*
2 * Copyright (C) 2016 Canonical, Ltd.
3 * Copyright (C) 2020 UBports Foundation.
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; version 3.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
18#include "MockAppDrawerModel.h"
20#include <QDebug>
21#include <QDateTime>
22#include <QTimer>
24MockAppDrawerModel::MockAppDrawerModel(QObject *parent):
25 AppDrawerModelInterface(parent),
26 m_refresing(false)
28 MockLauncherItem *item = new MockLauncherItem("dialer-app", "/usr/share/applications/dialer-app.desktop", "Dialer", "dialer-app", this);
29 m_list.append(item);
30 item = new MockLauncherItem("camera-app", "/usr/share/applications/camera-app.desktop", "Camera", "camera", this);
31 m_list.append(item);
32 item = new MockLauncherItem("camera-app2", "/usr/share/applications/camera-app2.desktop", "Camera2", "camera", this);
33 m_list.append(item);
34 item = new MockLauncherItem("gallery-app", "/usr/share/applications/gallery-app.desktop", "Gallery", "gallery", this);
35 m_list.append(item);
36 item = new MockLauncherItem("music-app", "/usr/share/applications/music-app.desktop", "Music", "soundcloud", this);
37 m_list.append(item);
38 item = new MockLauncherItem("facebook-webapp", "/usr/share/applications/facebook-webapp.desktop", "Facebook", "facebook", this);
39 m_list.append(item);
40 item = new MockLauncherItem("morph-browser", "/usr/share/applications/morph-browser.desktop", "Browser", "browser", this);
41 m_list.append(item);
42 item = new MockLauncherItem("twitter-webapp", "/usr/share/applications/twitter-webapp.desktop", "Twitter", "twitter", this);
43 m_list.append(item);
44 item = new MockLauncherItem("gmail-webapp", "/usr/share/applications/gmail-webapp.desktop", "GMail", "gmail", this);
45 m_list.append(item);
46 item = new MockLauncherItem("ubuntu-weather-app", "/usr/share/applications/ubuntu-weather-app.desktop", "Weather", "weather", this);
47 m_list.append(item);
48 item = new MockLauncherItem("notes-app", "/usr/share/applications/notes-app.desktop", "Notepad", "notepad", this);
49 m_list.append(item);
50 item = new MockLauncherItem("calendar-app", "/usr/share/applications/calendar-app.desktop","Calendar", "calendar", this);
51 m_list.append(item);
52 item = new MockLauncherItem("libreoffice", "/usr/share/applications/libreoffice.desktop","Libre Office Writer", "libreoffice", this);
53 m_list.append(item);
55 qsrand(QDateTime::currentMSecsSinceEpoch() / 1000);
58int MockAppDrawerModel::rowCount(const QModelIndex & /*parent*/) const
60 return m_list.count();
63QVariant MockAppDrawerModel::data(const QModelIndex &index, int role) const
65 switch (role) {
66 case RoleAppId:
67 return m_list.at(index.row())->appId();
68 case RoleName:
69 return m_list.at(index.row())->name();
70 case RoleIcon:
71 return m_list.at(index.row())->icon();
72 case RoleUsage:
73 return qrand();
74 }
76 return QVariant();
79bool MockAppDrawerModel::refreshing() {
80 return m_refresing;
83void MockAppDrawerModel::refresh() {
84 if (m_refresing)
85 return;
87 m_refresing = true;
88 Q_EMIT refreshingChanged();
90 QTimer::singleShot(/* msec */ 1000, this, [this] {
91 beginResetModel();
92 // Pretended that the data has changed;
93 endResetModel();
95 m_refresing = false;
96 Q_EMIT refreshingChanged();
97 });