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.
19 #include <Elementary.h>
23 #include <syspopup_caller.h>
24 #include <bundle_internal.h>
26 #include <tzsh_quickpanel_service.h>
29 #include "quickpanel-ui.h"
31 #include "setting_utils.h"
32 #include "setting_module_api.h"
33 #include "settings_icon_common.h"
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"
42 static void _mouse_clicked_cb(void *data, Evas_Object *obj, const char *emission, const char *source);
44 static const char *_label_get(void)
49 static const char *_icon_get(qp_setting_icon_image_type type)
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;
64 static void _long_press_cb(void *data)
66 #ifdef PACKAGE_SETTING_MENU
67 bundle *kb = bundle_create();
69 bundle_add(kb, "power_saving", "upsm");
70 quickpanel_setting_icon_handler_longpress(PACKAGE_SETTING_MENU, kb);
73 ERR("failed to create the bunlde");
79 static int _is_need_to_show_disclaimer(void) {
80 int ret = 0, status = 0;
82 ret = vconf_get_bool(VCONFKEY_SETAPPL_UPSM_DO_NOT_SHOW_DISCLAIMER, &status);
83 if (ret == 0 && status) {
91 static void _turn_on(int is_on)
95 //if(_is_need_to_show_disclaimer() == 1)
99 bundle_add(b, "viewtype", "disc");
101 quickpanel_setting_icon_handler_longpress(PACKAGE_SETTING_MENU, b);
110 bundle_add(b, "_MODE_SYSTEM_POPUP_TYPE_", "POPUP_EMERGENCY_PSMODE_SETTING");
112 bundle_add(b, "_MODE_SYSTEM_POPUP_TYPE_", "POPUP_NORMAL_PSMODE");
114 syspopup_launch(SYSPOPUP_NAME, b);
117 ERR("failed to create a bundle");
122 static void _view_update(Evas_Object *view, int state, int flag_extra_1, int flag_extra_2)
124 Evas_Object *image = NULL;
125 const char *icon_path = NULL;
127 quickpanel_setting_icon_state_set(view, state);
129 if (state == ICON_VIEW_STATE_ON) {
130 #ifdef BUTTON_ICON_HIGHLIGHT
131 icon_path = BUTTON_ICON_HIGHLIGHT;
133 } else if (state == ICON_VIEW_STATE_DIM) {
134 #ifdef BUTTON_ICON_DIM
135 icon_path = BUTTON_ICON_DIM;
138 icon_path = BUTTON_ICON_NORMAL;
141 if (icon_path == NULL) {
142 icon_path = BUTTON_ICON_NORMAL;
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);
149 static void _status_update(QP_Module_Setting *module, int flag_extra_1, int flag_extra_2)
153 retif(module == NULL, , "Invalid parameter!");
155 ret = vconf_get_int(VCONFKEY_SETAPPL_PSMODE, &status);
156 msgif(ret != 0, "fail to get VCONFKEY_SETAPPL_PSMODE:%d", ret);
158 if (status == SETTING_PSMODE_EMERGENCY) {
159 quickpanel_setting_module_icon_state_set(module, ICON_VIEW_STATE_ON);
161 quickpanel_setting_module_icon_state_set(module, ICON_VIEW_STATE_OFF);
164 quickpanel_setting_module_icon_view_update(module,
165 quickpanel_setting_module_icon_state_get(module),
169 static void _mouse_clicked_cb(void *data, Evas_Object *obj, const char *emission, const char *source)
171 QP_Module_Setting *module = (QP_Module_Setting *)data;
172 retif(module == NULL, , "Invalid parameter!");
174 if (quickpanel_setting_module_icon_state_get(module) == ICON_VIEW_STATE_ON) {
181 static void _powersave_vconf_cb(keynode_t *node, void *data)
183 _status_update(data, FLAG_VALUE_VOID, FLAG_VALUE_VOID);
186 static int _register_module_event_handler(void *data)
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);
197 static int _unregister_module_event_handler(void *data)
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);
208 /****************************************************************************
210 * Quickpanel Item functions
212 ****************************************************************************/
213 static int _init(void *data)
217 ret = _register_module_event_handler(data);
222 static int _fini(void *data)
226 ret = _unregister_module_event_handler(data);
231 static void _lang_changed(void *data)
233 QP_Module_Setting *module = (QP_Module_Setting *)data;
234 retif(module == NULL, , "Invalid parameter!");
236 quickpanel_setting_module_icon_view_update_text(module);
239 static void _refresh(void *data)
241 QP_Module_Setting *module = (QP_Module_Setting *)data;
242 retif(module == NULL, , "Invalid parameter!");
244 quickpanel_setting_module_icon_view_update_text(module);
247 QP_Module_Setting u_power_saving = {
248 .name = "u_power_saving",
251 .lang_changed = _lang_changed,
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,