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 //tern "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 std::string notiContent;
502 notiContent = content;
503 LoggerI(" get Content : " << content);
511 throw UnknownException("notification handle is null");
516 char* StatusNotification::getStrContent()
518 LoggerI("get Content handle: " << m_notiHandle);
521 char *content = NULL;
523 if (notification_get_text(m_notiHandle, NOTIFICATION_TEXT_TYPE_CONTENT, &content) != NOTIFICATION_ERROR_NONE)
525 throw UnknownException("get notification Content error");
532 throw UnknownException("notification handle is null");
536 void StatusNotification::setContent(std::string content)
538 LoggerI("Content : " << content);
541 if((getContent()).compare(content)) //different value.
543 if (notification_set_text(m_notiHandle, NOTIFICATION_TEXT_TYPE_CONTENT, content.c_str(),
544 NULL, NOTIFICATION_VARIABLE_TYPE_NONE ) != NOTIFICATION_ERROR_NONE)
546 throw UnknownException("set notification content error");
548 setUpdatedFlag(true);
553 LoggerD("noti Handle is NULL");
554 throw UnknownException("notification handle is null");
558 std::string StatusNotification::getIconPath()
561 LoggerI("m_notiHandle = " << m_notiHandle);
564 char *iconPath = NULL;
565 if (notification_get_image(m_notiHandle, NOTIFICATION_IMAGE_TYPE_ICON, &iconPath) != NOTIFICATION_ERROR_NONE)
567 throw UnknownException("get notification icon path error");
570 std::string notiIconPath(iconPath);
571 LoggerI("icon Path = " << iconPath);
573 //if icon path invalid, return empty string.
574 if ( notiIconPath.find(DEFAULT_ICON_PATH,0) == std::string::npos)
578 return std::string(""); //return empty string.
583 throw UnknownException("notification handle is null");
587 void StatusNotification::setIconPath(const std::string& iconPath)
591 LoggerI("icon path = " << iconPath << " origin icon path = " << getIconPath());
592 if( getIconPath().compare(iconPath))
594 if (notification_set_image(m_notiHandle,NOTIFICATION_IMAGE_TYPE_ICON, iconPath.c_str()) != NOTIFICATION_ERROR_NONE)
596 throw UnknownException("set notification icon error");
598 setUpdatedFlag(true);
603 LoggerD("noti Handle is NULL");
604 throw UnknownException("notification handle is null");
608 std::string StatusNotification::getSoundPath()
610 LoggerI("Handle = " << m_notiHandle);
614 const char *soundPath = NULL;
615 notification_sound_type_e type = NOTIFICATION_SOUND_TYPE_NONE;
617 if (notification_get_sound(m_notiHandle, &type, &soundPath) != NOTIFICATION_ERROR_NONE)
619 throw UnknownException("get notification sound error");
622 LoggerI(" sound type = " << type << " path = " << soundPath);
623 if ( type == NOTIFICATION_SOUND_TYPE_USER_DATA )
625 LoggerI("soundPath = " << soundPath);
626 return std::string(soundPath);
630 return std::string("");
635 LoggerD("noti Handle is NULL");
636 throw UnknownException("notification handle is null");
640 void StatusNotification::setSoundPath(const std::string& sound)
644 LoggerI("sound path = " << sound << " origin sound path = " << getSoundPath());
646 if( getSoundPath().compare(sound))
648 if (notification_set_sound(m_notiHandle,NOTIFICATION_SOUND_TYPE_USER_DATA, sound.c_str()) != NOTIFICATION_ERROR_NONE)
650 throw UnknownException("set notification sound error");
652 setUpdatedFlag(true);
657 LoggerI("sound path is NULL");
658 if ( NOTI_TYPE_ONGOING == getNotiType() || NOTI_TYPE_PROGRESS == getNotiType())
660 LoggerI("Ongoing Type" );
661 if (notification_set_sound(m_notiHandle,NOTIFICATION_SOUND_TYPE_NONE, NULL) != NOTIFICATION_ERROR_NONE)
663 throw UnknownException("set notification sound error");
668 if (notification_set_sound(m_notiHandle,NOTIFICATION_SOUND_TYPE_DEFAULT, sound.c_str()) != NOTIFICATION_ERROR_NONE)
670 throw UnknownException("set notification sound error");
678 LoggerD("noti Handle is NULL");
679 throw UnknownException("notification handle is null");
683 bool StatusNotification::getDefaultVibration()
685 LoggerI("getDefaultVibration");
688 notification_vibration_type_e vib_type;
689 if (notification_get_vibration(m_notiHandle, &vib_type, NULL) != NOTIFICATION_ERROR_NONE)
691 throw UnknownException("set notification sound error");
694 if (NOTIFICATION_VIBRATION_TYPE_DEFAULT == vib_type || NOTIFICATION_VIBRATION_TYPE_USER_DATA == vib_type)
705 LoggerD("noti Handle is NULL");
706 throw UnknownException("notification handle is null");
712 void StatusNotification::setDefaultVibration(const bool& vibration)
714 LoggerI("vibration = " << vibration);
717 notification_vibration_type_e vib_type = NOTIFICATION_VIBRATION_TYPE_NONE;
718 LoggerI("old vibration = " << getDefaultVibration());
719 if (getDefaultVibration() != vibration)
723 vib_type = NOTIFICATION_VIBRATION_TYPE_DEFAULT;
727 vib_type = NOTIFICATION_VIBRATION_TYPE_NONE;
729 LoggerI("type vibration type= " << vib_type);
731 if (notification_set_vibration(m_notiHandle, vib_type , NULL) != NOTIFICATION_ERROR_NONE)
733 throw UnknownException("set notification sound error");
735 setUpdatedFlag(true);
740 LoggerD("noti Handle is NULL");
741 throw UnknownException("notification handle is null");
746 DeviceAPI::Application::ApplicationControlPtr StatusNotification::getApplicationControl()
749 service_h service = NULL;
750 char *tempStr = NULL;
752 DeviceAPI::Application::ApplicationControlPtr appControl(new DeviceAPI::Application::ApplicationControl());
757 appControl->setService_h(m_service);
759 if(service_get_operation(m_service, &tempStr) == SERVICE_ERROR_NONE)
761 LoggerD("Operation Str = " << tempStr);
764 appControl->setOperation(tempStr);
771 if (service_get_mime(m_service, &tempStr) == SERVICE_ERROR_NONE)
773 LoggerD("Mime Str = " << tempStr);
776 appControl->setMime(tempStr);
783 if (service_get_uri(m_service, &tempStr) == SERVICE_ERROR_NONE)
785 LoggerD("Uri Str = " << tempStr);
788 appControl->setUri(tempStr);
794 if (service_get_category(m_service, &tempStr) == SERVICE_ERROR_NONE)
796 LoggerD("Category Str = " << tempStr);
799 appControl->setCategory(tempStr);
806 if ( service_foreach_extra_data(m_service, service_extra_data_cb,(void*)&appControl) != SERVICE_ERROR_NONE)
808 ThrowMsg(WrtDeviceApis::Commons::UnknownException, "get notification service uri error");
815 Catch (WrtDeviceApis::Commons::Exception)
829 LoggerW(_rethrown_exception.GetMessage());
835 void StatusNotification::setApplicationControl(DeviceAPI::Application::ApplicationControlPtr control)
837 LoggerI("Entered m_service : " << m_service << " control : " << control);
839 //delete old service.
842 service_destroy(m_service);
846 if(service_create(&m_service) != SERVICE_ERROR_NONE)
848 throw UnknownException("service creation error");
852 LoggerI("getOperation : " << control->getOperation().c_str());
853 if (control->getOperation().size() != 0)
855 m_launchFlag = true; //default attribute
856 if (service_set_operation(m_service, control->getOperation().c_str()) != SERVICE_ERROR_NONE)
858 throw UnknownException("service set operation error");
863 LoggerI("getUri : " << control->getUri().c_str());
864 if (control->getUri().size() != 0)
866 if (service_set_uri(m_service, control->getUri().c_str() ) != SERVICE_ERROR_NONE)
868 throw UnknownException("service set uri error");
873 LoggerI("getMime : " << control->getMime().c_str());
874 if (control->getMime().size() != 0)
876 if (service_set_mime(m_service, control->getMime().c_str() ) != SERVICE_ERROR_NONE)
878 throw UnknownException("service set mime error");
882 LoggerI("Category : " << control->getCategory().c_str());
883 if (control->getCategory().size() != 0)
885 if (service_set_category(m_service, control->getCategory().c_str() ) != SERVICE_ERROR_NONE)
887 throw UnknownException("service set mime error");
892 if ( service_foreach_extra_data(m_service, service_extra_data_delete_cb, NULL) != SERVICE_ERROR_NONE)
894 throw UnknownException("get notification service uri error");
897 std::vector<DeviceAPI::Application::ApplicationControlDataPtr> appControlDataArray = control->getAppControlDataArray();
900 LoggerI (" App Control Datas Count : " << appControlDataArray.size());
902 DeviceAPI::Application::ApplicationControlDataArray::iterator iter;
904 for(iter = appControlDataArray.begin(); iter != appControlDataArray.end(); iter++)
906 DeviceAPI::Application::ApplicationControlDataPtr appControlData = *iter;
907 std::string key = appControlData->getKey();
908 LoggerI(" key : " << key);
913 std::vector<std::string> value = appControlDataArray[index]->getValue();
914 const char **arrayValue = (const char**)calloc(sizeof(char*), value.size());
916 for (size_t indexArray = 0; indexArray < value.size(); indexArray++)
918 arrayValue[indexArray] = (char*)value[indexArray].c_str();
919 LoggerI( " value : " << arrayValue[indexArray]);
922 const char* strKey = key.c_str();
923 LoggerI( " value size: " << value.size());
924 if (service_add_extra_data_array(m_service, strKey, arrayValue, value.size()) != SERVICE_ERROR_NONE)
926 throw UnknownException("service set extra data error");
934 bundle *bundle_data=NULL;
936 if(service_to_bundle(m_service, &bundle_data) != SERVICE_ERROR_NONE)
938 throw UnknownException("service get bundle");
941 LoggerD("bundle_data : " << bundle_data);
945 notification_set_execute_option(m_notiHandle, NOTIFICATION_EXECUTE_TYPE_SINGLE_LAUNCH,
946 NULL,NULL, bundle_data);
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");
971 if (service_set_app_id(m_service, appId.c_str())!= SERVICE_ERROR_NONE)
973 throw UnknownException("service set appId error");
980 std::string StatusNotification::getApplicationId()
982 std::string retString;
983 service_h service = NULL;
984 char* appIdStr = NULL;
986 if (m_service != NULL)
989 retcode = service_clone(&service, m_service);
991 if (retcode != SERVICE_ERROR_NONE)
993 if (retcode == SERVICE_ERROR_OUT_OF_MEMORY)
995 LoggerW("SERVICE_ERROR_OUT_OF_MEMORY");
999 LoggerW("UI_NOTIFICATION_ERROR_INVALID_PARAMETER");
1001 throw UnknownException ("get notification service error ");
1005 if (service == NULL)
1007 throw UnknownException ("get notification service ok, but service null");
1012 if (service != NULL)
1014 if (service_get_app_id(service, &appIdStr) != SERVICE_ERROR_NONE)
1016 throw UnknownException ("get a appId error");
1019 if (appIdStr != NULL)
1021 retString = appIdStr;
1031 double StatusNotification::getProgressValue()
1037 NotificationProgressType progressType = getProgressType();
1039 if (progressType == NOTI_PROGRESS_TYPE_SIZE)
1041 if (notification_get_size(m_notiHandle, &value) != NOTIFICATION_ERROR_NONE)
1043 throw UnknownException("get notification size error");
1045 LoggerI("Size Val = " << value);
1047 else if ( progressType == NOTI_PROGRESS_TYPE_PERCENTAGE )
1049 if (notification_get_progress(m_notiHandle, &value) != NOTIFICATION_ERROR_NONE)
1051 throw UnknownException("get notification percentage error");
1053 LoggerI("Percentage Val = " << value);
1057 throw UnknownException("get notification progress type error");
1062 LoggerD("noti Handle is NULL");
1064 LoggerI("value = " << value);
1069 void StatusNotification::setProgressValue(const double &progressValue)
1073 NotificationProgressType progressType = getProgressType();
1074 LoggerI("Progress Type : " << progressType);
1076 double val = getProgressValue();
1077 LoggerI("Progress value = " << progressValue << " origin Progress Value =" << val);
1079 if (progressType == NOTI_PROGRESS_TYPE_SIZE)
1081 if (notification_set_size(m_notiHandle, progressValue) != NOTIFICATION_ERROR_NONE)
1083 throw UnknownException("set notification progress size error");
1086 else if ( progressType == NOTI_PROGRESS_TYPE_PERCENTAGE )
1088 if (notification_set_progress(m_notiHandle, progressValue) != NOTIFICATION_ERROR_NONE)
1090 throw UnknownException("set notification percentage error");
1095 throw UnknownException("get notification progress type error");
1100 LoggerD("noti Handle is NULL");
1101 throw UnknownException( "notification handle is null");
1105 std::string StatusNotification::getSubIconPath()
1107 LoggerI("Handle = " << m_notiHandle);
1110 char *subIconPath = NULL;
1112 if (notification_get_image(m_notiHandle, NOTIFICATION_IMAGE_TYPE_ICON_SUB, &subIconPath) != NOTIFICATION_ERROR_NONE)
1114 throw UnknownException("get notification sub icon error");
1117 std::string notiSubIconPath;
1119 notiSubIconPath = subIconPath;
1120 return notiSubIconPath;
1124 throw UnknownException("notification handle is null");
1129 void StatusNotification::setSubIconPath(const std::string& subIconPath)
1133 LoggerI(" subIconPath = " << subIconPath << " origin SubIconPath = " << getSubIconPath());
1135 if( getSubIconPath().compare(subIconPath))
1137 if (notification_set_image(m_notiHandle,NOTIFICATION_IMAGE_TYPE_ICON_SUB, subIconPath.c_str()) != NOTIFICATION_ERROR_NONE)
1139 throw UnknownException("set notification sound error");
1141 setUpdatedFlag(true);
1146 LoggerD("noti Handle is NULL");
1147 throw UnknownException("notification handle is null");
1152 std::string StatusNotification::getInformation(int index)
1156 notification_text_type_e type = NOTIFICATION_TEXT_TYPE_NONE;
1160 type = NOTIFICATION_TEXT_TYPE_INFO_1;
1163 type = NOTIFICATION_TEXT_TYPE_INFO_2;
1166 type = NOTIFICATION_TEXT_TYPE_INFO_3;
1169 type = NOTIFICATION_TEXT_TYPE_NONE;
1173 if (NOTIFICATION_TEXT_TYPE_NONE != type && notification_get_text(m_notiHandle, type, &info) != NOTIFICATION_ERROR_NONE)
1175 throw UnknownException("get notification information error");
1178 std::string strInfo;
1181 LoggerD(" info " << strInfo);
1187 LoggerD("noti Handle is NULL");
1188 throw UnknownException("notification handle is null");
1193 void StatusNotification::setInformation( const std::string& info, int index)
1199 LoggerD(" index : " << idx);
1200 LoggerD(" log : " << info);
1201 notification_text_type_e type = NOTIFICATION_TEXT_TYPE_NONE;
1206 type = NOTIFICATION_TEXT_TYPE_INFO_1;
1209 type = NOTIFICATION_TEXT_TYPE_INFO_2;
1212 type = NOTIFICATION_TEXT_TYPE_INFO_3;
1215 type = NOTIFICATION_TEXT_TYPE_NONE;
1218 if ( type != NOTIFICATION_TEXT_TYPE_NONE)
1220 if (getInformation(idx).compare(info))
1222 if (notification_set_text(m_notiHandle, type, info.c_str(),
1223 NULL, NOTIFICATION_VARIABLE_TYPE_NONE) != NOTIFICATION_ERROR_NONE)
1225 throw UnknownException("set notification sound error");
1227 setUpdatedFlag(true);
1233 LoggerD("noti Handle is NULL");
1234 throw UnknownException("notification handle is null");
1238 std::string StatusNotification::getSubInformation(int index)
1243 notification_text_type_e type = NOTIFICATION_TEXT_TYPE_NONE;
1247 type = NOTIFICATION_TEXT_TYPE_INFO_SUB_1;
1250 type = NOTIFICATION_TEXT_TYPE_INFO_SUB_2;
1253 type = NOTIFICATION_TEXT_TYPE_INFO_SUB_3;
1256 type = NOTIFICATION_TEXT_TYPE_NONE;
1259 char *subInfo = NULL;
1261 if (NOTIFICATION_TEXT_TYPE_NONE != type && notification_get_text(m_notiHandle, type, &subInfo) != NOTIFICATION_ERROR_NONE)
1263 throw UnknownException( "get notification sub information error");
1266 std::string strSubInfo;
1268 strSubInfo = subInfo;
1269 LoggerD(" subInfo " << strSubInfo);
1275 LoggerD("noti Handle is NULL");
1276 throw UnknownException( "notification handle is null");
1281 void StatusNotification::setSubInformation( const std::string& subInfo, int index)
1286 LoggerD(" index : " << idx);
1287 LoggerD(" log : " << subInfo);
1288 notification_text_type_e type = NOTIFICATION_TEXT_TYPE_NONE;
1293 type = NOTIFICATION_TEXT_TYPE_INFO_SUB_1;
1296 type = NOTIFICATION_TEXT_TYPE_INFO_SUB_2;
1299 type = NOTIFICATION_TEXT_TYPE_INFO_SUB_3;
1302 type = NOTIFICATION_TEXT_TYPE_NONE;
1305 if ( type != NOTIFICATION_TEXT_TYPE_NONE)
1307 if (getSubInformation(idx).compare(subInfo))
1309 if (notification_set_text(m_notiHandle, type, subInfo.c_str(),
1310 NULL, NOTIFICATION_VARIABLE_TYPE_NONE) != NOTIFICATION_ERROR_NONE)
1312 throw UnknownException( "set notification sound error");
1314 setUpdatedFlag(true);
1320 LoggerD("noti Handle is NULL");
1321 throw UnknownException( "notification handle is null");
1327 void StatusNotification::loadThumbnails()
1331 if (!m_thumbs.empty())
1335 if (notification_get_image(m_notiHandle, NOTIFICATION_IMAGE_TYPE_LIST_1, &thumb) != NOTIFICATION_ERROR_NONE)
1337 throw UnknownException( "get notification thumbnail error");
1340 m_thumbs.push_back(thumb);
1342 // m_thumbs.push_back(std::string("")); //set empty
1345 if (notification_get_image(m_notiHandle, NOTIFICATION_IMAGE_TYPE_LIST_2, &thumb) != NOTIFICATION_ERROR_NONE)
1347 throw UnknownException( "get notification sub information error");
1350 m_thumbs.push_back(thumb);
1352 // m_thumbs.push_back(std::string("")); //set empty
1355 if (notification_get_image(m_notiHandle, NOTIFICATION_IMAGE_TYPE_LIST_3, &thumb) != NOTIFICATION_ERROR_NONE)
1357 throw UnknownException( "get notification sub information error");
1361 m_thumbs.push_back(thumb);
1363 // m_thumbs.push_back(std::string("")); //set empty
1366 if (notification_get_image(m_notiHandle, NOTIFICATION_IMAGE_TYPE_LIST_4, &thumb) != NOTIFICATION_ERROR_NONE)
1368 throw UnknownException( "get notification sub information error");
1372 m_thumbs.push_back(thumb);
1374 // m_thumbs.push_back(std::string("")); //set empty
1377 if (notification_get_image(m_notiHandle, NOTIFICATION_IMAGE_TYPE_LIST_5, &thumb) != NOTIFICATION_ERROR_NONE)
1379 throw UnknownException( "get notification sub information error");
1383 m_thumbs.push_back(thumb);
1385 m_thumbs.push_back(std::string("")); //set empty
1392 LoggerD("noti Handle is NULL");
1393 throw UnknownException( "notification handle is null");
1397 std::vector<std::string> StatusNotification::getThumbnails()
1399 LoggerI(" thumbnail Size : " << m_thumbs.size());
1403 std::string StatusNotification::getThumbnail(int index)
1407 LoggerI(" index : " << index);
1409 notification_image_type_e type = NOTIFICATION_IMAGE_TYPE_NONE;
1414 type = NOTIFICATION_IMAGE_TYPE_LIST_1;
1417 type = NOTIFICATION_IMAGE_TYPE_LIST_2;
1420 type = NOTIFICATION_IMAGE_TYPE_LIST_3;
1423 type = NOTIFICATION_IMAGE_TYPE_LIST_4;
1426 type = NOTIFICATION_IMAGE_TYPE_LIST_5;
1429 type = NOTIFICATION_IMAGE_TYPE_NONE;
1432 if ( type != NOTIFICATION_IMAGE_TYPE_NONE)
1435 if (notification_get_image(m_notiHandle, type, &thumb) != NOTIFICATION_ERROR_NONE)
1437 throw UnknownException( "set notification thumbnail error");
1440 std::string thumbnail;
1447 throw UnknownException( "notification handle is null");
1453 LoggerD("noti Handle is NULL");
1454 throw UnknownException( "notification handle is null");
1457 if (m_thumbs.size() > index)
1458 return m_thumbs[index];
1460 return std::string("");
1465 void StatusNotification::setThumbnails(std::vector<std::string> thumbs)
1467 LoggerI("set thumbnails");
1470 std::vector<std::string>::iterator it;
1473 for (it = thumbs.begin(); it < thumbs.end(); ++it)
1475 std::string str = *it;
1476 if ( idx < MAX_THUMBNAIL_LENGTH )
1477 setThumbnail(str, idx); //set notification's thumbnail value.
1485 LoggerD("noti Handle is NULL");
1486 throw UnknownException( "notification handle is null");
1490 void StatusNotification::setThumbnail( const std::string& thumb, int index)
1494 LoggerI(" index : " << index);
1495 LoggerI(" thumb : " << thumb);
1496 notification_image_type_e type = NOTIFICATION_IMAGE_TYPE_NONE;
1501 type = NOTIFICATION_IMAGE_TYPE_LIST_1;
1504 type = NOTIFICATION_IMAGE_TYPE_LIST_2;
1507 type = NOTIFICATION_IMAGE_TYPE_LIST_3;
1510 type = NOTIFICATION_IMAGE_TYPE_LIST_4;
1513 type = NOTIFICATION_IMAGE_TYPE_LIST_5;
1516 type = NOTIFICATION_IMAGE_TYPE_NONE;
1519 if ( type != NOTIFICATION_IMAGE_TYPE_NONE)
1521 if (getThumbnail(index).compare(thumb))
1523 if (notification_set_image(m_notiHandle, type, thumb.c_str()) != NOTIFICATION_ERROR_NONE)
1525 throw UnknownException( "set notification thumbnail error");
1527 setUpdatedFlag(true);
1533 std::string StatusNotification::getBackground()
1535 LoggerI(" Handle : " << m_notiHandle);
1539 char *background = NULL;
1541 if (notification_get_image(m_notiHandle, NOTIFICATION_IMAGE_TYPE_BACKGROUND, &background) != NOTIFICATION_ERROR_NONE)
1543 throw UnknownException( "get notification background error");
1546 std::string notiBackground;
1548 notiBackground = background;
1549 return notiBackground;
1553 LoggerD("noti Handle is NULL");
1554 throw UnknownException( "notification handle is null");
1559 void StatusNotification::setBackground(const std::string imagePath)
1561 LoggerI(" imagePath : " << imagePath);
1564 if (getBackground().compare(imagePath))
1566 if (notification_set_image(m_notiHandle,NOTIFICATION_IMAGE_TYPE_BACKGROUND, imagePath.c_str()) != NOTIFICATION_ERROR_NONE)
1568 throw UnknownException( "set notification sound error");
1570 setUpdatedFlag(true);
1575 LoggerD("noti Handle is NULL");
1576 throw UnknownException( "notification handle is null");
1580 long StatusNotification::getNumber()
1582 LoggerI("Handle = " << m_notiHandle);
1586 char *strNumber = NULL;
1588 if (notification_get_text(m_notiHandle, NOTIFICATION_TEXT_TYPE_EVENT_COUNT, &strNumber) != NOTIFICATION_ERROR_NONE)
1590 throw UnknownException( "get notification background error");
1594 std::istringstream(strNumber) >> number;
1596 LoggerI("Number Is NULL");
1598 LoggerI("number = " << number);
1604 LoggerD("noti Handle is NULL");
1609 const char* StatusNotification::getStrNumber()
1611 LoggerI("Handle = " << m_notiHandle);
1614 char *strNumber = NULL;
1616 if (notification_get_text(m_notiHandle, NOTIFICATION_TEXT_TYPE_EVENT_COUNT, &strNumber) != NOTIFICATION_ERROR_NONE)
1618 throw UnknownException( "get notification background error");
1630 LoggerD("noti Handle is NULL");
1635 void StatusNotification::setNumber(const long number)
1637 LoggerI("Number = " << number);
1640 if(number!=getNumber())
1642 std::stringstream stream;
1644 if (stream.fail()) {
1645 throw UnknownException(
1646 "Couldn't convert notification number");
1649 std::string strNumber = stream.str();
1650 if (notification_set_text(m_notiHandle, NOTIFICATION_TEXT_TYPE_EVENT_COUNT, strNumber.c_str(),
1651 NULL, NOTIFICATION_VARIABLE_TYPE_NONE) != NOTIFICATION_ERROR_NONE)
1653 throw UnknownException( "set notification text error");
1655 setUpdatedFlag(true);
1660 LoggerD("noti Handle is NULL");
1661 throw UnknownException( "notification handle is null");
1665 void* StatusNotification::getNotificationHandle()
1667 return m_notiHandle;
1670 void StatusNotification::setNotificationHandle(void *handle)
1674 throw UnknownException( "notification handle null error");
1676 LoggerI("handle = " << handle << " m_notiHandle = " << m_notiHandle);
1678 if (m_notiHandle != NULL)
1681 if ( notification_delete(m_notiHandle) != NOTIFICATION_ERROR_NONE)
1683 throw UnknownException( "notification delete error");
1685 m_notiHandle = NULL;
1688 m_notiHandle = (notification_h)handle;
1691 service_h StatusNotification::getService()
1698 void StatusNotification::loadDetailInfos()
1700 LoggerI("noti Handle = " << m_notiHandle);
1704 for ( int idx = 0; idx < MAX_NOTIFICATION_DETAIL_INFO_LENGTH; idx++)
1706 std::string main = getInformation(idx);
1707 std::string sub = getSubInformation(idx);
1708 LoggerI("Main : " << main << " Sub : " << sub);
1709 NotificationDetailInfo *info = new NotificationDetailInfo(m_notiHandle, idx, main, sub);
1710 m_detailInfos.push_back(info);
1715 LoggerD("noti Handle is NULL");
1716 throw UnknownException( "notification handle is null");
1721 std::vector<NotificationDetailInfo*> StatusNotification::getDetailInfos() const
1723 return m_detailInfos;
1726 void StatusNotification::setDetailInfos(const std::vector<NotificationDetailInfo*> value)
1728 LoggerI("DetailInfos = " << value.size());
1732 std::vector<NotificationDetailInfo*>::const_iterator it;
1735 for (it = value.begin(); it < value.end(); ++it)
1737 NotificationDetailInfo* info = *it;
1738 if ( idx < MAX_NOTIFICATION_DETAIL_INFO_LENGTH )
1740 LoggerI("main " << info->getMainText() << " sub " << info->getSubText() );
1741 setInformation(info->getMainText(), idx);
1742 setSubInformation(info->getSubText(), idx);
1747 m_detailInfos = value;
1751 LoggerD("noti Handle is NULL");
1752 throw UnknownException( "notification handle is null");
1757 int StatusNotification::getDetailInfosNum() const
1759 return m_detailInfos.size();
1762 void StatusNotification::clearDetailInfos()
1764 if ( !m_detailInfos.empty() )
1766 std::vector<NotificationDetailInfo*>::const_iterator it;
1769 for (it = m_detailInfos.begin(); it < m_detailInfos.end(); ++it)
1771 NotificationDetailInfo* info = *it;
1772 LoggerI("Delete Detail Info : " << info);
1777 m_detailInfos.clear(); //clear
1781 std::string StatusNotification::getInformation(int index)
1785 notification_text_type_e type = NOTIFICATION_TEXT_TYPE_NONE;
1789 type = NOTIFICATION_TEXT_TYPE_INFO_1;
1792 type = NOTIFICATION_TEXT_TYPE_INFO_2;
1795 type = NOTIFICATION_TEXT_TYPE_INFO_3;
1798 type = NOTIFICATION_TEXT_TYPE_NONE;
1802 if (NOTIFICATION_TEXT_TYPE_NONE != type && notification_get_text(m_notiHandle, type, &info) != NOTIFICATION_ERROR_NONE)
1804 throw UnknownException("Detail Info index value is invalid or mainText value getting is failed in Detail Info.");
1807 std::string strInfo;
1810 LoggerI(" info " << strInfo);
1816 LoggerW("noti Handle is NULL");
1817 throw UnknownException( "notification handle is null");
1822 std::string StatusNotification::getSubInformation(int index)
1826 notification_text_type_e type = NOTIFICATION_TEXT_TYPE_NONE;
1830 type = NOTIFICATION_TEXT_TYPE_INFO_SUB_1;
1833 type = NOTIFICATION_TEXT_TYPE_INFO_SUB_2;
1836 type = NOTIFICATION_TEXT_TYPE_INFO_SUB_3;
1839 type = NOTIFICATION_TEXT_TYPE_NONE;
1842 char *subInfo = NULL;
1844 if (NOTIFICATION_TEXT_TYPE_NONE != type && notification_get_text(m_notiHandle, type, &subInfo) != NOTIFICATION_ERROR_NONE)
1846 throw UnknownException("Detail Info index value is invalid or subText value getting is failed in Detail Info.");
1849 std::string strSubInfo;
1851 strSubInfo = subInfo;
1852 LoggerI(" subInfo " << strSubInfo);
1858 LoggerW("noti Handle is NULL");
1859 throw UnknownException ("notification handle is null");
1864 void StatusNotification::setInformation( const std::string& info, int index)
1869 LoggerD(" index : " << idx);
1870 LoggerD(" log : " << info);
1871 notification_text_type_e type = NOTIFICATION_TEXT_TYPE_NONE;
1876 type = NOTIFICATION_TEXT_TYPE_INFO_1;
1879 type = NOTIFICATION_TEXT_TYPE_INFO_2;
1882 type = NOTIFICATION_TEXT_TYPE_INFO_3;
1885 type = NOTIFICATION_TEXT_TYPE_NONE;
1888 if ( type != NOTIFICATION_TEXT_TYPE_NONE)
1890 if (getInformation(idx).compare(info))
1892 if (notification_set_text(m_notiHandle, type, info.c_str(),
1893 NULL, NOTIFICATION_VARIABLE_TYPE_NONE) != NOTIFICATION_ERROR_NONE)
1895 throw UnknownException("set notification sound error");
1897 setUpdatedFlag(true);
1902 LoggerW("noti Handle is NULL");
1903 throw UnknownException("notification handle is null");
1908 LoggerW("noti Handle is NULL");
1909 throw UnknownException("notification handle is null");
1913 void StatusNotification::setSubInformation( const std::string& subInfo, int index)
1919 LoggerD(" index : " << idx);
1920 LoggerD(" log : " << subInfo);
1921 notification_text_type_e type = NOTIFICATION_TEXT_TYPE_NONE;
1926 type = NOTIFICATION_TEXT_TYPE_INFO_SUB_1;
1929 type = NOTIFICATION_TEXT_TYPE_INFO_SUB_2;
1932 type = NOTIFICATION_TEXT_TYPE_INFO_SUB_3;
1935 type = NOTIFICATION_TEXT_TYPE_NONE;
1938 if ( type != NOTIFICATION_TEXT_TYPE_NONE)
1940 if (getSubInformation(idx).compare(subInfo))
1942 if (notification_set_text(m_notiHandle, type, subInfo.c_str(),
1943 NULL, NOTIFICATION_VARIABLE_TYPE_NONE) != NOTIFICATION_ERROR_NONE)
1945 throw UnknownException("set notification sound error");
1947 setUpdatedFlag(true);
1953 LoggerW("noti Handle is NULL");
1954 throw UnknownException("notification handle is null");
1961 StatusNotification::StatusNotification():
1966 m_backgroundImagePath(""),
1974 StatusNotification::~StatusNotification()
1978 std::string StatusNotification::getStatusType() const
1980 return m_statusType;
1983 void StatusNotification::setStatusType(std::string statusType)
1985 m_statusType = statusType;
1988 std::string StatusNotification::getIconPath() const
1993 void StatusNotification::setIconPath(std::string iconPath)
1995 m_iconPath = iconPath;
1998 std::string StatusNotification::getSubIconPath() const
2000 return m_subIconPath;
2003 void StatusNotification::setSubIconPath(std::string subIconPath)
2005 m_subIconPath = subIconPath;
2008 long StatusNotification::getNumber() const
2013 void StatusNotification::setNumber(long number)
2018 std::vector<NotificationDetailInfo*> StatusNotification::getDetailInfo() const
2020 return m_detailInfo;
2023 void StatusNotification::setDetailInfo(std::vector<NotificationDetailInfo*> detailInfo)
2025 m_detailInfo = detailInfo;
2028 std::string StatusNotification::getBackgroundImagePath() const
2030 return m_backgroundImagePath;
2033 void StatusNotification::setBackgroundImagePath(std::string backgroundImagePath)
2035 m_backgroundImagePath = backgroundImagePath;
2038 std::vector<std::string> StatusNotification::getThumbnails() const
2040 return m_thumbnails;
2043 void StatusNotification::setThumbnails(std::vector<std::string> thumbnails)
2045 m_thumbnails = thumbnails;
2048 std::string StatusNotification::getSoundPath() const
2053 void StatusNotification::setSoundPath(std::string soundPath)
2055 m_soundPath = soundPath;
2058 bool StatusNotification::getVibration() const
2063 void StatusNotification::setVibration(bool vibration)
2065 m_vibration = vibration;
2068 ApplicationControl StatusNotification::getAppControl() const
2070 return m_appControl;
2073 void StatusNotification::setAppControl(ApplicationControl appControl)
2075 m_appControl = appControl;
2078 ApplicationId StatusNotification::getAppId() const
2083 void StatusNotification::setAppId(ApplicationId appId)
2088 std::string StatusNotification::getProgressType() const
2090 return m_progressType;
2093 void StatusNotification::setProgressType(std::string progressType)
2095 m_progressType = progressType;
2098 unsigned long StatusNotification::getProgressValue() const
2100 return m_progressValue;
2103 void StatusNotification::setProgressValue(unsigned long progressValue)
2105 m_progressValue = progressValue;