Merge "packaging: spec cleanup" into tizen
[apps/core/preloaded/settings.git] / setting-font / src / setting-font.c
1 /*
2  * setting
3  * Copyright (c) 2012 Samsung Electronics Co., Ltd.
4  *
5  * Licensed under the Flora License, Version 1.1 (the License);
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  *     http://floralicense.org/license/
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an AS IS BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17 #include <setting-font.h>
18 #include <system_settings.h>
19 #ifndef UG_MODULE_API
20 #define UG_MODULE_API __attribute__ ((visibility("default")))
21 #endif
22
23 setting_view *__get_font_view_to_load(void *data,service_h service)
24 {
25         SETTING_TRACE_BEGIN;
26         setting_retvm_if((!data), NULL, "data is NULL");
27         SettingFontUG *fontUG = (SettingFontUG *)data;
28
29         setting_view_node_table_intialize();
30
31         char *category = NULL;
32         service_get_extra_data(service, "category", &category);
33
34         if (0 == safeStrCmp(category, "FontType")) {
35                 SETTING_TRACE("LAUNCHED BY APP-CONTROL MODE");
36                 fontUG->viewmode = FONT_SEL_VIEW_APPCONTROL;
37                 // here
38                 setting_view_node_table_register(&setting_view_font_font_size, &setting_view_font_main);
39                 setting_view_node_table_register(&setting_view_font_main, NULL);
40                 return &setting_view_font_main;
41         } else if (0 == safeStrCmp(category, "FontSize")) {
42                 SETTING_TRACE("category = %s", category);
43                 fontUG->viewmode = FONT_SIZE_VIEW_APPCONTROL;
44                 setting_view_node_table_register(&setting_view_font_font_size, NULL);
45                 return &setting_view_font_font_size;
46         }else {
47                 SETTING_TRACE("HERE ?? <<<<< ");
48                 fontUG->viewmode = FONT_SIZE_AND_FONT_SEL_UG;   // set default
49                 setting_view_node_table_register(&setting_view_font_font_size, &setting_view_font_main);
50                 setting_view_node_table_register(&setting_view_font_main, NULL);
51                 return &setting_view_font_main;
52         }
53 }
54
55 static void setting_font_ug_cb_resize(void *data, Evas *e, Evas_Object *obj,
56                                       void *event_info)
57 {
58         SettingFontUG *ad = (SettingFontUG *) data;
59         setting_view_update(&setting_view_font_main, ad);
60 }
61
62 static void *setting_font_ug_on_create(ui_gadget_h ug, enum ug_mode mode,
63                                        service_h service, void *priv)
64 {
65         setting_retvm_if((!priv), NULL, "!priv");
66         SettingFontUG *fontUG = priv;
67
68         setting_set_i18n(SETTING_PACKAGE, SETTING_LOCALEDIR);
69
70         fontUG->ug = ug;
71         fontUG->win_main_layout = (Evas_Object *) ug_get_parent_layout(ug);
72         fontUG->win_get = (Evas_Object *) ug_get_window();
73         evas_object_show(fontUG->win_main_layout);
74         fontUG->evas = evas_object_evas_get(fontUG->win_main_layout);
75
76         setting_retvm_if(fontUG->win_main_layout == NULL, NULL,
77                          "cannot get main window ");
78
79         fontUG->itc_seperator.item_style = "dialogue/separator";
80         fontUG->itc_seperator.func.text_get = NULL;
81         fontUG->itc_seperator.func.content_get = NULL;
82         fontUG->itc_seperator.func.state_get = NULL;
83         fontUG->itc_seperator.func.del = NULL;
84
85         setting_create_Gendial_itc("dialogue/2text.3/expandable", &(fontUG->itc_2text_3_parent));
86         setting_create_Gendial_itc("dialogue/1text.1icon/expandable2", &(fontUG->itc_1icon_1text_sub));
87         setting_create_Gendial_itc("dialogue/2text.3", &(fontUG->itc_2text_2));
88         setting_create_Gendial_itc("dialogue/1text.1icon.3.tb", &(fontUG->itc_1text_1icon_2));
89         setting_create_Gendial_itc("dialogue/title", &(fontUG->itc_group_item));
90         setting_create_Gendial_itc("multiline/1text", &(fontUG->itc_bg_1icon));
91
92         // view type checking
93         fontUG->view_to_load = __get_font_view_to_load(fontUG, service);
94         setting_retvm_if(NULL == fontUG->view_to_load, NULL, "NULL == fontUG->view_to_load");
95
96         setting_view_node_set_cur_view(fontUG->view_to_load);
97         setting_view_create(fontUG->view_to_load, (void *)fontUG);
98
99         /*  creating a view. */
100         //setting_view_create(&setting_view_font_main, (void *)fontUG);
101         evas_object_event_callback_add(fontUG->win_main_layout, EVAS_CALLBACK_RESIZE, setting_font_ug_cb_resize, fontUG);
102         return fontUG->ly_main;
103 }
104
105 static void setting_font_ug_on_start(ui_gadget_h ug, service_h service,
106                                      void *priv)
107 {
108 }
109
110 static void setting_font_ug_on_pause(ui_gadget_h ug, service_h service,
111                                      void *priv)
112 {
113 }
114
115 static void setting_font_ug_on_resume(ui_gadget_h ug, service_h service,
116                                       void *priv)
117 {
118 }
119
120 static void setting_font_ug_on_destroy(ui_gadget_h ug, service_h service,
121                                        void *priv)
122 {
123         SETTING_TRACE_BEGIN;
124         setting_retm_if((!priv), "!priv");
125         SettingFontUG *fontUG = priv;
126
127         evas_object_event_callback_del(fontUG->win_main_layout, EVAS_CALLBACK_RESIZE, setting_font_ug_cb_resize);       /* fix flash issue for gallery */
128         fontUG->ug = ug;
129
130 #if 0
131         /*  delete the allocated objects. */
132         if (fontUG->view_to_load == &setting_view_font_font_size) {
133                 setting_view_destroy(&setting_view_font_font_size, fontUG);
134         } else {
135                 setting_view_destroy(&setting_view_font_font_size, fontUG);
136                 setting_view_destroy(&setting_view_font_main, fontUG);
137         }
138 #else
139         setting_view_destroy(&setting_view_font_font_size, fontUG);
140         setting_view_destroy(&setting_view_font_main, fontUG);
141 #endif
142
143         if (NULL != ug_get_layout(fontUG->ug)) {
144                 evas_object_hide((Evas_Object *) ug_get_layout(fontUG->ug));
145                 evas_object_del((Evas_Object *) ug_get_layout(fontUG->ug));
146         }
147
148         SETTING_TRACE_END;
149 }
150
151 static void setting_font_ug_on_message(ui_gadget_h ug, service_h msg,
152                                        service_h service, void *priv)
153 {
154         SETTING_TRACE_BEGIN;
155 }
156
157 static void setting_font_ug_on_event(ui_gadget_h ug, enum ug_event event,
158                                      service_h service, void *priv)
159 {
160         SETTING_TRACE_BEGIN;
161         switch (event) {
162         case UG_EVENT_LOW_MEMORY:
163                 break;
164         case UG_EVENT_LOW_BATTERY:
165                 break;
166         case UG_EVENT_LANG_CHANGE:
167                 break;
168         case UG_EVENT_ROTATE_PORTRAIT:
169                 break;
170         case UG_EVENT_ROTATE_PORTRAIT_UPSIDEDOWN:
171                 break;
172         case UG_EVENT_ROTATE_LANDSCAPE:
173                 break;
174         case UG_EVENT_ROTATE_LANDSCAPE_UPSIDEDOWN:
175                 break;
176         case UG_EVENT_REGION_CHANGE:
177                 break;
178         default:
179                 break;
180         }
181 }
182
183 static void setting_font_ug_on_key_event(ui_gadget_h ug,
184                                          enum ug_key_event event, service_h service,
185                                          void *priv)
186 {
187         SETTING_TRACE_BEGIN;
188         if (!ug)
189                 return;
190
191         switch (event) {
192         case UG_KEY_EVENT_END:
193                 ug_destroy_me(ug);
194                 break;
195         default:
196                 break;
197         }
198 }
199
200 UG_MODULE_API int UG_MODULE_INIT(struct ug_module_ops *ops)
201 {
202         SETTING_TRACE_BEGIN;
203         SettingFontUG *fontUG = calloc(1, sizeof(SettingFontUG));
204         setting_retvm_if(!fontUG, -1, "Create SettingFontUG obj failed");
205
206         ops->create = setting_font_ug_on_create;
207         ops->start = setting_font_ug_on_start;
208         ops->pause = setting_font_ug_on_pause;
209         ops->resume = setting_font_ug_on_resume;
210         ops->destroy = setting_font_ug_on_destroy;
211         ops->message = setting_font_ug_on_message;
212         ops->event = setting_font_ug_on_event;
213         ops->key_event = setting_font_ug_on_key_event;
214         ops->priv = fontUG;
215         ops->opt = UG_OPT_INDICATOR_ENABLE;
216
217         return 0;
218 }
219
220 UG_MODULE_API void UG_MODULE_EXIT(struct ug_module_ops *ops)
221 {
222         SETTING_TRACE_BEGIN;
223         struct SettingFontUG *fontUG;
224         setting_retm_if(!ops, "ops == NULL");
225
226         fontUG = ops->priv;
227         if (fontUG) {
228                 FREE(fontUG);
229         }
230 }
231
232 /* ***************************************************
233  *
234  *general func
235  *
236  ***************************************************/
237
238 int setting_font_update_vconf_key_int_type(void *data,
239                                            setting_int_slp_list slp_key)
240 {
241         SETTING_TRACE_BEGIN;
242         /* error check */
243         if (data == NULL) {
244                 return SETTING_GENERAL_ERR_NULL_DATA_PARAMETER;
245         }
246
247         int ret = SETTING_RETURN_FAIL;
248         int value;
249         int err;
250         /* SettingFontUG *ad = (SettingFontUG *)data; */
251
252         ret = setting_get_int_slp_key(slp_key, &value, &err);
253
254         switch (slp_key) {
255                 /*
256                    case INT_SLP_SETTING_LCD_TIMEOUT_NORMAL:
257                    {
258                    if (ret == SETTING_RETURN_FAIL) value = SETTING_BACKLIGHT_TIME_15SEC;
259
260                    switch(value)
261                    {
262                    case SETTING_BACKLIGHT_TIME_8SEC:    edje_object_part_text_set(_EDJ(ad->eo_DC_backlight), DC_ITEM_SUB_STR_BACKLIGHT, _(STR_SETTING_8SEC)); break;
263                    case SETTING_BACKLIGHT_TIME_15SEC: edje_object_part_text_set(_EDJ(ad->eo_DC_backlight), DC_ITEM_SUB_STR_BACKLIGHT, _(STR_SETTING_15SEC)); break;
264                    case SETTING_BACKLIGHT_TIME_30SEC: edje_object_part_text_set(_EDJ(ad->eo_DC_backlight), DC_ITEM_SUB_STR_BACKLIGHT, _(STR_SETTING_30SEC)); break;
265                    case SETTING_BACKLIGHT_TIME_1MIN: edje_object_part_text_set(_EDJ(ad->eo_DC_backlight), DC_ITEM_SUB_STR_BACKLIGHT, _(STR_SETTING_1MIN)); break;
266                    case SETTING_BACKLIGHT_TIME_3MIN: edje_object_part_text_set(_EDJ(ad->eo_DC_backlight), DC_ITEM_SUB_STR_BACKLIGHT, _(STR_SETTING_3MIN)); break;
267                    case SETTING_BACKLIGHT_TIME_10MIN: edje_object_part_text_set(_EDJ(ad->eo_DC_backlight), DC_ITEM_SUB_STR_BACKLIGHT, _(STR_SETTING_10MIN)); break;
268                    default: ret = SETTING_GENERAL_ERR_NOT_FIND_VALUE_SWITCH;
269                    }
270                    }
271                    break;
272                  */
273
274         default:
275                 ret = SETTING_GENERAL_ERR_NOT_FIND_VALUE_SWITCH;
276                 break;
277         }
278
279         return ret;
280 }
281
282 int setting_font_update_vconf_key(void *data, setting_vconf_type type,
283                                   int slp_key)
284 {
285         SETTING_TRACE_BEGIN;
286         /* error check */
287         if (data == NULL) {
288                 return SETTING_GENERAL_ERR_NULL_DATA_PARAMETER;
289         }
290
291         int ret = SETTING_RETURN_FAIL;
292         SettingFontUG *ad = (SettingFontUG *) data;
293
294         switch (type) {
295         case SETTING_VCONF_INT_TYPE:
296                 ret = setting_font_update_vconf_key_int_type(ad, slp_key);
297                 break;
298
299         case SETTING_VCONF_BOOL_TYPE:
300                 break;
301
302         case SETTING_VCONF_STR_TYPE:
303                 break;
304         default:
305                 /* do nothing */
306                 break;
307         }
308
309         return ret;
310 }
311 /**
312 * Reset function to 'reset' the settings of the UG, it will be invoked by 'Reset' UG
313 */
314 UG_MODULE_API int setting_plugin_reset(service_h service, void *priv)
315 {
316         SETTING_TRACE_BEGIN;
317         int ret = 0;
318         int value = SYSTEM_SETTINGS_FONT_SIZE_NORMAL;
319         vconf_get_int(VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_SIZE, &value);
320         if (value != SYSTEM_SETTINGS_FONT_SIZE_NORMAL)
321         {
322                 /* reset font type, default is HelveticaNeue */
323                 font_config_set("HelveticaNeue");
324                 ret += vconf_set_int(VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_SIZE, SYSTEM_SETTINGS_FONT_SIZE_NORMAL);
325                 setting_retvm_if(ret == -1, ret, "Failed to set vconf");
326                 font_size_set();
327         }
328         return ret;
329 }
330