power off: update the popup to use common functions
[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 <svi.h>
23 #include <sysman.h>
24 #include <Elementary.h>
25 #include <bundle.h>
26 #include <Ecore_X.h>
27 #include <utilX.h>
28 #include "common.h"
29
30 #define PREDEF_POWEROFF "poweroff"
31
32 static void response_poweroff_yes_clicked(void *data, Evas_Object * obj, void *event_info)
33 {
34         struct appdata *ad = (struct appdata *)data;
35         Evas_Object *rect;
36         Evas_Coord w, h, size;
37         static bool multi = false;
38
39         if (multi)
40                 return;
41         multi = true;
42
43         _I("OK clicked");
44
45         if (ad && ad->popup && ad->win_main) {
46                 release_evas_object(&(ad->popup));
47
48                 rect = evas_object_rectangle_add(evas_object_evas_get(ad->win_main));
49                 evas_object_geometry_get(ad->win_main, NULL, NULL, &w, &h);
50                 size = max(w, h);
51                 evas_object_resize(rect, size, size);
52                 evas_object_color_set(rect, 0, 0, 0, 255);
53                 evas_object_show(rect);
54         }
55
56 /*      if (vconf_set_int(VCONFKEY_SYSMAN_POWER_OFF_STATUS, SYSTEMD_STOP_POWER_OFF) != 0)*/
57         if (sysman_call_predef_action(PREDEF_POWEROFF, 0) == -1)
58                 _E("Failed to request poweroff to deviced");
59 }
60
61 static void response_poweroff_no_clicked(void *data, Evas_Object * obj, void *event_info)
62 {
63         _I("Cancel clicked");
64         object_cleanup(data);
65         popup_terminate();
66 }
67
68 static int show_poweroff_popup(struct appdata *ad)
69 {
70         if (!ad)
71                 return -EINVAL;
72
73         ad->popup = load_normal_popup(ad,
74                         _("IDS_ST_BODY_POWER_OFF"),
75                         _("IDS_COM_BODY_OUR_PHONE_WILL_SHUT_DOWN"),
76                         dgettext("sys_string","IDS_COM_SK_CANCEL"),
77                         response_poweroff_no_clicked,
78                         dgettext("sys_string","IDS_COM_SK_OK"),
79                         response_poweroff_yes_clicked);
80         if (!(ad->popup)) {
81                 _E("Failed to make popup");
82                 return -ENOMEM;
83         }
84
85         return 0;
86 }
87
88 static int app_create(void *data)
89 {
90         Evas_Object *win;
91         struct appdata *ad = data;
92         int ret;
93
94         ad->handler.def_term_fn = NULL;
95         ad->handler.def_timeout_fn = NULL;
96
97         win = create_win(PACKAGE);
98         if (win == NULL)
99                 return -1;
100
101         ad->win_main = win;
102
103         ret = appcore_set_i18n(LANG_DOMAIN, LOCALE_DIR);
104         if (ret != 0)
105                 _E("FAIL: appcore_set_i18n()");
106
107         return 0;
108 }
109
110 static int app_terminate(void *data)
111 {
112         struct appdata *ad = data;
113
114         release_evas_object(&(ad->win_main));
115
116         return 0;
117 }
118
119 static int app_pause(void *data)
120 {
121         return 0;
122 }
123
124 static int app_resume(void *data)
125 {
126         return 0;
127 }
128
129 static int app_reset(bundle *b, void *data)
130 {
131         struct appdata *ad = data;
132         int ret;
133
134         if (syspopup_has_popup(b)) {
135                 syspopup_reset(b);
136                 return 0;
137         }
138
139         ret = syspopup_create(b, &(ad->handler), ad->win_main, ad);
140         if (ret < 0) {
141                 _E("Failed to create syspopup(%d)", ret);
142                 goto out;
143         }
144
145         evas_object_show(ad->win_main);
146
147         ret = show_poweroff_popup(ad);
148         if (ret < 0)
149                 _E("Failed to show poweroff popup (%d)", ret);
150
151 out:
152         if (ret < 0)
153                 popup_terminate();
154
155         return ret;
156 }
157
158 int main(int argc, char *argv[])
159 {
160         struct appdata ad;
161
162         /* App life cycle management */
163         struct appcore_ops ops = {
164                 .create = app_create,
165                 .terminate = app_terminate,
166                 .pause = app_pause,
167                 .resume = app_resume,
168                 .reset = app_reset,
169         };
170
171         memset(&ad, 0x0, sizeof(struct appdata));
172         ops.data = &ad;
173
174         return appcore_efl_main(PACKAGE, &argc, &argv, &ops);
175 }