Initialize Tizen 2.3
[apps/home/b2-clocksetting.git] / src / setting-sound.c
1 /*
2  * Copyright (c) 2000 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16 */
17 #include <feedback.h>
18 #include <sys/types.h>
19 #include <dirent.h>
20 #include <vconf.h>
21 #include <vconf-keys.h>
22
23 #include "setting-sound.h"
24 #include "util.h"
25 #include "setting-common-sound.h"
26 #include "setting_control_haptic.h"
27 #include "setting_view_toast.h"
28 #include "setting_data_vconf.h"
29 #include "setting-volume.h"
30
31
32 #define AUDIO_RESOURCE_EXTENSION        ".ogg"
33
34 static struct _sound_menu_item sound_menu_its[] = {
35         { "IDS_ST_OPT_VOLUME",                                  0,              _volume_cb      },
36         { "IDS_ST_OPT_SOUND_MODE_ABB",                  0,              _sound_mode_cb  },
37         { "IDS_ST_BODY_TOUCH_SOUNDS_ABB",               0,              _touch_sound_cb },
38         { "IDS_CST_MBODY_RINGTONES",            0,              _ringtone_cb    },
39         { "IDS_ST_BUTTON_NOTIFICATIONS",                0,              _noti_cb                },
40         { "IDS_ST_HEADER_VIBRATION_ABB",                0,              _vibrate_cb     },
41 //      { "IDS_ST_BODY_PREFERRED_ARM_ABB",      0,              _preferred_cb   },
42         { NULL, 0, NULL }
43 };
44
45 char* sound_mode_str[] = {
46                 "IDS_ST_OPT_SOUND_ABB2",
47                 "IDS_ST_BODY_VIBRATE_ABB2",
48                 "IDS_ST_OPT_MUTE"
49 };
50 char* ringtone_str[] = {
51                 "Ringtone1",
52                 "Ringtone2",
53                 "Ringtone3"
54 };
55 char* notification_str[] = {
56                 "Notification1",
57                 "Notification2",
58                 "Notification3"
59 };
60 char* vibration_str[] = {
61                 "IDS_ST_OPT_STRONG_M_INTENSITY",
62                 //"IDS_ST_OPT_MEDIUM_M_INTENSITY",
63                 "IDS_ST_OPT_WEAK_M_INTENSITY"
64 };
65 char* pref_arm_str[] = {
66                 "IDS_ST_OPT_LEFT_ARM_ABB",
67                 "IDS_ST_OPT_RIGHT_ARM_ABB"
68 };
69 char* pref_arm_toast_msg[] = {
70                 "IDS_ST_TPOP_MAIN_MIC_ADJUSTED_FOR_LEFT_ARM",
71                 "IDS_ST_TPOP_MAIN_MIC_ADJUSTED_FOR_RIGHT_ARM"
72 };
73
74 static char ringtone_arr[RINGTONE_MAX_COUNT][1024];
75 static char ringtone_name_arr[RINGTONE_MAX_COUNT][1024];
76 static char notification_arr[RINGTONE_MAX_COUNT][1024];
77 static char notification_name_arr[RINGTONE_MAX_COUNT][1024];
78
79 static appdata* temp_ad                                         = NULL;
80 static Evas_Object* g_sound_genlist                     = NULL;
81 static Evas_Object* g_sound_mode_genlist                = NULL;
82 static Evas_Object* g_ringtone_type_genlist     = NULL;
83 static Evas_Object* g_notification_type_genlist = NULL;
84 static Evas_Object* g_vibration_type_genlist    = NULL;
85 static Evas_Object* g_pref_arm_type_genlist     = NULL;
86 static Elm_Object_Item * g_vib_item = NULL;
87
88 static int sound_mode        = 1;                       // Vibrate
89 static int ringtone_type         = 0;                   // Rigntone type
90 static int confirmed_ringtone_type       = 0;                   // setted Rigntone type
91 static int notification_type = 0;                       // Notification type
92 static int confirmed_Notification_type   = 0;                   // setted Notification type
93 static int vibrate_type          = 0;                   // Vibration type
94 static int pref_arm_type         = 0;                   // Pref_arm_type
95 static int changing_sound_mode_myself = 0;
96
97 static int ringtone_count = 0;
98 static int notification_count = 0;
99
100 char curr_ringtone_file_path[1023];
101 char curr_noti_file_path[1023];
102
103 static int cur_sound_type;
104 static int is_loaded_ringtone_data = 0;
105 static int is_loaded_noti_data = 0;
106 static int origin_vibration_level;
107
108 static Ecore_Timer * vibration_timer = NULL;
109
110 static int is_wav_playing = SOUND_STATE_STOP;
111 static int sound_id = -1;
112
113
114 static void sound_vconf_changed_cb(keynode_t * key, void * data);
115 static void vibrate_vconf_changed_cb(keynode_t * key, void * data);
116 static void pm_state_vconf_changed_cb(keynode_t * key, void * data);
117 static void _vibration_gl_cb(void *data, Evas_Object *obj, void *event_info);
118 static void stop_wav();
119
120
121 void _initialize()
122 {
123         // touch sound
124         //effect_playsound_init();
125 }
126
127 Eina_Bool _clear_sound_cb(void *data, Elm_Object_Item *it)
128 {
129         _clear_sound_resource();
130
131         return EINA_TRUE;
132 }
133
134 void _clear_sound_resource()
135 {
136         if( vibration_timer ) {
137                 ecore_timer_del(vibration_timer);
138                 vibration_timer = NULL;
139         }
140
141         _haptic_close();
142
143         temp_ad = NULL;
144         g_sound_genlist = NULL;
145         g_sound_mode_genlist = NULL;
146         g_ringtone_type_genlist = NULL;
147         g_notification_type_genlist = NULL;
148         g_vibration_type_genlist = NULL;
149         g_pref_arm_type_genlist = NULL;
150         g_vib_item = NULL;
151
152         sound_mode = 0;
153         ringtone_type = 0;
154         notification_type = 0;
155         vibrate_type = 0;
156         pref_arm_type = 0;
157         cur_sound_type = 0;
158         is_loaded_ringtone_data = 0;
159         is_loaded_noti_data = 0;
160         origin_vibration_level = 0;
161
162         is_wav_playing = 0;
163         sound_id = -1;
164
165         _stop_player();
166
167         /* Unregister sound mode vconf callback */
168         unregister_vconf_changing(VCONFKEY_SETAPPL_SOUND_STATUS_BOOL, sound_vconf_changed_cb);
169         unregister_vconf_changing(VCONFKEY_SETAPPL_VIBRATION_STATUS_BOOL, vibrate_vconf_changed_cb);
170 }
171
172 void _stop_all_sound_play()
173 {
174         DBG("Setting - stop all sound");
175
176         stop_wav();
177
178         _stop_player();
179 }
180
181 static void stop_wav()
182 {
183         if( is_wav_playing == SOUND_STATE_PLAY ) {
184                 DBG("Setting - sound id : %d", sound_id);
185
186                 wav_player_stop(sound_id);
187                 is_wav_playing = SOUND_STATE_STOP;
188                 sound_id = -1;
189         }
190 }
191
192 void _stop_wav_player()
193 {
194         stop_wav();
195 }
196
197 void _stop_player()
198 {
199         DBG("Setting - _stop_player() is called!");
200         if( is_created_player() )
201         {
202                 _close_player(NULL, cur_sound_type);
203         }
204 }
205
206 static void sorting_file_list(int type)
207 {
208         int i;
209         int j;
210         char * cur_ring_path = NULL;
211         if( type )
212         {
213                 if( ringtone_count == 0 )
214                 {
215                         return;
216                 }
217
218                 cur_ring_path = vconf_get_str(VCONFKEY_SETAPPL_CALL_RINGTONE_PATH_STR);
219                 if( cur_ring_path == NULL )
220                 {
221                         cur_ring_path = vconf_get_str(VCONFKEY_SETAPPL_CALL_RINGTONE_DEFAULT_PATH_STR);
222                 }
223
224                 for( i = 0; i < 3; i++ )
225                 {
226                         for( j = i+1; j < 3; j++ )
227                         {
228                                 if( strcmp(ringtone_name_arr[i], ringtone_name_arr[j]) > 0 )
229                                 {
230                                         char temp[1024];
231                                         strcpy(temp, ringtone_name_arr[i]);
232                                         strcpy(ringtone_name_arr[i], ringtone_name_arr[j]);
233                                         strcpy(ringtone_name_arr[j], temp);
234
235                                         strcpy(temp, "");
236                                         strcpy(temp, ringtone_arr[i]);
237                                         strcpy(ringtone_arr[i], ringtone_arr[j]);
238                                         strcpy(ringtone_arr[j], temp);
239                                 }
240                         }
241                 }
242
243                 for( i = 0; i < 3; i++ )
244                 {
245                         if( !strcmp(cur_ring_path, ringtone_arr[i]))
246                         {
247                                 ringtone_type = i;
248                                 break;
249                         }
250                 }
251         }
252         else
253         {
254                 if( notification_count == 0 )
255                 {
256                         return;
257                 }
258
259                 cur_ring_path = vconf_get_str(VCONFKEY_SETAPPL_NOTI_MSG_RINGTONE_PATH_STR);
260                 if( cur_ring_path == NULL )
261                 {
262                         cur_ring_path = vconf_get_str(VCONFKEY_SETAPPL_NOTI_RINGTONE_DEFAULT_PATH_STR);
263                 }
264
265                 for( i = 0; i < 3; i++ )
266                 {
267                         for( j = i+1; j < 3; j++ )
268                         {
269                                 if( strcmp(notification_name_arr[i], notification_name_arr[j]) > 0 )
270                                 {
271                                         char temp[1024];
272                                         strcpy(temp, notification_name_arr[i]);
273                                         strcpy(notification_name_arr[i], notification_name_arr[j]);
274                                         strcpy(notification_name_arr[j], temp);
275
276                                         strcpy(temp, "");
277                                         strcpy(temp, notification_arr[i]);
278                                         strcpy(notification_arr[i], notification_arr[j]);
279                                         strcpy(notification_arr[j], temp);
280                                 }
281                         }
282                 }
283
284                 for( i = 0; i < 3; i++ )
285                 {
286                         if( !strcmp(cur_ring_path, notification_arr[i]))
287                         {
288                                 notification_type = i;
289                                 break;
290                         }
291                 }
292         }
293 }
294
295 static void get_sound_file_list(char* dir, int type)
296 {
297         DIR * dp;
298         struct dirent *dirp;
299         char * cur_ring_path = NULL;
300
301         if((dp = opendir(dir)) == NULL ) {
302                 DBG("Setting - dir open error!");
303                 return;
304         }
305
306         if( type ) {
307                 cur_ring_path = vconf_get_str(VCONFKEY_SETAPPL_CALL_RINGTONE_PATH_STR);
308                 if( cur_ring_path == NULL )
309                 {
310                         cur_ring_path = vconf_get_str(VCONFKEY_SETAPPL_CALL_RINGTONE_DEFAULT_PATH_STR);
311                 }
312                 ringtone_count = 0;
313         }
314         else
315         {
316                 cur_ring_path = vconf_get_str(VCONFKEY_SETAPPL_NOTI_MSG_RINGTONE_PATH_STR);
317                 if( cur_ring_path == NULL )
318                 {
319                         cur_ring_path = vconf_get_str(VCONFKEY_SETAPPL_NOTI_RINGTONE_DEFAULT_PATH_STR);
320                 }
321                 notification_count = 0;
322         }
323
324         while( (dirp = readdir(dp)) )
325         {
326                 if( strncmp(dirp->d_name, ".", 1) )
327                 {
328                         if( type )
329                         {
330                                 strcpy(ringtone_arr[ringtone_count], dir);
331                                 strcat(ringtone_arr[ringtone_count], dirp->d_name);
332
333                                 strcpy(ringtone_name_arr[ringtone_count], replace(dirp->d_name, ".ogg", ""));
334
335                                 //DBG("Setting - %s", ringtone_arr[ringtone_count]);
336
337                                 if(!strcmp(cur_ring_path, ringtone_arr[ringtone_count]))
338                                 {
339                                         ringtone_type = ringtone_count;
340                                         //DBG("Settng - %s is same with %s", cur_ring_path, ringtone_arr[ringtone_count]);
341                                 }
342                                 //DBG("Settng - %s is same with %s", cur_ring_path, ringtone_arr[ringtone_count]);
343
344                                 ringtone_count++;
345                         }
346                         else
347                         {
348                                 strcpy(notification_arr[notification_count], dir);
349                                 strcat(notification_arr[notification_count], dirp->d_name);
350
351                                 strcpy(notification_name_arr[notification_count], replace(dirp->d_name, ".ogg", ""));
352                                 strcpy(notification_name_arr[notification_count], replace(notification_name_arr[notification_count], "_", " "));
353
354                                 //DBG("Setting - %s", notification_arr[notification_count]);
355
356                                 if(!strcmp(cur_ring_path, notification_arr[notification_count]))
357                                 {
358                                         notification_type = notification_count;
359                                         //DBG("Settng - %s is same with %s", cur_ring_path, notification_arr[notification_count]);
360                                 }
361                                 //DBG("Settng - %s is same with %s", cur_ring_path, notification_arr[notification_count]);
362
363                                 notification_count++;
364                         }
365                 }
366         }
367         closedir(dp);
368 }
369
370
371 static int get_vibration_level()
372 {
373         int mode = 1;
374         int level = 0;
375
376         vconf_get_int(VCONFKEY_SETAPPL_NOTI_VIBRATION_LEVEL_INT, &level);
377
378         switch(level) {
379         case VIBRATION_LEVEL_LOW_INT :
380                 mode = VIBRATION_LEVEL_LOW;
381                 break;
382 //      case VIBRATION_LEVEL_MID_INT :
383 //              mode = VIBRATION_LEVEL_MID;
384 //              break;
385         case VIBRATION_LEVEL_HIGH_INT :
386                 mode = VIBRATION_LEVEL_HIGH;
387                 break;
388         }
389         return mode;
390 }
391
392 void _show_volume_list(void *data)
393 {
394         Evas_Object* genlist = NULL;
395         Elm_Object_Item *nf_it = NULL;
396         appdata *ad = data;
397
398         if( ad == NULL )
399         {
400                 DBG("Setting - ad is null");
401                 return;
402         }
403
404         _initialize_volume();
405
406         genlist = _create_volume_list(data);
407         if(genlist == NULL)
408         {
409                 DBG("%s", "volume cb - genlist is null");
410                 return;
411         }
412         nf_it = elm_naviframe_item_push(ad->nf, NULL, NULL, NULL, genlist, NULL);
413         elm_naviframe_item_title_enabled_set(nf_it, EINA_FALSE, EINA_FALSE);
414         evas_object_event_callback_add(genlist, EVAS_CALLBACK_DEL, _clear_volume_cb, ad);
415 }
416
417 void _volume_cb(void *data, Evas_Object *obj, void *event_info)
418 {
419         elm_genlist_item_selected_set((Elm_Object_Item *)event_info, EINA_FALSE);
420
421         _show_volume_list(data);
422 }
423
424 void _sound_mode_cb(void *data, Evas_Object *obj, void *event_info)
425 {
426         elm_genlist_item_selected_set((Elm_Object_Item *)event_info, EINA_FALSE);
427
428         _show_sound_mode_list(data);
429 }
430
431 void _touch_sound_cb(void *data, Evas_Object *obj, void *event_info)
432 {
433         Elm_Object_Item* it = (Elm_Object_Item *)event_info;
434         appdata *ad = data;
435
436         if( ad == NULL )
437         {
438                 DBG("%s", "_touch_sound_cb - appdata or check is null");
439                 return;
440         }
441         sound_menu_its[2].is_enable_touch_sound = sound_menu_its[2].is_enable_touch_sound ? 0 : 1;
442         vconf_set_bool(VCONFKEY_SETAPPL_TOUCH_SOUNDS_BOOL, sound_menu_its[2].is_enable_touch_sound);
443         vconf_set_bool(VCONFKEY_SETAPPL_BUTTON_SOUNDS_BOOL, sound_menu_its[2].is_enable_touch_sound);
444
445         elm_genlist_item_selected_set(it, EINA_FALSE);
446
447         elm_genlist_item_update(it);
448 }
449
450 void _ringtone_cb(void *data, Evas_Object *obj, void *event_info)
451 {
452         elm_genlist_item_selected_set((Elm_Object_Item *)event_info, EINA_FALSE);
453
454         _show_ringtone_popup_cb(data, obj, event_info);
455 }
456
457 void _noti_cb(void *data, Evas_Object *obj, void *event_info)
458 {
459         elm_genlist_item_selected_set((Elm_Object_Item *)event_info, EINA_FALSE);
460
461         _show_notification_popup_cb(data, obj, event_info);
462 }
463
464 void _vibrate_cb(void *data, Evas_Object *obj, void *event_info)
465 {
466         elm_genlist_item_selected_set((Elm_Object_Item *)event_info, EINA_FALSE);
467
468         _show_vibration_popup_cb(data, obj, event_info);
469 }
470
471 void _preferred_cb(void *data, Evas_Object *obj, void *event_info)
472 {
473         elm_genlist_item_selected_set((Elm_Object_Item *)event_info, EINA_FALSE);
474
475         _show_pref_arm_mode_list(data);
476 }
477
478 static char * _get_sound_file_name(char * full_name)
479 {
480         char * token = NULL;
481         char * temp_token = NULL;
482         char sep[] = "*/*";
483
484         DBG("Setting - %s, %s", token, full_name);
485
486         strtok(full_name, sep);
487
488         do {
489                 token = strtok(NULL, sep);
490                 if( token != NULL ) {
491                         temp_token = token;
492                 }
493         }while( token != NULL );
494
495         char * result_token = NULL;
496         if( temp_token )
497         {
498                 temp_token = replace(temp_token, ".ogg", "");
499                 result_token = replace(temp_token, "_", " ");
500         }
501         return result_token;
502 }
503
504 char * _gl_Sound_title_get(void *data, Evas_Object *obj, const char *part)
505 {
506         char buf[1024];
507         Item_Data *id = data;
508         int index = id->index;
509         char * pa_cur_ringtone = NULL;
510
511         if( !strcmp(part, "elm.text.1") || !strcmp(part, "elm.text") )
512         {
513                 snprintf(buf, sizeof(buf)-1, "%s", _(sound_menu_its[index % ITEM_SIZE].name));
514         }
515         else if( !strcmp(part, "elm.text.2") )
516         {
517                 switch( index ){
518                 case 1 :
519                         sound_mode = get_sound_mode();
520                         snprintf(buf, sizeof(buf)-1, "%s", _(sound_mode_str[sound_mode % 3]));
521                         break;
522                 case 3 :
523                         pa_cur_ringtone = vconf_get_str(VCONFKEY_SETAPPL_CALL_RINGTONE_PATH_STR);
524                         if( pa_cur_ringtone == NULL ) {
525                                 pa_cur_ringtone = vconf_get_str(VCONFKEY_SETAPPL_CALL_RINGTONE_DEFAULT_PATH_STR);
526                         }
527                         strcpy(curr_ringtone_file_path, pa_cur_ringtone);
528                         DBG("Setting - ringtone path : %s", pa_cur_ringtone);
529
530                         snprintf(buf, sizeof(buf)-1, "%s", _get_sound_file_name(pa_cur_ringtone));
531                         break;
532                 case 4 :
533                         pa_cur_ringtone = vconf_get_str(VCONFKEY_SETAPPL_NOTI_MSG_RINGTONE_PATH_STR);
534                         if( pa_cur_ringtone == NULL ) {
535                                 pa_cur_ringtone = vconf_get_str(VCONFKEY_SETAPPL_NOTI_RINGTONE_DEFAULT_PATH_STR);
536                         }
537                         strcpy(curr_noti_file_path, pa_cur_ringtone);
538                         DBG("Setting - noti's ringtone path : %s", pa_cur_ringtone);
539
540                         snprintf(buf, sizeof(buf)-1, "%s", _get_sound_file_name(pa_cur_ringtone));
541                         break;
542                 case 5 :
543                         vibrate_type = get_vibration_level();
544                         snprintf(buf, sizeof(buf)-1, "%s", _(vibration_str[vibrate_type % 3]));
545                         break;
546 /*
547                 case 5 :
548                         vconf_get_bool(VCONFKEY_SETAPPL_PERFERED_ARM_LEFT_BOOL, &pref_arm_type);
549                         pref_arm_type = (pref_arm_type == TRUE) ? 0 : 1;
550                         snprintf(buf, sizeof(buf)-1, "%s", _(pref_arm_str[pref_arm_type % 2]));
551                         break;
552 */
553                 }
554                 index++;
555         }
556         return strdup(buf);
557 }
558
559 void _sound_chk_changed_cb(void *data, Evas_Object *obj, void *event_info)
560 {
561         DBG("Setting - _sound_chk_changed_cb() is called!!");
562
563         vconf_get_bool(VCONFKEY_SETAPPL_TOUCH_SOUNDS_BOOL, &sound_menu_its[2].is_enable_touch_sound);
564
565         sound_menu_its[2].is_enable_touch_sound = !sound_menu_its[2].is_enable_touch_sound;
566
567         /* Update touch sound enable state */
568         vconf_set_bool(VCONFKEY_SETAPPL_TOUCH_SOUNDS_BOOL, sound_menu_its[2].is_enable_touch_sound);
569         vconf_set_bool(VCONFKEY_SETAPPL_BUTTON_SOUNDS_BOOL, sound_menu_its[2].is_enable_touch_sound);
570 }
571
572 static void _sound_gl_del(void *data, Evas_Object *obj)
573 {
574         Sound_Item_Data *id = data;
575         if (id)
576                 free(id);
577 }
578
579 Evas_Object * _gl_sound_check_get(void *data, Evas_Object *obj, const char *part)
580 {
581         Evas_Object *check = NULL;
582
583         Sound_Item_Data *id = data;
584         int index = id->index;
585
586         if( !strcmp(part, "elm.icon") )
587         {
588                 check = elm_check_add(obj);
589
590                 if (vconf_get_bool(VCONFKEY_SETAPPL_TOUCH_SOUNDS_BOOL, &sound_menu_its[2].is_enable_touch_sound) < 0)
591                 {
592                         sound_menu_its[2].is_enable_touch_sound = TOUCH_SOUND_ENABLE;   /*  default value of touch sounds : on */
593                 }
594                 elm_check_state_set(check, (sound_menu_its[2].is_enable_touch_sound) ? EINA_TRUE : EINA_FALSE);
595                 evas_object_smart_callback_add(check, "changed", _sound_chk_changed_cb, (void *)1);
596                 evas_object_size_hint_align_set(check, EVAS_HINT_FILL, EVAS_HINT_FILL);
597                 evas_object_size_hint_weight_set(check, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
598                 evas_object_propagate_events_set(check, EINA_FALSE);
599
600                 id->check = check;
601
602                 index++;
603         }
604
605         return check;
606 }
607
608 Evas_Object* _create_sound_list(void* data)
609 {
610         appdata *ad = data;
611         if( ad == NULL )
612         {
613                 DBG("%s", "_create_sound_list - appdata is null");
614                 return NULL;
615         }
616
617         temp_ad = ad;
618
619         Evas_Object *genlist  = NULL;
620         struct _sound_menu_item *menu_its = NULL;
621         int idx = 0;
622
623         Elm_Genlist_Item_Class *itc_tmp;
624
625         Elm_Genlist_Item_Class *itc_1text = elm_genlist_item_class_new();
626         itc_1text->item_style = "1text";
627         itc_1text->func.text_get = _gl_Sound_title_get;
628         itc_1text->func.del = _sound_gl_del;
629
630         Elm_Genlist_Item_Class *itc = elm_genlist_item_class_new();
631         itc->item_style = "2text";
632         itc->func.text_get = _gl_Sound_title_get;
633         itc->func.del = _sound_gl_del;
634
635         Elm_Genlist_Item_Class *itc_touch_snd = elm_genlist_item_class_new();
636         itc_touch_snd->item_style = "1text.1icon.1";
637         itc_touch_snd->func.text_get = _gl_Sound_title_get;
638         itc_touch_snd->func.content_get = _gl_sound_check_get;
639         itc_touch_snd->func.del = _sound_gl_del;
640
641         genlist = elm_genlist_add(ad->nf);
642         elm_genlist_mode_set(genlist, ELM_LIST_COMPRESS);
643
644         menu_its = sound_menu_its;
645
646         for (idx = 0; idx < ITEM_SIZE; idx++)
647         {
648                 if( idx == 0 )
649                 {
650                         itc_tmp = itc_1text;
651                 }
652                 else if( idx == 2 )
653                 {
654                         itc_tmp = itc_touch_snd;
655                 }
656                 else
657                 {
658                         itc_tmp = itc;
659                 }
660
661                 Sound_Item_Data *id = calloc(sizeof(Sound_Item_Data), 1);
662                 id->index = idx;
663                 id->item = elm_genlist_item_append(
664                                         genlist,                        // genlist object
665                                         itc_tmp,                        // item class
666                                         id,                         // data
667                                         NULL,
668                                         ELM_GENLIST_ITEM_NONE,
669                                         menu_its[ idx ].func,   // call back
670                                         ad);
671
672                 if( idx == ITEM_SIZE-1 )
673                 {
674                         g_vib_item = id->item;
675                 }
676         }
677         elm_genlist_item_class_free(itc_1text);
678         elm_genlist_item_class_free(itc);
679         elm_genlist_item_class_free(itc_touch_snd);
680
681         g_sound_genlist = genlist;
682
683         /* Register sound mode vconf callback */
684         register_vconf_changing(VCONFKEY_SETAPPL_SOUND_STATUS_BOOL, sound_vconf_changed_cb, NULL);
685         register_vconf_changing(VCONFKEY_SETAPPL_VIBRATION_STATUS_BOOL, vibrate_vconf_changed_cb, NULL);
686
687         return genlist;
688 }
689
690 static char * _gl_sound_mode_title_get(void *data, Evas_Object *obj, const char *part)
691 {
692         char buf[1024];
693         Item_Data *id = data;
694         int index = id->index;
695
696         if( !strcmp(part, "elm.text") )
697         {
698                 snprintf(buf, sizeof(buf)-1, "%s", _(sound_mode_str[index % 3]));
699                 index++;
700         }
701         return strdup(buf);
702 }
703
704 static Evas_Object * _gl_sound_mode_ridio_get(void *data, Evas_Object *obj, const char *part)
705 {
706         Evas_Object *radio = NULL;
707         Evas_Object *radio_main = evas_object_data_get(obj, "radio_main");
708         Item_Data *id = data;
709         int index = id->index;
710
711         if( !strcmp(part, "elm.icon") )
712         {
713                 radio = elm_radio_add(obj);
714                 elm_radio_state_value_set(radio, id->index);
715                 evas_object_size_hint_align_set(radio, EVAS_HINT_FILL, EVAS_HINT_FILL);
716                 evas_object_size_hint_weight_set(radio, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
717                 elm_radio_group_add(radio, radio_main);
718                 evas_object_smart_callback_add(radio, "changed", NULL, (void *)id->index);
719                 if( sound_mode == id->index )
720                         elm_radio_value_set(radio_main, sound_mode);
721
722                 index++;
723         }
724         return radio;
725 }
726
727 static void _sound_mode_gl_del(void *data, Evas_Object *obj)
728 {
729         Item_Data *id = data;
730         if (id)
731                 free(id);
732 }
733
734 static int curr_touch_sound = 0;
735
736
737 static void _sound_mode_gl_cb(void *data, Evas_Object *obj, void *event_info)
738 {
739         elm_genlist_item_selected_set((Elm_Object_Item *)event_info, EINA_FALSE);
740
741         sound_mode = (int)data;
742
743         changing_sound_mode_myself = 1;
744
745         if(g_sound_mode_genlist)
746         {
747                 elm_genlist_realized_items_update(g_sound_mode_genlist);
748         }
749
750         int ringtone_level = 0;
751         int prev_sound_mode = get_sound_mode();
752         int err = -1;
753         int enable = FALSE;
754
755         switch(sound_mode) {
756         case SOUND_MODE_SOUND:
757                 if( get_sound_mode() != SOUND_MODE_SOUND )
758                 {
759                         DBG("Setting - current sound mode is not sound!! Change sound mode to sound!!");
760
761                         vconf_get_bool(VCONFKEY_SETAPPL_TOUCH_SOUNDS_BOOL, &curr_touch_sound);
762                         if( curr_touch_sound )
763                         {
764                                 vconf_set_bool(VCONFKEY_SETAPPL_TOUCH_SOUNDS_BOOL, FALSE);
765                         }
766
767                         vconf_get_int(SETTING_RINGTONE_VOLUME_BACKUP, &ringtone_level);
768                         DBG("Setting - ringtone backup level: %d", ringtone_level);
769
770                         vconf_set_int(VCONFKEY_SETAPPL_CALL_RINGTONE_SOUND_VOLUME_INT, ringtone_level);
771
772                         if( is_created_player() )
773                         {
774                                 _close_player(NULL, SOUND_TYPE_RINGTONE);
775                         }
776                         play_sound_for_sound_mode(SETTING_DEFAULT_SILENT_OFF_TONE, 0.0, SOUND_TYPE_RINGTONE);
777                         set_looping(FALSE);
778
779                         sound_manager_get_volume(SOUND_TYPE_RINGTONE, &ringtone_level);
780                         if( ringtone_level == 0 )
781                         {
782                                 DBG("Setting - Ringtone volume is 0!! Restore to 1!!");
783                                 sound_manager_set_volume(SOUND_TYPE_RINGTONE, 1);
784                         }
785
786                         vconf_set_bool(VCONFKEY_SETAPPL_SOUND_STATUS_BOOL, TRUE);
787                         vconf_set_bool(VCONFKEY_SETAPPL_VIBRATION_STATUS_BOOL, FALSE);
788
789                         vconf_set_bool(VCONFKEY_SETAPPL_TOUCH_SOUNDS_BOOL, curr_touch_sound);
790                         curr_touch_sound = 0;
791                 }
792                 break;
793         case SOUND_MODE_VIBRATE:
794                 if( prev_sound_mode != SOUND_MODE_VIBRATE )
795                 {
796                         DBG("Setting - current sound mode is not vibration. Change sound mode to vibration!!");
797
798                         vconf_set_bool(VCONFKEY_SETAPPL_SOUND_STATUS_BOOL, FALSE);
799                         vconf_set_bool(VCONFKEY_SETAPPL_VIBRATION_STATUS_BOOL, TRUE);
800
801                         vconf_get_int(VCONFKEY_SETAPPL_CALL_RINGTONE_SOUND_VOLUME_INT, &ringtone_level);
802                         DBG("Setting - ringtone original level: %d", ringtone_level);
803
804                         vconf_set_int(SETTING_RINGTONE_VOLUME_BACKUP, ringtone_level);
805                         //sound_manager_set_muteall(TRUE);      // mute!!
806                 }
807                 _start_vibration(5, SETTING_VIB_STRONG_RATE, SETTING_DEFAULT_SYSTEM_HAPTIC_PREVIEW_VIB);
808                 break;
809         case SOUND_MODE_MUTE:
810                 if( prev_sound_mode != SOUND_MODE_MUTE )
811                 {
812                         DBG("Setting - current sound mode is not mute. Change sound mode to mute!!");
813
814                         vconf_set_bool(VCONFKEY_SETAPPL_SOUND_STATUS_BOOL, FALSE);
815                         vconf_set_bool(VCONFKEY_SETAPPL_VIBRATION_STATUS_BOOL, FALSE);
816
817                         vconf_get_int(VCONFKEY_SETAPPL_CALL_RINGTONE_SOUND_VOLUME_INT, &ringtone_level);
818                         DBG("Setting - ringtone original level: %d", ringtone_level);
819
820                         vconf_set_int(SETTING_RINGTONE_VOLUME_BACKUP, ringtone_level);
821                         //sound_manager_set_muteall(TRUE);      // mute!!
822                 }
823                 break;
824         default:
825                 ERR("Setting - wrong sound mode value!!");
826                 break;
827         }
828
829         elm_naviframe_item_pop(temp_ad->nf);
830         if(!temp_ad->sound_mode_rdg)
831         {
832                 evas_object_del(temp_ad->sound_mode_rdg);
833                 temp_ad->sound_mode_rdg = NULL;
834         }
835
836         if( g_sound_genlist )
837         {
838                 elm_genlist_realized_items_update(g_sound_genlist);
839         }
840 }
841
842 static void sound_vconf_changed_cb(keynode_t * key, void * data)
843 {
844         DBG("Setting - sound_vconf_changed_cb() is called!!");
845
846         if(changing_sound_mode_myself)
847         {
848                 DBG("Setting - changing_sound_mode_myself!!");
849
850                 changing_sound_mode_myself = 0;
851                 return;
852         }
853
854         sound_mode = get_sound_mode();
855
856         if( g_sound_mode_genlist )
857         {
858                 elm_genlist_realized_items_update(g_sound_mode_genlist);
859         }
860
861         if( g_sound_genlist )
862         {
863                 elm_genlist_realized_items_update(g_sound_genlist);
864         }
865 }
866
867 static void vibrate_vconf_changed_cb(keynode_t * key, void * data)
868 {
869         DBG("Setting - vibrate_vconf_changed_cb() is called!!");
870
871         sound_mode = get_sound_mode();
872
873         if( g_sound_mode_genlist )
874         {
875                 elm_genlist_realized_items_update(g_sound_mode_genlist);
876         }
877
878         if( g_sound_genlist )
879         {
880                 elm_genlist_realized_items_update(g_sound_genlist);
881         }
882 }
883
884 Eina_Bool _sound_mode_back_cb(void *data, Elm_Object_Item *it)
885 {
886         g_sound_mode_genlist = NULL;
887
888         return EINA_TRUE;
889 }
890
891 void _show_sound_mode_list(void* data)
892 {
893         appdata *ad = data;
894         if( ad == NULL )
895         {
896                 DBG("%s", "_show_sound_mode_list - appdata is null");
897                 return;
898         }
899         Evas_Object *genlist  = NULL;
900         Elm_Object_Item *item = NULL;
901         Elm_Object_Item *nf_it = NULL;
902
903         Elm_Genlist_Item_Class *itc = elm_genlist_item_class_new();
904         itc->item_style = "1text.1icon.1";
905         itc->func.text_get = _gl_sound_mode_title_get;
906         itc->func.content_get = _gl_sound_mode_ridio_get;
907         itc->func.del = _sound_mode_gl_del;
908
909         sound_mode = get_sound_mode();
910
911         Evas_Object * layout = elm_layout_add(ad->nf);
912         elm_layout_file_set(layout, EDJE_PATH, "setting/genlist/layout");
913         evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
914
915         genlist = elm_genlist_add(layout);
916         elm_genlist_block_count_set(genlist, 14);
917         elm_genlist_mode_set(genlist, ELM_LIST_COMPRESS);
918         evas_object_size_hint_weight_set(genlist, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
919
920         Item_Data *id = calloc(sizeof(Item_Data), 1);
921         id->index = 0;
922         item = elm_genlist_item_append(genlist, itc, id, NULL, ELM_GENLIST_ITEM_NONE, _sound_mode_gl_cb, (void*)0);
923         id->item = item;
924
925         Item_Data *id2 = calloc(sizeof(Item_Data), 1);
926         id2->index = 1;
927         item = elm_genlist_item_append(genlist, itc, id2, NULL, ELM_GENLIST_ITEM_NONE, _sound_mode_gl_cb, (void*)1);
928         id2->item = item;
929
930         Item_Data *id3 = calloc(sizeof(Item_Data), 1);
931         id3->index = 2;
932         item = elm_genlist_item_append(genlist, itc, id3, NULL, ELM_GENLIST_ITEM_NONE, _sound_mode_gl_cb, (void*)2);
933         id3->item = item;
934
935         ad->sound_mode_rdg = elm_radio_add(genlist);
936         elm_radio_state_value_set(ad->sound_mode_rdg, 3);
937         elm_radio_value_set(ad->sound_mode_rdg, sound_mode);
938
939         evas_object_data_set(genlist, "radio_main", ad->sound_mode_rdg);
940
941         elm_genlist_item_class_free(itc);
942
943         g_sound_mode_genlist = genlist;
944
945         elm_object_part_content_set(layout, "elm.genlist", genlist);
946
947         nf_it = elm_naviframe_item_push(ad->nf, NULL, NULL, NULL, layout, NULL);
948         elm_naviframe_item_title_enabled_set(nf_it, EINA_FALSE, EINA_FALSE);
949         elm_naviframe_item_pop_cb_set(nf_it, _sound_mode_back_cb, ad);
950 }
951
952 static void _response_ringtone_ok_cb(void *data, Evas_Object *obj, void *event_info)
953 {
954         appdata * ad = (appdata *)data;
955
956         _stop_player();
957
958 #if 0
959         // stop wav sound!
960         stop_wav();
961 #endif
962         // save a ringtone type.
963         vconf_set_str(VCONFKEY_SETAPPL_CALL_RINGTONE_PATH_STR ,ringtone_arr[ringtone_type]);
964
965         if( g_ringtone_type_genlist != NULL)
966         {
967                 evas_object_del(g_ringtone_type_genlist);
968                 g_ringtone_type_genlist = NULL;
969         }
970
971         if( temp_ad->ringtone_type_rdg != NULL )
972         {
973                 evas_object_del(temp_ad->ringtone_type_rdg);
974                 temp_ad->ringtone_type_rdg = NULL;
975         }
976
977         if( ad != NULL)
978         {
979                 elm_naviframe_item_pop(ad->nf);
980         }
981
982         if(     g_sound_genlist != NULL )
983         {
984                 elm_genlist_realized_items_update(g_sound_genlist);
985         }
986
987         confirmed_ringtone_type = ringtone_type;
988 }
989
990 static void _response_ringtone_cancel_cb(void *data, Evas_Object *obj, void *event_info)
991 {
992         if( g_ringtone_type_genlist != NULL)
993         {
994                 evas_object_del(g_ringtone_type_genlist);
995                 g_ringtone_type_genlist = NULL;
996         }
997
998         appdata * ad = (appdata *)data;
999         if( ad != NULL)
1000         {
1001                 elm_naviframe_item_pop(ad->nf);
1002         }
1003
1004         _stop_player();
1005
1006         ringtone_type = confirmed_ringtone_type;
1007
1008 #if 0
1009         // stop wav sound!
1010         stop_wav();
1011 #endif
1012 }
1013
1014 static char *_gl_ringtone_text_get(void *data, Evas_Object *obj, const char *part)
1015 {
1016         Item_Data * item = data;
1017         if( item == NULL )
1018                 return NULL;
1019
1020         char buf[1024];
1021
1022         sprintf(buf, "%s", ringtone_name_arr[item->index % ringtone_count]);
1023
1024         return strdup(buf);
1025 }
1026
1027 static Evas_Object *_gl_ringtone_radio_get(void *data, Evas_Object *obj, const char *part)
1028 {
1029         Evas_Object *radio = NULL;
1030         Evas_Object *radio_main = evas_object_data_get(obj, "radio_main");
1031         Item_Data *id = data;
1032         int index = id->index;
1033
1034         if( !strcmp(part, "elm.icon") )
1035         {
1036                 radio = elm_radio_add(obj);
1037                 elm_radio_state_value_set(radio, id->index);
1038                 evas_object_size_hint_align_set(radio, EVAS_HINT_FILL, EVAS_HINT_FILL);
1039                 evas_object_size_hint_weight_set(radio, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1040                 elm_radio_group_add(radio, radio_main);
1041
1042                 if( id->index == ringtone_type )
1043                 {
1044                         elm_radio_value_set(radio_main, id->index);
1045                 }
1046                 index++;
1047         }
1048         return radio;
1049 }
1050
1051 static void _ringtone_type_gl_cb(void *data, Evas_Object *obj, void *event_info)
1052 {
1053         elm_genlist_item_selected_set((Elm_Object_Item *)event_info, EINA_FALSE);
1054
1055         ringtone_type = (int)data;
1056
1057 #if 0
1058         stop_wav();
1059
1060         is_wav_playing = SOUND_STATE_PLAY;
1061         wav_player_start(ringtone_arr[ringtone_type], SOUND_TYPE_RINGTONE, NULL, (void*)1, &sound_id);
1062 #endif
1063
1064         int volume = 0;
1065         sound_manager_get_volume(SOUND_TYPE_RINGTONE, &volume);
1066
1067         if( volume == 0 || get_sound_mode() != SOUND_MODE_SOUND )
1068         {
1069                 if( temp_ad )
1070                 {
1071                         struct _toast_data * toast = _create_toast(temp_ad, _("IDS_ST_TPOP_VOLUME_CURRENTLY_SET_TO_0"));
1072                         if( toast ) {
1073                                 _show_toast(temp_ad, toast);
1074                         }
1075                 }
1076         }
1077         else
1078         {
1079                 play_sound(ringtone_arr[ringtone_type], 0.0, SOUND_TYPE_RINGTONE);
1080         }
1081
1082         elm_genlist_realized_items_update(g_ringtone_type_genlist);
1083 }
1084
1085 static void _ringtone_back_cb(void * data, Evas_Object * obj, void * event_info)
1086 {
1087         appdata *ad = data;
1088         if (ad == NULL)
1089         return;
1090
1091         ringtone_type = confirmed_ringtone_type;
1092
1093         _stop_all_sound_play();
1094
1095         unregister_vconf_changing(VCONFKEY_PM_STATE, pm_state_vconf_changed_cb);
1096 }
1097
1098
1099 static void pm_state_vconf_changed_cb(keynode_t * key, void * data)
1100 {
1101         DBG("Setting - pm_state_vconf_changed_cb() is called!");
1102
1103         int pm_state = 0;
1104         vconf_get_int(VCONFKEY_PM_STATE, &pm_state);
1105
1106         if (pm_state == VCONFKEY_PM_STATE_LCDOFF)
1107         {
1108                 DBG("Setting - LCD Off!! stop sound!");
1109                 _stop_all_sound_play();
1110         }
1111 }
1112
1113 void _show_ringtone_popup_cb(void *data, Evas_Object *obj, void *event_info)
1114 {
1115         Evas_Object *popup, *btn;
1116         unsigned int index;
1117         appdata *ad = data;
1118
1119         if( ad == NULL )
1120                 return;
1121
1122         ad->MENU_TYPE = SETTING_SOUND_RINGTONE;
1123
1124         if( is_loaded_ringtone_data == 0 )
1125         {
1126                 get_sound_file_list("/opt/share/settings/Ringtones/", 1);
1127                 is_loaded_ringtone_data = 1;
1128
1129                 sorting_file_list(1);
1130         }
1131
1132         cur_sound_type = SOUND_TYPE_RINGTONE;
1133
1134         popup = elm_layout_add(ad->win_main);
1135         elm_layout_file_set(popup, EDJE_PATH, "setting/genlist/2button-layout");
1136         evas_object_size_hint_weight_set (popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1137         evas_object_size_hint_align_set(popup, EVAS_HINT_FILL, EVAS_HINT_FILL);
1138
1139
1140         Elm_Genlist_Item_Class *itc = NULL;
1141         itc = elm_genlist_item_class_new();
1142         itc->item_style = "settings.1text.1icon.1"; //"1text.1icon.1";
1143         itc->func.text_get = _gl_ringtone_text_get;
1144         itc->func.content_get = _gl_ringtone_radio_get;
1145
1146         Evas_Object *genlist;
1147         genlist = elm_genlist_add(popup);
1148         elm_object_style_set(genlist, "popup");
1149         elm_genlist_mode_set(genlist, ELM_LIST_COMPRESS);
1150
1151         for (index = 0; index < ringtone_count; index++)
1152         {
1153                 Item_Data * item = (Item_Data*)calloc(sizeof(Item_Data), 1);
1154                 item->index = index;
1155                 item->item = elm_genlist_item_append(genlist,
1156                                                                                          itc,
1157                                                                                          item,
1158                                                                                          NULL,
1159                                                                                          ELM_GENLIST_ITEM_NONE,
1160                                                                                          _ringtone_type_gl_cb,
1161                                                                                          (void*)index);
1162         }
1163
1164         ad->ringtone_type_rdg = elm_radio_add(genlist);
1165         elm_radio_state_value_set(ad->ringtone_type_rdg, ringtone_count);
1166         elm_radio_value_set(ad->ringtone_type_rdg, ringtone_type);
1167         confirmed_ringtone_type = ringtone_type;
1168
1169         evas_object_data_set(genlist, "radio_main", ad->ringtone_type_rdg);
1170
1171         g_ringtone_type_genlist = genlist;
1172
1173         elm_object_part_content_set(popup, "elm.genlist", genlist);
1174         evas_object_show(genlist);
1175
1176         elm_genlist_item_class_free(itc);
1177
1178         btn = elm_button_add(popup);
1179         evas_object_size_hint_weight_set(btn, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1180         elm_object_text_set(btn, _("IDS_ST_BUTTON_CANCEL_ABB2"));
1181         elm_object_part_content_set(popup, "btn.left", btn);
1182         evas_object_smart_callback_add(btn, "clicked", _response_ringtone_cancel_cb, ad);
1183
1184         btn = elm_button_add(popup);
1185         evas_object_size_hint_weight_set(btn, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1186         elm_object_text_set(btn, _("IDS_WNOTI_BUTTON_OK_ABB2"));
1187         elm_object_part_content_set(popup, "btn.right", btn);
1188         evas_object_smart_callback_add(btn, "clicked", _response_ringtone_ok_cb, ad);
1189
1190         elm_naviframe_item_push( ad->nf, _("IDS_ST_HEADER_RINGTONES_ABB"), NULL, NULL, popup, NULL );
1191         ea_object_event_callback_add(ad->nf, EA_CALLBACK_BACK, _ringtone_back_cb, ad);
1192
1193         //VCONFKEY_PM_STATE
1194         register_vconf_changing(VCONFKEY_PM_STATE, pm_state_vconf_changed_cb,NULL);
1195 }
1196
1197 static void _notification_back_cb(void * data, Evas_Object * obj, void * event_info)
1198 {
1199         appdata *ad = data;
1200         if (ad == NULL)
1201         return;
1202
1203         notification_type = confirmed_Notification_type;
1204
1205         _stop_all_sound_play();
1206
1207         unregister_vconf_changing(VCONFKEY_PM_STATE, pm_state_vconf_changed_cb);
1208 }
1209
1210 static void _response_notification_ok_cb(void *data, Evas_Object *obj, void *event_info)
1211 {
1212         //stop_wav();
1213
1214         if( is_created_player() )
1215         {
1216                 _close_player(NULL, SOUND_TYPE_NOTIFICATION);
1217         }
1218
1219         // save a notification type.
1220         vconf_set_str(VCONFKEY_SETAPPL_NOTI_MSG_RINGTONE_PATH_STR ,notification_arr[notification_type]);
1221
1222         if( g_notification_type_genlist != NULL)
1223         {
1224                 evas_object_del(g_notification_type_genlist);
1225                 g_notification_type_genlist = NULL;
1226         }
1227
1228         if( temp_ad->notification_rdg != NULL )
1229         {
1230                 evas_object_del(temp_ad->notification_rdg);
1231                 temp_ad->notification_rdg = NULL;
1232         }
1233
1234         confirmed_Notification_type = notification_type;
1235
1236         appdata * ad = (appdata *)data;
1237         if( ad != NULL)
1238         {
1239                 elm_naviframe_item_pop(ad->nf);
1240         }
1241
1242         if(     g_sound_genlist != NULL )
1243         {
1244                 elm_genlist_realized_items_update(g_sound_genlist);
1245         }
1246 }
1247
1248 static void _response_notification_cancel_cb(void *data, Evas_Object *obj, void *event_info)
1249 {
1250         if( g_notification_type_genlist != NULL)
1251         {
1252                 evas_object_del(g_notification_type_genlist);
1253                 g_notification_type_genlist = NULL;
1254         }
1255
1256         appdata * ad = (appdata *)data;
1257         if( ad != NULL)
1258         {
1259                 elm_naviframe_item_pop(ad->nf);
1260         }
1261
1262         notification_type = confirmed_Notification_type;
1263
1264         if( is_created_player() )
1265         {
1266                 _close_player(NULL, SOUND_TYPE_RINGTONE);
1267         }
1268
1269         //stop_wav();
1270 }
1271
1272 static char *_gl_notification_text_get(void *data, Evas_Object *obj, const char *part)
1273 {
1274         Item_Data * item = data;
1275         if( item == NULL )
1276                 return NULL;
1277
1278         char buf[1024];
1279
1280         sprintf(buf, "%s", notification_name_arr[item->index % notification_count]);
1281
1282         return strdup(buf);
1283 }
1284
1285 static Evas_Object *_gl_notification_radio_get(void *data, Evas_Object *obj, const char *part)
1286 {
1287         Evas_Object *radio = NULL;
1288         Evas_Object *radio_main = evas_object_data_get(obj, "radio_main");
1289         Item_Data *id = data;
1290         int index = id->index;
1291
1292         if( !strcmp(part, "elm.icon") )
1293         {
1294                 radio = elm_radio_add(obj);
1295                 elm_radio_state_value_set(radio, id->index);
1296                 evas_object_size_hint_align_set(radio, EVAS_HINT_FILL, EVAS_HINT_FILL);
1297                 evas_object_size_hint_weight_set(radio, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1298                 elm_radio_group_add(radio, radio_main);
1299                 if( id->index == notification_type )
1300                 {
1301                         elm_radio_value_set(radio_main, id->index);
1302                 }
1303                 index++;
1304         }
1305         return radio;
1306 }
1307
1308 static void _notification_gl_cb(void *data, Evas_Object *obj, void *event_info)
1309 {
1310         elm_genlist_item_selected_set((Elm_Object_Item *)event_info, EINA_FALSE);
1311
1312         notification_type = (int)data;
1313
1314 #if 0
1315         is_wav_playing = SOUND_STATE_PLAY;
1316         wav_player_start(notification_arr[notification_type], SOUND_TYPE_NOTIFICATION, NULL, (void*)2, &sound_id);
1317 #endif
1318
1319         int volume = 0;
1320         sound_manager_get_volume(SOUND_TYPE_NOTIFICATION, &volume);
1321
1322         if( volume == 0 || get_sound_mode() != SOUND_MODE_SOUND )
1323         {
1324                 if( temp_ad )
1325                 {
1326                         struct _toast_data * toast = _create_toast(temp_ad, _("IDS_ST_TPOP_VOLUME_CURRENTLY_SET_TO_0"));
1327                         if( toast ) {
1328                                 _show_toast(temp_ad, toast);
1329                         }
1330                 }
1331         }
1332         else
1333         {
1334                 play_sound(notification_arr[notification_type], 0.0, SOUND_TYPE_NOTIFICATION);
1335                 set_looping(FALSE);
1336         }
1337
1338         if( g_notification_type_genlist )
1339         {
1340                 elm_genlist_realized_items_update(g_notification_type_genlist);
1341         }
1342 }
1343
1344 void _show_notification_popup_cb(void *data, Evas_Object *obj, void *event_info)
1345 {
1346         Evas_Object *popup, *btn;
1347         unsigned int index;
1348         appdata *ad = data;
1349
1350         if( ad == NULL )
1351                 return;
1352
1353         ad->MENU_TYPE = SETTING_SOUND_NOTIFICATION;
1354
1355         if( is_loaded_noti_data == 0 )
1356         {
1357                 get_sound_file_list("/opt/share/settings/Alerts/", 0);
1358                 is_loaded_noti_data = 1;
1359
1360                 sorting_file_list(0);
1361         }
1362
1363         cur_sound_type = SOUND_TYPE_NOTIFICATION;
1364
1365         popup = elm_layout_add(ad->win_main);
1366         elm_layout_file_set(popup, EDJE_PATH, "setting/genlist/2button-layout");
1367         evas_object_size_hint_weight_set (popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1368         evas_object_size_hint_align_set(popup, EVAS_HINT_FILL, EVAS_HINT_FILL);
1369
1370         Elm_Genlist_Item_Class *itc = NULL;
1371         itc = elm_genlist_item_class_new();
1372         itc->item_style = "settings.1text.1icon.1"; //"1text.1icon.1";
1373         itc->func.text_get = _gl_notification_text_get;
1374         itc->func.content_get = _gl_notification_radio_get;
1375
1376         Evas_Object *genlist;
1377         genlist = elm_genlist_add(popup);
1378         elm_object_style_set(genlist, "popup");
1379         elm_genlist_mode_set(genlist, ELM_LIST_COMPRESS);
1380
1381
1382         for (index = 0; index < notification_count; index++)
1383         {
1384                 Item_Data * item = (Item_Data*)calloc(sizeof(Item_Data), 1);
1385                 item->index = index;
1386                 item->item = elm_genlist_item_append(genlist,
1387                                 itc,
1388                                 item,
1389                                 NULL,
1390                                 ELM_GENLIST_ITEM_NONE,
1391                                 _notification_gl_cb,
1392                                 (void*)index);
1393         }
1394
1395         ad->notification_rdg = elm_radio_add(genlist);
1396         elm_radio_state_value_set(ad->notification_rdg, notification_count);
1397         elm_radio_value_set(ad->notification_rdg, notification_type);
1398         confirmed_Notification_type = notification_type;
1399
1400         evas_object_data_set(genlist, "radio_main", ad->notification_rdg);
1401
1402         g_notification_type_genlist = genlist;
1403
1404         elm_object_part_content_set(popup, "elm.genlist", genlist);
1405         evas_object_show(genlist);
1406         elm_genlist_item_class_free(itc);
1407
1408         btn = elm_button_add(popup);
1409         evas_object_size_hint_weight_set(btn, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1410         elm_object_text_set(btn, _("IDS_ST_BUTTON_CANCEL_ABB2"));
1411         elm_object_part_content_set(popup, "btn.left", btn);
1412         evas_object_smart_callback_add(btn, "clicked", _response_notification_cancel_cb, ad);
1413
1414         btn = elm_button_add(popup);
1415         evas_object_size_hint_weight_set(btn, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1416         elm_object_text_set(btn, _("IDS_WNOTI_BUTTON_OK_ABB2"));
1417         elm_object_part_content_set(popup, "btn.right", btn);
1418         evas_object_smart_callback_add(btn, "clicked", _response_notification_ok_cb, ad);
1419
1420         elm_naviframe_item_push( ad->nf, _("IDS_ST_BUTTON_NOTIFICATIONS"), NULL, NULL, popup, NULL );
1421         ea_object_event_callback_add(ad->nf, EA_CALLBACK_BACK, _notification_back_cb, ad);
1422
1423         //VCONFKEY_PM_STATE
1424         register_vconf_changing(VCONFKEY_PM_STATE, pm_state_vconf_changed_cb,NULL);
1425 }
1426
1427 static void _response_vibration_ok_cb(void *data, Evas_Object *obj, void *event_info)
1428 {
1429         // save a vibration level
1430         int level = 0;
1431
1432         _haptic_close();
1433
1434         switch(vibrate_type) {
1435         case VIBRATION_LEVEL_LOW:
1436                 vconf_set_int(VCONFKEY_SETAPPL_NOTI_VIBRATION_LEVEL_INT, VIBRATION_LEVEL_LOW_INT);
1437                 vconf_set_int(VCONFKEY_SETAPPL_TOUCH_FEEDBACK_VIBRATION_LEVEL_INT, VIBRATION_LEVEL_LOW_INT);
1438                 break;
1439         case VIBRATION_LEVEL_HIGH:
1440                 vconf_set_int(VCONFKEY_SETAPPL_NOTI_VIBRATION_LEVEL_INT, VIBRATION_LEVEL_HIGH_INT);
1441                 vconf_set_int(VCONFKEY_SETAPPL_TOUCH_FEEDBACK_VIBRATION_LEVEL_INT, VIBRATION_LEVEL_HIGH_INT);
1442                 break;
1443         default:
1444                 break;
1445         }
1446
1447         vconf_get_int(VCONFKEY_SETAPPL_NOTI_VIBRATION_LEVEL_INT, &level);
1448         DBG("Setting - vibration level : %d", level);
1449
1450         if( g_vibration_type_genlist != NULL)
1451         {
1452                 evas_object_del(g_vibration_type_genlist);
1453                 g_vibration_type_genlist = NULL;
1454         }
1455
1456         if( temp_ad->vibration_rdg != NULL )
1457         {
1458                 evas_object_del(temp_ad->vibration_rdg);
1459                 temp_ad->vibration_rdg = NULL;
1460         }
1461
1462         appdata * ad = (appdata *)data;
1463         if( ad != NULL)
1464         {
1465                 elm_naviframe_item_pop(ad->nf);
1466         }
1467
1468         if(     g_vib_item != NULL )
1469         {
1470                 elm_genlist_item_update(g_vib_item);
1471         }
1472 }
1473
1474 static void _response_vibration_cancel_cb(void *data, Evas_Object *obj, void *event_info)
1475 {
1476         _haptic_close();
1477
1478         vconf_get_int(VCONFKEY_SETAPPL_NOTI_VIBRATION_LEVEL_INT, &vibrate_type);
1479
1480         DBG("Setting - vibrate type have backed : %d", vibrate_type);
1481
1482         if( g_vibration_type_genlist != NULL)
1483         {
1484                 evas_object_del(g_vibration_type_genlist);
1485                 g_vibration_type_genlist = NULL;
1486         }
1487
1488         appdata * ad = (appdata *)data;
1489         if( ad != NULL)
1490         {
1491                 elm_naviframe_item_pop(ad->nf);
1492         }
1493 }
1494
1495 static char *_gl_vibration_text_get(void *data, Evas_Object *obj, const char *part)
1496 {
1497         Item_Data * item = data;
1498         if( item == NULL )
1499                 return NULL;
1500
1501         return strdup(_(vibration_str[item->index % 3]));
1502 }
1503
1504 static Evas_Object *_gl_vibration_radio_get(void *data, Evas_Object *obj, const char *part)
1505 {
1506         Evas_Object *radio = NULL;
1507         Evas_Object *radio_main = evas_object_data_get(obj, "radio_main");
1508         Item_Data *id = data;
1509         int index = id->index;
1510
1511         if( !strcmp(part, "elm.icon") )
1512         {
1513                 radio = elm_radio_add(obj);
1514                 elm_radio_state_value_set(radio, id->index);
1515                 evas_object_size_hint_align_set(radio, EVAS_HINT_FILL, EVAS_HINT_FILL);
1516                 evas_object_size_hint_weight_set(radio, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1517                 elm_radio_group_add(radio, radio_main);
1518                 evas_object_smart_callback_add(radio, "changed", _vibration_gl_cb, (void *)id->index);
1519                 evas_object_propagate_events_set(radio, EINA_FALSE);
1520
1521                 if( vibrate_type == id->index )
1522                 {
1523                         elm_radio_value_set(radio_main, vibrate_type);
1524                 }
1525                 index++;
1526         }
1527         return radio;
1528 }
1529
1530 static void _vibration_gl_cb(void *data, Evas_Object *obj, void *event_info)
1531 {
1532         elm_genlist_item_selected_set((Elm_Object_Item *)event_info, EINA_FALSE);
1533
1534         vconf_get_int(VCONFKEY_SETAPPL_NOTI_VIBRATION_LEVEL_INT, &origin_vibration_level);
1535
1536         vibrate_type = (int)data;
1537
1538         int level = VIBRATION_LEVEL_LOW_INT;
1539         int feedback_rate = SETTING_VIB_MEDIUM_RATE;
1540         switch( vibrate_type ){
1541 //      case 2:
1542 //              level = VIBRATION_LEVEL_LOW_INT;
1543 //              feedback_rate = SETTING_VIB_WEAK_RATE;
1544 //              break;
1545         case 1:
1546                 level = VIBRATION_LEVEL_LOW_INT;
1547                 feedback_rate = SETTING_VIB_WEAK_RATE;
1548                 break;
1549         case 0:
1550                 level = VIBRATION_LEVEL_HIGH_INT;
1551                 feedback_rate = SETTING_VIB_STRONG_RATE;
1552                 break;
1553         }
1554
1555         DBG("Setting - feedback level: %d, rate: %d", level, feedback_rate);
1556
1557         _start_vibration(level, feedback_rate, SETTING_DEFAULT_NOTIFICATION_GENERAL_PREVIEW_VIB);
1558
1559         elm_genlist_realized_items_update(g_vibration_type_genlist);
1560 }
1561
1562 static void _vibration_layout_del_cb(void *data, Evas_Object *obj, void *event_info)
1563 {
1564         DBG("Setting - _vibration_layout_del_cb() is called!");
1565
1566         _haptic_close();
1567
1568         if(     g_vib_item )
1569         {
1570                 elm_genlist_item_update(g_vib_item);
1571         }
1572 }
1573
1574 static int get_vibration_type()
1575 {
1576         int type = 1;
1577
1578         vconf_get_int(VCONFKEY_SETAPPL_NOTI_VIBRATION_LEVEL_INT, &origin_vibration_level);
1579         switch( origin_vibration_level ){
1580         case VIBRATION_LEVEL_LOW_INT:
1581                 type = 1;
1582                 break;
1583 //      case VIBRATION_LEVEL_MID_INT:
1584 //              type = 1;
1585 //              break;
1586         case VIBRATION_LEVEL_HIGH_INT:
1587                 type = 0;
1588                 break;
1589         }
1590
1591         return type;
1592 }
1593
1594 void _show_vibration_popup_cb(void *data, Evas_Object *obj, void *event_info)
1595 {
1596         Evas_Object *popup, *btn;
1597         unsigned int index;
1598         appdata *ad = data;
1599
1600         vibrate_type = get_vibration_type();
1601
1602         popup = elm_layout_add(ad->win_main);
1603         elm_layout_file_set(popup, EDJE_PATH, "setting/genlist/2button-layout");
1604         evas_object_size_hint_weight_set (popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1605         evas_object_size_hint_align_set(popup, EVAS_HINT_FILL, EVAS_HINT_FILL);
1606         evas_object_event_callback_add(popup, EVAS_CALLBACK_DEL, _vibration_layout_del_cb, ad);
1607
1608         Elm_Genlist_Item_Class *itc = NULL;
1609         itc = elm_genlist_item_class_new();
1610         itc->item_style = "1text.1icon.1";
1611         itc->func.text_get = _gl_vibration_text_get;
1612         itc->func.content_get = _gl_vibration_radio_get;
1613
1614         Evas_Object *genlist;
1615         genlist = elm_genlist_add(popup);
1616         elm_object_style_set(genlist, "popup");
1617         elm_genlist_mode_set(genlist, ELM_LIST_COMPRESS);
1618         elm_genlist_homogeneous_set(genlist, EINA_TRUE);
1619
1620         int count = sizeof(vibration_str) / sizeof(vibration_str[0]);
1621
1622         for (index = 0; index < count; index++)
1623         {
1624                 Item_Data * item = (Item_Data*)calloc(sizeof(Item_Data), 1);
1625                 item->index = index;
1626                 item->item = elm_genlist_item_append(genlist,
1627                                 itc,
1628                                 item,
1629                                 NULL,
1630                                 ELM_GENLIST_ITEM_NONE,
1631                                 _vibration_gl_cb,
1632                                 (void*)index);
1633         }
1634
1635         ad->vibration_rdg = elm_radio_add(genlist);
1636         elm_radio_state_value_set(ad->vibration_rdg, 3);
1637         elm_radio_value_set(ad->vibration_rdg, notification_type);
1638
1639         evas_object_data_set(genlist, "radio_main", ad->vibration_rdg);
1640
1641         g_vibration_type_genlist = genlist;
1642
1643         elm_object_part_content_set(popup, "elm.genlist", genlist);
1644         evas_object_show(genlist);
1645         elm_genlist_item_class_free(itc);
1646
1647         btn = elm_button_add(popup);
1648         elm_object_style_set(btn, "default");
1649         evas_object_size_hint_weight_set(btn, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1650         elm_object_text_set(btn, _("IDS_ST_BUTTON_CANCEL_ABB2"));
1651         elm_object_part_content_set(popup, "btn.left", btn);
1652         evas_object_smart_callback_add(btn, "clicked", _response_vibration_cancel_cb, ad);
1653
1654         btn = elm_button_add(popup);
1655         elm_object_style_set(btn, "default");
1656         evas_object_size_hint_weight_set(btn, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1657         elm_object_text_set(btn, _("IDS_WNOTI_BUTTON_OK_ABB2"));
1658         elm_object_part_content_set(popup, "btn.right", btn);
1659         evas_object_smart_callback_add(btn, "clicked", _response_vibration_ok_cb, ad);
1660
1661         elm_naviframe_item_push( ad->nf, _("IDS_ST_HEADER_VIBRATION_ABB"), NULL, NULL, popup, NULL );
1662 }
1663
1664 static char * _gl_pref_arm_title_get(void *data, Evas_Object *obj, const char *part)
1665 {
1666         char buf[1024];
1667         Item_Data *id = data;
1668         int index = id->index;
1669
1670         if( !strcmp(part, "elm.text") )
1671         {
1672                 snprintf(buf, sizeof(buf)-1, "%s", _(pref_arm_str[index % 2]));
1673                 index++;
1674         }
1675         return strdup(buf);
1676 }
1677
1678 static Evas_Object * _gl_pref_arm_ridio_get(void *data, Evas_Object *obj, const char *part)
1679 {
1680         Evas_Object *radio = NULL;
1681         Evas_Object *radio_main = evas_object_data_get(obj, "radio_main");
1682         Item_Data *id = data;
1683         int index = id->index;
1684         int prefered_arm_type = 0;
1685
1686         if( !strcmp(part, "elm.icon") )
1687         {
1688                 radio = elm_radio_add(obj);
1689                 elm_radio_state_value_set(radio, id->index);
1690                 evas_object_size_hint_align_set(radio, EVAS_HINT_FILL, EVAS_HINT_FILL);
1691                 evas_object_size_hint_weight_set(radio, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1692                 elm_radio_group_add(radio, radio_main);
1693                 evas_object_smart_callback_add(radio, "changed", NULL, (void *)id->index);
1694
1695                 vconf_get_bool(VCONFKEY_SETAPPL_PERFERED_ARM_LEFT_BOOL, &prefered_arm_type);
1696
1697                 prefered_arm_type = (prefered_arm_type) ? 0 : 1;
1698
1699                 if( pref_arm_type == id->index )
1700                 {
1701                         elm_radio_value_set(radio_main, pref_arm_type);
1702                 }
1703                 index++;
1704         }
1705         return radio;
1706 }
1707
1708 static void _pref_arm_gl_del(void *data, Evas_Object *obj)
1709 {
1710         Item_Data *id = data;
1711         if (id)
1712                 free(id);
1713 }
1714
1715 static void _pref_arm_gl_cb(void *data, Evas_Object *obj, void *event_info)
1716 {
1717         elm_genlist_item_selected_set((Elm_Object_Item *)event_info, EINA_FALSE);
1718
1719         pref_arm_type = (int)data;
1720
1721         elm_genlist_realized_items_update(g_pref_arm_type_genlist);
1722
1723         if(temp_ad)
1724         {
1725                 elm_naviframe_item_pop(temp_ad->nf);
1726                 if(!temp_ad->pref_arm_rdg)
1727                 {
1728                         evas_object_del(temp_ad->pref_arm_rdg);
1729                         temp_ad->pref_arm_rdg = NULL;
1730                 }
1731         }
1732         /* save a perfered arm type */
1733         vconf_set_bool(VCONFKEY_SETAPPL_PERFERED_ARM_LEFT_BOOL, (pref_arm_type==0) ? TRUE : FALSE);
1734
1735         if( g_sound_genlist )
1736         {
1737                 elm_genlist_realized_items_update(g_sound_genlist);
1738         }
1739
1740         /* show toast message */
1741         if( temp_ad )
1742         {
1743                 struct _toast_data * toast = _create_toast(temp_ad, _(pref_arm_toast_msg[pref_arm_type % 2]));
1744                 if( toast )
1745                 {
1746                         _show_toast(temp_ad, toast);
1747                 }
1748         }
1749 }
1750
1751 void _show_pref_arm_mode_list(void* data)
1752 {
1753         appdata *ad = data;
1754         if( ad == NULL )
1755         {
1756                 DBG("%s", "_show_pref_arm_mode_list - appdata is null");
1757                 return;
1758         }
1759         Evas_Object *genlist  = NULL;
1760         Elm_Object_Item *item = NULL;
1761         Elm_Object_Item *nf_it = NULL;
1762         //struct _dt_menu_item *menu_its = NULL;
1763
1764         Elm_Genlist_Item_Class *itc = elm_genlist_item_class_new();
1765         itc->item_style = "1text.1icon.1";
1766         itc->func.text_get = _gl_pref_arm_title_get;
1767         itc->func.content_get = _gl_pref_arm_ridio_get;
1768         itc->func.del = _pref_arm_gl_del;
1769
1770         Evas_Object * layout = elm_layout_add(ad->nf);
1771         elm_layout_file_set(layout, EDJE_PATH, "setting/genlist/layout");
1772         evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1773
1774         genlist = elm_genlist_add(layout);
1775         elm_genlist_block_count_set(genlist, 14);
1776         elm_genlist_mode_set(genlist, ELM_LIST_COMPRESS);
1777         evas_object_size_hint_weight_set(genlist, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1778
1779         Item_Data *id = calloc(sizeof(Item_Data), 1);
1780         id->index = 0;
1781         item = elm_genlist_item_append(genlist, itc, id, NULL, ELM_GENLIST_ITEM_NONE, _pref_arm_gl_cb, (void*)0);
1782         id->item = item;
1783
1784         Item_Data *id2 = calloc(sizeof(Item_Data), 1);
1785         id2->index = 1;
1786         item = elm_genlist_item_append(genlist, itc, id2, NULL, ELM_GENLIST_ITEM_NONE, _pref_arm_gl_cb, (void*)1);
1787         id2->item = item;
1788
1789         ad->pref_arm_rdg = elm_radio_add(genlist);
1790         elm_radio_state_value_set(ad->pref_arm_rdg, 2);
1791         elm_radio_value_set(ad->pref_arm_rdg, pref_arm_type);
1792
1793         evas_object_data_set(genlist, "radio_main", ad->pref_arm_rdg);
1794
1795         elm_genlist_item_class_free(itc);
1796
1797         g_pref_arm_type_genlist = genlist;
1798
1799         elm_object_part_content_set(layout, "elm.genlist", genlist);
1800
1801         nf_it = elm_naviframe_item_push(ad->nf, NULL, NULL, NULL, layout, NULL);
1802         elm_naviframe_item_title_enabled_set(nf_it, EINA_FALSE, EINA_FALSE);
1803 }