summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjstebbins <[email protected]>2009-05-26 17:53:03 +0000
committerjstebbins <[email protected]>2009-05-26 17:53:03 +0000
commitfddec5e55d487728a34e6b894b342c49ad0e0ca3 (patch)
tree325079ed6f6d25104f55c4bbeb7bb1dfa8cc8f4e
parent5172463301d64c13c3903d93f7bfaaa777538fc9 (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
-rw-r--r--gtk/src/internal_defaults.xml2
-rw-r--r--gtk/src/main.c2
-rw-r--r--gtk/src/presets.c100
-rw-r--r--gtk/src/presets.h2
4 files changed, 103 insertions, 3 deletions
diff --git a/gtk/src/internal_defaults.xml b/gtk/src/internal_defaults.xml
index 2c5bb2043..3f408dff2 100644
--- a/gtk/src/internal_defaults.xml
+++ b/gtk/src/internal_defaults.xml
@@ -173,6 +173,8 @@
</dict>
<key>Presets</key>
<dict>
+ <key>PresetBuildNumber</key>
+ <string></string>
<key>PictureAutoCrop</key>
<true />
<key>ChapterMarkers</key>
diff --git a/gtk/src/main.c b/gtk/src/main.c
index db5450580..ef0dc18c2 100644
--- a/gtk/src/main.c
+++ b/gtk/src/main.c
@@ -736,7 +736,7 @@ main (int argc, char *argv[])
// Load all internal settings
ghb_settings_init(ud);
// Load the presets files
- ghb_presets_load();
+ ghb_presets_load(ud);
ghb_prefs_load(ud);
ghb_prefs_to_ui(ud);
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);
diff --git a/gtk/src/presets.h b/gtk/src/presets.h
index 6bcd14a54..8c05f1978 100644
--- a/gtk/src/presets.h
+++ b/gtk/src/presets.h
@@ -17,7 +17,7 @@
#define _GHB_PRESETS_H_
void ghb_settings_save(signal_user_data_t *ud, const gchar *name);
-void ghb_presets_load(void);
+void ghb_presets_load(signal_user_data_t *ud);
void ghb_update_from_preset(signal_user_data_t *ud, const gchar *key);
void ghb_prefs_load(signal_user_data_t *ud);
void ghb_settings_init(signal_user_data_t *ud);