DB : group manipulation
[apps/native/sample/adventure.git] / src / adventure.c
1 /*
2  * Samsung API
3  * Copyright (c) 2009-2015 Samsung Electronics Co., Ltd.
4  *
5  * Licensed under the Apache License, Version 2.0 (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://www.apache.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
18 #include <tizen.h>
19 #include <Elementary.h>
20 #include "adventure.h"
21 #include "log.h"
22 #include "initial.h"
23 #include "loading.h"
24 #include "util.h"
25
26 static void
27 win_delete_request_cb(void *data, Evas_Object *obj, void *event_info)
28 {
29         ui_app_exit();
30 }
31
32 static Evas_Object *_create_adventure(Evas_Object *parent)
33 {
34         Evas_Object *adventure = NULL;
35         char *path = NULL;
36         char full_path[PATH_LEN] = {0, };
37
38         adventure = elm_layout_add(parent);
39         retv_if(!adventure, NULL);
40
41         path = app_get_resource_path();
42         retv_if(!path, NULL);
43
44         snprintf(full_path, sizeof(full_path), "%s/edje/adventure.edj", path);
45
46         elm_layout_file_set(adventure, full_path, "main");
47         evas_object_size_hint_weight_set(adventure, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
48         evas_object_size_hint_align_set(adventure, EVAS_HINT_FILL, EVAS_HINT_FILL);
49         evas_object_show(adventure);
50
51         return adventure;
52 }
53
54 static void _destroy_adventure(Evas_Object *adventure)
55 {
56         ret_if(!adventure);
57         evas_object_del(adventure);
58 }
59
60 Eina_Bool _destroy_initial_cb(void *data)
61 {
62         adventure_info_s *adventure_info = data;
63
64         retv_if(!adventure_info, ECORE_CALLBACK_CANCEL);
65
66         elm_object_part_content_unset(adventure_info->adventure, "initial");
67         initial_destroy(adventure_info->initial);
68         adventure_info->initial_timer = NULL;
69
70         adventure_info->ui_manager = ui_manager_create(adventure_info->conformant, adventure_info);
71         retv_if(!adventure_info->ui_manager, ECORE_CALLBACK_CANCEL);
72
73 #if 0
74         adventure_info->loading = loading_create(adventure_info->adventure, adventure_info->width, adventure_info->height);
75         retv_if(!adventure_info->loading, ECORE_CALLBACK_CANCEL);
76         elm_object_part_content_set(adventure_info->adventure, "loading", adventure_info->loading);
77 #endif
78
79         return ECORE_CALLBACK_CANCEL;
80 }
81
82 static bool
83 app_create(void *data)
84 {
85         adventure_info_s *adventure_info = data;
86         adventure_info->win = elm_win_util_standard_add(PACKAGE, PACKAGE);
87         elm_win_conformant_set(adventure_info->win, EINA_TRUE);
88         elm_win_autodel_set(adventure_info->win, EINA_TRUE);
89         if (elm_win_wm_rotation_supported_get(adventure_info->win)) {
90                 int rots[1] = {0};
91                 elm_win_wm_rotation_available_rotations_set(adventure_info->win, (const int *)(&rots), 1);
92         }
93         evas_object_smart_callback_add(adventure_info->win, "delete,request", win_delete_request_cb, NULL);
94         elm_win_screen_size_get(adventure_info->win, NULL, NULL, &adventure_info->width, &adventure_info->height);
95         evas_object_show(adventure_info->win);
96
97         adventure_info->conform = elm_conformant_add(adventure_info->win);
98         elm_win_indicator_mode_set(adventure_info->win, ELM_WIN_INDICATOR_HIDE);
99         evas_object_size_hint_weight_set(adventure_info->conform, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
100         elm_win_resize_object_add(adventure_info->win, adventure_info->conform);
101         evas_object_show(adventure_info->conform);
102
103         _D("Window size (%d:%d)", adventure_info->width, adventure_info->height);
104
105         adventure_info->adventure = _create_adventure(adventure_info->conform);
106         if (adventure_info->adventure)
107                 elm_object_content_set(adventure_info->conform, adventure_info->adventure);
108         else
109                 _E("cannot create the adventure ui");
110
111         adventure_info->initial = initial_create(adventure_info->conform, adventure_info->width, adventure_info->height);
112         if (adventure_info->initial)
113                 elm_object_part_content_set(adventure_info->adventure, "initial", adventure_info->initial);
114         else
115                 _E("cannot create the initial ui");
116
117         adventure_info->initial_timer = ecore_timer_add(3.0f, _destroy_initial_cb, adventure_info);
118         retv_if(!adventure_info->initial_timer, false);
119
120         return true;
121 }
122
123 static void
124 app_control(app_control_h app_control, void *data)
125 {
126         adventure_info_s *adventure_info = data;
127         ret_if(!adventure_info);
128 }
129
130 static void
131 app_pause(void *data)
132 {
133         /* Take necessary actions when application becomes invisible. */
134 }
135
136 static void
137 app_resume(void *data)
138 {
139         /* Take necessary actions when application becomes visible. */
140 }
141
142 static void
143 app_terminate(void *data)
144 {
145         adventure_info_s *adventure_info = data;
146
147         if (adventure_info->ui_manager)
148                 ui_manager_destroy(adventure_info->ui_manager);
149
150         if (adventure_info->adventure)
151                 _destroy_adventure(adventure_info->adventure);
152
153         if (adventure_info->initial_timer) {
154                 ecore_timer_del(adventure_info->initial_timer);
155                 initial_destroy(adventure_info->initial);
156         }
157
158         if (adventure_info->conform)
159                 evas_object_del(adventure_info->conform);
160
161         if (adventure_info->win)
162                 evas_object_del(adventure_info->win);
163 }
164
165 static void
166 ui_app_lang_changed(app_event_info_h event_info, void *user_data)
167 {
168         /*APP_EVENT_LANGUAGE_CHANGED*/
169         char *locale = NULL;
170         system_settings_get_value_string(SYSTEM_SETTINGS_KEY_LOCALE_LANGUAGE, &locale);
171         elm_language_set(locale);
172         free(locale);
173         return;
174 }
175
176 static void
177 ui_app_orient_changed(app_event_info_h event_info, void *user_data)
178 {
179         /*APP_EVENT_DEVICE_ORIENTATION_CHANGED*/
180         return;
181 }
182
183 static void
184 ui_app_region_changed(app_event_info_h event_info, void *user_data)
185 {
186         /*APP_EVENT_REGION_FORMAT_CHANGED*/
187 }
188
189 static void
190 ui_app_low_battery(app_event_info_h event_info, void *user_data)
191 {
192         /*APP_EVENT_LOW_BATTERY*/
193 }
194
195 static void
196 ui_app_low_memory(app_event_info_h event_info, void *user_data)
197 {
198         /*APP_EVENT_LOW_MEMORY*/
199 }
200
201 int
202 main(int argc, char *argv[])
203 {
204         adventure_info_s adventure_info = {0,};
205         int ret = 0;
206
207         ui_app_lifecycle_callback_s event_callback = {0,};
208         app_event_handler_h handlers[5] = {NULL, };
209
210         event_callback.create = app_create;
211         event_callback.terminate = app_terminate;
212         event_callback.pause = app_pause;
213         event_callback.resume = app_resume;
214         event_callback.app_control = app_control;
215
216         ui_app_add_event_handler(&handlers[APP_EVENT_LOW_BATTERY], APP_EVENT_LOW_BATTERY, ui_app_low_battery, &adventure_info);
217         ui_app_add_event_handler(&handlers[APP_EVENT_LOW_MEMORY], APP_EVENT_LOW_MEMORY, ui_app_low_memory, &adventure_info);
218         ui_app_add_event_handler(&handlers[APP_EVENT_DEVICE_ORIENTATION_CHANGED], APP_EVENT_DEVICE_ORIENTATION_CHANGED, ui_app_orient_changed, &adventure_info);
219         ui_app_add_event_handler(&handlers[APP_EVENT_LANGUAGE_CHANGED], APP_EVENT_LANGUAGE_CHANGED, ui_app_lang_changed, &adventure_info);
220         ui_app_add_event_handler(&handlers[APP_EVENT_REGION_FORMAT_CHANGED], APP_EVENT_REGION_FORMAT_CHANGED, ui_app_region_changed, &adventure_info);
221         ui_app_remove_event_handler(handlers[APP_EVENT_LOW_MEMORY]);
222
223         ret = ui_app_main(argc, argv, &event_callback, &adventure_info);
224         if (ret != APP_ERROR_NONE) {
225                 dlog_print(DLOG_ERROR, LOG_TAG, "ui_app_main() is failed. err = %d", ret);
226         }
227
228         return ret;
229 }