Merge lp:~marcustomlinson/qtcreator-plugin-ubuntu/js-scope-template into lp:qtcreator-plugin-ubuntu
- js-scope-template
- Merge into trunk
Status: | Work in progress |
---|---|
Proposed branch: | lp:~marcustomlinson/qtcreator-plugin-ubuntu/js-scope-template |
Merge into: | lp:qtcreator-plugin-ubuntu |
Diff against target: |
583 lines (+509/-0) 12 files modified
debian/control (+3/-0) share/qtcreator/templates/wizards/ubuntu/scope-js/.bzrignore (+5/-0) share/qtcreator/templates/wizards/ubuntu/scope-js/CMakeLists.txt (+57/-0) share/qtcreator/templates/wizards/ubuntu/scope-js/displayName.apparmor (+6/-0) share/qtcreator/templates/wizards/ubuntu/scope-js/manifest.json.in (+15/-0) share/qtcreator/templates/wizards/ubuntu/scope-js/po/CMakeLists.txt (+14/-0) share/qtcreator/templates/wizards/ubuntu/scope-js/po/POTFILES.in.in (+3/-0) share/qtcreator/templates/wizards/ubuntu/scope-js/src/CMakeLists.txt (+56/-0) share/qtcreator/templates/wizards/ubuntu/scope-js/src/data/displayName-settings.ini.in (+21/-0) share/qtcreator/templates/wizards/ubuntu/scope-js/src/data/displayName.ini.in (+9/-0) share/qtcreator/templates/wizards/ubuntu/scope-js/src/displayName.js (+224/-0) share/qtcreator/templates/wizards/ubuntu/scope-js/wizard.xml (+96/-0) |
To merge this branch: | bzr merge lp:~marcustomlinson/qtcreator-plugin-ubuntu/js-scope-template |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Ubuntu SDK team | Pending | ||
Review via email: mp+271480@code.launchpad.net |
Commit message
Added JavaScript scope templates
Description of the change
- 417. By Marcus Tomlinson
-
The POTFILES.in.in should actaully be committed to bzr
- 418. By Marcus Tomlinson
-
Add unity-js-
scopes- bindings and unity-js- scopes- launcher to control - 419. By Marcus Tomlinson
-
Reverted changes to regular scope template
- 420. By Marcus Tomlinson
-
Updated rebuild_modules custom target to build npm modules for target arch
- 421. By Marcus Tomlinson
-
Add unity-js-
scopes- tool to debian/control - 422. By Marcus Tomlinson
-
Make installation of unity-js-scopes explicit in top CMakeLists.txt
- 423. By Marcus Tomlinson
-
Call build on node_modules as to not redundantly rebuild on every run in sdk
- 424. By Marcus Tomlinson
-
Shorted CLICK_ARCH CMake variable to ARCH
- 425. By Marcus Tomlinson
-
Install the source directory node_modules not the build directory one
- 426. By Marcus Tomlinson
-
Don't copy node_modules to build dir for local execution, make a symlink instead
- 427. By Marcus Tomlinson
-
Update template to use OpenWeatherMap
- 428. By Marcus Tomlinson
-
Added xml and empty code paths
- 429. By Marcus Tomlinson
-
Fixed xml template
- 430. By Marcus Tomlinson
-
Revert control file changes
- 431. By Marcus Tomlinson
-
Don't pass arch to unity-js-
scopes- tool build - 432. By Marcus Tomlinson
-
Update template to use new style contructors
- 433. By Marcus Tomlinson
-
OOPS!
- 434. By Marcus Tomlinson
-
Added unity-js-scopes deps
Unmerged revisions
- 434. By Marcus Tomlinson
-
Added unity-js-scopes deps
- 433. By Marcus Tomlinson
-
OOPS!
- 432. By Marcus Tomlinson
-
Update template to use new style contructors
- 431. By Marcus Tomlinson
-
Don't pass arch to unity-js-
scopes- tool build - 430. By Marcus Tomlinson
-
Revert control file changes
- 429. By Marcus Tomlinson
-
Fixed xml template
- 428. By Marcus Tomlinson
-
Added xml and empty code paths
- 427. By Marcus Tomlinson
-
Update template to use OpenWeatherMap
- 426. By Marcus Tomlinson
-
Don't copy node_modules to build dir for local execution, make a symlink instead
- 425. By Marcus Tomlinson
-
Install the source directory node_modules not the build directory one
Preview Diff
1 | === modified file 'debian/control' |
2 | --- debian/control 2015-08-17 10:29:20 +0000 |
3 | +++ debian/control 2015-10-21 14:17:53 +0000 |
4 | @@ -41,6 +41,9 @@ |
5 | python3-scope-harness [i386 amd64 armhf], |
6 | unity-scope-tool [i386 amd64 armhf], |
7 | cmake-extras, |
8 | + unity-js-scopes-bindings, |
9 | + unity-js-scopes-launcher, |
10 | + unity-js-scopes-tool, |
11 | # up until this |
12 | gdb-multiarch, |
13 | click-reviewers-tools, |
14 | |
15 | === added directory 'share/qtcreator/templates/wizards/ubuntu/scope-js' |
16 | === added file 'share/qtcreator/templates/wizards/ubuntu/scope-js/.bzrignore' |
17 | --- share/qtcreator/templates/wizards/ubuntu/scope-js/.bzrignore 1970-01-01 00:00:00 +0000 |
18 | +++ share/qtcreator/templates/wizards/ubuntu/scope-js/.bzrignore 2015-10-21 14:17:53 +0000 |
19 | @@ -0,0 +1,5 @@ |
20 | +./CMakeLists.txt.user |
21 | +./po/Makefile.in.in |
22 | +./po/POTFILES.in |
23 | +./src/etc |
24 | +./src/node_modules |
25 | |
26 | === added file 'share/qtcreator/templates/wizards/ubuntu/scope-js/CMakeLists.txt' |
27 | --- share/qtcreator/templates/wizards/ubuntu/scope-js/CMakeLists.txt 1970-01-01 00:00:00 +0000 |
28 | +++ share/qtcreator/templates/wizards/ubuntu/scope-js/CMakeLists.txt 2015-10-21 14:17:53 +0000 |
29 | @@ -0,0 +1,57 @@ |
30 | +project(%ProjectName:l%) |
31 | +cmake_minimum_required(VERSION 2.8.10) |
32 | + |
33 | +# This is required to ensure the correct node modules are included in the project |
34 | +execute_process(COMMAND unity-js-scopes-tool install ${CMAKE_SOURCE_DIR}/src/node_modules unity-js-scopes) |
35 | +@if "%ContentType%" == "http+xml" |
36 | +execute_process(COMMAND unity-js-scopes-tool install ${CMAKE_SOURCE_DIR}/src/node_modules pixl-xml) |
37 | +@endif |
38 | +add_custom_target(build_modules ALL COMMAND unity-js-scopes-tool build ${CMAKE_SOURCE_DIR}/src/node_modules) |
39 | + |
40 | +# Do not remove this, its required for the correct functionality of the Ubuntu-SDK |
41 | +set(UBUNTU_MANIFEST_PATH "manifest.json.in" CACHE INTERNAL "Tells QtCreator location and name of the manifest file") |
42 | +set(UBUNTU_PROJECT_TYPE "Scope" CACHE INTERNAL "Tells QtCreator this is a Scope project") |
43 | + |
44 | +# Important project paths |
45 | +set(CMAKE_INSTALL_PREFIX /) |
46 | +set(SCOPE_INSTALL_DIR "/%ClickHookName:l%") |
47 | +set(GETTEXT_PACKAGE "%ProjectName:l%") |
48 | +set(PACKAGE_NAME "%ProjectName:l%.%ClickDomain:l%") |
49 | +set(SCOPE_NAME "${PACKAGE_NAME}_%ClickHookName:l%") |
50 | + |
51 | +# This command figures out the target architecture and puts it into the manifest file |
52 | +execute_process( |
53 | + COMMAND dpkg-architecture -qDEB_HOST_ARCH |
54 | + OUTPUT_VARIABLE CLICK_ARCH |
55 | + OUTPUT_STRIP_TRAILING_WHITESPACE |
56 | +) |
57 | + |
58 | +# Install the manifest and apparmor files |
59 | +configure_file(manifest.json.in ${CMAKE_CURRENT_BINARY_DIR}/manifest.json) |
60 | +install(FILES ${CMAKE_CURRENT_BINARY_DIR}/manifest.json DESTINATION "/") |
61 | +install(FILES "%ClickHookName:l%.apparmor" DESTINATION "/") |
62 | + |
63 | +# Make these files show up in QtCreator |
64 | +file(GLOB_RECURSE |
65 | + _PO_JS_FILES |
66 | + "po/*.po" |
67 | + "*.js" |
68 | +) |
69 | +add_custom_target(hidden_files |
70 | + ALL |
71 | + SOURCES |
72 | + manifest.json.in |
73 | + %ClickHookName:l%.apparmor |
74 | + src/data/%ClickHookName:l%.ini.in |
75 | + src/data/%ClickHookName:l%-settings.ini.in |
76 | + po/POTFILES.in.in |
77 | + po/${GETTEXT_PACKAGE}.pot |
78 | + ${_PO_JS_FILES} |
79 | +) |
80 | + |
81 | +# Search for our dependencies |
82 | +find_package(Intltool) |
83 | + |
84 | +# Add our main directories |
85 | +add_subdirectory(po) |
86 | +add_subdirectory(src) |
87 | |
88 | === added file 'share/qtcreator/templates/wizards/ubuntu/scope-js/displayName.apparmor' |
89 | --- share/qtcreator/templates/wizards/ubuntu/scope-js/displayName.apparmor 1970-01-01 00:00:00 +0000 |
90 | +++ share/qtcreator/templates/wizards/ubuntu/scope-js/displayName.apparmor 2015-10-21 14:17:53 +0000 |
91 | @@ -0,0 +1,6 @@ |
92 | +{ |
93 | + "template": "%ConfinementType%", |
94 | + "policy_groups": [], |
95 | + "policy_version": %ClickAAPolicyVersion% |
96 | +} |
97 | + |
98 | |
99 | === added file 'share/qtcreator/templates/wizards/ubuntu/scope-js/manifest.json.in' |
100 | --- share/qtcreator/templates/wizards/ubuntu/scope-js/manifest.json.in 1970-01-01 00:00:00 +0000 |
101 | +++ share/qtcreator/templates/wizards/ubuntu/scope-js/manifest.json.in 2015-10-21 14:17:53 +0000 |
102 | @@ -0,0 +1,15 @@ |
103 | +{ |
104 | + "description": "A simple Unity scope written in JavaScript", |
105 | + "maintainer": "%ClickMaintainer%", |
106 | + "architecture": "@CLICK_ARCH@", |
107 | + "name": "%ProjectName:l%.%ClickDomain:l%", |
108 | + "title": "%ProjectName:l%", |
109 | + "framework" : "%ClickFrameworkVersion%", |
110 | + "hooks": { |
111 | + "%ClickHookName:l%": { |
112 | + "scope": "%ClickHookName:l%", |
113 | + "apparmor": "%ClickHookName:l%.apparmor" |
114 | + } |
115 | + } |
116 | +} |
117 | + |
118 | |
119 | === added directory 'share/qtcreator/templates/wizards/ubuntu/scope-js/po' |
120 | === added file 'share/qtcreator/templates/wizards/ubuntu/scope-js/po/CMakeLists.txt' |
121 | --- share/qtcreator/templates/wizards/ubuntu/scope-js/po/CMakeLists.txt 1970-01-01 00:00:00 +0000 |
122 | +++ share/qtcreator/templates/wizards/ubuntu/scope-js/po/CMakeLists.txt 2015-10-21 14:17:53 +0000 |
123 | @@ -0,0 +1,14 @@ |
124 | +intltool_update_potfile( |
125 | + ALL |
126 | + KEYWORDS "tr" "tr:1,2" "dtr:2" "dtr:2,3" "N_" |
127 | + COPYRIGHT_HOLDER "" |
128 | + POTFILES_TEMPLATE "POTFILES.in.in" |
129 | + GETTEXT_PACKAGE ${GETTEXT_PACKAGE} |
130 | +) |
131 | + |
132 | +intltool_install_translations( |
133 | + ALL |
134 | + GETTEXT_PACKAGE ${GETTEXT_PACKAGE} |
135 | +) |
136 | + |
137 | + |
138 | |
139 | === added file 'share/qtcreator/templates/wizards/ubuntu/scope-js/po/POTFILES.in.in' |
140 | --- share/qtcreator/templates/wizards/ubuntu/scope-js/po/POTFILES.in.in 1970-01-01 00:00:00 +0000 |
141 | +++ share/qtcreator/templates/wizards/ubuntu/scope-js/po/POTFILES.in.in 2015-10-21 14:17:53 +0000 |
142 | @@ -0,0 +1,3 @@ |
143 | +[type: gettext/ini] src/data/%ClickHookName:l%.ini.in |
144 | +[type: gettext/ini] src/data/%ClickHookName:l%-settings.ini.in |
145 | +@GENERATED_POTFILES@ |
146 | |
147 | === added file 'share/qtcreator/templates/wizards/ubuntu/scope-js/po/displayName.pot' |
148 | === added directory 'share/qtcreator/templates/wizards/ubuntu/scope-js/src' |
149 | === added file 'share/qtcreator/templates/wizards/ubuntu/scope-js/src/CMakeLists.txt' |
150 | --- share/qtcreator/templates/wizards/ubuntu/scope-js/src/CMakeLists.txt 1970-01-01 00:00:00 +0000 |
151 | +++ share/qtcreator/templates/wizards/ubuntu/scope-js/src/CMakeLists.txt 2015-10-21 14:17:53 +0000 |
152 | @@ -0,0 +1,56 @@ |
153 | +# Put the ini, image, and js files in the build directory next |
154 | +# to the scope .so file so test tools can find them easily. |
155 | +intltool_merge_translations( |
156 | + "data/%ClickHookName:l%.ini.in" |
157 | + "${CMAKE_CURRENT_BINARY_DIR}/${SCOPE_NAME}.ini" |
158 | + ALL UTF8 |
159 | +) |
160 | +intltool_merge_translations( |
161 | + "data/%ClickHookName:l%-settings.ini.in" |
162 | + "${CMAKE_CURRENT_BINARY_DIR}/${SCOPE_NAME}-settings.ini" |
163 | + ALL UTF8 |
164 | +) |
165 | + |
166 | +configure_file( |
167 | + "data/icon.png" |
168 | + "${CMAKE_CURRENT_BINARY_DIR}/icon.png" |
169 | + @ONLY COPYONLY |
170 | +) |
171 | +configure_file( |
172 | + "data/logo.png" |
173 | + "${CMAKE_CURRENT_BINARY_DIR}/logo.png" |
174 | + @ONLY COPYONLY |
175 | +) |
176 | + |
177 | +configure_file( |
178 | + "%ClickHookName:l%.js" |
179 | + "${CMAKE_CURRENT_BINARY_DIR}/${SCOPE_NAME}.js" |
180 | + @ONLY COPYONLY |
181 | +) |
182 | + |
183 | +add_custom_target( |
184 | + copy_modules ALL |
185 | + COMMAND ${CMAKE_COMMAND} -E create_symlink |
186 | + "${CMAKE_CURRENT_SOURCE_DIR}/node_modules" |
187 | + "${CMAKE_CURRENT_BINARY_DIR}/node_modules" |
188 | +) |
189 | + |
190 | +# Install the scope ini, image, and js files |
191 | +install( |
192 | + FILES |
193 | + "${CMAKE_CURRENT_BINARY_DIR}/${SCOPE_NAME}.ini" |
194 | + "${CMAKE_CURRENT_BINARY_DIR}/${SCOPE_NAME}-settings.ini" |
195 | + "${CMAKE_CURRENT_BINARY_DIR}/icon.png" |
196 | + "${CMAKE_CURRENT_BINARY_DIR}/logo.png" |
197 | + "${CMAKE_CURRENT_BINARY_DIR}/${SCOPE_NAME}.js" |
198 | + DESTINATION |
199 | + ${SCOPE_INSTALL_DIR} |
200 | +) |
201 | + |
202 | +install( |
203 | + DIRECTORY |
204 | + "${CMAKE_CURRENT_SOURCE_DIR}/node_modules" |
205 | + DESTINATION |
206 | + ${SCOPE_INSTALL_DIR} |
207 | + USE_SOURCE_PERMISSIONS |
208 | +) |
209 | |
210 | === added directory 'share/qtcreator/templates/wizards/ubuntu/scope-js/src/data' |
211 | === added file 'share/qtcreator/templates/wizards/ubuntu/scope-js/src/data/displayName-settings.ini.in' |
212 | --- share/qtcreator/templates/wizards/ubuntu/scope-js/src/data/displayName-settings.ini.in 1970-01-01 00:00:00 +0000 |
213 | +++ share/qtcreator/templates/wizards/ubuntu/scope-js/src/data/displayName-settings.ini.in 2015-10-21 14:17:53 +0000 |
214 | @@ -0,0 +1,21 @@ |
215 | +@if "%ContentType%" != "empty" |
216 | +# Below are some example settings. You can access your scope's |
217 | +# settings by calling settings() from the Query::run() method. |
218 | +# E.g. auto location = settings().at("location").get_string(); |
219 | + |
220 | +#[location] |
221 | +#type = string |
222 | +#defaultValue = London,uk |
223 | +#_displayName = Default Location |
224 | + |
225 | +#[units] |
226 | +#type = list |
227 | +#_displayName = Temperature Units |
228 | +#_displayValues = Metric;Imperial |
229 | +#defaultValue = 0 |
230 | + |
231 | +#[forecast] |
232 | +#type = boolean |
233 | +#defaultValue = true |
234 | +#_displayName = Show Forecast |
235 | +@endif |
236 | |
237 | === added file 'share/qtcreator/templates/wizards/ubuntu/scope-js/src/data/displayName.ini.in' |
238 | --- share/qtcreator/templates/wizards/ubuntu/scope-js/src/data/displayName.ini.in 1970-01-01 00:00:00 +0000 |
239 | +++ share/qtcreator/templates/wizards/ubuntu/scope-js/src/data/displayName.ini.in 2015-10-21 14:17:53 +0000 |
240 | @@ -0,0 +1,9 @@ |
241 | +[ScopeConfig] |
242 | +ScopeRunner=./node_modules/unity-js-scopes/bin/unity-js-scopes-launcher %S %R |
243 | +_DisplayName=%ProjectName:c% Scope |
244 | +_Description=This is a %ProjectName:c% scope |
245 | +Author = Firstname Lastname |
246 | +Icon = icon.png |
247 | + |
248 | +[Appearance] |
249 | +PageHeader.Logo = logo.png |
250 | |
251 | === added file 'share/qtcreator/templates/wizards/ubuntu/scope-js/src/data/icon.png' |
252 | Binary files share/qtcreator/templates/wizards/ubuntu/scope-js/src/data/icon.png 1970-01-01 00:00:00 +0000 and share/qtcreator/templates/wizards/ubuntu/scope-js/src/data/icon.png 2015-10-21 14:17:53 +0000 differ |
253 | === added file 'share/qtcreator/templates/wizards/ubuntu/scope-js/src/data/logo.png' |
254 | Binary files share/qtcreator/templates/wizards/ubuntu/scope-js/src/data/logo.png 1970-01-01 00:00:00 +0000 and share/qtcreator/templates/wizards/ubuntu/scope-js/src/data/logo.png 2015-10-21 14:17:53 +0000 differ |
255 | === added file 'share/qtcreator/templates/wizards/ubuntu/scope-js/src/displayName.js' |
256 | --- share/qtcreator/templates/wizards/ubuntu/scope-js/src/displayName.js 1970-01-01 00:00:00 +0000 |
257 | +++ share/qtcreator/templates/wizards/ubuntu/scope-js/src/displayName.js 2015-10-21 14:17:53 +0000 |
258 | @@ -0,0 +1,224 @@ |
259 | +var scopes = require('unity-js-scopes') |
260 | +@if "%ContentType%" != "empty" |
261 | +var http = require('http'); |
262 | +@if "%ContentType%" == "http+xml" |
263 | +var XML = require('pixl-xml'); |
264 | +@endif |
265 | + |
266 | +var query_host = "api.openweathermap.org" |
267 | +@if "%ContentType%" == "http+xml" |
268 | +var current_weather_path = "/data/2.5/weather?units=metric&APPID=2b12bf09b4e0ab0c1aa5e32a9a3f0cdc&mode=xml&q=" |
269 | +var forecast_weather_path = "/data/2.5/forecast/daily/?units=metric&cnt=7&APPID=2b12bf09b4e0ab0c1aa5e32a9a3f0cdc&mode=xml&q=" |
270 | +@elsif "%ContentType%" == "http+json" |
271 | +var current_weather_path = "/data/2.5/weather?units=metric&APPID=2b12bf09b4e0ab0c1aa5e32a9a3f0cdc&q=" |
272 | +var forecast_weather_path = "/data/2.5/forecast/daily/?units=metric&cnt=7&APPID=2b12bf09b4e0ab0c1aa5e32a9a3f0cdc&q=" |
273 | +@endif |
274 | + |
275 | +var CURRENT_TEMPLATE = |
276 | +{ |
277 | + "schema-version": 1, |
278 | + "template": { |
279 | + "category-layout": "grid", |
280 | + "card-size": "medium" |
281 | + }, |
282 | + "components": { |
283 | + "title": "title", |
284 | + "art": { |
285 | + "field": "art" |
286 | + }, |
287 | + "subtitle": "subtitle" |
288 | + } |
289 | +} |
290 | + |
291 | +var FORECAST_TEMPLATE = |
292 | +{ |
293 | + "schema-version": 1, |
294 | + "template": { |
295 | + "category-layout": "grid", |
296 | + "card-layout": "horizontal", |
297 | + "card-size": "small" |
298 | + }, |
299 | + "components": { |
300 | + "title": "title", |
301 | + "art" : { |
302 | + "field": "art" |
303 | + }, |
304 | + "subtitle": "subtitle" |
305 | + } |
306 | +} |
307 | +@endif |
308 | + |
309 | +scopes.self.initialize( |
310 | + {} |
311 | + , |
312 | + { |
313 | + run: function() { |
314 | + console.log('Running...') |
315 | + }, |
316 | + start: function(scope_id) { |
317 | + console.log('Starting scope id: ' |
318 | + + scope_id |
319 | + + ', ' |
320 | + + scopes.self.scope_config) |
321 | + }, |
322 | + search: function(canned_query, metadata) { |
323 | + return new scopes.lib.search_query( |
324 | + canned_query, |
325 | + metadata, |
326 | + // run |
327 | + function(search_reply) { |
328 | +@if "%ContentType%" != "empty" |
329 | + var qs = canned_query.query_string(); |
330 | + if (!qs) { |
331 | + qs = "London,uk" |
332 | + } |
333 | + |
334 | + var current_weather_cb = function(response) { |
335 | + var res = ''; |
336 | + |
337 | + // Another chunk of data has been recieved, so append it to res |
338 | + response.on('data', function(chunk) { |
339 | + res += chunk; |
340 | + }); |
341 | + |
342 | + // The whole response has been recieved |
343 | + response.on('end', function() { |
344 | +@if "%ContentType%" == "http+xml" |
345 | + r = XML.parse(res); |
346 | + |
347 | + var category_renderer = new scopes.lib.category_renderer(JSON.stringify(CURRENT_TEMPLATE)); |
348 | + var category = search_reply.register_category("current", r.city.name + ", " + r.city.country, "", category_renderer); |
349 | + |
350 | + var categorised_result = new scopes.lib.categorised_result(category); |
351 | + categorised_result.set_uri(r.city.id.toString()); |
352 | + categorised_result.set_title(r.temperature.value.toString() + "°C"); |
353 | + categorised_result.set_art("http://openweathermap.org/img/w/" + r.weather.icon + ".png"); |
354 | + categorised_result.set("subtitle", r.weather.value); |
355 | + categorised_result.set("description", "A description of the result"); |
356 | +@elsif "%ContentType%" == "http+json" |
357 | + r = JSON.parse(res); |
358 | + |
359 | + var category_renderer = new scopes.lib.category_renderer(JSON.stringify(CURRENT_TEMPLATE)); |
360 | + var category = search_reply.register_category("current", r.name + ", " + r.sys.country, "", category_renderer); |
361 | + |
362 | + var categorised_result = new scopes.lib.categorised_result(category); |
363 | + categorised_result.set_uri(r.id.toString()); |
364 | + categorised_result.set_title(r.main.temp.toString() + "°C"); |
365 | + categorised_result.set_art("http://openweathermap.org/img/w/" + r.weather[0].icon + ".png"); |
366 | + categorised_result.set("subtitle", r.weather[0].description); |
367 | + categorised_result.set("description", "A description of the result"); |
368 | +@endif |
369 | + |
370 | + search_reply.push(categorised_result); |
371 | + |
372 | + // Now call back into the API for a 7 day forecast |
373 | + http.request({host: query_host, path: forecast_weather_path + qs}, forecase_weather_cb).end(); |
374 | + }); |
375 | + } |
376 | + |
377 | + var forecase_weather_cb = function(response) { |
378 | + var res = ''; |
379 | + |
380 | + // Another chunk of data has been recieved, so append it to res |
381 | + response.on('data', function(chunk) { |
382 | + res += chunk; |
383 | + }); |
384 | + |
385 | + // The whole response has been recieved |
386 | + response.on('end', function() { |
387 | + try { |
388 | +@if "%ContentType%" == "http+xml" |
389 | + r = XML.parse(res); |
390 | + |
391 | + var category_renderer = new scopes.lib.category_renderer(JSON.stringify(FORECAST_TEMPLATE)); |
392 | + var category = search_reply.register_category("forecast", "7 day forecast", "", category_renderer); |
393 | + |
394 | + var weather_id = 1000000; |
395 | + for (i = 0; i < r.forecast.time.length; i++) { |
396 | + var categorised_result = new scopes.lib.categorised_result(category); |
397 | + categorised_result.set_uri((weather_id++).toString()); |
398 | + categorised_result.set_title(r.forecast.time[i].temperature.min.toString() + "°C to " |
399 | + + r.forecast.time[i].temperature.max.toString() + "°C"); |
400 | + categorised_result.set_art("http://openweathermap.org/img/w/" + r.forecast.time[i].symbol.var + ".png"); |
401 | + categorised_result.set("subtitle", r.forecast.time[i].symbol.name); |
402 | + categorised_result.set("description", "A description of the result"); |
403 | + |
404 | + search_reply.push(categorised_result); |
405 | + } |
406 | +@elsif "%ContentType%" == "http+json" |
407 | + r = JSON.parse(res); |
408 | + |
409 | + var category_renderer = new scopes.lib.category_renderer(JSON.stringify(FORECAST_TEMPLATE)); |
410 | + var category = search_reply.register_category("forecast", "7 day forecast", "", category_renderer); |
411 | + |
412 | + for (i = 0; i < r.list.length; i++) { |
413 | + var categorised_result = new scopes.lib.categorised_result(category); |
414 | + categorised_result.set_uri(r.list[i].weather[0].id.toString()); |
415 | + categorised_result.set_title(r.list[i].temp.min.toString() + "°C to " |
416 | + + r.list[i].temp.max.toString() + "°C"); |
417 | + categorised_result.set_art("http://openweathermap.org/img/w/" + r.list[i].weather[0].icon + ".png"); |
418 | + categorised_result.set("subtitle", r.list[i].weather[0].description); |
419 | + categorised_result.set("description", "A description of the result"); |
420 | + |
421 | + search_reply.push(categorised_result); |
422 | + } |
423 | +@endif |
424 | + |
425 | + // We are done, call finished() on our search_reply |
426 | + search_reply.finished(); |
427 | + } |
428 | + catch(e) { |
429 | + // Forecast not available |
430 | + console.log("Forecast for '" + qs + "' is unavailable: " + e) |
431 | + } |
432 | + }); |
433 | + } |
434 | + |
435 | + http.request({host: query_host, path: current_weather_path + qs}, current_weather_cb).end(); |
436 | +@endif |
437 | + }, |
438 | + // cancelled |
439 | + function() { |
440 | + }); |
441 | + }, |
442 | + preview: function(result, action_metadata) { |
443 | + return new scopes.lib.preview_query( |
444 | + result, |
445 | + action_metadata, |
446 | + // run |
447 | + function(preview_reply) { |
448 | +@if "%ContentType%" != "empty" |
449 | + var layout1col = new scopes.lib.column_layout(1); |
450 | + var layout2col = new scopes.lib.column_layout(2); |
451 | + var layout3col = new scopes.lib.column_layout(3); |
452 | + layout1col.add_column(["image", "header", "summary"]); |
453 | + |
454 | + layout2col.add_column(["image"]); |
455 | + layout2col.add_column(["header", "summary"]); |
456 | + |
457 | + layout3col.add_column(["image"]); |
458 | + layout3col.add_column(["header", "summary"]); |
459 | + layout3col.add_column([]); |
460 | + |
461 | + preview_reply.register_layout([layout1col, layout2col, layout3col]); |
462 | + |
463 | + var header = new scopes.lib.preview_widget("header", "header"); |
464 | + header.add_attribute_mapping("title", "title"); |
465 | + header.add_attribute_mapping("subtitle", "subtitle"); |
466 | + |
467 | + var image = new scopes.lib.preview_widget("image", "image"); |
468 | + image.add_attribute_mapping("source", "art"); |
469 | + |
470 | + var description = new scopes.lib.preview_widget("summary", "text"); |
471 | + description.add_attribute_mapping("text", "description"); |
472 | + |
473 | + preview_reply.push([image, header, description ]); |
474 | + preview_reply.finished(); |
475 | +@endif |
476 | + }, |
477 | + // cancelled |
478 | + function() { |
479 | + }); |
480 | + } |
481 | + } |
482 | + ); |
483 | |
484 | === added file 'share/qtcreator/templates/wizards/ubuntu/scope-js/wizard.xml' |
485 | --- share/qtcreator/templates/wizards/ubuntu/scope-js/wizard.xml 1970-01-01 00:00:00 +0000 |
486 | +++ share/qtcreator/templates/wizards/ubuntu/scope-js/wizard.xml 2015-10-21 14:17:53 +0000 |
487 | @@ -0,0 +1,96 @@ |
488 | +<?xml version="1.0" encoding="UTF-8"?> |
489 | +<wizard version="1" kind="project" firstpage="10" id="C_UbuntuUnityJsScope" category="A.UbuntuProject" |
490 | + platformIndependent="true" |
491 | + class="ubuntu-project-cmake" |
492 | + featuresRequired="" |
493 | + > |
494 | + <icon>../share/ubuntu.png</icon> |
495 | + <description>A simple JavaScript based Unity Scope</description> |
496 | + <displayname>Unity Scope (JavaScript)</displayname> |
497 | + <displaycategory>Ubuntu</displaycategory> |
498 | + <files> |
499 | + <file source="po/CMakeLists.txt"/> |
500 | + <file source="po/displayName.pot" target="po/%ProjectName:l%.pot"/> |
501 | + <file source="po/POTFILES.in.in"/> |
502 | + |
503 | + <file source="src/data/displayName.ini.in" target="src/data/%ClickHookName:l%.ini.in"/> |
504 | + <file source="src/data/displayName-settings.ini.in" target="src/data/%ClickHookName:l%-settings.ini.in"/> |
505 | + <file source="src/data/icon.png" binary="true"/> |
506 | + <file source="src/data/logo.png" binary="true"/> |
507 | + |
508 | + <file source="src/displayName.js" target="src/%ClickHookName:l%.js"/> |
509 | + <file source="src/CMakeLists.txt"/> |
510 | + |
511 | + <file source="CMakeLists.txt" openproject="true"/> |
512 | + <file source="displayName.apparmor" target="%ClickHookName:l%.apparmor"/> |
513 | + <file source="manifest.json.in" openeditor="true"/> |
514 | + <file source=".bzrignore"/> |
515 | + </files> |
516 | + |
517 | + <!-- Create a 2nd wizard page with click package parameters --> |
518 | + <fieldpagetitle>Click package parameters</fieldpagetitle> |
519 | + <fields> |
520 | + <field mandatory="true" name="ClickDomain"> |
521 | + <fieldcontrol class="QLineEdit" validator='^[A-Za-z0-9-]+$' |
522 | + defaulttext="" placeholdertext="Nickname"/> |
523 | + <fielddescription>Nickname:</fielddescription> |
524 | + </field> |
525 | + <field mandatory="true" name="ClickMaintainer"> |
526 | + <fieldcontrol class="QLineEdit" validator='^[^"]+$' |
527 | + defaulttext="" placeholdertext="Maintainer"/> |
528 | + <fielddescription>Maintainer:</fielddescription> |
529 | + </field> |
530 | + <field mandatory="true" name="ClickHookName"> |
531 | + <fieldcontrol class="QLineEdit" validator='^[A-Za-z0-9.-]+$' |
532 | + defaulttext="%ProjectName%" placeholdertext="scope hook name"/> |
533 | + <fielddescription>Scope name:</fielddescription> |
534 | + </field> |
535 | + <field name="ClickFrameworkVersion"> |
536 | + <fieldcontrol class="QComboBox" defaultindex="0"> |
537 | + <comboentries> |
538 | + <!-- Do not add any other frameworks here, they are populated at runtime, this is just a dummy framework to make sure we can find the combobox --> |
539 | + <comboentry value="ubuntu-sdk-dummy-framework"> |
540 | + <comboentrytext>Dummy Framework</comboentrytext> |
541 | + </comboentry> |
542 | + </comboentries> |
543 | + </fieldcontrol> |
544 | + <fielddescription>Framework:</fielddescription> |
545 | + </field> |
546 | + <field name="ConfinementType"> |
547 | + <fieldcontrol class="QComboBox" defaultindex="0"> |
548 | + <comboentries> |
549 | + <comboentry value="ubuntu-scope-network"> |
550 | + <comboentrytext>Scope with network access</comboentrytext> |
551 | + </comboentry> |
552 | + <!-- |
553 | + <comboentry value="ubuntu-scope-local-content"> |
554 | + <comboentrytext>Scope with local content</comboentrytext> |
555 | + </comboentry> |
556 | + --> |
557 | + </comboentries> |
558 | + </fieldcontrol> |
559 | + <fielddescription>Confinement type:</fielddescription> |
560 | + </field> |
561 | + <field name="ContentType"> |
562 | + <fieldcontrol class="QComboBox" defaultindex="0"> |
563 | + <comboentries> |
564 | + <comboentry value="http+json"> |
565 | + <comboentrytext>JavaScript scope using HTTP and JSON</comboentrytext> |
566 | + </comboentry> |
567 | + <comboentry value="http+xml"> |
568 | + <comboentrytext>JavaScript scope using HTTP and XML</comboentrytext> |
569 | + </comboentry> |
570 | + <comboentry value="empty"> |
571 | + <comboentrytext>Empty scope</comboentrytext> |
572 | + </comboentry> |
573 | + </comboentries> |
574 | + </fieldcontrol> |
575 | + <fielddescription>Template type:</fielddescription> |
576 | + </field> |
577 | + </fields> |
578 | + <validationrules> |
579 | + <validationrule condition='/^(.*)\s+<(.*@.*)>$/.test("%ClickMaintainer%")'> |
580 | + <message>Invalid format for maintainer (should be like "Joe Bloggs <joe.bloggs@isp.com>")</message> |
581 | + </validationrule> |
582 | + </validationrules> |
583 | +</wizard> |