Update change log and spec for wrt-plugins-tizen_0.4.58
[platform/framework/web/wrt-plugins-tizen.git] / src / Notification / StatusNotification.cpp
index 7de06eb..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),
@@ -122,7 +106,7 @@ StatusNotification::StatusNotification(NotificationType statusType) :
                throw TypeMismatchException("value is not notification type");
        }
 
-       setProgressType(NOTI_PROGRESS_TYPE_PERCENTAGE); //default
+       //setProgressType(NOTI_PROGRESS_TYPE_PERCENTAGE);       //default
 
        LoggerI("Notification Type : " << type);
 
@@ -135,8 +119,12 @@ StatusNotification::StatusNotification(NotificationType statusType) :
                if (NOTIFICATION_TYPE_ONGOING ==  type)
                {       //ongoing no ticker.
                        LoggerI("ongoing type");
-                       notification_set_display_applist(noti, NOTIFICATION_DISPLAY_APP_NOTIFICATION_TRAY |NOTIFICATION_DISPLAY_APP_INDICATOR );
+                       if ( NOTIFICATION_ERROR_NONE != notification_set_display_applist(noti, NOTIFICATION_DISPLAY_APP_NOTIFICATION_TRAY |NOTIFICATION_DISPLAY_APP_INDICATOR ))
+                       {
+                               throw UnknownException("can't set notification display applist");
+                       }
                }
+               
        }
        else
        {
@@ -196,17 +184,29 @@ StatusNotification::StatusNotification(void* noti) :
 
                LoggerI(" notification type  =" << type);
                setNotiType(type);
-               setProgressType(NOTI_PROGRESS_TYPE_PERCENTAGE); //default.
+               //setProgressType(NOTI_PROGRESS_TYPE_PERCENTAGE); //default.
+               //read Progress type value.
+               char *strProgressType = NULL;
+               if (NOTIFICATION_ERROR_NONE == notification_get_image(notification, NOTIFICATION_IMAGE_TYPE_LIST_5,  &strProgressType))
+               {
+                       if ( strProgressType )
+                       {
+                               std::string notiProgressType(strProgressType);
+                               if( notiProgressType.compare(TIZEN_NOTIFICATION_PROGRESS_TYPE_BYTE) == 0)
+                                       m_progressType = NOTI_PROGRESS_TYPE_SIZE;
+                       }
+               }
                
                setNotificationHandle((void*)notification);
                loadThumbnails();
                loadDetailInfos();
 
+#if 0
                 if ( type  == NOTI_TYPE_PROGRESS)
                 {
                         notification_update_progress(notification, NOTIFICATION_PRIV_ID_NONE, getProgressValue());
                 }
-
+#endif
                //service
                bundle *bSvc = NULL;
 
@@ -288,16 +288,28 @@ StatusNotification::StatusNotification(int privID) :
 
                LoggerI(" notification type  =" << type);
                setNotiType(type);
-               setProgressType(NOTI_PROGRESS_TYPE_PERCENTAGE); //default.      
+               //setProgressType(NOTI_PROGRESS_TYPE_PERCENTAGE); //default.
+               //read Progress type value.
+               char *strProgressType = NULL;
+               if (NOTIFICATION_ERROR_NONE == notification_get_image(notification, NOTIFICATION_IMAGE_TYPE_LIST_5,  &strProgressType))
+               {
+                       if ( strProgressType )
+                       {
+                               std::string notiProgressType(strProgressType);
+                               if( notiProgressType.compare(TIZEN_NOTIFICATION_PROGRESS_TYPE_BYTE) == 0)
+                                       m_progressType = NOTI_PROGRESS_TYPE_SIZE;
+                       }
+               }
+               
                setNotificationHandle((void*)notification);
                loadThumbnails();
                loadDetailInfos();
-
+#if 0
                 if ( type  == NOTI_TYPE_PROGRESS)
                 {
                         notification_update_progress(notification, NOTIFICATION_PRIV_ID_NONE, getProgressValue());
                 }
-
+#endif
                //service
                bundle *bSvc = NULL;
 
@@ -340,14 +352,13 @@ StatusNotification::~StatusNotification()
        
        if (m_notiHandle)
        {
-#if 0
                LoggerI(" service = " << m_service);
                if (m_service != NULL)
                {
                        service_destroy(m_service);
                        m_service = NULL;
                }
-#endif         
+
                if (notification_free(m_notiHandle) != NOTIFICATION_ERROR_NONE)
                {
                        throw UnknownException("notification free failed...");
@@ -445,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
@@ -482,7 +499,6 @@ void StatusNotification::setTitle(std::string title)
        }
 }
 
-
 std::string StatusNotification::getContent()
 {
        LoggerI("get Content handle: " << m_notiHandle);
@@ -495,12 +511,13 @@ std::string StatusNotification::getContent()
                        throw UnknownException("get notification Content error");
                }
                
-               LoggerI(" get Content : " << content);
-
                std::string notiContent;
                
                if(content)
+               {
                        notiContent = content;
+                       LoggerI(" get Content : " << content);
+               }
 
                return notiContent;
                
@@ -566,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)
@@ -617,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
        {
@@ -964,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");      
                }
        }
 
@@ -979,9 +1001,10 @@ void StatusNotification::setApplicationId(const std::string& appId)
 std::string StatusNotification::getApplicationId()
 {
        std::string retString;
-       service_h service = NULL;
        char* appIdStr = NULL;
-       
+#if 0  
+       service_h service = NULL;
+
        if (m_service != NULL)
        {
                int retcode;
@@ -1007,10 +1030,10 @@ std::string StatusNotification::getApplicationId()
                        }
                }
        }
-
-       if (service != NULL) 
+#endif
+       if (m_service != NULL) 
        {
-               if (service_get_app_id(service, &appIdStr) != SERVICE_ERROR_NONE)
+               if (service_get_app_id(m_service, &appIdStr) != SERVICE_ERROR_NONE)
                {
                        throw UnknownException ("get a appId error");
                }
@@ -1101,6 +1124,48 @@ void StatusNotification::setProgressValue(const double &progressValue)
        }
 }
 
+NotificationProgressType StatusNotification::getProgressType()
+{
+       return m_progressType;
+}
+
+void StatusNotification::setProgressType(NotificationProgressType type)
+{
+       
+       if (m_notiHandle)
+       {
+               LoggerI(" NotificationProgressType = " << type);
+
+               std::string progressType;
+
+               if ( type == NOTI_PROGRESS_TYPE_PERCENTAGE)
+               {
+                       progressType = TIZEN_NOTIFICATION_PROGRESS_TYPE_PERCENTAGE;
+               }
+               else if ( type == NOTI_PROGRESS_TYPE_SIZE)
+               {
+                       progressType = TIZEN_NOTIFICATION_PROGRESS_TYPE_BYTE;
+               }
+               else
+               {
+                       throw TypeMismatchException("Invalid Progress Type.");
+               }
+               
+               if (notification_set_image(m_notiHandle,NOTIFICATION_IMAGE_TYPE_LIST_5, progressType.c_str()) != NOTIFICATION_ERROR_NONE)
+               {
+                       throw UnknownException("set notification sound error");
+               }
+
+               m_progressType = type;
+       }
+       else
+       {       
+               LoggerD("noti Handle is NULL");
+               throw UnknownException("notification handle is null");
+       }
+       
+}
+
 std::string StatusNotification::getSubIconPath()
 {
         LoggerI("Handle = " << m_notiHandle);
@@ -1692,6 +1757,185 @@ service_h StatusNotification::getService()
        return m_service;
 }
 
+std::string StatusNotification::getLight()
+{
+       LoggerI("get Light handle: " << m_notiHandle);
+       if (m_notiHandle)
+       {
+               int ledColor = 0;
+               notification_led_op_e type = NOTIFICATION_LED_OP_ON;
+               if (notification_get_led(m_notiHandle, &type, &ledColor) != NOTIFICATION_ERROR_NONE)
+               {
+                       throw UnknownException("get notification Content error");
+               }
+               std::string light;
+               std::stringstream stream;
+               if (NOTIFICATION_LED_OP_OFF != type)
+               {
+                       stream <<  std::hex  << ledColor;
+                       light = "#" + stream.str();
+               }
+               
+               return boost::to_lower_copy(light);
+       }
+       else
+       {
+               throw UnknownException("notification handle is null");
+       }
+}
+
+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());
+
+                       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;
+                       
+                       if (notification_set_led(m_notiHandle, type, ledColor) != NOTIFICATION_ERROR_NONE)
+                       {
+                               throw UnknownException("set notification led ");
+                       }                       
+                       
+               }
+               else
+               {
+                       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
+       {
+               throw UnknownException("notification handle is null");
+       }
+}
+
+unsigned long StatusNotification::getLightOnTime()
+{
+       LoggerI("get Light on Time handle: " << m_notiHandle);
+       if (m_notiHandle)
+       {
+               int onTime = 0;
+               int offTime = 0;
+               
+               if (notification_get_led_time_period(m_notiHandle, &onTime, &offTime ) != NOTIFICATION_ERROR_NONE)
+               {
+                       throw UnknownException("set notification led ");
+               }
+               LoggerI("onTime " << onTime);
+               
+               return (unsigned long) onTime;
+       }
+       else
+       {
+               throw UnknownException("notification handle is null");
+       }
+}
+
+void StatusNotification::setLightOnTime(unsigned long time)
+{
+       LoggerI("set Light on Time handle: " << m_notiHandle);
+       LoggerI("itme = " << time);
+       if (m_notiHandle)
+       {
+               int offTime = getLightOffTime();
+               
+               if (notification_set_led_time_period(m_notiHandle, time, offTime ) != NOTIFICATION_ERROR_NONE)
+               {
+                       throw UnknownException("set notification led ");
+               }
+               
+       }
+       else
+       {
+               throw UnknownException("notification handle is null");
+       }
+}
+
+unsigned long StatusNotification::getLightOffTime()
+{
+
+       LoggerI("get Light on Time handle: " << m_notiHandle);
+       if (m_notiHandle)
+       {
+               int onTime = 0;
+               int offTime = 0;
+               
+               if (notification_get_led_time_period(m_notiHandle, &onTime, &offTime ) != NOTIFICATION_ERROR_NONE)
+               {
+                       throw UnknownException("set notification led ");
+               }
+               LoggerI("offTime " << offTime);
+               
+               return offTime;
+       }
+       else
+       {
+               throw UnknownException("notification handle is null");
+       }
+
+}
+
+void StatusNotification::setLightOffTime(unsigned long time)
+{
+       LoggerI("set Light off Time handle: " << m_notiHandle);
+       LoggerI("time = " << time);
+       if (m_notiHandle)
+       {
+               int onTime = getLightOnTime();
+               
+               if (notification_set_led_time_period(m_notiHandle, onTime, time ) != NOTIFICATION_ERROR_NONE)
+               {
+                       throw UnknownException("set notification led ");
+               }
+       }
+       else
+       {
+               throw UnknownException("notification handle is null");
+       }
+}
 
 //Detail Info
 void StatusNotification::loadDetailInfos()
@@ -1702,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
@@ -1736,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);
@@ -1818,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)
@@ -1886,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)
@@ -1954,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