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 throw TypeMismatchException("notification status type mismatch.");
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 throw InvalidValuesException("Icon file path is invaild");
316 catch ( const BasePlatformException& err)
318 LoggerW("notification's icon path convertion is failed." << err.getMessage());
324 JSValueRef soundValue = JSUtil::getProperty(context, notiInitDict, STATUS_NOTIFICATION_SOUND_PATH);
325 if (!JSValueIsUndefined(context, soundValue))
327 DeviceAPI::Filesystem::IPathPtr path = DeviceAPI::Filesystem::Utils::fromVirtualPath(context, JSUtil::JSValueToString(context, soundValue));
328 priv->setSoundPath(path->getFullPath());
333 throw InvalidValuesException("sound file path is invaild");
337 JSValueRef vibrationValue = JSUtil::getProperty(context, notiInitDict, STATUS_NOTIFICATION_VIBRATION);
338 priv->setDefaultVibration(JSUtil::JSValueToBoolean(context, vibrationValue));
341 JSValueRef appControlValue = JSUtil::getProperty(context, notiInitDict, STATUS_NOTIFICATION_APP_CONTROL);
342 if (!JSValueIsUndefined(context, appControlValue))
343 priv->setApplicationControl(DeviceAPI::Application::JSApplicationControl::getApplicationControl(context, JSUtil::JSValueToObject(context, appControlValue) ));
346 JSValueRef appIdValue = JSUtil::getProperty(context, notiInitDict, STATUS_NOTIFICATION_APP_ID);
347 if (!JSValueIsUndefined(context, appIdValue))
348 priv->setApplicationId(JSUtil::JSValueToString(context, appIdValue));
351 JSValueRef lightValue = JSUtil::getProperty(context, notiInitDict, STATUS_NOTIFICATION_LIGHT);
352 LoggerI("Light :" << JSUtil::JSValueToString(context, lightValue));
353 if (!JSValueIsUndefined(context, lightValue))
354 priv->setLight(JSUtil::JSValueToString(context, lightValue));
357 JSValueRef onTimeValue = JSUtil::getProperty(context, notiInitDict, STATUS_NOTIFICATION_LIGHT_ONTIME);
358 if (!JSValueIsUndefined(context, onTimeValue))
359 priv->setLightOnTime(JSUtil::JSValueToLong(context, onTimeValue));
362 JSValueRef offTimeValue = JSUtil::getProperty(context, notiInitDict, STATUS_NOTIFICATION_LIGHT_OFFTIME);
363 if (!JSValueIsUndefined(context, offTimeValue))
364 priv->setLightOffTime(JSUtil::JSValueToLong(context, offTimeValue));
367 NotificationProgressType progressType = NOTI_PROGRESS_TYPE_PERCENTAGE;
369 JSStringRef propertyName = JSStringCreateWithUTF8CString(STATUS_NOTIFICATION_PROGRESS_TYPE);
370 bool has = JSObjectHasProperty(context, notiInitDict, propertyName);
371 JSStringRelease(propertyName);
374 JSValueRef progressTypeValue = JSUtil::getProperty(context, notiInitDict, STATUS_NOTIFICATION_PROGRESS_TYPE);
375 std::string strProgressType = JSUtil::JSValueToString(context, progressTypeValue);
376 LoggerI("==Progress Type : " << strProgressType);
377 if( strProgressType.compare(TIZEN_NOTIFICATION_PROGRESS_TYPE_PERCENTAGE) == 0)
378 progressType = NOTI_PROGRESS_TYPE_PERCENTAGE;
379 else if( strProgressType.compare(TIZEN_NOTIFICATION_PROGRESS_TYPE_BYTE) == 0)
380 progressType = NOTI_PROGRESS_TYPE_SIZE;
382 throw TypeMismatchException("Invalid Progress Type.");
384 priv->setProgressType(progressType);
387 JSValueRef progressTypeValue = JSUtil::getProperty(context, notiInitDict, STATUS_NOTIFICATION_PROGRESS_TYPE);
388 if (progressTypeValue)
392 if (!JSValueIsUndefined(context, progressTypeValue))
394 std::string strProgressType = JSUtil::JSValueToString(context, progressTypeValue);
395 LoggerI("==Progress Type : " << strProgressType);
396 if( strProgressType.compare(TIZEN_NOTIFICATION_PROGRESS_TYPE_PERCENTAGE) == 0)
397 progressType = NOTI_PROGRESS_TYPE_PERCENTAGE;
398 else if( strProgressType.compare(TIZEN_NOTIFICATION_PROGRESS_TYPE_BYTE) == 0)
399 progressType = NOTI_PROGRESS_TYPE_SIZE;
401 throw TypeMismatchException("Invalid Progress Type.");
403 priv->setProgressType(progressType);
406 JSValueRef progressValue = JSUtil::getProperty(context, notiInitDict, STATUS_NOTIFICATION_PROGRESS_VALUE);
407 if (!JSValueIsUndefined(context, progressValue))
409 if ( progressType == NOTI_PROGRESS_TYPE_PERCENTAGE)
411 if ( 100 < JSUtil::JSValueToULong(context, progressValue) )
412 throw TypeMismatchException("The percentage progress value must be between 0 and 100");
413 priv->setProgressValue((double)JSUtil::JSValueToULong(context, progressValue)/(double)100);
417 priv->setProgressValue((double)JSUtil::JSValueToULong(context, progressValue));
422 JSValueRef detailInfoValue = JSUtil::getProperty(context, notiInitDict, STATUS_NOTIFICATION_DETAIL_INFO);
424 std::vector<NotificationDetailInfo*> detailInfos;
425 if (JSIsArrayValue(context, detailInfoValue))
427 JSObjectRef arrayobj = JSUtil::JSValueToObject(context, detailInfoValue);
428 for(std::size_t i = 0; i < JSGetArrayLength(context, arrayobj); ++i)
430 JSValueRef element = JSGetArrayElement(context, arrayobj, i);
431 JSObjectRef object = JSUtil::JSValueToObject(context, element);
434 NotificationDetailInfo* item = static_cast<NotificationDetailInfo*>(JSObjectGetPrivate(object));
435 std::string main = item->getMainText();
436 std::string sub = item->getSubText();
437 LoggerI("Main : " << main << " Sub : " << sub);
439 NotificationDetailInfo *detailinfo = new NotificationDetailInfo(NULL, (int)i, main, sub);
440 detailInfos.push_back(detailinfo);
444 priv->setDetailInfos(detailInfos);
448 JSValueRef backgroundImageValue = JSUtil::getProperty(context, notiInitDict, STATUS_NOTIFICATION_BACKGROUND_IMAGE_PATH);
449 if (!JSValueIsUndefined(context, backgroundImageValue))
451 DeviceAPI::Filesystem::IPathPtr path = DeviceAPI::Filesystem::Utils::fromVirtualPath(context, JSUtil::JSValueToString(context, backgroundImageValue));
452 priv->setBackground(path->getFullPath());
457 throw TypeMismatchException("The backgound image path is invalid : ");
461 JSValueRef numberValue = JSUtil::getProperty(context, notiInitDict, STATUS_NOTIFICATION_NUMBER);
462 if (!JSValueIsUndefined(context, numberValue))
464 priv->setNumber(JSUtil::JSValueToLong(context, numberValue));
469 JSValueRef thumbnailsValue = JSUtil::getProperty(context, notiInitDict, STATUS_NOTIFICATION_THUMBNAILS);
470 if (!JSValueIsUndefined(context, thumbnailsValue))
473 std::vector<std::string> thumbnailPaths;
474 if( JSIsArrayValue(context, thumbnailsValue)){
475 JSObjectRef arrayobj = JSUtil::JSValueToObject(context, thumbnailsValue);
476 for (std::size_t i = 0; i < JSGetArrayLength(context, arrayobj); ++i) {
477 JSValueRef element = JSGetArrayElement(context, arrayobj, i);
478 DeviceAPI::Filesystem::IPathPtr thumbnailPath =
479 DeviceAPI::Filesystem::Utils::fromVirtualPath(context, JSUtil::JSValueToString(context, element));
480 LoggerI("thumbnail Path = " << thumbnailPath->getFullPath());
481 thumbnailPaths.push_back(thumbnailPath->getFullPath());
484 priv->setThumbnails(thumbnailPaths);
489 throw TypeMismatchException("thumbnail path convertion is failed.");
494 JSValueRef subIconPathValue = JSUtil::getProperty(context, notiInitDict, STATUS_NOTIFICATION_SUB_ICON_PATH);
495 if (!JSValueIsUndefined(context, subIconPathValue))
497 DeviceAPI::Filesystem::IPathPtr path = DeviceAPI::Filesystem::Utils::fromVirtualPath(context, JSUtil::JSValueToString(context, subIconPathValue));
498 priv->setSubIconPath( path->getFullPath());
503 throw TypeMismatchException("subIcon path convertion is failed.");
508 setPrivateObject(context, obj, priv);
511 catch ( const BasePlatformException& err)
513 LoggerW(" notification convertion is failed. " << err.getName().c_str() << ":" << err.getMessage().c_str());
514 JSObjectRef error = JSWebAPIErrorFactory::makeErrorObject(context, err);
523 StatusNotification* JSStatusNotification::getPrivateObject(JSContextRef context, JSObjectRef object)
525 LoggerD("get object :" << object);
527 StatusNotification *priv = static_cast<StatusNotification*>(JSObjectGetPrivate(object));
528 LoggerD("statusNotification :" << priv);
530 throw TypeMismatchException("StatusNotification's private object is NULL.");
534 JSValueRef type = JSUtil::getProperty(context, object, NOTIFICATION_TYPE);
535 if ((JSUtil::JSValueToString(context, type)).compare(NOTIFICATION_TYPE_VALUE) )
537 throw TypeMismatchException("StatusNotification's type is mismatched");
541 JSValueRef title = JSUtil::getProperty(context, object, NOTIFICATION_TITLE);
542 priv->setTitle( JSUtil::JSValueToString(context, title));
545 JSValueRef contents = JSUtil::getProperty(context, object, NOTIFICATION_CONTENT);
546 if (!JSValueIsNull(context, contents))
548 priv->setContent( JSUtil::JSValueToString(context, contents));
552 JSValueRef iconPath = JSUtil::getProperty(context, object, STATUS_NOTIFICATION_ICON_PATH);
553 if ( !JSValueIsNull(context, contents) )
555 DeviceAPI::Filesystem::IPathPtr icon = DeviceAPI::Filesystem::Utils::fromVirtualPath(context, JSUtil::JSValueToString(context, iconPath));
556 priv->setIconPath(icon->getFullPath());
560 // priv->setIconPath("");
564 JSValueRef subIconPath = JSUtil::getProperty(context, object, STATUS_NOTIFICATION_SUB_ICON_PATH);
565 if (!JSValueIsNull(context, subIconPath))
567 DeviceAPI::Filesystem::IPathPtr subIcon = DeviceAPI::Filesystem::Utils::fromVirtualPath(context, JSUtil::JSValueToString(context, subIconPath));
568 priv->setSubIconPath(subIcon->getFullPath());
572 // priv->setSubIconPath("");
576 JSValueRef number = JSUtil::getProperty(context, object, STATUS_NOTIFICATION_NUMBER);
577 priv->setNumber(JSUtil::JSValueToLong(context, number));
580 JSValueRef detailInfo = JSUtil::getProperty(context, object, STATUS_NOTIFICATION_DETAIL_INFO);
581 std::vector<NotificationDetailInfo*> detailInfos;
582 if (JSIsArrayValue(context, detailInfo))
584 JSObjectRef arrayobj = JSUtil::JSValueToObject(context, detailInfo);
585 for(std::size_t i = 0; i < JSGetArrayLength(context, arrayobj); ++i)
587 JSValueRef element = JSGetArrayElement(context, arrayobj, i);
588 JSObjectRef object = JSUtil::JSValueToObject(context, element);
591 NotificationDetailInfo* detailinfo = static_cast<NotificationDetailInfo*>(JSObjectGetPrivate(object));
592 detailInfos.push_back(detailinfo);
596 priv->setDetailInfos(detailInfos);
598 // backgroundImagePath
599 JSValueRef backgroundImagePath = JSUtil::getProperty(context, object, STATUS_NOTIFICATION_BACKGROUND_IMAGE_PATH);
600 if (!JSValueIsNull(context, backgroundImagePath))
602 DeviceAPI::Filesystem::IPathPtr backgroundImage = DeviceAPI::Filesystem::Utils::fromVirtualPath(context, JSUtil::JSValueToString(context, backgroundImagePath));
603 priv->setBackground(backgroundImage->getFullPath());
607 // priv->setBackground("");
611 JSValueRef thumbnails = JSUtil::getProperty(context, object, STATUS_NOTIFICATION_THUMBNAILS);
613 std::vector<std::string> thumbnailPaths;
614 if( JSIsArrayValue(context, thumbnails)){
615 JSObjectRef arrayobj = JSUtil::JSValueToObject(context, thumbnails);
616 for (std::size_t i = 0; i < JSGetArrayLength(context, arrayobj); ++i) {
617 JSValueRef element = JSGetArrayElement(context, arrayobj, i);
618 DeviceAPI::Filesystem::IPathPtr thumbnailPath =
619 DeviceAPI::Filesystem::Utils::fromVirtualPath(context, JSUtil::JSValueToString(context, element));
620 LoggerI("thumbnail Path = " << thumbnailPath->getFullPath());
621 thumbnailPaths.push_back(thumbnailPath->getFullPath());
624 priv->setThumbnails(thumbnailPaths);
627 JSValueRef soundPath = JSUtil::getProperty(context, object, STATUS_NOTIFICATION_SOUND_PATH);
628 if (!JSValueIsNull(context, soundPath))
630 DeviceAPI::Filesystem::IPathPtr sound = DeviceAPI::Filesystem::Utils::fromVirtualPath(context, JSUtil::JSValueToString(context, soundPath));
631 priv->setSoundPath(sound->getFullPath());
635 // priv->setSoundPath("");
639 JSValueRef vibration = JSUtil::getProperty(context, object, STATUS_NOTIFICATION_VIBRATION);
640 priv->setDefaultVibration(JSUtil::JSValueToBoolean(context, vibration));
643 JSValueRef appControl = JSUtil::getProperty(context, object, STATUS_NOTIFICATION_APP_CONTROL);
644 if (!JSValueIsUndefined(context, appControl) && !JSValueIsNull(context, appControl))
645 priv->setApplicationControl(DeviceAPI::Application::JSApplicationControl::getApplicationControl(context, JSUtil::JSValueToObject(context,appControl)));
648 JSValueRef appId = JSUtil::getProperty(context, object, STATUS_NOTIFICATION_APP_ID);
649 if (!JSValueIsNull(context, appId))
650 priv->setApplicationId(JSUtil::JSValueToString(context, appId));
653 JSValueRef light = JSUtil::getProperty(context, object, STATUS_NOTIFICATION_LIGHT);
654 if (!JSValueIsNull(context, light))
655 priv->setLight(JSUtil::JSValueToString(context, light));
658 JSValueRef onTime = JSUtil::getProperty(context, object, STATUS_NOTIFICATION_LIGHT_ONTIME);
659 if (!JSValueIsNull(context, onTime))
660 priv->setLightOnTime(JSUtil::JSValueToLong(context, onTime));
663 JSValueRef offTime = JSUtil::getProperty(context, object, STATUS_NOTIFICATION_LIGHT_OFFTIME);
664 if (!JSValueIsNull(context, offTime))
665 priv->setLightOffTime(JSUtil::JSValueToLong(context, offTime));
669 JSValueRef progressType = JSUtil::getProperty(context, object, STATUS_NOTIFICATION_PROGRESS_TYPE);
670 std::string strProgressType = JSUtil::JSValueToString(context, progressType);
671 LoggerI("Progress Type : " << strProgressType);
673 NotificationProgressType progType = NOTI_PROGRESS_TYPE_NONE;
674 if( strProgressType.compare(TIZEN_NOTIFICATION_PROGRESS_TYPE_PERCENTAGE) == 0)
675 progType = NOTI_PROGRESS_TYPE_PERCENTAGE;
676 else if( strProgressType.compare(TIZEN_NOTIFICATION_PROGRESS_TYPE_BYTE) == 0)
677 progType = NOTI_PROGRESS_TYPE_SIZE;
679 throw InvalidValuesException("Invalid Progress Type.");
680 priv->setProgressType(progType);
683 JSValueRef progressValue = JSUtil::getProperty(context, object, STATUS_NOTIFICATION_PROGRESS_VALUE);
684 LoggerI(" Progress Value in Private Object = " << JSUtil::JSValueToULong(context, progressValue));
685 if ( progType == NOTI_PROGRESS_TYPE_PERCENTAGE)
687 if ( 100 < JSUtil::JSValueToULong(context, progressValue) )
688 throw InvalidValuesException("The percentage progress value must be between 0 and 100");
689 priv->setProgressValue((double)JSUtil::JSValueToULong(context, progressValue)/(double)100);
693 priv->setProgressValue((double)JSUtil::JSValueToULong(context, progressValue));
699 void JSStatusNotification::setPrivateObject(JSContextRef context, JSObjectRef object, StatusNotification *priv)
702 JSObjectSetPrivate(object, static_cast<void*>(priv));
705 throw TypeMismatchException("StatusNotification object is invaild.");
708 std::string typeVal(NOTIFICATION_TYPE_VALUE);
709 JSUtil::setProperty(context, object, NOTIFICATION_TYPE,
710 JSUtil::toJSValueRef(context, typeVal), kJSPropertyAttributeReadOnly);
715 if ( NOTI_TYPE_SIMPLE == priv->getNotiType())
716 type = TIZEN_STATUS_NOTIFICATION_TYPE_SIMPLE;
717 else if ( NOTI_TYPE_ONGOING == priv->getNotiType())
718 type = TIZEN_STATUS_NOTIFICATION_TYPE_ONGOING;
719 else if ( NOTI_TYPE_PROGRESS == priv->getNotiType())
720 type = TIZEN_STATUS_NOTIFICATION_TYPE_PROGRESS;
721 else if ( NOTI_TYPE_THUMBNAIL == priv->getNotiType())
722 type = TIZEN_STATUS_NOTIFICATION_TYPE_THUMBNAIL;
724 throw TypeMismatchException("status type mismatch.");
726 JSUtil::setProperty(context, object, STATUS_NOTIFICATION_STATUS_TYPE,
727 JSUtil::toJSValueRef(context, type), kJSPropertyAttributeReadOnly);
729 if (priv->getID() >= 0)
731 std::stringstream stream;
732 stream << priv->getID();
735 throw TypeMismatchException("Notification's ID conversion is failed.");
737 JSUtil::setProperty(context, object, NOTIFICATION_ID,
738 JSUtil::toJSValueRef(context, stream.str()), kJSPropertyAttributeReadOnly);
742 JSUtil::setProperty(context, object, NOTIFICATION_ID,
743 JSValueMakeUndefined(context), kJSPropertyAttributeReadOnly);
747 if (priv->getPostedTime() > 0)
749 JSUtil::setProperty(context, object, NOTIFICATION_POSTED_TIME,
750 JSUtil::makeDateObject(context,priv->getPostedTime()), kJSPropertyAttributeReadOnly);
754 JSUtil::setProperty(context, object, NOTIFICATION_POSTED_TIME,
755 JSValueMakeNull(context), kJSPropertyAttributeReadOnly);
759 JSUtil::setProperty(context, object, NOTIFICATION_TITLE,
760 JSUtil::toJSValueRef(context, priv->getTitle()), kJSPropertyAttributeNone);
763 if (priv->getStrContent())
764 JSUtil::setProperty(context, object, NOTIFICATION_CONTENT,
765 JSUtil::toJSValueRef(context, priv->getContent()), kJSPropertyAttributeNone);
767 JSUtil::setProperty(context, object, NOTIFICATION_CONTENT, JSValueMakeNull(context), kJSPropertyAttributeNone);
770 if (!priv->getIconPath().empty())
771 JSUtil::setProperty(context, object, STATUS_NOTIFICATION_ICON_PATH,
772 JSUtil::toJSValueRef(context, DeviceAPI::Filesystem::Utils::toVirtualPath(context, priv->getIconPath())), kJSPropertyAttributeNone);
774 JSUtil::setProperty(context, object, STATUS_NOTIFICATION_ICON_PATH, JSValueMakeNull(context), kJSPropertyAttributeNone);
777 if ( !priv->getSubIconPath().empty())
778 JSUtil::setProperty(context, object, STATUS_NOTIFICATION_SUB_ICON_PATH,
779 JSUtil::toJSValueRef(context, DeviceAPI::Filesystem::Utils::toVirtualPath(context, priv->getSubIconPath())), kJSPropertyAttributeNone);
781 JSUtil::setProperty(context, object, STATUS_NOTIFICATION_SUB_ICON_PATH, JSValueMakeNull(context), kJSPropertyAttributeNone);
784 if (priv->getStrNumber()){
785 JSUtil::setProperty(context, object, STATUS_NOTIFICATION_NUMBER,
786 JSUtil::toJSValueRef(context, priv->getNumber()), kJSPropertyAttributeNone);
789 JSUtil::setProperty(context, object, STATUS_NOTIFICATION_NUMBER, JSValueMakeNull(context), kJSPropertyAttributeNone);
791 // backgroundImagePath
792 if ( !priv->getBackground().empty())
793 JSUtil::setProperty(context, object, STATUS_NOTIFICATION_BACKGROUND_IMAGE_PATH,
794 JSUtil::toJSValueRef(context, DeviceAPI::Filesystem::Utils::toVirtualPath(context, priv->getBackground())), kJSPropertyAttributeNone);
796 JSUtil::setProperty(context, object, STATUS_NOTIFICATION_BACKGROUND_IMAGE_PATH, JSValueMakeNull(context), kJSPropertyAttributeNone);
799 std::vector<std::string> thumbnails = priv->getThumbnails();
800 LoggerI("Thumbnail Size : " << thumbnails.size());
801 JSValueRef tumbnailvalueArray[thumbnails.size()];
802 for( unsigned int i = 0 ; i < thumbnails.size(); i++) {
803 if (!thumbnails[i].empty())
805 LoggerI("Thumbnail :" << thumbnails[i]);
806 tumbnailvalueArray[i] = JSUtil::toJSValueRef(context, DeviceAPI::Filesystem::Utils::toVirtualPath(context, thumbnails[i]));
810 JSValueRef exception = NULL;
811 JSObjectRef jsThumbnails = JSObjectMakeArray(context, thumbnails.size(), tumbnailvalueArray, &exception);
812 if (exception != NULL) {
813 throw DeviceAPI::Common::UnknownException("Make Object Array failed.");
816 JSUtil::setProperty(context, object, STATUS_NOTIFICATION_THUMBNAILS,
817 jsThumbnails, kJSPropertyAttributeNone);
820 if ( !priv->getSoundPath().empty() )
821 JSUtil::setProperty(context, object, STATUS_NOTIFICATION_SOUND_PATH,
822 JSUtil::toJSValueRef(context, DeviceAPI::Filesystem::Utils::toVirtualPath(context, priv->getSoundPath())), kJSPropertyAttributeNone);
824 JSUtil::setProperty(context, object, STATUS_NOTIFICATION_SOUND_PATH, JSValueMakeNull(context), kJSPropertyAttributeNone);
827 JSUtil::setProperty(context, object, STATUS_NOTIFICATION_VIBRATION,
828 JSUtil::toJSValueRef(context, priv->getDefaultVibration()), kJSPropertyAttributeNone);
831 if (!priv->getApplicationId().empty())
832 JSUtil::setProperty(context, object, STATUS_NOTIFICATION_APP_ID,
833 JSUtil::toJSValueRef(context, priv->getApplicationId()), kJSPropertyAttributeNone);
835 JSUtil::setProperty(context, object, STATUS_NOTIFICATION_APP_ID, JSValueMakeNull(context), kJSPropertyAttributeNone);
838 JSUtil::setProperty(context, object, STATUS_NOTIFICATION_LIGHT,
839 JSUtil::toJSValueRef(context, priv->getLight()), kJSPropertyAttributeNone);
841 JSUtil::setProperty(context, object, STATUS_NOTIFICATION_LIGHT_ONTIME,
842 JSUtil::toJSValueRef(context, priv->getLightOnTime()), kJSPropertyAttributeNone);
844 JSUtil::setProperty(context, object, STATUS_NOTIFICATION_LIGHT_OFFTIME,
845 JSUtil::toJSValueRef(context, priv->getLightOffTime()), kJSPropertyAttributeNone);
848 // progressType & Value
849 LoggerI("Progress Type=" << priv->getProgressType());
852 unsigned long progressVal = 0;
853 if ( NOTI_PROGRESS_TYPE_PERCENTAGE == priv->getProgressType())
855 type = TIZEN_NOTIFICATION_PROGRESS_TYPE_PERCENTAGE;
856 progressVal = (unsigned long)( (priv->getProgressValue()*100) );
858 else if ( NOTI_PROGRESS_TYPE_SIZE== priv->getProgressType())
860 type = TIZEN_NOTIFICATION_PROGRESS_TYPE_BYTE;
861 progressVal = (unsigned long)priv->getProgressValue();
864 LoggerI("Progress Type=" << type);
865 JSUtil::setProperty(context, object, STATUS_NOTIFICATION_PROGRESS_TYPE,
866 JSUtil::toJSValueRef(context, type), kJSPropertyAttributeNone);
868 LoggerI("Progress Value =" << progressVal);
869 JSUtil::setProperty(context, object, STATUS_NOTIFICATION_PROGRESS_VALUE,
870 JSUtil::toJSValueRef(context, progressVal), kJSPropertyAttributeNone);
873 std::vector<NotificationDetailInfo*> detailInfo = priv->getDetailInfos();
874 LoggerI("detail Info Size : " << detailInfo.size());
875 JSObjectRef valueArray[detailInfo.size()];
876 for( unsigned int i = 0 ; i < detailInfo.size(); i++) {
879 LoggerI("Main = " << detailInfo[i]->getMainText() << " Sub = " << detailInfo[i]->getSubText());
880 valueArray[i] = JSObjectMake(GlobalContextManager::getInstance()->getGlobalContext(context), JSNotificationDetailInfo::getClassRef(), static_cast<void*>(detailInfo[i]));
881 JSNotificationDetailInfo::setPrivateObject(context, valueArray[i], detailInfo[i]);
882 LoggerI("make Object : " << valueArray[i]);
887 JSObjectRef jsResult = JSObjectMakeArray(GlobalContextManager::getInstance()->getGlobalContext(context), detailInfo.size(), valueArray, &exception);
888 if (exception != NULL) {
889 throw DeviceAPI::Common::UnknownException("Make Object Array failed.");
893 JSUtil::setProperty(context, object, STATUS_NOTIFICATION_DETAIL_INFO,
894 jsResult, kJSPropertyAttributeNone);
897 if ( !(priv->getApplicationControl())->getOperation().empty())
899 DeviceAPI::Application::JSApplicationControlPriv *appCtrlPriv = new DeviceAPI::Application::JSApplicationControlPriv(context, priv->getApplicationControl());
900 JSObjectRef jsAppCtrl = JSObjectMake(context, DeviceAPI::Application::JSApplicationControl::getClassRef(), appCtrlPriv);
901 JSUtil::setProperty(context, object, STATUS_NOTIFICATION_APP_CONTROL, jsAppCtrl, kJSPropertyAttributeNone);
904 JSUtil::setProperty(context, object, STATUS_NOTIFICATION_APP_CONTROL, JSValueMakeNull(context), kJSPropertyAttributeNone);