diff options
author | jstebbins <[email protected]> | 2008-09-02 22:56:19 +0000 |
---|---|---|
committer | jstebbins <[email protected]> | 2008-09-02 22:56:19 +0000 |
commit | 45cabbfe4ab8b95b5f25a236f8c93b64d3ccf8df (patch) | |
tree | 40326771d4a7f4721363e3b76ebfca5329595deb /gtk/src/ini_to_plist.c | |
parent | fd744170cb1da2675e1168402866f5c20f08a726 (diff) |
LinGui: Presets and preferences are now stored as plists
This will also make saving/restoring the queue much easier.
It's a scary big change. 1400 new lines of code. Due to efficiencies
of a better desing, 2400 lines of old code also gets refactored
down to 1600. Giving a final net +600 lines.
Along the way, I stumbled across a couple bugs and fixed them.
Chapter list entry would get wedged under certain circumstances.
Pausing encoding didn't display pause message in status bar.
git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@1662 b64f7644-9d1e-0410-96f1-a4d463321fa5
Diffstat (limited to 'gtk/src/ini_to_plist.c')
-rw-r--r-- | gtk/src/ini_to_plist.c | 104 |
1 files changed, 104 insertions, 0 deletions
diff --git a/gtk/src/ini_to_plist.c b/gtk/src/ini_to_plist.c new file mode 100644 index 000000000..d0d441d8d --- /dev/null +++ b/gtk/src/ini_to_plist.c @@ -0,0 +1,104 @@ +#include <glib.h> +#include <glib-object.h> +#include <glib/gstdio.h> +#include <string.h> +#include "values.h" +#include "plist.h" + +gboolean +string_is_true(const gchar *str) +{ + return (strcmp(str, "enable") == 0); +} + +gboolean +string_is_bool(const gchar *str) +{ + return (strcmp(str, "enable") == 0) || (strcmp(str, "disable") == 0); +} + +GType +guess_type(const gchar *str) +{ + gchar *end; + gdouble dval; + + if (*str == 0) + return G_TYPE_STRING; + if (string_is_bool(str)) + return G_TYPE_BOOLEAN; + dval = g_strtod(str, &end); + if (*end == 0) + { + if (strchr(str, '.') == NULL) + return G_TYPE_INT64; + else + return G_TYPE_DOUBLE; + } + + return G_TYPE_STRING; +} + +void +set_value(GValue *gval, const gchar *str, GType gtype) +{ + if (gtype == G_TYPE_STRING) + { + g_value_set_string(gval, str); + } + else if (gtype == G_TYPE_INT64) + { + gint64 val = g_strtod(str, NULL); + g_value_set_int64(gval, val); + } + else if (gtype == G_TYPE_DOUBLE) + { + gdouble val = g_strtod(str, NULL); + g_value_set_double(gval, val); + } + else if (gtype == G_TYPE_BOOLEAN) + { + if (string_is_true(str)) + g_value_set_boolean(gval, TRUE); + else + g_value_set_boolean(gval, FALSE); + } +} + +int +main(gint argc, gchar *argv[]) +{ + GKeyFile *kf; + gchar **groups; + gchar **keys; + gint ii, jj; + GValue *top; + GValue *dict; + + g_type_init(); + top = ghb_dict_value_new(); + kf = g_key_file_new(); + g_key_file_load_from_file(kf, argv[1], 0, NULL); + groups = g_key_file_get_groups(kf, NULL); + for (ii = 0; groups[ii]; ii++) + { + dict = ghb_dict_value_new(); + ghb_dict_insert(top, , g_strdup(groups[ii]), dict); + keys = g_key_file_get_keys(kf, groups[ii], NULL, NULL); + for (jj = 0; keys[jj]; jj++) + { + gchar *str; + GValue *gval; + GType gtype; + + str = g_key_file_get_string(kf, groups[ii], keys[jj], NULL); + gtype = guess_type(str); + gval = g_malloc0(sizeof(GValue)); + g_value_init(gval, gtype); + set_value(gval, str, gtype); + ghb_dict_insert(dict, g_strdup(keys[jj]), gval); + } + } + ghb_plist_write_file("a_p_list", top); +} + |