on xenial help sign in
Fix issues brought up in review
740f52bMichal Hruby
Dash/GenericScopeView.qml+2−2
@@ -72,10 +72,10 @@ ScopeView {
72 delegate: Tile {
72 delegate: Tile {
73 width: filtergrid.cellWidth
73 width: filtergrid.cellWidth
74 height: filtergrid.cellHeight
74 height: filtergrid.cellHeight
75− text: title ? title : "" // FIXME: this shouldn't be necessary
75+ text: title
76 imageWidth: units.gu(11)
76 imageWidth: units.gu(11)
77 imageHeight: units.gu(16)
77 imageHeight: units.gu(16)
78− source: icon ? IconUtil.from_gicon(icon) : "" // FIXME: ditto
78+ source: IconUtil.from_gicon(icon)
79 }
79 }
80 }
80 }
81 }
81 }
plugins/Unity/categories.cpp+32−23
@@ -21,15 +21,23 @@
21#include "categories.h"
21#include "categories.h"
22#include "categoryresults.h"
22#include "categoryresults.h"
23
23
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+
24Categories::Categories(QObject* parent)
33Categories::Categories(QObject* parent)
25 : DeeListModel(parent)
34 : DeeListModel(parent)
26{
35{
27− // FIXME: need to clean up unused filters on countChanged
28 m_roles[Categories::RoleId] = "id";
36 m_roles[Categories::RoleId] = "id";
29 m_roles[Categories::RoleName] = "name";
37 m_roles[Categories::RoleName] = "name";
30 m_roles[Categories::RoleIcon] = "icon";
38 m_roles[Categories::RoleIcon] = "icon";
31 m_roles[Categories::RoleRenderer] = "renderer";
39 m_roles[Categories::RoleRenderer] = "renderer";
32− m_roles[Categories::RoleContentType] = "content_type";
40+ m_roles[Categories::RoleContentType] = "contentType";
33 m_roles[Categories::RoleHints] = "hints";
41 m_roles[Categories::RoleHints] = "hints";
34 m_roles[Categories::RoleResults] = "results";
42 m_roles[Categories::RoleResults] = "results";
35 m_roles[Categories::RoleCount] = "count";
43 m_roles[Categories::RoleCount] = "count";
@@ -39,23 +47,19 @@ Categories::Categories(QObject* parent)
39 // change of the search term harder to reproduce
47 // change of the search term harder to reproduce
40 m_timer.setSingleShot(true);
48 m_timer.setSingleShot(true);
41 m_timer.setInterval(50);
49 m_timer.setInterval(50);
42− connect(&m_timer, SIGNAL(timeout()), this, SLOT(onEmitCountChanged()));
50+ connect(&m_timer, &QTimer::timeout, this, &Categories::onEmitCountChanged);
43−}
44−
45−Categories::~Categories()
46−{
47}
51}
48
52
49DeeListModel*
53DeeListModel*
50−Categories::getFilter(int index) const
54+Categories::getResults(int index) const
51{
55{
52− if (!m_results.contains(index) || m_results[index].isNull()) {
56+ if (!m_results.contains(index)) {
53− auto results = new CategoryResults;
57+ CategoryResults* results = new CategoryResults(const_cast<Categories*>(this));
54 results->setCategoryIndex(index);
58 results->setCategoryIndex(index);
55 connect(results, &DeeListModel::countChanged, this, &Categories::onCountChanged);
59 connect(results, &DeeListModel::countChanged, this, &Categories::onCountChanged);
56
60
57− unsigned cat_index = static_cast<unsigned>(index);
61+ unsigned categoryIndex = static_cast<unsigned>(index);
58− auto unity_results = m_unityScope->GetResultsForCategory(cat_index);
62+ auto unity_results = m_unityScope->GetResultsForCategory(categoryIndex);
59 results->setModel(unity_results->model());
63 results->setModel(unity_results->model());
60
64
61 m_results.insert(index, results);
65 m_results.insert(index, results);
@@ -68,6 +72,9 @@ void Categories::onCategoriesModelChanged(unity::glib::Object<DeeModel> model)
68{
72{
69 m_updatedCategories.clear();
73 m_updatedCategories.clear();
70 // FIXME: this might destroy the renderer view and re-create it, optimize?
74 // FIXME: this might destroy the renderer view and re-create it, optimize?
75+ Q_FOREACH(DeeListModel* model, m_results) {
76+ delete model;
77+ }
71 m_results.clear();
78 m_results.clear();
72 setModel(model);
79 setModel(model);
73}
80}
@@ -80,7 +87,9 @@ Categories::setUnityScope(const unity::dash::Scope::Ptr& scope)
80 // no need to call this, we'll get notified
87 // no need to call this, we'll get notified
81 //setModel(m_unityScope->categories()->model());
88 //setModel(m_unityScope->categories()->model());
82
89
90+ m_categoriesChangedConnection.disconnect();
91+ m_categoriesChangedConnection =
83− m_unityScope->categories()->model.changed.connect(sigc::mem_fun(this, &Categories::onCategoriesModelChanged));
92+ m_unityScope->categories()->model.changed.connect(sigc::mem_fun(this, &Categories::onCategoriesModelChanged));
84}
93}
85
94
86void
95void
@@ -98,9 +107,9 @@ Categories::onEmitCountChanged()
98{
107{
99 QVector<int> roles;
108 QVector<int> roles;
100 roles.append(Categories::RoleCount);
109 roles.append(Categories::RoleCount);
101− Q_FOREACH(int cat_index, m_updatedCategories) {
110+ Q_FOREACH(int categoryIndex, m_updatedCategories) {
102− if (m_results[cat_index].isNull()) continue;
111+ if (!m_results.contains(categoryIndex)) continue;
103− QModelIndex changedIndex = index(cat_index);
112+ QModelIndex changedIndex = index(categoryIndex);
104 Q_EMIT dataChanged(changedIndex, changedIndex, roles);
113 Q_EMIT dataChanged(changedIndex, changedIndex, roles);
105 }
114 }
106 m_updatedCategories.clear();
115 m_updatedCategories.clear();
@@ -123,22 +132,22 @@ Categories::data(const QModelIndex& index, int role) const
123 case RoleId:
132 case RoleId:
124 return QVariant::fromValue(index.row());
133 return QVariant::fromValue(index.row());
125 case RoleName:
134 case RoleName:
126− return DeeListModel::data(index, 1); //DISPLAY_NAME
135+ return DeeListModel::data(index, CategoryColumn::DISPLAY_NAME);
127 case RoleIcon:
136 case RoleIcon:
128− return DeeListModel::data(index, 2); //ICON_HINT
137+ return DeeListModel::data(index, CategoryColumn::ICON_HINT);
129 case RoleRenderer:
138 case RoleRenderer:
130− return DeeListModel::data(index, 3); //RENDERER_NAME
139+ return DeeListModel::data(index, CategoryColumn::RENDERER_NAME);
131 case RoleContentType:
140 case RoleContentType:
132 {
141 {
133− auto hints = DeeListModel::data(index, 4).toHash();
142+ auto hints = DeeListModel::data(index, CategoryColumn::HINTS).toHash();
134 return hints.contains("content-type") ? hints["content-type"] : QVariant(QString("default"));
143 return hints.contains("content-type") ? hints["content-type"] : QVariant(QString("default"));
135 }
144 }
136 case RoleHints:
145 case RoleHints:
137− return DeeListModel::data(index, 4); //HINTS
146+ return DeeListModel::data(index, CategoryColumn::HINTS);
138 case RoleResults:
147 case RoleResults:
139− return QVariant::fromValue(getFilter(index.row()));
148+ return QVariant::fromValue(getResults(index.row()));
140 case RoleCount:
149 case RoleCount:
141− return QVariant::fromValue(getFilter(index.row())->rowCount());
150+ return QVariant::fromValue(getResults(index.row())->rowCount());
142 default:
151 default:
143 return QVariant();
152 return QVariant();
144 }
153 }
plugins/Unity/categories.h+3−3
@@ -39,7 +39,6 @@ class Categories : public DeeListModel
39
39
40public:
40public:
41 explicit Categories(QObject* parent = 0);
41 explicit Categories(QObject* parent = 0);
42− ~Categories();
43
42
44 enum Roles {
43 enum Roles {
45 RoleId,
44 RoleId,
@@ -66,13 +65,14 @@ private Q_SLOTS:
66private:
65private:
67 void onCategoriesModelChanged(unity::glib::Object<DeeModel> model);
66 void onCategoriesModelChanged(unity::glib::Object<DeeModel> model);
68
67
69− DeeListModel* getFilter(int index) const;
68+ DeeListModel* getResults(int index) const;
70
69
71 unity::dash::Scope::Ptr m_unityScope;
70 unity::dash::Scope::Ptr m_unityScope;
72 QTimer m_timer;
71 QTimer m_timer;
73 QSet<int> m_updatedCategories;
72 QSet<int> m_updatedCategories;
74 QHash<int, QByteArray> m_roles;
73 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;
76};
76};
77
77
78#endif // CATEGORIES_H
78#endif // CATEGORIES_H
plugins/Unity/categoryresults.cpp+22−13
@@ -20,6 +20,19 @@
20// self
20// self
21#include "categoryresults.h"
21#include "categoryresults.h"
22
22
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+
23CategoryResults::CategoryResults(QObject* parent)
36CategoryResults::CategoryResults(QObject* parent)
24 : DeeListModel(parent)
37 : DeeListModel(parent)
25 , m_category_index(-1)
38 , m_category_index(-1)
@@ -30,14 +43,10 @@ CategoryResults::CategoryResults(QObject* parent)
30 m_roles[CategoryResults::RoleMimetype] = "mimetype";
43 m_roles[CategoryResults::RoleMimetype] = "mimetype";
31 m_roles[CategoryResults::RoleTitle] = "title";
44 m_roles[CategoryResults::RoleTitle] = "title";
32 m_roles[CategoryResults::RoleComment] = "comment";
45 m_roles[CategoryResults::RoleComment] = "comment";
33− m_roles[CategoryResults::RoleDndUri] = "dnd_uri";
46+ m_roles[CategoryResults::RoleDndUri] = "dndUri";
34 m_roles[CategoryResults::RoleMetadata] = "metadata";
47 m_roles[CategoryResults::RoleMetadata] = "metadata";
35}
48}
36
49
37−CategoryResults::~CategoryResults()
38−{
39−}
40−
41int CategoryResults::categoryIndex() const
50int CategoryResults::categoryIndex() const
42{
51{
43 return m_category_index;
52 return m_category_index;
@@ -66,21 +75,21 @@ CategoryResults::data(const QModelIndex& index, int role) const
66
75
67 switch (role) {
76 switch (role) {
68 case RoleUri:
77 case RoleUri:
69− return DeeListModel::data(index, 0);
78+ return DeeListModel::data(index, ResultsColumn::URI);
70 case RoleIconHint:
79 case RoleIconHint:
71− return DeeListModel::data(index, 1);
80+ return DeeListModel::data(index, ResultsColumn::ICON_HINT);
72 case RoleCategory:
81 case RoleCategory:
73− return DeeListModel::data(index, 2);
82+ return DeeListModel::data(index, ResultsColumn::CATEGORY);
74 case RoleMimetype:
83 case RoleMimetype:
75− return DeeListModel::data(index, 4);
84+ return DeeListModel::data(index, ResultsColumn::MIMETYPE);
76 case RoleTitle:
85 case RoleTitle:
77− return DeeListModel::data(index, 5);
86+ return DeeListModel::data(index, ResultsColumn::TITLE);
78 case RoleComment:
87 case RoleComment:
79− return DeeListModel::data(index, 6);
88+ return DeeListModel::data(index, ResultsColumn::COMMENT);
80 case RoleDndUri:
89 case RoleDndUri:
81− return DeeListModel::data(index, 7);
90+ return DeeListModel::data(index, ResultsColumn::DND_URI);
82 case RoleMetadata:
91 case RoleMetadata:
83− return DeeListModel::data(index, 8);
92+ return DeeListModel::data(index, ResultsColumn::METADATA);
84 default:
93 default:
85 return QVariant();
94 return QVariant();
86 }
95 }
plugins/Unity/categoryresults.h−2
@@ -34,13 +34,11 @@ class CategoryResults : public DeeListModel
34
34
35public:
35public:
36 explicit CategoryResults(QObject* parent = 0);
36 explicit CategoryResults(QObject* parent = 0);
37− ~CategoryResults();
38
37
39 enum Roles {
38 enum Roles {
40 RoleUri,
39 RoleUri,
41 RoleIconHint,
40 RoleIconHint,
42 RoleCategory,
41 RoleCategory,
43− //RoleResultType, // not needed
44 RoleMimetype,
42 RoleMimetype,
45 RoleTitle,
43 RoleTitle,
46 RoleComment,
44 RoleComment,
plugins/Unity/plugin.cpp+1−1
@@ -49,7 +49,7 @@ void UnityPlugin::registerTypes(const char *uri)
49 qmlRegisterType<Scope>(uri, 0, 1, "Scope");
49 qmlRegisterType<Scope>(uri, 0, 1, "Scope");
50 qmlRegisterType<Scopes>(uri, 0, 1, "Scopes");
50 qmlRegisterType<Scopes>(uri, 0, 1, "Scopes");
51 qmlRegisterType<Categories>(uri, 0, 1, "Categories");
51 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.");
53 qmlRegisterType<DeeListModel>(uri, 0, 1, "DeeListModel");
53 qmlRegisterType<DeeListModel>(uri, 0, 1, "DeeListModel");
54 qmlRegisterType<LauncherModel>(uri, 0, 1, "LauncherModel");
54 qmlRegisterType<LauncherModel>(uri, 0, 1, "LauncherModel");
55 qmlRegisterUncreatableType<LauncherItem>(uri, 0, 1, "LauncherItem", "Can't create new Launcher Items in QML. Get them from the LauncherModel.");
55 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)
21 add_executable(${_test}Exec ${_test}.cpp previewbindingstest.cpp)
21 add_executable(${_test}Exec ${_test}.cpp previewbindingstest.cpp)
22 qt5_use_modules(${_test}Exec Test Core Qml)
22 qt5_use_modules(${_test}Exec Test Core Qml)
23 set_tests_properties(test${CLASSNAME}${_test}
23 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}")
25
25
26 target_link_libraries(${_test}Exec
26 target_link_libraries(${_test}Exec
27 Unity-qml
27 Unity-qml
tests/qmltests/plugins/Unity/fake_unity_plugin.cpp+1−1
@@ -40,7 +40,7 @@ void FakeUnityPlugin::registerTypes(const char *uri)
40 qmlRegisterType<Scopes>(uri, 0, 1, "Scopes");
40 qmlRegisterType<Scopes>(uri, 0, 1, "Scopes");
41 qmlRegisterType<Scope>(uri, 0, 1, "Scope");
41 qmlRegisterType<Scope>(uri, 0, 1, "Scope");
42 qmlRegisterType<Categories>(uri, 0, 1, "Categories");
42 qmlRegisterType<Categories>(uri, 0, 1, "Categories");
43− qmlRegisterType<CategoryResults>(uri, 0, 1, "CategoryResults");
43+ qmlRegisterUncreatableType<CategoryResults>(uri, 0, 1, "CategoryResults", "Can't create");
44 qmlRegisterType<LauncherModel>(uri, 0, 1, "LauncherModel");
44 qmlRegisterType<LauncherModel>(uri, 0, 1, "LauncherModel");
45 qmlRegisterUncreatableType<LauncherItem>(uri, 0, 1, "LauncherItem", "Can't create");
45 qmlRegisterUncreatableType<LauncherItem>(uri, 0, 1, "LauncherItem", "Can't create");
46}
46}