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