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.
23 #include "quickpanel-ui.h"
24 #include "quickpanel_def.h"
27 #include "setting_utils.h"
28 #include "settings_ipc.h"
29 #include "pager_common.h"
30 #ifdef QP_SCREENREADER_ENABLE
31 #include "accessibility.h"
33 #include "preference.h"
34 #ifdef QP_EMERGENCY_MODE_ENABLE
35 #include "emergency_mode.h"
37 #include "configuration.h"
39 static int quickpanel_settings_init(void *data);
40 static int quickpanel_settings_fini(void *data);
41 static int quickpanel_settings_suspend(void *data);
42 static int quickpanel_settings_resume(void *data);
43 static void quickpanel_settings_lang_changed(void *data);
44 static void quickpanel_settings_reflesh(void *data);
45 static Eina_Bool _module_is_enabled(QP_Module_Setting *module);
47 extern QP_Module_Setting wifi;
48 extern QP_Module_Setting gps;
49 extern QP_Module_Setting bluetooth;
50 extern QP_Module_Setting sound;
51 extern QP_Module_Setting rotate;
52 extern QP_Module_Setting mobile_data;
53 extern QP_Module_Setting flightmode;
54 extern QP_Module_Setting u_power_saving;
55 extern QP_Module_Setting tethering;
56 extern QP_Module_Setting assistive_light;
58 QP_Module settings = {
60 .init = quickpanel_settings_init,
61 .fini = quickpanel_settings_fini,
62 .suspend = quickpanel_settings_suspend,
63 .resume = quickpanel_settings_resume,
64 .lang_changed = quickpanel_settings_lang_changed,
65 .refresh = quickpanel_settings_reflesh,
69 GHashTable *module_table;
70 QP_Module_Setting *modules[];
83 static void _module_init(QP_Module_Setting *module)
85 if (module->init != NULL) {
86 module->loader = (QP_Setting_Loaded_Item *)calloc(1, sizeof(QP_Setting_Loaded_Item));
88 module->is_loaded = EINA_TRUE;
92 static void _module_fini(QP_Module_Setting *module)
94 if (module->fini != NULL) {
96 if (module->loader != NULL) {
98 module->loader = NULL;
99 module->is_loaded = EINA_FALSE;
104 static int _module_count_get(void)
108 for (i = 0; s_info.modules[i] != NULL; i++) {
115 static QP_Module_Setting *_module_get_by_name(const char *name)
117 retif(name == NULL, NULL, "invalid parameter");
118 retif(s_info.module_table == NULL, NULL, "invalid parameter");
120 return g_hash_table_lookup(s_info.module_table, name);
123 static Eina_Bool _module_is_enabled(QP_Module_Setting *module) {
124 retif(module == NULL, EINA_FALSE, "invalid parameter");
125 retif(module->name == NULL, EINA_FALSE, "invalid parameter");
127 if (strcmp(module->name, MODULE_BLANK) == 0) {
130 if (module->supported_get) {
131 if (module->supported_get() == 0)
137 static char *_preference_get(const char *key)
139 char line[PREF_LEN_VALUE_MAX + 1] = {0,};
141 if (quickpanel_preference_get(key, line) == QP_OK) {
142 DBG("quicksetting order from file:%s", line);
149 static void _reservied_list_get_with_active_list(Eina_List **list)
151 int i = 0, module_count = 0;
152 Eina_List *list_featured = NULL;
153 retif(list == NULL, , "invalid data.");
155 quickpanel_settings_featured_list_get(&list_featured);
156 retif(list_featured == NULL, , "failed to get default active list");
158 module_count = _module_count_get();
160 for (i = 0; i < module_count; i++) {
161 if (eina_list_data_find(list_featured, s_info.modules[i]) == NULL){
162 if (_module_is_enabled(s_info.modules[i]) == EINA_TRUE) {
163 *list = eina_list_append (*list, s_info.modules[i]);
168 eina_list_free(list_featured);
171 static int quickpanel_settings_init(void *data)
175 struct appdata *ad = data;
176 retif(ad == NULL, QP_FAIL, "Invalid parameter!");
178 mod_count = _module_count_get();
179 if (s_info.module_table != NULL) {
180 g_hash_table_remove_all(s_info.module_table);
181 g_hash_table_destroy(s_info.module_table);
182 s_info.module_table = NULL;
184 s_info.module_table = g_hash_table_new_full(g_str_hash, g_str_equal,
185 (GDestroyNotify)g_free,
187 if (s_info.module_table != NULL) {
188 for (i = 0; i < mod_count; i++) {
189 if (s_info.modules[i]->supported_get != NULL) {
190 if (s_info.modules[i]->supported_get() == 0) {
195 if (s_info.modules[i]->init != NULL && s_info.modules[i]->name != NULL) {
196 ERR("quickbutton %s is initialized", s_info.modules[i]->name);
197 DBG("quickbutton %s is initialized", s_info.modules[i]->name);
198 g_hash_table_insert(s_info.module_table,
199 g_strdup(s_info.modules[i]->name),
201 _module_init(s_info.modules[i]);
205 ERR("failed to create module has table");
209 quickpanel_settings_ipc_init(ad);
214 static int quickpanel_settings_fini(void *data)
218 struct appdata *ad = data;
219 retif(ad == NULL, QP_FAIL, "Invalid parameter!");
221 quickpanel_settings_ipc_fini(ad);
223 for (i = 0; s_info.modules[i] != NULL; i++) {
224 if (_module_is_enabled(s_info.modules[i]) == EINA_TRUE) {
225 _module_fini(s_info.modules[i]);
229 if (s_info.module_table) {
230 g_hash_table_remove_all(s_info.module_table);
231 g_hash_table_destroy(s_info.module_table);
232 s_info.module_table = NULL;
238 static int quickpanel_settings_suspend(void *data)
242 struct appdata *ad = data;
243 retif(ad == NULL, QP_FAIL, "Invalid parameter!");
245 for (i = 0; s_info.modules[i] != NULL; i++) {
246 if (_module_is_enabled(s_info.modules[i]) == EINA_TRUE) {
247 if ((s_info.modules[i])->suspend != NULL) {
248 (s_info.modules[i])->suspend(s_info.modules[i]);
256 static int quickpanel_settings_resume(void *data)
260 struct appdata *ad = data;
261 retif(ad == NULL, QP_FAIL, "Invalid parameter!");
263 for (i = 0; s_info.modules[i] != NULL; i++) {
264 if (_module_is_enabled(s_info.modules[i]) == EINA_TRUE) {
265 if ((s_info.modules[i])->resume != NULL) {
266 (s_info.modules[i])->resume(s_info.modules[i]);
274 static void quickpanel_settings_lang_changed(void *data)
277 struct appdata *ad = data;
278 retif(ad == NULL, , "Invalid parameter!");
280 for (i = 0; s_info.modules[i] != NULL; i++) {
281 if (_module_is_enabled(s_info.modules[i]) == EINA_TRUE) {
282 if ((s_info.modules[i])->lang_changed != NULL) {
283 (s_info.modules[i])->lang_changed(s_info.modules[i]);
289 static void quickpanel_settings_reflesh(void *data)
292 struct appdata *ad = data;
293 retif(ad == NULL, , "Invalid parameter!");
295 for (i = 0; s_info.modules[i] != NULL; i++) {
296 if (_module_is_enabled(s_info.modules[i]) == EINA_TRUE) {
297 if ((s_info.modules[i])->refresh != NULL) {
298 (s_info.modules[i])->refresh(s_info.modules[i]);
304 HAPI int quickpanel_settings_featured_list_validation_check(char *order)
306 int i = 0, is_valid = 0;
308 gchar **order_split = NULL;
309 QP_Module_Setting *mod = NULL;
310 retif(order == NULL, is_valid, "Invalid parameter!");
312 if (s_info.module_table == NULL) {
316 order_split = g_strsplit(order, ",", 0);
318 if (order_split != NULL) {
319 order_count = g_strv_length(order_split);
321 if (order_count >= QP_SETTING_NUM_MINIMUM_ICON) {
322 for (i = 0; i < order_count; i++) {
323 mod = _module_get_by_name(order_split[i]);
333 g_strfreev(order_split);
339 HAPI void quickpanel_settings_featured_list_get(Eina_List **list)
341 int i = 0, seq_count = 0;
342 int num_featured = 0;
343 int seq_added_count = 0;
344 gchar **params = NULL;
345 QP_Module_Setting *module = NULL;
346 retif(list == NULL, , "invalid data.");
347 char *sequence = _preference_get(PREF_QUICKSETTING_ORDER);
348 const char *default_sequence = quickpanel_preference_default_get(PREF_QUICKSETTING_ORDER);
350 char *num_featured_str = _preference_get(PREF_QUICKSETTING_FEATURED_NUM);
351 const char *default_num_featured_str = quickpanel_preference_default_get(PREF_QUICKSETTING_FEATURED_NUM);
353 if (sequence != NULL) {
354 params = g_strsplit(sequence, ",", 0);
357 params = g_strsplit(default_sequence, ",", 0);
360 if (num_featured_str != NULL) {
361 num_featured = atoi(num_featured_str);
362 free(num_featured_str);
364 if (default_num_featured_str != NULL) {
365 num_featured = atoi(default_num_featured_str);
367 num_featured = QP_SETTING_NUM_TOTAL_ICON;
371 if (params != NULL) {
372 seq_count = g_strv_length(params);
374 for (i = 0; i < seq_count; i++) {
375 if (seq_added_count >= num_featured){
379 module = _module_get_by_name(params[i]);
380 if (module != NULL) {
381 if (_module_is_enabled(module) == EINA_TRUE) {
382 *list = eina_list_append (*list, module);
392 HAPI void quickpanel_settings_all_list_get(Eina_List **list)
394 int i = 0, seq_count = 0;
395 gchar **params = NULL;
396 QP_Module_Setting *module = NULL;
397 retif(list == NULL, , "invalid data.");
398 char *sequence = _preference_get(PREF_QUICKSETTING_ORDER);
399 const char *default_sequence = quickpanel_preference_default_get(PREF_QUICKSETTING_ORDER);
401 if (sequence != NULL) {
402 params = g_strsplit(sequence, ",", 0);
404 } else if (default_sequence != NULL){
405 params = g_strsplit(default_sequence, ",", 0);
408 if (params != NULL) {
409 seq_count = g_strv_length(params);
411 for (i = 0; i < seq_count; i++) {
412 module = _module_get_by_name(params[i]);
413 if (module != NULL) {
414 if (_module_is_enabled(module) == EINA_TRUE) {
415 *list = eina_list_append (*list, module);
424 HAPI void quickpanel_setting_save_list_to_file(Eina_List *list, int num_featured)
428 QP_Module_Setting *module = NULL;
430 retif(list == NULL, , "invalid parameter");
437 EINA_LIST_FOREACH_SAFE(list, l, l_next, module) {
441 if (module->name == NULL) {
444 if (_module_is_enabled(module) == EINA_FALSE) {
449 base = g_strdup(module->name);
452 temp = g_strconcat(base, ",", module->name, NULL);
453 if (base != NULL) g_free(base);
460 if (quickpanel_preference_set(PREF_QUICKSETTING_ORDER, base) == QP_FAIL) {
461 ERR("failed to write quicksetting order");
464 snprintf(buf, sizeof(buf) - 1, "%d", num_featured);
465 if (quickpanel_preference_set(PREF_QUICKSETTING_FEATURED_NUM, buf) == QP_FAIL) {
466 ERR("failed to write quicksetting featured num");
471 HAPI QP_Module_Setting *quickpanel_settings_module_get_by_name(const char *name)
473 return _module_get_by_name(name);
476 HAPI int quickpanel_settings_module_count_get(void)
478 return _module_count_get();