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"
19#include "xdgwatcher.h"
24AppDrawerModel::AppDrawerModel(QObject *parent):
25 AppDrawerModelInterface(parent),
26 m_ual(new UalWrapper(this)),
27 m_xdgWatcher(new XdgWatcher(this))
29 Q_FOREACH (const QString &appId, UalWrapper::installedApps()) {
30 UalWrapper::AppInfo info = UalWrapper::getApplicationInfo(appId);
32 qWarning() << "Failed to get app info for app" << appId;
35 LauncherItem* item = new LauncherItem(appId, info.name, info.icon, this);
36 item->setKeywords(info.keywords);
37 item->setPopularity(info.popularity);
41 // keep this a queued connection as it's coming from another thread.
42 connect(m_xdgWatcher, &XdgWatcher::appAdded, this, &AppDrawerModel::appAdded, Qt::QueuedConnection);
43 connect(m_xdgWatcher, &XdgWatcher::appRemoved, this, &AppDrawerModel::appRemoved, Qt::QueuedConnection);
44 connect(m_xdgWatcher, &XdgWatcher::appInfoChanged, this, &AppDrawerModel::appInfoChanged, Qt::QueuedConnection);
47int AppDrawerModel::rowCount(const QModelIndex &parent) const
50 return m_list.count();
53QVariant AppDrawerModel::data(const QModelIndex &index, int role) const
57 return m_list.at(index.row())->appId();
59 return m_list.at(index.row())->name();
61 return m_list.at(index.row())->icon();
63 return m_list.at(index.row())->keywords();
65 return m_list.at(index.row())->popularity();
71void AppDrawerModel::appAdded(const QString &appId)
73 UalWrapper::AppInfo info = UalWrapper::getApplicationInfo(appId);
75 qWarning() << "App added signal received but failed to get app info for app" << appId;
79 beginInsertRows(QModelIndex(), m_list.count(), m_list.count());
80 LauncherItem* item = new LauncherItem(appId, info.name, info.icon, this);
81 item->setKeywords(info.keywords);
82 item->setPopularity(info.popularity);
87void AppDrawerModel::appRemoved(const QString &appId)
90 for (int i = 0; i < m_list.count(); i++) {
91 if (m_list.at(i)->appId() == appId) {
97 qWarning() << "App removed signal received but app doesn't seem to be in the drawer model";
100 beginRemoveRows(QModelIndex(), idx, idx);
101 m_list.takeAt(idx)->deleteLater();
105void AppDrawerModel::appInfoChanged(const QString &appId)
107 LauncherItem *item = nullptr;
110 for(int i = 0; i < m_list.count(); i++) {
111 if (m_list.at(i)->appId() == appId) {
122 UalWrapper::AppInfo info = m_ual->getApplicationInfo(appId);
123 item->setPopularity(info.popularity);
124 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