Update change log and spec for wrt-plugins-tizen_0.4.15
[platform/framework/web/wrt-plugins-tizen.git] / src / Notification / StatusNotification.cpp
1 //
2 // Tizen Web Device API
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 //
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
8 //
9 // http://www.apache.org/licenses/LICENSE-2.0
10 //
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.
16 //
17
18 #include <PlatformException.h>
19 #include <Logger.h>
20 #include <sstream>
21 #include <appsvc/appsvc.h>
22
23 #include "StatusNotification.h"
24
25 namespace DeviceAPI {
26 namespace Notification {
27
28 #define DEFAULT_ICON_PATH "/opt/share/icons/default/"
29 #define MAX_NOTIFICATION_DETAIL_INFO_LENGTH 2
30 #define MAX_THUMBNAIL_LENGTH 4
31
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);
34
35 //callback functions.
36 static bool service_extra_data_cb(service_h service, const char *key, void *user_data)
37 {
38         LogInfo("OK");
39         char **value = NULL;
40         int length = 0;
41
42         if (user_data != NULL && key != NULL)
43         {       
44                 LogInfo("user data & key is existed");
45
46                 DeviceAPI::Application::ApplicationControlPtr* appControl = 
47                         (DeviceAPI::Application::ApplicationControlPtr*)(user_data);
48
49                 DeviceAPI::Application::ApplicationControlDataPtr data(new DeviceAPI::Application::ApplicationControlData());
50                 LogInfo("key = " << key);
51                 std::string keyStr = key;
52                 std::vector<std::string> keyValue;
53                 int index = 0;
54
55                 if (service_get_extra_data_array((*appControl)->getService_h(), key, &value, &length) == SERVICE_ERROR_NONE)
56                 {
57                         LogInfo("extra_data_array length = " << length);
58                         
59                         if (value != NULL && length != 0)
60                         {
61                                 LogInfo("extra_data_length = " << length);
62                                 data->setKey(key);
63                                 for (index = 0; index < length; index++)
64                                 {
65                                         LogInfo("Value=" << value[index]);
66                                         keyValue.push_back(value[index]);
67                                 }
68                                 
69                                 data->setValue(keyValue);
70                                 (*appControl)->addAppControlData(data);
71                         }
72                         
73                         if(value)
74                                 free(value);
75                 }
76         }
77         return true;
78 }
79
80 static bool service_extra_data_delete_cb(service_h service, const char *key, void *user_data)
81 {
82         LogInfo("OK");
83         if (key != NULL)
84         {       
85                 LogInfo("del key = " << key);
86                 
87                 if (service_remove_extra_data(service, key) != SERVICE_ERROR_NONE)
88                 {
89                         LogWarning("remove extra data failed");
90                         return false;
91                 }
92         }
93         return true;
94 }
95
96 StatusNotification::StatusNotification(NotificationType statusType) :
97         m_notiType(NOTI_TYPE_NONE),
98         m_service(NULL),
99         m_notiHandle(NULL),
100         m_progressType(NOTI_PROGRESS_TYPE_PERCENTAGE),
101         m_notiUpdated(false)
102 {
103         LogInfo("statusType =" << statusType);
104
105         notification_type_e type = NOTIFICATION_TYPE_NONE;
106         setNotiType(statusType);
107
108         if (statusType == NOTI_TYPE_SIMPLE || statusType == NOTI_TYPE_MUTIPLE || statusType == NOTI_TYPE_THUMBNAIL)
109         {
110                 type = NOTIFICATION_TYPE_NOTI;
111         }
112         else if ( statusType == NOTI_TYPE_ONGOING || statusType == NOTI_TYPE_PROGRESS)
113         {
114                 type = NOTIFICATION_TYPE_ONGOING;
115         }
116         else
117         {
118                 LogInfo(" invalide noti type");
119                 throw TypeMismatchException("value is not notification type");
120         }
121
122         setProgressType(NOTI_PROGRESS_TYPE_PERCENTAGE); //default
123
124         LogInfo("Notification Type : " << type);
125
126         notification_h noti = notification_create(type);        //create notificatin.
127         if ( noti )
128         {
129                 LogInfo("noti =" << noti);
130                 setNotificationHandle((void*)noti);
131 #if 0           
132                 if ( statusType == NOTI_TYPE_PROGRESS)
133                 {
134                         notification_update_progress(noti, NOTIFICATION_PRIV_ID_NONE, getProgressValue());
135                 }
136 #endif
137                 
138         }
139         else
140         {
141                 throw UnknownException("can't make new notification object");
142         }
143         
144         //m_detailInfos = new std::vector<NotificationDetailInfo*>();   
145         //m_thumbs = new std::vector<std::string>();
146         
147 }
148
149 StatusNotification::StatusNotification(void* noti) :
150         m_notiType(NOTI_TYPE_NONE),
151         m_service(NULL),
152         m_notiHandle(NULL),
153         m_progressType(NOTI_PROGRESS_TYPE_PERCENTAGE),
154         m_notiUpdated(false)
155 {
156         LogInfo("noti : " << noti);
157         
158         notification_h notification = (notification_h)noti;
159
160         if ( notification )
161         {
162                 NotificationType type = NOTI_TYPE_NONE;
163                 notification_type_e noti_type = NOTIFICATION_TYPE_NONE;
164                 notification_ly_type_e noti_layout = NOTIFICATION_LY_NONE;
165
166                 notification_get_type(notification, &noti_type);
167                 notification_get_layout(notification, &noti_layout);
168
169                 //get type.
170                 if ( noti_type == NOTIFICATION_TYPE_NOTI )
171                 {
172                         if ( noti_layout == NOTIFICATION_LY_NOTI_EVENT_SINGLE || 
173                                 noti_layout == NOTIFICATION_LY_NOTI_EVENT_MULTIPLE )
174                         {
175                                 type = NOTI_TYPE_SIMPLE;
176                         }
177                         else if (noti_layout == NOTIFICATION_LY_NOTI_THUMBNAIL)
178                         {
179                                 type = NOTI_TYPE_THUMBNAIL;
180                         }
181                 }
182                 else if ( noti_type == NOTIFICATION_TYPE_ONGOING)
183                 {
184                         if ( noti_layout == NOTIFICATION_LY_ONGOING_EVENT )
185                         {
186                                 type = NOTI_TYPE_ONGOING;
187                         }
188                         else if ( noti_layout == NOTIFICATION_LY_ONGOING_PROGRESS)
189                         {
190                                 type = NOTI_TYPE_PROGRESS;
191                         }
192                 }
193
194                 LogInfo(" notification type  =" << type);
195                 setNotiType(type);
196                 setProgressType(NOTI_PROGRESS_TYPE_PERCENTAGE); //default.
197                 
198                 setNotificationHandle((void*)notification);
199                 loadThumbnails();
200                 loadDetailInfos();
201
202                  if ( type  == NOTI_TYPE_PROGRESS)
203                 {
204                         notification_update_progress(notification, NOTIFICATION_PRIV_ID_NONE, getProgressValue());
205                 }
206
207                 //service
208                 bundle *bSvc = NULL;
209
210                 int ret =  notification_get_execute_option(notification, NOTIFICATION_EXECUTE_TYPE_SINGLE_LAUNCH, NULL, &bSvc);
211                 LogInfo("ret = " << ret); 
212                 if (ret == NOTIFICATION_ERROR_NONE)
213                 {
214                         LogInfo(" bundle = " << bSvc);
215                         if (bSvc)
216                         {
217                                 LogInfo("bundle is valid");     
218                                 int ret = service_create_event(bSvc, &m_service);
219                                 if (ret != SERVICE_ERROR_NONE)
220                                 {
221                                         LogInfo("Service Create Event Error");
222                                         throw UnknownException("can't make service object");
223                                 }
224                         }
225                 }
226                 else
227                 {
228                         notification_free(notification);
229                         throw UnknownException("can't get service data");
230                 }
231                 
232         }
233         else
234         {
235                 throw InvalidValuesException("It is not notification object.");
236         }
237         
238 }
239
240 StatusNotification::StatusNotification(int privID) :
241         m_notiType(NOTI_TYPE_NONE),
242         m_service(NULL),
243         m_notiHandle(NULL),
244         m_progressType(NOTI_PROGRESS_TYPE_PERCENTAGE),
245         m_notiUpdated(false)
246 {
247         LogInfo("priv ID : " << privID);
248
249         notification_h notification = notification_load( NULL, privID); //load notification.
250         LogInfo(" notification " << notification);
251
252         if ( notification )
253         {
254                 NotificationType type = NOTI_TYPE_NONE; 
255                 notification_type_e noti_type = NOTIFICATION_TYPE_NONE;
256                 notification_ly_type_e noti_layout = NOTIFICATION_LY_NONE;
257                 
258                 notification_get_type(notification, &noti_type);
259                 notification_get_layout(notification, &noti_layout);
260                 
261                 if ( noti_type == NOTIFICATION_TYPE_NOTI )
262                 {
263                         if ( noti_layout == NOTIFICATION_LY_NOTI_EVENT_SINGLE || 
264                                 noti_layout == NOTIFICATION_LY_NOTI_EVENT_MULTIPLE )
265                         {
266                                 type = NOTI_TYPE_SIMPLE;
267                         }
268                         else if (noti_layout == NOTIFICATION_LY_NOTI_THUMBNAIL)
269                         {
270                                 type = NOTI_TYPE_THUMBNAIL;
271                         }
272                 }
273                 else if ( noti_type == NOTIFICATION_TYPE_ONGOING)
274                 {
275                         if ( noti_layout == NOTIFICATION_LY_ONGOING_EVENT )
276                         {
277                                 type = NOTI_TYPE_ONGOING;
278                         }
279                         else if ( noti_layout == NOTIFICATION_LY_ONGOING_PROGRESS)
280                         {
281                                 type = NOTI_TYPE_PROGRESS;
282                         }
283                 }
284
285                 LogInfo(" notification type  =" << type);
286                 setNotiType(type);
287                 setProgressType(NOTI_PROGRESS_TYPE_PERCENTAGE); //default.      
288                 setNotificationHandle((void*)notification);
289                 loadThumbnails();
290                 loadDetailInfos();
291
292                  if ( type  == NOTI_TYPE_PROGRESS)
293                 {
294                         notification_update_progress(notification, NOTIFICATION_PRIV_ID_NONE, getProgressValue());
295                 }
296
297                 //service
298                 bundle *bSvc = NULL;
299
300                 int ret =  notification_get_execute_option(notification, NOTIFICATION_EXECUTE_TYPE_SINGLE_LAUNCH, NULL, &bSvc);
301                 LogInfo("ret = " << ret); 
302                 if (ret == NOTIFICATION_ERROR_NONE)
303                 {
304                         LogInfo(" bundle = " << bSvc);
305                         if (bSvc)
306                         {
307                                 LogInfo("bundle is valid");     
308                                 int ret = service_create_event(bSvc, &m_service);
309                                 if (ret != SERVICE_ERROR_NONE)
310                                 {
311                                         LogInfo("Service Create Event Error");
312                                         throw UnknownException("can't make service object");
313                                 }
314                         }
315                 }
316                 else
317                 {
318                         notification_free(notification);
319                         throw UnknownException("can't get service data");
320                 }
321                 
322         }
323         else
324         {
325                 throw NotFoundException("It is not notification ID or removed notification");
326         }
327         
328 }
329
330 StatusNotification::~StatusNotification() 
331 {
332         LogInfo(" notification = " << m_notiHandle);
333
334         //clear thumbnail.
335         //clearDetailInfos();
336         
337         if (m_notiHandle)
338         {
339 #if 0
340                 LogInfo(" service = " << m_service);
341                 if (m_service != NULL)
342                 {
343                         service_destroy(m_service);
344                         m_service = NULL;
345                 }
346 #endif          
347                 if (notification_free(m_notiHandle) != NOTIFICATION_ERROR_NONE)
348                 {
349                         throw UnknownException("notification free failed...");
350                 }
351                 
352                 m_notiHandle = NULL;
353         }
354 }
355
356 int StatusNotification::getID()
357 {
358         int id = -1;    // notification not inserted yet.
359         if (m_notiHandle)
360         {
361                 notification_get_id(m_notiHandle, NULL, &id);
362         }
363
364         return id;
365 }
366
367 std::string StatusNotification::getStatusType()
368 {
369         std::string type;
370         
371         if ( NOTI_TYPE_SIMPLE ==  getNotiType())
372         {
373                 type = "SIMPLE";
374         }
375         else if ( NOTI_TYPE_ONGOING ==  getNotiType())
376         {
377                 type = "ONGOING";
378         }
379         else if ( NOTI_TYPE_PROGRESS ==  getNotiType())
380         {
381                 type = "PROGRESS"; 
382         }
383         else if ( NOTI_TYPE_THUMBNAIL ==  getNotiType())
384         {
385                 type = "THUMBNAIL"; 
386         }
387
388         return type;
389                 
390 }
391
392
393
394 void StatusNotification::setStatusType(std::string type)
395 {
396         LogInfo("type = " << type);
397         
398         NotificationType notiType = NOTI_TYPE_NONE; 
399         
400         if( type.compare(TIZEN_STATUS_NOTIFICATION_TYPE_SIMPLE) == 0)
401                 notiType = NOTI_TYPE_SIMPLE;
402         else if( type.compare(TIZEN_STATUS_NOTIFICATION_TYPE_THUMBNAIL) == 0)
403                 notiType = NOTI_TYPE_THUMBNAIL;
404         else if( type.compare(TIZEN_STATUS_NOTIFICATION_TYPE_ONGOING) == 0)
405                 notiType = NOTI_TYPE_ONGOING;    
406         else if( type.compare(TIZEN_STATUS_NOTIFICATION_TYPE_PROGRESS) == 0)
407                 notiType = NOTI_TYPE_PROGRESS;
408         else
409         throw InvalidValuesException("Invalid Status Type.");
410
411         LogInfo("Notification type = " << notiType);
412         setNotiType(notiType);
413 }
414
415 time_t StatusNotification::getPostedTime()
416 {
417         LogInfo("get m_notiHandle = " << m_notiHandle);
418         
419         time_t postedTime = 0;
420         
421         if (m_notiHandle)
422         {                       
423                 if (notification_get_insert_time(m_notiHandle, &postedTime) != NOTIFICATION_ERROR_NONE)
424                 {
425                         throw UnknownException("get notification posted time error");
426                 }
427         }
428         
429         LogInfo("posted Time =" << ctime(&postedTime));
430         return postedTime;
431 }
432
433 std::string StatusNotification::getTitle()
434 {
435         if (m_notiHandle)
436         {
437                 char *title = NULL;
438         
439                 if (notification_get_text(m_notiHandle,NOTIFICATION_TEXT_TYPE_TITLE, &title) != NOTIFICATION_ERROR_NONE)
440                 {
441                         throw UnknownException("get notification title error");
442                 }
443
444                 std::string notiTitle(title);
445                 return notiTitle;       
446         }
447         else
448         {
449                 throw UnknownException("notification handle is null");
450         }
451 }
452
453 void StatusNotification::setTitle(std::string title)
454 {
455         LogInfo("Title : " << title);
456         if (m_notiHandle)
457         {
458                 LogInfo("get Title : " << getTitle());
459                 if((getTitle()).compare(title)) //different value.
460                 {
461                         if (notification_set_text(m_notiHandle, NOTIFICATION_TEXT_TYPE_TITLE, title.c_str(), 
462                                 NULL, NOTIFICATION_VARIABLE_TYPE_NONE ) != NOTIFICATION_ERROR_NONE)
463                         {
464                                 throw UnknownException("set notification title error");
465                         }
466                         
467                         setUpdatedFlag(true);
468                 }
469                 else
470                 {
471                         LogInfo(" title = " << title << " getTitle = " << getTitle());
472                 }
473         }
474         else
475         {       
476                 LogDebug("noti Handle is NULL");
477                 throw UnknownException("notification handle is null");
478         }
479 }
480
481
482 std::string StatusNotification::getContent()
483 {
484         LogInfo("get Content handle: " << m_notiHandle);
485         if (m_notiHandle)
486         {
487                 char *content = NULL;
488
489                 if (notification_get_text(m_notiHandle, NOTIFICATION_TEXT_TYPE_CONTENT, &content) != NOTIFICATION_ERROR_NONE)
490                 {
491                         throw UnknownException("get notification Content error");
492                 }
493                 
494                 LogInfo(" get Content : " << content);
495
496                 std::string notiContent;
497                 
498                 if(content)
499                         notiContent = content;
500
501                 return notiContent;
502                 
503         }
504         else
505         {
506                 throw UnknownException("notification handle is null");
507         }
508         
509 }
510
511 void StatusNotification::setContent(std::string content)
512 {
513         LogInfo("Content : " << content);
514         if (m_notiHandle)
515         {
516                 if((getContent()).compare(content))     //different value.
517                 {
518                         if (notification_set_text(m_notiHandle, NOTIFICATION_TEXT_TYPE_CONTENT, content.c_str(),
519                                 NULL, NOTIFICATION_VARIABLE_TYPE_NONE ) != NOTIFICATION_ERROR_NONE)
520                         {
521                                 throw UnknownException("set notification content error");
522                         }
523                         setUpdatedFlag(true);
524                 }
525         }
526         else
527         {       
528                 LogDebug("noti Handle is NULL");
529                 throw UnknownException("notification handle is null");
530         }
531 }
532
533 std::string StatusNotification::getIconPath()
534 {
535
536         LogInfo("m_notiHandle = " << m_notiHandle);
537         if (m_notiHandle)
538         {
539                 char *iconPath = NULL;
540                 if (notification_get_image(m_notiHandle, NOTIFICATION_IMAGE_TYPE_ICON,  &iconPath) != NOTIFICATION_ERROR_NONE)
541                 {
542                         throw UnknownException("get notification icon path error");
543                 }
544
545                 std::string notiIconPath(iconPath);
546                 LogInfo("icon Path = " << iconPath);
547                 
548                 //if icon path invalid, return empty string.
549                 if ( notiIconPath.find(DEFAULT_ICON_PATH,0) == std::string::npos)
550                         return notiIconPath;    
551                 else
552                 {
553                         return std::string(""); //return empty string.
554                 }
555         }
556         else
557         {
558                 throw UnknownException("notification handle is null");
559         }
560 }
561
562 void StatusNotification::setIconPath(const std::string& iconPath)
563 {
564         if (m_notiHandle)
565         {
566                 LogInfo("icon path = " << iconPath << " origin icon path = " << getIconPath());
567                 if( getIconPath().compare(iconPath))
568                 {
569                         if (notification_set_image(m_notiHandle,NOTIFICATION_IMAGE_TYPE_ICON, iconPath.c_str()) != NOTIFICATION_ERROR_NONE)
570                         {
571                                 throw UnknownException("set notification icon error");
572                         }
573                         setUpdatedFlag(true);
574                 }
575         }
576         else
577         {
578                 LogDebug("noti Handle is NULL");
579                 throw UnknownException("notification handle is null");
580         }
581 }
582
583 std::string StatusNotification::getSoundPath()
584 {
585         LogInfo("Handle = " << m_notiHandle);
586
587         if (m_notiHandle)
588         {
589                 const char *soundPath = NULL;
590                 notification_sound_type_e type = NOTIFICATION_SOUND_TYPE_NONE;
591                 
592                 if (notification_get_sound(m_notiHandle, &type,  &soundPath) != NOTIFICATION_ERROR_NONE)
593                 {
594                         throw UnknownException("get notification sound error");
595                 }
596
597                 LogInfo(" sound type = " << type << " path = " << soundPath);
598                 if ( type == NOTIFICATION_SOUND_TYPE_USER_DATA )
599                 {
600                         LogInfo("soundPath = " << soundPath);
601                         return std::string(soundPath); 
602                 }
603                 else
604                 {
605                         return std::string("");
606                 }
607         }
608         else
609         {
610                 LogDebug("noti Handle is NULL");
611                 throw UnknownException("notification handle is null");
612         }
613 }
614
615 void StatusNotification::setSoundPath(const std::string& sound)
616 {
617         if (m_notiHandle)
618         {
619                 LogInfo("sound path = " << sound << " origin sound path = " << getSoundPath());
620                 
621                 if( getSoundPath().compare(sound))
622                 {
623                         if (notification_set_sound(m_notiHandle,NOTIFICATION_SOUND_TYPE_USER_DATA, sound.c_str()) != NOTIFICATION_ERROR_NONE)
624                         {
625                                 throw UnknownException("set notification sound error");
626                         }
627                         setUpdatedFlag(true);
628                 }
629
630                 if (sound.empty()) 
631                 {
632                     LogInfo("sound path is NULL");
633                     if (notification_set_sound(m_notiHandle,NOTIFICATION_SOUND_TYPE_DEFAULT, sound.c_str()) != NOTIFICATION_ERROR_NONE)
634                     {
635                         throw UnknownException("set notification sound error");
636                     }
637                 }
638         }
639         else
640         {       
641                 LogDebug("noti Handle is NULL");
642                 throw UnknownException("notification handle is null");
643         }
644 }
645
646 bool StatusNotification::getDefaultVibration()
647 {
648         LogInfo("getDefaultVibration");
649         if (m_notiHandle)
650         {
651                 notification_vibration_type_e vib_type;
652                 if (notification_get_vibration(m_notiHandle, &vib_type,  NULL) != NOTIFICATION_ERROR_NONE)
653                 {
654                         throw UnknownException("set notification sound error");
655                 }
656
657                 if (vib_type == NOTIFICATION_VIBRATION_TYPE_DEFAULT)
658                 {
659                         return true;
660                 }
661                 else
662                 {
663                         return false;
664                 }
665         }
666         else
667         {
668                 LogDebug("noti Handle is NULL");
669                 throw UnknownException("notification handle is null");
670         }
671
672         return false;
673 }
674
675 void StatusNotification::setDefaultVibration(const bool& vibration) 
676 {
677     LogInfo("vibration = " << vibration);
678         if (m_notiHandle)
679         {
680                 notification_vibration_type_e vib_type = NOTIFICATION_VIBRATION_TYPE_NONE;
681                 
682                 if (getDefaultVibration() != vibration)
683                 {
684                         if (vibration)
685                         {
686                                 vib_type = NOTIFICATION_VIBRATION_TYPE_DEFAULT;
687                         }
688                         
689                         if (notification_set_vibration(m_notiHandle, vib_type , NULL) != NOTIFICATION_ERROR_NONE)
690                         {
691                                 throw UnknownException("set notification sound error");
692                         }
693                         setUpdatedFlag(true);
694                 }
695         }
696         else
697         {
698                 LogDebug("noti Handle is NULL");
699                 throw UnknownException("notification handle is null");
700         }
701
702 }
703
704 DeviceAPI::Application::ApplicationControlPtr StatusNotification::getApplicationControl()
705 {
706
707     service_h service = NULL;
708     char *tempStr = NULL;
709
710     DeviceAPI::Application::ApplicationControlPtr appControl(new DeviceAPI::Application::ApplicationControl());
711
712     try {
713                 if (m_service)
714                 {
715                         appControl->setService_h(m_service);
716                         // mandatory
717                         if(service_get_operation(m_service, &tempStr) == SERVICE_ERROR_NONE)
718                         {
719                                 LogDebug("Operation Str = " << tempStr);
720                                 if (tempStr) 
721                                 {
722                                         appControl->setOperation(tempStr);
723                                         free(tempStr);
724                                         tempStr = NULL;
725                                 }
726                         }
727
728                         // optional
729                         if (service_get_mime(m_service, &tempStr) == SERVICE_ERROR_NONE)
730                         {
731                                 LogDebug("Mime Str = " << tempStr);
732                                 if (tempStr) 
733                                 {
734                                         appControl->setMime(tempStr);
735                                         free(tempStr);
736                                         tempStr = NULL;
737                                 }
738                         }
739
740                         // optional
741                         if (service_get_uri(m_service, &tempStr) == SERVICE_ERROR_NONE)
742                         {
743                                 LogDebug("Uri Str = " << tempStr);
744                                 if (tempStr)
745                                 {
746                                         appControl->setUri(tempStr);
747                                         free(tempStr);
748                                         tempStr = NULL;
749                                 }
750                         }
751
752                         if (service_get_category(m_service, &tempStr) == SERVICE_ERROR_NONE)
753                         {
754                                 LogDebug("Category Str = " << tempStr);
755                                 if (tempStr)
756                                 {
757                                         appControl->setCategory(tempStr);
758                                         free(tempStr);
759                                         tempStr = NULL;
760                                 }
761                         }
762                         
763                         // optional
764                         if ( service_foreach_extra_data(m_service, service_extra_data_cb,(void*)&appControl) != SERVICE_ERROR_NONE)
765                         {
766                                 ThrowMsg(WrtDeviceApis::Commons::UnknownException, "get notification service uri error");
767                         }
768
769                         return appControl;
770                 }
771
772         }
773         Catch (WrtDeviceApis::Commons::Exception) 
774         {
775                 if (tempStr) 
776                 {
777                         free(tempStr);
778                         tempStr = NULL;
779                 }
780
781                 if (service)
782                 {
783                         free(service);
784                         service = NULL;
785                 }
786
787                 LogWarning(_rethrown_exception.GetMessage());
788         }
789         
790     return appControl;
791 }
792
793 void StatusNotification::setApplicationControl(DeviceAPI::Application::ApplicationControlPtr control)
794 {
795         LogInfo("Entered m_service : " << m_service << " control : " << control);
796
797         //delete old service.
798         if (m_service)
799         {
800                 service_destroy(m_service);
801                 m_service = NULL;
802         }
803         
804         if(service_create(&m_service) != SERVICE_ERROR_NONE)
805         {
806                 throw UnknownException("service creation error");
807         }
808         else
809         {
810                 LogInfo("getOperation : " << control->getOperation().c_str());
811                 if (control->getOperation().size() != 0)
812                 {
813                         if (service_set_operation(m_service, control->getOperation().c_str()) != SERVICE_ERROR_NONE)
814                         {
815                                 throw UnknownException("service set operation error");
816                         }
817                 }
818                         
819                 // optional
820                 LogInfo("getUri : " << control->getUri().c_str());
821                 if (control->getUri().size() != 0)
822                 {
823                         if (service_set_uri(m_service, control->getUri().c_str() ) != SERVICE_ERROR_NONE)
824                         {
825                                 throw UnknownException("service set uri error");
826                         }
827                 }
828         
829                 // optional
830                 LogInfo("getMime : " << control->getMime().c_str());
831                 if (control->getMime().size() != 0)
832                 {
833                         if (service_set_mime(m_service, control->getMime().c_str() ) != SERVICE_ERROR_NONE)
834                         {
835                                 throw UnknownException("service set mime error");
836                         }
837                 }
838         
839                 LogInfo("Category : " << control->getCategory().c_str());
840                 if (control->getCategory().size() != 0)
841                 {
842                         if (service_set_category(m_service, control->getCategory().c_str() ) != SERVICE_ERROR_NONE)
843                         {
844                                 throw UnknownException("service set mime error");
845                         }
846                 }
847
848                 //remove key
849                 //if ( service_foreach_extra_data(m_service, service_extra_data_delete_cb, NULL) != SERVICE_ERROR_NONE)
850                 //{
851                 //      throw UnknownException("get notification service uri error");
852                 //}
853                 
854                 std::vector<DeviceAPI::Application::ApplicationControlDataPtr> appControlDataArray = control->getAppControlDataArray();
855                 size_t index = 0;
856         
857                 LogInfo (" App Control Datas Count : " << appControlDataArray.size());
858         
859                 DeviceAPI::Application::ApplicationControlDataArray::iterator iter;
860         
861                 for(iter = appControlDataArray.begin(); iter != appControlDataArray.end(); iter++)
862                 {
863                         DeviceAPI::Application::ApplicationControlDataPtr appControlData = *iter;
864                         std::string key = appControlData->getKey();
865                         LogInfo(" key : " << key);
866                 
867                         if (key.empty())
868                                 continue;
869                 
870                         std::vector<std::string> value = appControlDataArray[index]->getValue();
871                         const char **arrayValue = (const char**)calloc(sizeof(char*), value.size());
872         
873                         for (size_t indexArray = 0; indexArray < value.size(); indexArray++)
874                         {
875                                 arrayValue[indexArray] = (char*)value[indexArray].c_str();
876                                 LogInfo( " value : " << arrayValue[indexArray]);
877                         }
878         
879                         const char* strKey = key.c_str();
880                         LogInfo( " value size: " << value.size());
881                         if (service_add_extra_data_array(m_service, strKey, arrayValue, value.size()) != SERVICE_ERROR_NONE)
882                         {
883                                 throw UnknownException("service set extra data error");                 
884                         }
885                          
886                         if (arrayValue)
887                                 free(arrayValue);
888                 }                                       
889         
890                 bundle *bundle_data=NULL;
891                 
892                 if(service_to_bundle(m_service, &bundle_data) != SERVICE_ERROR_NONE)
893                 {
894                         throw UnknownException("service get bundle");                   
895                 }
896
897                 LogDebug("bundle_data : " << bundle_data);
898                 
899                 if (bundle_data)
900                 {
901                         notification_set_execute_option(m_notiHandle, NOTIFICATION_EXECUTE_TYPE_SINGLE_LAUNCH,
902                                 NULL,NULL, bundle_data);
903                 }
904                                 
905         }
906         
907 }
908
909 void StatusNotification::setApplicationId(const std::string& appId)
910 {
911         LogInfo("m_service = "  << m_service << " appId = " << appId);
912         if (!m_service)
913         {       
914                 if (service_create(&m_service) != SERVICE_ERROR_NONE)
915                 {
916                         LogWarning("Create Service Failed..");
917                         throw DeviceAPI::Common::UnknownException ("service creation error");
918                 }
919         }
920
921         if (m_service)
922         {
923                 if (service_set_app_id(m_service, appId.c_str())!= SERVICE_ERROR_NONE)
924                 {
925                         throw DeviceAPI::Common::UnknownException ("service set appId error");  
926                 }
927         }
928
929 }
930
931 std::string StatusNotification::getApplicationId()
932 {
933         std::string retString;
934         service_h service = NULL;
935         char* appIdStr = NULL;
936         
937         if (m_service != NULL)
938         {
939                 int retcode;
940                 retcode = service_clone(&service, m_service);   
941                 
942                 if (retcode != SERVICE_ERROR_NONE)
943                 {
944                         if (retcode == SERVICE_ERROR_OUT_OF_MEMORY)
945                         {
946                                 LogWarning("SERVICE_ERROR_OUT_OF_MEMORY");
947                         }
948                         else
949                         {
950                                 LogWarning("UI_NOTIFICATION_ERROR_INVALID_PARAMETER");
951                         }
952                         throw DeviceAPI::Common::UnknownException ("get notification service error ");
953                 }
954                 else
955                 {
956                         if (service == NULL)
957                         {
958                                 throw DeviceAPI::Common::UnknownException ("get notification service ok, but service null");                    
959                         }
960                 }
961         }
962
963         if (service != NULL) 
964         {
965                 if (service_get_app_id(service, &appIdStr) != SERVICE_ERROR_NONE)
966                 {
967                         throw DeviceAPI::Common::UnknownException ("get a appId error");
968                 }
969
970                 if (appIdStr != NULL)
971                 {
972                         retString = appIdStr;
973                         free(appIdStr);
974                 }
975         }
976         LogInfo(retString);
977         
978         return retString;
979
980 }
981
982 double StatusNotification::getProgressValue() 
983 {
984         double value = 0.0;
985         
986         if (m_notiHandle)
987         {
988                 NotificationProgressType progressType = getProgressType();
989         
990                 if (progressType == NOTI_PROGRESS_TYPE_SIZE)
991                 {
992                         if (notification_get_size(m_notiHandle, &value) != NOTIFICATION_ERROR_NONE)
993                         {
994                                 throw UnknownException("get notification size error");
995                         }
996                         LogInfo("Size Val = " << value);
997                 }
998                 else if ( progressType == NOTI_PROGRESS_TYPE_PERCENTAGE )
999                 {
1000                         if (notification_get_progress(m_notiHandle, &value) != NOTIFICATION_ERROR_NONE)
1001                         {
1002                                 throw UnknownException("get notification percentage error");
1003                         }
1004                         LogInfo("Percentage Val = " << value);
1005                 }
1006                 else
1007                 {
1008                         throw UnknownException("get notification progress type error");
1009                 }
1010         }
1011         else
1012         {
1013                 LogDebug("noti Handle is NULL");
1014         }
1015         LogInfo("value = " << value);
1016         return value;
1017         
1018 }
1019
1020 void StatusNotification::setProgressValue(const double &progressValue)
1021 {
1022         if (m_notiHandle)
1023         {       
1024                 NotificationProgressType progressType = getProgressType();
1025                 LogInfo("Progress Type : " << progressType);
1026                 
1027                 double val = getProgressValue();
1028                 LogInfo("Progress value = " << progressValue << " origin Progress Value =" << val);
1029                 
1030                 if (progressType == NOTI_PROGRESS_TYPE_SIZE)
1031                 {
1032                         if (notification_set_size(m_notiHandle, progressValue) != NOTIFICATION_ERROR_NONE)
1033                         {
1034                                 throw UnknownException("set notification progress size error");
1035                         }
1036                 }
1037                 else if ( progressType == NOTI_PROGRESS_TYPE_PERCENTAGE )
1038                 {       
1039                         if (notification_set_progress(m_notiHandle, progressValue) != NOTIFICATION_ERROR_NONE)
1040                         {
1041                                 throw UnknownException("set notification percentage error");
1042                         }
1043                 }
1044                 else
1045                 {
1046                         throw UnknownException("get notification progress type error");
1047                 }
1048         }
1049         else
1050         {
1051                 LogDebug("noti Handle is NULL");
1052                 throw UnknownException( "notification handle is null");
1053         }
1054 }
1055
1056 std::string StatusNotification::getSubIconPath()
1057 {
1058         LogInfo("Handle = " << m_notiHandle);
1059         if (m_notiHandle)
1060         {
1061                 char *subIconPath = NULL;
1062         
1063                 if (notification_get_image(m_notiHandle, NOTIFICATION_IMAGE_TYPE_ICON_SUB,  &subIconPath) != NOTIFICATION_ERROR_NONE)
1064                 {
1065                         throw UnknownException("get notification sub icon error");
1066                 }
1067
1068                 std::string notiSubIconPath;
1069                 if(subIconPath)
1070                         notiSubIconPath = subIconPath;
1071                 return notiSubIconPath; 
1072         }
1073         else
1074         {
1075                 throw UnknownException("notification handle is null");
1076         }
1077
1078 }
1079
1080 void StatusNotification::setSubIconPath(const std::string& subIconPath)
1081 {
1082         if (m_notiHandle)
1083         {
1084                 LogInfo(" subIconPath = " << subIconPath << " origin SubIconPath = " << getSubIconPath());      
1085
1086                 if( getSubIconPath().compare(subIconPath))
1087                 {
1088                         if (notification_set_image(m_notiHandle,NOTIFICATION_IMAGE_TYPE_ICON_SUB, subIconPath.c_str()) != NOTIFICATION_ERROR_NONE)
1089                         {
1090                                 throw UnknownException("set notification sound error");
1091                         }
1092                         setUpdatedFlag(true);
1093                 }
1094         }
1095         else
1096         {       
1097                 LogDebug("noti Handle is NULL");
1098                 throw UnknownException("notification handle is null");
1099         }
1100 }
1101
1102 #if 0
1103 std::string StatusNotification::getInformation(int index)
1104 {
1105         if (m_notiHandle)
1106         {
1107                 notification_text_type_e type = NOTIFICATION_TEXT_TYPE_NONE; 
1108                 switch (index)
1109                 {
1110                         case 0:
1111                                 type = NOTIFICATION_TEXT_TYPE_INFO_1;
1112                                 break;
1113                         case 1:
1114                                 type = NOTIFICATION_TEXT_TYPE_INFO_2;
1115                                 break;
1116                         case 2:
1117                                 type = NOTIFICATION_TEXT_TYPE_INFO_3;
1118                                 break;
1119                         default :
1120                                 type = NOTIFICATION_TEXT_TYPE_NONE;
1121                 }
1122                 char *info = NULL;
1123                 
1124                 if (NOTIFICATION_TEXT_TYPE_NONE != type && notification_get_text(m_notiHandle, type, &info) != NOTIFICATION_ERROR_NONE)
1125                 {
1126                         throw UnknownException("get notification information error");
1127                 }
1128
1129                 std::string strInfo;
1130                 if (info)
1131                         strInfo = info;
1132                 LogDebug(" info " << strInfo);
1133                 return strInfo;
1134
1135         }
1136         else
1137         {       
1138                 LogDebug("noti Handle is NULL");
1139                 throw UnknownException("notification handle is null");
1140         }
1141         
1142 }
1143
1144 void StatusNotification::setInformation( const std::string& info, int index)
1145 {
1146
1147         if (m_notiHandle)
1148         {
1149                 int idx = index;
1150                 LogDebug(" index : " << idx);
1151                 LogDebug(" log : " << info);
1152                 notification_text_type_e type = NOTIFICATION_TEXT_TYPE_NONE; 
1153                 
1154                 switch (idx)
1155                 {
1156                         case 0:
1157                                 type = NOTIFICATION_TEXT_TYPE_INFO_1;
1158                                 break;
1159                         case 1:
1160                                 type = NOTIFICATION_TEXT_TYPE_INFO_2;
1161                                 break;
1162                         case 2:
1163                                 type = NOTIFICATION_TEXT_TYPE_INFO_3;
1164                                 break;
1165                         default :
1166                                 type = NOTIFICATION_TEXT_TYPE_NONE;
1167                 }
1168
1169                 if ( type != NOTIFICATION_TEXT_TYPE_NONE)
1170                 {
1171                         if (getInformation(idx).compare(info))
1172                         {
1173                                 if (notification_set_text(m_notiHandle, type, info.c_str(),
1174                                         NULL, NOTIFICATION_VARIABLE_TYPE_NONE) != NOTIFICATION_ERROR_NONE)
1175                                 {
1176                                         throw UnknownException("set notification sound error");
1177                                 }
1178                                 setUpdatedFlag(true);
1179                         }
1180                 }
1181         }
1182         else
1183         {       
1184                 LogDebug("noti Handle is NULL");
1185                 throw UnknownException("notification handle is null");
1186         }
1187 }
1188
1189 std::string StatusNotification::getSubInformation(int index)
1190 {
1191
1192         if (m_notiHandle)
1193         {
1194                 notification_text_type_e type = NOTIFICATION_TEXT_TYPE_NONE; 
1195                 switch (index)
1196                 {
1197                         case 0:
1198                                 type = NOTIFICATION_TEXT_TYPE_INFO_SUB_1;
1199                                 break;
1200                         case 1:
1201                                 type = NOTIFICATION_TEXT_TYPE_INFO_SUB_2;
1202                                 break;
1203                         case 2:
1204                                 type = NOTIFICATION_TEXT_TYPE_INFO_SUB_3;
1205                                 break;
1206                         default :
1207                                 type = NOTIFICATION_TEXT_TYPE_NONE;
1208                 }
1209                                 
1210                 char *subInfo = NULL;
1211                 
1212                 if (NOTIFICATION_TEXT_TYPE_NONE != type && notification_get_text(m_notiHandle, type, &subInfo) != NOTIFICATION_ERROR_NONE)
1213                 {
1214                         throw UnknownException( "get notification sub information error");
1215                 }
1216
1217                 std::string strSubInfo;
1218                 if (subInfo)
1219                         strSubInfo = subInfo;
1220                 LogDebug(" subInfo " << strSubInfo);
1221                 return strSubInfo;
1222                                 
1223         }
1224         else
1225         {       
1226                 LogDebug("noti Handle is NULL");
1227                 throw UnknownException( "notification handle is null");
1228         }
1229         
1230 }
1231
1232 void StatusNotification::setSubInformation( const std::string& subInfo, int index)
1233 {
1234         if (m_notiHandle)
1235         {
1236                 int idx = index;
1237                 LogDebug(" index : " << idx);
1238                 LogDebug(" log : " << subInfo);
1239                 notification_text_type_e type = NOTIFICATION_TEXT_TYPE_NONE; 
1240                 
1241                 switch (idx)
1242                 {
1243                         case 0:
1244                                 type = NOTIFICATION_TEXT_TYPE_INFO_SUB_1;
1245                                 break;
1246                         case 1:
1247                                 type = NOTIFICATION_TEXT_TYPE_INFO_SUB_2;
1248                                 break;
1249                         case 2:
1250                                 type = NOTIFICATION_TEXT_TYPE_INFO_SUB_3;
1251                                 break;
1252                         default :
1253                                 type = NOTIFICATION_TEXT_TYPE_NONE;
1254                 }
1255
1256                 if ( type != NOTIFICATION_TEXT_TYPE_NONE)
1257                 {
1258                         if (getSubInformation(idx).compare(subInfo))
1259                         {
1260                                 if (notification_set_text(m_notiHandle, type, subInfo.c_str(),
1261                                         NULL, NOTIFICATION_VARIABLE_TYPE_NONE) != NOTIFICATION_ERROR_NONE)
1262                                 {
1263                                         throw UnknownException( "set notification sound error");
1264                                 }
1265                                 setUpdatedFlag(true);
1266                         }
1267                 }
1268         }
1269         else
1270         {       
1271                 LogDebug("noti Handle is NULL");
1272                 throw UnknownException( "notification handle is null");
1273         }
1274                 
1275 }
1276 #endif
1277
1278 void StatusNotification::loadThumbnails()
1279 {
1280         if (m_notiHandle)
1281         {       
1282                 if (!m_thumbs.empty())
1283                         m_thumbs.clear();
1284
1285                 char *thumb = NULL;
1286                 if (notification_get_image(m_notiHandle, NOTIFICATION_IMAGE_TYPE_LIST_1, &thumb) != NOTIFICATION_ERROR_NONE)
1287                 {
1288                         throw UnknownException( "get notification thumbnail error");
1289                 }
1290                 if (thumb)
1291                         m_thumbs.push_back(thumb);
1292                 //else
1293                 //      m_thumbs.push_back(std::string("")); //set empty
1294                 thumb = NULL;
1295                 
1296                 if (notification_get_image(m_notiHandle, NOTIFICATION_IMAGE_TYPE_LIST_2, &thumb) != NOTIFICATION_ERROR_NONE)
1297                 {
1298                         throw UnknownException( "get notification sub information error");
1299                 }       
1300                 if (thumb)
1301                         m_thumbs.push_back(thumb);
1302                 //else
1303                 //      m_thumbs.push_back(std::string("")); //set empty
1304                 thumb = NULL;
1305                 
1306                 if (notification_get_image(m_notiHandle, NOTIFICATION_IMAGE_TYPE_LIST_3, &thumb) != NOTIFICATION_ERROR_NONE)
1307                 {
1308                         throw UnknownException( "get notification sub information error");
1309                 }
1310                 
1311                 if (thumb)
1312                         m_thumbs.push_back(thumb);
1313                 //else
1314                 //      m_thumbs.push_back(std::string("")); //set empty
1315                 thumb = NULL;
1316
1317                 if (notification_get_image(m_notiHandle, NOTIFICATION_IMAGE_TYPE_LIST_4, &thumb) != NOTIFICATION_ERROR_NONE)
1318                 {
1319                         throw UnknownException( "get notification sub information error");
1320                 }
1321                 
1322                 if (thumb)
1323                         m_thumbs.push_back(thumb);
1324                 //else
1325                 //      m_thumbs.push_back(std::string("")); //set empty
1326                 thumb = NULL;
1327 #if 0   
1328                 if (notification_get_image(m_notiHandle, NOTIFICATION_IMAGE_TYPE_LIST_5, &thumb) != NOTIFICATION_ERROR_NONE)
1329                 {
1330                         throw UnknownException( "get notification sub information error");
1331                 }
1332                 
1333                 if (thumb)
1334                         m_thumbs.push_back(thumb);
1335                 else
1336                         m_thumbs.push_back(std::string("")); //set empty
1337                 thumb = NULL;
1338 #endif          
1339                 
1340         }
1341         else
1342         {       
1343                 LogDebug("noti Handle is NULL");
1344                 throw UnknownException( "notification handle is null");
1345         }
1346 }
1347
1348 std::vector<std::string> StatusNotification::getThumbnails()
1349 {
1350         LogInfo(" thumbnail Size : " << m_thumbs.size());
1351         return m_thumbs;
1352 }
1353
1354 std::string StatusNotification::getThumbnail(int index)
1355 {
1356         if (m_notiHandle)
1357         {
1358                 LogInfo(" index : " << index);
1359                 
1360                 notification_image_type_e type = NOTIFICATION_IMAGE_TYPE_NONE; 
1361                 
1362                 switch (index)
1363                 {
1364                         case 0:
1365                                 type = NOTIFICATION_IMAGE_TYPE_LIST_1;
1366                                 break;
1367                         case 1:
1368                                 type = NOTIFICATION_IMAGE_TYPE_LIST_2;
1369                                 break;
1370                         case 2:
1371                                 type = NOTIFICATION_IMAGE_TYPE_LIST_3;
1372                                 break;
1373                         case 3:
1374                                 type = NOTIFICATION_IMAGE_TYPE_LIST_4;
1375                                 break;
1376                         case 4:
1377                                 type = NOTIFICATION_IMAGE_TYPE_LIST_5;
1378                                 break;
1379                         default :
1380                                 type = NOTIFICATION_IMAGE_TYPE_NONE;
1381                 }
1382
1383                 if ( type != NOTIFICATION_IMAGE_TYPE_NONE)
1384                 {
1385                         char *thumb = NULL;
1386                         if (notification_get_image(m_notiHandle, type, &thumb) != NOTIFICATION_ERROR_NONE)
1387                         {
1388                                 throw UnknownException( "set notification thumbnail error");
1389                         }
1390
1391                         std::string thumbnail;
1392                         if(thumb)
1393                                 thumbnail = thumb;
1394                         return thumbnail;
1395                 }
1396                 else
1397                 {
1398                         throw UnknownException( "notification handle is null");
1399                 }
1400                 
1401         }
1402         else
1403         {       
1404                 LogDebug("noti Handle is NULL");
1405                 throw UnknownException( "notification handle is null");
1406         }
1407 #if 0
1408         if (m_thumbs.size() > index)
1409                 return m_thumbs[index];
1410         else
1411                 return std::string("");
1412 #endif
1413
1414 }
1415
1416 void StatusNotification::setThumbnails(std::vector<std::string> thumbs)
1417 {
1418         LogInfo("set thumbnails");
1419         if (m_notiHandle)
1420         {
1421                 std::vector<std::string>::iterator it;
1422
1423                 int idx = 0;
1424                 for (it = thumbs.begin(); it < thumbs.end(); ++it)
1425                 {
1426                         std::string str = *it;
1427                         if ( idx < MAX_THUMBNAIL_LENGTH )
1428                                 setThumbnail(str, idx); //set notification's thumbnail value.
1429                         idx ++;
1430                 }
1431
1432                 m_thumbs = thumbs;
1433         }
1434         else
1435         {       
1436                 LogDebug("noti Handle is NULL");
1437                 throw UnknownException( "notification handle is null");
1438         }
1439 }
1440
1441 void StatusNotification::setThumbnail( const std::string& thumb, int index)
1442 {
1443         if (m_notiHandle)
1444         {
1445                 LogInfo(" index : " << index);
1446                 LogInfo(" thumb : " << thumb);
1447                 notification_image_type_e type = NOTIFICATION_IMAGE_TYPE_NONE; 
1448                 
1449                 switch (index)
1450                 {
1451                         case 0:
1452                                 type = NOTIFICATION_IMAGE_TYPE_LIST_1;
1453                                 break;
1454                         case 1:
1455                                 type = NOTIFICATION_IMAGE_TYPE_LIST_2;
1456                                 break;
1457                         case 2:
1458                                 type = NOTIFICATION_IMAGE_TYPE_LIST_3;
1459                                 break;
1460                         case 3:
1461                                 type = NOTIFICATION_IMAGE_TYPE_LIST_4;
1462                                 break;
1463                         case 4:
1464                                 type = NOTIFICATION_IMAGE_TYPE_LIST_5;
1465                                 break;
1466                         default :
1467                                 type = NOTIFICATION_IMAGE_TYPE_NONE;
1468                 }
1469
1470                 if ( type != NOTIFICATION_IMAGE_TYPE_NONE)
1471                 {
1472                         if (getThumbnail(index).compare(thumb))
1473                         {
1474                                 if (notification_set_image(m_notiHandle, type, thumb.c_str()) != NOTIFICATION_ERROR_NONE)
1475                                 {
1476                                         throw UnknownException( "set notification thumbnail error");
1477                                 }
1478                                 setUpdatedFlag(true);
1479                         }
1480                 }
1481         }
1482 }
1483
1484 std::string StatusNotification::getBackground()
1485 {
1486         LogInfo(" Handle : " << m_notiHandle);
1487
1488         if (m_notiHandle)
1489         {
1490                 char *background = NULL;
1491         
1492                 if (notification_get_image(m_notiHandle, NOTIFICATION_IMAGE_TYPE_BACKGROUND, &background) != NOTIFICATION_ERROR_NONE)
1493                 {
1494                         throw UnknownException( "get notification background error");
1495                 }
1496                 
1497                 std::string notiBackground;
1498                 if (background)
1499                         notiBackground = background;
1500                 return notiBackground;
1501         }
1502         else
1503         {
1504                 LogDebug("noti Handle is NULL");
1505                 throw UnknownException( "notification handle is null");
1506         }
1507
1508 }
1509
1510 void StatusNotification::setBackground(const std::string imagePath)
1511 {
1512         LogInfo(" imagePath : " << imagePath);
1513         if (m_notiHandle)
1514         {
1515                 if (getBackground().compare(imagePath))
1516                 {
1517                         if (notification_set_image(m_notiHandle,NOTIFICATION_IMAGE_TYPE_BACKGROUND, imagePath.c_str()) != NOTIFICATION_ERROR_NONE)
1518                         {
1519                                 throw UnknownException( "set notification sound error");
1520                         }
1521                         setUpdatedFlag(true);
1522                 }
1523         }
1524         else
1525         {       
1526                 LogDebug("noti Handle is NULL");
1527                 throw UnknownException( "notification handle is null");
1528         }
1529 }
1530
1531 unsigned int StatusNotification::getNumber()
1532 {
1533         LogInfo("Handle = " << m_notiHandle);
1534         if (m_notiHandle)
1535         {
1536                 int number = 0;
1537                 char *strNumber = NULL;
1538
1539                 if (notification_get_text(m_notiHandle, NOTIFICATION_TEXT_TYPE_EVENT_COUNT, &strNumber) != NOTIFICATION_ERROR_NONE)
1540                 {
1541                         throw UnknownException( "get notification background error");
1542                 }
1543
1544                 if (strNumber)
1545                         std::istringstream(strNumber) >> number;
1546
1547                 LogInfo("number = " << number);
1548
1549                 if (number < 0 )
1550                         number = 0;
1551                 return number;
1552         }
1553         else
1554         {
1555                 LogDebug("noti Handle is NULL");
1556                 return 0;
1557         }
1558 }
1559
1560 void StatusNotification::setNumber(const unsigned int number)
1561 {
1562         LogInfo("Number = " << number);
1563         if (m_notiHandle)
1564         {
1565                 if(number!=getNumber())
1566                 {
1567                         std::stringstream stream;
1568                         stream << number;
1569                         if (stream.fail()) {
1570                                 throw UnknownException(
1571                                                  "Couldn't convert e-mail account id");
1572                         }
1573                         
1574                         std::string strNumber = stream.str();           
1575                         if (notification_set_text(m_notiHandle, NOTIFICATION_TEXT_TYPE_EVENT_COUNT, strNumber.c_str(),
1576                                 NULL, NOTIFICATION_VARIABLE_TYPE_NONE) != NOTIFICATION_ERROR_NONE)
1577                         {
1578                                 throw UnknownException( "set notification sound error");
1579                         }
1580                         setUpdatedFlag(true);
1581                 }
1582         }
1583         else
1584         {               
1585                 LogDebug("noti Handle is NULL");
1586                 throw UnknownException( "notification handle is null");
1587         }
1588 }
1589
1590 void* StatusNotification::getNotificationHandle()
1591 {
1592         return m_notiHandle;
1593 }
1594
1595 void StatusNotification::setNotificationHandle(void *handle)
1596 {
1597         if (handle == NULL)
1598         {
1599                 throw UnknownException( "notification handle null error");
1600         }
1601         LogInfo("handle = " << handle << " m_notiHandle = " << m_notiHandle);
1602         
1603         if (m_notiHandle != NULL)
1604         {       
1605                 //delete old noti.
1606                 if ( notification_delete(m_notiHandle) != NOTIFICATION_ERROR_NONE)
1607                 {
1608                         throw UnknownException( "notification delete error");
1609                 }
1610                 m_notiHandle = NULL;
1611         }
1612         
1613         m_notiHandle = (notification_h)handle;
1614 }
1615
1616 service_h StatusNotification::getService()
1617 {
1618         return m_service;
1619 }
1620
1621
1622 //Detail Info
1623 void StatusNotification::loadDetailInfos()
1624 {
1625         LogInfo("noti Handle = " << m_notiHandle);
1626
1627         if (m_notiHandle)
1628         {
1629                 for ( int idx = 0; idx < MAX_NOTIFICATION_DETAIL_INFO_LENGTH; idx++)
1630                 {
1631                     std::string main = getInformation(idx);
1632                     std::string sub = getSubInformation(idx);
1633                     LogInfo("Main : " << main << " Sub : " << sub);
1634                     NotificationDetailInfo *info = new NotificationDetailInfo(m_notiHandle, idx, main, sub);
1635                     m_detailInfos.push_back(info);
1636                 }
1637         }
1638         else
1639         {               
1640                 LogDebug("noti Handle is NULL");
1641                 throw UnknownException( "notification handle is null");
1642         }
1643         
1644 }
1645
1646 std::vector<NotificationDetailInfo*> StatusNotification::getDetailInfos() const
1647 {
1648         return m_detailInfos;
1649 }
1650
1651 void StatusNotification::setDetailInfos(const std::vector<NotificationDetailInfo*> value)
1652 {
1653     LogInfo("DetailInfos = " << value.size());
1654
1655     if (m_notiHandle)
1656     {
1657         std::vector<NotificationDetailInfo*>::const_iterator it;
1658         
1659         int idx = 0;
1660         for (it = value.begin(); it < value.end(); ++it)
1661         {
1662             NotificationDetailInfo* info = *it;
1663             if ( idx < MAX_NOTIFICATION_DETAIL_INFO_LENGTH )
1664             {
1665                 LogInfo("main " << info->getMainText() << " sub " << info->getSubText() );
1666                 setInformation(info->getMainText(), idx);
1667                 setSubInformation(info->getSubText(), idx);
1668             }
1669             idx ++;
1670         }
1671     
1672         m_detailInfos = value;
1673     }
1674     else
1675     {   
1676         LogDebug("noti Handle is NULL");
1677         throw UnknownException( "notification handle is null");
1678     }
1679         
1680 }
1681
1682 int StatusNotification::getDetailInfosNum() const
1683 {
1684         return m_detailInfos.size();
1685 }
1686
1687 void StatusNotification::clearDetailInfos()
1688 {
1689         if ( !m_detailInfos.empty() )
1690         {
1691                 std::vector<NotificationDetailInfo*>::const_iterator it;
1692                
1693                 int idx = 0;
1694                 for (it = m_detailInfos.begin(); it < m_detailInfos.end(); ++it)
1695                 {
1696                     NotificationDetailInfo* info = *it;
1697                     LogInfo("Delete Detail Info : " << info);
1698                     if (info)
1699                         delete info;
1700                     idx ++;
1701                 }
1702                 m_detailInfos.clear();          //clear
1703         }
1704 }
1705
1706 std::string StatusNotification::getInformation(int index)
1707 {
1708         if (m_notiHandle)
1709         {
1710                 notification_text_type_e type = NOTIFICATION_TEXT_TYPE_NONE; 
1711                 switch (index)
1712                 {
1713                         case 0:
1714                                 type = NOTIFICATION_TEXT_TYPE_INFO_1;
1715                                 break;
1716                         case 1:
1717                                 type = NOTIFICATION_TEXT_TYPE_INFO_2;
1718                                 break;
1719                         case 2:
1720                                 type = NOTIFICATION_TEXT_TYPE_INFO_3;
1721                                 break;
1722                         default :
1723                                 type = NOTIFICATION_TEXT_TYPE_NONE;
1724                 }
1725                 char *info = NULL;
1726                 
1727                 if (NOTIFICATION_TEXT_TYPE_NONE != type && notification_get_text(m_notiHandle, type, &info) != NOTIFICATION_ERROR_NONE)
1728                 {
1729                         throw UnknownException("Detail Info index value is invalid or mainText value getting is failed in Detail Info.");
1730                 }
1731
1732                 std::string strInfo;
1733                 if (info)
1734                         strInfo = info;
1735                 LogInfo(" info " << strInfo);
1736                 return strInfo;
1737
1738         }
1739         else
1740         {       
1741                 LogWarning("noti Handle is NULL");
1742                 throw UnknownException( "notification handle is null");
1743         }
1744         
1745 }
1746
1747 std::string StatusNotification::getSubInformation(int index)
1748 {
1749         if (m_notiHandle)
1750         {
1751                 notification_text_type_e type = NOTIFICATION_TEXT_TYPE_NONE; 
1752                 switch (index)
1753                 {
1754                         case 0:
1755                                 type = NOTIFICATION_TEXT_TYPE_INFO_SUB_1;
1756                                 break;
1757                         case 1:
1758                                 type = NOTIFICATION_TEXT_TYPE_INFO_SUB_2;
1759                                 break;
1760                         case 2:
1761                                 type = NOTIFICATION_TEXT_TYPE_INFO_SUB_3;
1762                                 break;
1763                         default :
1764                                 type = NOTIFICATION_TEXT_TYPE_NONE;
1765                 }
1766                                 
1767                 char *subInfo = NULL;
1768                 
1769                 if (NOTIFICATION_TEXT_TYPE_NONE != type && notification_get_text(m_notiHandle, type, &subInfo) != NOTIFICATION_ERROR_NONE)
1770                 {
1771                         throw UnknownException("Detail Info index value is invalid or subText value getting is failed in Detail Info.");
1772                 }
1773
1774                 std::string strSubInfo;
1775                 if (subInfo)
1776                         strSubInfo = subInfo;
1777                 LogInfo(" subInfo " << strSubInfo);
1778                 return strSubInfo;
1779                                 
1780         }
1781         else
1782         {       
1783                 LogWarning("noti Handle is NULL");
1784                 throw UnknownException ("notification handle is null");
1785         }
1786         
1787 }
1788
1789 void StatusNotification::setInformation( const std::string& info, int index)
1790 {
1791         if (m_notiHandle)
1792         {
1793                 int idx = index;
1794                 LogDebug(" index : " << idx);
1795                 LogDebug(" log : " << info);
1796                 notification_text_type_e type = NOTIFICATION_TEXT_TYPE_NONE; 
1797                 
1798                 switch (idx)
1799                 {
1800                         case 0:
1801                                 type = NOTIFICATION_TEXT_TYPE_INFO_1;
1802                                 break;
1803                         case 1:
1804                                 type = NOTIFICATION_TEXT_TYPE_INFO_2;
1805                                 break;
1806                         case 2:
1807                                 type = NOTIFICATION_TEXT_TYPE_INFO_3;
1808                                 break;
1809                         default :
1810                                 type = NOTIFICATION_TEXT_TYPE_NONE;
1811                 }
1812
1813                 if ( type != NOTIFICATION_TEXT_TYPE_NONE)
1814                 {
1815                         if (getInformation(idx).compare(info))
1816                         {
1817                                 if (notification_set_text(m_notiHandle, type, info.c_str(),
1818                                         NULL, NOTIFICATION_VARIABLE_TYPE_NONE) != NOTIFICATION_ERROR_NONE)
1819                                 {
1820                                         throw UnknownException("set notification sound error");
1821                                 }
1822                                 setUpdatedFlag(true);
1823                         }
1824                 }
1825                 else
1826                 {       
1827                         LogWarning("noti Handle is NULL");
1828                         throw UnknownException("notification handle is null");
1829                 }
1830         }
1831         else
1832         {       
1833                 LogWarning("noti Handle is NULL");
1834                 throw UnknownException("notification handle is null");
1835         }
1836 }
1837
1838 void StatusNotification::setSubInformation( const std::string& subInfo, int index)
1839 {
1840
1841         if (m_notiHandle)
1842         {
1843                 int idx = index;
1844                 LogDebug(" index : " << idx);
1845                 LogDebug(" log : " << subInfo);
1846                 notification_text_type_e type = NOTIFICATION_TEXT_TYPE_NONE; 
1847                 
1848                 switch (idx)
1849                 {
1850                         case 0:
1851                                 type = NOTIFICATION_TEXT_TYPE_INFO_SUB_1;
1852                                 break;
1853                         case 1:
1854                                 type = NOTIFICATION_TEXT_TYPE_INFO_SUB_2;
1855                                 break;
1856                         case 2:
1857                                 type = NOTIFICATION_TEXT_TYPE_INFO_SUB_3;
1858                                 break;
1859                         default :
1860                                 type = NOTIFICATION_TEXT_TYPE_NONE;
1861                 }
1862
1863                 if ( type != NOTIFICATION_TEXT_TYPE_NONE)
1864                 {
1865                         if (getSubInformation(idx).compare(subInfo))
1866                         {
1867                                 if (notification_set_text(m_notiHandle, type, subInfo.c_str(),
1868                                         NULL, NOTIFICATION_VARIABLE_TYPE_NONE) != NOTIFICATION_ERROR_NONE)
1869                                 {
1870                                         throw UnknownException("set notification sound error");
1871                                 }
1872                                 setUpdatedFlag(true);
1873                         }
1874                 }
1875         }
1876         else
1877         {       
1878                 LogWarning("noti Handle is NULL");
1879                 throw UnknownException("notification handle is null");
1880         }
1881 }
1882
1883
1884 #if 0
1885
1886 StatusNotification::StatusNotification():
1887     m_statusType(""),
1888     m_iconPath(""),
1889     m_subIconPath(""),
1890     m_number(0),
1891     m_backgroundImagePath(""),
1892     m_soundPath(""),
1893     m_vibration(false),
1894     m_progressType(""),
1895     m_progressValue(0)
1896 {
1897 }
1898
1899 StatusNotification::~StatusNotification()
1900 {
1901 }
1902
1903 std::string StatusNotification::getStatusType() const
1904 {
1905     return m_statusType;
1906 }
1907
1908 void StatusNotification::setStatusType(std::string statusType)
1909 {
1910     m_statusType = statusType;
1911 }
1912
1913 std::string StatusNotification::getIconPath() const
1914 {
1915     return m_iconPath;
1916 }
1917
1918 void StatusNotification::setIconPath(std::string iconPath)
1919 {
1920     m_iconPath = iconPath;
1921 }
1922
1923 std::string StatusNotification::getSubIconPath() const
1924 {
1925     return m_subIconPath;
1926 }
1927
1928 void StatusNotification::setSubIconPath(std::string subIconPath)
1929 {
1930     m_subIconPath = subIconPath;
1931 }
1932
1933 long StatusNotification::getNumber() const
1934 {
1935     return m_number;
1936 }
1937
1938 void StatusNotification::setNumber(long number)
1939 {
1940     m_number = number;
1941 }
1942
1943 std::vector<NotificationDetailInfo*> StatusNotification::getDetailInfo() const
1944 {
1945     return m_detailInfo;
1946 }
1947
1948 void StatusNotification::setDetailInfo(std::vector<NotificationDetailInfo*> detailInfo)
1949 {
1950     m_detailInfo = detailInfo;
1951 }
1952
1953 std::string StatusNotification::getBackgroundImagePath() const
1954 {
1955     return m_backgroundImagePath;
1956 }
1957
1958 void StatusNotification::setBackgroundImagePath(std::string backgroundImagePath)
1959 {
1960     m_backgroundImagePath = backgroundImagePath;
1961 }
1962
1963 std::vector<std::string> StatusNotification::getThumbnails() const
1964 {
1965     return m_thumbnails;
1966 }
1967
1968 void StatusNotification::setThumbnails(std::vector<std::string> thumbnails)
1969 {
1970     m_thumbnails = thumbnails;
1971 }
1972
1973 std::string StatusNotification::getSoundPath() const
1974 {
1975     return m_soundPath;
1976 }
1977
1978 void StatusNotification::setSoundPath(std::string soundPath)
1979 {
1980     m_soundPath = soundPath;
1981 }
1982
1983 bool StatusNotification::getVibration() const
1984 {
1985     return m_vibration;
1986 }
1987
1988 void StatusNotification::setVibration(bool vibration)
1989 {
1990     m_vibration = vibration;
1991 }
1992
1993 ApplicationControl StatusNotification::getAppControl() const
1994 {
1995     return m_appControl;
1996 }
1997
1998 void StatusNotification::setAppControl(ApplicationControl appControl)
1999 {
2000     m_appControl = appControl;
2001 }
2002
2003 ApplicationId StatusNotification::getAppId() const
2004 {
2005     return m_appId;
2006 }
2007
2008 void StatusNotification::setAppId(ApplicationId appId)
2009 {
2010     m_appId = appId;
2011 }
2012
2013 std::string StatusNotification::getProgressType() const
2014 {
2015     return m_progressType;
2016 }
2017
2018 void StatusNotification::setProgressType(std::string progressType)
2019 {
2020     m_progressType = progressType;
2021 }
2022
2023 unsigned long StatusNotification::getProgressValue() const
2024 {
2025     return m_progressValue;
2026 }
2027
2028 void StatusNotification::setProgressValue(unsigned long progressValue)
2029 {
2030     m_progressValue = progressValue;
2031 }
2032 #endif
2033
2034 } // Notification
2035 } // DeviceAPI