Merge lp:~abreu-alexandre/unity-webapps-qml/new-content-hub-api into lp:unity-webapps-qml
- new-content-hub-api
- Merge into trunk
Status: | Merged |
---|---|
Approved by: | Alberto Mardegan |
Approved revision: | 101 |
Merged at revision: | 98 |
Proposed branch: | lp:~abreu-alexandre/unity-webapps-qml/new-content-hub-api |
Merge into: | lp:unity-webapps-qml |
Diff against target: |
1352 lines (+828/-191) 6 files modified
examples/api-bindings/content-hub/www/js/app.js (+30/-53) examples/api-bindings/content-peer-picker/main.qml.in (+32/-0) examples/api-bindings/content-peer-picker/www/index.html (+33/-0) examples/api-bindings/content-peer-picker/www/js/app.js (+104/-0) src/Ubuntu/UnityWebApps/UnityWebAppsBackendComponents.js (+342/-66) src/Ubuntu/UnityWebApps/bindings/content-hub/client/content-hub.js (+287/-72) |
To merge this branch: | bzr merge lp:~abreu-alexandre/unity-webapps-qml/new-content-hub-api |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Alberto Mardegan (community) | Approve | ||
PS Jenkins bot (community) | continuous-integration | Approve | |
WebApps | Pending | ||
Review via email: mp+211165@code.launchpad.net |
Commit message
Add support for the new content hub api
Description of the change
Add support for the new content hub api.
You need https:/
- Testing the feature
-------
you have the examples/
- content-hub: example of an import application. It lists the potential sources for images,
- content-
APP_ID=
- content-hub-picker: example of an application that uses the Content Peer Picker UI,
- Automated/unit tests
-------
Another branch will land that adds integration tests for all API components, which is why
no tests have been added/updated,
PS Jenkins bot (ps-jenkins) wrote : | # |
Alberto Mardegan (mardy) wrote : | # |
L646: + if (this._
I guess you wanted "if (!..."
L670: Isn't it possible to avoid building the code this way, and use backendDelegate
L673-678 (but also later): I'd put the ";" at the end of the line, rather than at the beginning. Otherwise if the first filter is not set and the second one is, you'd end up with code like "ContentPeerModel { ; handler: ..."
L952: I guess the result of the expression must be a boolean, so maybe write it as
this.
I didn't test it yet, will do that soon.
Alberto Mardegan (mardy) wrote : | # |
I tested it, and the examples work.
- 101. By Alexandre Abreu
-
fixes
Alexandre Abreu (abreu-alexandre) wrote : | # |
> L646: + if (this._
> I guess you wanted "if (!..."
right, done
> L670: Isn't it possible to avoid building the code this way, and use
> backendDelegate
> guess you had your reasons not to do it this way, please explain :-) )
sure, the issue is w/ the plugin specific types that are not js builtins.
Things work find w/ the backend.create[..] when you have builtin types but
it is not really meant to specify custom type params like ContentType.
Those have to be handled specifically, hence the lousy creation steps,
>
> L673-678 (but also later): I'd put the ";" at the end of the line, rather than
> at the beginning. Otherwise if the first filter is not set and the second one
> is, you'd end up with code like "ContentPeerModel { ; handler: ..."
right, done
> L952: I guess the result of the expression must be a boolean, so maybe write
> it as
> this._isDefaultPeer = content && content.
done
PS Jenkins bot (ps-jenkins) wrote : | # |
PASSED: Continuous integration, rev:101
http://
Executed test runs:
SUCCESS: http://
SUCCESS: http://
Click here to trigger a rebuild:
http://
Preview Diff
1 | === modified file 'examples/api-bindings/content-hub/www/js/app.js' | |||
2 | --- examples/api-bindings/content-hub/www/js/app.js 2014-02-11 09:18:34 +0000 | |||
3 | +++ examples/api-bindings/content-hub/www/js/app.js 2014-03-18 13:59:59 +0000 | |||
4 | @@ -6,32 +6,18 @@ | |||
5 | 6 | var pictureContentType = hub.ContentType.Pictures; | 6 | var pictureContentType = hub.ContentType.Pictures; |
6 | 7 | 7 | ||
7 | 8 | var sourcePeers = {}; | 8 | var sourcePeers = {}; |
10 | 9 | hub.knownSourcesForType( | 9 | hub.getPeers( |
11 | 10 | pictureContentType | 10 | {contentType: hub.ContentType.Pictures} |
12 | 11 | , function (peers) { | 11 | , function (peers) { |
13 | 12 | if ( ! peers.length) | ||
14 | 13 | return; | ||
15 | 14 | |||
16 | 12 | for (var j = 0; j < peers.length; ++j) { | 15 | for (var j = 0; j < peers.length; ++j) { |
17 | 13 | addPeerElement(peers[j].appId(), peers[j].name()); | 16 | addPeerElement(peers[j].appId(), peers[j].name()); |
18 | 14 | sourcePeers[peers[j].appId()] = peers[j]; | 17 | sourcePeers[peers[j].appId()] = peers[j]; |
19 | 15 | } | 18 | } |
39 | 16 | 19 | document.getElementById('importdiv').style.display = 'block'; | |
40 | 17 | console.log('peers defaultSourceForType: ' + peers) | 20 | document.getElementById('lowLevelImportdiv').style.display = 'block'; |
22 | 18 | |||
23 | 19 | hub.defaultSourceForType( | ||
24 | 20 | pictureContentType | ||
25 | 21 | , function(peer) { | ||
26 | 22 | if (peer) { | ||
27 | 23 | addPeerElement(peer.appId(), peer.name()); | ||
28 | 24 | sourcePeers[peer.appId()] = peer; | ||
29 | 25 | } | ||
30 | 26 | |||
31 | 27 | if (Object.keys(sourcePeers).length === 0) { | ||
32 | 28 | nopeers(); | ||
33 | 29 | return; | ||
34 | 30 | } | ||
35 | 31 | document.getElementById('importdiv').style.display = 'block'; | ||
36 | 32 | document.getElementById('lowLevelImportdiv').style.display = 'block'; | ||
37 | 33 | } | ||
38 | 34 | ); | ||
41 | 35 | }); | 21 | }); |
42 | 36 | 22 | ||
43 | 37 | document.getElementById('import').addEventListener('click', doSimpleApiImport); | 23 | document.getElementById('import').addEventListener('click', doSimpleApiImport); |
44 | @@ -132,7 +118,7 @@ | |||
45 | 132 | 118 | ||
46 | 133 | hub.api.importContent(pictureContentType | 119 | hub.api.importContent(pictureContentType |
47 | 134 | , peer | 120 | , peer |
49 | 135 | , {importToLocalStore: true} | 121 | , {scope: hub.ContentScope.App} |
50 | 136 | , function(items) { | 122 | , function(items) { |
51 | 137 | for (var i = 0; i < items.length; ++i) { | 123 | for (var i = 0; i < items.length; ++i) { |
52 | 138 | addResult(items[i]); | 124 | addResult(items[i]); |
53 | @@ -159,40 +145,31 @@ | |||
54 | 159 | return; | 145 | return; |
55 | 160 | } | 146 | } |
56 | 161 | 147 | ||
84 | 162 | hub.importContentForPeer( | 148 | hub.getStore(hub.ContentScope.App, function(store) { |
85 | 163 | pictureContentType, | 149 | peer.requestForStore(store, function(transfer) { |
86 | 164 | peer, | 150 | transfer.start(function(state) { |
87 | 165 | function(transfer) { | 151 | if (transferState.Aborted === state) { |
88 | 166 | 152 | transfer.finalize(); | |
89 | 167 | hub.defaultStoreForType(pictureContentType, function(store) { | 153 | peer.destroy(); |
90 | 168 | transfer.setStore(store, function() { | 154 | transfer.destroy(); |
91 | 169 | 155 | aborted(); | |
92 | 170 | transfer.start(function(state) { | 156 | return; |
93 | 171 | if (transferState.Aborted === state) { | 157 | } |
94 | 172 | transfer.finalize(); | 158 | |
95 | 173 | peer.destroy(); | 159 | if (transferState.Charged === state) { |
96 | 174 | transfer.destroy(); | 160 | transfer.items(function(items) { |
97 | 175 | aborted(); | 161 | for (var i = 0; i < items.length; ++i) { |
98 | 176 | return; | 162 | addResult(items[i]); |
99 | 177 | } | 163 | } |
100 | 178 | 164 | transfer.finalize(); | |
101 | 179 | if (transferState.Charged === state) { | 165 | peer.destroy(); |
102 | 180 | transfer.items(function(items) { | 166 | transfer.destroy(); |
76 | 181 | for (var i = 0; i < items.length; ++i) { | ||
77 | 182 | addResult(items[i]); | ||
78 | 183 | } | ||
79 | 184 | transfer.finalize(); | ||
80 | 185 | peer.destroy(); | ||
81 | 186 | transfer.destroy(); | ||
82 | 187 | }); | ||
83 | 188 | } | ||
103 | 189 | }); | 167 | }); |
106 | 190 | }); | 168 | } |
105 | 191 | |||
107 | 192 | }); | 169 | }); |
108 | 193 | 170 | ||
111 | 194 | } | 171 | }); |
112 | 195 | ); | 172 | }); |
113 | 196 | }; | 173 | }; |
114 | 197 | }; | 174 | }; |
115 | 198 | 175 | ||
116 | 199 | 176 | ||
117 | === added directory 'examples/api-bindings/content-peer-picker' | |||
118 | === added file 'examples/api-bindings/content-peer-picker/main.qml.in' | |||
119 | --- examples/api-bindings/content-peer-picker/main.qml.in 1970-01-01 00:00:00 +0000 | |||
120 | +++ examples/api-bindings/content-peer-picker/main.qml.in 2014-03-18 13:59:59 +0000 | |||
121 | @@ -0,0 +1,32 @@ | |||
122 | 1 | import QtQuick 2.0 | ||
123 | 2 | import QtWebKit 3.0 | ||
124 | 3 | import QtWebKit.experimental 1.0 | ||
125 | 4 | import Ubuntu.Components 0.1 | ||
126 | 5 | import Ubuntu.UnityWebApps 0.1 | ||
127 | 6 | |||
128 | 7 | MainView { | ||
129 | 8 | id: root | ||
130 | 9 | focus: true | ||
131 | 10 | applicationName: \"helloworld\" | ||
132 | 11 | |||
133 | 12 | width: units.gu(100) | ||
134 | 13 | height: units.gu(100) | ||
135 | 14 | |||
136 | 15 | WebView { | ||
137 | 16 | id: webview | ||
138 | 17 | anchors.fill: parent | ||
139 | 18 | url: \"file://$$OUT_PWD/content-hub/www/index.html\" | ||
140 | 19 | |||
141 | 20 | experimental.preferences.navigatorQtObjectEnabled: true | ||
142 | 21 | experimental.preferences.developerExtrasEnabled: true | ||
143 | 22 | |||
144 | 23 | function getUnityWebappsProxies() { | ||
145 | 24 | return UnityWebAppsUtils.makeProxiesForQtWebViewBindee(webview); | ||
146 | 25 | } | ||
147 | 26 | |||
148 | 27 | UnityWebApps { | ||
149 | 28 | id: webapps | ||
150 | 29 | bindee: webview | ||
151 | 30 | } | ||
152 | 31 | } | ||
153 | 32 | } | ||
154 | 0 | 33 | ||
155 | === added directory 'examples/api-bindings/content-peer-picker/www' | |||
156 | === added file 'examples/api-bindings/content-peer-picker/www/index.html' | |||
157 | --- examples/api-bindings/content-peer-picker/www/index.html 1970-01-01 00:00:00 +0000 | |||
158 | +++ examples/api-bindings/content-peer-picker/www/index.html 2014-03-18 13:59:59 +0000 | |||
159 | @@ -0,0 +1,33 @@ | |||
160 | 1 | <html> | ||
161 | 2 | |||
162 | 3 | <head> | ||
163 | 4 | <title>Content Hub: Content Peer Picker example</title> | ||
164 | 5 | <script src="./js/app.js"></script> | ||
165 | 6 | </head> | ||
166 | 7 | |||
167 | 8 | <style> | ||
168 | 9 | |||
169 | 10 | .selected { background-color: red; } | ||
170 | 11 | |||
171 | 12 | </style> | ||
172 | 13 | |||
173 | 14 | <body> | ||
174 | 15 | <div> | ||
175 | 16 | Start Content Peer picking to import content: <input type="button" id="pick"></input> | ||
176 | 17 | </div> | ||
177 | 18 | |||
178 | 19 | <div> | ||
179 | 20 | Selected peer: | ||
180 | 21 | <div id="selected-peer"> | ||
181 | 22 | </div> | ||
182 | 23 | </div> | ||
183 | 24 | |||
184 | 25 | <div> | ||
185 | 26 | Imported Image: | ||
186 | 27 | <div id="results"> | ||
187 | 28 | </div> | ||
188 | 29 | </div> | ||
189 | 30 | |||
190 | 31 | </body> | ||
191 | 32 | |||
192 | 33 | </html> | ||
193 | 0 | 34 | ||
194 | === added directory 'examples/api-bindings/content-peer-picker/www/js' | |||
195 | === added file 'examples/api-bindings/content-peer-picker/www/js/app.js' | |||
196 | --- examples/api-bindings/content-peer-picker/www/js/app.js 1970-01-01 00:00:00 +0000 | |||
197 | +++ examples/api-bindings/content-peer-picker/www/js/app.js 2014-03-18 13:59:59 +0000 | |||
198 | @@ -0,0 +1,104 @@ | |||
199 | 1 | window.onload = function() { | ||
200 | 2 | var api = external.getUnityObject('1.0'); | ||
201 | 3 | var hub = api.ContentHub; | ||
202 | 4 | |||
203 | 5 | var transferState = hub.ContentTransfer.State; | ||
204 | 6 | var pictureContentType = hub.ContentType.Pictures; | ||
205 | 7 | |||
206 | 8 | document.getElementById('pick').addEventListener('click', doContentPeerPicking); | ||
207 | 9 | function doContentPeerPicking() { | ||
208 | 10 | hub.launchContentPeerPicker( | ||
209 | 11 | { | ||
210 | 12 | contentType: hub.ContentType.Pictures, | ||
211 | 13 | handler: hub.ContentHandler.Source, | ||
212 | 14 | }, | ||
213 | 15 | function(peer) { | ||
214 | 16 | if ( ! peer) { | ||
215 | 17 | nopeers(); | ||
216 | 18 | return; | ||
217 | 19 | } | ||
218 | 20 | addPeerElement(peer.appId(), peer.name()); | ||
219 | 21 | doSimpleApiImport(peer); | ||
220 | 22 | }, | ||
221 | 23 | function() { | ||
222 | 24 | aborted(); | ||
223 | 25 | }); | ||
224 | 26 | }; | ||
225 | 27 | |||
226 | 28 | function addPeerElement(appId, name) { | ||
227 | 29 | var selectedpeer = document.querySelector('#selected-peer'); | ||
228 | 30 | var span = document.createElement('span'); | ||
229 | 31 | |||
230 | 32 | var text = document.createTextNode('appId: ' + appId + ', name: ' + name) | ||
231 | 33 | span.appendChild(text); | ||
232 | 34 | selectedpeer.appendChild(span); | ||
233 | 35 | }; | ||
234 | 36 | |||
235 | 37 | var results = []; | ||
236 | 38 | function addResult(item) { | ||
237 | 39 | results.push({name: item.name, url: item.url}); | ||
238 | 40 | renderResults(results); | ||
239 | 41 | }; | ||
240 | 42 | |||
241 | 43 | function displayImages(images) { | ||
242 | 44 | var res = document.getElementById('results'); | ||
243 | 45 | for (var i = 0; i < images.length; ++i) { | ||
244 | 46 | var img = document.createElement('img'); | ||
245 | 47 | |||
246 | 48 | img.setAttribute('src', images[i].url); | ||
247 | 49 | img.setAttribute('height', '100px'); | ||
248 | 50 | img.setAttribute('width', '100px'); | ||
249 | 51 | |||
250 | 52 | if (images[i].name && images[i].name.length !== 0) | ||
251 | 53 | img.setAttribute('alt', images[i].name); | ||
252 | 54 | |||
253 | 55 | res.appendChild(img); | ||
254 | 56 | } | ||
255 | 57 | }; | ||
256 | 58 | |||
257 | 59 | function aborted() { | ||
258 | 60 | setResults('Transfer aborted'); | ||
259 | 61 | }; | ||
260 | 62 | |||
261 | 63 | function nopeers() { | ||
262 | 64 | setResults('No peers found'); | ||
263 | 65 | }; | ||
264 | 66 | |||
265 | 67 | function setResults(results) { | ||
266 | 68 | var resultEl = document.getElementById('results'); | ||
267 | 69 | resultEl.innerHTML = results; | ||
268 | 70 | }; | ||
269 | 71 | |||
270 | 72 | function formatResults(results) { | ||
271 | 73 | var content = '<ul>'; | ||
272 | 74 | for (var i = 0; i < results.length; ++i) { | ||
273 | 75 | content += '<li>' | ||
274 | 76 | + results[i].name | ||
275 | 77 | + ', ' | ||
276 | 78 | + results[i].url | ||
277 | 79 | + '</li>'; | ||
278 | 80 | } | ||
279 | 81 | content += '</ul>'; | ||
280 | 82 | return content; | ||
281 | 83 | }; | ||
282 | 84 | |||
283 | 85 | function renderResults(results) { | ||
284 | 86 | setResults(formatResults(results)); | ||
285 | 87 | displayImages(results); | ||
286 | 88 | }; | ||
287 | 89 | |||
288 | 90 | function doSimpleApiImport(peer) { | ||
289 | 91 | hub.api.importContent(pictureContentType | ||
290 | 92 | , peer | ||
291 | 93 | , {scope: hub.ContentScope.App} | ||
292 | 94 | , function(items) { | ||
293 | 95 | for (var i = 0; i < items.length; ++i) { | ||
294 | 96 | addResult(items[i]); | ||
295 | 97 | } | ||
296 | 98 | } | ||
297 | 99 | , function() { | ||
298 | 100 | aborted(); | ||
299 | 101 | }); | ||
300 | 102 | }; | ||
301 | 103 | }; | ||
302 | 104 | |||
303 | 0 | 105 | ||
304 | === modified file 'src/Ubuntu/UnityWebApps/UnityWebAppsBackendComponents.js' | |||
305 | --- src/Ubuntu/UnityWebApps/UnityWebAppsBackendComponents.js 2014-02-26 13:21:37 +0000 | |||
306 | +++ src/Ubuntu/UnityWebApps/UnityWebAppsBackendComponents.js 2014-03-18 13:59:59 +0000 | |||
307 | @@ -201,6 +201,14 @@ | |||
308 | 201 | return {object: this._objects[id], id: id}; | 201 | return {object: this._objects[id], id: id}; |
309 | 202 | }, | 202 | }, |
310 | 203 | 203 | ||
311 | 204 | parent: function() { | ||
312 | 205 | return this._parent; | ||
313 | 206 | }, | ||
314 | 207 | |||
315 | 208 | parentView: function() { | ||
316 | 209 | return this._parent ? this._parent.bindee : null; | ||
317 | 210 | }, | ||
318 | 211 | |||
319 | 204 | isObjectProxyInfo: function(info) { | 212 | isObjectProxyInfo: function(info) { |
320 | 205 | return 'type' in info && | 213 | return 'type' in info && |
321 | 206 | info.type === 'object-proxy' && | 214 | info.type === 'object-proxy' && |
322 | @@ -1308,14 +1316,32 @@ | |||
323 | 1308 | // TODO find a better way | 1316 | // TODO find a better way |
324 | 1309 | function _nameToContentType(name) { | 1317 | function _nameToContentType(name) { |
325 | 1310 | var contentTypePerName = { | 1318 | var contentTypePerName = { |
326 | 1319 | "All": ContentHubBridge.ContentType.All, | ||
327 | 1320 | "Unknown": ContentHubBridge.ContentType.Unknown, | ||
328 | 1311 | "Pictures": ContentHubBridge.ContentType.Pictures, | 1321 | "Pictures": ContentHubBridge.ContentType.Pictures, |
331 | 1312 | "Documents": ContentHubBridge.ContentType.Pictures, | 1322 | "Documents": ContentHubBridge.ContentType.Documents, |
332 | 1313 | "Music": ContentHubBridge.ContentType.Pictures, | 1323 | "Music": ContentHubBridge.ContentType.Music, |
333 | 1324 | "Contacts": ContentHubBridge.ContentType.Contacts, | ||
334 | 1314 | }; | 1325 | }; |
335 | 1315 | return name in contentTypePerName ? | 1326 | return name in contentTypePerName ? |
336 | 1316 | contentTypePerName[name] | 1327 | contentTypePerName[name] |
337 | 1317 | : ContentHubBridge.ContentType.Unknown; | 1328 | : ContentHubBridge.ContentType.Unknown; |
338 | 1318 | }; | 1329 | }; |
339 | 1330 | function _contentTypeToName(state) { | ||
340 | 1331 | if (state === ContentHubBridge.ContentType.All) | ||
341 | 1332 | return "All"; | ||
342 | 1333 | else if (state === ContentHubBridge.ContentType.Unknown) | ||
343 | 1334 | return "Unknown"; | ||
344 | 1335 | else if (state === ContentHubBridge.ContentType.Pictures) | ||
345 | 1336 | return "Pictures"; | ||
346 | 1337 | else if (state === ContentHubBridge.ContentType.Documents) | ||
347 | 1338 | return "Documents"; | ||
348 | 1339 | else if (state === ContentHubBridge.ContentType.Music) | ||
349 | 1340 | return "Music"; | ||
350 | 1341 | else if (state === ContentHubBridge.ContentType.Contacts) | ||
351 | 1342 | return "Contacts"; | ||
352 | 1343 | return "Unknown"; | ||
353 | 1344 | }; | ||
354 | 1319 | 1345 | ||
355 | 1320 | function _nameToContentTransferSelection(name) { | 1346 | function _nameToContentTransferSelection(name) { |
356 | 1321 | var contentTypePerName = { | 1347 | var contentTypePerName = { |
357 | @@ -1334,10 +1360,31 @@ | |||
358 | 1334 | return "Single"; | 1360 | return "Single"; |
359 | 1335 | }; | 1361 | }; |
360 | 1336 | 1362 | ||
361 | 1363 | function _nameToContentHandler(name) { | ||
362 | 1364 | var contentHandlerPerName = { | ||
363 | 1365 | "Source": ContentHubBridge.ContentHandler.Source, | ||
364 | 1366 | "Destination": ContentHubBridge.ContentHandler.Destination, | ||
365 | 1367 | "Share": ContentHubBridge.ContentHandler.Share, | ||
366 | 1368 | }; | ||
367 | 1369 | return name in contentHandlerPerName ? | ||
368 | 1370 | contentHandlerPerName[name] | ||
369 | 1371 | : ContentHubBridge.ContentHandler.Source; | ||
370 | 1372 | }; | ||
371 | 1373 | function _contentHandlerToName(state) { | ||
372 | 1374 | if (state === ContentHubBridge.ContentHandler.Source) | ||
373 | 1375 | return "Source"; | ||
374 | 1376 | else if (state === ContentHubBridge.ContentHandler.Destination) | ||
375 | 1377 | return "Destination"; | ||
376 | 1378 | else if (state === ContentHubBridge.ContentHandler.Share) | ||
377 | 1379 | return "Share"; | ||
378 | 1380 | return "Source"; | ||
379 | 1381 | }; | ||
380 | 1382 | |||
381 | 1337 | function _nameToContentTransferDirection(name) { | 1383 | function _nameToContentTransferDirection(name) { |
382 | 1338 | var contentTypePerName = { | 1384 | var contentTypePerName = { |
383 | 1339 | "Import": ContentHubBridge.ContentTransfer.Import, | 1385 | "Import": ContentHubBridge.ContentTransfer.Import, |
384 | 1340 | "Export": ContentHubBridge.ContentTransfer.Export, | 1386 | "Export": ContentHubBridge.ContentTransfer.Export, |
385 | 1387 | "Share": ContentHubBridge.ContentTransfer.Share, | ||
386 | 1341 | }; | 1388 | }; |
387 | 1342 | return name in contentTypePerName ? | 1389 | return name in contentTypePerName ? |
388 | 1343 | contentTypePerName[name] | 1390 | contentTypePerName[name] |
389 | @@ -1348,9 +1395,31 @@ | |||
390 | 1348 | return "Import"; | 1395 | return "Import"; |
391 | 1349 | else if (state === ContentHubBridge.ContentTransfer.Export) | 1396 | else if (state === ContentHubBridge.ContentTransfer.Export) |
392 | 1350 | return "Export"; | 1397 | return "Export"; |
393 | 1398 | else if (state === ContentHubBridge.ContentTransfer.Share) | ||
394 | 1399 | return "Share"; | ||
395 | 1351 | return "Import"; | 1400 | return "Import"; |
396 | 1352 | }; | 1401 | }; |
397 | 1353 | 1402 | ||
398 | 1403 | function _nameToContentScope(name) { | ||
399 | 1404 | var contentScopePerName = { | ||
400 | 1405 | "System": ContentHubBridge.ContentScope.System, | ||
401 | 1406 | "User": ContentHubBridge.ContentScope.User, | ||
402 | 1407 | "App": ContentHubBridge.ContentScope.App, | ||
403 | 1408 | }; | ||
404 | 1409 | return name in contentScopePerName ? | ||
405 | 1410 | contentScopePerName[name] | ||
406 | 1411 | : ContentHubBridge.ContentScope.App; | ||
407 | 1412 | }; | ||
408 | 1413 | function _contentScopeToName(state) { | ||
409 | 1414 | if (state === ContentHubBridge.ContentScope.System) | ||
410 | 1415 | return "System"; | ||
411 | 1416 | else if (state === ContentHubBridge.ContentScope.User) | ||
412 | 1417 | return "User"; | ||
413 | 1418 | else if (state === ContentHubBridge.ContentScope.App) | ||
414 | 1419 | return "App"; | ||
415 | 1420 | return "App"; | ||
416 | 1421 | }; | ||
417 | 1422 | |||
418 | 1354 | function _nameToContentTransferState(name) { | 1423 | function _nameToContentTransferState(name) { |
419 | 1355 | var contentTransferStatePerName = { | 1424 | var contentTransferStatePerName = { |
420 | 1356 | "Created": ContentHubBridge.ContentTransfer.Created, | 1425 | "Created": ContentHubBridge.ContentTransfer.Created, |
421 | @@ -1426,6 +1495,8 @@ | |||
422 | 1426 | content: { | 1495 | content: { |
423 | 1427 | store: self._object.store, | 1496 | store: self._object.store, |
424 | 1428 | state: self._object.state, | 1497 | state: self._object.state, |
425 | 1498 | selectionType: self._object.selectionType, | ||
426 | 1499 | direction: self._object.direction, | ||
427 | 1429 | } | 1500 | } |
428 | 1430 | } | 1501 | } |
429 | 1431 | }, | 1502 | }, |
430 | @@ -1461,6 +1532,15 @@ | |||
431 | 1461 | if (callback && typeof(callback) === 'function') | 1532 | if (callback && typeof(callback) === 'function') |
432 | 1462 | callback(); | 1533 | callback(); |
433 | 1463 | }, | 1534 | }, |
434 | 1535 | onStateChanged: function(callback) { | ||
435 | 1536 | if (!callback || typeof(callback) !== 'function') | ||
436 | 1537 | return; | ||
437 | 1538 | this._validate(); | ||
438 | 1539 | var self = this; | ||
439 | 1540 | this._object.onStateChanged.connect(function() { | ||
440 | 1541 | callback(_contentTransferStateToName(self._object.state)); | ||
441 | 1542 | }); | ||
442 | 1543 | }, | ||
443 | 1464 | 1544 | ||
444 | 1465 | selectionType: function(callback) { | 1545 | selectionType: function(callback) { |
445 | 1466 | this._validate(); | 1546 | this._validate(); |
446 | @@ -1504,16 +1584,11 @@ | |||
447 | 1504 | item.object.name = items[i].name; | 1584 | item.object.name = items[i].name; |
448 | 1505 | item.object.url = items[i].url; | 1585 | item.object.url = items[i].url; |
449 | 1506 | 1586 | ||
450 | 1507 | console.debug('setItems: adding item ' + item.object.name.toString() | ||
451 | 1508 | + ', ' + item.object.url.toString()); | ||
452 | 1509 | |||
453 | 1510 | contentItems.push(item.object); | 1587 | contentItems.push(item.object); |
454 | 1511 | } | 1588 | } |
455 | 1512 | 1589 | ||
456 | 1513 | this._object.items = contentItems; | 1590 | this._object.items = contentItems; |
457 | 1514 | 1591 | ||
458 | 1515 | console.debug('setItems: grand total of ' + this._object.items.length + ' added'); | ||
459 | 1516 | |||
460 | 1517 | if (callback && typeof(callback) === 'function') | 1592 | if (callback && typeof(callback) === 'function') |
461 | 1518 | callback(); | 1593 | callback(); |
462 | 1519 | }, | 1594 | }, |
463 | @@ -1593,12 +1668,24 @@ | |||
464 | 1593 | 1668 | ||
465 | 1594 | content: { | 1669 | content: { |
466 | 1595 | uri: self._object.uri, | 1670 | uri: self._object.uri, |
467 | 1671 | scope: _contentScopeToName(self._object.scope), | ||
468 | 1596 | } | 1672 | } |
469 | 1597 | } | 1673 | } |
470 | 1598 | }, | 1674 | }, |
471 | 1599 | 1675 | ||
472 | 1600 | // properties | 1676 | // properties |
473 | 1601 | 1677 | ||
474 | 1678 | scope: function(callback) { | ||
475 | 1679 | this._validate(); | ||
476 | 1680 | callback(_contentScopeToName(this._object.scope)); | ||
477 | 1681 | }, | ||
478 | 1682 | setScope: function(scope, callback) { | ||
479 | 1683 | this._validate(); | ||
480 | 1684 | this._object.scope = _nameToContentScope(scope); | ||
481 | 1685 | if (callback && typeof(callback) === 'function') | ||
482 | 1686 | callback(); | ||
483 | 1687 | }, | ||
484 | 1688 | |||
485 | 1602 | //immutable | 1689 | //immutable |
486 | 1603 | uri: function(callback) { | 1690 | uri: function(callback) { |
487 | 1604 | this._validate(); | 1691 | this._validate(); |
488 | @@ -1648,23 +1735,165 @@ | |||
489 | 1648 | content: { | 1735 | content: { |
490 | 1649 | appId: self._object.appId, | 1736 | appId: self._object.appId, |
491 | 1650 | name: self._object.name, | 1737 | name: self._object.name, |
492 | 1738 | handler: self._object.handler, | ||
493 | 1739 | contentType: self._object.contentType, | ||
494 | 1740 | selectionType: self._object.selectionType, | ||
495 | 1741 | isDefaultPeer: self._object.isDefaultPeer, | ||
496 | 1651 | }, | 1742 | }, |
497 | 1652 | } | 1743 | } |
498 | 1653 | }, | 1744 | }, |
499 | 1654 | 1745 | ||
500 | 1655 | // properties | 1746 | // properties |
501 | 1656 | 1747 | ||
502 | 1657 | // immutable | ||
503 | 1658 | appId: function(callback) { | 1748 | appId: function(callback) { |
504 | 1659 | this._validate(); | 1749 | this._validate(); |
505 | 1660 | callback(this._object.appId); | 1750 | callback(this._object.appId); |
506 | 1661 | }, | 1751 | }, |
507 | 1752 | setAppId: function(appId, callback) { | ||
508 | 1753 | this._validate(); | ||
509 | 1754 | this._object.appId = appId; | ||
510 | 1755 | if (callback && typeof(callback) === 'function') | ||
511 | 1756 | callback(); | ||
512 | 1757 | }, | ||
513 | 1758 | |||
514 | 1759 | handler: function(callback) { | ||
515 | 1760 | this._validate(); | ||
516 | 1761 | callback(_contentHandlerToName(this._object.handler)); | ||
517 | 1762 | }, | ||
518 | 1763 | setHandler: function(handler, callback) { | ||
519 | 1764 | this._validate(); | ||
520 | 1765 | this._object.handler = _nameToContentHandler(handler); | ||
521 | 1766 | if (callback && typeof(callback) === 'function') | ||
522 | 1767 | callback(); | ||
523 | 1768 | }, | ||
524 | 1769 | |||
525 | 1770 | contentType: function(callback) { | ||
526 | 1771 | this._validate(); | ||
527 | 1772 | callback(_contentTypeToName(this._object.contentType)); | ||
528 | 1773 | }, | ||
529 | 1774 | setContentType: function(contentType, callback) { | ||
530 | 1775 | this._validate(); | ||
531 | 1776 | this._object.contentType = _nameToContentType(contentType); | ||
532 | 1777 | if (callback && typeof(callback) === 'function') | ||
533 | 1778 | callback(); | ||
534 | 1779 | }, | ||
535 | 1780 | |||
536 | 1781 | selectionType: function(callback) { | ||
537 | 1782 | this._validate(); | ||
538 | 1783 | callback(_contentTransferSelectionToName(this._object.selectionType)); | ||
539 | 1784 | }, | ||
540 | 1785 | setSelectionType: function(selectionType, callback) { | ||
541 | 1786 | this._validate(); | ||
542 | 1787 | this._object.selectionType = _nameToContentTransferSelection(selectionType); | ||
543 | 1788 | if (callback && typeof(callback) === 'function') | ||
544 | 1789 | callback(); | ||
545 | 1790 | }, | ||
546 | 1662 | 1791 | ||
547 | 1663 | // immutable | 1792 | // immutable |
548 | 1664 | name: function(callback) { | 1793 | name: function(callback) { |
549 | 1665 | this._validate(); | 1794 | this._validate(); |
550 | 1666 | callback(this._object.name); | 1795 | callback(this._object.name); |
551 | 1667 | }, | 1796 | }, |
552 | 1797 | |||
553 | 1798 | isDefaultPeer: function(callback) { | ||
554 | 1799 | this._validate(); | ||
555 | 1800 | callback(this._object.isDefaultPeer); | ||
556 | 1801 | }, | ||
557 | 1802 | |||
558 | 1803 | // methods | ||
559 | 1804 | |||
560 | 1805 | request: function(callback) { | ||
561 | 1806 | this._validate(); | ||
562 | 1807 | var transfer = new ContentTransfer(this._object.request()); | ||
563 | 1808 | |||
564 | 1809 | if (callback && typeof(callback) === 'function') | ||
565 | 1810 | callback(transfer.serialize()); | ||
566 | 1811 | }, | ||
567 | 1812 | |||
568 | 1813 | requestForStore: function(store, callback) { | ||
569 | 1814 | if ( ! store) { | ||
570 | 1815 | callback(null); | ||
571 | 1816 | return; | ||
572 | 1817 | } | ||
573 | 1818 | |||
574 | 1819 | if (! backendDelegate.isObjectProxyInfo(store)) { | ||
575 | 1820 | console.debug('requestForStore: invalid store object proxy') | ||
576 | 1821 | callback("Invalid store"); | ||
577 | 1822 | return; | ||
578 | 1823 | } | ||
579 | 1824 | |||
580 | 1825 | var _store = backendDelegate.objectFromId(store.objectid); | ||
581 | 1826 | if ( ! _store) { | ||
582 | 1827 | callback("Invalid store object (NULL)"); | ||
583 | 1828 | return; | ||
584 | 1829 | } | ||
585 | 1830 | this._validate(); | ||
586 | 1831 | |||
587 | 1832 | var transfer = new ContentTransfer(this._object.request(_store)); | ||
588 | 1833 | if (callback && typeof(callback) === 'function') | ||
589 | 1834 | callback(transfer.serialize()); | ||
590 | 1835 | }, | ||
591 | 1836 | |||
592 | 1837 | // internal | ||
593 | 1838 | |||
594 | 1839 | internal: { | ||
595 | 1840 | request: function(self) { | ||
596 | 1841 | return self._object.request(); | ||
597 | 1842 | } | ||
598 | 1843 | } | ||
599 | 1844 | }; | ||
600 | 1845 | |||
601 | 1846 | function ContentPeerModel(filterParams) { | ||
602 | 1847 | var result = backendDelegate.createQmlObject( | ||
603 | 1848 | PLUGIN_URI, VERSION, 'ContentPeerModel', filterParams); | ||
604 | 1849 | this._id = result.id; | ||
605 | 1850 | this._object = result.object; | ||
606 | 1851 | |||
607 | 1852 | this._modelAdaptor = backendDelegate.createModelAdaptorFor(this._object); | ||
608 | 1853 | this._roles = this._modelAdaptor.roles(); | ||
609 | 1854 | }; | ||
610 | 1855 | ContentPeerModel.prototype = { | ||
611 | 1856 | _validate: function() { | ||
612 | 1857 | if (! this._object) | ||
613 | 1858 | throw new TypeError("Invalid object null"); | ||
614 | 1859 | }, | ||
615 | 1860 | |||
616 | 1861 | destroy: function() { | ||
617 | 1862 | if (! this._object) | ||
618 | 1863 | return; | ||
619 | 1864 | this._object.destroy(); | ||
620 | 1865 | this._modelAdaptor.destroy(); | ||
621 | 1866 | backendDelegate.deleteId(this._id); | ||
622 | 1867 | }, | ||
623 | 1868 | |||
624 | 1869 | // properties | ||
625 | 1870 | setContentType: function(contentType, callback) { | ||
626 | 1871 | this._validate(); | ||
627 | 1872 | this._object.contentType = contentType; | ||
628 | 1873 | if (callback) | ||
629 | 1874 | callback(); | ||
630 | 1875 | }, | ||
631 | 1876 | |||
632 | 1877 | setHandler: function(handler, callback) { | ||
633 | 1878 | this._validate(); | ||
634 | 1879 | this._object.handler = handler; | ||
635 | 1880 | if (callback) | ||
636 | 1881 | callback(); | ||
637 | 1882 | }, | ||
638 | 1883 | |||
639 | 1884 | peers: function() { | ||
640 | 1885 | this._validate(); | ||
641 | 1886 | return this._object.peers; | ||
642 | 1887 | }, | ||
643 | 1888 | |||
644 | 1889 | // QAbtractListModel prototype | ||
645 | 1890 | count: function(callback) { | ||
646 | 1891 | if (!this._modelAdaptor) { | ||
647 | 1892 | callback(-1); | ||
648 | 1893 | return; | ||
649 | 1894 | } | ||
650 | 1895 | callback(this._modelAdaptor.rowCount()); | ||
651 | 1896 | }, | ||
652 | 1668 | }; | 1897 | }; |
653 | 1669 | 1898 | ||
654 | 1670 | function _constructorFromName(className) { | 1899 | function _constructorFromName(className) { |
655 | @@ -1679,33 +1908,95 @@ | |||
656 | 1679 | } | 1908 | } |
657 | 1680 | 1909 | ||
658 | 1681 | return { | 1910 | return { |
664 | 1682 | defaultSourceForType: function(type, callback) { | 1911 | getPeers: function(filters, callback) { |
665 | 1683 | var _type = _nameToContentType(type); | 1912 | if ( ! filters){ |
666 | 1684 | var peer = _contenthub.defaultSourceForType(_type) | 1913 | callback(null); |
667 | 1685 | var source = new ContentPeer(peer); | 1914 | return; |
668 | 1686 | callback(source.serialize()); | 1915 | } |
669 | 1916 | |||
670 | 1917 | var statement = "import QtQuick 2.0; import Ubuntu.Content 0.1; ContentPeerModel {"; | ||
671 | 1918 | var filterParams = {}; | ||
672 | 1919 | if (filters.contentType) { | ||
673 | 1920 | statement += " contentType: ContentType." + filters.contentType + ";"; | ||
674 | 1921 | } | ||
675 | 1922 | if (filters.handler) { | ||
676 | 1923 | statement += " handler: ContentHandler." + filters.handler + ";"; | ||
677 | 1924 | } | ||
678 | 1925 | statement += " }"; | ||
679 | 1926 | |||
680 | 1927 | var peerModel = Qt.createQmlObject(statement, backendDelegate.parent()); | ||
681 | 1928 | var onPeersFound = function() { | ||
682 | 1929 | var peers = peerModel.peers; | ||
683 | 1930 | |||
684 | 1931 | var wrappedPeers = []; | ||
685 | 1932 | for (var i = 0; i < peers.length; ++i) { | ||
686 | 1933 | var wrappedPeer = new ContentPeer(peers[i]); | ||
687 | 1934 | wrappedPeers.push(wrappedPeer.serialize()); | ||
688 | 1935 | } | ||
689 | 1936 | peerModel.onFindPeersCompleted.disconnect(onPeersFound); | ||
690 | 1937 | callback(wrappedPeers); | ||
691 | 1938 | }; | ||
692 | 1939 | peerModel.onFindPeersCompleted.connect(onPeersFound); | ||
693 | 1687 | }, | 1940 | }, |
694 | 1688 | 1941 | ||
697 | 1689 | defaultStoreForType: function(type, callback) { | 1942 | getStore: function(scope, callback) { |
698 | 1690 | var store = new ContentStore(_contenthub.defaultStoreForType(_nameToContentType(type))); | 1943 | if ( ! scope){ |
699 | 1944 | callback(null); | ||
700 | 1945 | return; | ||
701 | 1946 | } | ||
702 | 1947 | var store = new ContentStore(); | ||
703 | 1948 | store.setScope(scope); | ||
704 | 1691 | callback(store.serialize()); | 1949 | callback(store.serialize()); |
705 | 1692 | }, | 1950 | }, |
706 | 1693 | 1951 | ||
722 | 1694 | importContent: function(type, callback) { | 1952 | launchContentPeerPicker: function(filters, onPeerSelected, onCancelPressed) { |
723 | 1695 | var transfer = new ContentTransfer(_contenthub.importContent(_nameToContentType(type))); | 1953 | if ( ! filters){ |
724 | 1696 | callback(transfer.serialize()); | 1954 | callback(null); |
725 | 1697 | }, | 1955 | return; |
726 | 1698 | 1956 | } | |
727 | 1699 | knownSourcesForType: function(type, callback) { | 1957 | |
728 | 1700 | var peers = _contenthub.knownSourcesForType(_nameToContentType(type)); | 1958 | var parentItem = backendDelegate.parentView(); |
729 | 1701 | var wrappedPeers = []; | 1959 | if ( ! parentItem || ! parentItem.visible || ! parentItem.height || ! parentItem.width) { |
730 | 1702 | 1960 | console.debug("Cannot launch the content peer picker UI, invalid parent item: " + parentItem); | |
731 | 1703 | for (var i = 0; i < peers.length; ++i) { | 1961 | onCancelPressed(); |
732 | 1704 | var wrappedPeer = new ContentPeer(peers[i]); | 1962 | return; |
733 | 1705 | wrappedPeers.push(wrappedPeer.serialize()); | 1963 | } |
734 | 1706 | } | 1964 | |
735 | 1707 | 1965 | var statement = "import QtQuick 2.0; import Ubuntu.Content 0.1; ContentPeerPicker {"; | |
736 | 1708 | callback(wrappedPeers); | 1966 | var filterParams = {}; |
737 | 1967 | if (filters.contentType) { | ||
738 | 1968 | statement += " contentType: ContentType." + filters.contentType + ""; | ||
739 | 1969 | } | ||
740 | 1970 | if (filters.handler) { | ||
741 | 1971 | statement += "; handler: ContentHandler." + filters.handler + ""; | ||
742 | 1972 | } | ||
743 | 1973 | if (filters.showTitle) { | ||
744 | 1974 | statement += "; showTitle: " + filters.showTitle === false ? "false" : "true"; | ||
745 | 1975 | } | ||
746 | 1976 | statement += "; visible: true; }"; | ||
747 | 1977 | |||
748 | 1978 | if (parentItem.parent) | ||
749 | 1979 | parentItem.visible = false; | ||
750 | 1980 | var contentPeerPicker = Qt.createQmlObject(statement, | ||
751 | 1981 | parentItem.parent ? parentItem.parent : parentItem); | ||
752 | 1982 | function _onPeerSelected() { | ||
753 | 1983 | var peer = new ContentPeer(contentPeerPicker.peer); | ||
754 | 1984 | contentPeerPicker.visible = false; | ||
755 | 1985 | parentItem.visible = true; | ||
756 | 1986 | onPeerSelected(peer.serialize()); | ||
757 | 1987 | contentPeerPicker.onPeerSelected.disconnect(_onPeerSelected); | ||
758 | 1988 | contentPeerPicker.destroy(); | ||
759 | 1989 | } | ||
760 | 1990 | function _onCancelPressed() { | ||
761 | 1991 | contentPeerPicker.visible = false; | ||
762 | 1992 | parentItem.visible = true; | ||
763 | 1993 | onCancelPressed(); | ||
764 | 1994 | contentPeerPicker.onPeerSelected.disconnect(_onCancelPressed); | ||
765 | 1995 | contentPeerPicker.destroy(); | ||
766 | 1996 | } | ||
767 | 1997 | |||
768 | 1998 | contentPeerPicker.onPeerSelected.connect(_onPeerSelected); | ||
769 | 1999 | contentPeerPicker.onCancelPressed.connect(_onCancelPressed); | ||
770 | 1709 | }, | 2000 | }, |
771 | 1710 | 2001 | ||
772 | 1711 | apiImportContent: function(type, peer, transferOptions, onSuccess, onFailure) { | 2002 | apiImportContent: function(type, peer, transferOptions, onSuccess, onFailure) { |
773 | @@ -1714,59 +2005,44 @@ | |||
774 | 1714 | onError("Invalid peer"); | 2005 | onError("Invalid peer"); |
775 | 1715 | return; | 2006 | return; |
776 | 1716 | } | 2007 | } |
777 | 2008 | |||
778 | 1717 | var _type = _nameToContentType(type); | 2009 | var _type = _nameToContentType(type); |
779 | 1718 | var _peer = backendDelegate.objectFromId(peer.objectid); | 2010 | var _peer = backendDelegate.objectFromId(peer.objectid); |
780 | 1719 | if ( ! _peer) { | 2011 | if ( ! _peer) { |
781 | 1720 | onError("Invalid peer object (NULL)"); | 2012 | onError("Invalid peer object (NULL)"); |
782 | 1721 | return; | 2013 | return; |
783 | 1722 | } | 2014 | } |
784 | 2015 | var _transfer = null; | ||
785 | 2016 | if (transferOptions.scope) { | ||
786 | 2017 | var store = new ContentStore(); | ||
787 | 2018 | store.setScope(transferOptions.scope); | ||
788 | 2019 | _transfer = _peer.request(store._object); | ||
789 | 2020 | } | ||
790 | 2021 | else { | ||
791 | 2022 | _transfer = _peer.request(); | ||
792 | 2023 | } | ||
793 | 1723 | 2024 | ||
794 | 1724 | var transfer = _contenthub.importContent(_type, _peer); | ||
795 | 1725 | console.log('*** Transfer object: ' + transfer + '') | ||
796 | 1726 | if (transferOptions.multipleFiles) { | 2025 | if (transferOptions.multipleFiles) { |
798 | 1727 | transfer.selectionType = ContentHubBridge.ContentTransfer.Multiple; | 2026 | _transfer.selectionType = ContentHubBridge.ContentTransfer.Multiple; |
799 | 1728 | } | 2027 | } |
800 | 1729 | else { | 2028 | else { |
813 | 1730 | transfer.selectionType = ContentHubBridge.ContentTransfer.Single; | 2029 | _transfer.selectionType = ContentHubBridge.ContentTransfer.Single; |
814 | 1731 | } | 2030 | } |
815 | 1732 | 2031 | ||
816 | 1733 | if (transferOptions.importToLocalStore) { | 2032 | var transfer = new ContentTransfer(_transfer) |
817 | 1734 | var store = _contenthub.defaultStoreForType(_type); | 2033 | _transfer.stateChanged.connect(function() { |
818 | 1735 | transfer.setStore(store); | 2034 | if (_transfer.state === ContentHubBridge.ContentTransfer.Aborted) { |
807 | 1736 | } | ||
808 | 1737 | |||
809 | 1738 | var _transfer = new ContentTransfer(transfer) | ||
810 | 1739 | transfer.stateChanged.connect(function() { | ||
811 | 1740 | console.log('** Transfer state change: ' + transfer + ', state: ' + _contentTransferStateToName(transfer.state)); | ||
812 | 1741 | if (transfer.state === ContentHubBridge.ContentTransfer.Aborted) { | ||
819 | 1742 | onFailure("Aborted"); | 2035 | onFailure("Aborted"); |
820 | 1743 | return; | 2036 | return; |
821 | 1744 | } | 2037 | } |
829 | 1745 | else if (transfer.state === ContentHubBridge.ContentTransfer.Charged) { | 2038 | else if (_transfer.state === ContentHubBridge.ContentTransfer.Charged) { |
830 | 1746 | console.log('*** Transfer complete: got: ' + transfer.items.length + ' items (' + transfer + ')') | 2039 | var d = transfer.internal.serializeItems(_transfer); |
824 | 1747 | for (var i = 0; i < transfer.items.length; ++i) { | ||
825 | 1748 | console.log('** item ' + i + ' : ' + transfer.items[i].url); | ||
826 | 1749 | } | ||
827 | 1750 | |||
828 | 1751 | var d = _transfer.internal.serializeItems(transfer); | ||
831 | 1752 | onSuccess(d); | 2040 | onSuccess(d); |
833 | 1753 | transfer.finalize(); | 2041 | _transfer.finalize(); |
834 | 1754 | return; | 2042 | return; |
835 | 1755 | } | 2043 | } |
836 | 1756 | }); | 2044 | }); |
850 | 1757 | transfer.start(); | 2045 | _transfer.start(); |
838 | 1758 | }, | ||
839 | 1759 | |||
840 | 1760 | importContentForPeer: function(type, peerProxy, callback) { | ||
841 | 1761 | if (! backendDelegate.isObjectProxyInfo(peerProxy)) { | ||
842 | 1762 | console.debug('importContentForPeer: invalid peer object proxy') | ||
843 | 1763 | callback(); | ||
844 | 1764 | return; | ||
845 | 1765 | } | ||
846 | 1766 | var peer = backendDelegate.objectFromId(peerProxy.objectid); | ||
847 | 1767 | var transfer = new ContentTransfer(_contenthub.importContent(_nameToContentType(type), peer)); | ||
848 | 1768 | |||
849 | 1769 | callback(transfer.serialize()); | ||
851 | 1770 | }, | 2046 | }, |
852 | 1771 | 2047 | ||
853 | 1772 | onExportRequested: function(callback) { | 2048 | onExportRequested: function(callback) { |
854 | 1773 | 2049 | ||
855 | === modified file 'src/Ubuntu/UnityWebApps/bindings/content-hub/client/content-hub.js' | |||
856 | --- src/Ubuntu/UnityWebApps/bindings/content-hub/client/content-hub.js 2014-03-04 20:40:16 +0000 | |||
857 | +++ src/Ubuntu/UnityWebApps/bindings/content-hub/client/content-hub.js 2014-03-18 13:59:59 +0000 | |||
858 | @@ -42,6 +42,10 @@ | |||
859 | 42 | ? content.store : null; | 42 | ? content.store : null; |
860 | 43 | this._state = content && content.state | 43 | this._state = content && content.state |
861 | 44 | ? content.state : null; | 44 | ? content.state : null; |
862 | 45 | this._selectionType = content && content.selectionType | ||
863 | 46 | ? content.selectionType : null; | ||
864 | 47 | this._direction = content && content.direction | ||
865 | 48 | ? content.direction : null; | ||
866 | 45 | }; | 49 | }; |
867 | 46 | ContentTransfer.prototype = { | 50 | ContentTransfer.prototype = { |
868 | 47 | // object methods | 51 | // object methods |
869 | @@ -77,7 +81,7 @@ | |||
870 | 77 | * | 81 | * |
871 | 78 | * @method setStore | 82 | * @method setStore |
872 | 79 | * @param store {ContentStore} | 83 | * @param store {ContentStore} |
874 | 80 | * @param callback (optional) {Function()} | 84 | * @param callback (optional) {Function()} called when the store has been updated |
875 | 81 | */ | 85 | */ |
876 | 82 | setStore: function(store, callback) { | 86 | setStore: function(store, callback) { |
877 | 83 | this._proxy.call('setStore', [store.serialize(), callback]); | 87 | this._proxy.call('setStore', [store.serialize(), callback]); |
878 | @@ -108,6 +112,15 @@ | |||
879 | 108 | setState: function(state, callback) { | 112 | setState: function(state, callback) { |
880 | 109 | this._proxy.call('setState', [state, callback]); | 113 | this._proxy.call('setState', [state, callback]); |
881 | 110 | }, | 114 | }, |
882 | 115 | /** | ||
883 | 116 | * Notifies the listener when the state of the transfer changes. | ||
884 | 117 | * | ||
885 | 118 | * @method onStateChanged | ||
886 | 119 | * @param callback {Function(ContentTransfer.State)} | ||
887 | 120 | */ | ||
888 | 121 | onStateChanged: function(callback) { | ||
889 | 122 | this._proxy.call('onStateChanged', [callback]); | ||
890 | 123 | }, | ||
891 | 111 | 124 | ||
892 | 112 | /** | 125 | /** |
893 | 113 | * Retrieves the current selection type. | 126 | * Retrieves the current selection type. |
894 | @@ -116,7 +129,11 @@ | |||
895 | 116 | * @param callback {Function(ContentTransfer.SelectionType)} | 129 | * @param callback {Function(ContentTransfer.SelectionType)} |
896 | 117 | */ | 130 | */ |
897 | 118 | selectionType: function(callback) { | 131 | selectionType: function(callback) { |
899 | 119 | this._proxy.call('selectionType', [], callback); | 132 | if (callback && typeof(callback) === 'function') { |
900 | 133 | this._proxy.call('selectionType', [], callback); | ||
901 | 134 | return; | ||
902 | 135 | } | ||
903 | 136 | return this._selectionType; | ||
904 | 120 | }, | 137 | }, |
905 | 121 | /** | 138 | /** |
906 | 122 | * Sets the selection type (single or multiple). | 139 | * Sets the selection type (single or multiple). |
907 | @@ -126,17 +143,24 @@ | |||
908 | 126 | * @param callback {Function()} called when the state has been updated | 143 | * @param callback {Function()} called when the state has been updated |
909 | 127 | */ | 144 | */ |
910 | 128 | setSelectionType: function(selectionType, callback) { | 145 | setSelectionType: function(selectionType, callback) { |
911 | 146 | this._selectionType = selectionType; | ||
912 | 129 | this._proxy.call('setSelectionType', [selectionType, callback]); | 147 | this._proxy.call('setSelectionType', [selectionType, callback]); |
913 | 130 | }, | 148 | }, |
914 | 131 | 149 | ||
915 | 132 | /** | 150 | /** |
916 | 133 | * Retrieves the current transfer direction. | 151 | * Retrieves the current transfer direction. |
917 | 134 | * | 152 | * |
918 | 153 | * If the callback parameter is not set, the current "local" value is retrieved. | ||
919 | 154 | * | ||
920 | 135 | * @method direction | 155 | * @method direction |
922 | 136 | * @param callback {Function(ContentTransfer.Direction)} | 156 | * @param callback (optional) {Function(ContentTransfer.Direction)} |
923 | 137 | */ | 157 | */ |
924 | 138 | direction: function(callback) { | 158 | direction: function(callback) { |
926 | 139 | this._proxy.call('direction', [], callback); | 159 | if (callback && typeof(callback) === 'function') { |
927 | 160 | this._proxy.call('direction', [], callback); | ||
928 | 161 | return; | ||
929 | 162 | } | ||
930 | 163 | return this._direction; | ||
931 | 140 | }, | 164 | }, |
932 | 141 | /** | 165 | /** |
933 | 142 | * Sets the transfer direction (import or export). | 166 | * Sets the transfer direction (import or export). |
934 | @@ -146,6 +170,7 @@ | |||
935 | 146 | * @param callback {Function()} called when the state has been updated | 170 | * @param callback {Function()} called when the state has been updated |
936 | 147 | */ | 171 | */ |
937 | 148 | setDirection: function(direction, callback) { | 172 | setDirection: function(direction, callback) { |
938 | 173 | this._direction = direction; | ||
939 | 149 | this._proxy.call('setDirection', [direction, callback]); | 174 | this._proxy.call('setDirection', [direction, callback]); |
940 | 150 | }, | 175 | }, |
941 | 151 | 176 | ||
942 | @@ -231,6 +256,13 @@ | |||
943 | 231 | ? content.appId : null; | 256 | ? content.appId : null; |
944 | 232 | this._name = content && content.name | 257 | this._name = content && content.name |
945 | 233 | ? content.name : null; | 258 | ? content.name : null; |
946 | 259 | this._handler = content && content.handler | ||
947 | 260 | ? content.handler : null; | ||
948 | 261 | this._contentType = content && content.contentType | ||
949 | 262 | ? content.contentType : null; | ||
950 | 263 | this._selectionType = content && content.selectionType | ||
951 | 264 | ? content.selectionType : null; | ||
952 | 265 | this._isDefaultPeer = content && content.isDefaultPeer; | ||
953 | 234 | }; | 266 | }; |
954 | 235 | ContentPeer.prototype = { | 267 | ContentPeer.prototype = { |
955 | 236 | // object methods | 268 | // object methods |
956 | @@ -246,14 +278,13 @@ | |||
957 | 246 | 278 | ||
958 | 247 | // properties | 279 | // properties |
959 | 248 | 280 | ||
960 | 249 | // immutable | ||
961 | 250 | |||
962 | 251 | /** | 281 | /** |
963 | 252 | * Retrieves the app Id of the associated peer. | 282 | * Retrieves the app Id of the associated peer. |
964 | 253 | * | 283 | * |
965 | 254 | * If the callback parameter is not set, the current "local" value is retrieved. | 284 | * If the callback parameter is not set, the current "local" value is retrieved. |
966 | 255 | * | 285 | * |
967 | 256 | * @method appId | 286 | * @method appId |
968 | 287 | * @return {String} Application Id for this peer | ||
969 | 257 | * @param callback (optional) {Function(String)} | 288 | * @param callback (optional) {Function(String)} |
970 | 258 | */ | 289 | */ |
971 | 259 | appId: function(callback) { | 290 | appId: function(callback) { |
972 | @@ -263,8 +294,97 @@ | |||
973 | 263 | } | 294 | } |
974 | 264 | return this._appId; | 295 | return this._appId; |
975 | 265 | }, | 296 | }, |
978 | 266 | 297 | /** | |
979 | 267 | // immutable | 298 | * Sets the app Id of the associated peer. |
980 | 299 | * | ||
981 | 300 | * @method setAppId | ||
982 | 301 | * @param appId {String} | ||
983 | 302 | * @param callback {Function()} called when the appId has been updated | ||
984 | 303 | */ | ||
985 | 304 | setAppId: function(appId, callback) { | ||
986 | 305 | this._proxy.call('setAppId', [appId, callback]); | ||
987 | 306 | }, | ||
988 | 307 | |||
989 | 308 | /** | ||
990 | 309 | * Retrieves the specific ContentHandler for this peer. | ||
991 | 310 | * | ||
992 | 311 | * If the callback parameter is not set, the current "local" value is retrieved. | ||
993 | 312 | * | ||
994 | 313 | * @method handler | ||
995 | 314 | * @return {String} ContentHandler for this peer | ||
996 | 315 | * @param callback (optional) {Function(String)} | ||
997 | 316 | */ | ||
998 | 317 | handler: function(callback) { | ||
999 | 318 | if (callback && typeof(callback) === 'function') { | ||
1000 | 319 | this._proxy.call('handler', [], callback); | ||
1001 | 320 | return; | ||
1002 | 321 | } | ||
1003 | 322 | return this._handler; | ||
1004 | 323 | }, | ||
1005 | 324 | /** | ||
1006 | 325 | * Sets specific ContentHandler for this peer. | ||
1007 | 326 | * | ||
1008 | 327 | * @method setHandler | ||
1009 | 328 | * @param handler {ContentHandler} | ||
1010 | 329 | * @param callback {Function()} called when the appId has been updated | ||
1011 | 330 | */ | ||
1012 | 331 | setHandler: function(handler, callback) { | ||
1013 | 332 | this._proxy.call('setHandler', [handler, callback]); | ||
1014 | 333 | }, | ||
1015 | 334 | |||
1016 | 335 | /** | ||
1017 | 336 | * Retrieves the specific ContentType for this peer. | ||
1018 | 337 | * | ||
1019 | 338 | * If the callback parameter is not set, the current "local" value is retrieved. | ||
1020 | 339 | * | ||
1021 | 340 | * @method contentType | ||
1022 | 341 | * @return {String} ContentType for this peer | ||
1023 | 342 | * @param callback (optional) {Function(String)} | ||
1024 | 343 | */ | ||
1025 | 344 | contentType: function(callback) { | ||
1026 | 345 | if (callback && typeof(callback) === 'function') { | ||
1027 | 346 | this._proxy.call('contentType', [], callback); | ||
1028 | 347 | return; | ||
1029 | 348 | } | ||
1030 | 349 | return this._contentType; | ||
1031 | 350 | }, | ||
1032 | 351 | /** | ||
1033 | 352 | * Sets specific ContentType for this peer. | ||
1034 | 353 | * | ||
1035 | 354 | * @method setContentType | ||
1036 | 355 | * @param contentType {ContentType} | ||
1037 | 356 | * @param callback {Function()} called when the content type has been updated | ||
1038 | 357 | */ | ||
1039 | 358 | setContentType: function(contentType, callback) { | ||
1040 | 359 | this._proxy.call('setContentType', [contentType, callback]); | ||
1041 | 360 | }, | ||
1042 | 361 | |||
1043 | 362 | /** | ||
1044 | 363 | * Retrieves the specific SelectionType for this peer. | ||
1045 | 364 | * | ||
1046 | 365 | * If the callback parameter is not set, the current "local" value is retrieved. | ||
1047 | 366 | * | ||
1048 | 367 | * @method selectionType | ||
1049 | 368 | * @return {String} ContentTransfer.SelectionType for this peer | ||
1050 | 369 | * @param callback (optional) {Function(String)} | ||
1051 | 370 | */ | ||
1052 | 371 | selectionType: function(callback) { | ||
1053 | 372 | if (callback && typeof(callback) === 'function') { | ||
1054 | 373 | this._proxy.call('selectionType', [], callback); | ||
1055 | 374 | return; | ||
1056 | 375 | } | ||
1057 | 376 | return this._selectionType; | ||
1058 | 377 | }, | ||
1059 | 378 | /** | ||
1060 | 379 | * Sets specific SelectionType for this peer. | ||
1061 | 380 | * | ||
1062 | 381 | * @method setSelectionType | ||
1063 | 382 | * @param selectionType {ContentTransfer.SelectionType} | ||
1064 | 383 | * @param callback {Function()} called when the content type has been updated | ||
1065 | 384 | */ | ||
1066 | 385 | setSelectionType: function(selectionType, callback) { | ||
1067 | 386 | this._proxy.call('setSelectionType', [selectionType, callback]); | ||
1068 | 387 | }, | ||
1069 | 268 | 388 | ||
1070 | 269 | /** | 389 | /** |
1071 | 270 | * Retrieves the name of the associated peer. | 390 | * Retrieves the name of the associated peer. |
1072 | @@ -282,6 +402,45 @@ | |||
1073 | 282 | return this._name; | 402 | return this._name; |
1074 | 283 | }, | 403 | }, |
1075 | 284 | 404 | ||
1076 | 405 | /** | ||
1077 | 406 | * Returns true if the peer is a default one, false otherwise. | ||
1078 | 407 | * | ||
1079 | 408 | * If the callback parameter is not set, the current "local" value is retrieved. | ||
1080 | 409 | * | ||
1081 | 410 | * @method isDefaultPeer | ||
1082 | 411 | * @param callback (optional) {Function(Bool)} | ||
1083 | 412 | */ | ||
1084 | 413 | isDefaultPeer: function(callback) { | ||
1085 | 414 | if (callback && typeof(callback) === 'function') { | ||
1086 | 415 | this._proxy.call('isDefaultPeer', [], callback); | ||
1087 | 416 | return; | ||
1088 | 417 | } | ||
1089 | 418 | return this._isDefaultPeer; | ||
1090 | 419 | }, | ||
1091 | 420 | |||
1092 | 421 | // methods | ||
1093 | 422 | |||
1094 | 423 | /** | ||
1095 | 424 | * Request to import data from this ContentPeer. | ||
1096 | 425 | * | ||
1097 | 426 | * @method request | ||
1098 | 427 | * @param callback {Function(ContentTransfer)} Called with the resulting content transfer | ||
1099 | 428 | */ | ||
1100 | 429 | request: function(callback) { | ||
1101 | 430 | this._proxy.call('request', [], callback); | ||
1102 | 431 | }, | ||
1103 | 432 | |||
1104 | 433 | /** | ||
1105 | 434 | * Request to import data from this ContentPeer and use a ContentStore for permanent storage. | ||
1106 | 435 | * | ||
1107 | 436 | * @method requestForStore | ||
1108 | 437 | * @param store {ContentStore} Store used as a permanent storage | ||
1109 | 438 | * @param callback {Function(ContentTransfer)} Called with the resulting content transfer | ||
1110 | 439 | */ | ||
1111 | 440 | requestForStore: function(store, callback) { | ||
1112 | 441 | this._proxy.call('requestForStore', [store.serialize()], callback); | ||
1113 | 442 | }, | ||
1114 | 443 | |||
1115 | 285 | // extras | 444 | // extras |
1116 | 286 | 445 | ||
1117 | 287 | /** | 446 | /** |
1118 | @@ -321,6 +480,8 @@ | |||
1119 | 321 | 480 | ||
1120 | 322 | this._uri = content && content.uri | 481 | this._uri = content && content.uri |
1121 | 323 | ? content.uri : null; | 482 | ? content.uri : null; |
1122 | 483 | this._scope = content && content.scope | ||
1123 | 484 | ? content.scope : null; | ||
1124 | 324 | }; | 485 | }; |
1125 | 325 | ContentStore.prototype = { | 486 | ContentStore.prototype = { |
1126 | 326 | // object methods | 487 | // object methods |
1127 | @@ -343,6 +504,7 @@ | |||
1128 | 343 | * If the callback parameter is not set, the current "local" value is retrieved. | 504 | * If the callback parameter is not set, the current "local" value is retrieved. |
1129 | 344 | * | 505 | * |
1130 | 345 | * @method uri | 506 | * @method uri |
1131 | 507 | * @return {String} current uri | ||
1132 | 346 | * @param callback (optional) {Function(String)} | 508 | * @param callback (optional) {Function(String)} |
1133 | 347 | */ | 509 | */ |
1134 | 348 | uri: function(callback) { | 510 | uri: function(callback) { |
1135 | @@ -353,6 +515,33 @@ | |||
1136 | 353 | return this._uri; | 515 | return this._uri; |
1137 | 354 | }, | 516 | }, |
1138 | 355 | 517 | ||
1139 | 518 | /** | ||
1140 | 519 | * Retrieves the current scope. | ||
1141 | 520 | * | ||
1142 | 521 | * If the callback parameter is not set, the current "local" value is retrieved. | ||
1143 | 522 | * | ||
1144 | 523 | * @method scope | ||
1145 | 524 | * @return {ContentScope} current scope | ||
1146 | 525 | * @param callback (optional) {Function(ContentScope)} | ||
1147 | 526 | */ | ||
1148 | 527 | scope: function(callback) { | ||
1149 | 528 | if (callback && typeof(callback) === 'function') { | ||
1150 | 529 | this._proxy.call('scope', [], callback); | ||
1151 | 530 | return; | ||
1152 | 531 | } | ||
1153 | 532 | return this._scope; | ||
1154 | 533 | }, | ||
1155 | 534 | /** | ||
1156 | 535 | * Sets the current scope. | ||
1157 | 536 | * | ||
1158 | 537 | * @method setScope | ||
1159 | 538 | * @param scope {ContentScope} | ||
1160 | 539 | * @param callback {Function()} called when the scope has been updated | ||
1161 | 540 | */ | ||
1162 | 541 | setScope: function(scope, callback) { | ||
1163 | 542 | this._proxy.call('setScope', [scope, callback]); | ||
1164 | 543 | }, | ||
1165 | 544 | |||
1166 | 356 | // extras | 545 | // extras |
1167 | 357 | 546 | ||
1168 | 358 | /** | 547 | /** |
1169 | @@ -394,7 +583,9 @@ | |||
1170 | 394 | Documents | 583 | Documents |
1171 | 395 | 584 | ||
1172 | 396 | Music | 585 | Music |
1174 | 397 | 586 | ||
1175 | 587 | Contacts | ||
1176 | 588 | |||
1177 | 398 | @static | 589 | @static |
1178 | 399 | @property ContentType {String} | 590 | @property ContentType {String} |
1179 | 400 | 591 | ||
1180 | @@ -406,9 +597,52 @@ | |||
1181 | 406 | var pictureContentType = hub.ContentType.Pictures; | 597 | var pictureContentType = hub.ContentType.Pictures; |
1182 | 407 | */ | 598 | */ |
1183 | 408 | ContentType: { | 599 | ContentType: { |
1184 | 600 | All: "All", | ||
1185 | 601 | Unknown: "Unknown", | ||
1186 | 409 | Pictures: "Pictures", | 602 | Pictures: "Pictures", |
1187 | 410 | Documents: "Documents", | 603 | Documents: "Documents", |
1189 | 411 | Music: "Music" | 604 | Music: "Music", |
1190 | 605 | Contacts: "Contacts", | ||
1191 | 606 | }, | ||
1192 | 607 | |||
1193 | 608 | /** | ||
1194 | 609 | ContentHandler is an enumeration of well known content handlers. | ||
1195 | 610 | |||
1196 | 611 | Values: | ||
1197 | 612 | |||
1198 | 613 | Source | ||
1199 | 614 | |||
1200 | 615 | Destination | ||
1201 | 616 | |||
1202 | 617 | Share | ||
1203 | 618 | |||
1204 | 619 | @static | ||
1205 | 620 | @property ContentHandler {String} | ||
1206 | 621 | */ | ||
1207 | 622 | ContentHandler: { | ||
1208 | 623 | Source: "Source", | ||
1209 | 624 | Destination: "Destination", | ||
1210 | 625 | Share: "Share", | ||
1211 | 626 | }, | ||
1212 | 627 | |||
1213 | 628 | /** | ||
1214 | 629 | ContentScope is an enumeration of well known scope types. | ||
1215 | 630 | |||
1216 | 631 | Values: | ||
1217 | 632 | |||
1218 | 633 | System | ||
1219 | 634 | |||
1220 | 635 | User | ||
1221 | 636 | |||
1222 | 637 | App | ||
1223 | 638 | |||
1224 | 639 | @static | ||
1225 | 640 | @property ContentScope {String} | ||
1226 | 641 | */ | ||
1227 | 642 | ContentScope: { | ||
1228 | 643 | System: "System", | ||
1229 | 644 | User: "User", | ||
1230 | 645 | App: "App", | ||
1231 | 412 | }, | 646 | }, |
1232 | 413 | 647 | ||
1233 | 414 | ContentTransfer: { | 648 | ContentTransfer: { |
1234 | @@ -527,67 +761,46 @@ | |||
1235 | 527 | /** | 761 | /** |
1236 | 528 | * Creates a ContentPeer object for the given source type. | 762 | * Creates a ContentPeer object for the given source type. |
1237 | 529 | * | 763 | * |
1299 | 530 | * @method defaultSourceForType | 764 | * @method getPeers |
1300 | 531 | * @param type {ContentType} Content type. | 765 | * @param filters {Object} A dictionary of parameters to filter the result. The filtering keys are: |
1301 | 532 | * @param callback {Function (ContentPeer)} Function called with the created ContentPeer. | 766 | * - contentType: desired ContentType |
1302 | 533 | */ | 767 | * - handler: desired ContentHandler |
1303 | 534 | defaultSourceForType: function(type, callback) { | 768 | * |
1304 | 535 | backendBridge.call('ContentHub.defaultSourceForType', | 769 | * @param callback {Function(List of ContentPeer objects)} Callback that receives the result or null |
1305 | 536 | [type], | 770 | */ |
1306 | 537 | callback); | 771 | getPeers: function(filter, callback) { |
1307 | 538 | }, | 772 | backendBridge.call('ContentHub.getPeers', |
1308 | 539 | 773 | [filter], | |
1309 | 540 | /** | 774 | callback); |
1310 | 541 | * Creates a ContentStore object for the given content type. | 775 | }, |
1311 | 542 | * | 776 | |
1312 | 543 | * @method defaultStoreForType | 777 | /** |
1313 | 544 | * @param type {ContentType} Content type. | 778 | * Creates a ContentStore object for the given scope type. |
1314 | 545 | * @param callback {Function (ContentStore)} Function called with the created ContentStore. | 779 | * |
1315 | 546 | */ | 780 | * @method getStore |
1316 | 547 | defaultStoreForType: function(type, callback) { | 781 | * @param scope {ContentScope} The content scope for the store |
1317 | 548 | backendBridge.call('ContentHub.defaultStoreForType', | 782 | * @param callback {Function(ContentStore)} Callback that receives the result or null |
1318 | 549 | [type], | 783 | */ |
1319 | 550 | callback); | 784 | getStore: function(scope, callback) { |
1320 | 551 | }, | 785 | backendBridge.call('ContentHub.getStore', |
1321 | 552 | 786 | [scope], | |
1322 | 553 | /** | 787 | callback); |
1323 | 554 | * Returns all possible peers for the given ContentType. | 788 | }, |
1324 | 555 | * | 789 | |
1325 | 556 | * @method knownSourcesForType | 790 | /** |
1326 | 557 | * @param type {ContentType} Content type. | 791 | * Launches the content peer picker ui that allows the user to select a peer. |
1327 | 558 | * @param callback {Function (Array of ContentPeer)} Function called with the possible ContentPeers. | 792 | * |
1328 | 559 | */ | 793 | * @method launchContentPeerPicker |
1329 | 560 | knownSourcesForType: function(type, callback) { | 794 | * @param filters {Object} A dictionary of parameters to filter the result. The filtering keys are: |
1330 | 561 | backendBridge.call('ContentHub.knownSourcesForType', | 795 | * - contentType: desired ContentType |
1331 | 562 | [type], | 796 | * - handler: desired ContentHandler |
1332 | 563 | callback); | 797 | * - showTitle: boolean value indicating if the title should be visible |
1333 | 564 | }, | 798 | * @param onPeerSelected {Function(ContentPeer)} Called when the user has selected a peer |
1334 | 565 | 799 | * @param onCancelPressed {Function()} Called when the user has pressed cancel | |
1335 | 566 | /** | 800 | */ |
1336 | 567 | * Creates a ContentTransfer object for the given content type. | 801 | launchContentPeerPicker: function(filters, onPeerSelected, onCancelPressed) { |
1337 | 568 | * | 802 | backendBridge.call('ContentHub.launchContentPeerPicker', |
1338 | 569 | * @method importContent | 803 | [filters, onPeerSelected, onCancelPressed]); |
1278 | 570 | * @param type {ContentType} Content type. | ||
1279 | 571 | * @param callback {Function(ContentTransfer)} Function called with the created ContentTransfer. | ||
1280 | 572 | */ | ||
1281 | 573 | importContent: function(type, callback) { | ||
1282 | 574 | backendBridge.call('ContentHub.importContent', | ||
1283 | 575 | [type], | ||
1284 | 576 | callback); | ||
1285 | 577 | }, | ||
1286 | 578 | |||
1287 | 579 | /** | ||
1288 | 580 | * Creates a ContentTransfer object for the given ContentPeer. | ||
1289 | 581 | * | ||
1290 | 582 | * @method importContentForPeer | ||
1291 | 583 | * @param type {ContentType} Content type. | ||
1292 | 584 | * @param peer {ContentPeer} Content peer. | ||
1293 | 585 | * @param callback {Function(ContentTransfer)} Function called with the created ContentTransfer. | ||
1294 | 586 | */ | ||
1295 | 587 | importContentForPeer: function(type, peer, callback) { | ||
1296 | 588 | backendBridge.call('ContentHub.importContentForPeer', | ||
1297 | 589 | [type, peer.serialize()], | ||
1298 | 590 | callback); | ||
1339 | 591 | }, | 804 | }, |
1340 | 592 | 805 | ||
1341 | 593 | /** | 806 | /** |
1342 | @@ -631,7 +844,9 @@ | |||
1343 | 631 | * @method api.importContent | 844 | * @method api.importContent |
1344 | 632 | * @param type {ContentType} type of the content to import | 845 | * @param type {ContentType} type of the content to import |
1345 | 633 | * @param peer {ContentPeer} peer whos content should be imported | 846 | * @param peer {ContentPeer} peer whos content should be imported |
1347 | 634 | * @param transferOptions {Object {multipleFiles: {Bool}, importToLocalStore: {Bool}} } the set of options for the transfer | 847 | * @param transferOptions {Object} a dictionary of transfer options. The options are the following: |
1348 | 848 | * - multipleFiles {Bool}: specified if a transfer should involve multiple files or not | ||
1349 | 849 | * - scope {ContentScope}: specifies the location where the transferred files should be copied to | ||
1350 | 635 | * @param onError {Function(reason:)} called when the transfer has failed | 850 | * @param onError {Function(reason:)} called when the transfer has failed |
1351 | 636 | * @param onSuccess {Function(Array of {ContentItem})} called when the transfer has been a success and items are available | 851 | * @param onSuccess {Function(Array of {ContentItem})} called when the transfer has been a success and items are available |
1352 | 637 | */ | 852 | */ |
PASSED: Continuous integration, rev:100 jenkins. qa.ubuntu. com/job/ unity-webapps- qml-ci/ 90/ jenkins. qa.ubuntu. com/job/ unity-webapps- qml-trusty- amd64-ci/ 38 jenkins. qa.ubuntu. com/job/ unity-webapps- qml-trusty- armhf-ci/ 38
http://
Executed test runs:
SUCCESS: http://
SUCCESS: http://
Click here to trigger a rebuild: s-jenkins. ubuntu- ci:8080/ job/unity- webapps- qml-ci/ 90/rebuild
http://