Update change log and spec for wrt-plugins-tizen_0.4.9
[platform/framework/web/wrt-plugins-tizen.git] / src / Notification / NotificationConverter.cpp
index 91fd33c..de98447 100755 (executable)
@@ -96,6 +96,25 @@ NotificationType NotificationConverter::toNotificationType(const JSValueRef arg)
        }       
 }
 
+NotificationProgressType NotificationConverter::toNotificationProgressType(const JSValueRef arg)
+{
+       std::string strType = toString(arg);
+       LogDebug("progress Type : " << strType);
+       if ( strType.compare("BYTE") == 0 ) 
+       {
+               return NOTI_PROGRESS_TYPE_SIZE;
+       }
+       else if ( strType.compare("PERCENTAGE") == 0 ) 
+       {
+               return NOTI_PROGRESS_TYPE_PERCENTAGE;
+       }       
+       else
+       {
+               ThrowMsg(WrtDeviceApis::Commons::ConversionException, "notification type not supported");
+       }
+}
+
+
 void NotificationConverter::NotificationConverter::toNotificationFromDict( INotificationPtr& notification, const JSValueRef arg)
 {
        if (JSValueIsUndefined(m_context, arg) || JSValueIsNull(m_context, arg)) 
@@ -124,6 +143,7 @@ void NotificationConverter::NotificationConverter::toNotificationFromDict( INoti
        const ScopedJSStringRef numberStr(JSStringCreateWithUTF8CString(NOTIFICATION_NUMBER)); 
        const ScopedJSStringRef thumbnailsStr(JSStringCreateWithUTF8CString(NOTIFICATION_THUMBNAILS)); 
        const ScopedJSStringRef subIconPathStr(JSStringCreateWithUTF8CString(NOTIFICATION_SUB_ICON_PATH)); 
+       const ScopedJSStringRef progressTypeStr(JSStringCreateWithUTF8CString(NOTIFICATION_PROGRESS_TYPE)); 
 
        DeviceAPI::Filesystem::IPathPtr path;
        
@@ -145,6 +165,7 @@ void NotificationConverter::NotificationConverter::toNotificationFromDict( INoti
        JSValueRef numberValue = JSObjectGetProperty(m_context, dictObject, numberStr.get(), NULL);
        JSValueRef thumbnailsValue = JSObjectGetProperty(m_context, dictObject, thumbnailsStr.get(), NULL);
        JSValueRef subIconPathValue = JSObjectGetProperty(m_context, dictObject, subIconPathStr.get(), NULL);
+       JSValueRef progressTypeValue = JSObjectGetProperty(m_context, dictObject, progressTypeStr.get(), NULL);
 
     if (!JSValueIsUndefined(m_context, contentValue)) 
        {
@@ -193,13 +214,38 @@ void NotificationConverter::NotificationConverter::toNotificationFromDict( INoti
                std::string appId = toString(appIdValue);
                notification->setApplicationId(appId);
        }
+
+       if (!JSValueIsUndefined(m_context, progressTypeValue)) 
+       {
+               notification->setProgressType(toNotificationProgressType(progressTypeValue));
+       }
        
        if (!JSValueIsUndefined(m_context, progressValue)) 
        {
-               //unsigned short value = toULong(progressValue);
-               double value = toDouble(progressValue);
-               LogDebug(" Progress Value : " << value);
-               notification->setProgressValue(value);
+               unsigned int progressVal = toULong(progressValue);
+               NotificationProgressType progressType = notification->getProgressType();
+               
+               LogDebug(" progress type = " << progressType << "progressValue = " << progressVal);
+                                               
+               if ( NOTI_PROGRESS_TYPE_SIZE == progressType)
+               {
+                       notification->setProgressValue(progressVal);
+               }
+               else if ( NOTI_PROGRESS_TYPE_PERCENTAGE == progressType)
+               {
+                       //check arrang.
+                       if (  progressVal > 100 )
+                       {
+                               progressVal = 100;
+                       }
+                       double percentage = (double)progressVal/(double)100;
+                       LogDebug(" Percentage Value = " << percentage);
+                       notification->setProgressValue(percentage);
+               }
+                               
+               //double value = toDouble(progressValue);
+               //LogDebug(" Progress Value : " << value);
+               //notification->setProgressValue(value);
        }
 
        if (!JSValueIsUndefined(m_context, detailInfoValue)) 
@@ -252,6 +298,7 @@ void NotificationConverter::NotificationConverter::toNotificationFromDict( INoti
                subIconPath = path->getFullPath();
                notification->setSubIconPath(subIconPath);
        }
+       
 
 }
 
@@ -310,6 +357,24 @@ JSValueRef NotificationConverter::toJSValueRef(const NotificationType arg)
        {
                return toJSValueRef("PROGRESS"); 
        }
+       else if ( NOTI_TYPE_THUMBNAIL ==  arg)
+       {
+               return toJSValueRef("THUMBNAIL"); 
+       }
+       
+       return  JSValueMakeUndefined(m_context);
+}
+
+JSValueRef NotificationConverter::toJSValueRef(const NotificationProgressType &arg)
+{
+       if ( NOTI_PROGRESS_TYPE_SIZE ==  arg)
+       {
+               return toJSValueRef("BYTE");
+       }
+       else if ( NOTI_PROGRESS_TYPE_PERCENTAGE==  arg)
+       {
+               return toJSValueRef("PERCENTAGE");
+       }
        
        return  JSValueMakeUndefined(m_context);
 }