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),
103 LogInfo("statusType =" << statusType);
105 notification_type_e type = NOTIFICATION_TYPE_NONE;
106 setNotiType(statusType);
108 if (statusType == NOTI_TYPE_SIMPLE || statusType == NOTI_TYPE_MUTIPLE || statusType == NOTI_TYPE_THUMBNAIL)
110 type = NOTIFICATION_TYPE_NOTI;
112 else if ( statusType == NOTI_TYPE_ONGOING || statusType == NOTI_TYPE_PROGRESS)
114 type = NOTIFICATION_TYPE_ONGOING;
118 LogInfo(" invalide noti type");
119 throw TypeMismatchException("value is not notification type");
122 setProgressType(NOTI_PROGRESS_TYPE_PERCENTAGE); //default
124 LogInfo("Notification Type : " << type);
126 notification_h noti = notification_create(type); //create notificatin.
129 LogInfo("noti =" << noti);
130 setNotificationHandle((void*)noti);
132 if (NOTIFICATION_TYPE_ONGOING == type)
133 { //ongoing no ticker.
134 LogInfo("ongoing type");
135 notification_set_display_applist(noti, NOTIFICATION_DISPLAY_APP_NOTIFICATION_TRAY |NOTIFICATION_DISPLAY_APP_INDICATOR );
140 throw UnknownException("can't make new notification object");
143 //m_detailInfos = new std::vector<NotificationDetailInfo*>();
144 //m_thumbs = new std::vector<std::string>();
148 StatusNotification::StatusNotification(void* noti) :
149 m_notiType(NOTI_TYPE_NONE),
152 m_progressType(NOTI_PROGRESS_TYPE_PERCENTAGE),
155 LogInfo("noti : " << noti);
157 notification_h notification = (notification_h)noti;
161 NotificationType type = NOTI_TYPE_NONE;
162 notification_type_e noti_type = NOTIFICATION_TYPE_NONE;
163 notification_ly_type_e noti_layout = NOTIFICATION_LY_NONE;
165 notification_get_type(notification, ¬i_type);
166 notification_get_layout(notification, ¬i_layout);
169 if ( noti_type == NOTIFICATION_TYPE_NOTI )
171 if ( noti_layout == NOTIFICATION_LY_NOTI_EVENT_SINGLE ||
172 noti_layout == NOTIFICATION_LY_NOTI_EVENT_MULTIPLE )
174 type = NOTI_TYPE_SIMPLE;
176 else if (noti_layout == NOTIFICATION_LY_NOTI_THUMBNAIL)
178 type = NOTI_TYPE_THUMBNAIL;
181 else if ( noti_type == NOTIFICATION_TYPE_ONGOING)
183 if ( noti_layout == NOTIFICATION_LY_ONGOING_EVENT )
185 type = NOTI_TYPE_ONGOING;
187 else if ( noti_layout == NOTIFICATION_LY_ONGOING_PROGRESS)
189 type = NOTI_TYPE_PROGRESS;
193 LogInfo(" notification type =" << type);
195 setProgressType(NOTI_PROGRESS_TYPE_PERCENTAGE); //default.
197 setNotificationHandle((void*)notification);
201 if ( type == NOTI_TYPE_PROGRESS)
203 notification_update_progress(notification, NOTIFICATION_PRIV_ID_NONE, getProgressValue());
209 int ret = notification_get_execute_option(notification, NOTIFICATION_EXECUTE_TYPE_SINGLE_LAUNCH, NULL, &bSvc);
210 LogInfo("ret = " << ret);
211 if (ret == NOTIFICATION_ERROR_NONE)
213 LogInfo(" bundle = " << bSvc);
216 LogInfo("bundle is valid");
217 int ret = service_create_event(bSvc, &m_service);
218 if (ret != SERVICE_ERROR_NONE)
220 LogInfo("Service Create Event Error");
221 throw UnknownException("can't make service object");
227 notification_free(notification);
228 throw UnknownException("can't get service data");
234 throw InvalidValuesException("It is not notification object.");
239 StatusNotification::StatusNotification(int privID) :
240 m_notiType(NOTI_TYPE_NONE),
243 m_progressType(NOTI_PROGRESS_TYPE_PERCENTAGE),
246 LogInfo("priv ID : " << privID);
248 notification_h notification = notification_load( NULL, privID); //load notification.
249 LogInfo(" notification " << notification);
253 NotificationType type = NOTI_TYPE_NONE;
254 notification_type_e noti_type = NOTIFICATION_TYPE_NONE;
255 notification_ly_type_e noti_layout = NOTIFICATION_LY_NONE;
257 notification_get_type(notification, ¬i_type);
258 notification_get_layout(notification, ¬i_layout);
260 if ( noti_type == NOTIFICATION_TYPE_NOTI )
262 if ( noti_layout == NOTIFICATION_LY_NOTI_EVENT_SINGLE ||
263 noti_layout == NOTIFICATION_LY_NOTI_EVENT_MULTIPLE )
265 type = NOTI_TYPE_SIMPLE;
267 else if (noti_layout == NOTIFICATION_LY_NOTI_THUMBNAIL)
269 type = NOTI_TYPE_THUMBNAIL;
272 else if ( noti_type == NOTIFICATION_TYPE_ONGOING)
274 if ( noti_layout == NOTIFICATION_LY_ONGOING_EVENT )
276 type = NOTI_TYPE_ONGOING;
278 else if ( noti_layout == NOTIFICATION_LY_ONGOING_PROGRESS)
280 type = NOTI_TYPE_PROGRESS;
284 LogInfo(" notification type =" << type);
286 setProgressType(NOTI_PROGRESS_TYPE_PERCENTAGE); //default.
287 setNotificationHandle((void*)notification);
291 if ( type == NOTI_TYPE_PROGRESS)
293 notification_update_progress(notification, NOTIFICATION_PRIV_ID_NONE, getProgressValue());
299 int ret = notification_get_execute_option(notification, NOTIFICATION_EXECUTE_TYPE_SINGLE_LAUNCH, NULL, &bSvc);
300 LogInfo("ret = " << ret);
301 if (ret == NOTIFICATION_ERROR_NONE)
303 LogInfo(" bundle = " << bSvc);
306 LogInfo("bundle is valid");
307 int ret = service_create_event(bSvc, &m_service);
308 if (ret != SERVICE_ERROR_NONE)
310 LogInfo("Service Create Event Error");
311 throw UnknownException("can't make service object");
317 notification_free(notification);
318 throw UnknownException("can't get service data");
324 throw NotFoundException("It is not notification ID or removed notification");
329 StatusNotification::~StatusNotification()
331 LogInfo(" notification = " << m_notiHandle);
334 //clearDetailInfos();
339 LogInfo(" service = " << m_service);
340 if (m_service != NULL)
342 service_destroy(m_service);
346 if (notification_free(m_notiHandle) != NOTIFICATION_ERROR_NONE)
348 throw UnknownException("notification free failed...");
355 int StatusNotification::getID()
357 int id = -1; // notification not inserted yet.
360 notification_get_id(m_notiHandle, NULL, &id);
366 std::string StatusNotification::getStatusType()
370 if ( NOTI_TYPE_SIMPLE == getNotiType())
374 else if ( NOTI_TYPE_ONGOING == getNotiType())
378 else if ( NOTI_TYPE_PROGRESS == getNotiType())
382 else if ( NOTI_TYPE_THUMBNAIL == getNotiType())
393 void StatusNotification::setStatusType(std::string type)
395 LogInfo("type = " << type);
397 NotificationType notiType = NOTI_TYPE_NONE;
399 if( type.compare(TIZEN_STATUS_NOTIFICATION_TYPE_SIMPLE) == 0)
400 notiType = NOTI_TYPE_SIMPLE;
401 else if( type.compare(TIZEN_STATUS_NOTIFICATION_TYPE_THUMBNAIL) == 0)
402 notiType = NOTI_TYPE_THUMBNAIL;
403 else if( type.compare(TIZEN_STATUS_NOTIFICATION_TYPE_ONGOING) == 0)
404 notiType = NOTI_TYPE_ONGOING;
405 else if( type.compare(TIZEN_STATUS_NOTIFICATION_TYPE_PROGRESS) == 0)
406 notiType = NOTI_TYPE_PROGRESS;
408 throw InvalidValuesException("Invalid Status Type.");
410 LogInfo("Notification type = " << notiType);
411 setNotiType(notiType);
414 time_t StatusNotification::getPostedTime()
416 LogInfo("get m_notiHandle = " << m_notiHandle);
418 time_t postedTime = 0;
422 if (notification_get_insert_time(m_notiHandle, &postedTime) != NOTIFICATION_ERROR_NONE)
424 throw UnknownException("get notification posted time error");
428 LogInfo("posted Time =" << ctime(&postedTime));
432 std::string StatusNotification::getTitle()
438 if (notification_get_text(m_notiHandle,NOTIFICATION_TEXT_TYPE_TITLE, &title) != NOTIFICATION_ERROR_NONE)
440 throw UnknownException("get notification title error");
443 std::string notiTitle(title);
448 throw UnknownException("notification handle is null");
452 void StatusNotification::setTitle(std::string title)
454 LogInfo("Title : " << title);
457 LogInfo("get Title : " << getTitle());
458 if((getTitle()).compare(title)) //different value.
460 if (notification_set_text(m_notiHandle, NOTIFICATION_TEXT_TYPE_TITLE, title.c_str(),
461 NULL, NOTIFICATION_VARIABLE_TYPE_NONE ) != NOTIFICATION_ERROR_NONE)
463 throw UnknownException("set notification title error");
466 setUpdatedFlag(true);
470 LogInfo(" title = " << title << " getTitle = " << getTitle());
475 LogDebug("noti Handle is NULL");
476 throw UnknownException("notification handle is null");
481 std::string StatusNotification::getContent()
483 LogInfo("get Content handle: " << m_notiHandle);
486 char *content = NULL;
488 if (notification_get_text(m_notiHandle, NOTIFICATION_TEXT_TYPE_CONTENT, &content) != NOTIFICATION_ERROR_NONE)
490 throw UnknownException("get notification Content error");
493 LogInfo(" get Content : " << content);
495 std::string notiContent;
498 notiContent = content;
505 throw UnknownException("notification handle is null");
510 void StatusNotification::setContent(std::string content)
512 LogInfo("Content : " << content);
515 if((getContent()).compare(content)) //different value.
517 if (notification_set_text(m_notiHandle, NOTIFICATION_TEXT_TYPE_CONTENT, content.c_str(),
518 NULL, NOTIFICATION_VARIABLE_TYPE_NONE ) != NOTIFICATION_ERROR_NONE)
520 throw UnknownException("set notification content error");
522 setUpdatedFlag(true);
527 LogDebug("noti Handle is NULL");
528 throw UnknownException("notification handle is null");
532 std::string StatusNotification::getIconPath()
535 LogInfo("m_notiHandle = " << m_notiHandle);
538 char *iconPath = NULL;
539 if (notification_get_image(m_notiHandle, NOTIFICATION_IMAGE_TYPE_ICON, &iconPath) != NOTIFICATION_ERROR_NONE)
541 throw UnknownException("get notification icon path error");
544 std::string notiIconPath(iconPath);
545 LogInfo("icon Path = " << iconPath);
547 //if icon path invalid, return empty string.
548 if ( notiIconPath.find(DEFAULT_ICON_PATH,0) == std::string::npos)
552 return std::string(""); //return empty string.
557 throw UnknownException("notification handle is null");
561 void StatusNotification::setIconPath(const std::string& iconPath)
565 LogInfo("icon path = " << iconPath << " origin icon path = " << getIconPath());
566 if( getIconPath().compare(iconPath))
568 if (notification_set_image(m_notiHandle,NOTIFICATION_IMAGE_TYPE_ICON, iconPath.c_str()) != NOTIFICATION_ERROR_NONE)
570 throw UnknownException("set notification icon error");
572 setUpdatedFlag(true);
577 LogDebug("noti Handle is NULL");
578 throw UnknownException("notification handle is null");
582 std::string StatusNotification::getSoundPath()
584 LogInfo("Handle = " << m_notiHandle);
588 const char *soundPath = NULL;
589 notification_sound_type_e type = NOTIFICATION_SOUND_TYPE_NONE;
591 if (notification_get_sound(m_notiHandle, &type, &soundPath) != NOTIFICATION_ERROR_NONE)
593 throw UnknownException("get notification sound error");
596 LogInfo(" sound type = " << type << " path = " << soundPath);
597 if ( type == NOTIFICATION_SOUND_TYPE_USER_DATA )
599 LogInfo("soundPath = " << soundPath);
600 return std::string(soundPath);
604 return std::string("");
609 LogDebug("noti Handle is NULL");
610 throw UnknownException("notification handle is null");
614 void StatusNotification::setSoundPath(const std::string& sound)
618 LogInfo("sound path = " << sound << " origin sound path = " << getSoundPath());
620 if( getSoundPath().compare(sound))
622 if (notification_set_sound(m_notiHandle,NOTIFICATION_SOUND_TYPE_USER_DATA, sound.c_str()) != NOTIFICATION_ERROR_NONE)
624 throw UnknownException("set notification sound error");
626 setUpdatedFlag(true);
631 LogInfo("sound path is NULL");
632 if ( NOTI_TYPE_ONGOING == getNotiType() || NOTI_TYPE_PROGRESS == getNotiType())
634 LogInfo("Ongoing Type" );
635 if (notification_set_sound(m_notiHandle,NOTIFICATION_SOUND_TYPE_NONE, NULL) != NOTIFICATION_ERROR_NONE)
637 throw UnknownException("set notification sound error");
642 if (notification_set_sound(m_notiHandle,NOTIFICATION_SOUND_TYPE_DEFAULT, sound.c_str()) != NOTIFICATION_ERROR_NONE)
644 throw UnknownException("set notification sound error");
652 LogDebug("noti Handle is NULL");
653 throw UnknownException("notification handle is null");
657 bool StatusNotification::getDefaultVibration()
659 LogInfo("getDefaultVibration");
662 notification_vibration_type_e vib_type;
663 if (notification_get_vibration(m_notiHandle, &vib_type, NULL) != NOTIFICATION_ERROR_NONE)
665 throw UnknownException("set notification sound error");
668 if (NOTIFICATION_VIBRATION_TYPE_DEFAULT == vib_type || NOTIFICATION_VIBRATION_TYPE_USER_DATA == vib_type)
679 LogDebug("noti Handle is NULL");
680 throw UnknownException("notification handle is null");
686 void StatusNotification::setDefaultVibration(const bool& vibration)
688 LogInfo("vibration = " << vibration);
691 notification_vibration_type_e vib_type = NOTIFICATION_VIBRATION_TYPE_NONE;
692 LogInfo("old vibration = " << getDefaultVibration());
693 if (getDefaultVibration() != vibration)
697 vib_type = NOTIFICATION_VIBRATION_TYPE_DEFAULT;
701 vib_type = NOTIFICATION_VIBRATION_TYPE_NONE;
703 LogInfo("type vibration type= " << vib_type);
705 if (notification_set_vibration(m_notiHandle, vib_type , NULL) != NOTIFICATION_ERROR_NONE)
707 throw UnknownException("set notification sound error");
709 setUpdatedFlag(true);
714 LogDebug("noti Handle is NULL");
715 throw UnknownException("notification handle is null");
720 DeviceAPI::Application::ApplicationControlPtr StatusNotification::getApplicationControl()
723 service_h service = NULL;
724 char *tempStr = NULL;
726 DeviceAPI::Application::ApplicationControlPtr appControl(new DeviceAPI::Application::ApplicationControl());
731 appControl->setService_h(m_service);
733 if(service_get_operation(m_service, &tempStr) == SERVICE_ERROR_NONE)
735 LogDebug("Operation Str = " << tempStr);
738 appControl->setOperation(tempStr);
745 if (service_get_mime(m_service, &tempStr) == SERVICE_ERROR_NONE)
747 LogDebug("Mime Str = " << tempStr);
750 appControl->setMime(tempStr);
757 if (service_get_uri(m_service, &tempStr) == SERVICE_ERROR_NONE)
759 LogDebug("Uri Str = " << tempStr);
762 appControl->setUri(tempStr);
768 if (service_get_category(m_service, &tempStr) == SERVICE_ERROR_NONE)
770 LogDebug("Category Str = " << tempStr);
773 appControl->setCategory(tempStr);
780 if ( service_foreach_extra_data(m_service, service_extra_data_cb,(void*)&appControl) != SERVICE_ERROR_NONE)
782 ThrowMsg(WrtDeviceApis::Commons::UnknownException, "get notification service uri error");
789 Catch (WrtDeviceApis::Commons::Exception)
803 LogWarning(_rethrown_exception.GetMessage());
809 void StatusNotification::setApplicationControl(DeviceAPI::Application::ApplicationControlPtr control)
811 LogInfo("Entered m_service : " << m_service << " control : " << control);
813 //delete old service.
816 service_destroy(m_service);
820 if(service_create(&m_service) != SERVICE_ERROR_NONE)
822 throw UnknownException("service creation error");
826 LogInfo("getOperation : " << control->getOperation().c_str());
827 if (control->getOperation().size() != 0)
829 if (service_set_operation(m_service, control->getOperation().c_str()) != SERVICE_ERROR_NONE)
831 throw UnknownException("service set operation error");
836 LogInfo("getUri : " << control->getUri().c_str());
837 if (control->getUri().size() != 0)
839 if (service_set_uri(m_service, control->getUri().c_str() ) != SERVICE_ERROR_NONE)
841 throw UnknownException("service set uri error");
846 LogInfo("getMime : " << control->getMime().c_str());
847 if (control->getMime().size() != 0)
849 if (service_set_mime(m_service, control->getMime().c_str() ) != SERVICE_ERROR_NONE)
851 throw UnknownException("service set mime error");
855 LogInfo("Category : " << control->getCategory().c_str());
856 if (control->getCategory().size() != 0)
858 if (service_set_category(m_service, control->getCategory().c_str() ) != SERVICE_ERROR_NONE)
860 throw UnknownException("service set mime error");
865 //if ( service_foreach_extra_data(m_service, service_extra_data_delete_cb, NULL) != SERVICE_ERROR_NONE)
867 // throw UnknownException("get notification service uri error");
870 std::vector<DeviceAPI::Application::ApplicationControlDataPtr> appControlDataArray = control->getAppControlDataArray();
873 LogInfo (" App Control Datas Count : " << appControlDataArray.size());
875 DeviceAPI::Application::ApplicationControlDataArray::iterator iter;
877 for(iter = appControlDataArray.begin(); iter != appControlDataArray.end(); iter++)
879 DeviceAPI::Application::ApplicationControlDataPtr appControlData = *iter;
880 std::string key = appControlData->getKey();
881 LogInfo(" key : " << key);
886 std::vector<std::string> value = appControlDataArray[index]->getValue();
887 const char **arrayValue = (const char**)calloc(sizeof(char*), value.size());
889 for (size_t indexArray = 0; indexArray < value.size(); indexArray++)
891 arrayValue[indexArray] = (char*)value[indexArray].c_str();
892 LogInfo( " value : " << arrayValue[indexArray]);
895 const char* strKey = key.c_str();
896 LogInfo( " value size: " << value.size());
897 if (service_add_extra_data_array(m_service, strKey, arrayValue, value.size()) != SERVICE_ERROR_NONE)
899 throw UnknownException("service set extra data error");
906 bundle *bundle_data=NULL;
908 if(service_to_bundle(m_service, &bundle_data) != SERVICE_ERROR_NONE)
910 throw UnknownException("service get bundle");
913 LogDebug("bundle_data : " << bundle_data);
917 notification_set_execute_option(m_notiHandle, NOTIFICATION_EXECUTE_TYPE_SINGLE_LAUNCH,
918 NULL,NULL, bundle_data);
925 void StatusNotification::setApplicationId(const std::string& appId)
927 LogInfo("m_service = " << m_service << " appId = " << appId);
930 if (service_create(&m_service) != SERVICE_ERROR_NONE)
932 LogWarning("Create Service Failed..");
933 throw DeviceAPI::Common::UnknownException ("service creation error");
939 if (service_set_app_id(m_service, appId.c_str())!= SERVICE_ERROR_NONE)
941 throw DeviceAPI::Common::UnknownException ("service set appId error");
947 std::string StatusNotification::getApplicationId()
949 std::string retString;
950 service_h service = NULL;
951 char* appIdStr = NULL;
953 if (m_service != NULL)
956 retcode = service_clone(&service, m_service);
958 if (retcode != SERVICE_ERROR_NONE)
960 if (retcode == SERVICE_ERROR_OUT_OF_MEMORY)
962 LogWarning("SERVICE_ERROR_OUT_OF_MEMORY");
966 LogWarning("UI_NOTIFICATION_ERROR_INVALID_PARAMETER");
968 throw DeviceAPI::Common::UnknownException ("get notification service error ");
974 throw DeviceAPI::Common::UnknownException ("get notification service ok, but service null");
981 if (service_get_app_id(service, &appIdStr) != SERVICE_ERROR_NONE)
983 throw DeviceAPI::Common::UnknownException ("get a appId error");
986 if (appIdStr != NULL)
988 retString = appIdStr;
998 double StatusNotification::getProgressValue()
1004 NotificationProgressType progressType = getProgressType();
1006 if (progressType == NOTI_PROGRESS_TYPE_SIZE)
1008 if (notification_get_size(m_notiHandle, &value) != NOTIFICATION_ERROR_NONE)
1010 throw UnknownException("get notification size error");
1012 LogInfo("Size Val = " << value);
1014 else if ( progressType == NOTI_PROGRESS_TYPE_PERCENTAGE )
1016 if (notification_get_progress(m_notiHandle, &value) != NOTIFICATION_ERROR_NONE)
1018 throw UnknownException("get notification percentage error");
1020 LogInfo("Percentage Val = " << value);
1024 throw UnknownException("get notification progress type error");
1029 LogDebug("noti Handle is NULL");
1031 LogInfo("value = " << value);
1036 void StatusNotification::setProgressValue(const double &progressValue)
1040 NotificationProgressType progressType = getProgressType();
1041 LogInfo("Progress Type : " << progressType);
1043 double val = getProgressValue();
1044 LogInfo("Progress value = " << progressValue << " origin Progress Value =" << val);
1046 if (progressType == NOTI_PROGRESS_TYPE_SIZE)
1048 if (notification_set_size(m_notiHandle, progressValue) != NOTIFICATION_ERROR_NONE)
1050 throw UnknownException("set notification progress size error");
1053 else if ( progressType == NOTI_PROGRESS_TYPE_PERCENTAGE )
1055 if (notification_set_progress(m_notiHandle, progressValue) != NOTIFICATION_ERROR_NONE)
1057 throw UnknownException("set notification percentage error");
1062 throw UnknownException("get notification progress type error");
1067 LogDebug("noti Handle is NULL");
1068 throw UnknownException( "notification handle is null");
1072 std::string StatusNotification::getSubIconPath()
1074 LogInfo("Handle = " << m_notiHandle);
1077 char *subIconPath = NULL;
1079 if (notification_get_image(m_notiHandle, NOTIFICATION_IMAGE_TYPE_ICON_SUB, &subIconPath) != NOTIFICATION_ERROR_NONE)
1081 throw UnknownException("get notification sub icon error");
1084 std::string notiSubIconPath;
1086 notiSubIconPath = subIconPath;
1087 return notiSubIconPath;
1091 throw UnknownException("notification handle is null");
1096 void StatusNotification::setSubIconPath(const std::string& subIconPath)
1100 LogInfo(" subIconPath = " << subIconPath << " origin SubIconPath = " << getSubIconPath());
1102 if( getSubIconPath().compare(subIconPath))
1104 if (notification_set_image(m_notiHandle,NOTIFICATION_IMAGE_TYPE_ICON_SUB, subIconPath.c_str()) != NOTIFICATION_ERROR_NONE)
1106 throw UnknownException("set notification sound error");
1108 setUpdatedFlag(true);
1113 LogDebug("noti Handle is NULL");
1114 throw UnknownException("notification handle is null");
1119 std::string StatusNotification::getInformation(int index)
1123 notification_text_type_e type = NOTIFICATION_TEXT_TYPE_NONE;
1127 type = NOTIFICATION_TEXT_TYPE_INFO_1;
1130 type = NOTIFICATION_TEXT_TYPE_INFO_2;
1133 type = NOTIFICATION_TEXT_TYPE_INFO_3;
1136 type = NOTIFICATION_TEXT_TYPE_NONE;
1140 if (NOTIFICATION_TEXT_TYPE_NONE != type && notification_get_text(m_notiHandle, type, &info) != NOTIFICATION_ERROR_NONE)
1142 throw UnknownException("get notification information error");
1145 std::string strInfo;
1148 LogDebug(" info " << strInfo);
1154 LogDebug("noti Handle is NULL");
1155 throw UnknownException("notification handle is null");
1160 void StatusNotification::setInformation( const std::string& info, int index)
1166 LogDebug(" index : " << idx);
1167 LogDebug(" log : " << info);
1168 notification_text_type_e type = NOTIFICATION_TEXT_TYPE_NONE;
1173 type = NOTIFICATION_TEXT_TYPE_INFO_1;
1176 type = NOTIFICATION_TEXT_TYPE_INFO_2;
1179 type = NOTIFICATION_TEXT_TYPE_INFO_3;
1182 type = NOTIFICATION_TEXT_TYPE_NONE;
1185 if ( type != NOTIFICATION_TEXT_TYPE_NONE)
1187 if (getInformation(idx).compare(info))
1189 if (notification_set_text(m_notiHandle, type, info.c_str(),
1190 NULL, NOTIFICATION_VARIABLE_TYPE_NONE) != NOTIFICATION_ERROR_NONE)
1192 throw UnknownException("set notification sound error");
1194 setUpdatedFlag(true);
1200 LogDebug("noti Handle is NULL");
1201 throw UnknownException("notification handle is null");
1205 std::string StatusNotification::getSubInformation(int index)
1210 notification_text_type_e type = NOTIFICATION_TEXT_TYPE_NONE;
1214 type = NOTIFICATION_TEXT_TYPE_INFO_SUB_1;
1217 type = NOTIFICATION_TEXT_TYPE_INFO_SUB_2;
1220 type = NOTIFICATION_TEXT_TYPE_INFO_SUB_3;
1223 type = NOTIFICATION_TEXT_TYPE_NONE;
1226 char *subInfo = NULL;
1228 if (NOTIFICATION_TEXT_TYPE_NONE != type && notification_get_text(m_notiHandle, type, &subInfo) != NOTIFICATION_ERROR_NONE)
1230 throw UnknownException( "get notification sub information error");
1233 std::string strSubInfo;
1235 strSubInfo = subInfo;
1236 LogDebug(" subInfo " << strSubInfo);
1242 LogDebug("noti Handle is NULL");
1243 throw UnknownException( "notification handle is null");
1248 void StatusNotification::setSubInformation( const std::string& subInfo, int index)
1253 LogDebug(" index : " << idx);
1254 LogDebug(" log : " << subInfo);
1255 notification_text_type_e type = NOTIFICATION_TEXT_TYPE_NONE;
1260 type = NOTIFICATION_TEXT_TYPE_INFO_SUB_1;
1263 type = NOTIFICATION_TEXT_TYPE_INFO_SUB_2;
1266 type = NOTIFICATION_TEXT_TYPE_INFO_SUB_3;
1269 type = NOTIFICATION_TEXT_TYPE_NONE;
1272 if ( type != NOTIFICATION_TEXT_TYPE_NONE)
1274 if (getSubInformation(idx).compare(subInfo))
1276 if (notification_set_text(m_notiHandle, type, subInfo.c_str(),
1277 NULL, NOTIFICATION_VARIABLE_TYPE_NONE) != NOTIFICATION_ERROR_NONE)
1279 throw UnknownException( "set notification sound error");
1281 setUpdatedFlag(true);
1287 LogDebug("noti Handle is NULL");
1288 throw UnknownException( "notification handle is null");
1294 void StatusNotification::loadThumbnails()
1298 if (!m_thumbs.empty())
1302 if (notification_get_image(m_notiHandle, NOTIFICATION_IMAGE_TYPE_LIST_1, &thumb) != NOTIFICATION_ERROR_NONE)
1304 throw UnknownException( "get notification thumbnail error");
1307 m_thumbs.push_back(thumb);
1309 // m_thumbs.push_back(std::string("")); //set empty
1312 if (notification_get_image(m_notiHandle, NOTIFICATION_IMAGE_TYPE_LIST_2, &thumb) != NOTIFICATION_ERROR_NONE)
1314 throw UnknownException( "get notification sub information error");
1317 m_thumbs.push_back(thumb);
1319 // m_thumbs.push_back(std::string("")); //set empty
1322 if (notification_get_image(m_notiHandle, NOTIFICATION_IMAGE_TYPE_LIST_3, &thumb) != NOTIFICATION_ERROR_NONE)
1324 throw UnknownException( "get notification sub information error");
1328 m_thumbs.push_back(thumb);
1330 // m_thumbs.push_back(std::string("")); //set empty
1333 if (notification_get_image(m_notiHandle, NOTIFICATION_IMAGE_TYPE_LIST_4, &thumb) != NOTIFICATION_ERROR_NONE)
1335 throw UnknownException( "get notification sub information error");
1339 m_thumbs.push_back(thumb);
1341 // m_thumbs.push_back(std::string("")); //set empty
1344 if (notification_get_image(m_notiHandle, NOTIFICATION_IMAGE_TYPE_LIST_5, &thumb) != NOTIFICATION_ERROR_NONE)
1346 throw UnknownException( "get notification sub information error");
1350 m_thumbs.push_back(thumb);
1352 m_thumbs.push_back(std::string("")); //set empty
1359 LogDebug("noti Handle is NULL");
1360 throw UnknownException( "notification handle is null");
1364 std::vector<std::string> StatusNotification::getThumbnails()
1366 LogInfo(" thumbnail Size : " << m_thumbs.size());
1370 std::string StatusNotification::getThumbnail(int index)
1374 LogInfo(" index : " << index);
1376 notification_image_type_e type = NOTIFICATION_IMAGE_TYPE_NONE;
1381 type = NOTIFICATION_IMAGE_TYPE_LIST_1;
1384 type = NOTIFICATION_IMAGE_TYPE_LIST_2;
1387 type = NOTIFICATION_IMAGE_TYPE_LIST_3;
1390 type = NOTIFICATION_IMAGE_TYPE_LIST_4;
1393 type = NOTIFICATION_IMAGE_TYPE_LIST_5;
1396 type = NOTIFICATION_IMAGE_TYPE_NONE;
1399 if ( type != NOTIFICATION_IMAGE_TYPE_NONE)
1402 if (notification_get_image(m_notiHandle, type, &thumb) != NOTIFICATION_ERROR_NONE)
1404 throw UnknownException( "set notification thumbnail error");
1407 std::string thumbnail;
1414 throw UnknownException( "notification handle is null");
1420 LogDebug("noti Handle is NULL");
1421 throw UnknownException( "notification handle is null");
1424 if (m_thumbs.size() > index)
1425 return m_thumbs[index];
1427 return std::string("");
1432 void StatusNotification::setThumbnails(std::vector<std::string> thumbs)
1434 LogInfo("set thumbnails");
1437 std::vector<std::string>::iterator it;
1440 for (it = thumbs.begin(); it < thumbs.end(); ++it)
1442 std::string str = *it;
1443 if ( idx < MAX_THUMBNAIL_LENGTH )
1444 setThumbnail(str, idx); //set notification's thumbnail value.
1452 LogDebug("noti Handle is NULL");
1453 throw UnknownException( "notification handle is null");
1457 void StatusNotification::setThumbnail( const std::string& thumb, int index)
1461 LogInfo(" index : " << index);
1462 LogInfo(" thumb : " << thumb);
1463 notification_image_type_e type = NOTIFICATION_IMAGE_TYPE_NONE;
1468 type = NOTIFICATION_IMAGE_TYPE_LIST_1;
1471 type = NOTIFICATION_IMAGE_TYPE_LIST_2;
1474 type = NOTIFICATION_IMAGE_TYPE_LIST_3;
1477 type = NOTIFICATION_IMAGE_TYPE_LIST_4;
1480 type = NOTIFICATION_IMAGE_TYPE_LIST_5;
1483 type = NOTIFICATION_IMAGE_TYPE_NONE;
1486 if ( type != NOTIFICATION_IMAGE_TYPE_NONE)
1488 if (getThumbnail(index).compare(thumb))
1490 if (notification_set_image(m_notiHandle, type, thumb.c_str()) != NOTIFICATION_ERROR_NONE)
1492 throw UnknownException( "set notification thumbnail error");
1494 setUpdatedFlag(true);
1500 std::string StatusNotification::getBackground()
1502 LogInfo(" Handle : " << m_notiHandle);
1506 char *background = NULL;
1508 if (notification_get_image(m_notiHandle, NOTIFICATION_IMAGE_TYPE_BACKGROUND, &background) != NOTIFICATION_ERROR_NONE)
1510 throw UnknownException( "get notification background error");
1513 std::string notiBackground;
1515 notiBackground = background;
1516 return notiBackground;
1520 LogDebug("noti Handle is NULL");
1521 throw UnknownException( "notification handle is null");
1526 void StatusNotification::setBackground(const std::string imagePath)
1528 LogInfo(" imagePath : " << imagePath);
1531 if (getBackground().compare(imagePath))
1533 if (notification_set_image(m_notiHandle,NOTIFICATION_IMAGE_TYPE_BACKGROUND, imagePath.c_str()) != NOTIFICATION_ERROR_NONE)
1535 throw UnknownException( "set notification sound error");
1537 setUpdatedFlag(true);
1542 LogDebug("noti Handle is NULL");
1543 throw UnknownException( "notification handle is null");
1547 unsigned int StatusNotification::getNumber()
1549 LogInfo("Handle = " << m_notiHandle);
1553 char *strNumber = NULL;
1555 if (notification_get_text(m_notiHandle, NOTIFICATION_TEXT_TYPE_EVENT_COUNT, &strNumber) != NOTIFICATION_ERROR_NONE)
1557 throw UnknownException( "get notification background error");
1561 std::istringstream(strNumber) >> number;
1563 LogInfo("number = " << number);
1571 LogDebug("noti Handle is NULL");
1576 void StatusNotification::setNumber(const unsigned int number)
1578 LogInfo("Number = " << number);
1581 if(number!=getNumber())
1583 std::stringstream stream;
1585 if (stream.fail()) {
1586 throw UnknownException(
1587 "Couldn't convert e-mail account id");
1590 std::string strNumber = stream.str();
1591 if (notification_set_text(m_notiHandle, NOTIFICATION_TEXT_TYPE_EVENT_COUNT, strNumber.c_str(),
1592 NULL, NOTIFICATION_VARIABLE_TYPE_NONE) != NOTIFICATION_ERROR_NONE)
1594 throw UnknownException( "set notification sound error");
1596 setUpdatedFlag(true);
1601 LogDebug("noti Handle is NULL");
1602 throw UnknownException( "notification handle is null");
1606 void* StatusNotification::getNotificationHandle()
1608 return m_notiHandle;
1611 void StatusNotification::setNotificationHandle(void *handle)
1615 throw UnknownException( "notification handle null error");
1617 LogInfo("handle = " << handle << " m_notiHandle = " << m_notiHandle);
1619 if (m_notiHandle != NULL)
1622 if ( notification_delete(m_notiHandle) != NOTIFICATION_ERROR_NONE)
1624 throw UnknownException( "notification delete error");
1626 m_notiHandle = NULL;
1629 m_notiHandle = (notification_h)handle;
1632 service_h StatusNotification::getService()
1639 void StatusNotification::loadDetailInfos()
1641 LogInfo("noti Handle = " << m_notiHandle);
1645 for ( int idx = 0; idx < MAX_NOTIFICATION_DETAIL_INFO_LENGTH; idx++)
1647 std::string main = getInformation(idx);
1648 std::string sub = getSubInformation(idx);
1649 LogInfo("Main : " << main << " Sub : " << sub);
1650 NotificationDetailInfo *info = new NotificationDetailInfo(m_notiHandle, idx, main, sub);
1651 m_detailInfos.push_back(info);
1656 LogDebug("noti Handle is NULL");
1657 throw UnknownException( "notification handle is null");
1662 std::vector<NotificationDetailInfo*> StatusNotification::getDetailInfos() const
1664 return m_detailInfos;
1667 void StatusNotification::setDetailInfos(const std::vector<NotificationDetailInfo*> value)
1669 LogInfo("DetailInfos = " << value.size());
1673 std::vector<NotificationDetailInfo*>::const_iterator it;
1676 for (it = value.begin(); it < value.end(); ++it)
1678 NotificationDetailInfo* info = *it;
1679 if ( idx < MAX_NOTIFICATION_DETAIL_INFO_LENGTH )
1681 LogInfo("main " << info->getMainText() << " sub " << info->getSubText() );
1682 setInformation(info->getMainText(), idx);
1683 setSubInformation(info->getSubText(), idx);
1688 m_detailInfos = value;
1692 LogDebug("noti Handle is NULL");
1693 throw UnknownException( "notification handle is null");
1698 int StatusNotification::getDetailInfosNum() const
1700 return m_detailInfos.size();
1703 void StatusNotification::clearDetailInfos()
1705 if ( !m_detailInfos.empty() )
1707 std::vector<NotificationDetailInfo*>::const_iterator it;
1710 for (it = m_detailInfos.begin(); it < m_detailInfos.end(); ++it)
1712 NotificationDetailInfo* info = *it;
1713 LogInfo("Delete Detail Info : " << info);
1718 m_detailInfos.clear(); //clear
1722 std::string StatusNotification::getInformation(int index)
1726 notification_text_type_e type = NOTIFICATION_TEXT_TYPE_NONE;
1730 type = NOTIFICATION_TEXT_TYPE_INFO_1;
1733 type = NOTIFICATION_TEXT_TYPE_INFO_2;
1736 type = NOTIFICATION_TEXT_TYPE_INFO_3;
1739 type = NOTIFICATION_TEXT_TYPE_NONE;
1743 if (NOTIFICATION_TEXT_TYPE_NONE != type && notification_get_text(m_notiHandle, type, &info) != NOTIFICATION_ERROR_NONE)
1745 throw UnknownException("Detail Info index value is invalid or mainText value getting is failed in Detail Info.");
1748 std::string strInfo;
1751 LogInfo(" info " << strInfo);
1757 LogWarning("noti Handle is NULL");
1758 throw UnknownException( "notification handle is null");
1763 std::string StatusNotification::getSubInformation(int index)
1767 notification_text_type_e type = NOTIFICATION_TEXT_TYPE_NONE;
1771 type = NOTIFICATION_TEXT_TYPE_INFO_SUB_1;
1774 type = NOTIFICATION_TEXT_TYPE_INFO_SUB_2;
1777 type = NOTIFICATION_TEXT_TYPE_INFO_SUB_3;
1780 type = NOTIFICATION_TEXT_TYPE_NONE;
1783 char *subInfo = NULL;
1785 if (NOTIFICATION_TEXT_TYPE_NONE != type && notification_get_text(m_notiHandle, type, &subInfo) != NOTIFICATION_ERROR_NONE)
1787 throw UnknownException("Detail Info index value is invalid or subText value getting is failed in Detail Info.");
1790 std::string strSubInfo;
1792 strSubInfo = subInfo;
1793 LogInfo(" subInfo " << strSubInfo);
1799 LogWarning("noti Handle is NULL");
1800 throw UnknownException ("notification handle is null");
1805 void StatusNotification::setInformation( const std::string& info, int index)
1810 LogDebug(" index : " << idx);
1811 LogDebug(" log : " << info);
1812 notification_text_type_e type = NOTIFICATION_TEXT_TYPE_NONE;
1817 type = NOTIFICATION_TEXT_TYPE_INFO_1;
1820 type = NOTIFICATION_TEXT_TYPE_INFO_2;
1823 type = NOTIFICATION_TEXT_TYPE_INFO_3;
1826 type = NOTIFICATION_TEXT_TYPE_NONE;
1829 if ( type != NOTIFICATION_TEXT_TYPE_NONE)
1831 if (getInformation(idx).compare(info))
1833 if (notification_set_text(m_notiHandle, type, info.c_str(),
1834 NULL, NOTIFICATION_VARIABLE_TYPE_NONE) != NOTIFICATION_ERROR_NONE)
1836 throw UnknownException("set notification sound error");
1838 setUpdatedFlag(true);
1843 LogWarning("noti Handle is NULL");
1844 throw UnknownException("notification handle is null");
1849 LogWarning("noti Handle is NULL");
1850 throw UnknownException("notification handle is null");
1854 void StatusNotification::setSubInformation( const std::string& subInfo, int index)
1860 LogDebug(" index : " << idx);
1861 LogDebug(" log : " << subInfo);
1862 notification_text_type_e type = NOTIFICATION_TEXT_TYPE_NONE;
1867 type = NOTIFICATION_TEXT_TYPE_INFO_SUB_1;
1870 type = NOTIFICATION_TEXT_TYPE_INFO_SUB_2;
1873 type = NOTIFICATION_TEXT_TYPE_INFO_SUB_3;
1876 type = NOTIFICATION_TEXT_TYPE_NONE;
1879 if ( type != NOTIFICATION_TEXT_TYPE_NONE)
1881 if (getSubInformation(idx).compare(subInfo))
1883 if (notification_set_text(m_notiHandle, type, subInfo.c_str(),
1884 NULL, NOTIFICATION_VARIABLE_TYPE_NONE) != NOTIFICATION_ERROR_NONE)
1886 throw UnknownException("set notification sound error");
1888 setUpdatedFlag(true);
1894 LogWarning("noti Handle is NULL");
1895 throw UnknownException("notification handle is null");
1902 StatusNotification::StatusNotification():
1907 m_backgroundImagePath(""),
1915 StatusNotification::~StatusNotification()
1919 std::string StatusNotification::getStatusType() const
1921 return m_statusType;
1924 void StatusNotification::setStatusType(std::string statusType)
1926 m_statusType = statusType;
1929 std::string StatusNotification::getIconPath() const
1934 void StatusNotification::setIconPath(std::string iconPath)
1936 m_iconPath = iconPath;
1939 std::string StatusNotification::getSubIconPath() const
1941 return m_subIconPath;
1944 void StatusNotification::setSubIconPath(std::string subIconPath)
1946 m_subIconPath = subIconPath;
1949 long StatusNotification::getNumber() const
1954 void StatusNotification::setNumber(long number)
1959 std::vector<NotificationDetailInfo*> StatusNotification::getDetailInfo() const
1961 return m_detailInfo;
1964 void StatusNotification::setDetailInfo(std::vector<NotificationDetailInfo*> detailInfo)
1966 m_detailInfo = detailInfo;
1969 std::string StatusNotification::getBackgroundImagePath() const
1971 return m_backgroundImagePath;
1974 void StatusNotification::setBackgroundImagePath(std::string backgroundImagePath)
1976 m_backgroundImagePath = backgroundImagePath;
1979 std::vector<std::string> StatusNotification::getThumbnails() const
1981 return m_thumbnails;
1984 void StatusNotification::setThumbnails(std::vector<std::string> thumbnails)
1986 m_thumbnails = thumbnails;
1989 std::string StatusNotification::getSoundPath() const
1994 void StatusNotification::setSoundPath(std::string soundPath)
1996 m_soundPath = soundPath;
1999 bool StatusNotification::getVibration() const
2004 void StatusNotification::setVibration(bool vibration)
2006 m_vibration = vibration;
2009 ApplicationControl StatusNotification::getAppControl() const
2011 return m_appControl;
2014 void StatusNotification::setAppControl(ApplicationControl appControl)
2016 m_appControl = appControl;
2019 ApplicationId StatusNotification::getAppId() const
2024 void StatusNotification::setAppId(ApplicationId appId)
2029 std::string StatusNotification::getProgressType() const
2031 return m_progressType;
2034 void StatusNotification::setProgressType(std::string progressType)
2036 m_progressType = progressType;
2039 unsigned long StatusNotification::getProgressValue() const
2041 return m_progressValue;
2044 void StatusNotification::setProgressValue(unsigned long progressValue)
2046 m_progressValue = progressValue;