OSDN Git Service

LinGui: automatically update the built-in presets when the hb build number changes
authorjstebbins <jstebbins@b64f7644-9d1e-0410-96f1-a4d463321fa5>
Tue, 26 May 2009 17:53:03 +0000 (17:53 +0000)
committerjstebbins <jstebbins@b64f7644-9d1e-0410-96f1-a4d463321fa5>
Tue, 26 May 2009 17:53:03 +0000 (17:53 +0000)
git-svn-id: svn://localhost/HandBrake/trunk@2453 b64f7644-9d1e-0410-96f1-a4d463321fa5

gtk/src/internal_defaults.xml
gtk/src/main.c
gtk/src/presets.c
gtk/src/presets.h

index 2c5bb20..3f408df 100644 (file)
        </dict>
        <key>Presets</key>
        <dict>
+               <key>PresetBuildNumber</key>
+               <string></string>
                <key>PictureAutoCrop</key>
                <true />
                <key>ChapterMarkers</key>
index db54505..ef0dc18 100644 (file)
@@ -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);
index 5d64de1..45bf963 100644 (file)
@@ -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);
index 6bcd14a..8c05f19 100644 (file)
@@ -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);