on xenial help sign in
Fix issues brought up in review
commit740f52bb4f0a036135015ec509cf275d05a2c110 authorMichal Hruby <michal.mhr@gmail.com> dateThu 4 Jul 2013, 12:14 (13 years ago) parent1b817d4
8 files changed+62−46
Dash/GenericScopeView.qml+2−2 plugins/Unity/categories.cpp+32−23 plugins/Unity/categories.h+3−3 plugins/Unity/categoryresults.cpp+22−13 plugins/Unity/categoryresults.h−2 plugins/Unity/plugin.cpp+1−1 tests/plugins/Unity/CMakeLists.txt+1−1 tests/qmltests/plugins/Unity/fake_unity_plugin.cpp+1−1
Dash/GenericScopeView.qml+2−2
@@ -72,10 +72,10 @@ ScopeView {
7272 delegate: Tile {
7373 width: filtergrid.cellWidth
7474 height: filtergrid.cellHeight
75− text: title ? title : "" // FIXME: this shouldn't be necessary
75+ text: title
7676 imageWidth: units.gu(11)
7777 imageHeight: units.gu(16)
78− source: icon ? IconUtil.from_gicon(icon) : "" // FIXME: ditto
78+ source: IconUtil.from_gicon(icon)
7979 }
8080 }
8181 }
plugins/Unity/categories.cpp+32−23
@@ -21,15 +21,23 @@
2121#include "categories.h"
2222#include "categoryresults.h"
2323
24+// TODO: use something from libunity once it's public
25+enum CategoryColumn {
26+ ID,
27+ DISPLAY_NAME,
28+ ICON_HINT,
29+ RENDERER_NAME,
30+ HINTS
31+};
32+
2433Categories::Categories(QObject* parent)
2534 : DeeListModel(parent)
2635{
27− // FIXME: need to clean up unused filters on countChanged
2836 m_roles[Categories::RoleId] = "id";
2937 m_roles[Categories::RoleName] = "name";
3038 m_roles[Categories::RoleIcon] = "icon";
3139 m_roles[Categories::RoleRenderer] = "renderer";
32− m_roles[Categories::RoleContentType] = "content_type";
40+ m_roles[Categories::RoleContentType] = "contentType";
3341 m_roles[Categories::RoleHints] = "hints";
3442 m_roles[Categories::RoleResults] = "results";
3543 m_roles[Categories::RoleCount] = "count";
@@ -39,23 +47,19 @@ Categories::Categories(QObject* parent)
3947 // change of the search term harder to reproduce
4048 m_timer.setSingleShot(true);
4149 m_timer.setInterval(50);
42− connect(&m_timer, SIGNAL(timeout()), this, SLOT(onEmitCountChanged()));
43−}
44−
45−Categories::~Categories()
46−{
50+ connect(&m_timer, &QTimer::timeout, this, &Categories::onEmitCountChanged);
4751}
4852
4953DeeListModel*
50−Categories::getFilter(int index) const
54+Categories::getResults(int index) const
5155{
52− if (!m_results.contains(index) || m_results[index].isNull()) {
53− auto results = new CategoryResults;
56+ if (!m_results.contains(index)) {
57+ CategoryResults* results = new CategoryResults(const_cast<Categories*>(this));
5458 results->setCategoryIndex(index);
5559 connect(results, &DeeListModel::countChanged, this, &Categories::onCountChanged);
5660
57− unsigned cat_index = static_cast<unsigned>(index);
58− auto unity_results = m_unityScope->GetResultsForCategory(cat_index);
61+ unsigned categoryIndex = static_cast<unsigned>(index);
62+ auto unity_results = m_unityScope->GetResultsForCategory(categoryIndex);
5963 results->setModel(unity_results->model());
6064
6165 m_results.insert(index, results);
@@ -68,6 +72,9 @@ void Categories::onCategoriesModelChanged(unity::glib::Object<DeeModel> model)
6872{
6973 m_updatedCategories.clear();
7074 // FIXME: this might destroy the renderer view and re-create it, optimize?
75+ Q_FOREACH(DeeListModel* model, m_results) {
76+ delete model;
77+ }
7178 m_results.clear();
7279 setModel(model);
7380}
@@ -80,7 +87,9 @@ Categories::setUnityScope(const unity::dash::Scope::Ptr& scope)
8087 // no need to call this, we'll get notified
8188 //setModel(m_unityScope->categories()->model());
8289
83− m_unityScope->categories()->model.changed.connect(sigc::mem_fun(this, &Categories::onCategoriesModelChanged));
90+ m_categoriesChangedConnection.disconnect();
91+ m_categoriesChangedConnection =
92+ m_unityScope->categories()->model.changed.connect(sigc::mem_fun(this, &Categories::onCategoriesModelChanged));
8493}
8594
8695void
@@ -98,9 +107,9 @@ Categories::onEmitCountChanged()
98107{
99108 QVector<int> roles;
100109 roles.append(Categories::RoleCount);
101− Q_FOREACH(int cat_index, m_updatedCategories) {
102− if (m_results[cat_index].isNull()) continue;
103− QModelIndex changedIndex = index(cat_index);
110+ Q_FOREACH(int categoryIndex, m_updatedCategories) {
111+ if (!m_results.contains(categoryIndex)) continue;
112+ QModelIndex changedIndex = index(categoryIndex);
104113 Q_EMIT dataChanged(changedIndex, changedIndex, roles);
105114 }
106115 m_updatedCategories.clear();
@@ -123,22 +132,22 @@ Categories::data(const QModelIndex& index, int role) const
123132 case RoleId:
124133 return QVariant::fromValue(index.row());
125134 case RoleName:
126− return DeeListModel::data(index, 1); //DISPLAY_NAME
135+ return DeeListModel::data(index, CategoryColumn::DISPLAY_NAME);
127136 case RoleIcon:
128− return DeeListModel::data(index, 2); //ICON_HINT
137+ return DeeListModel::data(index, CategoryColumn::ICON_HINT);
129138 case RoleRenderer:
130− return DeeListModel::data(index, 3); //RENDERER_NAME
139+ return DeeListModel::data(index, CategoryColumn::RENDERER_NAME);
131140 case RoleContentType:
132141 {
133− auto hints = DeeListModel::data(index, 4).toHash();
142+ auto hints = DeeListModel::data(index, CategoryColumn::HINTS).toHash();
134143 return hints.contains("content-type") ? hints["content-type"] : QVariant(QString("default"));
135144 }
136145 case RoleHints:
137− return DeeListModel::data(index, 4); //HINTS
146+ return DeeListModel::data(index, CategoryColumn::HINTS);
138147 case RoleResults:
139− return QVariant::fromValue(getFilter(index.row()));
148+ return QVariant::fromValue(getResults(index.row()));
140149 case RoleCount:
141− return QVariant::fromValue(getFilter(index.row())->rowCount());
150+ return QVariant::fromValue(getResults(index.row())->rowCount());
142151 default:
143152 return QVariant();
144153 }
plugins/Unity/categories.h+3−3
@@ -39,7 +39,6 @@ class Categories : public DeeListModel
3939
4040public:
4141 explicit Categories(QObject* parent = 0);
42− ~Categories();
4342
4443 enum Roles {
4544 RoleId,
@@ -66,13 +65,14 @@ private Q_SLOTS:
6665private:
6766 void onCategoriesModelChanged(unity::glib::Object<DeeModel> model);
6867
69− DeeListModel* getFilter(int index) const;
68+ DeeListModel* getResults(int index) const;
7069
7170 unity::dash::Scope::Ptr m_unityScope;
7271 QTimer m_timer;
7372 QSet<int> m_updatedCategories;
7473 QHash<int, QByteArray> m_roles;
75− mutable QMap<int, QPointer<DeeListModel>> m_results;
74+ mutable QMap<int, DeeListModel*> m_results;
75+ sigc::connection m_categoriesChangedConnection;
7676};
7777
7878#endif // CATEGORIES_H
plugins/Unity/categoryresults.cpp+22−13
@@ -20,6 +20,19 @@
2020// self
2121#include "categoryresults.h"
2222
23+// TODO: use something from libunity once it's public
24+enum ResultsColumn {
25+ URI,
26+ ICON_HINT,
27+ CATEGORY,
28+ RESULT_TYPE,
29+ MIMETYPE,
30+ TITLE,
31+ COMMENT,
32+ DND_URI,
33+ METADATA
34+};
35+
2336CategoryResults::CategoryResults(QObject* parent)
2437 : DeeListModel(parent)
2538 , m_category_index(-1)
@@ -30,14 +43,10 @@ CategoryResults::CategoryResults(QObject* parent)
3043 m_roles[CategoryResults::RoleMimetype] = "mimetype";
3144 m_roles[CategoryResults::RoleTitle] = "title";
3245 m_roles[CategoryResults::RoleComment] = "comment";
33− m_roles[CategoryResults::RoleDndUri] = "dnd_uri";
46+ m_roles[CategoryResults::RoleDndUri] = "dndUri";
3447 m_roles[CategoryResults::RoleMetadata] = "metadata";
3548}
3649
37−CategoryResults::~CategoryResults()
38−{
39−}
40−
4150int CategoryResults::categoryIndex() const
4251{
4352 return m_category_index;
@@ -66,21 +75,21 @@ CategoryResults::data(const QModelIndex& index, int role) const
6675
6776 switch (role) {
6877 case RoleUri:
69− return DeeListModel::data(index, 0);
78+ return DeeListModel::data(index, ResultsColumn::URI);
7079 case RoleIconHint:
71− return DeeListModel::data(index, 1);
80+ return DeeListModel::data(index, ResultsColumn::ICON_HINT);
7281 case RoleCategory:
73− return DeeListModel::data(index, 2);
82+ return DeeListModel::data(index, ResultsColumn::CATEGORY);
7483 case RoleMimetype:
75− return DeeListModel::data(index, 4);
84+ return DeeListModel::data(index, ResultsColumn::MIMETYPE);
7685 case RoleTitle:
77− return DeeListModel::data(index, 5);
86+ return DeeListModel::data(index, ResultsColumn::TITLE);
7887 case RoleComment:
79− return DeeListModel::data(index, 6);
88+ return DeeListModel::data(index, ResultsColumn::COMMENT);
8089 case RoleDndUri:
81− return DeeListModel::data(index, 7);
90+ return DeeListModel::data(index, ResultsColumn::DND_URI);
8291 case RoleMetadata:
83− return DeeListModel::data(index, 8);
92+ return DeeListModel::data(index, ResultsColumn::METADATA);
8493 default:
8594 return QVariant();
8695 }
plugins/Unity/categoryresults.h−2
@@ -34,13 +34,11 @@ class CategoryResults : public DeeListModel
3434
3535public:
3636 explicit CategoryResults(QObject* parent = 0);
37− ~CategoryResults();
3837
3938 enum Roles {
4039 RoleUri,
4140 RoleIconHint,
4241 RoleCategory,
43− //RoleResultType, // not needed
4442 RoleMimetype,
4543 RoleTitle,
4644 RoleComment,
plugins/Unity/plugin.cpp+1−1
@@ -49,7 +49,7 @@ void UnityPlugin::registerTypes(const char *uri)
4949 qmlRegisterType<Scope>(uri, 0, 1, "Scope");
5050 qmlRegisterType<Scopes>(uri, 0, 1, "Scopes");
5151 qmlRegisterType<Categories>(uri, 0, 1, "Categories");
52− qmlRegisterType<CategoryResults>(uri, 0, 1, "CategoryResults");
52+ qmlRegisterUncreatableType<CategoryResults>(uri, 0, 1, "CategoryResults", "Can't create new Category Results in QML. Get them from Categories instance.");
5353 qmlRegisterType<DeeListModel>(uri, 0, 1, "DeeListModel");
5454 qmlRegisterType<LauncherModel>(uri, 0, 1, "LauncherModel");
5555 qmlRegisterUncreatableType<LauncherItem>(uri, 0, 1, "LauncherItem", "Can't create new Launcher Items in QML. Get them from the LauncherModel.");
tests/plugins/Unity/CMakeLists.txt+1−1
@@ -21,7 +21,7 @@ macro(run_tests)
2121 add_executable(${_test}Exec ${_test}.cpp previewbindingstest.cpp)
2222 qt5_use_modules(${_test}Exec Test Core Qml)
2323 set_tests_properties(test${CLASSNAME}${_test}
24− PROPERTIES ENVIRONMENT LD_LIBRARY_PATH=${CMAKE_BINARY_DIR}/plugins/Unity:${LIBUNITYPROTO_LIBRARY_DIRS})
24+ PROPERTIES ENVIRONMENT "LD_LIBRARY_PATH=${CMAKE_BINARY_DIR}/plugins/Unity:${LIBUNITYPROTO_LIBRARY_DIRS}")
2525
2626 target_link_libraries(${_test}Exec
2727 Unity-qml
tests/qmltests/plugins/Unity/fake_unity_plugin.cpp+1−1
@@ -40,7 +40,7 @@ void FakeUnityPlugin::registerTypes(const char *uri)
4040 qmlRegisterType<Scopes>(uri, 0, 1, "Scopes");
4141 qmlRegisterType<Scope>(uri, 0, 1, "Scope");
4242 qmlRegisterType<Categories>(uri, 0, 1, "Categories");
43− qmlRegisterType<CategoryResults>(uri, 0, 1, "CategoryResults");
43+ qmlRegisterUncreatableType<CategoryResults>(uri, 0, 1, "CategoryResults", "Can't create");
4444 qmlRegisterType<LauncherModel>(uri, 0, 1, "LauncherModel");
4545 qmlRegisterUncreatableType<LauncherItem>(uri, 0, 1, "LauncherItem", "Can't create");
4646}