tizen 2.4 release
[apps/home/settings.git] / setting-profile / src / setting-profile.c
1 /*
2  * setting
3  *
4  * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd.
5  *
6  * Contact: MyoungJune Park <mj2004.park@samsung.com>
7  *
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
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
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.
19  *
20  */
21
22 #include <setting-profile.h>
23
24 #ifndef UG_MODULE_API
25 #define UG_MODULE_API __attribute__ ((visibility("default")))
26 #endif
27
28
29 static void setting_sound_ug_cb_resize(void *data, Evas *e,
30                                        Evas_Object *obj, void *event_info)
31 {
32         ret_if(data == NULL);
33
34         SettingProfileUG *ad = (SettingProfileUG *) data;
35         setting_view_update(&setting_view_sound_main, ad);
36 }
37
38 static void *setting_sound_ug_on_create(ui_gadget_h ug,
39                                         enum ug_mode mode, app_control_h service,
40                                         void *priv)
41 {
42         SETTING_TRACE_BEGIN;
43         /*appcore_measure_start(); */
44         retv_if(priv == NULL, NULL);
45
46         SettingProfileUG *profileUG = priv;
47         profileUG->ug = ug;
48
49         profileUG->win_main_layout = (Evas_Object *) ug_get_parent_layout(ug);
50         profileUG->win_get = (Evas_Object *) ug_get_window();
51         evas_object_show(profileUG->win_main_layout);
52         profileUG->evas = evas_object_evas_get(profileUG->win_main_layout);
53         setting_retvm_if(profileUG->win_main_layout == NULL, NULL, "cannot get main window ");
54
55         app_control_get_caller(service, &(profileUG->viewtype));
56         setting_sound_init(profileUG);
57         evas_object_event_callback_add(profileUG->win_main_layout,
58                                        EVAS_CALLBACK_RESIZE,
59                                        setting_sound_ug_cb_resize, profileUG);
60         return profileUG->ly_main;
61 }
62
63 static void setting_sound_ug_on_start(ui_gadget_h ug, app_control_h service, void *priv)
64 {
65 }
66
67 static void setting_sound_ug_on_pause(ui_gadget_h ug, app_control_h service, void *priv)
68 {
69         ret_if(priv == NULL);
70         SettingProfileUG *profileUG = (SettingProfileUG *)priv;
71
72         if (profileUG->calling_popup) {
73                 evas_object_del(profileUG->calling_popup);
74                 profileUG->calling_popup = NULL;
75         }
76
77         /* if click home key, players have to be closed */
78         setting_sound_close_all_mm_players(profileUG);
79
80         /* If sound ug is paused, others can use volume HW key popup (set 0) */
81         vconf_set_int(VCONFKEY_STARTER_USE_VOLUME_KEY, 0);
82 }
83
84
85 static void setting_sound_ug_on_resume(ui_gadget_h ug, app_control_h service, void *priv)
86 {
87         ret_if(priv == NULL);
88         SettingProfileUG *profileUG = (SettingProfileUG *)priv;
89
90         /* If current view is sound main, block volume app */
91         /* To prevent conflict with volume app */
92         if (!safeStrCmp(profileUG->viewtype, "com.samsung.volume")) {
93                 vconf_set_int(VCONFKEY_STARTER_USE_VOLUME_KEY, 2);
94         } else {
95                 vconf_set_int(VCONFKEY_STARTER_USE_VOLUME_KEY, 0);
96         }
97
98         /* update path of tones */
99         char *pa_tone_path = NULL;
100
101         /* 1. incoming call ringtone */
102         if (profileUG->data_call_alert_tone) {
103                 SETTING_TRACE_DEBUG("change call_alert_tone %x", profileUG->data_call_alert_tone);
104                 pa_tone_path = vconf_get_str(VCONFKEY_SETAPPL_CALL_RINGTONE_PATH_STR);
105                 if ((pa_tone_path == NULL) || (setting_sound_check_file_exist(profileUG, pa_tone_path) == SETTING_RETURN_FAIL)) {
106                         if (isEmulBin())
107                                 pa_tone_path = (char *)strdup(SETTING_DEFAULT_CALL_TONE_SDK);
108                         else
109                                 pa_tone_path = (char *)strdup(SETTING_DEFAULT_CALL_TONE);
110                         if (vconf_set_str(VCONFKEY_SETAPPL_CALL_RINGTONE_PATH_STR, pa_tone_path) < 0) {
111                                 FREE(pa_tone_path);
112                                 return;
113                         }
114                         profileUG->data_call_alert_tone->sub_desc = setting_media_basename(pa_tone_path);
115                         elm_genlist_item_update(profileUG->data_call_alert_tone->item);
116                 }
117                 FREE(pa_tone_path);
118         }
119
120         /* 2. message ringtone */
121         if (profileUG->data_msg_alert_tone) {
122                 SETTING_TRACE_DEBUG("change msg_alert_tone %x", profileUG->data_msg_alert_tone);
123                 pa_tone_path = vconf_get_str(VCONFKEY_SETAPPL_NOTI_MSG_RINGTONE_PATH_STR);
124                 if ((pa_tone_path == NULL) || (setting_sound_check_file_exist(profileUG, pa_tone_path) == SETTING_RETURN_FAIL)) {
125                         pa_tone_path = (char *)strdup(SETTING_DEFAULT_MSG_TONE);
126                         if (vconf_set_str(VCONFKEY_SETAPPL_NOTI_MSG_RINGTONE_PATH_STR, SETTING_DEFAULT_MSG_TONE) < 0) {
127                                 FREE(pa_tone_path);
128                                 return;
129                         }
130
131                         profileUG->data_msg_alert_tone->sub_desc = setting_media_basename(pa_tone_path);
132                         elm_genlist_item_update(profileUG->data_msg_alert_tone->item);
133                 }
134                 FREE(pa_tone_path);
135         }
136
137         int sound_value = 0, volume = 0;
138
139         if (vconf_get_bool(VCONFKEY_SETAPPL_SOUND_STATUS_BOOL, &sound_value) < 0)
140                 sound_value = TRUE;
141
142         (void)sound_manager_get_volume(SOUND_TYPE_RINGTONE, &volume);
143         if (sound_value == FALSE)
144                 volume = 0;
145         if (profileUG->data_call_volume && profileUG->data_call_volume->eo_check) {
146                 profileUG->data_call_volume->chk_status = volume;
147                 elm_slider_value_set(profileUG->data_call_volume->eo_check, volume);
148         }
149
150         (void)sound_manager_get_volume(SOUND_TYPE_NOTIFICATION, &volume);
151         if (sound_value == FALSE)
152                 volume = 0;
153         if (profileUG->data_noti_volume && profileUG->data_noti_volume->eo_check) {
154                 profileUG->data_noti_volume->chk_status = volume;
155                 elm_slider_value_set(profileUG->data_noti_volume->eo_check, volume);
156         }
157
158         (void)sound_manager_get_volume(SOUND_TYPE_MEDIA, &volume);
159         if (profileUG->data_media_volume && profileUG->data_media_volume->eo_check) {
160                 profileUG->data_media_volume->chk_status = volume;
161                 elm_slider_value_set(profileUG->data_media_volume->eo_check, volume);
162         }
163
164         (void)sound_manager_get_volume(SOUND_TYPE_SYSTEM, &volume);
165         if (sound_value == FALSE)
166                 volume = 0;
167         if (profileUG->data_touch_volume && profileUG->data_touch_volume->eo_check) {
168                 profileUG->data_touch_volume->chk_status = volume;
169                 elm_slider_value_set(profileUG->data_touch_volume->eo_check, volume);
170         }
171
172         setting_sound_update_slider_icon(profileUG->data_call_volume, SND_SLIDER_CALL);
173         setting_sound_update_slider_icon(profileUG->data_noti_volume, SND_SLIDER_NOTI);
174         setting_sound_update_slider_icon(profileUG->data_media_volume, SND_SLIDER_MEDIA);
175         setting_sound_update_slider_icon(profileUG->data_touch_volume, SND_SLIDER_SYSTEM);
176 }
177
178 static void setting_sound_ug_on_destroy(ui_gadget_h ug, app_control_h service, void *priv)
179 {
180         SETTING_TRACE_BEGIN;
181         ret_if(priv == NULL);
182
183         SettingProfileUG *ad = priv;
184         evas_object_event_callback_del(ad->win_main_layout, EVAS_CALLBACK_RESIZE, setting_sound_ug_cb_resize);  /* fix flash issue for gallery */
185         setting_sound_deinit(ad);
186
187         if (NULL != ug_get_layout(ad->ug)) {
188                 evas_object_hide((Evas_Object *) ug_get_layout(ad->ug));
189                 evas_object_del((Evas_Object *) ug_get_layout(ad->ug));
190         }
191         SETTING_TRACE_END;
192 }
193
194 static void setting_sound_ug_on_message(ui_gadget_h ug, app_control_h msg,
195                                         app_control_h service, void *priv)
196 {
197 }
198
199 static void setting_sound_ug_on_event(ui_gadget_h ug,
200                                       enum ug_event event, app_control_h service, void *priv)
201 {
202         SETTING_TRACE_BEGIN;
203         /*SettingProfileUG *ad = (SettingProfileUG *)priv; */
204
205         switch (event) {
206                 case UG_EVENT_LOW_MEMORY:
207                         break;
208                 case UG_EVENT_LOW_BATTERY:
209                         break;
210                 case UG_EVENT_LANG_CHANGE:
211                         break;
212                 case UG_EVENT_ROTATE_PORTRAIT:
213                 case UG_EVENT_ROTATE_PORTRAIT_UPSIDEDOWN:
214                         break;
215                 case UG_EVENT_ROTATE_LANDSCAPE:
216                 case UG_EVENT_ROTATE_LANDSCAPE_UPSIDEDOWN:
217                         break;
218                 case UG_EVENT_REGION_CHANGE:
219                         break;
220                 default:
221                         break;
222         }
223 }
224
225 static void setting_sound_ug_on_key_event(ui_gadget_h ug,
226                                           enum ug_key_event event, app_control_h service, void *priv)
227 {
228         ret_if(priv == NULL);
229
230         /*SettingProfileUG *ad = (SettingProfileUG *) priv; */
231
232         switch (event) {
233                 case UG_KEY_EVENT_END:
234                         break;
235                 default:
236                         break;
237         }
238 }
239
240 UG_MODULE_API int UG_MODULE_INIT(struct ug_module_ops *ops)
241 {
242         SETTING_TRACE_BEGIN;
243         /*appcore_measure_start(); */
244         SettingProfileUG *profileUG = calloc(1, sizeof(SettingProfileUG));
245         setting_retvm_if(!profileUG, -1, "Create SettingProfileUG obj failed");
246
247         ops->create = setting_sound_ug_on_create;
248         ops->start = setting_sound_ug_on_start;
249         ops->pause = setting_sound_ug_on_pause;
250         ops->resume = setting_sound_ug_on_resume;
251         ops->destroy = setting_sound_ug_on_destroy;
252         ops->message = setting_sound_ug_on_message;
253         ops->event = setting_sound_ug_on_event;
254         ops->key_event = setting_sound_ug_on_key_event;
255         ops->priv = profileUG;
256         ops->opt = UG_OPT_INDICATOR_ENABLE;
257
258         memset(profileUG, 0x00, sizeof(SettingProfileUG));
259
260         return 0;
261 }
262
263 UG_MODULE_API void UG_MODULE_EXIT(struct ug_module_ops *ops)
264 {
265         ret_if(ops == NULL);
266
267         struct SettingProfileUG *profileUG;
268         profileUG = ops->priv;
269         if (profileUG)
270                 FREE(profileUG);
271 }
272
273 /* ***************************************************
274  *
275  *general func
276  *
277  ***************************************************/
278