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