[Content] Add deprecation to some not frequently used members
[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         },
144         id: {
145             get: function() {
146                 return id;
147             },
148             set: function(v) {
149                 if (edit_.isAllowed) {
150                     id = converter_.toString(v, false);
151                 }
152             },
153             enumerable: true
154         },
155         name: {
156             get: function() {
157                 return name;
158             },
159             set: function(v) {
160                 // since 5.5 this attribute is readonly, it is disallowed to modify it
161                 if (edit_.isAllowed) {
162                     if (!type_.isNull(v)) {
163                         name = converter_.toString(v, false);
164                     }
165                 } else {
166                     utils_.warn(
167                         'Since 5.5 "name" attribute is readonly, modifying it has no ' +
168                             'effect.'
169                     );
170                 }
171             },
172             enumerable: true
173         },
174         type: {
175             get: function() {
176                 return type;
177             },
178             set: function(v) {
179                 if (edit_.isAllowed) {
180                     type = converter_.toEnum(v, Object.keys(ContentType), false);
181                 }
182             },
183             enumerable: true
184         },
185         mimeType: {
186             get: function() {
187                 return mimeType;
188             },
189             set: function(v) {
190                 if (edit_.isAllowed) {
191                     mimeType = converter_.toString(v, false);
192                 }
193             },
194             enumerable: true
195         },
196         title: {
197             get: function() {
198                 return title;
199             },
200             set: function(v) {
201                 if (edit_.isAllowed) {
202                     title = converter_.toString(v, false);
203                 }
204             },
205             enumerable: true
206         },
207         contentURI: {
208             get: function() {
209                 return contentURI;
210             },
211             set: function(v) {
212                 if (edit_.isAllowed) {
213                     contentURI = convertPathToUri_(v);
214                 }
215             },
216             enumerable: true
217         },
218         thumbnailURIs: {
219             get: function() {
220                 return thumbnailURIs;
221             },
222             set: function(v) {
223                 if (edit_.isAllowed) {
224                     thumbnailURIs = converter_.toArray(v, true);
225                 }
226             },
227             enumerable: true
228         },
229         releaseDate: {
230             get: function() {
231                 privUtils_.deprecationWarn(
232                     'releaseDate is deprecated since Tizen 9.0 with no replacement.',
233                     '9.0'
234                 );
235                 return releaseDate;
236             },
237             set: function(v) {
238                 if (edit_.isAllowed) {
239                     releaseDate = v > 0 ? new Date(v * 1000) : null;
240                 }
241             },
242             enumerable: true
243         },
244         modifiedDate: {
245             get: function() {
246                 return modifiedDate;
247             },
248             set: function(v) {
249                 if (edit_.isAllowed) {
250                     modifiedDate = v > 0 ? new Date(v * 1000) : null;
251                 }
252             },
253             enumerable: true
254         },
255         size: {
256             get: function() {
257                 return size;
258             },
259             set: function(v) {
260                 if (edit_.isAllowed) {
261                     size = converter_.toUnsignedLong(v, false);
262                 }
263             },
264             enumerable: true
265         },
266         description: {
267             get: function() {
268                 privUtils_.deprecationWarn(
269                     'description is deprecated since Tizen 9.0 with no replacement.',
270                     '9.0'
271                 );
272                 return description;
273             },
274             set: function(v) {
275                 // since 5.5 this attribute is readonly, it is disallowed to modify it
276                 if (edit_.isAllowed) {
277                     description = converter_.toString(v, true);
278                 } else {
279                     utils_.warn(
280                         'Since 5.5 "description" attribute is readonly, modifying it ' +
281                             'has no effect.'
282                     );
283                 }
284             },
285             enumerable: true
286         },
287         rating: {
288             get: function() {
289                 privUtils_.deprecationWarn(
290                     'rating is deprecated since Tizen 9.0 with no replacement.',
291                     '9.0'
292                 );
293                 return rating;
294             },
295             set: function(v) {
296                 // since 5.5 this attribute is readonly, it is disallowed to modify it
297                 if (edit_.isAllowed) {
298                     if (!type_.isNull(v) && v >= 0 && v <= 10) {
299                         rating = converter_.toUnsignedLong(v, false);
300                     }
301                 } else {
302                     utils_.warn(
303                         'Since 5.5 "rating" attribute is readonly, modifying it has no ' +
304                             'effect.'
305                     );
306                 }
307             },
308             enumerable: true
309         },
310         isFavorite: {
311             get: function() {
312                 privUtils_.deprecationWarn(
313                     'isFavorite is deprecated since Tizen 9.0 with no replacement.',
314                     '9.0'
315                 );
316                 return isFavorite;
317             },
318             set: function(v) {
319                 privUtils_.deprecationWarn(
320                     'isFavorite is deprecated since Tizen 9.0 with no replacement.',
321                     '9.0'
322                 );
323                 if (!type_.isNull(v)) {
324                     isFavorite = converter_.toBoolean(v, false);
325                 }
326             },
327             enumerable: true
328         }
329     });
330
331     if (type_.isObject(data)) {
332         // fill object with data
333         edit_.allow();
334         for (var key in data) {
335             if (data.hasOwnProperty(key) && this.hasOwnProperty(key)) {
336                 this[key] = data[key];
337             }
338         }
339         edit_.disallow();
340     }
341 }
342
343 function VideoContent(data) {
344     Content.call(this, data);
345
346     var editableAttributes = this.editableAttributes;
347     var geolocation;
348     var album;
349     var artists;
350     var duration;
351     var width;
352     var height;
353
354     Object.defineProperties(this, {
355         editableAttributes: {
356             get: function () {
357                 privUtils_.deprecationWarn(
358                     'editableAttributes is deprecated since Tizen 9.0 with no replacement.',
359                     '9.0'
360                 );
361                 return editableAttributes;
362             },
363             set: function () { },
364             enumerable: true
365         },
366         geolocation: {
367             get: function() {
368                 privUtils_.deprecationWarn(
369                     'geolocation is deprecated since Tizen 9.0 with no replacement.',
370                     '9.0'
371                 );
372                 // for keep geolocation's latitude and longitude readonly
373                 // we need to return copy of this object
374                 return new tizen.SimpleCoordinates(
375                     geolocation.latitude,
376                     geolocation.longitude
377                 );
378             },
379             set: function(v) {
380                 // since 5.5 this attribute is readonly, it is disallowed to modify it
381                 if (edit_.isAllowed) {
382                     if (!type_.isNull(v)) {
383                         var latitude = converter_.toDouble(v.latitude, false);
384                         var longitude = converter_.toDouble(v.longitude, false);
385                         geolocation = new tizen.SimpleCoordinates(latitude, longitude);
386                     }
387                 } else {
388                     utils_.warn(
389                         'Since 5.5 "geolocation" attribute is readonly, modifying it ' +
390                             'has no effect.'
391                     );
392                 }
393             },
394             enumerable: true
395         },
396         album: {
397             get: function() {
398                 privUtils_.deprecationWarn(
399                     'album is deprecated since Tizen 9.0 with no replacement.',
400                     '9.0'
401                 );
402                 return album;
403             },
404             set: function(v) {
405                 if (edit_.isAllowed) {
406                     album = converter_.toString(v, false);
407                 }
408             },
409             enumerable: true
410         },
411         artists: {
412             get: function () {
413                 privUtils_.deprecationWarn(
414                     'artists is deprecated since Tizen 9.0 with no replacement.',
415                     '9.0'
416                 );
417                 return artists;
418             },
419             set: function(v) {
420                 if (edit_.isAllowed) {
421                     artists = converter_.toArray(v, true);
422                 }
423             },
424             enumerable: true
425         },
426         duration: {
427             get: function() {
428                 privUtils_.deprecationWarn(
429                     'duration is deprecated since Tizen 9.0 with no replacement.',
430                     '9.0'
431                 );
432                 return duration;
433             },
434             set: function(v) {
435                 if (edit_.isAllowed) {
436                     duration = converter_.toUnsignedLong(v, false);
437                 }
438             },
439             enumerable: true
440         },
441         width: {
442             get: function() {
443                 privUtils_.deprecationWarn(
444                     'width is deprecated since Tizen 9.0 with no replacement.',
445                     '9.0'
446                 );
447                 return width;
448             },
449             set: function(v) {
450                 if (edit_.isAllowed) {
451                     width = converter_.toUnsignedLong(v, false);
452                 }
453             },
454             enumerable: true
455         },
456         height: {
457             get: function() {
458                 privUtils_.deprecationWarn(
459                     'height is deprecated since Tizen 9.0 with no replacement.',
460                     '9.0'
461                 );
462                 return height;
463             },
464             set: function(v) {
465                 if (edit_.isAllowed) {
466                     height = converter_.toUnsignedLong(v, false);
467                 }
468             },
469             enumerable: true
470         }
471     });
472
473     if (type_.isObject(data)) {
474         // fill object with data
475         edit_.allow();
476         for (var key in data) {
477             if (data.hasOwnProperty(key) && this.hasOwnProperty(key)) {
478                 this[key] = data[key];
479             }
480         }
481         edit_.disallow();
482     }
483 }
484
485 VideoContent.prototype = new Content();
486 VideoContent.prototype.constructor = VideoContent;
487
488 function AudioContentLyrics(data) {
489     var type;
490     var timestamps;
491     var texts;
492
493     Object.defineProperties(this, {
494         type: {
495             get: function() {
496                 return type;
497             },
498             set: function(v) {
499                 if (edit_.isAllowed) {
500                     type = converter_.toEnum(
501                         v,
502                         Object.keys(AudioContentLyricsType),
503                         false
504                     );
505                 }
506             },
507             enumerable: true
508         },
509         timestamps: {
510             get: function() {
511                 return timestamps;
512             },
513             set: function(v) {
514                 if (edit_.isAllowed) {
515                     timestamps = converter_.toArray(v, true);
516                 }
517             },
518             enumerable: true
519         },
520         texts: {
521             get: function() {
522                 return texts;
523             },
524             set: function(v) {
525                 if (edit_.isAllowed) {
526                     texts = converter_.toArray(v, false);
527                 }
528             },
529             enumerable: true
530         }
531     });
532
533     if (type_.isObject(data)) {
534         // fill object with data
535         edit_.allow();
536         for (var key in data) {
537             if (data.hasOwnProperty(key) && this.hasOwnProperty(key)) {
538                 this[key] = data[key];
539             }
540         }
541         edit_.disallow();
542     }
543 }
544
545 function AudioContent(data) {
546     Content.call(this, data);
547
548     var album;
549     var genres;
550     var artists;
551     var composers;
552     var lyrics;
553     var copyright;
554     var bitrate;
555     var trackNumber;
556     var duration;
557
558     var getLyrics = function() {
559         var data = {
560             contentURI: convertUriToPath_(this.contentURI)
561         };
562
563         var result = native_.callSync('ContentManagerAudioGetLyrics', data);
564
565         if (native_.isFailure(result)) {
566             utils_.log('Getting lyrics failed for ' + data.contentURI);
567             var error_object = native_.getErrorObject(result);
568             if (WebAPIException.SECURITY_ERR == error_object.code) {
569                 throw error_object;
570             }
571             return;
572         }
573
574         return new AudioContentLyrics(native_.getResultObject(result));
575     }.bind(this);
576
577     Object.defineProperties(this, {
578         album: {
579             get: function() {
580                 return album;
581             },
582             set: function(v) {
583                 if (edit_.isAllowed) {
584                     album = converter_.toString(v, false);
585                 }
586             },
587             enumerable: true
588         },
589         genres: {
590             get: function() {
591                 return genres;
592             },
593             set: function(v) {
594                 if (edit_.isAllowed) {
595                     genres = converter_.toArray(v, true);
596                 }
597             },
598             enumerable: true
599         },
600         artists: {
601             get: function() {
602                 return artists;
603             },
604             set: function(v) {
605                 if (edit_.isAllowed) {
606                     artists = converter_.toArray(v, true);
607                 }
608             },
609             enumerable: true
610         },
611         composers: {
612             get: function() {
613                 privUtils_.deprecationWarn(
614                     'composers is deprecated since Tizen 9.0 with no replacement.',
615                     '9.0'
616                 );
617                 return composers;
618             },
619             set: function(v) {
620                 if (edit_.isAllowed) {
621                     composers = converter_.toArray(v, true);
622                 }
623             },
624             enumerable: true
625         },
626         lyrics: {
627             get: function() {
628                 if (lyrics === undefined) {
629                     lyrics = getLyrics();
630                 }
631                 return lyrics;
632             },
633             set: function(v) {
634                 if (edit_.isAllowed && type_.isObject(v)) {
635                     lyrics = new AudioContentLyrics(v);
636                 }
637             },
638             enumerable: true
639         },
640         copyright: {
641             get: function() {
642                 privUtils_.deprecationWarn(
643                     'copyright is deprecated since Tizen 9.0 with no replacement.',
644                     '9.0'
645                 );
646                 return copyright;
647             },
648             set: function(v) {
649                 if (edit_.isAllowed) {
650                     copyright = converter_.toString(v, false);
651                 }
652             },
653             enumerable: true
654         },
655         bitrate: {
656             get: function() {
657                 privUtils_.deprecationWarn(
658                     'bitrate is deprecated since Tizen 9.0 with no replacement.',
659                     '9.0'
660                 );
661                 return bitrate;
662             },
663             set: function(v) {
664                 if (edit_.isAllowed) {
665                     bitrate = converter_.toUnsignedLong(v, false);
666                 }
667             },
668             enumerable: true
669         },
670         trackNumber: {
671             get: function() {
672                 return trackNumber;
673             },
674             set: function(v) {
675                 if (edit_.isAllowed) {
676                     trackNumber = converter_.toUnsignedLong(v, false);
677                 }
678             },
679             enumerable: true
680         },
681         duration: {
682             get: function() {
683                 privUtils_.deprecationWarn(
684                     'duration is deprecated since Tizen 9.0 with no replacement.',
685                     '9.0'
686                 );
687                 return duration;
688             },
689             set: function(v) {
690                 if (edit_.isAllowed) {
691                     duration = converter_.toUnsignedLong(v, false);
692                 }
693             },
694             enumerable: true
695         }
696     });
697
698     if (type_.isObject(data)) {
699         // fill object with data
700         edit_.allow();
701         for (var key in data) {
702             if (data.hasOwnProperty(key) && this.hasOwnProperty(key)) {
703                 this[key] = data[key];
704             }
705         }
706         edit_.disallow();
707     }
708 }
709
710 AudioContent.prototype = new Content();
711 AudioContent.prototype.constructor = AudioContent;
712
713 function ImageContent(data) {
714     Content.call(this, data);
715
716     var editableAttributes = this.editableAttributes;
717     var geolocation;
718     var width;
719     var height;
720     var orientation;
721
722     Object.defineProperties(this, {
723         editableAttributes: {
724             get: function () {
725                 privUtils_.deprecationWarn(
726                     'editableAttributes is deprecated since Tizen 9.0 with no replacement.',
727                     '9.0'
728                 );
729                 return editableAttributes;
730             },
731             set: function () { },
732             enumerable: true
733         },
734         geolocation: {
735             get: function() {
736                 privUtils_.deprecationWarn(
737                     'geolocation is deprecated since Tizen 9.0 with no replacement.',
738                     '9.0'
739                 );
740                 // for keep geolocation's latitude and longitude readonly
741                 // we need to return copy of this object
742                 return new tizen.SimpleCoordinates(
743                     geolocation.latitude,
744                     geolocation.longitude
745                 );
746             },
747             set: function(v) {
748                 // since 5.5 this attribute is readonly, it is disallowed to modify it
749                 if (edit_.isAllowed) {
750                     if (!type_.isNull(v)) {
751                         var latitude = converter_.toDouble(v.latitude, false);
752                         var longitude = converter_.toDouble(v.longitude, false);
753                         geolocation = new tizen.SimpleCoordinates(latitude, longitude);
754                     }
755                 } else {
756                     utils_.warn(
757                         'Since 5.5 "geolocation" attribute is readonly, modifying it ' +
758                             'has no effect.'
759                     );
760                 }
761             },
762             enumerable: true
763         },
764         width: {
765             get: function() {
766                 return width;
767             },
768             set: function(v) {
769                 if (edit_.isAllowed) {
770                     width = converter_.toUnsignedLong(v, false);
771                 }
772             },
773             enumerable: true
774         },
775         height: {
776             get: function() {
777                 return height;
778             },
779             set: function(v) {
780                 if (edit_.isAllowed) {
781                     height = converter_.toUnsignedLong(v, false);
782                 }
783             },
784             enumerable: true
785         },
786         orientation: {
787             get: function() {
788                 return orientation;
789             },
790             set: function(v) {
791                 // since 5.5 this attribute is readonly, it is disallowed to modify it
792                 if (edit_.isAllowed) {
793                     if (!type_.isNull(v)) {
794                         orientation = converter_.toEnum(
795                             v,
796                             Object.keys(ImageContentOrientation),
797                             false
798                         );
799                     }
800                 } else {
801                     utils_.warn(
802                         'Since 5.5 "orientation" attribute is readonly, modifying it ' +
803                             'has no effect.'
804                     );
805                 }
806             },
807             enumerable: true
808         }
809     });
810
811     if (type_.isObject(data)) {
812         // fill object with data
813         edit_.allow();
814         for (var key in data) {
815             if (data.hasOwnProperty(key) && this.hasOwnProperty(key)) {
816                 this[key] = data[key];
817             }
818         }
819         edit_.disallow();
820     }
821 }
822
823 ImageContent.prototype = new Content();
824 ImageContent.prototype.constructor = ImageContent;
825
826 function PlaylistItem(data) {
827     var content = data;
828
829     Object.defineProperties(this, {
830         content: {
831             get: function() {
832                 return content;
833             },
834             set: function(v) {
835                 if (edit_.isAllowed && v instanceof Content) {
836                     content = v;
837                 }
838             },
839             enumerable: true
840         }
841     });
842 }