2 * Copyright 2012 Samsung Electronics Co., Ltd
4 * Licensed under the Flora License, Version 1.1 (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
8 * http://floralicense.org/license
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.
17 var gMediaSource, gMediaFolders, gMediaItems, gItemId, gFolderId, gMediaType = "ALL";
18 var gStorageType, flagInit;
20 $(document).delegate("#main", "pageinit", function() {
21 var highlightStoragetype = function (storageType) {
22 $("#folder-list li").each(function(){
23 $(this).removeClass("storagetypeHighlight");
25 if (storageType == "ALL") $("#folder-type-all").addClass("storagetypeHighlight");
26 else if (storageType == "INTERNAL") $("#folder-type-internal").addClass("storagetypeHighlight");
27 else if (storageType == "EXTERNAL") $("#folder-type-external").addClass("storagetypeHighlight");
32 gStorageType = gMediaType;
34 $("#folder-type-all").bind("vclick", function() {
35 showFolderList("ALL");
36 highlightStoragetype("ALL");
39 $("#folder-type-internal").bind("vclick", function() {
40 showFolderList("INTERNAL");
41 highlightStoragetype("INTERNAL");
44 $("#folder-type-external").bind("vclick", function() {
45 showFolderList("EXTERNAL");
46 highlightStoragetype("EXTERNAL");
52 $(document).delegate("#items", "pageinit", function() {
53 $("#items").bind("pagebeforeshow", showItemList);
55 $("#items-list input").bind("change", function() {
56 if ($(this).prop("checked") == true) {
57 gMediaType = $(this).attr("value");
58 getFolderItems(gFolderId, gMediaType);
62 $("#items-list").delegate("li", "vclick", function() {
63 var id = $(this).data("id");
66 $.mobile.changePage("#detail");
72 $(document).delegate("#detail", "pageinit", function() {
73 $("#detail").bind("pagebeforeshow", showMediaDetail);
76 $(window).on('tizenhwkey', function (e) {
77 if (e.originalEvent.keyName === "back") {
78 if ($.mobile.activePage.attr('id') === 'main') {
79 tizen.application.getCurrentApplication().exit();
86 function setLastStorage(storageType) {
87 gStorageType = storageType;
90 function makeListItem(id, mainText, subText) {
91 return '<li class="ui-li-has-multiline ui-li-text-ellipsis"'
92 + (id == null ? '' : ' data-id="'+ id +'"')
95 + '<span class="ui-li-text-sub">'
100 function getFolders (storageType) {
102 gMediaSource = tizen.content;
103 gMediaSource.getDirectories(onGetFoldersSuccess, onGetFoldersError);
105 alert("getLocalMediaSource exc:" + exc.message);
108 function onGetFoldersSuccess(folders) {
109 $("#file-list").delegate("li", "vclick", function() {
110 var id = $(this).data("id");
112 getFolderItems(Number(id), gMediaType);
117 gMediaFolders = folders;
118 showFolderList(storageType);
121 function onGetFoldersError(err) {
122 alert("GetFolders failed:" + err.message);
128 function onContentChange() {
129 tizen.systeminfo.addPropertyValueChangeListener('STORAGE', function() {
130 getFolders(gStorageType);
134 function showFolderList(storageType) {
135 setLastStorage(storageType);
137 if(flagInit == false){
138 getFolders(storageType);
142 for (var i = 0; i < gMediaFolders.length; i++) {
143 if (storageType == "ALL" || storageType == gMediaFolders[i].storageType) {
144 str += makeListItem(i, gMediaFolders[i].title, gMediaFolders[i].directoryURI);
147 $("#file-list").empty().hide().append(str).listview("refresh").show();
152 function showItemList() {
154 var title = gMediaFolders[gFolderId].title;
156 $("#items-title").html(gFolderId == null ? "All" : title.toString());
158 for (var i = 0; i < gMediaItems.length; i++) {
159 str += makeListItem(i, gMediaItems[i].title,
160 gMediaItems[i].type + " Rating: " + gMediaItems[i].rating);
163 $("#items-list>li[data-id]").remove();
164 $("#items-list").append(str).trigger("create").listview("refresh");
167 function getFolderItems(folderId, mediaType) {
168 function onFindItemsSuccess(items) {
170 gFolderId = folderId;
171 gMediaType = mediaType;
173 if($.mobile.activePage.attr("id") == "items") {
176 $.mobile.changePage("#items");
180 function onFindItemsError(err) {
181 alert("getFolderItems findItems failed: " + err.message);
185 gMediaSource.find(onFindItemsSuccess, onFindItemsError,
186 folderId == null ? null : gMediaFolders[folderId].id,
187 mediaType == "ALL" ? null : new tizen.AttributeFilter("type", "EXACTLY", mediaType),
188 new tizen.SortMode("title", "ASC"));
190 //alert("findItems exc:" + exc.message);
194 function makeCommonPropertiesListItems(item) {
195 return makeListItem(null, "Title", item.title)
196 + makeListItem(null, "Size", item.size + " Bytes")
197 + makeListItem(null, "Type", item.type)
198 + makeListItem(null, "Identifier", item.id)
199 + makeListItem(null, "Item URI", item.contentURI)
200 + makeListItem(null, "MIME type", item.mimeType)
201 + makeListItem(null, "Modified date", item.modifiedDate)
202 + makeListItem(null, "Description", item.description)
203 + makeListItem(null, "Rating", item.rating);
206 function showMediaDetail() {
207 var str, item = gMediaItems[gItemId];
208 if (item.type == "IMAGE") {
209 str = makeCommonPropertiesListItems(item)
210 + makeListItem(null, "Width", item.width)
211 + makeListItem(null, "Height", item.height);
212 if (item.geolocation) {
213 str += makeListItem(null, "Latitude", item.geolocation.latitude)
214 + makeListItem(null, "Longitude", item.geolocation.longitude);
216 } else if (item.type == "VIDEO") {
217 str = makeCommonPropertiesListItems(item)
218 + makeListItem(null, "Width", item.width)
219 + makeListItem(null, "Height", item.height)
220 + makeListItem(null, "Album", item.album)
221 + makeListItem(null, "Artist", item.artists[0])
222 + makeListItem(null, "Duration", item.duration + " Milliseconds");
223 } else if (item.type == "AUDIO") {
224 str = makeCommonPropertiesListItems(item)
225 + makeListItem(null, "Album", item.album)
226 + makeListItem(null, "Artist", item.artists[0])
227 + makeListItem(null, "Composer", item.composers[0])
228 + makeListItem(null, "Genre", item.genres[0])
229 + makeListItem(null, "Copyright", item.copyright)
230 + makeListItem(null, "Bitrate", item.bitrate + " Bps")
231 + makeListItem(null, "Track number", item.trackNumber)
232 + makeListItem(null, "Duration", item.duration + " Milliseconds");
234 str = makeCommonPropertiesListItems(item);
237 $("#media-details").html(str).trigger("create").listview("refresh");