tizen 2.4 release
[apps/home/settings.git] / setting-time / src / setting-time.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-time.h>
23 #include <setting-cfg.h>
24 #include <unicode/uloc.h>
25
26 #ifndef UG_MODULE_API
27 #define UG_MODULE_API __attribute__ ((visibility("default")))
28 #endif
29
30 /**
31 * @callback handler for EVAS_CALLBACK_RESIZE
32 *
33 * @param data user data (SettingTimeUG *)
34 */
35 static void setting_time_ug_cb_resize(void *data, Evas *e, Evas_Object *obj,
36                                       void *event_info)
37 {
38         SETTING_TRACE_BEGIN;
39         SettingTimeUG *ad = (SettingTimeUG *) data;
40         setting_view_update(&setting_view_time_main, ad);
41 }
42
43 /**
44 * @callback function called first while loading setting-time UG.
45 *
46 * @param ug ug object itself.
47 * @param mode
48 * @param data bundle (key, value pair) data as arguments into UG.
49 * @param priv SettingTimeUG context
50 *
51 * @return
52 */
53 static void *setting_time_ug_on_create(ui_gadget_h ug, enum ug_mode mode,
54                                        app_control_h service, void *priv)
55 {
56         SETTING_TRACE_BEGIN;
57         setting_retvm_if((!priv), NULL, "!priv");
58
59         SettingTimeUG *timeUG = priv;
60         timeUG->ug = ug;
61         timeUG->bundle_data = service;
62         timeUG->win_main_layout = (Evas_Object *) ug_get_parent_layout(ug);
63         timeUG->win_get = (Evas_Object *) ug_get_window();
64         evas_object_show(timeUG->win_main_layout);
65         timeUG->evas = evas_object_evas_get(timeUG->win_main_layout);
66
67         timeUG->pop_progress = NULL;
68         /*  Initialize Caller value */
69         timeUG->caller = NULL;
70
71         setting_retvm_if(timeUG->win_main_layout == NULL, NULL, "cannot get main window ");
72
73         /* set launguage */
74         setting_set_i18n(SETTING_PACKAGE, SETTING_LOCALEDIR);
75
76         /* register view node table */
77         setting_view_node_table_intialize();
78         setting_view_node_table_register(&setting_view_time_main, NULL);
79
80         setting_create_Gendial_itc(SETTING_GENLIST_ICON_1LINE_STYLE, &(timeUG->itc_1text_1icon));
81         setting_create_Gendial_itc("entry.main", &(timeUG->itc_layout));
82         setting_create_Gendial_itc(SETTING_GENLIST_2LINE_STYLE, &(timeUG->itc_2text_2));
83         setting_create_Gendial_itc(SETTING_GENLIST_2LINE_STYLE, &(timeUG->itc_2text_3_parent));
84         setting_create_Gendial_itc(SETTING_GENLIST_2LINE_STYLE, &(timeUG->itc_1icon_1text_sub));
85
86         timeUG->is_expand_time_format_list = 0;
87
88         char *viewtype = NULL;
89         app_control_get_extra_data(service, "viewtype", &viewtype);
90         if (!safeStrCmp(viewtype, "format_expand")) {
91                 timeUG->is_expand_time_format_list = 1;
92         }
93
94         /*  creating a view. */
95         setting_view_node_set_cur_view(&setting_view_time_main);
96         setting_view_create(&setting_view_time_main, (void *)timeUG);
97         evas_object_event_callback_add(timeUG->win_main_layout,
98                                        EVAS_CALLBACK_RESIZE,
99                                        setting_time_ug_cb_resize, timeUG);
100         return timeUG->ly_main;
101 }
102
103 static void setting_time_ug_on_start(ui_gadget_h ug, app_control_h service,
104                                      void *priv)
105 {
106         SETTING_TRACE_BEGIN;
107         /*  do nothing */
108 }
109
110 static void setting_time_ug_on_pause(ui_gadget_h ug, app_control_h service,
111                                      void *priv)
112 {
113         SETTING_TRACE_BEGIN;
114         /*  do nothing */
115 }
116
117 static void setting_time_ug_on_resume(ui_gadget_h ug, app_control_h service,
118                                       void *priv)
119 {
120         /*  do nothing */
121 }
122
123 static void setting_time_ug_on_destroy(ui_gadget_h ug, app_control_h service,
124                                        void *priv)
125 {
126         SETTING_TRACE_BEGIN;
127         setting_retm_if((!priv), "!priv");
128         SettingTimeUG *timeUG = priv;
129
130         evas_object_event_callback_del(timeUG->win_main_layout, EVAS_CALLBACK_RESIZE, setting_time_ug_cb_resize);       /* fix flash issue for gallery */
131         timeUG->ug = ug;
132
133         /*  delete the allocated objects. */
134         setting_view_destroy(&setting_view_time_main, timeUG);
135
136         if (NULL != ug_get_layout(timeUG->ug)) {
137                 evas_object_hide((Evas_Object *) ug_get_layout(timeUG->ug));
138                 evas_object_del((Evas_Object *) ug_get_layout(timeUG->ug));
139         }
140
141         SETTING_TRACE_END;
142 }
143
144 static void setting_time_ug_on_message(ui_gadget_h ug, app_control_h msg,
145                                        app_control_h service, void *priv)
146 {
147         SETTING_TRACE_BEGIN;
148 }
149
150 static void setting_time_ug_on_event(ui_gadget_h ug, enum ug_event event,
151                                      app_control_h service, void *priv)
152 {
153         SETTING_TRACE_BEGIN;
154         SettingTimeUG *ad = (SettingTimeUG *) priv;
155
156         switch (event) {
157                 case UG_EVENT_LOW_MEMORY:
158                         break;
159                 case UG_EVENT_LOW_BATTERY:
160                         break;
161                 case UG_EVENT_LANG_CHANGE: {
162                                 const char *pa_lang = vconf_get_str(VCONFKEY_LANGSET);
163                                 if (pa_lang) {
164                                         char *q = strchr(pa_lang, '.');
165                                         if (q) {
166                                                 *q = '\0';
167                                         }
168                                 }
169                                 int err = -1;
170
171                                 uloc_setDefault(pa_lang, &err);
172                                 FREE(pa_lang);
173                                 setting_view_update(&setting_view_time_main, ad);
174                         }
175                         break;
176                 case UG_EVENT_ROTATE_PORTRAIT:
177                         break;
178                 case UG_EVENT_ROTATE_PORTRAIT_UPSIDEDOWN:
179                         break;
180                 case UG_EVENT_ROTATE_LANDSCAPE:
181                         break;
182                 case UG_EVENT_ROTATE_LANDSCAPE_UPSIDEDOWN:
183                         break;
184                 case UG_EVENT_REGION_CHANGE:
185                         break;
186                 default:
187                         break;
188         }
189 }
190
191 /**
192 * @brief key event handler for UG
193 */
194 static void setting_time_ug_on_key_event(ui_gadget_h ug,
195                                          enum ug_key_event event, app_control_h service,
196                                          void *priv)
197 {
198         SETTING_TRACE_BEGIN;
199         SettingTimeUG *ad = (SettingTimeUG *) priv;
200
201         switch (event) {
202                 case UG_KEY_EVENT_END: {
203 #if 0
204                                 if (0 == safeStrCmp(ad->caller, "pwlock")) {
205                                         /*  Create Bundle and send message */
206
207                                         app_control_h svc;
208                                         if (app_control_create(&svc))
209                                                 return;
210
211                                         app_control_add_extra_data(svc, "result", "lbutton_click");
212                                         ug_send_result(ad->ug, svc);
213
214                                         app_control_destroy(svc);
215                                 }
216 #endif
217
218                                 if (elm_naviframe_top_item_get(ad->navi_bar) ==
219                                     elm_naviframe_bottom_item_get(ad->navi_bar)) {
220                                         ug_destroy_me(ug);
221                                 } else {
222                                         /* elm_naviframe_item_pop(ad->navi_bar); */
223                                         setting_view_cb_at_endKey(ad);
224                                 }
225                         }
226                         break;
227                 default:
228                         break;
229         }
230 }
231
232 /**
233 * @brief UG entry point - create the SettingTimeUG context
234 * @return 0
235 */
236 UG_MODULE_API int UG_MODULE_INIT(struct ug_module_ops *ops)
237 {
238         SETTING_TRACE_BEGIN;
239         SettingTimeUG *timeUG = calloc(1, sizeof(SettingTimeUG));
240         setting_retvm_if(!timeUG, -1, "Create SettingTimeUG obj failed");
241
242         ops->create = setting_time_ug_on_create;
243         ops->start = setting_time_ug_on_start;
244         ops->pause = setting_time_ug_on_pause;
245         ops->resume = setting_time_ug_on_resume;
246         ops->destroy = setting_time_ug_on_destroy;
247         ops->message = setting_time_ug_on_message;
248         ops->event = setting_time_ug_on_event;
249         ops->key_event = setting_time_ug_on_key_event;
250         ops->priv = timeUG;
251         ops->opt = UG_OPT_INDICATOR_ENABLE;
252
253         return 0;
254 }
255
256 /**
257 * @brief UG finalizer - destroy the SettingTimeUG context
258 */
259 UG_MODULE_API void UG_MODULE_EXIT(struct ug_module_ops *ops)
260 {
261         SETTING_TRACE_BEGIN;
262         struct SettingTimeUG *timeUG;
263         setting_retm_if(!ops, "ops == NULL");
264
265         timeUG = ops->priv;
266         if (timeUG)
267                 FREE(timeUG);
268 }
269
270 UG_MODULE_API int setting_plugin_search_init(app_control_h service, void *priv,
271                                              char **applocale)
272 {
273         int i, size;
274         Setting_Cfg_Node_T *node;
275         Eina_List **pplist = priv;
276
277         const Setting_Cfg_Node_T search_configs[] = {
278                 {DATE_TIME_STR_AUTOMATIC_UPDATE, NULL, NULL, 0, Cfg_Item_unResetable, 0, Cfg_Item_View_Node, NULL, DATE_TIME_STR_DATE_AND_TIME, NULL, NULL },
279                 {DATE_TIME_STR_TIME_ZONE, NULL, NULL, 0, Cfg_Item_unResetable, 0, Cfg_Item_View_Node, NULL,  DATE_TIME_STR_DATE_AND_TIME, NULL, NULL },
280
281                 /* Duplicated title name : 'Date and time' with UG name : 'Date and time' */
282                 {DATE_TIME_STR_DATE_AND_TIME, NULL, NULL,  0, Cfg_Item_unResetable, 0,          Cfg_Item_View_Node, NULL,  DATE_TIME_STR_DATE_AND_TIME, NULL, NULL },
283                 {DATE_TIME_STR_TIME_FORMAT, NULL, "viewtype:format_expand", 0, Cfg_Item_unResetable, 0, Cfg_Item_View_Node, NULL,  DATE_TIME_STR_DATE_AND_TIME, NULL, NULL }
284         };
285
286         retv_if(NULL == priv, SETTING_GENERAL_ERR_NULL_DATA_PARAMETER);
287         retv_if(NULL == applocale, SETTING_GENERAL_ERR_NULL_DATA_PARAMETER);
288
289         *applocale = strdup("setting:/usr/apps/org.tizen.setting/res/locale");
290
291         size = sizeof(search_configs) / sizeof(Setting_Cfg_Node_T);
292
293         for (i = 0; i < size; i++) {
294                 node = setting_plugin_search_item_subindex_add(
295                            search_configs[i].key_name,
296                            search_configs[i].ug_args,
297                            IMG_DateTime,
298                            search_configs[i].item_type,
299                            search_configs[i].data,
300                            search_configs[i].sub_index);
301
302                 *pplist = eina_list_append(*pplist, node);
303         }
304         return 0;
305 }