Merge lp:~dobey/unity-scope-click/result-attrs into lp:unity-scope-click/devel

Proposed by dobey
Status: Superseded
Proposed branch: lp:~dobey/unity-scope-click/result-attrs
Merge into: lp:unity-scope-click/devel
Diff against target: 173 lines (+62/-7)
4 files modified
libclickscope/click/package.cpp (+2/-0)
libclickscope/click/package.h (+4/-0)
scope/clickstore/store-query.cpp (+29/-7)
scope/tests/test_query.cpp (+27/-0)
To merge this branch: bzr merge lp:~dobey/unity-scope-click/result-attrs
Reviewer Review Type Date Requested Status
PS Jenkins bot (community) continuous-integration Approve
Unity Team Pending
Review via email: mp+231799@code.launchpad.net

Commit message

Add the price and rating as attributes in search results.

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
412. By dobey

Merge alecu's scopes branch.

413. By dobey

Add the attributes on the scopes category as well.

Unmerged revisions

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'libclickscope/click/package.cpp'
2--- libclickscope/click/package.cpp 2014-08-11 18:30:00 +0000
3+++ libclickscope/click/package.cpp 2014-08-22 20:29:37 +0000
4@@ -84,6 +84,8 @@
5 p.icon_url = item[Package::JsonKeys::icon_url].asString();
6 p.url = item[Package::JsonKeys::links][Package::JsonKeys::self][Package::JsonKeys::href].asString();
7 p.content = item[Package::JsonKeys::content].asString();
8+ p.publisher = item[Package::JsonKeys::publisher].asString();
9+ p.rating = item[Package::JsonKeys::rating].asDouble();
10 return p;
11 }
12
13
14=== modified file 'libclickscope/click/package.h'
15--- libclickscope/click/package.h 2014-08-11 18:30:00 +0000
16+++ libclickscope/click/package.h 2014-08-22 20:29:37 +0000
17@@ -61,6 +61,8 @@
18 constexpr static const char* price{"price"};
19 constexpr static const char* icon_url{"icon_url"};
20 constexpr static const char* content{"content"};
21+ constexpr static const char* publisher{"publisher"};
22+ constexpr static const char* rating{"ratings_average"};
23 };
24
25 Package() = default;
26@@ -96,6 +98,8 @@
27 std::string icon_url;
28 std::string url;
29 std::string version;
30+ std::string publisher;
31+ double rating;
32 void matches (std::string query, std::function<bool> callback);
33 std::string content;
34
35
36=== modified file 'scope/clickstore/store-query.cpp'
37--- scope/clickstore/store-query.cpp 2014-08-21 21:15:13 +0000
38+++ scope/clickstore/store-query.cpp 2014-08-22 20:29:37 +0000
39@@ -43,7 +43,11 @@
40 #include <unity/scopes/CannedQuery.h>
41 #include <unity/scopes/SearchReply.h>
42 #include <unity/scopes/SearchMetadata.h>
43+#include <unity/scopes/Variant.h>
44+#include <unity/scopes/VariantBuilder.h>
45
46+#include <iostream>
47+#include <iomanip>
48 #include<vector>
49 #include<set>
50 #include<sstream>
51@@ -69,6 +73,7 @@
52 "components" : {
53 "title" : "title",
54 "subtitle": "subtitle",
55+ "attributes": "attributes",
56 "art" : {
57 "field": "art",
58 "aspect-ratio": 1.13
59@@ -88,6 +93,7 @@
60 "components" : {
61 "title" : "title",
62 "subtitle": "subtitle",
63+ "attributes": "attributes",
64 "art" : {
65 "field": "art",
66 "aspect-ratio": 0.55
67@@ -106,6 +112,7 @@
68 "components": {
69 "title": "title",
70 "subtitle": "subtitle",
71+ "attributes": "attributes",
72 "art": {
73 "aspect-ratio": 2.5,
74 "field": "art"
75@@ -128,7 +135,8 @@
76 "field": "art",
77 "aspect-ratio": 1.13
78 },
79- "subtitle": "subtitle"
80+ "subtitle": "subtitle",
81+ "attributes": "attributes"
82 }
83 }
84 )";
85@@ -298,8 +306,15 @@
86 res.set_art(pkg.icon_url);
87 res.set_uri(pkg.url);
88 res[click::Query::ResultKeys::NAME] = pkg.name;
89+ res["subtitle"] = pkg.publisher;
90 auto installed = installedPackages.find(pkg);
91
92+ std::string price = _("FREE");
93+ std::stringstream ss;
94+ ss << std::fixed << std::setprecision(1);
95+ ss << "☆ " << pkg.rating;
96+ std::string rating{ss.str()};
97+
98 bool purchased = false;
99 if (pkg.price > 0.00f) {
100 if (!Configuration::get_purchases_enabled()) {
101@@ -312,24 +327,31 @@
102 if (installed != installedPackages.end()) {
103 res[click::Query::ResultKeys::INSTALLED] = true;
104 res[click::Query::ResultKeys::PURCHASED] = purchased;
105- res["subtitle"] = _("✔ INSTALLED");
106+ price = _("✔ INSTALLED");
107 res[click::Query::ResultKeys::VERSION] = installed->version;
108 } else if (purchased) {
109 res[click::Query::ResultKeys::PURCHASED] = true;
110 res[click::Query::ResultKeys::INSTALLED] = false;
111- res["subtitle"] = _("✔ PURCHASED");
112+ price = _("✔ PURCHASED");
113 } else {
114 res[click::Query::ResultKeys::INSTALLED] = false;
115 res[click::Query::ResultKeys::PURCHASED] = false;
116 if (pkg.price > 0.00f) {
117 QLocale locale;
118- res["subtitle"] = locale.toCurrencyString(pkg.price, "$").toUtf8().data();
119- } else {
120- res["subtitle"] = _("FREE");
121+ price = locale.toCurrencyString(pkg.price, "$").toUtf8().data();
122 }
123- // TODO: get the real price from the webservice (upcoming branch)
124 }
125
126+ // Add the price and rating as attributes.
127+ scopes::VariantBuilder builder;
128+ builder.add_tuple({
129+ {"value", scopes::Variant(price)},
130+ });
131+ builder.add_tuple({
132+ {"value", scopes::Variant(rating)},
133+ });
134+ res["attributes"] = builder.end();
135+
136 this->push_result(searchReply, res);
137 } catch(const std::exception& e){
138 qDebug() << "PackageDetails::loadJson: Exception thrown while decoding JSON: " << e.what() ;
139
140=== modified file 'scope/tests/test_query.cpp'
141--- scope/tests/test_query.cpp 2014-08-05 14:16:26 +0000
142+++ scope/tests/test_query.cpp 2014-08-22 20:29:37 +0000
143@@ -528,3 +528,30 @@
144
145 ASSERT_EQ(unsetenv(Configuration::PURCHASES_ENVVAR), 0);
146 }
147+
148+MATCHER_P(HasAttributes, b, "") { return !arg["attributes"].is_null() == b; }
149+
150+TEST(QueryTest, testPushPackagePushesAttributes)
151+{
152+ click::Packages packages {
153+ {"org.example.app1", "app title1", 0.0, "icon", "uri"},
154+ };
155+ MockIndex mock_index(packages);
156+ scopes::SearchMetadata metadata("en_EN", "phone");
157+ PackageSet no_installed_packages;
158+ click::DepartmentLookup dept_lookup;
159+ click::HighlightList highlights;
160+ MockPayPackage pay_pkg;
161+ const unity::scopes::CannedQuery query("foo.scope", FAKE_QUERY, "");
162+ MockQuery q(query, mock_index, dept_lookup, nullptr, highlights, metadata, pay_pkg);
163+ EXPECT_CALL(mock_index, do_search(FAKE_QUERY, _));
164+
165+ scopes::CategoryRenderer renderer("{}");
166+ auto ptrCat = std::make_shared<FakeCategory>("id", "", "", renderer);
167+ EXPECT_CALL(q, register_category(_, _, _, _, _)).Times(2).WillRepeatedly(Return(ptrCat));
168+
169+ scopes::testing::MockSearchReply mock_reply;
170+ scopes::SearchReplyProxy reply(&mock_reply, [](unity::scopes::SearchReply*){});
171+ EXPECT_CALL(q, push_result(_, HasAttributes(true)));
172+ q.wrap_add_available_apps(reply, no_installed_packages, FAKE_CATEGORY_TEMPLATE);
173+}

Subscribers

People subscribed via source and target branches

to all changes: