diff options
author | jin0.kim <jin0.kim@samsung.com> | 2016-04-25 20:06:02 +0830 |
---|---|---|
committer | jin0.kim <jin0.kim@samsung.com> | 2016-04-26 11:30:34 +0830 |
commit | ab72290154976ebc0c8244a0b84aaaab033c469b (patch) | |
tree | 3582f3b1d5f056a941c067ef8a5eee3a60ab4755 | |
parent | 6622b4766211eec71a9877620e8dfcd4621a45a8 (diff) | |
download | quickpanel-ab72290154976ebc0c8244a0b84aaaab033c469b.tar.gz quickpanel-ab72290154976ebc0c8244a0b84aaaab033c469b.tar.bz2 quickpanel-ab72290154976ebc0c8244a0b84aaaab033c469b.zip |
change iniparser to preference
Change-Id: I36821dc9c1ee55d5f87d0d5f667fdad74f62feeb
-rwxr-xr-x | daemon/device/brightness.c | 2 | ||||
-rwxr-xr-x | daemon/preference.c | 178 | ||||
-rwxr-xr-x | daemon/preference.h | 2 | ||||
-rwxr-xr-x | daemon/settings/settings.c | 46 |
4 files changed, 59 insertions, 169 deletions
diff --git a/daemon/device/brightness.c b/daemon/device/brightness.c index 9084666..c5fc7c8 100755 --- a/daemon/device/brightness.c +++ b/daemon/device/brightness.c @@ -667,7 +667,6 @@ static void _ipc_fini(void *data) static int _init(void *data) { - char buf[PREF_LEN_VALUE_MAX] = {0,}; retif(data == NULL, QP_FAIL, "Invalid parameter!"); #ifdef QP_EMERGENCY_MODE_ENABLE @@ -676,7 +675,6 @@ static int _init(void *data) } #endif - quickpanel_preference_get(PREF_BRIGHTNESS, buf); _brightness_create(data); _ipc_init(data); diff --git a/daemon/preference.c b/daemon/preference.c index 185b0db..6cceb37 100755 --- a/daemon/preference.c +++ b/daemon/preference.c @@ -17,12 +17,8 @@ #include <stdio.h> -#include <fcntl.h> -#include <unistd.h> - -#include <iniparser.h> +#include <app_preference.h> #include <Elementary.h> - #include <tzsh.h> #include <tzsh_quickpanel_service.h> #include <E_DBus.h> @@ -30,26 +26,8 @@ #include "preference.h" #include "common.h" - - #include "quickpanel-ui.h" -#define PREFERENCE_FILE_NAME "preference.ini" - -static char *_get_preference_file_path() -{ - char *data_path = NULL; - char file_path[MAX_FILE_PATH_LEN] = {0, }; - - - data_path = app_get_data_path(); - retif(data_path == NULL, NULL, "failed to app_get_data_path()"); - - snprintf(file_path, sizeof(file_path), "%s%s", data_path, PREFERENCE_FILE_NAME); - free(data_path); - - return strdup(file_path); -} static const char *_default_preference_get(const char *key) { @@ -57,13 +35,13 @@ static const char *_default_preference_get(const char *key) if (strcmp(key, PREF_BRIGHTNESS) == 0) { return "OFF"; - } else if (strcmp(key, PREF_QUICKSETTING_ORDER) == 0){ + } else if (strcmp(key, PREF_QUICKSETTING_ORDER) == 0) { return "wifi,gps,sound,rotate,bluetooth,mobile_data,assisitvelight,u_power_saving,wifi_hotspot,flightmode"; - } else if (strcmp(key, PREF_QUICKSETTING_FEATURED_NUM) == 0){ + } else if (strcmp(key, PREF_QUICKSETTING_FEATURED_NUM) == 0) { return "11"; - } else if (strcmp(key, PREF_SHORTCUT_ENABLE) == 0){ + } else if (strcmp(key, PREF_SHORTCUT_ENABLE) == 0) { return "ON"; - } else if (strcmp(key, PREF_SHORTCUT_EARPHONE_ORDER) == 0){ + } else if (strcmp(key, PREF_SHORTCUT_EARPHONE_ORDER) == 0) { return "org.tizen.music-player,org.tizen.videos,org.tizen.phone,srfxzv8GKR.YouTube,org.tizen.voicerecorder"; } @@ -87,100 +65,49 @@ static inline int _key_validation_check(const char *key) return 0; } -static inline int _is_file_exist(void) +HAPI int quickpanel_preference_get(const char *key, char **value) { - char *file_path = _get_preference_file_path(); - retif(file_path == NULL, 0, "failed to _get_preference_file_path()"); - - if (access(file_path, O_RDWR) == 0) { - return 1; - } - - if (file_path != NULL) { - free(file_path); - } - - return 0; -} + bool existing = false; -static void _default_file_create(void) -{ - FILE *fp = NULL ; - char *file_path = _get_preference_file_path(); - retif(file_path == NULL, , "failed to _get_preference_file_path()"); - - fp = fopen(file_path, "w"); - retif(fp == NULL, , "fatal:failed to create preference file %s", file_path); - - fprintf(fp, "\n\ - [%s]\n\ - %s = %s ;\n\ - %s = %s ;\n\ - %s = %s ;\n\ - %s = %s ;\n\ - %s = %s ;\n\ - \n" - , PREF_SECTION - , PREF_BRIGHTNESS_KEY, _default_preference_get(PREF_BRIGHTNESS) - , PREF_QUICKSETTING_ORDER_KEY, _default_preference_get(PREF_QUICKSETTING_ORDER) - , PREF_QUICKSETTING_FEATURED_NUM_KEY, _default_preference_get(PREF_QUICKSETTING_FEATURED_NUM) - , PREF_SHORTCUT_ENABLE_KEY, _default_preference_get(PREF_SHORTCUT_ENABLE) - , PREF_SHORTCUT_EARPHONE_ORDER_KEY, _default_preference_get(PREF_SHORTCUT_EARPHONE_ORDER) - ); - - fclose(fp); - - if (file_path != NULL) { - free(file_path); - } -} - -HAPI int quickpanel_preference_get(const char *key, char *value) -{ - int ret = QP_OK; - dictionary *ini = NULL; - const char *value_r = NULL; - char *file_path = NULL; retif(key == NULL, QP_FAIL, "Invalid parameter!"); retif(value == NULL, QP_FAIL, "Invalid parameter!"); - file_path = _get_preference_file_path(); - retif(file_path == NULL, QP_FAIL, "failed to _get_preference_file_path()"); - - ini = iniparser_load(file_path); - if (ini == NULL) { - DBG("failed to load ini file"); - _default_file_create(); - value_r = _default_preference_get(key); - goto END; - } + if (preference_is_existing(key, &existing) == PREFERENCE_ERROR_NONE && !existing + && _key_validation_check(key)) { + DBG("preference does not exist"); + /* Create preference */ + if (preference_set_string(PREF_BRIGHTNESS, _default_preference_get(PREF_BRIGHTNESS)) != PREFERENCE_ERROR_NONE) { + DBG("preference set error %s", PREF_BRIGHTNESS); + return QP_FAIL; + } - value_r = iniparser_getstring(ini, key, NULL); - if (value_r == NULL) { - value_r = _default_preference_get(key); - if (_key_validation_check(key) == 1) { - _default_file_create(); + if (preference_set_string(PREF_QUICKSETTING_ORDER, _default_preference_get(PREF_QUICKSETTING_ORDER)) != PREFERENCE_ERROR_NONE) { + DBG("preference set error %s", PREF_QUICKSETTING_ORDER); + return QP_FAIL; } - } else { - DBG("get:[%s]", value_r); - } + if (preference_set_string(PREF_QUICKSETTING_FEATURED_NUM, _default_preference_get(PREF_QUICKSETTING_FEATURED_NUM)) != PREFERENCE_ERROR_NONE) { + DBG("preference set error %s", PREF_QUICKSETTING_FEATURED_NUM); + return QP_FAIL; + } -END: - if (value_r != NULL) { - strncpy(value, value_r, strlen(value_r)); - ret = QP_OK; - } + if (preference_set_string(PREF_SHORTCUT_ENABLE, _default_preference_get(PREF_SHORTCUT_ENABLE)) != PREFERENCE_ERROR_NONE) { + DBG("preference set error %s", PREF_SHORTCUT_ENABLE); + return QP_FAIL; + } - if (ini != NULL) { - iniparser_freedict(ini); + if (preference_set_string(PREF_SHORTCUT_EARPHONE_ORDER, _default_preference_get(PREF_SHORTCUT_EARPHONE_ORDER)) != PREFERENCE_ERROR_NONE) { + DBG("preference set error %s", PREF_SHORTCUT_EARPHONE_ORDER); + return QP_FAIL; + } } - if (file_path != NULL) { - free(file_path); + if ( preference_get_string(key, value) != PREFERENCE_ERROR_NONE) { + DBG("preference_get_string error : key(%s)", key); + return QP_FAIL; } - return ret; + return QP_OK; } HAPI const char *quickpanel_preference_default_get(const char *key) @@ -192,42 +119,15 @@ HAPI const char *quickpanel_preference_default_get(const char *key) HAPI int quickpanel_preference_set(const char *key, char *value) { - int ret = QP_FAIL; - FILE *fp = NULL; - dictionary *ini = NULL; retif(key == NULL, QP_FAIL, "Invalid parameter!"); retif(value == NULL, QP_FAIL, "Invalid parameter!"); - if (_is_file_exist() == 0) { - _default_file_create(); - } - - char *file_path = _get_preference_file_path(); - retif(file_path == NULL, QP_FAIL, "failed to _get_preference_file_path()"); - - ini = iniparser_load(file_path); - retif(ini == NULL, QP_FAIL, "failed to load ini file"); - - if (iniparser_set(ini, (char *)key, value) == 0) { - ret = QP_OK; + if (preference_set_string(key, value) == PREFERENCE_ERROR_NONE) { + DBG("quickpanel_preference_set key[%s] value [%s]", key, value); } else { - ERR("failed to write %s=%s", key, value); - } - - fp = fopen(file_path, "w"); - if (fp != NULL) { - iniparser_dump_ini(ini, fp); - fclose(fp); + DBG("quickpanel_preference_set failed key[%s]", key, value); + return QP_FAIL; } - iniparser_freedict(ini); - - if (file_path != NULL) { - free(file_path); - } - - return ret; + return QP_OK; } - - - diff --git a/daemon/preference.h b/daemon/preference.h index ba26de6..1ccf954 100755 --- a/daemon/preference.h +++ b/daemon/preference.h @@ -34,7 +34,7 @@ #define PREF_SHORTCUT_ENABLE PREF_SECTION":"PREF_SHORTCUT_ENABLE_KEY #define PREF_SHORTCUT_EARPHONE_ORDER PREF_SECTION":"PREF_SHORTCUT_EARPHONE_ORDER_KEY -extern int quickpanel_preference_get(const char *key, char *value); +extern int quickpanel_preference_get(const char *key, char **value); extern const char *quickpanel_preference_default_get(const char *key); extern int quickpanel_preference_set(const char *key, char *value); diff --git a/daemon/settings/settings.c b/daemon/settings/settings.c index e688dfb..864d05e 100755 --- a/daemon/settings/settings.c +++ b/daemon/settings/settings.c @@ -124,7 +124,8 @@ static QP_Module_Setting *_module_get_by_name(const char *name) return g_hash_table_lookup(s_info.module_table, name); } -static Eina_Bool _module_is_enabled(QP_Module_Setting *module) { +static Eina_Bool _module_is_enabled(QP_Module_Setting *module) +{ retif(module == NULL, EINA_FALSE, "invalid parameter"); retif(module->name == NULL, EINA_FALSE, "invalid parameter"); @@ -138,18 +139,6 @@ static Eina_Bool _module_is_enabled(QP_Module_Setting *module) { return EINA_TRUE; } -static char *_preference_get(const char *key) -{ - char line[PREF_LEN_VALUE_MAX + 1] = {0,}; - - if (quickpanel_preference_get(key, line) == QP_OK) { - DBG("quicksetting order from file:%s", line); - return strdup(line); - } - - return NULL; -} - static int quickpanel_settings_init(void *data) { int i; @@ -325,31 +314,31 @@ HAPI void quickpanel_settings_featured_list_get(Eina_List **list) int seq_added_count = 0; gchar **params = NULL; QP_Module_Setting *module = NULL; - retif(list == NULL, , "invalid data."); - char *sequence = _preference_get(PREF_QUICKSETTING_ORDER); + char *sequence = NULL; + char *num_featured_str = NULL; const char *default_sequence = quickpanel_preference_default_get(PREF_QUICKSETTING_ORDER); - - char *num_featured_str = _preference_get(PREF_QUICKSETTING_FEATURED_NUM); const char *default_num_featured_str = quickpanel_preference_default_get(PREF_QUICKSETTING_FEATURED_NUM); - if (sequence != NULL) { + retif(list == NULL, , "invalid data."); + + if (quickpanel_preference_get(PREF_QUICKSETTING_ORDER, &sequence) == QP_OK && sequence != NULL) { + DBG("preference_get key(%s) value(%s)", PREF_QUICKSETTING_ORDER, sequence); params = g_strsplit(sequence, ",", 0); free(sequence); } else { params = g_strsplit(default_sequence, ",", 0); } - if (num_featured_str != NULL) { + if (quickpanel_preference_get(PREF_QUICKSETTING_FEATURED_NUM, &num_featured_str) == QP_OK && num_featured_str != NULL) { + DBG("preference_get key(%s) value(%s)", PREF_QUICKSETTING_FEATURED_NUM, num_featured_str); num_featured = atoi(num_featured_str); free(num_featured_str); } else { - if (default_num_featured_str != NULL) { - num_featured = atoi(default_num_featured_str); - } else { - num_featured = QP_SETTING_NUM_TOTAL_ICON; - } + num_featured = atoi(default_num_featured_str); } + *list = NULL; + if (params != NULL) { seq_count = g_strv_length(params); @@ -377,16 +366,19 @@ HAPI void quickpanel_settings_all_list_get(Eina_List **list) gchar **params = NULL; QP_Module_Setting *module = NULL; retif(list == NULL, , "invalid data."); - char *sequence = _preference_get(PREF_QUICKSETTING_ORDER); + char *sequence = NULL; const char *default_sequence = quickpanel_preference_default_get(PREF_QUICKSETTING_ORDER); - if (sequence != NULL) { + if (quickpanel_preference_get(PREF_QUICKSETTING_ORDER, &sequence) == QP_OK && sequence != NULL) { + DBG("preference_get key(%s) value(%s)", PREF_QUICKSETTING_ORDER, sequence); params = g_strsplit(sequence, ",", 0); free(sequence); - } else if (default_sequence != NULL){ + } else { params = g_strsplit(default_sequence, ",", 0); } + *list = NULL; + if (params != NULL) { seq_count = g_strv_length(params); |