2 // Tizen Web Device API
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
5 // Licensed under the Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
9 // http://www.apache.org/licenses/LICENSE-2.0
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
18 #include <CommonsJavaScript/PrivateObject.h>
19 #include <CommonsJavaScript/Converter.h>
20 #include <CommonsJavaScript/JSUtils.h>
21 #include <CommonsJavaScript/JSDOMExceptionFactory.h>
22 #include "ContentFactory.h"
23 #include "ContentController.h"
30 #define TIZEN_CONTENT_FOLDER_ATTRIBUTENAME "ContentDirectory"
31 #define TIZEN_CONTENT_FOLDER_UID "id"
32 #define TIZEN_CONTENT_FOLDER_NAME "title"
33 #define TIZEN_CONTENT_FOLDER_PATH "directoryURI"
34 #define TIZEN_CONTENT_FOLDER_STORAGE_TYPE "storageType"
35 #define TIZEN_CONTENT_FOLDER_MODIFIEDDATE "modifiedDate"
38 JSClassDefinition JSFolder::m_classInfo =
41 kJSClassAttributeNone,
42 TIZEN_CONTENT_FOLDER_ATTRIBUTENAME,
45 m_function, // m_function,
51 NULL, //DeleteProperty,
52 NULL, //GetPropertyNames,
53 NULL, //CallAsFunction,
54 NULL, //CallAsConstructor,
59 JSStaticValue JSFolder::m_property[] =
62 { TIZEN_CONTENT_FOLDER_UID, getPropertyId, NULL, kJSPropertyAttributeReadOnly},
63 { TIZEN_CONTENT_FOLDER_NAME, getPropertyName, NULL, kJSPropertyAttributeReadOnly},
64 { TIZEN_CONTENT_FOLDER_PATH, getPropertyPath, NULL, kJSPropertyAttributeReadOnly},
65 { TIZEN_CONTENT_FOLDER_STORAGE_TYPE, getPropertyStorageType, NULL, kJSPropertyAttributeReadOnly},
66 { TIZEN_CONTENT_FOLDER_MODIFIEDDATE, getPropertyModifiedDate, NULL, kJSPropertyAttributeReadOnly},
70 JSStaticFunction JSFolder::m_function[] =
76 JSClassRef JSFolder::m_jsClassRef = JSClassCreate(JSFolder::getClassInfo());
78 void JSFolder::initialize(JSContextRef context, JSObjectRef object)
80 FolderPrivObject *priv = static_cast<FolderPrivObject*>( JSObjectGetPrivate( object ) );
83 MediacontentFolderPtr privateData(new MediacontentFolder());
84 priv = new FolderPrivObject(context, privateData);
85 JSObjectSetPrivate(object, static_cast<void*>(priv));
89 LoggerD("private object already exists");
94 void JSFolder::finalize(JSObjectRef object)
96 FolderPrivObject *priv = static_cast<FolderPrivObject*>( JSObjectGetPrivate( object ) ) ;
101 JSObjectSetPrivate(object, NULL);
107 const JSClassRef JSFolder::getClassRef()
111 m_jsClassRef = JSClassCreate(&m_classInfo);
116 const JSClassDefinition* JSFolder::getClassInfo()
122 MediacontentFolderPtr JSFolder::getFolderObject(JSObjectRef object)
124 FolderPrivObject *priv = static_cast<FolderPrivObject*>(JSObjectGetPrivate(object));
126 ThrowMsg(NullPointerException, "Private object is null");
128 MediacontentFolderPtr result = priv->getObject();
130 ThrowMsg(NullPointerException, "Private object is null");
137 JSValueRef JSFolder::getPropertyId(
138 JSContextRef context,
140 JSStringRef propertyName,
141 JSValueRef* exception)
145 Converter converter(context);
146 MediacontentFolderPtr folder = getFolderObject(object);
147 return converter.toJSValueRef(folder->getFolderUUID());
151 LoggerW("trying to get incorrect value");
153 return JSValueMakeUndefined(context);
157 JSValueRef JSFolder::getPropertyName(
158 JSContextRef context,
160 JSStringRef propertyName,
161 JSValueRef* exception)
165 Converter converter(context);
166 MediacontentFolderPtr folder = getFolderObject(object);
167 return converter.toJSValueRef(folder->getFolderName());
171 LoggerW("trying to get incorrect value");
173 return JSValueMakeUndefined(context);
177 JSValueRef JSFolder::getPropertyPath(
178 JSContextRef context,
180 JSStringRef propertyName,
181 JSValueRef* exception)
185 Converter converter(context);
186 MediacontentFolderPtr folder = getFolderObject(object);
187 return converter.toJSValueRef(folder->getFolderPath());
191 LoggerW("trying to get incorrect value");
193 return JSValueMakeNull(context);
197 JSValueRef JSFolder::getPropertyStorageType(
198 JSContextRef context,
200 JSStringRef propertyName,
201 JSValueRef* exception)
205 Converter converter(context);
206 MediacontentFolderPtr folder = getFolderObject(object);
207 return converter.toJSValueRef(folder->getFolderStorageType());
211 LoggerW("trying to get incorrect value");
213 return JSValueMakeUndefined(context);
217 JSValueRef JSFolder::getPropertyModifiedDate(
218 JSContextRef context,
220 JSStringRef propertyName,
221 JSValueRef* exception)
225 Converter converter(context);
226 MediacontentFolderPtr folder = getFolderObject(object);
227 if(folder->getFolderModifiedDate() != NULL)
229 return converter.toJSValueRef(*(folder->getFolderModifiedDate()));
234 LoggerW("trying to get incorrect value");
236 return JSValueMakeNull(context);
240 JSValueRef JSFolder::getPropertyMediaId(
241 JSContextRef context,
243 JSStringRef propertyName,
244 JSValueRef* exception)
248 Converter converter(context);
249 MediacontentFolderPtr folder = getFolderObject(object);
250 MediaIdListPtr mediaIdLstPtr = folder->getMediaIdList();
251 JSObjectRef jsResult = JSCreateArrayObject(context, 0, NULL);
255 if (NULL == jsResult)
257 ThrowMsg(NullPointerException, "Could not create js array object");
259 for(unsigned int i=0; i<mediaIdLstPtr->size(); i++)
261 JSValueRef val = converter.toJSValueRef(mediaIdLstPtr->at(i));
262 if(!JSSetArrayElement(context, jsResult, i, val))
264 ThrowMsg(UnknownException, "Could not insert value into js array");
272 LoggerW("trying to get incorrect value");
274 return JSValueMakeUndefined(context);