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