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