2 * Copyright 2012 Samsung Electronics Co., Ltd
4 * Licensed under the Flora License, Version 1.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
8 * http://www.tizenopensource.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";
19 $(document).delegate("#main", "pageinit", function() {
20 $("#main .ui-btn-back").bind("vclick", function() {
21 tizen.application.getCurrentApplication().exit();
25 $("#folder-list input").bind("change", function() {
26 if ($(this).prop("checked") == true) {
27 showFolderList($(this).attr("value"));
31 $("#folder-list").delegate("li", "vclick", function() {
32 var id = $(this).data("id");
34 getFolderItems(Number(id), gMediaType);
39 $("#all-items").bind("vclick", function() {
40 getFolderItems(null, gMediaType);
45 gMediaSource = tizen.content;
47 alert("getLocalMediaSource exc:" + exc.message);
53 $(document).delegate("#items", "pageinit", function() {
54 $("#items").bind("pagebeforeshow", showItemList);
56 $("#items-list input").bind("change", function() {
57 if ($(this).prop("checked") == true) {
58 gMediaType = $(this).attr("value");
59 getFolderItems(gFolderId, gMediaType);
63 $("#items-list").delegate("li", "vclick", function() {
64 var id = $(this).data("id");
67 $.mobile.changePage("#detail");
72 $("#batch-update").bind("vclick", function() {
78 $(document).delegate("#detail", "pageinit", function() {
79 $("#detail").bind("pagebeforeshow", showMediaDetail);
81 $("#update").bind("vclick", function() {
83 window.history.back();
88 function getFolders() {
89 function onGetFoldersSuccess(folders) {
90 gMediaFolders = folders;
91 showFolderList("ALL");
94 function onGetFoldersError(err) {
95 alert("GetFolders failed:" + err.message);
99 gMediaSource.getDirectories(onGetFoldersSuccess, onGetFoldersError);
101 alert("getFolders exc:" + exc.message);
105 function makeListItem(id, mainText, subText) {
106 return '<li class="ui-li-has-multiline ui-li-text-ellipsis"'
107 + (id == null ? '' : ' data-id="'+ id +'"')
110 + '<span class="ui-li-text-sub">'
115 function showFolderList(storageType) {
117 for (var i = 0; i < gMediaFolders.length; i++) {
118 if (storageType == "ALL" || storageType == gMediaFolders[i].storageType) {
119 str += makeListItem(i, gMediaFolders[i].title, gMediaFolders[i].folderURI);
122 $("#folder-list>li[data-id]").remove();
123 $("#folder-list").append(str).trigger("create").listview("refresh");
128 function showItemList() {
131 $("#items-title").html(gFolderId == null ? "All" : gMediaFolders[gFolderId].title);
133 for (var i = 0; i < gMediaItems.length; i++) {
134 str += makeListItem(i, gMediaItems[i].title,
135 gMediaItems[i].type + " Rating: " + gMediaItems[i].rating);
138 $("#items-list>li[data-id]").remove();
139 $("#items-list").append(str).trigger("create").listview("refresh");
142 function getFolderItems(folderId, mediaType) {
143 function onFindItemsSuccess(items) {
145 gFolderId = folderId;
146 gMediaType = mediaType;
148 if($.mobile.activePage.attr("id") == "items") {
151 $.mobile.changePage("#items");
155 function onFindItemsError(err) {
156 alert("getFolderItems findItems failed: " + err.message);
160 gMediaSource.find(onFindItemsSuccess, onFindItemsError,
161 folderId == null ? null : gMediaFolders[folderId].id,
162 mediaType == "ALL" ? null : new tizen.AttributeFilter("type", "EXACTLY", mediaType),
163 new tizen.SortMode("title", "ASC"));
165 //alert("findItems exc:" + exc.message);
169 function makeCommonPropertiesListItems(item) {
170 return makeListItem(null, "Title", item.title)
171 + makeListItem(null, "Size", item.size + " Bytes")
172 + makeListItem(null, "Type", item.type)
173 + makeListItem(null, "Identifier", item.id)
174 + makeListItem(null, "Item URI", item.contentURI)
175 + makeListItem(null, "MIME type", item.mimeType)
176 + makeListItem(null, "Release date", item.releaseDate)
177 + makeListItem(null, "Modified date", item.modifiedDate)
178 + makeListItem(null, "Description", item.description)
179 + makeListItem(null, "Rating", item.rating)
180 + makeListItem(null, "Thumbnail URI", item.thumbnailURIs[0]);
183 function showMediaDetail() {
184 var str, item = gMediaItems[gItemId];
186 if (item.type == "IMAGE") {
187 str = makeCommonPropertiesListItems(item)
188 + makeListItem(null, "Width", item.width)
189 + makeListItem(null, "Height", item.height)
190 + makeListItem(null, "Latitude", item.geolocation.latitude)
191 + makeListItem(null, "Longitude", item.geolocation.longitude);
192 } else if (item.type == "VIDEO") {
193 str = makeCommonPropertiesListItems(item)
194 + makeListItem(null, "Width", item.width)
195 + makeListItem(null, "Height", item.height)
196 + makeListItem(null, "Album", item.album)
197 + makeListItem(null, "Artist", item.artists[0])
198 + makeListItem(null, "Duration", item.duration + " Milliseconds");
199 } else if (item.type == "AUDIO") {
200 str = makeCommonPropertiesListItems(item)
201 + makeListItem(null, "Album", item.album)
202 + makeListItem(null, "Artist", item.artists[0])
203 + makeListItem(null, "Composer", item.composers[0])
204 + makeListItem(null, "Genre", item.genres[0])
205 + makeListItem(null, "Copyright", item.copyright)
206 + makeListItem(null, "Bitrate", item.bitrate + " Bps")
207 + makeListItem(null, "Track number", item.trackNumber)
208 + makeListItem(null, "Duration", item.duration + " Milliseconds");
210 alert("Invalid type");
213 $("#media-details").html(str).trigger("create").listview("refresh");
216 function updateRating() {
217 var item = gMediaItems[gItemId];
219 item.rating += 1; /* increase by 1 */
221 gMediaSource.update(item);
223 alert("updateItem exc: " + exc.message);
227 function updateLast3Ratings() {
228 function onSuccess() {
229 getFolderItems(gFolderId, gMediaType);
232 function onError(err) {
233 alert("updateItemsBatch failed:" + err.message);
238 for (var i = gMediaItems.length - 1, j = 0; i >= 0 && j < 3; i--, j++) {
239 gMediaItems[i].rating += 1;
240 itemArray.push(gMediaItems[i]);
244 gMediaSource.updateBatch(itemArray, onSuccess, onError);
246 alert("updateItemsBatch exc:" + exc.message);