4 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd.
6 * Contact: MyoungJune Park <mj2004.park@samsung.com>
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
21 #include <setting-ringtone-main.h>
23 #define RINGTONE_FILE_PATH "/opt/usr/share/settings/Ringtones"
24 #define ALERT_FILE_PATH "/opt/usr/share/settings/Alerts"
25 #define RINGTONE_FILE_PATH_DEF "/opt/usr/share/settings/Ringtones/Over_the_horizon.ogg"
26 #define ALERT_FILE_PATH_DEF "/opt/usr/share/settings/Alerts/Beep_Once.ogg"
28 #define RINGTONE_FILE_PATH_1 "/opt/usr/share/settings/Ringtones/"
29 #define ALERT_FILE_PATH_1 "/opt/usr/share/settings/Alerts/"
31 static int setting_ringtone_create(void *cb);
32 static int setting_ringtone_destroy(void *cb);
33 static int setting_ringtone_update(void *cb);
34 static int setting_ringtone_cleanup(void *cb);
36 setting_view setting_view_ringtone_main = {
37 .create = setting_ringtone_create,
38 .destroy = setting_ringtone_destroy,
39 .update = setting_ringtone_update,
40 .cleanup = setting_ringtone_cleanup,
43 static void setting_ringtone_cancel_click_cb(void *data, Evas_Object *obj, void *event_info)
46 retm_if(data == NULL, "Data parameter is NULL");
47 SettingRingtoneUG *ad = (SettingRingtoneUG *) data;
49 ug_destroy_me(ad->ug);
53 static void setting_ringtone_done_click_cb(void *data, Evas_Object *obj, void *event_info)
56 retm_if(data == NULL, "Data parameter is NULL");
57 SettingRingtoneUG *ad = (SettingRingtoneUG *) data;
59 if (ad->sel_file_path) {
61 int is_def_seleted = 0;
62 if (ad->sel_item_data && !safeStrCmp(ad->sel_item_data->keyStr, STR_DEFAULT_RINGTONE)) {
65 SETTING_TRACE("is_def_seleted: %d", is_def_seleted);
68 /*if default item is seleted, return "default" */
69 ad->rlt_file_path = strdup("default");
71 ad->rlt_file_path = strdup(ad->sel_file_path);
75 if (ad->rlt_file_path && ad->source_svc && !app_control_create(&reply)) {
76 SETTING_TRACE("reply rlt: %s", ad->rlt_file_path);
77 app_control_add_extra_data(reply, "result", ad->rlt_file_path);
78 app_control_reply_to_launch_request(reply, ad->source_svc, APP_CONTROL_RESULT_SUCCEEDED);
79 ug_send_result(ad->ug, reply);
80 app_control_destroy(reply);
84 ug_destroy_me(ad->ug);
88 char *_ringtone_gl_label_get(void *data, Evas_Object *obj, const char *part)
90 retvm_if(data == NULL, NULL, "Data parameter is NULL");
91 Setting_GenGroupItem_Data *item_data = (Setting_GenGroupItem_Data *) data;
93 if (safeStrCmp(part, "elm.text.main.left"))
96 return (char *)g_strdup(_(item_data->keyStr));
99 Evas_Object *_ringtone_gl_icon_get(void *data, Evas_Object *obj,
102 retvm_if(data == NULL, NULL, "Data parameter is NULL");
103 Setting_GenGroupItem_Data *item_data = (Setting_GenGroupItem_Data *) data;
104 /*SettingRingtoneUG *ad = (SettingRingtoneUG *) (item_data->userdata); */
106 if (safeStrCmp(part, "elm.icon.right"))
109 Evas_Object *lay = elm_layout_add(obj);
111 Evas_Object *radio = elm_radio_add(lay);
112 evas_object_propagate_events_set(radio, EINA_FALSE);
113 evas_object_repeat_events_set(radio, EINA_TRUE);
114 elm_radio_state_value_set(radio, item_data->chk_status);
115 elm_radio_group_add(radio, item_data->rgd);
116 evas_object_show(radio);
117 item_data->eo_check = radio;
119 elm_layout_theme_set(lay, "layout", "list/C/type.2", "default");
120 elm_layout_content_set(lay, "elm.swallow.content", radio);
125 static void _ringtone_gl_del(void *data, Evas_Object *obj)
127 Setting_GenGroupItem_Data *item_data =
128 (Setting_GenGroupItem_Data *) data;
131 G_FREE(item_data->keyStr);
132 G_FREE(item_data->filepath);
137 static inline void appmgrUg_init_itcs(SettingRingtoneUG *ad)
140 ad->itc_ring.item_style = "1line";
141 ad->itc_ring.func.text_get = _ringtone_gl_label_get;
142 ad->itc_ring.func.content_get = _ringtone_gl_icon_get;
143 ad->itc_ring.func.state_get = NULL;
144 ad->itc_ring.func.del = _ringtone_gl_del;
147 static void ringtone_item_sel(void *data, Evas_Object *obj, void *event_info)
150 setting_retm_if(data == NULL, "Data parameter is NULL");
152 retm_if(event_info == NULL, "Invalid argument: event info is NULL");
153 Elm_Object_Item *item = (Elm_Object_Item *) event_info;
154 elm_genlist_item_selected_set(item, 0);
155 Setting_GenGroupItem_Data *list_item =
156 (Setting_GenGroupItem_Data *) elm_object_item_data_get(item);
158 SettingRingtoneUG *ad = (SettingRingtoneUG *)data;
160 Evas_Object *radio = list_item->eo_check;
161 elm_radio_value_set(radio, list_item->chk_status);
163 G_FREE(ad->sel_file_path);
164 ad->sel_file_path = g_strdup(list_item->filepath);
165 ad->sel_item_data = list_item;
167 SETTING_TRACE("sel file: %s", ad->sel_file_path);
168 if (ad->mp_ringtone) {
169 ringtone_stop_sound(ad);
171 if (safeStrCmp(list_item->keyStr, "IDS_ST_BODY_PHONEPROFILES_SILENT")) {
172 ringtone_play_sound(ad->sel_file_path, &ad->mp_ringtone);
176 static int _compare_cb(const void *d1, const void *d2)
178 fileNodeInfo *pNode1 = d1;
179 fileNodeInfo *pNode2 = d2;
181 return safeStrCmp(pNode1->media_name, pNode2->media_name);
184 char *get_default_filepath(SettingRingtoneUG *ad)
186 retv_if(ad == NULL, NULL);
188 char *default_ringtone = NULL;
190 if (!safeStrCmp(ad->dir_path, RINGTONE_FILE_PATH) ||
191 !safeStrCmp(ad->dir_path, RINGTONE_FILE_PATH_1)) {
193 default_ringtone = vconf_get_str(VCONFKEY_SETAPPL_CALL_RINGTONE_PATH_STR);
194 if (default_ringtone && ecore_file_exists(default_ringtone)) {
195 return default_ringtone;
197 FREE(default_ringtone);
198 default_ringtone = g_strdup(RINGTONE_FILE_PATH_DEF);
203 default_ringtone = vconf_get_str(VCONFKEY_SETAPPL_NOTI_RINGTONE_PATH_STR);
204 if (default_ringtone && ecore_file_exists(default_ringtone)) {
205 return default_ringtone;
207 FREE(default_ringtone);
208 default_ringtone = g_strdup(ALERT_FILE_PATH_DEF);
212 return default_ringtone;
215 /* ***************************************************
219 ***************************************************/
221 static int setting_ringtone_create(void *cb)
224 retv_if(cb == NULL, SETTING_GENERAL_ERR_NULL_DATA_PARAMETER);
226 SettingRingtoneUG *ad = (SettingRingtoneUG *) cb;
228 ad->ly_main = setting_create_layout_navi_bar_genlist(ad->win_main_layout,
234 NULL, ad, &ad->scroller,
236 Elm_Object_Item *navi_it;
237 navi_it = elm_naviframe_top_item_get(ad->navi_bar);
238 elm_naviframe_item_pop_cb_set(navi_it, setting_ringtone_click_back_cb, ad);
240 Evas_Object *btn_cancel = elm_button_add(ad->navi_bar);
241 elm_object_style_set(btn_cancel, "naviframe/title_cancel");
242 evas_object_smart_callback_add(btn_cancel, "clicked", setting_ringtone_cancel_click_cb, ad);
243 elm_object_item_part_content_set(navi_it, "title_left_btn", btn_cancel);
245 Evas_Object *btn_done = elm_button_add(ad->navi_bar);
246 elm_object_style_set(btn_done, "naviframe/title_done");
247 evas_object_smart_callback_add(btn_done, "clicked", setting_ringtone_done_click_cb, ad);
248 elm_object_item_part_content_set(navi_it, "title_right_btn", btn_done);
250 appmgrUg_init_itcs(ad);
253 Eina_List *filelist = NULL;
254 int ret = get_filelist_from_dir_path(ad->dir_path, &filelist);
256 SETTING_TRACE_ERROR("Failed to get filelist, ret = %d", ret);
258 filelist = eina_list_sort(filelist,
259 eina_list_count(filelist), _compare_cb);
260 ad->filelist = filelist;
264 Elm_Object_Item *cur_item;
265 Setting_GenGroupItem_Data *item_data = NULL;
267 int cur_pos = -1; /*current selected item */
268 char fullPath[512] = {0, };
270 ad->ring_rgd = elm_radio_add(ad->scroller);
271 elm_radio_state_value_set(ad->ring_rgd, -1);
273 /*create default item */
274 if (ad->is_show_def) {
275 item_data = (Setting_GenGroupItem_Data *)calloc(1, sizeof(Setting_GenGroupItem_Data));
277 item_data->userdata = ad;
278 item_data->keyStr = g_strdup(STR_DEFAULT_RINGTONE);
279 item_data->rgd = ad->ring_rgd;
280 item_data->chk_status = cnt;
281 item_data->filepath = get_default_filepath(ad);
282 item_data->item = elm_genlist_item_append(ad->scroller, &(ad->itc_ring), item_data, NULL,
283 ELM_GENLIST_ITEM_NONE, ringtone_item_sel, ad);
285 if (!safeStrCmp("default", ad->file_path)) {
287 cur_item = item_data->item;
291 SETTING_TRACE_ERROR("item_data is NULL");
295 /*create silent item */
296 if (ad->is_show_silent) {
297 item_data = (Setting_GenGroupItem_Data *)calloc(1, sizeof(Setting_GenGroupItem_Data));
299 item_data->userdata = ad;
300 item_data->keyStr = g_strdup("IDS_ST_BODY_PHONEPROFILES_SILENT");
301 item_data->rgd = ad->ring_rgd;
302 item_data->chk_status = cnt;
303 item_data->filepath = g_strdup("silent");
304 item_data->item = elm_genlist_item_append(ad->scroller, &(ad->itc_ring), item_data, NULL,
305 ELM_GENLIST_ITEM_NONE, ringtone_item_sel, ad);
307 if (!safeStrCmp("silent", ad->file_path)) {
309 cur_item = item_data->item;
313 SETTING_TRACE_ERROR("item_data is NULL");
317 /*create items in specified dir */
318 EINA_LIST_FOREACH(filelist, l, pNode) {
320 if (pNode->path && pNode->name) {
321 memset(fullPath, 0x00, sizeof(fullPath));
322 snprintf(fullPath, sizeof(fullPath), "%s/%s", pNode->path, pNode->name);
327 item_data = (Setting_GenGroupItem_Data *)calloc(1, sizeof(Setting_GenGroupItem_Data));
329 item_data->userdata = ad;
330 item_data->keyStr = g_strdup(pNode->media_name);
331 item_data->rgd = ad->ring_rgd;
332 item_data->chk_status = cnt;
333 item_data->filepath = g_strdup(fullPath);
334 item_data->item = elm_genlist_item_append(ad->scroller, &(ad->itc_ring), item_data, NULL,
335 ELM_GENLIST_ITEM_NONE, ringtone_item_sel, ad);
337 if (!safeStrCmp(fullPath, ad->file_path)) {
339 cur_item = item_data->item;
343 SETTING_TRACE_ERROR("item_data is NULL");
346 elm_radio_value_set(ad->ring_rgd, cur_pos);
348 elm_genlist_item_bring_in(cur_item, ELM_GENLIST_ITEM_SCROLLTO_MIDDLE);
351 setting_view_ringtone_main.is_create = 1;
352 return SETTING_RETURN_SUCCESS;
355 static int setting_ringtone_destroy(void *cb)
359 retv_if(cb == NULL, SETTING_GENERAL_ERR_NULL_DATA_PARAMETER);
360 SettingRingtoneUG *ad = (SettingRingtoneUG *) cb;
362 if (ad->ly_main != NULL) {
363 evas_object_del(ad->ly_main);
365 setting_view_ringtone_main.is_create = 0;
368 if (ad->mp_ringtone) {
369 ringtone_stop_sound(ad);
374 G_FREE(ad->sel_file_path);
379 fileNodeInfo *node = NULL;
380 EINA_LIST_FOREACH(ad->filelist, l, node) {
383 G_FREE(node->media_name);
386 eina_list_free(ad->filelist);
389 return SETTING_RETURN_SUCCESS;
392 static int setting_ringtone_update(void *cb)
395 SettingRingtoneUG *ad = (SettingRingtoneUG *) cb;
397 if (ad->ly_main != NULL) {
398 evas_object_show(ad->ly_main);
400 return SETTING_RETURN_SUCCESS;
404 static int setting_ringtone_cleanup(void *cb)
407 SettingRingtoneUG *ad = (SettingRingtoneUG *) cb;
409 if (ad->ly_main != NULL) {
410 evas_object_hide(ad->ly_main);
412 return SETTING_RETURN_SUCCESS;
415 /* ***************************************************
419 ***************************************************/
422 setting_ringtone_click_back_cb(void *data, Elm_Object_Item *it)
424 setting_retvm_if(data == NULL, EINA_FALSE, "Data parameter is NULL");
426 SettingRingtoneUG *ad = (SettingRingtoneUG *) data;
428 ug_destroy_me(ad->ug);