Merge lp:~webapps/unity-js-scopes/cleanup-bindings into lp:unity-js-scopes

Proposed by Marcus Tomlinson
Status: Merged
Merged at revision: 78
Proposed branch: lp:~webapps/unity-js-scopes/cleanup-bindings
Merge into: lp:unity-js-scopes
Diff against target: 3177 lines (+1372/-1008)
48 files modified
README.md (+1/-2)
debian/control (+0/-1)
examples/simple-click/src/js-scope.webapps_js-scope.js (+9/-9)
examples/simple/simple.js (+8/-4)
examples/soundcloud/soundcloud.ini (+13/-0)
examples/soundcloud/soundcloud.js (+226/-0)
src/bindings/CMakeLists.txt (+0/-1)
src/bindings/index.js (+4/-7)
src/bindings/src/action-metadata.cc (+14/-5)
src/bindings/src/action-metadata.h (+7/-7)
src/bindings/src/activation-query-proxy.cc (+60/-0)
src/bindings/src/activation-query-proxy.h (+50/-0)
src/bindings/src/activation-query.cc (+61/-0)
src/bindings/src/activation-query.h (+47/-0)
src/bindings/src/addon.cc (+225/-114)
src/bindings/src/canned-query.cc (+0/-40)
src/bindings/src/canned-query.h (+0/-45)
src/bindings/src/categorised-result.cc (+0/-72)
src/bindings/src/categorised-result.h (+0/-46)
src/bindings/src/category-renderer.cc (+0/-31)
src/bindings/src/category-renderer.h (+0/-43)
src/bindings/src/category.cc (+0/-48)
src/bindings/src/category.h (+0/-43)
src/bindings/src/column-layout.cc (+0/-86)
src/bindings/src/column-layout.h (+0/-46)
src/bindings/src/common.cc (+120/-0)
src/bindings/src/common.h (+37/-0)
src/bindings/src/preview-query-proxy.cc (+52/-0)
src/bindings/src/preview-query-proxy.h (+48/-0)
src/bindings/src/preview-query.cc (+34/-25)
src/bindings/src/preview-query.h (+11/-7)
src/bindings/src/preview-reply.cc (+6/-4)
src/bindings/src/preview-reply.h (+5/-3)
src/bindings/src/preview-widget.cc (+31/-75)
src/bindings/src/preview-widget.h (+2/-16)
src/bindings/src/result.cc (+16/-57)
src/bindings/src/result.h (+32/-20)
src/bindings/src/scope-base.cc (+82/-46)
src/bindings/src/scope-base.h (+4/-7)
src/bindings/src/search-query-proxy.cc (+52/-0)
src/bindings/src/search-query-proxy.h (+48/-0)
src/bindings/src/search-query.cc (+14/-32)
src/bindings/src/search-query.h (+2/-6)
src/bindings/src/search-reply.cc (+17/-44)
src/bindings/src/search-reply.h (+14/-2)
src/launcher/config.h.in (+2/-2)
src/tool/config.h.in (+2/-2)
src/tool/main.cc (+16/-10)
To merge this branch: bzr merge lp:~webapps/unity-js-scopes/cleanup-bindings
Reviewer Review Type Date Requested Status
WebApps Pending
Review via email: mp+273951@code.launchpad.net

Commit message

Bindings cleanup and fixes for bug #1477640, bug #1480409, and bug #1482131

To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'README.md'
2--- README.md 2015-09-30 19:54:57 +0000
3+++ README.md 2015-10-09 07:21:04 +0000
4@@ -15,6 +15,5 @@
5
6 - Desktop
7
8-export NODE_PATH=`pwd`/
9-unity-scope-tool `pwd`/examples/simple/simple.ini
10+NODE_PATH=`pwd`/ unity-scope-tool `pwd`/examples/simple/simple.ini
11
12
13=== modified file 'debian/control'
14--- debian/control 2015-10-01 13:09:54 +0000
15+++ debian/control 2015-10-09 07:21:04 +0000
16@@ -8,7 +8,6 @@
17 pkg-config,
18 g++,
19 libboost-filesystem-dev,
20- libnet-cpp-dev,
21 libunity-scopes-dev,
22 Standards-Version: 3.9.5
23 Homepage: https://launchpad.net/unity-js-scopes
24
25=== removed file 'doc/index.html'
26=== modified file 'examples/simple-click/src/js-scope.webapps_js-scope.js'
27--- examples/simple-click/src/js-scope.webapps_js-scope.js 2015-09-30 11:50:25 +0000
28+++ examples/simple-click/src/js-scope.webapps_js-scope.js 2015-10-09 07:21:04 +0000
29@@ -36,7 +36,7 @@
30 + scopes.self.scope_config)
31 },
32 search: function(canned_query, metadata) {
33- return scopes.lib.new_search_query(
34+ return scopes.lib.new_SearchQuery(
35 canned_query,
36 metadata,
37 // run
38@@ -65,7 +65,7 @@
39 response.on('end', function() {
40 r = JSON.parse(res);
41 for (i = 0; i < r.length; i++) {
42- var categorised_result = scopes.lib.new_categorised_result(category);
43+ var categorised_result = new scopes.lib.categorised_result(category);
44 categorised_result.set_uri(r[i].url);
45 categorised_result.set_title(r[i].title);
46 categorised_result.set_art(r[i].imageUrl);
47@@ -87,14 +87,14 @@
48 });
49 },
50 preview: function(result, action_metadata) {
51- return scopes.lib.new_preview_query(
52+ return scopes.lib.new_PreviewQuery(
53 result,
54 action_metadata,
55 // run
56 function(preview_reply) {
57- var layout1col = scopes.lib.new_column_layout(1);
58- var layout2col = scopes.lib.new_column_layout(2);
59- var layout3col = scopes.lib.new_column_layout(3);
60+ var layout1col = new scopes.lib.column_layout(1);
61+ var layout2col = new scopes.lib.column_layout(2);
62+ var layout3col = new scopes.lib.column_layout(3);
63 layout1col.add_column(["image", "header", "summary"]);
64
65 layout2col.add_column(["image"]);
66@@ -106,14 +106,14 @@
67
68 preview_reply.register_layout([layout1col, layout2col, layout3col]);
69
70- var header = scopes.lib.new_preview_widget("header", "header");
71+ var header = scopes.lib.new_PreviewWidget("header", "header");
72 header.add_attribute_mapping("title", "title");
73 header.add_attribute_mapping("subtitle", "subtitle");
74
75- var image = scopes.lib.new_preview_widget("image", "image");
76+ var image = scopes.lib.new_PreviewWidget("image", "image");
77 image.add_attribute_mapping("source", "art");
78
79- var description = scopes.lib.new_preview_widget("summary", "text");
80+ var description = scopes.lib.new_PreviewWidget("summary", "text");
81 description.add_attribute_mapping("text", "description");
82
83 preview_reply.push([image, header, description ]);
84
85=== modified file 'examples/simple/simple.js'
86--- examples/simple/simple.js 2015-07-30 12:28:09 +0000
87+++ examples/simple/simple.js 2015-10-09 07:21:04 +0000
88@@ -32,7 +32,7 @@
89 + scopes.self.scope_config)
90 },
91 search: function(canned_query, metadata) {
92- return scopes.lib.new_search_query(
93+ return scopes.lib.new_SearchQuery(
94 canned_query,
95 metadata,
96 // run
97@@ -40,10 +40,14 @@
98 var qs =
99 canned_query.query_string();
100 var category =
101- search_reply.register_category("simple", "hello world from js", "");
102-
103+ search_reply.register_category(
104+ "simple",
105+ "hello world from js",
106+ "",
107+ null);
108+
109 var categorised_result =
110- scopes.lib.new_categorised_result(category);
111+ new scopes.lib.categorised_result(category);
112 categorised_result.set_uri("http://www.ubuntu.com");
113 categorised_result.set_title("'" + qs + "'");
114
115
116=== added directory 'examples/soundcloud'
117=== added file 'examples/soundcloud/logo.png'
118Binary files examples/soundcloud/logo.png 1970-01-01 00:00:00 +0000 and examples/soundcloud/logo.png 2015-10-09 07:21:04 +0000 differ
119=== added file 'examples/soundcloud/soundcloud.ini'
120--- examples/soundcloud/soundcloud.ini 1970-01-01 00:00:00 +0000
121+++ examples/soundcloud/soundcloud.ini 2015-10-09 07:21:04 +0000
122@@ -0,0 +1,13 @@
123+[ScopeConfig]
124+ScopeRunner=/usr/bin/unity-js-scopes-launcher %S %R
125+DisplayName = Soundcloud JS Scope
126+Description = Soundcloud JS scope
127+Author = WebApps
128+Icon = icon.png
129+SearchHint = Search
130+
131+[Appearance]
132+PageHeader.Logo = logo.png
133+PageHeader.ForegroundColor = white
134+PageHeader.Background = color:///black
135+ShapeImages = false
136
137=== added file 'examples/soundcloud/soundcloud.js'
138--- examples/soundcloud/soundcloud.js 1970-01-01 00:00:00 +0000
139+++ examples/soundcloud/soundcloud.js 2015-10-09 07:21:04 +0000
140@@ -0,0 +1,226 @@
141+/*
142+ * Copyright 2015 Canonical Ltd.
143+ *
144+ * This file is part of unity-js-scopes.
145+ *
146+ * unity-js-scopes is free software; you can redistribute it and/or modify
147+ * it under the terms of the GNU General Public License as published by
148+ * the Free Software Foundation; version 3.
149+ *
150+ * unity-js-scopes is distributed in the hope that it will be useful,
151+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
152+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
153+ * GNU General Public License for more details.
154+ *
155+ * You should have received a copy of the GNU General Public License
156+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
157+ */
158+
159+var http = require('http')
160+var scopes = require('unity-js-scopes')
161+
162+// TODO: LANG specific host
163+var query_scheme = "https://";
164+var query_host = "api.soundcloud.com";
165+var query_path_tracks = "/tracks.json?client_id={1}&q={2}";
166+
167+function SoundCloudClient() {
168+}
169+SoundCloudClient.prototype = {
170+ // TODO use promises
171+ tracks: function(search_query, callback) {
172+ var options = {
173+ host: query_host,
174+ path: query_path_tracks.
175+ replace("{1}", "apigee").
176+ replace("{2}", encodeURIComponent(search_query))
177+ };
178+ request_callback = function(http_response) {
179+ var result_data = '';
180+
181+ http_response.on('data', function(chunk) {
182+ result_data += chunk;
183+ });
184+ http_response.on('end', function() {
185+ var results;
186+
187+ try {
188+ results = JSON.parse(result_data);
189+ } catch (e) { }
190+
191+ if (! results
192+ || ! results.length) {
193+ callback([]);
194+ return;
195+ }
196+
197+ var track_results = [];
198+ for (var i = 0;
199+ i < results.length;
200+ i++) {
201+ track_results.push({
202+ id: results[i].id,
203+ art: results[i].artwork_url ? results[i].artwork_url : "",
204+ stream_url: results[i].stream_url,
205+ uri: results[i].uri,
206+ description: results[i].description,
207+ genre: results[i].genre,
208+ artist: {
209+ id: results[i].user.id,
210+ username: results[i].user.username,
211+ search_url: results[i].user.uri
212+ }
213+ });
214+ }
215+ callback(track_results);
216+ });
217+ }
218+ http.request(options, request_callback).end();
219+ }
220+};
221+
222+var client = new SoundCloudClient()
223+
224+function scope_result_from_search_result(
225+ category,
226+ result) {
227+
228+ var categorised_result =
229+ new scopes.lib.categorised_result(category);
230+
231+ categorised_result.set_uri(result.uri)
232+ categorised_result.set_title(result.description);
233+ categorised_result.set_art(result.art);
234+
235+// categorised_result.set("artist", result.artist.username);
236+// categorised_result.set("stream", result.artist.stream_url);
237+
238+ return categorised_result
239+}
240+
241+function on_search(canned_query, metadata) {
242+ var category_description = "{ \
243+ \"schema-version\": 1, \
244+ \"template\": { \
245+ \"category-layout\": \"grid\", \
246+ \"card-layout\": \"horizontal\", \
247+ \"card-size\": \"large\" \
248+ }, \
249+ \"components\": { \
250+ \"title\": \"title\", \
251+ \"art\" : { \
252+ \"field\": \"art\" \
253+ }, \
254+ \"subtitle\": \"artist\" \
255+ } \
256+ }";
257+
258+ return scopes.lib.new_SearchQuery(
259+ canned_query,
260+ metadata,
261+ // Query.run
262+ function(search_reply) {
263+ var category_renderer =
264+ new scopes.lib.category_renderer(category_description);
265+ var category =
266+ search_reply.register_category(
267+ "tracks",
268+ "",
269+ "",
270+ category_renderer);
271+
272+ var query_string =
273+ canned_query.query_string().trim();
274+
275+ if (query_string &&
276+ query_string.length &&
277+ query_string.length != 0) {
278+ client.tracks(query_string, function(results) {
279+ for (var i in results) {
280+ var cr = scope_result_from_search_result(
281+ category,
282+ results[i]
283+ );
284+ search_reply.push(cr);
285+ }
286+ search_reply.finished();
287+ });
288+ }
289+ else {
290+ client.tracks("blur cover", function(results) {
291+ for (var i in results) {
292+ var cr = scope_result_from_search_result(
293+ category,
294+ results[i]
295+ );
296+ search_reply.push(cr);
297+ }
298+ search_reply.finished();
299+ });
300+ }
301+ },
302+ // cancelled
303+ function() {
304+ console.log('Result query cancelled')
305+ });
306+};
307+
308+function on_preview(result, action_metadata) {
309+ return scopes.lib.new_PreviewQuery(
310+ result,
311+ action_metadata,
312+ // run
313+ function(preview_reply) {
314+ var r = this.result();
315+
316+ var layout1col = new scopes.lib.column_layout(1)
317+ layout1col.add_column(["imageId", "headerId", "actionsId"])
318+
319+ var layout2col = new scopes.lib.column_layout(2)
320+ layout2col.add_column(["imageId"])
321+ layout2col.add_column(["headerId", "actionsId"])
322+
323+ preview_reply.register_layout([layout1col, layout2col]);
324+
325+ var header_widget = scopes.lib.new_PreviewWidget("headerId", "header");
326+ header_widget.add_attribute_mapping("title", "title");
327+ header_widget.add_attribute_mapping("subtitle", "subtitle");
328+
329+ var art_widget = scopes.lib.new_PreviewWidget("imageId", "image");
330+ art_widget.add_attribute_mapping("source", "art");
331+
332+ var actions_widget = scopes.lib.new_PreviewWidget("actionsId", "actions");
333+ actions_widget.add_attribute_value(
334+ "actions",
335+ {
336+ "id": "open",
337+ "label": "Open",
338+ // TODO fix
339+// "uri": r.get("uri")
340+ }
341+ );
342+ preview_reply.push([header_widget, art_widget, actions_widget])
343+ },
344+ // cancelled
345+ function() {
346+ console.log('Result preview cancelled')
347+ });
348+};
349+
350+scopes.self.initialize(
351+ {}
352+ ,
353+ {
354+ run: function() {
355+ console.log('Running...')
356+ },
357+ start: function(scope_id) {
358+ console.log('Starting scope id: '
359+ + scope_id
360+ + ', '
361+ + scopes.self.scope_config)
362+ },
363+ search: on_search,
364+ preview: on_preview,
365+ }
366+);
367
368=== modified file 'src/bindings/CMakeLists.txt'
369--- src/bindings/CMakeLists.txt 2015-09-29 11:57:36 +0000
370+++ src/bindings/CMakeLists.txt 2015-10-09 07:21:04 +0000
371@@ -59,7 +59,6 @@
372 pkg_check_modules(
373 SCOPE
374 libunity-scopes>=0.6.0
375- net-cpp>=1.1.0
376 REQUIRED
377 )
378
379
380=== modified file 'src/bindings/index.js'
381--- src/bindings/index.js 2015-07-29 08:31:17 +0000
382+++ src/bindings/index.js 2015-10-09 07:21:04 +0000
383@@ -70,22 +70,19 @@
384 }
385 },
386 get scope_directory() {
387- return this._base.get_scope_directory();
388+ return this._base.scope_directory();
389 },
390 get cache_directory() {
391- return this._base.get_cache_directory();
392+ return this._base.cache_directory();
393 },
394 get tmp_directory() {
395- return this._base.get_tmp_directory();
396+ return this._base.tmp_directory();
397 },
398 get registry() {
399 return null
400 },
401 get settings() {
402- return null
403- },
404- get settings() {
405- return null
406+ return this._base.settings();
407 },
408 get scope_config() {
409 return this._scope_binding.scope_config();
410
411=== modified file 'src/bindings/src/action-metadata.cc'
412--- src/bindings/src/action-metadata.cc 2015-06-23 19:47:08 +0000
413+++ src/bindings/src/action-metadata.cc 2015-10-09 07:21:04 +0000
414@@ -18,14 +18,23 @@
415
416 #include "action-metadata.h"
417
418-ActionMetaData::ActionMetaData(unity::scopes::ActionMetadata const &metadata)
419- : metadata_(metadata) {
420+ActionMetaData::ActionMetaData(unity::scopes::ActionMetadata const &action_metadata)
421+ : unity::scopes::ActionMetadata(action_metadata) {
422+}
423+
424+ActionMetaData::ActionMetaData(std::string const &locale,
425+ std::string const &form_factor)
426+ : unity::scopes::ActionMetadata(locale, form_factor) {
427 }
428
429 ActionMetaData::~ActionMetaData() {
430 }
431
432-const unity::scopes::ActionMetadata&
433-ActionMetaData::get_action_metadata() const {
434- return metadata_;
435+unity::scopes::Variant ActionMetaData::get(const std::string& key) {
436+ return (*this)[key];
437+}
438+
439+void ActionMetaData::set(const std::string& key,
440+ const unity::scopes::Variant& val) {
441+ (*this)[key] = val;;
442 }
443
444=== modified file 'src/bindings/src/action-metadata.h'
445--- src/bindings/src/action-metadata.h 2015-06-23 19:47:08 +0000
446+++ src/bindings/src/action-metadata.h 2015-10-09 07:21:04 +0000
447@@ -23,17 +23,17 @@
448
449 #include <v8-cpp.h>
450
451-class ActionMetaData
452+class ActionMetaData : public unity::scopes::ActionMetadata
453 {
454 public:
455- ActionMetaData(unity::scopes::ActionMetadata const &metadata);
456+ ActionMetaData(unity::scopes::ActionMetadata const &action_metadata);
457+ ActionMetaData(std::string const &locale,
458+ std::string const &form_factor);
459 ~ActionMetaData();
460
461- const unity::scopes::ActionMetadata& get_action_metadata() const;
462-
463- private:
464-
465- unity::scopes::ActionMetadata const &metadata_;
466+ // unity::scopes::ActionMetadata extra v8 bindings
467+ unity::scopes::Variant get(const std::string& key);
468+ void set(const std::string& key, const unity::scopes::Variant& val);
469 };
470
471 #endif // _UNITY_JS_ACTION_METADATA_H_
472
473=== added file 'src/bindings/src/activation-query-proxy.cc'
474--- src/bindings/src/activation-query-proxy.cc 1970-01-01 00:00:00 +0000
475+++ src/bindings/src/activation-query-proxy.cc 2015-10-09 07:21:04 +0000
476@@ -0,0 +1,60 @@
477+/*
478+ * Copyright 2015 Canonical Ltd.
479+ *
480+ * This file is part of unity-js-scopes.
481+ *
482+ * unity-js-scopes is free software; you can redistribute it and/or modify
483+ * it under the terms of the GNU General Public License as published by
484+ * the Free Software Foundation; version 3.
485+ *
486+ * unity-js-scopes is distributed in the hope that it will be useful,
487+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
488+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
489+ * GNU General Public License for more details.
490+ *
491+ * You should have received a copy of the GNU General Public License
492+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
493+ */
494+
495+#include "activation-query-proxy.h"
496+
497+#include <unity/scopes/Result.h>
498+#include <unity/scopes/ActionMetadata.h>
499+
500+ActivationQueryProxy::ActivationQueryProxy(
501+ std::shared_ptr<unity::scopes::ActivationQueryBase> backend)
502+ : unity::scopes::ActivationQueryBase(backend->result(), backend->action_metadata()),
503+ backend_(backend) {
504+}
505+
506+unity::scopes::ActivationResponse ActivationQueryProxy::activate() {
507+ return backend_->activate();
508+}
509+
510+unity::scopes::Result ActivationQueryProxy::result() const {
511+ return backend_->result();
512+}
513+
514+unity::scopes::ActionMetadata ActivationQueryProxy::action_metadata() const {
515+ return backend_->action_metadata();
516+}
517+
518+std::string ActivationQueryProxy::widget_id() const {
519+ return backend_->widget_id();
520+}
521+
522+std::string ActivationQueryProxy::action_id() const {
523+ return backend_->action_id();
524+}
525+
526+void ActivationQueryProxy::cancelled() {
527+ backend_->cancelled();
528+}
529+
530+bool ActivationQueryProxy::valid() const {
531+ return backend_->valid();
532+}
533+
534+unity::scopes::VariantMap ActivationQueryProxy::settings() const {
535+ return backend_->settings();
536+}
537
538=== added file 'src/bindings/src/activation-query-proxy.h'
539--- src/bindings/src/activation-query-proxy.h 1970-01-01 00:00:00 +0000
540+++ src/bindings/src/activation-query-proxy.h 2015-10-09 07:21:04 +0000
541@@ -0,0 +1,50 @@
542+/*
543+ * Copyright 2015 Canonical Ltd.
544+ *
545+ * This file is part of unity-js-scopes.
546+ *
547+ * unity-js-scopes is free software; you can redistribute it and/or modify
548+ * it under the terms of the GNU General Public License as published by
549+ * the Free Software Foundation; version 3.
550+ *
551+ * unity-js-scopes is distributed in the hope that it will be useful,
552+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
553+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
554+ * GNU General Public License for more details.
555+ *
556+ * You should have received a copy of the GNU General Public License
557+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
558+ */
559+
560+#ifndef _UNITY_JS_ACTIVATION_QUERY_PROXY_H_
561+#define _UNITY_JS_ACTIVATION_QUERY_PROXY_H_
562+
563+#include <unity/scopes/ActivationQueryBase.h>
564+
565+#include <v8-cpp.h>
566+
567+
568+class ActivationQueryProxy : public unity::scopes::ActivationQueryBase
569+{
570+ public:
571+ ActivationQueryProxy(
572+ std::shared_ptr<unity::scopes::ActivationQueryBase> backend);
573+
574+ unity::scopes::ActivationResponse activate() override;
575+ unity::scopes::Result result() const;
576+ unity::scopes::ActionMetadata action_metadata() const;
577+ std::string widget_id() const;
578+ std::string action_id() const;
579+ void cancelled() override;
580+ bool valid() const;
581+ unity::scopes::VariantMap settings() const;
582+
583+ // TODO handle the subsearch override functions
584+
585+ private:
586+ std::shared_ptr<unity::scopes::ActivationQueryBase> backend_;
587+};
588+
589+#endif // _UNITY_JS_ACTIVATION_QUERY_PROXY_H_
590+
591+
592
593=== added file 'src/bindings/src/activation-query.cc'
594--- src/bindings/src/activation-query.cc 1970-01-01 00:00:00 +0000
595+++ src/bindings/src/activation-query.cc 2015-10-09 07:21:04 +0000
596@@ -0,0 +1,61 @@
597+/*
598+ * Copyright 2015 Canonical Ltd.
599+ *
600+ * This file is part of unity-js-scopes.
601+ *
602+ * unity-js-scopes is free software; you can redistribute it and/or modify
603+ * it under the terms of the GNU General Public License as published by
604+ * the Free Software Foundation; version 3.
605+ *
606+ * unity-js-scopes is distributed in the hope that it will be useful,
607+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
608+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
609+ * GNU General Public License for more details.
610+ *
611+ * You should have received a copy of the GNU General Public License
612+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
613+ */
614+
615+#include "activation-query.h"
616+
617+#include "event_queue.h"
618+
619+ActivationQuery::ActivationQuery(
620+ unity::scopes::Result const& result,
621+ unity::scopes::ActionMetadata const& metadata,
622+ const v8::Local<v8::Function> &cancelled_callback)
623+ : unity::scopes::ActivationQueryBase(result, metadata),
624+ isolate_(v8::Isolate::GetCurrent()),
625+ cancelled_callback_(v8::Isolate::GetCurrent(), cancelled_callback) {
626+}
627+
628+ActivationQuery::~ActivationQuery() {
629+ if (!cancelled_callback_.IsEmpty()) {
630+ cancelled_callback_.Reset();
631+ }
632+}
633+
634+void ActivationQuery::cancelled() {
635+ if (cancelled_callback_.IsEmpty()) {
636+ return;
637+ }
638+
639+ EventQueue::instance().run(isolate_, [this]
640+ {
641+ v8::Local<v8::Function> cancelled_callback =
642+ v8cpp::to_local<v8::Function>(isolate_, cancelled_callback_);
643+
644+ v8cpp::call_v8_with_receiver(
645+ isolate_,
646+ v8cpp::to_v8(isolate_, shared_from_this()),
647+ cancelled_callback
648+ );
649+ });
650+}
651+
652+v8::Local<v8::Value>
653+ActivationQuery::activate(v8::FunctionCallbackInfo<v8::Value> const& args) {
654+ return v8cpp::to_v8(isolate_, nullptr);
655+ // unity::scopes::ActivationResponse
656+}
657+
658
659=== added file 'src/bindings/src/activation-query.h'
660--- src/bindings/src/activation-query.h 1970-01-01 00:00:00 +0000
661+++ src/bindings/src/activation-query.h 2015-10-09 07:21:04 +0000
662@@ -0,0 +1,47 @@
663+/*
664+ * Copyright 2015 Canonical Ltd.
665+ *
666+ * This file is part of unity-js-scopes.
667+ *
668+ * unity-js-scopes is free software; you can redistribute it and/or modify
669+ * it under the terms of the GNU General Public License as published by
670+ * the Free Software Foundation; version 3.
671+ *
672+ * unity-js-scopes is distributed in the hope that it will be useful,
673+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
674+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
675+ * GNU General Public License for more details.
676+ *
677+ * You should have received a copy of the GNU General Public License
678+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
679+ */
680+
681+#ifndef _UNITY_JS_ACTIVATION_QUERY_H_
682+#define _UNITY_JS_ACTIVATION_QUERY_H_
683+
684+#include <unity/scopes/ActivationQueryBase.h>
685+
686+#include <v8-cpp.h>
687+
688+class ActivationQuery : public unity::scopes::ActivationQueryBase,
689+ public std::enable_shared_from_this<ActivationQuery>
690+{
691+ public:
692+ ActivationQuery(unity::scopes::Result const& result,
693+ unity::scopes::ActionMetadata const& metadata,
694+ const v8::Local<v8::Function> &cancelled_callback);
695+ ~ActivationQuery() override;
696+
697+ // v8 bindings
698+ v8::Local<v8::Value> activate(v8::FunctionCallbackInfo<v8::Value> const& args);
699+
700+ // PreviewQueryBase implementation
701+ void cancelled() override;
702+
703+ private:
704+ v8::Isolate* isolate_;
705+
706+ v8::Persistent<v8::Function> cancelled_callback_;
707+};
708+
709+#endif // _UNITY_JS_ACTIVATION_QUERY_H_
710
711=== modified file 'src/bindings/src/addon.cc'
712--- src/bindings/src/addon.cc 2015-08-27 11:46:23 +0000
713+++ src/bindings/src/addon.cc 2015-10-09 07:21:04 +0000
714@@ -20,18 +20,22 @@
715
716 #include <stdexcept>
717
718+#include <unity/scopes/ActionMetadata.h>
719+#include <unity/scopes/CannedQuery.h>
720+#include <unity/scopes/Category.h>
721+#include <unity/scopes/CategorisedResult.h>
722+#include <unity/scopes/CategoryRenderer.h>
723+#include <unity/scopes/Result.h>
724+#include <unity/scopes/SearchReply.h>
725+
726 #include <boost/algorithm/string/predicate.hpp>
727 #include <boost/filesystem.hpp>
728
729 #include <node.h>
730
731+#include "activation-query.h"
732 #include "scope-base.h"
733 #include "scope.h"
734-#include "canned-query.h"
735-#include "category.h"
736-#include "categorised-result.h"
737-#include "category-renderer.h"
738-#include "column-layout.h"
739 #include "search-query.h"
740 #include "search-reply.h"
741 #include "search-metadata.h"
742@@ -46,19 +50,43 @@
743 return new JavascriptScopeRuntime(runtime_config);
744 }
745
746-v8::Handle<v8::Object> new_search_query(
747+v8::Handle<v8::Object> get_scopes_runtime_version() {
748+ v8::Handle<v8::Object> o =
749+ v8::Object::New(v8::Isolate::GetCurrent());
750+
751+ int major, minor, micro;
752+ unity::scopes::ScopeBase::runtime_version(major, minor, micro);
753+
754+ o->Set(v8::String::NewFromUtf8(v8::Isolate::GetCurrent(), "major"),
755+ v8::Integer::New(v8::Isolate::GetCurrent(), major));
756+ o->Set(v8::String::NewFromUtf8(v8::Isolate::GetCurrent(), "minor"),
757+ v8::Integer::New(v8::Isolate::GetCurrent(), minor));
758+ o->Set(v8::String::NewFromUtf8(v8::Isolate::GetCurrent(), "micro"),
759+ v8::Integer::New(v8::Isolate::GetCurrent(), micro));
760+
761+ return o;
762+}
763+
764+std::shared_ptr<unity::scopes::CategoryRenderer>
765+new_category_renderer_from_file(const std::string& file_path) {
766+ return std::shared_ptr<unity::scopes::CategoryRenderer>(
767+ new unity::scopes::CategoryRenderer(
768+ unity::scopes::CategoryRenderer::from_file(file_path)));
769+}
770+
771+v8::Handle<v8::Object> new_SearchQuery(
772 v8::FunctionCallbackInfo<v8::Value> const& args) {
773 if (args.Length() != 4) {
774 throw std::runtime_error("Invalid number of arguments");
775 }
776
777- CannedQuery *c =
778- v8cpp::from_v8<CannedQuery*>(
779+ std::shared_ptr<unity::scopes::CannedQuery> c =
780+ v8cpp::from_v8<std::shared_ptr<unity::scopes::CannedQuery>>(
781 v8::Isolate::GetCurrent(),
782 args[0]->ToObject());
783
784- SearchMetaData *s =
785- v8cpp::from_v8<SearchMetaData*>(
786+ std::shared_ptr<SearchMetaData> s =
787+ v8cpp::from_v8<std::shared_ptr<SearchMetaData>>(
788 v8::Isolate::GetCurrent(),
789 args[1]->ToObject());
790
791@@ -75,42 +103,31 @@
792 v8::Local<v8::Function> cancelled_callback =
793 v8::Handle<v8::Function>::Cast(args[3]);
794
795- SearchQuery *sq =
796+ std::shared_ptr<SearchQuery> sq(
797 new SearchQuery(
798- c->get_canned_query(),
799+ *c,
800 static_cast<const unity::scopes::SearchMetadata&>(*s),
801 run_callback,
802- cancelled_callback);
803+ cancelled_callback)
804+ );
805
806 return v8cpp::to_v8(v8::Isolate::GetCurrent(), sq);
807 }
808
809-v8::Handle<v8::Object> new_category_renderer(
810- v8::FunctionCallbackInfo<v8::Value> const& args) {
811- if (args.Length() != 1) {
812- throw std::runtime_error("Invalid number of arguments");
813- }
814- if (!args[0]->IsString()) {
815- throw std::runtime_error("Invalid arguments types");
816- }
817-
818- std::string json_text = *(v8::String::Utf8Value(args[0]->ToString()));
819-
820- CategoryRenderer* category_renderer = new CategoryRenderer(json_text);
821-
822- return v8cpp::to_v8(v8::Isolate::GetCurrent(), category_renderer);
823-}
824-
825-v8::Handle<v8::Object> new_preview_query(v8::FunctionCallbackInfo<v8::Value> const& args) {
826+v8::Handle<v8::Object> new_PreviewQuery(v8::FunctionCallbackInfo<v8::Value> const& args) {
827 if (args.Length() != 4) {
828 throw std::runtime_error("Invalid number of arguments");
829 }
830
831- Result *r =
832- v8cpp::from_v8<Result*>(v8::Isolate::GetCurrent(), args[0]->ToObject());
833+ std::shared_ptr<Result> r =
834+ v8cpp::from_v8<std::shared_ptr<Result>>(
835+ v8::Isolate::GetCurrent(),
836+ args[0]->ToObject());
837
838- ActionMetaData *a =
839- v8cpp::from_v8<ActionMetaData*>(v8::Isolate::GetCurrent(), args[1]->ToObject());
840+ std::shared_ptr<unity::scopes::ActionMetadata> a =
841+ v8cpp::from_v8<std::shared_ptr<unity::scopes::ActionMetadata>>(
842+ v8::Isolate::GetCurrent(),
843+ args[1]->ToObject());
844
845 if (!r || !a) {
846 throw std::runtime_error("Invalid arguments types");
847@@ -130,23 +147,25 @@
848 v8::Local<v8::Function> cancelled_callback =
849 v8::Handle<v8::Function>::Cast(args[3]);
850
851- PreviewQuery *pq =
852- new PreviewQuery(
853- r->get_result(),
854- a->get_action_metadata(),
855+ std::shared_ptr<PreviewQuery> pq(
856+ new PreviewQuery(
857+ *r,
858+ *a,
859 run_callback,
860- cancelled_callback);
861+ cancelled_callback));
862+
863 return v8cpp::to_v8(v8::Isolate::GetCurrent(), pq);
864 }
865
866-v8::Handle<v8::Object> new_preview_widget(v8::FunctionCallbackInfo<v8::Value> const& args) {
867+v8::Handle<v8::Object> new_PreviewWidget(
868+ v8::FunctionCallbackInfo<v8::Value> const& args) {
869 if (args.Length() < 1 || args.Length() > 2) {
870 throw std::runtime_error("Invalid number of arguments");
871 }
872
873 if (args.Length() == 2) {
874 if (!args[0]->IsString() || !args[1]->IsString()) {
875- throw std::runtime_error("Invalid arguments types");
876+ throw std::runtime_error("Invalid arguments types: should be id, widget_type");
877 }
878 std::string id =
879 *(v8::String::Utf8Value(args[0]->ToString()));
880@@ -173,34 +192,28 @@
881 return v8cpp::to_v8(v8::Isolate::GetCurrent(), preview_widget);
882 }
883
884-v8::Handle<v8::Object> new_categorised_result(
885- v8::FunctionCallbackInfo<v8::Value> const& args) {
886- if (args.Length() != 1) {
887- throw std::runtime_error("Invalid number of arguments");
888- }
889-
890- Category *c =
891- v8cpp::from_v8<Category*>(v8::Isolate::GetCurrent(),
892- args[0]->ToObject());
893-
894- if (!c) {
895- throw std::runtime_error("Invalid arguments types");
896- }
897-
898- CategorisedResult *cr = new CategorisedResult(c);
899-
900- return v8cpp::to_v8(v8::Isolate::GetCurrent(), cr);
901-}
902-
903-ColumnLayout* new_column_layout(int num_of_columns)
904-{
905- return new ColumnLayout(num_of_columns);
906-}
907-
908 void InitAll(v8::Handle<v8::Object> exports)
909 {
910 v8::Isolate* isolate = v8::Isolate::GetCurrent();
911
912+ v8cpp::Class<unity::scopes::VariantMap> variant_map(isolate);
913+ v8cpp::Class<unity::scopes::VariantArray> variant_array(isolate);
914+
915+ // TODO: which enum should be bound
916+ v8cpp::Class<unity::scopes::Variant> variant(isolate);
917+ variant
918+ .add_method("get_int", &unity::scopes::Variant::get_int)
919+ .add_method("get_double", &unity::scopes::Variant::get_double)
920+ .add_method("get_bool", &unity::scopes::Variant::get_bool)
921+ .add_method("get_string", &unity::scopes::Variant::get_string)
922+ .add_method("get_dict", &unity::scopes::Variant::get_dict)
923+ .add_method("get_array", &unity::scopes::Variant::get_array)
924+ .add_method("is_null", &unity::scopes::Variant::is_null)
925+ .add_method("which", &unity::scopes::Variant::which)
926+ .add_method("serialize_json", &unity::scopes::Variant::serialize_json)
927+ .add_method("deserialize_json", &unity::scopes::Variant::deserialize_json)
928+ .add_method("which", &unity::scopes::Variant::which);
929+
930 v8cpp::Class<JavascriptScopeRuntime> js_scope(isolate);
931 js_scope
932 .add_method("scope_base", &JavascriptScopeRuntime::scope_base)
933@@ -209,83 +222,162 @@
934
935 v8cpp::Class<ScopeBase> scope_base(isolate);
936 scope_base
937+ .add_inheritance<unity::scopes::ScopeBase>()
938 .add_method("onstart", &ScopeBase::onstart)
939 .add_method("onstop", &ScopeBase::onstop)
940 .add_method("onrun", &ScopeBase::onrun)
941 .add_method("onsearch", &ScopeBase::onsearch)
942 .add_method("onpreview", &ScopeBase::onpreview)
943- .add_method("get_scope_directory", &ScopeBase::get_scope_directory)
944- .add_method("get_cache_directory", &ScopeBase::get_cache_directory)
945- .add_method("get_tmp_directory", &ScopeBase::get_tmp_directory);
946-
947- v8cpp::Class<ActionMetaData> action_metadata(isolate);
948-
949- v8cpp::Class<Category> category(isolate);
950+ // unity::scopes::ScopeBase
951+ .add_method("scope_directory", &unity::scopes::ScopeBase::scope_directory)
952+ .add_method("cache_directory", &unity::scopes::ScopeBase::cache_directory)
953+ .add_method("tmp_directory", &unity::scopes::ScopeBase::tmp_directory)
954+ .add_method("settings", &unity::scopes::ScopeBase::settings)
955+ .add_method("registry", &unity::scopes::ScopeBase::registry);
956+
957+ v8cpp::Class<unity::scopes::ActionMetadata> action_metadata(isolate);
958+ action_metadata
959+ // unity::scopes::ActionMetadata
960+ .add_method("set_scope_data", &unity::scopes::ActionMetadata::set_scope_data)
961+ .add_method("scope_data", &unity::scopes::ActionMetadata::scope_data)
962+ .add_method("set_hint", &unity::scopes::ActionMetadata::set_hint)
963+ .add_method("hints", &unity::scopes::ActionMetadata::hints)
964+ .add_method("contains_hint", &unity::scopes::ActionMetadata::contains_hint)
965+ // unity::scopes::QueryMetadata
966+ .add_method("locale", &unity::scopes::QueryMetadata::locale)
967+ .add_method("form_factor", &unity::scopes::QueryMetadata::form_factor)
968+ .add_method("set_internet_connectivity", &unity::scopes::QueryMetadata::set_internet_connectivity)
969+ .add_method("internet_connectivity", &unity::scopes::QueryMetadata::internet_connectivity);
970+
971+ v8cpp::Class<ActivationQuery> activation_query(isolate);
972+ activation_query
973+ .add_inheritance<unity::scopes::ActivationQueryBase>()
974+ // ActivationQuery
975+ .add_method("activate", &ActivationQuery::activate)
976+ // ActivationQueryBase
977+ .add_method("result", &unity::scopes::ActivationQueryBase::result)
978+ .add_method("action_metadata", &unity::scopes::ActivationQueryBase::action_metadata)
979+ .add_method("widget_id", &unity::scopes::ActivationQueryBase::widget_id)
980+ .add_method("action_id", &unity::scopes::ActivationQueryBase::action_id)
981+ // QueryBase
982+ .add_method("valid", &unity::scopes::QueryBase::valid)
983+ .add_method("settings", &unity::scopes::QueryBase::settings);
984+
985+ v8cpp::Class<unity::scopes::Category> category(isolate);
986 category
987- .add_method("id", &Category::id)
988- .add_method("title", &Category::title)
989- .add_method("icon", &Category::icon);
990+ // unity::scopes::Category
991+ .add_method("query", &unity::scopes::Category::query)
992+ .add_method("id", &unity::scopes::Category::id)
993+ .add_method("title", &unity::scopes::Category::title)
994+ .add_method("icon", &unity::scopes::Category::icon);
995
996- v8cpp::Class<CategorisedResult> categorised_result(isolate);
997+ v8cpp::Class<unity::scopes::CategorisedResult> categorised_result(isolate);
998 categorised_result
999- .add_method("set_uri", &CategorisedResult::set_uri)
1000- .add_method("set_title", &CategorisedResult::set_title)
1001- .add_method("set_art", &CategorisedResult::set_art);
1002+ .add_inheritance<unity::scopes::Result>()
1003+ .set_constructor<unity::scopes::Category::SCPtr>()
1004+ // unity::scopes::Result
1005+ .add_method("set_uri", &unity::scopes::Result::set_uri)
1006+ .add_method("set_title", &unity::scopes::Result::set_title)
1007+ .add_method("set_art", &unity::scopes::Result::set_art)
1008+ .add_method("set_dnd_uri", &unity::scopes::Result::set_dnd_uri)
1009+ .add_method("set_intercept_activation", &unity::scopes::Result::set_intercept_activation)
1010+ .add_method("direct_activation", &unity::scopes::Result::direct_activation)
1011+ .add_method("uri", &unity::scopes::Result::uri)
1012+ .add_method("title", &unity::scopes::Result::title)
1013+ .add_method("art", &unity::scopes::Result::art)
1014+ .add_method("dnd_uri", &unity::scopes::Result::dnd_uri)
1015+ .add_method("contains", &unity::scopes::Result::contains)
1016+ // Result
1017+ .add_method("set", &set_result_value<unity::scopes::CategorisedResult>)
1018+ .add_method("get", &get_result_value<unity::scopes::CategorisedResult>)
1019+ // unity::scopes::CategorisedResult
1020+ .add_method("set_category", &unity::scopes::CategorisedResult::set_category)
1021+ .add_method("category", &unity::scopes::CategorisedResult::category);
1022
1023- v8cpp::Class<CannedQuery> canned_query(isolate);
1024+ v8cpp::Class<unity::scopes::CannedQuery> canned_query(isolate);
1025 canned_query
1026- .add_method("query_string", &CannedQuery::query_string)
1027- .add_method("to_uri", &CannedQuery::to_uri);
1028+ .add_method("set_department_id", &unity::scopes::CannedQuery::set_department_id)
1029+ .add_method("set_query_string", &unity::scopes::CannedQuery::set_query_string)
1030+ .add_method("set_filter_state", &unity::scopes::CannedQuery::set_filter_state)
1031+ .add_method("scope_id", &unity::scopes::CannedQuery::scope_id)
1032+ .add_method("department_id", &unity::scopes::CannedQuery::department_id)
1033+ .add_method("filter_state", &unity::scopes::CannedQuery::filter_state)
1034+ .add_method("query_string", &unity::scopes::CannedQuery::query_string)
1035+ .add_method("to_uri", &unity::scopes::CannedQuery::to_uri);
1036
1037- v8cpp::Class<CategoryRenderer> category_renderer(isolate);
1038+ // TODO Should it be more of a value type? (it seems to be used that way
1039+ // in unity API)
1040+ v8cpp::Class<unity::scopes::CategoryRenderer> category_renderer(isolate);
1041 category_renderer
1042- .add_method("data", &CategoryRenderer::data);
1043+ .set_constructor<std::string>()
1044+ .add_method("data", &unity::scopes::CategoryRenderer::data);
1045
1046- v8cpp::Class<ColumnLayout> column_layout(isolate);
1047+ v8cpp::Class<unity::scopes::ColumnLayout> column_layout(isolate);
1048 column_layout
1049- .add_method("add_column", &ColumnLayout::add_column)
1050- .add_method("size", &ColumnLayout::size)
1051- .add_method("number_of_columns", &ColumnLayout::number_of_columns)
1052- .add_method("column", &ColumnLayout::column);
1053+ .set_constructor<int>()
1054+ .add_method("add_column", &unity::scopes::ColumnLayout::add_column)
1055+ .add_method("size", &unity::scopes::ColumnLayout::size)
1056+ .add_method("number_of_columns", &unity::scopes::ColumnLayout::number_of_columns)
1057+ .add_method("column", &unity::scopes::ColumnLayout::column);
1058
1059 v8cpp::Class<PreviewWidget> preview_widget(isolate);
1060 preview_widget
1061+ .add_inheritance<unity::scopes::PreviewWidget>()
1062+ // unity::scopes::PreviewWidget
1063+ .add_method("id", &unity::scopes::PreviewWidget::id)
1064+ .add_method("widget_type", &unity::scopes::PreviewWidget::widget_type)
1065+ .add_method("attribute_mappings", &unity::scopes::PreviewWidget::attribute_mappings)
1066+ .add_method("data", &unity::scopes::PreviewWidget::data)
1067+ .add_method("add_attribute_mapping", &unity::scopes::PreviewWidget::add_attribute_mapping)
1068+ // PreviewWidget
1069 .add_method("add_attribute_value", &PreviewWidget::add_attribute_value)
1070- .add_method("add_attribute_mapping", &PreviewWidget::add_attribute_mapping)
1071- .add_method("add_widget", &PreviewWidget::add_widget)
1072- .add_method("id", &PreviewWidget::id)
1073- .add_method("widget_type", &PreviewWidget::widget_type)
1074- .add_method("attribute_mappings", &PreviewWidget::attribute_mappings)
1075- .add_method("attribute_values", &PreviewWidget::attribute_values)
1076- .add_method("widgets", &PreviewWidget::widgets)
1077- .add_method("data", &PreviewWidget::data);
1078+ .add_method("add_widget", &PreviewWidget::add_widget);
1079
1080 v8cpp::Class<PreviewQuery> preview_query(isolate);
1081 preview_query
1082- .add_method("run", &PreviewQuery::run)
1083- .add_method("cancelled", &PreviewQuery::cancelled);
1084+ .add_inheritance<unity::scopes::PreviewQueryBase>()
1085+ // unity::scopes::QueryBase
1086+ .add_method("valid", &unity::scopes::QueryBase::valid)
1087+ .add_method("settings", &unity::scopes::QueryBase::settings)
1088+ // PreviewQuery
1089+ .add_method("result", &PreviewQuery::result)
1090+ .add_method("action_metadata", &PreviewQuery::action_metadata);
1091
1092+ // TODO handle info()
1093 v8cpp::Class<PreviewReply> preview_reply(isolate);
1094 preview_reply
1095+ // PreviewReply
1096 .add_method("register_layout", &PreviewReply::register_layout)
1097 .add_method("push", &PreviewReply::push)
1098- .add_method("finished", &PreviewReply::finished);
1099+ // unity::scopes::PreviewReply
1100+ .add_method("finished", &unity::scopes::PreviewReply::finished);
1101
1102 v8cpp::Class<Result> result(isolate);
1103 result
1104- .add_method("art", &Result::art)
1105- .add_method("set_art", &Result::set_art)
1106- .add_method("title", &Result::title)
1107- .add_method("set_title", &Result::set_title)
1108- .add_method("dnd_uri", &Result::dnd_uri)
1109- .add_method("set_dnd_uri", &Result::set_dnd_uri)
1110- .add_method("uri", &Result::uri)
1111- .add_method("set_uri", &Result::set_uri);
1112+ // unity::scopes::Result
1113+ .add_method("art", &unity::scopes::Result::art)
1114+ .add_method("set_art", &unity::scopes::Result::set_art)
1115+ .add_method("title", &unity::scopes::Result::title)
1116+ .add_method("set_title", &unity::scopes::Result::set_title)
1117+ .add_method("dnd_uri", &unity::scopes::Result::dnd_uri)
1118+ .add_method("set_dnd_uri", &unity::scopes::Result::set_dnd_uri)
1119+ .add_method("uri", &unity::scopes::Result::uri)
1120+ .add_method("set_uri", &unity::scopes::Result::set_uri)
1121+ .add_method("set_intercept_activation", &unity::scopes::Result::set_intercept_activation)
1122+ .add_method("direct_activation", &unity::scopes::Result::direct_activation)
1123+ .add_method("has_stored_result", &unity::scopes::Result::has_stored_result)
1124+ // Result
1125+ .add_method("set", &set_result_value<unity::scopes::Result>)
1126+ .add_method("get", &get_result_value<unity::scopes::Result>)
1127+ .add_method("retrieve_stored_result", &Result::retrieve_stored_result)
1128+ .add_method("store", &Result::store);
1129
1130 v8cpp::Class<SearchReply> search_reply(isolate);
1131 search_reply
1132+ // SearchReply
1133 .add_method("register_category", &SearchReply::register_category)
1134 .add_method("push", &SearchReply::push)
1135+ .add_method("lookup_category", &SearchReply::lookup_category)
1136 .add_method("finished", &SearchReply::finished);
1137
1138 v8cpp::Class<SearchQuery> search_query(isolate);
1139@@ -294,11 +386,27 @@
1140 .add_method("oncancelled", &SearchQuery::oncancelled);
1141
1142 v8cpp::Class<SearchMetaData> search_metadata(isolate);
1143+ search_metadata
1144+ .add_inheritance<unity::scopes::SearchMetadata>()
1145+ // SearchMetadata
1146+ .add_method("set_cardinality", &unity::scopes::SearchMetadata::set_cardinality)
1147+ .add_method("cardinality", &unity::scopes::SearchMetadata::cardinality)
1148+ .add_method("set_location", &unity::scopes::SearchMetadata::set_location)
1149+ .add_method("location", &unity::scopes::SearchMetadata::location)
1150+ .add_method("has_location", &unity::scopes::SearchMetadata::has_location)
1151+ .add_method("set_hint", &unity::scopes::SearchMetadata::set_hint)
1152+ .add_method("hints", &unity::scopes::SearchMetadata::hints)
1153+ // QueryMetadata
1154+ .add_method("locale", &unity::scopes::QueryMetadata::locale)
1155+ .add_method("form_factor", &unity::scopes::QueryMetadata::form_factor)
1156+ .add_method("set_internet_connectivity", &unity::scopes::QueryMetadata::set_internet_connectivity)
1157+ .add_method("internet_connectivity", &unity::scopes::QueryMetadata::internet_connectivity);
1158
1159 v8cpp::Module module(isolate);
1160 module.add_class("js_scope", js_scope);
1161 module.add_class("scope_base", scope_base);
1162 module.add_class("action_metadata", action_metadata);
1163+ module.add_class("activation_query", activation_query);
1164 module.add_class("category", category);
1165 module.add_class("categorised_result", categorised_result);
1166 module.add_class("canned_query", canned_query);
1167@@ -311,14 +419,17 @@
1168 module.add_class("search_reply", search_reply);
1169 module.add_class("search_query", search_query);
1170 module.add_class("search_metadata", search_metadata);
1171+ module.add_class("variant", variant);
1172+ module.add_class("variant_map", variant_map);
1173+ module.add_class("variant_array", variant_array);
1174
1175 module.add_function("new_scope", &new_scope);
1176- module.add_function("new_search_query", &new_search_query);
1177- module.add_function("new_category_renderer", &new_category_renderer);
1178- module.add_function("new_preview_query", &new_preview_query);
1179- module.add_function("new_preview_widget", &new_preview_widget);
1180- module.add_function("new_categorised_result", &new_categorised_result);
1181- module.add_function("new_column_layout", &new_column_layout);
1182+ module.add_function("new_SearchQuery", &new_SearchQuery);
1183+ module.add_function("new_PreviewQuery", &new_PreviewQuery);
1184+ module.add_function("new_PreviewWidget", &new_PreviewWidget);
1185+ module.add_function("new_category_renderer_from_file", &new_category_renderer_from_file);
1186+
1187+ module.add_function("runtime_version", &get_scopes_runtime_version);
1188
1189 exports->SetPrototype(module.create_prototype());
1190 }
1191
1192=== removed file 'src/bindings/src/canned-query.cc'
1193--- src/bindings/src/canned-query.cc 2015-06-18 16:39:04 +0000
1194+++ src/bindings/src/canned-query.cc 1970-01-01 00:00:00 +0000
1195@@ -1,40 +0,0 @@
1196-/*
1197- * Copyright 2015 Canonical Ltd.
1198- *
1199- * This file is part of unity-js-scopes.
1200- *
1201- * unity-js-scopes is free software; you can redistribute it and/or modify
1202- * it under the terms of the GNU General Public License as published by
1203- * the Free Software Foundation; version 3.
1204- *
1205- * unity-js-scopes is distributed in the hope that it will be useful,
1206- * but WITHOUT ANY WARRANTY; without even the implied warranty of
1207- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1208- * GNU General Public License for more details.
1209- *
1210- * You should have received a copy of the GNU General Public License
1211- * along with this program. If not, see <http://www.gnu.org/licenses/>.
1212- */
1213-
1214-#include "canned-query.h"
1215-
1216-CannedQuery::CannedQuery(unity::scopes::CannedQuery const &query)
1217- : query_(query) {
1218-}
1219-
1220-CannedQuery::~CannedQuery() {
1221-}
1222-
1223-v8::Local<v8::Value> CannedQuery::query_string(
1224- v8::FunctionCallbackInfo<v8::Value> const& args) {
1225- return v8cpp::to_v8(v8::Isolate::GetCurrent(), query_.query_string().c_str());
1226-}
1227-
1228-v8::Local<v8::Value> CannedQuery::to_uri(
1229- v8::FunctionCallbackInfo<v8::Value> const& args) {
1230- return v8cpp::to_v8(v8::Isolate::GetCurrent(), query_.to_uri().c_str());
1231-}
1232-
1233-unity::scopes::CannedQuery const & CannedQuery::get_canned_query() {
1234- return query_;
1235-}
1236
1237=== removed file 'src/bindings/src/canned-query.h'
1238--- src/bindings/src/canned-query.h 2015-07-30 12:28:09 +0000
1239+++ src/bindings/src/canned-query.h 1970-01-01 00:00:00 +0000
1240@@ -1,45 +0,0 @@
1241-/*
1242- * Copyright 2015 Canonical Ltd.
1243- *
1244- * This file is part of unity-js-scopes.
1245- *
1246- * unity-js-scopes is free software; you can redistribute it and/or modify
1247- * it under the terms of the GNU General Public License as published by
1248- * the Free Software Foundation; version 3.
1249- *
1250- * unity-js-scopes is distributed in the hope that it will be useful,
1251- * but WITHOUT ANY WARRANTY; without even the implied warranty of
1252- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1253- * GNU General Public License for more details.
1254- *
1255- * You should have received a copy of the GNU General Public License
1256- * along with this program. If not, see <http://www.gnu.org/licenses/>.
1257- */
1258-
1259-#ifndef _UNITY_JS_CANNED_QUERY_H_
1260-#define _UNITY_JS_CANNED_QUERY_H_
1261-
1262-#include <unity/scopes/CannedQuery.h>
1263-
1264-#include <v8-cpp.h>
1265-
1266-class CannedQuery
1267-{
1268- public:
1269- CannedQuery(unity::scopes::CannedQuery const &query);
1270- ~CannedQuery();
1271-
1272- // v8 binding
1273- v8::Local<v8::Value> query_string(
1274- v8::FunctionCallbackInfo<v8::Value> const& args);
1275- v8::Local<v8::Value> to_uri(
1276- v8::FunctionCallbackInfo<v8::Value> const& args);
1277-
1278- unity::scopes::CannedQuery const & get_canned_query();
1279-
1280- private:
1281-
1282- unity::scopes::CannedQuery const query_;
1283-};
1284-
1285-#endif // _UNITY_JS_CANNED_QUERY_H_
1286
1287=== removed file 'src/bindings/src/categorised-result.cc'
1288--- src/bindings/src/categorised-result.cc 2015-08-11 07:04:10 +0000
1289+++ src/bindings/src/categorised-result.cc 1970-01-01 00:00:00 +0000
1290@@ -1,72 +0,0 @@
1291-/*
1292- * Copyright 2015 Canonical Ltd.
1293- *
1294- * This file is part of unity-js-scopes.
1295- *
1296- * unity-js-scopes is free software; you can redistribute it and/or modify
1297- * it under the terms of the GNU General Public License as published by
1298- * the Free Software Foundation; version 3.
1299- *
1300- * unity-js-scopes is distributed in the hope that it will be useful,
1301- * but WITHOUT ANY WARRANTY; without even the implied warranty of
1302- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1303- * GNU General Public License for more details.
1304- *
1305- * You should have received a copy of the GNU General Public License
1306- * along with this program. If not, see <http://www.gnu.org/licenses/>.
1307- */
1308-
1309-#include "categorised-result.h"
1310-
1311-CategorisedResult::CategorisedResult(Category * category)
1312- : unity::scopes::CategorisedResult(category->get_category()),
1313- category_(category) {
1314-}
1315-
1316-CategorisedResult::~CategorisedResult() {
1317-}
1318-
1319-void CategorisedResult::set_uri(
1320- v8::FunctionCallbackInfo<v8::Value> const& args) {
1321- if (args.Length() != 1) {
1322- // TODO fix
1323- return;
1324- }
1325-
1326- if (!args[0]->IsString()) {
1327- // TODO fix
1328- return;
1329- }
1330-
1331- unity::scopes::CategorisedResult::set_uri(*(v8::String::Utf8Value(args[0]->ToString())));
1332-}
1333-
1334-void CategorisedResult::set_title(
1335- v8::FunctionCallbackInfo<v8::Value> const& args) {
1336- if (args.Length() != 1) {
1337- // TODO fix
1338- return;
1339- }
1340-
1341- if (!args[0]->IsString()) {
1342- // TODO fix
1343- return;
1344- }
1345-
1346- unity::scopes::CategorisedResult::set_title(*(v8::String::Utf8Value(args[0]->ToString())));
1347-}
1348-
1349-void CategorisedResult::set_art(
1350- v8::FunctionCallbackInfo<v8::Value> const& args) {
1351- if (args.Length() != 1) {
1352- // TODO fix
1353- return;
1354- }
1355-
1356- if (!args[0]->IsString()) {
1357- // TODO fix
1358- return;
1359- }
1360-
1361- unity::scopes::CategorisedResult::set_art(*(v8::String::Utf8Value(args[0]->ToString())));
1362-}
1363
1364=== removed file 'src/bindings/src/categorised-result.h'
1365--- src/bindings/src/categorised-result.h 2015-08-11 07:04:10 +0000
1366+++ src/bindings/src/categorised-result.h 1970-01-01 00:00:00 +0000
1367@@ -1,46 +0,0 @@
1368-/*
1369- * Copyright 2015 Canonical Ltd.
1370- *
1371- * This file is part of unity-js-scopes.
1372- *
1373- * unity-js-scopes is free software; you can redistribute it and/or modify
1374- * it under the terms of the GNU General Public License as published by
1375- * the Free Software Foundation; version 3.
1376- *
1377- * unity-js-scopes is distributed in the hope that it will be useful,
1378- * but WITHOUT ANY WARRANTY; without even the implied warranty of
1379- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1380- * GNU General Public License for more details.
1381- *
1382- * You should have received a copy of the GNU General Public License
1383- * along with this program. If not, see <http://www.gnu.org/licenses/>.
1384- */
1385-
1386-#ifndef _UNITY_JS_CATEGORISED_RESULT_H_
1387-#define _UNITY_JS_CATEGORISED_RESULT_H_
1388-
1389-#include <unity/scopes/CategorisedResult.h>
1390-
1391-#include <v8-cpp.h>
1392-
1393-#include "category.h"
1394-
1395-class CategorisedResult : public unity::scopes::CategorisedResult
1396-{
1397- public:
1398- CategorisedResult(Category * category);
1399- ~CategorisedResult() override;
1400-
1401- // v8 binding
1402- void set_uri(v8::FunctionCallbackInfo<v8::Value> const& args);
1403- void set_title(v8::FunctionCallbackInfo<v8::Value> const& args);
1404- void set_art(v8::FunctionCallbackInfo<v8::Value> const& args);
1405-
1406- private:
1407-
1408- // TODO ownership & lifetime !
1409- // better to own the scptr
1410- Category * category_;
1411-};
1412-
1413-#endif // _UNITY_JS_CATEGORISED_RESULT_H_
1414
1415=== removed file 'src/bindings/src/category-renderer.cc'
1416--- src/bindings/src/category-renderer.cc 2015-06-23 19:47:08 +0000
1417+++ src/bindings/src/category-renderer.cc 1970-01-01 00:00:00 +0000
1418@@ -1,31 +0,0 @@
1419-/*
1420- * Copyright 2015 Canonical Ltd.
1421- *
1422- * This file is part of unity-js-scopes.
1423- *
1424- * unity-js-scopes is free software; you can redistribute it and/or modify
1425- * it under the terms of the GNU General Public License as published by
1426- * the Free Software Foundation; version 3.
1427- *
1428- * unity-js-scopes is distributed in the hope that it will be useful,
1429- * but WITHOUT ANY WARRANTY; without even the implied warranty of
1430- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1431- * GNU General Public License for more details.
1432- *
1433- * You should have received a copy of the GNU General Public License
1434- * along with this program. If not, see <http://www.gnu.org/licenses/>.
1435- */
1436-
1437-#include "category-renderer.h"
1438-
1439-CategoryRenderer::CategoryRenderer(std::string const &json_text)
1440- : renderer_(json_text) {
1441-}
1442-
1443-CategoryRenderer::~CategoryRenderer() {
1444-}
1445-
1446-v8::Local<v8::Value> CategoryRenderer::data(
1447- v8::FunctionCallbackInfo<v8::Value> const& args) {
1448- return v8cpp::to_v8(args.GetIsolate(), renderer_.data().c_str());
1449-}
1450
1451=== removed file 'src/bindings/src/category-renderer.h'
1452--- src/bindings/src/category-renderer.h 2015-06-23 19:47:08 +0000
1453+++ src/bindings/src/category-renderer.h 1970-01-01 00:00:00 +0000
1454@@ -1,43 +0,0 @@
1455-/*
1456- * Copyright 2015 Canonical Ltd.
1457- *
1458- * This file is part of unity-js-scopes.
1459- *
1460- * unity-js-scopes is free software; you can redistribute it and/or modify
1461- * it under the terms of the GNU General Public License as published by
1462- * the Free Software Foundation; version 3.
1463- *
1464- * unity-js-scopes is distributed in the hope that it will be useful,
1465- * but WITHOUT ANY WARRANTY; without even the implied warranty of
1466- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1467- * GNU General Public License for more details.
1468- *
1469- * You should have received a copy of the GNU General Public License
1470- * along with this program. If not, see <http://www.gnu.org/licenses/>.
1471- */
1472-
1473-#ifndef _UNITY_JS_CATEGORY_RENDERER_H_
1474-#define _UNITY_JS_CATEGORY_RENDERER_H_
1475-
1476-#include <unity/scopes/CategoryRenderer.h>
1477-
1478-#include <v8-cpp.h>
1479-
1480-class CategoryRenderer
1481-{
1482- public:
1483- CategoryRenderer(std::string const &json_text);
1484- ~CategoryRenderer();
1485-
1486- const unity::scopes::CategoryRenderer&
1487- get_renderer() const;
1488-
1489- // v8 implementation
1490- v8::Local<v8::Value> data(v8::FunctionCallbackInfo<v8::Value> const& args);
1491-
1492- private:
1493-
1494- unity::scopes::CategoryRenderer renderer_;
1495-};
1496-
1497-#endif // _UNITY_JS_SEARCH_METADATA_H_
1498
1499=== removed file 'src/bindings/src/category.cc'
1500--- src/bindings/src/category.cc 2015-06-18 16:39:04 +0000
1501+++ src/bindings/src/category.cc 1970-01-01 00:00:00 +0000
1502@@ -1,48 +0,0 @@
1503-/*
1504- * Copyright 2015 Canonical Ltd.
1505- *
1506- * This file is part of unity-js-scopes.
1507- *
1508- * unity-js-scopes is free software; you can redistribute it and/or modify
1509- * it under the terms of the GNU General Public License as published by
1510- * the Free Software Foundation; version 3.
1511- *
1512- * unity-js-scopes is distributed in the hope that it will be useful,
1513- * but WITHOUT ANY WARRANTY; without even the implied warranty of
1514- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1515- * GNU General Public License for more details.
1516- *
1517- * You should have received a copy of the GNU General Public License
1518- * along with this program. If not, see <http://www.gnu.org/licenses/>.
1519- */
1520-
1521-#include "category.h"
1522-
1523-Category::Category(unity::scopes::Category::SCPtr category)
1524- : category_(category) {
1525-}
1526-
1527-Category::~Category() {
1528-}
1529-
1530-v8::Local<v8::Value> Category::id(
1531- v8::FunctionCallbackInfo<v8::Value> const& args) {
1532- v8::Isolate *isolate = args.GetIsolate();
1533- return v8cpp::to_v8(isolate, category_->id().c_str());
1534-}
1535-
1536-v8::Local<v8::Value> Category::title(
1537- v8::FunctionCallbackInfo<v8::Value> const& args) {
1538- v8::Isolate *isolate = args.GetIsolate();
1539- return v8cpp::to_v8(isolate, category_->title().c_str());
1540-}
1541-
1542-v8::Local<v8::Value> Category::icon(
1543- v8::FunctionCallbackInfo<v8::Value> const& args) {
1544- v8::Isolate *isolate = args.GetIsolate();
1545- return v8cpp::to_v8(isolate, category_->icon().c_str());
1546-}
1547-
1548-unity::scopes::Category::SCPtr Category::get_category() {
1549- return category_;
1550-}
1551
1552=== removed file 'src/bindings/src/category.h'
1553--- src/bindings/src/category.h 2015-06-18 16:39:04 +0000
1554+++ src/bindings/src/category.h 1970-01-01 00:00:00 +0000
1555@@ -1,43 +0,0 @@
1556-/*
1557- * Copyright 2015 Canonical Ltd.
1558- *
1559- * This file is part of unity-js-scopes.
1560- *
1561- * unity-js-scopes is free software; you can redistribute it and/or modify
1562- * it under the terms of the GNU General Public License as published by
1563- * the Free Software Foundation; version 3.
1564- *
1565- * unity-js-scopes is distributed in the hope that it will be useful,
1566- * but WITHOUT ANY WARRANTY; without even the implied warranty of
1567- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1568- * GNU General Public License for more details.
1569- *
1570- * You should have received a copy of the GNU General Public License
1571- * along with this program. If not, see <http://www.gnu.org/licenses/>.
1572- */
1573-
1574-#ifndef _UNITY_JS_CATEGORY_H_
1575-#define _UNITY_JS_CATEGORY_H_
1576-
1577-#include <unity/scopes/Category.h>
1578-
1579-#include <v8-cpp.h>
1580-
1581-class Category
1582-{
1583- public:
1584- Category(unity::scopes::Category::SCPtr category);
1585- ~Category();
1586-
1587- // v8 binding
1588- v8::Local<v8::Value> id(v8::FunctionCallbackInfo<v8::Value> const& args);
1589- v8::Local<v8::Value> title(v8::FunctionCallbackInfo<v8::Value> const& args);
1590- v8::Local<v8::Value> icon(v8::FunctionCallbackInfo<v8::Value> const& args);
1591-
1592- unity::scopes::Category::SCPtr get_category();
1593-
1594- private:
1595- unity::scopes::Category::SCPtr category_;
1596-};
1597-
1598-#endif // _UNITY_JS_CATEGORY_H_
1599
1600=== removed file 'src/bindings/src/column-layout.cc'
1601--- src/bindings/src/column-layout.cc 2015-08-18 21:05:20 +0000
1602+++ src/bindings/src/column-layout.cc 1970-01-01 00:00:00 +0000
1603@@ -1,86 +0,0 @@
1604-/*
1605- * Copyright 2015 Canonical Ltd.
1606- *
1607- * This file is part of unity-js-scopes.
1608- *
1609- * unity-js-scopes is free software; you can redistribute it and/or modify
1610- * it under the terms of the GNU General Public License as published by
1611- * the Free Software Foundation; version 3.
1612- *
1613- * unity-js-scopes is distributed in the hope that it will be useful,
1614- * but WITHOUT ANY WARRANTY; without even the implied warranty of
1615- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1616- * GNU General Public License for more details.
1617- *
1618- * You should have received a copy of the GNU General Public License
1619- * along with this program. If not, see <http://www.gnu.org/licenses/>.
1620- */
1621-
1622-#include "column-layout.h"
1623-
1624-ColumnLayout::ColumnLayout(int num_of_columns)
1625- : column_layout_(num_of_columns) {
1626-}
1627-
1628-ColumnLayout::~ColumnLayout() {
1629-}
1630-
1631-void ColumnLayout::add_column(
1632- v8::FunctionCallbackInfo<v8::Value> const& args) {
1633- if (args.Length() != 1) {
1634- return;
1635- }
1636-
1637- if (!args[0]->IsArray()) {
1638- return;
1639- }
1640-
1641- std::vector<std::string> columns;
1642-
1643- v8::Handle<v8::Array> array =
1644- v8::Handle<v8::Array>::Cast(args[0]);
1645- for (size_t i = 0; i < array->Length(); i++) {
1646- v8::Local<v8::Value> element = array->Get(i);
1647- if (!element->IsString()) {
1648- return;
1649- }
1650- columns.push_back(
1651- *v8::String::Utf8Value(element->ToString()));
1652- }
1653- column_layout_.add_column(columns);
1654-}
1655-
1656-v8::Local<v8::Value> ColumnLayout::size(
1657- v8::FunctionCallbackInfo<v8::Value> const& args) {
1658- return v8cpp::to_v8(args.GetIsolate(), column_layout_.size());
1659-}
1660-
1661-v8::Local<v8::Value> ColumnLayout::number_of_columns(
1662- v8::FunctionCallbackInfo<v8::Value> const& args) {
1663- return v8cpp::to_v8(args.GetIsolate(), column_layout_.number_of_columns());
1664-}
1665-
1666-v8::Local<v8::Value> ColumnLayout::column(
1667- v8::FunctionCallbackInfo<v8::Value> const& args) {
1668- if (args.Length() != 1 || !args[0]->IsInt32()) {
1669- return v8cpp::to_v8(args.GetIsolate(), nullptr);
1670- }
1671-
1672- int index = args[0]->Int32Value();
1673- std::vector<std::string> c =
1674- column_layout_.column(index);
1675-
1676- v8::Handle<v8::Array> array =
1677- v8::Array::New(args.GetIsolate(), c.size());
1678-
1679- for (std::vector<std::string>::size_type i = 0;
1680- i < c.size();
1681- ++i) {
1682- array->Set(i, v8::String::NewFromUtf8(args.GetIsolate(), c[i].c_str()));
1683- }
1684- return array;
1685-}
1686-
1687-const unity::scopes::ColumnLayout& ColumnLayout::get_column_layout() const {
1688- return column_layout_;
1689-}
1690
1691=== removed file 'src/bindings/src/column-layout.h'
1692--- src/bindings/src/column-layout.h 2015-06-23 19:47:08 +0000
1693+++ src/bindings/src/column-layout.h 1970-01-01 00:00:00 +0000
1694@@ -1,46 +0,0 @@
1695-/*
1696- * Copyright 2015 Canonical Ltd.
1697- *
1698- * This file is part of unity-js-scopes.
1699- *
1700- * unity-js-scopes is free software; you can redistribute it and/or modify
1701- * it under the terms of the GNU General Public License as published by
1702- * the Free Software Foundation; version 3.
1703- *
1704- * unity-js-scopes is distributed in the hope that it will be useful,
1705- * but WITHOUT ANY WARRANTY; without even the implied warranty of
1706- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1707- * GNU General Public License for more details.
1708- *
1709- * You should have received a copy of the GNU General Public License
1710- * along with this program. If not, see <http://www.gnu.org/licenses/>.
1711- */
1712-
1713-#ifndef _UNITY_JS_COLUMN_LAYOUT_H_
1714-#define _UNITY_JS_COLUMN_LAYOUT_H_
1715-
1716-#include <unity/scopes/ColumnLayout.h>
1717-
1718-#include <v8-cpp.h>
1719-
1720-class ColumnLayout
1721-{
1722- public:
1723- ColumnLayout(int num_of_columns);
1724- ~ColumnLayout();
1725-
1726- // v8 implementation
1727- void add_column(v8::FunctionCallbackInfo<v8::Value> const& args);
1728- v8::Local<v8::Value> size(v8::FunctionCallbackInfo<v8::Value> const& args);
1729- v8::Local<v8::Value> number_of_columns(v8::FunctionCallbackInfo<v8::Value> const& args);
1730- v8::Local<v8::Value> column(v8::FunctionCallbackInfo<v8::Value> const& args);
1731-
1732- const unity::scopes::ColumnLayout&
1733- get_column_layout() const;
1734-
1735- private:
1736-
1737- unity::scopes::ColumnLayout column_layout_;
1738-};
1739-
1740-#endif // _UNITY_JS_COLUMN_LAYOUT_H_
1741
1742=== added file 'src/bindings/src/common.cc'
1743--- src/bindings/src/common.cc 1970-01-01 00:00:00 +0000
1744+++ src/bindings/src/common.cc 2015-10-09 07:21:04 +0000
1745@@ -0,0 +1,120 @@
1746+/*
1747+ * Copyright 2015 Canonical Ltd.
1748+ *
1749+ * This file is part of unity-js-scopes.
1750+ *
1751+ * unity-js-scopes is free software; you can redistribute it and/or modify
1752+ * it under the terms of the GNU General Public License as published by
1753+ * the Free Software Foundation; version 3.
1754+ *
1755+ * unity-js-scopes is distributed in the hope that it will be useful,
1756+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
1757+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1758+ * GNU General Public License for more details.
1759+ *
1760+ * You should have received a copy of the GNU General Public License
1761+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
1762+ */
1763+
1764+#include "common.h"
1765+
1766+v8::Local<v8::Value> unity::scopesjs::from_variant(
1767+ const unity::scopes::Variant& variant) {
1768+ switch(variant.which()) {
1769+ case unity::scopes::Variant::Null:
1770+ return v8::Null(v8::Isolate::GetCurrent());
1771+ break;
1772+ case unity::scopes::Variant::Int:
1773+ return v8::Integer::New(v8::Isolate::GetCurrent(), variant.get_int());
1774+ break;
1775+ case unity::scopes::Variant::Bool:
1776+ return v8::Boolean::New(v8::Isolate::GetCurrent(), variant.get_bool());
1777+ break;
1778+ case unity::scopes::Variant::String:
1779+ return v8::String::NewFromUtf8(v8::Isolate::GetCurrent(), variant.get_string().c_str());
1780+ break;
1781+ case unity::scopes::Variant::Double:
1782+ return v8::Number::New(v8::Isolate::GetCurrent(), variant.get_double());
1783+ break;
1784+ case unity::scopes::Variant::Int64:
1785+ return v8::Number::New(v8::Isolate::GetCurrent(), variant.get_int());
1786+ break;
1787+ case unity::scopes::Variant::Dict:
1788+ {
1789+ v8::Handle<v8::Object> o = v8::Object::New(v8::Isolate::GetCurrent());
1790+ for (const auto& e : variant.get_dict()) {
1791+ o->Set(v8::String::NewFromUtf8(
1792+ v8::Isolate::GetCurrent(),
1793+ e.first.c_str()),
1794+ from_variant(e.second));
1795+ }
1796+ return o;
1797+ }
1798+ break;
1799+ case unity::scopes::Variant::Array:
1800+ {
1801+ const unity::scopes::VariantArray & va =
1802+ variant.get_array();
1803+ v8::Handle<v8::Array> a =
1804+ v8::Array::New(v8::Isolate::GetCurrent(), variant.get_array().size());
1805+
1806+ for (size_t i = 0; i < va.size(); ++i) {
1807+ a->Set(i, from_variant(va[i]));
1808+ }
1809+ return a;
1810+ }
1811+ break;
1812+ }
1813+
1814+ return v8::Null(v8::Isolate::GetCurrent());
1815+}
1816+
1817+unity::scopes::Variant unity::scopesjs::to_variant(
1818+ v8::Local<v8::Value> value) {
1819+ using unity::scopes::Variant;
1820+ using unity::scopes::VariantArray;
1821+ using unity::scopes::VariantMap;
1822+
1823+ Variant v;
1824+
1825+ if (value->IsString()) {
1826+ v = *(v8::String::Utf8Value(value->ToString()));
1827+ } else if (value->IsUint32()) {
1828+ v = Variant((double) value->ToUint32()->Value());
1829+ } else if (value->IsInt32()) {
1830+ v = Variant(value->ToInt32()->Value());
1831+ } else if (value->IsBoolean()) {
1832+ v = Variant(value->ToBoolean()->Value());
1833+ } else if (value->IsNumber()) {
1834+ v = Variant(value->NumberValue());
1835+ } else if (value->IsObject()) {
1836+ v8::Handle<v8::Object> o = v8::Handle<v8::Object>::Cast(value);
1837+
1838+ v8::Local<v8::Array> names = o->GetPropertyNames();
1839+
1840+ VariantMap vm;
1841+
1842+ for (size_t i = 0; i < names->Length(); ++i) {
1843+ std::string name = *(v8::String::Utf8Value(names->Get(i)));
1844+ vm[name] = to_variant(o->Get(v8::String::NewFromUtf8(
1845+ v8::Isolate::GetCurrent(), name.c_str())));
1846+ }
1847+
1848+ v = vm;
1849+ } else if (value->IsArray()) {
1850+ v8::Handle<v8::Object> o = v8::Handle<v8::Object>::Cast(value);
1851+
1852+ VariantArray va;
1853+
1854+ for (size_t i = 0;
1855+ i < o->Get(v8::String::NewFromUtf8(
1856+ v8::Isolate::GetCurrent(), "length"))->ToObject()->Uint32Value();
1857+ ++i) {
1858+ va.push_back(to_variant(o->Get(i)));
1859+ }
1860+
1861+ v = va;
1862+ }
1863+
1864+ return v;
1865+}
1866
1867=== added file 'src/bindings/src/common.h'
1868--- src/bindings/src/common.h 1970-01-01 00:00:00 +0000
1869+++ src/bindings/src/common.h 2015-10-09 07:21:04 +0000
1870@@ -0,0 +1,37 @@
1871+/*
1872+ * Copyright 2015 Canonical Ltd.
1873+ *
1874+ * This file is part of unity-js-scopes.
1875+ *
1876+ * unity-js-scopes is free software; you can redistribute it and/or modify
1877+ * it under the terms of the GNU General Public License as published by
1878+ * the Free Software Foundation; version 3.
1879+ *
1880+ * unity-js-scopes is distributed in the hope that it will be useful,
1881+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
1882+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1883+ * GNU General Public License for more details.
1884+ *
1885+ * You should have received a copy of the GNU General Public License
1886+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
1887+ */
1888+
1889+#include <string>
1890+
1891+#include <v8-cpp.h>
1892+
1893+#include "unity/scopes/Variant.h"
1894+
1895+
1896+namespace unity {
1897+namespace scopesjs {
1898+
1899+unity::scopes::Variant
1900+to_variant(v8::Local<v8::Value> value);
1901+
1902+v8::Local<v8::Value>
1903+from_variant(const unity::scopes::Variant& variant);
1904+
1905+} // namespace scopesjs
1906+} // namespace unity
1907+
1908
1909=== added file 'src/bindings/src/preview-query-proxy.cc'
1910--- src/bindings/src/preview-query-proxy.cc 1970-01-01 00:00:00 +0000
1911+++ src/bindings/src/preview-query-proxy.cc 2015-10-09 07:21:04 +0000
1912@@ -0,0 +1,52 @@
1913+/*
1914+ * Copyright 2015 Canonical Ltd.
1915+ *
1916+ * This file is part of unity-js-scopes.
1917+ *
1918+ * unity-js-scopes is free software; you can redistribute it and/or modify
1919+ * it under the terms of the GNU General Public License as published by
1920+ * the Free Software Foundation; version 3.
1921+ *
1922+ * unity-js-scopes is distributed in the hope that it will be useful,
1923+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
1924+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1925+ * GNU General Public License for more details.
1926+ *
1927+ * You should have received a copy of the GNU General Public License
1928+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
1929+ */
1930+
1931+#include "preview-query-proxy.h"
1932+
1933+#include <unity/scopes/Result.h>
1934+#include <unity/scopes/ActionMetadata.h>
1935+
1936+PreviewQueryProxy::PreviewQueryProxy(
1937+ std::shared_ptr<unity::scopes::PreviewQueryBase> backend)
1938+ : unity::scopes::PreviewQueryBase(backend->result(), backend->action_metadata()),
1939+ backend_(backend) {
1940+}
1941+
1942+void PreviewQueryProxy::run(unity::scopes::PreviewReplyProxy const &reply) {
1943+ backend_->run(reply);
1944+}
1945+
1946+unity::scopes::Result PreviewQueryProxy::result() const {
1947+ return backend_->result();
1948+}
1949+
1950+unity::scopes::ActionMetadata PreviewQueryProxy::action_metadata() const {
1951+ return backend_->action_metadata();
1952+}
1953+
1954+void PreviewQueryProxy::cancelled() {
1955+ backend_->cancelled();
1956+}
1957+
1958+bool PreviewQueryProxy::valid() const {
1959+ return backend_->valid();
1960+}
1961+
1962+unity::scopes::VariantMap PreviewQueryProxy::settings() const {
1963+ return backend_->settings();
1964+}
1965
1966=== added file 'src/bindings/src/preview-query-proxy.h'
1967--- src/bindings/src/preview-query-proxy.h 1970-01-01 00:00:00 +0000
1968+++ src/bindings/src/preview-query-proxy.h 2015-10-09 07:21:04 +0000
1969@@ -0,0 +1,48 @@
1970+/*
1971+ * Copyright 2015 Canonical Ltd.
1972+ *
1973+ * This file is part of unity-js-scopes.
1974+ *
1975+ * unity-js-scopes is free software; you can redistribute it and/or modify
1976+ * it under the terms of the GNU General Public License as published by
1977+ * the Free Software Foundation; version 3.
1978+ *
1979+ * unity-js-scopes is distributed in the hope that it will be useful,
1980+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
1981+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1982+ * GNU General Public License for more details.
1983+ *
1984+ * You should have received a copy of the GNU General Public License
1985+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
1986+ */
1987+
1988+#ifndef _UNITY_JS_PREVIEW_QUERY_PROXY_H_
1989+#define _UNITY_JS_PREVIEW_QUERY_PROXY_H_
1990+
1991+#include <unity/scopes/PreviewQueryBase.h>
1992+
1993+#include <v8-cpp.h>
1994+
1995+
1996+class PreviewQueryProxy : public unity::scopes::PreviewQueryBase
1997+{
1998+ public:
1999+ PreviewQueryProxy(
2000+ std::shared_ptr<unity::scopes::PreviewQueryBase> backend);
2001+
2002+ void run(unity::scopes::PreviewReplyProxy const &reply) override;
2003+ unity::scopes::Result result () const;
2004+ unity::scopes::ActionMetadata action_metadata () const;
2005+ bool valid() const;
2006+ unity::scopes::VariantMap settings() const;
2007+ void cancelled() override;
2008+
2009+ // TODO handle the subsearch override functions
2010+
2011+ private:
2012+ std::shared_ptr<unity::scopes::PreviewQueryBase> backend_;
2013+};
2014+
2015+#endif // _UNITY_JS_SEARCH_QUERY_PROXY_H_
2016+
2017+
2018
2019=== modified file 'src/bindings/src/preview-query.cc'
2020--- src/bindings/src/preview-query.cc 2015-08-27 11:46:23 +0000
2021+++ src/bindings/src/preview-query.cc 2015-10-09 07:21:04 +0000
2022@@ -40,26 +40,6 @@
2023 }
2024 }
2025
2026-void PreviewQuery::onrun(
2027- v8::FunctionCallbackInfo<v8::Value> const& args) {
2028- if (args.Length() != 1) {
2029- // TODO fix
2030- return;
2031- }
2032-
2033- if (!args[0]->IsFunction()) {
2034- // TODO fix
2035- return;
2036- }
2037-
2038- if (!run_callback_.IsEmpty()) {
2039- run_callback_.Reset();
2040- }
2041-
2042- v8::Local<v8::Function> cb = v8::Handle<v8::Function>::Cast(args[0]);
2043- run_callback_.Reset(args.GetIsolate(), cb);
2044-}
2045-
2046 void PreviewQuery::run(unity::scopes::PreviewReplyProxy const& reply) {
2047 if (run_callback_.IsEmpty()) {
2048 return;
2049@@ -67,17 +47,46 @@
2050
2051 EventQueue::instance().run(isolate_, [this, reply]
2052 {
2053- // wrap & fire
2054- PreviewReply *pr = new PreviewReply(reply);
2055-
2056- auto wrapped_pr = v8cpp::to_v8(isolate_, pr);
2057+ std::shared_ptr<PreviewReply> r =
2058+ std::shared_ptr<PreviewReply>(new PreviewReply(reply));
2059
2060 v8::Local<v8::Function> run_callback =
2061 v8cpp::to_local<v8::Function>(isolate_, run_callback_);
2062
2063- v8cpp::call_v8(isolate_, run_callback, wrapped_pr);
2064+ v8cpp::call_v8_with_receiver(
2065+ isolate_,
2066+ v8cpp::to_v8(isolate_, shared_from_this()),
2067+ run_callback,
2068+ v8cpp::to_v8(isolate_, r)
2069+ );
2070 });
2071 }
2072
2073 void PreviewQuery::cancelled() {
2074+ if (cancelled_callback_.IsEmpty()) {
2075+ return;
2076+ }
2077+
2078+ EventQueue::instance().run(isolate_, [this]
2079+ {
2080+ v8::Local<v8::Function> cancelled_callback =
2081+ v8cpp::to_local<v8::Function>(isolate_, cancelled_callback_);
2082+
2083+ v8cpp::call_v8_with_receiver(
2084+ isolate_,
2085+ v8cpp::to_v8(isolate_, shared_from_this()),
2086+ cancelled_callback
2087+ );
2088+ });
2089+}
2090+
2091+std::shared_ptr<unity::scopes::ActionMetadata>
2092+PreviewQuery::action_metadata() const {
2093+ return std::shared_ptr<unity::scopes::ActionMetadata>(
2094+ new unity::scopes::ActionMetadata(unity::scopes::PreviewQueryBase::action_metadata()));
2095+}
2096+
2097+std::shared_ptr<unity::scopes::Result> PreviewQuery::result() const {
2098+ return std::shared_ptr<unity::scopes::Result>(
2099+ new unity::scopes::Result(unity::scopes::PreviewQueryBase::result()));
2100 }
2101
2102=== modified file 'src/bindings/src/preview-query.h'
2103--- src/bindings/src/preview-query.h 2015-08-27 11:46:23 +0000
2104+++ src/bindings/src/preview-query.h 2015-10-09 07:21:04 +0000
2105@@ -19,11 +19,14 @@
2106 #ifndef _UNITY_JS_PREVIEW_QUERY_H_
2107 #define _UNITY_JS_PREVIEW_QUERY_H_
2108
2109+#include <unity/scopes/ActionMetadata.h>
2110 #include <unity/scopes/PreviewQueryBase.h>
2111+#include <unity/scopes/Result.h>
2112
2113 #include <v8-cpp.h>
2114
2115-class PreviewQuery : public unity::scopes::PreviewQueryBase
2116+class PreviewQuery : public unity::scopes::PreviewQueryBase,
2117+ public std::enable_shared_from_this<PreviewQuery>
2118 {
2119 public:
2120 PreviewQuery(unity::scopes::Result const& result,
2121@@ -34,12 +37,13 @@
2122
2123 // PreviewQueryBase implementation
2124 void run(unity::scopes::PreviewReplyProxy const& reply);
2125- void cancelled();
2126-
2127- // v8 binding
2128- void onrun(v8::FunctionCallbackInfo<v8::Value> const& args);
2129- // v8::Local<v8::Value> get_result(v8::FunctionCallbackInfo<v8::Value> const& args);
2130- // v8::Local<v8::Value> get_action_metadata(v8::FunctionCallbackInfo<v8::Value> const& args);
2131+
2132+ // QueryBase implementation
2133+ void cancelled() override;
2134+
2135+ // v8 bindings
2136+ std::shared_ptr<unity::scopes::ActionMetadata> action_metadata() const;
2137+ std::shared_ptr<unity::scopes::Result> result() const;
2138
2139 private:
2140 v8::Isolate* isolate_;
2141
2142=== modified file 'src/bindings/src/preview-reply.cc'
2143--- src/bindings/src/preview-reply.cc 2015-09-01 10:31:12 +0000
2144+++ src/bindings/src/preview-reply.cc 2015-10-09 07:21:04 +0000
2145@@ -27,20 +27,22 @@
2146 PreviewReply::~PreviewReply() {
2147 }
2148
2149-void PreviewReply::register_layout(std::vector<ColumnLayout*> const& columns) {
2150+void PreviewReply::register_layout(
2151+ std::vector<std::shared_ptr<unity::scopes::ColumnLayout>> const& columns) {
2152 unity::scopes::ColumnLayoutList columns_list;
2153 for (auto const& column : columns)
2154 {
2155- columns_list.emplace_back(column->get_column_layout());
2156+ columns_list.push_back(*column);
2157 }
2158 reply_->register_layout(columns_list);
2159 }
2160
2161-void PreviewReply::push(std::vector<PreviewWidget*> const& widgets) {
2162+void PreviewReply::push(
2163+ std::vector<std::shared_ptr<unity::scopes::PreviewWidget>> const& widgets) {
2164 unity::scopes::PreviewWidgetList widgets_list;
2165 for (auto const& widget : widgets)
2166 {
2167- widgets_list.emplace_back(widget->get_preview_widget());
2168+ widgets_list.push_back(*widget);
2169 }
2170 reply_->push(widgets_list);
2171 }
2172
2173=== modified file 'src/bindings/src/preview-reply.h'
2174--- src/bindings/src/preview-reply.h 2015-09-01 10:31:12 +0000
2175+++ src/bindings/src/preview-reply.h 2015-10-09 07:21:04 +0000
2176@@ -20,7 +20,7 @@
2177 #define _UNITY_JS_PREVIEW_REPLY_H_
2178
2179 #include <unity/scopes/PreviewReply.h>
2180-#include "column-layout.h"
2181+
2182 #include "preview-widget.h"
2183
2184 #include <v8-cpp.h>
2185@@ -32,8 +32,10 @@
2186 ~PreviewReply();
2187
2188 // v8 bindings
2189- void register_layout(std::vector<ColumnLayout*> const& columns);
2190- void push(std::vector<PreviewWidget*> const& widgets);
2191+ void register_layout(
2192+ std::vector<std::shared_ptr<unity::scopes::ColumnLayout>> const& columns);
2193+ void push(
2194+ std::vector<std::shared_ptr<unity::scopes::PreviewWidget>> const& widgets);
2195 void finished();
2196
2197 private:
2198
2199=== modified file 'src/bindings/src/preview-widget.cc'
2200--- src/bindings/src/preview-widget.cc 2015-07-09 18:30:28 +0000
2201+++ src/bindings/src/preview-widget.cc 2015-10-09 07:21:04 +0000
2202@@ -18,13 +18,18 @@
2203
2204 #include "preview-widget.h"
2205
2206+#include <unity/scopes/VariantBuilder.h>
2207+
2208+#include "common.h"
2209+
2210+
2211 PreviewWidget::PreviewWidget(std::string const &id,
2212 std::string const &widget_type)
2213- : preview_widget_(id, widget_type) {
2214+ : unity::scopes::PreviewWidget(id, widget_type) {
2215 }
2216
2217 PreviewWidget::PreviewWidget(std::string const &definition)
2218- : preview_widget_(definition) {
2219+ : unity::scopes::PreviewWidget(definition) {
2220 }
2221
2222 PreviewWidget::~PreviewWidget() {
2223@@ -45,89 +50,40 @@
2224 if (args[1]->IsString()) {
2225 unity::scopes::Variant v(
2226 *v8::String::Utf8Value(args[1]->ToString()));
2227- preview_widget_.add_attribute_value(key, v);
2228+ unity::scopes::PreviewWidget::add_attribute_value(key, v);
2229 } else if (args[1]->IsBoolean()) {
2230 unity::scopes::Variant v(
2231 args[1]->BooleanValue());
2232- preview_widget_.add_attribute_value(key, v);
2233+ unity::scopes::PreviewWidget::add_attribute_value(key, v);
2234 } else if (args[1]->IsInt32()) {
2235 unity::scopes::Variant v(
2236 args[1]->Int32Value());
2237- preview_widget_.add_attribute_value(key, v);
2238+ unity::scopes::PreviewWidget::add_attribute_value(key, v);
2239 } else if (args[1]->IsNumber()) {
2240 unity::scopes::Variant v(
2241 args[1]->NumberValue());
2242- preview_widget_.add_attribute_value(key, v);
2243- }
2244-}
2245-
2246-void PreviewWidget::add_attribute_mapping(
2247- v8::FunctionCallbackInfo<v8::Value> const& args) {
2248- if (args.Length() != 2) {
2249- return;
2250- }
2251- if (!args[0]->IsString() || !args[1]->IsString()) {
2252- return;
2253- }
2254-
2255- std::string key =
2256- *v8::String::Utf8Value(args[0]->ToString());
2257-
2258- std::string field_name =
2259- *v8::String::Utf8Value(args[1]->ToString());
2260-
2261- preview_widget_.add_attribute_mapping(
2262- key, field_name);
2263+ unity::scopes::PreviewWidget::add_attribute_value(key, v);
2264+ } else if (args[1]->IsObject()) {
2265+ unity::scopes::VariantBuilder vb;
2266+
2267+ unity::scopes::Variant v =
2268+ unity::scopesjs::to_variant(args[1]);
2269+
2270+ if (v.which() == unity::scopes::Variant::Dict) {
2271+ unity::scopes::VariantMap vm = v.get_dict();
2272+ std::vector<std::pair<std::string, unity::scopes::Variant>> t;
2273+
2274+ for (auto &c : vm) {
2275+ t.push_back({c.first, c.second});
2276+ }
2277+
2278+ vb.add_tuple(t);
2279+ unity::scopes::PreviewWidget::add_attribute_value(key, vb.end());
2280+ }
2281+ }
2282 }
2283
2284 void PreviewWidget::add_widget(
2285- v8::FunctionCallbackInfo<v8::Value> const& args) {
2286- if (args.Length() != 1) {
2287- return;
2288- }
2289-
2290- PreviewWidget *pw =
2291- v8cpp::from_v8<PreviewWidget*>(args.GetIsolate(), args[0]);
2292- if (!pw) {
2293- return;
2294- }
2295-
2296- preview_widget_.add_widget(pw->get_preview_widget());
2297-}
2298-
2299-const unity::scopes::PreviewWidget&
2300-PreviewWidget::get_preview_widget() const {
2301- return preview_widget_;
2302-}
2303-
2304-v8::Local<v8::Value> PreviewWidget::id(
2305- v8::FunctionCallbackInfo<v8::Value> const& args) {
2306- return v8cpp::to_v8(args.GetIsolate(), preview_widget_.id());
2307-}
2308-
2309-v8::Local<v8::Value> PreviewWidget::widget_type(
2310- v8::FunctionCallbackInfo<v8::Value> const& args) {
2311- return v8cpp::to_v8(args.GetIsolate(), preview_widget_.widget_type());
2312-}
2313-
2314-v8::Local<v8::Value> PreviewWidget::attribute_mappings(
2315- v8::FunctionCallbackInfo<v8::Value> const& args) {
2316- std::map<std::string, std::string> am =
2317- preview_widget_.attribute_mappings();
2318- return v8cpp::to_v8(args.GetIsolate(), am);
2319-}
2320-
2321-v8::Local<v8::Value> PreviewWidget::attribute_values(
2322- v8::FunctionCallbackInfo<v8::Value> const& args) {
2323- return v8cpp::to_v8(args.GetIsolate(), nullptr);
2324-}
2325-
2326-v8::Local<v8::Value> PreviewWidget::widgets(
2327- v8::FunctionCallbackInfo<v8::Value> const& args) {
2328- return v8cpp::to_v8(args.GetIsolate(), nullptr);
2329-}
2330-
2331-v8::Local<v8::Value> PreviewWidget::data(
2332- v8::FunctionCallbackInfo<v8::Value> const& args) {
2333- return v8cpp::to_v8(args.GetIsolate(), preview_widget_.data().c_str());
2334+ std::shared_ptr<unity::scopes::PreviewWidget> preview_widget) {
2335+ unity::scopes::PreviewWidget::add_widget(*preview_widget.get());
2336 }
2337
2338=== modified file 'src/bindings/src/preview-widget.h'
2339--- src/bindings/src/preview-widget.h 2015-06-23 19:47:08 +0000
2340+++ src/bindings/src/preview-widget.h 2015-10-09 07:21:04 +0000
2341@@ -23,7 +23,7 @@
2342
2343 #include <v8-cpp.h>
2344
2345-class PreviewWidget
2346+class PreviewWidget : public unity::scopes::PreviewWidget
2347 {
2348 public:
2349 PreviewWidget(std::string const &id,
2350@@ -33,21 +33,7 @@
2351
2352 // v8 binding
2353 void add_attribute_value(v8::FunctionCallbackInfo<v8::Value> const& args);
2354- void add_attribute_mapping(v8::FunctionCallbackInfo<v8::Value> const& args);
2355- void add_widget(v8::FunctionCallbackInfo<v8::Value> const& args);
2356-
2357- v8::Local<v8::Value> id(v8::FunctionCallbackInfo<v8::Value> const& args);
2358- v8::Local<v8::Value> widget_type(v8::FunctionCallbackInfo<v8::Value> const& args);
2359-
2360- v8::Local<v8::Value> attribute_mappings(v8::FunctionCallbackInfo<v8::Value> const& args);
2361- v8::Local<v8::Value> attribute_values(v8::FunctionCallbackInfo<v8::Value> const& args);
2362- v8::Local<v8::Value> widgets(v8::FunctionCallbackInfo<v8::Value> const& args);
2363- v8::Local<v8::Value> data(v8::FunctionCallbackInfo<v8::Value> const& args);
2364-
2365- const unity::scopes::PreviewWidget& get_preview_widget() const;
2366-
2367- private:
2368- unity::scopes::PreviewWidget preview_widget_;
2369+ void add_widget(std::shared_ptr<unity::scopes::PreviewWidget> preview_widget);
2370 };
2371
2372 #endif // _UNITY_JS_PREVIEW_WIDGET_H_
2373
2374=== modified file 'src/bindings/src/result.cc'
2375--- src/bindings/src/result.cc 2015-06-23 19:47:08 +0000
2376+++ src/bindings/src/result.cc 2015-10-09 07:21:04 +0000
2377@@ -19,61 +19,20 @@
2378 #include "result.h"
2379
2380 Result::Result(unity::scopes::Result const &result)
2381- : result_(result) {
2382-}
2383-
2384-Result::~Result() {
2385-}
2386-
2387-v8::Local<v8::Value> Result::uri(
2388- v8::FunctionCallbackInfo<v8::Value> const& args) {
2389- std::string uri = result_.uri();
2390- return v8cpp::to_v8(args.GetIsolate(), uri.c_str());
2391-}
2392-
2393-void Result::set_uri(v8::FunctionCallbackInfo<v8::Value> const& args) {
2394- if (args.Length() != 1 || !args[0]->IsString()) {
2395- throw std::runtime_error("Invalid arguments");
2396- }
2397- result_.set_uri(*(v8::String::Utf8Value(args[0]->ToString())));
2398-}
2399-
2400-v8::Local<v8::Value> Result::title(v8::FunctionCallbackInfo<v8::Value> const& args) {
2401- std::string title = result_.title();
2402- return v8cpp::to_v8(args.GetIsolate(), title.c_str());
2403-}
2404-
2405-void Result::set_title(v8::FunctionCallbackInfo<v8::Value> const& args) {
2406- if (args.Length() != 1 || !args[0]->IsString()) {
2407- throw std::runtime_error("Invalid arguments");
2408- }
2409- result_.set_title(*(v8::String::Utf8Value(args[0]->ToString())));
2410-}
2411-
2412-v8::Local<v8::Value> Result::art(v8::FunctionCallbackInfo<v8::Value> const& args) {
2413- std::string art = result_.art();
2414- return v8cpp::to_v8(args.GetIsolate(), art.c_str());
2415-}
2416-
2417-void Result::set_art(v8::FunctionCallbackInfo<v8::Value> const& args) {
2418- if (args.Length() != 1 || !args[0]->IsString()) {
2419- throw std::runtime_error("Invalid arguments");
2420- }
2421- result_.set_art(*(v8::String::Utf8Value(args[0]->ToString())));
2422-}
2423-
2424-v8::Local<v8::Value> Result::dnd_uri(v8::FunctionCallbackInfo<v8::Value> const& args) {
2425- std::string dnd_uri = result_.dnd_uri();
2426- return v8cpp::to_v8(args.GetIsolate(), dnd_uri.c_str());
2427-}
2428-
2429-void Result::set_dnd_uri(v8::FunctionCallbackInfo<v8::Value> const& args) {
2430- if (args.Length() != 1 || !args[0]->IsString()) {
2431- throw std::runtime_error("Invalid arguments");
2432- }
2433- result_.set_dnd_uri(*(v8::String::Utf8Value(args[0]->ToString())));
2434-}
2435-
2436-const unity::scopes::Result& Result::get_result() const {
2437- return result_;
2438+ : unity::scopes::Result(result) {
2439+}
2440+
2441+std::shared_ptr<Result>
2442+Result::retrieve_stored_result() const {
2443+ return std::shared_ptr<Result>(
2444+ new Result(unity::scopes::Result::retrieve()));
2445+}
2446+
2447+void Result::store(
2448+ std::shared_ptr<Result> result,
2449+ bool intercept_activation) {
2450+ unity::scopes::Result::store(
2451+ *result,
2452+ intercept_activation
2453+ );
2454 }
2455
2456=== modified file 'src/bindings/src/result.h'
2457--- src/bindings/src/result.h 2015-06-23 19:47:08 +0000
2458+++ src/bindings/src/result.h 2015-10-09 07:21:04 +0000
2459@@ -23,29 +23,41 @@
2460
2461 #include <v8-cpp.h>
2462
2463-class Result
2464+#include "common.h"
2465+
2466+class Result : public unity::scopes::Result
2467 {
2468 public:
2469 Result(unity::scopes::Result const &result);
2470- ~Result();
2471-
2472- // v8 binding
2473- v8::Local<v8::Value> uri(v8::FunctionCallbackInfo<v8::Value> const& args);
2474- void set_uri(v8::FunctionCallbackInfo<v8::Value> const& args);
2475-
2476- v8::Local<v8::Value> title(v8::FunctionCallbackInfo<v8::Value> const& args);
2477- void set_title(v8::FunctionCallbackInfo<v8::Value> const& args);
2478-
2479- v8::Local<v8::Value> art(v8::FunctionCallbackInfo<v8::Value> const& args);
2480- void set_art(v8::FunctionCallbackInfo<v8::Value> const& args);
2481-
2482- v8::Local<v8::Value> dnd_uri(v8::FunctionCallbackInfo<v8::Value> const& args);
2483- void set_dnd_uri(v8::FunctionCallbackInfo<v8::Value> const& args);
2484-
2485- const unity::scopes::Result& get_result() const;
2486-
2487- private:
2488- unity::scopes::Result result_;
2489+
2490+ // v8 bindings
2491+ std::shared_ptr<Result> retrieve_stored_result() const;
2492+ void store(std::shared_ptr<Result> result, bool intercept_activation);
2493+
2494 };
2495
2496+template <typename T>
2497+void set_result_value(T * self,
2498+ v8::FunctionCallbackInfo<v8::Value> const& args) {
2499+ if (args.Length() != 2) {
2500+ throw std::runtime_error("Invalid number of arguments");
2501+ }
2502+
2503+ if (!args[0]->IsString()) {
2504+ throw std::runtime_error("Invalid argument type");
2505+ }
2506+
2507+ std::string key =
2508+ *(v8::String::Utf8Value(args[0]->ToString()));
2509+
2510+ (*static_cast<unity::scopes::Result*>(self))[key] = unity::scopesjs::to_variant(args[1]);
2511+}
2512+
2513+template <typename T>
2514+v8::Handle<v8::Value> get_result_value(const T * self,
2515+ const std::string& key) {
2516+ return unity::scopesjs::from_variant((*static_cast<const unity::scopes::Result*>(self))[key]);
2517+}
2518+
2519+
2520 #endif // _UNITY_JS_RESULT_H_
2521
2522=== modified file 'src/bindings/src/scope-base.cc'
2523--- src/bindings/src/scope-base.cc 2015-08-25 09:40:42 +0000
2524+++ src/bindings/src/scope-base.cc 2015-10-09 07:21:04 +0000
2525@@ -18,12 +18,15 @@
2526
2527 #include "scope-base.h"
2528
2529-#include "canned-query.h"
2530+#include "action-metadata.h"
2531+#include "activation-query.h"
2532+#include "activation-query-proxy.h"
2533 #include "search-query.h"
2534+#include "search-query-proxy.h"
2535 #include "search-metadata.h"
2536 #include "result.h"
2537-#include "action-metadata.h"
2538 #include "preview-query.h"
2539+#include "preview-query-proxy.h"
2540 #include "event_queue.h"
2541
2542 ScopeBase::ScopeBase()
2543@@ -54,9 +57,11 @@
2544 v8::Local<v8::Function> start_callback =
2545 v8cpp::to_local<v8::Function>(isolate_, start_callback_);
2546
2547- v8cpp::call_v8(isolate_,
2548- start_callback,
2549- v8cpp::to_v8(isolate_, scope_id.c_str()));
2550+ v8cpp::call_v8(
2551+ isolate_,
2552+ start_callback,
2553+ v8cpp::to_v8(isolate_, scope_id.c_str())
2554+ );
2555 });
2556 }
2557
2558@@ -70,7 +75,10 @@
2559 v8::Local<v8::Function> stop_callback =
2560 v8cpp::to_local<v8::Function>(isolate_, stop_callback_);
2561
2562- v8cpp::call_v8(isolate_, stop_callback);
2563+ v8cpp::call_v8(
2564+ isolate_,
2565+ stop_callback
2566+ );
2567 });
2568 }
2569
2570@@ -84,7 +92,10 @@
2571 v8::Local<v8::Function> run_callback =
2572 v8cpp::to_local<v8::Function>(isolate_, run_callback_);
2573
2574- v8cpp::call_v8(isolate_, run_callback);
2575+ v8cpp::call_v8(
2576+ isolate_,
2577+ run_callback
2578+ );
2579 });
2580 }
2581
2582@@ -98,23 +109,27 @@
2583 return EventQueue::instance().run<unity::scopes::SearchQueryBase::UPtr>(isolate_, [this, query, metadata]
2584 {
2585 // wrap & fire
2586- CannedQuery *q = new CannedQuery(query);
2587- SearchMetaData *m = new SearchMetaData(metadata);
2588+ std::shared_ptr<unity::scopes::CannedQuery> q(
2589+ new unity::scopes::CannedQuery(std::move(query)));
2590+
2591+ std::shared_ptr<SearchMetaData> m(
2592+ new SearchMetaData(metadata));
2593
2594 v8::Local<v8::Function> search_callback =
2595 v8cpp::to_local<v8::Function>(isolate_, search_callback_);
2596
2597 v8::Handle<v8::Value> result =
2598- v8cpp::call_v8(isolate_,
2599- search_callback,
2600- v8cpp::to_v8(isolate_, q),
2601- v8cpp::to_v8(isolate_, m));
2602-
2603- // TODO watch out release
2604- SearchQuery * sq =
2605- v8cpp::from_v8<SearchQuery*>(isolate_, result);
2606-
2607- return unity::scopes::SearchQueryBase::UPtr(sq);
2608+ v8cpp::call_v8(
2609+ isolate_,
2610+ search_callback,
2611+ v8cpp::to_v8(isolate_, q),
2612+ v8cpp::to_v8(isolate_, m)
2613+ );
2614+
2615+ std::shared_ptr<SearchQuery> sq =
2616+ v8cpp::from_v8<std::shared_ptr<SearchQuery>>(isolate_, result);
2617+
2618+ return unity::scopes::SearchQueryBase::UPtr(new SearchQueryProxy(sq));
2619 });
2620 }
2621
2622@@ -132,9 +147,37 @@
2623 unity::scopes::ActionMetadata const &metadata,
2624 std::string const &widget_id,
2625 std::string const &action_id) {
2626- return EventQueue::instance().run<unity::scopes::ActivationQueryBase::UPtr>(isolate_, [this]
2627- {
2628+ if (perform_action_callback_.IsEmpty()) {
2629 return nullptr;
2630+ }
2631+
2632+ return EventQueue::instance().run<unity::scopes::ActivationQueryBase::UPtr>(
2633+ isolate_,
2634+ [this, result, metadata, widget_id, action_id] {
2635+
2636+ std::shared_ptr<Result> r(new Result(result));
2637+ std::shared_ptr<unity::scopes::ActionMetadata> m(
2638+ new unity::scopes::ActionMetadata(metadata));
2639+
2640+ v8::Local<v8::Function> perform_action_callback =
2641+ v8cpp::to_local<v8::Function>(isolate_, perform_action_callback_);
2642+
2643+ v8::Handle<v8::Value> wrapped_activation_query =
2644+ v8cpp::call_v8(
2645+ isolate_,
2646+ perform_action_callback,
2647+ v8cpp::to_v8(isolate_, r),
2648+ v8cpp::to_v8(isolate_, m),
2649+ widget_id,
2650+ action_id
2651+ );
2652+
2653+ std::shared_ptr<ActivationQuery> aq =
2654+ v8cpp::from_v8<std::shared_ptr<ActivationQuery>>(
2655+ isolate_,
2656+ wrapped_activation_query);
2657+
2658+ return unity::scopes::ActivationQueryBase::UPtr(new ActivationQueryProxy(aq));
2659 });
2660 }
2661
2662@@ -145,26 +188,34 @@
2663 return nullptr;
2664 }
2665
2666- return EventQueue::instance().run<unity::scopes::PreviewQueryBase::UPtr>(isolate_, [this, result, action_metadata]
2667+ return EventQueue::instance().run<unity::scopes::PreviewQueryBase::UPtr>(
2668+ isolate_,
2669+ [this, result, action_metadata]
2670 {
2671 // wrap & fire
2672- Result *r = new Result(result);
2673- ActionMetaData *m = new ActionMetaData(action_metadata);
2674+ std::shared_ptr<Result> r(new Result(result));
2675+
2676+ std::shared_ptr<unity::scopes::ActionMetadata> m(
2677+ new unity::scopes::ActionMetadata(action_metadata));
2678
2679 v8::Local<v8::Function> preview_callback =
2680 v8cpp::to_local<v8::Function>(isolate_, preview_callback_);
2681
2682 v8::Handle<v8::Value> wrapped_preview =
2683- v8cpp::call_v8(isolate_,
2684- preview_callback,
2685- v8cpp::to_v8(isolate_, r),
2686- v8cpp::to_v8(isolate_, m));
2687+ v8cpp::call_v8(
2688+ isolate_,
2689+ preview_callback,
2690+ v8cpp::to_v8(isolate_, r),
2691+ v8cpp::to_v8(isolate_, m)
2692+ );
2693
2694 // TODO watch out release
2695- PreviewQuery * sq =
2696- v8cpp::from_v8<PreviewQuery*>(isolate_, wrapped_preview);
2697+ std::shared_ptr<PreviewQuery> sq =
2698+ v8cpp::from_v8<std::shared_ptr<PreviewQuery>>(
2699+ isolate_,
2700+ wrapped_preview);
2701
2702- return unity::scopes::PreviewQueryBase::UPtr(sq);
2703+ return unity::scopes::PreviewQueryBase::UPtr(new PreviewQueryProxy(sq));
2704 });
2705 }
2706
2707@@ -267,18 +318,3 @@
2708 v8::Local<v8::Function> cb = v8::Handle<v8::Function>::Cast(args[0]);
2709 preview_callback_.Reset(args.GetIsolate(), cb);
2710 }
2711-
2712-v8::Local<v8::Value> ScopeBase::get_scope_directory(
2713- v8::FunctionCallbackInfo<v8::Value> const& args) {
2714- return v8cpp::to_v8(args.GetIsolate(), scope_directory().c_str());
2715-}
2716-
2717-v8::Local<v8::Value> ScopeBase::get_cache_directory(
2718- v8::FunctionCallbackInfo<v8::Value> const& args) {
2719- return v8cpp::to_v8(args.GetIsolate(), cache_directory().c_str());
2720-}
2721-
2722-v8::Local<v8::Value> ScopeBase::get_tmp_directory(
2723- v8::FunctionCallbackInfo<v8::Value> const& args) {
2724- return v8cpp::to_v8(args.GetIsolate(), tmp_directory().c_str());
2725-}
2726
2727=== modified file 'src/bindings/src/scope-base.h'
2728--- src/bindings/src/scope-base.h 2015-07-28 12:15:26 +0000
2729+++ src/bindings/src/scope-base.h 2015-10-09 07:21:04 +0000
2730@@ -36,13 +36,8 @@
2731
2732 void onsearch(v8::FunctionCallbackInfo<v8::Value> const& args);
2733 void onpreview(v8::FunctionCallbackInfo<v8::Value> const& args);
2734-
2735- v8::Local<v8::Value> get_scope_directory(
2736- v8::FunctionCallbackInfo<v8::Value> const& args);
2737- v8::Local<v8::Value> get_cache_directory(
2738- v8::FunctionCallbackInfo<v8::Value> const& args);
2739- v8::Local<v8::Value> get_tmp_directory(
2740- v8::FunctionCallbackInfo<v8::Value> const& args);
2741+ void onactivate(v8::FunctionCallbackInfo<v8::Value> const& args);
2742+ void onperform_action(v8::FunctionCallbackInfo<v8::Value> const& args);
2743
2744 // unity::scopes::ScopeBase implementation
2745 void start(std::string const& scope_id) override;
2746@@ -76,6 +71,8 @@
2747
2748 v8::Persistent<v8::Function> search_callback_;
2749 v8::Persistent<v8::Function> preview_callback_;
2750+ v8::Persistent<v8::Function> activate_callback_;
2751+ v8::Persistent<v8::Function> perform_action_callback_;
2752 };
2753
2754 #endif // _UNITY_JS_SCOPES_BASE_H_
2755
2756=== added file 'src/bindings/src/search-query-proxy.cc'
2757--- src/bindings/src/search-query-proxy.cc 1970-01-01 00:00:00 +0000
2758+++ src/bindings/src/search-query-proxy.cc 2015-10-09 07:21:04 +0000
2759@@ -0,0 +1,52 @@
2760+/*
2761+ * Copyright 2015 Canonical Ltd.
2762+ *
2763+ * This file is part of unity-js-scopes.
2764+ *
2765+ * unity-js-scopes is free software; you can redistribute it and/or modify
2766+ * it under the terms of the GNU General Public License as published by
2767+ * the Free Software Foundation; version 3.
2768+ *
2769+ * unity-js-scopes is distributed in the hope that it will be useful,
2770+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
2771+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2772+ * GNU General Public License for more details.
2773+ *
2774+ * You should have received a copy of the GNU General Public License
2775+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
2776+ */
2777+
2778+#include "search-query-proxy.h"
2779+
2780+#include <unity/scopes/Result.h>
2781+#include <unity/scopes/SearchMetadata.h>
2782+
2783+SearchQueryProxy::SearchQueryProxy(
2784+ std::shared_ptr<unity::scopes::SearchQueryBase> backend)
2785+ : unity::scopes::SearchQueryBase(backend->query(), backend->search_metadata()),
2786+ backend_(backend) {
2787+}
2788+
2789+void SearchQueryProxy::run(unity::scopes::SearchReplyProxy const &reply) {
2790+ backend_->run(reply);
2791+}
2792+
2793+unity::scopes::CannedQuery SearchQueryProxy::query() const {
2794+ return backend_->query();
2795+}
2796+
2797+unity::scopes::SearchMetadata SearchQueryProxy::search_metadata() const {
2798+ return backend_->search_metadata();
2799+}
2800+
2801+void SearchQueryProxy::cancelled() {
2802+ backend_->cancelled();
2803+}
2804+
2805+bool SearchQueryProxy::valid() const {
2806+ return backend_->valid();
2807+}
2808+
2809+unity::scopes::VariantMap SearchQueryProxy::settings() const {
2810+ return backend_->settings();
2811+}
2812
2813=== added file 'src/bindings/src/search-query-proxy.h'
2814--- src/bindings/src/search-query-proxy.h 1970-01-01 00:00:00 +0000
2815+++ src/bindings/src/search-query-proxy.h 2015-10-09 07:21:04 +0000
2816@@ -0,0 +1,48 @@
2817+/*
2818+ * Copyright 2015 Canonical Ltd.
2819+ *
2820+ * This file is part of unity-js-scopes.
2821+ *
2822+ * unity-js-scopes is free software; you can redistribute it and/or modify
2823+ * it under the terms of the GNU General Public License as published by
2824+ * the Free Software Foundation; version 3.
2825+ *
2826+ * unity-js-scopes is distributed in the hope that it will be useful,
2827+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
2828+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2829+ * GNU General Public License for more details.
2830+ *
2831+ * You should have received a copy of the GNU General Public License
2832+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
2833+ */
2834+
2835+#ifndef _UNITY_JS_SEARCH_QUERY_PROXY_H_
2836+#define _UNITY_JS_SEARCH_QUERY_PROXY_H_
2837+
2838+#include <unity/scopes/SearchQueryBase.h>
2839+
2840+#include <v8-cpp.h>
2841+
2842+
2843+class SearchQueryProxy : public unity::scopes::SearchQueryBase
2844+{
2845+ public:
2846+ SearchQueryProxy(
2847+ std::shared_ptr<unity::scopes::SearchQueryBase> backend);
2848+
2849+ void run(unity::scopes::SearchReplyProxy const &reply) override;
2850+ unity::scopes::CannedQuery query() const;
2851+ unity::scopes::SearchMetadata search_metadata() const;
2852+ void cancelled() override;
2853+ bool valid() const;
2854+ unity::scopes::VariantMap settings() const;
2855+
2856+ // TODO handle the subsearch override functions
2857+
2858+ private:
2859+ std::shared_ptr<unity::scopes::SearchQueryBase> backend_;
2860+};
2861+
2862+#endif // _UNITY_JS_SEARCH_QUERY_PROXY_H_
2863+
2864+
2865
2866=== modified file 'src/bindings/src/search-query.cc'
2867--- src/bindings/src/search-query.cc 2015-08-25 09:40:42 +0000
2868+++ src/bindings/src/search-query.cc 2015-10-09 07:21:04 +0000
2869@@ -18,7 +18,6 @@
2870
2871 #include "search-query.h"
2872
2873-#include "canned-query.h"
2874 #include "search-metadata.h"
2875 #include "search-reply.h"
2876 #include "event_queue.h"
2877@@ -83,14 +82,6 @@
2878 cancelled_callback_.Reset(args.GetIsolate(), cb);
2879 }
2880
2881-v8::Local<v8::Value> SearchQuery::query(
2882- v8::FunctionCallbackInfo<v8::Value> const& args) {
2883- CannedQuery *q =
2884- new CannedQuery(unity::scopes::SearchQueryBase::query());
2885-
2886- return v8cpp::to_v8(isolate_, q);
2887-}
2888-
2889 void SearchQuery::run(unity::scopes::SearchReplyProxy const& reply) {
2890 if (run_callback_.IsEmpty()) {
2891 return;
2892@@ -99,14 +90,18 @@
2893 EventQueue::instance().run(isolate_, [this, reply]
2894 {
2895 // wrap & fire
2896- SearchReply *sr = new SearchReply(reply);
2897-
2898- auto wrapped_sr = v8cpp::to_v8(isolate_, sr);
2899+ std::shared_ptr<SearchReply> sr =
2900+ std::shared_ptr<SearchReply>(new SearchReply(reply));
2901
2902 v8::Local<v8::Function> run_callback =
2903- v8cpp::to_local<v8::Function>(isolate_, run_callback_);
2904+ v8cpp::to_local<v8::Function>(isolate_, run_callback_);
2905
2906- v8cpp::call_v8(isolate_, run_callback, wrapped_sr);
2907+ v8cpp::call_v8_with_receiver(
2908+ isolate_,
2909+ v8cpp::to_v8(isolate_, shared_from_this()),
2910+ run_callback,
2911+ v8cpp::to_v8(isolate_, sr)
2912+ );
2913 });
2914 }
2915
2916@@ -120,23 +115,10 @@
2917 v8::Local<v8::Function> cancelled_callback =
2918 v8cpp::to_local<v8::Function>(isolate_, cancelled_callback_);
2919
2920- v8cpp::call_v8(isolate_, cancelled_callback);
2921+ v8cpp::call_v8_with_receiver(
2922+ isolate_,
2923+ v8cpp::to_v8(isolate_, shared_from_this()),
2924+ cancelled_callback
2925+ );
2926 });
2927 }
2928-
2929-v8::Local<v8::Value> SearchQuery::valid(
2930- v8::FunctionCallbackInfo<v8::Value> const& args) {
2931- return v8cpp::to_v8(
2932- args.GetIsolate(),
2933- unity::scopes::SearchQueryBase::valid());
2934-}
2935-
2936-v8::Local<v8::Value> SearchQuery::settings(
2937- v8::FunctionCallbackInfo<v8::Value> const& args) {
2938- return v8cpp::to_v8(args.GetIsolate(), nullptr);
2939-}
2940-
2941-v8::Local<v8::Value> SearchQuery::search_metadata(
2942- v8::FunctionCallbackInfo<v8::Value> const& args) {
2943- return v8cpp::to_v8(args.GetIsolate(), nullptr);
2944-}
2945
2946=== modified file 'src/bindings/src/search-query.h'
2947--- src/bindings/src/search-query.h 2015-07-29 08:31:17 +0000
2948+++ src/bindings/src/search-query.h 2015-10-09 07:21:04 +0000
2949@@ -23,7 +23,8 @@
2950
2951 #include <v8-cpp.h>
2952
2953-class SearchQuery : public unity::scopes::SearchQueryBase
2954+class SearchQuery : public unity::scopes::SearchQueryBase,
2955+ public std::enable_shared_from_this<SearchQuery>
2956 {
2957 public:
2958 SearchQuery(unity::scopes::CannedQuery const& query,
2959@@ -35,11 +36,6 @@
2960 // v8 binding
2961 void onrun(v8::FunctionCallbackInfo<v8::Value> const& args);
2962 void oncancelled(v8::FunctionCallbackInfo<v8::Value> const& args);
2963- v8::Local<v8::Value> query(v8::FunctionCallbackInfo<v8::Value> const& args);
2964-
2965- v8::Local<v8::Value> valid(v8::FunctionCallbackInfo<v8::Value> const& args);
2966- v8::Local<v8::Value> settings(v8::FunctionCallbackInfo<v8::Value> const& args);
2967- v8::Local<v8::Value> search_metadata(v8::FunctionCallbackInfo<v8::Value> const& args);
2968
2969 // unity::scopes::SearchQueryBase implementation
2970 void run(unity::scopes::SearchReplyProxy const& reply) override;
2971
2972=== modified file 'src/bindings/src/search-reply.cc'
2973--- src/bindings/src/search-reply.cc 2015-08-27 11:46:23 +0000
2974+++ src/bindings/src/search-reply.cc 2015-10-09 07:21:04 +0000
2975@@ -22,8 +22,6 @@
2976
2977 #include <unity/scopes/SearchReply.h>
2978
2979-#include "categorised-result.h"
2980-#include "category.h"
2981
2982 SearchReply::SearchReply(unity::scopes::SearchReplyProxy const& reply)
2983 : reply_(reply){
2984@@ -32,51 +30,26 @@
2985 SearchReply::~SearchReply() {
2986 }
2987
2988-v8::Local<v8::Value> SearchReply::register_category(
2989- v8::FunctionCallbackInfo<v8::Value> const& args) {
2990- if (args.Length() != 3) {
2991- // TODO fix
2992- throw std::runtime_error("Invalid number of arguments");
2993- }
2994-
2995- if (!args[0]->IsString()
2996- || !args[1]->IsString()
2997- || !args[2]->IsString()) {
2998- // TODO fix
2999- throw std::runtime_error("Invalid type of arguments");
3000- }
3001-
3002- std::string id;
3003- std::string title;
3004- std::string icon;
3005-
3006- id = *(v8::String::Utf8Value(args[0]->ToString()));
3007- title = *(v8::String::Utf8Value(args[1]->ToString()));
3008- icon = *(v8::String::Utf8Value(args[2]->ToString()));
3009-
3010- Category *category = new Category(reply_->register_category(id, title, icon));
3011-
3012- v8::Isolate *isolate = args.GetIsolate();
3013-
3014- return v8cpp::to_v8(isolate, category);
3015+unity::scopes::Category::SCPtr SearchReply::lookup_category(
3016+ const std::string& id) {
3017+ return reply_->lookup_category(id);
3018 }
3019
3020 void SearchReply::push(
3021- v8::FunctionCallbackInfo<v8::Value> const& args) {
3022- if (args.Length() != 1) {
3023- // TODO fix
3024- throw std::runtime_error("Invalid number of arguments");
3025- }
3026-
3027- CategorisedResult *r =
3028- v8cpp::from_v8<CategorisedResult*>(
3029- v8::Isolate::GetCurrent(),
3030- args[0]->ToObject());
3031- if (!r) {
3032- throw std::runtime_error("Invalid argument type");
3033- }
3034-
3035- reply_->push(static_cast<const unity::scopes::CategorisedResult &>(*r));
3036+ std::shared_ptr<unity::scopes::CategorisedResult> categorised_result) {
3037+ reply_->push(*categorised_result);
3038+}
3039+
3040+unity::scopes::Category::SCPtr SearchReply::register_category(
3041+ const std::string& id,
3042+ const std::string& title,
3043+ const std::string& icon,
3044+ std::shared_ptr<unity::scopes::CategoryRenderer> category_renderer) {
3045+ return reply_->register_category(
3046+ id,
3047+ title,
3048+ icon,
3049+ category_renderer ? *category_renderer : unity::scopes::CategoryRenderer());
3050 }
3051
3052 void SearchReply::finished()
3053
3054=== modified file 'src/bindings/src/search-reply.h'
3055--- src/bindings/src/search-reply.h 2015-08-27 11:46:23 +0000
3056+++ src/bindings/src/search-reply.h 2015-10-09 07:21:04 +0000
3057@@ -20,17 +20,29 @@
3058 #define _UNITY_JS_SEARCH_REPLY_H_
3059
3060 #include <unity/scopes/SearchReplyProxyFwd.h>
3061+#include <unity/scopes/Category.h>
3062+#include <unity/scopes/CategorisedResult.h>
3063
3064 #include <v8-cpp.h>
3065
3066+
3067 class SearchReply
3068 {
3069 public:
3070 SearchReply(unity::scopes::SearchReplyProxy const& reply);
3071 ~SearchReply();
3072
3073- v8::Local<v8::Value> register_category(v8::FunctionCallbackInfo<v8::Value> const& args);
3074- void push(v8::FunctionCallbackInfo<v8::Value> const& args);
3075+ unity::scopes::Category::SCPtr register_category(
3076+ const std::string& id,
3077+ const std::string& title,
3078+ const std::string& icon,
3079+ std::shared_ptr<unity::scopes::CategoryRenderer> category_renderer);
3080+
3081+ unity::scopes::Category::SCPtr
3082+ lookup_category(const std::string& id);
3083+
3084+ void push(std::shared_ptr<unity::scopes::CategorisedResult> categorised_result);
3085+
3086 void finished();
3087
3088 private:
3089
3090=== modified file 'src/launcher/config.h.in'
3091--- src/launcher/config.h.in 2015-09-30 06:40:08 +0000
3092+++ src/launcher/config.h.in 2015-10-09 07:21:04 +0000
3093@@ -3,11 +3,11 @@
3094 *
3095 * This file is part of unity-js-scopes.
3096 *
3097- * webbrowser-app is free software; you can redistribute it and/or modify
3098+ * unity-js-scopes is free software; you can redistribute it and/or modify
3099 * it under the terms of the GNU General Public License as published by
3100 * the Free Software Foundation; version 3.
3101 *
3102- * webbrowser-app is distributed in the hope that it will be useful,
3103+ * unity-js-scopes is distributed in the hope that it will be useful,
3104 * but WITHOUT ANY WARRANTY; without even the implied warranty of
3105 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3106 * GNU General Public License for more details.
3107
3108=== modified file 'src/tool/config.h.in'
3109--- src/tool/config.h.in 2015-09-30 06:40:08 +0000
3110+++ src/tool/config.h.in 2015-10-09 07:21:04 +0000
3111@@ -3,11 +3,11 @@
3112 *
3113 * This file is part of unity-js-scopes.
3114 *
3115- * webbrowser-app is free software; you can redistribute it and/or modify
3116+ * unity-js-scopes is free software; you can redistribute it and/or modify
3117 * it under the terms of the GNU General Public License as published by
3118 * the Free Software Foundation; version 3.
3119 *
3120- * webbrowser-app is distributed in the hope that it will be useful,
3121+ * unity-js-scopes is distributed in the hope that it will be useful,
3122 * but WITHOUT ANY WARRANTY; without even the implied warranty of
3123 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3124 * GNU General Public License for more details.
3125
3126=== modified file 'src/tool/main.cc'
3127--- src/tool/main.cc 2015-10-05 05:39:27 +0000
3128+++ src/tool/main.cc 2015-10-09 07:21:04 +0000
3129@@ -219,26 +219,28 @@
3130
3131 if (should_build)
3132 {
3133+ std::vector<std::string> environment_updates;
3134+
3135 std::cout << "Setting target arch to '" << current_arch << "' ..." << std::endl;
3136 if (current_arch == "armhf")
3137 {
3138 if (boost::filesystem::exists("/usr/bin/arm-linux-gnueabihf-gcc-5"))
3139 {
3140 std::cout << "Setting armhf compiler to 'GCC 5' ..." << std::endl;
3141- putenv("CC=arm-linux-gnueabihf-gcc-5");
3142- putenv("CXX=arm-linux-gnueabihf-g++-5");
3143- putenv("LINK=arm-linux-gnueabihf-g++-5");
3144- putenv("AR=arm-linux-gnueabihf-ar");
3145- putenv("npm_config_arch=arm");
3146+ environment_updates.push_back("CC=arm-linux-gnueabihf-gcc-5");
3147+ environment_updates.push_back("CXX=arm-linux-gnueabihf-g++-5");
3148+ environment_updates.push_back("LINK=arm-linux-gnueabihf-g++-5");
3149+ environment_updates.push_back("AR=arm-linux-gnueabihf-ar");
3150+ environment_updates.push_back("npm_config_arch=arm");
3151 }
3152 else if (boost::filesystem::exists("/usr/bin/arm-linux-gnueabihf-gcc-4.9"))
3153 {
3154 std::cout << "Setting armhf compiler to 'GCC 4.9' ..." << std::endl;
3155- putenv("CC=arm-linux-gnueabihf-gcc-4.9");
3156- putenv("CXX=arm-linux-gnueabihf-g++-4.9");
3157- putenv("LINK=arm-linux-gnueabihf-g++-4.9");
3158- putenv("AR=arm-linux-gnueabihf-ar");
3159- putenv("npm_config_arch=arm");
3160+ environment_updates.push_back("CC=arm-linux-gnueabihf-gcc-4.9");
3161+ environment_updates.push_back("CXX=arm-linux-gnueabihf-g++-4.9");
3162+ environment_updates.push_back("LINK=arm-linux-gnueabihf-g++-4.9");
3163+ environment_updates.push_back("AR=arm-linux-gnueabihf-ar");
3164+ environment_updates.push_back("npm_config_arch=arm");
3165 }
3166 else
3167 {
3168@@ -246,6 +248,10 @@
3169 }
3170 }
3171
3172+ for (auto e: environment_updates) {
3173+ putenv(const_cast<char*>(e.c_str()));
3174+ }
3175+
3176 // Reinstall the unity-js-scopes module for new target arch
3177 install_unity_js_scopes(modules_dir);
3178

Subscribers

People subscribed via source and target branches

to all changes: