[UI]Add emulator check
[apps/core/preloaded/lockscreen.git] / src / lockscreen.c
1 /*
2  * Copyright 2012  Samsung Electronics Co., Ltd
3  *
4  * Licensed under the Flora License, Version 1.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.tizenopensource.org/license
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
18 #include <app.h>
19 #include <vconf.h>
20 #include <Ecore_X.h>
21 #include <system_info.h>
22
23 #include "lockscreen.h"
24 #include "util.h"
25
26 #define QP_EMUL_STR      "Emulator"
27
28 static void win_del(void *data, Evas_Object * obj, void *event)
29 {
30         elm_exit();
31 }
32
33 static Evas_Object *create_win(const char *name)
34 {
35         if (name == NULL)
36                 return NULL;
37
38         Evas_Object *eo;
39         int w, h;
40
41         eo = elm_win_add(NULL, name, ELM_WIN_BASIC);
42         if (!eo) {
43                 LOGE("[%s:%d] eo is NULL", __func__, __LINE__);
44                 return NULL;
45         }
46
47         elm_win_title_set(eo, name);
48         elm_win_borderless_set(eo, EINA_TRUE);
49         evas_object_smart_callback_add(eo, "delete,request", win_del, NULL);
50         ecore_x_window_size_get(ecore_x_window_root_first_get(), &w, &h);
51         evas_object_resize(eo, w, h);
52         elm_win_alpha_set(eo, EINA_TRUE);
53
54         return eo;
55 }
56
57 static void resize_cb(void *data, Evas *e, Evas_Object *obj, void *event_info)
58 {
59         Evas_Coord w;
60         Evas_Coord h;
61
62         evas_object_geometry_get(obj, NULL, NULL, &w, &h);
63 }
64
65 static int _check_emul()
66 {
67         int is_emul = 0;
68         char *info = NULL;
69
70         if (system_info_get_value_string(SYSTEM_INFO_KEY_MODEL, &info) == 0) {
71                 if (info == NULL) return 0;
72                 if (!strncmp(QP_EMUL_STR, info, strlen(info))) {
73                         is_emul = 1;
74                 }
75         }
76
77         if (info != NULL) free(info);
78
79         return is_emul;
80 }
81
82 static bool app_create(void *data)
83 {
84         struct appdata *ad = data;
85         LOGD("[ == %s == ]", __func__);
86         if (ad == NULL)
87                 return false;
88
89         ad->win = NULL;
90         ad->ly_main = NULL;
91         ad->info = NULL;
92         ad->event_bg = NULL;
93         ad->slider = NULL;
94         ad->bDrag = 0;
95
96         Evas_Object *win = NULL;
97
98         ecore_x_window_size_get(ecore_x_window_root_first_get(), &ad->win_w, &ad->win_h);
99         LOGD("[%s:%d] win_w : %d, win_h : %d", __func__, __LINE__, ad->win_w, ad->win_h);
100
101         win = create_win(PACKAGE);
102         if (win == NULL)
103                 return false;
104         ad->win = win;
105         elm_win_conformant_set(ad->win, EINA_TRUE);
106         evas_object_resize(win, ad->win_w, ad->win_h);
107         evas_object_event_callback_add(win, EVAS_CALLBACK_RESIZE, resize_cb, NULL);
108
109         int ret = _app_create(ad);
110         if(ret == -1)
111                 return false;
112
113         return true;
114 }
115
116 static void app_service(service_h service, void *data)
117 {
118         struct appdata *ad = data;
119         LOGD("[ == %s == ]", __func__);
120         if (ad == NULL)
121                 return;
122
123         if (ad->win)
124                 elm_win_activate(ad->win);
125
126         _app_reset(ad);
127 }
128
129 static void app_terminate(void *data)
130 {
131         struct appdata *ad = data;
132         LOGD("[ == %s == ]", __func__);
133         if (ad == NULL)
134                 return;
135
136         if (ad->ly_main)
137                 evas_object_del(ad->ly_main);
138
139         if (ad->win)
140                 evas_object_del(ad->win);
141 }
142
143 static void app_pause(void *data)
144 {
145         struct appdata *ad = data;
146         LOGD("[ == %s == ]", __func__);
147         if (ad == NULL)
148                 return;
149 }
150
151 static void app_resume(void *data)
152 {
153         struct appdata *ad = data;
154         LOGD("[ == %s == ]", __func__);
155         if (ad == NULL)
156                 return;
157 }
158
159 static void device_orientation(app_device_orientation_e orientation, void * data)
160 {
161         struct appdata *ad = data;
162         LOGD("[ == %s == ]", __func__);
163         if (ad == NULL || ad->win == NULL)
164                 return;
165 }
166
167 int main(int argc, char *argv[])
168 {
169         struct appdata ad;
170
171         app_event_callback_s event_callback;
172
173         event_callback.create = app_create;
174         event_callback.terminate = app_terminate;
175         event_callback.pause = app_pause;
176         event_callback.resume = app_resume;
177         event_callback.service = app_service;
178         event_callback.low_memory = NULL;
179         event_callback.low_battery = NULL;
180         event_callback.device_orientation = device_orientation;
181         event_callback.language_changed = NULL;
182         event_callback.region_format_changed = NULL;
183
184         memset(&ad, 0x0, sizeof(struct appdata));
185
186         if(!_check_emul()) {
187                 setenv("ELM_ENGINE", "gl", 1);
188         }
189
190         return app_efl_main(&argc, &argv, &event_callback, &ad);
191 }