summaryrefslogtreecommitdiffstats
path: root/gtk
diff options
context:
space:
mode:
authorJohn Stebbins <[email protected]>2015-10-29 08:27:52 -0700
committerJohn Stebbins <[email protected]>2015-10-29 08:29:33 -0700
commitbd6d8dbba750419c4bb46b10f952cc405f7f5054 (patch)
treee910e25b49e6efd9220bcad090fcccf1fb388125 /gtk
parent5adef96a78cc94e75c79dfef5c053023751c2175 (diff)
LinGui: Fix duplicate preset name creation
Don't allow presets with the same name in the same folder. If duplicate found, append "(N)" to the name.
Diffstat (limited to 'gtk')
-rw-r--r--gtk/src/presets.c31
1 files changed, 30 insertions, 1 deletions
diff --git a/gtk/src/presets.c b/gtk/src/presets.c
index a6ee0f360..151ac8b09 100644
--- a/gtk/src/presets.c
+++ b/gtk/src/presets.c
@@ -1624,8 +1624,37 @@ settings_save(signal_user_data_t *ud, hb_preset_index_t *path, const char *name)
replace = TRUE;
}
}
+ char * new_name = strdup(name);
+ if (!replace)
+ {
+ // We are creating a new preset. Make sure there is not
+ // another preset in this folder that has the same name
+ int ii, count, index = 1;
+ GhbValue *children;
+
+ children = hb_presets_get_folder_children(path);
+ count = ghb_array_len(children);
+ do
+ {
+ for (ii = 0; ii < count; ii++)
+ {
+ GhbValue *preset;
+ const char *s;
+
+ preset = ghb_array_get(children, ii);
+ s = ghb_dict_get_string(preset, "PresetName");
+ if (s != NULL && !strcmp(s, new_name))
+ {
+ free(new_name);
+ new_name = g_strdup_printf("%s (%d)", name, index++);
+ break;
+ }
+ }
+ } while (ii < count);
+ }
dict = ghb_settings_to_preset(ud->settings);
- ghb_dict_set_string(dict, "PresetName", name);
+ ghb_dict_set_string(dict, "PresetName", new_name);
+ free(new_name);
if (replace)
{
// Already exists, update its description