@@ -19,11 +19,10 @@
1919
2020// self
2121#include "categories.h"
22−#include "categoryfilter.h"
22+#include "categoryresults.h"
2323
2424Categories::Categories(QObject* parent)
2525 : DeeListModel(parent)
26− , m_resultModel(0)
2726{
2827 // FIXME: need to clean up unused filters on countChanged
2928 m_roles[Categories::RoleId] = "id";
@@ -45,42 +44,57 @@ Categories::Categories(QObject* parent)
4544
4645Categories::~Categories()
4746{
48− qDeleteAll(m_filters);
4947}
5048
51−CategoryFilter*
49+DeeListModel*
5250Categories::getFilter(int index) const
5351{
5452 if (!m_filters.contains(index)) {
55− CategoryFilter* filter = new CategoryFilter();
56− connect(filter, SIGNAL(countChanged()), this, SLOT(onCountChanged()));
57− filter->setModel(m_resultModel);
58− filter->setIndex(index);
53+ auto results = std::make_shared<CategoryResults> ();
54+ results->setCategoryIndex(index);
55+ connect(results.get(), SIGNAL(countChanged()), this, SLOT(onCountChanged()));
5956
60− m_filters.insert(index, filter);
57+ unsigned cat_index = static_cast<unsigned>(index);
58+ auto unity_results = m_unityScope->GetResultsForCategory(cat_index);
59+ results->setModel(unity_results->model());
60+
61+ m_filters.insert(index, results);
6162 }
6263
63− return m_filters[index];
64+ return m_filters[index].get();
65+}
66+
67+void Categories::onCategoriesModelChanged(unity::glib::Object<DeeModel> model)
68+{
69+ m_timerFilters.clear();
70+ m_filters.clear();
71+
72+ setModel(model);
6473}
6574
6675void
67−Categories::setResultModel(DeeListModel* model)
76+Categories::setUnityScope(const unity::dash::Scope::Ptr& scope)
6877{
69− if (model != m_resultModel) {
70− m_resultModel = model;
78+ m_unityScope = scope;
7179
80+ // no need to call this, we'll get notified
81+ //setModel(m_unityScope->categories()->model());
82+
83+ m_unityScope->categories()->model.changed.connect(sigc::mem_fun(this, &Categories::onCategoriesModelChanged));
84+
85+ /*
86+ if (model != m_resultModel) {
7287 Q_FOREACH(CategoryFilter* filter, m_filters) {
7388 filter->setModel(m_resultModel);
7489 }
75−
76− Q_EMIT resultModelChanged(m_resultModel);
7790 }
91+ */
7892}
7993
8094void
8195Categories::onCountChanged()
8296{
83− CategoryFilter* filter = qobject_cast<CategoryFilter*>(sender());
97+ DeeListModel* filter = qobject_cast<DeeListModel*>(sender());
8498 if (filter) {
8599 m_timerFilters << filter;
86100 m_timer.start();
@@ -92,8 +106,9 @@ Categories::onEmitCountChanged()
92106{
93107 QVector<int> roles;
94108 roles.append(Categories::RoleCount);
95− Q_FOREACH(CategoryFilter* filter, m_timerFilters) {
96− QModelIndex changedIndex = index(filter->index());
109+ Q_FOREACH(DeeListModel* results, m_timerFilters) {
110+ auto cat_results = qobject_cast<CategoryResults*>(results);
111+ QModelIndex changedIndex = index(cat_results->categoryIndex());
97112 Q_EMIT dataChanged(changedIndex, changedIndex, roles);
98113 }
99114 m_timerFilters.clear();
@@ -116,25 +131,22 @@ Categories::data(const QModelIndex& index, int role) const
116131 case RoleId:
117132 return QVariant::fromValue(index.row());
118133 case RoleName:
119− return QVariant::fromValue(DeeListModel::data(index, 1)); //DISPLAY_NAME
134+ return DeeListModel::data(index, 1); //DISPLAY_NAME
120135 case RoleIcon:
121− return QVariant::fromValue(DeeListModel::data(index, 2)); //ICON_HINT
136+ return DeeListModel::data(index, 2); //ICON_HINT
122137 case RoleRenderer:
123− return QVariant::fromValue(DeeListModel::data(index, 3)); //RENDERER_NAME
138+ return DeeListModel::data(index, 3); //RENDERER_NAME
124139 case RoleContentType:
125140 {
126− auto hints = QVariant::fromValue(DeeListModel::data(index, 4)).toHash();
141+ auto hints = DeeListModel::data(index, 4).toHash();
127142 return hints.contains("content-type") ? hints["content-type"] : QVariant(QString("default"));
128143 }
129144 case RoleHints:
130− return QVariant::fromValue(DeeListModel::data(index, 4)); //HINTS
145+ return DeeListModel::data(index, 4); //HINTS
131146 case RoleResults:
132147 return QVariant::fromValue(getFilter(index.row()));
133148 case RoleCount:
134− {
135− CategoryFilter* filter = getFilter(index.row());
136− return QVariant::fromValue(filter->rowCount());
137− }
149+ return QVariant::fromValue(getFilter(index.row())->rowCount());
138150 default:
139151 return QVariant();
140152 }