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 LogInfo("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 LogInfo("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 LogInfo("extra_data_array length = " << length);
59 if (value != NULL && length != 0)
61 LogInfo("extra_data_length = " << length);
63 for (index = 0; index < length; index++)
65 LogInfo("Value=" << value[index]);
66 keyValue.push_back(value[index]);
69 data->setValue(keyValue);
70 (*appControl)->addAppControlData(data);
80 static bool service_extra_data_delete_cb(service_h service, const char *key, void *user_data)
85 LogInfo("del key = " << key);
87 if (service_remove_extra_data(service, key) != SERVICE_ERROR_NONE)
89 LogWarning("remove extra data failed");
96 StatusNotification::StatusNotification(NotificationType statusType) :
97 m_notiType(NOTI_TYPE_NONE),
100 m_progressType(NOTI_PROGRESS_TYPE_PERCENTAGE),
101 m_notiUpdated(false),
104 LogInfo("statusType =" << statusType);
106 notification_type_e type = NOTIFICATION_TYPE_NONE;
107 setNotiType(statusType);
109 if (statusType == NOTI_TYPE_SIMPLE || statusType == NOTI_TYPE_MUTIPLE || statusType == NOTI_TYPE_THUMBNAIL)
111 type = NOTIFICATION_TYPE_NOTI;
113 else if ( statusType == NOTI_TYPE_ONGOING || statusType == NOTI_TYPE_PROGRESS)
115 type = NOTIFICATION_TYPE_ONGOING;
119 LogInfo(" invalide noti type");
120 throw TypeMismatchException("value is not notification type");
123 setProgressType(NOTI_PROGRESS_TYPE_PERCENTAGE); //default
125 LogInfo("Notification Type : " << type);
127 notification_h noti = notification_create(type); //create notificatin.
130 LogInfo("noti =" << noti);
131 setNotificationHandle((void*)noti);
133 if (NOTIFICATION_TYPE_ONGOING == type)
134 { //ongoing no ticker.
135 LogInfo("ongoing type");
136 notification_set_display_applist(noti, NOTIFICATION_DISPLAY_APP_NOTIFICATION_TRAY |NOTIFICATION_DISPLAY_APP_INDICATOR );
141 throw UnknownException("can't make new notification object");
144 //m_detailInfos = new std::vector<NotificationDetailInfo*>();
145 //m_thumbs = new std::vector<std::string>();
149 StatusNotification::StatusNotification(void* noti) :
150 m_notiType(NOTI_TYPE_NONE),
153 m_progressType(NOTI_PROGRESS_TYPE_PERCENTAGE),
154 m_notiUpdated(false),
157 LogInfo("noti : " << noti);
159 notification_h notification = (notification_h)noti;
163 NotificationType type = NOTI_TYPE_NONE;
164 notification_type_e noti_type = NOTIFICATION_TYPE_NONE;
165 notification_ly_type_e noti_layout = NOTIFICATION_LY_NONE;
167 notification_get_type(notification, ¬i_type);
168 notification_get_layout(notification, ¬i_layout);
171 if ( noti_type == NOTIFICATION_TYPE_NOTI )
173 if ( noti_layout == NOTIFICATION_LY_NOTI_EVENT_SINGLE ||
174 noti_layout == NOTIFICATION_LY_NOTI_EVENT_MULTIPLE )
176 type = NOTI_TYPE_SIMPLE;
178 else if (noti_layout == NOTIFICATION_LY_NOTI_THUMBNAIL)
180 type = NOTI_TYPE_THUMBNAIL;
183 else if ( noti_type == NOTIFICATION_TYPE_ONGOING)
185 if ( noti_layout == NOTIFICATION_LY_ONGOING_EVENT )
187 type = NOTI_TYPE_ONGOING;
189 else if ( noti_layout == NOTIFICATION_LY_ONGOING_PROGRESS)
191 type = NOTI_TYPE_PROGRESS;
195 LogInfo(" notification type =" << type);
197 setProgressType(NOTI_PROGRESS_TYPE_PERCENTAGE); //default.
199 setNotificationHandle((void*)notification);
203 if ( type == NOTI_TYPE_PROGRESS)
205 notification_update_progress(notification, NOTIFICATION_PRIV_ID_NONE, getProgressValue());
211 int ret = notification_get_execute_option(notification, NOTIFICATION_EXECUTE_TYPE_SINGLE_LAUNCH, NULL, &bSvc);
212 LogInfo("ret = " << ret);
213 if (ret == NOTIFICATION_ERROR_NONE)
215 LogInfo(" bundle = " << bSvc);
218 LogInfo("bundle is valid");
219 int ret = service_create_event(bSvc, &m_service);
220 if (ret != SERVICE_ERROR_NONE)
222 LogInfo("Service Create Event Error");
223 throw UnknownException("can't make service object");
229 notification_free(notification);
230 throw UnknownException("can't get service data");
236 throw InvalidValuesException("It is not notification object.");
241 StatusNotification::StatusNotification(int privID) :
242 m_notiType(NOTI_TYPE_NONE),
245 m_progressType(NOTI_PROGRESS_TYPE_PERCENTAGE),
246 m_notiUpdated(false),
249 LogInfo("priv ID : " << privID);
251 notification_h notification = notification_load( NULL, privID); //load notification.
252 LogInfo(" notification " << notification);
256 NotificationType type = NOTI_TYPE_NONE;
257 notification_type_e noti_type = NOTIFICATION_TYPE_NONE;
258 notification_ly_type_e noti_layout = NOTIFICATION_LY_NONE;
260 notification_get_type(notification, ¬i_type);
261 notification_get_layout(notification, ¬i_layout);
263 if ( noti_type == NOTIFICATION_TYPE_NOTI )
265 if ( noti_layout == NOTIFICATION_LY_NOTI_EVENT_SINGLE ||
266 noti_layout == NOTIFICATION_LY_NOTI_EVENT_MULTIPLE )
268 type = NOTI_TYPE_SIMPLE;
270 else if (noti_layout == NOTIFICATION_LY_NOTI_THUMBNAIL)
272 type = NOTI_TYPE_THUMBNAIL;
275 else if ( noti_type == NOTIFICATION_TYPE_ONGOING)
277 if ( noti_layout == NOTIFICATION_LY_ONGOING_EVENT )
279 type = NOTI_TYPE_ONGOING;
281 else if ( noti_layout == NOTIFICATION_LY_ONGOING_PROGRESS)
283 type = NOTI_TYPE_PROGRESS;
287 LogInfo(" notification type =" << type);
289 setProgressType(NOTI_PROGRESS_TYPE_PERCENTAGE); //default.
290 setNotificationHandle((void*)notification);
294 if ( type == NOTI_TYPE_PROGRESS)
296 notification_update_progress(notification, NOTIFICATION_PRIV_ID_NONE, getProgressValue());
302 int ret = notification_get_execute_option(notification, NOTIFICATION_EXECUTE_TYPE_SINGLE_LAUNCH, NULL, &bSvc);
303 LogInfo("ret = " << ret);
304 if (ret == NOTIFICATION_ERROR_NONE)
306 LogInfo(" bundle = " << bSvc);
309 LogInfo("bundle is valid");
310 int ret = service_create_event(bSvc, &m_service);
311 if (ret != SERVICE_ERROR_NONE)
313 LogInfo("Service Create Event Error");
314 throw UnknownException("can't make service object");
320 notification_free(notification);
321 throw UnknownException("can't get service data");
327 throw NotFoundException("It is not notification ID or removed notification");
332 StatusNotification::~StatusNotification()
334 LogInfo(" notification = " << m_notiHandle);
337 //clearDetailInfos();
342 LogInfo(" service = " << m_service);
343 if (m_service != NULL)
345 service_destroy(m_service);
349 if (notification_free(m_notiHandle) != NOTIFICATION_ERROR_NONE)
351 throw UnknownException("notification free failed...");
358 int StatusNotification::getID()
360 int id = -1; // notification not inserted yet.
363 notification_get_id(m_notiHandle, NULL, &id);
369 std::string StatusNotification::getStatusType()
373 if ( NOTI_TYPE_SIMPLE == getNotiType())
377 else if ( NOTI_TYPE_ONGOING == getNotiType())
381 else if ( NOTI_TYPE_PROGRESS == getNotiType())
385 else if ( NOTI_TYPE_THUMBNAIL == getNotiType())
396 void StatusNotification::setStatusType(std::string type)
398 LogInfo("type = " << type);
400 NotificationType notiType = NOTI_TYPE_NONE;
402 if( type.compare(TIZEN_STATUS_NOTIFICATION_TYPE_SIMPLE) == 0)
403 notiType = NOTI_TYPE_SIMPLE;
404 else if( type.compare(TIZEN_STATUS_NOTIFICATION_TYPE_THUMBNAIL) == 0)
405 notiType = NOTI_TYPE_THUMBNAIL;
406 else if( type.compare(TIZEN_STATUS_NOTIFICATION_TYPE_ONGOING) == 0)
407 notiType = NOTI_TYPE_ONGOING;
408 else if( type.compare(TIZEN_STATUS_NOTIFICATION_TYPE_PROGRESS) == 0)
409 notiType = NOTI_TYPE_PROGRESS;
411 throw InvalidValuesException("Invalid Status Type.");
413 LogInfo("Notification type = " << notiType);
414 setNotiType(notiType);
417 time_t StatusNotification::getPostedTime()
419 LogInfo("get m_notiHandle = " << m_notiHandle);
421 time_t postedTime = 0;
425 if (notification_get_insert_time(m_notiHandle, &postedTime) != NOTIFICATION_ERROR_NONE)
427 throw UnknownException("get notification posted time error");
431 LogInfo("posted Time =" << ctime(&postedTime));
435 std::string StatusNotification::getTitle()
441 if (notification_get_text(m_notiHandle,NOTIFICATION_TEXT_TYPE_TITLE, &title) != NOTIFICATION_ERROR_NONE)
443 throw UnknownException("get notification title error");
446 std::string notiTitle(title);
451 throw UnknownException("notification handle is null");
455 void StatusNotification::setTitle(std::string title)
457 LogInfo("Title : " << title);
460 LogInfo("get Title : " << getTitle());
461 if((getTitle()).compare(title)) //different value.
463 if (notification_set_text(m_notiHandle, NOTIFICATION_TEXT_TYPE_TITLE, title.c_str(),
464 NULL, NOTIFICATION_VARIABLE_TYPE_NONE ) != NOTIFICATION_ERROR_NONE)
466 throw UnknownException("set notification title error");
469 setUpdatedFlag(true);
473 LogInfo(" title = " << title << " getTitle = " << getTitle());
478 LogDebug("noti Handle is NULL");
479 throw UnknownException("notification handle is null");
484 std::string StatusNotification::getContent()
486 LogInfo("get Content handle: " << m_notiHandle);
489 char *content = NULL;
491 if (notification_get_text(m_notiHandle, NOTIFICATION_TEXT_TYPE_CONTENT, &content) != NOTIFICATION_ERROR_NONE)
493 throw UnknownException("get notification Content error");
496 LogInfo(" get Content : " << content);
498 std::string notiContent;
501 notiContent = content;
508 throw UnknownException("notification handle is null");
513 char* StatusNotification::getStrContent()
515 LogInfo("get Content handle: " << m_notiHandle);
518 char *content = NULL;
520 if (notification_get_text(m_notiHandle, NOTIFICATION_TEXT_TYPE_CONTENT, &content) != NOTIFICATION_ERROR_NONE)
522 throw UnknownException("get notification Content error");
529 throw UnknownException("notification handle is null");
533 void StatusNotification::setContent(std::string content)
535 LogInfo("Content : " << content);
538 if((getContent()).compare(content)) //different value.
540 if (notification_set_text(m_notiHandle, NOTIFICATION_TEXT_TYPE_CONTENT, content.c_str(),
541 NULL, NOTIFICATION_VARIABLE_TYPE_NONE ) != NOTIFICATION_ERROR_NONE)
543 throw UnknownException("set notification content error");
545 setUpdatedFlag(true);
550 LogDebug("noti Handle is NULL");
551 throw UnknownException("notification handle is null");
555 std::string StatusNotification::getIconPath()
558 LogInfo("m_notiHandle = " << m_notiHandle);
561 char *iconPath = NULL;
562 if (notification_get_image(m_notiHandle, NOTIFICATION_IMAGE_TYPE_ICON, &iconPath) != NOTIFICATION_ERROR_NONE)
564 throw UnknownException("get notification icon path error");
567 std::string notiIconPath(iconPath);
568 LogInfo("icon Path = " << iconPath);
570 //if icon path invalid, return empty string.
571 if ( notiIconPath.find(DEFAULT_ICON_PATH,0) == std::string::npos)
575 return std::string(""); //return empty string.
580 throw UnknownException("notification handle is null");
584 void StatusNotification::setIconPath(const std::string& iconPath)
588 LogInfo("icon path = " << iconPath << " origin icon path = " << getIconPath());
589 if( getIconPath().compare(iconPath))
591 if (notification_set_image(m_notiHandle,NOTIFICATION_IMAGE_TYPE_ICON, iconPath.c_str()) != NOTIFICATION_ERROR_NONE)
593 throw UnknownException("set notification icon error");
595 setUpdatedFlag(true);
600 LogDebug("noti Handle is NULL");
601 throw UnknownException("notification handle is null");
605 std::string StatusNotification::getSoundPath()
607 LogInfo("Handle = " << m_notiHandle);
611 const char *soundPath = NULL;
612 notification_sound_type_e type = NOTIFICATION_SOUND_TYPE_NONE;
614 if (notification_get_sound(m_notiHandle, &type, &soundPath) != NOTIFICATION_ERROR_NONE)
616 throw UnknownException("get notification sound error");
619 LogInfo(" sound type = " << type << " path = " << soundPath);
620 if ( type == NOTIFICATION_SOUND_TYPE_USER_DATA )
622 LogInfo("soundPath = " << soundPath);
623 return std::string(soundPath);
627 return std::string("");
632 LogDebug("noti Handle is NULL");
633 throw UnknownException("notification handle is null");
637 void StatusNotification::setSoundPath(const std::string& sound)
641 LogInfo("sound path = " << sound << " origin sound path = " << getSoundPath());
643 if( getSoundPath().compare(sound))
645 if (notification_set_sound(m_notiHandle,NOTIFICATION_SOUND_TYPE_USER_DATA, sound.c_str()) != NOTIFICATION_ERROR_NONE)
647 throw UnknownException("set notification sound error");
649 setUpdatedFlag(true);
654 LogInfo("sound path is NULL");
655 if ( NOTI_TYPE_ONGOING == getNotiType() || NOTI_TYPE_PROGRESS == getNotiType())
657 LogInfo("Ongoing Type" );
658 if (notification_set_sound(m_notiHandle,NOTIFICATION_SOUND_TYPE_NONE, NULL) != NOTIFICATION_ERROR_NONE)
660 throw UnknownException("set notification sound error");
665 if (notification_set_sound(m_notiHandle,NOTIFICATION_SOUND_TYPE_DEFAULT, sound.c_str()) != NOTIFICATION_ERROR_NONE)
667 throw UnknownException("set notification sound error");
675 LogDebug("noti Handle is NULL");
676 throw UnknownException("notification handle is null");
680 bool StatusNotification::getDefaultVibration()
682 LogInfo("getDefaultVibration");
685 notification_vibration_type_e vib_type;
686 if (notification_get_vibration(m_notiHandle, &vib_type, NULL) != NOTIFICATION_ERROR_NONE)
688 throw UnknownException("set notification sound error");
691 if (NOTIFICATION_VIBRATION_TYPE_DEFAULT == vib_type || NOTIFICATION_VIBRATION_TYPE_USER_DATA == vib_type)
702 LogDebug("noti Handle is NULL");
703 throw UnknownException("notification handle is null");
709 void StatusNotification::setDefaultVibration(const bool& vibration)
711 LogInfo("vibration = " << vibration);
714 notification_vibration_type_e vib_type = NOTIFICATION_VIBRATION_TYPE_NONE;
715 LogInfo("old vibration = " << getDefaultVibration());
716 if (getDefaultVibration() != vibration)
720 vib_type = NOTIFICATION_VIBRATION_TYPE_DEFAULT;
724 vib_type = NOTIFICATION_VIBRATION_TYPE_NONE;
726 LogInfo("type vibration type= " << vib_type);
728 if (notification_set_vibration(m_notiHandle, vib_type , NULL) != NOTIFICATION_ERROR_NONE)
730 throw UnknownException("set notification sound error");
732 setUpdatedFlag(true);
737 LogDebug("noti Handle is NULL");
738 throw UnknownException("notification handle is null");
743 DeviceAPI::Application::ApplicationControlPtr StatusNotification::getApplicationControl()
746 service_h service = NULL;
747 char *tempStr = NULL;
749 DeviceAPI::Application::ApplicationControlPtr appControl(new DeviceAPI::Application::ApplicationControl());
754 appControl->setService_h(m_service);
756 if(service_get_operation(m_service, &tempStr) == SERVICE_ERROR_NONE)
758 LogDebug("Operation Str = " << tempStr);
761 appControl->setOperation(tempStr);
768 if (service_get_mime(m_service, &tempStr) == SERVICE_ERROR_NONE)
770 LogDebug("Mime Str = " << tempStr);
773 appControl->setMime(tempStr);
780 if (service_get_uri(m_service, &tempStr) == SERVICE_ERROR_NONE)
782 LogDebug("Uri Str = " << tempStr);
785 appControl->setUri(tempStr);
791 if (service_get_category(m_service, &tempStr) == SERVICE_ERROR_NONE)
793 LogDebug("Category Str = " << tempStr);
796 appControl->setCategory(tempStr);
803 if ( service_foreach_extra_data(m_service, service_extra_data_cb,(void*)&appControl) != SERVICE_ERROR_NONE)
805 ThrowMsg(WrtDeviceApis::Commons::UnknownException, "get notification service uri error");
812 Catch (WrtDeviceApis::Commons::Exception)
826 LogWarning(_rethrown_exception.GetMessage());
832 void StatusNotification::setApplicationControl(DeviceAPI::Application::ApplicationControlPtr control)
834 LogInfo("Entered m_service : " << m_service << " control : " << control);
836 //delete old service.
839 service_destroy(m_service);
843 if(service_create(&m_service) != SERVICE_ERROR_NONE)
845 throw UnknownException("service creation error");
849 LogInfo("getOperation : " << control->getOperation().c_str());
850 if (control->getOperation().size() != 0)
852 m_launchFlag = true; //default attribute
853 if (service_set_operation(m_service, control->getOperation().c_str()) != SERVICE_ERROR_NONE)
855 throw UnknownException("service set operation error");
860 LogInfo("getUri : " << control->getUri().c_str());
861 if (control->getUri().size() != 0)
863 if (service_set_uri(m_service, control->getUri().c_str() ) != SERVICE_ERROR_NONE)
865 throw UnknownException("service set uri error");
870 LogInfo("getMime : " << control->getMime().c_str());
871 if (control->getMime().size() != 0)
873 if (service_set_mime(m_service, control->getMime().c_str() ) != SERVICE_ERROR_NONE)
875 throw UnknownException("service set mime error");
879 LogInfo("Category : " << control->getCategory().c_str());
880 if (control->getCategory().size() != 0)
882 if (service_set_category(m_service, control->getCategory().c_str() ) != SERVICE_ERROR_NONE)
884 throw UnknownException("service set mime error");
889 //if ( service_foreach_extra_data(m_service, service_extra_data_delete_cb, NULL) != SERVICE_ERROR_NONE)
891 // throw UnknownException("get notification service uri error");
894 std::vector<DeviceAPI::Application::ApplicationControlDataPtr> appControlDataArray = control->getAppControlDataArray();
897 LogInfo (" App Control Datas Count : " << appControlDataArray.size());
899 DeviceAPI::Application::ApplicationControlDataArray::iterator iter;
901 for(iter = appControlDataArray.begin(); iter != appControlDataArray.end(); iter++)
903 DeviceAPI::Application::ApplicationControlDataPtr appControlData = *iter;
904 std::string key = appControlData->getKey();
905 LogInfo(" key : " << key);
910 std::vector<std::string> value = appControlDataArray[index]->getValue();
911 const char **arrayValue = (const char**)calloc(sizeof(char*), value.size());
913 for (size_t indexArray = 0; indexArray < value.size(); indexArray++)
915 arrayValue[indexArray] = (char*)value[indexArray].c_str();
916 LogInfo( " value : " << arrayValue[indexArray]);
919 const char* strKey = key.c_str();
920 LogInfo( " value size: " << value.size());
921 if (service_add_extra_data_array(m_service, strKey, arrayValue, value.size()) != SERVICE_ERROR_NONE)
923 throw UnknownException("service set extra data error");
930 bundle *bundle_data=NULL;
932 if(service_to_bundle(m_service, &bundle_data) != SERVICE_ERROR_NONE)
934 throw UnknownException("service get bundle");
937 LogDebug("bundle_data : " << bundle_data);
941 notification_set_execute_option(m_notiHandle, NOTIFICATION_EXECUTE_TYPE_SINGLE_LAUNCH,
942 NULL,NULL, bundle_data);
949 void StatusNotification::setApplicationId(const std::string& appId)
951 LogInfo("m_service = " << m_service << " appId = " << appId);
954 if (service_create(&m_service) != SERVICE_ERROR_NONE)
956 LogWarning("Create Service Failed..");
957 throw UnknownException("service creation error");
966 if (service_set_app_id(m_service, appId.c_str())!= SERVICE_ERROR_NONE)
968 throw UnknownException("service set appId error");
975 std::string StatusNotification::getApplicationId()
977 std::string retString;
978 service_h service = NULL;
979 char* appIdStr = NULL;
981 if (m_service != NULL)
984 retcode = service_clone(&service, m_service);
986 if (retcode != SERVICE_ERROR_NONE)
988 if (retcode == SERVICE_ERROR_OUT_OF_MEMORY)
990 LogWarning("SERVICE_ERROR_OUT_OF_MEMORY");
994 LogWarning("UI_NOTIFICATION_ERROR_INVALID_PARAMETER");
996 throw UnknownException ("get notification service error ");
1000 if (service == NULL)
1002 throw UnknownException ("get notification service ok, but service null");
1007 if (service != NULL)
1009 if (service_get_app_id(service, &appIdStr) != SERVICE_ERROR_NONE)
1011 throw UnknownException ("get a appId error");
1014 if (appIdStr != NULL)
1016 retString = appIdStr;
1026 double StatusNotification::getProgressValue()
1032 NotificationProgressType progressType = getProgressType();
1034 if (progressType == NOTI_PROGRESS_TYPE_SIZE)
1036 if (notification_get_size(m_notiHandle, &value) != NOTIFICATION_ERROR_NONE)
1038 throw UnknownException("get notification size error");
1040 LogInfo("Size Val = " << value);
1042 else if ( progressType == NOTI_PROGRESS_TYPE_PERCENTAGE )
1044 if (notification_get_progress(m_notiHandle, &value) != NOTIFICATION_ERROR_NONE)
1046 throw UnknownException("get notification percentage error");
1048 LogInfo("Percentage Val = " << value);
1052 throw UnknownException("get notification progress type error");
1057 LogDebug("noti Handle is NULL");
1059 LogInfo("value = " << value);
1064 void StatusNotification::setProgressValue(const double &progressValue)
1068 NotificationProgressType progressType = getProgressType();
1069 LogInfo("Progress Type : " << progressType);
1071 double val = getProgressValue();
1072 LogInfo("Progress value = " << progressValue << " origin Progress Value =" << val);
1074 if (progressType == NOTI_PROGRESS_TYPE_SIZE)
1076 if (notification_set_size(m_notiHandle, progressValue) != NOTIFICATION_ERROR_NONE)
1078 throw UnknownException("set notification progress size error");
1081 else if ( progressType == NOTI_PROGRESS_TYPE_PERCENTAGE )
1083 if (notification_set_progress(m_notiHandle, progressValue) != NOTIFICATION_ERROR_NONE)
1085 throw UnknownException("set notification percentage error");
1090 throw UnknownException("get notification progress type error");
1095 LogDebug("noti Handle is NULL");
1096 throw UnknownException( "notification handle is null");
1100 std::string StatusNotification::getSubIconPath()
1102 LogInfo("Handle = " << m_notiHandle);
1105 char *subIconPath = NULL;
1107 if (notification_get_image(m_notiHandle, NOTIFICATION_IMAGE_TYPE_ICON_SUB, &subIconPath) != NOTIFICATION_ERROR_NONE)
1109 throw UnknownException("get notification sub icon error");
1112 std::string notiSubIconPath;
1114 notiSubIconPath = subIconPath;
1115 return notiSubIconPath;
1119 throw UnknownException("notification handle is null");
1124 void StatusNotification::setSubIconPath(const std::string& subIconPath)
1128 LogInfo(" subIconPath = " << subIconPath << " origin SubIconPath = " << getSubIconPath());
1130 if( getSubIconPath().compare(subIconPath))
1132 if (notification_set_image(m_notiHandle,NOTIFICATION_IMAGE_TYPE_ICON_SUB, subIconPath.c_str()) != NOTIFICATION_ERROR_NONE)
1134 throw UnknownException("set notification sound error");
1136 setUpdatedFlag(true);
1141 LogDebug("noti Handle is NULL");
1142 throw UnknownException("notification handle is null");
1147 std::string StatusNotification::getInformation(int index)
1151 notification_text_type_e type = NOTIFICATION_TEXT_TYPE_NONE;
1155 type = NOTIFICATION_TEXT_TYPE_INFO_1;
1158 type = NOTIFICATION_TEXT_TYPE_INFO_2;
1161 type = NOTIFICATION_TEXT_TYPE_INFO_3;
1164 type = NOTIFICATION_TEXT_TYPE_NONE;
1168 if (NOTIFICATION_TEXT_TYPE_NONE != type && notification_get_text(m_notiHandle, type, &info) != NOTIFICATION_ERROR_NONE)
1170 throw UnknownException("get notification information error");
1173 std::string strInfo;
1176 LogDebug(" info " << strInfo);
1182 LogDebug("noti Handle is NULL");
1183 throw UnknownException("notification handle is null");
1188 void StatusNotification::setInformation( const std::string& info, int index)
1194 LogDebug(" index : " << idx);
1195 LogDebug(" log : " << info);
1196 notification_text_type_e type = NOTIFICATION_TEXT_TYPE_NONE;
1201 type = NOTIFICATION_TEXT_TYPE_INFO_1;
1204 type = NOTIFICATION_TEXT_TYPE_INFO_2;
1207 type = NOTIFICATION_TEXT_TYPE_INFO_3;
1210 type = NOTIFICATION_TEXT_TYPE_NONE;
1213 if ( type != NOTIFICATION_TEXT_TYPE_NONE)
1215 if (getInformation(idx).compare(info))
1217 if (notification_set_text(m_notiHandle, type, info.c_str(),
1218 NULL, NOTIFICATION_VARIABLE_TYPE_NONE) != NOTIFICATION_ERROR_NONE)
1220 throw UnknownException("set notification sound error");
1222 setUpdatedFlag(true);
1228 LogDebug("noti Handle is NULL");
1229 throw UnknownException("notification handle is null");
1233 std::string StatusNotification::getSubInformation(int index)
1238 notification_text_type_e type = NOTIFICATION_TEXT_TYPE_NONE;
1242 type = NOTIFICATION_TEXT_TYPE_INFO_SUB_1;
1245 type = NOTIFICATION_TEXT_TYPE_INFO_SUB_2;
1248 type = NOTIFICATION_TEXT_TYPE_INFO_SUB_3;
1251 type = NOTIFICATION_TEXT_TYPE_NONE;
1254 char *subInfo = NULL;
1256 if (NOTIFICATION_TEXT_TYPE_NONE != type && notification_get_text(m_notiHandle, type, &subInfo) != NOTIFICATION_ERROR_NONE)
1258 throw UnknownException( "get notification sub information error");
1261 std::string strSubInfo;
1263 strSubInfo = subInfo;
1264 LogDebug(" subInfo " << strSubInfo);
1270 LogDebug("noti Handle is NULL");
1271 throw UnknownException( "notification handle is null");
1276 void StatusNotification::setSubInformation( const std::string& subInfo, int index)
1281 LogDebug(" index : " << idx);
1282 LogDebug(" log : " << subInfo);
1283 notification_text_type_e type = NOTIFICATION_TEXT_TYPE_NONE;
1288 type = NOTIFICATION_TEXT_TYPE_INFO_SUB_1;
1291 type = NOTIFICATION_TEXT_TYPE_INFO_SUB_2;
1294 type = NOTIFICATION_TEXT_TYPE_INFO_SUB_3;
1297 type = NOTIFICATION_TEXT_TYPE_NONE;
1300 if ( type != NOTIFICATION_TEXT_TYPE_NONE)
1302 if (getSubInformation(idx).compare(subInfo))
1304 if (notification_set_text(m_notiHandle, type, subInfo.c_str(),
1305 NULL, NOTIFICATION_VARIABLE_TYPE_NONE) != NOTIFICATION_ERROR_NONE)
1307 throw UnknownException( "set notification sound error");
1309 setUpdatedFlag(true);
1315 LogDebug("noti Handle is NULL");
1316 throw UnknownException( "notification handle is null");
1322 void StatusNotification::loadThumbnails()
1326 if (!m_thumbs.empty())
1330 if (notification_get_image(m_notiHandle, NOTIFICATION_IMAGE_TYPE_LIST_1, &thumb) != NOTIFICATION_ERROR_NONE)
1332 throw UnknownException( "get notification thumbnail error");
1335 m_thumbs.push_back(thumb);
1337 // m_thumbs.push_back(std::string("")); //set empty
1340 if (notification_get_image(m_notiHandle, NOTIFICATION_IMAGE_TYPE_LIST_2, &thumb) != NOTIFICATION_ERROR_NONE)
1342 throw UnknownException( "get notification sub information error");
1345 m_thumbs.push_back(thumb);
1347 // m_thumbs.push_back(std::string("")); //set empty
1350 if (notification_get_image(m_notiHandle, NOTIFICATION_IMAGE_TYPE_LIST_3, &thumb) != NOTIFICATION_ERROR_NONE)
1352 throw UnknownException( "get notification sub information error");
1356 m_thumbs.push_back(thumb);
1358 // m_thumbs.push_back(std::string("")); //set empty
1361 if (notification_get_image(m_notiHandle, NOTIFICATION_IMAGE_TYPE_LIST_4, &thumb) != NOTIFICATION_ERROR_NONE)
1363 throw UnknownException( "get notification sub information error");
1367 m_thumbs.push_back(thumb);
1369 // m_thumbs.push_back(std::string("")); //set empty
1372 if (notification_get_image(m_notiHandle, NOTIFICATION_IMAGE_TYPE_LIST_5, &thumb) != NOTIFICATION_ERROR_NONE)
1374 throw UnknownException( "get notification sub information error");
1378 m_thumbs.push_back(thumb);
1380 m_thumbs.push_back(std::string("")); //set empty
1387 LogDebug("noti Handle is NULL");
1388 throw UnknownException( "notification handle is null");
1392 std::vector<std::string> StatusNotification::getThumbnails()
1394 LogInfo(" thumbnail Size : " << m_thumbs.size());
1398 std::string StatusNotification::getThumbnail(int index)
1402 LogInfo(" index : " << index);
1404 notification_image_type_e type = NOTIFICATION_IMAGE_TYPE_NONE;
1409 type = NOTIFICATION_IMAGE_TYPE_LIST_1;
1412 type = NOTIFICATION_IMAGE_TYPE_LIST_2;
1415 type = NOTIFICATION_IMAGE_TYPE_LIST_3;
1418 type = NOTIFICATION_IMAGE_TYPE_LIST_4;
1421 type = NOTIFICATION_IMAGE_TYPE_LIST_5;
1424 type = NOTIFICATION_IMAGE_TYPE_NONE;
1427 if ( type != NOTIFICATION_IMAGE_TYPE_NONE)
1430 if (notification_get_image(m_notiHandle, type, &thumb) != NOTIFICATION_ERROR_NONE)
1432 throw UnknownException( "set notification thumbnail error");
1435 std::string thumbnail;
1442 throw UnknownException( "notification handle is null");
1448 LogDebug("noti Handle is NULL");
1449 throw UnknownException( "notification handle is null");
1452 if (m_thumbs.size() > index)
1453 return m_thumbs[index];
1455 return std::string("");
1460 void StatusNotification::setThumbnails(std::vector<std::string> thumbs)
1462 LogInfo("set thumbnails");
1465 std::vector<std::string>::iterator it;
1468 for (it = thumbs.begin(); it < thumbs.end(); ++it)
1470 std::string str = *it;
1471 if ( idx < MAX_THUMBNAIL_LENGTH )
1472 setThumbnail(str, idx); //set notification's thumbnail value.
1480 LogDebug("noti Handle is NULL");
1481 throw UnknownException( "notification handle is null");
1485 void StatusNotification::setThumbnail( const std::string& thumb, int index)
1489 LogInfo(" index : " << index);
1490 LogInfo(" thumb : " << thumb);
1491 notification_image_type_e type = NOTIFICATION_IMAGE_TYPE_NONE;
1496 type = NOTIFICATION_IMAGE_TYPE_LIST_1;
1499 type = NOTIFICATION_IMAGE_TYPE_LIST_2;
1502 type = NOTIFICATION_IMAGE_TYPE_LIST_3;
1505 type = NOTIFICATION_IMAGE_TYPE_LIST_4;
1508 type = NOTIFICATION_IMAGE_TYPE_LIST_5;
1511 type = NOTIFICATION_IMAGE_TYPE_NONE;
1514 if ( type != NOTIFICATION_IMAGE_TYPE_NONE)
1516 if (getThumbnail(index).compare(thumb))
1518 if (notification_set_image(m_notiHandle, type, thumb.c_str()) != NOTIFICATION_ERROR_NONE)
1520 throw UnknownException( "set notification thumbnail error");
1522 setUpdatedFlag(true);
1528 std::string StatusNotification::getBackground()
1530 LogInfo(" Handle : " << m_notiHandle);
1534 char *background = NULL;
1536 if (notification_get_image(m_notiHandle, NOTIFICATION_IMAGE_TYPE_BACKGROUND, &background) != NOTIFICATION_ERROR_NONE)
1538 throw UnknownException( "get notification background error");
1541 std::string notiBackground;
1543 notiBackground = background;
1544 return notiBackground;
1548 LogDebug("noti Handle is NULL");
1549 throw UnknownException( "notification handle is null");
1554 void StatusNotification::setBackground(const std::string imagePath)
1556 LogInfo(" imagePath : " << imagePath);
1559 if (getBackground().compare(imagePath))
1561 if (notification_set_image(m_notiHandle,NOTIFICATION_IMAGE_TYPE_BACKGROUND, imagePath.c_str()) != NOTIFICATION_ERROR_NONE)
1563 throw UnknownException( "set notification sound error");
1565 setUpdatedFlag(true);
1570 LogDebug("noti Handle is NULL");
1571 throw UnknownException( "notification handle is null");
1575 long StatusNotification::getNumber()
1577 LogInfo("Handle = " << m_notiHandle);
1581 char *strNumber = NULL;
1583 if (notification_get_text(m_notiHandle, NOTIFICATION_TEXT_TYPE_EVENT_COUNT, &strNumber) != NOTIFICATION_ERROR_NONE)
1585 throw UnknownException( "get notification background error");
1589 std::istringstream(strNumber) >> number;
1591 LogInfo("Number Is NULL");
1593 LogInfo("number = " << number);
1599 LogDebug("noti Handle is NULL");
1604 const char* StatusNotification::getStrNumber()
1606 LogInfo("Handle = " << m_notiHandle);
1609 char *strNumber = NULL;
1611 if (notification_get_text(m_notiHandle, NOTIFICATION_TEXT_TYPE_EVENT_COUNT, &strNumber) != NOTIFICATION_ERROR_NONE)
1613 throw UnknownException( "get notification background error");
1625 LogDebug("noti Handle is NULL");
1630 void StatusNotification::setNumber(const long number)
1632 LogInfo("Number = " << number);
1635 if(number!=getNumber())
1637 std::stringstream stream;
1639 if (stream.fail()) {
1640 throw UnknownException(
1641 "Couldn't convert notification number");
1644 std::string strNumber = stream.str();
1645 if (notification_set_text(m_notiHandle, NOTIFICATION_TEXT_TYPE_EVENT_COUNT, strNumber.c_str(),
1646 NULL, NOTIFICATION_VARIABLE_TYPE_NONE) != NOTIFICATION_ERROR_NONE)
1648 throw UnknownException( "set notification text error");
1650 setUpdatedFlag(true);
1655 LogDebug("noti Handle is NULL");
1656 throw UnknownException( "notification handle is null");
1660 void* StatusNotification::getNotificationHandle()
1662 return m_notiHandle;
1665 void StatusNotification::setNotificationHandle(void *handle)
1669 throw UnknownException( "notification handle null error");
1671 LogInfo("handle = " << handle << " m_notiHandle = " << m_notiHandle);
1673 if (m_notiHandle != NULL)
1676 if ( notification_delete(m_notiHandle) != NOTIFICATION_ERROR_NONE)
1678 throw UnknownException( "notification delete error");
1680 m_notiHandle = NULL;
1683 m_notiHandle = (notification_h)handle;
1686 service_h StatusNotification::getService()
1693 void StatusNotification::loadDetailInfos()
1695 LogInfo("noti Handle = " << m_notiHandle);
1699 for ( int idx = 0; idx < MAX_NOTIFICATION_DETAIL_INFO_LENGTH; idx++)
1701 std::string main = getInformation(idx);
1702 std::string sub = getSubInformation(idx);
1703 LogInfo("Main : " << main << " Sub : " << sub);
1704 NotificationDetailInfo *info = new NotificationDetailInfo(m_notiHandle, idx, main, sub);
1705 m_detailInfos.push_back(info);
1710 LogDebug("noti Handle is NULL");
1711 throw UnknownException( "notification handle is null");
1716 std::vector<NotificationDetailInfo*> StatusNotification::getDetailInfos() const
1718 return m_detailInfos;
1721 void StatusNotification::setDetailInfos(const std::vector<NotificationDetailInfo*> value)
1723 LogInfo("DetailInfos = " << value.size());
1727 std::vector<NotificationDetailInfo*>::const_iterator it;
1730 for (it = value.begin(); it < value.end(); ++it)
1732 NotificationDetailInfo* info = *it;
1733 if ( idx < MAX_NOTIFICATION_DETAIL_INFO_LENGTH )
1735 LogInfo("main " << info->getMainText() << " sub " << info->getSubText() );
1736 setInformation(info->getMainText(), idx);
1737 setSubInformation(info->getSubText(), idx);
1742 m_detailInfos = value;
1746 LogDebug("noti Handle is NULL");
1747 throw UnknownException( "notification handle is null");
1752 int StatusNotification::getDetailInfosNum() const
1754 return m_detailInfos.size();
1757 void StatusNotification::clearDetailInfos()
1759 if ( !m_detailInfos.empty() )
1761 std::vector<NotificationDetailInfo*>::const_iterator it;
1764 for (it = m_detailInfos.begin(); it < m_detailInfos.end(); ++it)
1766 NotificationDetailInfo* info = *it;
1767 LogInfo("Delete Detail Info : " << info);
1772 m_detailInfos.clear(); //clear
1776 std::string StatusNotification::getInformation(int index)
1780 notification_text_type_e type = NOTIFICATION_TEXT_TYPE_NONE;
1784 type = NOTIFICATION_TEXT_TYPE_INFO_1;
1787 type = NOTIFICATION_TEXT_TYPE_INFO_2;
1790 type = NOTIFICATION_TEXT_TYPE_INFO_3;
1793 type = NOTIFICATION_TEXT_TYPE_NONE;
1797 if (NOTIFICATION_TEXT_TYPE_NONE != type && notification_get_text(m_notiHandle, type, &info) != NOTIFICATION_ERROR_NONE)
1799 throw UnknownException("Detail Info index value is invalid or mainText value getting is failed in Detail Info.");
1802 std::string strInfo;
1805 LogInfo(" info " << strInfo);
1811 LogWarning("noti Handle is NULL");
1812 throw UnknownException( "notification handle is null");
1817 std::string StatusNotification::getSubInformation(int index)
1821 notification_text_type_e type = NOTIFICATION_TEXT_TYPE_NONE;
1825 type = NOTIFICATION_TEXT_TYPE_INFO_SUB_1;
1828 type = NOTIFICATION_TEXT_TYPE_INFO_SUB_2;
1831 type = NOTIFICATION_TEXT_TYPE_INFO_SUB_3;
1834 type = NOTIFICATION_TEXT_TYPE_NONE;
1837 char *subInfo = NULL;
1839 if (NOTIFICATION_TEXT_TYPE_NONE != type && notification_get_text(m_notiHandle, type, &subInfo) != NOTIFICATION_ERROR_NONE)
1841 throw UnknownException("Detail Info index value is invalid or subText value getting is failed in Detail Info.");
1844 std::string strSubInfo;
1846 strSubInfo = subInfo;
1847 LogInfo(" subInfo " << strSubInfo);
1853 LogWarning("noti Handle is NULL");
1854 throw UnknownException ("notification handle is null");
1859 void StatusNotification::setInformation( const std::string& info, int index)
1864 LogDebug(" index : " << idx);
1865 LogDebug(" log : " << info);
1866 notification_text_type_e type = NOTIFICATION_TEXT_TYPE_NONE;
1871 type = NOTIFICATION_TEXT_TYPE_INFO_1;
1874 type = NOTIFICATION_TEXT_TYPE_INFO_2;
1877 type = NOTIFICATION_TEXT_TYPE_INFO_3;
1880 type = NOTIFICATION_TEXT_TYPE_NONE;
1883 if ( type != NOTIFICATION_TEXT_TYPE_NONE)
1885 if (getInformation(idx).compare(info))
1887 if (notification_set_text(m_notiHandle, type, info.c_str(),
1888 NULL, NOTIFICATION_VARIABLE_TYPE_NONE) != NOTIFICATION_ERROR_NONE)
1890 throw UnknownException("set notification sound error");
1892 setUpdatedFlag(true);
1897 LogWarning("noti Handle is NULL");
1898 throw UnknownException("notification handle is null");
1903 LogWarning("noti Handle is NULL");
1904 throw UnknownException("notification handle is null");
1908 void StatusNotification::setSubInformation( const std::string& subInfo, int index)
1914 LogDebug(" index : " << idx);
1915 LogDebug(" log : " << subInfo);
1916 notification_text_type_e type = NOTIFICATION_TEXT_TYPE_NONE;
1921 type = NOTIFICATION_TEXT_TYPE_INFO_SUB_1;
1924 type = NOTIFICATION_TEXT_TYPE_INFO_SUB_2;
1927 type = NOTIFICATION_TEXT_TYPE_INFO_SUB_3;
1930 type = NOTIFICATION_TEXT_TYPE_NONE;
1933 if ( type != NOTIFICATION_TEXT_TYPE_NONE)
1935 if (getSubInformation(idx).compare(subInfo))
1937 if (notification_set_text(m_notiHandle, type, subInfo.c_str(),
1938 NULL, NOTIFICATION_VARIABLE_TYPE_NONE) != NOTIFICATION_ERROR_NONE)
1940 throw UnknownException("set notification sound error");
1942 setUpdatedFlag(true);
1948 LogWarning("noti Handle is NULL");
1949 throw UnknownException("notification handle is null");
1956 StatusNotification::StatusNotification():
1961 m_backgroundImagePath(""),
1969 StatusNotification::~StatusNotification()
1973 std::string StatusNotification::getStatusType() const
1975 return m_statusType;
1978 void StatusNotification::setStatusType(std::string statusType)
1980 m_statusType = statusType;
1983 std::string StatusNotification::getIconPath() const
1988 void StatusNotification::setIconPath(std::string iconPath)
1990 m_iconPath = iconPath;
1993 std::string StatusNotification::getSubIconPath() const
1995 return m_subIconPath;
1998 void StatusNotification::setSubIconPath(std::string subIconPath)
2000 m_subIconPath = subIconPath;
2003 long StatusNotification::getNumber() const
2008 void StatusNotification::setNumber(long number)
2013 std::vector<NotificationDetailInfo*> StatusNotification::getDetailInfo() const
2015 return m_detailInfo;
2018 void StatusNotification::setDetailInfo(std::vector<NotificationDetailInfo*> detailInfo)
2020 m_detailInfo = detailInfo;
2023 std::string StatusNotification::getBackgroundImagePath() const
2025 return m_backgroundImagePath;
2028 void StatusNotification::setBackgroundImagePath(std::string backgroundImagePath)
2030 m_backgroundImagePath = backgroundImagePath;
2033 std::vector<std::string> StatusNotification::getThumbnails() const
2035 return m_thumbnails;
2038 void StatusNotification::setThumbnails(std::vector<std::string> thumbnails)
2040 m_thumbnails = thumbnails;
2043 std::string StatusNotification::getSoundPath() const
2048 void StatusNotification::setSoundPath(std::string soundPath)
2050 m_soundPath = soundPath;
2053 bool StatusNotification::getVibration() const
2058 void StatusNotification::setVibration(bool vibration)
2060 m_vibration = vibration;
2063 ApplicationControl StatusNotification::getAppControl() const
2065 return m_appControl;
2068 void StatusNotification::setAppControl(ApplicationControl appControl)
2070 m_appControl = appControl;
2073 ApplicationId StatusNotification::getAppId() const
2078 void StatusNotification::setAppId(ApplicationId appId)
2083 std::string StatusNotification::getProgressType() const
2085 return m_progressType;
2088 void StatusNotification::setProgressType(std::string progressType)
2090 m_progressType = progressType;
2093 unsigned long StatusNotification::getProgressValue() const
2095 return m_progressValue;
2098 void StatusNotification::setProgressValue(unsigned long progressValue)
2100 m_progressValue = progressValue;