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;
62 QP_Module settings = {
64 .init = quickpanel_settings_init,
65 .fini = quickpanel_settings_fini,
66 .suspend = quickpanel_settings_suspend,
67 .resume = quickpanel_settings_resume,
68 .lang_changed = quickpanel_settings_lang_changed,
69 .refresh = quickpanel_settings_reflesh,
73 GHashTable *module_table;
74 QP_Module_Setting *modules[];
87 static void _module_init(QP_Module_Setting *module)
89 if (module->init != NULL) {
90 module->loader = (QP_Setting_Loaded_Item *)calloc(1, sizeof(QP_Setting_Loaded_Item));
92 module->is_loaded = EINA_TRUE;
96 static void _module_fini(QP_Module_Setting *module)
98 if (module->fini != NULL) {
100 if (module->loader != NULL) {
101 free(module->loader);
102 module->loader = NULL;
103 module->is_loaded = EINA_FALSE;
108 static int _module_count_get(void)
112 for (i = 0; s_info.modules[i] != NULL; i++) {
119 static QP_Module_Setting *_module_get_by_name(const char *name)
121 retif(name == NULL, NULL, "invalid parameter");
122 retif(s_info.module_table == NULL, NULL, "invalid parameter");
124 return g_hash_table_lookup(s_info.module_table, name);
127 static Eina_Bool _module_is_enabled(QP_Module_Setting *module)
129 retif(module == NULL, EINA_FALSE, "invalid parameter");
130 retif(module->name == NULL, EINA_FALSE, "invalid parameter");
132 if (strcmp(module->name, MODULE_BLANK) == 0) {
135 if (module->supported_get) {
136 if (module->supported_get() == 0)
142 static int quickpanel_settings_init(void *data)
146 struct appdata *ad = data;
147 retif(ad == NULL, QP_FAIL, "Invalid parameter!");
149 mod_count = _module_count_get();
150 if (s_info.module_table != NULL) {
151 g_hash_table_remove_all(s_info.module_table);
152 g_hash_table_destroy(s_info.module_table);
153 s_info.module_table = NULL;
155 s_info.module_table = g_hash_table_new_full(g_str_hash, g_str_equal,
156 (GDestroyNotify)g_free,
158 if (s_info.module_table != NULL) {
159 for (i = 0; i < mod_count; i++) {
160 if (s_info.modules[i]->supported_get != NULL) {
161 if (s_info.modules[i]->supported_get() == 0) {
166 if (s_info.modules[i]->init != NULL && s_info.modules[i]->name != NULL) {
167 ERR("quickbutton %s is initialized", s_info.modules[i]->name);
168 DBG("quickbutton %s is initialized", s_info.modules[i]->name);
169 g_hash_table_insert(s_info.module_table,
170 g_strdup(s_info.modules[i]->name),
172 _module_init(s_info.modules[i]);
176 ERR("failed to create module has table");
180 quickpanel_settings_ipc_init(ad);
185 static int quickpanel_settings_fini(void *data)
189 struct appdata *ad = data;
190 retif(ad == NULL, QP_FAIL, "Invalid parameter!");
192 quickpanel_settings_ipc_fini(ad);
194 for (i = 0; s_info.modules[i] != NULL; i++) {
195 if (_module_is_enabled(s_info.modules[i]) == EINA_TRUE) {
196 _module_fini(s_info.modules[i]);
200 if (s_info.module_table) {
201 g_hash_table_remove_all(s_info.module_table);
202 g_hash_table_destroy(s_info.module_table);
203 s_info.module_table = NULL;
209 static int quickpanel_settings_suspend(void *data)
213 struct appdata *ad = data;
214 retif(ad == NULL, QP_FAIL, "Invalid parameter!");
216 for (i = 0; s_info.modules[i] != NULL; i++) {
217 if (_module_is_enabled(s_info.modules[i]) == EINA_TRUE) {
218 if ((s_info.modules[i])->suspend != NULL) {
219 (s_info.modules[i])->suspend(s_info.modules[i]);
227 static int quickpanel_settings_resume(void *data)
231 struct appdata *ad = data;
232 retif(ad == NULL, QP_FAIL, "Invalid parameter!");
234 for (i = 0; s_info.modules[i] != NULL; i++) {
235 if (_module_is_enabled(s_info.modules[i]) == EINA_TRUE) {
236 if ((s_info.modules[i])->resume != NULL) {
237 (s_info.modules[i])->resume(s_info.modules[i]);
245 static void quickpanel_settings_lang_changed(void *data)
248 struct appdata *ad = data;
249 retif(ad == NULL, , "Invalid parameter!");
251 for (i = 0; s_info.modules[i] != NULL; i++) {
252 if (_module_is_enabled(s_info.modules[i]) == EINA_TRUE) {
253 if ((s_info.modules[i])->lang_changed != NULL) {
254 (s_info.modules[i])->lang_changed(s_info.modules[i]);
260 static void quickpanel_settings_reflesh(void *data)
263 struct appdata *ad = data;
264 retif(ad == NULL, , "Invalid parameter!");
266 for (i = 0; s_info.modules[i] != NULL; i++) {
267 if (_module_is_enabled(s_info.modules[i]) == EINA_TRUE) {
268 if ((s_info.modules[i])->refresh != NULL) {
269 (s_info.modules[i])->refresh(s_info.modules[i]);
275 HAPI int quickpanel_settings_featured_list_validation_check(char *order)
277 int i = 0, is_valid = 0;
279 gchar **order_split = NULL;
280 QP_Module_Setting *mod = NULL;
281 retif(order == NULL, is_valid, "Invalid parameter!");
283 if (s_info.module_table == NULL) {
287 order_split = g_strsplit(order, ",", 0);
289 if (order_split != NULL) {
290 order_count = g_strv_length(order_split);
292 if (order_count >= QP_SETTING_NUM_MINIMUM_ICON) {
293 for (i = 0; i < order_count; i++) {
294 mod = _module_get_by_name(order_split[i]);
304 g_strfreev(order_split);
310 HAPI void quickpanel_settings_featured_list_get(Eina_List **list)
312 int i = 0, seq_count = 0;
313 int num_featured = 0;
314 int seq_added_count = 0;
315 gchar **params = NULL;
316 QP_Module_Setting *module = NULL;
317 char *sequence = NULL;
318 char *num_featured_str = NULL;
319 const char *default_sequence = quickpanel_preference_default_get(PREF_QUICKSETTING_ORDER);
320 const char *default_num_featured_str = quickpanel_preference_default_get(PREF_QUICKSETTING_FEATURED_NUM);
322 retif(list == NULL, , "invalid data.");
324 if (quickpanel_preference_get(PREF_QUICKSETTING_ORDER, &sequence) == QP_OK && sequence != NULL) {
325 DBG("preference_get key(%s) value(%s)", PREF_QUICKSETTING_ORDER, sequence);
326 params = g_strsplit(sequence, ",", 0);
329 params = g_strsplit(default_sequence, ",", 0);
332 if (quickpanel_preference_get(PREF_QUICKSETTING_FEATURED_NUM, &num_featured_str) == QP_OK && num_featured_str != NULL) {
333 DBG("preference_get key(%s) value(%s)", PREF_QUICKSETTING_FEATURED_NUM, num_featured_str);
334 num_featured = atoi(num_featured_str);
335 free(num_featured_str);
337 num_featured = atoi(default_num_featured_str);
342 if (params != NULL) {
343 seq_count = g_strv_length(params);
345 for (i = 0; i < seq_count; i++) {
346 if (seq_added_count >= num_featured){
350 module = _module_get_by_name(params[i]);
351 if (module != NULL) {
352 if (_module_is_enabled(module) == EINA_TRUE) {
353 *list = eina_list_append (*list, module);
363 HAPI void quickpanel_settings_all_list_get(Eina_List **list)
365 int i = 0, seq_count = 0;
366 gchar **params = NULL;
367 QP_Module_Setting *module = NULL;
368 retif(list == NULL, , "invalid data.");
369 char *sequence = NULL;
370 const char *default_sequence = quickpanel_preference_default_get(PREF_QUICKSETTING_ORDER);
372 if (quickpanel_preference_get(PREF_QUICKSETTING_ORDER, &sequence) == QP_OK && sequence != NULL) {
373 DBG("preference_get key(%s) value(%s)", PREF_QUICKSETTING_ORDER, sequence);
374 params = g_strsplit(sequence, ",", 0);
377 params = g_strsplit(default_sequence, ",", 0);
382 if (params != NULL) {
383 seq_count = g_strv_length(params);
385 for (i = 0; i < seq_count; i++) {
386 module = _module_get_by_name(params[i]);
387 if (module != NULL) {
388 if (_module_is_enabled(module) == EINA_TRUE) {
389 *list = eina_list_append (*list, module);
398 HAPI void quickpanel_setting_save_list_to_file(Eina_List *list, int num_featured)
402 QP_Module_Setting *module = NULL;
404 retif(list == NULL, , "invalid parameter");
411 EINA_LIST_FOREACH_SAFE(list, l, l_next, module) {
415 if (module->name == NULL) {
418 if (_module_is_enabled(module) == EINA_FALSE) {
423 base = g_strdup(module->name);
426 temp = g_strconcat(base, ",", module->name, NULL);
427 if (base != NULL) g_free(base);
434 if (quickpanel_preference_set(PREF_QUICKSETTING_ORDER, base) == QP_FAIL) {
435 ERR("failed to write quicksetting order");
438 snprintf(buf, sizeof(buf) - 1, "%d", num_featured);
439 if (quickpanel_preference_set(PREF_QUICKSETTING_FEATURED_NUM, buf) == QP_FAIL) {
440 ERR("failed to write quicksetting featured num");
445 HAPI QP_Module_Setting *quickpanel_settings_module_get_by_name(const char *name)
447 return _module_get_by_name(name);
450 HAPI int quickpanel_settings_module_count_get(void)
452 return _module_count_get();