/* "true" --> 1 "false" --> 0 */
if (retstr && safeStrCmp(retstr, "true") == 0) {
g_sortedarr[i].value.b = 1;
- } else if (retstr && safeStrCmp(retstr, "false") == 0) {
+ } else if (retstr && safeStrCmp(retstr, "false") == 0) {
g_sortedarr[i].value.b = 0;
}
break;
return safeStrCmp(str1, str2);
}
-EXPORT_PUBLIC
-void setting_import_json(status_handler_fp fp, void *data)
-{
- SETTING_TRACE_BEGIN;
- /*--------------------------------------------------------------------------------- */
- JsonParser *parser;
- JsonNode *root;
- GError *error;
-
- /*---- */
- int bcount = sizeof(g_btable) / sizeof(g_btable[0]) - 1;
- int icount = sizeof(g_itable) / sizeof(g_itable[0]) - 1;
- int scount = sizeof(g_stable) / sizeof(g_stable[0]) - 1; /* why?? buggy */
- int total = bcount + icount + scount;
- SETTING_TRACE(" >>> total : %d ", total);
-
- VconfNode *arr3 = (VconfNode *)malloc(sizeof(VconfNode)*total);
- if (!arr3) return;
- memcpy(arr3, g_btable, sizeof(VconfNode)*(bcount));
- memcpy(&arr3[bcount - 1], g_itable, sizeof(g_itable));
- memcpy(&arr3[bcount - 1 + icount - 1], g_stable, sizeof(g_stable));
- qsort(arr3, total, sizeof(VconfNode), __compareByCategory);
- /*---- */
-
- g_sortedarr = arr3;
-
- parser = json_parser_new();
-
- error = NULL;
- json_parser_load_from_file(parser, SETTING_CFG_JSON_FILE_PATH, &error);
- if (error) {
- SETTING_TRACE("Unable to parse `%s': %s", SETTING_CFG_JSON_FILE_PATH, error->message);
- g_error_free(error);
- g_object_unref(parser);
- return;
- }
-
- root = json_parser_get_root(parser);
- /* manipulate the object tree and then exit */
-
- JsonObject *obj1 = json_node_get_object(root);
- if (json_object_has_member(obj1, "value")) {
- JsonNode *node = json_object_get_member(obj1, "value");
- JsonObject *object2 = json_node_get_object(node);
- json_object_foreach_member(object2, __func_cb, NULL); /* with g_sortedarr */
- }
- g_object_unref(parser);
-
- FREE(arr3);
- g_sortedarr = NULL;
-}
-
-/**
- * setting --> cloud : JSON
- *
- * int status_handler(int total, int current, void* data);
- */
-EXPORT_PUBLIC
-char *setting_export_json(status_handler_fp fp, void *data)
-{
- JsonNode *root = NULL;
-
- root = json_node_new(JSON_NODE_OBJECT);
- JsonObject *top = json_object_new();
- json_node_take_object(root, top);
-
- json_object_set_string_member(top, "key", "SETTINGS_359617040746834_8592d887-8b97-406e-9cf9-03aebc045f81");
-
- int bcount = sizeof(g_btable) / sizeof(g_btable[0]) - 1;
- int icount = sizeof(g_itable) / sizeof(g_itable[0]) - 1;
- int scount = sizeof(g_stable) / sizeof(g_stable[0]) - 1; /* why?? buggy */
-
- int total = bcount + icount + scount;
-
- JsonNode *topnode = json_node_new(JSON_NODE_OBJECT);
- JsonObject *topobj = json_object_new();
- json_node_take_object(topnode, topobj);
-
- json_object_set_member(top, "value", topnode);
-
- VconfNode *arr3 = (VconfNode *)malloc(sizeof(VconfNode)*total);
- if (!arr3) return NULL;
- memcpy(arr3, g_btable, sizeof(VconfNode)*(bcount));
- memcpy(&arr3[bcount - 1], g_itable, sizeof(g_itable));
- memcpy(&arr3[bcount - 1 + icount - 1], g_stable, sizeof(g_stable));
- qsort(arr3, total, sizeof(VconfNode), __compareByCategory);
-
- char *public_groupkey = "";
-
- /*JsonArray* array = NULL; */
- JsonObject *obj = NULL;
- JsonNode *node = NULL;
-
- int i;
- for (i = 0; i < total; i++) {
- if (arr3[i].public_key) {
- if (public_groupkey && safeStrCmp(public_groupkey, arr3[i].public_groupkey) != 0) {
- public_groupkey = (char *)(arr3[i].public_groupkey);
- /*array = json_array_new(); */
- obj = json_object_new();
- node = json_node_new(JSON_NODE_OBJECT);
- json_node_take_object(node, obj);
- json_object_set_member(topobj, public_groupkey, node);
- /*json_array_add_element(array, node); */
- }
-
- /* get data from vconf */
- /* get vconf_get */
- char *val = NULL;
- char arr[1024];
- VconfNode result;
- switch (arr3[i].type) {
- case eBOOL:
- get_vconf(arr3[i], &result);
- if (result.value.b)
- val = "true";
- else
- val = "false";
- break;
- case eINT:
- get_vconf(arr3[i], &result);
- snprintf(arr, 1024, "%d", result.value.i);
- val = arr;
- /*if (val == NULL) val = "-100"; */
- break;
- case eSTRING:
- get_vconf(arr3[i], &result);
- val = result.value.c;
- if (val == NULL) val = "";
- break;
- default:
- val = "error";
- }
-
- json_object_set_string_member(obj, arr3[i].public_key, val);
- }
- }
-
- /* save data to a file */
- GError *error = NULL;
- JsonGenerator *generator = json_generator_new();
- json_generator_set_root(generator, root/*node*/);
-
- gsize len;
- char *buf = (char *)json_generator_to_data(generator, &len);
-
- g_object_set(generator, "pretty", TRUE, NULL); /*write file in indent format */
- gboolean ret = json_generator_to_file(generator, SETTING_CFG_JSON_FILE_PATH, &error);
- g_object_unref(generator);
-
- if (FALSE == ret) {
- SETTING_TRACE_ERROR("Error writing file %s!", SETTING_CFG_JSON_FILE_PATH);
- /*return FALSE; */
- }
-
- json_node_free(root);
- FREE(arr3);
-
- return buf;
-}
-
int set_vconf(VconfNode node, VconfNode *result)
{
/*SETTING_TRACE_BEGIN; */
{
SETTING_TRACE_BEGIN;
xmlNode *cur_node = NULL;
- char *id;
- char *string;
+ char *id = NULL;
+ char *string = NULL;
char *mcc = NULL;
- /*int number = 1; */
+ char *tmp = NULL;
+ setting_lang_entry *pitem = NULL;
for (cur_node = cur; cur_node; cur_node = cur_node->next) {
if (cur_node->type == XML_ELEMENT_NODE) {
- /*SETTING_TRACE(" name=%s title=%s \n", xmlGetProp(cur_node, (const xmlChar *)"id"), xmlGetProp(cur_node, (const xmlChar *)"string")); */
- id = (char *)g_strdup((char *)xmlGetProp(cur_node, (const xmlChar *)"id"));
- string = (char *)g_strdup((char *) xmlGetProp(cur_node, (const xmlChar *)"string"));
- /*SETTING_TRACE_DEBUG("lang: %s", xmlGetProp(cur_node, (const xmlChar *)"lang")); */
- mcc = (char *)g_strdup((char *) xmlGetProp(cur_node, (const xmlChar *)"mcc"));
- /*number = atoi((char*) xmlGetProp(cur_node, (const xmlChar *)"no")); */
+ tmp = (char *)xmlGetProp(cur_node, (const xmlChar *)"id");
+ id = (char *)g_strdup(tmp);
+ xmlFree(tmp);
+
+ tmp = (char *)xmlGetProp(cur_node, (const xmlChar *)"string");
+ string = (char *)g_strdup(tmp);
+ xmlFree(tmp);
- setting_lang_entry *pitem = (setting_lang_entry *)calloc(1, sizeof(setting_lang_entry));
+ tmp = (char *)xmlGetProp(cur_node, (const xmlChar *)"mcc");
+ mcc = (char *)g_strdup(tmp);
+ xmlFree(tmp);
+
+ pitem = (setting_lang_entry *)calloc(1, sizeof(setting_lang_entry));
if (pitem) {
pitem->locale = id;
pitem->title = string;
pitem->mcc = mcc;
- /*pitem->number = number++; */
- /*SETTING_TRACE_DEBUG("no=%d", pitem->number); */
- /*SETTING_TRACE_DEBUG(">>>> locale: %s title: %s mcc: %s", pitem->locale, pitem->title, pitem->mcc); */
s_langlist = eina_list_append(s_langlist, pitem);
+ } else {
+ g_free(id);
+ g_free(string);
+ g_free(mcc);
}
}
}
EXPORT_PUBLIC
bool setting_add_listen_node(Eina_List **listened_list, const char *vconf, vconf_callback_fn cb, void *data)
{
- Vconf_Change_Node *node = calloc(1, sizeof(Vconf_Change_Node));
bool ret = TRUE;
- if (node && vconf && cb) {
- node->in_key = vconf;
- node->cb = cb;
- node->cb_data = data;
-
- if (0 == vconf_notify_key_changed(vconf, cb, data)) {
- /*SETTING_TRACE("Register callback[%p] of %s", node->cb, node->in_key); */
- *listened_list = eina_list_append(*listened_list, node);
- } else {
- SETTING_TRACE_ERROR("Failed to register callback[%p] of %s", node->cb, node->in_key);
- FREE(node);
- ret = FALSE;
- }
+ if (!vconf || cb)
+ return ret;
+
+ Vconf_Change_Node *node = calloc(1, sizeof(Vconf_Change_Node));
+ if (!node)
+ return ret;
+
+
+ node->in_key = vconf;
+ node->cb = cb;
+ node->cb_data = data;
+
+ if (0 == vconf_notify_key_changed(vconf, cb, data)) {
+ /*SETTING_TRACE("Register callback[%p] of %s", node->cb, node->in_key); */
+ *listened_list = eina_list_append(*listened_list, node);
+ } else {
+ SETTING_TRACE_ERROR("Failed to register callback[%p] of %s", node->cb, node->in_key);
+ FREE(node);
+ ret = FALSE;
}
return ret;
}
+++ /dev/null
-/*
- * setting_confutil
- *
- *
- *
- $ setting_confutil // create a cfg file in default
- $ setting_confutil export // export current status to a xml file
- $ setting_confutil timezone_init // timezone init
- */
-#include <stdio.h>
-
-#include <setting-cfg.h>
-#include <setting-debug.h>
-#include <stdio.h>
-#include <Elementary.h>
-#include <setting-common-general-func.h>
-#include <setting-common-data-slp-setting.h>
-#include <unistd.h>
-#include <system_settings.h>
-
-#include <stdio.h>
-#include <libxml/parser.h>
-#include <libxml/tree.h>
-#include <setting-common-search.h>
-
-static char *get_timezone();
-
-static void get_gmt_offset(char *str_buf, int size)
-{
- /* timezone string +/-<n> ex. +9, -1 */
- time_t t = time(0); /* get unix time. sec. */
-
- struct tm *pdata, data;
- pdata = localtime_r(&t, &data); /* save time as structure. */
- setting_retm_if(!pdata, "data is NULL");
- pdata->tm_isdst = 0; /* summer time, not applied. */
- time_t a = mktime(pdata);
-
- pdata = gmtime_r(&a, &data);
- setting_retm_if(!pdata, "data is NULL");
- pdata->tm_isdst = 0; /* summer time, not applied. */
- time_t b = mktime(pdata);
-
- int gmtoffset_hour = (a - b) / 3600; /* result : hour. */
- int gmtoffset_min = ((a - b) % 3600) / 60; /* result : min. */
- if (gmtoffset_min != 0) {
- gmtoffset_min = 30;
- }
-
- snprintf(str_buf, size, "%+d:%02u", gmtoffset_hour, gmtoffset_min);
- SETTING_TRACE("szTimezone is of a valid format: GMT: %s", str_buf);
-}
-
-int generate_setting_cfg()
-{
- if (0 == setting_cfg_create(false)) {
- SETTING_TRACE_ERROR("Error to create a new config file");
- return 0 ;
- }
-
- return 1;
-}
-
-int migrate_setting_cfg()
-{
- SETTING_TRACE_BEGIN;
- if (0 == setting_cfg_migrate()) {
- SETTING_TRACE_ERROR("Fail to migrate config file");
- return 0 ;
- }
- SETTING_TRACE_END;
- return 1;
-}
-
-void timezone_init()
-{
- char *tzpath = get_timezone();
- int ret = vconf_set_str(VCONFKEY_SETAPPL_TIMEZONE_ID, tzpath + 20);
- if (ret != 0) {
- SETTING_TRACE("fail to set vconf");
- }
- char str_buf[256] = {0, };
- get_gmt_offset(str_buf, 256);
- SETTING_TRACE(">>> time zone GMT string : %s", str_buf);
- g_free(tzpath);
-}
-
-void get_current_font()
-{
- char *value = NULL;
- int retcode = system_settings_get_value_string(SYSTEM_SETTINGS_KEY_FONT_TYPE, &value);
- if (retcode != 0) {
- SETTING_TRACE("fail to set SYSTEM_SETTINGS_KEY_FONT_TYPE");
- }
- SETTING_TRACE(">>> get current font type : %s \n", value);
-}
-
-int status_fp(int total, int current, void *data)
-{
- SETTING_TRACE(">> total : %d ---- current : %d ", total, current);
- return 0;
-}
-
-
-/**
-sh-4.1# [_TZ_SYS_RW_APP]/org.tizen.setting/bin/setting_conf_util timezone_check
-debug level init 1(1)
->>> time zone : /usr/share/zoneinfo/Asia/Seoul
-*/
-int main(int argc, char *argv[])
-{
- elm_init(argc, argv);
- setting_set_i18n_force(SETTING_PACKAGE, SETTING_LOCALEDIR);
-
- if ((argc == 2) && (0 == strcmp(argv[1], "export_json"))) {
- setting_export_json(status_fp, NULL);
- } else if ((argc == 2) && (0 == strcmp(argv[1], "import_json"))) {
- setting_import_json(status_fp, NULL);
- } else if ((argc == 2) && (0 == strcmp(argv[1], "timezone_init"))) {
- timezone_init();
- } else if ((argc == 2) && (0 == strcmp(argv[1], "get_current_font"))) {
- get_current_font();
- } else if ((argc == 2) && (0 == strcmp(argv[1], "gen_cfg"))) {
- generate_setting_cfg();
- } else if ((argc == 2) && (0 == strcmp(argv[1], "mig_cfg"))) {
- migrate_setting_cfg();
- } else {
- /* cfg create */
- /* TRUE or FALSE */
- setting_cfg_create(false);
- }
- return 0;
-}
-
-/* automatic */
-static char *get_timezone()
-{
- SETTING_TRACE_BEGIN;
-
- enum { BUFFERSIZE = 1024 };
- char buf[BUFFERSIZE] = {0, };
- ssize_t len = readlink(_TZ_SYS_ETC"/localtime", buf, sizeof(buf) - 1);
-
- if (len != -1) {
- buf[len] = '\0';
- } else {
- /* handle error condition */
- return NULL;
- }
- return g_strdup(buf);
-}
-