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.
commited85b03f56a5894f4eea70d32c16e0400b9e1fb4 authorPawel Stolowski <pawel.stolowski@canonical.com> dateMon 23 Sep 2013, 15:03 (13 years ago) parent6fe2f9b
2 files changed+23−1
plugins/Unity/categories.cpp+21−1 plugins/Unity/categories.h+2
plugins/Unity/categories.cpp+21−1
@@ -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
plugins/Unity/categories.h+2
@@ -70,6 +70,7 @@ private Q_SLOTS:
7070
7171private:
7272 void onCategoriesModelChanged(unity::glib::Object<DeeModel> model);
73+ void onScopeResultsModelChanged(unity::glib::Object<DeeModel> model);
7374
7475 DeeListModel* getResults(int index) const;
7576
@@ -80,6 +81,7 @@ private:
8081 QMap<QString, QAbstractItemModel*> m_overriddenCategories;
8182 mutable QMap<int, DeeListModel*> m_results;
8283 sigc::connection m_categoriesChangedConnection;
84+ sigc::connection m_resultshangedConnection;
8385};
8486
8587#endif // CATEGORIES_H