tizen 2.3.1 release
[apps/home/settings.git] / setting-font / src / setting-font.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 #include <setting-font.h>
22 #include <system_settings.h>
23 #include <setting-cfg.h>
24
25 #ifndef UG_MODULE_API
26 #define UG_MODULE_API __attribute__ ((visibility("default")))
27 #endif
28
29 setting_view *__default_view_state(void *data, app_control_h service)
30 {
31         SETTING_TRACE_BEGIN;
32         setting_retvm_if((!data), NULL, "data is NULL");
33         SettingFontUG *fontUG = (SettingFontUG *)data;
34
35         /* argument processing */
36         char *category = NULL;
37         app_control_get_extra_data(service, "category", &category);
38
39         if (0 == safeStrCmp(category, "FontType")) {
40                 SETTING_TRACE("LAUNCHED BY APP-CONTROL MODE");
41                 fontUG->viewmode = FONT_SEL_VIEW_APPCONTROL;
42                 setting_view_node_table_register(&setting_view_font_font_size, &setting_view_font_main);
43                 setting_view_node_table_register(&setting_view_font_main, NULL);
44                 FREE(category);
45                 return &setting_view_font_main;
46         } else if (0 == safeStrCmp(category, "FontSize")) {
47                 SETTING_TRACE("category = %s", category);
48                 fontUG->viewmode = FONT_SIZE_VIEW_APPCONTROL;
49                 setting_view_node_table_register(&setting_view_font_font_size, NULL);
50                 FREE(category);
51                 return &setting_view_font_font_size;
52         } else {
53                 SETTING_TRACE("HERE ?? <<<<< ");
54                 char *viewtype = NULL;
55                 app_control_get_extra_data(service, "viewtype", &viewtype);
56                 if (!safeStrCmp(viewtype, "FontType_expand")) {
57                         fontUG->font_expand_state = FONT_EXPAND_STATE_FONT_TYPE;
58                 } else if (!safeStrCmp(viewtype, "FontSize_expand")) {
59                         fontUG->font_expand_state = FONT_EXPAND_STATE_FONT_SIZE;
60                 } else {
61                         fontUG->font_expand_state = FONT_EXPAND_STATE_NONE;
62                 }
63                 fontUG->viewmode = FONT_SIZE_AND_FONT_SEL_UG;   /* set default */
64                 setting_view_node_table_register(&setting_view_font_font_size, &setting_view_font_main);
65                 setting_view_node_table_register(&setting_view_font_main, NULL);
66                 FREE(category);
67                 return &setting_view_font_main;
68         }
69 }
70
71 /*------------------------------------------------------------- */
72 /* http://tizen.org/appcontrol/operation/configure/font/type */
73 /* http://tizen.org/appcontrol/operation/configure/font/size */
74 /*------------------------------------------------------------- */
75 setting_view *__app_control_get_operation_handler(void *data, app_control_h service)
76 {
77         SETTING_TRACE_BEGIN;
78         setting_retvm_if((!data), NULL, "data is NULL");
79         setting_retvm_if((!service), NULL, "service is NULL");
80         SettingFontUG *fontUG = (SettingFontUG *)data;
81         char *output_url = NULL;
82
83         int ret = app_control_get_operation(service, &output_url);
84
85         if (ret == APP_CONTROL_ERROR_NONE) {
86                 /*SETTING_TRACE(" >>>>>>>>>>>>>>>>>>> (%s) ", output_url); */
87                 if (0 == safeStrCmp(output_url, "http://tizen.org/appcontrol/operation/configure/font/type")
88                     || 0 == safeStrCmp(output_url, "http://samsung.com/appcontrol/operation/configure/font/type")) {
89                         fontUG->viewmode = FONT_SEL_VIEW_APPCONTROL;
90                         setting_view_node_table_register(&setting_view_font_font_size, &setting_view_font_main);
91                         setting_view_node_table_register(&setting_view_font_main, NULL);
92
93                         FREE(output_url);
94                         return &setting_view_font_main;
95                 } else if (0 == safeStrCmp(output_url, "http://tizen.org/appcontrol/operation/configure/font/size")
96                            || 0 == safeStrCmp(output_url, "http://tizen.org/appcontrol/operation/configure/font/size")) {
97                         fontUG->viewmode = FONT_SIZE_VIEW_APPCONTROL;
98                         setting_view_node_table_register(&setting_view_font_font_size, NULL);
99
100                         FREE(output_url);
101                         return &setting_view_font_font_size;
102                 } else {
103                         SETTING_TRACE("No URL, default action - argument parsing");
104                         FREE(output_url);
105                         return __default_view_state(fontUG, service);
106                 }
107         } else {
108                 SETTING_TRACE("failed to call app_control_get_operation with error code %d", ret);
109                 if (output_url) {
110                         FREE(output_url);
111                 }
112                 return NULL;
113         }
114 }
115
116 setting_view *__get_font_view_to_load(void *data, app_control_h service)
117 {
118         SETTING_TRACE_BEGIN;
119         setting_retvm_if((!data), NULL, "data is NULL");
120         SettingFontUG *fontUG = (SettingFontUG *)data;
121
122         /*if ug is called by accessibility, view node table should not be initialized */
123         char *caller = NULL;
124         app_control_get_extra_data(service, "caller", &caller);
125         if (0 != safeStrCmp(caller, "accessibility")) {
126                 /*need to initialize the node table when UG is re-created and it is NOT loaded by another UG*/
127                 setting_view_node_table_intialize();
128         }
129         FREE(caller);
130
131         /* if argument is there, process it first */
132         char *output_url = NULL;
133         int ret = app_control_get_operation(service, &output_url);
134
135         /* service OK, but there's no argument */
136         if ((ret == APP_CONTROL_ERROR_NONE)
137             && (0 == safeStrCmp(output_url, "http://tizen.org/appcontrol/operation/default")
138                 || 0 == safeStrCmp(output_url, "http://samsung.com/appcontrol/operation/default"))) {
139                 FREE(output_url);
140                 return __default_view_state(fontUG, service);
141
142         } else if (ret == APP_CONTROL_ERROR_NONE) {
143                 FREE(output_url);
144                 return __app_control_get_operation_handler(fontUG, service);
145
146         } else {
147                 if (output_url) {
148                         FREE(output_url);
149                 }
150                 /* service is not OK, but need to handle default action */
151                 return __default_view_state(fontUG, service);
152         }
153 }
154
155 static void setting_font_ug_cb_resize(void *data, Evas *e, Evas_Object *obj,
156                                       void *event_info)
157 {
158         SettingFontUG *ad = (SettingFontUG *) data;
159         setting_view_update(&setting_view_font_main, ad);
160 }
161
162 static void *setting_font_ug_on_create(ui_gadget_h ug, enum ug_mode mode,
163                                        app_control_h service, void *priv)
164 {
165         setting_retvm_if((!priv), NULL, "!priv");
166         SettingFontUG *fontUG = priv;
167
168         setting_set_i18n(SETTING_PACKAGE, SETTING_LOCALEDIR);
169
170         fontUG->ug = ug;
171         fontUG->win_main_layout = (Evas_Object *) ug_get_parent_layout(ug);
172         fontUG->win_get = (Evas_Object *) ug_get_window();
173         evas_object_show(fontUG->win_main_layout);
174         fontUG->evas = evas_object_evas_get(fontUG->win_main_layout);
175
176         setting_retvm_if(fontUG->win_main_layout == NULL, NULL,
177                          "cannot get main window ");
178
179         setting_create_Gendial_itc("2line.top", &(fontUG->itc_2text_3_parent));
180         setting_create_Gendial_itc("2line.top", &(fontUG->itc_1icon_1text_sub));
181         /*setting_create_Gendial_itc("dialogue/2text.3", &(fontUG->itc_2text_2)); */
182         setting_create_Gendial_itc("2line.top", &(fontUG->itc_2text_2));
183         setting_create_Gendial_itc("groupindex", &(fontUG->itc_group_item));
184         setting_create_Gendial_itc("multiline", &(fontUG->itc_bg_1icon));
185
186         /* view type checking */
187         fontUG->view_to_load = __get_font_view_to_load(fontUG, service);
188         setting_retvm_if(NULL == fontUG->view_to_load, NULL, "NULL == fontUG->view_to_load");
189
190         setting_view_node_set_cur_view(fontUG->view_to_load);
191         setting_view_create(fontUG->view_to_load, (void *)fontUG);
192
193         /*  creating a view. */
194         /*setting_view_create(&setting_view_font_main, (void *)fontUG); */
195         evas_object_event_callback_add(fontUG->win_main_layout, EVAS_CALLBACK_RESIZE, setting_font_ug_cb_resize, fontUG);
196         return fontUG->ly_main;
197 }
198
199 static void setting_font_ug_on_start(ui_gadget_h ug, app_control_h service,
200                                      void *priv)
201 {
202 }
203
204 static void setting_font_ug_on_pause(ui_gadget_h ug, app_control_h service,
205                                      void *priv)
206 {
207 }
208
209 static void setting_font_ug_on_resume(ui_gadget_h ug, app_control_h service,
210                                       void *priv)
211 {
212 }
213
214 static void setting_font_ug_on_destroy(ui_gadget_h ug, app_control_h service,
215                                        void *priv)
216 {
217         SETTING_TRACE_BEGIN;
218         setting_retm_if((!priv), "!priv");
219         SettingFontUG *fontUG = priv;
220
221         evas_object_event_callback_del(fontUG->win_main_layout, EVAS_CALLBACK_RESIZE, setting_font_ug_cb_resize);       /* fix flash issue for gallery */
222         fontUG->ug = ug;
223
224         setting_view_destroy(&setting_view_font_font_size, fontUG);
225         setting_view_destroy(&setting_view_font_main, fontUG);
226
227         if (NULL != ug_get_layout(fontUG->ug)) {
228                 evas_object_hide((Evas_Object *) ug_get_layout(fontUG->ug));
229                 evas_object_del((Evas_Object *) ug_get_layout(fontUG->ug));
230         }
231
232         SETTING_TRACE_END;
233 }
234
235 static void setting_font_ug_on_message(ui_gadget_h ug, app_control_h msg,
236                                        app_control_h service, void *priv)
237 {
238         SETTING_TRACE_BEGIN;
239 }
240
241
242 static void setting_font_ug_on_event(ui_gadget_h ug, enum ug_event event,
243                                      app_control_h service, void *priv)
244 {
245         SETTING_TRACE_BEGIN;
246         SettingFontUG *ad = (SettingFontUG *)priv;
247         setting_retm_if(NULL == ad, "ad is NULL");
248         switch (event) {
249                 case UG_EVENT_LOW_MEMORY:
250                         break;
251                 case UG_EVENT_LOW_BATTERY:
252                         break;
253                 case UG_EVENT_LANG_CHANGE:
254                         setting_navi_items_update(ad->navibar);
255                         break;
256                 case UG_EVENT_ROTATE_PORTRAIT:
257                         break;
258                 case UG_EVENT_ROTATE_PORTRAIT_UPSIDEDOWN:
259                         break;
260                 case UG_EVENT_ROTATE_LANDSCAPE:
261                         break;
262                 case UG_EVENT_ROTATE_LANDSCAPE_UPSIDEDOWN:
263                         break;
264                 case UG_EVENT_REGION_CHANGE:
265                         break;
266                 default:
267                         break;
268         }
269 }
270
271 static void setting_font_ug_on_key_event(ui_gadget_h ug,
272                                          enum ug_key_event event, app_control_h service,
273                                          void *priv)
274 {
275         SETTING_TRACE_BEGIN;
276         if (!ug) {
277                 return;
278         }
279
280         switch (event) {
281                 case UG_KEY_EVENT_END:
282                         ug_destroy_me(ug);
283                         break;
284                 default:
285                         break;
286         }
287 }
288
289 UG_MODULE_API int UG_MODULE_INIT(struct ug_module_ops *ops)
290 {
291         SETTING_TRACE_BEGIN;
292         SettingFontUG *fontUG = calloc(1, sizeof(SettingFontUG));
293         setting_retvm_if(!fontUG, -1, "Create SettingFontUG obj failed");
294
295         ops->create = setting_font_ug_on_create;
296         ops->start = setting_font_ug_on_start;
297         ops->pause = setting_font_ug_on_pause;
298         ops->resume = setting_font_ug_on_resume;
299         ops->destroy = setting_font_ug_on_destroy;
300         ops->message = setting_font_ug_on_message;
301         ops->event = setting_font_ug_on_event;
302         ops->key_event = setting_font_ug_on_key_event;
303         ops->priv = fontUG;
304         ops->opt = UG_OPT_INDICATOR_ENABLE;
305
306         memset(fontUG, 0x00, sizeof(SettingFontUG));
307
308         return 0;
309 }
310
311 UG_MODULE_API void UG_MODULE_EXIT(struct ug_module_ops *ops)
312 {
313         SETTING_TRACE_BEGIN;
314         struct SettingFontUG *fontUG;
315         setting_retm_if(!ops, "ops == NULL");
316
317         fontUG = ops->priv;
318         if (fontUG) {
319                 FREE(fontUG);
320         }
321 }
322
323 /* ***************************************************
324  *
325  *general func
326  *
327  ***************************************************/
328
329 static Setting_Cfg_Node_T s_cfg_node_array[] = {
330         {"IDS_ST_BODY_FONT_TYPE", NULL, "viewtype:FontType_expand;tab:first;keyword:IDS_ST_BODY_FONT_TYPE", 0, 0, 0, Cfg_Item_View_Node, NULL, NULL, NULL, NULL},
331         {"IDS_ST_MBODY_FONT_SIZE", NULL, "viewtype:FontSize_expand;tab:first;keyword:IDS_ST_MBODY_FONT_SIZE", 0, 0, 0, Cfg_Item_View_Node, NULL, NULL, NULL, NULL},
332 };
333
334 UG_MODULE_API int setting_plugin_search_init(app_control_h service, void *priv, char **applocale)
335 {
336         SETTING_TRACE_BEGIN;
337         SETTING_TRACE(">> setting-font-efl DB search code");
338         setting_retvm_if(!priv || !applocale, SETTING_GENERAL_ERR_NULL_DATA_PARAMETER, "pplist/applocale is NULL");
339
340         *applocale = strdup("setting:/usr/apps/org.tizen.setting/res/locale");
341
342         Eina_List **pplist = (Eina_List **)priv;
343         int i;
344         int size = sizeof(s_cfg_node_array) / sizeof(s_cfg_node_array[0]);
345         for (i = 0; i < size; i++) {
346                 Setting_Cfg_Node_T *node = setting_plugin_search_item_subindex_add(s_cfg_node_array[i].key_name, s_cfg_node_array[i].ug_args, IMG_Font, s_cfg_node_array[i].item_type,  s_cfg_node_array[i].data, "Font");
347                 *pplist = eina_list_append(*pplist, node);
348         }
349         return 0;
350 }
351