4 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd.
6 * Contact: MyoungJune Park <mj2004.park@samsung.com>
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
12 * http://www.apache.org/licenses/LICENSE-2.0
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.
21 #include <setting-debug.h>
23 #include <ui-gadget.h>
24 #include <Elementary.h>
26 #include <appcore-efl.h>
27 #include <appcore-common.h>
32 #include <efl_assist.h>
33 #include <setting-common-general-func.h>
35 #define EXPORT_PUBLIC __attribute__((visibility("default")))
38 typedef struct _support_help_appdata {
43 Evas_Object *win_main;
44 Evas_Object *navibar_main;
45 Evas_Object *ly_main; /**< seting view main */
46 app_control_h service;
47 Ecore_Event_Handler *event_handler;
48 } support_help_appdata;
51 * The function is called when Setting is terminated
53 static void support_help_app_terminate(void *data)
56 support_help_appdata *ad = data;
58 SETTING_TRACE("support_help_terminate!");
60 if (ad->event_handler) {
61 ecore_event_handler_del(ad->event_handler);
62 ad->event_handler = NULL;
66 evas_object_del(ad->ly_main);
71 evas_object_del(ad->win_main);
80 * The event process when win object is destroyed
82 static void support_help_del_win(void *data, Evas_Object *obj, void *event)
89 * To create a win object, the win is shared between the App and all its UGs
91 static Evas_Object *support_help_create_win(const char *name)
97 eo = elm_win_add(NULL, name, ELM_WIN_BASIC);
100 elm_win_title_set(eo, name);
101 elm_win_borderless_set(eo, EINA_TRUE);
102 evas_object_smart_callback_add(eo, "delete,request",
103 support_help_del_win, NULL);
105 ecore_x_window_size_get(ecore_x_window_root_first_get(),
107 evas_object_resize(eo, w, h);
114 static Eina_Bool __key_press_cb(void *data, int type, void *event)
117 Evas_Event_Key_Down *ev = event;
119 return ECORE_CALLBACK_RENEW;
122 support_help_appdata *ad = data;
125 if (strcmp(ev->keyname, KEY_HOME) == 0) {
126 setting_ug_destroy(ad->ug);
129 return ECORE_CALLBACK_RENEW;
133 * The function is called to create Setting view widgets
135 static bool support_help_app_create(void *data)
139 support_help_appdata *ad = data;
141 SETTING_TRACE("[TIME] 3. it taked %d msec from main to setting_help_app_create ", appcore_measure_time());
142 appcore_measure_start();
145 ad->win_main = support_help_create_win("org.tizen.setting.helpringtone");
146 if (ad->win_main == NULL) {
147 SETTING_TRACE("Can't create window");
151 if (elm_win_wm_rotation_supported_get(ad->win_main)) {
152 int rots[4] = { 0, 90, 180, 270 };
153 elm_win_wm_rotation_available_rotations_set(ad->win_main, rots, 4);
156 UG_INIT_EFL(ad->win_main, UG_OPT_INDICATOR_ENABLE);
157 ad->evas = evas_object_evas_get(ad->win_main);
159 elm_win_indicator_mode_set(ad->win_main, ELM_WIN_INDICATOR_SHOW);
160 elm_win_indicator_opacity_set(ad->win_main, ELM_WIN_INDICATOR_OPAQUE);
163 Evas_Object *conform = elm_conformant_add(ad->win_main);
164 ad->ly_main = elm_layout_add(ad->win_main);
165 evas_object_size_hint_weight_set(ad->ly_main, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
166 elm_layout_theme_set(ad->ly_main, "layout", "application", "default");
169 Evas_Object *bg = elm_bg_add(ad->ly_main);
170 elm_object_style_set(bg, "group_list");
171 evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
172 elm_object_part_content_set(ad->ly_main, "elm.swallow.bg", bg);
173 evas_object_show(bg);
176 Evas_Object *indicator_bg = elm_bg_add(conform);
177 elm_object_style_set(indicator_bg, "indicator/headerbg");
178 elm_object_part_content_set(conform, "elm.swallow.indicator_bg", indicator_bg);
179 evas_object_show(indicator_bg);
181 evas_object_size_hint_weight_set(conform, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
182 evas_object_size_hint_align_set(conform, EVAS_HINT_FILL, EVAS_HINT_FILL);
183 elm_win_resize_object_add(ad->win_main, conform);
184 elm_object_content_set(conform, ad->ly_main);
185 evas_object_show(conform);
186 elm_win_conformant_set(ad->win_main, EINA_TRUE);
188 SETTING_TRACE("[TIME] 4. setting_main_app_create taked %d msec ", appcore_measure_time());
189 appcore_measure_start();
191 /* add event handler */
192 ad->event_handler = ecore_event_handler_add(ECORE_EVENT_KEY_DOWN, __key_press_cb, ad);
198 * The function is called when Setting begins run in background from forground
200 static void support_help_app_pause(void *data)
203 support_help_appdata *ad = data;
212 * The function is called when Setting begins run in forground from background
214 static void support_help_app_resume(void *data)
217 support_help_appdata *ad = data;
223 void support_help_app_destroy_ug_cb(ui_gadget_h ug, void *priv)
225 support_help_appdata *ad = (support_help_appdata *) priv;
227 return; /* do nothing if ad is NULL */
229 elm_win_lower(ad->win_main);
232 setting_ug_destroy(ug);
237 void support_help_app_end_ug_cb(ui_gadget_h ug, void *priv)
241 support_help_appdata *ad = (support_help_appdata *) priv;
243 return; /* do nothing if ad is NULL */
244 support_help_app_terminate(ad);
247 void support_help_app_layout_ug_cb(ui_gadget_h ug, enum ug_mode mode,
255 base = (Evas_Object *) ug_get_layout(ug);
260 case UG_MODE_FULLVIEW:
261 evas_object_size_hint_weight_set(base, EVAS_HINT_EXPAND,
263 ug_disable_effect(ug);
264 evas_object_show(base);
272 EXPORT_PUBLIC void update_lang(void)
277 lang = vconf_get_str(VCONFKEY_LANGSET);
279 setenv("LANG", lang, 1);
280 setenv("LC_MESSAGES", lang, 1);
281 r = setlocale(LC_ALL, "");
283 setlocale(LC_ALL, vconf_get_str(VCONFKEY_LANGSET));
289 EXPORT_PUBLIC void update_region(void)
293 region = vconf_get_str(VCONFKEY_REGIONFORMAT);
295 setenv("LC_CTYPE", region, 1);
296 setenv("LC_NUMERIC", region, 1);
297 setenv("LC_TIME", region, 1);
298 setenv("LC_COLLATE", region, 1);
299 setenv("LC_MONETARY", region, 1);
300 setenv("LC_PAPER", region, 1);
301 setenv("LC_NAME", region, 1);
302 setenv("LC_ADDRESS", region, 1);
303 setenv("LC_TELEPHONE", region, 1);
304 setenv("LC_MEASUREMENT", region, 1);
305 setenv("LC_IDENTIFICATION", region, 1);
310 static int __set_i18n(const char *domain, const char *dir)
313 if (domain == NULL) {
318 r = setlocale(LC_ALL, "");
319 /* if locale is not set properly, try again to set as language base */
321 r = setlocale(LC_ALL, vconf_get_str(VCONFKEY_LANGSET));
323 bindtextdomain(domain, dir);
328 int set_i18n(char *pkgname, char *localedir)
329 /*int set_i18n(const char *domainname, const char *dirname) */
336 return __set_i18n(pkgname, localedir);
340 * The function is called by app-fwk after app_create. It always do the process which cost much time.
342 static void support_help_app_reset(app_control_h service, void *data)
345 support_help_appdata *ad = data;
349 struct ug_cbs *cbs = (struct ug_cbs *)calloc(1, sizeof(struct ug_cbs));
351 support_help_app_terminate(ad);
355 cbs->layout_cb = support_help_app_layout_ug_cb;
356 cbs->result_cb = NULL;
357 cbs->destroy_cb = support_help_app_destroy_ug_cb;
358 cbs->end_cb = support_help_app_end_ug_cb;
359 cbs->priv = (void *)ad;
361 if (app_control_create(&svc)) {
363 support_help_app_terminate(ad);
367 app_control_set_uri(svc, "tizen-help://org.tizen.setting/ringtone");
369 char *cur_ringtone_path = vconf_get_str(VCONFKEY_SETAPPL_CALL_RINGTONE_PATH_STR);
370 if (cur_ringtone_path == NULL)
371 cur_ringtone_path = (char *)strdup("/opt/usr/share/settings/Ringtones/Over_the_horizon.ogg");
372 app_control_add_extra_data(svc, "title", "IDS_ST_HEADER_RINGTONES");
373 app_control_add_extra_data(svc, "domain", "setting");
374 app_control_add_extra_data(svc, "path", "/opt/usr/share/settings/Ringtones");
375 app_control_add_extra_data(svc, "select_type", "SINGLE_FILE");
376 app_control_add_extra_data(svc, "file_type", "SOUND");
377 app_control_add_extra_data(svc, "drm_type", "DRM_ALL");
378 app_control_add_extra_data(svc, "silent", "silent_show");
379 if (safeStrCmp(cur_ringtone_path, "silent") == 0)
380 app_control_add_extra_data(svc, "marked_mode", "silent");
382 app_control_add_extra_data(svc, "marked_mode", cur_ringtone_path);
383 ad->ug = setting_ug_create(NULL, "myfile-efl", UG_MODE_FULLVIEW, svc, cbs);
385 app_control_destroy(svc);
388 evas_object_show(ad->ly_main);
391 FREE(cur_ringtone_path);
392 support_help_app_terminate(ad);
398 evas_object_show(ad->win_main);
399 elm_win_activate(ad->win_main);
404 FREE(cur_ringtone_path);
408 static void support_help_app_lang_changed(app_event_info_h event_info, void *data)
411 support_help_appdata *ad = data;
414 lang = vconf_get_str(VCONFKEY_LANGSET);
416 elm_language_set((const char *)lang);
421 ug_send_event(UG_EVENT_LANG_CHANGE);
425 int main(int argc, char *argv[])
429 support_help_appdata ad;
431 ui_app_lifecycle_callback_s ops = {
432 .create = support_help_app_create,
433 .terminate = support_help_app_terminate,
434 .pause = support_help_app_pause,
435 .resume = support_help_app_resume,
436 .app_control = support_help_app_reset,
439 app_event_handler_h handlers[5] = {NULL, };
440 ui_app_add_event_handler(&handlers[APP_EVENT_LOW_BATTERY], APP_EVENT_LOW_BATTERY, NULL, NULL);
441 ui_app_add_event_handler(&handlers[APP_EVENT_LANGUAGE_CHANGED], APP_EVENT_LANGUAGE_CHANGED, support_help_app_lang_changed, NULL);
442 ui_app_add_event_handler(&handlers[APP_EVENT_REGION_FORMAT_CHANGED], APP_EVENT_REGION_FORMAT_CHANGED, NULL, NULL);
443 ui_app_add_event_handler(&handlers[APP_EVENT_DEVICE_ORIENTATION_CHANGED], APP_EVENT_DEVICE_ORIENTATION_CHANGED, NULL, NULL);
445 memset(&ad, 0x00, sizeof(support_help_appdata));
447 r = ui_app_main(argc, argv, &ops, &ad);
448 SETTING_TRACE_DEBUG("r = %d", r);
451 SETTING_TRACE_ERROR("ui_app_main() returns -1");