#include <Logger.h>
#include <sstream>
#include <appsvc/appsvc.h>
+#include <sstream>
+#include <boost/algorithm/string.hpp>
#include "StatusNotification.h"
namespace DeviceAPI {
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),
throw UnknownException("get notification title error");
}
- std::string notiTitle(title);
+ std::string notiTitle;
+ if (title)
+ {
+ notiTitle = title;
+ LoggerI(" get title : " << title);
+ }
+
return notiTitle;
}
else
}
}
-
std::string StatusNotification::getContent()
{
LoggerI("get Content handle: " << m_notiHandle);
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)
{
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
{
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");
}
}
return m_service;
}
-
std::string StatusNotification::getLight()
{
LoggerI("get Light handle: " << m_notiHandle);
{
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
{
}
}
+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
{
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
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);
}
+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)
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)
}
}
-
-#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