on xenial help sign in
Check pointer returned by GetResultsForCategory from UnityCore. Suscribe to change of results model of the scope and reset categories if it happens.
ed85b03Pawel Stolowski
plugins/Unity/categories.cpp+21−1
@@ -21,6 +21,7 @@
21// self
21// self
22#include "categories.h"
22#include "categories.h"
23#include "categoryresults.h"
23#include "categoryresults.h"
24+#include <QDebug>
24
25
25// TODO: use something from libunity once it's public
26// TODO: use something from libunity once it's public
26enum CategoryColumn {
27enum CategoryColumn {
@@ -62,7 +63,16 @@ Categories::getResults(int index) const
62
63
63 unsigned categoryIndex = static_cast<unsigned>(index);
64 unsigned categoryIndex = static_cast<unsigned>(index);
64 auto unity_results = m_unityScope->GetResultsForCategory(categoryIndex);
65 auto unity_results = m_unityScope->GetResultsForCategory(categoryIndex);
66+ if (unity_results) {
65− results->setModel(unity_results->model());
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+ }
66
76
67 m_results.insert(index, results);
77 m_results.insert(index, results);
68 }
78 }
@@ -81,6 +91,13 @@ void Categories::onCategoriesModelChanged(unity::glib::Object<DeeModel> model)
81 setModel(model);
91 setModel(model);
82}
92}
83
93
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+
84void
101void
85Categories::setUnityScope(const unity::dash::Scope::Ptr& scope)
102Categories::setUnityScope(const unity::dash::Scope::Ptr& scope)
86{
103{
@@ -92,6 +109,9 @@ Categories::setUnityScope(const unity::dash::Scope::Ptr& scope)
92 m_categoriesChangedConnection.disconnect();
109 m_categoriesChangedConnection.disconnect();
93 m_categoriesChangedConnection =
110 m_categoriesChangedConnection =
94 m_unityScope->categories()->model.changed.connect(sigc::mem_fun(this, &Categories::onCategoriesModelChanged));
111 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));
95}
115}
96
116
97void
117void
plugins/Unity/categories.h+2
@@ -70,6 +70,7 @@ private Q_SLOTS:
70
70
71private:
71private:
72 void onCategoriesModelChanged(unity::glib::Object<DeeModel> model);
72 void onCategoriesModelChanged(unity::glib::Object<DeeModel> model);
73+ void onScopeResultsModelChanged(unity::glib::Object<DeeModel> model);
73
74
74 DeeListModel* getResults(int index) const;
75 DeeListModel* getResults(int index) const;
75
76
@@ -80,6 +81,7 @@ private:
80 QMap<QString, QAbstractItemModel*> m_overriddenCategories;
81 QMap<QString, QAbstractItemModel*> m_overriddenCategories;
81 mutable QMap<int, DeeListModel*> m_results;
82 mutable QMap<int, DeeListModel*> m_results;
82 sigc::connection m_categoriesChangedConnection;
83 sigc::connection m_categoriesChangedConnection;
84+ sigc::connection m_resultshangedConnection;
83};
85};
84
86
85#endif // CATEGORIES_H
87#endif // CATEGORIES_H