diff options
author | jstebbins <[email protected]> | 2009-05-26 17:53:03 +0000 |
---|---|---|
committer | jstebbins <[email protected]> | 2009-05-26 17:53:03 +0000 |
commit | fddec5e55d487728a34e6b894b342c49ad0e0ca3 (patch) | |
tree | 325079ed6f6d25104f55c4bbeb7bb1dfa8cc8f4e /gtk/src/presets.c | |
parent | 5172463301d64c13c3903d93f7bfaaa777538fc9 (diff) |
LinGui: automatically update the built-in presets when the hb build number changes
git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@2453 b64f7644-9d1e-0410-96f1-a4d463321fa5
Diffstat (limited to 'gtk/src/presets.c')
-rw-r--r-- | gtk/src/presets.c | 100 |
1 files changed, 99 insertions, 1 deletions
diff --git a/gtk/src/presets.c b/gtk/src/presets.c index 5d64de1a2..45bf963bd 100644 --- a/gtk/src/presets.c +++ b/gtk/src/presets.c @@ -2633,6 +2633,8 @@ ghb_presets_reload(signal_user_data_t *ud) std_dict = ghb_array_get_nth(std_presets, ii); copy_dict = ghb_value_dup(std_dict); + ghb_dict_insert(copy_dict, g_strdup("PresetBuildNumber"), + ghb_int64_value_new(hb_get_build(NULL))); ghb_presets_insert(presetsPlist, copy_dict, &indices, 1); presets_list_insert(ud, &indices, 1); } @@ -2659,8 +2661,102 @@ check_old_presets() return FALSE; } +static void +replace_standard_presets() +{ + GValue *std_presets; + int *indices, len; + gint count, ii; + + count = ghb_array_len(presetsPlist); + for (ii = count-1; ii >= 0; ii--) + { + GValue *dict; + gint ptype; + + dict = ghb_array_get_nth(presetsPlist, ii); + ptype = ghb_value_int(preset_dict_get_value(dict, "Type")); + if (ptype == PRESETS_BUILTIN) + { + gint indices = 0; + ghb_presets_remove(presetsPlist, &indices, 1); + } + } + + std_presets = ghb_resource_get("standard-presets"); + if (std_presets == NULL) return; + + indices = presets_find_default(presetsPlist, &len); + if (indices) + { + presets_clear_default(std_presets); + g_free(indices); + } + // Merge the keyfile contents into our presets + count = ghb_array_len(std_presets); + for (ii = count-1; ii >= 0; ii--) + { + GValue *std_dict; + GValue *copy_dict; + gint indices = 0; + + std_dict = ghb_array_get_nth(std_presets, ii); + copy_dict = ghb_value_dup(std_dict); + ghb_dict_insert(copy_dict, g_strdup("PresetBuildNumber"), + ghb_int64_value_new(hb_get_build(NULL))); + ghb_presets_insert(presetsPlist, copy_dict, &indices, 1); + } + import_xlat_presets(presetsPlist); + store_presets(); +} + +static void +update_standard_presets(signal_user_data_t *ud) +{ + gint count, ii; + + count = ghb_array_len(presetsPlist); + for (ii = count-1; ii >= 0; ii--) + { + GValue *dict; + const GValue *gval; + gint64 build; + gint type; + + dict = ghb_array_get_nth(presetsPlist, ii); + gval = ghb_dict_lookup(dict, "Type"); + if (gval == NULL) + { + // Old preset that doesn't have a Type + replace_standard_presets(); + return; + } + + type = ghb_value_int(gval); + if (type == 0) + { + gval = ghb_dict_lookup(dict, "PresetBuildNumber"); + if (gval == NULL) + { + // Old preset that doesn't have a build number + replace_standard_presets(); + return; + } + + build = ghb_value_int64(gval); + if (build != hb_get_build(NULL)) + { + // Build number does not match + replace_standard_presets(); + return; + } + } + } + return; +} + void -ghb_presets_load() +ghb_presets_load(signal_user_data_t *ud) { presetsPlist = load_plist("presets"); if (presetsPlist == NULL) @@ -2683,6 +2779,7 @@ ghb_presets_load() import_xlat_presets(presetsPlist); store_presets(); } + update_standard_presets(ud); import_xlat_presets(presetsPlist); } @@ -2738,6 +2835,7 @@ settings_save(signal_user_data_t *ud, const GValue *path) current_preset = dict; autoscale = ghb_settings_get_boolean(ud->settings, "autoscale"); ghb_settings_set_int64(ud->settings, "Type", PRESETS_CUSTOM); + ghb_settings_set_int64(ud->settings, "PresetBuildNumber", hb_get_build(NULL)); internal = plist_get_dict(internalPlist, "Presets"); ghb_dict_iter_init(&iter, internal); |