Support language change in runtime
[platform/core/uifw/inputmethod-setting.git] / im_setting_list / input_method_setting_list.cpp
1 /*
2  * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17 #include <app.h>
18 #include <unistd.h>
19 #include "input_method_setting_list.h"
20 #include "input_method_setting_list_ui.h"
21
22 static bool
23 app_create(void *data)
24 {
25     LOGD("");
26     /* Hook to take necessary actions before main event loop starts
27        Initialize UI resources and application's data
28        If this function returns true, the main loop of application starts
29        If this function returns false, the application is terminated */
30     return true;
31 }
32
33 static void
34 app_control(app_control_h app_control, void *data)
35 {
36     /* Handle the launch request. */
37     appdata *ad = (appdata *)data;
38     char* type = NULL;
39     int res;
40
41     LOGD("");
42
43     if (!ad)
44         return;
45
46     if (ad->app_state == APP_STATE_PAUSE || ad->app_state == APP_STATE_RESUME)
47     {
48         if (ad->win)
49         {
50             elm_win_activate(ad->win);
51             im_setting_list_update_window(ad);
52         }
53         ad->app_state = APP_STATE_SERVICE;
54         return;
55     }
56
57     ad->app_type = APP_TYPE_NORMAL;
58
59     res = app_control_get_extra_data(app_control, "caller", &type);
60     if (APP_CONTROL_ERROR_NONE == res && NULL != type) {
61         if (strcmp(type, "settings") == 0) {
62             ad->app_type = APP_TYPE_SETTING;
63         } else if (strcmp(type, "settings_no_rotation") == 0) {
64             ad->app_type = APP_TYPE_SETTING_NO_ROTATION;
65         }
66     }
67
68     ad->app_state = APP_STATE_SERVICE;
69     im_setting_list_app_create(ad);
70     if (NULL != type)
71     {
72         free(type);
73     }
74 }
75
76 static void
77 app_pause(void *data)
78 {
79     appdata *ad = (appdata *)data;
80     LOGD("");
81     /* Take necessary actions when application becomes invisible. */
82
83     if (!ad)
84         return;
85     if (ad->popup)
86     {
87         evas_object_del(ad->popup);
88         ad->popup = NULL;
89     }
90     ad->app_state = APP_STATE_PAUSE;
91 }
92
93 static void
94 app_resume(void *data)
95 {
96     appdata *ad = (appdata *)data;
97     LOGD("");
98     /* Take necessary actions when application becomes visible. */
99
100     if (!ad)
101         return;
102     if (ad->app_state == APP_STATE_PAUSE)
103     {
104         if (ad->win)
105         {
106             elm_win_activate(ad->win);
107         }
108         im_setting_list_app_resume(ad);
109         ad->app_state = APP_STATE_RESUME;
110         return;
111     }
112     ad->app_state = APP_STATE_RESUME;
113 }
114
115 static void
116 app_terminate(void *data)
117 {
118     appdata *ad = (appdata *)data;
119     LOGD("");
120     /* Release all resources. */
121
122     if (!ad)
123         return;
124     ad->app_state = APP_STATE_TERMINATE;
125     im_setting_list_app_terminate(ad);
126 }
127
128 static void
129 ui_app_lang_changed(app_event_info_h event_info, void *user_data)
130 {
131     /*APP_EVENT_LANGUAGE_CHANGED*/
132     char *lang = NULL;
133     app_event_get_language(event_info, &lang);
134
135     LOGD("lang : %s", lang);
136
137     if (lang) {
138         elm_language_set(lang);
139         free(lang);
140     }
141 }
142
143 static void
144 ui_app_orient_changed(app_event_info_h event_info, void *user_data)
145 {
146     LOGD("");
147     /*APP_EVENT_DEVICE_ORIENTATION_CHANGED*/
148 }
149
150 static void
151 ui_app_region_changed(app_event_info_h event_info, void *user_data)
152 {
153     LOGD("");
154     /*APP_EVENT_REGION_FORMAT_CHANGED*/
155 }
156
157 static void
158 ui_app_low_battery(app_event_info_h event_info, void *user_data)
159 {
160     LOGD("");
161     /*APP_EVENT_LOW_BATTERY*/
162 }
163
164 static void
165 ui_app_low_memory(app_event_info_h event_info, void *user_data)
166 {
167     LOGD("");
168     /*APP_EVENT_LOW_MEMORY*/
169 }
170
171 EXPORTED int
172 main(int argc, char *argv[])
173 {
174     appdata ad = {0, };
175     int ret = 0;
176
177     ui_app_lifecycle_callback_s event_callback = {0, };
178     app_event_handler_h handlers[5] = {NULL, };
179
180     event_callback.create = app_create;
181     event_callback.terminate = app_terminate;
182     event_callback.pause = app_pause;
183     event_callback.resume = app_resume;
184     event_callback.app_control = app_control;
185
186     ui_app_add_event_handler(&handlers[APP_EVENT_LOW_BATTERY], APP_EVENT_LOW_BATTERY, ui_app_low_battery, &ad);
187     ui_app_add_event_handler(&handlers[APP_EVENT_LOW_MEMORY], APP_EVENT_LOW_MEMORY, ui_app_low_memory, &ad);
188     ui_app_add_event_handler(&handlers[APP_EVENT_DEVICE_ORIENTATION_CHANGED], APP_EVENT_DEVICE_ORIENTATION_CHANGED, ui_app_orient_changed, &ad);
189     ui_app_add_event_handler(&handlers[APP_EVENT_LANGUAGE_CHANGED], APP_EVENT_LANGUAGE_CHANGED, ui_app_lang_changed, &ad);
190     ui_app_add_event_handler(&handlers[APP_EVENT_REGION_FORMAT_CHANGED], APP_EVENT_REGION_FORMAT_CHANGED, ui_app_region_changed, &ad);
191
192     ret = ui_app_main(argc, argv, &event_callback, &ad);
193     if (ret != APP_ERROR_NONE) {
194        LOGW("ui_app_main failed, Err=%d\n", ret);
195     }
196
197     return ret;
198 }
199