[Content] Fixed the reconfigurable issue
[platform/core/api/webapi-plugins.git] / src / content / js / datatypes.js
1 /*
2  * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  *    Licensed under the Apache License, Version 2.0 (the "License");
5  *    you may not use this file except in compliance with the License.
6  *    You may obtain a copy of the License at
7  *
8  *        http://www.apache.org/licenses/LICENSE-2.0
9  *
10  *    Unless required by applicable law or agreed to in writing, software
11  *    distributed under the License is distributed on an "AS IS" BASIS,
12  *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  *    See the License for the specific language governing permissions and
14  *    limitations under the License.
15  */
16
17 var privUtils_ = xwalk.utils;
18
19 var ContentType = {
20     IMAGE: 'IMAGE',
21     VIDEO: 'VIDEO',
22     AUDIO: 'AUDIO',
23     OTHER: 'OTHER'
24 };
25
26 var AudioContentLyricsType = {
27     SYNCHRONIZED: 'SYNCHRONIZED',
28     UNSYNCHRONIZED: 'UNSYNCHRONIZED'
29 };
30
31 var ImageContentOrientation = {
32     NORMAL: 'NORMAL',
33     FLIP_HORIZONTAL: 'FLIP_HORIZONTAL',
34     ROTATE_180: 'ROTATE_180',
35     FLIP_VERTICAL: 'FLIP_VERTICAL',
36     TRANSPOSE: 'TRANSPOSE',
37     ROTATE_90: 'ROTATE_90',
38     TRANSVERSE: 'TRANSVERSE',
39     ROTATE_270: 'ROTATE_270'
40 };
41
42 function ContentDirectory(data) {
43     var id;
44     var directoryURI;
45     var title;
46     var modifiedDate = null;
47
48     Object.defineProperties(this, {
49         id: {
50             get: function() {
51                 return id;
52             },
53             set: function(v) {
54                 if (edit_.isAllowed) {
55                     id = converter_.toString(v, false);
56                 }
57             },
58             enumerable: true
59         },
60         directoryURI: {
61             get: function() {
62                 return directoryURI;
63             },
64             set: function(v) {
65                 if (edit_.isAllowed) {
66                     directoryURI = convertPathToUri_(converter_.toString(v, false));
67                 }
68             },
69             enumerable: true
70         },
71         title: {
72             get: function() {
73                 return title;
74             },
75             set: function(v) {
76                 if (edit_.isAllowed) {
77                     title = converter_.toString(v, false);
78                 }
79             },
80             enumerable: true
81         },
82         storageType: {
83             get: function() {
84                 utils_.printDeprecationWarningFor('ContentDirectoryStorageType');
85                 return "storageType_NOT_SUPPORTED";
86             },
87             set: function (v) {
88             },
89             enumerable: true
90         },
91         modifiedDate: {
92             get: function() {
93                 return modifiedDate;
94             },
95             set: function(v) {
96                 if (edit_.isAllowed) {
97                     modifiedDate = v > 0 ? new Date(v * 1000) : null;
98                 }
99             },
100             enumerable: true
101         }
102     });
103
104     if (type_.isObject(data)) {
105         // fill object with data
106         edit_.allow();
107         for (var key in data) {
108             if (data.hasOwnProperty(key) && this.hasOwnProperty(key)) {
109                 this[key] = data[key];
110             }
111         }
112         edit_.disallow();
113     }
114 }
115
116 function Content(data) {
117     var editableAttributes = ['isFavorite'];
118     var id;
119     var name;
120     var type;
121     var mimeType;
122     var title;
123     var contentURI;
124     var thumbnailURIs = null;
125     var releaseDate = null;
126     var modifiedDate = null;
127     var size;
128     var description = null;
129     var rating;
130     var isFavorite;
131
132     Object.defineProperties(this, {
133         editableAttributes: {
134             get: function () {
135                 privUtils_.deprecationWarn(
136                     'editableAttributes is deprecated since Tizen 9.0 with no replacement.',
137                     '9.0'
138                 );
139                 return editableAttributes;
140             },
141             set: function () { },
142             enumerable: true,
143             configurable: true
144         },
145         id: {
146             get: function() {
147                 return id;
148             },
149             set: function(v) {
150                 if (edit_.isAllowed) {
151                     id = converter_.toString(v, false);
152                 }
153             },
154             enumerable: true
155         },
156         name: {
157             get: function() {
158                 return name;
159             },
160             set: function(v) {
161                 // since 5.5 this attribute is readonly, it is disallowed to modify it
162                 if (edit_.isAllowed) {
163                     if (!type_.isNull(v)) {
164                         name = converter_.toString(v, false);
165                     }
166                 } else {
167                     utils_.warn(
168                         'Since 5.5 "name" attribute is readonly, modifying it has no ' +
169                             'effect.'
170                     );
171                 }
172             },
173             enumerable: true
174         },
175         type: {
176             get: function() {
177                 return type;
178             },
179             set: function(v) {
180                 if (edit_.isAllowed) {
181                     type = converter_.toEnum(v, Object.keys(ContentType), false);
182                 }
183             },
184             enumerable: true
185         },
186         mimeType: {
187             get: function() {
188                 return mimeType;
189             },
190             set: function(v) {
191                 if (edit_.isAllowed) {
192                     mimeType = converter_.toString(v, false);
193                 }
194             },
195             enumerable: true
196         },
197         title: {
198             get: function() {
199                 return title;
200             },
201             set: function(v) {
202                 if (edit_.isAllowed) {
203                     title = converter_.toString(v, false);
204                 }
205             },
206             enumerable: true
207         },
208         contentURI: {
209             get: function() {
210                 return contentURI;
211             },
212             set: function(v) {
213                 if (edit_.isAllowed) {
214                     contentURI = convertPathToUri_(v);
215                 }
216             },
217             enumerable: true
218         },
219         thumbnailURIs: {
220             get: function() {
221                 return thumbnailURIs;
222             },
223             set: function(v) {
224                 if (edit_.isAllowed) {
225                     thumbnailURIs = converter_.toArray(v, true);
226                 }
227             },
228             enumerable: true
229         },
230         releaseDate: {
231             get: function() {
232                 privUtils_.deprecationWarn(
233                     'releaseDate is deprecated since Tizen 9.0 with no replacement.',
234                     '9.0'
235                 );
236                 return releaseDate;
237             },
238             set: function(v) {
239                 if (edit_.isAllowed) {
240                     releaseDate = v > 0 ? new Date(v * 1000) : null;
241                 }
242             },
243             enumerable: true
244         },
245         modifiedDate: {
246             get: function() {
247                 return modifiedDate;
248             },
249             set: function(v) {
250                 if (edit_.isAllowed) {
251                     modifiedDate = v > 0 ? new Date(v * 1000) : null;
252                 }
253             },
254             enumerable: true
255         },
256         size: {
257             get: function() {
258                 return size;
259             },
260             set: function(v) {
261                 if (edit_.isAllowed) {
262                     size = converter_.toUnsignedLong(v, false);
263                 }
264             },
265             enumerable: true
266         },
267         description: {
268             get: function() {
269                 privUtils_.deprecationWarn(
270                     'description is deprecated since Tizen 9.0 with no replacement.',
271                     '9.0'
272                 );
273                 return description;
274             },
275             set: function(v) {
276                 // since 5.5 this attribute is readonly, it is disallowed to modify it
277                 if (edit_.isAllowed) {
278                     description = converter_.toString(v, true);
279                 } else {
280                     utils_.warn(
281                         'Since 5.5 "description" attribute is readonly, modifying it ' +
282                             'has no effect.'
283                     );
284                 }
285             },
286             enumerable: true
287         },
288         rating: {
289             get: function() {
290                 privUtils_.deprecationWarn(
291                     'rating is deprecated since Tizen 9.0 with no replacement.',
292                     '9.0'
293                 );
294                 return rating;
295             },
296             set: function(v) {
297                 // since 5.5 this attribute is readonly, it is disallowed to modify it
298                 if (edit_.isAllowed) {
299                     if (!type_.isNull(v) && v >= 0 && v <= 10) {
300                         rating = converter_.toUnsignedLong(v, false);
301                     }
302                 } else {
303                     utils_.warn(
304                         'Since 5.5 "rating" attribute is readonly, modifying it has no ' +
305                             'effect.'
306                     );
307                 }
308             },
309             enumerable: true
310         },
311         isFavorite: {
312             get: function() {
313                 privUtils_.deprecationWarn(
314                     'isFavorite is deprecated since Tizen 9.0 with no replacement.',
315                     '9.0'
316                 );
317                 return isFavorite;
318             },
319             set: function(v) {
320                 privUtils_.deprecationWarn(
321                     'isFavorite is deprecated since Tizen 9.0 with no replacement.',
322                     '9.0'
323                 );
324                 if (!type_.isNull(v)) {
325                     isFavorite = converter_.toBoolean(v, false);
326                 }
327             },
328             enumerable: true
329         }
330     });
331
332     if (type_.isObject(data)) {
333         // fill object with data
334         edit_.allow();
335         for (var key in data) {
336             if (data.hasOwnProperty(key) && this.hasOwnProperty(key)) {
337                 this[key] = data[key];
338             }
339         }
340         edit_.disallow();
341     }
342 }
343
344 function VideoContent(data) {
345     Content.call(this, data);
346
347     var editableAttributes = this.editableAttributes;
348     var geolocation;
349     var album;
350     var artists;
351     var duration;
352     var width;
353     var height;
354
355     Object.defineProperties(this, {
356         editableAttributes: {
357             get: function () {
358                 privUtils_.deprecationWarn(
359                     'editableAttributes is deprecated since Tizen 9.0 with no replacement.',
360                     '9.0'
361                 );
362                 return editableAttributes;
363             },
364             set: function () { },
365             enumerable: true,
366             configurable: true
367         },
368         geolocation: {
369             get: function() {
370                 privUtils_.deprecationWarn(
371                     'geolocation is deprecated since Tizen 9.0 with no replacement.',
372                     '9.0'
373                 );
374                 // for keep geolocation's latitude and longitude readonly
375                 // we need to return copy of this object
376                 return new tizen.SimpleCoordinates(
377                     geolocation.latitude,
378                     geolocation.longitude
379                 );
380             },
381             set: function(v) {
382                 // since 5.5 this attribute is readonly, it is disallowed to modify it
383                 if (edit_.isAllowed) {
384                     if (!type_.isNull(v)) {
385                         var latitude = converter_.toDouble(v.latitude, false);
386                         var longitude = converter_.toDouble(v.longitude, false);
387                         geolocation = new tizen.SimpleCoordinates(latitude, longitude);
388                     }
389                 } else {
390                     utils_.warn(
391                         'Since 5.5 "geolocation" attribute is readonly, modifying it ' +
392                             'has no effect.'
393                     );
394                 }
395             },
396             enumerable: true
397         },
398         album: {
399             get: function() {
400                 privUtils_.deprecationWarn(
401                     'album is deprecated since Tizen 9.0 with no replacement.',
402                     '9.0'
403                 );
404                 return album;
405             },
406             set: function(v) {
407                 if (edit_.isAllowed) {
408                     album = converter_.toString(v, false);
409                 }
410             },
411             enumerable: true
412         },
413         artists: {
414             get: function () {
415                 privUtils_.deprecationWarn(
416                     'artists is deprecated since Tizen 9.0 with no replacement.',
417                     '9.0'
418                 );
419                 return artists;
420             },
421             set: function(v) {
422                 if (edit_.isAllowed) {
423                     artists = converter_.toArray(v, true);
424                 }
425             },
426             enumerable: true
427         },
428         duration: {
429             get: function() {
430                 privUtils_.deprecationWarn(
431                     'duration is deprecated since Tizen 9.0 with no replacement.',
432                     '9.0'
433                 );
434                 return duration;
435             },
436             set: function(v) {
437                 if (edit_.isAllowed) {
438                     duration = converter_.toUnsignedLong(v, false);
439                 }
440             },
441             enumerable: true
442         },
443         width: {
444             get: function() {
445                 privUtils_.deprecationWarn(
446                     'width is deprecated since Tizen 9.0 with no replacement.',
447                     '9.0'
448                 );
449                 return width;
450             },
451             set: function(v) {
452                 if (edit_.isAllowed) {
453                     width = converter_.toUnsignedLong(v, false);
454                 }
455             },
456             enumerable: true
457         },
458         height: {
459             get: function() {
460                 privUtils_.deprecationWarn(
461                     'height is deprecated since Tizen 9.0 with no replacement.',
462                     '9.0'
463                 );
464                 return height;
465             },
466             set: function(v) {
467                 if (edit_.isAllowed) {
468                     height = converter_.toUnsignedLong(v, false);
469                 }
470             },
471             enumerable: true
472         }
473     });
474
475     if (type_.isObject(data)) {
476         // fill object with data
477         edit_.allow();
478         for (var key in data) {
479             if (data.hasOwnProperty(key) && this.hasOwnProperty(key)) {
480                 this[key] = data[key];
481             }
482         }
483         edit_.disallow();
484     }
485 }
486
487 VideoContent.prototype = new Content();
488 VideoContent.prototype.constructor = VideoContent;
489
490 function AudioContentLyrics(data) {
491     var type;
492     var timestamps;
493     var texts;
494
495     Object.defineProperties(this, {
496         type: {
497             get: function() {
498                 return type;
499             },
500             set: function(v) {
501                 if (edit_.isAllowed) {
502                     type = converter_.toEnum(
503                         v,
504                         Object.keys(AudioContentLyricsType),
505                         false
506                     );
507                 }
508             },
509             enumerable: true
510         },
511         timestamps: {
512             get: function() {
513                 return timestamps;
514             },
515             set: function(v) {
516                 if (edit_.isAllowed) {
517                     timestamps = converter_.toArray(v, true);
518                 }
519             },
520             enumerable: true
521         },
522         texts: {
523             get: function() {
524                 return texts;
525             },
526             set: function(v) {
527                 if (edit_.isAllowed) {
528                     texts = converter_.toArray(v, false);
529                 }
530             },
531             enumerable: true
532         }
533     });
534
535     if (type_.isObject(data)) {
536         // fill object with data
537         edit_.allow();
538         for (var key in data) {
539             if (data.hasOwnProperty(key) && this.hasOwnProperty(key)) {
540                 this[key] = data[key];
541             }
542         }
543         edit_.disallow();
544     }
545 }
546
547 function AudioContent(data) {
548     Content.call(this, data);
549
550     var album;
551     var genres;
552     var artists;
553     var composers;
554     var lyrics;
555     var copyright;
556     var bitrate;
557     var trackNumber;
558     var duration;
559
560     var getLyrics = function() {
561         var data = {
562             contentURI: convertUriToPath_(this.contentURI)
563         };
564
565         var result = native_.callSync('ContentManagerAudioGetLyrics', data);
566
567         if (native_.isFailure(result)) {
568             utils_.log('Getting lyrics failed for ' + data.contentURI);
569             var error_object = native_.getErrorObject(result);
570             if (WebAPIException.SECURITY_ERR == error_object.code) {
571                 throw error_object;
572             }
573             return;
574         }
575
576         return new AudioContentLyrics(native_.getResultObject(result));
577     }.bind(this);
578
579     Object.defineProperties(this, {
580         album: {
581             get: function() {
582                 return album;
583             },
584             set: function(v) {
585                 if (edit_.isAllowed) {
586                     album = converter_.toString(v, false);
587                 }
588             },
589             enumerable: true
590         },
591         genres: {
592             get: function() {
593                 return genres;
594             },
595             set: function(v) {
596                 if (edit_.isAllowed) {
597                     genres = converter_.toArray(v, true);
598                 }
599             },
600             enumerable: true
601         },
602         artists: {
603             get: function() {
604                 return artists;
605             },
606             set: function(v) {
607                 if (edit_.isAllowed) {
608                     artists = converter_.toArray(v, true);
609                 }
610             },
611             enumerable: true
612         },
613         composers: {
614             get: function() {
615                 privUtils_.deprecationWarn(
616                     'composers is deprecated since Tizen 9.0 with no replacement.',
617                     '9.0'
618                 );
619                 return composers;
620             },
621             set: function(v) {
622                 if (edit_.isAllowed) {
623                     composers = converter_.toArray(v, true);
624                 }
625             },
626             enumerable: true
627         },
628         lyrics: {
629             get: function() {
630                 if (lyrics === undefined) {
631                     lyrics = getLyrics();
632                 }
633                 return lyrics;
634             },
635             set: function(v) {
636                 if (edit_.isAllowed && type_.isObject(v)) {
637                     lyrics = new AudioContentLyrics(v);
638                 }
639             },
640             enumerable: true
641         },
642         copyright: {
643             get: function() {
644                 privUtils_.deprecationWarn(
645                     'copyright is deprecated since Tizen 9.0 with no replacement.',
646                     '9.0'
647                 );
648                 return copyright;
649             },
650             set: function(v) {
651                 if (edit_.isAllowed) {
652                     copyright = converter_.toString(v, false);
653                 }
654             },
655             enumerable: true
656         },
657         bitrate: {
658             get: function() {
659                 privUtils_.deprecationWarn(
660                     'bitrate is deprecated since Tizen 9.0 with no replacement.',
661                     '9.0'
662                 );
663                 return bitrate;
664             },
665             set: function(v) {
666                 if (edit_.isAllowed) {
667                     bitrate = converter_.toUnsignedLong(v, false);
668                 }
669             },
670             enumerable: true
671         },
672         trackNumber: {
673             get: function() {
674                 return trackNumber;
675             },
676             set: function(v) {
677                 if (edit_.isAllowed) {
678                     trackNumber = converter_.toUnsignedLong(v, false);
679                 }
680             },
681             enumerable: true
682         },
683         duration: {
684             get: function() {
685                 privUtils_.deprecationWarn(
686                     'duration is deprecated since Tizen 9.0 with no replacement.',
687                     '9.0'
688                 );
689                 return duration;
690             },
691             set: function(v) {
692                 if (edit_.isAllowed) {
693                     duration = converter_.toUnsignedLong(v, false);
694                 }
695             },
696             enumerable: true
697         }
698     });
699
700     if (type_.isObject(data)) {
701         // fill object with data
702         edit_.allow();
703         for (var key in data) {
704             if (data.hasOwnProperty(key) && this.hasOwnProperty(key)) {
705                 this[key] = data[key];
706             }
707         }
708         edit_.disallow();
709     }
710 }
711
712 AudioContent.prototype = new Content();
713 AudioContent.prototype.constructor = AudioContent;
714
715 function ImageContent(data) {
716     Content.call(this, data);
717
718     var editableAttributes = this.editableAttributes;
719     var geolocation;
720     var width;
721     var height;
722     var orientation;
723
724     Object.defineProperties(this, {
725         editableAttributes: {
726             get: function () {
727                 privUtils_.deprecationWarn(
728                     'editableAttributes is deprecated since Tizen 9.0 with no replacement.',
729                     '9.0'
730                 );
731                 return editableAttributes;
732             },
733             set: function () { },
734             enumerable: true,
735             configurable: true
736         },
737         geolocation: {
738             get: function() {
739                 privUtils_.deprecationWarn(
740                     'geolocation is deprecated since Tizen 9.0 with no replacement.',
741                     '9.0'
742                 );
743                 // for keep geolocation's latitude and longitude readonly
744                 // we need to return copy of this object
745                 return new tizen.SimpleCoordinates(
746                     geolocation.latitude,
747                     geolocation.longitude
748                 );
749             },
750             set: function(v) {
751                 // since 5.5 this attribute is readonly, it is disallowed to modify it
752                 if (edit_.isAllowed) {
753                     if (!type_.isNull(v)) {
754                         var latitude = converter_.toDouble(v.latitude, false);
755                         var longitude = converter_.toDouble(v.longitude, false);
756                         geolocation = new tizen.SimpleCoordinates(latitude, longitude);
757                     }
758                 } else {
759                     utils_.warn(
760                         'Since 5.5 "geolocation" attribute is readonly, modifying it ' +
761                             'has no effect.'
762                     );
763                 }
764             },
765             enumerable: true
766         },
767         width: {
768             get: function() {
769                 return width;
770             },
771             set: function(v) {
772                 if (edit_.isAllowed) {
773                     width = converter_.toUnsignedLong(v, false);
774                 }
775             },
776             enumerable: true
777         },
778         height: {
779             get: function() {
780                 return height;
781             },
782             set: function(v) {
783                 if (edit_.isAllowed) {
784                     height = converter_.toUnsignedLong(v, false);
785                 }
786             },
787             enumerable: true
788         },
789         orientation: {
790             get: function() {
791                 return orientation;
792             },
793             set: function(v) {
794                 // since 5.5 this attribute is readonly, it is disallowed to modify it
795                 if (edit_.isAllowed) {
796                     if (!type_.isNull(v)) {
797                         orientation = converter_.toEnum(
798                             v,
799                             Object.keys(ImageContentOrientation),
800                             false
801                         );
802                     }
803                 } else {
804                     utils_.warn(
805                         'Since 5.5 "orientation" attribute is readonly, modifying it ' +
806                             'has no effect.'
807                     );
808                 }
809             },
810             enumerable: true
811         }
812     });
813
814     if (type_.isObject(data)) {
815         // fill object with data
816         edit_.allow();
817         for (var key in data) {
818             if (data.hasOwnProperty(key) && this.hasOwnProperty(key)) {
819                 this[key] = data[key];
820             }
821         }
822         edit_.disallow();
823     }
824 }
825
826 ImageContent.prototype = new Content();
827 ImageContent.prototype.constructor = ImageContent;
828
829 function PlaylistItem(data) {
830     var content = data;
831
832     Object.defineProperties(this, {
833         content: {
834             get: function() {
835                 return content;
836             },
837             set: function(v) {
838                 if (edit_.isAllowed && v instanceof Content) {
839                     content = v;
840                 }
841             },
842             enumerable: true
843         }
844     });
845 }