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