2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 #include <dpl/log/log.h>
19 #include <CommonsJavaScript/PrivateObject.h>
20 #include <CommonsJavaScript/Converter.h>
21 #include <CommonsJavaScript/JSUtils.h>
22 #include <Tizen/Common/JSTizenException.h>
23 #include <Tizen/Common/JSTizenExceptionFactory.h>
26 #include "JSMediacontent.h"
31 namespace Mediacontent {
33 #define TIZEN_MEDIACONTENT_MEDIA_ATTRIBUTENAME "MediaItem"
34 #define TIZEN_MEDIACONTENT_MEDIA_UID "id"
35 #define TIZEN_MEDIACONTENT_MEDIA_TYPE "type"
36 #define TIZEN_MEDIACONTENT_MEDIA_MIME_TYPE "mimeType"
37 #define TIZEN_MEDIACONTENT_MEDIA_TITLE "title"
38 #define TIZEN_MEDIACONTENT_MEDIA_FILE_URL "fileURL"
39 #define TIZEN_MEDIACONTENT_MEDIA_THUMBNAILPATH "thumbnailPath"
40 #define TIZEN_MEDIACONTENT_MEDIA_CREATEDDATE "createdDate"
41 #define TIZEN_MEDIACONTENT_MEDIA_RELEASEDDATE "releasedDate"
42 #define TIZEN_MEDIACONTENT_MEDIA_MODIFIEDDATE "modifiedDate"
43 #define TIZEN_MEDIACONTENT_MEDIA_DESCRIPTION "description"
44 #define TIZEN_MEDIACONTENT_MEDIA_RATING "rating"
47 JSClassDefinition JSMedia::m_classInfo =
50 kJSClassAttributeNone,
51 TIZEN_MEDIACONTENT_MEDIA_ATTRIBUTENAME,
60 NULL, //DeleteProperty,
61 NULL, //GetPropertyNames,
62 NULL, //CallAsFunction,
63 NULL, //CallAsConstructor,
69 JSStaticValue JSMedia::m_property[] =
72 { TIZEN_MEDIACONTENT_MEDIA_UID, getPropertyId, NULL, kJSPropertyAttributeReadOnly},
73 { TIZEN_MEDIACONTENT_MEDIA_TYPE, getPropertyType , NULL, kJSPropertyAttributeReadOnly},
74 { TIZEN_MEDIACONTENT_MEDIA_MIME_TYPE, getPropertyMimeType , NULL, kJSPropertyAttributeReadOnly},
75 { TIZEN_MEDIACONTENT_MEDIA_TITLE, getPropertyDisplayName, NULL, kJSPropertyAttributeReadOnly},
76 { TIZEN_MEDIACONTENT_MEDIA_FILE_URL, getPropertyFilePath, NULL, kJSPropertyAttributeReadOnly},
77 { TIZEN_MEDIACONTENT_MEDIA_THUMBNAILPATH, getPropertyThumbnailPath, NULL, kJSPropertyAttributeReadOnly},
78 { TIZEN_MEDIACONTENT_MEDIA_CREATEDDATE, getPropertyCreatedDate, NULL, kJSPropertyAttributeReadOnly},
79 { TIZEN_MEDIACONTENT_MEDIA_RELEASEDDATE, getPropertyReleasedDate, NULL, kJSPropertyAttributeReadOnly},
80 { TIZEN_MEDIACONTENT_MEDIA_MODIFIEDDATE, getPropertyModifiedDate, NULL, kJSPropertyAttributeReadOnly},
81 { TIZEN_MEDIACONTENT_MEDIA_DESCRIPTION, getPropertyDescription, NULL, kJSPropertyAttributeReadOnly},
82 { TIZEN_MEDIACONTENT_MEDIA_RATING, getPropertyFavorite, setPropertyFavorite, kJSPropertyAttributeNone},
87 JSClassRef JSMedia::m_jsClassRef = JSClassCreate(JSMedia::getClassInfo());
89 void JSMedia::initialize(JSContextRef context, JSObjectRef object)
91 LogDebug( "entered" );
92 MediaPrivObject *priv = static_cast<MediaPrivObject*>( JSObjectGetPrivate( object ) );
95 MediacontentMediaPtr privateData(new MediacontentMedia());
96 priv = new MediaPrivObject(context, privateData);
97 JSObjectSetPrivate(object, static_cast<void*>(priv));
98 LogDebug("new event is created" );
102 LogDebug("private object already exists");
106 void JSMedia::finalize(JSObjectRef object)
108 LogDebug( "entered" );
109 MediaPrivObject *priv = static_cast<MediaPrivObject*>( JSObjectGetPrivate( object ) ) ;
113 const JSClassRef JSMedia::getClassRef()
115 LogDebug("JSMedia::getClassRef()");
118 m_jsClassRef = JSClassCreate(&m_classInfo);
123 const JSClassDefinition* JSMedia::getClassInfo()
128 MediacontentMediaPtr JSMedia::getMediaObject(JSObjectRef object)
131 MediaPrivObject *priv = static_cast<MediaPrivObject*>(JSObjectGetPrivate(object));
134 ThrowMsg(NullPointerException, "Private object is null");
136 MediacontentMediaPtr result = priv->getObject();
139 ThrowMsg(NullPointerException, "Private object is null");
144 JSValueRef JSMedia::getPropertyId(
145 JSContextRef context,
147 JSStringRef propertyName,
148 JSValueRef* exception)
153 Converter converter(context);
154 MediacontentMediaPtr event = getMediaObject(object);
156 return converter.toJSValueRef(event->getMediaUUID());
160 LogWarning("trying to get incorrect value");
162 return JSValueMakeUndefined(context);
166 JSValueRef JSMedia::getPropertyMimeType(
167 JSContextRef context,
169 JSStringRef propertyName,
170 JSValueRef* exception)
175 Converter converter(context);
176 MediacontentMediaPtr event = getMediaObject(object);
177 return converter.toJSValueRef(event->getMimeType());
181 LogWarning("trying to get incorrect value");
183 return JSValueMakeUndefined(context);
188 JSValueRef JSMedia::getPropertyDisplayName(
189 JSContextRef context,
191 JSStringRef propertyName,
192 JSValueRef* exception)
194 LogDebug("getPropertyDisplayName::entered");
197 Converter converter(context);
198 MediacontentMediaPtr event = getMediaObject(object);
199 LogDebug("getDisplayName:"<<event->getDisplayName());
200 return converter.toJSValueRef(event->getDisplayName());
204 LogWarning("trying to get incorrect value");
206 return JSValueMakeUndefined(context);
210 JSValueRef JSMedia::getPropertyFilePath(
211 JSContextRef context,
213 JSStringRef propertyName,
214 JSValueRef* exception)
219 Converter converter(context);
220 MediacontentMediaPtr event = getMediaObject(object);
221 return converter.toJSValueRef(event->getFilePath());
225 LogWarning("trying to get incorrect value");
227 return JSValueMakeUndefined(context);
231 JSValueRef JSMedia::getPropertyThumbnailPath(
232 JSContextRef context,
234 JSStringRef propertyName,
235 JSValueRef* exception)
240 Converter converter(context);
241 MediacontentMediaPtr event = getMediaObject(object);
242 return converter.toJSValueRef(event->getThumbnailPath());
246 LogWarning("trying to get incorrect value");
248 return JSValueMakeUndefined(context);
251 JSValueRef JSMedia::getPropertyDescription(
252 JSContextRef context,
254 JSStringRef propertyName,
255 JSValueRef* exception)
260 Converter converter(context);
261 MediacontentMediaPtr event = getMediaObject(object);
262 return converter.toJSValueRef(event->getDescription());
266 LogWarning("trying to get incorrect value");
268 return JSValueMakeUndefined(context);
273 JSValueRef JSMedia::getPropertyCreatedDate(
274 JSContextRef context,
276 JSStringRef propertyName,
277 JSValueRef* exception)
282 Converter converter(context);
283 MediacontentMediaPtr event = getMediaObject(object);
284 return converter.toJSValueRef(event->getCreatedDate());
288 LogWarning("trying to get incorrect value");
290 return JSValueMakeUndefined(context);
294 JSValueRef JSMedia::getPropertyModifiedDate(
295 JSContextRef context,
297 JSStringRef propertyName,
298 JSValueRef* exception)
303 Converter converter(context);
304 MediacontentMediaPtr event = getMediaObject(object);
305 return converter.toJSValueRef(event->getModifiedDate());
309 LogWarning("trying to get incorrect value");
311 return JSValueMakeUndefined(context);
314 JSValueRef JSMedia::getPropertyReleasedDate(
315 JSContextRef context,
317 JSStringRef propertyName,
318 JSValueRef* exception)
323 Converter converter(context);
324 MediacontentMediaPtr event = getMediaObject(object);
325 return converter.toJSValueRef(event->getReleasedDate());
329 LogWarning("trying to get incorrect value");
331 return JSValueMakeUndefined(context);
336 JSValueRef JSMedia::getPropertyFavorite(
337 JSContextRef context,
339 JSStringRef propertyName,
340 JSValueRef* exception)
345 Converter converter(context);
346 MediacontentMediaPtr event = getMediaObject(object);
347 return converter.toJSValueRef(event->getFavorite());
351 LogWarning("trying to get incorrect value");
353 return JSValueMakeUndefined(context);
356 JSValueRef JSMedia::getPropertyType(
357 JSContextRef context,
359 JSStringRef propertyName,
360 JSValueRef* exception)
362 LogDebug("getPropertyType::entered");
365 Converter converter(context);
366 MediacontentMediaPtr event = getMediaObject(object);
367 return converter.toJSValueRef(event->getMediaType());
371 LogWarning("trying to get incorrect value");
373 return JSValueMakeUndefined(context);
377 bool JSMedia::setPropertyFavorite(
378 JSContextRef context,
380 JSStringRef propertyName,
382 JSValueRef* exception)
387 Converter converter(context);
388 MediacontentMediaPtr event = getMediaObject(object);
389 int rating = converter.toInt(value);
391 LogDebug("value : " << rating);
392 event->setFavorite(rating);
397 LogWarning("trying to set incorrect value");
398 TizenApis::Commons::JSTizenExceptionFactory::postException(context, exception, TizenApis::Commons::JSTizenException::TYPE_MISMATCH_ERROR);