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