change iniparser to preference 75/67175/3
authorjin0.kim <jin0.kim@samsung.com>
Mon, 25 Apr 2016 11:36:02 +0000 (20:06 +0830)
committerjin0.kim <jin0.kim@samsung.com>
Tue, 26 Apr 2016 03:00:34 +0000 (11:30 +0830)
Change-Id: I36821dc9c1ee55d5f87d0d5f667fdad74f62feeb

daemon/device/brightness.c
daemon/preference.c
daemon/preference.h
daemon/settings/settings.c

index 908466610ca127ba8273e9f63588f7dca296f06c..c5fc7c8639f43f796de77e2c2a8c282f8cef4ddb 100755 (executable)
@@ -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);
index 185b0db708f780dbb04329cefe64bafe5ccbdc7f..6cceb3748b7ef9dd9a130671aba744ba0ec1b566 100755 (executable)
 
 
 #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>
 
 #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;
 }
-
-
-
index ba26de6ca91795931bb02377fda5b36bf9cef9ee..1ccf95427ad37a59cf01b69416f834632b8564f0 100755 (executable)
@@ -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);
 
index e688dfba9fc4c358376fcc466c33b4cf9cdb990a..864d05e4743a0edb0ee3e8552bdf4921599905d7 100755 (executable)
@@ -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);