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.
19 #include <dpl/log/log.h>
20 #include <CommonsJavaScript/PrivateObject.h>
21 #include <CommonsJavaScript/Converter.h>
22 #include <CommonsJavaScript/JSUtils.h>
23 #include <CommonsJavaScript/JSDOMExceptionFactory.h>
24 #include "ContentFactory.h"
25 #include "ContentController.h"
32 #define TIZEN_CONTENT_FOLDER_ATTRIBUTENAME "ContentDirectory"
33 #define TIZEN_CONTENT_FOLDER_UID "id"
34 #define TIZEN_CONTENT_FOLDER_NAME "title"
35 #define TIZEN_CONTENT_FOLDER_PATH "directoryURI"
36 #define TIZEN_CONTENT_FOLDER_STORAGE_TYPE "storageType"
37 #define TIZEN_CONTENT_FOLDER_MODIFIEDDATE "modifiedDate"
40 JSClassDefinition JSFolder::m_classInfo =
43 kJSClassAttributeNone,
44 TIZEN_CONTENT_FOLDER_ATTRIBUTENAME,
47 m_function, // m_function,
53 NULL, //DeleteProperty,
54 NULL, //GetPropertyNames,
55 NULL, //CallAsFunction,
56 NULL, //CallAsConstructor,
61 JSStaticValue JSFolder::m_property[] =
64 { TIZEN_CONTENT_FOLDER_UID, getPropertyId, NULL, kJSPropertyAttributeReadOnly},
65 { TIZEN_CONTENT_FOLDER_NAME, getPropertyName, NULL, kJSPropertyAttributeReadOnly},
66 { TIZEN_CONTENT_FOLDER_PATH, getPropertyPath, NULL, kJSPropertyAttributeReadOnly},
67 { TIZEN_CONTENT_FOLDER_STORAGE_TYPE, getPropertyStorageType, NULL, kJSPropertyAttributeReadOnly},
68 { TIZEN_CONTENT_FOLDER_MODIFIEDDATE, getPropertyModifiedDate, NULL, kJSPropertyAttributeReadOnly},
72 JSStaticFunction JSFolder::m_function[] =
78 JSClassRef JSFolder::m_jsClassRef = JSClassCreate(JSFolder::getClassInfo());
80 void JSFolder::initialize(JSContextRef context, JSObjectRef object)
82 LogDebug( "entered" );
83 FolderPrivObject *priv = static_cast<FolderPrivObject*>( JSObjectGetPrivate( object ) );
86 MediacontentFolderPtr privateData(new MediacontentFolder());
87 priv = new FolderPrivObject(context, privateData);
88 JSObjectSetPrivate(object, static_cast<void*>(priv));
89 LogDebug("new event is created" );
93 LogDebug("private object already exists");
98 void JSFolder::finalize(JSObjectRef object)
100 LogDebug( "entered" );
101 FolderPrivObject *priv = static_cast<FolderPrivObject*>( JSObjectGetPrivate( object ) ) ;
106 JSObjectSetPrivate(object, NULL);
113 const JSClassRef JSFolder::getClassRef()
117 m_jsClassRef = JSClassCreate(&m_classInfo);
122 const JSClassDefinition* JSFolder::getClassInfo()
128 MediacontentFolderPtr JSFolder::getFolderObject(JSObjectRef object)
131 FolderPrivObject *priv = static_cast<FolderPrivObject*>(JSObjectGetPrivate(object));
133 ThrowMsg(NullPointerException, "Private object is null");
135 MediacontentFolderPtr result = priv->getObject();
137 ThrowMsg(NullPointerException, "Private object is null");
144 JSValueRef JSFolder::getPropertyId(
145 JSContextRef context,
147 JSStringRef propertyName,
148 JSValueRef* exception)
153 Converter converter(context);
154 MediacontentFolderPtr folder = getFolderObject(object);
156 return converter.toJSValueRef(folder->getFolderUUID());
160 LogWarning("trying to get incorrect value");
162 return JSValueMakeUndefined(context);
166 JSValueRef JSFolder::getPropertyName(
167 JSContextRef context,
169 JSStringRef propertyName,
170 JSValueRef* exception)
175 Converter converter(context);
176 MediacontentFolderPtr folder = getFolderObject(object);
177 return converter.toJSValueRef(folder->getFolderName());
181 LogWarning("trying to get incorrect value");
183 return JSValueMakeUndefined(context);
187 JSValueRef JSFolder::getPropertyPath(
188 JSContextRef context,
190 JSStringRef propertyName,
191 JSValueRef* exception)
193 LogDebug("getPropertyPath::entered");
196 Converter converter(context);
197 MediacontentFolderPtr folder = getFolderObject(object);
198 return converter.toJSValueRef(folder->getFolderPath());
202 LogWarning("trying to get incorrect value");
204 return JSValueMakeUndefined(context);
208 JSValueRef JSFolder::getPropertyStorageType(
209 JSContextRef context,
211 JSStringRef propertyName,
212 JSValueRef* exception)
217 Converter converter(context);
218 MediacontentFolderPtr folder = getFolderObject(object);
219 return converter.toJSValueRef(folder->getFolderStorageType());
223 LogWarning("trying to get incorrect value");
225 return JSValueMakeUndefined(context);
229 JSValueRef JSFolder::getPropertyModifiedDate(
230 JSContextRef context,
232 JSStringRef propertyName,
233 JSValueRef* exception)
238 Converter converter(context);
239 MediacontentFolderPtr folder = getFolderObject(object);
240 if(folder->getFolderModifiedDate() != NULL)
242 return converter.toJSValueRef(*(folder->getFolderModifiedDate()));
247 LogWarning("trying to get incorrect value");
249 return JSValueMakeUndefined(context);
253 JSValueRef JSFolder::getPropertyMediaId(
254 JSContextRef context,
256 JSStringRef propertyName,
257 JSValueRef* exception)
262 Converter converter(context);
263 MediacontentFolderPtr folder = getFolderObject(object);
264 //folder->getMediaIdList()
265 //MediaIdListPtr getMediaIdList() const;
266 //typedef vector<std::string> MediaIdList;
267 //typedef DPL::SharedPtr<MediaIdList> MediaIdListPtr;
268 MediaIdListPtr mediaIdLstPtr = folder->getMediaIdList();
269 JSObjectRef jsResult = JSCreateArrayObject(context, 0, NULL);
273 if (NULL == jsResult)
275 ThrowMsg(NullPointerException, "Could not create js array object");
277 for(unsigned int i=0; i<mediaIdLstPtr->size(); i++)
279 JSValueRef val = converter.toJSValueRef(mediaIdLstPtr->at(i));
280 if(!JSSetArrayElement(context, jsResult, i, val))
282 ThrowMsg(UnknownException, "Could not insert value into js array");
290 LogWarning("trying to get incorrect value");
292 return JSValueMakeUndefined(context);