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