Apply multiscale
[profile/tv/apps/native/air_favorite.git] / src / main.c
1 /*
2  * Copyright (c) 2015 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 <Elementary.h>
19 #include <viewmgr.h>
20 #include <inputmgr.h>
21 #include <ui-gadget.h>
22 #include <app_define.h>
23 #include <app_debug.h>
24
25 #include "define.h"
26 #include "utils.h"
27 #include "view.h"
28
29 SET_TAG(PACKAGE);
30
31 struct _appdata {
32         Evas_Object *win;
33         const char *name;
34 };
35
36 static bool _create(void *data)
37 {
38         struct _appdata *ad;
39         Evas_Object *win;
40
41         if (!data) {
42                 _ERR("Get data failed.");
43                 return false;
44         }
45         ad = data;
46
47         elm_app_base_scale_set(APP_BASE_SCALE);
48
49         elm_theme_overlay_add(NULL, THEMEFILE);
50
51         win = utils_add_window(ad->name);
52         if (!win) {
53                 _ERR("Add window failed.");
54                 return false;
55         }
56
57         if (ug_init_efl(win, UG_OPT_INDICATOR_ENABLE) < 0) {
58                 _ERR("Fail to init ug");
59                 evas_object_del(win);
60                 return false;
61         }
62
63         if (!viewmgr_create(win)) {
64                 _ERR("Create viewmgr failed.");
65                 evas_object_del(win);
66                 return false;
67         }
68
69         if (!viewmgr_add_view(view_base_get_vclass(), NULL)) {
70                 _ERR("Add view failed.");
71                 viewmgr_destroy();
72                 evas_object_del(win);
73                 return false;
74         }
75
76         if (!viewmgr_add_view(view_action_menu_get_vclass(), NULL)) {
77                 _ERR("Add view faild.");
78                 viewmgr_destroy();
79                 evas_object_del(win);
80                 return false;
81         }
82
83         if (!viewmgr_add_view(view_pin_get_vclass(), NULL)) {
84                 _ERR("Add view faild.");
85                 viewmgr_destroy();
86                 evas_object_del(win);
87                 return false;
88         }
89
90         ad->win = win;
91
92         return true;
93 }
94
95 static void _terminate(void *data)
96 {
97         struct _appdata *ad;
98
99         if (!data) {
100                 _ERR("Get data failed.");
101                 return;
102         }
103         ad = data;
104
105         if (ad->win) {
106                 evas_object_del(ad->win);
107                 ad->win = NULL;
108         }
109
110         viewmgr_remove_view(VIEW_BASE);
111         viewmgr_remove_view(VIEW_ACTION_MENU);
112         viewmgr_remove_view(VIEW_PIN);
113         viewmgr_destroy();
114 }
115
116 static void _app_control(app_control_h control, void *data)
117 {
118         struct _appdata *ad;
119         char *category;
120         int r;
121
122         if (!data) {
123                 _ERR("Get data failed.");
124                 return;
125         }
126         ad = data;
127
128         if (ad->win)
129                 elm_win_activate(ad->win);
130
131         r = app_control_get_extra_data(control, PARAM_CATEGORY, &category);
132         if (r != APP_CONTROL_ERROR_NONE)
133                 category = NULL;
134
135         if (category)
136                 viewmgr_update_view(VIEW_BASE, UPDATE_MENU, category);
137
138         if (!viewmgr_push_view(VIEW_BASE))
139                 _ERR("Push view failed.");
140 }
141
142 static void _pause(void *data)
143 {
144         view_state state;
145
146         state = viewmgr_get_view_state(VIEW_ACTION_MENU);
147         if (state == VIEW_STATE_VISIBLE)
148                 viewmgr_hide_view(VIEW_ACTION_MENU);
149
150         state = viewmgr_get_view_state(VIEW_PIN);
151         if (state == VIEW_STATE_VISIBLE)
152                 viewmgr_hide_view(VIEW_PIN);
153
154         inputmgr_enable(EINA_FALSE);
155 }
156
157 static void _resume(void *data)
158 {
159         inputmgr_enable(EINA_TRUE);
160 }
161
162 int main(int argc, char *argv[])
163 {
164         struct _appdata ad;
165         ui_app_lifecycle_callback_s cbs = {
166                 .create = _create,
167                 .terminate = _terminate,
168                 .app_control = _app_control,
169                 .pause = _pause,
170                 .resume = _resume,
171         };
172
173         memset(&ad, 0x00, sizeof(ad));
174         ad.name = PACKAGE;
175
176         return ui_app_main(argc, argv, &cbs, &ad);
177 }