1 /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
4 * Copyright (C) John Stebbins 2008 <stebbins@stebbins>
6 * presets.c is free software.
8 * You may redistribute it and/or modify it under the terms of the
9 * GNU General Public License, as published by the Free Software
10 * Foundation; either version 2 of the License, or (at your option)
15 #include <glib-object.h>
16 #include <glib/gstdio.h>
20 #include "callbacks.h"
21 #include "audiohandler.h"
22 #include "hb-backend.h"
24 #include "resources.h"
29 #define MAX_NESTED_PRESET 3
37 static GValue *presetsPlist = NULL;
38 static GValue *internalPlist = NULL;
39 static GValue *prefsPlist = NULL;
41 static const GValue* preset_dict_get_value(GValue *dict, const gchar *key);
42 static void store_plist(GValue *plist, const gchar *name);
43 static void store_presets(void);
45 // This only handle limited depth
47 ghb_tree_path_new_from_indices(gint *indices, gint len)
52 return gtk_tree_path_new_from_indices(
55 return gtk_tree_path_new_from_indices(
56 indices[0], indices[1], -1);
58 return gtk_tree_path_new_from_indices(
59 indices[0], indices[1], indices[2], -1);
61 return gtk_tree_path_new_from_indices(
62 indices[0], indices[1], indices[2], indices[3], -1);
64 return gtk_tree_path_new_from_indices(
65 indices[0], indices[1], indices[2], indices[3], indices[4], -1);
72 ghb_parse_preset_path(const gchar *path)
78 preset = ghb_array_value_new(MAX_NESTED_PRESET);
79 split = g_strsplit(path, "#", MAX_NESTED_PRESET);
80 for (ii = 0; split[ii] != NULL; ii++)
82 ghb_array_append(preset, ghb_string_value_new(split[ii]));
89 preset_path_from_indices(GValue *presets, gint *indices, gint len)
94 g_debug("preset_path_from_indices");
95 path = ghb_array_value_new(MAX_NESTED_PRESET);
96 for (ii = 0; ii < len; ii++)
102 count = ghb_array_len(presets);
103 if (indices[ii] >= count) break;
104 dict = ghb_array_get_nth(presets, indices[ii]);
105 name = ghb_dict_lookup(dict, "PresetName");
107 ghb_array_append(path, ghb_value_dup(name));
108 folder = ghb_value_boolean(preset_dict_get_value(dict, "Folder"));
111 presets = ghb_dict_lookup(dict, "ChildrenArray");
117 ghb_preset_path_string(const GValue *path)
124 gstr = g_string_new("");
127 count = ghb_array_len(path);
128 for (ii = 0; ii < count; ii++)
130 val = ghb_array_get_nth(path, ii);
131 str = ghb_value_string(val);
132 g_string_append(gstr, str);
134 g_string_append(gstr, "->");
138 str = g_string_free(gstr, FALSE);
143 debug_show_type(GType tp)
145 const gchar *str = "unknown";
146 if (tp == G_TYPE_STRING)
150 else if (tp == G_TYPE_INT)
154 else if (tp == G_TYPE_INT64)
158 else if (tp == G_TYPE_BOOLEAN)
162 else if (tp == ghb_array_get_type())
166 else if (tp == ghb_dict_get_type())
170 g_message("Type: %s", str);
174 dump_preset_path(const gchar *msg, const GValue *path)
179 debug_show_type (G_VALUE_TYPE(path));
180 str = ghb_preset_path_string(path);
181 g_message("%s path: (%s)", msg, str);
186 dump_preset_indices(const gchar *msg, gint *indices, gint len)
190 g_message("%s indices: len %d", msg, len);
191 for (ii = 0; ii < len; ii++)
193 printf("%d ", indices[ii]);
200 preset_path_cmp(const GValue *path1, const GValue *path2)
207 count = ghb_array_len(path1);
208 ii = ghb_array_len(path2);
211 for (ii = 0; ii < count; ii++)
213 val = ghb_array_get_nth(path1, ii);
214 str1 = ghb_value_string(val);
215 val = ghb_array_get_nth(path2, ii);
216 str2 = ghb_value_string(val);
217 result = strcmp(str1, str2);
228 presets_get_dict(GValue *presets, gint *indices, gint len)
230 gint ii, count, folder;
233 g_debug("presets_get_dict ()");
234 for (ii = 0; ii < len; ii++)
236 count = ghb_array_len(presets);
237 if (indices[ii] >= count) return NULL;
238 dict = ghb_array_get_nth(presets, indices[ii]);
241 folder = ghb_value_boolean(preset_dict_get_value(dict, "Folder"));
244 presets = ghb_dict_lookup(dict, "ChildrenArray");
253 presets_get_folder(GValue *presets, gint *indices, gint len)
255 gint ii, count, folder;
258 g_debug("presets_get_folder ()");
259 for (ii = 0; ii < len; ii++)
261 count = ghb_array_len(presets);
262 if (indices[ii] >= count) return NULL;
263 dict = ghb_array_get_nth(presets, indices[ii]);
264 folder = ghb_value_boolean(preset_dict_get_value(dict, "Folder"));
267 presets = ghb_dict_lookup(dict, "ChildrenArray");
275 plist_get_dict(GValue *presets, const gchar *name)
277 if (presets == NULL || name == NULL) return NULL;
278 return ghb_dict_lookup(presets, name);
282 preset_get_name(GValue *dict)
284 return g_value_get_string(preset_dict_get_value(dict, "PresetName"));
288 ghb_preset_folder(GValue *dict)
290 return ghb_value_int(preset_dict_get_value(dict, "Folder"));
294 ghb_preset_type(GValue *dict)
296 return ghb_value_int(preset_dict_get_value(dict, "Type"));
300 presets_remove_nth(GValue *presets, gint pos)
305 if (presets == NULL || pos < 0) return;
306 count = ghb_array_len(presets);
307 if (pos >= count) return;
308 dict = ghb_array_get_nth(presets, pos);
309 ghb_array_remove(presets, pos);
310 ghb_value_free(dict);
319 GValue *folder = NULL;
321 folder = presets_get_folder(presets, indices, len-1);
323 presets_remove_nth(folder, indices[len-1]);
326 g_warning("ghb_presets_remove ()");
327 g_warning("internal preset lookup error");
340 GValue *folder = NULL;
342 folder = presets_get_folder(presets, indices, len-1);
344 ghb_array_replace(folder, indices[len-1], dict);
347 g_warning("ghb_presets_replace ()");
348 g_warning("internal preset lookup error");
359 GValue *folder = NULL;
361 folder = presets_get_folder(presets, indices, len-1);
363 ghb_array_insert(folder, indices[len-1], dict);
366 g_warning("ghb_presets_insert ()");
367 g_warning("internal preset lookup error");
372 presets_find_element(GValue *presets, const gchar *name)
377 g_debug("presets_find_element () (%s)", name);
378 if (presets == NULL || name == NULL) return -1;
379 count = ghb_array_len(presets);
380 for (ii = 0; ii < count; ii++)
383 dict = ghb_array_get_nth(presets, ii);
384 str = preset_get_name(dict);
385 if (strcmp(name, str) == 0)
394 single_find_pos(GValue *presets, const gchar *name, gint type)
397 gint count, ii, ptype, last;
399 if (presets == NULL || name == NULL) return -1;
400 last = count = ghb_array_len(presets);
401 for (ii = 0; ii < count; ii++)
404 dict = ghb_array_get_nth(presets, ii);
405 str = preset_get_name(dict);
406 ptype = ghb_value_int(preset_dict_get_value(dict, "Type"));
407 if (strcasecmp(name, str) <= 0 && ptype == type)
418 presets_find_pos(const GValue *path, gint type, gint *len)
424 gint *indices = NULL;
428 g_debug("presets_find_pos () ");
429 nested = presetsPlist;
430 count = ghb_array_len(path);
431 indices = g_malloc(MAX_NESTED_PRESET * sizeof(gint));
432 for (ii = 0; ii < count-1; ii++)
434 val = ghb_array_get_nth(path, ii);
435 name = g_value_get_string(val);
436 indices[ii] = presets_find_element(nested, name);
437 if (indices[ii] == -1) return NULL;
438 dict = ghb_array_get_nth(nested, indices[ii]);
439 folder = ghb_value_boolean(preset_dict_get_value(dict, "Folder"));
443 nested = ghb_dict_lookup(dict, "ChildrenArray");
449 name = g_value_get_string(ghb_array_get_nth(path, count-1));
450 indices[ii] = single_find_pos(nested, name, type);
458 preset_tree_depth(GValue *dict)
462 folder = ghb_value_boolean(preset_dict_get_value(dict, "Folder"));
469 presets = ghb_dict_lookup(dict, "ChildrenArray");
470 count = ghb_array_len(presets);
471 for (ii = 0; ii < count; ii++)
475 dict = ghb_array_get_nth(presets, ii);
476 tmp = preset_tree_depth(dict);
477 depth = MAX(depth, tmp);
488 preset_is_default(GValue *dict)
492 val = preset_dict_get_value(dict, "Default");
493 return ghb_value_boolean(val);
497 presets_clear_default(GValue *presets)
501 count = ghb_array_len(presets);
502 for (ii = 0; ii < count; ii++)
507 dict = ghb_array_get_nth(presets, ii);
508 folder = ghb_value_boolean(preset_dict_get_value(dict, "Folder"));
513 nested = ghb_dict_lookup(dict, "ChildrenArray");
514 presets_clear_default(nested);
518 if (preset_is_default(dict))
520 ghb_dict_insert(dict, g_strdup("Default"),
521 ghb_boolean_value_new(FALSE));
528 presets_find_default2(GValue *presets, gint *len)
533 count = ghb_array_len(presets);
534 for (ii = 0; ii < count; ii++)
539 dict = ghb_array_get_nth(presets, ii);
540 folder = ghb_value_boolean(preset_dict_get_value(dict, "Folder"));
546 nested = ghb_dict_lookup(dict, "ChildrenArray");
548 indices = presets_find_default2(nested, len);
559 if (preset_is_default(dict))
561 indices = malloc(MAX_NESTED_PRESET * sizeof(gint));
572 presets_find_default(GValue *presets, gint *len)
575 return presets_find_default2(presets, len);
579 ghb_preset_indices_from_path(
587 gint *indices = NULL;
592 g_debug("ghb_preset_indices_from_path () ");
594 count = ghb_array_len(path);
596 indices = g_malloc(MAX_NESTED_PRESET * sizeof(gint));
598 for (ii = 0; ii < count; ii++)
600 val = ghb_array_get_nth(path, ii);
601 name = g_value_get_string(val);
602 indices[ii] = presets_find_element(nested, name);
603 if (indices[ii] == -1)
610 dict = ghb_array_get_nth(nested, indices[ii]);
611 folder = ghb_value_boolean(preset_dict_get_value(dict, "Folder"));
617 nested = ghb_dict_lookup(dict, "ChildrenArray");
625 ghb_presets_get_type(
633 dict = presets_get_dict(presets, indices, len);
636 type = ghb_preset_type(dict);
640 g_warning("ghb_presets_get_type ()");
641 g_warning("internal preset lookup error");
647 ghb_presets_get_folder(
653 gboolean folder = FALSE;
655 dict = presets_get_dict(presets, indices, len);
658 folder = ghb_preset_folder(dict);
662 g_warning("ghb_presets_get_folder ()");
663 g_warning("internal preset lookup error");
669 presets_set_default(gint *indices, gint len)
673 g_debug("presets_set_default ()");
674 presets_clear_default(presetsPlist);
675 dict = presets_get_dict(presetsPlist, indices, len);
678 ghb_dict_insert(dict, g_strdup("Default"), ghb_boolean_value_new(TRUE));
683 // Used for sorting dictionaries.
685 key_cmp(gconstpointer a, gconstpointer b)
687 gchar *stra = (gchar*)a;
688 gchar *strb = (gchar*)b;
690 return strcmp(stra, strb);
694 preset_dict_get_value(GValue *dict, const gchar *key)
696 const GValue *gval = NULL;
700 gval = ghb_dict_lookup(dict, key);
702 if (internalPlist == NULL) return NULL;
705 dict = plist_get_dict(internalPlist, "Presets");
706 if (dict == NULL) return NULL;
707 gval = ghb_dict_lookup(dict, key);
713 ghb_presets_get_description(GValue *pdict)
717 if (pdict == NULL) return NULL;
718 desc = g_value_get_string(
719 preset_dict_get_value(pdict, "PresetDescription"));
720 if (desc[0] == 0) return NULL;
725 static void init_settings_from_dict(
726 GValue *dest, GValue *internal, GValue *dict);
729 init_settings_from_array(
737 count = ghb_array_len(array);
738 // The first element of the internal version is always the
739 // template for the allowed values
740 gval = ghb_array_get_nth(internal, 0);
741 for (ii = 0; ii < count; ii++)
744 val = ghb_array_get_nth(array, ii);
747 if (G_VALUE_TYPE(gval) == ghb_dict_get_type())
750 new_dict = ghb_dict_value_new();
751 ghb_array_append(dest, new_dict);
752 if (G_VALUE_TYPE(val) == ghb_dict_get_type())
753 init_settings_from_dict(new_dict, gval, val);
755 init_settings_from_dict(new_dict, gval, gval);
757 else if (G_VALUE_TYPE(gval) == ghb_array_get_type())
760 new_array = ghb_array_value_new(8);
761 ghb_array_append(dest, new_array);
762 if (G_VALUE_TYPE(val) == ghb_array_get_type())
763 init_settings_from_array(new_array, gval, val);
765 init_settings_from_array(new_array, gval, gval);
769 ghb_array_append(dest, val);
775 init_settings_from_dict(
784 ghb_dict_iter_init(&iter, internal);
785 // middle (void*) cast prevents gcc warning "defreferencing type-punned
786 // pointer will break strict-aliasing rules"
787 while (g_hash_table_iter_next(
788 &iter, (gpointer*)(void*)&key, (gpointer*)(void*)&gval))
792 val = ghb_dict_lookup(dict, key);
795 if (G_VALUE_TYPE(gval) == ghb_dict_get_type())
798 new_dict = ghb_dict_value_new();
799 ghb_settings_take_value(dest, key, new_dict);
800 if (G_VALUE_TYPE(val) == ghb_dict_get_type())
801 init_settings_from_dict(new_dict, gval, val);
803 init_settings_from_dict(new_dict, gval, gval);
805 else if (G_VALUE_TYPE(gval) == ghb_array_get_type())
808 new_array = ghb_array_value_new(8);
809 ghb_settings_take_value(dest, key, new_array);
810 if (G_VALUE_TYPE(val) == ghb_array_get_type())
811 init_settings_from_array(new_array, gval, val);
813 init_settings_from_array(new_array, gval, gval);
818 ghb_settings_set_value(dest, key, val);
825 signal_user_data_t *ud,
833 ghb_dict_iter_init(&iter, internal);
834 // middle (void*) cast prevents gcc warning "defreferencing type-punned
835 // pointer will break strict-aliasing rules"
836 while (g_hash_table_iter_next(
837 &iter, (gpointer*)(void*)&key, (gpointer*)(void*)&gval))
841 val = ghb_dict_lookup(dict, key);
844 ghb_ui_update(ud, key, val);
849 preset_to_ui(signal_user_data_t *ud, GValue *dict)
851 g_debug("preset_to_ui()\n");
852 // Initialize the ui from presets file.
853 GValue *internal, *hidden;
855 // Get key list from internal default presets. This way we do not
856 // load any unknown keys.
857 if (internalPlist == NULL) return;
858 internal = plist_get_dict(internalPlist, "Presets");
859 hidden = plist_get_dict(internalPlist, "XlatPresets");
860 // Setting a ui widget will cause the corresponding setting
861 // to be set, but it also triggers a callback that can
862 // have the side effect of using other settings values
863 // that have not yet been set. So set *all* settings first
864 // then update the ui.
865 init_settings_from_dict(ud->settings, internal, dict);
866 init_settings_from_dict(ud->settings, hidden, dict);
867 init_ui_from_dict(ud, internal, dict);
868 init_ui_from_dict(ud, hidden, dict);
870 if (ghb_settings_get_boolean(ud->settings, "allow_tweaks"))
873 gval = preset_dict_get_value(dict, "PictureDeinterlace");
876 ghb_ui_update(ud, "tweak_PictureDeinterlace", gval);
878 gval = preset_dict_get_value(dict, "PictureDenoise");
881 ghb_ui_update(ud, "tweak_PictureDenoise", gval);
887 ghb_settings_to_ui(signal_user_data_t *ud, GValue *dict)
889 init_ui_from_dict(ud, dict, dict);
892 static GValue *current_preset = NULL;
895 ghb_set_preset_from_indices(signal_user_data_t *ud, gint *indices, gint len)
898 gint fallback[2] = {0, -1};
901 dict = presets_get_dict(presetsPlist, indices, len);
906 dict = presets_get_dict(presetsPlist, indices, len);
910 preset_to_ui(ud, NULL);
911 current_preset = NULL;
918 current_preset = dict;
919 folder = ghb_value_boolean(preset_dict_get_value(dict, "Folder"));
921 preset_to_ui(ud, NULL);
923 preset_to_ui(ud, dict);
924 path = preset_path_from_indices(presetsPlist, indices, len);
925 ghb_settings_set_value(ud->settings, "preset", path);
926 ghb_value_free(path);
931 curr_preset_get_value(const gchar *key)
933 if (current_preset == NULL) return NULL;
934 return preset_dict_get_value(current_preset, key);
938 ghb_update_from_preset(
939 signal_user_data_t *ud,
944 g_debug("ghb_update_from_preset() %s", key);
945 gval = curr_preset_get_value(key);
948 ghb_ui_update(ud, key, gval);
958 GtkTreeView *treeview;
959 GtkTreeSelection *selection;
964 g_debug("ghb_select_preset2()");
965 treeview = GTK_TREE_VIEW(GHB_WIDGET(builder, "presets_list"));
966 selection = gtk_tree_view_get_selection (treeview);
967 store = gtk_tree_view_get_model (treeview);
968 path = ghb_tree_path_new_from_indices(indices, len);
971 if (gtk_tree_model_get_iter(store, &iter, path))
973 gtk_tree_selection_select_iter (selection, &iter);
977 if (gtk_tree_model_get_iter_first(store, &iter))
978 gtk_tree_selection_select_iter (selection, &iter);
980 gtk_tree_path_free(path);
985 ghb_select_preset(GtkBuilder *builder, const GValue *path)
989 g_debug("ghb_select_preset()");
990 indices = ghb_preset_indices_from_path(presetsPlist, path, &len);
993 ghb_select_preset2(builder, indices, len);
999 ghb_select_default_preset(GtkBuilder *builder)
1003 g_debug("ghb_select_default_preset()");
1004 indices = presets_find_default(presetsPlist, &len);
1007 ghb_select_preset2(builder, indices, len);
1013 ghb_get_user_config_dir()
1018 dir = g_get_user_config_dir();
1019 if (!g_file_test(dir, G_FILE_TEST_IS_DIR))
1021 dir = g_get_home_dir();
1022 config = g_strdup_printf ("%s/.ghb", dir);
1023 if (!g_file_test(config, G_FILE_TEST_IS_DIR))
1024 g_mkdir (config, 0755);
1028 config = g_strdup_printf ("%s/ghb", dir);
1029 if (!g_file_test(config, G_FILE_TEST_IS_DIR))
1030 g_mkdir (config, 0755);
1036 store_plist(GValue *plist, const gchar *name)
1038 gchar *config, *path;
1041 config = ghb_get_user_config_dir();
1042 path = g_strdup_printf ("%s/%s", config, name);
1043 file = g_fopen(path, "w");
1046 ghb_plist_write(file, plist);
1051 load_plist(const gchar *name)
1053 gchar *config, *path;
1054 GValue *plist = NULL;
1056 config = ghb_get_user_config_dir();
1057 path = g_strdup_printf ("%s/%s", config, name);
1058 if (g_file_test(path, G_FILE_TEST_IS_REGULAR))
1060 plist = ghb_plist_parse_file(path);
1068 remove_plist(const gchar *name)
1070 gchar *config, *path;
1072 config = ghb_get_user_config_dir();
1073 path = g_strdup_printf ("%s/%s", config, name);
1074 if (g_file_test(path, G_FILE_TEST_IS_REGULAR))
1082 static gboolean prefs_initializing = FALSE;
1085 ghb_prefs_to_ui(signal_user_data_t *ud)
1090 GValue *internal, *dict;
1091 GHashTableIter iter;
1094 g_debug("ghb_prefs_to_ui");
1095 prefs_initializing = TRUE;
1097 // Setting a ui widget will cause the corresponding setting
1098 // to be set, but it also triggers a callback that can
1099 // have the side effect of using other settings values
1100 // that have not yet been set. So set *all* settings first
1101 // then update the ui.
1102 internal = plist_get_dict(internalPlist, "Initialization");
1103 ghb_dict_iter_init(&iter, internal);
1104 // middle (void*) cast prevents gcc warning "defreferencing type-punned
1105 // pointer will break strict-aliasing rules"
1106 while (g_hash_table_iter_next(
1107 &iter, (gpointer*)(void*)&key, (gpointer*)(void*)&gval))
1109 ghb_ui_update(ud, key, gval);
1112 dict = plist_get_dict(prefsPlist, "Preferences");
1113 internal = plist_get_dict(internalPlist, "Preferences");
1114 ghb_dict_iter_init(&iter, internal);
1115 // middle (void*) cast prevents gcc warning "defreferencing type-punned
1116 // pointer will break strict-aliasing rules"
1117 while (g_hash_table_iter_next(
1118 &iter, (gpointer*)(void*)&key, (gpointer*)(void*)&gval))
1120 const GValue *value = NULL;
1122 value = ghb_dict_lookup(dict, key);
1125 ghb_settings_set_value(ud->settings, key, value);
1127 internal = plist_get_dict(internalPlist, "Preferences");
1128 ghb_dict_iter_init(&iter, internal);
1129 // middle (void*) cast prevents gcc warning "defreferencing type-punned
1130 // pointer will break strict-aliasing rules"
1131 while (g_hash_table_iter_next(
1132 &iter, (gpointer*)(void*)&key, (gpointer*)(void*)&gval))
1134 const GValue *value = NULL;
1136 value = ghb_dict_lookup(dict, key);
1139 ghb_ui_update(ud, key, value);
1142 val = ghb_settings_get_value(ud->settings, "show_presets");
1143 ghb_ui_update(ud, "show_presets", val);
1144 if (ghb_settings_get_boolean(ud->settings, "hbfd_feature"))
1147 val = ghb_settings_get_value(ud->settings, "hbfd");
1148 ghb_ui_update(ud, "hbfd", val);
1149 action = GHB_ACTION (ud->builder, "hbfd");
1150 gtk_action_set_visible(action, TRUE);
1154 ghb_ui_update(ud, "hbfd", ghb_int64_value(0));
1156 gval = ghb_settings_get_value(ud->settings, "default_source");
1157 ghb_settings_set_value (ud->settings, "source", gval);
1158 str = ghb_settings_get_string(ud->settings, "destination_dir");
1160 gchar *path = g_strdup_printf ("%s/new_video.mp4", str);
1161 ghb_ui_update(ud, "destination", ghb_string_value(path));
1165 prefs_initializing = FALSE;
1169 ghb_prefs_save(GValue *settings)
1173 GHashTableIter iter;
1175 const GValue *value;
1177 if (prefs_initializing) return;
1178 dict = plist_get_dict(internalPlist, "Preferences");
1179 if (dict == NULL) return;
1180 pref_dict = plist_get_dict(prefsPlist, "Preferences");
1181 if (pref_dict == NULL) return;
1182 ghb_dict_iter_init(&iter, dict);
1183 // middle (void*) cast prevents gcc warning "defreferencing type-punned
1184 // pointer will break strict-aliasing rules"
1185 while (g_hash_table_iter_next(
1186 &iter, (gpointer*)(void*)&key, (gpointer*)(void*)&value))
1188 value = ghb_settings_get_value(settings, key);
1191 ghb_dict_insert(pref_dict, g_strdup(key), ghb_value_dup(value));
1194 store_plist(prefsPlist, "preferences");
1198 ghb_pref_save(GValue *settings, const gchar *key)
1200 const GValue *value;
1202 if (prefs_initializing) return;
1203 value = ghb_settings_get_value(settings, key);
1207 dict = plist_get_dict(prefsPlist, "Preferences");
1208 if (dict == NULL) return;
1209 ghb_dict_insert(dict, g_strdup(key), ghb_value_dup(value));
1210 store_plist(prefsPlist, "preferences");
1215 ghb_settings_init(signal_user_data_t *ud)
1218 GHashTableIter iter;
1223 g_debug("ghb_settings_init");
1224 prefs_initializing = TRUE;
1226 internalPlist = ghb_resource_get("internal-defaults");
1227 // Setting a ui widget will cause the corresponding setting
1228 // to be set, but it also triggers a callback that can
1229 // have the side effect of using other settings values
1230 // that have not yet been set. So set *all* settings first
1231 // then update the ui.
1232 internal = plist_get_dict(internalPlist, "Initialization");
1233 ghb_dict_iter_init(&iter, internal);
1234 // middle (void*) cast prevents gcc warning "defreferencing type-punned
1235 // pointer will break strict-aliasing rules"
1236 while (g_hash_table_iter_next(
1237 &iter, (gpointer*)(void*)&key, (gpointer*)(void*)&gval))
1239 ghb_settings_set_value(ud->settings, key, gval);
1242 internal = plist_get_dict(internalPlist, "Presets");
1243 ghb_dict_iter_init(&iter, internal);
1244 // middle (void*) cast prevents gcc warning "defreferencing type-punned
1245 // pointer will break strict-aliasing rules"
1246 while (g_hash_table_iter_next(
1247 &iter, (gpointer*)(void*)&key, (gpointer*)(void*)&gval))
1249 ghb_settings_set_value(ud->settings, key, gval);
1252 internal = plist_get_dict(internalPlist, "Preferences");
1253 ghb_dict_iter_init(&iter, internal);
1254 // middle (void*) cast prevents gcc warning "defreferencing type-punned
1255 // pointer will break strict-aliasing rules"
1256 while (g_hash_table_iter_next(
1257 &iter, (gpointer*)(void*)&key, (gpointer*)(void*)&gval))
1259 ghb_settings_set_value(ud->settings, key, gval);
1261 prefs_initializing = FALSE;
1265 ghb_settings_close()
1268 ghb_value_free(internalPlist);
1270 ghb_value_free(presetsPlist);
1272 ghb_value_free(prefsPlist);
1276 ghb_prefs_load(signal_user_data_t *ud)
1278 GValue *dict, *internal;
1279 GHashTableIter iter;
1281 GValue *gval, *path;
1283 g_debug("ghb_prefs_load");
1284 prefsPlist = load_plist("preferences");
1285 if (prefsPlist == NULL)
1286 prefsPlist = ghb_dict_value_new();
1287 dict = plist_get_dict(prefsPlist, "Preferences");
1288 internal = plist_get_dict(internalPlist, "Preferences");
1289 if (dict == NULL && internal)
1291 dict = ghb_dict_value_new();
1292 ghb_dict_insert(prefsPlist, g_strdup("Preferences"), dict);
1294 // Get defaults from internal defaults
1295 ghb_dict_iter_init(&iter, internal);
1296 // middle (void*) cast prevents gcc warning "defreferencing type-punned
1297 // pointer will break strict-aliasing rules"
1298 while (g_hash_table_iter_next(
1299 &iter, (gpointer*)(void*)&key, (gpointer*)(void*)&gval))
1301 ghb_dict_insert(dict, g_strdup(key), ghb_value_dup(gval));
1303 const gchar *dir = g_get_user_special_dir (G_USER_DIRECTORY_VIDEOS);
1308 ghb_dict_insert(dict,
1309 g_strdup("destination_dir"), ghb_value_dup(ghb_string_value(dir)));
1310 store_plist(prefsPlist, "preferences");
1312 // Read legacy default_preset preference and update accordingly
1313 path = ghb_dict_lookup(dict, "default_preset");
1318 if (G_VALUE_TYPE(path) == G_TYPE_STRING)
1322 path = ghb_array_value_new(1);
1323 ghb_array_append(path, ghb_value_dup(str));
1324 indices = ghb_preset_indices_from_path(presetsPlist, path, &len);
1325 ghb_value_free(path);
1328 indices = ghb_preset_indices_from_path(presetsPlist, path, &len);
1332 presets_set_default(indices, len);
1335 ghb_dict_remove(dict, "default_preset");
1336 store_plist(prefsPlist, "preferences");
1341 get_preset_color(gint type, gboolean folder)
1345 if (type == PRESETS_CUSTOM)
1365 ghb_presets_list_init(
1366 signal_user_data_t *ud,
1370 GtkTreeView *treeview;
1371 GtkTreeIter iter, titer, *piter;
1373 GtkTreeStore *store;
1374 const gchar *preset;
1375 GtkTreePath *parent_path;
1376 const gchar *description;
1381 GValue *presets = NULL;
1383 g_debug("ghb_presets_list_init ()");
1384 more_indices = g_malloc((len+1)*sizeof(gint));
1385 memcpy(more_indices, indices, len*sizeof(gint));
1386 presets = presets_get_folder(presetsPlist, indices, len);
1387 if (presets == NULL)
1389 g_warning("Failed to find parent folder when adding child.");
1392 count = ghb_array_len(presets);
1393 treeview = GTK_TREE_VIEW(GHB_WIDGET(ud->builder, "presets_list"));
1394 store = GTK_TREE_STORE(gtk_tree_view_get_model(treeview));
1395 parent_path = ghb_tree_path_new_from_indices(indices, len);
1398 gtk_tree_model_get_iter(GTK_TREE_MODEL(store), &titer, parent_path);
1400 gtk_tree_path_free(parent_path);
1406 for (ii = 0; ii < count; ii++)
1412 // Additional settings, add row
1413 dict = ghb_array_get_nth(presets, ii);
1414 preset = preset_get_name(dict);
1415 more_indices[len] = ii;
1416 def = preset_is_default(dict);
1418 description = ghb_presets_get_description(dict);
1419 gtk_tree_store_append(store, &iter, piter);
1420 type = ghb_preset_type(dict);
1421 folder = ghb_preset_folder(dict);
1422 color = get_preset_color(type, folder);
1423 gtk_tree_store_set(store, &iter, 0, preset,
1434 if (gtk_tree_model_iter_parent(
1435 GTK_TREE_MODEL(store), &ppiter, piter))
1437 path = gtk_tree_model_get_path(GTK_TREE_MODEL(store), &ppiter);
1438 gtk_tree_view_expand_row(treeview, path, FALSE);
1439 gtk_tree_path_free(path);
1441 path = gtk_tree_model_get_path(GTK_TREE_MODEL(store), piter);
1442 gtk_tree_view_expand_row(treeview, path, FALSE);
1443 gtk_tree_path_free(path);
1447 ghb_presets_list_init(ud, more_indices, len+1);
1450 g_free(more_indices);
1454 presets_list_update_item(
1455 signal_user_data_t *ud,
1459 GtkTreeView *treeview;
1460 GtkTreeStore *store;
1462 GtkTreePath *treepath;
1464 const gchar *description;
1466 gboolean def, folder;
1470 g_debug("presets_list_update_item ()");
1471 dict = presets_get_dict(presetsPlist, indices, len);
1474 treeview = GTK_TREE_VIEW(GHB_WIDGET(ud->builder, "presets_list"));
1475 store = GTK_TREE_STORE(gtk_tree_view_get_model(treeview));
1476 treepath = ghb_tree_path_new_from_indices(indices, len);
1477 gtk_tree_model_get_iter(GTK_TREE_MODEL(store), &iter, treepath);
1478 // Additional settings, add row
1479 name = preset_get_name(dict);
1480 def = preset_is_default(dict);
1482 description = ghb_presets_get_description(dict);
1483 type = ghb_preset_type(dict);
1484 folder = ghb_preset_folder(dict);
1485 color = get_preset_color(type, folder);
1486 gtk_tree_store_set(store, &iter, 0, name,
1494 ghb_presets_list_init(ud, indices, len);
1499 presets_list_insert(
1500 signal_user_data_t *ud,
1504 GtkTreeView *treeview;
1505 GtkTreeIter iter, titer, *piter;
1506 GtkTreeStore *store;
1507 const gchar *preset;
1508 const gchar *description;
1510 gboolean def, folder;
1513 GtkTreePath *parent_path;
1517 g_debug("presets_list_insert ()");
1518 treeview = GTK_TREE_VIEW(GHB_WIDGET(ud->builder, "presets_list"));
1519 store = GTK_TREE_STORE(gtk_tree_view_get_model(treeview));
1520 presets = presets_get_folder(presetsPlist, indices, len-1);
1521 if (presets == NULL)
1523 g_warning("Failed to find parent folder while adding child.");
1526 parent_path = ghb_tree_path_new_from_indices(indices, len-1);
1529 gtk_tree_model_get_iter(GTK_TREE_MODEL(store), &titer, parent_path);
1531 gtk_tree_path_free(parent_path);
1537 count = ghb_array_len(presets);
1538 if (indices[len-1] >= count)
1540 // Additional settings, add row
1541 dict = ghb_array_get_nth(presets, indices[len-1]);
1542 preset = preset_get_name(dict);
1543 def = preset_is_default(dict);
1545 description = ghb_presets_get_description(dict);
1546 gtk_tree_store_insert(store, &iter, piter, indices[len-1]);
1547 type = ghb_preset_type(dict);
1548 folder = ghb_preset_folder(dict);
1549 color = get_preset_color(type, folder);
1550 gtk_tree_store_set(store, &iter, 0, preset,
1558 ghb_presets_list_init(ud, indices, len);
1563 presets_list_remove(
1564 signal_user_data_t *ud,
1568 GtkTreeView *treeview;
1569 GtkTreePath *treepath;
1571 GtkTreeStore *store;
1573 g_debug("presets_list_remove ()");
1574 treeview = GTK_TREE_VIEW(GHB_WIDGET(ud->builder, "presets_list"));
1575 store = GTK_TREE_STORE(gtk_tree_view_get_model(treeview));
1576 treepath = ghb_tree_path_new_from_indices(indices, len);
1579 if (gtk_tree_model_get_iter(GTK_TREE_MODEL(store), &iter, treepath))
1580 gtk_tree_store_remove(store, &iter);
1581 gtk_tree_path_free(treepath);
1586 remove_std_presets(signal_user_data_t *ud)
1591 count = ghb_array_len(presetsPlist);
1592 for (ii = count-1; ii >= 0; ii--)
1597 dict = ghb_array_get_nth(presetsPlist, ii);
1598 ptype = ghb_value_int(preset_dict_get_value(dict, "Type"));
1599 if (ptype == PRESETS_BUILTIN)
1601 if (ghb_presets_remove(presetsPlist, &indices, 1))
1603 presets_list_remove(ud, &indices, 1);
1610 ghb_save_queue(GValue *queue)
1612 store_plist(queue, "queue");
1618 return load_plist("queue");
1622 ghb_remove_queue_file()
1624 remove_plist("queue");
1633 static value_map_t vcodec_xlat[] =
1635 {"MPEG-4 (FFmpeg)", "ffmpeg"},
1636 {"MPEG-4 (XviD)", "xvid"},
1637 {"H.264 (x264)", "x264"},
1638 {"VP3 (Theora)", "theora"},
1642 static value_map_t acodec_xlat[] =
1644 {"AAC (faac)", "faac"},
1645 {"AC3 Passthru", "ac3"},
1646 {"MP3 (lame)", "lame"},
1647 {"Vorbis (vorbis)", "vorbis"},
1651 value_map_t container_xlat[] =
1653 {"MP4 file", "mp4"},
1654 {"M4V file", "m4v"},
1655 {"MKV file", "mkv"},
1656 {"AVI file", "avi"},
1657 {"OGM file", "ogm"},
1661 value_map_t framerate_xlat[] =
1663 {"Same as source", "source"},
1668 {"23.976", "23.976"},
1675 value_map_t samplerate_xlat[] =
1686 value_map_t mix_xlat[] =
1689 {"Stereo", "stereo"},
1690 {"Dolby Surround", "dpl1"},
1691 {"Dolby Pro Logic II", "dpl2"},
1692 {"6-channel discrete", "6ch"},
1693 {"AC3 Passthru", "none"},
1697 value_map_t deint_xlat[] =
1706 value_map_t denoise_xlat[] =
1715 extern iso639_lang_t ghb_language_table[];
1718 export_lang_xlat2(GValue *lin_val)
1722 if (lin_val == NULL) return NULL;
1726 str = ghb_value_string(lin_val);
1727 for (ii = 0; ghb_language_table[ii].eng_name; ii++)
1729 if (strcmp(str, ghb_language_table[ii].iso639_2) == 0)
1731 gval = ghb_string_value_new(ghb_language_table[ii].eng_name);
1736 g_debug("Can't map language value: (%s)", str);
1742 export_subtitle_xlat2(GValue *lin_val)
1747 if (lin_val == NULL) return NULL;
1748 str = ghb_value_string(lin_val);
1749 if (strcmp(str, "none") == 0)
1751 gval = ghb_string_value_new("None");
1753 else if (strcmp(str, "auto") == 0)
1755 gval = ghb_string_value_new("Autoselect");
1759 gval = export_lang_xlat2(lin_val);
1766 import_lang_xlat2(GValue *mac_val)
1770 if (mac_val == NULL) return NULL;
1774 str = ghb_value_string(mac_val);
1775 for (ii = 0; ghb_language_table[ii].eng_name; ii++)
1777 if (strcmp(str, ghb_language_table[ii].eng_name) == 0)
1779 gval = ghb_string_value_new(ghb_language_table[ii].iso639_2);
1784 g_debug("Can't map language value: (%s)", str);
1790 import_subtitle_xlat2(GValue *mac_val)
1795 if (mac_val == NULL) return NULL;
1796 str = ghb_value_string(mac_val);
1797 if (strcmp(str, "None") == 0)
1799 gval = ghb_string_value_new("none");
1801 else if (strcmp(str, "Autoselect") == 0)
1803 gval = ghb_string_value_new("auto");
1807 gval = import_lang_xlat2(mac_val);
1814 export_audio_track_xlat2(GValue *lin_val)
1817 GValue *gval = NULL;
1819 if (lin_val == NULL) return NULL;
1820 str = ghb_value_string(lin_val);
1821 if (strcmp(str, "none") == 0)
1823 gval = ghb_int_value_new(1);
1827 gint val = ghb_value_int(lin_val) + 1;
1828 gval = ghb_int_value_new(val);
1835 import_audio_track_xlat2(GValue *mac_val)
1841 if (mac_val == NULL) return NULL;
1842 val = ghb_value_int(mac_val);
1851 str = g_strdup_printf("%d", val);
1852 gval = ghb_string_value_new(str);
1858 export_value_xlat2(value_map_t *value_map, GValue *lin_val, GType mac_type)
1862 if (lin_val == NULL) return NULL;
1867 str = ghb_value_string(lin_val);
1868 for (ii = 0; value_map[ii].mac_val; ii++)
1870 if (strcmp(str, value_map[ii].lin_val) == 0)
1872 sval = ghb_string_value_new(value_map[ii].mac_val);
1874 gval = ghb_value_new(mac_type);
1875 if (!g_value_transform(sval, gval))
1877 g_warning("can't transform");
1878 ghb_value_free(gval);
1879 ghb_value_free(sval);
1882 ghb_value_free(sval);
1886 g_debug("Can't map value: (%s)", str);
1892 export_value_xlat(GValue *dict)
1894 GValue *lin_val, *gval;
1897 key = "VideoEncoder";
1898 lin_val = ghb_dict_lookup(dict, key);
1899 gval = export_value_xlat2(vcodec_xlat, lin_val, G_TYPE_STRING);
1901 ghb_dict_insert(dict, g_strdup(key), gval);
1903 lin_val = ghb_dict_lookup(dict, key);
1904 gval = export_value_xlat2(container_xlat, lin_val, G_TYPE_STRING);
1906 ghb_dict_insert(dict, g_strdup(key), gval);
1907 key = "VideoFramerate";
1908 lin_val = ghb_dict_lookup(dict, key);
1909 gval = export_value_xlat2(framerate_xlat, lin_val, G_TYPE_STRING);
1911 ghb_dict_insert(dict, g_strdup(key), gval);
1912 key = "PictureDeinterlace";
1913 lin_val = ghb_dict_lookup(dict, key);
1914 gval = export_value_xlat2(deint_xlat, lin_val, G_TYPE_INT);
1916 ghb_dict_insert(dict, g_strdup(key), gval);
1918 ghb_dict_insert(dict, g_strdup(key), ghb_value_dup(lin_val));
1919 key = "PictureDenoise";
1920 lin_val = ghb_dict_lookup(dict, key);
1921 gval = export_value_xlat2(denoise_xlat, lin_val, G_TYPE_INT);
1923 ghb_dict_insert(dict, g_strdup(key), gval);
1925 ghb_dict_insert(dict, g_strdup(key), ghb_value_dup(lin_val));
1927 lin_val = ghb_dict_lookup(dict, key);
1928 gval = export_subtitle_xlat2(lin_val);
1930 ghb_dict_insert(dict, g_strdup(key), gval);
1936 alist = ghb_dict_lookup(dict, "AudioList");
1937 count = ghb_array_len(alist);
1938 for (ii = 0; ii < count; ii++)
1940 adict = ghb_array_get_nth(alist, ii);
1942 lin_val = ghb_dict_lookup(adict, key);
1943 gval = export_audio_track_xlat2(lin_val);
1945 ghb_dict_insert(adict, g_strdup(key), gval);
1946 key = "AudioEncoder";
1947 lin_val = ghb_dict_lookup(adict, key);
1948 gval = export_value_xlat2(acodec_xlat, lin_val, G_TYPE_STRING);
1950 ghb_dict_insert(adict, g_strdup(key), gval);
1951 key = "AudioSamplerate";
1952 lin_val = ghb_dict_lookup(adict, key);
1953 gval = export_value_xlat2(samplerate_xlat, lin_val, G_TYPE_STRING);
1955 ghb_dict_insert(adict, g_strdup(key), gval);
1956 key = "AudioMixdown";
1957 lin_val = ghb_dict_lookup(adict, key);
1958 gval = export_value_xlat2(mix_xlat, lin_val, G_TYPE_STRING);
1960 ghb_dict_insert(adict, g_strdup(key), gval);
1968 value_map_t *value_map,
1972 GValue *gval, *def_val;
1974 if (mac_val == NULL) return NULL;
1975 def_val = ghb_dict_lookup(defaults, key);
1982 str = ghb_value_string(mac_val);
1983 for (ii = 0; value_map[ii].mac_val; ii++)
1985 if (strcmp(str, value_map[ii].mac_val) == 0)
1987 sval = ghb_string_value_new(value_map[ii].lin_val);
1989 gval = ghb_value_new(G_VALUE_TYPE(def_val));
1990 if (!g_value_transform(sval, gval))
1992 g_warning("can't transform");
1993 ghb_value_free(gval);
1994 ghb_value_free(sval);
1997 ghb_value_free(sval);
2001 //g_warning("Can't map value: (%s)", str);
2006 g_warning("Bad key: (%s)", key);
2013 import_value_xlat(GValue *dict)
2015 GValue *defaults, *mac_val, *gval;
2018 defaults = plist_get_dict(internalPlist, "Presets");
2019 key = "VideoEncoder";
2020 mac_val = ghb_dict_lookup(dict, key);
2021 gval = import_value_xlat2(defaults, vcodec_xlat, key, mac_val);
2023 ghb_dict_insert(dict, g_strdup(key), gval);
2025 mac_val = ghb_dict_lookup(dict, key);
2026 gval = import_value_xlat2(defaults, container_xlat, key, mac_val);
2028 ghb_dict_insert(dict, g_strdup(key), gval);
2029 key = "VideoFramerate";
2030 mac_val = ghb_dict_lookup(dict, key);
2031 gval = import_value_xlat2(defaults, framerate_xlat, key, mac_val);
2033 ghb_dict_insert(dict, g_strdup(key), gval);
2034 key = "PictureDeinterlace";
2035 mac_val = ghb_dict_lookup(dict, key);
2036 gval = import_value_xlat2(defaults, deint_xlat, key, mac_val);
2038 ghb_dict_insert(dict, g_strdup(key), gval);
2039 key = "PictureDenoise";
2040 mac_val = ghb_dict_lookup(dict, key);
2041 gval = import_value_xlat2(defaults, denoise_xlat, key, mac_val);
2043 ghb_dict_insert(dict, g_strdup(key), gval);
2045 mac_val = ghb_dict_lookup(dict, key);
2046 gval = import_subtitle_xlat2(mac_val);
2048 ghb_dict_insert(dict, g_strdup(key), gval);
2056 adeflist = ghb_dict_lookup(dict, "AudioList");
2059 adefaults = ghb_array_get_nth(adeflist, 0);
2060 alist = ghb_dict_lookup(dict, "AudioList");
2061 count = ghb_array_len(alist);
2062 for (ii = 0; ii < count; ii++)
2064 adict = ghb_array_get_nth(alist, ii);
2066 mac_val = ghb_dict_lookup(adict, key);
2067 gval = import_audio_track_xlat2(mac_val);
2069 ghb_dict_insert(adict, g_strdup(key), gval);
2070 key = "AudioEncoder";
2071 mac_val = ghb_dict_lookup(adict, key);
2072 gval = import_value_xlat2(adefaults, acodec_xlat, key, mac_val);
2074 ghb_dict_insert(adict, g_strdup(key), gval);
2075 key = "AudioSamplerate";
2076 mac_val = ghb_dict_lookup(adict, key);
2077 gval = import_value_xlat2(adefaults, samplerate_xlat, key, mac_val);
2079 ghb_dict_insert(adict, g_strdup(key), gval);
2080 key = "AudioMixdown";
2081 mac_val = ghb_dict_lookup(adict, key);
2082 gval = import_value_xlat2(adefaults, mix_xlat, key, mac_val);
2084 ghb_dict_insert(adict, g_strdup(key), gval);
2090 import_xlat_preset(GValue *dict)
2097 g_debug("import_xlat_preset ()");
2098 uses_max = ghb_value_boolean(
2099 preset_dict_get_value(dict, "UsesMaxPictureSettings"));
2100 uses_pic = ghb_value_int(
2101 preset_dict_get_value(dict, "UsesPictureSettings"));
2102 par = ghb_value_int(preset_dict_get_value(dict, "PicturePAR"));
2103 vqtype = ghb_value_int(preset_dict_get_value(dict, "VideoQualityType"));
2105 if (uses_max || uses_pic == 2)
2107 ghb_dict_insert(dict, g_strdup("autoscale"),
2108 ghb_boolean_value_new(TRUE));
2114 ghb_dict_insert(dict, g_strdup("anamorphic"),
2115 ghb_boolean_value_new(FALSE));
2116 if (ghb_dict_lookup(dict, "ModDimensions") == NULL)
2117 ghb_dict_insert(dict, g_strdup("ModDimensions"),
2118 ghb_boolean_value_new(TRUE));
2122 ghb_dict_insert(dict, g_strdup("anamorphic"),
2123 ghb_boolean_value_new(TRUE));
2124 ghb_dict_insert(dict, g_strdup("ModDimensions"),
2125 ghb_boolean_value_new(FALSE));
2129 ghb_dict_insert(dict, g_strdup("anamorphic"),
2130 ghb_boolean_value_new(TRUE));
2131 ghb_dict_insert(dict, g_strdup("ModDimensions"),
2132 ghb_boolean_value_new(TRUE));
2136 ghb_dict_insert(dict, g_strdup("anamorphic"),
2137 ghb_boolean_value_new(TRUE));
2138 ghb_dict_insert(dict, g_strdup("ModDimensions"),
2139 ghb_boolean_value_new(TRUE));
2142 // VideoQualityType/0/1/2 - vquality_type_/target/bitrate/constant
2147 ghb_dict_insert(dict, g_strdup("vquality_type_target"),
2148 ghb_boolean_value_new(TRUE));
2149 ghb_dict_insert(dict, g_strdup("vquality_type_bitrate"),
2150 ghb_boolean_value_new(FALSE));
2151 ghb_dict_insert(dict, g_strdup("vquality_type_constant"),
2152 ghb_boolean_value_new(FALSE));
2156 ghb_dict_insert(dict, g_strdup("vquality_type_target"),
2157 ghb_boolean_value_new(FALSE));
2158 ghb_dict_insert(dict, g_strdup("vquality_type_bitrate"),
2159 ghb_boolean_value_new(TRUE));
2160 ghb_dict_insert(dict, g_strdup("vquality_type_constant"),
2161 ghb_boolean_value_new(FALSE));
2165 ghb_dict_insert(dict, g_strdup("vquality_type_target"),
2166 ghb_boolean_value_new(FALSE));
2167 ghb_dict_insert(dict, g_strdup("vquality_type_bitrate"),
2168 ghb_boolean_value_new(FALSE));
2169 ghb_dict_insert(dict, g_strdup("vquality_type_constant"),
2170 ghb_boolean_value_new(TRUE));
2174 ghb_dict_insert(dict, g_strdup("vquality_type_target"),
2175 ghb_boolean_value_new(FALSE));
2176 ghb_dict_insert(dict, g_strdup("vquality_type_bitrate"),
2177 ghb_boolean_value_new(FALSE));
2178 ghb_dict_insert(dict, g_strdup("vquality_type_constant"),
2179 ghb_boolean_value_new(TRUE));
2182 import_value_xlat(dict);
2186 import_xlat_presets(GValue *presets)
2192 g_debug("import_xlat_presets ()");
2193 if (presets == NULL) return;
2194 count = ghb_array_len(presets);
2195 for (ii = 0; ii < count; ii++)
2197 dict = ghb_array_get_nth(presets, ii);
2198 folder = ghb_value_boolean(preset_dict_get_value(dict, "Folder"));
2203 nested = ghb_dict_lookup(dict, "ChildrenArray");
2204 import_xlat_presets(nested);
2208 import_xlat_preset(dict);
2214 export_xlat_preset(GValue *dict)
2216 gboolean ana, round, autoscale, target, br, constant;
2218 g_debug("export_xlat_prest ()");
2219 autoscale = ghb_value_boolean(preset_dict_get_value(dict, "autoscale"));
2220 ana = ghb_value_boolean(preset_dict_get_value(dict, "anamorphic"));
2221 round = ghb_value_boolean(preset_dict_get_value(dict, "ModDimensions"));
2222 target = ghb_value_boolean(
2223 preset_dict_get_value(dict, "vquality_type_target"));
2224 br = ghb_value_boolean(
2225 preset_dict_get_value(dict, "vquality_type_bitrate"));
2226 constant = ghb_value_boolean(
2227 preset_dict_get_value(dict, "vquality_type_constant"));
2230 ghb_dict_insert(dict, g_strdup("UsesPictureSettings"),
2231 ghb_int_value_new(2));
2233 ghb_dict_insert(dict, g_strdup("UsesPictureSettings"),
2234 ghb_int_value_new(1));
2239 ghb_dict_insert(dict, g_strdup("PicturePAR"),
2240 ghb_int_value_new(2));
2242 ghb_dict_insert(dict, g_strdup("PicturePAR"),
2243 ghb_int_value_new(1));
2247 ghb_dict_insert(dict, g_strdup("PicturePAR"),
2248 ghb_int_value_new(0));
2250 // VideoQualityType/0/1/2 - vquality_type_/target/bitrate/constant
2253 ghb_dict_insert(dict, g_strdup("VideoQualityType"),
2254 ghb_int_value_new(0));
2258 ghb_dict_insert(dict, g_strdup("VideoQualityType"),
2259 ghb_int_value_new(1));
2263 ghb_dict_insert(dict, g_strdup("VideoQualityType"),
2264 ghb_int_value_new(2));
2266 ghb_dict_remove(dict, "autoscale");
2267 ghb_dict_remove(dict, "anamorphic");
2268 ghb_dict_remove(dict, "vquality_type_target");
2269 ghb_dict_remove(dict, "vquality_type_bitrate");
2270 ghb_dict_remove(dict, "vquality_type_constant");
2271 export_value_xlat(dict);
2275 export_xlat_presets(GValue *presets)
2281 if (presets == NULL) return;
2282 count = ghb_array_len(presets);
2283 for (ii = 0; ii < count; ii++)
2285 dict = ghb_array_get_nth(presets, ii);
2286 folder = ghb_value_boolean(preset_dict_get_value(dict, "Folder"));
2291 nested = ghb_dict_lookup(dict, "ChildrenArray");
2292 export_xlat_presets(nested);
2296 export_xlat_preset(dict);
2306 export = ghb_value_dup(presetsPlist);
2307 export_xlat_presets(export);
2308 store_plist(export, "presets");
2309 ghb_value_free(export);
2313 ghb_presets_reload(signal_user_data_t *ud)
2315 GValue *std_presets;
2319 g_debug("ghb_presets_reload()\n");
2320 std_presets = ghb_resource_get("standard-presets");
2321 if (std_presets == NULL) return;
2323 remove_std_presets(ud);
2324 indices = presets_find_default(presetsPlist, &len);
2327 presets_clear_default(std_presets);
2330 // Merge the keyfile contents into our presets
2331 count = ghb_array_len(std_presets);
2332 for (ii = count-1; ii >= 0; ii--)
2338 std_dict = ghb_array_get_nth(std_presets, ii);
2339 copy_dict = ghb_value_dup(std_dict);
2340 ghb_presets_insert(presetsPlist, copy_dict, &indices, 1);
2341 presets_list_insert(ud, &indices, 1);
2343 import_xlat_presets(presetsPlist);
2352 count = ghb_array_len(presetsPlist);
2353 for (ii = count-1; ii >= 0; ii--)
2358 dict = ghb_array_get_nth(presetsPlist, ii);
2359 type = ghb_dict_lookup(dict, "Type");
2369 presetsPlist = load_plist("presets");
2370 if (presetsPlist == NULL)
2372 presetsPlist = ghb_value_dup(ghb_resource_get("standard-presets"));
2375 else if (G_VALUE_TYPE(presetsPlist) == ghb_dict_get_type())
2376 { // Presets is older dictionary format. Convert to array
2377 ghb_value_free(presetsPlist);
2378 presetsPlist = ghb_value_dup(ghb_resource_get("standard-presets"));
2381 else if (check_old_presets())
2383 ghb_value_free(presetsPlist);
2384 presetsPlist = ghb_value_dup(ghb_resource_get("standard-presets"));
2387 import_xlat_presets(presetsPlist);
2391 settings_save(signal_user_data_t *ud, const GValue *path)
2393 GValue *dict, *internal;
2394 GHashTableIter iter;
2398 gint *indices, len, count;
2400 gboolean replace = FALSE;
2402 g_debug("settings_save");
2403 if (internalPlist == NULL) return;
2404 count = ghb_array_len(path);
2405 name = g_value_get_string(ghb_array_get_nth(path, count-1));
2406 indices = ghb_preset_indices_from_path(presetsPlist, path, &len);
2409 if (ghb_presets_get_folder(presetsPlist, indices, len))
2412 message = g_strdup_printf(
2413 "%s: Folder already exists.\n"
2414 "You can not replace it with a preset.",
2416 ghb_message_dialog(GTK_MESSAGE_ERROR, message, "Cancel", NULL);
2420 dict = ghb_dict_value_new();
2421 ghb_presets_replace(presetsPlist, dict, indices, len);
2426 indices = presets_find_pos(path, PRESETS_CUSTOM, &len);
2429 dict = ghb_dict_value_new();
2430 ghb_presets_insert(presetsPlist, dict, indices, len);
2434 g_warning("failed to find insert path");
2439 if (ghb_settings_get_boolean(ud->settings, "allow_tweaks"))
2442 str = ghb_settings_get_string(ud->settings, "tweak_PictureDeinterlace");
2445 ghb_settings_set_string(ud->settings, "PictureDeinterlace", str);
2448 str = ghb_settings_get_string(ud->settings, "tweak_PictureDenoise");
2451 ghb_settings_set_string(ud->settings, "PictureDenoise", str);
2455 autoscale = ghb_settings_get_boolean(ud->settings, "autoscale");
2456 ghb_settings_set_int64(ud->settings, "Type", PRESETS_CUSTOM);
2458 internal = plist_get_dict(internalPlist, "Presets");
2459 ghb_dict_iter_init(&iter, internal);
2460 // middle (void*) cast prevents gcc warning "defreferencing type-punned
2461 // pointer will break strict-aliasing rules"
2462 while (g_hash_table_iter_next(
2463 &iter, (gpointer*)(void*)&key, (gpointer*)(void*)&value))
2471 if (strcmp(key, "PictureWidth") == 0)
2473 key2 = "scale_width";
2475 else if (strcmp(key, "PictureHeight") == 0)
2477 key2 = "scale_height";
2480 gval = ghb_settings_get_value(ud->settings, key2);
2485 ghb_dict_insert(dict, g_strdup(key), ghb_value_dup(gval));
2487 internal = plist_get_dict(internalPlist, "XlatPresets");
2488 ghb_dict_iter_init(&iter, internal);
2489 // middle (void*) cast prevents gcc warning "defreferencing type-punned
2490 // pointer will break strict-aliasing rules"
2491 while (g_hash_table_iter_next(
2492 &iter, (gpointer*)(void*)&key, (gpointer*)(void*)&value))
2496 gval = ghb_settings_get_value(ud->settings, key);
2501 ghb_dict_insert(dict, g_strdup(key), ghb_value_dup(gval));
2503 ghb_dict_insert(dict, g_strdup("PresetName"), ghb_string_value_new(name));
2505 presets_list_update_item(ud, indices, len);
2508 ghb_dict_insert(dict, g_strdup("Default"),
2509 ghb_boolean_value_new(FALSE));
2510 presets_list_insert(ud, indices, len);
2513 ud->dont_clear_presets = TRUE;
2514 // Make the new preset the selected item
2515 ghb_select_preset2(ud->builder, indices, len);
2517 ud->dont_clear_presets = FALSE;
2522 folder_save(signal_user_data_t *ud, const GValue *path)
2524 GValue *dict, *folder;
2525 gint *indices, len, count;
2528 count = ghb_array_len(path);
2529 name = g_value_get_string(ghb_array_get_nth(path, count-1));
2530 indices = ghb_preset_indices_from_path(presetsPlist, path, &len);
2533 if (!ghb_presets_get_folder(presetsPlist, indices, len))
2536 message = g_strdup_printf(
2537 "%s: Preset already exists.\n"
2538 "You can not replace it with a folder.",
2540 ghb_message_dialog(GTK_MESSAGE_ERROR, message, "Cancel", NULL);
2545 // Already exists, update its description
2546 dict = presets_get_dict(presetsPlist, indices, len);
2547 ghb_dict_insert(dict, g_strdup("PresetDescription"),
2548 ghb_value_dup(preset_dict_get_value(
2549 ud->settings, "PresetDescription")));
2555 indices = presets_find_pos(path, PRESETS_CUSTOM, &len);
2558 dict = ghb_dict_value_new();
2559 ghb_presets_insert(presetsPlist, dict, indices, len);
2563 g_warning("failed to find insert path");
2567 ghb_dict_insert(dict, g_strdup("PresetDescription"),
2568 ghb_value_dup(preset_dict_get_value(
2569 ud->settings, "PresetDescription")));
2570 ghb_dict_insert(dict, g_strdup("PresetName"), ghb_string_value_new(name));
2571 folder = ghb_array_value_new(8);
2572 ghb_dict_insert(dict, g_strdup("ChildrenArray"), folder);
2573 ghb_dict_insert(dict, g_strdup("Type"),
2574 ghb_int64_value_new(PRESETS_CUSTOM));
2575 ghb_dict_insert(dict, g_strdup("Folder"), ghb_boolean_value_new(TRUE));
2577 presets_list_insert(ud, indices, len);
2584 ghb_presets_list_default(signal_user_data_t *ud)
2586 GtkTreeView *treeview;
2587 GtkTreePath *treepath;
2589 GtkTreeStore *store;
2592 g_debug("ghb_presets_list_default ()");
2593 treeview = GTK_TREE_VIEW(GHB_WIDGET(ud->builder, "presets_list"));
2594 store = GTK_TREE_STORE(gtk_tree_view_get_model(treeview));
2595 indices = presets_find_default(presetsPlist, &len);
2596 if (indices == NULL) return;
2597 treepath = ghb_tree_path_new_from_indices(indices, len);
2600 if (gtk_tree_model_get_iter(GTK_TREE_MODEL(store), &iter, treepath))
2602 gtk_tree_store_set(store, &iter,
2607 gtk_tree_path_free(treepath);
2613 ghb_presets_list_clear_default(signal_user_data_t *ud)
2615 GtkTreeView *treeview;
2616 GtkTreePath *treepath;
2618 GtkTreeStore *store;
2621 g_debug("ghb_presets_list_clear_default ()");
2622 treeview = GTK_TREE_VIEW(GHB_WIDGET(ud->builder, "presets_list"));
2623 store = GTK_TREE_STORE(gtk_tree_view_get_model(treeview));
2624 indices = presets_find_default(presetsPlist, &len);
2625 if (indices == NULL) return;
2626 treepath = ghb_tree_path_new_from_indices(indices, len);
2629 if (gtk_tree_model_get_iter(GTK_TREE_MODEL(store), &iter, treepath))
2631 gtk_tree_store_set(store, &iter,
2636 gtk_tree_path_free(treepath);
2642 update_audio_presets(signal_user_data_t *ud)
2644 g_debug("update_audio_presets");
2645 const GValue *audio_list;
2647 audio_list = ghb_settings_get_value(ud->settings, "audio_list");
2648 ghb_settings_set_value(ud->settings, "AudioList", audio_list);
2652 enforce_preset_type(signal_user_data_t *ud, const GValue *path)
2655 GtkWidget *normal, *folder;
2658 normal = GHB_WIDGET(ud->builder, "preset_type_normal");
2659 folder = GHB_WIDGET(ud->builder, "preset_type_folder");
2660 indices = ghb_preset_indices_from_path(presetsPlist, path, &len);
2663 fold = ghb_presets_get_folder(presetsPlist, indices, len);
2665 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(folder),
2668 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(normal),
2670 gtk_widget_set_sensitive(folder, fold);
2671 gtk_widget_set_sensitive(normal, !fold);
2676 gtk_widget_set_sensitive(folder, TRUE);
2677 gtk_widget_set_sensitive(normal, TRUE);
2682 presets_save_clicked_cb(GtkWidget *xwidget, signal_user_data_t *ud)
2687 GtkResponseType response;
2689 const gchar *name = "";
2690 gint count, *indices, len;
2692 g_debug("presets_save_clicked_cb ()");
2693 preset = ghb_settings_get_value (ud->settings, "preset_selection");
2695 count = ghb_array_len(preset);
2697 name = g_value_get_string(ghb_array_get_nth(preset, count-1));
2700 // Clear the description
2701 desc = GTK_TEXT_VIEW(GHB_WIDGET(ud->builder, "PresetDescription"));
2702 dialog = GHB_WIDGET(ud->builder, "preset_save_dialog");
2703 entry = GTK_ENTRY(GHB_WIDGET(ud->builder, "PresetName"));
2704 gtk_entry_set_text(entry, name);
2705 enforce_preset_type(ud, preset);
2706 response = gtk_dialog_run(GTK_DIALOG(dialog));
2707 gtk_widget_hide(dialog);
2708 if (response == GTK_RESPONSE_OK)
2711 const gchar *name = gtk_entry_get_text(entry);
2714 if (ghb_settings_get_boolean(ud->settings, "preset_type_folder"))
2716 if (count > MAX_NESTED_PRESET-1)
2718 count = MAX_NESTED_PRESET-1;
2721 dest = ghb_array_value_new(MAX_NESTED_PRESET);
2722 indices = ghb_preset_indices_from_path(presetsPlist, preset, &len);
2727 ptype = ghb_presets_get_type(presetsPlist, indices, len);
2728 if (ptype == PRESETS_CUSTOM)
2730 ghb_array_copy(dest, preset, count-1);
2733 ghb_array_append(dest, ghb_string_value_new(name));
2735 ghb_widget_to_setting(ud->settings, GTK_WIDGET(desc));
2736 if (ghb_settings_get_boolean(ud->settings, "preset_type_folder"))
2738 folder_save(ud, dest);
2742 // Construct the audio settings presets from the current audio list
2743 update_audio_presets(ud);
2744 settings_save(ud, dest);
2746 ghb_value_free(dest);
2751 preset_type_changed_cb(GtkWidget *widget, signal_user_data_t *ud)
2753 ghb_widget_to_setting(ud->settings, widget);
2757 preset_name_changed_cb(GtkWidget *entry, signal_user_data_t *ud)
2760 GValue *preset, *dest;
2763 preset = ghb_settings_get_value (ud->settings, "preset_selection");
2764 name = ghb_widget_string(entry);
2765 dest = ghb_value_dup(preset);
2766 count = ghb_array_len(dest);
2767 ghb_array_replace(dest, count-1, ghb_string_value_new(name));
2768 enforce_preset_type(ud, dest);
2769 ghb_value_free(dest);
2773 presets_restore_clicked_cb(GtkWidget *xwidget, signal_user_data_t *ud)
2777 g_debug("presets_restore_clicked_cb ()");
2778 // Reload only the standard presets
2779 ghb_presets_reload(ud);
2780 // Updating the presets list shuffles things around
2781 // need to make sure the proper preset is selected
2782 preset = ghb_settings_get_value (ud->settings, "preset");
2783 ghb_select_preset(ud->builder, preset);
2787 presets_remove_clicked_cb(GtkWidget *xwidget, signal_user_data_t *ud)
2789 GtkTreeView *treeview;
2790 GtkTreeSelection *selection;
2791 GtkTreeModel *store;
2794 GtkResponseType response;
2796 g_debug("presets_remove_clicked_cb ()");
2797 treeview = GTK_TREE_VIEW(GHB_WIDGET(ud->builder, "presets_list"));
2798 selection = gtk_tree_view_get_selection (treeview);
2799 if (gtk_tree_selection_get_selected(selection, &store, &iter))
2806 gtk_tree_model_get(store, &iter, 0, &preset, -1);
2807 path = gtk_tree_model_get_path(store, &iter);
2808 indices = gtk_tree_path_get_indices(path);
2809 len = gtk_tree_path_get_depth(path);
2811 folder = ghb_presets_get_folder(presetsPlist, indices, len);
2812 dialog = gtk_message_dialog_new(NULL, GTK_DIALOG_MODAL,
2813 GTK_MESSAGE_QUESTION, GTK_BUTTONS_YES_NO,
2814 "Confirm deletion of %s:\n\n%s",
2815 folder ? "folder" : "preset",
2817 response = gtk_dialog_run(GTK_DIALOG(dialog));
2818 gtk_widget_destroy (dialog);
2819 if (response == GTK_RESPONSE_YES)
2821 GtkTreeIter nextIter = iter;
2822 gboolean valid = TRUE;
2823 if (!gtk_tree_model_iter_next(store, &nextIter))
2825 if (!gtk_tree_model_iter_parent(store, &nextIter, &iter))
2830 // Remove the selected item
2831 // First unselect it so that selecting the new item works properly
2832 gtk_tree_selection_unselect_iter (selection, &iter);
2833 if (ghb_presets_remove(presetsPlist, indices, len))
2836 presets_list_remove(ud, indices, len);
2839 valid = gtk_tree_model_get_iter_first(store, &nextIter);
2842 gtk_tree_path_free(path);
2843 path = gtk_tree_model_get_path(store, &nextIter);
2844 indices = gtk_tree_path_get_indices(path);
2845 len = gtk_tree_path_get_depth(path);
2846 ghb_select_preset2(ud->builder, indices, len);
2850 gtk_tree_path_free(path);
2854 // controls where valid drop locations are
2856 presets_drag_motion_cb(
2858 GdkDragContext *ctx,
2862 signal_user_data_t *ud)
2864 GtkTreePath *path = NULL;
2865 GtkTreeViewDropPosition drop_pos;
2869 GtkTreeModel *model;
2870 GtkTreeSelection *select;
2871 gint src_ptype, dst_ptype;
2872 gboolean src_folder, dst_folder;
2874 gint tree_depth, ii;
2876 // Get the type of the object being dragged
2877 srctv = GTK_TREE_VIEW(gtk_drag_get_source_widget(ctx));
2878 select = gtk_tree_view_get_selection (srctv);
2879 gtk_tree_selection_get_selected (select, &model, &iter);
2880 path = gtk_tree_model_get_path (model, &iter);
2881 indices = gtk_tree_path_get_indices(path);
2882 len = gtk_tree_path_get_depth(path);
2884 preset = presets_get_dict(presetsPlist, indices, len);
2885 tree_depth = preset_tree_depth(preset);
2887 src_ptype = ghb_presets_get_type(presetsPlist, indices, len);
2888 src_folder = ghb_presets_get_folder(presetsPlist, indices, len);
2889 gtk_tree_path_free(path);
2891 if (src_folder && tree_depth == 1)
2894 // The rest checks that the destination is a valid position
2896 gtk_tree_view_get_dest_row_at_pos (tv, x, y, &path, &drop_pos);
2899 gdk_drag_status(ctx, 0, time);
2902 // Don't allow repositioning of builtin presets
2903 if (src_ptype != PRESETS_CUSTOM)
2905 gdk_drag_status(ctx, 0, time);
2909 len = gtk_tree_path_get_depth(path);
2910 if (len+tree_depth-1 >= MAX_NESTED_PRESET)
2912 if (drop_pos == GTK_TREE_VIEW_DROP_INTO_OR_BEFORE)
2913 drop_pos = GTK_TREE_VIEW_DROP_BEFORE;
2914 if (drop_pos == GTK_TREE_VIEW_DROP_INTO_OR_AFTER)
2915 drop_pos = GTK_TREE_VIEW_DROP_AFTER;
2917 for (ii = len+tree_depth-1; ii > MAX_NESTED_PRESET; ii--)
2918 gtk_tree_path_up(path);
2919 indices = gtk_tree_path_get_indices(path);
2920 len = gtk_tree_path_get_depth(path);
2921 dst_ptype = ghb_presets_get_type(presetsPlist, indices, len);
2922 dst_folder = ghb_presets_get_folder(presetsPlist, indices, len);
2923 // Don't allow mixing custom presets in the builtins
2924 if (dst_ptype != PRESETS_CUSTOM)
2926 gdk_drag_status(ctx, 0, time);
2930 // Only allow *drop into* for folders
2933 if (drop_pos == GTK_TREE_VIEW_DROP_INTO_OR_BEFORE)
2934 drop_pos = GTK_TREE_VIEW_DROP_BEFORE;
2935 if (drop_pos == GTK_TREE_VIEW_DROP_INTO_OR_AFTER)
2936 drop_pos = GTK_TREE_VIEW_DROP_AFTER;
2939 len = gtk_tree_path_get_depth(path);
2940 gtk_tree_view_set_drag_dest_row(tv, path, drop_pos);
2941 gtk_tree_path_free(path);
2942 gdk_drag_status(ctx, GDK_ACTION_MOVE, time);
2948 GtkTreeView *dstwidget,
2951 GtkSelectionData *selection_data,
2952 guint info, guint t,
2953 signal_user_data_t *ud)
2955 GtkTreePath *path = NULL;
2956 GtkTreeViewDropPosition drop_pos;
2957 GtkTreeIter dstiter, srciter;
2958 gint *dst_indices, dst_len, *src_indices, src_len;
2960 gboolean src_folder, dst_folder;
2962 GtkTreeModel *dstmodel = gtk_tree_view_get_model(dstwidget);
2964 g_debug("preset_drag_cb ()");
2965 // This doesn't work here for some reason...
2966 // gtk_tree_view_get_drag_dest_row(dstwidget, &path, &drop_pos);
2967 gtk_tree_view_get_dest_row_at_pos (dstwidget, x, y, &path, &drop_pos);
2968 // This little hack is needed because attempting to drop after
2969 // the last item gives us no path or drop_pos.
2974 n_children = gtk_tree_model_iter_n_children(dstmodel, NULL);
2977 drop_pos = GTK_TREE_VIEW_DROP_AFTER;
2978 path = gtk_tree_path_new_from_indices(n_children-1, -1);
2982 drop_pos = GTK_TREE_VIEW_DROP_BEFORE;
2983 path = gtk_tree_path_new_from_indices(0, -1);
2988 GtkTreeView *srcwidget;
2989 GtkTreeModel *srcmodel;
2990 GtkTreeSelection *select;
2991 GtkTreePath *srcpath = NULL;
2993 gint tree_depth, ii;
2995 srcwidget = GTK_TREE_VIEW(gtk_drag_get_source_widget(dc));
2996 select = gtk_tree_view_get_selection (srcwidget);
2997 gtk_tree_selection_get_selected (select, &srcmodel, &srciter);
2999 srcpath = gtk_tree_model_get_path (srcmodel, &srciter);
3000 src_indices = gtk_tree_path_get_indices(srcpath);
3001 src_len = gtk_tree_path_get_depth(srcpath);
3002 src_ptype = ghb_presets_get_type(presetsPlist, src_indices, src_len);
3003 src_folder = ghb_presets_get_folder(presetsPlist, src_indices, src_len);
3004 preset = ghb_value_dup(
3005 presets_get_dict(presetsPlist, src_indices, src_len));
3006 gtk_tree_path_free(srcpath);
3008 // Don't allow repositioning of builtin presets
3009 if (src_ptype != PRESETS_CUSTOM)
3012 tree_depth = preset_tree_depth(preset);
3013 if (src_folder && tree_depth == 1)
3016 dst_len = gtk_tree_path_get_depth(path);
3017 if (dst_len+tree_depth-1 >= MAX_NESTED_PRESET)
3019 if (drop_pos == GTK_TREE_VIEW_DROP_INTO_OR_BEFORE)
3020 drop_pos = GTK_TREE_VIEW_DROP_BEFORE;
3021 if (drop_pos == GTK_TREE_VIEW_DROP_INTO_OR_AFTER)
3022 drop_pos = GTK_TREE_VIEW_DROP_AFTER;
3025 for (ii = dst_len+tree_depth-1; ii > MAX_NESTED_PRESET; ii--)
3026 gtk_tree_path_up(path);
3027 dst_indices = gtk_tree_path_get_indices(path);
3028 dst_len = gtk_tree_path_get_depth(path);
3029 dst_folder = ghb_presets_get_folder(presetsPlist, dst_indices, dst_len);
3030 // Only allow *drop into* for folders
3033 if (drop_pos == GTK_TREE_VIEW_DROP_INTO_OR_BEFORE)
3034 drop_pos = GTK_TREE_VIEW_DROP_BEFORE;
3035 if (drop_pos == GTK_TREE_VIEW_DROP_INTO_OR_AFTER)
3036 drop_pos = GTK_TREE_VIEW_DROP_AFTER;
3038 if (gtk_tree_model_get_iter (dstmodel, &dstiter, path))
3041 GtkTreePath *dstpath = NULL;
3045 case GTK_TREE_VIEW_DROP_BEFORE:
3046 gtk_tree_store_insert_before(GTK_TREE_STORE (dstmodel),
3047 &iter, NULL, &dstiter);
3050 case GTK_TREE_VIEW_DROP_INTO_OR_BEFORE:
3051 gtk_tree_store_insert(GTK_TREE_STORE (dstmodel),
3052 &iter, &dstiter, 0);
3055 case GTK_TREE_VIEW_DROP_AFTER:
3056 gtk_tree_store_insert_after(GTK_TREE_STORE (dstmodel),
3057 &iter, NULL, &dstiter);
3060 case GTK_TREE_VIEW_DROP_INTO_OR_AFTER:
3061 gtk_tree_store_insert_after(GTK_TREE_STORE (dstmodel),
3062 &iter, &dstiter, 0);
3069 dstpath = gtk_tree_model_get_path (dstmodel, &iter);
3070 dst_indices = gtk_tree_path_get_indices(dstpath);
3071 dst_len = gtk_tree_path_get_depth(dstpath);
3072 ghb_presets_insert(presetsPlist, preset, dst_indices, dst_len);
3073 gtk_tree_path_free(dstpath);
3075 srcpath = gtk_tree_model_get_path (srcmodel, &srciter);
3076 src_indices = gtk_tree_path_get_indices(srcpath);
3077 src_len = gtk_tree_path_get_depth(srcpath);
3078 ghb_presets_remove(presetsPlist, src_indices, src_len);
3079 gtk_tree_path_free(srcpath);
3081 gtk_tree_store_remove (GTK_TREE_STORE (srcmodel), &srciter);
3083 dstpath = gtk_tree_model_get_path (dstmodel, &iter);
3084 dst_indices = gtk_tree_path_get_indices(dstpath);
3085 dst_len = gtk_tree_path_get_depth(dstpath);
3086 presets_list_update_item(ud, dst_indices, dst_len);
3087 gtk_tree_path_free(dstpath);
3091 gtk_tree_path_free(path);
3096 preset_update_title_deps(signal_user_data_t *ud, ghb_title_info_t *tinfo)
3100 ghb_ui_update(ud, "scale_width",
3101 ghb_int64_value(tinfo->width - tinfo->crop[2] - tinfo->crop[3]));
3102 // If anamorphic or keep_aspect, the hight will be automatically calculated
3103 gboolean keep_aspect, anamorphic;
3104 keep_aspect = ghb_settings_get_boolean(ud->settings, "PictureKeepRatio");
3105 anamorphic = ghb_settings_get_boolean(ud->settings, "anamorphic");
3106 if (!(keep_aspect || anamorphic))
3108 ghb_ui_update(ud, "scale_height",
3109 ghb_int64_value(tinfo->height - tinfo->crop[0] - tinfo->crop[1]));
3112 // Set the limits of cropping. hb_set_anamorphic_size crashes if
3113 // you pass it a cropped width or height == 0.
3115 bound = tinfo->height / 2 - 2;
3116 widget = GHB_WIDGET (ud->builder, "PictureTopCrop");
3117 gtk_spin_button_set_range (GTK_SPIN_BUTTON(widget), 0, bound);
3118 widget = GHB_WIDGET (ud->builder, "PictureBottomCrop");
3119 gtk_spin_button_set_range (GTK_SPIN_BUTTON(widget), 0, bound);
3120 bound = tinfo->width / 2 - 2;
3121 widget = GHB_WIDGET (ud->builder, "PictureLeftCrop");
3122 gtk_spin_button_set_range (GTK_SPIN_BUTTON(widget), 0, bound);
3123 widget = GHB_WIDGET (ud->builder, "PictureRightCrop");
3124 gtk_spin_button_set_range (GTK_SPIN_BUTTON(widget), 0, bound);
3125 if (ghb_settings_get_boolean(ud->settings, "PictureAutoCrop"))
3127 ghb_ui_update(ud, "PictureTopCrop", ghb_int64_value(tinfo->crop[0]));
3128 ghb_ui_update(ud, "PictureBottomCrop", ghb_int64_value(tinfo->crop[1]));
3129 ghb_ui_update(ud, "PictureLeftCrop", ghb_int64_value(tinfo->crop[2]));
3130 ghb_ui_update(ud, "PictureRightCrop", ghb_int64_value(tinfo->crop[3]));
3135 presets_list_selection_changed_cb(GtkTreeSelection *selection, signal_user_data_t *ud)
3137 GtkTreeModel *store;
3139 ghb_title_info_t tinfo;
3142 g_debug("presets_list_selection_changed_cb ()");
3143 widget = GHB_WIDGET (ud->builder, "presets_remove");
3144 if (gtk_tree_selection_get_selected(selection, &store, &iter))
3146 GtkTreePath *treepath;
3151 treepath = gtk_tree_model_get_path(store, &iter);
3152 indices = gtk_tree_path_get_indices(treepath);
3153 len = gtk_tree_path_get_depth(treepath);
3155 path = preset_path_from_indices(presetsPlist, indices, len);
3156 ghb_settings_take_value(ud->settings, "preset_selection", path);
3158 folder = ghb_presets_get_folder(presetsPlist, indices, len);
3161 ud->dont_clear_presets = TRUE;
3162 // Temporarily set the video_quality range to (0,100)
3163 // This is needed so the video_quality value does not get
3164 // truncated when set. The range will be readjusted below
3165 GtkWidget *qp = GHB_WIDGET(ud->builder, "VideoQualitySlider");
3166 gtk_range_set_range (GTK_RANGE(qp), 0, 100);
3167 gtk_scale_set_digits(GTK_SCALE(qp), 3);
3168 // Clear the audio list prior to changing the preset. Existing
3169 // audio can cause the container extension to be automatically
3170 // changed when it shouldn't be
3171 ghb_clear_audio_list(ud);
3172 ghb_set_preset_from_indices(ud, indices, len);
3173 gtk_tree_path_free(treepath);
3175 titleindex = ghb_settings_combo_int(ud->settings, "title");
3176 ghb_set_pref_audio(titleindex, ud);
3177 ghb_settings_set_boolean(ud->settings, "preset_modified", FALSE);
3178 ud->dont_clear_presets = FALSE;
3179 if (ghb_get_title_info (&tinfo, titleindex))
3181 preset_update_title_deps(ud, &tinfo);
3183 ghb_set_scale (ud, GHB_SCALE_KEEP_NONE);
3185 gdouble vqmin, vqmax, step, page;
3187 ghb_vquality_range(ud, &vqmin, &vqmax, &step, &page, &digits);
3188 gtk_range_set_range (GTK_RANGE(qp), vqmin, vqmax);
3189 gtk_range_set_increments (GTK_RANGE(qp), step, page);
3190 gtk_scale_set_digits(GTK_SCALE(qp), digits);
3194 GtkWidget *crop_widget;
3195 crop[0] = ghb_settings_get_int(ud->settings, "PictureTopCrop");
3196 crop[1] = ghb_settings_get_int(ud->settings, "PictureBottomCrop");
3197 crop[2] = ghb_settings_get_int(ud->settings, "PictureLeftCrop");
3198 crop[3] = ghb_settings_get_int(ud->settings, "PictureRightCrop");
3199 crop_widget = GHB_WIDGET (ud->builder, "crop_values");
3200 text = g_strdup_printf("%d:%d:%d:%d",
3201 crop[0], crop[1], crop[2], crop[3]);
3202 gtk_label_set_text (GTK_LABEL(crop_widget), text);
3205 gtk_widget_set_sensitive(widget, TRUE);
3209 g_debug("No selection??? Perhaps unselected.");
3210 gtk_widget_set_sensitive(widget, FALSE);
3215 ghb_clear_presets_selection(signal_user_data_t *ud)
3217 GtkTreeView *treeview;
3218 GtkTreeSelection *selection;
3220 if (ud->dont_clear_presets) return;
3221 g_debug("ghb_clear_presets_selection()");
3222 treeview = GTK_TREE_VIEW(GHB_WIDGET(ud->builder, "presets_list"));
3223 selection = gtk_tree_view_get_selection (treeview);
3224 gtk_tree_selection_unselect_all (selection);
3225 ghb_settings_set_boolean(ud->settings, "preset_modified", TRUE);
3229 presets_frame_size_allocate_cb(GtkWidget *widget, GtkAllocation *allocation, signal_user_data_t *ud)
3231 GtkTreeView *treeview;
3232 GtkTreeSelection *selection;
3233 GtkTreeModel *store;
3236 treeview = GTK_TREE_VIEW(GHB_WIDGET(ud->builder, "presets_list"));
3237 selection = gtk_tree_view_get_selection(treeview);
3238 if (gtk_tree_selection_get_selected(selection, &store, &iter))
3241 path = gtk_tree_model_get_path (store, &iter);
3242 // Make the parent visible in scroll window if it is not.
3243 gtk_tree_view_scroll_to_cell (treeview, path, NULL, FALSE, 0, 0);
3244 gtk_tree_path_free(path);
3249 presets_default_clicked_cb(GtkWidget *xwidget, signal_user_data_t *ud)
3254 g_debug("presets_default_clicked_cb ()");
3255 preset = ghb_settings_get_value(ud->settings, "preset_selection");
3256 indices = ghb_preset_indices_from_path(presetsPlist, preset, &len);
3259 if (!ghb_presets_get_folder(presetsPlist, indices, len))
3261 ghb_presets_list_clear_default(ud);
3262 presets_set_default(indices, len);
3263 ghb_presets_list_default(ud);