2 // Tizen Web Device API
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
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
9 // http://www.apache.org/licenses/LICENSE-2.0
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.
18 #include <PlatformException.h>
21 #include <appsvc/appsvc.h>
24 #include <boost/algorithm/string.hpp>
25 #include "StatusNotification.h"
28 namespace Notification {
30 #define DEFAULT_ICON_PATH "/opt/share/icons/default/"
31 #define MAX_NOTIFICATION_DETAIL_INFO_LENGTH 2
32 #define MAX_THUMBNAIL_LENGTH 4
34 extern "C" int service_create_event(bundle *data, struct service_s **service);
35 //tern "C" int service_to_bundle(service_h service, bundle **data);
38 static bool service_extra_data_cb(service_h service, const char *key, void *user_data)
44 if (user_data != NULL && key != NULL)
46 LoggerI("user data & key is existed");
48 DeviceAPI::Application::ApplicationControlPtr* appControl =
49 (DeviceAPI::Application::ApplicationControlPtr*)(user_data);
51 DeviceAPI::Application::ApplicationControlDataPtr data(new DeviceAPI::Application::ApplicationControlData());
52 LoggerI("key = " << key);
53 std::string keyStr = key;
54 std::vector<std::string> keyValue;
57 if (service_get_extra_data_array((*appControl)->getService_h(), key, &value, &length) == SERVICE_ERROR_NONE)
59 LoggerI("extra_data_array length = " << length);
61 if (value != NULL && length != 0)
63 LoggerI("extra_data_length = " << length);
65 for (index = 0; index < length; index++)
67 LoggerI("Value=" << value[index]);
68 keyValue.push_back(value[index]);
71 data->setValue(keyValue);
72 (*appControl)->addAppControlData(data);
82 StatusNotification::StatusNotification(NotificationType statusType) :
83 m_notiType(NOTI_TYPE_NONE),
86 m_progressType(NOTI_PROGRESS_TYPE_PERCENTAGE),
90 LoggerI("statusType =" << statusType);
92 notification_type_e type = NOTIFICATION_TYPE_NONE;
93 setNotiType(statusType);
95 if (statusType == NOTI_TYPE_SIMPLE || statusType == NOTI_TYPE_MUTIPLE || statusType == NOTI_TYPE_THUMBNAIL)
97 type = NOTIFICATION_TYPE_NOTI;
99 else if ( statusType == NOTI_TYPE_ONGOING || statusType == NOTI_TYPE_PROGRESS)
101 type = NOTIFICATION_TYPE_ONGOING;
105 LoggerI(" invalide noti type");
106 throw TypeMismatchException("value is not notification type");
109 //setProgressType(NOTI_PROGRESS_TYPE_PERCENTAGE); //default
111 LoggerI("Notification Type : " << type);
113 notification_h noti = notification_create(type); //create notificatin.
116 LoggerI("noti =" << noti);
117 setNotificationHandle((void*)noti);
119 if (NOTIFICATION_TYPE_ONGOING == type)
120 { //ongoing no ticker.
121 LoggerI("ongoing type");
122 if ( NOTIFICATION_ERROR_NONE != notification_set_display_applist(noti, NOTIFICATION_DISPLAY_APP_NOTIFICATION_TRAY |NOTIFICATION_DISPLAY_APP_INDICATOR ))
124 throw UnknownException("can't set notification display applist");
131 throw UnknownException("can't make new notification object");
134 //m_detailInfos = new std::vector<NotificationDetailInfo*>();
135 //m_thumbs = new std::vector<std::string>();
139 StatusNotification::StatusNotification(void* noti) :
140 m_notiType(NOTI_TYPE_NONE),
143 m_progressType(NOTI_PROGRESS_TYPE_PERCENTAGE),
144 m_notiUpdated(false),
147 LoggerI("noti : " << noti);
149 notification_h notification = (notification_h)noti;
153 NotificationType type = NOTI_TYPE_NONE;
154 notification_type_e noti_type = NOTIFICATION_TYPE_NONE;
155 notification_ly_type_e noti_layout = NOTIFICATION_LY_NONE;
157 notification_get_type(notification, ¬i_type);
158 notification_get_layout(notification, ¬i_layout);
161 if ( noti_type == NOTIFICATION_TYPE_NOTI )
163 if ( noti_layout == NOTIFICATION_LY_NOTI_EVENT_SINGLE ||
164 noti_layout == NOTIFICATION_LY_NOTI_EVENT_MULTIPLE )
166 type = NOTI_TYPE_SIMPLE;
168 else if (noti_layout == NOTIFICATION_LY_NOTI_THUMBNAIL)
170 type = NOTI_TYPE_THUMBNAIL;
173 else if ( noti_type == NOTIFICATION_TYPE_ONGOING)
175 if ( noti_layout == NOTIFICATION_LY_ONGOING_EVENT )
177 type = NOTI_TYPE_ONGOING;
179 else if ( noti_layout == NOTIFICATION_LY_ONGOING_PROGRESS)
181 type = NOTI_TYPE_PROGRESS;
185 LoggerI(" notification type =" << type);
187 //setProgressType(NOTI_PROGRESS_TYPE_PERCENTAGE); //default.
188 //read Progress type value.
189 char *strProgressType = NULL;
190 if (NOTIFICATION_ERROR_NONE == notification_get_image(notification, NOTIFICATION_IMAGE_TYPE_LIST_5, &strProgressType))
192 if ( strProgressType )
194 std::string notiProgressType(strProgressType);
195 if( notiProgressType.compare(TIZEN_NOTIFICATION_PROGRESS_TYPE_BYTE) == 0)
196 m_progressType = NOTI_PROGRESS_TYPE_SIZE;
200 setNotificationHandle((void*)notification);
205 if ( type == NOTI_TYPE_PROGRESS)
207 notification_update_progress(notification, NOTIFICATION_PRIV_ID_NONE, getProgressValue());
213 int ret = notification_get_execute_option(notification, NOTIFICATION_EXECUTE_TYPE_SINGLE_LAUNCH, NULL, &bSvc);
214 LoggerI("ret = " << ret);
215 if (ret == NOTIFICATION_ERROR_NONE)
217 LoggerI(" bundle = " << bSvc);
220 LoggerI("bundle is valid");
221 int ret = service_create_event(bSvc, &m_service);
222 if (ret != SERVICE_ERROR_NONE)
224 LoggerI("Service Create Event Error");
225 throw UnknownException("can't make service object");
231 notification_free(notification);
232 throw UnknownException("can't get service data");
238 throw InvalidValuesException("It is not notification object.");
243 StatusNotification::StatusNotification(int privID) :
244 m_notiType(NOTI_TYPE_NONE),
247 m_progressType(NOTI_PROGRESS_TYPE_PERCENTAGE),
248 m_notiUpdated(false),
251 LoggerI("priv ID : " << privID);
253 notification_h notification = notification_load( NULL, privID); //load notification.
254 LoggerI(" notification " << notification);
258 NotificationType type = NOTI_TYPE_NONE;
259 notification_type_e noti_type = NOTIFICATION_TYPE_NONE;
260 notification_ly_type_e noti_layout = NOTIFICATION_LY_NONE;
262 notification_get_type(notification, ¬i_type);
263 notification_get_layout(notification, ¬i_layout);
265 if ( noti_type == NOTIFICATION_TYPE_NOTI )
267 if ( noti_layout == NOTIFICATION_LY_NOTI_EVENT_SINGLE ||
268 noti_layout == NOTIFICATION_LY_NOTI_EVENT_MULTIPLE )
270 type = NOTI_TYPE_SIMPLE;
272 else if (noti_layout == NOTIFICATION_LY_NOTI_THUMBNAIL)
274 type = NOTI_TYPE_THUMBNAIL;
277 else if ( noti_type == NOTIFICATION_TYPE_ONGOING)
279 if ( noti_layout == NOTIFICATION_LY_ONGOING_EVENT )
281 type = NOTI_TYPE_ONGOING;
283 else if ( noti_layout == NOTIFICATION_LY_ONGOING_PROGRESS)
285 type = NOTI_TYPE_PROGRESS;
289 LoggerI(" notification type =" << type);
291 //setProgressType(NOTI_PROGRESS_TYPE_PERCENTAGE); //default.
292 //read Progress type value.
293 char *strProgressType = NULL;
294 if (NOTIFICATION_ERROR_NONE == notification_get_image(notification, NOTIFICATION_IMAGE_TYPE_LIST_5, &strProgressType))
296 if ( strProgressType )
298 std::string notiProgressType(strProgressType);
299 if( notiProgressType.compare(TIZEN_NOTIFICATION_PROGRESS_TYPE_BYTE) == 0)
300 m_progressType = NOTI_PROGRESS_TYPE_SIZE;
304 setNotificationHandle((void*)notification);
308 if ( type == NOTI_TYPE_PROGRESS)
310 notification_update_progress(notification, NOTIFICATION_PRIV_ID_NONE, getProgressValue());
316 int ret = notification_get_execute_option(notification, NOTIFICATION_EXECUTE_TYPE_SINGLE_LAUNCH, NULL, &bSvc);
317 LoggerI("ret = " << ret);
318 if (ret == NOTIFICATION_ERROR_NONE)
320 LoggerI(" bundle = " << bSvc);
323 LoggerI("bundle is valid");
324 int ret = service_create_event(bSvc, &m_service);
325 if (ret != SERVICE_ERROR_NONE)
327 LoggerI("Service Create Event Error");
328 throw UnknownException("can't make service object");
334 notification_free(notification);
335 throw UnknownException("can't get service data");
341 throw NotFoundException("It is not notification ID or removed notification");
346 StatusNotification::~StatusNotification()
348 LoggerI(" notification = " << m_notiHandle);
351 //clearDetailInfos();
355 LoggerI(" service = " << m_service);
356 if (m_service != NULL)
358 service_destroy(m_service);
362 if (notification_free(m_notiHandle) != NOTIFICATION_ERROR_NONE)
364 throw UnknownException("notification free failed...");
371 int StatusNotification::getID()
373 int id = -1; // notification not inserted yet.
376 notification_get_id(m_notiHandle, NULL, &id);
382 std::string StatusNotification::getStatusType()
386 if ( NOTI_TYPE_SIMPLE == getNotiType())
390 else if ( NOTI_TYPE_ONGOING == getNotiType())
394 else if ( NOTI_TYPE_PROGRESS == getNotiType())
398 else if ( NOTI_TYPE_THUMBNAIL == getNotiType())
409 void StatusNotification::setStatusType(std::string type)
411 LoggerI("type = " << type);
413 NotificationType notiType = NOTI_TYPE_NONE;
415 if( type.compare(TIZEN_STATUS_NOTIFICATION_TYPE_SIMPLE) == 0)
416 notiType = NOTI_TYPE_SIMPLE;
417 else if( type.compare(TIZEN_STATUS_NOTIFICATION_TYPE_THUMBNAIL) == 0)
418 notiType = NOTI_TYPE_THUMBNAIL;
419 else if( type.compare(TIZEN_STATUS_NOTIFICATION_TYPE_ONGOING) == 0)
420 notiType = NOTI_TYPE_ONGOING;
421 else if( type.compare(TIZEN_STATUS_NOTIFICATION_TYPE_PROGRESS) == 0)
422 notiType = NOTI_TYPE_PROGRESS;
424 throw InvalidValuesException("Invalid Status Type.");
426 LoggerI("Notification type = " << notiType);
427 setNotiType(notiType);
430 time_t StatusNotification::getPostedTime()
432 LoggerI("get m_notiHandle = " << m_notiHandle);
434 time_t postedTime = 0;
438 if (notification_get_insert_time(m_notiHandle, &postedTime) != NOTIFICATION_ERROR_NONE)
440 throw UnknownException("get notification posted time error");
444 LoggerI("posted Time =" << ctime(&postedTime));
448 std::string StatusNotification::getTitle()
454 if (notification_get_text(m_notiHandle,NOTIFICATION_TEXT_TYPE_TITLE, &title) != NOTIFICATION_ERROR_NONE)
456 throw UnknownException("get notification title error");
459 std::string notiTitle;
463 LoggerI(" get title : " << title);
470 throw UnknownException("notification handle is null");
474 void StatusNotification::setTitle(std::string title)
476 LoggerI("Title : " << title);
479 LoggerI("get Title : " << getTitle());
480 if((getTitle()).compare(title)) //different value.
482 if (notification_set_text(m_notiHandle, NOTIFICATION_TEXT_TYPE_TITLE, title.c_str(),
483 NULL, NOTIFICATION_VARIABLE_TYPE_NONE ) != NOTIFICATION_ERROR_NONE)
485 throw UnknownException("set notification title error");
488 setUpdatedFlag(true);
492 LoggerI(" title = " << title << " getTitle = " << getTitle());
497 LoggerD("noti Handle is NULL");
498 throw UnknownException("notification handle is null");
502 std::string StatusNotification::getContent()
504 LoggerI("get Content handle: " << m_notiHandle);
507 char *content = NULL;
509 if (notification_get_text(m_notiHandle, NOTIFICATION_TEXT_TYPE_CONTENT, &content) != NOTIFICATION_ERROR_NONE)
511 throw UnknownException("get notification Content error");
514 std::string notiContent;
518 notiContent = content;
519 LoggerI(" get Content : " << content);
527 throw UnknownException("notification handle is null");
532 char* StatusNotification::getStrContent()
534 LoggerI("get Content handle: " << m_notiHandle);
537 char *content = NULL;
539 if (notification_get_text(m_notiHandle, NOTIFICATION_TEXT_TYPE_CONTENT, &content) != NOTIFICATION_ERROR_NONE)
541 throw UnknownException("get notification Content error");
548 throw UnknownException("notification handle is null");
552 void StatusNotification::setContent(std::string content)
554 LoggerI("Content : " << content);
557 if((getContent()).compare(content)) //different value.
559 if (notification_set_text(m_notiHandle, NOTIFICATION_TEXT_TYPE_CONTENT, content.c_str(),
560 NULL, NOTIFICATION_VARIABLE_TYPE_NONE ) != NOTIFICATION_ERROR_NONE)
562 throw UnknownException("set notification content error");
564 setUpdatedFlag(true);
569 LoggerD("noti Handle is NULL");
570 throw UnknownException("notification handle is null");
574 std::string StatusNotification::getIconPath()
577 LoggerI("m_notiHandle = " << m_notiHandle);
580 char *iconPath = NULL;
581 if (notification_get_image(m_notiHandle, NOTIFICATION_IMAGE_TYPE_ICON, &iconPath) != NOTIFICATION_ERROR_NONE)
583 throw UnknownException("get notification icon path error");
586 std::string notiIconPath;
589 notiIconPath = iconPath;
590 LoggerI("icon Path = " << iconPath);
593 //if icon path invalid, return empty string.
594 if ( notiIconPath.find(DEFAULT_ICON_PATH,0) == std::string::npos)
598 return std::string(""); //return empty string.
603 throw UnknownException("notification handle is null");
607 void StatusNotification::setIconPath(const std::string& iconPath)
611 LoggerI("icon path = " << iconPath << " origin icon path = " << getIconPath());
612 if( getIconPath().compare(iconPath))
614 if (notification_set_image(m_notiHandle,NOTIFICATION_IMAGE_TYPE_ICON, iconPath.c_str()) != NOTIFICATION_ERROR_NONE)
616 throw UnknownException("set notification icon error");
618 setUpdatedFlag(true);
623 LoggerD("noti Handle is NULL");
624 throw UnknownException("notification handle is null");
628 std::string StatusNotification::getSoundPath()
630 LoggerI("Handle = " << m_notiHandle);
634 const char *soundPath = NULL;
635 notification_sound_type_e type = NOTIFICATION_SOUND_TYPE_NONE;
637 if (notification_get_sound(m_notiHandle, &type, &soundPath) != NOTIFICATION_ERROR_NONE)
639 throw UnknownException("get notification sound error");
642 std::string strSoundPath;
645 LoggerI(" soudn type=" << type);
646 if ( type == NOTIFICATION_SOUND_TYPE_USER_DATA)
648 LoggerI("soundPath = " << soundPath);
649 strSoundPath = soundPath;
653 LoggerI("soundPath :" << strSoundPath);
659 LoggerD("noti Handle is NULL");
660 throw UnknownException("notification handle is null");
664 void StatusNotification::setSoundPath(const std::string& sound)
668 LoggerI("sound path = " << sound << " origin sound path = " << getSoundPath());
670 if( getSoundPath().compare(sound))
672 if (notification_set_sound(m_notiHandle,NOTIFICATION_SOUND_TYPE_USER_DATA, sound.c_str()) != NOTIFICATION_ERROR_NONE)
674 throw UnknownException("set notification sound error");
676 setUpdatedFlag(true);
681 LoggerI("sound path is NULL");
682 if ( NOTI_TYPE_ONGOING == getNotiType() || NOTI_TYPE_PROGRESS == getNotiType())
684 LoggerI("Ongoing Type" );
685 if (notification_set_sound(m_notiHandle,NOTIFICATION_SOUND_TYPE_NONE, NULL) != NOTIFICATION_ERROR_NONE)
687 throw UnknownException("set notification sound error");
692 if (notification_set_sound(m_notiHandle,NOTIFICATION_SOUND_TYPE_DEFAULT, sound.c_str()) != NOTIFICATION_ERROR_NONE)
694 throw UnknownException("set notification sound error");
702 LoggerD("noti Handle is NULL");
703 throw UnknownException("notification handle is null");
707 bool StatusNotification::getDefaultVibration()
709 LoggerI("getDefaultVibration");
712 notification_vibration_type_e vib_type;
713 if (notification_get_vibration(m_notiHandle, &vib_type, NULL) != NOTIFICATION_ERROR_NONE)
715 throw UnknownException("set notification sound error");
718 if (NOTIFICATION_VIBRATION_TYPE_DEFAULT == vib_type || NOTIFICATION_VIBRATION_TYPE_USER_DATA == vib_type)
729 LoggerD("noti Handle is NULL");
730 throw UnknownException("notification handle is null");
736 void StatusNotification::setDefaultVibration(const bool& vibration)
738 LoggerI("vibration = " << vibration);
741 notification_vibration_type_e vib_type = NOTIFICATION_VIBRATION_TYPE_NONE;
742 LoggerI("old vibration = " << getDefaultVibration());
743 if (getDefaultVibration() != vibration)
747 vib_type = NOTIFICATION_VIBRATION_TYPE_DEFAULT;
751 vib_type = NOTIFICATION_VIBRATION_TYPE_NONE;
753 LoggerI("type vibration type= " << vib_type);
755 if (notification_set_vibration(m_notiHandle, vib_type , NULL) != NOTIFICATION_ERROR_NONE)
757 throw UnknownException("set notification sound error");
759 setUpdatedFlag(true);
764 LoggerD("noti Handle is NULL");
765 throw UnknownException("notification handle is null");
770 DeviceAPI::Application::ApplicationControlPtr StatusNotification::getApplicationControl()
773 service_h service = NULL;
774 char *tempStr = NULL;
776 DeviceAPI::Application::ApplicationControlPtr appControl(new DeviceAPI::Application::ApplicationControl());
781 appControl->setService_h(m_service);
783 if(service_get_operation(m_service, &tempStr) == SERVICE_ERROR_NONE)
785 LoggerD("Operation Str = " << tempStr);
788 appControl->setOperation(tempStr);
795 if (service_get_mime(m_service, &tempStr) == SERVICE_ERROR_NONE)
797 LoggerD("Mime Str = " << tempStr);
800 appControl->setMime(tempStr);
807 if (service_get_uri(m_service, &tempStr) == SERVICE_ERROR_NONE)
809 LoggerD("Uri Str = " << tempStr);
812 appControl->setUri(tempStr);
818 if (service_get_category(m_service, &tempStr) == SERVICE_ERROR_NONE)
820 LoggerD("Category Str = " << tempStr);
823 appControl->setCategory(tempStr);
830 if ( service_foreach_extra_data(m_service, service_extra_data_cb,(void*)&appControl) != SERVICE_ERROR_NONE)
832 ThrowMsg(WrtDeviceApis::Commons::UnknownException, "get notification service uri error");
839 Catch (WrtDeviceApis::Commons::Exception)
853 LoggerW(_rethrown_exception.GetMessage());
859 void StatusNotification::setApplicationControl(DeviceAPI::Application::ApplicationControlPtr control)
861 LoggerI("Entered m_service : " << m_service << " control : " << control);
863 //delete old service.
866 service_destroy(m_service);
870 if(service_create(&m_service) != SERVICE_ERROR_NONE)
872 throw UnknownException("service creation error");
876 LoggerI("getOperation : " << control->getOperation().c_str());
877 if (control->getOperation().size() != 0)
879 m_launchFlag = true; //default attribute
880 if (service_set_operation(m_service, control->getOperation().c_str()) != SERVICE_ERROR_NONE)
882 throw UnknownException("service set operation error");
887 LoggerI("getUri : " << control->getUri().c_str());
888 if (control->getUri().size() != 0)
890 if (service_set_uri(m_service, control->getUri().c_str() ) != SERVICE_ERROR_NONE)
892 throw UnknownException("service set uri error");
897 LoggerI("getMime : " << control->getMime().c_str());
898 if (control->getMime().size() != 0)
900 if (service_set_mime(m_service, control->getMime().c_str() ) != SERVICE_ERROR_NONE)
902 throw UnknownException("service set mime error");
906 LoggerI("Category : " << control->getCategory().c_str());
907 if (control->getCategory().size() != 0)
909 if (service_set_category(m_service, control->getCategory().c_str() ) != SERVICE_ERROR_NONE)
911 throw UnknownException("service set mime error");
915 std::vector<DeviceAPI::Application::ApplicationControlDataPtr> appControlDataArray = control->getAppControlDataArray();
918 LoggerI (" App Control Datas Count : " << appControlDataArray.size());
920 DeviceAPI::Application::ApplicationControlDataArray::iterator iter;
922 for(iter = appControlDataArray.begin(); iter != appControlDataArray.end(); iter++)
924 DeviceAPI::Application::ApplicationControlDataPtr appControlData = *iter;
925 std::string key = appControlData->getKey();
926 LoggerI(" key : " << key);
931 std::vector<std::string> value = appControlDataArray[index]->getValue();
932 const char **arrayValue = (const char**)calloc(sizeof(char*), value.size());
934 for (size_t indexArray = 0; indexArray < value.size(); indexArray++)
936 arrayValue[indexArray] = (char*)value[indexArray].c_str();
937 LoggerI( " value : " << arrayValue[indexArray]);
940 const char* strKey = key.c_str();
941 LoggerI( " value size: " << value.size());
942 if (service_add_extra_data_array(m_service, strKey, arrayValue, value.size()) != SERVICE_ERROR_NONE)
944 throw UnknownException("service set extra data error");
954 void StatusNotification::setApplicationId(const std::string& appId)
956 LoggerI("m_service = " << m_service << " appId = " << appId);
959 if (service_create(&m_service) != SERVICE_ERROR_NONE)
961 LoggerW("Create Service Failed..");
962 throw UnknownException("service creation error");
969 if (service_set_app_id(m_service, appId.c_str())!= SERVICE_ERROR_NONE)
971 throw UnknownException("service set appId error");
977 std::string StatusNotification::getApplicationId()
979 std::string retString;
980 char* appIdStr = NULL;
982 if (m_service != NULL)
984 if (service_get_app_id(m_service, &appIdStr) != SERVICE_ERROR_NONE)
986 throw UnknownException ("Get applicaiton ID failed...");
989 if (appIdStr != NULL)
991 retString = appIdStr;
1000 bool StatusNotification::isNullApplicationID()
1002 char* appIdStr = NULL;
1004 if (m_service != NULL)
1007 if (service_get_app_id(m_service, &appIdStr) != SERVICE_ERROR_NONE)
1009 throw UnknownException ("Get applicaiton ID failed...");
1012 if (appIdStr == NULL)
1025 double StatusNotification::getProgressValue()
1031 NotificationProgressType progressType = getProgressType();
1033 if (progressType == NOTI_PROGRESS_TYPE_SIZE)
1035 if (notification_get_size(m_notiHandle, &value) != NOTIFICATION_ERROR_NONE)
1037 throw UnknownException("get notification size error");
1039 LoggerI("Size Val = " << value);
1041 else if ( progressType == NOTI_PROGRESS_TYPE_PERCENTAGE )
1043 if (notification_get_progress(m_notiHandle, &value) != NOTIFICATION_ERROR_NONE)
1045 throw UnknownException("get notification percentage error");
1047 LoggerI("Percentage Val = " << value);
1051 throw UnknownException("get notification progress type error");
1056 LoggerD("noti Handle is NULL");
1058 LoggerI("value = " << value);
1063 void StatusNotification::setProgressValue(const double &progressValue)
1067 NotificationProgressType progressType = getProgressType();
1068 LoggerI("Progress Type : " << progressType);
1070 double val = getProgressValue();
1071 LoggerI("Progress value = " << progressValue << " origin Progress Value =" << val);
1073 if (progressType == NOTI_PROGRESS_TYPE_SIZE)
1075 if (notification_set_size(m_notiHandle, progressValue) != NOTIFICATION_ERROR_NONE)
1077 throw UnknownException("set notification progress size error");
1080 else if ( progressType == NOTI_PROGRESS_TYPE_PERCENTAGE )
1082 if (notification_set_progress(m_notiHandle, progressValue) != NOTIFICATION_ERROR_NONE)
1084 throw UnknownException("set notification percentage error");
1089 throw UnknownException("get notification progress type error");
1094 LoggerD("noti Handle is NULL");
1095 throw UnknownException( "notification handle is null");
1099 NotificationProgressType StatusNotification::getProgressType()
1101 return m_progressType;
1104 void StatusNotification::setProgressType(NotificationProgressType type)
1109 LoggerI(" NotificationProgressType = " << type);
1111 std::string progressType;
1113 if ( type == NOTI_PROGRESS_TYPE_PERCENTAGE)
1115 progressType = TIZEN_NOTIFICATION_PROGRESS_TYPE_PERCENTAGE;
1117 else if ( type == NOTI_PROGRESS_TYPE_SIZE)
1119 progressType = TIZEN_NOTIFICATION_PROGRESS_TYPE_BYTE;
1123 throw TypeMismatchException("Invalid Progress Type.");
1126 if (notification_set_image(m_notiHandle,NOTIFICATION_IMAGE_TYPE_LIST_5, progressType.c_str()) != NOTIFICATION_ERROR_NONE)
1128 throw UnknownException("set notification sound error");
1131 m_progressType = type;
1135 LoggerD("noti Handle is NULL");
1136 throw UnknownException("notification handle is null");
1141 std::string StatusNotification::getSubIconPath()
1143 LoggerI("Handle = " << m_notiHandle);
1146 char *subIconPath = NULL;
1148 if (notification_get_image(m_notiHandle, NOTIFICATION_IMAGE_TYPE_ICON_SUB, &subIconPath) != NOTIFICATION_ERROR_NONE)
1150 throw UnknownException("get notification sub icon error");
1153 std::string notiSubIconPath;
1155 notiSubIconPath = subIconPath;
1156 return notiSubIconPath;
1160 throw UnknownException("notification handle is null");
1165 void StatusNotification::setSubIconPath(const std::string& subIconPath)
1169 LoggerI(" subIconPath = " << subIconPath << " origin SubIconPath = " << getSubIconPath());
1171 if( getSubIconPath().compare(subIconPath))
1173 if (notification_set_image(m_notiHandle,NOTIFICATION_IMAGE_TYPE_ICON_SUB, subIconPath.c_str()) != NOTIFICATION_ERROR_NONE)
1175 throw UnknownException("set notification sound error");
1177 setUpdatedFlag(true);
1182 LoggerD("noti Handle is NULL");
1183 throw UnknownException("notification handle is null");
1187 void StatusNotification::loadThumbnails()
1191 if (!m_thumbs.empty())
1195 if (notification_get_image(m_notiHandle, NOTIFICATION_IMAGE_TYPE_LIST_1, &thumb) != NOTIFICATION_ERROR_NONE)
1197 throw UnknownException( "get notification thumbnail error");
1200 m_thumbs.push_back(thumb);
1202 // m_thumbs.push_back(std::string("")); //set empty
1205 if (notification_get_image(m_notiHandle, NOTIFICATION_IMAGE_TYPE_LIST_2, &thumb) != NOTIFICATION_ERROR_NONE)
1207 throw UnknownException( "get notification sub information error");
1210 m_thumbs.push_back(thumb);
1212 // m_thumbs.push_back(std::string("")); //set empty
1215 if (notification_get_image(m_notiHandle, NOTIFICATION_IMAGE_TYPE_LIST_3, &thumb) != NOTIFICATION_ERROR_NONE)
1217 throw UnknownException( "get notification sub information error");
1221 m_thumbs.push_back(thumb);
1223 // m_thumbs.push_back(std::string("")); //set empty
1226 if (notification_get_image(m_notiHandle, NOTIFICATION_IMAGE_TYPE_LIST_4, &thumb) != NOTIFICATION_ERROR_NONE)
1228 throw UnknownException( "get notification sub information error");
1232 m_thumbs.push_back(thumb);
1234 // m_thumbs.push_back(std::string("")); //set empty
1237 if (notification_get_image(m_notiHandle, NOTIFICATION_IMAGE_TYPE_LIST_5, &thumb) != NOTIFICATION_ERROR_NONE)
1239 throw UnknownException( "get notification sub information error");
1243 m_thumbs.push_back(thumb);
1245 m_thumbs.push_back(std::string("")); //set empty
1252 LoggerD("noti Handle is NULL");
1253 throw UnknownException( "notification handle is null");
1257 std::vector<std::string> StatusNotification::getThumbnails()
1259 LoggerI(" thumbnail Size : " << m_thumbs.size());
1263 std::string StatusNotification::getThumbnail(int index)
1267 LoggerI(" index : " << index);
1269 notification_image_type_e type = NOTIFICATION_IMAGE_TYPE_NONE;
1274 type = NOTIFICATION_IMAGE_TYPE_LIST_1;
1277 type = NOTIFICATION_IMAGE_TYPE_LIST_2;
1280 type = NOTIFICATION_IMAGE_TYPE_LIST_3;
1283 type = NOTIFICATION_IMAGE_TYPE_LIST_4;
1286 type = NOTIFICATION_IMAGE_TYPE_LIST_5;
1289 type = NOTIFICATION_IMAGE_TYPE_NONE;
1292 if ( type != NOTIFICATION_IMAGE_TYPE_NONE)
1295 if (notification_get_image(m_notiHandle, type, &thumb) != NOTIFICATION_ERROR_NONE)
1297 throw UnknownException( "set notification thumbnail error");
1300 std::string thumbnail;
1307 throw UnknownException( "notification handle is null");
1313 LoggerD("noti Handle is NULL");
1314 throw UnknownException( "notification handle is null");
1317 if (m_thumbs.size() > index)
1318 return m_thumbs[index];
1320 return std::string("");
1325 void StatusNotification::setThumbnails(std::vector<std::string> thumbs)
1327 LoggerI("set thumbnails");
1330 std::vector<std::string>::iterator it;
1333 for (it = thumbs.begin(); it < thumbs.end(); ++it)
1335 std::string str = *it;
1336 if ( idx < MAX_THUMBNAIL_LENGTH )
1337 setThumbnail(str, idx); //set notification's thumbnail value.
1345 LoggerD("noti Handle is NULL");
1346 throw UnknownException( "notification handle is null");
1350 void StatusNotification::setThumbnail( const std::string& thumb, int index)
1354 LoggerI(" index : " << index);
1355 LoggerI(" thumb : " << thumb);
1356 notification_image_type_e type = NOTIFICATION_IMAGE_TYPE_NONE;
1361 type = NOTIFICATION_IMAGE_TYPE_LIST_1;
1364 type = NOTIFICATION_IMAGE_TYPE_LIST_2;
1367 type = NOTIFICATION_IMAGE_TYPE_LIST_3;
1370 type = NOTIFICATION_IMAGE_TYPE_LIST_4;
1373 type = NOTIFICATION_IMAGE_TYPE_LIST_5;
1376 type = NOTIFICATION_IMAGE_TYPE_NONE;
1379 if ( type != NOTIFICATION_IMAGE_TYPE_NONE)
1381 if (getThumbnail(index).compare(thumb))
1383 if (notification_set_image(m_notiHandle, type, thumb.c_str()) != NOTIFICATION_ERROR_NONE)
1385 throw UnknownException( "set notification thumbnail error");
1387 setUpdatedFlag(true);
1393 std::string StatusNotification::getBackground()
1395 LoggerI(" Handle : " << m_notiHandle);
1399 char *background = NULL;
1401 if (notification_get_image(m_notiHandle, NOTIFICATION_IMAGE_TYPE_BACKGROUND, &background) != NOTIFICATION_ERROR_NONE)
1403 throw UnknownException( "get notification background error");
1406 std::string notiBackground;
1408 notiBackground = background;
1409 return notiBackground;
1413 LoggerD("noti Handle is NULL");
1414 throw UnknownException( "notification handle is null");
1419 void StatusNotification::setBackground(const std::string imagePath)
1421 LoggerI(" imagePath : " << imagePath);
1424 if (getBackground().compare(imagePath))
1426 if (notification_set_image(m_notiHandle,NOTIFICATION_IMAGE_TYPE_BACKGROUND, imagePath.c_str()) != NOTIFICATION_ERROR_NONE)
1428 throw UnknownException( "set notification sound error");
1430 setUpdatedFlag(true);
1435 LoggerD("noti Handle is NULL");
1436 throw UnknownException( "notification handle is null");
1440 long StatusNotification::getNumber()
1442 LoggerI("Handle = " << m_notiHandle);
1446 char *strNumber = NULL;
1448 if (notification_get_text(m_notiHandle, NOTIFICATION_TEXT_TYPE_EVENT_COUNT, &strNumber) != NOTIFICATION_ERROR_NONE)
1450 throw UnknownException( "get notification background error");
1454 std::istringstream(strNumber) >> number;
1456 LoggerI("Number Is NULL");
1458 LoggerI("number = " << number);
1464 LoggerD("noti Handle is NULL");
1469 const char* StatusNotification::getStrNumber()
1471 LoggerI("Handle = " << m_notiHandle);
1474 char *strNumber = NULL;
1476 if (notification_get_text(m_notiHandle, NOTIFICATION_TEXT_TYPE_EVENT_COUNT, &strNumber) != NOTIFICATION_ERROR_NONE)
1478 throw UnknownException( "get notification background error");
1490 LoggerD("noti Handle is NULL");
1495 void StatusNotification::setNumber(const long number)
1497 LoggerI("Number = " << number);
1500 if(number!=getNumber())
1502 std::stringstream stream;
1504 if (stream.fail()) {
1505 throw UnknownException(
1506 "Couldn't convert notification number");
1509 std::string strNumber = stream.str();
1510 if (notification_set_text(m_notiHandle, NOTIFICATION_TEXT_TYPE_EVENT_COUNT, strNumber.c_str(),
1511 NULL, NOTIFICATION_VARIABLE_TYPE_NONE) != NOTIFICATION_ERROR_NONE)
1513 throw UnknownException( "set notification text error");
1515 setUpdatedFlag(true);
1520 LoggerD("noti Handle is NULL");
1521 throw UnknownException( "notification handle is null");
1525 void* StatusNotification::getNotificationHandle()
1527 return m_notiHandle;
1530 void StatusNotification::setNotificationHandle(void *handle)
1534 throw UnknownException( "notification handle null error");
1536 LoggerI("handle = " << handle << " m_notiHandle = " << m_notiHandle);
1538 if (m_notiHandle != NULL)
1541 if ( notification_delete(m_notiHandle) != NOTIFICATION_ERROR_NONE)
1543 throw UnknownException( "notification delete error");
1545 m_notiHandle = NULL;
1548 m_notiHandle = (notification_h)handle;
1551 service_h StatusNotification::getService()
1556 std::string StatusNotification::getLight()
1558 LoggerI("get Light handle: " << m_notiHandle);
1562 notification_led_op_e type = NOTIFICATION_LED_OP_ON;
1563 if (notification_get_led(m_notiHandle, &type, &ledColor) != NOTIFICATION_ERROR_NONE)
1565 throw UnknownException("get notification Content error");
1568 std::stringstream stream;
1569 if (NOTIFICATION_LED_OP_OFF != type)
1571 stream << std::hex << ledColor;
1572 light = "#" + stream.str();
1575 return boost::to_lower_copy(light);
1579 throw UnknownException("notification handle is null");
1583 bool StatusNotification::isColorFormatNumberic(std::string& color)
1585 //first check length
1586 std::string hexCode = "0123456789abcdef";
1587 if (color.length() == 7 && !color.compare(0, 1, "#") )
1589 for ( size_t i = 1 ; i < color.length() ; i++)
1591 if (std::string::npos == hexCode.find(color[i]))
1599 void StatusNotification::setLight(std::string color)
1601 LoggerI("set Light handle: " << m_notiHandle);
1602 LoggerI("led Color : " << color);
1605 color = boost::to_lower_copy(color); //convert lowercase.
1606 if ( isColorFormatNumberic(color))
1608 std::stringstream stream;
1610 notification_led_op_e type = NOTIFICATION_LED_OP_ON;
1611 std::string colorCode = color.substr(1, color.length());
1613 stream << std::hex << colorCode;
1614 LoggerI("LedColor = " << stream.str());
1616 LoggerI("LedColor = " << ledColor);
1619 type = NOTIFICATION_LED_OP_ON_CUSTOM_COLOR;
1621 type = NOTIFICATION_LED_OP_OFF;
1623 if (notification_set_led(m_notiHandle, type, ledColor) != NOTIFICATION_ERROR_NONE)
1625 throw UnknownException("set notification led ");
1631 LoggerI("color.length()=" << color.length());
1632 if (color.length() == 0)
1634 if (notification_set_led(m_notiHandle, NOTIFICATION_LED_OP_OFF, 0) != NOTIFICATION_ERROR_NONE)
1636 throw UnknownException("set notification led ");
1641 throw InvalidValuesException("color code error!");
1647 throw UnknownException("notification handle is null");
1651 unsigned long StatusNotification::getLightOnTime()
1653 LoggerI("get Light on Time handle: " << m_notiHandle);
1659 if (notification_get_led_time_period(m_notiHandle, &onTime, &offTime ) != NOTIFICATION_ERROR_NONE)
1661 throw UnknownException("set notification led ");
1663 LoggerI("onTime " << onTime);
1665 return (unsigned long) onTime;
1669 throw UnknownException("notification handle is null");
1673 void StatusNotification::setLightOnTime(unsigned long time)
1675 LoggerI("set Light on Time handle: " << m_notiHandle);
1676 LoggerI("itme = " << time);
1679 int offTime = getLightOffTime();
1681 if (notification_set_led_time_period(m_notiHandle, time, offTime ) != NOTIFICATION_ERROR_NONE)
1683 throw UnknownException("set notification led ");
1689 throw UnknownException("notification handle is null");
1693 unsigned long StatusNotification::getLightOffTime()
1696 LoggerI("get Light on Time handle: " << m_notiHandle);
1702 if (notification_get_led_time_period(m_notiHandle, &onTime, &offTime ) != NOTIFICATION_ERROR_NONE)
1704 throw UnknownException("set notification led ");
1706 LoggerI("offTime " << offTime);
1712 throw UnknownException("notification handle is null");
1717 void StatusNotification::setLightOffTime(unsigned long time)
1719 LoggerI("set Light off Time handle: " << m_notiHandle);
1720 LoggerI("time = " << time);
1723 int onTime = getLightOnTime();
1725 if (notification_set_led_time_period(m_notiHandle, onTime, time ) != NOTIFICATION_ERROR_NONE)
1727 throw UnknownException("set notification led ");
1732 throw UnknownException("notification handle is null");
1737 void StatusNotification::loadDetailInfos()
1739 LoggerI("noti Handle = " << m_notiHandle);
1743 for ( int idx = 0; idx < MAX_NOTIFICATION_DETAIL_INFO_LENGTH; idx++)
1745 if (!isNullInformation(idx))
1747 bool isNull = false;
1748 std::string main = getInformation(idx);
1749 std::string sub = getSubInformation(idx, isNull);
1751 LoggerI("Main : [" << main << "] Sub : ['" << sub <<"] isNull :[" << isNull << "]" );
1753 NotificationDetailInfo *info = NULL;
1755 info = new NotificationDetailInfo(m_notiHandle, idx, main);
1757 info = new NotificationDetailInfo(m_notiHandle, idx, main, sub);
1758 m_detailInfos.push_back(info);
1764 LoggerD("noti Handle is NULL");
1765 throw UnknownException( "notification handle is null");
1770 std::vector<NotificationDetailInfo*> StatusNotification::getDetailInfos() const
1772 return m_detailInfos;
1775 void StatusNotification::setDetailInfos(const std::vector<NotificationDetailInfo*> value)
1777 LoggerI("DetailInfos = " << value.size());
1781 std::vector<NotificationDetailInfo*>::const_iterator it;
1784 for (it = value.begin(); it < value.end(); ++it)
1786 NotificationDetailInfo* info = *it;
1787 if ( idx < MAX_NOTIFICATION_DETAIL_INFO_LENGTH )
1790 LoggerI("main " << info->getMainText() << " sub " << info->getSubText() );
1791 setInformation(info->getMainText(), idx);
1792 setSubInformation(info->getSubText(), idx);
1797 m_detailInfos = value;
1801 LoggerD("noti Handle is NULL");
1802 throw UnknownException( "notification handle is null");
1807 int StatusNotification::getDetailInfosNum() const
1809 return m_detailInfos.size();
1812 void StatusNotification::clearDetailInfos()
1814 if ( !m_detailInfos.empty() )
1816 std::vector<NotificationDetailInfo*>::const_iterator it;
1819 for (it = m_detailInfos.begin(); it < m_detailInfos.end(); ++it)
1821 NotificationDetailInfo* info = *it;
1822 LoggerI("Delete Detail Info : " << info);
1827 m_detailInfos.clear(); //clear
1831 std::string StatusNotification::getInformation(int index)
1835 notification_text_type_e type = NOTIFICATION_TEXT_TYPE_NONE;
1839 type = NOTIFICATION_TEXT_TYPE_INFO_1;
1842 type = NOTIFICATION_TEXT_TYPE_INFO_2;
1845 type = NOTIFICATION_TEXT_TYPE_INFO_3;
1848 type = NOTIFICATION_TEXT_TYPE_NONE;
1852 if (NOTIFICATION_TEXT_TYPE_NONE != type && notification_get_text(m_notiHandle, type, &info) != NOTIFICATION_ERROR_NONE)
1854 throw UnknownException("Detail Info index value is invalid or mainText value getting is failed in Detail Info.");
1857 std::string strInfo;
1860 LoggerI(" info " << strInfo);
1866 LoggerW("noti Handle is NULL");
1867 throw UnknownException( "notification handle is null");
1872 bool StatusNotification::isNullInformation(int index)
1876 notification_text_type_e type = NOTIFICATION_TEXT_TYPE_NONE;
1880 type = NOTIFICATION_TEXT_TYPE_INFO_1;
1883 type = NOTIFICATION_TEXT_TYPE_INFO_2;
1886 type = NOTIFICATION_TEXT_TYPE_INFO_3;
1889 type = NOTIFICATION_TEXT_TYPE_NONE;
1893 if (NOTIFICATION_TEXT_TYPE_NONE != type && notification_get_text(m_notiHandle, type, &info) != NOTIFICATION_ERROR_NONE)
1895 throw UnknownException("Detail Info index value is invalid or mainText value getting is failed in Detail Info.");
1900 LoggerI("is not null");
1912 LoggerW("noti Handle is NULL");
1913 throw UnknownException( "notification handle is null");
1917 std::string StatusNotification::getSubInformation(int index, bool& isNull)
1921 notification_text_type_e type = NOTIFICATION_TEXT_TYPE_NONE;
1925 type = NOTIFICATION_TEXT_TYPE_INFO_SUB_1;
1928 type = NOTIFICATION_TEXT_TYPE_INFO_SUB_2;
1931 type = NOTIFICATION_TEXT_TYPE_INFO_SUB_3;
1934 type = NOTIFICATION_TEXT_TYPE_NONE;
1937 char *subInfo = NULL;
1939 if (NOTIFICATION_TEXT_TYPE_NONE != type && notification_get_text(m_notiHandle, type, &subInfo) != NOTIFICATION_ERROR_NONE)
1941 throw UnknownException("Detail Info index value is invalid or subText value getting is failed in Detail Info.");
1944 std::string strSubInfo;
1947 strSubInfo = subInfo;
1952 LoggerI(" subInfo:" << strSubInfo);
1953 LoggerI(" isNull:" << isNull);
1959 LoggerW("noti Handle is NULL");
1960 throw UnknownException ("notification handle is null");
1965 void StatusNotification::setInformation( const std::string& info, int index)
1970 LoggerD(" index : " << idx);
1971 LoggerD(" log : " << info);
1972 notification_text_type_e type = NOTIFICATION_TEXT_TYPE_NONE;
1977 type = NOTIFICATION_TEXT_TYPE_INFO_1;
1980 type = NOTIFICATION_TEXT_TYPE_INFO_2;
1983 type = NOTIFICATION_TEXT_TYPE_INFO_3;
1986 type = NOTIFICATION_TEXT_TYPE_NONE;
1989 if ( type != NOTIFICATION_TEXT_TYPE_NONE)
1991 if (getInformation(idx).compare(info) || isNullInformation(idx))
1993 if (notification_set_text(m_notiHandle, type, info.c_str(),
1994 NULL, NOTIFICATION_VARIABLE_TYPE_NONE) != NOTIFICATION_ERROR_NONE)
1996 throw UnknownException("set notification sound error");
1998 setUpdatedFlag(true);
2003 LoggerW("noti Handle is NULL");
2004 throw UnknownException("notification handle is null");
2009 LoggerW("noti Handle is NULL");
2010 throw UnknownException("notification handle is null");
2014 void StatusNotification::setSubInformation( const std::string& subInfo, int index)
2020 LoggerD(" index : " << idx);
2021 LoggerD(" log : " << subInfo);
2022 notification_text_type_e type = NOTIFICATION_TEXT_TYPE_NONE;
2027 type = NOTIFICATION_TEXT_TYPE_INFO_SUB_1;
2030 type = NOTIFICATION_TEXT_TYPE_INFO_SUB_2;
2033 type = NOTIFICATION_TEXT_TYPE_INFO_SUB_3;
2036 type = NOTIFICATION_TEXT_TYPE_NONE;
2039 if ( type != NOTIFICATION_TEXT_TYPE_NONE)
2041 bool isNull = false;
2042 if (getSubInformation(idx, isNull).compare(subInfo))
2044 if (notification_set_text(m_notiHandle, type, subInfo.c_str(),
2045 NULL, NOTIFICATION_VARIABLE_TYPE_NONE) != NOTIFICATION_ERROR_NONE)
2047 throw UnknownException("set notification sound error");
2049 setUpdatedFlag(true);
2055 LoggerW("noti Handle is NULL");
2056 throw UnknownException("notification handle is null");