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 },
67 bool JSStatusNotification::setProperty(JSContextRef context,
69 JSStringRef propertyName,
71 JSValueRef* exception)
74 StatusNotification *priv = static_cast<StatusNotification*>(JSObjectGetPrivate(object));
75 LoggerD("statusNotification :" << priv);
77 throw TypeMismatchException("StatusNotification's private object is NULL.");
82 size_t jsSize = JSStringGetMaximumUTF8CStringSize(propertyName);
85 char* buffer = new char[jsSize];
86 size_t written = JSStringGetUTF8CString(propertyName, buffer, jsSize);
87 if (written > jsSize) {
88 throw InvalidValuesException("Conversion could not be fully performed.");
94 LoggerI("property =" << property);
96 if ( property == STATUS_NOTIFICATION_PROGRESS_TYPE)
98 std::string strProgressType = JSUtil::JSValueToString(context, value);
99 LoggerI("Progress Type : " << strProgressType);
101 NotificationProgressType progType = NOTI_PROGRESS_TYPE_NONE;
102 if( strProgressType.compare(TIZEN_NOTIFICATION_PROGRESS_TYPE_PERCENTAGE) == 0)
103 progType = NOTI_PROGRESS_TYPE_PERCENTAGE;
104 else if( strProgressType.compare(TIZEN_NOTIFICATION_PROGRESS_TYPE_BYTE) == 0)
105 progType = NOTI_PROGRESS_TYPE_SIZE;
107 throw InvalidValuesException("Invalid Progress Type.");
109 priv->setProgressType(progType); //set progress Type
113 else if ( property == STATUS_NOTIFICATION_PROGRESS_VALUE)
116 unsigned long progressVal = JSUtil::JSValueToULong(context, value);
117 LoggerI("Progress Value : " << progressVal);
119 if ( priv->getProgressType() == NOTI_PROGRESS_TYPE_PERCENTAGE)
121 if ( 100 < progressVal )
122 throw InvalidValuesException("The percentage progress value must be between 0 and 100");
123 priv->setProgressValue((double)progressVal/(double)100);
127 priv->setProgressValue((double)progressVal);
134 catch ( const BasePlatformException& err)
136 LoggerW(" notification convertion is failed. " << err.getName().c_str() << ":" << err.getMessage().c_str());
143 JSValueRef JSStatusNotification::getProperty(JSContextRef context,
145 JSStringRef propertyName,
146 JSValueRef* exception)
149 StatusNotification *priv = static_cast<StatusNotification*>(JSObjectGetPrivate(object));
150 LoggerD("statusNotification :" << priv);
152 throw TypeMismatchException("StatusNotification's private object is NULL.");
156 std::string property;
157 size_t jsSize = JSStringGetMaximumUTF8CStringSize(propertyName);
160 char* buffer = new char[jsSize];
161 size_t written = JSStringGetUTF8CString(propertyName, buffer, jsSize);
162 if (written > jsSize) {
163 throw InvalidValuesException("Conversion could not be fully performed.");
169 LoggerI("property =" << property);
170 if ( property == STATUS_NOTIFICATION_PROGRESS_TYPE)
173 if ( NOTI_PROGRESS_TYPE_PERCENTAGE == priv->getProgressType())
175 type = TIZEN_NOTIFICATION_PROGRESS_TYPE_PERCENTAGE;
177 else if ( NOTI_PROGRESS_TYPE_SIZE== priv->getProgressType())
179 type = TIZEN_NOTIFICATION_PROGRESS_TYPE_BYTE;
182 return JSUtil::toJSValueRef(context, type);
185 else if ( property == STATUS_NOTIFICATION_PROGRESS_VALUE)
188 LoggerI("Progress Type=" << priv->getProgressType());
191 unsigned long progressVal = 0;
192 if ( NOTI_PROGRESS_TYPE_PERCENTAGE == priv->getProgressType())
194 progressVal = (unsigned long)( (priv->getProgressValue()*100) );
196 else if ( NOTI_PROGRESS_TYPE_SIZE== priv->getProgressType())
198 progressVal = (unsigned long)priv->getProgressValue();
201 LoggerI("Progress Value=" << progressVal);
203 if( priv->getNotiType() != NOTI_TYPE_PROGRESS && progressVal == 0)
205 return JSValueMakeNull(context);
209 return JSUtil::toJSValueRef(context, progressVal);
214 catch ( const BasePlatformException& err)
216 LoggerW(" notification convertion is failed. " << err.getName().c_str() << ":" << err.getMessage().c_str());
224 JSClassRef JSStatusNotification::m_jsClassRef = JSClassCreate(JSStatusNotification::getClassInfo());
226 const JSClassRef JSStatusNotification::getClassRef()
229 m_jsClassRef = JSClassCreate(&m_classInfo);
234 const JSClassDefinition* JSStatusNotification::getClassInfo()
239 void JSStatusNotification::initialize(JSContextRef context, JSObjectRef object)
241 LoggerD("JSStatusNotification::initialize, nothing ");
244 void JSStatusNotification::finalize(JSObjectRef object)
246 StatusNotification *priv = static_cast<StatusNotification*>(JSObjectGetPrivate(object));
248 JSObjectSetPrivate(object, NULL);
253 JSObjectRef JSStatusNotification::constructor(JSContextRef context,
254 JSObjectRef constructor,
255 size_t argumentCount,
256 const JSValueRef arguments[],
257 JSValueRef* exception)
259 ArgumentValidator validator(context, argumentCount, arguments);
262 JSObjectRef obj = JSObjectMake(context, getClassRef(), NULL);
264 JSStringRef ctorName = JSStringCreateWithUTF8CString("constructor");
265 JSObjectSetProperty(context, obj, ctorName, constructor,
266 kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete | kJSPropertyAttributeDontEnum, NULL);
267 JSStringRelease(ctorName);
270 //Status Notification Type.
271 NotificationType notiType = NOTI_TYPE_NONE;
272 std::string strStatusType = validator.toString(0, false, "");
273 LoggerI("Notification Type : " << strStatusType);
275 if( strStatusType.compare(TIZEN_STATUS_NOTIFICATION_TYPE_SIMPLE) == 0)
276 notiType = NOTI_TYPE_SIMPLE;
277 else if( strStatusType.compare(TIZEN_STATUS_NOTIFICATION_TYPE_THUMBNAIL) == 0)
278 notiType = NOTI_TYPE_THUMBNAIL;
279 else if( strStatusType.compare(TIZEN_STATUS_NOTIFICATION_TYPE_ONGOING) == 0)
280 notiType = NOTI_TYPE_ONGOING;
281 else if( strStatusType.compare(TIZEN_STATUS_NOTIFICATION_TYPE_PROGRESS) == 0)
282 notiType = NOTI_TYPE_PROGRESS;
284 notiType = NOTI_TYPE_NONE;
286 StatusNotification *priv = new StatusNotification(notiType);
288 priv->setTitle(validator.toString(1, false, "")); //title
290 JSObjectRef notiInitDict = validator.toObject(2, true);
294 LoggerI("Set Notification Init Dictionary");
296 JSValueRef contentValue = JSUtil::getProperty(context, notiInitDict, NOTIFICATION_CONTENT);
297 if (!(JSValueIsUndefined(context, contentValue) || JSValueIsNull(context, contentValue)))
299 priv->setContent(JSUtil::JSValueToString(context, contentValue));
304 JSValueRef iconValue = JSUtil::getProperty(context, notiInitDict, STATUS_NOTIFICATION_ICON_PATH);
305 if (!JSValueIsUndefined(context, iconValue))
307 DeviceAPI::Filesystem::IPathPtr path = DeviceAPI::Filesystem::Utils::fromVirtualPath(context, JSUtil::JSValueToString(context, iconValue));
308 priv->setIconPath(path->getFullPath());
313 LoggerW("Icon file path is invaild");
318 JSValueRef soundValue = JSUtil::getProperty(context, notiInitDict, STATUS_NOTIFICATION_SOUND_PATH);
319 if (!JSValueIsUndefined(context, soundValue))
321 DeviceAPI::Filesystem::IPathPtr path = DeviceAPI::Filesystem::Utils::fromVirtualPath(context, JSUtil::JSValueToString(context, soundValue));
322 priv->setSoundPath(path->getFullPath());
327 LoggerW("sound file path is invaild");
332 JSValueRef vibrationValue = JSUtil::getProperty(context, notiInitDict, STATUS_NOTIFICATION_VIBRATION);
333 priv->setDefaultVibration(JSUtil::JSValueToBoolean(context, vibrationValue));
337 LoggerW("sound file path is invaild");
342 JSValueRef appControlValue = JSUtil::getProperty(context, notiInitDict, STATUS_NOTIFICATION_APP_CONTROL);
343 if (!JSValueIsUndefined(context, appControlValue))
344 priv->setApplicationControl(DeviceAPI::Application::JSApplicationControl::getApplicationControl(context, JSUtil::JSValueToObject(context, appControlValue) ));
348 LoggerW("sound file path is invaild");
353 JSValueRef appIdValue = JSUtil::getProperty(context, notiInitDict, STATUS_NOTIFICATION_APP_ID);
354 if (!JSValueIsUndefined(context, appIdValue))
355 priv->setApplicationId(JSUtil::JSValueToString(context, appIdValue));
359 LoggerW("appID is invaild");
364 JSValueRef lightValue = JSUtil::getProperty(context, notiInitDict, STATUS_NOTIFICATION_LIGHT);
365 LoggerI("Light :" << JSUtil::JSValueToString(context, lightValue));
366 if (!JSValueIsUndefined(context, lightValue))
367 priv->setLight(JSUtil::JSValueToString(context, lightValue));
371 LoggerW("The LED value is invalid ");
377 JSValueRef onTimeValue = JSUtil::getProperty(context, notiInitDict, STATUS_NOTIFICATION_LIGHT_ONTIME);
378 if (!JSValueIsUndefined(context, onTimeValue))
379 priv->setLightOnTime(JSUtil::JSValueToLong(context, onTimeValue));
383 LoggerW("The LED value is invalid ");
388 JSValueRef offTimeValue = JSUtil::getProperty(context, notiInitDict, STATUS_NOTIFICATION_LIGHT_OFFTIME);
389 if (!JSValueIsUndefined(context, offTimeValue))
390 priv->setLightOffTime(JSUtil::JSValueToLong(context, offTimeValue));
395 LoggerW("The LED value is invalid ");
399 NotificationProgressType progressType = NOTI_PROGRESS_TYPE_PERCENTAGE;
402 JSStringRef propertyName = JSStringCreateWithUTF8CString(STATUS_NOTIFICATION_PROGRESS_TYPE);
403 bool has = JSObjectHasProperty(context, notiInitDict, propertyName);
404 JSStringRelease(propertyName);
407 JSValueRef progressTypeValue = JSUtil::getProperty(context, notiInitDict, STATUS_NOTIFICATION_PROGRESS_TYPE);
408 std::string strProgressType = JSUtil::JSValueToString(context, progressTypeValue);
409 LoggerI("==Progress Type : " << strProgressType);
410 if( strProgressType.compare(TIZEN_NOTIFICATION_PROGRESS_TYPE_PERCENTAGE) == 0)
411 progressType = NOTI_PROGRESS_TYPE_PERCENTAGE;
412 else if( strProgressType.compare(TIZEN_NOTIFICATION_PROGRESS_TYPE_BYTE) == 0)
413 progressType = NOTI_PROGRESS_TYPE_SIZE;
415 progressType = NOTI_PROGRESS_TYPE_NONE;
417 priv->setProgressType(progressType);
421 LoggerW("The progress type is invalid ");
426 JSValueRef progressValue = JSUtil::getProperty(context, notiInitDict, STATUS_NOTIFICATION_PROGRESS_VALUE);
427 if (!JSValueIsUndefined(context, progressValue))
429 if ( progressType == NOTI_PROGRESS_TYPE_PERCENTAGE)
431 if ( 100 < JSUtil::JSValueToULong(context, progressValue) )
433 LoggerW("The percentage progress value must be between 0 and 100");
435 priv->setProgressValue((double)JSUtil::JSValueToULong(context, progressValue)/(double)100);
439 priv->setProgressValue((double)JSUtil::JSValueToULong(context, progressValue));
445 LoggerW("The progress value is invalid ");
449 JSValueRef detailInfoValue = JSUtil::getProperty(context, notiInitDict, STATUS_NOTIFICATION_DETAIL_INFO);
451 std::vector<NotificationDetailInfo*> detailInfos;
452 if (JSIsArrayValue(context, detailInfoValue))
454 JSObjectRef arrayobj = JSUtil::JSValueToObject(context, detailInfoValue);
455 for(std::size_t i = 0; i < JSGetArrayLength(context, arrayobj); ++i)
457 JSValueRef element = JSGetArrayElement(context, arrayobj, i);
458 JSObjectRef object = JSUtil::JSValueToObject(context, element);
461 NotificationDetailInfo* item = static_cast<NotificationDetailInfo*>(JSObjectGetPrivate(object));
464 NotificationDetailInfo *detailinfo = NULL;
465 std::string main = item->getMainText();
467 if (item->isSubTexstNull())
469 detailinfo = new NotificationDetailInfo(NULL, (int)i, main);
473 std::string sub = item->getSubText();
474 detailinfo = new NotificationDetailInfo(NULL, (int)i, main, sub);
476 detailInfos.push_back(detailinfo);
481 NotificationDetailInfo *detailinfo = NULL;
482 std::string main = JSUtil::JSValueToString(context, JSUtil::getProperty(context, object, NOTIFICATION_DETAIL_INFO_MAIN_TEXT));
484 JSStringRef propertyName = JSStringCreateWithUTF8CString(NOTIFICATION_DETAIL_INFO_SUB_TEXT);
485 if ( JSObjectHasProperty(context, object, propertyName))
487 JSValueRef subObj = JSUtil::getProperty(context, object, NOTIFICATION_DETAIL_INFO_SUB_TEXT);
488 if (JSValueIsNull(context, subObj))
490 detailinfo = new NotificationDetailInfo(NULL, (int)i, main);
494 std::string sub = JSUtil::JSValueToString(context, JSUtil::getProperty(context, object, NOTIFICATION_DETAIL_INFO_SUB_TEXT));
495 detailinfo = new NotificationDetailInfo(NULL, (int)i, main, sub);
500 detailinfo = new NotificationDetailInfo(NULL, (int)i, main);
503 JSStringRelease(propertyName);
505 detailInfos.push_back(detailinfo);
511 priv->setDetailInfos(detailInfos);
515 JSValueRef backgroundImageValue = JSUtil::getProperty(context, notiInitDict, STATUS_NOTIFICATION_BACKGROUND_IMAGE_PATH);
516 if (!JSValueIsUndefined(context, backgroundImageValue))
518 DeviceAPI::Filesystem::IPathPtr path = DeviceAPI::Filesystem::Utils::fromVirtualPath(context, JSUtil::JSValueToString(context, backgroundImageValue));
519 priv->setBackground(path->getFullPath());
524 //throw TypeMismatchException("The backgound image path is invalid ");
525 LoggerW("The backgound image path is invalid ");
530 JSValueRef numberValue = JSUtil::getProperty(context, notiInitDict, STATUS_NOTIFICATION_NUMBER);
531 if (!JSValueIsUndefined(context, numberValue))
533 priv->setNumber(JSUtil::JSValueToLong(context, numberValue));
537 LoggerW("The number is invalid ");
542 JSValueRef thumbnailsValue = JSUtil::getProperty(context, notiInitDict, STATUS_NOTIFICATION_THUMBNAILS);
543 if (!JSValueIsUndefined(context, thumbnailsValue))
546 std::vector<std::string> thumbnailPaths;
547 if( JSIsArrayValue(context, thumbnailsValue)){
548 JSObjectRef arrayobj = JSUtil::JSValueToObject(context, thumbnailsValue);
549 for (std::size_t i = 0; i < JSGetArrayLength(context, arrayobj); ++i) {
550 JSValueRef element = JSGetArrayElement(context, arrayobj, i);
551 DeviceAPI::Filesystem::IPathPtr thumbnailPath =
552 DeviceAPI::Filesystem::Utils::fromVirtualPath(context, JSUtil::JSValueToString(context, element));
553 LoggerI("thumbnail Path = " << thumbnailPath->getFullPath());
554 thumbnailPaths.push_back(thumbnailPath->getFullPath());
557 priv->setThumbnails(thumbnailPaths);
562 //throw TypeMismatchException("thumbnail path convertion is failed.");
563 LoggerW("thumbnail path convertion is failed.");
568 JSValueRef subIconPathValue = JSUtil::getProperty(context, notiInitDict, STATUS_NOTIFICATION_SUB_ICON_PATH);
569 if (!JSValueIsUndefined(context, subIconPathValue))
571 DeviceAPI::Filesystem::IPathPtr path = DeviceAPI::Filesystem::Utils::fromVirtualPath(context, JSUtil::JSValueToString(context, subIconPathValue));
572 priv->setSubIconPath( path->getFullPath());
577 //throw TypeMismatchException("subIcon path convertion is failed.");
578 LoggerW("subIcon path convertion is failed.");
583 setPrivateObject(context, obj, priv);
585 catch ( const BasePlatformException& err)
587 LoggerW(" notification convertion is failed. " << err.getName().c_str() << ":" << err.getMessage().c_str());
588 //JSObjectRef error = JSWebAPIErrorFactory::makeErrorObject(context, err);
589 //*exception = error;
597 StatusNotification* JSStatusNotification::getPrivateObject(JSContextRef context, JSObjectRef object)
599 LoggerD("get object :" << object);
601 StatusNotification *priv = static_cast<StatusNotification*>(JSObjectGetPrivate(object));
602 LoggerD("statusNotification :" << priv);
604 throw TypeMismatchException("StatusNotification's private object is NULL.");
608 JSValueRef type = JSUtil::getProperty(context, object, NOTIFICATION_TYPE);
609 if ((JSUtil::JSValueToString(context, type)).compare(NOTIFICATION_TYPE_VALUE) )
611 throw TypeMismatchException("StatusNotification's type is mismatched");
615 JSValueRef title = JSUtil::getProperty(context, object, NOTIFICATION_TITLE);
616 priv->setTitle( JSUtil::JSValueToString(context, title));
619 JSValueRef contents = JSUtil::getProperty(context, object, NOTIFICATION_CONTENT);
620 if (!JSValueIsNull(context, contents))
622 priv->setContent( JSUtil::JSValueToString(context, contents));
626 JSValueRef iconPath = JSUtil::getProperty(context, object, STATUS_NOTIFICATION_ICON_PATH);
627 if ( !JSValueIsNull(context, contents) )
629 DeviceAPI::Filesystem::IPathPtr icon = DeviceAPI::Filesystem::Utils::fromVirtualPath(context, JSUtil::JSValueToString(context, iconPath));
630 priv->setIconPath(icon->getFullPath());
634 JSValueRef subIconPath = JSUtil::getProperty(context, object, STATUS_NOTIFICATION_SUB_ICON_PATH);
635 if (!JSValueIsNull(context, subIconPath))
637 DeviceAPI::Filesystem::IPathPtr subIcon = DeviceAPI::Filesystem::Utils::fromVirtualPath(context, JSUtil::JSValueToString(context, subIconPath));
638 priv->setSubIconPath(subIcon->getFullPath());
642 JSValueRef number = JSUtil::getProperty(context, object, STATUS_NOTIFICATION_NUMBER);
643 priv->setNumber(JSUtil::JSValueToLong(context, number));
646 JSValueRef detailInfo = JSUtil::getProperty(context, object, STATUS_NOTIFICATION_DETAIL_INFO);
647 std::vector<NotificationDetailInfo*> detailInfos;
648 if (JSIsArrayValue(context, detailInfo))
650 JSObjectRef arrayobj = JSUtil::JSValueToObject(context, detailInfo);
651 for(std::size_t i = 0; i < JSGetArrayLength(context, arrayobj); ++i)
653 JSValueRef element = JSGetArrayElement(context, arrayobj, i);
654 JSObjectRef object = JSUtil::JSValueToObject(context, element);
657 NotificationDetailInfo* detailinfo = static_cast<NotificationDetailInfo*>(JSObjectGetPrivate(object));
658 detailInfos.push_back(detailinfo);
662 priv->setDetailInfos(detailInfos);
664 // backgroundImagePath
665 JSValueRef backgroundImagePath = JSUtil::getProperty(context, object, STATUS_NOTIFICATION_BACKGROUND_IMAGE_PATH);
666 if (!JSValueIsNull(context, backgroundImagePath))
668 DeviceAPI::Filesystem::IPathPtr backgroundImage = DeviceAPI::Filesystem::Utils::fromVirtualPath(context, JSUtil::JSValueToString(context, backgroundImagePath));
669 priv->setBackground(backgroundImage->getFullPath());
673 JSValueRef thumbnails = JSUtil::getProperty(context, object, STATUS_NOTIFICATION_THUMBNAILS);
675 std::vector<std::string> thumbnailPaths;
676 if( JSIsArrayValue(context, thumbnails)){
677 JSObjectRef arrayobj = JSUtil::JSValueToObject(context, thumbnails);
678 for (std::size_t i = 0; i < JSGetArrayLength(context, arrayobj); ++i) {
679 JSValueRef element = JSGetArrayElement(context, arrayobj, i);
680 DeviceAPI::Filesystem::IPathPtr thumbnailPath =
681 DeviceAPI::Filesystem::Utils::fromVirtualPath(context, JSUtil::JSValueToString(context, element));
682 LoggerI("thumbnail Path = " << thumbnailPath->getFullPath());
683 thumbnailPaths.push_back(thumbnailPath->getFullPath());
686 priv->setThumbnails(thumbnailPaths);
689 JSValueRef soundPath = JSUtil::getProperty(context, object, STATUS_NOTIFICATION_SOUND_PATH);
690 if (!JSValueIsNull(context, soundPath))
692 DeviceAPI::Filesystem::IPathPtr sound = DeviceAPI::Filesystem::Utils::fromVirtualPath(context, JSUtil::JSValueToString(context, soundPath));
693 priv->setSoundPath(sound->getFullPath());
697 JSValueRef vibration = JSUtil::getProperty(context, object, STATUS_NOTIFICATION_VIBRATION);
698 priv->setDefaultVibration(JSUtil::JSValueToBoolean(context, vibration));
701 JSValueRef appControl = JSUtil::getProperty(context, object, STATUS_NOTIFICATION_APP_CONTROL);
702 if (!JSValueIsUndefined(context, appControl) && !JSValueIsNull(context, appControl))
703 priv->setApplicationControl(DeviceAPI::Application::JSApplicationControl::getApplicationControl(context, JSUtil::JSValueToObject(context,appControl)));
706 JSValueRef appId = JSUtil::getProperty(context, object, STATUS_NOTIFICATION_APP_ID);
707 if (!JSValueIsNull(context, appId))
708 priv->setApplicationId(JSUtil::JSValueToString(context, appId));
711 JSValueRef light = JSUtil::getProperty(context, object, STATUS_NOTIFICATION_LIGHT);
712 if (!JSValueIsNull(context, light))
713 priv->setLight(JSUtil::JSValueToString(context, light));
716 JSValueRef onTime = JSUtil::getProperty(context, object, STATUS_NOTIFICATION_LIGHT_ONTIME);
717 if (!JSValueIsNull(context, onTime))
718 priv->setLightOnTime(JSUtil::JSValueToLong(context, onTime));
721 JSValueRef offTime = JSUtil::getProperty(context, object, STATUS_NOTIFICATION_LIGHT_OFFTIME);
722 if (!JSValueIsNull(context, offTime))
723 priv->setLightOffTime(JSUtil::JSValueToLong(context, offTime));
728 void JSStatusNotification::setPrivateObject(JSContextRef context, JSObjectRef object, StatusNotification *priv)
731 JSObjectSetPrivate(object, static_cast<void*>(priv));
734 throw TypeMismatchException("StatusNotification object is invaild.");
737 std::string typeVal(NOTIFICATION_TYPE_VALUE);
738 JSUtil::setProperty(context, object, NOTIFICATION_TYPE,
739 JSUtil::toJSValueRef(context, typeVal), kJSPropertyAttributeReadOnly);
744 if ( NOTI_TYPE_SIMPLE == priv->getNotiType())
745 type = TIZEN_STATUS_NOTIFICATION_TYPE_SIMPLE;
746 else if ( NOTI_TYPE_ONGOING == priv->getNotiType())
747 type = TIZEN_STATUS_NOTIFICATION_TYPE_ONGOING;
748 else if ( NOTI_TYPE_PROGRESS == priv->getNotiType())
749 type = TIZEN_STATUS_NOTIFICATION_TYPE_PROGRESS;
750 else if ( NOTI_TYPE_THUMBNAIL == priv->getNotiType())
751 type = TIZEN_STATUS_NOTIFICATION_TYPE_THUMBNAIL;
753 throw TypeMismatchException("status type mismatch.");
755 JSUtil::setProperty(context, object, STATUS_NOTIFICATION_STATUS_TYPE,
756 JSUtil::toJSValueRef(context, type), kJSPropertyAttributeReadOnly);
758 if (priv->getID() >= 0)
760 std::stringstream stream;
761 stream << priv->getID();
764 throw TypeMismatchException("Notification's ID conversion is failed.");
766 JSUtil::setProperty(context, object, NOTIFICATION_ID,
767 JSUtil::toJSValueRef(context, stream.str()), kJSPropertyAttributeReadOnly);
771 JSUtil::setProperty(context, object, NOTIFICATION_ID,
772 JSValueMakeUndefined(context), kJSPropertyAttributeReadOnly);
776 if (priv->getPostedTime() > 0)
778 JSUtil::setProperty(context, object, NOTIFICATION_POSTED_TIME,
779 JSUtil::makeDateObject(context,priv->getPostedTime()), kJSPropertyAttributeReadOnly);
783 JSUtil::setProperty(context, object, NOTIFICATION_POSTED_TIME,
784 JSValueMakeNull(context), kJSPropertyAttributeReadOnly);
788 JSUtil::setProperty(context, object, NOTIFICATION_TITLE,
789 JSUtil::toJSValueRef(context, priv->getTitle()), kJSPropertyAttributeNone);
792 if (!priv->getContent().empty())
793 JSUtil::setProperty(context, object, NOTIFICATION_CONTENT,
794 JSUtil::toJSValueRef(context, priv->getContent()), kJSPropertyAttributeNone);
796 JSUtil::setProperty(context, object, NOTIFICATION_CONTENT, JSValueMakeNull(context), kJSPropertyAttributeNone);
799 if (!priv->getIconPath().empty())
800 JSUtil::setProperty(context, object, STATUS_NOTIFICATION_ICON_PATH,
801 JSUtil::toJSValueRef(context, DeviceAPI::Filesystem::Utils::toVirtualPath(context, priv->getIconPath())), kJSPropertyAttributeNone);
803 JSUtil::setProperty(context, object, STATUS_NOTIFICATION_ICON_PATH, JSValueMakeNull(context), kJSPropertyAttributeNone);
806 if ( !priv->getSubIconPath().empty())
807 JSUtil::setProperty(context, object, STATUS_NOTIFICATION_SUB_ICON_PATH,
808 JSUtil::toJSValueRef(context, DeviceAPI::Filesystem::Utils::toVirtualPath(context, priv->getSubIconPath())), kJSPropertyAttributeNone);
810 JSUtil::setProperty(context, object, STATUS_NOTIFICATION_SUB_ICON_PATH, JSValueMakeNull(context), kJSPropertyAttributeNone);
813 if (priv->getStrNumber()){
814 JSUtil::setProperty(context, object, STATUS_NOTIFICATION_NUMBER,
815 JSUtil::toJSValueRef(context, priv->getNumber()), kJSPropertyAttributeNone);
818 JSUtil::setProperty(context, object, STATUS_NOTIFICATION_NUMBER, JSValueMakeNull(context), kJSPropertyAttributeNone);
820 // backgroundImagePath
821 if ( !priv->getBackground().empty())
822 JSUtil::setProperty(context, object, STATUS_NOTIFICATION_BACKGROUND_IMAGE_PATH,
823 JSUtil::toJSValueRef(context, DeviceAPI::Filesystem::Utils::toVirtualPath(context, priv->getBackground())), kJSPropertyAttributeNone);
825 JSUtil::setProperty(context, object, STATUS_NOTIFICATION_BACKGROUND_IMAGE_PATH, JSValueMakeNull(context), kJSPropertyAttributeNone);
828 std::vector<std::string> thumbnails = priv->getThumbnails();
829 LoggerI("Thumbnail Size : " << thumbnails.size());
830 JSValueRef tumbnailvalueArray[thumbnails.size()];
831 for( unsigned int i = 0 ; i < thumbnails.size(); i++) {
832 if (!thumbnails[i].empty())
834 LoggerI("Thumbnail :" << thumbnails[i]);
835 tumbnailvalueArray[i] = JSUtil::toJSValueRef(context, DeviceAPI::Filesystem::Utils::toVirtualPath(context, thumbnails[i]));
839 JSValueRef exception = NULL;
840 JSObjectRef jsThumbnails = JSObjectMakeArray(context, thumbnails.size(), tumbnailvalueArray, &exception);
841 if (exception != NULL) {
842 throw DeviceAPI::Common::UnknownException("Make Object Array failed.");
845 JSUtil::setProperty(context, object, STATUS_NOTIFICATION_THUMBNAILS,
846 jsThumbnails, kJSPropertyAttributeNone);
849 if ( !priv->getSoundPath().empty() )
850 JSUtil::setProperty(context, object, STATUS_NOTIFICATION_SOUND_PATH,
851 JSUtil::toJSValueRef(context, DeviceAPI::Filesystem::Utils::toVirtualPath(context, priv->getSoundPath())), kJSPropertyAttributeNone);
853 JSUtil::setProperty(context, object, STATUS_NOTIFICATION_SOUND_PATH, JSValueMakeNull(context), kJSPropertyAttributeNone);
856 JSUtil::setProperty(context, object, STATUS_NOTIFICATION_VIBRATION,
857 JSUtil::toJSValueRef(context, priv->getDefaultVibration()), kJSPropertyAttributeNone);
860 if (!priv->isNullApplicationID())
861 JSUtil::setProperty(context, object, STATUS_NOTIFICATION_APP_ID,
862 JSUtil::toJSValueRef(context, priv->getApplicationId()), kJSPropertyAttributeNone);
864 JSUtil::setProperty(context, object, STATUS_NOTIFICATION_APP_ID, JSValueMakeNull(context), kJSPropertyAttributeNone);
867 if (!priv->getLight().empty())
868 JSUtil::setProperty(context, object, STATUS_NOTIFICATION_LIGHT,
869 JSUtil::toJSValueRef(context, priv->getLight()), kJSPropertyAttributeNone);
871 JSUtil::setProperty(context, object, STATUS_NOTIFICATION_LIGHT,
872 JSValueMakeNull(context), kJSPropertyAttributeNone);
874 JSUtil::setProperty(context, object, STATUS_NOTIFICATION_LIGHT_ONTIME,
875 JSUtil::toJSValueRef(context, priv->getLightOnTime()), kJSPropertyAttributeNone);
877 JSUtil::setProperty(context, object, STATUS_NOTIFICATION_LIGHT_OFFTIME,
878 JSUtil::toJSValueRef(context, priv->getLightOffTime()), kJSPropertyAttributeNone);
881 std::vector<NotificationDetailInfo*> detailInfo = priv->getDetailInfos();
882 LoggerI("detail Info Size : " << detailInfo.size());
883 JSObjectRef valueArray[detailInfo.size()];
884 for( unsigned int i = 0 ; i < detailInfo.size(); i++) {
887 LoggerI("Main = " << detailInfo[i]->getMainText() << " Sub = " << detailInfo[i]->getSubText());
888 valueArray[i] = JSObjectMake(GlobalContextManager::getInstance()->getGlobalContext(context), JSNotificationDetailInfo::getClassRef(), static_cast<void*>(detailInfo[i]));
889 JSNotificationDetailInfo::setPrivateObject(context, valueArray[i], detailInfo[i]);
890 LoggerI("make Object : " << valueArray[i]);
895 JSObjectRef jsResult = JSObjectMakeArray(GlobalContextManager::getInstance()->getGlobalContext(context), detailInfo.size(), valueArray, &exception);
896 if (exception != NULL) {
897 throw DeviceAPI::Common::UnknownException("Make Object Array failed.");
901 JSUtil::setProperty(context, object, STATUS_NOTIFICATION_DETAIL_INFO,
902 jsResult, kJSPropertyAttributeNone);
905 if ( !(priv->getApplicationControl())->getOperation().empty())
907 DeviceAPI::Application::JSApplicationControlPriv *appCtrlPriv = new DeviceAPI::Application::JSApplicationControlPriv(context, priv->getApplicationControl());
908 JSObjectRef jsAppCtrl = JSObjectMake(context, DeviceAPI::Application::JSApplicationControl::getClassRef(), appCtrlPriv);
909 JSUtil::setProperty(context, object, STATUS_NOTIFICATION_APP_CONTROL, jsAppCtrl, kJSPropertyAttributeNone);
912 JSUtil::setProperty(context, object, STATUS_NOTIFICATION_APP_CONTROL, JSValueMakeNull(context), kJSPropertyAttributeNone);