2 * Copyright (c) 2012 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 #include <appcore-efl.h>
22 #include <devman_haptic.h>
28 #include <Ecore_Input.h>
31 /* Time profiling support */
34 #endif /* ACCT_PROF */
39 int create_and_show_basic_popup_min(struct appdata *ad);
40 void poweroff_response_yes_cb_min(void *data, Evas_Object * obj, void *event_info);
41 void poweroff_response_no_cb_min(void *data, Evas_Object * obj, void *event_info);
44 int myterm(bundle *b, void *data)
49 int mytimeout(bundle *b, void *data)
54 syspopup_handler handler = {
55 .def_term_fn = myterm,
56 .def_timeout_fn = mytimeout
59 static Eina_Bool exit_idler_cb(void *data)
62 return ECORE_CALLBACK_CANCEL;
65 void popup_terminate(void)
67 if (ecore_idler_add(exit_idler_cb, NULL))
73 /* App Life cycle funtions */
74 static void win_del(void *data, Evas_Object * obj, void *event)
80 static void main_quit_cb(void *data, Evas_Object * obj, const char *emission,
86 /* Update text font */
87 static void update_ts(Evas_Object * eo, struct text_part *tp, int size)
91 if (eo == NULL || tp == NULL || size < 0)
94 for (i = 0; i < size; i++) {
95 if (tp[i].part && tp[i].msgid)
96 edje_object_part_text_set(eo, tp[i].part,
101 /* Language changed noti handler */
102 static int lang_changed(void *data)
104 struct appdata *ad = data;
106 if (ad->layout_main == NULL)
109 update_ts(elm_layout_edje_get(ad->layout_main), main_txt,
110 sizeof(main_txt) / sizeof(main_txt[0]));
114 /* Create main window */
115 static Evas_Object *create_win(const char *name)
120 eo = elm_win_add(NULL, name, ELM_WIN_DIALOG_BASIC);
122 elm_win_title_set(eo, name);
123 elm_win_borderless_set(eo, EINA_TRUE);
124 evas_object_smart_callback_add(eo, "delete,request", win_del, NULL);
125 elm_win_alpha_set(eo, EINA_TRUE);
126 ecore_x_window_size_get(ecore_x_window_root_first_get(), &w,
128 evas_object_resize(eo, w, h);
134 /* Read from EDJ file */
135 static Evas_Object *load_edj(Evas_Object * parent, const char *file,
141 eo = elm_layout_add(parent);
143 r = elm_layout_file_set(eo, file, group);
149 evas_object_size_hint_weight_set(eo, EVAS_HINT_EXPAND,
156 /* Terminate noti handler */
157 static int app_terminate(void *data)
159 struct appdata *ad = data;
162 evas_object_del(ad->layout_main);
165 evas_object_del(ad->win_main);
170 /* Pause/background */
171 static int app_pause(void *data)
177 static int app_resume(void *data)
184 static int app_reset(bundle *b, void *data)
186 struct appdata *ad = data;
188 if (syspopup_has_popup(b)) {
191 syspopup_create(b, &handler, ad->win_main, ad);
192 evas_object_show(ad->win_main);
195 poweroff_start((void *)ad);
201 /* Customized print */
202 void system_print(const char *format, ...)
204 /* Un-comment return to disable logs */
207 va_start(args, format);
208 vfprintf(stderr, format, args);
212 /* Cleanup objects to avoid mem-leak */
213 void poweroff_cleanup(struct appdata *ad)
215 if (ad->popup_poweroff)
216 evas_object_del(ad->popup_poweroff);
218 evas_object_del(ad->layout_main);
221 /* Background clicked noti */
222 static void bg_clicked_cb(void *data, Evas * e, Evas_Object * obj, void *event_info)
224 system_print("\n system-popup : In BG Noti \n");
229 static void poweroff_popup_direct_cancel(keynode_t *key, void *data)
232 struct appdata *ad = data;
233 if ( vconf_get_int(VCONFKEY_PM_STATE, &val) == 0
234 && val == VCONFKEY_PM_STATE_LCDOFF ) {
235 vconf_ignore_key_changed(VCONFKEY_PM_STATE,(void*)poweroff_popup_direct_cancel);
237 poweroff_cleanup(ad);
243 void poweroff_response_yes_cb_min(void *data, Evas_Object * obj, void *event_info)
245 static int bPowerOff = 0;
249 system_print("System-popup : Switching off phone !! Bye Bye \n");
250 vconf_ignore_key_changed(VCONFKEY_PM_STATE,(void*)poweroff_popup_direct_cancel);
251 /* This will cleanup the memory */
253 poweroff_cleanup(data);
255 if (sysman_call_predef_action(PREDEF_POWEROFF, 0) == -1) {
256 system_print("System-popup : failed to request poweroff to system_server \n");
261 void poweroff_response_no_cb_min(void *data, Evas_Object * obj, void *event_info)
263 system_print("\nSystem-popup: Option is Wrong");
264 vconf_ignore_key_changed(VCONFKEY_PM_STATE,(void*)poweroff_popup_direct_cancel);
266 poweroff_cleanup(data);
270 int create_and_show_basic_popup_min(struct appdata *ad)
275 ad->popup_poweroff = elm_popup_add(ad->win_main);
276 if (ad->popup_poweroff == NULL) {
277 system_print("\n System-popup : Add popup failed \n");
281 evas_object_size_hint_weight_set(ad->popup_poweroff, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
282 elm_object_style_set(ad->popup_poweroff, "transparent");
283 elm_object_text_set(ad->popup_poweroff, _("IDS_ST_BODY_POWER_OFF"));
284 elm_object_part_text_set(ad->popup_poweroff, "title,text", _("IDS_COM_BODY_SYSTEM_INFO_ABB"));
286 btn1 = elm_button_add(ad->popup_poweroff);
287 elm_object_text_set(btn1, _("IDS_COM_SK_CANCEL"));
288 elm_object_part_content_set(ad->popup_poweroff, "button1", btn1);
289 elm_object_style_set (btn1,"popup_button/default");
290 evas_object_smart_callback_add(btn1, "clicked", poweroff_response_no_cb_min, ad);
291 btn2 = elm_button_add(ad->popup_poweroff);
292 elm_object_text_set(btn2, _("IDS_COM_SK_OK"));
293 elm_object_part_content_set(ad->popup_poweroff, "button2", btn2);
294 elm_object_style_set (btn2,"popup_button/default");
295 evas_object_smart_callback_add(btn2, "clicked", poweroff_response_yes_cb_min, ad);
298 xwin = elm_win_xwindow_get(ad->popup_poweroff);
299 ecore_x_netwm_window_type_set(xwin, ECORE_X_WINDOW_TYPE_NOTIFICATION);
300 utilx_grab_key(ecore_x_display_get(), xwin, KEY_SELECT, SHARED_GRAB);
301 evas_object_show(ad->popup_poweroff);
302 vconf_notify_key_changed(VCONFKEY_PM_STATE, poweroff_popup_direct_cancel, ad);
307 static void bg_noti_cb(void *data)
309 ui_bgimg_reload((Evas_Object *) data);
312 /* Create indicator bar */
313 static int poweroff_create_indicator(struct appdata *ad)
316 elm_win_indicator_mode_set(ad->win_main, ELM_WIN_INDICATOR_HIDE);
321 static int poweroff_play_vibration()
328 /* Open the haptic device */
329 dev_handle = device_haptic_open(DEV_IDX_0, mode);
333 /* Play a monotone pattern for 1s */
334 ret_val = device_haptic_play_monotone(dev_handle, 1000);
335 device_haptic_close(dev_handle);
344 int poweroff_start(void *data)
346 struct appdata *ad = data;
349 /* Create and show popup */
350 ret_val = create_and_show_basic_popup_min(ad);
354 /* Change LCD brightness */
355 ret_val = pm_change_state(LCD_NORMAL);
359 /* Play a vibration for 1 sec */
360 ret_val = poweroff_play_vibration();
362 system_print("\n Poweroff : Play vibration Failed \n");
368 int app_create(void *data)
372 struct appdata *ad = data;
374 /* Create window (Reqd for sys-popup) */
375 win = create_win(PACKAGE);
381 elm_theme_overlay_add(NULL,EDJ_NAME);
386 int main(int argc, char *argv[])
390 /* App life cycle management */
391 struct appcore_ops ops = {
392 .create = app_create,
393 .terminate = app_terminate,
395 .resume = app_resume,
399 memset(&ad, 0x0, sizeof(struct appdata));
403 return appcore_efl_main(PACKAGE, &argc, &argv, &ops);