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