Merge lp:~unity-team/unity-scopes-shell/max-attrs-count into lp:unity-scopes-shell

Proposed by Michal Hruby
Status: Merged
Approved by: Albert Astals Cid
Approved revision: 109
Merged at revision: 109
Proposed branch: lp:~unity-team/unity-scopes-shell/max-attrs-count
Merge into: lp:unity-scopes-shell
Diff against target: 143 lines (+26/-6)
4 files modified
src/Unity/categories.cpp (+14/-1)
src/Unity/resultsmodel.cpp (+9/-4)
src/Unity/resultsmodel.h (+2/-0)
tests/data/mock-scope/mock-scope.cpp (+1/-1)
To merge this branch: bzr merge lp:~unity-team/unity-scopes-shell/max-attrs-count
Reviewer Review Type Date Requested Status
Albert Astals Cid (community) Approve
Review via email: mp+228144@code.launchpad.net

Commit message

Make the number of maximum attributes configurable by the scope and expose it to shell.

Description of the change

Make the number of maximum attributes configurable by the scope and expose it to shell.

To post a comment you must log in.
Revision history for this message
Albert Astals Cid (aacid) wrote :

Looks good :)

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/Unity/categories.cpp'
2--- src/Unity/categories.cpp 2014-07-08 16:47:30 +0000
3+++ src/Unity/categories.cpp 2014-07-24 15:29:20 +0000
4@@ -39,7 +39,7 @@
5 namespace scopes_ng {
6
7 // FIXME: this should be in a common place
8-#define CATEGORY_JSON_DEFAULTS R"({"schema-version":1,"template": {"category-layout":"grid","card-layout":"vertical","card-size":"small","overlay-mode":null,"collapsed-rows":2}, "components": { "title":null, "art": { "aspect-ratio":1.0, "fill-mode":"crop" }, "subtitle":null, "mascot":null, "emblem":null, "summary":null, "attributes":null, "background":null }, "resources":{}})"
9+#define CATEGORY_JSON_DEFAULTS R"({"schema-version":1,"template": {"category-layout":"grid","card-layout":"vertical","card-size":"small","overlay-mode":null,"collapsed-rows":2}, "components": { "title":null, "art": { "aspect-ratio":1.0, "fill-mode":"crop" }, "subtitle":null, "mascot":null, "emblem":null, "summary":null, "attributes": { "max-count":2 }, "background":null }, "resources":{}})"
10
11 class CategoryData
12 {
13@@ -140,6 +140,15 @@
14 return result;
15 }
16
17+ int getMaxAttributes() const
18+ {
19+ QJsonObject components_obj = m_components.toObject();
20+ QJsonObject attrs_obj = components_obj.value("attributes").toObject();
21+ QJsonValue max_count_val = attrs_obj.value("max-count");
22+
23+ return max_count_val.toInt(2);
24+ }
25+
26 QVector<int> updateAttributes(scopes::Category::SCPtr category)
27 {
28 QVector<int> roles;
29@@ -355,6 +364,7 @@
30 resultsModel = catData->resultsModel();
31 if (resultsModel) {
32 resultsModel->setComponentsMapping(catData->getComponentsMapping());
33+ resultsModel->setMaxAtrributesCount(catData->getMaxAttributes());
34 }
35 }
36 beginInsertRows(QModelIndex(), emptyIndex, emptyIndex);
37@@ -369,6 +379,7 @@
38 resultsModel = catData->resultsModel();
39 if (resultsModel) {
40 resultsModel->setComponentsMapping(catData->getComponentsMapping());
41+ resultsModel->setMaxAtrributesCount(catData->getMaxAttributes());
42 }
43 QModelIndex changedIndex(this->index(index));
44 dataChanged(changedIndex, changedIndex, changedRoles);
45@@ -386,6 +397,7 @@
46 m_categories.insert(emptyIndex, QSharedPointer<CategoryData>(catData));
47 resultsModel->setCategoryId(QString::fromStdString(category->id()));
48 resultsModel->setComponentsMapping(catData->getComponentsMapping());
49+ resultsModel->setMaxAtrributesCount(catData->getMaxAttributes());
50 m_categoryResults[category->id()] = resultsModel;
51
52 endInsertRows();
53@@ -438,6 +450,7 @@
54 }
55 if (catData->resultsModel()) {
56 catData->resultsModel()->setComponentsMapping(catData->getComponentsMapping());
57+ catData->resultsModel()->setMaxAtrributesCount(catData->getMaxAttributes());
58 }
59 QModelIndex changeIndex(index(idx));
60 QVector<int> roles;
61
62=== modified file 'src/Unity/resultsmodel.cpp'
63--- src/Unity/resultsmodel.cpp 2014-05-19 09:58:14 +0000
64+++ src/Unity/resultsmodel.cpp 2014-07-24 15:29:20 +0000
65@@ -28,10 +28,9 @@
66
67 using namespace unity;
68
69-const int MAX_ATTRIBUTES = 3;
70-
71 ResultsModel::ResultsModel(QObject* parent)
72 : unity::shell::scopes::ResultsModelInterface(parent)
73+ , m_maxAttributes(2)
74 {
75 }
76
77@@ -64,6 +63,11 @@
78 }
79 }
80
81+void ResultsModel::setMaxAtrributesCount(int count)
82+{
83+ m_maxAttributes = count;
84+}
85+
86 void ResultsModel::addResults(QList<std::shared_ptr<unity::scopes::CategorisedResult>> const& results)
87 {
88 if (results.count() == 0) return;
89@@ -136,6 +140,7 @@
90 }
91
92 QVariantList attributes;
93+ QString defaultStyle("default");
94 scopes::VariantArray arr(v.get_array());
95 for (unsigned i = 0; i < arr.size(); i++) {
96 if (arr[i].which() != scopes::Variant::Type::Dict) {
97@@ -150,11 +155,11 @@
98 continue;
99 }
100 if (!attribute.contains("style")) {
101- attribute["style"] = QString("default");
102+ attribute["style"] = defaultStyle;
103 }
104 attributes << QVariant(attribute);
105 // we'll limit the number of attributes
106- if (attributes.size() >= MAX_ATTRIBUTES) {
107+ if (attributes.size() >= m_maxAttributes) {
108 break;
109 }
110 }
111
112=== modified file 'src/Unity/resultsmodel.h'
113--- src/Unity/resultsmodel.h 2014-05-19 09:58:14 +0000
114+++ src/Unity/resultsmodel.h 2014-07-24 15:29:20 +0000
115@@ -50,6 +50,7 @@
116 /* setters */
117 void setCategoryId(QString const& id) override;
118 void setComponentsMapping(QHash<QString, QString> const& mapping);
119+ void setMaxAtrributesCount(int count);
120
121 private:
122 QVariant componentValue(unity::scopes::CategorisedResult const* result, std::string const& fieldName) const;
123@@ -58,6 +59,7 @@
124 std::unordered_map<std::string, std::string> m_componentMapping;
125 QList<std::shared_ptr<unity::scopes::CategorisedResult>> m_results;
126 QString m_categoryId;
127+ int m_maxAttributes;
128 };
129
130 } // namespace scopes_ng
131
132=== modified file 'tests/data/mock-scope/mock-scope.cpp'
133--- tests/data/mock-scope/mock-scope.cpp 2014-07-04 14:42:30 +0000
134+++ tests/data/mock-scope/mock-scope.cpp 2014-07-24 15:29:20 +0000
135@@ -77,7 +77,7 @@
136 }
137 else if (query_ == "attributes")
138 {
139- CategoryRenderer rating_rndr(R"({"schema-version": 1, "components": {"title": "title", "attributes": "attributes"}})");
140+ CategoryRenderer rating_rndr(R"({"schema-version": 1, "components": {"title": "title", "attributes": {"field": "attributes", "max-count":3}}})");
141 auto cat = reply->register_category("cat1", "Category 1", "", rating_rndr);
142 CategorisedResult res(cat);
143 res.set_uri("test:uri");

Subscribers

People subscribed via source and target branches

to all changes: