2 * Copyright (c) 2016-2020 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.
22 static void ss_json_ringtone_save(JsonNode *root)
25 JsonGenerator *generator = json_generator_new();
26 json_generator_set_root(generator, root);
27 json_generator_set_pretty(generator, TRUE);
30 gboolean ret = json_generator_to_file(generator, filename, &error);
32 gchar *result = json_generator_to_data(generator, NULL);
33 vconf_set_str(VCONFKEY_SETAPPL_CALL_RINGTONE_USER_LIST, (char*)result);
35 g_object_unref(generator);
38 JsonParser* ss_json_ringtone_open_file(char *path)
44 parser = json_parser_new();
47 json_parser_load_from_file(parser, path, &error);
49 SST_SECURE_TRACE("Unable to parse `%s': %s\n", path, error->message);
51 g_object_unref(parser);
58 JsonParser* ss_json_ringtone_load_from_data()
64 parser = json_parser_new();
67 char *load_data = vconf_get_str(VCONFKEY_SETAPPL_CALL_RINGTONE_USER_LIST);
68 json_parser_load_from_data(parser, load_data, -1, &error);
70 SST_SECURE_TRACE("Unable to load data : %s \n", error->message);
72 g_object_unref(parser);
78 void ss_json_ringtone_add(JsonNode *root, char *filename, char *nameval, char *pathval)
80 JsonNode *menu_item = json_node_new(JSON_NODE_OBJECT);
81 JsonObject *object = json_object_new();
82 json_node_take_object(menu_item, object);
83 json_object_set_string_member(object, "name", nameval);
84 json_object_set_string_member(object, "path", pathval);
86 JsonArray *menu = json_node_get_array(root);
87 json_array_add_element(menu, menu_item);
89 ss_json_ringtone_save(root);
92 void ss_json_ringtone_print(JsonNode *root)
94 JsonNode *node = root;
96 JsonGenerator *generator = json_generator_new();
97 json_generator_set_root(generator, node);
98 json_generator_set_pretty(generator, TRUE);
99 gchar *data = json_generator_to_data(generator, NULL);
100 //SETTING_TRACE("%s", (char * )data);
101 SST_SECURE_TRACE("-------------------------------------------------------\n");
102 SST_SECURE_TRACE("%s", data);
103 SST_SECURE_TRACE("-------------------------------------------------------\n");
105 SST_SECURE_TRACE("VCONFKEY_SETAPPL_CALL_RINGTONE_USER_LIST SET !!!!\n");
106 vconf_set_str(VCONFKEY_SETAPPL_CALL_RINGTONE_USER_LIST, (char*)data);
108 g_object_unref(generator);
111 void ss_json_ringtone_remove(JsonNode *root, char *filename, char *path_to_del)
113 int size = json_array_get_length(json_node_get_array(root));
115 SST_SECURE_TRACE("BBB size : (%d) \n", size);
117 for (i = 0; i < size; i++) {
118 JsonObject *ringtone = json_array_get_object_element(json_node_get_array(root), i);
119 //char *nameval = (char*)json_object_get_string_member(ringtone, "name");
120 char *pathval = (char*)json_object_get_string_member(ringtone, "path");
122 if (pathval && !strcmp(pathval, path_to_del)) {
123 json_array_remove_element(json_node_get_array(root), i);
124 SST_SECURE_TRACE("remove BBB : (%s) --- (%s) \n", pathval, path_to_del);
128 ss_json_ringtone_save(root);
131 bool ss_json_ringtone_contain(JsonNode *root, char *newfile)
133 int size = json_array_get_length(json_node_get_array(root));
138 for (i = 0; i < size; i++) {
139 JsonObject *ringtone = json_array_get_object_element(json_node_get_array(root), i);
140 //char *nameval = (char*)json_object_get_string_member(ringtone, "name");
141 char *pathval = (char*)json_object_get_string_member(ringtone, "path");
142 //SETTING_TRACE("(%s) --- (%s) \n", name, path);
144 if (pathval && !strcmp(pathval, newfile)) {
145 //SETTING_TRACE("FOUND\n");
149 //SETTING_TRACE("*NOT* FOUND\n");
157 void ss_json_ringtone_list(JsonNode *root)
159 int size = json_array_get_length(json_node_get_array(root));
162 for (i = 0; i < size; i++) {
163 JsonObject *ringtone = json_array_get_object_element(json_node_get_array(root), i);
164 char *name = (char*)json_object_get_string_member(ringtone, "name");
165 char *path = (char*)json_object_get_string_member(ringtone, "path");
166 SST_SECURE_TRACE("(%s) --- (%s) \n", name, path);