Update change log and spec for wrt-plugins-tizen_0.4.44
[framework/web/wrt-plugins-tizen.git] / src / Notification / JSStatusNotification.cpp
1 //
2 // Tizen Web Device API
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 //
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
8 //
9 // http://www.apache.org/licenses/LICENSE-2.0
10 //
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.
16 //
17
18 #include <SecurityExceptions.h>
19
20 #include <JSUtil.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"
28
29 #include "JSStatusNotification.h"
30 #include "JSNotificationDetailInfo.h"
31
32 using namespace WrtDeviceApis::Commons;
33 using namespace DeviceAPI::Common;
34
35 namespace DeviceAPI {
36 namespace Notification {
37
38 #define NOTIFICATION_TYPE_VALUE "STATUS"
39
40 JSClassDefinition JSStatusNotification::m_classInfo = {
41     0,
42     kJSClassAttributeNone,
43     "StatusNotification",
44     NULL, //ParentClass
45     m_property, //StaticValues
46     NULL, //StaticFunctions
47     initialize, //Initialize
48     finalize, //Finalize
49     NULL, //HasProperty,
50     NULL, //GetProperty,
51     NULL, //SetProperty,
52     NULL, //DeleteProperty,
53     NULL, //GetPropertyNames,
54     NULL, //CallAsFunction,
55     NULL, //CallAsConstructor,
56     NULL, //HasInstance,
57     NULL //ConvertToType
58 };
59
60 JSStaticValue JSStatusNotification::m_property[] = 
61 {
62         {STATUS_NOTIFICATION_PROGRESS_TYPE,  JSStatusNotification::getProperty, JSStatusNotification::setProperty,      kJSPropertyAttributeNone },
63         {STATUS_NOTIFICATION_PROGRESS_VALUE,  JSStatusNotification::getProperty, JSStatusNotification::setProperty,     kJSPropertyAttributeNone },
64         {0, 0, 0, 0}
65 };
66
67 bool JSStatusNotification::setProperty(JSContextRef context,
68         JSObjectRef object,
69         JSStringRef propertyName,
70         JSValueRef value,
71         JSValueRef* exception)
72 {
73
74     StatusNotification *priv = static_cast<StatusNotification*>(JSObjectGetPrivate(object));
75     LoggerD("statusNotification :" << priv);
76     if (!priv) {
77         throw TypeMismatchException("StatusNotification's private object is NULL.");
78     }
79
80         try {
81                     std::string property;
82                     size_t jsSize = JSStringGetMaximumUTF8CStringSize(propertyName);
83                     if (jsSize > 0) {
84                         jsSize = jsSize + 1;
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.");
89                         }
90                         property = buffer;
91                         delete[] buffer;
92                     }
93
94                    LoggerI("property =" << property);
95
96                    if ( property == STATUS_NOTIFICATION_PROGRESS_TYPE)
97                    {
98                         std::string strProgressType = JSUtil::JSValueToString(context, value);
99                         LoggerI("Progress Type : " << strProgressType);
100
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;
106                         else
107                             throw InvalidValuesException("Invalid Progress Type.");
108                         
109                         priv->setProgressType(progType);        //set progress Type
110
111                         return true;
112                    }
113                    else if ( property == STATUS_NOTIFICATION_PROGRESS_VALUE)
114                    {
115                             // progressValue
116                             unsigned long progressVal = JSUtil::JSValueToULong(context, value);
117                             LoggerI("Progress Value : " << progressVal);
118                                 
119                             if ( priv->getProgressType() == NOTI_PROGRESS_TYPE_PERCENTAGE)
120                             {
121                                 if ( 100 < progressVal )
122                                                 throw InvalidValuesException("The percentage progress value must be between 0 and 100");
123                                 priv->setProgressValue((double)progressVal/(double)100);
124                             }
125                             else 
126                             {
127                                 priv->setProgressValue((double)progressVal);
128                             }
129
130                             return true;
131                    }
132
133     }
134     catch ( const BasePlatformException& err) 
135     {
136         LoggerW(" notification convertion is failed. "   << err.getName().c_str() << ":"  << err.getMessage().c_str());
137     }
138         
139
140     return false;
141 }
142
143 JSValueRef JSStatusNotification::getProperty(JSContextRef context,
144                                                                                 JSObjectRef object,
145                                                                                 JSStringRef propertyName,
146                                                                                 JSValueRef* exception)
147 {
148
149         StatusNotification *priv = static_cast<StatusNotification*>(JSObjectGetPrivate(object));
150         LoggerD("statusNotification :" << priv);
151         if (!priv) {
152                 throw TypeMismatchException("StatusNotification's private object is NULL.");
153         }
154
155         try {
156                     std::string property;
157                     size_t jsSize = JSStringGetMaximumUTF8CStringSize(propertyName);
158                     if (jsSize > 0) {
159                         jsSize = jsSize + 1;
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.");
164                         }
165                         property = buffer;
166                         delete[] buffer;
167                     }
168
169                    LoggerI("property =" << property);
170                    if ( property == STATUS_NOTIFICATION_PROGRESS_TYPE)
171                    {
172                         std::string type;
173                         if ( NOTI_PROGRESS_TYPE_PERCENTAGE ==  priv->getProgressType())
174                         {
175                                 type = TIZEN_NOTIFICATION_PROGRESS_TYPE_PERCENTAGE;
176                         }
177                         else if ( NOTI_PROGRESS_TYPE_SIZE==   priv->getProgressType())
178                         {
179                                 type = TIZEN_NOTIFICATION_PROGRESS_TYPE_BYTE;
180                         }
181                    
182                         return JSUtil::toJSValueRef(context, type);
183                    
184                    }
185                    else if ( property == STATUS_NOTIFICATION_PROGRESS_VALUE)
186                    {                            
187                         // progressValue
188                         LoggerI("Progress Type=" << priv->getProgressType());
189                         
190                            // progressValue
191                         unsigned long progressVal = 0;  
192                         if ( NOTI_PROGRESS_TYPE_PERCENTAGE ==  priv->getProgressType())
193                         {
194                                 progressVal = (unsigned long)( (priv->getProgressValue()*100) );
195                         }
196                         else if ( NOTI_PROGRESS_TYPE_SIZE==   priv->getProgressType())
197                         {
198                                 progressVal = (unsigned long)priv->getProgressValue();
199                         }
200                         
201                         LoggerI("Progress Value=" << progressVal);
202
203                         if( priv->getNotiType() != NOTI_TYPE_PROGRESS && progressVal == 0)
204                         {
205                                 return JSValueMakeNull(context);
206                         }
207                         else
208                         {                                  
209                                 return  JSUtil::toJSValueRef(context, progressVal);
210                         }
211                    }
212
213     }
214     catch ( const BasePlatformException& err) 
215     {
216         LoggerW(" notification convertion is failed. "   << err.getName().c_str() << ":"  << err.getMessage().c_str());
217         return NULL;
218     }
219
220    return NULL;
221 }
222
223
224 JSClassRef JSStatusNotification::m_jsClassRef = JSClassCreate(JSStatusNotification::getClassInfo());
225
226 const JSClassRef JSStatusNotification::getClassRef()
227 {
228     if (!m_jsClassRef) {
229         m_jsClassRef = JSClassCreate(&m_classInfo);
230     }
231     return m_jsClassRef;
232 }
233
234 const JSClassDefinition* JSStatusNotification::getClassInfo()
235 {
236     return &m_classInfo;
237 }
238
239 void JSStatusNotification::initialize(JSContextRef context, JSObjectRef object)
240 {
241         LoggerD("JSStatusNotification::initialize, nothing ");
242 }
243
244 void JSStatusNotification::finalize(JSObjectRef object)
245 {
246     StatusNotification *priv = static_cast<StatusNotification*>(JSObjectGetPrivate(object));
247     if (priv) {
248         JSObjectSetPrivate(object, NULL);
249         delete priv;
250     }
251 }
252
253 JSObjectRef JSStatusNotification::constructor(JSContextRef context,
254     JSObjectRef constructor,
255     size_t argumentCount,
256     const JSValueRef arguments[],
257     JSValueRef* exception)
258 {
259     ArgumentValidator validator(context, argumentCount, arguments);
260
261     //get StatusType
262     JSObjectRef obj = JSObjectMake(context, getClassRef(), NULL);
263            
264     JSStringRef ctorName = JSStringCreateWithUTF8CString("constructor");
265     JSObjectSetProperty(context, obj, ctorName, constructor,
266                 kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete | kJSPropertyAttributeDontEnum, NULL);
267     JSStringRelease(ctorName);
268         
269     try {
270         //Status Notification Type.
271         NotificationType notiType = NOTI_TYPE_NONE;
272         std::string strStatusType = validator.toString(0, false, "");
273         LoggerI("Notification Type : " << strStatusType);
274         
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;
283         else
284             throw TypeMismatchException("notification status type mismatch.");
285         
286         StatusNotification *priv = new StatusNotification(notiType);
287         
288         priv->setTitle(validator.toString(1, false, ""));    //title
289         
290         JSObjectRef notiInitDict = validator.toObject(2, true);
291         
292         if (notiInitDict)
293         {
294             LoggerI("Set Notification Init Dictionary");
295             //content
296             JSValueRef contentValue = JSUtil::getProperty(context, notiInitDict, NOTIFICATION_CONTENT);
297             if (!(JSValueIsUndefined(context, contentValue) || JSValueIsNull(context, contentValue)))
298             {   
299                 priv->setContent(JSUtil::JSValueToString(context, contentValue));
300             }
301                     
302             //icon
303             try {                  
304                 JSValueRef iconValue = JSUtil::getProperty(context, notiInitDict, STATUS_NOTIFICATION_ICON_PATH);
305                 if (!JSValueIsUndefined(context, iconValue))
306                 {
307                     DeviceAPI::Filesystem::IPathPtr path = DeviceAPI::Filesystem::Utils::fromVirtualPath(context, JSUtil::JSValueToString(context, iconValue));
308                     priv->setIconPath(path->getFullPath());
309                 }
310             }
311             catch (...)
312             {
313                 throw InvalidValuesException("Icon file path is invaild");
314             }
315 #if 0                   
316             catch ( const BasePlatformException& err) 
317             {
318                 LoggerW("notification's icon path convertion is failed."  << err.getMessage());
319             }
320 #endif
321             
322             //sound
323             try {                  
324                 JSValueRef soundValue   = JSUtil::getProperty(context, notiInitDict, STATUS_NOTIFICATION_SOUND_PATH);      
325                 if (!JSValueIsUndefined(context, soundValue))
326                 {
327                     DeviceAPI::Filesystem::IPathPtr path = DeviceAPI::Filesystem::Utils::fromVirtualPath(context, JSUtil::JSValueToString(context, soundValue));
328                     priv->setSoundPath(path->getFullPath());
329                 }
330             }
331             catch (...)
332             {
333                  throw InvalidValuesException("sound file path is invaild");
334             }
335        
336             //vibration
337             JSValueRef vibrationValue = JSUtil::getProperty(context, notiInitDict, STATUS_NOTIFICATION_VIBRATION);
338             priv->setDefaultVibration(JSUtil::JSValueToBoolean(context, vibrationValue));
339             
340             //appControl
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) ));
344             
345             //appID                
346             JSValueRef appIdValue = JSUtil::getProperty(context, notiInitDict, STATUS_NOTIFICATION_APP_ID);
347             if (!JSValueIsUndefined(context, appIdValue))
348                 priv->setApplicationId(JSUtil::JSValueToString(context, appIdValue));
349
350             //Light
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));
355
356             //onTime
357             JSValueRef onTimeValue = JSUtil::getProperty(context, notiInitDict, STATUS_NOTIFICATION_LIGHT_ONTIME);
358             if (!JSValueIsUndefined(context, onTimeValue))
359                 priv->setLightOnTime(JSUtil::JSValueToLong(context, onTimeValue));
360
361             //offTime
362             JSValueRef offTimeValue = JSUtil::getProperty(context, notiInitDict, STATUS_NOTIFICATION_LIGHT_OFFTIME);
363             if (!JSValueIsUndefined(context, offTimeValue))
364                 priv->setLightOffTime(JSUtil::JSValueToLong(context, offTimeValue));                    
365                 
366             //progressType
367             NotificationProgressType progressType = NOTI_PROGRESS_TYPE_PERCENTAGE;
368
369             JSStringRef propertyName = JSStringCreateWithUTF8CString(STATUS_NOTIFICATION_PROGRESS_TYPE);
370             bool has = JSObjectHasProperty(context, notiInitDict, propertyName);
371             JSStringRelease(propertyName);
372             if (has)
373             {
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;
381                 else
382                         throw TypeMismatchException("Invalid Progress Type.");          
383             }
384             priv->setProgressType(progressType);
385
386 #if 0                   
387             JSValueRef progressTypeValue = JSUtil::getProperty(context, notiInitDict, STATUS_NOTIFICATION_PROGRESS_TYPE);
388             if (progressTypeValue)
389             {
390
391             }
392             if (!JSValueIsUndefined(context, progressTypeValue))
393             {      
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;
400                     else
401                             throw TypeMismatchException("Invalid Progress Type.");
402             }
403             priv->setProgressType(progressType);
404 #endif                                          
405             //ProgressValue
406             JSValueRef progressValue    = JSUtil::getProperty(context, notiInitDict, STATUS_NOTIFICATION_PROGRESS_VALUE);          
407             if (!JSValueIsUndefined(context, progressValue))
408             {
409                 if ( progressType == NOTI_PROGRESS_TYPE_PERCENTAGE)
410                {
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);
414                 }
415                 else 
416                {
417                     priv->setProgressValue((double)JSUtil::JSValueToULong(context, progressValue));
418                }
419             }
420              
421             //DetailInfo
422             JSValueRef detailInfoValue  = JSUtil::getProperty(context, notiInitDict, STATUS_NOTIFICATION_DETAIL_INFO);
423
424             std::vector<NotificationDetailInfo*> detailInfos;
425             if (JSIsArrayValue(context, detailInfoValue))
426             {
427                 JSObjectRef arrayobj = JSUtil::JSValueToObject(context, detailInfoValue);
428                 for(std::size_t i = 0; i < JSGetArrayLength(context, arrayobj); ++i)
429                 {
430                     JSValueRef element = JSGetArrayElement(context, arrayobj, i);
431                     JSObjectRef object = JSUtil::JSValueToObject(context, element);
432                     if (object)
433                     {
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);
438              
439                         NotificationDetailInfo *detailinfo = new NotificationDetailInfo(NULL, (int)i, main, sub);
440                         detailInfos.push_back(detailinfo);      
441                     }
442                 }
443             }
444             priv->setDetailInfos(detailInfos);  
445     
446             //backgroundimage
447             try {                  
448                 JSValueRef backgroundImageValue = JSUtil::getProperty(context, notiInitDict, STATUS_NOTIFICATION_BACKGROUND_IMAGE_PATH);
449                 if (!JSValueIsUndefined(context, backgroundImageValue))
450                 {
451                     DeviceAPI::Filesystem::IPathPtr path = DeviceAPI::Filesystem::Utils::fromVirtualPath(context, JSUtil::JSValueToString(context, backgroundImageValue));
452                     priv->setBackground(path->getFullPath());
453                 }
454             }
455             catch(...)
456             {
457                  throw TypeMismatchException("The backgound image path is invalid : ");
458             }
459         
460             //number
461             JSValueRef numberValue  = JSUtil::getProperty(context, notiInitDict, STATUS_NOTIFICATION_NUMBER);
462             if (!JSValueIsUndefined(context, numberValue))
463             {
464                  priv->setNumber(JSUtil::JSValueToLong(context, numberValue));
465             }
466            
467             //thumbnail
468             try {                  
469                 JSValueRef thumbnailsValue  = JSUtil::getProperty(context, notiInitDict, STATUS_NOTIFICATION_THUMBNAILS);
470                 if (!JSValueIsUndefined(context, thumbnailsValue))
471                 {
472
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());
482                         }
483                     }           
484                     priv->setThumbnails(thumbnailPaths);                
485                 }
486             }
487             catch ( ... ) 
488             {
489                 throw TypeMismatchException("thumbnail path convertion is failed.");
490             }
491
492             //subIconPath
493             try {                  
494                 JSValueRef subIconPathValue = JSUtil::getProperty(context, notiInitDict, STATUS_NOTIFICATION_SUB_ICON_PATH);
495                 if (!JSValueIsUndefined(context, subIconPathValue))
496                 {
497                     DeviceAPI::Filesystem::IPathPtr path = DeviceAPI::Filesystem::Utils::fromVirtualPath(context, JSUtil::JSValueToString(context, subIconPathValue));
498                     priv->setSubIconPath( path->getFullPath());
499                 }
500             }
501             catch (...) 
502             {
503                 throw TypeMismatchException("subIcon path convertion is failed.");
504             }
505                     
506         }
507                
508         setPrivateObject(context, obj, priv);
509                 
510     } 
511      catch ( const BasePlatformException& err) 
512     {
513         LoggerW(" notification convertion is failed. "   << err.getName().c_str() << ":"  << err.getMessage().c_str());
514         JSObjectRef error = JSWebAPIErrorFactory::makeErrorObject(context, err);
515         *exception = error;
516         return error;
517     }
518
519     return obj;      
520
521 }
522
523 StatusNotification* JSStatusNotification::getPrivateObject(JSContextRef context, JSObjectRef object)
524 {
525     LoggerD("get object :" << object);
526
527     StatusNotification *priv = static_cast<StatusNotification*>(JSObjectGetPrivate(object));
528     LoggerD("statusNotification :" << priv);
529     if (!priv) {
530         throw TypeMismatchException("StatusNotification's private object is NULL.");
531     }
532
533     //type
534     JSValueRef type = JSUtil::getProperty(context, object, NOTIFICATION_TYPE);
535     if ((JSUtil::JSValueToString(context, type)).compare(NOTIFICATION_TYPE_VALUE) )
536     {
537         throw TypeMismatchException("StatusNotification's type is mismatched");
538     }
539      
540     //Title
541     JSValueRef title = JSUtil::getProperty(context, object, NOTIFICATION_TITLE);
542     priv->setTitle( JSUtil::JSValueToString(context, title));
543
544     //Content
545     JSValueRef contents = JSUtil::getProperty(context, object, NOTIFICATION_CONTENT);
546     if (!JSValueIsNull(context, contents))
547     {
548         priv->setContent( JSUtil::JSValueToString(context, contents));
549     }
550
551     // iconPath
552     JSValueRef iconPath = JSUtil::getProperty(context, object, STATUS_NOTIFICATION_ICON_PATH);
553     if ( !JSValueIsNull(context, contents) )
554     {
555         DeviceAPI::Filesystem::IPathPtr icon = DeviceAPI::Filesystem::Utils::fromVirtualPath(context, JSUtil::JSValueToString(context, iconPath));
556         priv->setIconPath(icon->getFullPath());
557     }
558     //else
559     //{
560     //    priv->setIconPath("");
561     //}
562
563     // subIconPath
564     JSValueRef subIconPath = JSUtil::getProperty(context, object, STATUS_NOTIFICATION_SUB_ICON_PATH);
565     if (!JSValueIsNull(context, subIconPath))
566     {
567         DeviceAPI::Filesystem::IPathPtr subIcon = DeviceAPI::Filesystem::Utils::fromVirtualPath(context, JSUtil::JSValueToString(context, subIconPath));
568         priv->setSubIconPath(subIcon->getFullPath());
569     }
570     //else
571     //{
572     //    priv->setSubIconPath("");
573     //}
574
575     // number
576     JSValueRef number = JSUtil::getProperty(context, object, STATUS_NOTIFICATION_NUMBER);
577     priv->setNumber(JSUtil::JSValueToLong(context, number));
578
579     // detailInfo
580     JSValueRef detailInfo = JSUtil::getProperty(context, object, STATUS_NOTIFICATION_DETAIL_INFO);
581     std::vector<NotificationDetailInfo*> detailInfos;
582     if (JSIsArrayValue(context, detailInfo))
583     {
584         JSObjectRef arrayobj = JSUtil::JSValueToObject(context, detailInfo);
585         for(std::size_t i = 0; i < JSGetArrayLength(context, arrayobj); ++i)
586         {
587             JSValueRef element = JSGetArrayElement(context, arrayobj, i);
588             JSObjectRef object = JSUtil::JSValueToObject(context, element);
589             if (object)
590             {
591                 NotificationDetailInfo* detailinfo = static_cast<NotificationDetailInfo*>(JSObjectGetPrivate(object));
592                 detailInfos.push_back(detailinfo);      
593             }
594         }
595     }
596     priv->setDetailInfos(detailInfos);
597     
598     // backgroundImagePath
599     JSValueRef backgroundImagePath = JSUtil::getProperty(context, object, STATUS_NOTIFICATION_BACKGROUND_IMAGE_PATH);
600     if (!JSValueIsNull(context, backgroundImagePath))
601     {
602         DeviceAPI::Filesystem::IPathPtr backgroundImage = DeviceAPI::Filesystem::Utils::fromVirtualPath(context, JSUtil::JSValueToString(context, backgroundImagePath));
603         priv->setBackground(backgroundImage->getFullPath());
604     }
605     //else
606     //{
607     //    priv->setBackground("");
608     //}
609     
610     // thumbnails
611     JSValueRef thumbnails = JSUtil::getProperty(context, object, STATUS_NOTIFICATION_THUMBNAILS);
612
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());
622          }
623     }           
624     priv->setThumbnails(thumbnailPaths);
625     
626     // soundPath
627     JSValueRef soundPath = JSUtil::getProperty(context, object, STATUS_NOTIFICATION_SOUND_PATH);
628     if (!JSValueIsNull(context, soundPath))
629     {
630         DeviceAPI::Filesystem::IPathPtr sound = DeviceAPI::Filesystem::Utils::fromVirtualPath(context, JSUtil::JSValueToString(context, soundPath));
631         priv->setSoundPath(sound->getFullPath());
632     }
633     //else
634     //{
635     //    priv->setSoundPath("");
636     //}
637     
638     // vibration
639     JSValueRef vibration = JSUtil::getProperty(context, object, STATUS_NOTIFICATION_VIBRATION);
640     priv->setDefaultVibration(JSUtil::JSValueToBoolean(context, vibration));
641
642     // appControl
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)));
646
647     // appId
648     JSValueRef appId = JSUtil::getProperty(context, object, STATUS_NOTIFICATION_APP_ID);
649     if (!JSValueIsNull(context, appId))
650         priv->setApplicationId(JSUtil::JSValueToString(context, appId));
651         
652     // light
653     JSValueRef light = JSUtil::getProperty(context, object, STATUS_NOTIFICATION_LIGHT);
654     if (!JSValueIsNull(context, light))
655         priv->setLight(JSUtil::JSValueToString(context, light));
656
657     // onTime
658     JSValueRef onTime = JSUtil::getProperty(context, object, STATUS_NOTIFICATION_LIGHT_ONTIME);
659     if (!JSValueIsNull(context, onTime))
660         priv->setLightOnTime(JSUtil::JSValueToLong(context, onTime));
661
662     // offTime
663     JSValueRef offTime = JSUtil::getProperty(context, object, STATUS_NOTIFICATION_LIGHT_OFFTIME);
664     if (!JSValueIsNull(context, offTime))
665         priv->setLightOffTime(JSUtil::JSValueToLong(context, offTime));
666
667 #if 0
668     // progressType
669     JSValueRef progressType = JSUtil::getProperty(context, object, STATUS_NOTIFICATION_PROGRESS_TYPE);
670     std::string strProgressType = JSUtil::JSValueToString(context, progressType);
671     LoggerI("Progress Type : " << strProgressType);
672     
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;
678     else
679         throw InvalidValuesException("Invalid Progress Type.");
680     priv->setProgressType(progType);
681     
682     // progressValue
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)
686     {
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);
690     }
691     else 
692     {
693         priv->setProgressValue((double)JSUtil::JSValueToULong(context, progressValue));
694     }
695  #endif   
696     return priv;
697 }
698
699 void JSStatusNotification::setPrivateObject(JSContextRef context, JSObjectRef object, StatusNotification *priv)
700 {
701     if (priv) {
702         JSObjectSetPrivate(object, static_cast<void*>(priv));
703     }
704     else
705         throw TypeMismatchException("StatusNotification object is invaild.");
706
707     //type
708     std::string typeVal(NOTIFICATION_TYPE_VALUE);
709     JSUtil::setProperty(context, object, NOTIFICATION_TYPE,
710             JSUtil::toJSValueRef(context, typeVal), kJSPropertyAttributeReadOnly);
711         
712     std::string type;
713     
714     //statusType
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;
723     else
724         throw TypeMismatchException("status type mismatch.");
725         
726     JSUtil::setProperty(context, object, STATUS_NOTIFICATION_STATUS_TYPE,
727             JSUtil::toJSValueRef(context, type), kJSPropertyAttributeReadOnly);
728     //id
729     if (priv->getID() >= 0)
730     {
731             std::stringstream stream;
732             stream << priv->getID();
733             
734             if(stream.fail())
735                throw TypeMismatchException("Notification's ID conversion is failed.");
736
737             JSUtil::setProperty(context, object, NOTIFICATION_ID,
738                 JSUtil::toJSValueRef(context, stream.str()), kJSPropertyAttributeReadOnly);        
739     }
740     else
741     {
742             JSUtil::setProperty(context, object, NOTIFICATION_ID,
743                     JSValueMakeNull(context), kJSPropertyAttributeReadOnly);
744     }
745
746     //postedTime
747     if (priv->getPostedTime() > 0)
748     {
749             JSUtil::setProperty(context, object, NOTIFICATION_POSTED_TIME,
750                 JSUtil::makeDateObject(context,priv->getPostedTime()), kJSPropertyAttributeReadOnly);  
751     }
752     else
753     {
754             JSUtil::setProperty(context, object, NOTIFICATION_POSTED_TIME,
755                     JSValueMakeNull(context), kJSPropertyAttributeReadOnly);
756     }    
757
758     //title
759     JSUtil::setProperty(context, object, NOTIFICATION_TITLE,
760             JSUtil::toJSValueRef(context, priv->getTitle()), kJSPropertyAttributeNone);
761
762     //content
763     if (priv->getStrContent())
764         JSUtil::setProperty(context, object, NOTIFICATION_CONTENT,
765                   JSUtil::toJSValueRef(context, priv->getContent()), kJSPropertyAttributeNone);
766     else
767         JSUtil::setProperty(context, object, NOTIFICATION_CONTENT, JSValueMakeNull(context), kJSPropertyAttributeNone);   
768
769     //iconPath
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);
773     else
774          JSUtil::setProperty(context, object, STATUS_NOTIFICATION_ICON_PATH, JSValueMakeNull(context), kJSPropertyAttributeNone);
775
776     //subIconPath
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);
780     else 
781         JSUtil::setProperty(context, object, STATUS_NOTIFICATION_SUB_ICON_PATH,  JSValueMakeNull(context), kJSPropertyAttributeNone);
782
783     //number
784     if (priv->getStrNumber()){
785         JSUtil::setProperty(context, object, STATUS_NOTIFICATION_NUMBER,
786             JSUtil::toJSValueRef(context, priv->getNumber()), kJSPropertyAttributeNone);        
787     }
788     else
789         JSUtil::setProperty(context, object, STATUS_NOTIFICATION_NUMBER, JSValueMakeNull(context), kJSPropertyAttributeNone);                   
790
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);
795     else
796         JSUtil::setProperty(context, object, STATUS_NOTIFICATION_BACKGROUND_IMAGE_PATH, JSValueMakeNull(context), kJSPropertyAttributeNone);
797         
798     // thumbnails
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())
804             {
805                 LoggerI("Thumbnail :" << thumbnails[i]);
806                 tumbnailvalueArray[i] =  JSUtil::toJSValueRef(context, DeviceAPI::Filesystem::Utils::toVirtualPath(context, thumbnails[i]));
807             }
808     }
809
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.");
814     }
815
816     JSUtil::setProperty(context, object, STATUS_NOTIFICATION_THUMBNAILS,
817            jsThumbnails, kJSPropertyAttributeNone);
818
819     // soundPath
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);
823     else
824         JSUtil::setProperty(context, object, STATUS_NOTIFICATION_SOUND_PATH, JSValueMakeNull(context), kJSPropertyAttributeNone);
825
826     // vibration
827     JSUtil::setProperty(context, object, STATUS_NOTIFICATION_VIBRATION,
828             JSUtil::toJSValueRef(context, priv->getDefaultVibration()), kJSPropertyAttributeNone);
829
830     // appId
831     if (!priv->getApplicationId().empty())
832         JSUtil::setProperty(context, object, STATUS_NOTIFICATION_APP_ID,
833             JSUtil::toJSValueRef(context, priv->getApplicationId()), kJSPropertyAttributeNone);
834     else
835         JSUtil::setProperty(context, object, STATUS_NOTIFICATION_APP_ID, JSValueMakeNull(context), kJSPropertyAttributeNone);
836
837    //Light
838    JSUtil::setProperty(context, object, STATUS_NOTIFICATION_LIGHT,
839                 JSUtil::toJSValueRef(context, priv->getLight()), kJSPropertyAttributeNone);
840
841    JSUtil::setProperty(context, object, STATUS_NOTIFICATION_LIGHT_ONTIME,
842                 JSUtil::toJSValueRef(context, priv->getLightOnTime()), kJSPropertyAttributeNone);
843
844    JSUtil::setProperty(context, object, STATUS_NOTIFICATION_LIGHT_OFFTIME,
845                 JSUtil::toJSValueRef(context, priv->getLightOffTime()), kJSPropertyAttributeNone);
846
847 #if 0
848     // progressType   & Value
849     LoggerI("Progress Type=" << priv->getProgressType());
850
851        // progressValue
852     unsigned long progressVal = 0;      
853     if ( NOTI_PROGRESS_TYPE_PERCENTAGE ==  priv->getProgressType())
854     {
855         type = TIZEN_NOTIFICATION_PROGRESS_TYPE_PERCENTAGE;
856         progressVal = (unsigned long)( (priv->getProgressValue()*100) );
857     }
858     else if ( NOTI_PROGRESS_TYPE_SIZE==   priv->getProgressType())
859     {
860         type = TIZEN_NOTIFICATION_PROGRESS_TYPE_BYTE;
861         progressVal = (unsigned long)priv->getProgressValue();
862     }
863
864     LoggerI("Progress Type=" << type);
865     JSUtil::setProperty(context, object, STATUS_NOTIFICATION_PROGRESS_TYPE,
866             JSUtil::toJSValueRef(context, type), kJSPropertyAttributeNone);
867                 
868     LoggerI("Progress Value =" << progressVal); 
869     JSUtil::setProperty(context, object, STATUS_NOTIFICATION_PROGRESS_VALUE,                
870             JSUtil::toJSValueRef(context, progressVal), kJSPropertyAttributeNone);
871 #endif
872     // detailInfo
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++) {
877             if (detailInfo[i])
878             {
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]);
883             }
884     }
885
886     exception = NULL;
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.");
890     }
891
892        // detailInfo
893     JSUtil::setProperty(context, object, STATUS_NOTIFICATION_DETAIL_INFO,
894            jsResult, kJSPropertyAttributeNone);
895
896     // appControl
897     if (  !(priv->getApplicationControl())->getOperation().empty())
898     {   
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);
902     }
903     else
904            JSUtil::setProperty(context, object, STATUS_NOTIFICATION_APP_CONTROL,   JSValueMakeNull(context), kJSPropertyAttributeNone);
905   
906 }
907
908
909 } // Notification
910 } // DeviceAPI