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 <Elementary.h>
24 #include <notification.h>
26 #include <tzsh_quickpanel_service.h>
30 #include "quickpanel-ui.h"
31 #include "quickpanel_def.h"
34 #include "setting_utils.h"
35 #include "settings_ipc.h"
37 #include "pager_common.h"
38 #include "preference.h"
40 #ifdef QP_SCREENREADER_ENABLE
41 #include "accessibility.h"
44 #ifdef QP_EMERGENCY_MODE_ENABLE
45 #include "emergency_mode.h"
48 static int quickpanel_settings_init(void *data);
49 static int quickpanel_settings_fini(void *data);
50 static int quickpanel_settings_suspend(void *data);
51 static int quickpanel_settings_resume(void *data);
52 static void quickpanel_settings_lang_changed(void *data);
53 static void quickpanel_settings_reflesh(void *data);
54 static Eina_Bool _module_is_enabled(QP_Module_Setting *module);
56 extern QP_Module_Setting wifi;
57 extern QP_Module_Setting gps;
58 extern QP_Module_Setting bluetooth;
59 extern QP_Module_Setting sound;
60 extern QP_Module_Setting rotate;
61 extern QP_Module_Setting mobile_data;
62 extern QP_Module_Setting flightmode;
63 extern QP_Module_Setting u_power_saving;
64 extern QP_Module_Setting tethering;
65 extern QP_Module_Setting assistive_light;
67 QP_Module settings = {
69 .init = quickpanel_settings_init,
70 .fini = quickpanel_settings_fini,
71 .suspend = quickpanel_settings_suspend,
72 .resume = quickpanel_settings_resume,
73 .lang_changed = quickpanel_settings_lang_changed,
74 .refresh = quickpanel_settings_reflesh,
78 GHashTable *module_table;
79 QP_Module_Setting *modules[];
92 static void _module_init(QP_Module_Setting *module)
94 if (module->init != NULL) {
95 module->loader = (QP_Setting_Loaded_Item *)calloc(1, sizeof(QP_Setting_Loaded_Item));
97 module->is_loaded = EINA_TRUE;
101 static void _module_fini(QP_Module_Setting *module)
103 if (module->fini != NULL) {
104 module->fini(module);
105 if (module->loader != NULL) {
106 free(module->loader);
107 module->loader = NULL;
108 module->is_loaded = EINA_FALSE;
113 static int _module_count_get(void)
117 for (i = 0; s_info.modules[i] != NULL; i++) {
124 static QP_Module_Setting *_module_get_by_name(const char *name)
126 retif(name == NULL, NULL, "invalid parameter");
127 retif(s_info.module_table == NULL, NULL, "invalid parameter");
129 return g_hash_table_lookup(s_info.module_table, name);
132 static Eina_Bool _module_is_enabled(QP_Module_Setting *module) {
133 retif(module == NULL, EINA_FALSE, "invalid parameter");
134 retif(module->name == NULL, EINA_FALSE, "invalid parameter");
136 if (strcmp(module->name, MODULE_BLANK) == 0) {
139 if (module->supported_get) {
140 if (module->supported_get() == 0)
146 static char *_preference_get(const char *key)
148 char line[PREF_LEN_VALUE_MAX + 1] = {0,};
150 if (quickpanel_preference_get(key, line) == QP_OK) {
151 DBG("quicksetting order from file:%s", line);
158 static int quickpanel_settings_init(void *data)
162 struct appdata *ad = data;
163 retif(ad == NULL, QP_FAIL, "Invalid parameter!");
165 mod_count = _module_count_get();
166 if (s_info.module_table != NULL) {
167 g_hash_table_remove_all(s_info.module_table);
168 g_hash_table_destroy(s_info.module_table);
169 s_info.module_table = NULL;
171 s_info.module_table = g_hash_table_new_full(g_str_hash, g_str_equal,
172 (GDestroyNotify)g_free,
174 if (s_info.module_table != NULL) {
175 for (i = 0; i < mod_count; i++) {
176 if (s_info.modules[i]->supported_get != NULL) {
177 if (s_info.modules[i]->supported_get() == 0) {
182 if (s_info.modules[i]->init != NULL && s_info.modules[i]->name != NULL) {
183 ERR("quickbutton %s is initialized", s_info.modules[i]->name);
184 DBG("quickbutton %s is initialized", s_info.modules[i]->name);
185 g_hash_table_insert(s_info.module_table,
186 g_strdup(s_info.modules[i]->name),
188 _module_init(s_info.modules[i]);
192 ERR("failed to create module has table");
196 quickpanel_settings_ipc_init(ad);
201 static int quickpanel_settings_fini(void *data)
205 struct appdata *ad = data;
206 retif(ad == NULL, QP_FAIL, "Invalid parameter!");
208 quickpanel_settings_ipc_fini(ad);
210 for (i = 0; s_info.modules[i] != NULL; i++) {
211 if (_module_is_enabled(s_info.modules[i]) == EINA_TRUE) {
212 _module_fini(s_info.modules[i]);
216 if (s_info.module_table) {
217 g_hash_table_remove_all(s_info.module_table);
218 g_hash_table_destroy(s_info.module_table);
219 s_info.module_table = NULL;
225 static int quickpanel_settings_suspend(void *data)
229 struct appdata *ad = data;
230 retif(ad == NULL, QP_FAIL, "Invalid parameter!");
232 for (i = 0; s_info.modules[i] != NULL; i++) {
233 if (_module_is_enabled(s_info.modules[i]) == EINA_TRUE) {
234 if ((s_info.modules[i])->suspend != NULL) {
235 (s_info.modules[i])->suspend(s_info.modules[i]);
243 static int quickpanel_settings_resume(void *data)
247 struct appdata *ad = data;
248 retif(ad == NULL, QP_FAIL, "Invalid parameter!");
250 for (i = 0; s_info.modules[i] != NULL; i++) {
251 if (_module_is_enabled(s_info.modules[i]) == EINA_TRUE) {
252 if ((s_info.modules[i])->resume != NULL) {
253 (s_info.modules[i])->resume(s_info.modules[i]);
261 static void quickpanel_settings_lang_changed(void *data)
264 struct appdata *ad = data;
265 retif(ad == NULL, , "Invalid parameter!");
267 for (i = 0; s_info.modules[i] != NULL; i++) {
268 if (_module_is_enabled(s_info.modules[i]) == EINA_TRUE) {
269 if ((s_info.modules[i])->lang_changed != NULL) {
270 (s_info.modules[i])->lang_changed(s_info.modules[i]);
276 static void quickpanel_settings_reflesh(void *data)
279 struct appdata *ad = data;
280 retif(ad == NULL, , "Invalid parameter!");
282 for (i = 0; s_info.modules[i] != NULL; i++) {
283 if (_module_is_enabled(s_info.modules[i]) == EINA_TRUE) {
284 if ((s_info.modules[i])->refresh != NULL) {
285 (s_info.modules[i])->refresh(s_info.modules[i]);
291 HAPI int quickpanel_settings_featured_list_validation_check(char *order)
293 int i = 0, is_valid = 0;
295 gchar **order_split = NULL;
296 QP_Module_Setting *mod = NULL;
297 retif(order == NULL, is_valid, "Invalid parameter!");
299 if (s_info.module_table == NULL) {
303 order_split = g_strsplit(order, ",", 0);
305 if (order_split != NULL) {
306 order_count = g_strv_length(order_split);
308 if (order_count >= QP_SETTING_NUM_MINIMUM_ICON) {
309 for (i = 0; i < order_count; i++) {
310 mod = _module_get_by_name(order_split[i]);
320 g_strfreev(order_split);
326 HAPI void quickpanel_settings_featured_list_get(Eina_List **list)
328 int i = 0, seq_count = 0;
329 int num_featured = 0;
330 int seq_added_count = 0;
331 gchar **params = NULL;
332 QP_Module_Setting *module = NULL;
333 retif(list == NULL, , "invalid data.");
334 char *sequence = _preference_get(PREF_QUICKSETTING_ORDER);
335 const char *default_sequence = quickpanel_preference_default_get(PREF_QUICKSETTING_ORDER);
337 char *num_featured_str = _preference_get(PREF_QUICKSETTING_FEATURED_NUM);
338 const char *default_num_featured_str = quickpanel_preference_default_get(PREF_QUICKSETTING_FEATURED_NUM);
340 if (sequence != NULL) {
341 params = g_strsplit(sequence, ",", 0);
344 params = g_strsplit(default_sequence, ",", 0);
347 if (num_featured_str != NULL) {
348 num_featured = atoi(num_featured_str);
349 free(num_featured_str);
351 if (default_num_featured_str != NULL) {
352 num_featured = atoi(default_num_featured_str);
354 num_featured = QP_SETTING_NUM_TOTAL_ICON;
358 if (params != NULL) {
359 seq_count = g_strv_length(params);
361 for (i = 0; i < seq_count; i++) {
362 if (seq_added_count >= num_featured){
366 module = _module_get_by_name(params[i]);
367 if (module != NULL) {
368 if (_module_is_enabled(module) == EINA_TRUE) {
369 *list = eina_list_append (*list, module);
379 HAPI void quickpanel_settings_all_list_get(Eina_List **list)
381 int i = 0, seq_count = 0;
382 gchar **params = NULL;
383 QP_Module_Setting *module = NULL;
384 retif(list == NULL, , "invalid data.");
385 char *sequence = _preference_get(PREF_QUICKSETTING_ORDER);
386 const char *default_sequence = quickpanel_preference_default_get(PREF_QUICKSETTING_ORDER);
388 if (sequence != NULL) {
389 params = g_strsplit(sequence, ",", 0);
391 } else if (default_sequence != NULL){
392 params = g_strsplit(default_sequence, ",", 0);
395 if (params != NULL) {
396 seq_count = g_strv_length(params);
398 for (i = 0; i < seq_count; i++) {
399 module = _module_get_by_name(params[i]);
400 if (module != NULL) {
401 if (_module_is_enabled(module) == EINA_TRUE) {
402 *list = eina_list_append (*list, module);
411 HAPI void quickpanel_setting_save_list_to_file(Eina_List *list, int num_featured)
415 QP_Module_Setting *module = NULL;
417 retif(list == NULL, , "invalid parameter");
424 EINA_LIST_FOREACH_SAFE(list, l, l_next, module) {
428 if (module->name == NULL) {
431 if (_module_is_enabled(module) == EINA_FALSE) {
436 base = g_strdup(module->name);
439 temp = g_strconcat(base, ",", module->name, NULL);
440 if (base != NULL) g_free(base);
447 if (quickpanel_preference_set(PREF_QUICKSETTING_ORDER, base) == QP_FAIL) {
448 ERR("failed to write quicksetting order");
451 snprintf(buf, sizeof(buf) - 1, "%d", num_featured);
452 if (quickpanel_preference_set(PREF_QUICKSETTING_FEATURED_NUM, buf) == QP_FAIL) {
453 ERR("failed to write quicksetting featured num");
458 HAPI QP_Module_Setting *quickpanel_settings_module_get_by_name(const char *name)
460 return _module_get_by_name(name);
463 HAPI int quickpanel_settings_module_count_get(void)
465 return _module_count_get();