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 <SecurityExceptions.h>
21 #include <ArgumentValidator.h>
22 #include <GlobalContextManager.h>
23 #include <MultiCallbackUserData.h>
24 #include <PlatformException.h>
25 #include <JSWebAPIErrorFactory.h>
26 #include <FilesystemUtils.h>
27 #include "plugin_config.h"
29 #include "JSStatusNotification.h"
30 #include "JSNotificationDetailInfo.h"
32 using namespace WrtDeviceApis::Commons;
33 using namespace DeviceAPI::Common;
36 namespace Notification {
38 #define NOTIFICATION_TYPE_VALUE "STATUS"
40 JSClassDefinition JSStatusNotification::m_classInfo = {
42 kJSClassAttributeNone,
45 m_property, //StaticValues
46 NULL, //StaticFunctions
47 initialize, //Initialize
52 NULL, //DeleteProperty,
53 NULL, //GetPropertyNames,
54 NULL, //CallAsFunction,
55 NULL, //CallAsConstructor,
60 JSStaticValue JSStatusNotification::m_property[] =
62 {STATUS_NOTIFICATION_PROGRESS_TYPE, JSStatusNotification::getProperty, JSStatusNotification::setProperty, kJSPropertyAttributeNone },
63 {STATUS_NOTIFICATION_PROGRESS_VALUE, JSStatusNotification::getProperty, JSStatusNotification::setProperty, kJSPropertyAttributeNone },
64 {STATUS_NOTIFICATION_LIGHT_ONTIME, JSStatusNotification::getProperty, JSStatusNotification::setProperty, kJSPropertyAttributeNone },
65 {STATUS_NOTIFICATION_LIGHT_OFFTIME, JSStatusNotification::getProperty, JSStatusNotification::setProperty, kJSPropertyAttributeNone },
66 {STATUS_NOTIFICATION_VIBRATION, JSStatusNotification::getProperty, JSStatusNotification::setProperty, kJSPropertyAttributeNone },
67 {NOTIFICATION_TITLE, JSStatusNotification::getProperty, JSStatusNotification::setProperty, kJSPropertyAttributeNone },
71 bool JSStatusNotification::setProperty(JSContextRef context,
73 JSStringRef propertyName,
75 JSValueRef* exception)
78 StatusNotification *priv = static_cast<StatusNotification*>(JSObjectGetPrivate(object));
79 LoggerD("statusNotification :" << priv);
81 throw TypeMismatchException("StatusNotification's private object is NULL.");
86 size_t jsSize = JSStringGetMaximumUTF8CStringSize(propertyName);
89 char* buffer = new char[jsSize];
90 size_t written = JSStringGetUTF8CString(propertyName, buffer, jsSize);
91 if (written > jsSize) {
92 throw InvalidValuesException("Conversion could not be fully performed.");
98 LoggerI("property =" << property);
100 if ( property == STATUS_NOTIFICATION_PROGRESS_TYPE)
102 std::string strProgressType = JSUtil::JSValueToString(context, value);
103 LoggerI("Progress Type : " << strProgressType);
105 NotificationProgressType progType = NOTI_PROGRESS_TYPE_NONE;
106 if( strProgressType.compare(TIZEN_NOTIFICATION_PROGRESS_TYPE_PERCENTAGE) == 0)
107 progType = NOTI_PROGRESS_TYPE_PERCENTAGE;
108 else if( strProgressType.compare(TIZEN_NOTIFICATION_PROGRESS_TYPE_BYTE) == 0)
109 progType = NOTI_PROGRESS_TYPE_SIZE;
111 throw InvalidValuesException("Invalid Progress Type.");
113 priv->setProgressType(progType); //set progress Type
117 else if ( property == STATUS_NOTIFICATION_PROGRESS_VALUE)
120 unsigned long progressVal = JSUtil::JSValueToULong(context, value);
121 LoggerI("Progress Value : " << progressVal);
123 if ( priv->getProgressType() == NOTI_PROGRESS_TYPE_PERCENTAGE)
125 if ( 100 < progressVal )
126 throw InvalidValuesException("The percentage progress value must be between 0 and 100");
127 priv->setProgressValue((double)progressVal/(double)100);
131 priv->setProgressValue((double)progressVal);
136 else if ( property == STATUS_NOTIFICATION_LIGHT_ONTIME)
138 unsigned long onPeriod = JSUtil::JSValueToULong(context, value);
139 LoggerI(" LEDonPeriod = " << onPeriod);
140 priv->setLightOnTime(onPeriod);
142 else if ( property == STATUS_NOTIFICATION_LIGHT_OFFTIME)
144 unsigned long offPeriod = JSUtil::JSValueToULong(context, value);
145 LoggerI(" LEDoffPeriod = " << offPeriod);
146 priv->setLightOffTime(offPeriod);
148 else if ( property == STATUS_NOTIFICATION_VIBRATION)
150 bool vibration = JSUtil::JSValueToBoolean(context, value);
151 LoggerI(" vibration = " << vibration);
152 priv->setDefaultVibration(vibration);
154 else if ( property == NOTIFICATION_TITLE)
156 std::string title = JSUtil::JSValueToString(context, value);
157 LoggerI(" title = " << title);
158 priv->setTitle(title);
162 catch ( const BasePlatformException& err)
164 LoggerW(" notification convertion is failed. " << err.getName().c_str() << ":" << err.getMessage().c_str());
171 JSValueRef JSStatusNotification::getProperty(JSContextRef context,
173 JSStringRef propertyName,
174 JSValueRef* exception)
177 StatusNotification *priv = static_cast<StatusNotification*>(JSObjectGetPrivate(object));
178 LoggerD("statusNotification :" << priv);
180 throw TypeMismatchException("StatusNotification's private object is NULL.");
184 std::string property;
185 size_t jsSize = JSStringGetMaximumUTF8CStringSize(propertyName);
188 char* buffer = new char[jsSize];
189 size_t written = JSStringGetUTF8CString(propertyName, buffer, jsSize);
190 if (written > jsSize) {
191 throw InvalidValuesException("Conversion could not be fully performed.");
197 LoggerI("property =" << property);
198 if ( property == STATUS_NOTIFICATION_PROGRESS_TYPE)
201 if ( NOTI_PROGRESS_TYPE_PERCENTAGE == priv->getProgressType())
203 type = TIZEN_NOTIFICATION_PROGRESS_TYPE_PERCENTAGE;
205 else if ( NOTI_PROGRESS_TYPE_SIZE== priv->getProgressType())
207 type = TIZEN_NOTIFICATION_PROGRESS_TYPE_BYTE;
210 return JSUtil::toJSValueRef(context, type);
213 else if ( property == STATUS_NOTIFICATION_PROGRESS_VALUE)
216 LoggerI("Progress Type=" << priv->getProgressType());
219 unsigned long progressVal = 0;
220 if ( NOTI_PROGRESS_TYPE_PERCENTAGE == priv->getProgressType())
222 progressVal = (unsigned long)( (priv->getProgressValue()*100) );
224 else if ( NOTI_PROGRESS_TYPE_SIZE== priv->getProgressType())
226 progressVal = (unsigned long)priv->getProgressValue();
229 LoggerI("Progress Value=" << progressVal);
231 if( priv->getNotiType() != NOTI_TYPE_PROGRESS && progressVal == 0)
233 return JSValueMakeNull(context);
237 return JSUtil::toJSValueRef(context, progressVal);
240 else if ( property == STATUS_NOTIFICATION_LIGHT_ONTIME)
242 unsigned long onTime = priv->getLightOnTime();
243 return JSUtil::toJSValueRef(context, onTime);
245 else if ( property == STATUS_NOTIFICATION_LIGHT_OFFTIME)
247 unsigned long offTime = priv->getLightOffTime();
248 return JSUtil::toJSValueRef(context, offTime);
250 else if ( property == STATUS_NOTIFICATION_VIBRATION)
252 bool vibration = priv->getDefaultVibration();
253 return JSUtil::toJSValueRef(context, vibration);
255 else if ( property == NOTIFICATION_TITLE)
257 std::string title = priv->getTitle();
258 return JSUtil::toJSValueRef(context, title);
261 catch ( const BasePlatformException& err)
263 LoggerW(" notification convertion is failed. " << err.getName().c_str() << ":" << err.getMessage().c_str());
271 JSClassRef JSStatusNotification::m_jsClassRef = JSClassCreate(JSStatusNotification::getClassInfo());
273 const JSClassRef JSStatusNotification::getClassRef()
276 m_jsClassRef = JSClassCreate(&m_classInfo);
281 const JSClassDefinition* JSStatusNotification::getClassInfo()
286 void JSStatusNotification::initialize(JSContextRef context, JSObjectRef object)
288 LoggerD("JSStatusNotification::initialize, nothing ");
291 void JSStatusNotification::finalize(JSObjectRef object)
293 StatusNotification *priv = static_cast<StatusNotification*>(JSObjectGetPrivate(object));
295 JSObjectSetPrivate(object, NULL);
300 JSObjectRef JSStatusNotification::constructor(JSContextRef context,
301 JSObjectRef constructor,
302 size_t argumentCount,
303 const JSValueRef arguments[],
304 JSValueRef* exception)
306 ArgumentValidator validator(context, argumentCount, arguments);
309 JSObjectRef obj = JSObjectMake(context, getClassRef(), NULL);
311 JSStringRef ctorName = JSStringCreateWithUTF8CString("constructor");
312 JSObjectSetProperty(context, obj, ctorName, constructor,
313 kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete | kJSPropertyAttributeDontEnum, NULL);
314 JSStringRelease(ctorName);
317 //Status Notification Type.
318 NotificationType notiType = NOTI_TYPE_NONE;
319 std::string strStatusType = validator.toString(0, false, "");
320 LoggerI("Notification Type : " << strStatusType);
322 if( strStatusType.compare(TIZEN_STATUS_NOTIFICATION_TYPE_SIMPLE) == 0)
323 notiType = NOTI_TYPE_SIMPLE;
324 else if( strStatusType.compare(TIZEN_STATUS_NOTIFICATION_TYPE_THUMBNAIL) == 0)
325 notiType = NOTI_TYPE_THUMBNAIL;
326 else if( strStatusType.compare(TIZEN_STATUS_NOTIFICATION_TYPE_ONGOING) == 0)
327 notiType = NOTI_TYPE_ONGOING;
328 else if( strStatusType.compare(TIZEN_STATUS_NOTIFICATION_TYPE_PROGRESS) == 0)
329 notiType = NOTI_TYPE_PROGRESS;
331 notiType = NOTI_TYPE_NONE;
333 StatusNotification *priv = new StatusNotification(notiType);
335 priv->setTitle(validator.toString(1, false, "")); //title
337 JSObjectRef notiInitDict = validator.toObject(2, true);
341 LoggerI("Set Notification Init Dictionary");
343 JSValueRef contentValue = JSUtil::getProperty(context, notiInitDict, NOTIFICATION_CONTENT);
344 if (!(JSValueIsUndefined(context, contentValue) || JSValueIsNull(context, contentValue)))
346 priv->setContent(JSUtil::JSValueToString(context, contentValue));
351 JSValueRef iconValue = JSUtil::getProperty(context, notiInitDict, STATUS_NOTIFICATION_ICON_PATH);
352 if (!JSValueIsUndefined(context, iconValue))
354 DeviceAPI::Filesystem::IPathPtr path = DeviceAPI::Filesystem::Utils::fromVirtualPath(context, JSUtil::JSValueToString(context, iconValue));
355 priv->setIconPath(path->getFullPath());
360 LoggerW("Icon file path is invaild");
365 JSValueRef soundValue = JSUtil::getProperty(context, notiInitDict, STATUS_NOTIFICATION_SOUND_PATH);
366 if (!JSValueIsUndefined(context, soundValue))
368 DeviceAPI::Filesystem::IPathPtr path = DeviceAPI::Filesystem::Utils::fromVirtualPath(context, JSUtil::JSValueToString(context, soundValue));
369 priv->setSoundPath(path->getFullPath());
374 LoggerW("sound file path is invaild");
379 JSValueRef vibrationValue = JSUtil::getProperty(context, notiInitDict, STATUS_NOTIFICATION_VIBRATION);
380 priv->setDefaultVibration(JSUtil::JSValueToBoolean(context, vibrationValue));
384 LoggerW("sound file path is invaild");
389 JSValueRef appControlValue = JSUtil::getProperty(context, notiInitDict, STATUS_NOTIFICATION_APP_CONTROL);
390 if (!JSValueIsUndefined(context, appControlValue))
391 priv->setApplicationControl(DeviceAPI::Application::JSApplicationControl::getApplicationControl(context, JSUtil::JSValueToObject(context, appControlValue) ));
395 LoggerW("sound file path is invaild");
400 JSValueRef appIdValue = JSUtil::getProperty(context, notiInitDict, STATUS_NOTIFICATION_APP_ID);
401 if (!JSValueIsUndefined(context, appIdValue))
402 priv->setApplicationId(JSUtil::JSValueToString(context, appIdValue));
406 LoggerW("appID is invaild");
411 JSValueRef lightValue = JSUtil::getProperty(context, notiInitDict, STATUS_NOTIFICATION_LIGHT);
412 LoggerI("Light :" << JSUtil::JSValueToString(context, lightValue));
413 if (!JSValueIsUndefined(context, lightValue))
414 priv->setLight(JSUtil::JSValueToString(context, lightValue));
418 LoggerW("The LED value is invalid ");
424 JSValueRef onTimeValue = JSUtil::getProperty(context, notiInitDict, STATUS_NOTIFICATION_LIGHT_ONTIME);
425 if (!JSValueIsUndefined(context, onTimeValue))
426 priv->setLightOnTime(JSUtil::JSValueToLong(context, onTimeValue));
430 LoggerW("The LED value is invalid ");
435 JSValueRef offTimeValue = JSUtil::getProperty(context, notiInitDict, STATUS_NOTIFICATION_LIGHT_OFFTIME);
436 if (!JSValueIsUndefined(context, offTimeValue))
437 priv->setLightOffTime(JSUtil::JSValueToLong(context, offTimeValue));
442 LoggerW("The LED value is invalid ");
446 NotificationProgressType progressType = NOTI_PROGRESS_TYPE_PERCENTAGE;
449 JSStringRef propertyName = JSStringCreateWithUTF8CString(STATUS_NOTIFICATION_PROGRESS_TYPE);
450 bool has = JSObjectHasProperty(context, notiInitDict, propertyName);
451 JSStringRelease(propertyName);
454 JSValueRef progressTypeValue = JSUtil::getProperty(context, notiInitDict, STATUS_NOTIFICATION_PROGRESS_TYPE);
455 std::string strProgressType = JSUtil::JSValueToString(context, progressTypeValue);
456 LoggerI("==Progress Type : " << strProgressType);
457 if( strProgressType.compare(TIZEN_NOTIFICATION_PROGRESS_TYPE_PERCENTAGE) == 0)
458 progressType = NOTI_PROGRESS_TYPE_PERCENTAGE;
459 else if( strProgressType.compare(TIZEN_NOTIFICATION_PROGRESS_TYPE_BYTE) == 0)
460 progressType = NOTI_PROGRESS_TYPE_SIZE;
462 progressType = NOTI_PROGRESS_TYPE_NONE;
464 priv->setProgressType(progressType);
468 LoggerW("The progress type is invalid ");
473 JSValueRef progressValue = JSUtil::getProperty(context, notiInitDict, STATUS_NOTIFICATION_PROGRESS_VALUE);
474 if (!JSValueIsUndefined(context, progressValue))
476 if ( progressType == NOTI_PROGRESS_TYPE_PERCENTAGE)
478 if ( 100 < JSUtil::JSValueToULong(context, progressValue) )
480 LoggerW("The percentage progress value must be between 0 and 100");
482 priv->setProgressValue((double)JSUtil::JSValueToULong(context, progressValue)/(double)100);
486 priv->setProgressValue((double)JSUtil::JSValueToULong(context, progressValue));
492 LoggerW("The progress value is invalid ");
496 JSValueRef detailInfoValue = JSUtil::getProperty(context, notiInitDict, STATUS_NOTIFICATION_DETAIL_INFO);
498 std::vector<NotificationDetailInfo*> detailInfos;
499 if (JSIsArrayValue(context, detailInfoValue))
501 JSObjectRef arrayobj = JSUtil::JSValueToObject(context, detailInfoValue);
502 for(std::size_t i = 0; i < JSGetArrayLength(context, arrayobj); ++i)
504 JSValueRef element = JSGetArrayElement(context, arrayobj, i);
505 JSObjectRef object = JSUtil::JSValueToObject(context, element);
508 NotificationDetailInfo* item = static_cast<NotificationDetailInfo*>(JSObjectGetPrivate(object));
511 NotificationDetailInfo *detailinfo = NULL;
512 std::string main = item->getMainText();
514 if (item->isSubTexstNull())
516 detailinfo = new NotificationDetailInfo(NULL, (int)i, main);
520 std::string sub = item->getSubText();
521 detailinfo = new NotificationDetailInfo(NULL, (int)i, main, sub);
523 detailInfos.push_back(detailinfo);
528 NotificationDetailInfo *detailinfo = NULL;
529 std::string main = JSUtil::JSValueToString(context, JSUtil::getProperty(context, object, NOTIFICATION_DETAIL_INFO_MAIN_TEXT));
531 JSStringRef propertyName = JSStringCreateWithUTF8CString(NOTIFICATION_DETAIL_INFO_SUB_TEXT);
532 if ( JSObjectHasProperty(context, object, propertyName))
534 JSValueRef subObj = JSUtil::getProperty(context, object, NOTIFICATION_DETAIL_INFO_SUB_TEXT);
535 if (JSValueIsNull(context, subObj))
537 detailinfo = new NotificationDetailInfo(NULL, (int)i, main);
541 std::string sub = JSUtil::JSValueToString(context, JSUtil::getProperty(context, object, NOTIFICATION_DETAIL_INFO_SUB_TEXT));
542 detailinfo = new NotificationDetailInfo(NULL, (int)i, main, sub);
547 detailinfo = new NotificationDetailInfo(NULL, (int)i, main);
550 JSStringRelease(propertyName);
552 detailInfos.push_back(detailinfo);
558 priv->setDetailInfos(detailInfos);
562 JSValueRef backgroundImageValue = JSUtil::getProperty(context, notiInitDict, STATUS_NOTIFICATION_BACKGROUND_IMAGE_PATH);
563 if (!JSValueIsUndefined(context, backgroundImageValue))
565 DeviceAPI::Filesystem::IPathPtr path = DeviceAPI::Filesystem::Utils::fromVirtualPath(context, JSUtil::JSValueToString(context, backgroundImageValue));
566 priv->setBackground(path->getFullPath());
571 //throw TypeMismatchException("The backgound image path is invalid ");
572 LoggerW("The backgound image path is invalid ");
577 JSValueRef numberValue = JSUtil::getProperty(context, notiInitDict, STATUS_NOTIFICATION_NUMBER);
578 if (!JSValueIsUndefined(context, numberValue))
580 priv->setNumber(JSUtil::JSValueToLong(context, numberValue));
584 LoggerW("The number is invalid ");
589 JSValueRef thumbnailsValue = JSUtil::getProperty(context, notiInitDict, STATUS_NOTIFICATION_THUMBNAILS);
590 if (!JSValueIsUndefined(context, thumbnailsValue))
593 std::vector<std::string> thumbnailPaths;
594 if( JSIsArrayValue(context, thumbnailsValue)){
595 JSObjectRef arrayobj = JSUtil::JSValueToObject(context, thumbnailsValue);
596 for (std::size_t i = 0; i < JSGetArrayLength(context, arrayobj); ++i) {
597 JSValueRef element = JSGetArrayElement(context, arrayobj, i);
598 DeviceAPI::Filesystem::IPathPtr thumbnailPath =
599 DeviceAPI::Filesystem::Utils::fromVirtualPath(context, JSUtil::JSValueToString(context, element));
600 LoggerI("thumbnail Path = " << thumbnailPath->getFullPath());
601 thumbnailPaths.push_back(thumbnailPath->getFullPath());
604 priv->setThumbnails(thumbnailPaths);
609 //throw TypeMismatchException("thumbnail path convertion is failed.");
610 LoggerW("thumbnail path convertion is failed.");
615 JSValueRef subIconPathValue = JSUtil::getProperty(context, notiInitDict, STATUS_NOTIFICATION_SUB_ICON_PATH);
616 if (!JSValueIsUndefined(context, subIconPathValue))
618 DeviceAPI::Filesystem::IPathPtr path = DeviceAPI::Filesystem::Utils::fromVirtualPath(context, JSUtil::JSValueToString(context, subIconPathValue));
619 priv->setSubIconPath( path->getFullPath());
624 //throw TypeMismatchException("subIcon path convertion is failed.");
625 LoggerW("subIcon path convertion is failed.");
630 setPrivateObject(context, obj, priv);
632 catch ( const BasePlatformException& err)
634 LoggerW(" notification convertion is failed. " << err.getName().c_str() << ":" << err.getMessage().c_str());
635 //JSObjectRef error = JSWebAPIErrorFactory::makeErrorObject(context, err);
636 //*exception = error;
644 StatusNotification* JSStatusNotification::getPrivateObject(JSContextRef context, JSObjectRef object)
646 LoggerD("get object :" << object);
648 StatusNotification *priv = static_cast<StatusNotification*>(JSObjectGetPrivate(object));
649 LoggerD("statusNotification :" << priv);
651 throw TypeMismatchException("StatusNotification's private object is NULL.");
655 JSValueRef type = JSUtil::getProperty(context, object, NOTIFICATION_TYPE);
656 if ((JSUtil::JSValueToString(context, type)).compare(NOTIFICATION_TYPE_VALUE) )
658 throw TypeMismatchException("StatusNotification's type is mismatched");
662 JSValueRef title = JSUtil::getProperty(context, object, NOTIFICATION_TITLE);
663 priv->setTitle( JSUtil::JSValueToString(context, title));
666 JSValueRef contents = JSUtil::getProperty(context, object, NOTIFICATION_CONTENT);
667 if (!JSValueIsNull(context, contents))
669 priv->setContent( JSUtil::JSValueToString(context, contents));
673 JSValueRef iconPath = JSUtil::getProperty(context, object, STATUS_NOTIFICATION_ICON_PATH);
674 if ( !JSValueIsNull(context, contents) )
676 DeviceAPI::Filesystem::IPathPtr icon = DeviceAPI::Filesystem::Utils::fromVirtualPath(context, JSUtil::JSValueToString(context, iconPath));
677 priv->setIconPath(icon->getFullPath());
681 JSValueRef subIconPath = JSUtil::getProperty(context, object, STATUS_NOTIFICATION_SUB_ICON_PATH);
682 if (!JSValueIsNull(context, subIconPath))
684 DeviceAPI::Filesystem::IPathPtr subIcon = DeviceAPI::Filesystem::Utils::fromVirtualPath(context, JSUtil::JSValueToString(context, subIconPath));
685 priv->setSubIconPath(subIcon->getFullPath());
689 JSValueRef number = JSUtil::getProperty(context, object, STATUS_NOTIFICATION_NUMBER);
690 priv->setNumber(JSUtil::JSValueToLong(context, number));
693 JSValueRef detailInfo = JSUtil::getProperty(context, object, STATUS_NOTIFICATION_DETAIL_INFO);
694 std::vector<NotificationDetailInfo*> detailInfos;
695 if (JSIsArrayValue(context, detailInfo))
697 JSObjectRef arrayobj = JSUtil::JSValueToObject(context, detailInfo);
698 for(std::size_t i = 0; i < JSGetArrayLength(context, arrayobj); ++i)
700 JSValueRef element = JSGetArrayElement(context, arrayobj, i);
701 JSObjectRef object = JSUtil::JSValueToObject(context, element);
704 NotificationDetailInfo* detailinfo = static_cast<NotificationDetailInfo*>(JSObjectGetPrivate(object));
705 detailInfos.push_back(detailinfo);
709 priv->setDetailInfos(detailInfos);
711 // backgroundImagePath
712 JSValueRef backgroundImagePath = JSUtil::getProperty(context, object, STATUS_NOTIFICATION_BACKGROUND_IMAGE_PATH);
713 if (!JSValueIsNull(context, backgroundImagePath))
715 DeviceAPI::Filesystem::IPathPtr backgroundImage = DeviceAPI::Filesystem::Utils::fromVirtualPath(context, JSUtil::JSValueToString(context, backgroundImagePath));
716 priv->setBackground(backgroundImage->getFullPath());
720 JSValueRef thumbnails = JSUtil::getProperty(context, object, STATUS_NOTIFICATION_THUMBNAILS);
722 std::vector<std::string> thumbnailPaths;
723 if( JSIsArrayValue(context, thumbnails)){
724 JSObjectRef arrayobj = JSUtil::JSValueToObject(context, thumbnails);
725 for (std::size_t i = 0; i < JSGetArrayLength(context, arrayobj); ++i) {
726 JSValueRef element = JSGetArrayElement(context, arrayobj, i);
727 DeviceAPI::Filesystem::IPathPtr thumbnailPath =
728 DeviceAPI::Filesystem::Utils::fromVirtualPath(context, JSUtil::JSValueToString(context, element));
729 LoggerI("thumbnail Path = " << thumbnailPath->getFullPath());
730 thumbnailPaths.push_back(thumbnailPath->getFullPath());
733 priv->setThumbnails(thumbnailPaths);
736 JSValueRef soundPath = JSUtil::getProperty(context, object, STATUS_NOTIFICATION_SOUND_PATH);
737 if (!JSValueIsNull(context, soundPath))
739 DeviceAPI::Filesystem::IPathPtr sound = DeviceAPI::Filesystem::Utils::fromVirtualPath(context, JSUtil::JSValueToString(context, soundPath));
740 priv->setSoundPath(sound->getFullPath());
744 JSValueRef vibration = JSUtil::getProperty(context, object, STATUS_NOTIFICATION_VIBRATION);
745 priv->setDefaultVibration(JSUtil::JSValueToBoolean(context, vibration));
748 JSValueRef appControl = JSUtil::getProperty(context, object, STATUS_NOTIFICATION_APP_CONTROL);
749 if (!JSValueIsUndefined(context, appControl) && !JSValueIsNull(context, appControl))
750 priv->setApplicationControl(DeviceAPI::Application::JSApplicationControl::getApplicationControl(context, JSUtil::JSValueToObject(context,appControl)));
753 JSValueRef appId = JSUtil::getProperty(context, object, STATUS_NOTIFICATION_APP_ID);
754 if (!JSValueIsNull(context, appId))
755 priv->setApplicationId(JSUtil::JSValueToString(context, appId));
758 JSValueRef light = JSUtil::getProperty(context, object, STATUS_NOTIFICATION_LIGHT);
759 if (!JSValueIsNull(context, light))
760 priv->setLight(JSUtil::JSValueToString(context, light));
763 JSValueRef onTime = JSUtil::getProperty(context, object, STATUS_NOTIFICATION_LIGHT_ONTIME);
764 if (!JSValueIsNull(context, onTime))
765 priv->setLightOnTime(JSUtil::JSValueToLong(context, onTime));
768 JSValueRef offTime = JSUtil::getProperty(context, object, STATUS_NOTIFICATION_LIGHT_OFFTIME);
769 if (!JSValueIsNull(context, offTime))
770 priv->setLightOffTime(JSUtil::JSValueToLong(context, offTime));
775 void JSStatusNotification::setPrivateObject(JSContextRef context, JSObjectRef object, StatusNotification *priv)
778 JSObjectSetPrivate(object, static_cast<void*>(priv));
781 throw TypeMismatchException("StatusNotification object is invaild.");
784 std::string typeVal(NOTIFICATION_TYPE_VALUE);
785 JSUtil::setProperty(context, object, NOTIFICATION_TYPE,
786 JSUtil::toJSValueRef(context, typeVal), kJSPropertyAttributeReadOnly);
791 if ( NOTI_TYPE_SIMPLE == priv->getNotiType())
792 type = TIZEN_STATUS_NOTIFICATION_TYPE_SIMPLE;
793 else if ( NOTI_TYPE_ONGOING == priv->getNotiType())
794 type = TIZEN_STATUS_NOTIFICATION_TYPE_ONGOING;
795 else if ( NOTI_TYPE_PROGRESS == priv->getNotiType())
796 type = TIZEN_STATUS_NOTIFICATION_TYPE_PROGRESS;
797 else if ( NOTI_TYPE_THUMBNAIL == priv->getNotiType())
798 type = TIZEN_STATUS_NOTIFICATION_TYPE_THUMBNAIL;
800 throw TypeMismatchException("status type mismatch.");
802 JSUtil::setProperty(context, object, STATUS_NOTIFICATION_STATUS_TYPE,
803 JSUtil::toJSValueRef(context, type), kJSPropertyAttributeReadOnly);
805 if (priv->getID() >= 0)
807 std::stringstream stream;
808 stream << priv->getID();
811 throw TypeMismatchException("Notification's ID conversion is failed.");
813 JSUtil::setProperty(context, object, NOTIFICATION_ID,
814 JSUtil::toJSValueRef(context, stream.str()), kJSPropertyAttributeReadOnly);
818 JSUtil::setProperty(context, object, NOTIFICATION_ID,
819 JSValueMakeUndefined(context), kJSPropertyAttributeReadOnly);
823 if (priv->getPostedTime() > 0)
825 JSUtil::setProperty(context, object, NOTIFICATION_POSTED_TIME,
826 JSUtil::makeDateObject(context,priv->getPostedTime()), kJSPropertyAttributeReadOnly);
830 JSUtil::setProperty(context, object, NOTIFICATION_POSTED_TIME,
831 JSValueMakeNull(context), kJSPropertyAttributeReadOnly);
835 JSUtil::setProperty(context, object, NOTIFICATION_TITLE,
836 JSUtil::toJSValueRef(context, priv->getTitle()), kJSPropertyAttributeNone);
839 if (!priv->getContent().empty())
840 JSUtil::setProperty(context, object, NOTIFICATION_CONTENT,
841 JSUtil::toJSValueRef(context, priv->getContent()), kJSPropertyAttributeNone);
843 JSUtil::setProperty(context, object, NOTIFICATION_CONTENT, JSValueMakeNull(context), kJSPropertyAttributeNone);
846 if (!priv->getIconPath().empty())
847 JSUtil::setProperty(context, object, STATUS_NOTIFICATION_ICON_PATH,
848 JSUtil::toJSValueRef(context, DeviceAPI::Filesystem::Utils::toVirtualPath(context, priv->getIconPath())), kJSPropertyAttributeNone);
850 JSUtil::setProperty(context, object, STATUS_NOTIFICATION_ICON_PATH, JSValueMakeNull(context), kJSPropertyAttributeNone);
853 if ( !priv->getSubIconPath().empty())
854 JSUtil::setProperty(context, object, STATUS_NOTIFICATION_SUB_ICON_PATH,
855 JSUtil::toJSValueRef(context, DeviceAPI::Filesystem::Utils::toVirtualPath(context, priv->getSubIconPath())), kJSPropertyAttributeNone);
857 JSUtil::setProperty(context, object, STATUS_NOTIFICATION_SUB_ICON_PATH, JSValueMakeNull(context), kJSPropertyAttributeNone);
860 if (priv->getStrNumber()){
861 JSUtil::setProperty(context, object, STATUS_NOTIFICATION_NUMBER,
862 JSUtil::toJSValueRef(context, priv->getNumber()), kJSPropertyAttributeNone);
865 JSUtil::setProperty(context, object, STATUS_NOTIFICATION_NUMBER, JSValueMakeNull(context), kJSPropertyAttributeNone);
867 // backgroundImagePath
868 if ( !priv->getBackground().empty())
869 JSUtil::setProperty(context, object, STATUS_NOTIFICATION_BACKGROUND_IMAGE_PATH,
870 JSUtil::toJSValueRef(context, DeviceAPI::Filesystem::Utils::toVirtualPath(context, priv->getBackground())), kJSPropertyAttributeNone);
872 JSUtil::setProperty(context, object, STATUS_NOTIFICATION_BACKGROUND_IMAGE_PATH, JSValueMakeNull(context), kJSPropertyAttributeNone);
875 std::vector<std::string> thumbnails = priv->getThumbnails();
876 LoggerI("Thumbnail Size : " << thumbnails.size());
877 JSValueRef tumbnailvalueArray[thumbnails.size()];
878 for( unsigned int i = 0 ; i < thumbnails.size(); i++) {
879 if (!thumbnails[i].empty())
881 LoggerI("Thumbnail :" << thumbnails[i]);
882 tumbnailvalueArray[i] = JSUtil::toJSValueRef(context, DeviceAPI::Filesystem::Utils::toVirtualPath(context, thumbnails[i]));
886 JSValueRef exception = NULL;
887 JSObjectRef jsThumbnails = JSObjectMakeArray(context, thumbnails.size(), tumbnailvalueArray, &exception);
888 if (exception != NULL) {
889 throw DeviceAPI::Common::UnknownException("Make Object Array failed.");
892 JSUtil::setProperty(context, object, STATUS_NOTIFICATION_THUMBNAILS,
893 jsThumbnails, kJSPropertyAttributeNone);
896 if ( !priv->getSoundPath().empty() )
897 JSUtil::setProperty(context, object, STATUS_NOTIFICATION_SOUND_PATH,
898 JSUtil::toJSValueRef(context, DeviceAPI::Filesystem::Utils::toVirtualPath(context, priv->getSoundPath())), kJSPropertyAttributeNone);
900 JSUtil::setProperty(context, object, STATUS_NOTIFICATION_SOUND_PATH, JSValueMakeNull(context), kJSPropertyAttributeNone);
903 JSUtil::setProperty(context, object, STATUS_NOTIFICATION_VIBRATION,
904 JSUtil::toJSValueRef(context, priv->getDefaultVibration()), kJSPropertyAttributeNone);
907 if (!priv->isNullApplicationID())
908 JSUtil::setProperty(context, object, STATUS_NOTIFICATION_APP_ID,
909 JSUtil::toJSValueRef(context, priv->getApplicationId()), kJSPropertyAttributeNone);
911 JSUtil::setProperty(context, object, STATUS_NOTIFICATION_APP_ID, JSValueMakeNull(context), kJSPropertyAttributeNone);
914 if (!priv->getLight().empty())
915 JSUtil::setProperty(context, object, STATUS_NOTIFICATION_LIGHT,
916 JSUtil::toJSValueRef(context, priv->getLight()), kJSPropertyAttributeNone);
918 JSUtil::setProperty(context, object, STATUS_NOTIFICATION_LIGHT,
919 JSValueMakeNull(context), kJSPropertyAttributeNone);
921 JSUtil::setProperty(context, object, STATUS_NOTIFICATION_LIGHT_ONTIME,
922 JSUtil::toJSValueRef(context, priv->getLightOnTime()), kJSPropertyAttributeNone);
924 JSUtil::setProperty(context, object, STATUS_NOTIFICATION_LIGHT_OFFTIME,
925 JSUtil::toJSValueRef(context, priv->getLightOffTime()), kJSPropertyAttributeNone);
928 std::vector<NotificationDetailInfo*> detailInfo = priv->getDetailInfos();
929 LoggerI("detail Info Size : " << detailInfo.size());
930 JSObjectRef valueArray[detailInfo.size()];
931 for( unsigned int i = 0 ; i < detailInfo.size(); i++) {
934 LoggerI("Main = " << detailInfo[i]->getMainText() << " Sub = " << detailInfo[i]->getSubText());
935 valueArray[i] = JSObjectMake(GlobalContextManager::getInstance()->getGlobalContext(context), JSNotificationDetailInfo::getClassRef(), static_cast<void*>(detailInfo[i]));
936 JSNotificationDetailInfo::setPrivateObject(context, valueArray[i], detailInfo[i]);
937 LoggerI("make Object : " << valueArray[i]);
942 JSObjectRef jsResult = JSObjectMakeArray(GlobalContextManager::getInstance()->getGlobalContext(context), detailInfo.size(), valueArray, &exception);
943 if (exception != NULL) {
944 throw DeviceAPI::Common::UnknownException("Make Object Array failed.");
948 JSUtil::setProperty(context, object, STATUS_NOTIFICATION_DETAIL_INFO,
949 jsResult, kJSPropertyAttributeNone);
952 if ( !(priv->getApplicationControl())->getOperation().empty())
954 DeviceAPI::Application::JSApplicationControlPriv *appCtrlPriv = new DeviceAPI::Application::JSApplicationControlPriv(context, priv->getApplicationControl());
955 JSObjectRef jsAppCtrl = JSObjectMake(context, DeviceAPI::Application::JSApplicationControl::getClassRef(), appCtrlPriv);
956 JSUtil::setProperty(context, object, STATUS_NOTIFICATION_APP_CONTROL, jsAppCtrl, kJSPropertyAttributeNone);
959 JSUtil::setProperty(context, object, STATUS_NOTIFICATION_APP_CONTROL, JSValueMakeNull(context), kJSPropertyAttributeNone);