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