Apply tizen-ws-shell lockscreen service
[apps/core/preloaded/lockscreen.git] / src / window.c
1 /*
2  * Copyright (c) 2009-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 <Evas.h>
18 #include <Ecore.h>
19 #include <Elementary.h>
20 #include <vconf.h>
21 #include <efl_util.h>
22
23 #include "lockscreen.h"
24 #include "log.h"
25 #include "window.h"
26 #include "tzsh_lockscreen_service.h"
27
28 #define STR_ATOM_PANEL_SCROLLABLE_STATE "_E_MOVE_PANEL_SCROLLABLE_STATE"
29
30 static struct _s_info {
31         Evas_Object *win;
32
33         tzsh_h tzsh;
34         tzsh_lockscreen_service_h lockscreen_service;
35
36         int win_w;
37         int win_h;
38 } s_info = {
39         .win = NULL,
40
41         .tzsh = NULL,
42         .lockscreen_service = NULL,
43
44         .win_w = 0,
45         .win_h = 0,
46 };
47
48 Evas_Object *lock_window_win_get(void)
49 {
50         return s_info.win;
51 }
52
53 int lock_window_width_get(void)
54 {
55         return s_info.win_w;
56 }
57
58 int lock_window_height_get(void)
59 {
60         return s_info.win_h;
61 }
62
63 static lock_error_e _tzsh_set(Evas_Object *win)
64 {
65         tzsh_h tzsh = NULL;
66         tzsh_lockscreen_service_h lockscreen_service = NULL;
67         tzsh_window tz_win;
68
69         retv_if(!win, LOCK_ERROR_INVALID_PARAMETER);
70
71         tzsh = tzsh_create(TZSH_TOOLKIT_TYPE_EFL);
72         retv_if(!tzsh, LOCK_ERROR_FAIL);
73         s_info.tzsh = tzsh;
74
75         tz_win = elm_win_window_id_get(win);
76         if (!tz_win) {
77                 tzsh_destroy(tzsh);
78                 return LOCK_ERROR_FAIL;
79         }
80
81         lockscreen_service = tzsh_lockscreen_service_create(tzsh, tz_win);
82         if (!lockscreen_service) {
83                 tzsh_destroy(tzsh);
84                 return LOCK_ERROR_FAIL;
85         }
86         s_info.lockscreen_service = lockscreen_service;
87
88         return LOCK_ERROR_OK;
89 }
90
91 static void _tzsh_unset(void)
92 {
93         if (s_info.lockscreen_service) {
94                 tzsh_lockscreen_service_destroy(s_info.lockscreen_service);
95                 s_info.lockscreen_service = NULL;
96         }
97
98         if (s_info.tzsh) {
99                 tzsh_destroy(s_info.tzsh);
100                 s_info.tzsh = NULL;
101         }
102 }
103
104 Evas_Object *lock_window_create(int type)
105 {
106         int x = 0, y = 0, w = 0, h = 0;
107
108         Evas_Object *win = elm_win_add(NULL, "LOCKSCREEN", ELM_WIN_NOTIFICATION);
109         retv_if(!win, NULL);
110
111         elm_win_alpha_set(win, EINA_TRUE);
112         elm_win_title_set(win, "LOCKSCREEN");
113         elm_win_borderless_set(win, EINA_TRUE);
114         elm_win_autodel_set(win, EINA_TRUE);
115         efl_util_set_notification_window_level(win, EFL_UTIL_NOTIFICATION_LEVEL_MEDIUM);
116
117         elm_win_screen_size_get(win, &x, &y, &w, &h);
118
119         s_info.win = win;
120         s_info.win_w = w;
121         s_info.win_h = h;
122
123         if (LOCK_ERROR_OK != _tzsh_set(win)) {
124                 _E("Failed to set tzsh");
125         }
126
127         return win;
128 }
129
130 void lock_window_destroy(void)
131 {
132         _tzsh_unset();
133
134         if (s_info.win) {
135                 evas_object_del(s_info.win);
136                 s_info.win = NULL;
137         }
138 }