| 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 |
*/ |
| 17 |
|
| 18 |
#include "MockAppDrawerModel.h" |
| 19 |
#include <QRandomGenerator> |
| 20 |
#include <QDebug> |
| 21 |
#include <QDateTime> |
| 22 |
#include <QTimer> |
| 23 |
|
| 24 |
MockAppDrawerModel::MockAppDrawerModel(QObject *parent): |
| 25 |
AppDrawerModelInterface(parent), |
| 26 |
m_refresing(false) |
| 27 |
{ |
| 28 |
MockLauncherItem *item = new MockLauncherItem("lomiri-dialer-app", "/usr/share/applications/lomiri-dialer-app.desktop", "Dialer", "lomiri-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("lomiri-weather-app", "/usr/share/applications/lomiri-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); |
| 54 |
} |
| 55 |
|
| 56 |
int MockAppDrawerModel::rowCount(const QModelIndex & /*parent*/) const |
| 57 |
{ |
| 58 |
return m_list.count(); |
| 59 |
} |
| 60 |
|
| 61 |
QVariant MockAppDrawerModel::data(const QModelIndex &index, int role) const |
| 62 |
{ |
| 63 |
switch (role) { |
| 64 |
case RoleAppId: |
| 65 |
return m_list.at(index.row())->appId(); |
| 66 |
case RoleName: |
| 67 |
return m_list.at(index.row())->name(); |
| 68 |
case RoleIcon: |
| 69 |
return m_list.at(index.row())->icon(); |
| 70 |
case RoleUsage: |
| 71 |
return QRandomGenerator::global()->generate(); |
| 72 |
} |
| 73 |
|
| 74 |
return QVariant(); |
| 75 |
} |
| 76 |
|
| 77 |
bool MockAppDrawerModel::refreshing() { |
| 78 |
return m_refresing; |
| 79 |
} |
| 80 |
|
| 81 |
void MockAppDrawerModel::refresh() { |
| 82 |
if (m_refresing) |
| 83 |
return; |
| 84 |
|
| 85 |
m_refresing = true; |
| 86 |
Q_EMIT refreshingChanged(); |
| 87 |
|
| 88 |
QTimer::singleShot(/* msec */ 1000, this, [this] { |
| 89 |
beginResetModel(); |
| 90 |
// Pretended that the data has changed; |
| 91 |
endResetModel(); |
| 92 |
|
| 93 |
m_refresing = false; |
| 94 |
Q_EMIT refreshingChanged(); |
| 95 |
}); |
| 96 |
} |