2 * Copyright (C) 2013 Canonical, Ltd.
5 * Michał Sawicz <michal.sawicz@canonical.com>
6 * Michal Hruby <michal.hruby@canonical.com>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; version 3.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
22#include "categories.h"
23#include "categoryresults.h"
25// TODO: use something from libunity once it's public
34Categories::Categories(QObject* parent)
35 : DeeListModel(parent)
37 m_roles[Categories::RoleId] = "id";
38 m_roles[Categories::RoleName] = "name";
39 m_roles[Categories::RoleIcon] = "icon";
40 m_roles[Categories::RoleRenderer] = "renderer";
41 m_roles[Categories::RoleContentType] = "contentType";
42 m_roles[Categories::RoleHints] = "hints";
43 m_roles[Categories::RoleResults] = "results";
44 m_roles[Categories::RoleCount] = "count";
46 // TODO This should not be needed but accumulatting the count changes
47 // makes the visualization more stable and also makes crashes on fast
48 // change of the search term harder to reproduce
49 m_timer.setSingleShot(true);
50 m_timer.setInterval(50);
51 connect(&m_timer, &QTimer::timeout, this, &Categories::onEmitCountChanged);
55Categories::getResults(int index) const
57 if (!m_results.contains(index)) {
58 CategoryResults* results = new CategoryResults(const_cast<Categories*>(this));
59 results->setCategoryIndex(index);
60 connect(results, &DeeListModel::countChanged, this, &Categories::onCountChanged);
62 unsigned categoryIndex = static_cast<unsigned>(index);
63 auto unity_results = m_unityScope->GetResultsForCategory(categoryIndex);
64 results->setModel(unity_results->model());
66 m_results.insert(index, results);
69 return m_results[index];
72void Categories::onCategoriesModelChanged(unity::glib::Object<DeeModel> model)
74 m_updatedCategories.clear();
75 // FIXME: this might destroy the renderer view and re-create it, optimize?
76 Q_FOREACH(DeeListModel* model, m_results) {
84Categories::setUnityScope(const unity::dash::Scope::Ptr& scope)
88 // no need to call this, we'll get notified
89 //setModel(m_unityScope->categories()->model());
91 m_categoriesChangedConnection.disconnect();
92 m_categoriesChangedConnection =
93 m_unityScope->categories()->model.changed.connect(sigc::mem_fun(this, &Categories::onCategoriesModelChanged));
97Categories::onCountChanged()
99 CategoryResults* results = qobject_cast<CategoryResults*>(sender());
101 m_updatedCategories << results->categoryIndex();
107Categories::onEmitCountChanged()
110 roles.append(Categories::RoleCount);
111 Q_FOREACH(int categoryIndex, m_updatedCategories) {
112 if (!m_results.contains(categoryIndex)) continue;
113 QModelIndex changedIndex = index(categoryIndex);
114 Q_EMIT dataChanged(changedIndex, changedIndex, roles);
116 m_updatedCategories.clear();
119QHash<int, QByteArray>
120Categories::roleNames() const
126Categories::data(const QModelIndex& index, int role) const
128 if (!index.isValid()) {
134 return QVariant::fromValue(index.row());
136 return DeeListModel::data(index, CategoryColumn::DISPLAY_NAME);
138 return DeeListModel::data(index, CategoryColumn::ICON_HINT);
140 return DeeListModel::data(index, CategoryColumn::RENDERER_NAME);
141 case RoleContentType:
143 auto hints = DeeListModel::data(index, CategoryColumn::HINTS).toHash();
144 return hints.contains("content-type") ? hints["content-type"] : QVariant(QString("default"));
147 return DeeListModel::data(index, CategoryColumn::HINTS);
149 return QVariant::fromValue(getResults(index.row()));
151 return QVariant::fromValue(getResults(index.row())->rowCount());
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