Remove Unnecessary codes of poweroff popup
[platform/core/system/system-popup.git] / poweroff-popup / src / poweroff.c
1 /*
2  *  system-popup
3  *
4  * Copyright (c) 2000 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
5  * 
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  *
18 */
19
20
21 #include <stdio.h>
22 #include <appcore-efl.h>
23 #include <sensor.h>
24 //#include <dd-deviced.h>
25 //#include <dd-display.h>
26 #include <svi.h>
27 #include <sysman.h>
28 #include "poweroff.h"
29 #include "common.h"
30
31 #include <Ecore_X.h>
32 #include <Ecore_Input.h>
33 #include <utilX.h>
34
35 /* Time profiling support */
36 #ifdef ACCT_PROF
37 #include <sys/acct.h>
38 #endif /* ACCT_PROF */
39
40 #include <syspopup.h>
41 #include <vconf.h>
42
43 int create_and_show_basic_popup_min(struct appdata *ad);
44 void poweroff_response_yes_cb(void *data, Evas_Object * obj, void *event_info);
45 void poweroff_response_no_cb(void *data, Evas_Object * obj, void *event_info);
46
47 int myterm(bundle *b, void *data)
48 {
49         return 0;
50 }
51
52 int mytimeout(bundle *b, void *data)
53 {
54         return 0;
55 }
56
57 syspopup_handler handler = {
58         .def_term_fn = myterm,
59         .def_timeout_fn = mytimeout
60 };
61
62 /* App Life cycle funtions */
63 static void win_del(void *data, Evas_Object * obj, void *event)
64 {
65         popup_terminate();
66 }
67
68 /* Create main window */
69 static Evas_Object *create_win(const char *name)
70 {
71         Evas_Object *eo;
72         Ecore_X_Window xwin;
73         int w, h;
74         unsigned int val = 1;
75
76         eo = elm_win_add(NULL, name, ELM_WIN_DIALOG_BASIC);
77         if (eo) {
78                 elm_win_title_set(eo, name);
79                 elm_win_borderless_set(eo, EINA_TRUE);
80                 evas_object_smart_callback_add(eo, "delete,request", win_del, NULL);
81                 elm_win_alpha_set(eo, EINA_TRUE);
82                 ecore_x_window_size_get(ecore_x_window_root_first_get(), &w,
83                                         &h);
84                 evas_object_resize(eo, w, h);
85         }
86         xwin = elm_win_xwindow_get(eo);
87         ecore_x_window_prop_card32_set(xwin, ECORE_X_ATOM_E_ILLUME_ACCESS_CONTROL, &val, 1);
88
89         return eo;
90 }
91
92 /* Cleanup objects to avoid mem-leak */
93 void poweroff_cleanup(struct appdata *ad)
94 {
95         if (!ad)
96                 return;
97
98         if (ad->popup_poweroff)
99                 evas_object_del(ad->popup_poweroff);
100         if (ad->layout_main)
101                 evas_object_del(ad->layout_main);
102 }
103
104 void poweroff_response_yes_cb(void *data, Evas_Object * obj, void *event_info)
105 {
106         static int bPowerOff = 0;
107         if (1 == bPowerOff)
108                 return;
109         bPowerOff = 1;
110         _I("System-popup : Switching off phone !! Bye Bye");
111         /* This will cleanup the memory */
112         poweroff_cleanup(data);
113
114         if (sysman_call_predef_action(PREDEF_POWEROFF, 0) == -1) {
115                 _E("System-popup : failed to request poweroff to system_server");
116                 system("poweroff");
117         }
118 }
119
120 void poweroff_response_no_cb(void *data, Evas_Object * obj, void *event_info)
121 {
122         _I("System-popup: Option is Wrong");
123         poweroff_cleanup(data);
124         popup_terminate();
125 }
126
127 int create_and_show_basic_popup(struct appdata *ad)
128 {
129         Evas_Object *btn1;
130         Evas_Object *btn2;
131
132         ad->popup_poweroff = elm_popup_add(ad->win_main);
133         if (ad->popup_poweroff == NULL) {
134                 _E("System-popup : Add popup failed ");
135                 return -1;
136         }
137
138         evas_object_size_hint_weight_set(ad->popup_poweroff, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
139         elm_object_style_set(ad->popup_poweroff, "transparent");
140         elm_object_text_set(ad->popup_poweroff, _("IDS_ST_BODY_POWER_OFF"));
141         elm_object_part_text_set(ad->popup_poweroff, "title,text", _("IDS_COM_BODY_SYSTEM_INFO_ABB"));
142
143         btn1 = elm_button_add(ad->popup_poweroff);
144         elm_object_text_set(btn1, _("IDS_COM_SK_CANCEL"));
145         elm_object_part_content_set(ad->popup_poweroff, "button1", btn1);
146         elm_object_style_set (btn1,"popup_button/default");
147         evas_object_smart_callback_add(btn1, "clicked", poweroff_response_no_cb, ad);
148         btn2 = elm_button_add(ad->popup_poweroff);
149         elm_object_text_set(btn2, _("IDS_COM_SK_OK"));
150         elm_object_part_content_set(ad->popup_poweroff, "button2", btn2);
151         elm_object_style_set (btn2,"popup_button/default");
152         evas_object_smart_callback_add(btn2, "clicked", poweroff_response_yes_cb, ad);
153
154         Ecore_X_Window xwin;
155         xwin = elm_win_xwindow_get(ad->popup_poweroff);
156         ecore_x_netwm_window_type_set(xwin, ECORE_X_WINDOW_TYPE_NOTIFICATION);
157         utilx_grab_key(ecore_x_display_get(), xwin, KEY_SELECT, SHARED_GRAB);
158         evas_object_show(ad->popup_poweroff);
159         return 0;
160 }
161
162 /* Start UI */
163 int poweroff_start(void *data)
164 {
165         struct appdata *ad = data;
166         int ret_val = 0;
167
168         /* Create and show popup */
169         ret_val = create_and_show_basic_popup(ad);
170         if (ret_val != 0)
171                 return -1;
172
173         /* Change LCD brightness */
174 //      ret_val = display_change_state(LCD_NORMAL);
175         if (ret_val != 0)
176                 return -1;
177
178         return 0;
179 }
180
181 /* App init */
182 int app_create(void *data)
183 {
184
185         Evas_Object *win;
186         struct appdata *ad = data;
187
188         /* Create window (Reqd for sys-popup) */
189         win = create_win(PACKAGE);
190         if (win == NULL)
191                 return -1;
192
193         ad->win_main = win;
194
195         elm_theme_overlay_add(NULL,EDJ_NAME); 
196
197         return 0;
198 }
199
200 /* Terminate noti handler */
201 static int app_terminate(void *data)
202 {
203         struct appdata *ad = data;
204
205         if (ad->layout_main)
206                 evas_object_del(ad->layout_main);
207
208         if (ad->win_main)
209                 evas_object_del(ad->win_main);
210
211         return 0;
212 }
213
214 /* Pause/background */
215 static int app_pause(void *data)
216 {
217         return 0;
218 }
219
220 /* Resume */
221 static int app_resume(void *data)
222 {
223         return 0;
224 }
225
226
227 /* Reset */
228 static int app_reset(bundle *b, void *data)
229 {
230         struct appdata *ad = data;
231
232         if (syspopup_has_popup(b)) {
233                 syspopup_reset(b);
234         } else {
235                 syspopup_create(b, &handler, ad->win_main, ad);
236                 evas_object_show(ad->win_main);
237
238                 /* Start Main UI */
239                 poweroff_start((void *)ad);
240         }
241
242         return 0;
243 }
244
245 int main(int argc, char *argv[])
246 {
247         struct appdata ad;
248
249         /* App life cycle management */
250         struct appcore_ops ops = {
251                 .create = app_create,
252                 .terminate = app_terminate,
253                 .pause = app_pause,
254                 .resume = app_resume,
255                 .reset = app_reset,
256         };
257
258         memset(&ad, 0x0, sizeof(struct appdata));
259         ops.data = &ad;
260
261         /* Go into loop */
262         return appcore_efl_main(PACKAGE, &argc, &argv, &ops);
263 }