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