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
=== modified file 'libclickscope/click/package.cpp'
--- libclickscope/click/package.cpp 2014-08-11 18:30:00 +0000
+++ libclickscope/click/package.cpp 2014-08-22 20:29:37 +0000
@@ -84,6 +84,8 @@
84 p.icon_url = item[Package::JsonKeys::icon_url].asString();84 p.icon_url = item[Package::JsonKeys::icon_url].asString();
85 p.url = item[Package::JsonKeys::links][Package::JsonKeys::self][Package::JsonKeys::href].asString();85 p.url = item[Package::JsonKeys::links][Package::JsonKeys::self][Package::JsonKeys::href].asString();
86 p.content = item[Package::JsonKeys::content].asString();86 p.content = item[Package::JsonKeys::content].asString();
87 p.publisher = item[Package::JsonKeys::publisher].asString();
88 p.rating = item[Package::JsonKeys::rating].asDouble();
87 return p;89 return p;
88}90}
8991
9092
=== modified file 'libclickscope/click/package.h'
--- libclickscope/click/package.h 2014-08-11 18:30:00 +0000
+++ libclickscope/click/package.h 2014-08-22 20:29:37 +0000
@@ -61,6 +61,8 @@
61 constexpr static const char* price{"price"};61 constexpr static const char* price{"price"};
62 constexpr static const char* icon_url{"icon_url"};62 constexpr static const char* icon_url{"icon_url"};
63 constexpr static const char* content{"content"};63 constexpr static const char* content{"content"};
64 constexpr static const char* publisher{"publisher"};
65 constexpr static const char* rating{"ratings_average"};
64 };66 };
6567
66 Package() = default;68 Package() = default;
@@ -96,6 +98,8 @@
96 std::string icon_url;98 std::string icon_url;
97 std::string url;99 std::string url;
98 std::string version;100 std::string version;
101 std::string publisher;
102 double rating;
99 void matches (std::string query, std::function<bool> callback);103 void matches (std::string query, std::function<bool> callback);
100 std::string content;104 std::string content;
101105
102106
=== modified file 'scope/clickstore/store-query.cpp'
--- scope/clickstore/store-query.cpp 2014-08-21 21:15:13 +0000
+++ scope/clickstore/store-query.cpp 2014-08-22 20:29:37 +0000
@@ -43,7 +43,11 @@
43#include <unity/scopes/CannedQuery.h>43#include <unity/scopes/CannedQuery.h>
44#include <unity/scopes/SearchReply.h>44#include <unity/scopes/SearchReply.h>
45#include <unity/scopes/SearchMetadata.h>45#include <unity/scopes/SearchMetadata.h>
46#include <unity/scopes/Variant.h>
47#include <unity/scopes/VariantBuilder.h>
4648
49#include <iostream>
50#include <iomanip>
47#include<vector>51#include<vector>
48#include<set>52#include<set>
49#include<sstream>53#include<sstream>
@@ -69,6 +73,7 @@
69 "components" : {73 "components" : {
70 "title" : "title",74 "title" : "title",
71 "subtitle": "subtitle",75 "subtitle": "subtitle",
76 "attributes": "attributes",
72 "art" : {77 "art" : {
73 "field": "art",78 "field": "art",
74 "aspect-ratio": 1.1379 "aspect-ratio": 1.13
@@ -88,6 +93,7 @@
88 "components" : {93 "components" : {
89 "title" : "title",94 "title" : "title",
90 "subtitle": "subtitle",95 "subtitle": "subtitle",
96 "attributes": "attributes",
91 "art" : {97 "art" : {
92 "field": "art",98 "field": "art",
93 "aspect-ratio": 0.5599 "aspect-ratio": 0.55
@@ -106,6 +112,7 @@
106 "components": {112 "components": {
107 "title": "title",113 "title": "title",
108 "subtitle": "subtitle",114 "subtitle": "subtitle",
115 "attributes": "attributes",
109 "art": {116 "art": {
110 "aspect-ratio": 2.5,117 "aspect-ratio": 2.5,
111 "field": "art"118 "field": "art"
@@ -128,7 +135,8 @@
128 "field": "art",135 "field": "art",
129 "aspect-ratio": 1.13136 "aspect-ratio": 1.13
130 },137 },
131 "subtitle": "subtitle"138 "subtitle": "subtitle",
139 "attributes": "attributes"
132 }140 }
133 }141 }
134)";142)";
@@ -298,8 +306,15 @@
298 res.set_art(pkg.icon_url);306 res.set_art(pkg.icon_url);
299 res.set_uri(pkg.url);307 res.set_uri(pkg.url);
300 res[click::Query::ResultKeys::NAME] = pkg.name;308 res[click::Query::ResultKeys::NAME] = pkg.name;
309 res["subtitle"] = pkg.publisher;
301 auto installed = installedPackages.find(pkg);310 auto installed = installedPackages.find(pkg);
302311
312 std::string price = _("FREE");
313 std::stringstream ss;
314 ss << std::fixed << std::setprecision(1);
315 ss << "☆ " << pkg.rating;
316 std::string rating{ss.str()};
317
303 bool purchased = false;318 bool purchased = false;
304 if (pkg.price > 0.00f) {319 if (pkg.price > 0.00f) {
305 if (!Configuration::get_purchases_enabled()) {320 if (!Configuration::get_purchases_enabled()) {
@@ -312,24 +327,31 @@
312 if (installed != installedPackages.end()) {327 if (installed != installedPackages.end()) {
313 res[click::Query::ResultKeys::INSTALLED] = true;328 res[click::Query::ResultKeys::INSTALLED] = true;
314 res[click::Query::ResultKeys::PURCHASED] = purchased;329 res[click::Query::ResultKeys::PURCHASED] = purchased;
315 res["subtitle"] = _("✔ INSTALLED");330 price = _("✔ INSTALLED");
316 res[click::Query::ResultKeys::VERSION] = installed->version;331 res[click::Query::ResultKeys::VERSION] = installed->version;
317 } else if (purchased) {332 } else if (purchased) {
318 res[click::Query::ResultKeys::PURCHASED] = true;333 res[click::Query::ResultKeys::PURCHASED] = true;
319 res[click::Query::ResultKeys::INSTALLED] = false;334 res[click::Query::ResultKeys::INSTALLED] = false;
320 res["subtitle"] = _("✔ PURCHASED");335 price = _("✔ PURCHASED");
321 } else {336 } else {
322 res[click::Query::ResultKeys::INSTALLED] = false;337 res[click::Query::ResultKeys::INSTALLED] = false;
323 res[click::Query::ResultKeys::PURCHASED] = false;338 res[click::Query::ResultKeys::PURCHASED] = false;
324 if (pkg.price > 0.00f) {339 if (pkg.price > 0.00f) {
325 QLocale locale;340 QLocale locale;
326 res["subtitle"] = locale.toCurrencyString(pkg.price, "$").toUtf8().data();341 price = locale.toCurrencyString(pkg.price, "$").toUtf8().data();
327 } else {
328 res["subtitle"] = _("FREE");
329 }342 }
330 // TODO: get the real price from the webservice (upcoming branch)
331 }343 }
332344
345 // Add the price and rating as attributes.
346 scopes::VariantBuilder builder;
347 builder.add_tuple({
348 {"value", scopes::Variant(price)},
349 });
350 builder.add_tuple({
351 {"value", scopes::Variant(rating)},
352 });
353 res["attributes"] = builder.end();
354
333 this->push_result(searchReply, res);355 this->push_result(searchReply, res);
334 } catch(const std::exception& e){356 } catch(const std::exception& e){
335 qDebug() << "PackageDetails::loadJson: Exception thrown while decoding JSON: " << e.what() ;357 qDebug() << "PackageDetails::loadJson: Exception thrown while decoding JSON: " << e.what() ;
336358
=== modified file 'scope/tests/test_query.cpp'
--- scope/tests/test_query.cpp 2014-08-05 14:16:26 +0000
+++ scope/tests/test_query.cpp 2014-08-22 20:29:37 +0000
@@ -528,3 +528,30 @@
528528
529 ASSERT_EQ(unsetenv(Configuration::PURCHASES_ENVVAR), 0);529 ASSERT_EQ(unsetenv(Configuration::PURCHASES_ENVVAR), 0);
530}530}
531
532MATCHER_P(HasAttributes, b, "") { return !arg["attributes"].is_null() == b; }
533
534TEST(QueryTest, testPushPackagePushesAttributes)
535{
536 click::Packages packages {
537 {"org.example.app1", "app title1", 0.0, "icon", "uri"},
538 };
539 MockIndex mock_index(packages);
540 scopes::SearchMetadata metadata("en_EN", "phone");
541 PackageSet no_installed_packages;
542 click::DepartmentLookup dept_lookup;
543 click::HighlightList highlights;
544 MockPayPackage pay_pkg;
545 const unity::scopes::CannedQuery query("foo.scope", FAKE_QUERY, "");
546 MockQuery q(query, mock_index, dept_lookup, nullptr, highlights, metadata, pay_pkg);
547 EXPECT_CALL(mock_index, do_search(FAKE_QUERY, _));
548
549 scopes::CategoryRenderer renderer("{}");
550 auto ptrCat = std::make_shared<FakeCategory>("id", "", "", renderer);
551 EXPECT_CALL(q, register_category(_, _, _, _, _)).Times(2).WillRepeatedly(Return(ptrCat));
552
553 scopes::testing::MockSearchReply mock_reply;
554 scopes::SearchReplyProxy reply(&mock_reply, [](unity::scopes::SearchReply*){});
555 EXPECT_CALL(q, push_result(_, HasAttributes(true)));
556 q.wrap_add_available_apps(reply, no_installed_packages, FAKE_CATEGORY_TEMPLATE);
557}

Subscribers

People subscribed via source and target branches

to all changes: