Update change log and spec for wrt-plugins-tizen_0.4.58
[platform/framework/web/wrt-plugins-tizen.git] / src / Notification / StatusNotification.cpp
index 96789c0..6e57f94 100755 (executable)
@@ -19,7 +19,9 @@
 #include <Logger.h>
 #include <sstream>
 #include <appsvc/appsvc.h>
+#include <sstream>
 
+#include <boost/algorithm/string.hpp>
 #include "StatusNotification.h"
 
 namespace DeviceAPI {
@@ -77,24 +79,6 @@ static bool service_extra_data_cb(service_h service, const char *key, void *user
        return true;
 }
 
-#if 0
-static bool service_extra_data_delete_cb(service_h service, const char *key, void *user_data)
-{
-       LoggerI("OK");
-       if (key != NULL)
-       {       
-               LoggerI("del key = " << key);
-               
-               if (service_remove_extra_data(service, key) != SERVICE_ERROR_NONE)
-               {
-                       LoggerW("remove extra data failed");
-                       return false;
-               }
-       }
-       return true;
-}
-#endif
-
 StatusNotification::StatusNotification(NotificationType statusType) :
        m_notiType(NOTI_TYPE_NONE),
        m_service(NULL),
@@ -472,7 +456,13 @@ std::string StatusNotification::getTitle()
                        throw UnknownException("get notification title error");
                }
 
-               std::string notiTitle(title);
+               std::string notiTitle;
+               if (title)
+               {               
+                       notiTitle = title;
+                       LoggerI(" get title : " << title);
+               }
+
                return notiTitle;       
        }
        else
@@ -509,7 +499,6 @@ void StatusNotification::setTitle(std::string title)
        }
 }
 
-
 std::string StatusNotification::getContent()
 {
        LoggerI("get Content handle: " << m_notiHandle);
@@ -594,8 +583,12 @@ std::string StatusNotification::getIconPath()
                        throw UnknownException("get notification icon path error");
                }
 
-               std::string notiIconPath(iconPath);
-               LoggerI("icon Path = " << iconPath);
+               std::string notiIconPath;
+               if (iconPath)
+               {
+                       notiIconPath = iconPath;
+                       LoggerI("icon Path = " << iconPath);
+               }
                
                //if icon path invalid, return empty string.
                if ( notiIconPath.find(DEFAULT_ICON_PATH,0) == std::string::npos)
@@ -645,17 +638,21 @@ std::string StatusNotification::getSoundPath()
                {
                        throw UnknownException("get notification sound error");
                }
-
-               LoggerI(" sound type = " << type << " path = " << soundPath);
-               if ( type == NOTIFICATION_SOUND_TYPE_USER_DATA )
-               {
-                       LoggerI("soundPath = " << soundPath);
-                       return std::string(soundPath); 
-               }
-               else
+               
+               std::string strSoundPath;
+               if (soundPath)
                {
-                       return std::string("");
+                       LoggerI(" soudn type=" << type);
+                       if ( type == NOTIFICATION_SOUND_TYPE_USER_DATA)
+                       {
+                               LoggerI("soundPath = " << soundPath);
+                               strSoundPath = soundPath;
+                       }
                }
+               
+               LoggerI("soundPath :" << strSoundPath);
+               return strSoundPath;
+
        }
        else
        {
@@ -992,13 +989,10 @@ void StatusNotification::setApplicationId(const std::string& appId)
 
        if (m_service)
        {
-               if (!appId.empty())
+               m_launchFlag = true;
+               if (service_set_app_id(m_service, appId.c_str())!= SERVICE_ERROR_NONE)
                {
-                       m_launchFlag = true;
-                       if (service_set_app_id(m_service, appId.c_str())!= SERVICE_ERROR_NONE)
-                       {
-                               throw UnknownException("service set appId error");      
-                       }
+                       throw UnknownException("service set appId error");      
                }
        }
 
@@ -1763,7 +1757,6 @@ service_h StatusNotification::getService()
        return m_service;
 }
 
-
 std::string StatusNotification::getLight()
 {
        LoggerI("get Light handle: " << m_notiHandle);
@@ -1775,15 +1768,15 @@ std::string StatusNotification::getLight()
                {
                        throw UnknownException("get notification Content error");
                }
-
-               //ledColor = ledColor | 0xff000000;
+               std::string light;
                std::stringstream stream;
                if (NOTIFICATION_LED_OP_OFF != type)
                {
                        stream <<  std::hex  << ledColor;
+                       light = "#" + stream.str();
                }
                
-               return stream.str();
+               return boost::to_lower_copy(light);
        }
        else
        {
@@ -1791,25 +1784,66 @@ std::string StatusNotification::getLight()
        }
 }
 
+bool StatusNotification::isColorFormatNumberic(std::string& color)
+{
+       //first check length
+       std::string hexCode = "0123456789abcdef";
+       if (color.length() == 7 && !color.compare(0, 1, "#") )
+       {
+               for ( size_t i = 1 ; i < color.length() ; i++)
+               {
+                       if (std::string::npos == hexCode.find(color[i]))
+                               return false;
+               }
+               return true;
+       }
+       return false;
+}
+
 void StatusNotification::setLight(std::string color)
 {
        LoggerI("set Light handle: " << m_notiHandle);
        LoggerI("led Color : " << color);
        if (m_notiHandle)
-       {
+       {       
+               color = boost::to_lower_copy(color);     //convert lowercase.
+               if ( isColorFormatNumberic(color))
+               {
+                       std::stringstream stream;       
+                       int ledColor = 0;
+                       notification_led_op_e type = NOTIFICATION_LED_OP_ON;
+                       std::string colorCode = color.substr(1, color.length());
 
-               std::stringstream stream;       
-               int ledColor = 0;
-               notification_led_op_e type = NOTIFICATION_LED_OP_ON;
+                       stream << std::hex << colorCode;
+                       LoggerI("LedColor = " << stream.str());
+                       stream >> ledColor;
+                       LoggerI("LedColor = " << ledColor);
+
+                       if (ledColor != 0)
+                               type = NOTIFICATION_LED_OP_ON_CUSTOM_COLOR;
+                       else
+                               type = NOTIFICATION_LED_OP_OFF;
                        
-               stream << std::hex << color;
-               LoggerI("LedColor = " << stream.str());
-               stream >> ledColor;
-               LoggerI("LedColor = " << ledColor);
-                               
-               if (notification_set_led(m_notiHandle, NOTIFICATION_LED_OP_ON_CUSTOM_COLOR, ledColor) != NOTIFICATION_ERROR_NONE)
+                       if (notification_set_led(m_notiHandle, type, ledColor) != NOTIFICATION_ERROR_NONE)
+                       {
+                               throw UnknownException("set notification led ");
+                       }                       
+                       
+               }
+               else
                {
-                       throw UnknownException("set notification led ");
+                       LoggerI("color.length()=" << color.length());
+                       if (color.length() == 0)
+                       {
+                               if (notification_set_led(m_notiHandle, NOTIFICATION_LED_OP_OFF, 0) != NOTIFICATION_ERROR_NONE)
+                               {
+                                       throw UnknownException("set notification led ");
+                               }
+                       }
+                       else
+                       {
+                               throw InvalidValuesException("color code error!");
+                       }
                }
        }
        else
@@ -1912,11 +1946,16 @@ void StatusNotification::loadDetailInfos()
         {
                for ( int idx = 0; idx < MAX_NOTIFICATION_DETAIL_INFO_LENGTH; idx++)
                {
-                   std::string main = getInformation(idx);
-                   std::string sub = getSubInformation(idx);
-                   LoggerI("Main : " << main << " Sub : " << sub);
-                   NotificationDetailInfo *info = new NotificationDetailInfo(m_notiHandle, idx, main, sub);
-                   m_detailInfos.push_back(info);
+                   if (!isNullInformation(idx))
+                   {
+                           std::string main = getInformation(idx);
+                           std::string sub = getSubInformation(idx);
+
+                           LoggerI("Main : [" << main << "] Sub : ['" << sub <<"]");      
+                           
+                           NotificationDetailInfo *info = new NotificationDetailInfo(m_notiHandle, idx, main, sub);
+                           m_detailInfos.push_back(info);
+                   }
                }
         }
         else
@@ -1946,6 +1985,7 @@ void StatusNotification::setDetailInfos(const std::vector<NotificationDetailInfo
             NotificationDetailInfo* info = *it;
             if ( idx < MAX_NOTIFICATION_DETAIL_INFO_LENGTH )
             {
+            
                 LoggerI("main " << info->getMainText() << " sub " << info->getSubText() );
                setInformation(info->getMainText(), idx);
                setSubInformation(info->getSubText(), idx);
@@ -2028,6 +2068,51 @@ std::string StatusNotification::getInformation(int index)
        
 }
 
+bool StatusNotification::isNullInformation(int index)
+{
+       if (m_notiHandle)
+       {
+               notification_text_type_e type = NOTIFICATION_TEXT_TYPE_NONE; 
+               switch (index)
+               {
+                       case 0:
+                               type = NOTIFICATION_TEXT_TYPE_INFO_1;
+                               break;
+                       case 1:
+                               type = NOTIFICATION_TEXT_TYPE_INFO_2;
+                               break;
+                       case 2:
+                               type = NOTIFICATION_TEXT_TYPE_INFO_3;
+                               break;
+                       default :
+                               type = NOTIFICATION_TEXT_TYPE_NONE;
+               }
+               char *info = NULL;
+               
+               if (NOTIFICATION_TEXT_TYPE_NONE != type && notification_get_text(m_notiHandle, type, &info) != NOTIFICATION_ERROR_NONE)
+               {
+                       throw UnknownException("Detail Info index value is invalid or mainText value getting is failed in Detail Info.");
+               }
+               
+               if (info)
+               {
+                       LoggerI("is not null");
+                       return false;
+               }
+               else
+               {
+                       LoggerI("is null");
+                       return true;
+               }
+
+       }
+       else
+       {       
+               LoggerW("noti Handle is NULL");
+               throw UnknownException( "notification handle is null");
+       }
+}
+
 std::string StatusNotification::getSubInformation(int index)
 {
        if (m_notiHandle)
@@ -2096,7 +2181,7 @@ void StatusNotification::setInformation( const std::string& info, int index)
 
                if ( type != NOTIFICATION_TEXT_TYPE_NONE)
                {
-                       if (getInformation(idx).compare(info))
+                       if (getInformation(idx).compare(info) || isNullInformation(idx))
                        {
                                if (notification_set_text(m_notiHandle, type, info.c_str(),
                                        NULL, NOTIFICATION_VARIABLE_TYPE_NONE) != NOTIFICATION_ERROR_NONE)
@@ -2164,156 +2249,5 @@ void StatusNotification::setSubInformation( const std::string& subInfo, int inde
        }
 }
 
-
-#if 0
-
-StatusNotification::StatusNotification():
-    m_statusType(""),
-    m_iconPath(""),
-    m_subIconPath(""),
-    m_number(0),
-    m_backgroundImagePath(""),
-    m_soundPath(""),
-    m_vibration(false),
-    m_progressType(""),
-    m_progressValue(0)
-{
-}
-
-StatusNotification::~StatusNotification()
-{
-}
-
-std::string StatusNotification::getStatusType() const
-{
-    return m_statusType;
-}
-
-void StatusNotification::setStatusType(std::string statusType)
-{
-    m_statusType = statusType;
-}
-
-std::string StatusNotification::getIconPath() const
-{
-    return m_iconPath;
-}
-
-void StatusNotification::setIconPath(std::string iconPath)
-{
-    m_iconPath = iconPath;
-}
-
-std::string StatusNotification::getSubIconPath() const
-{
-    return m_subIconPath;
-}
-
-void StatusNotification::setSubIconPath(std::string subIconPath)
-{
-    m_subIconPath = subIconPath;
-}
-
-long StatusNotification::getNumber() const
-{
-    return m_number;
-}
-
-void StatusNotification::setNumber(long number)
-{
-    m_number = number;
-}
-
-std::vector<NotificationDetailInfo*> StatusNotification::getDetailInfo() const
-{
-    return m_detailInfo;
-}
-
-void StatusNotification::setDetailInfo(std::vector<NotificationDetailInfo*> detailInfo)
-{
-    m_detailInfo = detailInfo;
-}
-
-std::string StatusNotification::getBackgroundImagePath() const
-{
-    return m_backgroundImagePath;
-}
-
-void StatusNotification::setBackgroundImagePath(std::string backgroundImagePath)
-{
-    m_backgroundImagePath = backgroundImagePath;
-}
-
-std::vector<std::string> StatusNotification::getThumbnails() const
-{
-    return m_thumbnails;
-}
-
-void StatusNotification::setThumbnails(std::vector<std::string> thumbnails)
-{
-    m_thumbnails = thumbnails;
-}
-
-std::string StatusNotification::getSoundPath() const
-{
-    return m_soundPath;
-}
-
-void StatusNotification::setSoundPath(std::string soundPath)
-{
-    m_soundPath = soundPath;
-}
-
-bool StatusNotification::getVibration() const
-{
-    return m_vibration;
-}
-
-void StatusNotification::setVibration(bool vibration)
-{
-    m_vibration = vibration;
-}
-
-ApplicationControl StatusNotification::getAppControl() const
-{
-    return m_appControl;
-}
-
-void StatusNotification::setAppControl(ApplicationControl appControl)
-{
-    m_appControl = appControl;
-}
-
-ApplicationId StatusNotification::getAppId() const
-{
-    return m_appId;
-}
-
-void StatusNotification::setAppId(ApplicationId appId)
-{
-    m_appId = appId;
-}
-
-std::string StatusNotification::getProgressType() const
-{
-    return m_progressType;
-}
-
-void StatusNotification::setProgressType(std::string progressType)
-{
-    m_progressType = progressType;
-}
-
-unsigned long StatusNotification::getProgressValue() const
-{
-    return m_progressValue;
-}
-
-void StatusNotification::setProgressValue(unsigned long progressValue)
-{
-    m_progressValue = progressValue;
-}
-#endif
-
 } // Notification
 } // DeviceAPI