2 * Copyright (C) 2016 Canonical, Ltd.
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU 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 General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17#include "appdrawermodel.h"
18#include "ualwrapper.h"
23AppDrawerModel::AppDrawerModel(QObject *parent):
24 AppDrawerModelInterface(parent),
25 m_ual(new UalWrapper(this))
27 Q_FOREACH (const QString &appId, UalWrapper::installedApps()) {
28 UalWrapper::AppInfo info = UalWrapper::getApplicationInfo(appId);
30 qWarning() << "Failed to get app info for app" << appId;
33 LauncherItem* item = new LauncherItem(appId, info.name, info.icon, this);
34 item->setKeywords(info.keywords);
35 item->setPopularity(info.popularity);
39 // keep this a queued connection as it's coming from another thread.
40 connect(m_ual, &UalWrapper::appAdded, this, &AppDrawerModel::appAdded, Qt::QueuedConnection);
41 connect(m_ual, &UalWrapper::appRemoved, this, &AppDrawerModel::appRemoved, Qt::QueuedConnection);
42 connect(m_ual, &UalWrapper::appInfoChanged, this, &AppDrawerModel::appInfoChanged, Qt::QueuedConnection);
45int AppDrawerModel::rowCount(const QModelIndex &parent) const
48 return m_list.count();
51QVariant AppDrawerModel::data(const QModelIndex &index, int role) const
55 return m_list.at(index.row())->appId();
57 return m_list.at(index.row())->name();
59 return m_list.at(index.row())->icon();
61 return m_list.at(index.row())->keywords();
63 return m_list.at(index.row())->popularity();
69void AppDrawerModel::appAdded(const QString &appId)
71 UalWrapper::AppInfo info = UalWrapper::getApplicationInfo(appId);
73 qWarning() << "App added signal received but failed to get app info for app" << appId;
77 beginInsertRows(QModelIndex(), m_list.count(), m_list.count());
78 LauncherItem* item = new LauncherItem(appId, info.name, info.icon, this);
79 item->setKeywords(info.keywords);
80 item->setPopularity(info.popularity);
85void AppDrawerModel::appRemoved(const QString &appId)
88 for (int i = 0; i < m_list.count(); i++) {
89 if (m_list.at(i)->appId() == appId) {
95 qWarning() << "App removed signal received but app doesn't seem to be in the drawer model";
98 beginRemoveRows(QModelIndex(), idx, idx);
99 m_list.takeAt(idx)->deleteLater();
103void AppDrawerModel::appInfoChanged(const QString &appId)
105 LauncherItem *item = nullptr;
108 for(int i = 0; i < m_list.count(); i++) {
109 if (m_list.at(i)->appId() == appId) {
120 UalWrapper::AppInfo info = m_ual->getApplicationInfo(appId);
121 item->setPopularity(info.popularity);
122 Q_EMIT dataChanged(index(idx), index(idx), {AppDrawerModelInterface::RoleUsage});
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