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