~webapps/unity-webapps-qml/15.04

« back to all changes in this revision

Viewing changes to src/Ubuntu/UnityWebApps/bindings/content-hub/client/docsbuild/files/content-hub.js.html

  • Committer: CI Train Bot
  • Author(s): Daniel Holbach
  • Date: 2015-04-09 13:29:10 UTC
  • mfrom: (148.1.5 unity-webapps-qml)
  • Revision ID: ci-train-bot@canonical.com-20150409132910-mmui8imfjseapg7f
Add ./update-docs script which generates API docs locally. We can't make this part of the build as not all node dependencies of yuidocsjs are packaged in the archive.
Approved by: PS Jenkins bot, David Barth

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<!DOCTYPE html>
 
2
<html lang="en">
 
3
<head>
 
4
    <meta charset="utf-8">
 
5
    <title>content-hub.js - Content Hub JS API</title>
 
6
    <link rel="stylesheet" href="http://yui.yahooapis.com/3.8.0pr2/build/cssgrids/cssgrids-min.css">
 
7
    <link rel="stylesheet" href="../assets/vendor/prettify/prettify-min.css">
 
8
    <link rel="stylesheet" href="../assets/css/main.css" id="site_styles">
 
9
    <script src="http://yui.yahooapis.com/combo?3.8.0pr2/build/yui/yui-min.js"></script>
 
10
</head>
 
11
<body class="yui3-skin-sam">
 
12
 
 
13
<div id="doc">
 
14
    <div id="hd" class="yui3-g header">
 
15
        <div class="yui3-u-3-4">
 
16
            <h1><a href="../index.html"><img src="../assets/css/logo.png">Content Hub JS API: content-hub.js</a></h1>
 
17
        </div>
 
18
        <div class="yui3-u-1-4 version">
 
19
            <em>API Docs for: 0.1</em>
 
20
        </div>
 
21
    </div>
 
22
    <div class="yui3-g">
 
23
 
 
24
        <div id="sidebar" class="yui3-u">
 
25
            <div id="modules" class="sidebox">
 
26
                <div class="hd">
 
27
                    <h2 class="no-toc">Modules</h2>
 
28
                </div>
 
29
                <div class="bd">
 
30
                    <ul>
 
31
                            <li><a href="../modules/ContentHub.html">ContentHub</a>
 
32
                            </li>
 
33
                    </ul>
 
34
                </div>
 
35
            </div>
 
36
            
 
37
            <div id="classes" class="sidebox">
 
38
                <div class="hd">
 
39
                    <h2 class="no-toc">Classes</h2>
 
40
                </div>
 
41
                <div class="bd">
 
42
                    <ul>
 
43
                            <li><a href="../classes/ContentHub.html">ContentHub</a></li>
 
44
                            <li><a href="../classes/ContentPeer.html">ContentPeer</a></li>
 
45
                            <li><a href="../classes/ContentStore.html">ContentStore</a></li>
 
46
                            <li><a href="../classes/ContentTransfer.html">ContentTransfer</a></li>
 
47
                    </ul>
 
48
                </div>
 
49
            </div>
 
50
            
 
51
            
 
52
            
 
53
            
 
54
            
 
55
            <div id="fileTree" class="sidebox">
 
56
                <div class="hd">
 
57
                    <h2 class="no-toc">Files</h2>
 
58
                </div>
 
59
                <div class="bd">
 
60
                    <ul><li>content-hub.js/<ul></ul></li></ul>
 
61
                </div>
 
62
            </div>
 
63
            
 
64
        </div>
 
65
 
 
66
        <div id="main" class="yui3-u">
 
67
            <div class="content"><h4>content-hub.js</h4>
 
68
 
 
69
<pre class="code prettyprint linenums">
 
70
/**
 
71
 * ContentHub is the entry point to resource io transfer
 
72
   from/to remote applications (peers).
 
73
 
 
74
 * @module ContentHub
 
75
 */
 
76
 
 
77
function createContentHubApi(backendBridge) {
 
78
    var PLUGIN_URI = &#x27;ContentHub&#x27;;
 
79
 
 
80
/**
 
81
 * ContentTransfer is an object created by the ContentHub to
 
82
   and allows one to properly setup and manage a data
 
83
   transfer between two peers.
 
84
 
 
85
 * @class ContentTransfer
 
86
 * @constructor
 
87
 * @example
 
88
 
 
89
       var api = external.getUnityObject(&#x27;1.0&#x27;);
 
90
       var hub = api.ContentHub;
 
91
 
 
92
       var pictureContentType = hub.ContentType.Pictures;
 
93
 
 
94
       hub.defaultSourceForType(
 
95
          pictureContentType
 
96
          , function(peer) {
 
97
            hub.importContentForPeer(
 
98
              pictureContentType,
 
99
              peer,
 
100
              function(transfer) {
 
101
                [setup the transfer options and store]
 
102
                transfer.start(function(state) { [...] });
 
103
              });
 
104
           });
 
105
 */
 
106
    function ContentTransfer(objectid, content) {
 
107
        this._proxy = backendBridge.createRemoteObject(
 
108
            PLUGIN_URI, &#x27;ContentTransfer&#x27;, objectid);
 
109
 
 
110
        this._store = content &amp;&amp; content.store
 
111
             ? content.store : null;
 
112
        this._state = content &amp;&amp; content.state
 
113
             ? content.state : null;
 
114
        this._selectionType = content &amp;&amp; content.selectionType
 
115
             ? content.selectionType : null;
 
116
        this._direction = content &amp;&amp; content.direction
 
117
             ? content.direction : null;
 
118
    };
 
119
    ContentTransfer.prototype = {
 
120
        // object methods
 
121
        serialize: function() {
 
122
            var self = this;
 
123
            return {
 
124
                type: &#x27;object-proxy&#x27;,
 
125
                apiid: &#x27;ContentHub&#x27;,
 
126
                objecttype: &#x27;ContentTransfer&#x27;,
 
127
                objectid: self._proxy.id(),
 
128
            }
 
129
        },
 
130
 
 
131
        // properties
 
132
 
 
133
        /**
 
134
         * Retrieves the current store.
 
135
         *
 
136
         * If the callback parameter is not set, the current &quot;local&quot; value is retrieved.
 
137
         *
 
138
         * @method store
 
139
         * @param callback (optional) {Function(String)}
 
140
         */
 
141
        store: function(callback) {
 
142
            if (callback &amp;&amp; typeof(callback) === &#x27;function&#x27;) {
 
143
                this._proxy.call(&#x27;store&#x27;, [], callback);
 
144
                return;
 
145
            }
 
146
            return this._store;
 
147
        },
 
148
        /**
 
149
         * Sets the current store for the ContentTransfer.
 
150
         *
 
151
         * @method setStore
 
152
         * @param store {ContentStore}
 
153
         * @param callback (optional) {Function()} called when the store has been updated
 
154
         */
 
155
        setStore: function(store, callback) {
 
156
            this._proxy.call(&#x27;setStore&#x27;, [store.serialize(), callback]);
 
157
        },
 
158
 
 
159
        /**
 
160
         * Retrieves the current state.
 
161
         *
 
162
         * If the callback parameter is not set, the current &quot;local&quot; value is retrieved.
 
163
         *
 
164
         * @method state
 
165
         * @param callback (optional) {Function(ContentTransfer.State)}
 
166
         */
 
167
        state: function(callback) {
 
168
            if (callback &amp;&amp; typeof(callback) === &#x27;function&#x27;) {
 
169
                this._proxy.call(&#x27;state&#x27;, [], callback);
 
170
                return;
 
171
            }
 
172
            return this._state;
 
173
        },
 
174
        /**
 
175
         * Sets the state of the transfer.
 
176
         *
 
177
         * @method setState
 
178
         * @param state {ContentTransfer.State}
 
179
         * @param callback {Function()} called when the state has been updated
 
180
         */
 
181
        setState: function(state, callback) {
 
182
            this._proxy.call(&#x27;setState&#x27;, [state, callback]);
 
183
        },
 
184
        /**
 
185
         * Notifies the listener when the state of the transfer changes.
 
186
         *
 
187
         * @method onStateChanged
 
188
         * @param callback {Function(ContentTransfer.State)}
 
189
         */
 
190
        onStateChanged: function(callback) {
 
191
            this._proxy.call(&#x27;onStateChanged&#x27;, [callback]);
 
192
        },
 
193
 
 
194
        /**
 
195
         * Retrieves the current selection type.
 
196
         *
 
197
         * @method selectionType
 
198
         * @param callback {Function(ContentTransfer.SelectionType)}
 
199
         */
 
200
        selectionType: function(callback) {
 
201
            if (callback &amp;&amp; typeof(callback) === &#x27;function&#x27;) {
 
202
                this._proxy.call(&#x27;selectionType&#x27;, [], callback);
 
203
                return;
 
204
            }
 
205
            return this._selectionType;
 
206
        },
 
207
        /**
 
208
         * Sets the selection type (single or multiple).
 
209
         *
 
210
         * @method setSelectionType
 
211
         * @param selectionType {ContentTransfer.SelectionType}
 
212
         * @param callback {Function()} called when the state has been updated
 
213
         */
 
214
        setSelectionType: function(selectionType, callback) {
 
215
            this._selectionType = selectionType;
 
216
            this._proxy.call(&#x27;setSelectionType&#x27;, [selectionType, callback]);
 
217
        },
 
218
 
 
219
        /**
 
220
         * Retrieves the current transfer direction.
 
221
         *
 
222
         * If the callback parameter is not set, the current &quot;local&quot; value is retrieved.
 
223
         *
 
224
         * @method direction
 
225
         * @param callback (optional) {Function(ContentTransfer.Direction)}
 
226
         */
 
227
        direction: function(callback) {
 
228
            if (callback &amp;&amp; typeof(callback) === &#x27;function&#x27;) {
 
229
                this._proxy.call(&#x27;direction&#x27;, [], callback);
 
230
                return;
 
231
            }
 
232
            return this._direction;
 
233
        },
 
234
        /**
 
235
         * Sets the transfer direction (import or export).
 
236
         *
 
237
         * @method setDirection
 
238
         * @param direction {ContentTransfer.Direction}
 
239
         * @param callback {Function()} called when the state has been updated
 
240
         */
 
241
        setDirection: function(direction, callback) {
 
242
            this._direction = direction;
 
243
            this._proxy.call(&#x27;setDirection&#x27;, [direction, callback]);
 
244
        },
 
245
 
 
246
        /**
 
247
         * Retrieves the list of items associated with the ContentTransfer.
 
248
         *
 
249
         * @method items
 
250
         * @param callback {Function( {Object{name: , url: }} )}
 
251
         */
 
252
        items: function(callback) {
 
253
            this._proxy.call(&#x27;items&#x27;, [], callback);
 
254
        },
 
255
        /**
 
256
         * Sets the list of items for the associated ContentTransfer (used when exporting).
 
257
         *
 
258
         * @method setItems
 
259
         * @param items {Array of Object{name: String, url: String}}
 
260
         * @param callback {Function()} called when the state has been updated
 
261
         */
 
262
        setItems: function(items, callback) {
 
263
            this._proxy.call(&#x27;setItems&#x27;, [items, callback]);
 
264
        },
 
265
 
 
266
        // methods
 
267
 
 
268
        /**
 
269
         * Starts a transfer
 
270
         * 
 
271
         * @method start
 
272
         * @param callback {Function(ContentTransfer.State)} 
 
273
         */
 
274
        start: function(callback) {
 
275
            this._proxy.call(&#x27;start&#x27;, [callback]);
 
276
        },
 
277
 
 
278
        /**
 
279
         * Sets State to ContentTransfer.Finalized and cleans up temporary files.
 
280
         *
 
281
         * @method finalize
 
282
         */
 
283
        finalize: function() {
 
284
            this._proxy.call(&#x27;finalize&#x27;, []);
 
285
        },
 
286
 
 
287
        // extras
 
288
 
 
289
        /**
 
290
         * Destroys the remote object. This proxy object is not valid anymore.
 
291
         *
 
292
         * @method destroy
 
293
         */
 
294
        destroy: function() {
 
295
            this._proxy.call(&#x27;destroy&#x27;, []);
 
296
        },
 
297
    };
 
298
 
 
299
/**
 
300
 * ContentPeer is an object returned by the ContentHub.
 
301
   It represents a remote peer that can be used in a request
 
302
   to import, export or share content.
 
303
 
 
304
 * @class ContentPeer
 
305
 * @module ContentHub
 
306
 * @constructor
 
307
 * @example
 
308
 
 
309
       var api = external.getUnityObject(&#x27;1.0&#x27;);
 
310
       var hub = api.ContentHub;
 
311
 
 
312
       var pictureContentType = hub.ContentType.Pictures;
 
313
 
 
314
       hub.defaultSourceForType(
 
315
          pictureContentType
 
316
          , function(peer) {
 
317
             [do something with the peer]
 
318
           });
 
319
 */
 
320
    function ContentPeer(objectid, content) {
 
321
        this._proxy = backendBridge.createRemoteObject(
 
322
            PLUGIN_URI, &#x27;ContentPeer&#x27;, objectid);
 
323
 
 
324
        this._appId = content &amp;&amp; content.appId
 
325
             ? content.appId : null;
 
326
        this._name = content &amp;&amp; content.name
 
327
             ? content.name : null;
 
328
        this._handler = content &amp;&amp; content.handler
 
329
             ? content.handler : null;
 
330
        this._contentType = content &amp;&amp; content.contentType
 
331
             ? content.contentType : null;
 
332
        this._selectionType = content &amp;&amp; content.selectionType
 
333
             ? content.selectionType : null;
 
334
        this._isDefaultPeer = content &amp;&amp; content.isDefaultPeer;
 
335
    };
 
336
    ContentPeer.prototype = {
 
337
        // object methods
 
338
        serialize: function() {
 
339
            var self = this;
 
340
            return {
 
341
                type: &#x27;object-proxy&#x27;,
 
342
                apiid: &#x27;ContentHub&#x27;,
 
343
                objecttype: &#x27;ContentPeer&#x27;,
 
344
                objectid: self._proxy.id(),
 
345
            }
 
346
        },
 
347
 
 
348
        // properties
 
349
 
 
350
        /**
 
351
         * Retrieves the app Id of the associated peer.
 
352
         *
 
353
         * If the callback parameter is not set, the current &quot;local&quot; value is retrieved.
 
354
         *
 
355
         * @method appId
 
356
         * @return {String} Application Id for this peer
 
357
         * @param callback (optional) {Function(String)}
 
358
         */
 
359
        appId: function(callback) {
 
360
            if (callback &amp;&amp; typeof(callback) === &#x27;function&#x27;) {
 
361
                this._proxy.call(&#x27;appId&#x27;, [], callback);
 
362
                return;
 
363
            }
 
364
            return this._appId;
 
365
        },
 
366
        /**
 
367
         * Sets the app Id of the associated peer.
 
368
         *
 
369
         * @method setAppId
 
370
         * @param appId {String}
 
371
         * @param callback {Function()} called when the appId has been updated
 
372
         */
 
373
        setAppId: function(appId, callback) {
 
374
            this._proxy.call(&#x27;setAppId&#x27;, [appId, callback]);
 
375
        },
 
376
 
 
377
        /**
 
378
         * Retrieves the specific ContentHandler for this peer.
 
379
         *
 
380
         * If the callback parameter is not set, the current &quot;local&quot; value is retrieved.
 
381
         *
 
382
         * @method handler
 
383
         * @return {String} ContentHandler for this peer
 
384
         * @param callback (optional) {Function(String)}
 
385
         */
 
386
        handler: function(callback) {
 
387
            if (callback &amp;&amp; typeof(callback) === &#x27;function&#x27;) {
 
388
                this._proxy.call(&#x27;handler&#x27;, [], callback);
 
389
                return;
 
390
            }
 
391
            return this._handler;
 
392
        },
 
393
        /**
 
394
         * Sets specific ContentHandler for this peer.
 
395
         *
 
396
         * @method setHandler
 
397
         * @param handler {ContentHandler}
 
398
         * @param callback {Function()} called when the appId has been updated
 
399
         */
 
400
        setHandler: function(handler, callback) {
 
401
            this._proxy.call(&#x27;setHandler&#x27;, [handler, callback]);
 
402
        },
 
403
 
 
404
        /**
 
405
         * Retrieves the specific ContentType for this peer.
 
406
         *
 
407
         * If the callback parameter is not set, the current &quot;local&quot; value is retrieved.
 
408
         *
 
409
         * @method contentType
 
410
         * @return {String} ContentType for this peer
 
411
         * @param callback (optional) {Function(String)}
 
412
         */
 
413
        contentType: function(callback) {
 
414
            if (callback &amp;&amp; typeof(callback) === &#x27;function&#x27;) {
 
415
                this._proxy.call(&#x27;contentType&#x27;, [], callback);
 
416
                return;
 
417
            }
 
418
            return this._contentType;
 
419
        },
 
420
        /**
 
421
         * Sets specific ContentType for this peer.
 
422
         *
 
423
         * @method setContentType
 
424
         * @param contentType {ContentType}
 
425
         * @param callback {Function()} called when the content type has been updated
 
426
         */
 
427
        setContentType: function(contentType, callback) {
 
428
            this._proxy.call(&#x27;setContentType&#x27;, [contentType, callback]);
 
429
        },
 
430
 
 
431
        /**
 
432
         * Retrieves the specific SelectionType for this peer.
 
433
         *
 
434
         * If the callback parameter is not set, the current &quot;local&quot; value is retrieved.
 
435
         *
 
436
         * @method selectionType
 
437
         * @return {String} ContentTransfer.SelectionType for this peer
 
438
         * @param callback (optional) {Function(String)}
 
439
         */
 
440
        selectionType: function(callback) {
 
441
            if (callback &amp;&amp; typeof(callback) === &#x27;function&#x27;) {
 
442
                this._proxy.call(&#x27;selectionType&#x27;, [], callback);
 
443
                return;
 
444
            }
 
445
            return this._selectionType;
 
446
        },
 
447
        /**
 
448
         * Sets specific SelectionType for this peer.
 
449
         *
 
450
         * @method setSelectionType
 
451
         * @param selectionType {ContentTransfer.SelectionType}
 
452
         * @param callback {Function()} called when the content type has been updated
 
453
         */
 
454
        setSelectionType: function(selectionType, callback) {
 
455
            this._proxy.call(&#x27;setSelectionType&#x27;, [selectionType, callback]);
 
456
        },
 
457
 
 
458
        /**
 
459
         * Retrieves the name of the associated peer.
 
460
         *
 
461
         * If the callback parameter is not set, the current &quot;local&quot; value is retrieved.
 
462
         *
 
463
         * @method name
 
464
         * @param callback (optional) {Function(String)}
 
465
         */
 
466
        name: function(callback) {
 
467
            if (callback &amp;&amp; typeof(callback) === &#x27;function&#x27;) {
 
468
                this._proxy.call(&#x27;name&#x27;, [], callback);
 
469
                return;
 
470
            }
 
471
            return this._name;
 
472
        },
 
473
 
 
474
        /**
 
475
         * Returns true if the peer is a default one, false otherwise.
 
476
         *
 
477
         * If the callback parameter is not set, the current &quot;local&quot; value is retrieved.
 
478
         *
 
479
         * @method isDefaultPeer
 
480
         * @param callback (optional) {Function(Bool)}
 
481
         */
 
482
        isDefaultPeer: function(callback) {
 
483
            if (callback &amp;&amp; typeof(callback) === &#x27;function&#x27;) {
 
484
                this._proxy.call(&#x27;isDefaultPeer&#x27;, [], callback);
 
485
                return;
 
486
            }
 
487
            return this._isDefaultPeer;
 
488
        },
 
489
 
 
490
        // methods
 
491
 
 
492
        /**
 
493
         * Request to exchange content with this ContentPeer.
 
494
         *
 
495
         * @method request
 
496
         * @param callback {Function(ContentTransfer)} Called with the resulting content transfer
 
497
         */
 
498
        request: function(callback) {
 
499
            this._proxy.call(&#x27;request&#x27;, [], callback);
 
500
        },
 
501
 
 
502
        /**
 
503
         * Request to import content from this ContentPeer and use a ContentStore for permanent storage.
 
504
         *
 
505
         * @method requestForStore
 
506
         * @param store {ContentStore} Store used as a permanent storage
 
507
         * @param callback {Function(ContentTransfer)} Called with the resulting content transfer
 
508
         */
 
509
        requestForStore: function(store, callback) {
 
510
            this._proxy.call(&#x27;requestForStore&#x27;, [store.serialize()], callback);
 
511
        },
 
512
 
 
513
        // extras
 
514
 
 
515
        /**
 
516
         * Destroys the remote object. This proxy object is not valid anymore.
 
517
         *
 
518
         * @method destroy
 
519
         */
 
520
        destroy: function() {
 
521
            this._proxy.call(&#x27;destroy&#x27;, []);
 
522
        },
 
523
    };
 
524
 
 
525
/**
 
526
 * ContentStore is an object returned by the ContentHub.
 
527
 
 
528
   It represents a location where the resources imported or
 
529
   exported from a peer during a transfer operation are to be
 
530
   either saved or found.
 
531
 
 
532
 * @class ContentStore
 
533
 * @module ContentHub
 
534
 * @constructor
 
535
 * @example
 
536
 
 
537
       var api = external.getUnityObject(&#x27;1.0&#x27;);
 
538
       var hub = api.ContentHub;
 
539
 
 
540
       var pictureContentType = hub.ContentType.Pictures;
 
541
 
 
542
       hub.defaultStoreForType(pictureContentType, function(store) {
 
543
         [do something with the store]
 
544
         });
 
545
 */
 
546
    function ContentStore(objectid, content) {
 
547
        this._proxy = backendBridge.createRemoteObject(
 
548
            PLUGIN_URI, &#x27;ContentStore&#x27;, objectid);
 
549
 
 
550
        this._uri = content &amp;&amp; content.uri
 
551
             ? content.uri : null;
 
552
        this._scope = content &amp;&amp; content.scope
 
553
             ? content.scope : null;
 
554
    };
 
555
    ContentStore.prototype = {
 
556
        // object methods
 
557
        serialize: function() {
 
558
            return {
 
559
                type: &#x27;object-proxy&#x27;,
 
560
                apiid: &#x27;ContentHub&#x27;,
 
561
                objecttype: &#x27;ContentStore&#x27;,
 
562
                objectid: this._proxy.id(),
 
563
            }
 
564
        },
 
565
 
 
566
        // properties
 
567
 
 
568
        //immutable
 
569
 
 
570
        /**
 
571
         * Retrieves the uri of the associated store.
 
572
         *
 
573
         * If the callback parameter is not set, the current &quot;local&quot; value is retrieved.
 
574
         *
 
575
         * @method uri
 
576
         * @return {String} current uri
 
577
         * @param callback (optional) {Function(String)}
 
578
         */
 
579
        uri: function(callback) {
 
580
            if (callback &amp;&amp; typeof(callback) === &#x27;function&#x27;) {
 
581
                this._proxy.call(&#x27;uri&#x27;, [], callback);
 
582
                return;
 
583
            }
 
584
            return this._uri;
 
585
        },
 
586
 
 
587
        /**
 
588
         * Retrieves the current scope.
 
589
         *
 
590
         * If the callback parameter is not set, the current &quot;local&quot; value is retrieved.
 
591
         *
 
592
         * @method scope
 
593
         * @return {ContentScope} current scope
 
594
         * @param callback (optional) {Function(ContentScope)}
 
595
         */
 
596
        scope: function(callback) {
 
597
            if (callback &amp;&amp; typeof(callback) === &#x27;function&#x27;) {
 
598
                this._proxy.call(&#x27;scope&#x27;, [], callback);
 
599
                return;
 
600
            }
 
601
            return this._scope;
 
602
        },
 
603
        /**
 
604
         * Sets the current scope.
 
605
         *
 
606
         * @method setScope
 
607
         * @param scope {ContentScope}
 
608
         * @param callback {Function()} called when the scope has been updated
 
609
         */
 
610
        setScope: function(scope, callback) {
 
611
            this._proxy.call(&#x27;setScope&#x27;, [scope, callback]);
 
612
        },
 
613
 
 
614
        // extras
 
615
 
 
616
        /**
 
617
         * Destroys the remote object. This proxy object is not valid anymore.
 
618
         *
 
619
         * @method destroy
 
620
         */
 
621
        destroy: function() {
 
622
            this._proxy.call(&#x27;destroy&#x27;, []);
 
623
        },
 
624
    };
 
625
 
 
626
    function _constructorFromName(className) {
 
627
        var constructorPerName = {
 
628
            &quot;ContentPeer&quot;: ContentPeer,
 
629
            &quot;ContentStore&quot;: ContentStore,
 
630
            &quot;ContentTransfer&quot;: ContentTransfer,
 
631
        };
 
632
        return className in constructorPerName
 
633
                ? constructorPerName[className]
 
634
                : null;
 
635
    };
 
636
 
 
637
/**
 
638
 * The ContentHub object.
 
639
 
 
640
 * @class ContentHub
 
641
 * @static
 
642
 * @constructor
 
643
 */
 
644
    return {
 
645
        /**
 
646
         ContentType is an enumeration of well known content types.
 
647
         
 
648
           Values:
 
649
 
 
650
             Pictures
 
651
 
 
652
             Documents
 
653
             
 
654
             Music
 
655
 
 
656
             Contacts
 
657
 
 
658
             Videos
 
659
 
 
660
             Links
 
661
 
 
662
         @static
 
663
         @property ContentType {String}
 
664
         
 
665
         @example
 
666
 
 
667
          var api = external.getUnityObject(&#x27;1.0&#x27;);
 
668
          var hub = api.ContentHub;
 
669
         
 
670
          var pictureContentType = hub.ContentType.Pictures;
 
671
         */
 
672
        ContentType: {
 
673
            All: &quot;All&quot;,
 
674
            Unknown: &quot;Unknown&quot;,
 
675
            Pictures: &quot;Pictures&quot;,
 
676
            Documents: &quot;Documents&quot;,
 
677
            Music: &quot;Music&quot;,
 
678
            Contacts: &quot;Contacts&quot;,
 
679
            Videos: &quot;Videos&quot;,
 
680
            Links: &quot;Links&quot;,
 
681
        },
 
682
 
 
683
        /**
 
684
          ContentHandler is an enumeration of well known content handlers.
 
685
 
 
686
           Values:
 
687
 
 
688
             Source
 
689
 
 
690
             Destination
 
691
 
 
692
             Share
 
693
 
 
694
           @static
 
695
           @property ContentHandler {String}
 
696
         */
 
697
        ContentHandler: {
 
698
            Source: &quot;Source&quot;,
 
699
            Destination: &quot;Destination&quot;,
 
700
            Share: &quot;Share&quot;,
 
701
        },
 
702
 
 
703
        /**
 
704
          ContentScope is an enumeration of well known scope types.
 
705
 
 
706
           Values:
 
707
 
 
708
             System
 
709
 
 
710
             User
 
711
 
 
712
             App
 
713
 
 
714
           @static
 
715
           @property ContentScope {String}
 
716
         */
 
717
        ContentScope: {
 
718
            System: &quot;System&quot;,
 
719
            User: &quot;User&quot;,
 
720
            App: &quot;App&quot;,
 
721
        },
 
722
 
 
723
        ContentTransfer: {
 
724
 
 
725
        /**
 
726
         ContentTransfer.State is an enumeration of the state of a given ongoing ContentTransfer.
 
727
         
 
728
           Values:
 
729
 
 
730
            Created: Transfer created, waiting to be initiated.
 
731
 
 
732
            Initiated: Transfer has been initiated.
 
733
 
 
734
            InProgress: Transfer is in progress.
 
735
 
 
736
            Charged: Transfer is charged with items and ready to be collected.
 
737
 
 
738
            Collected: Items in the transfer have been collected.
 
739
 
 
740
            Aborted: Transfer has been aborted.
 
741
 
 
742
            Finalized: Transfer has been finished and cleaned up.
 
743
 
 
744
            Downloaded: Download specified by downloadId has completed.
 
745
 
 
746
            Downloading: Transfer is downloading item specified by downloadId.
 
747
          
 
748
         @static
 
749
         @property ContentTransfer.State {String}
 
750
         
 
751
         @example
 
752
 
 
753
          var api = external.getUnityObject(&#x27;1.0&#x27;);
 
754
          var hub = api.ContentHub;
 
755
         
 
756
          var transferState = hub.ContentTransfer.State;
 
757
          var pictureContentType = hub.ContentType.Pictures;
 
758
 
 
759
          hub.importContentForPeer(
 
760
            pictureContentType,
 
761
            peer,
 
762
            function(transfer) {
 
763
                hub.defaultStoreForType(pictureContentType, function(store) {
 
764
                    transfer.setStore(store, function() {
 
765
                        transfer.start(function(state) {
 
766
                            if (transferState.Aborted === state) {
 
767
                              [...]
 
768
                            }
 
769
                            [...]
 
770
                        });
 
771
                    });
 
772
                });
 
773
          });
 
774
 
 
775
         */
 
776
            State: {
 
777
                // Transfer created, waiting to be initiated.
 
778
                Created: &quot;Created&quot;,
 
779
 
 
780
                // Transfer has been initiated.
 
781
                Initiated: &quot;Initiated&quot;,
 
782
 
 
783
                // Transfer is in progress.
 
784
                InProgress: &quot;InProgress&quot;,
 
785
 
 
786
                // Transfer is charged with items and ready to be collected.
 
787
                Charged: &quot;Charged&quot;,
 
788
 
 
789
                // Items in the transfer have been collected.
 
790
                Collected: &quot;Collected&quot;,
 
791
 
 
792
                // Transfer has been aborted.
 
793
                Aborted: &quot;Aborted&quot;,
 
794
 
 
795
                // Transfer has been finished and cleaned up.
 
796
                Finalized: &quot;Finalized&quot;,
 
797
 
 
798
                // Transfer has finished downloading.
 
799
                Downloaded: &quot;Downloaded&quot;,
 
800
 
 
801
                // Transfer is downloading.
 
802
                Downloading: &quot;Downloading&quot;,
 
803
            },
 
804
 
 
805
        /**
 
806
         ContentTransfer.Direction is an enumeration of the directions of a given ContentTransfer.
 
807
         
 
808
           Values:
 
809
 
 
810
            Import
 
811
 
 
812
            Export
 
813
 
 
814
            Share
 
815
 
 
816
         @static
 
817
         @property ContentTransfer.Direction {String}
 
818
         */
 
819
            Direction: {
 
820
                // Transfer is a request to import content
 
821
                Import: &quot;Import&quot;,
 
822
 
 
823
                // Transfer is a request to export content
 
824
                Export: &quot;Export&quot;,
 
825
 
 
826
                // Transfer is a request to share content
 
827
                Share: &quot;Share&quot;,
 
828
            },
 
829
 
 
830
        /**
 
831
         ContentTransfer.SelectionType is an enumeration of the directions of a given ContentTransfer.
 
832
         
 
833
           Values:
 
834
 
 
835
            Single: Transfer should contain a single item
 
836
 
 
837
            Multiple: Transfer can contain multiple items
 
838
 
 
839
         @static
 
840
         @property ContentTransfer.SelectionType {String}
 
841
         */
 
842
            SelectionType: {
 
843
                // Transfer should contain a single item
 
844
                Single: &quot;Single&quot;,
 
845
 
 
846
                // Transfer can contain multiple items
 
847
                Multiple: &quot;Multiple&quot;,
 
848
            },
 
849
        },
 
850
 
 
851
        /**
 
852
         * Creates a ContentPeer object for the given source type.
 
853
         *
 
854
         * @method getPeers
 
855
         * @param filters {Object} A dictionary of parameters to filter the result. The filtering keys are:
 
856
         * - contentType: desired ContentType
 
857
         * - handler: desired ContentHandler
 
858
         *
 
859
         * @param callback {Function(List of ContentPeer objects)} Callback that receives the result or null
 
860
         */
 
861
        getPeers: function(filter, callback) {
 
862
            backendBridge.call(&#x27;ContentHub.getPeers&#x27;,
 
863
                               [filter],
 
864
                               callback);
 
865
        },
 
866
 
 
867
        /**
 
868
         * Creates a ContentStore object for the given scope type.
 
869
         *
 
870
         * @method getStore
 
871
         * @param scope {ContentScope} The content scope for the store
 
872
         * @param callback {Function(ContentStore)} Callback that receives the result or null
 
873
         */
 
874
        getStore: function(scope, callback) {
 
875
            backendBridge.call(&#x27;ContentHub.getStore&#x27;,
 
876
                               [scope],
 
877
                               callback);
 
878
        },
 
879
 
 
880
        /**
 
881
         * Launches the content peer picker ui that allows the user to select a peer.
 
882
         *
 
883
         * @method launchContentPeerPicker
 
884
         * @param filters {Object} A dictionary of parameters to filter the result. The filtering keys are:
 
885
         * - contentType: desired ContentType
 
886
         * - handler: desired ContentHandler
 
887
         * - showTitle: boolean value indicating if the title should be visible
 
888
         * @param onPeerSelected {Function(ContentPeer)} Called when the user has selected a peer
 
889
         * @param onCancelPressed {Function()} Called when the user has pressed cancel
 
890
         */
 
891
        launchContentPeerPicker: function(filters, onPeerSelected, onCancelPressed) {
 
892
            backendBridge.call(&#x27;ContentHub.launchContentPeerPicker&#x27;,
 
893
                               [filters, onPeerSelected, onCancelPressed]);
 
894
        },
 
895
 
 
896
        /**
 
897
         * Sets a handler that is to be called when the current application is the
 
898
         * target of an export request.
 
899
         *
 
900
         * @method onExportRequested
 
901
         * @param callback {Function(ContentTransfer)} Function when one requests a resource to be exported.
 
902
         *                                                          The corresponding ContentTransfer is provided as a parameter.
 
903
         * 
 
904
         * @example
 
905
         
 
906
            var api = external.getUnityObject(1.0);
 
907
            var hub = api.ContentHub;
 
908
         
 
909
            var transferState = hub.ContentTransfer.State;
 
910
            
 
911
            function _exportRequested(transfer) {
 
912
              var url = window.location.href;
 
913
              url = url.substr(0, url.lastIndexOf(&#x27;/&#x27;)+1) + &#x27;img/ubuntuone-music.png&#x27;;
 
914
            
 
915
              transfer.setItems([{name: &#x27;Ubuntu One&#x27;, url: url}],
 
916
                function() {
 
917
                  transfer.setState(hub.ContentTransfer.State.Charged);
 
918
                });
 
919
              };
 
920
            
 
921
            hub.onExportRequested(_exportRequested);
 
922
         
 
923
         */
 
924
        onExportRequested: function(callback) {
 
925
            backendBridge.call(&#x27;ContentHub.onExportRequested&#x27;,
 
926
                               [callback]);
 
927
        },
 
928
 
 
929
        /**
 
930
         * Sets a handler that is to be called when the current application is the
 
931
         * target of an share request.
 
932
         *
 
933
         * @method onShareRequested
 
934
         * @param callback {Function(ContentTransfer)} Function when one requests a resource to be shared.
 
935
         *                                                          The corresponding ContentTransfer is provided as a parameter.
 
936
         *
 
937
         * @example
 
938
 
 
939
            var api = external.getUnityObject(1.0);
 
940
            var hub = api.ContentHub;
 
941
 
 
942
            var transferState = hub.ContentTransfer.State;
 
943
 
 
944
            function _shareRequested(transfer) {
 
945
            };
 
946
 
 
947
            hub.onShareRequested(_shareRequested);
 
948
 
 
949
         */
 
950
        onShareRequested: function(callback) {
 
951
            backendBridge.call(&#x27;ContentHub.onShareRequested&#x27;,
 
952
                               [callback]);
 
953
        },
 
954
 
 
955
        /**
 
956
         * Sets a handler that is to be called when the current application is the
 
957
         * target of an import request.
 
958
         *
 
959
         * @method onImportRequested
 
960
         * @param callback {Function(ContentTransfer)} Function when one requests a resource to be imported.
 
961
         *                                                          The corresponding ContentTransfer is provided as a parameter.
 
962
         *
 
963
         * @example
 
964
 
 
965
            var api = external.getUnityObject(1.0);
 
966
            var hub = api.ContentHub;
 
967
 
 
968
            var transferState = hub.ContentTransfer.State;
 
969
 
 
970
            function _importRequested(transfer) {
 
971
            };
 
972
 
 
973
            hub.onImportRequested(_importRequested);
 
974
 
 
975
         */
 
976
        onImportRequested: function(callback) {
 
977
            backendBridge.call(&#x27;ContentHub.onImportRequested&#x27;,
 
978
                               [callback]);
 
979
        },
 
980
 
 
981
        api: {
 
982
 
 
983
            /**
 
984
             * Creates a ContentStore object for the given ContentPeer.
 
985
             *
 
986
             * @method api.importContent
 
987
             * @param type {ContentType} type of the content to import
 
988
             * @param peer {ContentPeer} peer who&#x27;s content should be imported
 
989
             * @param transferOptions {Object} a dictionary of transfer options. The options are the following:
 
990
             * - multipleFiles {Bool}: specified if a transfer should involve multiple files or not
 
991
             * - scope {ContentScope}: specifies the location where the transferred files should be copied to
 
992
             * @param onError {Function(reason:)} called when the transfer has failed
 
993
             * @param onSuccess {Function(Array of {ContentItem})} called when the transfer has been a success and items are available
 
994
             */
 
995
            importContent: function(type, peer, transferOptions, onSuccess, onError) {
 
996
                backendBridge.call(&#x27;ContentHub.apiImportContent&#x27;,
 
997
                                  [type, peer.serialize(), transferOptions, onSuccess, onError]);
 
998
            }
 
999
        },
 
1000
 
 
1001
        // Internal
 
1002
 
 
1003
        /**
 
1004
         * @private
 
1005
         *
 
1006
         */
 
1007
        createObjectWrapper: function(objectType, objectId, content) {
 
1008
            var Constructor = _constructorFromName(objectType);
 
1009
            return new Constructor(objectId, content);
 
1010
        },
 
1011
    };
 
1012
};
 
1013
 
 
1014
</pre>
 
1015
 
 
1016
</div>
 
1017
        </div>
 
1018
    </div>
 
1019
</div>
 
1020
<script src="../assets/vendor/prettify/prettify-min.js"></script>
 
1021
<script>prettyPrint();</script>
 
1022
<script src="../assets/js/yui-prettify.js"></script>
 
1023
<script src="../assets/js/tabs.js"></script>
 
1024
</body>
 
1025
</html>