Update change log and spec for wrt-plugins-tizen_0.4.21
[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 char* StatusNotification::getStrContent()
514 {
515         LogInfo("get Content handle: " << m_notiHandle);
516         if (m_notiHandle)
517         {
518                 char *content = NULL;
519
520                 if (notification_get_text(m_notiHandle, NOTIFICATION_TEXT_TYPE_CONTENT, &content) != NOTIFICATION_ERROR_NONE)
521                 {
522                         throw UnknownException("get notification Content error");
523                 }
524                 
525                 return content;
526         }
527         else
528         {
529                 throw UnknownException("notification handle is null");
530         }
531 }
532
533 void StatusNotification::setContent(std::string content)
534 {
535         LogInfo("Content : " << content);
536         if (m_notiHandle)
537         {
538                 if((getContent()).compare(content))     //different value.
539                 {
540                         if (notification_set_text(m_notiHandle, NOTIFICATION_TEXT_TYPE_CONTENT, content.c_str(),
541                                 NULL, NOTIFICATION_VARIABLE_TYPE_NONE ) != NOTIFICATION_ERROR_NONE)
542                         {
543                                 throw UnknownException("set notification content error");
544                         }
545                         setUpdatedFlag(true);
546                 }
547         }
548         else
549         {       
550                 LogDebug("noti Handle is NULL");
551                 throw UnknownException("notification handle is null");
552         }
553 }
554
555 std::string StatusNotification::getIconPath()
556 {
557
558         LogInfo("m_notiHandle = " << m_notiHandle);
559         if (m_notiHandle)
560         {
561                 char *iconPath = NULL;
562                 if (notification_get_image(m_notiHandle, NOTIFICATION_IMAGE_TYPE_ICON,  &iconPath) != NOTIFICATION_ERROR_NONE)
563                 {
564                         throw UnknownException("get notification icon path error");
565                 }
566
567                 std::string notiIconPath(iconPath);
568                 LogInfo("icon Path = " << iconPath);
569                 
570                 //if icon path invalid, return empty string.
571                 if ( notiIconPath.find(DEFAULT_ICON_PATH,0) == std::string::npos)
572                         return notiIconPath;    
573                 else
574                 {
575                         return std::string(""); //return empty string.
576                 }
577         }
578         else
579         {
580                 throw UnknownException("notification handle is null");
581         }
582 }
583
584 void StatusNotification::setIconPath(const std::string& iconPath)
585 {
586         if (m_notiHandle)
587         {
588                 LogInfo("icon path = " << iconPath << " origin icon path = " << getIconPath());
589                 if( getIconPath().compare(iconPath))
590                 {
591                         if (notification_set_image(m_notiHandle,NOTIFICATION_IMAGE_TYPE_ICON, iconPath.c_str()) != NOTIFICATION_ERROR_NONE)
592                         {
593                                 throw UnknownException("set notification icon error");
594                         }
595                         setUpdatedFlag(true);
596                 }
597         }
598         else
599         {
600                 LogDebug("noti Handle is NULL");
601                 throw UnknownException("notification handle is null");
602         }
603 }
604
605 std::string StatusNotification::getSoundPath()
606 {
607         LogInfo("Handle = " << m_notiHandle);
608
609         if (m_notiHandle)
610         {
611                 const char *soundPath = NULL;
612                 notification_sound_type_e type = NOTIFICATION_SOUND_TYPE_NONE;
613                 
614                 if (notification_get_sound(m_notiHandle, &type,  &soundPath) != NOTIFICATION_ERROR_NONE)
615                 {
616                         throw UnknownException("get notification sound error");
617                 }
618
619                 LogInfo(" sound type = " << type << " path = " << soundPath);
620                 if ( type == NOTIFICATION_SOUND_TYPE_USER_DATA )
621                 {
622                         LogInfo("soundPath = " << soundPath);
623                         return std::string(soundPath); 
624                 }
625                 else
626                 {
627                         return std::string("");
628                 }
629         }
630         else
631         {
632                 LogDebug("noti Handle is NULL");
633                 throw UnknownException("notification handle is null");
634         }
635 }
636
637 void StatusNotification::setSoundPath(const std::string& sound)
638 {
639         if (m_notiHandle)
640         {
641                 LogInfo("sound path = " << sound << " origin sound path = " << getSoundPath());
642                 
643                 if( getSoundPath().compare(sound))
644                 {
645                         if (notification_set_sound(m_notiHandle,NOTIFICATION_SOUND_TYPE_USER_DATA, sound.c_str()) != NOTIFICATION_ERROR_NONE)
646                         {
647                                 throw UnknownException("set notification sound error");
648                         }
649                         setUpdatedFlag(true);
650                 }
651
652                 if (sound.empty()) 
653                 {
654                     LogInfo("sound path is NULL");
655                     if ( NOTI_TYPE_ONGOING == getNotiType() || NOTI_TYPE_PROGRESS == getNotiType())
656                     {
657                                 LogInfo("Ongoing Type" );
658                                 if (notification_set_sound(m_notiHandle,NOTIFICATION_SOUND_TYPE_NONE, NULL) != NOTIFICATION_ERROR_NONE)
659                                 {
660                                         throw UnknownException("set notification sound error");
661                                 }
662                     }
663                     else
664                     {
665                                 if (notification_set_sound(m_notiHandle,NOTIFICATION_SOUND_TYPE_DEFAULT, sound.c_str()) != NOTIFICATION_ERROR_NONE)
666                                 {
667                                         throw UnknownException("set notification sound error");
668                                 }
669                     }           
670                     
671                 }
672         }
673         else
674         {       
675                 LogDebug("noti Handle is NULL");
676                 throw UnknownException("notification handle is null");
677         }
678 }
679
680 bool StatusNotification::getDefaultVibration()
681 {
682         LogInfo("getDefaultVibration");
683         if (m_notiHandle)
684         {
685                 notification_vibration_type_e vib_type;
686                 if (notification_get_vibration(m_notiHandle, &vib_type,  NULL) != NOTIFICATION_ERROR_NONE)
687                 {
688                         throw UnknownException("set notification sound error");
689                 }
690
691                 if (NOTIFICATION_VIBRATION_TYPE_DEFAULT == vib_type  || NOTIFICATION_VIBRATION_TYPE_USER_DATA == vib_type)
692                 {
693                         return true;
694                 }
695                 else
696                 {
697                         return false;
698                 }
699         }
700         else
701         {
702                 LogDebug("noti Handle is NULL");
703                 throw UnknownException("notification handle is null");
704         }
705
706         return false;
707 }
708
709 void StatusNotification::setDefaultVibration(const bool& vibration) 
710 {
711     LogInfo("vibration = " << vibration);
712         if (m_notiHandle)
713         {
714                 notification_vibration_type_e vib_type = NOTIFICATION_VIBRATION_TYPE_NONE;
715                 LogInfo("old vibration = " << getDefaultVibration());
716                 if (getDefaultVibration() != vibration)
717                 {
718                         if (vibration)
719                         {
720                                 vib_type = NOTIFICATION_VIBRATION_TYPE_DEFAULT;
721                         }
722                         else
723                         {
724                                 vib_type = NOTIFICATION_VIBRATION_TYPE_NONE;
725                         }
726                         LogInfo("type vibration type= " << vib_type);
727
728                         if (notification_set_vibration(m_notiHandle, vib_type , NULL) != NOTIFICATION_ERROR_NONE)
729                         {
730                                 throw UnknownException("set notification sound error");
731                         }
732                         setUpdatedFlag(true);
733                 }
734         }
735         else
736         {
737                 LogDebug("noti Handle is NULL");
738                 throw UnknownException("notification handle is null");
739         }
740
741 }
742
743 DeviceAPI::Application::ApplicationControlPtr StatusNotification::getApplicationControl()
744 {
745
746     service_h service = NULL;
747     char *tempStr = NULL;
748
749     DeviceAPI::Application::ApplicationControlPtr appControl(new DeviceAPI::Application::ApplicationControl());
750
751     try {
752                 if (m_service)
753                 {
754                         appControl->setService_h(m_service);
755                         // mandatory
756                         if(service_get_operation(m_service, &tempStr) == SERVICE_ERROR_NONE)
757                         {
758                                 LogDebug("Operation Str = " << tempStr);
759                                 if (tempStr) 
760                                 {
761                                         appControl->setOperation(tempStr);
762                                         free(tempStr);
763                                         tempStr = NULL;
764                                 }
765                         }
766
767                         // optional
768                         if (service_get_mime(m_service, &tempStr) == SERVICE_ERROR_NONE)
769                         {
770                                 LogDebug("Mime Str = " << tempStr);
771                                 if (tempStr) 
772                                 {
773                                         appControl->setMime(tempStr);
774                                         free(tempStr);
775                                         tempStr = NULL;
776                                 }
777                         }
778
779                         // optional
780                         if (service_get_uri(m_service, &tempStr) == SERVICE_ERROR_NONE)
781                         {
782                                 LogDebug("Uri Str = " << tempStr);
783                                 if (tempStr)
784                                 {
785                                         appControl->setUri(tempStr);
786                                         free(tempStr);
787                                         tempStr = NULL;
788                                 }
789                         }
790
791                         if (service_get_category(m_service, &tempStr) == SERVICE_ERROR_NONE)
792                         {
793                                 LogDebug("Category Str = " << tempStr);
794                                 if (tempStr)
795                                 {
796                                         appControl->setCategory(tempStr);
797                                         free(tempStr);
798                                         tempStr = NULL;
799                                 }
800                         }
801                         
802                         // optional
803                         if ( service_foreach_extra_data(m_service, service_extra_data_cb,(void*)&appControl) != SERVICE_ERROR_NONE)
804                         {
805                                 ThrowMsg(WrtDeviceApis::Commons::UnknownException, "get notification service uri error");
806                         }
807
808                         return appControl;
809                 }
810
811         }
812         Catch (WrtDeviceApis::Commons::Exception) 
813         {
814                 if (tempStr) 
815                 {
816                         free(tempStr);
817                         tempStr = NULL;
818                 }
819
820                 if (service)
821                 {
822                         free(service);
823                         service = NULL;
824                 }
825
826                 LogWarning(_rethrown_exception.GetMessage());
827         }
828         
829     return appControl;
830 }
831
832 void StatusNotification::setApplicationControl(DeviceAPI::Application::ApplicationControlPtr control)
833 {
834         LogInfo("Entered m_service : " << m_service << " control : " << control);
835
836         //delete old service.
837         if (m_service)
838         {
839                 service_destroy(m_service);
840                 m_service = NULL;
841         }
842         
843         if(service_create(&m_service) != SERVICE_ERROR_NONE)
844         {
845                 throw UnknownException("service creation error");
846         }
847         else
848         {
849                 LogInfo("getOperation : " << control->getOperation().c_str());
850                 if (control->getOperation().size() != 0)
851                 {
852                         m_launchFlag = true;            //default attribute
853                         if (service_set_operation(m_service, control->getOperation().c_str()) != SERVICE_ERROR_NONE)
854                         {
855                                 throw UnknownException("service set operation error");
856                         }
857                 }
858                         
859                 // optional
860                 LogInfo("getUri : " << control->getUri().c_str());
861                 if (control->getUri().size() != 0)
862                 {
863                         if (service_set_uri(m_service, control->getUri().c_str() ) != SERVICE_ERROR_NONE)
864                         {
865                                 throw UnknownException("service set uri error");
866                         }
867                 }
868         
869                 // optional
870                 LogInfo("getMime : " << control->getMime().c_str());
871                 if (control->getMime().size() != 0)
872                 {
873                         if (service_set_mime(m_service, control->getMime().c_str() ) != SERVICE_ERROR_NONE)
874                         {
875                                 throw UnknownException("service set mime error");
876                         }
877                 }
878         
879                 LogInfo("Category : " << control->getCategory().c_str());
880                 if (control->getCategory().size() != 0)
881                 {
882                         if (service_set_category(m_service, control->getCategory().c_str() ) != SERVICE_ERROR_NONE)
883                         {
884                                 throw UnknownException("service set mime error");
885                         }
886                 }
887
888                 //remove key
889                 //if ( service_foreach_extra_data(m_service, service_extra_data_delete_cb, NULL) != SERVICE_ERROR_NONE)
890                 //{
891                 //      throw UnknownException("get notification service uri error");
892                 //}
893                 
894                 std::vector<DeviceAPI::Application::ApplicationControlDataPtr> appControlDataArray = control->getAppControlDataArray();
895                 size_t index = 0;
896         
897                 LogInfo (" App Control Datas Count : " << appControlDataArray.size());
898         
899                 DeviceAPI::Application::ApplicationControlDataArray::iterator iter;
900         
901                 for(iter = appControlDataArray.begin(); iter != appControlDataArray.end(); iter++)
902                 {
903                         DeviceAPI::Application::ApplicationControlDataPtr appControlData = *iter;
904                         std::string key = appControlData->getKey();
905                         LogInfo(" key : " << key);
906                 
907                         if (key.empty())
908                                 continue;
909                 
910                         std::vector<std::string> value = appControlDataArray[index]->getValue();
911                         const char **arrayValue = (const char**)calloc(sizeof(char*), value.size());
912         
913                         for (size_t indexArray = 0; indexArray < value.size(); indexArray++)
914                         {
915                                 arrayValue[indexArray] = (char*)value[indexArray].c_str();
916                                 LogInfo( " value : " << arrayValue[indexArray]);
917                         }
918         
919                         const char* strKey = key.c_str();
920                         LogInfo( " value size: " << value.size());
921                         if (service_add_extra_data_array(m_service, strKey, arrayValue, value.size()) != SERVICE_ERROR_NONE)
922                         {
923                                 throw UnknownException("service set extra data error");                 
924                         }
925                          
926                         if (arrayValue)
927                                 free(arrayValue);
928                 }                                       
929         
930                 bundle *bundle_data=NULL;
931                 
932                 if(service_to_bundle(m_service, &bundle_data) != SERVICE_ERROR_NONE)
933                 {
934                         throw UnknownException("service get bundle");                   
935                 }
936
937                 LogDebug("bundle_data : " << bundle_data);
938                 
939                 if (bundle_data)
940                 {
941                         notification_set_execute_option(m_notiHandle, NOTIFICATION_EXECUTE_TYPE_SINGLE_LAUNCH,
942                                 NULL,NULL, bundle_data);
943                 }
944                                 
945         }
946         
947 }
948
949 void StatusNotification::setApplicationId(const std::string& appId)
950 {
951         LogInfo("m_service = "  << m_service << " appId = " << appId);
952         if (!m_service)
953         {       
954                 if (service_create(&m_service) != SERVICE_ERROR_NONE)
955                 {
956                         LogWarning("Create Service Failed..");
957                         throw UnknownException("service creation error");
958                 }
959         }
960
961         if (m_service)
962         {
963                 if (!appId.empty())
964                 {
965                         m_launchFlag = true;
966                         if (service_set_app_id(m_service, appId.c_str())!= SERVICE_ERROR_NONE)
967                         {
968                                 throw UnknownException("service set appId error");      
969                         }
970                 }
971         }
972
973 }
974
975 std::string StatusNotification::getApplicationId()
976 {
977         std::string retString;
978         service_h service = NULL;
979         char* appIdStr = NULL;
980         
981         if (m_service != NULL)
982         {
983                 int retcode;
984                 retcode = service_clone(&service, m_service);   
985                 
986                 if (retcode != SERVICE_ERROR_NONE)
987                 {
988                         if (retcode == SERVICE_ERROR_OUT_OF_MEMORY)
989                         {
990                                 LogWarning("SERVICE_ERROR_OUT_OF_MEMORY");
991                         }
992                         else
993                         {
994                                 LogWarning("UI_NOTIFICATION_ERROR_INVALID_PARAMETER");
995                         }
996                         throw UnknownException ("get notification service error ");
997                 }
998                 else
999                 {
1000                         if (service == NULL)
1001                         {
1002                                 throw UnknownException ("get notification service ok, but service null");                       
1003                         }
1004                 }
1005         }
1006
1007         if (service != NULL) 
1008         {
1009                 if (service_get_app_id(service, &appIdStr) != SERVICE_ERROR_NONE)
1010                 {
1011                         throw UnknownException ("get a appId error");
1012                 }
1013
1014                 if (appIdStr != NULL)
1015                 {
1016                         retString = appIdStr;
1017                         free(appIdStr);
1018                 }
1019         }
1020         LogInfo(retString);
1021         
1022         return retString;
1023
1024 }
1025
1026 double StatusNotification::getProgressValue() 
1027 {
1028         double value = 0.0;
1029         
1030         if (m_notiHandle)
1031         {
1032                 NotificationProgressType progressType = getProgressType();
1033         
1034                 if (progressType == NOTI_PROGRESS_TYPE_SIZE)
1035                 {
1036                         if (notification_get_size(m_notiHandle, &value) != NOTIFICATION_ERROR_NONE)
1037                         {
1038                                 throw UnknownException("get notification size error");
1039                         }
1040                         LogInfo("Size Val = " << value);
1041                 }
1042                 else if ( progressType == NOTI_PROGRESS_TYPE_PERCENTAGE )
1043                 {
1044                         if (notification_get_progress(m_notiHandle, &value) != NOTIFICATION_ERROR_NONE)
1045                         {
1046                                 throw UnknownException("get notification percentage error");
1047                         }
1048                         LogInfo("Percentage Val = " << value);
1049                 }
1050                 else
1051                 {
1052                         throw UnknownException("get notification progress type error");
1053                 }
1054         }
1055         else
1056         {
1057                 LogDebug("noti Handle is NULL");
1058         }
1059         LogInfo("value = " << value);
1060         return value;
1061         
1062 }
1063
1064 void StatusNotification::setProgressValue(const double &progressValue)
1065 {
1066         if (m_notiHandle)
1067         {       
1068                 NotificationProgressType progressType = getProgressType();
1069                 LogInfo("Progress Type : " << progressType);
1070                 
1071                 double val = getProgressValue();
1072                 LogInfo("Progress value = " << progressValue << " origin Progress Value =" << val);
1073                 
1074                 if (progressType == NOTI_PROGRESS_TYPE_SIZE)
1075                 {
1076                         if (notification_set_size(m_notiHandle, progressValue) != NOTIFICATION_ERROR_NONE)
1077                         {
1078                                 throw UnknownException("set notification progress size error");
1079                         }
1080                 }
1081                 else if ( progressType == NOTI_PROGRESS_TYPE_PERCENTAGE )
1082                 {       
1083                         if (notification_set_progress(m_notiHandle, progressValue) != NOTIFICATION_ERROR_NONE)
1084                         {
1085                                 throw UnknownException("set notification percentage error");
1086                         }
1087                 }
1088                 else
1089                 {
1090                         throw UnknownException("get notification progress type error");
1091                 }
1092         }
1093         else
1094         {
1095                 LogDebug("noti Handle is NULL");
1096                 throw UnknownException( "notification handle is null");
1097         }
1098 }
1099
1100 std::string StatusNotification::getSubIconPath()
1101 {
1102         LogInfo("Handle = " << m_notiHandle);
1103         if (m_notiHandle)
1104         {
1105                 char *subIconPath = NULL;
1106         
1107                 if (notification_get_image(m_notiHandle, NOTIFICATION_IMAGE_TYPE_ICON_SUB,  &subIconPath) != NOTIFICATION_ERROR_NONE)
1108                 {
1109                         throw UnknownException("get notification sub icon error");
1110                 }
1111
1112                 std::string notiSubIconPath;
1113                 if(subIconPath)
1114                         notiSubIconPath = subIconPath;
1115                 return notiSubIconPath; 
1116         }
1117         else
1118         {
1119                 throw UnknownException("notification handle is null");
1120         }
1121
1122 }
1123
1124 void StatusNotification::setSubIconPath(const std::string& subIconPath)
1125 {
1126         if (m_notiHandle)
1127         {
1128                 LogInfo(" subIconPath = " << subIconPath << " origin SubIconPath = " << getSubIconPath());      
1129
1130                 if( getSubIconPath().compare(subIconPath))
1131                 {
1132                         if (notification_set_image(m_notiHandle,NOTIFICATION_IMAGE_TYPE_ICON_SUB, subIconPath.c_str()) != NOTIFICATION_ERROR_NONE)
1133                         {
1134                                 throw UnknownException("set notification sound error");
1135                         }
1136                         setUpdatedFlag(true);
1137                 }
1138         }
1139         else
1140         {       
1141                 LogDebug("noti Handle is NULL");
1142                 throw UnknownException("notification handle is null");
1143         }
1144 }
1145
1146 #if 0
1147 std::string StatusNotification::getInformation(int index)
1148 {
1149         if (m_notiHandle)
1150         {
1151                 notification_text_type_e type = NOTIFICATION_TEXT_TYPE_NONE; 
1152                 switch (index)
1153                 {
1154                         case 0:
1155                                 type = NOTIFICATION_TEXT_TYPE_INFO_1;
1156                                 break;
1157                         case 1:
1158                                 type = NOTIFICATION_TEXT_TYPE_INFO_2;
1159                                 break;
1160                         case 2:
1161                                 type = NOTIFICATION_TEXT_TYPE_INFO_3;
1162                                 break;
1163                         default :
1164                                 type = NOTIFICATION_TEXT_TYPE_NONE;
1165                 }
1166                 char *info = NULL;
1167                 
1168                 if (NOTIFICATION_TEXT_TYPE_NONE != type && notification_get_text(m_notiHandle, type, &info) != NOTIFICATION_ERROR_NONE)
1169                 {
1170                         throw UnknownException("get notification information error");
1171                 }
1172
1173                 std::string strInfo;
1174                 if (info)
1175                         strInfo = info;
1176                 LogDebug(" info " << strInfo);
1177                 return strInfo;
1178
1179         }
1180         else
1181         {       
1182                 LogDebug("noti Handle is NULL");
1183                 throw UnknownException("notification handle is null");
1184         }
1185         
1186 }
1187
1188 void StatusNotification::setInformation( const std::string& info, int index)
1189 {
1190
1191         if (m_notiHandle)
1192         {
1193                 int idx = index;
1194                 LogDebug(" index : " << idx);
1195                 LogDebug(" log : " << info);
1196                 notification_text_type_e type = NOTIFICATION_TEXT_TYPE_NONE; 
1197                 
1198                 switch (idx)
1199                 {
1200                         case 0:
1201                                 type = NOTIFICATION_TEXT_TYPE_INFO_1;
1202                                 break;
1203                         case 1:
1204                                 type = NOTIFICATION_TEXT_TYPE_INFO_2;
1205                                 break;
1206                         case 2:
1207                                 type = NOTIFICATION_TEXT_TYPE_INFO_3;
1208                                 break;
1209                         default :
1210                                 type = NOTIFICATION_TEXT_TYPE_NONE;
1211                 }
1212
1213                 if ( type != NOTIFICATION_TEXT_TYPE_NONE)
1214                 {
1215                         if (getInformation(idx).compare(info))
1216                         {
1217                                 if (notification_set_text(m_notiHandle, type, info.c_str(),
1218                                         NULL, NOTIFICATION_VARIABLE_TYPE_NONE) != NOTIFICATION_ERROR_NONE)
1219                                 {
1220                                         throw UnknownException("set notification sound error");
1221                                 }
1222                                 setUpdatedFlag(true);
1223                         }
1224                 }
1225         }
1226         else
1227         {       
1228                 LogDebug("noti Handle is NULL");
1229                 throw UnknownException("notification handle is null");
1230         }
1231 }
1232
1233 std::string StatusNotification::getSubInformation(int index)
1234 {
1235
1236         if (m_notiHandle)
1237         {
1238                 notification_text_type_e type = NOTIFICATION_TEXT_TYPE_NONE; 
1239                 switch (index)
1240                 {
1241                         case 0:
1242                                 type = NOTIFICATION_TEXT_TYPE_INFO_SUB_1;
1243                                 break;
1244                         case 1:
1245                                 type = NOTIFICATION_TEXT_TYPE_INFO_SUB_2;
1246                                 break;
1247                         case 2:
1248                                 type = NOTIFICATION_TEXT_TYPE_INFO_SUB_3;
1249                                 break;
1250                         default :
1251                                 type = NOTIFICATION_TEXT_TYPE_NONE;
1252                 }
1253                                 
1254                 char *subInfo = NULL;
1255                 
1256                 if (NOTIFICATION_TEXT_TYPE_NONE != type && notification_get_text(m_notiHandle, type, &subInfo) != NOTIFICATION_ERROR_NONE)
1257                 {
1258                         throw UnknownException( "get notification sub information error");
1259                 }
1260
1261                 std::string strSubInfo;
1262                 if (subInfo)
1263                         strSubInfo = subInfo;
1264                 LogDebug(" subInfo " << strSubInfo);
1265                 return strSubInfo;
1266                                 
1267         }
1268         else
1269         {       
1270                 LogDebug("noti Handle is NULL");
1271                 throw UnknownException( "notification handle is null");
1272         }
1273         
1274 }
1275
1276 void StatusNotification::setSubInformation( const std::string& subInfo, int index)
1277 {
1278         if (m_notiHandle)
1279         {
1280                 int idx = index;
1281                 LogDebug(" index : " << idx);
1282                 LogDebug(" log : " << subInfo);
1283                 notification_text_type_e type = NOTIFICATION_TEXT_TYPE_NONE; 
1284                 
1285                 switch (idx)
1286                 {
1287                         case 0:
1288                                 type = NOTIFICATION_TEXT_TYPE_INFO_SUB_1;
1289                                 break;
1290                         case 1:
1291                                 type = NOTIFICATION_TEXT_TYPE_INFO_SUB_2;
1292                                 break;
1293                         case 2:
1294                                 type = NOTIFICATION_TEXT_TYPE_INFO_SUB_3;
1295                                 break;
1296                         default :
1297                                 type = NOTIFICATION_TEXT_TYPE_NONE;
1298                 }
1299
1300                 if ( type != NOTIFICATION_TEXT_TYPE_NONE)
1301                 {
1302                         if (getSubInformation(idx).compare(subInfo))
1303                         {
1304                                 if (notification_set_text(m_notiHandle, type, subInfo.c_str(),
1305                                         NULL, NOTIFICATION_VARIABLE_TYPE_NONE) != NOTIFICATION_ERROR_NONE)
1306                                 {
1307                                         throw UnknownException( "set notification sound error");
1308                                 }
1309                                 setUpdatedFlag(true);
1310                         }
1311                 }
1312         }
1313         else
1314         {       
1315                 LogDebug("noti Handle is NULL");
1316                 throw UnknownException( "notification handle is null");
1317         }
1318                 
1319 }
1320 #endif
1321
1322 void StatusNotification::loadThumbnails()
1323 {
1324         if (m_notiHandle)
1325         {       
1326                 if (!m_thumbs.empty())
1327                         m_thumbs.clear();
1328
1329                 char *thumb = NULL;
1330                 if (notification_get_image(m_notiHandle, NOTIFICATION_IMAGE_TYPE_LIST_1, &thumb) != NOTIFICATION_ERROR_NONE)
1331                 {
1332                         throw UnknownException( "get notification thumbnail error");
1333                 }
1334                 if (thumb)
1335                         m_thumbs.push_back(thumb);
1336                 //else
1337                 //      m_thumbs.push_back(std::string("")); //set empty
1338                 thumb = NULL;
1339                 
1340                 if (notification_get_image(m_notiHandle, NOTIFICATION_IMAGE_TYPE_LIST_2, &thumb) != NOTIFICATION_ERROR_NONE)
1341                 {
1342                         throw UnknownException( "get notification sub information error");
1343                 }       
1344                 if (thumb)
1345                         m_thumbs.push_back(thumb);
1346                 //else
1347                 //      m_thumbs.push_back(std::string("")); //set empty
1348                 thumb = NULL;
1349                 
1350                 if (notification_get_image(m_notiHandle, NOTIFICATION_IMAGE_TYPE_LIST_3, &thumb) != NOTIFICATION_ERROR_NONE)
1351                 {
1352                         throw UnknownException( "get notification sub information error");
1353                 }
1354                 
1355                 if (thumb)
1356                         m_thumbs.push_back(thumb);
1357                 //else
1358                 //      m_thumbs.push_back(std::string("")); //set empty
1359                 thumb = NULL;
1360
1361                 if (notification_get_image(m_notiHandle, NOTIFICATION_IMAGE_TYPE_LIST_4, &thumb) != NOTIFICATION_ERROR_NONE)
1362                 {
1363                         throw UnknownException( "get notification sub information error");
1364                 }
1365                 
1366                 if (thumb)
1367                         m_thumbs.push_back(thumb);
1368                 //else
1369                 //      m_thumbs.push_back(std::string("")); //set empty
1370                 thumb = NULL;
1371 #if 0   
1372                 if (notification_get_image(m_notiHandle, NOTIFICATION_IMAGE_TYPE_LIST_5, &thumb) != NOTIFICATION_ERROR_NONE)
1373                 {
1374                         throw UnknownException( "get notification sub information error");
1375                 }
1376                 
1377                 if (thumb)
1378                         m_thumbs.push_back(thumb);
1379                 else
1380                         m_thumbs.push_back(std::string("")); //set empty
1381                 thumb = NULL;
1382 #endif          
1383                 
1384         }
1385         else
1386         {       
1387                 LogDebug("noti Handle is NULL");
1388                 throw UnknownException( "notification handle is null");
1389         }
1390 }
1391
1392 std::vector<std::string> StatusNotification::getThumbnails()
1393 {
1394         LogInfo(" thumbnail Size : " << m_thumbs.size());
1395         return m_thumbs;
1396 }
1397
1398 std::string StatusNotification::getThumbnail(int index)
1399 {
1400         if (m_notiHandle)
1401         {
1402                 LogInfo(" index : " << index);
1403                 
1404                 notification_image_type_e type = NOTIFICATION_IMAGE_TYPE_NONE; 
1405                 
1406                 switch (index)
1407                 {
1408                         case 0:
1409                                 type = NOTIFICATION_IMAGE_TYPE_LIST_1;
1410                                 break;
1411                         case 1:
1412                                 type = NOTIFICATION_IMAGE_TYPE_LIST_2;
1413                                 break;
1414                         case 2:
1415                                 type = NOTIFICATION_IMAGE_TYPE_LIST_3;
1416                                 break;
1417                         case 3:
1418                                 type = NOTIFICATION_IMAGE_TYPE_LIST_4;
1419                                 break;
1420                         case 4:
1421                                 type = NOTIFICATION_IMAGE_TYPE_LIST_5;
1422                                 break;
1423                         default :
1424                                 type = NOTIFICATION_IMAGE_TYPE_NONE;
1425                 }
1426
1427                 if ( type != NOTIFICATION_IMAGE_TYPE_NONE)
1428                 {
1429                         char *thumb = NULL;
1430                         if (notification_get_image(m_notiHandle, type, &thumb) != NOTIFICATION_ERROR_NONE)
1431                         {
1432                                 throw UnknownException( "set notification thumbnail error");
1433                         }
1434
1435                         std::string thumbnail;
1436                         if(thumb)
1437                                 thumbnail = thumb;
1438                         return thumbnail;
1439                 }
1440                 else
1441                 {
1442                         throw UnknownException( "notification handle is null");
1443                 }
1444                 
1445         }
1446         else
1447         {       
1448                 LogDebug("noti Handle is NULL");
1449                 throw UnknownException( "notification handle is null");
1450         }
1451 #if 0
1452         if (m_thumbs.size() > index)
1453                 return m_thumbs[index];
1454         else
1455                 return std::string("");
1456 #endif
1457
1458 }
1459
1460 void StatusNotification::setThumbnails(std::vector<std::string> thumbs)
1461 {
1462         LogInfo("set thumbnails");
1463         if (m_notiHandle)
1464         {
1465                 std::vector<std::string>::iterator it;
1466
1467                 int idx = 0;
1468                 for (it = thumbs.begin(); it < thumbs.end(); ++it)
1469                 {
1470                         std::string str = *it;
1471                         if ( idx < MAX_THUMBNAIL_LENGTH )
1472                                 setThumbnail(str, idx); //set notification's thumbnail value.
1473                         idx ++;
1474                 }
1475
1476                 m_thumbs = thumbs;
1477         }
1478         else
1479         {       
1480                 LogDebug("noti Handle is NULL");
1481                 throw UnknownException( "notification handle is null");
1482         }
1483 }
1484
1485 void StatusNotification::setThumbnail( const std::string& thumb, int index)
1486 {
1487         if (m_notiHandle)
1488         {
1489                 LogInfo(" index : " << index);
1490                 LogInfo(" thumb : " << thumb);
1491                 notification_image_type_e type = NOTIFICATION_IMAGE_TYPE_NONE; 
1492                 
1493                 switch (index)
1494                 {
1495                         case 0:
1496                                 type = NOTIFICATION_IMAGE_TYPE_LIST_1;
1497                                 break;
1498                         case 1:
1499                                 type = NOTIFICATION_IMAGE_TYPE_LIST_2;
1500                                 break;
1501                         case 2:
1502                                 type = NOTIFICATION_IMAGE_TYPE_LIST_3;
1503                                 break;
1504                         case 3:
1505                                 type = NOTIFICATION_IMAGE_TYPE_LIST_4;
1506                                 break;
1507                         case 4:
1508                                 type = NOTIFICATION_IMAGE_TYPE_LIST_5;
1509                                 break;
1510                         default :
1511                                 type = NOTIFICATION_IMAGE_TYPE_NONE;
1512                 }
1513
1514                 if ( type != NOTIFICATION_IMAGE_TYPE_NONE)
1515                 {
1516                         if (getThumbnail(index).compare(thumb))
1517                         {
1518                                 if (notification_set_image(m_notiHandle, type, thumb.c_str()) != NOTIFICATION_ERROR_NONE)
1519                                 {
1520                                         throw UnknownException( "set notification thumbnail error");
1521                                 }
1522                                 setUpdatedFlag(true);
1523                         }
1524                 }
1525         }
1526 }
1527
1528 std::string StatusNotification::getBackground()
1529 {
1530         LogInfo(" Handle : " << m_notiHandle);
1531
1532         if (m_notiHandle)
1533         {
1534                 char *background = NULL;
1535         
1536                 if (notification_get_image(m_notiHandle, NOTIFICATION_IMAGE_TYPE_BACKGROUND, &background) != NOTIFICATION_ERROR_NONE)
1537                 {
1538                         throw UnknownException( "get notification background error");
1539                 }
1540                 
1541                 std::string notiBackground;
1542                 if (background)
1543                         notiBackground = background;
1544                 return notiBackground;
1545         }
1546         else
1547         {
1548                 LogDebug("noti Handle is NULL");
1549                 throw UnknownException( "notification handle is null");
1550         }
1551
1552 }
1553
1554 void StatusNotification::setBackground(const std::string imagePath)
1555 {
1556         LogInfo(" imagePath : " << imagePath);
1557         if (m_notiHandle)
1558         {
1559                 if (getBackground().compare(imagePath))
1560                 {
1561                         if (notification_set_image(m_notiHandle,NOTIFICATION_IMAGE_TYPE_BACKGROUND, imagePath.c_str()) != NOTIFICATION_ERROR_NONE)
1562                         {
1563                                 throw UnknownException( "set notification sound error");
1564                         }
1565                         setUpdatedFlag(true);
1566                 }
1567         }
1568         else
1569         {       
1570                 LogDebug("noti Handle is NULL");
1571                 throw UnknownException( "notification handle is null");
1572         }
1573 }
1574
1575 long StatusNotification::getNumber()
1576 {
1577         LogInfo("Handle = " << m_notiHandle);
1578         if (m_notiHandle)
1579         {
1580                 long number = 0;
1581                 char *strNumber = NULL;
1582
1583                 if (notification_get_text(m_notiHandle, NOTIFICATION_TEXT_TYPE_EVENT_COUNT, &strNumber) != NOTIFICATION_ERROR_NONE)
1584                 {
1585                         throw UnknownException( "get notification background error");
1586                 }
1587
1588                 if (strNumber)
1589                         std::istringstream(strNumber) >> number;
1590                 else
1591                         LogInfo("Number Is NULL");
1592
1593                 LogInfo("number = " << number);
1594
1595                 return number;
1596         }
1597         else
1598         {
1599                 LogDebug("noti Handle is NULL");
1600                 return 0;
1601         }
1602 }
1603
1604 const char* StatusNotification::getStrNumber()
1605 {
1606         LogInfo("Handle = " << m_notiHandle);
1607         if (m_notiHandle)
1608         {
1609                 char *strNumber = NULL;
1610
1611                 if (notification_get_text(m_notiHandle, NOTIFICATION_TEXT_TYPE_EVENT_COUNT, &strNumber) != NOTIFICATION_ERROR_NONE)
1612                 {
1613                         throw UnknownException( "get notification background error");
1614                 }
1615
1616                 if (!strNumber)
1617                 {
1618                         return NULL;
1619                 }
1620
1621                 return strNumber;
1622         }
1623         else
1624         {
1625                 LogDebug("noti Handle is NULL");
1626                 return NULL;
1627         }
1628 }
1629
1630 void StatusNotification::setNumber(const long number)
1631 {
1632         LogInfo("Number = " << number);
1633         if (m_notiHandle)
1634         {
1635                 if(number!=getNumber())
1636                 {
1637                         std::stringstream stream;
1638                         stream << number;
1639                         if (stream.fail()) {
1640                                 throw UnknownException(
1641                                                  "Couldn't convert notification number");
1642                         }
1643                         
1644                         std::string strNumber = stream.str();           
1645                         if (notification_set_text(m_notiHandle, NOTIFICATION_TEXT_TYPE_EVENT_COUNT, strNumber.c_str(),
1646                                 NULL, NOTIFICATION_VARIABLE_TYPE_NONE) != NOTIFICATION_ERROR_NONE)
1647                         {
1648                                 throw UnknownException( "set notification text error");
1649                         }
1650                         setUpdatedFlag(true);
1651                 }
1652         }
1653         else
1654         {               
1655                 LogDebug("noti Handle is NULL");
1656                 throw UnknownException( "notification handle is null");
1657         }
1658 }
1659
1660 void* StatusNotification::getNotificationHandle()
1661 {
1662         return m_notiHandle;
1663 }
1664
1665 void StatusNotification::setNotificationHandle(void *handle)
1666 {
1667         if (handle == NULL)
1668         {
1669                 throw UnknownException( "notification handle null error");
1670         }
1671         LogInfo("handle = " << handle << " m_notiHandle = " << m_notiHandle);
1672         
1673         if (m_notiHandle != NULL)
1674         {       
1675                 //delete old noti.
1676                 if ( notification_delete(m_notiHandle) != NOTIFICATION_ERROR_NONE)
1677                 {
1678                         throw UnknownException( "notification delete error");
1679                 }
1680                 m_notiHandle = NULL;
1681         }
1682         
1683         m_notiHandle = (notification_h)handle;
1684 }
1685
1686 service_h StatusNotification::getService()
1687 {
1688         return m_service;
1689 }
1690
1691
1692 //Detail Info
1693 void StatusNotification::loadDetailInfos()
1694 {
1695         LogInfo("noti Handle = " << m_notiHandle);
1696
1697         if (m_notiHandle)
1698         {
1699                 for ( int idx = 0; idx < MAX_NOTIFICATION_DETAIL_INFO_LENGTH; idx++)
1700                 {
1701                     std::string main = getInformation(idx);
1702                     std::string sub = getSubInformation(idx);
1703                     LogInfo("Main : " << main << " Sub : " << sub);
1704                     NotificationDetailInfo *info = new NotificationDetailInfo(m_notiHandle, idx, main, sub);
1705                     m_detailInfos.push_back(info);
1706                 }
1707         }
1708         else
1709         {               
1710                 LogDebug("noti Handle is NULL");
1711                 throw UnknownException( "notification handle is null");
1712         }
1713         
1714 }
1715
1716 std::vector<NotificationDetailInfo*> StatusNotification::getDetailInfos() const
1717 {
1718         return m_detailInfos;
1719 }
1720
1721 void StatusNotification::setDetailInfos(const std::vector<NotificationDetailInfo*> value)
1722 {
1723     LogInfo("DetailInfos = " << value.size());
1724
1725     if (m_notiHandle)
1726     {
1727         std::vector<NotificationDetailInfo*>::const_iterator it;
1728         
1729         int idx = 0;
1730         for (it = value.begin(); it < value.end(); ++it)
1731         {
1732             NotificationDetailInfo* info = *it;
1733             if ( idx < MAX_NOTIFICATION_DETAIL_INFO_LENGTH )
1734             {
1735                 LogInfo("main " << info->getMainText() << " sub " << info->getSubText() );
1736                 setInformation(info->getMainText(), idx);
1737                 setSubInformation(info->getSubText(), idx);
1738             }
1739             idx ++;
1740         }
1741     
1742         m_detailInfos = value;
1743     }
1744     else
1745     {   
1746         LogDebug("noti Handle is NULL");
1747         throw UnknownException( "notification handle is null");
1748     }
1749         
1750 }
1751
1752 int StatusNotification::getDetailInfosNum() const
1753 {
1754         return m_detailInfos.size();
1755 }
1756
1757 void StatusNotification::clearDetailInfos()
1758 {
1759         if ( !m_detailInfos.empty() )
1760         {
1761                 std::vector<NotificationDetailInfo*>::const_iterator it;
1762                
1763                 int idx = 0;
1764                 for (it = m_detailInfos.begin(); it < m_detailInfos.end(); ++it)
1765                 {
1766                     NotificationDetailInfo* info = *it;
1767                     LogInfo("Delete Detail Info : " << info);
1768                     if (info)
1769                         delete info;
1770                     idx ++;
1771                 }
1772                 m_detailInfos.clear();          //clear
1773         }
1774 }
1775
1776 std::string StatusNotification::getInformation(int index)
1777 {
1778         if (m_notiHandle)
1779         {
1780                 notification_text_type_e type = NOTIFICATION_TEXT_TYPE_NONE; 
1781                 switch (index)
1782                 {
1783                         case 0:
1784                                 type = NOTIFICATION_TEXT_TYPE_INFO_1;
1785                                 break;
1786                         case 1:
1787                                 type = NOTIFICATION_TEXT_TYPE_INFO_2;
1788                                 break;
1789                         case 2:
1790                                 type = NOTIFICATION_TEXT_TYPE_INFO_3;
1791                                 break;
1792                         default :
1793                                 type = NOTIFICATION_TEXT_TYPE_NONE;
1794                 }
1795                 char *info = NULL;
1796                 
1797                 if (NOTIFICATION_TEXT_TYPE_NONE != type && notification_get_text(m_notiHandle, type, &info) != NOTIFICATION_ERROR_NONE)
1798                 {
1799                         throw UnknownException("Detail Info index value is invalid or mainText value getting is failed in Detail Info.");
1800                 }
1801
1802                 std::string strInfo;
1803                 if (info)
1804                         strInfo = info;
1805                 LogInfo(" info " << strInfo);
1806                 return strInfo;
1807
1808         }
1809         else
1810         {       
1811                 LogWarning("noti Handle is NULL");
1812                 throw UnknownException( "notification handle is null");
1813         }
1814         
1815 }
1816
1817 std::string StatusNotification::getSubInformation(int index)
1818 {
1819         if (m_notiHandle)
1820         {
1821                 notification_text_type_e type = NOTIFICATION_TEXT_TYPE_NONE; 
1822                 switch (index)
1823                 {
1824                         case 0:
1825                                 type = NOTIFICATION_TEXT_TYPE_INFO_SUB_1;
1826                                 break;
1827                         case 1:
1828                                 type = NOTIFICATION_TEXT_TYPE_INFO_SUB_2;
1829                                 break;
1830                         case 2:
1831                                 type = NOTIFICATION_TEXT_TYPE_INFO_SUB_3;
1832                                 break;
1833                         default :
1834                                 type = NOTIFICATION_TEXT_TYPE_NONE;
1835                 }
1836                                 
1837                 char *subInfo = NULL;
1838                 
1839                 if (NOTIFICATION_TEXT_TYPE_NONE != type && notification_get_text(m_notiHandle, type, &subInfo) != NOTIFICATION_ERROR_NONE)
1840                 {
1841                         throw UnknownException("Detail Info index value is invalid or subText value getting is failed in Detail Info.");
1842                 }
1843
1844                 std::string strSubInfo;
1845                 if (subInfo)
1846                         strSubInfo = subInfo;
1847                 LogInfo(" subInfo " << strSubInfo);
1848                 return strSubInfo;
1849                                 
1850         }
1851         else
1852         {       
1853                 LogWarning("noti Handle is NULL");
1854                 throw UnknownException ("notification handle is null");
1855         }
1856         
1857 }
1858
1859 void StatusNotification::setInformation( const std::string& info, int index)
1860 {
1861         if (m_notiHandle)
1862         {
1863                 int idx = index;
1864                 LogDebug(" index : " << idx);
1865                 LogDebug(" log : " << info);
1866                 notification_text_type_e type = NOTIFICATION_TEXT_TYPE_NONE; 
1867                 
1868                 switch (idx)
1869                 {
1870                         case 0:
1871                                 type = NOTIFICATION_TEXT_TYPE_INFO_1;
1872                                 break;
1873                         case 1:
1874                                 type = NOTIFICATION_TEXT_TYPE_INFO_2;
1875                                 break;
1876                         case 2:
1877                                 type = NOTIFICATION_TEXT_TYPE_INFO_3;
1878                                 break;
1879                         default :
1880                                 type = NOTIFICATION_TEXT_TYPE_NONE;
1881                 }
1882
1883                 if ( type != NOTIFICATION_TEXT_TYPE_NONE)
1884                 {
1885                         if (getInformation(idx).compare(info))
1886                         {
1887                                 if (notification_set_text(m_notiHandle, type, info.c_str(),
1888                                         NULL, NOTIFICATION_VARIABLE_TYPE_NONE) != NOTIFICATION_ERROR_NONE)
1889                                 {
1890                                         throw UnknownException("set notification sound error");
1891                                 }
1892                                 setUpdatedFlag(true);
1893                         }
1894                 }
1895                 else
1896                 {       
1897                         LogWarning("noti Handle is NULL");
1898                         throw UnknownException("notification handle is null");
1899                 }
1900         }
1901         else
1902         {       
1903                 LogWarning("noti Handle is NULL");
1904                 throw UnknownException("notification handle is null");
1905         }
1906 }
1907
1908 void StatusNotification::setSubInformation( const std::string& subInfo, int index)
1909 {
1910
1911         if (m_notiHandle)
1912         {
1913                 int idx = index;
1914                 LogDebug(" index : " << idx);
1915                 LogDebug(" log : " << subInfo);
1916                 notification_text_type_e type = NOTIFICATION_TEXT_TYPE_NONE; 
1917                 
1918                 switch (idx)
1919                 {
1920                         case 0:
1921                                 type = NOTIFICATION_TEXT_TYPE_INFO_SUB_1;
1922                                 break;
1923                         case 1:
1924                                 type = NOTIFICATION_TEXT_TYPE_INFO_SUB_2;
1925                                 break;
1926                         case 2:
1927                                 type = NOTIFICATION_TEXT_TYPE_INFO_SUB_3;
1928                                 break;
1929                         default :
1930                                 type = NOTIFICATION_TEXT_TYPE_NONE;
1931                 }
1932
1933                 if ( type != NOTIFICATION_TEXT_TYPE_NONE)
1934                 {
1935                         if (getSubInformation(idx).compare(subInfo))
1936                         {
1937                                 if (notification_set_text(m_notiHandle, type, subInfo.c_str(),
1938                                         NULL, NOTIFICATION_VARIABLE_TYPE_NONE) != NOTIFICATION_ERROR_NONE)
1939                                 {
1940                                         throw UnknownException("set notification sound error");
1941                                 }
1942                                 setUpdatedFlag(true);
1943                         }
1944                 }
1945         }
1946         else
1947         {       
1948                 LogWarning("noti Handle is NULL");
1949                 throw UnknownException("notification handle is null");
1950         }
1951 }
1952
1953
1954 #if 0
1955
1956 StatusNotification::StatusNotification():
1957     m_statusType(""),
1958     m_iconPath(""),
1959     m_subIconPath(""),
1960     m_number(0),
1961     m_backgroundImagePath(""),
1962     m_soundPath(""),
1963     m_vibration(false),
1964     m_progressType(""),
1965     m_progressValue(0)
1966 {
1967 }
1968
1969 StatusNotification::~StatusNotification()
1970 {
1971 }
1972
1973 std::string StatusNotification::getStatusType() const
1974 {
1975     return m_statusType;
1976 }
1977
1978 void StatusNotification::setStatusType(std::string statusType)
1979 {
1980     m_statusType = statusType;
1981 }
1982
1983 std::string StatusNotification::getIconPath() const
1984 {
1985     return m_iconPath;
1986 }
1987
1988 void StatusNotification::setIconPath(std::string iconPath)
1989 {
1990     m_iconPath = iconPath;
1991 }
1992
1993 std::string StatusNotification::getSubIconPath() const
1994 {
1995     return m_subIconPath;
1996 }
1997
1998 void StatusNotification::setSubIconPath(std::string subIconPath)
1999 {
2000     m_subIconPath = subIconPath;
2001 }
2002
2003 long StatusNotification::getNumber() const
2004 {
2005     return m_number;
2006 }
2007
2008 void StatusNotification::setNumber(long number)
2009 {
2010     m_number = number;
2011 }
2012
2013 std::vector<NotificationDetailInfo*> StatusNotification::getDetailInfo() const
2014 {
2015     return m_detailInfo;
2016 }
2017
2018 void StatusNotification::setDetailInfo(std::vector<NotificationDetailInfo*> detailInfo)
2019 {
2020     m_detailInfo = detailInfo;
2021 }
2022
2023 std::string StatusNotification::getBackgroundImagePath() const
2024 {
2025     return m_backgroundImagePath;
2026 }
2027
2028 void StatusNotification::setBackgroundImagePath(std::string backgroundImagePath)
2029 {
2030     m_backgroundImagePath = backgroundImagePath;
2031 }
2032
2033 std::vector<std::string> StatusNotification::getThumbnails() const
2034 {
2035     return m_thumbnails;
2036 }
2037
2038 void StatusNotification::setThumbnails(std::vector<std::string> thumbnails)
2039 {
2040     m_thumbnails = thumbnails;
2041 }
2042
2043 std::string StatusNotification::getSoundPath() const
2044 {
2045     return m_soundPath;
2046 }
2047
2048 void StatusNotification::setSoundPath(std::string soundPath)
2049 {
2050     m_soundPath = soundPath;
2051 }
2052
2053 bool StatusNotification::getVibration() const
2054 {
2055     return m_vibration;
2056 }
2057
2058 void StatusNotification::setVibration(bool vibration)
2059 {
2060     m_vibration = vibration;
2061 }
2062
2063 ApplicationControl StatusNotification::getAppControl() const
2064 {
2065     return m_appControl;
2066 }
2067
2068 void StatusNotification::setAppControl(ApplicationControl appControl)
2069 {
2070     m_appControl = appControl;
2071 }
2072
2073 ApplicationId StatusNotification::getAppId() const
2074 {
2075     return m_appId;
2076 }
2077
2078 void StatusNotification::setAppId(ApplicationId appId)
2079 {
2080     m_appId = appId;
2081 }
2082
2083 std::string StatusNotification::getProgressType() const
2084 {
2085     return m_progressType;
2086 }
2087
2088 void StatusNotification::setProgressType(std::string progressType)
2089 {
2090     m_progressType = progressType;
2091 }
2092
2093 unsigned long StatusNotification::getProgressValue() const
2094 {
2095     return m_progressValue;
2096 }
2097
2098 void StatusNotification::setProgressValue(unsigned long progressValue)
2099 {
2100     m_progressValue = progressValue;
2101 }
2102 #endif
2103
2104 } // Notification
2105 } // DeviceAPI