tizen 2.4 release
[apps/home/quickpanel.git] / daemon / settings / modules / ultra_power_saving.c
1 /*
2  * Copyright (c) 2009-2015 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
18
19 #include <Elementary.h>
20
21 #include <app.h>
22 #include <vconf.h>
23 #include <syspopup_caller.h>
24 #include <bundle_internal.h>
25 #include <tzsh.h>
26 #include <tzsh_quickpanel_service.h>
27
28 #include "common.h"
29 #include "quickpanel-ui.h"
30 #include "settings.h"
31 #include "setting_utils.h"
32 #include "setting_module_api.h"
33 #include "settings_icon_common.h"
34
35 #define BUTTON_LABEL _("IDS_QP_BUTTON2_U_POWER_NSAVING_ABB")
36 #define BUTTON_ICON_NORMAL "quick_icon_ultra_power_saving.png"
37 #define BUTTON_ICON_HIGHLIGHT NULL
38 #define BUTTON_ICON_DIM NULL
39 #define PACKAGE_SETTING_MENU "setting-powersaving-efl"
40 #define SYSPOPUP_NAME "mode-syspopup"
41
42 static void _mouse_clicked_cb(void *data, Evas_Object *obj, const char *emission, const char *source);
43
44 static const char *_label_get(void)
45 {
46         return BUTTON_LABEL;
47 }
48
49 static const char *_icon_get(qp_setting_icon_image_type type)
50 {
51         if (type == QP_SETTING_ICON_NORMAL) {
52                 return BUTTON_ICON_NORMAL;
53         } else if (type == QP_SETTING_ICON_HIGHLIGHT) {
54                 return BUTTON_ICON_HIGHLIGHT;
55         } else if (type == QP_SETTING_ICON_DIM) {
56 #ifdef BUTTON_ICON_DIM
57                 return BUTTON_ICON_DIM;
58 #endif
59         }
60
61         return NULL;
62 }
63
64 static void _long_press_cb(void *data)
65 {
66 #ifdef PACKAGE_SETTING_MENU
67         bundle *kb = bundle_create();
68         if (kb != NULL) {
69                 bundle_add(kb, "power_saving", "upsm");
70                 quickpanel_setting_icon_handler_longpress(PACKAGE_SETTING_MENU, kb);
71                 bundle_free(kb);
72         } else {
73                 ERR("failed to create the bunlde");
74         }
75 #endif
76 }
77
78 #if 0
79 static int _is_need_to_show_disclaimer(void) {
80         int ret = 0, status = 0;
81
82         ret = vconf_get_bool(VCONFKEY_SETAPPL_UPSM_DO_NOT_SHOW_DISCLAIMER, &status);
83         if (ret == 0 && status) {
84                 return 0;
85         }
86
87         return 1;
88 }
89 #endif
90
91 static void _turn_on(int is_on)
92 {
93         bundle *b = NULL;
94
95         //if(_is_need_to_show_disclaimer() == 1)
96         {
97                 b = bundle_create();
98                 if (b != NULL) {
99                         bundle_add(b, "viewtype", "disc");
100
101                         quickpanel_setting_icon_handler_longpress(PACKAGE_SETTING_MENU, b);
102                         bundle_free(b);
103                 }
104         }
105         /*else
106           {
107           b = bundle_create();
108           if (b != NULL) {
109           if (is_on) {
110           bundle_add(b, "_MODE_SYSTEM_POPUP_TYPE_", "POPUP_EMERGENCY_PSMODE_SETTING");
111           } else {
112           bundle_add(b, "_MODE_SYSTEM_POPUP_TYPE_", "POPUP_NORMAL_PSMODE");
113           }
114           syspopup_launch(SYSPOPUP_NAME, b);
115           bundle_free(b);
116           } else {
117           ERR("failed to create a bundle");
118           }
119           }*/
120 }
121
122 static void _view_update(Evas_Object *view, int state, int flag_extra_1, int flag_extra_2)
123 {
124         Evas_Object *image = NULL;
125         const char *icon_path = NULL;
126
127         quickpanel_setting_icon_state_set(view, state);
128
129         if (state == ICON_VIEW_STATE_ON) {
130 #ifdef BUTTON_ICON_HIGHLIGHT
131                 icon_path = BUTTON_ICON_HIGHLIGHT;
132 #endif
133         } else if (state == ICON_VIEW_STATE_DIM) {
134 #ifdef BUTTON_ICON_DIM
135                 icon_path = BUTTON_ICON_DIM;
136 #endif
137         } else {
138                 icon_path = BUTTON_ICON_NORMAL;
139         }
140
141         if (icon_path == NULL) {
142                 icon_path = BUTTON_ICON_NORMAL;
143         }
144         image = quickpanel_setting_icon_image_new(view, icon_path);
145         quickpanel_setting_icon_content_set(view, image);
146         quickpanel_setting_icon_text_set(view, BUTTON_LABEL, state);
147 }
148
149 static void _status_update(QP_Module_Setting *module, int flag_extra_1, int flag_extra_2)
150 {
151         int ret = 0;
152         int status = 0;
153         retif(module == NULL, , "Invalid parameter!");
154
155         ret = vconf_get_int(VCONFKEY_SETAPPL_PSMODE, &status);
156         msgif(ret != 0, "fail to get VCONFKEY_SETAPPL_PSMODE:%d", ret);
157
158         if (status == SETTING_PSMODE_EMERGENCY) {
159                 quickpanel_setting_module_icon_state_set(module, ICON_VIEW_STATE_ON);
160         } else {
161                 quickpanel_setting_module_icon_state_set(module, ICON_VIEW_STATE_OFF);
162         }
163
164         quickpanel_setting_module_icon_view_update(module,
165                         quickpanel_setting_module_icon_state_get(module),
166                         FLAG_VALUE_VOID);
167 }
168
169 static void _mouse_clicked_cb(void *data, Evas_Object *obj, const char *emission, const char *source)
170 {
171         QP_Module_Setting *module = (QP_Module_Setting *)data;
172         retif(module == NULL, , "Invalid parameter!");
173
174         if (quickpanel_setting_module_icon_state_get(module) == ICON_VIEW_STATE_ON) {
175                 _turn_on(0);
176         } else {
177                 _turn_on(1);
178         }
179 }
180
181 static void _powersave_vconf_cb(keynode_t *node, void *data)
182 {
183         _status_update(data, FLAG_VALUE_VOID, FLAG_VALUE_VOID);
184 }
185
186 static int _register_module_event_handler(void *data)
187 {
188         int ret = 0;
189
190         ret = vconf_notify_key_changed(VCONFKEY_SETAPPL_PSMODE,
191                         _powersave_vconf_cb, data);
192         msgif(ret != 0, "failed to notify key(VCONFKEY_SETAPPL_PSMODE) : %d", ret);
193
194         return QP_OK;
195 }
196
197 static int _unregister_module_event_handler(void *data)
198 {
199         int ret = 0;
200
201         ret = vconf_ignore_key_changed(VCONFKEY_SETAPPL_PSMODE,
202                         _powersave_vconf_cb);
203         msgif(ret != 0, "failed to ignore key(VCONFKEY_SETAPPL_PSMODE) : %d", ret);
204
205         return QP_OK;
206 }
207
208 /****************************************************************************
209  *
210  * Quickpanel Item functions
211  *
212  ****************************************************************************/
213 static int _init(void *data)
214 {
215         int ret = QP_OK;
216
217         ret = _register_module_event_handler(data);
218
219         return ret;
220 }
221
222 static int _fini(void *data)
223 {
224         int ret = QP_OK;
225
226         ret = _unregister_module_event_handler(data);
227
228         return ret;
229 }
230
231 static void _lang_changed(void *data)
232 {
233         QP_Module_Setting *module = (QP_Module_Setting *)data;
234         retif(module == NULL, , "Invalid parameter!");
235
236         quickpanel_setting_module_icon_view_update_text(module);
237 }
238
239 static void _refresh(void *data)
240 {
241         QP_Module_Setting *module = (QP_Module_Setting *)data;
242         retif(module == NULL, , "Invalid parameter!");
243
244         quickpanel_setting_module_icon_view_update_text(module);
245 }
246
247 QP_Module_Setting u_power_saving = {
248         .name                           = "u_power_saving",
249         .init                           = _init,
250         .fini                           = _fini,
251         .lang_changed           = _lang_changed,
252         .refresh                        = _refresh,
253         .icon_get                       = _icon_get,
254         .label_get                      = _label_get,
255         .view_update        = _view_update,
256         .status_update          = _status_update,
257         .handler_longpress              = _long_press_cb,
258         .handler_press          = _mouse_clicked_cb,
259 };