4 * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved.
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
10 * http://www.apache.org/licenses/LICENSE-2.0
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.
20 #include "popup-common.h"
22 #define SYSTEMD_STOP_POWER_OFF 4
24 #define POWER_BUS_NAME "org.tizen.system.deviced"
25 #define POWER_OBJECT_PATH "/Org/Tizen/System/DeviceD/Power"
26 #define POWER_INTERFACE_NAME POWER_BUS_NAME".power"
28 #define POWER_METHOD "reboot"
29 #define POWER_OPERATION_OFF "poweroff"
31 static void remove_popup(const struct popup_ops *ops);
32 static void pm_state_changed(keynode_t *key, void *data);
33 static void event_back_key_up(void *data, Evas_Object *obj, void *event_info);
34 static void register_handlers(const struct popup_ops *ops);
35 static void unregister_handlers(const struct popup_ops *ops);
36 static int poweroff_launch(bundle *b, const struct popup_ops *ops);
37 static void poweroff_terminate(const struct popup_ops *ops);
38 static void poweroff_clicked(const struct popup_ops *ops);
39 static __attribute__ ((constructor)) void poweroff_register_popup(void);
41 static void remove_popup(const struct popup_ops *ops)
43 static bool terminating = false;
50 unload_simple_popup(ops);
54 static void pm_state_changed(keynode_t *key, void *data)
56 const struct popup_ops *ops = data;
61 if (vconf_keynode_get_int(key) != VCONFKEY_PM_STATE_LCDOFF)
67 static void event_back_key_up(void *data, Evas_Object *obj, void *event_info)
69 const struct popup_ops *ops = data;
73 static void register_handlers(const struct popup_ops *ops)
77 if (vconf_notify_key_changed(
81 _E("Failed to register vconf");
85 eext_object_event_callback_add(win, EEXT_CALLBACK_BACK, event_back_key_up, (void*)ops);
88 static void unregister_handlers(const struct popup_ops *ops)
92 vconf_ignore_key_changed(VCONFKEY_PM_STATE, pm_state_changed);
96 eext_object_event_callback_del(win, EEXT_CALLBACK_BACK, event_back_key_up);
99 static int poweroff_launch(bundle *b, const struct popup_ops *ops)
101 register_handlers(ops);
105 static void poweroff_terminate(const struct popup_ops *ops)
107 unregister_handlers(ops);
110 static void poweroff_clicked(const struct popup_ops *ops)
112 Evas_Object *rect, *win;
113 Evas_Coord w, h, size;
114 static int bPowerOff = 0;
123 unload_simple_popup(ops);
129 rect = evas_object_rectangle_add(evas_object_evas_get(win));
130 evas_object_geometry_get(win, NULL, NULL, &w, &h);
132 evas_object_resize(rect, size, size);
133 evas_object_color_set(rect, 0, 0, 0, 255);
134 evas_object_show(rect);
136 if (vconf_set_int(VCONFKEY_SYSMAN_POWER_OFF_STATUS, SYSTEMD_STOP_POWER_OFF) != 0)
137 _E("Failed to request poweroff to deviced");
139 param[0] = POWER_OPERATION_OFF;
140 snprintf(data, sizeof(data), "0");
142 ret = popup_dbus_method_sync(POWER_BUS_NAME,
144 POWER_INTERFACE_NAME,
148 _E("Failed to request poweroff to deviced (%d)", ret);
151 static const struct popup_ops poweroff_ops = {
153 .show = load_simple_popup,
154 .title = "IDS_ST_BODY_POWER_OFF",
155 .content = "IDS_TPLATFORM_BODY_POWER_OFF_THE_DEVICE_Q",
156 .left_text = "IDS_COM_SK_CANCEL",
157 .right_text = "IDS_HS_BUTTON_POWER_OFF_ABB2",
158 .right = poweroff_clicked,
159 .pre = poweroff_launch,
160 .terminate = poweroff_terminate,
163 static __attribute__ ((constructor)) void poweroff_register_popup(void)
165 register_popup(&poweroff_ops);