2 * Copyright (c) 2009-2015 Samsung Electronics Co., Ltd All Rights Reserved
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.
21 #include <syspopup_caller.h>
23 #include "quickpanel-ui.h"
25 #include "setting_utils.h"
26 #include "setting_module_api.h"
28 #define BUTTON_LABEL _("IDS_QP_BUTTON2_U_POWER_NSAVING_ABB")
29 #define BUTTON_ICON_NORMAL "quick_icon_ultra_power_saving.png"
30 #define BUTTON_ICON_HIGHLIGHT NULL
31 #define BUTTON_ICON_DIM NULL
32 #define PACKAGE_SETTING_MENU "setting-powersaving-efl"
33 #define SYSPOPUP_NAME "mode-syspopup"
35 static void _mouse_clicked_cb(void *data, Evas_Object *obj, const char *emission, const char *source);
37 static const char *_label_get(void) {
41 static const char *_icon_get(qp_setting_icon_image_type type) {
42 if (type == QP_SETTING_ICON_NORMAL) {
43 return BUTTON_ICON_NORMAL;
44 } else if (type == QP_SETTING_ICON_HIGHLIGHT) {
45 return BUTTON_ICON_HIGHLIGHT;
46 } else if (type == QP_SETTING_ICON_DIM) {
47 #ifdef BUTTON_ICON_DIM
48 return BUTTON_ICON_DIM;
55 static void _long_press_cb(void *data) {
56 #ifdef PACKAGE_SETTING_MENU
57 bundle *kb = bundle_create();
59 bundle_add(kb, "power_saving", "upsm");
60 qp_setting_icon_handler_longpress(PACKAGE_SETTING_MENU, kb);
63 ERR("failed to create the bunlde");
68 static int _is_need_to_show_disclaimer(void) {
69 int ret = 0, status = 0;
71 ret = vconf_get_bool(VCONFKEY_SETAPPL_UPSM_DO_NOT_SHOW_DISCLAIMER, &status);
72 if (ret == 0 && status) {
79 static void _turn_on(int is_on)
83 if (_is_need_to_show_disclaimer() == 1)
88 bundle_add(b, "viewtype", "disc");
90 qp_setting_icon_handler_longpress(PACKAGE_SETTING_MENU, b);
101 bundle_add(b, "_MODE_SYSTEM_POPUP_TYPE_", "POPUP_EMERGENCY_PSMODE_SETTING");
105 bundle_add(b, "_MODE_SYSTEM_POPUP_TYPE_", "POPUP_NORMAL_PSMODE");
107 syspopup_launch(SYSPOPUP_NAME, b);
112 ERR("failed to create a bundle");
117 static void _view_update(Evas_Object *view, int state, int flag_extra_1, int flag_extra_2) {
118 Evas_Object *image = NULL;
119 const char *icon_path = NULL;
121 qp_setting_icon_state_set(view, state);
123 if (state == ICON_VIEW_STATE_ON) {
124 #ifdef BUTTON_ICON_HIGHLIGHT
125 icon_path = BUTTON_ICON_HIGHLIGHT;
127 } else if (state == ICON_VIEW_STATE_DIM) {
128 #ifdef BUTTON_ICON_DIM
129 icon_path = BUTTON_ICON_DIM;
132 icon_path = BUTTON_ICON_NORMAL;
135 if (icon_path == NULL) {
136 icon_path = BUTTON_ICON_NORMAL;
138 image = qp_setting_icon_image_new(view, icon_path);
139 qp_setting_icon_content_set(view, image);
140 qp_setting_icon_text_set(view, BUTTON_LABEL, state);
143 static void _status_update(QP_Module_Setting *module, int flag_extra_1, int flag_extra_2) {
146 retif(module == NULL, , "Invalid parameter!");
148 ret = vconf_get_int(VCONFKEY_SETAPPL_PSMODE, &status);
149 msgif(ret != 0, "fail to get VCONFKEY_SETAPPL_PSMODE:%d", ret);
151 if (status == SETTING_PSMODE_EMERGENCY) {
152 qp_setting_module_icon_state_set(module, ICON_VIEW_STATE_ON);
154 qp_setting_module_icon_state_set(module, ICON_VIEW_STATE_OFF);
157 qp_setting_module_icon_view_update(module,
158 qp_setting_module_icon_state_get(module),
162 static void _mouse_clicked_cb(void *data,
163 Evas_Object *obj, const char *emission, const char *source) {
164 QP_Module_Setting *module = (QP_Module_Setting *)data;
165 retif(module == NULL, , "Invalid parameter!");
167 if (qp_setting_module_icon_state_get(module) == ICON_VIEW_STATE_ON) {
174 static void _powersave_vconf_cb(keynode_t *node, void *data) {
175 _status_update(data, FLAG_VALUE_VOID, FLAG_VALUE_VOID);
178 static int _register_module_event_handler(void *data) {
181 ret = vconf_notify_key_changed(VCONFKEY_SETAPPL_PSMODE,
182 _powersave_vconf_cb, data);
183 msgif(ret != 0, "failed to notify key(VCONFKEY_SETAPPL_PSMODE) : %d", ret);
188 static int _unregister_module_event_handler(void *data) {
191 ret = vconf_ignore_key_changed(VCONFKEY_SETAPPL_PSMODE,
192 _powersave_vconf_cb);
193 msgif(ret != 0, "failed to ignore key(VCONFKEY_SETAPPL_PSMODE) : %d", ret);
198 /****************************************************************************
200 * Quickpanel Item functions
202 ****************************************************************************/
203 static int _init(void *data) {
206 ret = _register_module_event_handler(data);
211 static int _fini(void *data) {
214 ret = _unregister_module_event_handler(data);
219 static void _lang_changed(void *data) {
220 QP_Module_Setting *module = (QP_Module_Setting *)data;
221 retif(module == NULL, , "Invalid parameter!");
223 qp_setting_module_icon_view_update_text(module);
226 static void _refresh(void *data) {
227 QP_Module_Setting *module = (QP_Module_Setting *)data;
228 retif(module == NULL, , "Invalid parameter!");
230 qp_setting_module_icon_view_update_text(module);
233 QP_Module_Setting u_power_saving = {
234 .name = "u_power_saving",
237 .lang_changed = _lang_changed,
239 .icon_get = _icon_get,
240 .label_get = _label_get,
241 .view_update = _view_update,
242 .status_update = _status_update,
243 .handler_longpress = _long_press_cb,
244 .handler_press = _mouse_clicked_cb,