Merge lp:~stolowski/unity-scopes-api/canned-query-data into lp:unity-scopes-api

Proposed by Paweł Stołowski
Status: Superseded
Proposed branch: lp:~stolowski/unity-scopes-api/canned-query-data
Merge into: lp:unity-scopes-api
Diff against target: 383 lines (+176/-3)
13 files modified
CMakeLists.txt (+1/-1)
RELEASE_NOTES.md (+4/-0)
STRUCTS (+8/-0)
debian/changelog (+6/-0)
include/unity/scopes/CannedQuery.h (+22/-0)
include/unity/scopes/internal/CannedQueryImpl.h (+5/-1)
include/unity/scopes/qt/QCannedQuery.h (+15/-0)
include/unity/scopes/qt/internal/QCannedQueryImpl.h (+2/-0)
src/scopes/CannedQuery.cpp (+15/-0)
src/scopes/internal/CannedQueryImpl.cpp (+54/-1)
src/scopes/qt/QCannedQuery.cpp (+10/-0)
src/scopes/qt/internal/QCannedQueryImpl.cpp (+10/-0)
test/gtest/scopes/CannedQuery/CannedQuery_test.cpp (+24/-0)
To merge this branch: bzr merge lp:~stolowski/unity-scopes-api/canned-query-data
Reviewer Review Type Date Requested Status
Unity Team Pending
Review via email: mp+249470@code.launchpad.net

This proposal has been superseded by a proposal from 2015-02-24.

Commit message

Added support for attaching arbitrary variant data to canned queries.

Description of the change

Added support for attaching arbitrary variant data to canned queries.

Note: needs changes in shell-plugin, therefore keeping not marking it ready yet.

To post a comment you must log in.
308. By Paweł Stołowski

Merged trunk

309. By Paweł Stołowski

Provide overloaded Scope::search method for passing arbitrary data.

310. By Paweł Stołowski

Updated symbols.

311. By Paweł Stołowski

Merged qt-coverage.

312. By Paweł Stołowski

Updated symbols.

313. By Paweł Stołowski

Support passing query data via subsearch() methods of SearchQueryBase.

314. By Paweł Stołowski

Implemented copy assignment operator. Renamed *data* to user_data.

315. By Paweł Stołowski

data -> user_data also in deserialize.

316. By Paweł Stołowski

More tests.

317. By Paweł Stołowski

Two more test cases.

318. By Paweł Stołowski

Updated doc of CannedQuery.

319. By Paweł Stołowski

Test for move.

320. By Paweł Stołowski

Updated symbols.

321. By Paweł Stołowski

Merged qt-coverage.

322. By Paweł Stołowski

Merged symbols fix.

323. By Paweł Stołowski

Fixed assignment copy/move tests.

324. By Paweł Stołowski

Renamed query_data -> user_data

Unmerged revisions

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'CMakeLists.txt'
2--- CMakeLists.txt 2015-02-13 09:20:20 +0000
3+++ CMakeLists.txt 2015-02-24 12:29:15 +0000
4@@ -227,7 +227,7 @@
5 # API version
6 set(UNITY_SCOPES_MAJOR 0)
7 set(UNITY_SCOPES_MINOR 6)
8-set(UNITY_SCOPES_MICRO 14)
9+set(UNITY_SCOPES_MICRO 15)
10 set(UNITY_SCOPES_SOVERSION 3)
11
12 # Version for testing, with all symbols visible
13
14=== modified file 'RELEASE_NOTES.md'
15--- RELEASE_NOTES.md 2015-02-13 09:20:20 +0000
16+++ RELEASE_NOTES.md 2015-02-24 12:29:15 +0000
17@@ -1,6 +1,10 @@
18 Release notes
19 =============
20
21+Changes in version 0.6.15
22+=========================
23+ - Added support for attaching arbitrary data to CannedQuery.
24+
25 Changes in version 0.6.14
26 =========================
27 - Added push_surfacing_results_from_cache() to Reply proxy. This allows a scope
28
29=== modified file 'STRUCTS'
30--- STRUCTS 2015-01-28 09:03:59 +0000
31+++ STRUCTS 2015-02-24 12:29:15 +0000
32@@ -177,3 +177,11 @@
33 ========================================
34 all QueryMetadata attributes
35 'scope_data' : variant
36+
37+CannedQuery (returned by serialize())
38+=====================================
39+ 'scope' : string
40+ 'query_string' : string
41+ 'department_id' : string
42+ 'filter_state' : variant
43+ 'data' : variant (optional)
44
45=== modified file 'debian/changelog'
46--- debian/changelog 2015-02-23 14:48:28 +0000
47+++ debian/changelog 2015-02-24 12:29:15 +0000
48@@ -1,3 +1,9 @@
49+unity-scopes-api (0.6.15-0ubuntu1) UNRELEASED; urgency=medium
50+
51+ * Added support for attaching arbitrary data to CannedQuery.
52+
53+ -- Pawel Stolowski <pawel.stolowski@canonical.com> Tue, 24 Feb 2015 13:27:37 +0100
54+
55 unity-scopes-api (0.6.14+15.04.20150223-0ubuntu1) vivid; urgency=medium
56
57 [ Pawel Stolowski ]
58
59=== modified file 'include/unity/scopes/CannedQuery.h'
60--- include/unity/scopes/CannedQuery.h 2014-11-03 05:31:30 +0000
61+++ include/unity/scopes/CannedQuery.h 2015-02-24 12:29:15 +0000
62@@ -133,6 +133,28 @@
63 */
64 static CannedQuery from_uri(std::string const& uri);
65
66+ /**
67+ \brief Attach arbitrary data.
68+
69+ \param value Data to attach to this canned query
70+ */
71+ void set_data(Variant const& value);
72+
73+ /**
74+ \brief Checks if data has been attached to this query.
75+
76+ \return true if data is available.
77+ */
78+ bool has_data() const;
79+
80+ /**
81+ \brief Get data attached to this query.
82+
83+ \return Data variant
84+ \throws unity::LogicException if data is not available.
85+ */
86+ Variant data() const;
87+
88 private:
89 CannedQuery(internal::CannedQueryImpl *impl);
90 std::unique_ptr<internal::CannedQueryImpl> p;
91
92=== modified file 'include/unity/scopes/internal/CannedQueryImpl.h'
93--- include/unity/scopes/internal/CannedQueryImpl.h 2014-11-03 05:31:30 +0000
94+++ include/unity/scopes/internal/CannedQueryImpl.h 2015-02-24 12:29:15 +0000
95@@ -40,7 +40,7 @@
96 explicit CannedQueryImpl(std::string const& scope_id);
97 CannedQueryImpl(std::string const& scope_id, std::string const& query_str, std::string const& department_id);
98 CannedQueryImpl(VariantMap const& variant);
99- CannedQueryImpl(CannedQueryImpl const &other) = default;
100+ CannedQueryImpl(CannedQueryImpl const &other);
101 CannedQueryImpl(CannedQueryImpl&&) = default;
102 CannedQueryImpl& operator=(CannedQueryImpl const& other) = default;
103 CannedQueryImpl& operator=(CannedQueryImpl&&) = default;
104@@ -56,6 +56,9 @@
105 std::string to_uri() const;
106 static CannedQuery from_uri(std::string const& uri);
107 static CannedQuery create(VariantMap const& var);
108+ void set_data(Variant const& value);
109+ bool has_data() const;
110+ Variant data() const;
111
112 static const std::string scopes_schema;
113
114@@ -65,6 +68,7 @@
115 std::string query_string_;
116 std::string department_id_;
117 FilterState filter_state_;
118+ std::unique_ptr<Variant> data_;
119 };
120
121 } // namespace internal
122
123=== modified file 'include/unity/scopes/qt/QCannedQuery.h'
124--- include/unity/scopes/qt/QCannedQuery.h 2015-02-06 00:12:18 +0000
125+++ include/unity/scopes/qt/QCannedQuery.h 2015-02-24 12:29:15 +0000
126@@ -142,6 +142,21 @@
127 */
128 static QCannedQuery from_uri(QString const& uri);
129
130+ /**
131+ \brief Checks if data has been attached to this query.
132+
133+ \return true if data is available.
134+ */
135+ bool has_data() const;
136+
137+ /**
138+ \brief Get data attached to this query.
139+
140+ \return Data variant
141+ \throws unity::LogicException if data is not available.
142+ */
143+ QVariant data() const;
144+
145 private:
146 QCannedQuery(internal::QCannedQueryImpl* impl);
147 QCannedQuery(CannedQuery const& api_query);
148
149=== modified file 'include/unity/scopes/qt/internal/QCannedQueryImpl.h'
150--- include/unity/scopes/qt/internal/QCannedQueryImpl.h 2015-02-06 00:12:18 +0000
151+++ include/unity/scopes/qt/internal/QCannedQueryImpl.h 2015-02-24 12:29:15 +0000
152@@ -70,6 +70,8 @@
153 FilterState filter_state() const;
154 QVariantMap serialize() const;
155 QString to_uri() const;
156+ bool has_data() const;
157+ QVariant data() const;
158 static QCannedQuery from_uri(QString const& uri);
159
160 // added for testing purposes
161
162=== modified file 'src/scopes/CannedQuery.cpp'
163--- src/scopes/CannedQuery.cpp 2014-04-11 12:04:41 +0000
164+++ src/scopes/CannedQuery.cpp 2015-02-24 12:29:15 +0000
165@@ -113,6 +113,21 @@
166 return internal::CannedQueryImpl::from_uri(uri);
167 }
168
169+void CannedQuery::set_data(Variant const& value)
170+{
171+ p->set_data(value);
172+}
173+
174+bool CannedQuery::has_data() const
175+{
176+ return p->has_data();
177+}
178+
179+Variant CannedQuery::data() const
180+{
181+ return p->data();
182+}
183+
184 } // namespace scopes
185
186 } // namespace unity
187
188=== modified file 'src/scopes/internal/CannedQueryImpl.cpp'
189--- src/scopes/internal/CannedQueryImpl.cpp 2014-12-01 08:26:52 +0000
190+++ src/scopes/internal/CannedQueryImpl.cpp 2015-02-24 12:29:15 +0000
191@@ -56,6 +56,18 @@
192 }
193 }
194
195+CannedQueryImpl::CannedQueryImpl(CannedQueryImpl const &other)
196+{
197+ scope_id_ = other.scope_id_;
198+ query_string_ = other.query_string_;
199+ department_id_ = other.department_id_;
200+ filter_state_ = other.filter_state_;
201+ if (other.data_ != nullptr)
202+ {
203+ data_.reset(new Variant(*other.data_));
204+ }
205+}
206+
207 CannedQueryImpl::CannedQueryImpl(VariantMap const& variant)
208 {
209 auto it = variant.find("scope");
210@@ -87,6 +99,12 @@
211 {
212 query_string_ = it->second.get_string();
213 }
214+
215+ it = variant.find("data");
216+ if (it != variant.end())
217+ {
218+ set_data(it->second);
219+ }
220 }
221
222 void CannedQueryImpl::set_department_id(std::string const& dep_id)
223@@ -124,6 +142,25 @@
224 return filter_state_;
225 }
226
227+void CannedQueryImpl::set_data(Variant const& value)
228+{
229+ data_.reset(new Variant(value));
230+}
231+
232+bool CannedQueryImpl::has_data() const
233+{
234+ return data_ != nullptr;
235+}
236+
237+Variant CannedQueryImpl::data() const
238+{
239+ if (data_)
240+ {
241+ return *data_;
242+ }
243+ throw unity::LogicException("CannedQuery::data(): data is not set for this query");
244+}
245+
246 VariantMap CannedQueryImpl::serialize() const
247 {
248 VariantMap vm;
249@@ -131,6 +168,10 @@
250 vm["query_string"] = query_string_;
251 vm["department_id"] = department_id_;
252 vm["filter_state"] = filter_state_.serialize();
253+ if (data_)
254+ {
255+ vm["data"] = *data_;
256+ }
257 return vm;
258 }
259
260@@ -152,6 +193,11 @@
261 internal::JsonCppNode const jstr(var);
262 s << "&filters=" << to_percent_encoding(jstr.to_json_string());
263 }
264+ if (data_)
265+ {
266+ internal::JsonCppNode const jstr(*(data_));
267+ s << "&data=" << to_percent_encoding(jstr.to_json_string());
268+ }
269 return s.str();
270 }
271
272@@ -231,7 +277,14 @@
273 s << "CannedQuery::from_uri(): invalid filters data for uri: '" << uri << "'";
274 throw InvalidArgumentException(s.str());
275 }
276- } // else - unknown keys are ignored
277+ }
278+ else if (key == "data")
279+ {
280+ auto const data_json = decode_or_throw(val, key, uri);
281+ internal::JsonCppNode const node(data_json);
282+ q.set_data(node.to_variant());
283+ }
284+ // else - unknown keys are ignored
285 } // else - the string with no '=' is ignored
286 }
287 }
288
289=== modified file 'src/scopes/qt/QCannedQuery.cpp'
290--- src/scopes/qt/QCannedQuery.cpp 2015-01-20 13:59:36 +0000
291+++ src/scopes/qt/QCannedQuery.cpp 2015-02-24 12:29:15 +0000
292@@ -116,3 +116,13 @@
293 {
294 return internal::QCannedQueryImpl::from_uri(uri);
295 }
296+
297+bool QCannedQuery::has_data() const
298+{
299+ return p->has_data();
300+}
301+
302+QVariant QCannedQuery::data() const
303+{
304+ return p->data();
305+}
306
307=== modified file 'src/scopes/qt/internal/QCannedQueryImpl.cpp'
308--- src/scopes/qt/internal/QCannedQueryImpl.cpp 2015-01-26 14:13:31 +0000
309+++ src/scopes/qt/internal/QCannedQueryImpl.cpp 2015-02-24 12:29:15 +0000
310@@ -81,6 +81,16 @@
311 return api_query_->filter_state();
312 }
313
314+bool QCannedQueryImpl::has_data() const
315+{
316+ return api_query_->has_data();
317+}
318+
319+QVariant QCannedQueryImpl::data() const
320+{
321+ return scopeVariantToQVariant(api_query_->data());
322+}
323+
324 QVariantMap QCannedQueryImpl::serialize() const
325 {
326 return scopeVariantMapToQVariantMap(api_query_->serialize());
327
328=== modified file 'test/gtest/scopes/CannedQuery/CannedQuery_test.cpp'
329--- test/gtest/scopes/CannedQuery/CannedQuery_test.cpp 2014-12-01 13:10:08 +0000
330+++ test/gtest/scopes/CannedQuery/CannedQuery_test.cpp 2015-02-24 12:29:15 +0000
331@@ -39,9 +39,13 @@
332 CannedQuery q("scope-A");
333 q.set_query_string("foo");
334 q.set_department_id("dep1");
335+ VariantArray va({Variant(10), Variant(20)});
336+ q.set_data(Variant(va));
337 EXPECT_EQ("scope-A", q.scope_id());
338 EXPECT_EQ("foo", q.query_string());
339 EXPECT_EQ("dep1", q.department_id());
340+ EXPECT_EQ(10, q.data().get_array()[0].get_int());
341+ EXPECT_EQ(20, q.data().get_array()[1].get_int());
342 }
343 }
344
345@@ -86,6 +90,13 @@
346 }
347 {
348 CannedQuery q("scope-A");
349+ q.set_query_string("foo");
350+ q.set_department_id("dep1");
351+ q.set_data(Variant(123));
352+ EXPECT_EQ("scope://scope-A?q=foo&dep=dep1&data=123%0A", q.to_uri());
353+ }
354+ {
355+ CannedQuery q("scope-A");
356 EXPECT_EQ("scope://scope-A?q=", q.to_uri());
357 }
358 {
359@@ -208,6 +219,13 @@
360 EXPECT_EQ("Foo bar", q.query_string());
361 EXPECT_EQ("a bc", q.department_id());
362 }
363+ {
364+ auto q = CannedQuery::from_uri("scope://foo?q=Foo&data=%22bar%22%0A");
365+ EXPECT_EQ("foo", q.scope_id());
366+ EXPECT_EQ("Foo", q.query_string());
367+ EXPECT_EQ("bar", q.data().get_string());
368+ }
369+
370 // percent-encoded host supported for backwards compatibility
371 {
372 auto q = CannedQuery::from_uri("scope://com%2Ecanonical%2Escope%2Efoo?q=Foo&filters=%7B%22f1%22%3A%5B%22o1%22%5D%7D");
373@@ -308,4 +326,10 @@
374 FAIL();
375 }
376 }
377+
378+ // no data
379+ {
380+ CannedQuery q("fooscope");
381+ EXPECT_THROW(q.data(), unity::LogicException);
382+ }
383 }

Subscribers

People subscribed via source and target branches

to all changes: