rename setting-test setting-plugin
[apps/home/settings.git] / setting-plugin / src / setting-plugin.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-plugin.h>
23 #include <Ecore_X.h>
24
25 #define SETTING_BRIGHTNESS_LEVEL_FOR_EMUL 24
26
27 #ifndef UG_MODULE_API
28 #define UG_MODULE_API __attribute__ ((visibility("default")))
29 #endif
30
31 static void setting_plugin_ug_cb_resize(void *data, Evas *e, Evas_Object *obj, void *event_info)
32 {
33         SettingPluginUG *ad = (SettingPluginUG *) data;
34         setting_view_update(ad->view_to_load, ad);
35 }
36
37 // draw text
38 static char* _gl_text_handler(void* data, Evas_Object* obj, const char* part)
39 {
40         SETTING_TRACE("%s ", part);
41     if (!safeStrCmp(part, "elm.text") || !safeStrCmp(part, "elm.text.1")) { /* title */
42                 return (char *)g_strdup("elm_text or elm.text.1");
43     } else if (!safeStrCmp(part, "elm.text.2")) {
44                 return (char *)g_strdup("elm.text.2");
45     }
46     return (char *)g_strdup("hello world");
47 }
48
49 // draw contents
50 static Evas_Object* _gl_content_handler(void* data, Evas_Object* obj, const char* part)
51 {
52         SETTING_TRACE("%s ", part);
53         //--------------------
54         // obj --> parent 
55         //--------------------
56
57     if (!safeStrCmp(part, "elm.icon") || !safeStrCmp(part, "elm.icon.1"))
58     {
59                 // left icon
60     }
61     else if (!safeStrCmp(part, "elm.icon.2"))
62     {
63                 // right icon
64     }
65     else if (!safeStrCmp(part, "elm.swallow.end"))
66     {
67                 // radio handler
68     }
69
70         // create an elm_datefield
71         Evas_Object* datetimefield = elm_datetime_add(obj/* parent */);
72     evas_object_size_hint_weight_set(datetimefield, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
73     evas_object_size_hint_align_set(datetimefield, EVAS_HINT_FILL, 0.5);
74     evas_object_show(datetimefield);
75
76         const char* time_format = NULL;
77     if (1)              //12 hours
78     {
79         time_format = "%I : %M %p";
80     } else {    //24 hours
81         time_format = "%H : %M";
82     }
83         elm_datetime_field_visible_set(datetimefield, ELM_DATETIME_AMPM, EINA_TRUE);
84         elm_datetime_format_set(datetimefield, "%d/%b /%y/ %H:%M");
85
86     // min : 1970 1, 01, Thursday 00:00:00
87     struct tm ts_ret;
88     memset(&ts_ret, 0, sizeof(struct tm));
89     ts_ret.tm_year = 138;
90     ts_ret.tm_mon = 1;
91     ts_ret.tm_mday = 19;
92     elm_datetime_value_max_set(datetimefield, &ts_ret);
93
94     // max : 2038 1, 19, Thursday 03:14:07
95     ts_ret.tm_year = 70;
96     ts_ret.tm_mon = 0;
97     ts_ret.tm_mday = 1;
98     elm_datetime_value_min_set(datetimefield, &ts_ret);
99
100
101     time_t ctime = time(NULL);
102     struct tm *ts = localtime_r(&ctime, &ts_ret);
103     retv_if(!ts, NULL);
104
105     elm_datetime_value_set(datetimefield, &ts_ret);
106
107         // set time
108         return datetimefield;
109 }
110
111
112 static void _gl_del_handler(void* data, Evas_Object* obj)
113 {
114
115 }
116
117
118 static void _init_itc(void* data)
119 {
120         SettingPluginUG *pluginUG = (SettingPluginUG *)data;
121
122         //----------------------------------------------------------------
123         // dialogue/separator/21/with_line
124         //----------------------------------------------------------------
125         pluginUG->itc_seperator.item_style = "dialogue/separator";
126         pluginUG->itc_seperator.func.text_get = NULL;
127         pluginUG->itc_seperator.func.content_get = NULL;
128         pluginUG->itc_seperator.func.state_get = NULL;
129         pluginUG->itc_seperator.func.del = NULL;
130
131
132         //----------------------------------------------------------------
133         // dialogue/1icon
134         // add genlist
135         //----------------------------------------------------------------
136         pluginUG->itc_layout.item_style = "dialogue/1icon";
137         pluginUG->itc_layout.func.text_get = _gl_text_handler;
138         pluginUG->itc_layout.func.content_get = _gl_content_handler;
139         pluginUG->itc_layout.func.state_get = NULL;
140         pluginUG->itc_layout.func.del = _gl_del_handler;
141 }
142
143 static void *setting_plugin_ug_on_create(ui_gadget_h ug,
144                                           enum ug_mode mode, service_h service,
145                                           void *priv)
146 {
147         setting_retvm_if((!priv), NULL, "!priv");
148
149         SettingPluginUG *pluginUG = priv;
150         pluginUG->ug = ug;
151         setting_set_i18n(SETTING_PACKAGE, SETTING_LOCALEDIR);
152
153         pluginUG->win_main_layout = (Evas_Object *) ug_get_parent_layout(ug);
154         pluginUG->win_get = (Evas_Object *) ug_get_window();
155         evas_object_show(pluginUG->win_main_layout);
156
157         pluginUG->evas = evas_object_evas_get(pluginUG->win_main_layout);
158
159         setting_retvm_if(pluginUG->win_main_layout == NULL, NULL, "cannot get main window ");
160
161
162         /* register view node table */
163         setting_view_node_table_intialize();
164
165         /*  creating a view. */
166
167         setting_view_node_table_register(&setting_view_test_main, NULL);
168         testUG->view_to_load = &setting_view_test_main;
169         setting_view_node_set_cur_view(testUG->view_to_load);
170         setting_view_create(testUG->view_to_load, (void *)testUG);
171         evas_object_event_callback_add(testUG->win_main_layout, EVAS_CALLBACK_RESIZE, setting_test_ug_cb_resize, testUG);
172
173         // init ITC for Gen-List
174         _init_itc(testUG);
175
176         return pluginUG->ly_main;
177 }
178
179 static void setting_plugin_ug_on_start(ui_gadget_h ug, service_h service,
180                                         void *priv)
181 {
182 }
183
184 static void setting_plugin_ug_on_pause(ui_gadget_h ug, service_h service,
185                                         void *priv)
186 {
187 }
188
189 static void setting_plugin_ug_on_resume(ui_gadget_h ug, service_h service,
190                                          void *priv)
191 {
192 }
193
194 static void setting_plugin_ug_on_destroy(ui_gadget_h ug, service_h service,
195                                           void *priv)
196 {
197         SETTING_TRACE_BEGIN;
198         setting_retm_if((!priv), "!priv");
199         SettingPluginUG *pluginUG = priv;
200
201         /* fix flash issue for gallery */
202         evas_object_event_callback_del(pluginUG->win_main_layout, EVAS_CALLBACK_RESIZE, setting_plugin_ug_cb_resize);
203         pluginUG->ug = ug;
204
205         /*  called when this shared gadget is terminated. similar with app_exit */
206         if (&setting_view_plugin_main == pluginUG->view_to_load) {
207                 setting_view_destroy(&setting_view_plugin_main, pluginUG);
208         }
209
210         if (NULL != ug_get_layout(pluginUG->ug)) {
211                 evas_object_hide((Evas_Object *) ug_get_layout(pluginUG->ug));
212                 evas_object_del((Evas_Object *) ug_get_layout(pluginUG->ug));
213         }
214
215         SETTING_TRACE_END;
216 }
217
218 static void setting_plugin_ug_on_message(ui_gadget_h ug, service_h msg,
219                                           service_h service, void *priv)
220 {
221         SETTING_TRACE_BEGIN;
222 }
223
224 static void setting_plugin_ug_on_event(ui_gadget_h ug,
225                                         enum ug_event event, service_h service,
226                                         void *priv)
227 {
228         SETTING_TRACE_BEGIN;
229         switch (event) {
230         case UG_EVENT_LOW_MEMORY:
231                 break;
232         case UG_EVENT_LOW_BATTERY:
233                 break;
234         case UG_EVENT_LANG_CHANGE:
235                 break;
236         case UG_EVENT_ROTATE_PORTRAIT:
237                 break;
238         case UG_EVENT_ROTATE_PORTRAIT_UPSIDEDOWN:
239                 break;
240         case UG_EVENT_ROTATE_LANDSCAPE:
241                 break;
242         case UG_EVENT_ROTATE_LANDSCAPE_UPSIDEDOWN:
243                 break;
244         case UG_EVENT_REGION_CHANGE:
245                 break;
246         default:
247                 break;
248         }
249 }
250
251 static void setting_plugin_ug_on_key_event(ui_gadget_h ug,
252                                             enum ug_key_event event,
253                                             service_h service, void *priv)
254 {
255         SETTING_TRACE_BEGIN;
256         SettingPluginUG *ad = (SettingPluginUG *) priv;
257
258         switch (event) {
259         case UG_KEY_EVENT_END:
260                 {
261                         if (elm_naviframe_top_item_get(ad->navi_bar) ==
262                            elm_naviframe_bottom_item_get(ad->navi_bar)) {
263                                 ug_destroy_me(ug);
264                         } else {
265                                 setting_view_cb_at_endKey(ad);
266                         }
267                 }
268                 break;
269         default:
270                 break;
271         }
272 }
273
274 UG_MODULE_API int UG_MODULE_INIT(struct ug_module_ops *ops)
275 {
276         SETTING_TRACE_BEGIN;
277         SettingPluginUG *pluginUG = calloc(1, sizeof(SettingPluginUG));
278         setting_retvm_if(!pluginUG, -1, "Create SettingPluginUG obj failed");
279
280         ops->create = setting_plugin_ug_on_create;
281         ops->start = setting_plugin_ug_on_start;
282         ops->pause = setting_plugin_ug_on_pause;
283         ops->resume = setting_plugin_ug_on_resume;
284         ops->destroy = setting_plugin_ug_on_destroy;
285         ops->message = setting_plugin_ug_on_message;
286         ops->event = setting_plugin_ug_on_event;
287         ops->key_event = setting_plugin_ug_on_key_event;
288         ops->priv = pluginUG;
289         ops->opt = UG_OPT_INDICATOR_ENABLE;
290
291         return 0;
292 }
293
294 UG_MODULE_API void UG_MODULE_EXIT(struct ug_module_ops *ops)
295 {
296         SETTING_TRACE_BEGIN;
297         struct SettingPluginUG *pluginUG;
298         setting_retm_if(!ops, "ops == NULL");
299
300         pluginUG = ops->priv;
301         if (pluginUG) {
302                 FREE(pluginUG);
303         }
304 }
305
306 /* ***************************************************
307  *
308  *general func
309  *
310  ***************************************************/
311
312 void setting_plugin_layout_ug_cb(ui_gadget_h ug, enum ug_mode mode,
313                                   void *priv)
314 {
315         SettingPluginUG *ad = (SettingPluginUG *) priv;
316         Evas_Object *base;
317
318         if (!priv)
319                 return;
320         SETTING_TRACE_BEGIN;
321
322         base = (Evas_Object *) ug_get_layout(ug);
323         if (!base)
324                 return;
325
326         switch (mode) {
327         case UG_MODE_FULLVIEW:
328                 evas_object_size_hint_weight_set(base, EVAS_HINT_EXPAND,
329                                                  EVAS_HINT_EXPAND);
330                 //elm_win_resize_object_add(ad->win_get, base);
331                 evas_object_show(base);
332                 break;
333         default:
334                 break;
335         }
336
337         SETTING_TRACE_END;
338 }
339
340 /*****/
341 UG_MODULE_API int setting_plugin_reset(service_h service, void *priv)
342 {
343         SETTING_TRACE_BEGIN;
344         return 0;
345 }
346
347 /*****/