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_find_default2(GValue *presets, gint *len)
502 count = ghb_array_len(presets);
503 for (ii = 0; ii < count; ii++)
508 dict = ghb_array_get_nth(presets, ii);
509 folder = ghb_value_boolean(preset_dict_get_value(dict, "Folder"));
515 nested = ghb_dict_lookup(dict, "ChildrenArray");
517 indices = presets_find_default2(nested, len);
528 if (preset_is_default(dict))
530 indices = malloc(MAX_NESTED_PRESET * sizeof(gint));
541 presets_find_default(gint *len)
544 return presets_find_default2(presetsPlist, len);
548 ghb_preset_indices_from_path(
556 gint *indices = NULL;
561 g_debug("ghb_preset_indices_from_path () ");
563 count = ghb_array_len(path);
565 indices = g_malloc(MAX_NESTED_PRESET * sizeof(gint));
567 for (ii = 0; ii < count; ii++)
569 val = ghb_array_get_nth(path, ii);
570 name = g_value_get_string(val);
571 indices[ii] = presets_find_element(nested, name);
572 if (indices[ii] == -1)
579 dict = ghb_array_get_nth(nested, indices[ii]);
580 folder = ghb_value_boolean(preset_dict_get_value(dict, "Folder"));
586 nested = ghb_dict_lookup(dict, "ChildrenArray");
594 ghb_presets_get_type(
602 dict = presets_get_dict(presets, indices, len);
605 type = ghb_preset_type(dict);
609 g_warning("ghb_presets_get_type ()");
610 g_warning("internal preset lookup error");
616 ghb_presets_get_folder(
622 gboolean folder = FALSE;
624 dict = presets_get_dict(presets, indices, len);
627 folder = ghb_preset_folder(dict);
631 g_warning("ghb_presets_get_folder ()");
632 g_warning("internal preset lookup error");
638 presets_set_default(gint *indices, gint len)
641 gint *curr_indices, curr_len;
643 g_debug("presets_set_default ()");
644 curr_indices = presets_find_default(&curr_len);
647 dict = presets_get_dict(presetsPlist, curr_indices, curr_len);
650 ghb_dict_insert(dict, g_strdup("Default"),
651 ghb_boolean_value_new(FALSE));
654 dict = presets_get_dict(presetsPlist, indices, len);
657 ghb_dict_insert(dict, g_strdup("Default"), ghb_boolean_value_new(TRUE));
662 // Used for sorting dictionaries.
664 key_cmp(gconstpointer a, gconstpointer b)
666 gchar *stra = (gchar*)a;
667 gchar *strb = (gchar*)b;
669 return strcmp(stra, strb);
673 preset_dict_get_value(GValue *dict, const gchar *key)
675 const GValue *gval = NULL;
679 gval = ghb_dict_lookup(dict, key);
681 if (internalPlist == NULL) return NULL;
684 dict = plist_get_dict(internalPlist, "Presets");
685 if (dict == NULL) return NULL;
686 gval = ghb_dict_lookup(dict, key);
692 ghb_presets_get_description(GValue *pdict)
696 if (pdict == NULL) return NULL;
697 desc = g_value_get_string(
698 preset_dict_get_value(pdict, "PresetDescription"));
699 if (desc[0] == 0) return NULL;
704 static void init_settings_from_dict(
705 GValue *dest, GValue *internal, GValue *dict);
708 init_settings_from_array(
716 count = ghb_array_len(array);
717 // The first element of the internal version is always the
718 // template for the allowed values
719 gval = ghb_array_get_nth(internal, 0);
720 for (ii = 0; ii < count; ii++)
723 val = ghb_array_get_nth(array, ii);
726 if (G_VALUE_TYPE(gval) == ghb_dict_get_type())
729 new_dict = ghb_dict_value_new();
730 ghb_array_append(dest, new_dict);
731 if (G_VALUE_TYPE(val) == ghb_dict_get_type())
732 init_settings_from_dict(new_dict, gval, val);
734 init_settings_from_dict(new_dict, gval, gval);
736 else if (G_VALUE_TYPE(gval) == ghb_array_get_type())
739 new_array = ghb_array_value_new(8);
740 ghb_array_append(dest, new_array);
741 if (G_VALUE_TYPE(val) == ghb_array_get_type())
742 init_settings_from_array(new_array, gval, val);
744 init_settings_from_array(new_array, gval, gval);
748 ghb_array_append(dest, val);
754 init_settings_from_dict(
763 ghb_dict_iter_init(&iter, internal);
764 // middle (void*) cast prevents gcc warning "defreferencing type-punned
765 // pointer will break strict-aliasing rules"
766 while (g_hash_table_iter_next(
767 &iter, (gpointer*)(void*)&key, (gpointer*)(void*)&gval))
771 val = ghb_dict_lookup(dict, key);
774 if (G_VALUE_TYPE(gval) == ghb_dict_get_type())
777 new_dict = ghb_dict_value_new();
778 ghb_settings_take_value(dest, key, new_dict);
779 if (G_VALUE_TYPE(val) == ghb_dict_get_type())
780 init_settings_from_dict(new_dict, gval, val);
782 init_settings_from_dict(new_dict, gval, gval);
784 else if (G_VALUE_TYPE(gval) == ghb_array_get_type())
787 new_array = ghb_array_value_new(8);
788 ghb_settings_take_value(dest, key, new_array);
789 if (G_VALUE_TYPE(val) == ghb_array_get_type())
790 init_settings_from_array(new_array, gval, val);
792 init_settings_from_array(new_array, gval, gval);
797 ghb_settings_set_value(dest, key, val);
804 signal_user_data_t *ud,
812 ghb_dict_iter_init(&iter, internal);
813 // middle (void*) cast prevents gcc warning "defreferencing type-punned
814 // pointer will break strict-aliasing rules"
815 while (g_hash_table_iter_next(
816 &iter, (gpointer*)(void*)&key, (gpointer*)(void*)&gval))
820 val = ghb_dict_lookup(dict, key);
823 ghb_ui_update(ud, key, val);
828 preset_to_ui(signal_user_data_t *ud, GValue *dict)
830 g_debug("preset_to_ui()\n");
831 // Initialize the ui from presets file.
832 GValue *internal, *hidden;
834 // Get key list from internal default presets. This way we do not
835 // load any unknown keys.
836 if (internalPlist == NULL) return;
837 internal = plist_get_dict(internalPlist, "Presets");
838 hidden = plist_get_dict(internalPlist, "XlatPresets");
839 // Setting a ui widget will cause the corresponding setting
840 // to be set, but it also triggers a callback that can
841 // have the side effect of using other settings values
842 // that have not yet been set. So set *all* settings first
843 // then update the ui.
844 init_settings_from_dict(ud->settings, internal, dict);
845 init_settings_from_dict(ud->settings, hidden, dict);
846 init_ui_from_dict(ud, internal, dict);
847 init_ui_from_dict(ud, hidden, dict);
849 if (ghb_settings_get_boolean(ud->settings, "allow_tweaks"))
852 gval = preset_dict_get_value(dict, "PictureDeinterlace");
855 ghb_ui_update(ud, "tweak_PictureDeinterlace", gval);
857 gval = preset_dict_get_value(dict, "PictureDenoise");
860 ghb_ui_update(ud, "tweak_PictureDenoise", gval);
866 ghb_settings_to_ui(signal_user_data_t *ud, GValue *dict)
868 init_ui_from_dict(ud, dict, dict);
871 static GValue *current_preset = NULL;
874 ghb_set_preset_from_indices(signal_user_data_t *ud, gint *indices, gint len)
877 gint fallback[2] = {0, -1};
880 dict = presets_get_dict(presetsPlist, indices, len);
885 dict = presets_get_dict(presetsPlist, indices, len);
889 preset_to_ui(ud, NULL);
890 current_preset = NULL;
897 current_preset = dict;
898 folder = ghb_value_boolean(preset_dict_get_value(dict, "Folder"));
900 preset_to_ui(ud, NULL);
902 preset_to_ui(ud, dict);
903 path = preset_path_from_indices(presetsPlist, indices, len);
904 ghb_settings_set_value(ud->settings, "preset", path);
905 ghb_value_free(path);
910 curr_preset_get_value(const gchar *key)
912 if (current_preset == NULL) return NULL;
913 return preset_dict_get_value(current_preset, key);
917 ghb_update_from_preset(
918 signal_user_data_t *ud,
923 g_debug("ghb_update_from_preset() %s", key);
924 gval = curr_preset_get_value(key);
927 ghb_ui_update(ud, key, gval);
937 GtkTreeView *treeview;
938 GtkTreeSelection *selection;
943 g_debug("ghb_select_preset2()");
944 treeview = GTK_TREE_VIEW(GHB_WIDGET(builder, "presets_list"));
945 selection = gtk_tree_view_get_selection (treeview);
946 store = gtk_tree_view_get_model (treeview);
947 path = ghb_tree_path_new_from_indices(indices, len);
950 if (gtk_tree_model_get_iter(store, &iter, path))
952 gtk_tree_selection_select_iter (selection, &iter);
956 if (gtk_tree_model_get_iter_first(store, &iter))
957 gtk_tree_selection_select_iter (selection, &iter);
959 gtk_tree_path_free(path);
964 ghb_select_preset(GtkBuilder *builder, const GValue *path)
968 g_debug("ghb_select_preset()");
969 indices = ghb_preset_indices_from_path(presetsPlist, path, &len);
972 ghb_select_preset2(builder, indices, len);
978 ghb_select_default_preset(GtkBuilder *builder)
982 g_debug("ghb_select_default_preset()");
983 indices = presets_find_default(&len);
986 ghb_select_preset2(builder, indices, len);
992 ghb_get_user_config_dir()
997 dir = g_get_user_config_dir();
998 if (!g_file_test(dir, G_FILE_TEST_IS_DIR))
1000 dir = g_get_home_dir();
1001 config = g_strdup_printf ("%s/.ghb", dir);
1002 if (!g_file_test(config, G_FILE_TEST_IS_DIR))
1003 g_mkdir (config, 0755);
1007 config = g_strdup_printf ("%s/ghb", dir);
1008 if (!g_file_test(config, G_FILE_TEST_IS_DIR))
1009 g_mkdir (config, 0755);
1015 store_plist(GValue *plist, const gchar *name)
1017 gchar *config, *path;
1020 config = ghb_get_user_config_dir();
1021 path = g_strdup_printf ("%s/%s", config, name);
1022 file = g_fopen(path, "w");
1025 ghb_plist_write(file, plist);
1030 load_plist(const gchar *name)
1032 gchar *config, *path;
1033 GValue *plist = NULL;
1035 config = ghb_get_user_config_dir();
1036 path = g_strdup_printf ("%s/%s", config, name);
1037 if (g_file_test(path, G_FILE_TEST_IS_REGULAR))
1039 plist = ghb_plist_parse_file(path);
1047 remove_plist(const gchar *name)
1049 gchar *config, *path;
1051 config = ghb_get_user_config_dir();
1052 path = g_strdup_printf ("%s/%s", config, name);
1053 if (g_file_test(path, G_FILE_TEST_IS_REGULAR))
1061 static gboolean prefs_initializing = FALSE;
1064 ghb_prefs_to_ui(signal_user_data_t *ud)
1069 GValue *internal, *dict;
1070 GHashTableIter iter;
1073 g_debug("ghb_prefs_to_ui");
1074 prefs_initializing = TRUE;
1076 // Setting a ui widget will cause the corresponding setting
1077 // to be set, but it also triggers a callback that can
1078 // have the side effect of using other settings values
1079 // that have not yet been set. So set *all* settings first
1080 // then update the ui.
1081 internal = plist_get_dict(internalPlist, "Initialization");
1082 ghb_dict_iter_init(&iter, internal);
1083 // middle (void*) cast prevents gcc warning "defreferencing type-punned
1084 // pointer will break strict-aliasing rules"
1085 while (g_hash_table_iter_next(
1086 &iter, (gpointer*)(void*)&key, (gpointer*)(void*)&gval))
1088 ghb_ui_update(ud, key, gval);
1091 dict = plist_get_dict(prefsPlist, "Preferences");
1092 internal = plist_get_dict(internalPlist, "Preferences");
1093 ghb_dict_iter_init(&iter, internal);
1094 // middle (void*) cast prevents gcc warning "defreferencing type-punned
1095 // pointer will break strict-aliasing rules"
1096 while (g_hash_table_iter_next(
1097 &iter, (gpointer*)(void*)&key, (gpointer*)(void*)&gval))
1099 const GValue *value = NULL;
1101 value = ghb_dict_lookup(dict, key);
1104 ghb_settings_set_value(ud->settings, key, value);
1106 internal = plist_get_dict(internalPlist, "Preferences");
1107 ghb_dict_iter_init(&iter, internal);
1108 // middle (void*) cast prevents gcc warning "defreferencing type-punned
1109 // pointer will break strict-aliasing rules"
1110 while (g_hash_table_iter_next(
1111 &iter, (gpointer*)(void*)&key, (gpointer*)(void*)&gval))
1113 const GValue *value = NULL;
1115 value = ghb_dict_lookup(dict, key);
1118 ghb_ui_update(ud, key, value);
1121 val = ghb_settings_get_value(ud->settings, "show_presets");
1122 ghb_ui_update(ud, "show_presets", val);
1123 if (ghb_settings_get_boolean(ud->settings, "hbfd_feature"))
1126 val = ghb_settings_get_value(ud->settings, "hbfd");
1127 ghb_ui_update(ud, "hbfd", val);
1128 action = GHB_ACTION (ud->builder, "hbfd");
1129 gtk_action_set_visible(action, TRUE);
1133 ghb_ui_update(ud, "hbfd", ghb_int64_value(0));
1135 gval = ghb_settings_get_value(ud->settings, "default_source");
1136 ghb_settings_set_value (ud->settings, "source", gval);
1137 str = ghb_settings_get_string(ud->settings, "destination_dir");
1139 gchar *path = g_strdup_printf ("%s/new_video.mp4", str);
1140 ghb_ui_update(ud, "destination", ghb_string_value(path));
1144 prefs_initializing = FALSE;
1148 ghb_prefs_save(GValue *settings)
1152 GHashTableIter iter;
1154 const GValue *value;
1156 if (prefs_initializing) return;
1157 dict = plist_get_dict(internalPlist, "Preferences");
1158 if (dict == NULL) return;
1159 pref_dict = plist_get_dict(prefsPlist, "Preferences");
1160 if (pref_dict == NULL) return;
1161 ghb_dict_iter_init(&iter, dict);
1162 // middle (void*) cast prevents gcc warning "defreferencing type-punned
1163 // pointer will break strict-aliasing rules"
1164 while (g_hash_table_iter_next(
1165 &iter, (gpointer*)(void*)&key, (gpointer*)(void*)&value))
1167 value = ghb_settings_get_value(settings, key);
1170 ghb_dict_insert(pref_dict, g_strdup(key), ghb_value_dup(value));
1173 store_plist(prefsPlist, "preferences");
1177 ghb_pref_save(GValue *settings, const gchar *key)
1179 const GValue *value;
1181 if (prefs_initializing) return;
1182 value = ghb_settings_get_value(settings, key);
1186 dict = plist_get_dict(prefsPlist, "Preferences");
1187 if (dict == NULL) return;
1188 ghb_dict_insert(dict, g_strdup(key), ghb_value_dup(value));
1189 store_plist(prefsPlist, "preferences");
1194 ghb_settings_init(signal_user_data_t *ud)
1197 GHashTableIter iter;
1202 g_debug("ghb_settings_init");
1203 prefs_initializing = TRUE;
1205 internalPlist = ghb_resource_get("internal-defaults");
1206 // Setting a ui widget will cause the corresponding setting
1207 // to be set, but it also triggers a callback that can
1208 // have the side effect of using other settings values
1209 // that have not yet been set. So set *all* settings first
1210 // then update the ui.
1211 internal = plist_get_dict(internalPlist, "Initialization");
1212 ghb_dict_iter_init(&iter, internal);
1213 // middle (void*) cast prevents gcc warning "defreferencing type-punned
1214 // pointer will break strict-aliasing rules"
1215 while (g_hash_table_iter_next(
1216 &iter, (gpointer*)(void*)&key, (gpointer*)(void*)&gval))
1218 ghb_settings_set_value(ud->settings, key, gval);
1221 internal = plist_get_dict(internalPlist, "Presets");
1222 ghb_dict_iter_init(&iter, internal);
1223 // middle (void*) cast prevents gcc warning "defreferencing type-punned
1224 // pointer will break strict-aliasing rules"
1225 while (g_hash_table_iter_next(
1226 &iter, (gpointer*)(void*)&key, (gpointer*)(void*)&gval))
1228 ghb_settings_set_value(ud->settings, key, gval);
1231 internal = plist_get_dict(internalPlist, "Preferences");
1232 ghb_dict_iter_init(&iter, internal);
1233 // middle (void*) cast prevents gcc warning "defreferencing type-punned
1234 // pointer will break strict-aliasing rules"
1235 while (g_hash_table_iter_next(
1236 &iter, (gpointer*)(void*)&key, (gpointer*)(void*)&gval))
1238 ghb_settings_set_value(ud->settings, key, gval);
1240 prefs_initializing = FALSE;
1244 ghb_settings_close()
1247 ghb_value_free(internalPlist);
1249 ghb_value_free(presetsPlist);
1251 ghb_value_free(prefsPlist);
1255 ghb_prefs_load(signal_user_data_t *ud)
1257 GValue *dict, *internal;
1258 GHashTableIter iter;
1260 GValue *gval, *path;
1262 g_debug("ghb_prefs_load");
1263 prefsPlist = load_plist("preferences");
1264 if (prefsPlist == NULL)
1265 prefsPlist = ghb_dict_value_new();
1266 dict = plist_get_dict(prefsPlist, "Preferences");
1267 internal = plist_get_dict(internalPlist, "Preferences");
1268 if (dict == NULL && internal)
1270 dict = ghb_dict_value_new();
1271 ghb_dict_insert(prefsPlist, g_strdup("Preferences"), dict);
1273 // Get defaults from internal defaults
1274 ghb_dict_iter_init(&iter, internal);
1275 // middle (void*) cast prevents gcc warning "defreferencing type-punned
1276 // pointer will break strict-aliasing rules"
1277 while (g_hash_table_iter_next(
1278 &iter, (gpointer*)(void*)&key, (gpointer*)(void*)&gval))
1280 ghb_dict_insert(dict, g_strdup(key), ghb_value_dup(gval));
1282 const gchar *dir = g_get_user_special_dir (G_USER_DIRECTORY_VIDEOS);
1287 ghb_dict_insert(dict,
1288 g_strdup("destination_dir"), ghb_value_dup(ghb_string_value(dir)));
1289 store_plist(prefsPlist, "preferences");
1291 // Read legacy default_preset preference and update accordingly
1292 path = ghb_dict_lookup(dict, "default_preset");
1297 if (G_VALUE_TYPE(path) == G_TYPE_STRING)
1301 path = ghb_array_value_new(1);
1302 ghb_array_append(path, ghb_value_dup(str));
1303 indices = ghb_preset_indices_from_path(presetsPlist, path, &len);
1304 ghb_value_free(path);
1307 indices = ghb_preset_indices_from_path(presetsPlist, path, &len);
1311 presets_set_default(indices, len);
1314 ghb_dict_remove(dict, "default_preset");
1315 store_plist(prefsPlist, "preferences");
1320 get_preset_color(gint type, gboolean folder)
1324 if (type == PRESETS_CUSTOM)
1344 ghb_presets_list_init(
1345 signal_user_data_t *ud,
1349 GtkTreeView *treeview;
1350 GtkTreeIter iter, titer, *piter;
1352 GtkTreeStore *store;
1353 const gchar *preset;
1354 GtkTreePath *parent_path;
1355 const gchar *description;
1360 GValue *presets = NULL;
1362 g_debug("ghb_presets_list_init ()");
1363 more_indices = g_malloc((len+1)*sizeof(gint));
1364 memcpy(more_indices, indices, len*sizeof(gint));
1365 presets = presets_get_folder(presetsPlist, indices, len);
1366 if (presets == NULL)
1368 g_warning("Failed to find parent folder when adding child.");
1371 count = ghb_array_len(presets);
1372 treeview = GTK_TREE_VIEW(GHB_WIDGET(ud->builder, "presets_list"));
1373 store = GTK_TREE_STORE(gtk_tree_view_get_model(treeview));
1374 parent_path = ghb_tree_path_new_from_indices(indices, len);
1377 gtk_tree_model_get_iter(GTK_TREE_MODEL(store), &titer, parent_path);
1379 gtk_tree_path_free(parent_path);
1385 for (ii = 0; ii < count; ii++)
1391 // Additional settings, add row
1392 dict = ghb_array_get_nth(presets, ii);
1393 preset = preset_get_name(dict);
1394 more_indices[len] = ii;
1395 def = preset_is_default(dict);
1397 description = ghb_presets_get_description(dict);
1398 gtk_tree_store_append(store, &iter, piter);
1399 type = ghb_preset_type(dict);
1400 folder = ghb_preset_folder(dict);
1401 color = get_preset_color(type, folder);
1402 gtk_tree_store_set(store, &iter, 0, preset,
1413 if (gtk_tree_model_iter_parent(
1414 GTK_TREE_MODEL(store), &ppiter, piter))
1416 path = gtk_tree_model_get_path(GTK_TREE_MODEL(store), &ppiter);
1417 gtk_tree_view_expand_row(treeview, path, FALSE);
1418 gtk_tree_path_free(path);
1420 path = gtk_tree_model_get_path(GTK_TREE_MODEL(store), piter);
1421 gtk_tree_view_expand_row(treeview, path, FALSE);
1422 gtk_tree_path_free(path);
1426 ghb_presets_list_init(ud, more_indices, len+1);
1429 g_free(more_indices);
1433 presets_list_update_item(
1434 signal_user_data_t *ud,
1438 GtkTreeView *treeview;
1439 GtkTreeStore *store;
1441 GtkTreePath *treepath;
1443 const gchar *description;
1445 gboolean def, folder;
1449 g_debug("presets_list_update_item ()");
1450 dict = presets_get_dict(presetsPlist, indices, len);
1453 treeview = GTK_TREE_VIEW(GHB_WIDGET(ud->builder, "presets_list"));
1454 store = GTK_TREE_STORE(gtk_tree_view_get_model(treeview));
1455 treepath = ghb_tree_path_new_from_indices(indices, len);
1456 gtk_tree_model_get_iter(GTK_TREE_MODEL(store), &iter, treepath);
1457 // Additional settings, add row
1458 name = preset_get_name(dict);
1459 def = preset_is_default(dict);
1461 description = ghb_presets_get_description(dict);
1462 type = ghb_preset_type(dict);
1463 folder = ghb_preset_folder(dict);
1464 color = get_preset_color(type, folder);
1465 gtk_tree_store_set(store, &iter, 0, name,
1473 ghb_presets_list_init(ud, indices, len);
1478 presets_list_insert(
1479 signal_user_data_t *ud,
1483 GtkTreeView *treeview;
1484 GtkTreeIter iter, titer, *piter;
1485 GtkTreeStore *store;
1486 const gchar *preset;
1487 const gchar *description;
1489 gboolean def, folder;
1492 GtkTreePath *parent_path;
1496 g_debug("presets_list_insert ()");
1497 treeview = GTK_TREE_VIEW(GHB_WIDGET(ud->builder, "presets_list"));
1498 store = GTK_TREE_STORE(gtk_tree_view_get_model(treeview));
1499 presets = presets_get_folder(presetsPlist, indices, len-1);
1500 if (presets == NULL)
1502 g_warning("Failed to find parent folder while adding child.");
1505 parent_path = ghb_tree_path_new_from_indices(indices, len-1);
1508 gtk_tree_model_get_iter(GTK_TREE_MODEL(store), &titer, parent_path);
1510 gtk_tree_path_free(parent_path);
1516 count = ghb_array_len(presets);
1517 if (indices[len-1] >= count)
1519 // Additional settings, add row
1520 dict = ghb_array_get_nth(presets, indices[len-1]);
1521 preset = preset_get_name(dict);
1522 def = preset_is_default(dict);
1524 description = ghb_presets_get_description(dict);
1525 gtk_tree_store_insert(store, &iter, piter, indices[len-1]);
1526 type = ghb_preset_type(dict);
1527 folder = ghb_preset_folder(dict);
1528 color = get_preset_color(type, folder);
1529 gtk_tree_store_set(store, &iter, 0, preset,
1537 ghb_presets_list_init(ud, indices, len);
1542 presets_list_remove(
1543 signal_user_data_t *ud,
1547 GtkTreeView *treeview;
1548 GtkTreePath *treepath;
1550 GtkTreeStore *store;
1552 g_debug("presets_list_remove ()");
1553 treeview = GTK_TREE_VIEW(GHB_WIDGET(ud->builder, "presets_list"));
1554 store = GTK_TREE_STORE(gtk_tree_view_get_model(treeview));
1555 treepath = ghb_tree_path_new_from_indices(indices, len);
1558 if (gtk_tree_model_get_iter(GTK_TREE_MODEL(store), &iter, treepath))
1559 gtk_tree_store_remove(store, &iter);
1560 gtk_tree_path_free(treepath);
1565 remove_std_presets(signal_user_data_t *ud)
1570 count = ghb_array_len(presetsPlist);
1571 for (ii = count-1; ii >= 0; ii--)
1576 dict = ghb_array_get_nth(presetsPlist, ii);
1577 ptype = ghb_value_int(preset_dict_get_value(dict, "Type"));
1578 if (ptype == PRESETS_BUILTIN)
1580 if (ghb_presets_remove(presetsPlist, &indices, 1))
1582 presets_list_remove(ud, &indices, 1);
1589 ghb_save_queue(GValue *queue)
1591 store_plist(queue, "queue");
1597 return load_plist("queue");
1601 ghb_remove_queue_file()
1603 remove_plist("queue");
1612 static value_map_t vcodec_xlat[] =
1614 {"MPEG-4 (FFmpeg)", "ffmpeg"},
1615 {"MPEG-4 (XviD)", "xvid"},
1616 {"H.264 (x264)", "x264"},
1617 {"VP3 (Theora)", "theora"},
1621 static value_map_t acodec_xlat[] =
1623 {"AAC (faac)", "faac"},
1624 {"AC3 Passthru", "ac3"},
1625 {"MP3 (lame)", "lame"},
1626 {"Vorbis (vorbis)", "vorbis"},
1630 value_map_t container_xlat[] =
1632 {"MP4 file", "mp4"},
1633 {"M4V file", "m4v"},
1634 {"MKV file", "mkv"},
1635 {"AVI file", "avi"},
1636 {"OGM file", "ogm"},
1640 value_map_t framerate_xlat[] =
1642 {"Same as source", "source"},
1647 {"23.976", "23.976"},
1654 value_map_t samplerate_xlat[] =
1665 value_map_t mix_xlat[] =
1668 {"Stereo", "stereo"},
1669 {"Dolby Surround", "dpl1"},
1670 {"Dolby Pro Logic II", "dpl2"},
1671 {"6-channel discrete", "6ch"},
1672 {"AC3 Passthru", "none"},
1676 value_map_t deint_xlat[] =
1685 value_map_t denoise_xlat[] =
1694 extern iso639_lang_t ghb_language_table[];
1697 export_lang_xlat2(GValue *lin_val)
1701 if (lin_val == NULL) return NULL;
1705 str = ghb_value_string(lin_val);
1706 for (ii = 0; ghb_language_table[ii].eng_name; ii++)
1708 if (strcmp(str, ghb_language_table[ii].iso639_2) == 0)
1710 gval = ghb_string_value_new(ghb_language_table[ii].eng_name);
1715 g_debug("Can't map language value: (%s)", str);
1721 export_subtitle_xlat2(GValue *lin_val)
1726 str = ghb_value_string(lin_val);
1727 if (strcmp(str, "none") == 0)
1729 gval = ghb_string_value_new("None");
1731 else if (strcmp(str, "auto") == 0)
1733 gval = ghb_string_value_new("Autoselect");
1737 gval = export_lang_xlat2(lin_val);
1744 import_lang_xlat2(GValue *mac_val)
1748 if (mac_val == NULL) return NULL;
1752 str = ghb_value_string(mac_val);
1753 for (ii = 0; ghb_language_table[ii].eng_name; ii++)
1755 if (strcmp(str, ghb_language_table[ii].eng_name) == 0)
1757 gval = ghb_string_value_new(ghb_language_table[ii].iso639_2);
1762 g_debug("Can't map language value: (%s)", str);
1768 import_subtitle_xlat2(GValue *mac_val)
1773 str = ghb_value_string(mac_val);
1774 if (strcmp(str, "None") == 0)
1776 gval = ghb_string_value_new("none");
1778 else if (strcmp(str, "Autoselect") == 0)
1780 gval = ghb_string_value_new("auto");
1784 gval = import_lang_xlat2(mac_val);
1791 export_audio_track_xlat2(GValue *lin_val)
1794 GValue *gval = NULL;
1796 str = ghb_value_string(lin_val);
1797 if (strcmp(str, "none") == 0)
1799 gval = ghb_int_value_new(1);
1803 gint val = ghb_value_int(lin_val) + 1;
1804 gval = ghb_int_value_new(val);
1811 import_audio_track_xlat2(GValue *mac_val)
1817 val = ghb_value_int(mac_val);
1826 str = g_strdup_printf("%d", val);
1827 gval = ghb_string_value_new(str);
1833 export_value_xlat2(value_map_t *value_map, GValue *lin_val, GType mac_type)
1837 if (lin_val == NULL) return NULL;
1842 str = ghb_value_string(lin_val);
1843 for (ii = 0; value_map[ii].mac_val; ii++)
1845 if (strcmp(str, value_map[ii].lin_val) == 0)
1847 sval = ghb_string_value_new(value_map[ii].mac_val);
1849 gval = ghb_value_new(mac_type);
1850 if (!g_value_transform(sval, gval))
1852 g_warning("can't transform");
1853 ghb_value_free(gval);
1854 ghb_value_free(sval);
1857 ghb_value_free(sval);
1861 g_debug("Can't map value: (%s)", str);
1867 export_value_xlat(GValue *dict)
1869 GValue *lin_val, *gval;
1872 key = "VideoEncoder";
1873 lin_val = ghb_dict_lookup(dict, key);
1874 gval = export_value_xlat2(vcodec_xlat, lin_val, G_TYPE_STRING);
1876 ghb_dict_insert(dict, g_strdup(key), gval);
1878 lin_val = ghb_dict_lookup(dict, key);
1879 gval = export_value_xlat2(container_xlat, lin_val, G_TYPE_STRING);
1881 ghb_dict_insert(dict, g_strdup(key), gval);
1882 key = "VideoFramerate";
1883 lin_val = ghb_dict_lookup(dict, key);
1884 gval = export_value_xlat2(framerate_xlat, lin_val, G_TYPE_STRING);
1886 ghb_dict_insert(dict, g_strdup(key), gval);
1887 key = "PictureDeinterlace";
1888 lin_val = ghb_dict_lookup(dict, key);
1889 gval = export_value_xlat2(deint_xlat, lin_val, G_TYPE_INT);
1891 ghb_dict_insert(dict, g_strdup(key), gval);
1893 ghb_dict_insert(dict, g_strdup(key), ghb_value_dup(lin_val));
1894 key = "PictureDenoise";
1895 lin_val = ghb_dict_lookup(dict, key);
1896 gval = export_value_xlat2(denoise_xlat, lin_val, G_TYPE_INT);
1898 ghb_dict_insert(dict, g_strdup(key), gval);
1900 ghb_dict_insert(dict, g_strdup(key), ghb_value_dup(lin_val));
1902 lin_val = ghb_dict_lookup(dict, key);
1903 gval = export_subtitle_xlat2(lin_val);
1905 ghb_dict_insert(dict, g_strdup(key), gval);
1911 alist = ghb_dict_lookup(dict, "AudioList");
1912 count = ghb_array_len(alist);
1913 for (ii = 0; ii < count; ii++)
1915 adict = ghb_array_get_nth(alist, ii);
1917 lin_val = ghb_dict_lookup(adict, key);
1918 gval = export_audio_track_xlat2(lin_val);
1920 ghb_dict_insert(adict, g_strdup(key), gval);
1921 key = "AudioEncoder";
1922 lin_val = ghb_dict_lookup(adict, key);
1923 gval = export_value_xlat2(acodec_xlat, lin_val, G_TYPE_STRING);
1925 ghb_dict_insert(adict, g_strdup(key), gval);
1926 key = "AudioSamplerate";
1927 lin_val = ghb_dict_lookup(adict, key);
1928 gval = export_value_xlat2(samplerate_xlat, lin_val, G_TYPE_STRING);
1930 ghb_dict_insert(adict, g_strdup(key), gval);
1931 key = "AudioMixdown";
1932 lin_val = ghb_dict_lookup(adict, key);
1933 gval = export_value_xlat2(mix_xlat, lin_val, G_TYPE_STRING);
1935 ghb_dict_insert(adict, g_strdup(key), gval);
1943 value_map_t *value_map,
1947 GValue *gval, *def_val;
1949 if (mac_val == NULL) return NULL;
1950 def_val = ghb_dict_lookup(defaults, key);
1957 str = ghb_value_string(mac_val);
1958 for (ii = 0; value_map[ii].mac_val; ii++)
1960 if (strcmp(str, value_map[ii].mac_val) == 0)
1962 sval = ghb_string_value_new(value_map[ii].lin_val);
1964 gval = ghb_value_new(G_VALUE_TYPE(def_val));
1965 if (!g_value_transform(sval, gval))
1967 g_warning("can't transform");
1968 ghb_value_free(gval);
1969 ghb_value_free(sval);
1972 ghb_value_free(sval);
1976 //g_warning("Can't map value: (%s)", str);
1981 g_warning("Bad key: (%s)", key);
1988 import_value_xlat(GValue *dict)
1990 GValue *defaults, *mac_val, *gval;
1993 defaults = plist_get_dict(internalPlist, "Presets");
1994 key = "VideoEncoder";
1995 mac_val = ghb_dict_lookup(dict, key);
1996 gval = import_value_xlat2(defaults, vcodec_xlat, key, mac_val);
1998 ghb_dict_insert(dict, g_strdup(key), gval);
2000 mac_val = ghb_dict_lookup(dict, key);
2001 gval = import_value_xlat2(defaults, container_xlat, key, mac_val);
2003 ghb_dict_insert(dict, g_strdup(key), gval);
2004 key = "VideoFramerate";
2005 mac_val = ghb_dict_lookup(dict, key);
2006 gval = import_value_xlat2(defaults, framerate_xlat, key, mac_val);
2008 ghb_dict_insert(dict, g_strdup(key), gval);
2009 key = "PictureDeinterlace";
2010 mac_val = ghb_dict_lookup(dict, key);
2011 gval = import_value_xlat2(defaults, deint_xlat, key, mac_val);
2013 ghb_dict_insert(dict, g_strdup(key), gval);
2014 key = "PictureDenoise";
2015 mac_val = ghb_dict_lookup(dict, key);
2016 gval = import_value_xlat2(defaults, denoise_xlat, key, mac_val);
2018 ghb_dict_insert(dict, g_strdup(key), gval);
2020 mac_val = ghb_dict_lookup(dict, key);
2021 gval = import_subtitle_xlat2(mac_val);
2023 ghb_dict_insert(dict, g_strdup(key), gval);
2031 adeflist = ghb_dict_lookup(dict, "AudioList");
2034 adefaults = ghb_array_get_nth(adeflist, 0);
2035 alist = ghb_dict_lookup(dict, "AudioList");
2036 count = ghb_array_len(alist);
2037 for (ii = 0; ii < count; ii++)
2039 adict = ghb_array_get_nth(alist, ii);
2041 mac_val = ghb_dict_lookup(adict, key);
2042 gval = import_audio_track_xlat2(mac_val);
2044 ghb_dict_insert(adict, g_strdup(key), gval);
2045 key = "AudioEncoder";
2046 mac_val = ghb_dict_lookup(adict, key);
2047 gval = import_value_xlat2(adefaults, acodec_xlat, key, mac_val);
2049 ghb_dict_insert(adict, g_strdup(key), gval);
2050 key = "AudioSamplerate";
2051 mac_val = ghb_dict_lookup(adict, key);
2052 gval = import_value_xlat2(adefaults, samplerate_xlat, key, mac_val);
2054 ghb_dict_insert(adict, g_strdup(key), gval);
2055 key = "AudioMixdown";
2056 mac_val = ghb_dict_lookup(adict, key);
2057 gval = import_value_xlat2(adefaults, mix_xlat, key, mac_val);
2059 ghb_dict_insert(adict, g_strdup(key), gval);
2065 import_xlat_preset(GValue *dict)
2072 g_debug("import_xlat_preset ()");
2073 uses_max = ghb_value_boolean(
2074 preset_dict_get_value(dict, "UsesMaxPictureSettings"));
2075 uses_pic = ghb_value_int(
2076 preset_dict_get_value(dict, "UsesPictureSettings"));
2077 par = ghb_value_int(preset_dict_get_value(dict, "PicturePAR"));
2078 vqtype = ghb_value_int(preset_dict_get_value(dict, "VideoQualityType"));
2080 if (uses_max || uses_pic == 2)
2082 ghb_dict_insert(dict, g_strdup("autoscale"),
2083 ghb_boolean_value_new(TRUE));
2089 ghb_dict_insert(dict, g_strdup("anamorphic"),
2090 ghb_boolean_value_new(FALSE));
2091 if (ghb_dict_lookup(dict, "ModDimensions") == NULL)
2092 ghb_dict_insert(dict, g_strdup("ModDimensions"),
2093 ghb_boolean_value_new(TRUE));
2097 ghb_dict_insert(dict, g_strdup("anamorphic"),
2098 ghb_boolean_value_new(TRUE));
2099 ghb_dict_insert(dict, g_strdup("ModDimensions"),
2100 ghb_boolean_value_new(FALSE));
2104 ghb_dict_insert(dict, g_strdup("anamorphic"),
2105 ghb_boolean_value_new(TRUE));
2106 ghb_dict_insert(dict, g_strdup("ModDimensions"),
2107 ghb_boolean_value_new(TRUE));
2111 ghb_dict_insert(dict, g_strdup("anamorphic"),
2112 ghb_boolean_value_new(TRUE));
2113 ghb_dict_insert(dict, g_strdup("ModDimensions"),
2114 ghb_boolean_value_new(TRUE));
2117 // VideoQualityType/0/1/2 - vquality_type_/target/bitrate/constant
2122 ghb_dict_insert(dict, g_strdup("vquality_type_target"),
2123 ghb_boolean_value_new(TRUE));
2124 ghb_dict_insert(dict, g_strdup("vquality_type_bitrate"),
2125 ghb_boolean_value_new(FALSE));
2126 ghb_dict_insert(dict, g_strdup("vquality_type_constant"),
2127 ghb_boolean_value_new(FALSE));
2131 ghb_dict_insert(dict, g_strdup("vquality_type_target"),
2132 ghb_boolean_value_new(FALSE));
2133 ghb_dict_insert(dict, g_strdup("vquality_type_bitrate"),
2134 ghb_boolean_value_new(TRUE));
2135 ghb_dict_insert(dict, g_strdup("vquality_type_constant"),
2136 ghb_boolean_value_new(FALSE));
2140 ghb_dict_insert(dict, g_strdup("vquality_type_target"),
2141 ghb_boolean_value_new(FALSE));
2142 ghb_dict_insert(dict, g_strdup("vquality_type_bitrate"),
2143 ghb_boolean_value_new(FALSE));
2144 ghb_dict_insert(dict, g_strdup("vquality_type_constant"),
2145 ghb_boolean_value_new(TRUE));
2149 ghb_dict_insert(dict, g_strdup("vquality_type_target"),
2150 ghb_boolean_value_new(FALSE));
2151 ghb_dict_insert(dict, g_strdup("vquality_type_bitrate"),
2152 ghb_boolean_value_new(FALSE));
2153 ghb_dict_insert(dict, g_strdup("vquality_type_constant"),
2154 ghb_boolean_value_new(TRUE));
2157 import_value_xlat(dict);
2161 import_xlat_presets(GValue *presets)
2167 g_debug("import_xlat_presets ()");
2168 if (presets == NULL) return;
2169 count = ghb_array_len(presets);
2170 for (ii = 0; ii < count; ii++)
2172 dict = ghb_array_get_nth(presets, ii);
2173 folder = ghb_value_boolean(preset_dict_get_value(dict, "Folder"));
2178 nested = ghb_dict_lookup(dict, "ChildrenArray");
2179 import_xlat_presets(nested);
2183 import_xlat_preset(dict);
2189 export_xlat_preset(GValue *dict)
2191 gboolean ana, round, autoscale, target, br, constant;
2193 g_debug("export_xlat_prest ()");
2194 autoscale = ghb_value_boolean(preset_dict_get_value(dict, "autoscale"));
2195 ana = ghb_value_boolean(preset_dict_get_value(dict, "anamorphic"));
2196 round = ghb_value_boolean(preset_dict_get_value(dict, "ModDimensions"));
2197 target = ghb_value_boolean(
2198 preset_dict_get_value(dict, "vquality_type_target"));
2199 br = ghb_value_boolean(
2200 preset_dict_get_value(dict, "vquality_type_bitrate"));
2201 constant = ghb_value_boolean(
2202 preset_dict_get_value(dict, "vquality_type_constant"));
2205 ghb_dict_insert(dict, g_strdup("UsesPictureSettings"),
2206 ghb_int_value_new(2));
2208 ghb_dict_insert(dict, g_strdup("UsesPictureSettings"),
2209 ghb_int_value_new(1));
2214 ghb_dict_insert(dict, g_strdup("PicturePAR"),
2215 ghb_int_value_new(2));
2217 ghb_dict_insert(dict, g_strdup("PicturePAR"),
2218 ghb_int_value_new(1));
2222 ghb_dict_insert(dict, g_strdup("PicturePAR"),
2223 ghb_int_value_new(0));
2225 // VideoQualityType/0/1/2 - vquality_type_/target/bitrate/constant
2228 ghb_dict_insert(dict, g_strdup("VideoQualityType"),
2229 ghb_int_value_new(0));
2233 ghb_dict_insert(dict, g_strdup("VideoQualityType"),
2234 ghb_int_value_new(1));
2238 ghb_dict_insert(dict, g_strdup("VideoQualityType"),
2239 ghb_int_value_new(2));
2241 ghb_dict_remove(dict, "autoscale");
2242 ghb_dict_remove(dict, "anamorphic");
2243 ghb_dict_remove(dict, "vquality_type_target");
2244 ghb_dict_remove(dict, "vquality_type_bitrate");
2245 ghb_dict_remove(dict, "vquality_type_constant");
2246 export_value_xlat(dict);
2250 export_xlat_presets(GValue *presets)
2256 if (presets == NULL) return;
2257 count = ghb_array_len(presets);
2258 for (ii = 0; ii < count; ii++)
2260 dict = ghb_array_get_nth(presets, ii);
2261 folder = ghb_value_boolean(preset_dict_get_value(dict, "Folder"));
2266 nested = ghb_dict_lookup(dict, "ChildrenArray");
2267 export_xlat_presets(nested);
2271 export_xlat_preset(dict);
2281 export = ghb_value_dup(presetsPlist);
2282 export_xlat_presets(export);
2283 store_plist(export, "presets");
2284 ghb_value_free(export);
2288 ghb_presets_reload(signal_user_data_t *ud)
2290 GValue *std_presets;
2293 g_debug("ghb_presets_reload()\n");
2294 std_presets = ghb_resource_get("standard-presets");
2295 if (std_presets == NULL) return;
2297 remove_std_presets(ud);
2298 // Merge the keyfile contents into our presets
2299 count = ghb_array_len(std_presets);
2300 for (ii = count-1; ii >= 0; ii--)
2304 GHashTableIter iter;
2309 std_dict = ghb_array_get_nth(std_presets, ii);
2310 copy_dict = ghb_dict_value_new();
2311 ghb_presets_insert(presetsPlist, copy_dict, &indices, 1);
2312 ghb_dict_iter_init(&iter, std_dict);
2313 // middle (void*) cast prevents gcc warning "defreferencing
2314 // type-punned pointer will break strict-aliasing rules"
2315 while (g_hash_table_iter_next(
2316 &iter, (gpointer*)(void*)&key, (gpointer*)(void*)&value))
2318 ghb_dict_insert(copy_dict, g_strdup(key), ghb_value_dup(value));
2320 presets_list_insert(ud, &indices, 1);
2322 import_xlat_presets(presetsPlist);
2329 presetsPlist = load_plist("presets");
2330 if (presetsPlist == NULL)
2332 presetsPlist = ghb_value_dup(ghb_resource_get("standard-presets"));
2335 else if (G_VALUE_TYPE(presetsPlist) == ghb_dict_get_type())
2336 { // Presets is older dictionary format. Convert to array
2337 ghb_value_free(presetsPlist);
2338 presetsPlist = ghb_value_dup(ghb_resource_get("standard-presets"));
2341 import_xlat_presets(presetsPlist);
2345 settings_save(signal_user_data_t *ud, const GValue *path)
2347 GValue *dict, *internal;
2348 GHashTableIter iter;
2352 gint *indices, len, count;
2354 gboolean replace = FALSE;
2356 g_debug("settings_save");
2357 if (internalPlist == NULL) return;
2358 count = ghb_array_len(path);
2359 name = g_value_get_string(ghb_array_get_nth(path, count-1));
2360 indices = ghb_preset_indices_from_path(presetsPlist, path, &len);
2363 if (ghb_presets_get_folder(presetsPlist, indices, len))
2366 message = g_strdup_printf(
2367 "%s: Folder already exists.\n"
2368 "You can not replace it with a preset.",
2370 ghb_message_dialog(GTK_MESSAGE_ERROR, message, "Cancel", NULL);
2374 dict = ghb_dict_value_new();
2375 ghb_presets_replace(presetsPlist, dict, indices, len);
2380 indices = presets_find_pos(path, PRESETS_CUSTOM, &len);
2383 dict = ghb_dict_value_new();
2384 ghb_presets_insert(presetsPlist, dict, indices, len);
2388 g_warning("failed to find insert path");
2393 if (ghb_settings_get_boolean(ud->settings, "allow_tweaks"))
2396 str = ghb_settings_get_string(ud->settings, "tweak_PictureDeinterlace");
2399 ghb_settings_set_string(ud->settings, "PictureDeinterlace", str);
2402 str = ghb_settings_get_string(ud->settings, "tweak_PictureDenoise");
2405 ghb_settings_set_string(ud->settings, "PictureDenoise", str);
2409 autoscale = ghb_settings_get_boolean(ud->settings, "autoscale");
2410 ghb_settings_set_int64(ud->settings, "Type", PRESETS_CUSTOM);
2412 internal = plist_get_dict(internalPlist, "Presets");
2413 ghb_dict_iter_init(&iter, internal);
2414 // middle (void*) cast prevents gcc warning "defreferencing type-punned
2415 // pointer will break strict-aliasing rules"
2416 while (g_hash_table_iter_next(
2417 &iter, (gpointer*)(void*)&key, (gpointer*)(void*)&value))
2425 if (strcmp(key, "PictureWidth") == 0)
2427 key2 = "scale_width";
2429 else if (strcmp(key, "PictureHeight") == 0)
2431 key2 = "scale_height";
2434 gval = ghb_settings_get_value(ud->settings, key2);
2439 ghb_dict_insert(dict, g_strdup(key), ghb_value_dup(gval));
2441 internal = plist_get_dict(internalPlist, "XlatPresets");
2442 ghb_dict_iter_init(&iter, internal);
2443 // middle (void*) cast prevents gcc warning "defreferencing type-punned
2444 // pointer will break strict-aliasing rules"
2445 while (g_hash_table_iter_next(
2446 &iter, (gpointer*)(void*)&key, (gpointer*)(void*)&value))
2450 gval = ghb_settings_get_value(ud->settings, key);
2455 ghb_dict_insert(dict, g_strdup(key), ghb_value_dup(gval));
2457 ghb_dict_insert(dict, g_strdup("PresetName"), ghb_string_value_new(name));
2459 presets_list_update_item(ud, indices, len);
2462 ghb_dict_insert(dict, g_strdup("Default"),
2463 ghb_boolean_value_new(FALSE));
2464 presets_list_insert(ud, indices, len);
2467 ud->dont_clear_presets = TRUE;
2468 // Make the new preset the selected item
2469 ghb_select_preset2(ud->builder, indices, len);
2471 ud->dont_clear_presets = FALSE;
2476 folder_save(signal_user_data_t *ud, const GValue *path)
2478 GValue *dict, *folder;
2479 gint *indices, len, count;
2482 count = ghb_array_len(path);
2483 name = g_value_get_string(ghb_array_get_nth(path, count-1));
2484 indices = ghb_preset_indices_from_path(presetsPlist, path, &len);
2487 if (!ghb_presets_get_folder(presetsPlist, indices, len))
2490 message = g_strdup_printf(
2491 "%s: Preset already exists.\n"
2492 "You can not replace it with a folder.",
2494 ghb_message_dialog(GTK_MESSAGE_ERROR, message, "Cancel", NULL);
2499 // Already exists, update its description
2500 dict = presets_get_dict(presetsPlist, indices, len);
2501 ghb_dict_insert(dict, g_strdup("PresetDescription"),
2502 ghb_value_dup(preset_dict_get_value(
2503 ud->settings, "PresetDescription")));
2509 indices = presets_find_pos(path, PRESETS_CUSTOM, &len);
2512 dict = ghb_dict_value_new();
2513 ghb_presets_insert(presetsPlist, dict, indices, len);
2517 g_warning("failed to find insert path");
2521 ghb_dict_insert(dict, g_strdup("PresetDescription"),
2522 ghb_value_dup(preset_dict_get_value(
2523 ud->settings, "PresetDescription")));
2524 ghb_dict_insert(dict, g_strdup("PresetName"), ghb_string_value_new(name));
2525 folder = ghb_array_value_new(8);
2526 ghb_dict_insert(dict, g_strdup("ChildrenArray"), folder);
2527 ghb_dict_insert(dict, g_strdup("Type"),
2528 ghb_int64_value_new(PRESETS_CUSTOM));
2529 ghb_dict_insert(dict, g_strdup("Folder"), ghb_boolean_value_new(TRUE));
2531 presets_list_insert(ud, indices, len);
2538 ghb_presets_list_default(signal_user_data_t *ud)
2540 GtkTreeView *treeview;
2541 GtkTreePath *treepath;
2543 GtkTreeStore *store;
2546 g_debug("ghb_presets_list_default ()");
2547 treeview = GTK_TREE_VIEW(GHB_WIDGET(ud->builder, "presets_list"));
2548 store = GTK_TREE_STORE(gtk_tree_view_get_model(treeview));
2549 indices = presets_find_default(&len);
2550 if (indices == NULL) return;
2551 treepath = ghb_tree_path_new_from_indices(indices, len);
2554 if (gtk_tree_model_get_iter(GTK_TREE_MODEL(store), &iter, treepath))
2556 gtk_tree_store_set(store, &iter,
2561 gtk_tree_path_free(treepath);
2567 ghb_presets_list_clear_default(signal_user_data_t *ud)
2569 GtkTreeView *treeview;
2570 GtkTreePath *treepath;
2572 GtkTreeStore *store;
2575 g_debug("ghb_presets_list_clear_default ()");
2576 treeview = GTK_TREE_VIEW(GHB_WIDGET(ud->builder, "presets_list"));
2577 store = GTK_TREE_STORE(gtk_tree_view_get_model(treeview));
2578 indices = presets_find_default(&len);
2579 if (indices == NULL) return;
2580 treepath = ghb_tree_path_new_from_indices(indices, len);
2583 if (gtk_tree_model_get_iter(GTK_TREE_MODEL(store), &iter, treepath))
2585 gtk_tree_store_set(store, &iter,
2590 gtk_tree_path_free(treepath);
2596 update_audio_presets(signal_user_data_t *ud)
2598 g_debug("update_audio_presets");
2599 const GValue *audio_list;
2601 audio_list = ghb_settings_get_value(ud->settings, "audio_list");
2602 ghb_settings_set_value(ud->settings, "AudioList", audio_list);
2606 enforce_preset_type(signal_user_data_t *ud, const GValue *path)
2609 GtkWidget *normal, *folder;
2612 normal = GHB_WIDGET(ud->builder, "preset_type_normal");
2613 folder = GHB_WIDGET(ud->builder, "preset_type_folder");
2614 indices = ghb_preset_indices_from_path(presetsPlist, path, &len);
2617 fold = ghb_presets_get_folder(presetsPlist, indices, len);
2619 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(folder),
2622 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(normal),
2624 gtk_widget_set_sensitive(folder, fold);
2625 gtk_widget_set_sensitive(normal, !fold);
2630 gtk_widget_set_sensitive(folder, TRUE);
2631 gtk_widget_set_sensitive(normal, TRUE);
2636 presets_save_clicked_cb(GtkWidget *xwidget, signal_user_data_t *ud)
2641 GtkResponseType response;
2643 const gchar *name = "";
2644 gint count, *indices, len;
2646 g_debug("presets_save_clicked_cb ()");
2647 preset = ghb_settings_get_value (ud->settings, "preset_selection");
2649 count = ghb_array_len(preset);
2651 name = g_value_get_string(ghb_array_get_nth(preset, count-1));
2654 // Clear the description
2655 desc = GTK_TEXT_VIEW(GHB_WIDGET(ud->builder, "PresetDescription"));
2656 dialog = GHB_WIDGET(ud->builder, "preset_save_dialog");
2657 entry = GTK_ENTRY(GHB_WIDGET(ud->builder, "PresetName"));
2658 gtk_entry_set_text(entry, name);
2659 enforce_preset_type(ud, preset);
2660 response = gtk_dialog_run(GTK_DIALOG(dialog));
2661 gtk_widget_hide(dialog);
2662 if (response == GTK_RESPONSE_OK)
2665 const gchar *name = gtk_entry_get_text(entry);
2668 if (ghb_settings_get_boolean(ud->settings, "preset_type_folder"))
2670 if (count > MAX_NESTED_PRESET-1)
2672 count = MAX_NESTED_PRESET-1;
2675 dest = ghb_array_value_new(MAX_NESTED_PRESET);
2676 indices = ghb_preset_indices_from_path(presetsPlist, preset, &len);
2681 ptype = ghb_presets_get_type(presetsPlist, indices, len);
2682 if (ptype == PRESETS_CUSTOM)
2684 ghb_array_copy(dest, preset, count-1);
2687 ghb_array_append(dest, ghb_string_value_new(name));
2689 ghb_widget_to_setting(ud->settings, GTK_WIDGET(desc));
2690 if (ghb_settings_get_boolean(ud->settings, "preset_type_folder"))
2692 folder_save(ud, dest);
2696 // Construct the audio settings presets from the current audio list
2697 update_audio_presets(ud);
2698 settings_save(ud, dest);
2700 ghb_value_free(dest);
2705 preset_type_changed_cb(GtkWidget *widget, signal_user_data_t *ud)
2707 ghb_widget_to_setting(ud->settings, widget);
2711 preset_name_changed_cb(GtkWidget *entry, signal_user_data_t *ud)
2714 GValue *preset, *dest;
2717 preset = ghb_settings_get_value (ud->settings, "preset_selection");
2718 name = ghb_widget_string(entry);
2719 dest = ghb_value_dup(preset);
2720 count = ghb_array_len(dest);
2721 ghb_array_replace(dest, count-1, ghb_string_value_new(name));
2722 enforce_preset_type(ud, dest);
2723 ghb_value_free(dest);
2727 presets_restore_clicked_cb(GtkWidget *xwidget, signal_user_data_t *ud)
2731 g_debug("presets_restore_clicked_cb ()");
2732 // Reload only the standard presets
2733 ghb_presets_reload(ud);
2734 // Updating the presets list shuffles things around
2735 // need to make sure the proper preset is selected
2736 preset = ghb_settings_get_value (ud->settings, "preset");
2737 ghb_select_preset(ud->builder, preset);
2741 presets_remove_clicked_cb(GtkWidget *xwidget, signal_user_data_t *ud)
2743 GtkTreeView *treeview;
2744 GtkTreeSelection *selection;
2745 GtkTreeModel *store;
2748 GtkResponseType response;
2750 g_debug("presets_remove_clicked_cb ()");
2751 treeview = GTK_TREE_VIEW(GHB_WIDGET(ud->builder, "presets_list"));
2752 selection = gtk_tree_view_get_selection (treeview);
2753 if (gtk_tree_selection_get_selected(selection, &store, &iter))
2760 gtk_tree_model_get(store, &iter, 0, &preset, -1);
2761 path = gtk_tree_model_get_path(store, &iter);
2762 indices = gtk_tree_path_get_indices(path);
2763 len = gtk_tree_path_get_depth(path);
2765 folder = ghb_presets_get_folder(presetsPlist, indices, len);
2766 dialog = gtk_message_dialog_new(NULL, GTK_DIALOG_MODAL,
2767 GTK_MESSAGE_QUESTION, GTK_BUTTONS_YES_NO,
2768 "Confirm deletion of %s:\n\n%s",
2769 folder ? "folder" : "preset",
2771 response = gtk_dialog_run(GTK_DIALOG(dialog));
2772 gtk_widget_destroy (dialog);
2773 if (response == GTK_RESPONSE_YES)
2775 GtkTreeIter nextIter = iter;
2776 gboolean valid = TRUE;
2777 if (!gtk_tree_model_iter_next(store, &nextIter))
2779 if (!gtk_tree_model_iter_parent(store, &nextIter, &iter))
2784 // Remove the selected item
2785 // First unselect it so that selecting the new item works properly
2786 gtk_tree_selection_unselect_iter (selection, &iter);
2787 if (ghb_presets_remove(presetsPlist, indices, len))
2790 presets_list_remove(ud, indices, len);
2793 valid = gtk_tree_model_get_iter_first(store, &nextIter);
2796 gtk_tree_path_free(path);
2797 path = gtk_tree_model_get_path(store, &nextIter);
2798 indices = gtk_tree_path_get_indices(path);
2799 len = gtk_tree_path_get_depth(path);
2800 ghb_select_preset2(ud->builder, indices, len);
2804 gtk_tree_path_free(path);
2808 // controls where valid drop locations are
2810 presets_drag_motion_cb(
2812 GdkDragContext *ctx,
2816 signal_user_data_t *ud)
2818 GtkTreePath *path = NULL;
2819 GtkTreeViewDropPosition drop_pos;
2823 GtkTreeModel *model;
2824 GtkTreeSelection *select;
2825 gint src_ptype, dst_ptype;
2826 gboolean src_folder, dst_folder;
2828 gint tree_depth, ii;
2830 // Get the type of the object being dragged
2831 srctv = GTK_TREE_VIEW(gtk_drag_get_source_widget(ctx));
2832 select = gtk_tree_view_get_selection (srctv);
2833 gtk_tree_selection_get_selected (select, &model, &iter);
2834 path = gtk_tree_model_get_path (model, &iter);
2835 indices = gtk_tree_path_get_indices(path);
2836 len = gtk_tree_path_get_depth(path);
2838 preset = presets_get_dict(presetsPlist, indices, len);
2839 tree_depth = preset_tree_depth(preset);
2841 src_ptype = ghb_presets_get_type(presetsPlist, indices, len);
2842 src_folder = ghb_presets_get_folder(presetsPlist, indices, len);
2843 gtk_tree_path_free(path);
2845 if (src_folder && tree_depth == 1)
2848 // The rest checks that the destination is a valid position
2850 gtk_tree_view_get_dest_row_at_pos (tv, x, y, &path, &drop_pos);
2853 gdk_drag_status(ctx, 0, time);
2856 // Don't allow repositioning of builtin presets
2857 if (src_ptype != PRESETS_CUSTOM)
2859 gdk_drag_status(ctx, 0, time);
2863 len = gtk_tree_path_get_depth(path);
2864 if (len+tree_depth-1 >= MAX_NESTED_PRESET)
2866 if (drop_pos == GTK_TREE_VIEW_DROP_INTO_OR_BEFORE)
2867 drop_pos = GTK_TREE_VIEW_DROP_BEFORE;
2868 if (drop_pos == GTK_TREE_VIEW_DROP_INTO_OR_AFTER)
2869 drop_pos = GTK_TREE_VIEW_DROP_AFTER;
2871 for (ii = len+tree_depth-1; ii > MAX_NESTED_PRESET; ii--)
2872 gtk_tree_path_up(path);
2873 indices = gtk_tree_path_get_indices(path);
2874 len = gtk_tree_path_get_depth(path);
2875 dst_ptype = ghb_presets_get_type(presetsPlist, indices, len);
2876 dst_folder = ghb_presets_get_folder(presetsPlist, indices, len);
2877 // Don't allow mixing custom presets in the builtins
2878 if (dst_ptype != PRESETS_CUSTOM)
2880 gdk_drag_status(ctx, 0, time);
2884 // Only allow *drop into* for folders
2887 if (drop_pos == GTK_TREE_VIEW_DROP_INTO_OR_BEFORE)
2888 drop_pos = GTK_TREE_VIEW_DROP_BEFORE;
2889 if (drop_pos == GTK_TREE_VIEW_DROP_INTO_OR_AFTER)
2890 drop_pos = GTK_TREE_VIEW_DROP_AFTER;
2893 len = gtk_tree_path_get_depth(path);
2894 gtk_tree_view_set_drag_dest_row(tv, path, drop_pos);
2895 gtk_tree_path_free(path);
2896 gdk_drag_status(ctx, GDK_ACTION_MOVE, time);
2902 GtkTreeView *dstwidget,
2905 GtkSelectionData *selection_data,
2906 guint info, guint t,
2907 signal_user_data_t *ud)
2909 GtkTreePath *path = NULL;
2910 GtkTreeViewDropPosition drop_pos;
2911 GtkTreeIter dstiter, srciter;
2912 gint *dst_indices, dst_len, *src_indices, src_len;
2914 gboolean src_folder, dst_folder;
2916 GtkTreeModel *dstmodel = gtk_tree_view_get_model(dstwidget);
2918 g_debug("preset_drag_cb ()");
2919 // This doesn't work here for some reason...
2920 // gtk_tree_view_get_drag_dest_row(dstwidget, &path, &drop_pos);
2921 gtk_tree_view_get_dest_row_at_pos (dstwidget, x, y, &path, &drop_pos);
2922 // This little hack is needed because attempting to drop after
2923 // the last item gives us no path or drop_pos.
2928 n_children = gtk_tree_model_iter_n_children(dstmodel, NULL);
2931 drop_pos = GTK_TREE_VIEW_DROP_AFTER;
2932 path = gtk_tree_path_new_from_indices(n_children-1, -1);
2936 drop_pos = GTK_TREE_VIEW_DROP_BEFORE;
2937 path = gtk_tree_path_new_from_indices(0, -1);
2942 GtkTreeView *srcwidget;
2943 GtkTreeModel *srcmodel;
2944 GtkTreeSelection *select;
2945 GtkTreePath *srcpath = NULL;
2947 gint tree_depth, ii;
2949 srcwidget = GTK_TREE_VIEW(gtk_drag_get_source_widget(dc));
2950 select = gtk_tree_view_get_selection (srcwidget);
2951 gtk_tree_selection_get_selected (select, &srcmodel, &srciter);
2953 srcpath = gtk_tree_model_get_path (srcmodel, &srciter);
2954 src_indices = gtk_tree_path_get_indices(srcpath);
2955 src_len = gtk_tree_path_get_depth(srcpath);
2956 src_ptype = ghb_presets_get_type(presetsPlist, src_indices, src_len);
2957 src_folder = ghb_presets_get_folder(presetsPlist, src_indices, src_len);
2958 preset = ghb_value_dup(
2959 presets_get_dict(presetsPlist, src_indices, src_len));
2960 gtk_tree_path_free(srcpath);
2962 // Don't allow repositioning of builtin presets
2963 if (src_ptype != PRESETS_CUSTOM)
2966 tree_depth = preset_tree_depth(preset);
2967 if (src_folder && tree_depth == 1)
2970 dst_len = gtk_tree_path_get_depth(path);
2971 if (dst_len+tree_depth-1 >= MAX_NESTED_PRESET)
2973 if (drop_pos == GTK_TREE_VIEW_DROP_INTO_OR_BEFORE)
2974 drop_pos = GTK_TREE_VIEW_DROP_BEFORE;
2975 if (drop_pos == GTK_TREE_VIEW_DROP_INTO_OR_AFTER)
2976 drop_pos = GTK_TREE_VIEW_DROP_AFTER;
2979 for (ii = dst_len+tree_depth-1; ii > MAX_NESTED_PRESET; ii--)
2980 gtk_tree_path_up(path);
2981 dst_indices = gtk_tree_path_get_indices(path);
2982 dst_len = gtk_tree_path_get_depth(path);
2983 dst_folder = ghb_presets_get_folder(presetsPlist, dst_indices, dst_len);
2984 // Only allow *drop into* for folders
2987 if (drop_pos == GTK_TREE_VIEW_DROP_INTO_OR_BEFORE)
2988 drop_pos = GTK_TREE_VIEW_DROP_BEFORE;
2989 if (drop_pos == GTK_TREE_VIEW_DROP_INTO_OR_AFTER)
2990 drop_pos = GTK_TREE_VIEW_DROP_AFTER;
2992 if (gtk_tree_model_get_iter (dstmodel, &dstiter, path))
2995 GtkTreePath *dstpath = NULL;
2999 case GTK_TREE_VIEW_DROP_BEFORE:
3000 gtk_tree_store_insert_before(GTK_TREE_STORE (dstmodel),
3001 &iter, NULL, &dstiter);
3004 case GTK_TREE_VIEW_DROP_INTO_OR_BEFORE:
3005 gtk_tree_store_insert(GTK_TREE_STORE (dstmodel),
3006 &iter, &dstiter, 0);
3009 case GTK_TREE_VIEW_DROP_AFTER:
3010 gtk_tree_store_insert_after(GTK_TREE_STORE (dstmodel),
3011 &iter, NULL, &dstiter);
3014 case GTK_TREE_VIEW_DROP_INTO_OR_AFTER:
3015 gtk_tree_store_insert_after(GTK_TREE_STORE (dstmodel),
3016 &iter, &dstiter, 0);
3023 dstpath = gtk_tree_model_get_path (dstmodel, &iter);
3024 dst_indices = gtk_tree_path_get_indices(dstpath);
3025 dst_len = gtk_tree_path_get_depth(dstpath);
3026 ghb_presets_insert(presetsPlist, preset, dst_indices, dst_len);
3027 gtk_tree_path_free(dstpath);
3029 srcpath = gtk_tree_model_get_path (srcmodel, &srciter);
3030 src_indices = gtk_tree_path_get_indices(srcpath);
3031 src_len = gtk_tree_path_get_depth(srcpath);
3032 ghb_presets_remove(presetsPlist, src_indices, src_len);
3033 gtk_tree_path_free(srcpath);
3035 gtk_tree_store_remove (GTK_TREE_STORE (srcmodel), &srciter);
3037 dstpath = gtk_tree_model_get_path (dstmodel, &iter);
3038 dst_indices = gtk_tree_path_get_indices(dstpath);
3039 dst_len = gtk_tree_path_get_depth(dstpath);
3040 presets_list_update_item(ud, dst_indices, dst_len);
3041 gtk_tree_path_free(dstpath);
3045 gtk_tree_path_free(path);
3050 preset_update_title_deps(signal_user_data_t *ud, ghb_title_info_t *tinfo)
3054 ghb_ui_update(ud, "scale_width",
3055 ghb_int64_value(tinfo->width - tinfo->crop[2] - tinfo->crop[3]));
3056 // If anamorphic or keep_aspect, the hight will be automatically calculated
3057 gboolean keep_aspect, anamorphic;
3058 keep_aspect = ghb_settings_get_boolean(ud->settings, "PictureKeepRatio");
3059 anamorphic = ghb_settings_get_boolean(ud->settings, "anamorphic");
3060 if (!(keep_aspect || anamorphic))
3062 ghb_ui_update(ud, "scale_height",
3063 ghb_int64_value(tinfo->height - tinfo->crop[0] - tinfo->crop[1]));
3066 // Set the limits of cropping. hb_set_anamorphic_size crashes if
3067 // you pass it a cropped width or height == 0.
3069 bound = tinfo->height / 2 - 2;
3070 widget = GHB_WIDGET (ud->builder, "PictureTopCrop");
3071 gtk_spin_button_set_range (GTK_SPIN_BUTTON(widget), 0, bound);
3072 widget = GHB_WIDGET (ud->builder, "PictureBottomCrop");
3073 gtk_spin_button_set_range (GTK_SPIN_BUTTON(widget), 0, bound);
3074 bound = tinfo->width / 2 - 2;
3075 widget = GHB_WIDGET (ud->builder, "PictureLeftCrop");
3076 gtk_spin_button_set_range (GTK_SPIN_BUTTON(widget), 0, bound);
3077 widget = GHB_WIDGET (ud->builder, "PictureRightCrop");
3078 gtk_spin_button_set_range (GTK_SPIN_BUTTON(widget), 0, bound);
3079 if (ghb_settings_get_boolean(ud->settings, "PictureAutoCrop"))
3081 ghb_ui_update(ud, "PictureTopCrop", ghb_int64_value(tinfo->crop[0]));
3082 ghb_ui_update(ud, "PictureBottomCrop", ghb_int64_value(tinfo->crop[1]));
3083 ghb_ui_update(ud, "PictureLeftCrop", ghb_int64_value(tinfo->crop[2]));
3084 ghb_ui_update(ud, "PictureRightCrop", ghb_int64_value(tinfo->crop[3]));
3089 presets_list_selection_changed_cb(GtkTreeSelection *selection, signal_user_data_t *ud)
3091 GtkTreeModel *store;
3093 ghb_title_info_t tinfo;
3096 g_debug("presets_list_selection_changed_cb ()");
3097 widget = GHB_WIDGET (ud->builder, "presets_remove");
3098 if (gtk_tree_selection_get_selected(selection, &store, &iter))
3100 GtkTreePath *treepath;
3105 treepath = gtk_tree_model_get_path(store, &iter);
3106 indices = gtk_tree_path_get_indices(treepath);
3107 len = gtk_tree_path_get_depth(treepath);
3109 path = preset_path_from_indices(presetsPlist, indices, len);
3110 ghb_settings_take_value(ud->settings, "preset_selection", path);
3112 folder = ghb_presets_get_folder(presetsPlist, indices, len);
3115 ud->dont_clear_presets = TRUE;
3116 // Temporarily set the video_quality range to (0,100)
3117 // This is needed so the video_quality value does not get
3118 // truncated when set. The range will be readjusted below
3119 GtkWidget *qp = GHB_WIDGET(ud->builder, "VideoQualitySlider");
3120 gtk_range_set_range (GTK_RANGE(qp), 0, 100);
3121 gtk_scale_set_digits(GTK_SCALE(qp), 3);
3122 // Clear the audio list prior to changing the preset. Existing
3123 // audio can cause the container extension to be automatically
3124 // changed when it shouldn't be
3125 ghb_clear_audio_list(ud);
3126 ghb_set_preset_from_indices(ud, indices, len);
3127 gtk_tree_path_free(treepath);
3129 titleindex = ghb_settings_combo_int(ud->settings, "title");
3130 ghb_set_pref_audio(titleindex, ud);
3131 ghb_settings_set_boolean(ud->settings, "preset_modified", FALSE);
3132 ud->dont_clear_presets = FALSE;
3133 if (ghb_get_title_info (&tinfo, titleindex))
3135 preset_update_title_deps(ud, &tinfo);
3137 ghb_set_scale (ud, GHB_SCALE_KEEP_NONE);
3139 gdouble vqmin, vqmax, step, page;
3141 ghb_vquality_range(ud, &vqmin, &vqmax, &step, &page, &digits);
3142 gtk_range_set_range (GTK_RANGE(qp), vqmin, vqmax);
3143 gtk_range_set_increments (GTK_RANGE(qp), step, page);
3144 gtk_scale_set_digits(GTK_SCALE(qp), digits);
3148 GtkWidget *crop_widget;
3149 crop[0] = ghb_settings_get_int(ud->settings, "PictureTopCrop");
3150 crop[1] = ghb_settings_get_int(ud->settings, "PictureBottomCrop");
3151 crop[2] = ghb_settings_get_int(ud->settings, "PictureLeftCrop");
3152 crop[3] = ghb_settings_get_int(ud->settings, "PictureRightCrop");
3153 crop_widget = GHB_WIDGET (ud->builder, "crop_values");
3154 text = g_strdup_printf("%d:%d:%d:%d",
3155 crop[0], crop[1], crop[2], crop[3]);
3156 gtk_label_set_text (GTK_LABEL(crop_widget), text);
3159 gtk_widget_set_sensitive(widget, TRUE);
3163 g_debug("No selection??? Perhaps unselected.");
3164 gtk_widget_set_sensitive(widget, FALSE);
3169 ghb_clear_presets_selection(signal_user_data_t *ud)
3171 GtkTreeView *treeview;
3172 GtkTreeSelection *selection;
3174 if (ud->dont_clear_presets) return;
3175 g_debug("ghb_clear_presets_selection()");
3176 treeview = GTK_TREE_VIEW(GHB_WIDGET(ud->builder, "presets_list"));
3177 selection = gtk_tree_view_get_selection (treeview);
3178 gtk_tree_selection_unselect_all (selection);
3179 ghb_settings_set_boolean(ud->settings, "preset_modified", TRUE);
3183 presets_frame_size_allocate_cb(GtkWidget *widget, GtkAllocation *allocation, signal_user_data_t *ud)
3185 GtkTreeView *treeview;
3186 GtkTreeSelection *selection;
3187 GtkTreeModel *store;
3190 treeview = GTK_TREE_VIEW(GHB_WIDGET(ud->builder, "presets_list"));
3191 selection = gtk_tree_view_get_selection(treeview);
3192 if (gtk_tree_selection_get_selected(selection, &store, &iter))
3195 path = gtk_tree_model_get_path (store, &iter);
3196 // Make the parent visible in scroll window if it is not.
3197 gtk_tree_view_scroll_to_cell (treeview, path, NULL, FALSE, 0, 0);
3198 gtk_tree_path_free(path);
3203 presets_default_clicked_cb(GtkWidget *xwidget, signal_user_data_t *ud)
3208 g_debug("presets_default_clicked_cb ()");
3209 preset = ghb_settings_get_value(ud->settings, "preset_selection");
3210 indices = ghb_preset_indices_from_path(presetsPlist, preset, &len);
3213 if (!ghb_presets_get_folder(presetsPlist, indices, len))
3215 ghb_presets_list_clear_default(ud);
3216 presets_set_default(indices, len);
3217 ghb_presets_list_default(ud);