@@ -21,6 +21,7 @@
2121// self
2222#include "categories.h"
2323#include "categoryresults.h"
24+#include <QDebug>
2425
2526// TODO: use something from libunity once it's public
2627enum CategoryColumn {
@@ -62,7 +63,16 @@ Categories::getResults(int index) const
6263
6364 unsigned categoryIndex = static_cast<unsigned>(index);
6465 auto unity_results = m_unityScope->GetResultsForCategory(categoryIndex);
65− results->setModel(unity_results->model());
66+ if (unity_results) {
67+ results->setModel(unity_results->model());
68+ } else {
69+ // No results model returned by unity core; this can be the case when the global
70+ // results model of this scope became invalid in unity core. Don't set backend
71+ // model in DeeListModel - it will still beahve properly as an empty model. Since
72+ // we're connected to the results model change signal, we'll reset category models
73+ // when results model is set again.
74+ qWarning() << "No results model for category" << categoryIndex;
75+ }
6676
6777 m_results.insert(index, results);
6878 }
@@ -81,6 +91,13 @@ void Categories::onCategoriesModelChanged(unity::glib::Object<DeeModel> model)
8191 setModel(model);
8292}
8393
94+
95+void Categories::onScopeResultsModelChanged(unity::glib::Object<DeeModel> /* model */)
96+{
97+ // if scope results model changes, we need to reset all category models
98+ onCategoriesModelChanged(m_unityScope->categories()->model());
99+}
100+
84101void
85102Categories::setUnityScope(const unity::dash::Scope::Ptr& scope)
86103{
@@ -92,6 +109,9 @@ Categories::setUnityScope(const unity::dash::Scope::Ptr& scope)
92109 m_categoriesChangedConnection.disconnect();
93110 m_categoriesChangedConnection =
94111 m_unityScope->categories()->model.changed.connect(sigc::mem_fun(this, &Categories::onCategoriesModelChanged));
112+
113+ m_resultshangedConnection.disconnect();
114+ m_resultshangedConnection = m_unityScope->results()->model.changed.connect(sigc::mem_fun(this, &Categories::onScopeResultsModelChanged));
95115}
96116
97117void