diff options
author | jstebbins <[email protected]> | 2015-03-06 22:17:34 +0000 |
---|---|---|
committer | jstebbins <[email protected]> | 2015-03-06 22:17:34 +0000 |
commit | 01eabb2d314372bb301c3468d53840994105c652 (patch) | |
tree | f82169e882e5b83b7be85d0301b3451e3d93b139 /gtk/src/values.c | |
parent | 0d4c60c548ffc487c66ca055efb18c7f09faa0c6 (diff) |
LinGui: add methods for reading and writing json config files
queue, preferences and app resources are now stored in json.
presets are not yet stored as json, pending sync with other platforms
git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@6970 b64f7644-9d1e-0410-96f1-a4d463321fa5
Diffstat (limited to 'gtk/src/values.c')
-rw-r--r-- | gtk/src/values.c | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/gtk/src/values.c b/gtk/src/values.c index c0bb1305b..749ce0bca 100644 --- a/gtk/src/values.c +++ b/gtk/src/values.c @@ -13,6 +13,7 @@ */ #include <glib.h> +#include <glib/gstdio.h> #include <glib-object.h> #include <stdio.h> #include <string.h> @@ -62,6 +63,20 @@ ghb_value_new(GhbType type) } void +ghb_value_incref(GhbValue *gval) +{ + if (gval == NULL) return; + json_incref(gval); +} + +void +ghb_value_decref(GhbValue *gval) +{ + if (gval == NULL) return; + json_decref(gval); +} + +void ghb_value_free(GhbValue *gval) { if (gval == NULL) return; @@ -535,3 +550,34 @@ ghb_array_len(const GhbValue *array) { return json_array_size(array); } + +void +ghb_json_write(FILE *file, GhbValue *gval) +{ + char * json = json_dumps(gval, JSON_INDENT(4)|JSON_PRESERVE_ORDER); + fprintf(file, "%s", json); + free(json); +} + +void +ghb_json_write_file(const char *path, GhbValue *gval) +{ + FILE *file = g_fopen(path, "w"); + if (file == NULL) + return; + ghb_json_write(file, gval); + fclose(file); +} + +GhbValue* +ghb_json_parse(const char *json, size_t size) +{ + return json_loadb(json, size, JSON_REJECT_DUPLICATES, NULL); +} + +GhbValue* +ghb_json_parse_file(const char *path) +{ + return json_load_file(path, JSON_REJECT_DUPLICATES, NULL); +} + |