tizen 2.4 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                 FREE(viewtype);
68                 return &setting_view_font_main;
69         }
70 }
71
72 /*------------------------------------------------------------- */
73 /* http://tizen.org/appcontrol/operation/configure/font/type */
74 /* http://tizen.org/appcontrol/operation/configure/font/size */
75 /*------------------------------------------------------------- */
76 setting_view *__app_control_get_operation_handler(void *data, app_control_h service)
77 {
78         SETTING_TRACE_BEGIN;
79         setting_retvm_if((!data), NULL, "data is NULL");
80         setting_retvm_if((!service), NULL, "service is NULL");
81         SettingFontUG *fontUG = (SettingFontUG *)data;
82         char *output_url = NULL;
83
84         int ret = app_control_get_operation(service, &output_url);
85
86         if (ret == APP_CONTROL_ERROR_NONE) {
87                 /*SETTING_TRACE(" >>>>>>>>>>>>>>>>>>> (%s) ", output_url); */
88                 if (0 == safeStrCmp(output_url, "http://tizen.org/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                         fontUG->viewmode = FONT_SIZE_VIEW_APPCONTROL;
97                         setting_view_node_table_register(&setting_view_font_font_size, NULL);
98
99                         FREE(output_url);
100                         return &setting_view_font_font_size;
101                 } else {
102                         SETTING_TRACE("No URL, default action - argument parsing");
103                         FREE(output_url);
104                         return __default_view_state(fontUG, service);
105                 }
106         } else {
107                 SETTING_TRACE("failed to call app_control_get_operation with error code %d", ret);
108                 if (output_url) {
109                         FREE(output_url);
110                 }
111                 return NULL;
112         }
113 }
114
115 setting_view *__get_font_view_to_load(void *data, app_control_h service)
116 {
117         SETTING_TRACE_BEGIN;
118         setting_retvm_if((!data), NULL, "data is NULL");
119         SettingFontUG *fontUG = (SettingFontUG *)data;
120
121         /*if ug is called by accessibility, view node table should not be initialized */
122         char *caller = NULL;
123         app_control_get_extra_data(service, "caller", &caller);
124         if (0 != safeStrCmp(caller, "accessibility")) {
125                 /*need to initialize the node table when UG is re-created and it is NOT loaded by another UG*/
126                 setting_view_node_table_intialize();
127         }
128         FREE(caller);
129
130         /* if argument is there, process it first */
131         char *output_url = NULL;
132         int ret = app_control_get_operation(service, &output_url);
133
134         /* service OK, but there's no argument */
135         if ((ret == APP_CONTROL_ERROR_NONE)
136             && (0 == safeStrCmp(output_url, "http://tizen.org/appcontrol/operation/default"))) {
137                 FREE(output_url);
138                 return __default_view_state(fontUG, service);
139
140         } else if (ret == APP_CONTROL_ERROR_NONE) {
141                 FREE(output_url);
142                 return __app_control_get_operation_handler(fontUG, service);
143
144         } else {
145                 if (output_url) {
146                         FREE(output_url);
147                 }
148                 /* service is not OK, but need to handle default action */
149                 return __default_view_state(fontUG, service);
150         }
151 }
152
153 static void setting_font_ug_cb_resize(void *data, Evas *e, Evas_Object *obj,
154                                       void *event_info)
155 {
156         SettingFontUG *ad = (SettingFontUG *) data;
157         setting_view_update(&setting_view_font_main, ad);
158 }
159
160 static void *setting_font_ug_on_create(ui_gadget_h ug, enum ug_mode mode,
161                                        app_control_h service, void *priv)
162 {
163         setting_retvm_if((!priv), NULL, "!priv");
164         SettingFontUG *fontUG = priv;
165
166         setting_set_i18n(SETTING_PACKAGE, SETTING_LOCALEDIR);
167
168         fontUG->ug = ug;
169         fontUG->win_main_layout = (Evas_Object *) ug_get_parent_layout(ug);
170         fontUG->win_get = (Evas_Object *) ug_get_window();
171         evas_object_show(fontUG->win_main_layout);
172         fontUG->evas = evas_object_evas_get(fontUG->win_main_layout);
173
174         setting_retvm_if(fontUG->win_main_layout == NULL, NULL,
175                          "cannot get main window ");
176
177         setting_create_Gendial_itc(SETTING_GENLIST_2LINE_STYLE, &(fontUG->itc_2text_3_parent));
178         setting_create_Gendial_itc(SETTING_GENLIST_2LINE_STYLE, &(fontUG->itc_1icon_1text_sub));
179         /*setting_create_Gendial_itc("dialogue/2text.3", &(fontUG->itc_2text_2)); */
180         setting_create_Gendial_itc(SETTING_GENLIST_2LINE_STYLE, &(fontUG->itc_2text_2));
181         setting_create_Gendial_itc(SETTING_GENLIST_GROUP_INDEX_STYLE, &(fontUG->itc_group_item));
182         setting_create_Gendial_itc("1icon", &(fontUG->itc_1icon));
183
184         /* view type checking */
185         fontUG->view_to_load = __get_font_view_to_load(fontUG, service);
186         setting_retvm_if(NULL == fontUG->view_to_load, NULL, "NULL == fontUG->view_to_load");
187
188         setting_view_node_set_cur_view(fontUG->view_to_load);
189         setting_view_create(fontUG->view_to_load, (void *)fontUG);
190
191         elm_theme_extension_add(NULL, SETTING_5STEP_SLIDER_EDJ_NAME);
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 /**
330 * Reset function to 'reset' the settings of the UG, it will be invoked by 'Reset' UG
331 */
332 UG_MODULE_API int setting_plugin_reset(app_control_h service, void *priv)
333 {
334         SETTING_TRACE_BEGIN;
335         int ret = 0;
336
337         /* reset font type, default is HelveticaNeue */
338         /*font_config_set("HelveticaNeue"); */
339         char *default_font_name = NULL;
340         default_font_name = _get_default_font();
341         if (NULL != default_font_name) {
342                 ret += system_settings_set_value_string(SYSTEM_SETTINGS_KEY_FONT_TYPE, default_font_name);
343         } else {
344                 SETTING_TRACE_ERROR("Failed to get default font type");
345         }
346         ret += vconf_set_int(VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_SIZE, SYSTEM_SETTINGS_FONT_SIZE_NORMAL);
347         setting_retvm_if(ret == -1, ret, "Failed to set vconf");
348         font_size_set();
349
350         return ret;
351 }
352 static Setting_Cfg_Node_T s_cfg_node_array[] = {
353         {"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},
354         {"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},
355 };
356
357 UG_MODULE_API int setting_plugin_search_init(app_control_h service, void *priv, char **applocale)
358 {
359         SETTING_TRACE_BEGIN;
360         SETTING_TRACE(">> setting-font-efl DB search code");
361         setting_retvm_if(!priv || !applocale, SETTING_GENERAL_ERR_NULL_DATA_PARAMETER, "pplist/applocale is NULL");
362
363         *applocale = strdup("setting:/usr/apps/org.tizen.setting/res/locale");
364
365         Eina_List **pplist = (Eina_List **)priv;
366         int i;
367         int size = sizeof(s_cfg_node_array) / sizeof(s_cfg_node_array[0]);
368         for (i = 0; i < size; i++) {
369                 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");
370                 *pplist = eina_list_append(*pplist, node);
371         }
372         return 0;
373 }
374