summaryrefslogtreecommitdiff
path: root/mobile_src/Content/JSFolder.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'mobile_src/Content/JSFolder.cpp')
-rwxr-xr-xmobile_src/Content/JSFolder.cpp282
1 files changed, 282 insertions, 0 deletions
diff --git a/mobile_src/Content/JSFolder.cpp b/mobile_src/Content/JSFolder.cpp
new file mode 100755
index 0000000..800b101
--- /dev/null
+++ b/mobile_src/Content/JSFolder.cpp
@@ -0,0 +1,282 @@
+//
+// Tizen Web Device API
+// Copyright (c) 2012 Samsung Electronics Co., Ltd.
+//
+// Licensed under the Apache License, Version 2.0 (the License);
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+#include <CommonsJavaScript/PrivateObject.h>
+#include <CommonsJavaScript/Converter.h>
+#include <CommonsJavaScript/JSUtils.h>
+#include <CommonsJavaScript/JSDOMExceptionFactory.h>
+#include "ContentFactory.h"
+#include "ContentController.h"
+#include "JSFolder.h"
+#include <Logger.h>
+
+namespace DeviceAPI {
+namespace Content {
+
+#define TIZEN_CONTENT_FOLDER_ATTRIBUTENAME "ContentDirectory"
+#define TIZEN_CONTENT_FOLDER_UID "id"
+#define TIZEN_CONTENT_FOLDER_NAME "title"
+#define TIZEN_CONTENT_FOLDER_PATH "directoryURI"
+#define TIZEN_CONTENT_FOLDER_STORAGE_TYPE "storageType"
+#define TIZEN_CONTENT_FOLDER_MODIFIEDDATE "modifiedDate"
+
+
+JSClassDefinition JSFolder::m_classInfo =
+{
+ 0,
+ kJSClassAttributeNone,
+ TIZEN_CONTENT_FOLDER_ATTRIBUTENAME,
+ 0,
+ m_property,
+ m_function, // m_function,
+ initialize,
+ finalize,
+ NULL, //hasProperty,
+ NULL, //getProperty,
+ NULL, //setProperty,
+ NULL, //DeleteProperty,
+ NULL, //GetPropertyNames,
+ NULL, //CallAsFunction,
+ NULL, //CallAsConstructor,
+ NULL, //HasInstance,
+ NULL //ConvertToType
+};
+
+JSStaticValue JSFolder::m_property[] =
+{
+ //FolderProperties
+ { TIZEN_CONTENT_FOLDER_UID, getPropertyId, NULL, kJSPropertyAttributeReadOnly},
+ { TIZEN_CONTENT_FOLDER_NAME, getPropertyName, NULL, kJSPropertyAttributeReadOnly},
+ { TIZEN_CONTENT_FOLDER_PATH, getPropertyPath, NULL, kJSPropertyAttributeReadOnly},
+ { TIZEN_CONTENT_FOLDER_STORAGE_TYPE, getPropertyStorageType, NULL, kJSPropertyAttributeReadOnly},
+ { TIZEN_CONTENT_FOLDER_MODIFIEDDATE, getPropertyModifiedDate, NULL, kJSPropertyAttributeReadOnly},
+ { 0, 0, 0, 0 }
+};
+
+JSStaticFunction JSFolder::m_function[] =
+{
+ { 0, 0, 0 }
+};
+
+
+JSClassRef JSFolder::m_jsClassRef = JSClassCreate(JSFolder::getClassInfo());
+
+void JSFolder::initialize(JSContextRef context, JSObjectRef object)
+{
+ FolderPrivObject *priv = static_cast<FolderPrivObject*>( JSObjectGetPrivate( object ) );
+ if (!priv)
+ {
+ MediacontentFolderPtr privateData(new MediacontentFolder());
+ priv = new FolderPrivObject(context, privateData);
+ JSObjectSetPrivate(object, static_cast<void*>(priv));
+ }
+ else
+ {
+ LoggerD("private object already exists");
+ }
+}
+
+
+void JSFolder::finalize(JSObjectRef object)
+{
+ FolderPrivObject *priv = static_cast<FolderPrivObject*>( JSObjectGetPrivate( object ) ) ;
+ if (priv != NULL)
+ {
+ delete (priv);
+ priv = NULL;
+ JSObjectSetPrivate(object, NULL);
+ }
+}
+
+
+
+const JSClassRef JSFolder::getClassRef()
+{
+ if (!m_jsClassRef)
+ {
+ m_jsClassRef = JSClassCreate(&m_classInfo);
+ }
+ return m_jsClassRef;
+}
+
+const JSClassDefinition* JSFolder::getClassInfo()
+{
+ return &m_classInfo;
+}
+
+
+MediacontentFolderPtr JSFolder::getFolderObject(JSObjectRef object)
+{
+ FolderPrivObject *priv = static_cast<FolderPrivObject*>(JSObjectGetPrivate(object));
+ if(!priv) {
+ ThrowMsg(NullPointerException, "Private object is null");
+ }
+ MediacontentFolderPtr result = priv->getObject();
+ if (!result) {
+ ThrowMsg(NullPointerException, "Private object is null");
+ }
+ return result;
+}
+
+
+
+JSValueRef JSFolder::getPropertyId(
+ JSContextRef context,
+ JSObjectRef object,
+ JSStringRef propertyName,
+ JSValueRef* exception)
+{
+ Try
+ {
+ Converter converter(context);
+ MediacontentFolderPtr folder = getFolderObject(object);
+ return converter.toJSValueRef(folder->getFolderUUID());
+ }
+ Catch(Exception)
+ {
+ LoggerW("trying to get incorrect value");
+ }
+ return JSValueMakeUndefined(context);
+
+}
+
+JSValueRef JSFolder::getPropertyName(
+ JSContextRef context,
+ JSObjectRef object,
+ JSStringRef propertyName,
+ JSValueRef* exception)
+{
+ Try
+ {
+ Converter converter(context);
+ MediacontentFolderPtr folder = getFolderObject(object);
+ return converter.toJSValueRef(folder->getFolderName());
+ }
+ Catch(Exception)
+ {
+ LoggerW("trying to get incorrect value");
+ }
+ return JSValueMakeUndefined(context);
+}
+
+
+JSValueRef JSFolder::getPropertyPath(
+ JSContextRef context,
+ JSObjectRef object,
+ JSStringRef propertyName,
+ JSValueRef* exception)
+{
+ Try
+ {
+ Converter converter(context);
+ MediacontentFolderPtr folder = getFolderObject(object);
+ return converter.toJSValueRef(folder->getFolderPath());
+ }
+ Catch(Exception)
+ {
+ LoggerW("trying to get incorrect value");
+ }
+ return JSValueMakeNull(context);
+}
+
+
+JSValueRef JSFolder::getPropertyStorageType(
+ JSContextRef context,
+ JSObjectRef object,
+ JSStringRef propertyName,
+ JSValueRef* exception)
+{
+ Try
+ {
+ Converter converter(context);
+ MediacontentFolderPtr folder = getFolderObject(object);
+ return converter.toJSValueRef(folder->getFolderStorageType());
+ }
+ Catch(Exception)
+ {
+ LoggerW("trying to get incorrect value");
+ }
+ return JSValueMakeUndefined(context);
+}
+
+
+JSValueRef JSFolder::getPropertyModifiedDate(
+ JSContextRef context,
+ JSObjectRef object,
+ JSStringRef propertyName,
+ JSValueRef* exception)
+{
+ Try
+ {
+ Converter converter(context);
+ MediacontentFolderPtr folder = getFolderObject(object);
+ if(folder->getFolderModifiedDate() != NULL)
+ {
+ return converter.toJSValueRef(*(folder->getFolderModifiedDate()));
+ }
+ }
+ Catch(Exception)
+ {
+ LoggerW("trying to get incorrect value");
+ }
+ return JSValueMakeNull(context);
+}
+
+
+JSValueRef JSFolder::getPropertyMediaId(
+ JSContextRef context,
+ JSObjectRef object,
+ JSStringRef propertyName,
+ JSValueRef* exception)
+{
+ Try
+ {
+ Converter converter(context);
+ MediacontentFolderPtr folder = getFolderObject(object);
+ MediaIdListPtr mediaIdLstPtr = folder->getMediaIdList();
+ JSObjectRef jsResult = JSCreateArrayObject(context, 0, NULL);
+
+ if(mediaIdLstPtr)
+ {
+ if (NULL == jsResult)
+ {
+ ThrowMsg(NullPointerException, "Could not create js array object");
+ }
+ for(unsigned int i=0; i<mediaIdLstPtr->size(); i++)
+ {
+ JSValueRef val = converter.toJSValueRef(mediaIdLstPtr->at(i));
+ if(!JSSetArrayElement(context, jsResult, i, val))
+ {
+ ThrowMsg(UnknownException, "Could not insert value into js array");
+ }
+ }
+ }
+ return jsResult;
+ }
+ Catch(Exception)
+ {
+ LoggerW("trying to get incorrect value");
+ }
+ return JSValueMakeUndefined(context);
+
+}
+
+
+
+}
+}
+