tizen 2.3.1 release
[apps/home/settings.git] / setting-ringtone / src / setting-ringtone.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 /**
23  *@defgroup setting-ringtone
24  *UG creation code for setting-ringtone
25  * html file viewer
26  */
27
28 #include <setting-ringtone.h>
29 #include <setting-ringtone-util.h>
30
31 #ifndef UG_MODULE_API
32 #define UG_MODULE_API __attribute__ ((visibility("default")))
33 #endif
34
35 bool __parse_ug_argument(app_control_h service, void *priv)
36 {
37         SETTING_TRACE_BEGIN;
38         SettingRingtoneUG *ad = priv;
39
40         ad->file_path = NULL;
41         app_control_get_extra_data(service, "marked_mode", &(ad->file_path));
42         setting_retvm_if(!ad->file_path, FALSE, "no arguement to specialize file");
43
44         ad->dir_path = NULL;
45         app_control_get_extra_data(service, "path", &(ad->dir_path));
46         setting_retvm_if(!ad->dir_path, FALSE, "no arguement to specialize file");
47
48         char *silent = NULL;
49         app_control_get_extra_data(service, "silent", &silent);
50         if (!safeStrCmp(silent , "silent show")) {
51                 ad->is_show_silent = 1;
52         }
53
54         char *default_str = NULL;
55         app_control_get_extra_data(service, "default", &default_str);
56         if (!safeStrCmp(default_str , "default show")) {
57                 ad->is_show_def = 1;
58         }
59
60         SETTING_TRACE("dir path: %s", ad->dir_path);
61         SETTING_TRACE("current file path: %s", ad->file_path);
62         SETTING_TRACE("show silent: %d", ad->is_show_silent);
63         return TRUE;
64 }
65
66 /**
67 * Event process when the sizeof UG view changes
68 *
69 * @param data
70 * @param e
71 * @param obj
72 * @param event_info
73 */
74 static void setting_ringtone_ug_cb_resize(void *data, Evas *e, Evas_Object *obj,
75                                           void *event_info)
76 {
77         SettingRingtoneUG *ad = (SettingRingtoneUG *) data;
78         setting_view_update(&setting_view_ringtone_main, ad);
79 }
80
81 /**
82 * on_create function of the UG
83 *
84 * @param ug
85 * @param mode
86 * @param data
87 * @param priv
88 *
89 * @return
90 */
91 static void *setting_ringtone_ug_on_create(ui_gadget_h ug, enum ug_mode mode,
92                                            app_control_h service, void *priv)
93 {
94         SETTING_TRACE_BEGIN;
95         setting_retvm_if((NULL == priv), NULL, "NULL == priv");
96         SettingRingtoneUG *ringtoneUG = priv;
97         ringtoneUG->ug = ug;
98
99         ringtoneUG->win_main_layout = (Evas_Object *) ug_get_parent_layout(ug);
100         ringtoneUG->win_get = (Evas_Object *) ug_get_window();
101         evas_object_show(ringtoneUG->win_main_layout);
102         ringtoneUG->evas = evas_object_evas_get(ringtoneUG->win_main_layout);
103
104         setting_retvm_if(ringtoneUG->win_main_layout == NULL, NULL,
105                          "cannot get main window ");
106
107         /*  creating a view. */
108         if (!__parse_ug_argument(service, priv)) {
109                 SETTING_TRACE_ERROR("Invalid arguement");
110                 return NULL;
111         }
112
113         if (0 != app_control_clone(&(ringtoneUG->source_svc), service)) {
114                 SETTING_TRACE_ERROR("failed to clone svc");
115         }
116
117         setting_view_create(&setting_view_ringtone_main, (void *)ringtoneUG);
118         evas_object_event_callback_add(ringtoneUG->win_main_layout,
119                                        EVAS_CALLBACK_RESIZE,
120                                        setting_ringtone_ug_cb_resize, ringtoneUG);
121         return ringtoneUG->ly_main;
122 }
123
124 static void setting_ringtone_ug_on_start(ui_gadget_h ug, app_control_h service,
125                                          void *priv)
126 {
127 }
128
129 static void setting_ringtone_ug_on_pause(ui_gadget_h ug, app_control_h service,
130                                          void *priv)
131 {
132         SETTING_TRACE_BEGIN;
133 }
134
135 static void setting_ringtone_ug_on_resume(ui_gadget_h ug, app_control_h service,
136                                           void *priv)
137 {
138         SETTING_TRACE_BEGIN;
139 }
140
141 /**
142 * on_destroy function of the UG
143 *
144 * @param ug
145 * @param data
146 * @param priv
147 */
148 static void setting_ringtone_ug_on_destroy(ui_gadget_h ug, app_control_h service,
149                                            void *priv)
150 {
151         SETTING_TRACE_BEGIN;
152         setting_retm_if((!priv), "!priv");
153         SettingRingtoneUG *ringtoneUG = priv;
154
155         evas_object_event_callback_del(ringtoneUG->win_main_layout, EVAS_CALLBACK_RESIZE, setting_ringtone_ug_cb_resize);       /* fix flash issue for gallery */
156         ringtoneUG->ug = ug;
157         /*  delete the allocated objects. */
158         setting_view_destroy(&setting_view_ringtone_main, ringtoneUG);
159
160         if (ringtoneUG->source_svc) {
161                 app_control_destroy(ringtoneUG->source_svc);
162                 ringtoneUG->source_svc = NULL;
163         }
164
165         if (NULL != ug_get_layout(ringtoneUG->ug)) {
166                 evas_object_hide((Evas_Object *) ug_get_layout(ringtoneUG->ug));
167                 evas_object_del((Evas_Object *) ug_get_layout(ringtoneUG->ug));
168         }
169
170         SETTING_TRACE_END;
171 }
172
173 static void setting_ringtone_ug_on_message(ui_gadget_h ug, app_control_h msg,
174                                            app_control_h service, void *priv)
175 {
176         SETTING_TRACE_BEGIN;
177 }
178
179 static void setting_ringtone_ug_on_event(ui_gadget_h ug, enum ug_event event,
180                                          app_control_h service, void *priv)
181 {
182         SETTING_TRACE_BEGIN;
183         switch (event) {
184                 case UG_EVENT_LOW_MEMORY:
185                         break;
186                 case UG_EVENT_LOW_BATTERY:
187                         break;
188                 case UG_EVENT_LANG_CHANGE:
189                         break;
190                 case UG_EVENT_ROTATE_PORTRAIT:
191                         break;
192                 case UG_EVENT_ROTATE_PORTRAIT_UPSIDEDOWN:
193                         break;
194                 case UG_EVENT_ROTATE_LANDSCAPE:
195                         break;
196                 case UG_EVENT_ROTATE_LANDSCAPE_UPSIDEDOWN:
197                         break;
198                 case UG_EVENT_REGION_CHANGE:
199                         break;
200                 default:
201                         break;
202         }
203 }
204
205 static void setting_ringtone_ug_on_key_event(ui_gadget_h ug,
206                                              enum ug_key_event event,
207                                              app_control_h service, void *priv)
208 {
209         SETTING_TRACE_BEGIN;
210         SettingRingtoneUG *ad = (SettingRingtoneUG *) priv;
211
212         switch (event) {
213                 case UG_KEY_EVENT_END: {
214                                 if (elm_naviframe_top_item_get(ad->navi_bar) ==
215                                     elm_naviframe_bottom_item_get(ad->navi_bar)) {
216                                         ug_destroy_me(ug);
217                                 } else {
218                                         /* elm_naviframe_item_pop(ad->navi_bar); */
219                                         setting_view_cb_at_endKey(ad);
220                                 }
221                         }
222                         break;
223                 default:
224                         break;
225         }
226 }
227
228 UG_MODULE_API int UG_MODULE_INIT(struct ug_module_ops *ops)
229 {
230         SETTING_TRACE_BEGIN;
231         SettingRingtoneUG *ringtoneUG = calloc(1, sizeof(SettingRingtoneUG));
232         setting_retvm_if(!ringtoneUG, -1, "Create SettingRingtoneUG obj failed");
233
234         ops->create = setting_ringtone_ug_on_create;
235         ops->start = setting_ringtone_ug_on_start;
236         ops->pause = setting_ringtone_ug_on_pause;
237         ops->resume = setting_ringtone_ug_on_resume;
238         ops->destroy = setting_ringtone_ug_on_destroy;
239         ops->message = setting_ringtone_ug_on_message;
240         ops->event = setting_ringtone_ug_on_event;
241         ops->key_event = setting_ringtone_ug_on_key_event;
242         ops->priv = ringtoneUG;
243         ops->opt = UG_OPT_INDICATOR_ENABLE;
244
245         return 0;
246 }
247
248 UG_MODULE_API void UG_MODULE_EXIT(struct ug_module_ops *ops)
249 {
250         SETTING_TRACE_BEGIN;
251         struct SettingRingtoneUG *ringtoneUG;
252         setting_retm_if(!ops, "ops == NULL");
253
254         ringtoneUG = ops->priv;
255         if (ringtoneUG) {
256                 FREE(ringtoneUG);
257         }
258 }
259
260 /* ***************************************************
261  **
262  **general func
263  **
264  ****************************************************/
265