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>
23 #include "StatusNotification.h"
26 namespace Notification {
28 #define DEFAULT_ICON_PATH "/opt/share/icons/default/"
29 #define MAX_NOTIFICATION_DETAIL_INFO_LENGTH 2
30 #define MAX_THUMBNAIL_LENGTH 4
32 extern "C" int service_create_event(bundle *data, struct service_s **service);
33 extern "C" int service_to_bundle(service_h service, bundle **data);
36 static bool service_extra_data_cb(service_h service, const char *key, void *user_data)
42 if (user_data != NULL && key != NULL)
44 LoggerI("user data & key is existed");
46 DeviceAPI::Application::ApplicationControlPtr* appControl =
47 (DeviceAPI::Application::ApplicationControlPtr*)(user_data);
49 DeviceAPI::Application::ApplicationControlDataPtr data(new DeviceAPI::Application::ApplicationControlData());
50 LoggerI("key = " << key);
51 std::string keyStr = key;
52 std::vector<std::string> keyValue;
55 if (service_get_extra_data_array((*appControl)->getService_h(), key, &value, &length) == SERVICE_ERROR_NONE)
57 LoggerI("extra_data_array length = " << length);
59 if (value != NULL && length != 0)
61 LoggerI("extra_data_length = " << length);
63 for (index = 0; index < length; index++)
65 LoggerI("Value=" << value[index]);
66 keyValue.push_back(value[index]);
69 data->setValue(keyValue);
70 (*appControl)->addAppControlData(data);
81 static bool service_extra_data_delete_cb(service_h service, const char *key, void *user_data)
86 LoggerI("del key = " << key);
88 if (service_remove_extra_data(service, key) != SERVICE_ERROR_NONE)
90 LoggerW("remove extra data failed");
98 StatusNotification::StatusNotification(NotificationType statusType) :
99 m_notiType(NOTI_TYPE_NONE),
102 m_progressType(NOTI_PROGRESS_TYPE_PERCENTAGE),
103 m_notiUpdated(false),
106 LoggerI("statusType =" << statusType);
108 notification_type_e type = NOTIFICATION_TYPE_NONE;
109 setNotiType(statusType);
111 if (statusType == NOTI_TYPE_SIMPLE || statusType == NOTI_TYPE_MUTIPLE || statusType == NOTI_TYPE_THUMBNAIL)
113 type = NOTIFICATION_TYPE_NOTI;
115 else if ( statusType == NOTI_TYPE_ONGOING || statusType == NOTI_TYPE_PROGRESS)
117 type = NOTIFICATION_TYPE_ONGOING;
121 LoggerI(" invalide noti type");
122 throw TypeMismatchException("value is not notification type");
125 setProgressType(NOTI_PROGRESS_TYPE_PERCENTAGE); //default
127 LoggerI("Notification Type : " << type);
129 notification_h noti = notification_create(type); //create notificatin.
132 LoggerI("noti =" << noti);
133 setNotificationHandle((void*)noti);
135 if (NOTIFICATION_TYPE_ONGOING == type)
136 { //ongoing no ticker.
137 LoggerI("ongoing type");
138 notification_set_display_applist(noti, NOTIFICATION_DISPLAY_APP_NOTIFICATION_TRAY |NOTIFICATION_DISPLAY_APP_INDICATOR );
143 throw UnknownException("can't make new notification object");
146 //m_detailInfos = new std::vector<NotificationDetailInfo*>();
147 //m_thumbs = new std::vector<std::string>();
151 StatusNotification::StatusNotification(void* noti) :
152 m_notiType(NOTI_TYPE_NONE),
155 m_progressType(NOTI_PROGRESS_TYPE_PERCENTAGE),
156 m_notiUpdated(false),
159 LoggerI("noti : " << noti);
161 notification_h notification = (notification_h)noti;
165 NotificationType type = NOTI_TYPE_NONE;
166 notification_type_e noti_type = NOTIFICATION_TYPE_NONE;
167 notification_ly_type_e noti_layout = NOTIFICATION_LY_NONE;
169 notification_get_type(notification, ¬i_type);
170 notification_get_layout(notification, ¬i_layout);
173 if ( noti_type == NOTIFICATION_TYPE_NOTI )
175 if ( noti_layout == NOTIFICATION_LY_NOTI_EVENT_SINGLE ||
176 noti_layout == NOTIFICATION_LY_NOTI_EVENT_MULTIPLE )
178 type = NOTI_TYPE_SIMPLE;
180 else if (noti_layout == NOTIFICATION_LY_NOTI_THUMBNAIL)
182 type = NOTI_TYPE_THUMBNAIL;
185 else if ( noti_type == NOTIFICATION_TYPE_ONGOING)
187 if ( noti_layout == NOTIFICATION_LY_ONGOING_EVENT )
189 type = NOTI_TYPE_ONGOING;
191 else if ( noti_layout == NOTIFICATION_LY_ONGOING_PROGRESS)
193 type = NOTI_TYPE_PROGRESS;
197 LoggerI(" notification type =" << type);
199 setProgressType(NOTI_PROGRESS_TYPE_PERCENTAGE); //default.
201 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 setNotificationHandle((void*)notification);
296 if ( type == NOTI_TYPE_PROGRESS)
298 notification_update_progress(notification, NOTIFICATION_PRIV_ID_NONE, getProgressValue());
304 int ret = notification_get_execute_option(notification, NOTIFICATION_EXECUTE_TYPE_SINGLE_LAUNCH, NULL, &bSvc);
305 LoggerI("ret = " << ret);
306 if (ret == NOTIFICATION_ERROR_NONE)
308 LoggerI(" bundle = " << bSvc);
311 LoggerI("bundle is valid");
312 int ret = service_create_event(bSvc, &m_service);
313 if (ret != SERVICE_ERROR_NONE)
315 LoggerI("Service Create Event Error");
316 throw UnknownException("can't make service object");
322 notification_free(notification);
323 throw UnknownException("can't get service data");
329 throw NotFoundException("It is not notification ID or removed notification");
334 StatusNotification::~StatusNotification()
336 LoggerI(" notification = " << m_notiHandle);
339 //clearDetailInfos();
344 LoggerI(" service = " << m_service);
345 if (m_service != NULL)
347 service_destroy(m_service);
351 if (notification_free(m_notiHandle) != NOTIFICATION_ERROR_NONE)
353 throw UnknownException("notification free failed...");
360 int StatusNotification::getID()
362 int id = -1; // notification not inserted yet.
365 notification_get_id(m_notiHandle, NULL, &id);
371 std::string StatusNotification::getStatusType()
375 if ( NOTI_TYPE_SIMPLE == getNotiType())
379 else if ( NOTI_TYPE_ONGOING == getNotiType())
383 else if ( NOTI_TYPE_PROGRESS == getNotiType())
387 else if ( NOTI_TYPE_THUMBNAIL == getNotiType())
398 void StatusNotification::setStatusType(std::string type)
400 LoggerI("type = " << type);
402 NotificationType notiType = NOTI_TYPE_NONE;
404 if( type.compare(TIZEN_STATUS_NOTIFICATION_TYPE_SIMPLE) == 0)
405 notiType = NOTI_TYPE_SIMPLE;
406 else if( type.compare(TIZEN_STATUS_NOTIFICATION_TYPE_THUMBNAIL) == 0)
407 notiType = NOTI_TYPE_THUMBNAIL;
408 else if( type.compare(TIZEN_STATUS_NOTIFICATION_TYPE_ONGOING) == 0)
409 notiType = NOTI_TYPE_ONGOING;
410 else if( type.compare(TIZEN_STATUS_NOTIFICATION_TYPE_PROGRESS) == 0)
411 notiType = NOTI_TYPE_PROGRESS;
413 throw InvalidValuesException("Invalid Status Type.");
415 LoggerI("Notification type = " << notiType);
416 setNotiType(notiType);
419 time_t StatusNotification::getPostedTime()
421 LoggerI("get m_notiHandle = " << m_notiHandle);
423 time_t postedTime = 0;
427 if (notification_get_insert_time(m_notiHandle, &postedTime) != NOTIFICATION_ERROR_NONE)
429 throw UnknownException("get notification posted time error");
433 LoggerI("posted Time =" << ctime(&postedTime));
437 std::string StatusNotification::getTitle()
443 if (notification_get_text(m_notiHandle,NOTIFICATION_TEXT_TYPE_TITLE, &title) != NOTIFICATION_ERROR_NONE)
445 throw UnknownException("get notification title error");
448 std::string notiTitle(title);
453 throw UnknownException("notification handle is null");
457 void StatusNotification::setTitle(std::string title)
459 LoggerI("Title : " << title);
462 LoggerI("get Title : " << getTitle());
463 if((getTitle()).compare(title)) //different value.
465 if (notification_set_text(m_notiHandle, NOTIFICATION_TEXT_TYPE_TITLE, title.c_str(),
466 NULL, NOTIFICATION_VARIABLE_TYPE_NONE ) != NOTIFICATION_ERROR_NONE)
468 throw UnknownException("set notification title error");
471 setUpdatedFlag(true);
475 LoggerI(" title = " << title << " getTitle = " << getTitle());
480 LoggerD("noti Handle is NULL");
481 throw UnknownException("notification handle is null");
486 std::string StatusNotification::getContent()
488 LoggerI("get Content handle: " << m_notiHandle);
491 char *content = NULL;
493 if (notification_get_text(m_notiHandle, NOTIFICATION_TEXT_TYPE_CONTENT, &content) != NOTIFICATION_ERROR_NONE)
495 throw UnknownException("get notification Content error");
498 LoggerI(" get Content : " << content);
500 std::string notiContent;
503 notiContent = content;
510 throw UnknownException("notification handle is null");
515 char* StatusNotification::getStrContent()
517 LoggerI("get Content handle: " << m_notiHandle);
520 char *content = NULL;
522 if (notification_get_text(m_notiHandle, NOTIFICATION_TEXT_TYPE_CONTENT, &content) != NOTIFICATION_ERROR_NONE)
524 throw UnknownException("get notification Content error");
531 throw UnknownException("notification handle is null");
535 void StatusNotification::setContent(std::string content)
537 LoggerI("Content : " << content);
540 if((getContent()).compare(content)) //different value.
542 if (notification_set_text(m_notiHandle, NOTIFICATION_TEXT_TYPE_CONTENT, content.c_str(),
543 NULL, NOTIFICATION_VARIABLE_TYPE_NONE ) != NOTIFICATION_ERROR_NONE)
545 throw UnknownException("set notification content error");
547 setUpdatedFlag(true);
552 LoggerD("noti Handle is NULL");
553 throw UnknownException("notification handle is null");
557 std::string StatusNotification::getIconPath()
560 LoggerI("m_notiHandle = " << m_notiHandle);
563 char *iconPath = NULL;
564 if (notification_get_image(m_notiHandle, NOTIFICATION_IMAGE_TYPE_ICON, &iconPath) != NOTIFICATION_ERROR_NONE)
566 throw UnknownException("get notification icon path error");
569 std::string notiIconPath(iconPath);
570 LoggerI("icon Path = " << iconPath);
572 //if icon path invalid, return empty string.
573 if ( notiIconPath.find(DEFAULT_ICON_PATH,0) == std::string::npos)
577 return std::string(""); //return empty string.
582 throw UnknownException("notification handle is null");
586 void StatusNotification::setIconPath(const std::string& iconPath)
590 LoggerI("icon path = " << iconPath << " origin icon path = " << getIconPath());
591 if( getIconPath().compare(iconPath))
593 if (notification_set_image(m_notiHandle,NOTIFICATION_IMAGE_TYPE_ICON, iconPath.c_str()) != NOTIFICATION_ERROR_NONE)
595 throw UnknownException("set notification icon error");
597 setUpdatedFlag(true);
602 LoggerD("noti Handle is NULL");
603 throw UnknownException("notification handle is null");
607 std::string StatusNotification::getSoundPath()
609 LoggerI("Handle = " << m_notiHandle);
613 const char *soundPath = NULL;
614 notification_sound_type_e type = NOTIFICATION_SOUND_TYPE_NONE;
616 if (notification_get_sound(m_notiHandle, &type, &soundPath) != NOTIFICATION_ERROR_NONE)
618 throw UnknownException("get notification sound error");
621 LoggerI(" sound type = " << type << " path = " << soundPath);
622 if ( type == NOTIFICATION_SOUND_TYPE_USER_DATA )
624 LoggerI("soundPath = " << soundPath);
625 return std::string(soundPath);
629 return std::string("");
634 LoggerD("noti Handle is NULL");
635 throw UnknownException("notification handle is null");
639 void StatusNotification::setSoundPath(const std::string& sound)
643 LoggerI("sound path = " << sound << " origin sound path = " << getSoundPath());
645 if( getSoundPath().compare(sound))
647 if (notification_set_sound(m_notiHandle,NOTIFICATION_SOUND_TYPE_USER_DATA, sound.c_str()) != NOTIFICATION_ERROR_NONE)
649 throw UnknownException("set notification sound error");
651 setUpdatedFlag(true);
656 LoggerI("sound path is NULL");
657 if ( NOTI_TYPE_ONGOING == getNotiType() || NOTI_TYPE_PROGRESS == getNotiType())
659 LoggerI("Ongoing Type" );
660 if (notification_set_sound(m_notiHandle,NOTIFICATION_SOUND_TYPE_NONE, NULL) != NOTIFICATION_ERROR_NONE)
662 throw UnknownException("set notification sound error");
667 if (notification_set_sound(m_notiHandle,NOTIFICATION_SOUND_TYPE_DEFAULT, sound.c_str()) != NOTIFICATION_ERROR_NONE)
669 throw UnknownException("set notification sound error");
677 LoggerD("noti Handle is NULL");
678 throw UnknownException("notification handle is null");
682 bool StatusNotification::getDefaultVibration()
684 LoggerI("getDefaultVibration");
687 notification_vibration_type_e vib_type;
688 if (notification_get_vibration(m_notiHandle, &vib_type, NULL) != NOTIFICATION_ERROR_NONE)
690 throw UnknownException("set notification sound error");
693 if (NOTIFICATION_VIBRATION_TYPE_DEFAULT == vib_type || NOTIFICATION_VIBRATION_TYPE_USER_DATA == vib_type)
704 LoggerD("noti Handle is NULL");
705 throw UnknownException("notification handle is null");
711 void StatusNotification::setDefaultVibration(const bool& vibration)
713 LoggerI("vibration = " << vibration);
716 notification_vibration_type_e vib_type = NOTIFICATION_VIBRATION_TYPE_NONE;
717 LoggerI("old vibration = " << getDefaultVibration());
718 if (getDefaultVibration() != vibration)
722 vib_type = NOTIFICATION_VIBRATION_TYPE_DEFAULT;
726 vib_type = NOTIFICATION_VIBRATION_TYPE_NONE;
728 LoggerI("type vibration type= " << vib_type);
730 if (notification_set_vibration(m_notiHandle, vib_type , NULL) != NOTIFICATION_ERROR_NONE)
732 throw UnknownException("set notification sound error");
734 setUpdatedFlag(true);
739 LoggerD("noti Handle is NULL");
740 throw UnknownException("notification handle is null");
745 DeviceAPI::Application::ApplicationControlPtr StatusNotification::getApplicationControl()
748 service_h service = NULL;
749 char *tempStr = NULL;
751 DeviceAPI::Application::ApplicationControlPtr appControl(new DeviceAPI::Application::ApplicationControl());
756 appControl->setService_h(m_service);
758 if(service_get_operation(m_service, &tempStr) == SERVICE_ERROR_NONE)
760 LoggerD("Operation Str = " << tempStr);
763 appControl->setOperation(tempStr);
770 if (service_get_mime(m_service, &tempStr) == SERVICE_ERROR_NONE)
772 LoggerD("Mime Str = " << tempStr);
775 appControl->setMime(tempStr);
782 if (service_get_uri(m_service, &tempStr) == SERVICE_ERROR_NONE)
784 LoggerD("Uri Str = " << tempStr);
787 appControl->setUri(tempStr);
793 if (service_get_category(m_service, &tempStr) == SERVICE_ERROR_NONE)
795 LoggerD("Category Str = " << tempStr);
798 appControl->setCategory(tempStr);
805 if ( service_foreach_extra_data(m_service, service_extra_data_cb,(void*)&appControl) != SERVICE_ERROR_NONE)
807 ThrowMsg(WrtDeviceApis::Commons::UnknownException, "get notification service uri error");
814 Catch (WrtDeviceApis::Commons::Exception)
828 LoggerW(_rethrown_exception.GetMessage());
834 void StatusNotification::setApplicationControl(DeviceAPI::Application::ApplicationControlPtr control)
836 LoggerI("Entered m_service : " << m_service << " control : " << control);
838 //delete old service.
841 service_destroy(m_service);
845 if(service_create(&m_service) != SERVICE_ERROR_NONE)
847 throw UnknownException("service creation error");
851 LoggerI("getOperation : " << control->getOperation().c_str());
852 if (control->getOperation().size() != 0)
854 m_launchFlag = true; //default attribute
855 if (service_set_operation(m_service, control->getOperation().c_str()) != SERVICE_ERROR_NONE)
857 throw UnknownException("service set operation error");
862 LoggerI("getUri : " << control->getUri().c_str());
863 if (control->getUri().size() != 0)
865 if (service_set_uri(m_service, control->getUri().c_str() ) != SERVICE_ERROR_NONE)
867 throw UnknownException("service set uri error");
872 LoggerI("getMime : " << control->getMime().c_str());
873 if (control->getMime().size() != 0)
875 if (service_set_mime(m_service, control->getMime().c_str() ) != SERVICE_ERROR_NONE)
877 throw UnknownException("service set mime error");
881 LoggerI("Category : " << control->getCategory().c_str());
882 if (control->getCategory().size() != 0)
884 if (service_set_category(m_service, control->getCategory().c_str() ) != SERVICE_ERROR_NONE)
886 throw UnknownException("service set mime error");
891 if ( service_foreach_extra_data(m_service, service_extra_data_delete_cb, NULL) != SERVICE_ERROR_NONE)
893 throw UnknownException("get notification service uri error");
896 std::vector<DeviceAPI::Application::ApplicationControlDataPtr> appControlDataArray = control->getAppControlDataArray();
899 LoggerI (" App Control Datas Count : " << appControlDataArray.size());
901 DeviceAPI::Application::ApplicationControlDataArray::iterator iter;
903 for(iter = appControlDataArray.begin(); iter != appControlDataArray.end(); iter++)
905 DeviceAPI::Application::ApplicationControlDataPtr appControlData = *iter;
906 std::string key = appControlData->getKey();
907 LoggerI(" key : " << key);
912 std::vector<std::string> value = appControlDataArray[index]->getValue();
913 const char **arrayValue = (const char**)calloc(sizeof(char*), value.size());
915 for (size_t indexArray = 0; indexArray < value.size(); indexArray++)
917 arrayValue[indexArray] = (char*)value[indexArray].c_str();
918 LoggerI( " value : " << arrayValue[indexArray]);
921 const char* strKey = key.c_str();
922 LoggerI( " value size: " << value.size());
923 if (service_add_extra_data_array(m_service, strKey, arrayValue, value.size()) != SERVICE_ERROR_NONE)
925 throw UnknownException("service set extra data error");
932 bundle *bundle_data=NULL;
934 if(service_to_bundle(m_service, &bundle_data) != SERVICE_ERROR_NONE)
936 throw UnknownException("service get bundle");
939 LoggerD("bundle_data : " << bundle_data);
943 notification_set_execute_option(m_notiHandle, NOTIFICATION_EXECUTE_TYPE_SINGLE_LAUNCH,
944 NULL,NULL, bundle_data);
951 void StatusNotification::setApplicationId(const std::string& appId)
953 LoggerI("m_service = " << m_service << " appId = " << appId);
956 if (service_create(&m_service) != SERVICE_ERROR_NONE)
958 LoggerW("Create Service Failed..");
959 throw UnknownException("service creation error");
968 if (service_set_app_id(m_service, appId.c_str())!= SERVICE_ERROR_NONE)
970 throw UnknownException("service set appId error");
977 std::string StatusNotification::getApplicationId()
979 std::string retString;
980 service_h service = NULL;
981 char* appIdStr = NULL;
983 if (m_service != NULL)
986 retcode = service_clone(&service, m_service);
988 if (retcode != SERVICE_ERROR_NONE)
990 if (retcode == SERVICE_ERROR_OUT_OF_MEMORY)
992 LoggerW("SERVICE_ERROR_OUT_OF_MEMORY");
996 LoggerW("UI_NOTIFICATION_ERROR_INVALID_PARAMETER");
998 throw UnknownException ("get notification service error ");
1002 if (service == NULL)
1004 throw UnknownException ("get notification service ok, but service null");
1009 if (service != NULL)
1011 if (service_get_app_id(service, &appIdStr) != SERVICE_ERROR_NONE)
1013 throw UnknownException ("get a appId error");
1016 if (appIdStr != NULL)
1018 retString = appIdStr;
1028 double StatusNotification::getProgressValue()
1034 NotificationProgressType progressType = getProgressType();
1036 if (progressType == NOTI_PROGRESS_TYPE_SIZE)
1038 if (notification_get_size(m_notiHandle, &value) != NOTIFICATION_ERROR_NONE)
1040 throw UnknownException("get notification size error");
1042 LoggerI("Size Val = " << value);
1044 else if ( progressType == NOTI_PROGRESS_TYPE_PERCENTAGE )
1046 if (notification_get_progress(m_notiHandle, &value) != NOTIFICATION_ERROR_NONE)
1048 throw UnknownException("get notification percentage error");
1050 LoggerI("Percentage Val = " << value);
1054 throw UnknownException("get notification progress type error");
1059 LoggerD("noti Handle is NULL");
1061 LoggerI("value = " << value);
1066 void StatusNotification::setProgressValue(const double &progressValue)
1070 NotificationProgressType progressType = getProgressType();
1071 LoggerI("Progress Type : " << progressType);
1073 double val = getProgressValue();
1074 LoggerI("Progress value = " << progressValue << " origin Progress Value =" << val);
1076 if (progressType == NOTI_PROGRESS_TYPE_SIZE)
1078 if (notification_set_size(m_notiHandle, progressValue) != NOTIFICATION_ERROR_NONE)
1080 throw UnknownException("set notification progress size error");
1083 else if ( progressType == NOTI_PROGRESS_TYPE_PERCENTAGE )
1085 if (notification_set_progress(m_notiHandle, progressValue) != NOTIFICATION_ERROR_NONE)
1087 throw UnknownException("set notification percentage error");
1092 throw UnknownException("get notification progress type error");
1097 LoggerD("noti Handle is NULL");
1098 throw UnknownException( "notification handle is null");
1102 std::string StatusNotification::getSubIconPath()
1104 LoggerI("Handle = " << m_notiHandle);
1107 char *subIconPath = NULL;
1109 if (notification_get_image(m_notiHandle, NOTIFICATION_IMAGE_TYPE_ICON_SUB, &subIconPath) != NOTIFICATION_ERROR_NONE)
1111 throw UnknownException("get notification sub icon error");
1114 std::string notiSubIconPath;
1116 notiSubIconPath = subIconPath;
1117 return notiSubIconPath;
1121 throw UnknownException("notification handle is null");
1126 void StatusNotification::setSubIconPath(const std::string& subIconPath)
1130 LoggerI(" subIconPath = " << subIconPath << " origin SubIconPath = " << getSubIconPath());
1132 if( getSubIconPath().compare(subIconPath))
1134 if (notification_set_image(m_notiHandle,NOTIFICATION_IMAGE_TYPE_ICON_SUB, subIconPath.c_str()) != NOTIFICATION_ERROR_NONE)
1136 throw UnknownException("set notification sound error");
1138 setUpdatedFlag(true);
1143 LoggerD("noti Handle is NULL");
1144 throw UnknownException("notification handle is null");
1149 std::string StatusNotification::getInformation(int index)
1153 notification_text_type_e type = NOTIFICATION_TEXT_TYPE_NONE;
1157 type = NOTIFICATION_TEXT_TYPE_INFO_1;
1160 type = NOTIFICATION_TEXT_TYPE_INFO_2;
1163 type = NOTIFICATION_TEXT_TYPE_INFO_3;
1166 type = NOTIFICATION_TEXT_TYPE_NONE;
1170 if (NOTIFICATION_TEXT_TYPE_NONE != type && notification_get_text(m_notiHandle, type, &info) != NOTIFICATION_ERROR_NONE)
1172 throw UnknownException("get notification information error");
1175 std::string strInfo;
1178 LoggerD(" info " << strInfo);
1184 LoggerD("noti Handle is NULL");
1185 throw UnknownException("notification handle is null");
1190 void StatusNotification::setInformation( const std::string& info, int index)
1196 LoggerD(" index : " << idx);
1197 LoggerD(" log : " << info);
1198 notification_text_type_e type = NOTIFICATION_TEXT_TYPE_NONE;
1203 type = NOTIFICATION_TEXT_TYPE_INFO_1;
1206 type = NOTIFICATION_TEXT_TYPE_INFO_2;
1209 type = NOTIFICATION_TEXT_TYPE_INFO_3;
1212 type = NOTIFICATION_TEXT_TYPE_NONE;
1215 if ( type != NOTIFICATION_TEXT_TYPE_NONE)
1217 if (getInformation(idx).compare(info))
1219 if (notification_set_text(m_notiHandle, type, info.c_str(),
1220 NULL, NOTIFICATION_VARIABLE_TYPE_NONE) != NOTIFICATION_ERROR_NONE)
1222 throw UnknownException("set notification sound error");
1224 setUpdatedFlag(true);
1230 LoggerD("noti Handle is NULL");
1231 throw UnknownException("notification handle is null");
1235 std::string StatusNotification::getSubInformation(int index)
1240 notification_text_type_e type = NOTIFICATION_TEXT_TYPE_NONE;
1244 type = NOTIFICATION_TEXT_TYPE_INFO_SUB_1;
1247 type = NOTIFICATION_TEXT_TYPE_INFO_SUB_2;
1250 type = NOTIFICATION_TEXT_TYPE_INFO_SUB_3;
1253 type = NOTIFICATION_TEXT_TYPE_NONE;
1256 char *subInfo = NULL;
1258 if (NOTIFICATION_TEXT_TYPE_NONE != type && notification_get_text(m_notiHandle, type, &subInfo) != NOTIFICATION_ERROR_NONE)
1260 throw UnknownException( "get notification sub information error");
1263 std::string strSubInfo;
1265 strSubInfo = subInfo;
1266 LoggerD(" subInfo " << strSubInfo);
1272 LoggerD("noti Handle is NULL");
1273 throw UnknownException( "notification handle is null");
1278 void StatusNotification::setSubInformation( const std::string& subInfo, int index)
1283 LoggerD(" index : " << idx);
1284 LoggerD(" log : " << subInfo);
1285 notification_text_type_e type = NOTIFICATION_TEXT_TYPE_NONE;
1290 type = NOTIFICATION_TEXT_TYPE_INFO_SUB_1;
1293 type = NOTIFICATION_TEXT_TYPE_INFO_SUB_2;
1296 type = NOTIFICATION_TEXT_TYPE_INFO_SUB_3;
1299 type = NOTIFICATION_TEXT_TYPE_NONE;
1302 if ( type != NOTIFICATION_TEXT_TYPE_NONE)
1304 if (getSubInformation(idx).compare(subInfo))
1306 if (notification_set_text(m_notiHandle, type, subInfo.c_str(),
1307 NULL, NOTIFICATION_VARIABLE_TYPE_NONE) != NOTIFICATION_ERROR_NONE)
1309 throw UnknownException( "set notification sound error");
1311 setUpdatedFlag(true);
1317 LoggerD("noti Handle is NULL");
1318 throw UnknownException( "notification handle is null");
1324 void StatusNotification::loadThumbnails()
1328 if (!m_thumbs.empty())
1332 if (notification_get_image(m_notiHandle, NOTIFICATION_IMAGE_TYPE_LIST_1, &thumb) != NOTIFICATION_ERROR_NONE)
1334 throw UnknownException( "get notification thumbnail error");
1337 m_thumbs.push_back(thumb);
1339 // m_thumbs.push_back(std::string("")); //set empty
1342 if (notification_get_image(m_notiHandle, NOTIFICATION_IMAGE_TYPE_LIST_2, &thumb) != NOTIFICATION_ERROR_NONE)
1344 throw UnknownException( "get notification sub information error");
1347 m_thumbs.push_back(thumb);
1349 // m_thumbs.push_back(std::string("")); //set empty
1352 if (notification_get_image(m_notiHandle, NOTIFICATION_IMAGE_TYPE_LIST_3, &thumb) != NOTIFICATION_ERROR_NONE)
1354 throw UnknownException( "get notification sub information error");
1358 m_thumbs.push_back(thumb);
1360 // m_thumbs.push_back(std::string("")); //set empty
1363 if (notification_get_image(m_notiHandle, NOTIFICATION_IMAGE_TYPE_LIST_4, &thumb) != NOTIFICATION_ERROR_NONE)
1365 throw UnknownException( "get notification sub information error");
1369 m_thumbs.push_back(thumb);
1371 // m_thumbs.push_back(std::string("")); //set empty
1374 if (notification_get_image(m_notiHandle, NOTIFICATION_IMAGE_TYPE_LIST_5, &thumb) != NOTIFICATION_ERROR_NONE)
1376 throw UnknownException( "get notification sub information error");
1380 m_thumbs.push_back(thumb);
1382 m_thumbs.push_back(std::string("")); //set empty
1389 LoggerD("noti Handle is NULL");
1390 throw UnknownException( "notification handle is null");
1394 std::vector<std::string> StatusNotification::getThumbnails()
1396 LoggerI(" thumbnail Size : " << m_thumbs.size());
1400 std::string StatusNotification::getThumbnail(int index)
1404 LoggerI(" index : " << index);
1406 notification_image_type_e type = NOTIFICATION_IMAGE_TYPE_NONE;
1411 type = NOTIFICATION_IMAGE_TYPE_LIST_1;
1414 type = NOTIFICATION_IMAGE_TYPE_LIST_2;
1417 type = NOTIFICATION_IMAGE_TYPE_LIST_3;
1420 type = NOTIFICATION_IMAGE_TYPE_LIST_4;
1423 type = NOTIFICATION_IMAGE_TYPE_LIST_5;
1426 type = NOTIFICATION_IMAGE_TYPE_NONE;
1429 if ( type != NOTIFICATION_IMAGE_TYPE_NONE)
1432 if (notification_get_image(m_notiHandle, type, &thumb) != NOTIFICATION_ERROR_NONE)
1434 throw UnknownException( "set notification thumbnail error");
1437 std::string thumbnail;
1444 throw UnknownException( "notification handle is null");
1450 LoggerD("noti Handle is NULL");
1451 throw UnknownException( "notification handle is null");
1454 if (m_thumbs.size() > index)
1455 return m_thumbs[index];
1457 return std::string("");
1462 void StatusNotification::setThumbnails(std::vector<std::string> thumbs)
1464 LoggerI("set thumbnails");
1467 std::vector<std::string>::iterator it;
1470 for (it = thumbs.begin(); it < thumbs.end(); ++it)
1472 std::string str = *it;
1473 if ( idx < MAX_THUMBNAIL_LENGTH )
1474 setThumbnail(str, idx); //set notification's thumbnail value.
1482 LoggerD("noti Handle is NULL");
1483 throw UnknownException( "notification handle is null");
1487 void StatusNotification::setThumbnail( const std::string& thumb, int index)
1491 LoggerI(" index : " << index);
1492 LoggerI(" thumb : " << thumb);
1493 notification_image_type_e type = NOTIFICATION_IMAGE_TYPE_NONE;
1498 type = NOTIFICATION_IMAGE_TYPE_LIST_1;
1501 type = NOTIFICATION_IMAGE_TYPE_LIST_2;
1504 type = NOTIFICATION_IMAGE_TYPE_LIST_3;
1507 type = NOTIFICATION_IMAGE_TYPE_LIST_4;
1510 type = NOTIFICATION_IMAGE_TYPE_LIST_5;
1513 type = NOTIFICATION_IMAGE_TYPE_NONE;
1516 if ( type != NOTIFICATION_IMAGE_TYPE_NONE)
1518 if (getThumbnail(index).compare(thumb))
1520 if (notification_set_image(m_notiHandle, type, thumb.c_str()) != NOTIFICATION_ERROR_NONE)
1522 throw UnknownException( "set notification thumbnail error");
1524 setUpdatedFlag(true);
1530 std::string StatusNotification::getBackground()
1532 LoggerI(" Handle : " << m_notiHandle);
1536 char *background = NULL;
1538 if (notification_get_image(m_notiHandle, NOTIFICATION_IMAGE_TYPE_BACKGROUND, &background) != NOTIFICATION_ERROR_NONE)
1540 throw UnknownException( "get notification background error");
1543 std::string notiBackground;
1545 notiBackground = background;
1546 return notiBackground;
1550 LoggerD("noti Handle is NULL");
1551 throw UnknownException( "notification handle is null");
1556 void StatusNotification::setBackground(const std::string imagePath)
1558 LoggerI(" imagePath : " << imagePath);
1561 if (getBackground().compare(imagePath))
1563 if (notification_set_image(m_notiHandle,NOTIFICATION_IMAGE_TYPE_BACKGROUND, imagePath.c_str()) != NOTIFICATION_ERROR_NONE)
1565 throw UnknownException( "set notification sound error");
1567 setUpdatedFlag(true);
1572 LoggerD("noti Handle is NULL");
1573 throw UnknownException( "notification handle is null");
1577 long StatusNotification::getNumber()
1579 LoggerI("Handle = " << m_notiHandle);
1583 char *strNumber = NULL;
1585 if (notification_get_text(m_notiHandle, NOTIFICATION_TEXT_TYPE_EVENT_COUNT, &strNumber) != NOTIFICATION_ERROR_NONE)
1587 throw UnknownException( "get notification background error");
1591 std::istringstream(strNumber) >> number;
1593 LoggerI("Number Is NULL");
1595 LoggerI("number = " << number);
1601 LoggerD("noti Handle is NULL");
1606 const char* StatusNotification::getStrNumber()
1608 LoggerI("Handle = " << m_notiHandle);
1611 char *strNumber = NULL;
1613 if (notification_get_text(m_notiHandle, NOTIFICATION_TEXT_TYPE_EVENT_COUNT, &strNumber) != NOTIFICATION_ERROR_NONE)
1615 throw UnknownException( "get notification background error");
1627 LoggerD("noti Handle is NULL");
1632 void StatusNotification::setNumber(const long number)
1634 LoggerI("Number = " << number);
1637 if(number!=getNumber())
1639 std::stringstream stream;
1641 if (stream.fail()) {
1642 throw UnknownException(
1643 "Couldn't convert notification number");
1646 std::string strNumber = stream.str();
1647 if (notification_set_text(m_notiHandle, NOTIFICATION_TEXT_TYPE_EVENT_COUNT, strNumber.c_str(),
1648 NULL, NOTIFICATION_VARIABLE_TYPE_NONE) != NOTIFICATION_ERROR_NONE)
1650 throw UnknownException( "set notification text error");
1652 setUpdatedFlag(true);
1657 LoggerD("noti Handle is NULL");
1658 throw UnknownException( "notification handle is null");
1662 void* StatusNotification::getNotificationHandle()
1664 return m_notiHandle;
1667 void StatusNotification::setNotificationHandle(void *handle)
1671 throw UnknownException( "notification handle null error");
1673 LoggerI("handle = " << handle << " m_notiHandle = " << m_notiHandle);
1675 if (m_notiHandle != NULL)
1678 if ( notification_delete(m_notiHandle) != NOTIFICATION_ERROR_NONE)
1680 throw UnknownException( "notification delete error");
1682 m_notiHandle = NULL;
1685 m_notiHandle = (notification_h)handle;
1688 service_h StatusNotification::getService()
1695 void StatusNotification::loadDetailInfos()
1697 LoggerI("noti Handle = " << m_notiHandle);
1701 for ( int idx = 0; idx < MAX_NOTIFICATION_DETAIL_INFO_LENGTH; idx++)
1703 std::string main = getInformation(idx);
1704 std::string sub = getSubInformation(idx);
1705 LoggerI("Main : " << main << " Sub : " << sub);
1706 NotificationDetailInfo *info = new NotificationDetailInfo(m_notiHandle, idx, main, sub);
1707 m_detailInfos.push_back(info);
1712 LoggerD("noti Handle is NULL");
1713 throw UnknownException( "notification handle is null");
1718 std::vector<NotificationDetailInfo*> StatusNotification::getDetailInfos() const
1720 return m_detailInfos;
1723 void StatusNotification::setDetailInfos(const std::vector<NotificationDetailInfo*> value)
1725 LoggerI("DetailInfos = " << value.size());
1729 std::vector<NotificationDetailInfo*>::const_iterator it;
1732 for (it = value.begin(); it < value.end(); ++it)
1734 NotificationDetailInfo* info = *it;
1735 if ( idx < MAX_NOTIFICATION_DETAIL_INFO_LENGTH )
1737 LoggerI("main " << info->getMainText() << " sub " << info->getSubText() );
1738 setInformation(info->getMainText(), idx);
1739 setSubInformation(info->getSubText(), idx);
1744 m_detailInfos = value;
1748 LoggerD("noti Handle is NULL");
1749 throw UnknownException( "notification handle is null");
1754 int StatusNotification::getDetailInfosNum() const
1756 return m_detailInfos.size();
1759 void StatusNotification::clearDetailInfos()
1761 if ( !m_detailInfos.empty() )
1763 std::vector<NotificationDetailInfo*>::const_iterator it;
1766 for (it = m_detailInfos.begin(); it < m_detailInfos.end(); ++it)
1768 NotificationDetailInfo* info = *it;
1769 LoggerI("Delete Detail Info : " << info);
1774 m_detailInfos.clear(); //clear
1778 std::string StatusNotification::getInformation(int index)
1782 notification_text_type_e type = NOTIFICATION_TEXT_TYPE_NONE;
1786 type = NOTIFICATION_TEXT_TYPE_INFO_1;
1789 type = NOTIFICATION_TEXT_TYPE_INFO_2;
1792 type = NOTIFICATION_TEXT_TYPE_INFO_3;
1795 type = NOTIFICATION_TEXT_TYPE_NONE;
1799 if (NOTIFICATION_TEXT_TYPE_NONE != type && notification_get_text(m_notiHandle, type, &info) != NOTIFICATION_ERROR_NONE)
1801 throw UnknownException("Detail Info index value is invalid or mainText value getting is failed in Detail Info.");
1804 std::string strInfo;
1807 LoggerI(" info " << strInfo);
1813 LoggerW("noti Handle is NULL");
1814 throw UnknownException( "notification handle is null");
1819 std::string StatusNotification::getSubInformation(int index)
1823 notification_text_type_e type = NOTIFICATION_TEXT_TYPE_NONE;
1827 type = NOTIFICATION_TEXT_TYPE_INFO_SUB_1;
1830 type = NOTIFICATION_TEXT_TYPE_INFO_SUB_2;
1833 type = NOTIFICATION_TEXT_TYPE_INFO_SUB_3;
1836 type = NOTIFICATION_TEXT_TYPE_NONE;
1839 char *subInfo = NULL;
1841 if (NOTIFICATION_TEXT_TYPE_NONE != type && notification_get_text(m_notiHandle, type, &subInfo) != NOTIFICATION_ERROR_NONE)
1843 throw UnknownException("Detail Info index value is invalid or subText value getting is failed in Detail Info.");
1846 std::string strSubInfo;
1848 strSubInfo = subInfo;
1849 LoggerI(" subInfo " << strSubInfo);
1855 LoggerW("noti Handle is NULL");
1856 throw UnknownException ("notification handle is null");
1861 void StatusNotification::setInformation( const std::string& info, int index)
1866 LoggerD(" index : " << idx);
1867 LoggerD(" log : " << info);
1868 notification_text_type_e type = NOTIFICATION_TEXT_TYPE_NONE;
1873 type = NOTIFICATION_TEXT_TYPE_INFO_1;
1876 type = NOTIFICATION_TEXT_TYPE_INFO_2;
1879 type = NOTIFICATION_TEXT_TYPE_INFO_3;
1882 type = NOTIFICATION_TEXT_TYPE_NONE;
1885 if ( type != NOTIFICATION_TEXT_TYPE_NONE)
1887 if (getInformation(idx).compare(info))
1889 if (notification_set_text(m_notiHandle, type, info.c_str(),
1890 NULL, NOTIFICATION_VARIABLE_TYPE_NONE) != NOTIFICATION_ERROR_NONE)
1892 throw UnknownException("set notification sound error");
1894 setUpdatedFlag(true);
1899 LoggerW("noti Handle is NULL");
1900 throw UnknownException("notification handle is null");
1905 LoggerW("noti Handle is NULL");
1906 throw UnknownException("notification handle is null");
1910 void StatusNotification::setSubInformation( const std::string& subInfo, int index)
1916 LoggerD(" index : " << idx);
1917 LoggerD(" log : " << subInfo);
1918 notification_text_type_e type = NOTIFICATION_TEXT_TYPE_NONE;
1923 type = NOTIFICATION_TEXT_TYPE_INFO_SUB_1;
1926 type = NOTIFICATION_TEXT_TYPE_INFO_SUB_2;
1929 type = NOTIFICATION_TEXT_TYPE_INFO_SUB_3;
1932 type = NOTIFICATION_TEXT_TYPE_NONE;
1935 if ( type != NOTIFICATION_TEXT_TYPE_NONE)
1937 if (getSubInformation(idx).compare(subInfo))
1939 if (notification_set_text(m_notiHandle, type, subInfo.c_str(),
1940 NULL, NOTIFICATION_VARIABLE_TYPE_NONE) != NOTIFICATION_ERROR_NONE)
1942 throw UnknownException("set notification sound error");
1944 setUpdatedFlag(true);
1950 LoggerW("noti Handle is NULL");
1951 throw UnknownException("notification handle is null");
1958 StatusNotification::StatusNotification():
1963 m_backgroundImagePath(""),
1971 StatusNotification::~StatusNotification()
1975 std::string StatusNotification::getStatusType() const
1977 return m_statusType;
1980 void StatusNotification::setStatusType(std::string statusType)
1982 m_statusType = statusType;
1985 std::string StatusNotification::getIconPath() const
1990 void StatusNotification::setIconPath(std::string iconPath)
1992 m_iconPath = iconPath;
1995 std::string StatusNotification::getSubIconPath() const
1997 return m_subIconPath;
2000 void StatusNotification::setSubIconPath(std::string subIconPath)
2002 m_subIconPath = subIconPath;
2005 long StatusNotification::getNumber() const
2010 void StatusNotification::setNumber(long number)
2015 std::vector<NotificationDetailInfo*> StatusNotification::getDetailInfo() const
2017 return m_detailInfo;
2020 void StatusNotification::setDetailInfo(std::vector<NotificationDetailInfo*> detailInfo)
2022 m_detailInfo = detailInfo;
2025 std::string StatusNotification::getBackgroundImagePath() const
2027 return m_backgroundImagePath;
2030 void StatusNotification::setBackgroundImagePath(std::string backgroundImagePath)
2032 m_backgroundImagePath = backgroundImagePath;
2035 std::vector<std::string> StatusNotification::getThumbnails() const
2037 return m_thumbnails;
2040 void StatusNotification::setThumbnails(std::vector<std::string> thumbnails)
2042 m_thumbnails = thumbnails;
2045 std::string StatusNotification::getSoundPath() const
2050 void StatusNotification::setSoundPath(std::string soundPath)
2052 m_soundPath = soundPath;
2055 bool StatusNotification::getVibration() const
2060 void StatusNotification::setVibration(bool vibration)
2062 m_vibration = vibration;
2065 ApplicationControl StatusNotification::getAppControl() const
2067 return m_appControl;
2070 void StatusNotification::setAppControl(ApplicationControl appControl)
2072 m_appControl = appControl;
2075 ApplicationId StatusNotification::getAppId() const
2080 void StatusNotification::setAppId(ApplicationId appId)
2085 std::string StatusNotification::getProgressType() const
2087 return m_progressType;
2090 void StatusNotification::setProgressType(std::string progressType)
2092 m_progressType = progressType;
2095 unsigned long StatusNotification::getProgressValue() const
2097 return m_progressValue;
2100 void StatusNotification::setProgressValue(unsigned long progressValue)
2102 m_progressValue = progressValue;