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>
21 #include "callbacks.h"
22 #include "audiohandler.h"
23 #include "hb-backend.h"
25 #include "resources.h"
30 #define MAX_NESTED_PRESET 3
38 static GValue *presetsPlist = NULL;
39 static GValue *internalPlist = NULL;
40 static GValue *prefsPlist = NULL;
42 static const GValue* preset_dict_get_value(GValue *dict, const gchar *key);
43 static void store_plist(GValue *plist, const gchar *name);
44 static void store_presets(void);
46 // This only handle limited depth
48 ghb_tree_path_new_from_indices(gint *indices, gint len)
53 return gtk_tree_path_new_from_indices(
56 return gtk_tree_path_new_from_indices(
57 indices[0], indices[1], -1);
59 return gtk_tree_path_new_from_indices(
60 indices[0], indices[1], indices[2], -1);
62 return gtk_tree_path_new_from_indices(
63 indices[0], indices[1], indices[2], indices[3], -1);
65 return gtk_tree_path_new_from_indices(
66 indices[0], indices[1], indices[2], indices[3], indices[4], -1);
73 ghb_parse_preset_path(const gchar *path)
79 preset = ghb_array_value_new(MAX_NESTED_PRESET);
80 split = g_strsplit(path, "#", MAX_NESTED_PRESET);
81 for (ii = 0; split[ii] != NULL; ii++)
83 ghb_array_append(preset, ghb_string_value_new(split[ii]));
90 preset_path_from_indices(GValue *presets, gint *indices, gint len)
95 g_debug("preset_path_from_indices");
96 path = ghb_array_value_new(MAX_NESTED_PRESET);
97 for (ii = 0; ii < len; ii++)
103 count = ghb_array_len(presets);
104 if (indices[ii] >= count) break;
105 dict = ghb_array_get_nth(presets, indices[ii]);
106 name = ghb_dict_lookup(dict, "PresetName");
108 ghb_array_append(path, ghb_value_dup(name));
109 folder = ghb_value_boolean(preset_dict_get_value(dict, "Folder"));
112 presets = ghb_dict_lookup(dict, "ChildrenArray");
118 ghb_preset_path_string(const GValue *path)
125 gstr = g_string_new("");
128 count = ghb_array_len(path);
129 for (ii = 0; ii < count; ii++)
131 val = ghb_array_get_nth(path, ii);
132 str = ghb_value_string(val);
133 g_string_append(gstr, str);
135 g_string_append(gstr, "->");
139 str = g_string_free(gstr, FALSE);
144 dump_preset_path(const gchar *msg, const GValue *path)
149 debug_show_type (G_VALUE_TYPE(path));
150 str = ghb_preset_path_string(path);
151 g_message("%s path: (%s)", msg, str);
156 dump_preset_indices(const gchar *msg, gint *indices, gint len)
160 g_message("%s indices: len %d", msg, len);
161 for (ii = 0; ii < len; ii++)
163 printf("%d ", indices[ii]);
170 preset_path_cmp(const GValue *path1, const GValue *path2)
177 count = ghb_array_len(path1);
178 ii = ghb_array_len(path2);
181 for (ii = 0; ii < count; ii++)
183 val = ghb_array_get_nth(path1, ii);
184 str1 = ghb_value_string(val);
185 val = ghb_array_get_nth(path2, ii);
186 str2 = ghb_value_string(val);
187 result = strcmp(str1, str2);
198 presets_get_dict(GValue *presets, gint *indices, gint len)
200 gint ii, count, folder;
203 g_debug("presets_get_dict ()");
204 for (ii = 0; ii < len; ii++)
206 count = ghb_array_len(presets);
207 if (indices[ii] >= count) return NULL;
208 dict = ghb_array_get_nth(presets, indices[ii]);
211 folder = ghb_value_boolean(preset_dict_get_value(dict, "Folder"));
214 presets = ghb_dict_lookup(dict, "ChildrenArray");
223 presets_get_folder(GValue *presets, gint *indices, gint len)
225 gint ii, count, folder;
228 g_debug("presets_get_folder ()");
229 for (ii = 0; ii < len; ii++)
231 count = ghb_array_len(presets);
232 if (indices[ii] >= count) return NULL;
233 dict = ghb_array_get_nth(presets, indices[ii]);
234 folder = ghb_value_boolean(preset_dict_get_value(dict, "Folder"));
237 presets = ghb_dict_lookup(dict, "ChildrenArray");
245 plist_get_dict(GValue *presets, const gchar *name)
247 if (presets == NULL || name == NULL) return NULL;
248 return ghb_dict_lookup(presets, name);
252 preset_get_name(GValue *dict)
254 return g_value_get_string(preset_dict_get_value(dict, "PresetName"));
258 ghb_preset_folder(GValue *dict)
260 return ghb_value_int(preset_dict_get_value(dict, "Folder"));
264 ghb_preset_type(GValue *dict)
266 return ghb_value_int(preset_dict_get_value(dict, "Type"));
270 presets_remove_nth(GValue *presets, gint pos)
275 if (presets == NULL || pos < 0) return;
276 count = ghb_array_len(presets);
277 if (pos >= count) return;
278 dict = ghb_array_get_nth(presets, pos);
279 ghb_array_remove(presets, pos);
280 ghb_value_free(dict);
289 GValue *folder = NULL;
291 folder = presets_get_folder(presets, indices, len-1);
293 presets_remove_nth(folder, indices[len-1]);
296 g_warning("ghb_presets_remove (): internal preset lookup error");
309 GValue *folder = NULL;
311 folder = presets_get_folder(presets, indices, len-1);
313 ghb_array_replace(folder, indices[len-1], dict);
316 g_warning("ghb_presets_replace (): internal preset lookup error");
327 GValue *folder = NULL;
329 folder = presets_get_folder(presets, indices, len-1);
331 ghb_array_insert(folder, indices[len-1], dict);
334 g_warning("ghb_presets_insert (): internal preset lookup error");
339 presets_find_element(GValue *presets, const gchar *name)
344 g_debug("presets_find_element () (%s)", name);
345 if (presets == NULL || name == NULL) return -1;
346 count = ghb_array_len(presets);
347 for (ii = 0; ii < count; ii++)
350 dict = ghb_array_get_nth(presets, ii);
351 str = preset_get_name(dict);
352 if (strcmp(name, str) == 0)
361 single_find_pos(GValue *presets, const gchar *name, gint type)
364 gint count, ii, ptype, last;
366 if (presets == NULL || name == NULL) return -1;
367 last = count = ghb_array_len(presets);
368 for (ii = 0; ii < count; ii++)
371 dict = ghb_array_get_nth(presets, ii);
372 str = preset_get_name(dict);
373 ptype = ghb_value_int(preset_dict_get_value(dict, "Type"));
374 if (strcasecmp(name, str) <= 0 && ptype == type)
385 presets_find_pos(const GValue *path, gint type, gint *len)
391 gint *indices = NULL;
395 g_debug("presets_find_pos () ");
396 nested = presetsPlist;
397 count = ghb_array_len(path);
398 indices = g_malloc(MAX_NESTED_PRESET * sizeof(gint));
399 for (ii = 0; ii < count-1; ii++)
401 val = ghb_array_get_nth(path, ii);
402 name = g_value_get_string(val);
403 indices[ii] = presets_find_element(nested, name);
404 if (indices[ii] == -1) return NULL;
405 dict = ghb_array_get_nth(nested, indices[ii]);
406 folder = ghb_value_boolean(preset_dict_get_value(dict, "Folder"));
410 nested = ghb_dict_lookup(dict, "ChildrenArray");
416 name = g_value_get_string(ghb_array_get_nth(path, count-1));
417 indices[ii] = single_find_pos(nested, name, type);
425 preset_tree_depth(GValue *dict)
429 folder = ghb_value_boolean(preset_dict_get_value(dict, "Folder"));
436 presets = ghb_dict_lookup(dict, "ChildrenArray");
437 count = ghb_array_len(presets);
438 for (ii = 0; ii < count; ii++)
442 dict = ghb_array_get_nth(presets, ii);
443 tmp = preset_tree_depth(dict);
444 depth = MAX(depth, tmp);
455 preset_is_default(GValue *dict)
459 val = preset_dict_get_value(dict, "Default");
460 return ghb_value_boolean(val);
464 presets_clear_default(GValue *presets)
468 count = ghb_array_len(presets);
469 for (ii = 0; ii < count; ii++)
474 dict = ghb_array_get_nth(presets, ii);
475 folder = ghb_value_boolean(preset_dict_get_value(dict, "Folder"));
480 nested = ghb_dict_lookup(dict, "ChildrenArray");
481 presets_clear_default(nested);
485 if (preset_is_default(dict))
487 ghb_dict_insert(dict, g_strdup("Default"),
488 ghb_boolean_value_new(FALSE));
495 presets_find_default2(GValue *presets, gint *len)
500 count = ghb_array_len(presets);
501 for (ii = 0; ii < count; ii++)
506 dict = ghb_array_get_nth(presets, ii);
507 folder = ghb_value_boolean(preset_dict_get_value(dict, "Folder"));
513 nested = ghb_dict_lookup(dict, "ChildrenArray");
515 indices = presets_find_default2(nested, len);
526 if (preset_is_default(dict))
528 indices = g_malloc(MAX_NESTED_PRESET * sizeof(gint));
539 presets_find_default(GValue *presets, gint *len)
542 return presets_find_default2(presets, len);
546 ghb_preset_indices_from_path(
554 gint *indices = NULL;
559 g_debug("ghb_preset_indices_from_path () ");
561 count = ghb_array_len(path);
563 indices = g_malloc(MAX_NESTED_PRESET * sizeof(gint));
565 for (ii = 0; ii < count; ii++)
567 val = ghb_array_get_nth(path, ii);
568 name = g_value_get_string(val);
569 indices[ii] = presets_find_element(nested, name);
570 if (indices[ii] == -1)
577 dict = ghb_array_get_nth(nested, indices[ii]);
578 folder = ghb_value_boolean(preset_dict_get_value(dict, "Folder"));
584 nested = ghb_dict_lookup(dict, "ChildrenArray");
592 ghb_presets_get_type(
600 dict = presets_get_dict(presets, indices, len);
603 type = ghb_preset_type(dict);
607 g_warning("ghb_presets_get_type (): internal preset lookup error");
613 ghb_presets_get_folder(
619 gboolean folder = FALSE;
621 dict = presets_get_dict(presets, indices, len);
624 folder = ghb_preset_folder(dict);
628 g_warning("ghb_presets_get_folder (): internal preset lookup error");
634 presets_set_default(gint *indices, gint len)
638 g_debug("presets_set_default ()");
639 presets_clear_default(presetsPlist);
640 dict = presets_get_dict(presetsPlist, indices, len);
643 ghb_dict_insert(dict, g_strdup("Default"), ghb_boolean_value_new(TRUE));
648 // Used for sorting dictionaries.
650 key_cmp(gconstpointer a, gconstpointer b)
652 gchar *stra = (gchar*)a;
653 gchar *strb = (gchar*)b;
655 return strcmp(stra, strb);
659 preset_dict_get_value(GValue *dict, const gchar *key)
661 const GValue *gval = NULL;
665 gval = ghb_dict_lookup(dict, key);
667 if (internalPlist == NULL) return NULL;
670 dict = plist_get_dict(internalPlist, "Presets");
671 if (dict == NULL) return NULL;
672 gval = ghb_dict_lookup(dict, key);
678 ghb_presets_get_description(GValue *pdict)
682 if (pdict == NULL) return NULL;
683 desc = g_value_get_string(
684 preset_dict_get_value(pdict, "PresetDescription"));
685 if (desc[0] == 0) return NULL;
690 static void init_settings_from_dict(
691 GValue *dest, GValue *internal, GValue *dict);
694 init_settings_from_array(
702 count = ghb_array_len(array);
703 // The first element of the internal version is always the
704 // template for the allowed values
705 gval = ghb_array_get_nth(internal, 0);
706 for (ii = 0; ii < count; ii++)
709 val = ghb_array_get_nth(array, ii);
712 if (G_VALUE_TYPE(gval) == ghb_dict_get_type())
715 new_dict = ghb_dict_value_new();
716 ghb_array_append(dest, new_dict);
717 if (G_VALUE_TYPE(val) == ghb_dict_get_type())
718 init_settings_from_dict(new_dict, gval, val);
720 init_settings_from_dict(new_dict, gval, gval);
722 else if (G_VALUE_TYPE(gval) == ghb_array_get_type())
725 new_array = ghb_array_value_new(8);
726 ghb_array_append(dest, new_array);
727 if (G_VALUE_TYPE(val) == ghb_array_get_type())
728 init_settings_from_array(new_array, gval, val);
730 init_settings_from_array(new_array, gval, gval);
734 ghb_array_append(dest, val);
740 init_settings_from_dict(
749 ghb_dict_iter_init(&iter, internal);
750 // middle (void*) cast prevents gcc warning "defreferencing type-punned
751 // pointer will break strict-aliasing rules"
752 while (g_hash_table_iter_next(
753 &iter, (gpointer*)(void*)&key, (gpointer*)(void*)&gval))
757 val = ghb_dict_lookup(dict, key);
760 if (G_VALUE_TYPE(gval) == ghb_dict_get_type())
763 new_dict = ghb_dict_value_new();
764 ghb_settings_take_value(dest, key, new_dict);
765 if (G_VALUE_TYPE(val) == ghb_dict_get_type())
766 init_settings_from_dict(new_dict, gval, val);
768 init_settings_from_dict(new_dict, gval, gval);
770 else if (G_VALUE_TYPE(gval) == ghb_array_get_type())
773 new_array = ghb_array_value_new(8);
774 ghb_settings_take_value(dest, key, new_array);
775 if (G_VALUE_TYPE(val) == ghb_array_get_type())
776 init_settings_from_array(new_array, gval, val);
778 init_settings_from_array(new_array, gval, gval);
783 ghb_settings_set_value(dest, key, val);
790 signal_user_data_t *ud,
798 ghb_dict_iter_init(&iter, internal);
799 // middle (void*) cast prevents gcc warning "defreferencing type-punned
800 // pointer will break strict-aliasing rules"
801 while (g_hash_table_iter_next(
802 &iter, (gpointer*)(void*)&key, (gpointer*)(void*)&gval))
806 val = ghb_dict_lookup(dict, key);
809 ghb_ui_update(ud, key, val);
814 preset_to_ui(signal_user_data_t *ud, GValue *dict)
816 g_debug("preset_to_ui()\n");
817 // Initialize the ui from presets file.
818 GValue *internal, *hidden;
820 // Get key list from internal default presets. This way we do not
821 // load any unknown keys.
822 if (internalPlist == NULL) return;
823 internal = plist_get_dict(internalPlist, "Presets");
824 hidden = plist_get_dict(internalPlist, "XlatPresets");
825 // Setting a ui widget will cause the corresponding setting
826 // to be set, but it also triggers a callback that can
827 // have the side effect of using other settings values
828 // that have not yet been set. So set *all* settings first
829 // then update the ui.
830 init_settings_from_dict(ud->settings, internal, dict);
831 init_settings_from_dict(ud->settings, hidden, dict);
832 init_ui_from_dict(ud, internal, dict);
833 init_ui_from_dict(ud, hidden, dict);
837 ghb_settings_to_ui(signal_user_data_t *ud, GValue *dict)
839 init_ui_from_dict(ud, dict, dict);
842 static GValue *current_preset = NULL;
845 ghb_preset_is_custom()
849 if (current_preset == NULL) return FALSE;
850 val = preset_dict_get_value(current_preset, "Type");
851 return (ghb_value_int(val) == 1);
855 ghb_set_preset_from_indices(signal_user_data_t *ud, gint *indices, gint len)
858 gint fallback[2] = {0, -1};
861 dict = presets_get_dict(presetsPlist, indices, len);
866 dict = presets_get_dict(presetsPlist, indices, len);
870 preset_to_ui(ud, NULL);
871 current_preset = NULL;
878 current_preset = dict;
879 folder = ghb_value_boolean(preset_dict_get_value(dict, "Folder"));
881 preset_to_ui(ud, NULL);
883 preset_to_ui(ud, dict);
884 path = preset_path_from_indices(presetsPlist, indices, len);
885 ghb_settings_set_value(ud->settings, "preset", path);
886 ghb_value_free(path);
891 curr_preset_get_value(const gchar *key)
893 if (current_preset == NULL) return NULL;
894 return preset_dict_get_value(current_preset, key);
898 ghb_update_from_preset(
899 signal_user_data_t *ud,
904 g_debug("ghb_update_from_preset() %s", key);
905 gval = curr_preset_get_value(key);
908 ghb_ui_update(ud, key, gval);
918 GtkTreeView *treeview;
919 GtkTreeSelection *selection;
924 g_debug("ghb_select_preset2()");
925 treeview = GTK_TREE_VIEW(GHB_WIDGET(builder, "presets_list"));
926 selection = gtk_tree_view_get_selection (treeview);
927 store = gtk_tree_view_get_model (treeview);
928 path = ghb_tree_path_new_from_indices(indices, len);
931 if (gtk_tree_model_get_iter(store, &iter, path))
933 gtk_tree_selection_select_iter (selection, &iter);
937 if (gtk_tree_model_get_iter_first(store, &iter))
938 gtk_tree_selection_select_iter (selection, &iter);
940 gtk_tree_path_free(path);
945 ghb_select_preset(GtkBuilder *builder, const GValue *path)
949 g_debug("ghb_select_preset()");
950 indices = ghb_preset_indices_from_path(presetsPlist, path, &len);
953 ghb_select_preset2(builder, indices, len);
959 ghb_select_default_preset(GtkBuilder *builder)
963 g_debug("ghb_select_default_preset()");
964 indices = presets_find_default(presetsPlist, &len);
967 ghb_select_preset2(builder, indices, len);
973 ghb_get_user_config_dir(gchar *subdir)
978 dir = g_get_user_config_dir();
979 if (!g_file_test(dir, G_FILE_TEST_IS_DIR))
981 dir = g_get_home_dir();
982 config = g_strdup_printf ("%s/.ghb", dir);
983 if (!g_file_test(config, G_FILE_TEST_IS_DIR))
984 g_mkdir (config, 0755);
988 config = g_strdup_printf ("%s/ghb", dir);
989 if (!g_file_test(config, G_FILE_TEST_IS_DIR))
990 g_mkdir (config, 0755);
997 split = g_strsplit(subdir, "/", -1);
998 for (ii = 0; split[ii] != NULL; ii++)
1002 tmp = g_strdup_printf ("%s/%s", config, split[ii]);
1005 if (!g_file_test(config, G_FILE_TEST_IS_DIR))
1006 g_mkdir (config, 0755);
1013 store_plist(GValue *plist, const gchar *name)
1015 gchar *config, *path;
1018 config = ghb_get_user_config_dir(NULL);
1019 path = g_strdup_printf ("%s/%s", config, name);
1020 file = g_fopen(path, "w");
1023 ghb_plist_write(file, plist);
1028 load_plist(const gchar *name)
1030 gchar *config, *path;
1031 GValue *plist = NULL;
1033 config = ghb_get_user_config_dir(NULL);
1034 path = g_strdup_printf ("%s/%s", config, name);
1035 if (g_file_test(path, G_FILE_TEST_IS_REGULAR))
1037 plist = ghb_plist_parse_file(path);
1045 remove_plist(const gchar *name)
1047 gchar *config, *path;
1049 config = ghb_get_user_config_dir(NULL);
1050 path = g_strdup_printf ("%s/%s", config, name);
1051 if (g_file_test(path, G_FILE_TEST_IS_REGULAR))
1059 static gboolean prefs_initializing = FALSE;
1062 ghb_prefs_to_ui(signal_user_data_t *ud)
1067 GValue *internal, *dict;
1068 GHashTableIter iter;
1071 g_debug("ghb_prefs_to_ui");
1072 prefs_initializing = TRUE;
1074 // Setting a ui widget will cause the corresponding setting
1075 // to be set, but it also triggers a callback that can
1076 // have the side effect of using other settings values
1077 // that have not yet been set. So set *all* settings first
1078 // then update the ui.
1079 internal = plist_get_dict(internalPlist, "Initialization");
1080 ghb_dict_iter_init(&iter, internal);
1081 // middle (void*) cast prevents gcc warning "defreferencing type-punned
1082 // pointer will break strict-aliasing rules"
1083 while (g_hash_table_iter_next(
1084 &iter, (gpointer*)(void*)&key, (gpointer*)(void*)&gval))
1086 ghb_ui_update(ud, key, gval);
1089 dict = plist_get_dict(prefsPlist, "Preferences");
1090 internal = plist_get_dict(internalPlist, "Preferences");
1091 ghb_dict_iter_init(&iter, internal);
1092 // middle (void*) cast prevents gcc warning "defreferencing type-punned
1093 // pointer will break strict-aliasing rules"
1094 while (g_hash_table_iter_next(
1095 &iter, (gpointer*)(void*)&key, (gpointer*)(void*)&gval))
1097 const GValue *value = NULL;
1099 value = ghb_dict_lookup(dict, key);
1102 ghb_settings_set_value(ud->settings, key, value);
1104 internal = plist_get_dict(internalPlist, "Preferences");
1105 ghb_dict_iter_init(&iter, internal);
1106 // middle (void*) cast prevents gcc warning "defreferencing type-punned
1107 // pointer will break strict-aliasing rules"
1108 while (g_hash_table_iter_next(
1109 &iter, (gpointer*)(void*)&key, (gpointer*)(void*)&gval))
1111 const GValue *value = NULL;
1113 value = ghb_dict_lookup(dict, key);
1116 ghb_ui_update(ud, key, value);
1119 val = ghb_settings_get_value(ud->settings, "show_presets");
1120 ghb_ui_update(ud, "show_presets", val);
1121 if (ghb_settings_get_boolean(ud->settings, "hbfd_feature"))
1124 val = ghb_settings_get_value(ud->settings, "hbfd");
1125 ghb_ui_update(ud, "hbfd", val);
1126 action = GHB_ACTION (ud->builder, "hbfd");
1127 gtk_action_set_visible(action, TRUE);
1131 ghb_ui_update(ud, "hbfd", ghb_int64_value(0));
1133 gval = ghb_settings_get_value(ud->settings, "default_source");
1134 ghb_settings_set_value (ud->settings, "source", gval);
1136 str = ghb_settings_get_string(ud->settings, "destination_dir");
1137 ghb_ui_update(ud, "dest_dir", ghb_string_value(str));
1139 gchar *file = g_strdup_printf ("new_video.mp4");
1140 ghb_ui_update(ud, "dest_file", ghb_string_value(file));
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[] =
1686 value_map_t denoise_xlat[] =
1696 value_map_t detel_xlat[] =
1704 value_map_t decomb_xlat[] =
1712 extern iso639_lang_t ghb_language_table[];
1715 export_lang_xlat2(GValue *lin_val)
1719 if (lin_val == NULL) return NULL;
1723 str = ghb_value_string(lin_val);
1724 for (ii = 0; ghb_language_table[ii].eng_name; ii++)
1726 if (strcmp(str, ghb_language_table[ii].iso639_2) == 0)
1728 gval = ghb_string_value_new(ghb_language_table[ii].eng_name);
1733 g_debug("Can't map language value: (%s)", str);
1739 export_subtitle_xlat2(GValue *lin_val)
1744 if (lin_val == NULL) return NULL;
1745 str = ghb_value_string(lin_val);
1746 if (strcmp(str, "none") == 0)
1748 gval = ghb_string_value_new("None");
1750 else if (strcmp(str, "auto") == 0)
1752 gval = ghb_string_value_new("Autoselect");
1756 gval = export_lang_xlat2(lin_val);
1763 import_lang_xlat2(GValue *mac_val)
1767 if (mac_val == NULL) return NULL;
1771 str = ghb_value_string(mac_val);
1772 for (ii = 0; ghb_language_table[ii].eng_name; ii++)
1774 if (strcmp(str, ghb_language_table[ii].eng_name) == 0)
1776 gval = ghb_string_value_new(ghb_language_table[ii].iso639_2);
1781 g_debug("Can't map language value: (%s)", str);
1787 import_subtitle_xlat2(GValue *mac_val)
1792 if (mac_val == NULL) return NULL;
1793 str = ghb_value_string(mac_val);
1794 if (strcmp(str, "None") == 0)
1796 gval = ghb_string_value_new("none");
1798 else if (strcmp(str, "Autoselect") == 0)
1800 gval = ghb_string_value_new("auto");
1804 gval = import_lang_xlat2(mac_val);
1811 export_audio_track_xlat2(GValue *lin_val)
1814 GValue *gval = NULL;
1816 if (lin_val == NULL) return NULL;
1817 str = ghb_value_string(lin_val);
1818 if (strcmp(str, "none") == 0)
1820 gval = ghb_int_value_new(1);
1824 gint val = ghb_value_int(lin_val) + 1;
1825 gval = ghb_int_value_new(val);
1832 import_audio_track_xlat2(GValue *mac_val)
1838 if (mac_val == NULL) return NULL;
1839 val = ghb_value_int(mac_val);
1848 str = g_strdup_printf("%d", val);
1849 gval = ghb_string_value_new(str);
1855 export_value_xlat2(value_map_t *value_map, GValue *lin_val, GType mac_type)
1859 if (lin_val == NULL) return NULL;
1864 str = ghb_value_string(lin_val);
1865 for (ii = 0; value_map[ii].mac_val; ii++)
1867 if (strcmp(str, value_map[ii].lin_val) == 0)
1869 sval = ghb_string_value_new(value_map[ii].mac_val);
1871 gval = ghb_value_new(mac_type);
1872 if (!g_value_transform(sval, gval))
1874 g_warning("can't transform");
1875 ghb_value_free(gval);
1876 ghb_value_free(sval);
1879 ghb_value_free(sval);
1883 g_debug("Can't map value: (%s)", str);
1889 export_value_xlat(GValue *dict)
1891 GValue *lin_val, *gval;
1894 key = "VideoEncoder";
1895 lin_val = ghb_dict_lookup(dict, key);
1896 gval = export_value_xlat2(vcodec_xlat, lin_val, G_TYPE_STRING);
1898 ghb_dict_insert(dict, g_strdup(key), gval);
1900 lin_val = ghb_dict_lookup(dict, key);
1901 gval = export_value_xlat2(container_xlat, lin_val, G_TYPE_STRING);
1903 ghb_dict_insert(dict, g_strdup(key), gval);
1904 key = "VideoFramerate";
1905 lin_val = ghb_dict_lookup(dict, key);
1906 gval = export_value_xlat2(framerate_xlat, lin_val, G_TYPE_STRING);
1908 ghb_dict_insert(dict, g_strdup(key), gval);
1909 key = "PictureDetelecine";
1910 lin_val = ghb_dict_lookup(dict, key);
1911 gval = export_value_xlat2(detel_xlat, lin_val, G_TYPE_INT);
1913 ghb_dict_insert(dict, g_strdup(key), gval);
1914 key = "PictureDecomb";
1915 lin_val = ghb_dict_lookup(dict, key);
1916 gval = export_value_xlat2(decomb_xlat, lin_val, G_TYPE_INT);
1918 ghb_dict_insert(dict, g_strdup(key), gval);
1919 key = "PictureDeinterlace";
1920 lin_val = ghb_dict_lookup(dict, key);
1921 gval = export_value_xlat2(deint_xlat, lin_val, G_TYPE_INT);
1923 ghb_dict_insert(dict, g_strdup(key), gval);
1924 key = "PictureDenoise";
1925 lin_val = ghb_dict_lookup(dict, key);
1926 gval = export_value_xlat2(denoise_xlat, lin_val, G_TYPE_INT);
1928 ghb_dict_insert(dict, g_strdup(key), gval);
1930 lin_val = ghb_dict_lookup(dict, key);
1931 gval = export_subtitle_xlat2(lin_val);
1933 ghb_dict_insert(dict, g_strdup(key), gval);
1939 alist = ghb_dict_lookup(dict, "AudioList");
1940 count = ghb_array_len(alist);
1941 for (ii = 0; ii < count; ii++)
1943 adict = ghb_array_get_nth(alist, ii);
1945 lin_val = ghb_dict_lookup(adict, key);
1946 gval = export_audio_track_xlat2(lin_val);
1948 ghb_dict_insert(adict, g_strdup(key), gval);
1949 key = "AudioEncoder";
1950 lin_val = ghb_dict_lookup(adict, key);
1951 gval = export_value_xlat2(acodec_xlat, lin_val, G_TYPE_STRING);
1953 ghb_dict_insert(adict, g_strdup(key), gval);
1954 key = "AudioSamplerate";
1955 lin_val = ghb_dict_lookup(adict, key);
1956 gval = export_value_xlat2(samplerate_xlat, lin_val, G_TYPE_STRING);
1958 ghb_dict_insert(adict, g_strdup(key), gval);
1959 key = "AudioMixdown";
1960 lin_val = ghb_dict_lookup(adict, key);
1961 gval = export_value_xlat2(mix_xlat, lin_val, G_TYPE_STRING);
1963 ghb_dict_insert(adict, g_strdup(key), gval);
1971 value_map_t *value_map,
1975 GValue *gval, *def_val;
1977 if (mac_val == NULL) return NULL;
1978 def_val = ghb_dict_lookup(defaults, key);
1985 str = ghb_value_string(mac_val);
1986 for (ii = 0; value_map[ii].mac_val; ii++)
1988 if (strcmp(str, value_map[ii].mac_val) == 0)
1990 sval = ghb_string_value_new(value_map[ii].lin_val);
1992 gval = ghb_value_new(G_VALUE_TYPE(def_val));
1993 if (!g_value_transform(sval, gval))
1995 g_warning("can't transform");
1996 ghb_value_free(gval);
1997 ghb_value_free(sval);
2000 ghb_value_free(sval);
2004 //g_warning("Can't map value: (%s)", str);
2009 g_warning("Bad key: (%s)", key);
2016 import_value_xlat(GValue *dict)
2018 GValue *defaults, *mac_val, *gval;
2021 defaults = plist_get_dict(internalPlist, "Presets");
2022 key = "VideoEncoder";
2023 mac_val = ghb_dict_lookup(dict, key);
2024 gval = import_value_xlat2(defaults, vcodec_xlat, key, mac_val);
2026 ghb_dict_insert(dict, g_strdup(key), gval);
2028 mac_val = ghb_dict_lookup(dict, key);
2029 gval = import_value_xlat2(defaults, container_xlat, key, mac_val);
2031 ghb_dict_insert(dict, g_strdup(key), gval);
2032 key = "VideoFramerate";
2033 mac_val = ghb_dict_lookup(dict, key);
2034 gval = import_value_xlat2(defaults, framerate_xlat, key, mac_val);
2036 ghb_dict_insert(dict, g_strdup(key), gval);
2037 key = "PictureDetelecine";
2038 mac_val = ghb_dict_lookup(dict, key);
2039 gval = import_value_xlat2(defaults, detel_xlat, key, mac_val);
2041 ghb_dict_insert(dict, g_strdup(key), gval);
2042 key = "PictureDecomb";
2043 mac_val = ghb_dict_lookup(dict, key);
2044 gval = import_value_xlat2(defaults, decomb_xlat, key, mac_val);
2046 ghb_dict_insert(dict, g_strdup(key), gval);
2047 key = "PictureDeinterlace";
2048 mac_val = ghb_dict_lookup(dict, key);
2049 gval = import_value_xlat2(defaults, deint_xlat, key, mac_val);
2051 ghb_dict_insert(dict, g_strdup(key), gval);
2052 key = "PictureDenoise";
2053 mac_val = ghb_dict_lookup(dict, key);
2054 gval = import_value_xlat2(defaults, denoise_xlat, key, mac_val);
2056 ghb_dict_insert(dict, g_strdup(key), gval);
2058 mac_val = ghb_dict_lookup(dict, key);
2059 gval = import_subtitle_xlat2(mac_val);
2061 ghb_dict_insert(dict, g_strdup(key), gval);
2069 adeflist = ghb_dict_lookup(dict, "AudioList");
2072 adefaults = ghb_array_get_nth(adeflist, 0);
2073 alist = ghb_dict_lookup(dict, "AudioList");
2074 count = ghb_array_len(alist);
2075 for (ii = 0; ii < count; ii++)
2077 adict = ghb_array_get_nth(alist, ii);
2079 mac_val = ghb_dict_lookup(adict, key);
2080 gval = import_audio_track_xlat2(mac_val);
2082 ghb_dict_insert(adict, g_strdup(key), gval);
2083 key = "AudioEncoder";
2084 mac_val = ghb_dict_lookup(adict, key);
2085 gval = import_value_xlat2(adefaults, acodec_xlat, key, mac_val);
2087 ghb_dict_insert(adict, g_strdup(key), gval);
2088 key = "AudioSamplerate";
2089 mac_val = ghb_dict_lookup(adict, key);
2090 gval = import_value_xlat2(adefaults, samplerate_xlat, key, mac_val);
2092 ghb_dict_insert(adict, g_strdup(key), gval);
2093 key = "AudioMixdown";
2094 mac_val = ghb_dict_lookup(adict, key);
2095 gval = import_value_xlat2(adefaults, mix_xlat, key, mac_val);
2097 ghb_dict_insert(adict, g_strdup(key), gval);
2103 import_xlat_preset(GValue *dict)
2110 g_debug("import_xlat_preset ()");
2111 uses_max = ghb_value_boolean(
2112 preset_dict_get_value(dict, "UsesMaxPictureSettings"));
2113 uses_pic = ghb_value_int(
2114 preset_dict_get_value(dict, "UsesPictureSettings"));
2115 par = ghb_value_int(preset_dict_get_value(dict, "PicturePAR"));
2116 vqtype = ghb_value_int(preset_dict_get_value(dict, "VideoQualityType"));
2118 if (uses_max || uses_pic == 2)
2120 ghb_dict_insert(dict, g_strdup("autoscale"),
2121 ghb_boolean_value_new(TRUE));
2127 ghb_dict_insert(dict, g_strdup("anamorphic"),
2128 ghb_boolean_value_new(FALSE));
2129 if (ghb_dict_lookup(dict, "ModDimensions") == NULL)
2130 ghb_dict_insert(dict, g_strdup("ModDimensions"),
2131 ghb_boolean_value_new(TRUE));
2135 ghb_dict_insert(dict, g_strdup("anamorphic"),
2136 ghb_boolean_value_new(TRUE));
2137 ghb_dict_insert(dict, g_strdup("ModDimensions"),
2138 ghb_boolean_value_new(FALSE));
2142 ghb_dict_insert(dict, g_strdup("anamorphic"),
2143 ghb_boolean_value_new(TRUE));
2144 ghb_dict_insert(dict, g_strdup("ModDimensions"),
2145 ghb_boolean_value_new(TRUE));
2149 ghb_dict_insert(dict, g_strdup("anamorphic"),
2150 ghb_boolean_value_new(TRUE));
2151 ghb_dict_insert(dict, g_strdup("ModDimensions"),
2152 ghb_boolean_value_new(TRUE));
2155 // VideoQualityType/0/1/2 - vquality_type_/target/bitrate/constant
2160 ghb_dict_insert(dict, g_strdup("vquality_type_target"),
2161 ghb_boolean_value_new(TRUE));
2162 ghb_dict_insert(dict, g_strdup("vquality_type_bitrate"),
2163 ghb_boolean_value_new(FALSE));
2164 ghb_dict_insert(dict, g_strdup("vquality_type_constant"),
2165 ghb_boolean_value_new(FALSE));
2169 ghb_dict_insert(dict, g_strdup("vquality_type_target"),
2170 ghb_boolean_value_new(FALSE));
2171 ghb_dict_insert(dict, g_strdup("vquality_type_bitrate"),
2172 ghb_boolean_value_new(TRUE));
2173 ghb_dict_insert(dict, g_strdup("vquality_type_constant"),
2174 ghb_boolean_value_new(FALSE));
2178 ghb_dict_insert(dict, g_strdup("vquality_type_target"),
2179 ghb_boolean_value_new(FALSE));
2180 ghb_dict_insert(dict, g_strdup("vquality_type_bitrate"),
2181 ghb_boolean_value_new(FALSE));
2182 ghb_dict_insert(dict, g_strdup("vquality_type_constant"),
2183 ghb_boolean_value_new(TRUE));
2187 ghb_dict_insert(dict, g_strdup("vquality_type_target"),
2188 ghb_boolean_value_new(FALSE));
2189 ghb_dict_insert(dict, g_strdup("vquality_type_bitrate"),
2190 ghb_boolean_value_new(FALSE));
2191 ghb_dict_insert(dict, g_strdup("vquality_type_constant"),
2192 ghb_boolean_value_new(TRUE));
2195 import_value_xlat(dict);
2200 vquality = ghb_value_double(preset_dict_get_value(dict, "VideoQualitySlider"));
2205 gval = preset_dict_get_value(dict, "VideoEncoder");
2206 vcodec = ghb_lookup_combo_int("VideoEncoder", gval);
2209 case HB_VCODEC_X264:
2211 vquality = 51. - vquality * 51.;
2214 case HB_VCODEC_XVID:
2215 case HB_VCODEC_FFMPEG:
2217 vquality = 31. - vquality * 30.;
2220 case HB_VCODEC_THEORA:
2222 vquality = vquality * 63.;
2230 ghb_dict_insert(dict, g_strdup("VideoQualitySlider"),
2231 ghb_double_value_new(vquality));
2236 import_xlat_presets(GValue *presets)
2242 g_debug("import_xlat_presets ()");
2243 if (presets == NULL) return;
2244 count = ghb_array_len(presets);
2245 for (ii = 0; ii < count; ii++)
2247 dict = ghb_array_get_nth(presets, ii);
2248 folder = ghb_value_boolean(preset_dict_get_value(dict, "Folder"));
2253 nested = ghb_dict_lookup(dict, "ChildrenArray");
2254 import_xlat_presets(nested);
2258 import_xlat_preset(dict);
2264 export_xlat_preset(GValue *dict)
2266 gboolean ana, round, autoscale, target, br, constant;
2268 g_debug("export_xlat_prest ()");
2269 autoscale = ghb_value_boolean(preset_dict_get_value(dict, "autoscale"));
2270 ana = ghb_value_boolean(preset_dict_get_value(dict, "anamorphic"));
2271 round = ghb_value_boolean(preset_dict_get_value(dict, "ModDimensions"));
2272 target = ghb_value_boolean(
2273 preset_dict_get_value(dict, "vquality_type_target"));
2274 br = ghb_value_boolean(
2275 preset_dict_get_value(dict, "vquality_type_bitrate"));
2276 constant = ghb_value_boolean(
2277 preset_dict_get_value(dict, "vquality_type_constant"));
2280 ghb_dict_insert(dict, g_strdup("UsesPictureSettings"),
2281 ghb_int_value_new(2));
2283 ghb_dict_insert(dict, g_strdup("UsesPictureSettings"),
2284 ghb_int_value_new(1));
2289 ghb_dict_insert(dict, g_strdup("PicturePAR"),
2290 ghb_int_value_new(2));
2292 ghb_dict_insert(dict, g_strdup("PicturePAR"),
2293 ghb_int_value_new(1));
2297 ghb_dict_insert(dict, g_strdup("PicturePAR"),
2298 ghb_int_value_new(0));
2300 // VideoQualityType/0/1/2 - vquality_type_/target/bitrate/constant
2303 ghb_dict_insert(dict, g_strdup("VideoQualityType"),
2304 ghb_int_value_new(0));
2308 ghb_dict_insert(dict, g_strdup("VideoQualityType"),
2309 ghb_int_value_new(1));
2313 ghb_dict_insert(dict, g_strdup("VideoQualityType"),
2314 ghb_int_value_new(2));
2316 ghb_dict_remove(dict, "UsesMaxPictureSettings");
2317 ghb_dict_remove(dict, "autoscale");
2318 ghb_dict_remove(dict, "anamorphic");
2319 ghb_dict_remove(dict, "vquality_type_target");
2320 ghb_dict_remove(dict, "vquality_type_bitrate");
2321 ghb_dict_remove(dict, "vquality_type_constant");
2322 export_value_xlat(dict);
2326 export_xlat_presets(GValue *presets)
2332 if (presets == NULL) return;
2333 count = ghb_array_len(presets);
2334 for (ii = 0; ii < count; ii++)
2336 dict = ghb_array_get_nth(presets, ii);
2337 folder = ghb_value_boolean(preset_dict_get_value(dict, "Folder"));
2342 nested = ghb_dict_lookup(dict, "ChildrenArray");
2343 export_xlat_presets(nested);
2347 export_xlat_preset(dict);
2357 export = ghb_value_dup(presetsPlist);
2358 export_xlat_presets(export);
2359 store_plist(export, "presets");
2360 ghb_value_free(export);
2364 ghb_presets_reload(signal_user_data_t *ud)
2366 GValue *std_presets;
2370 g_debug("ghb_presets_reload()\n");
2371 std_presets = ghb_resource_get("standard-presets");
2372 if (std_presets == NULL) return;
2374 remove_std_presets(ud);
2375 indices = presets_find_default(presetsPlist, &len);
2378 presets_clear_default(std_presets);
2381 // Merge the keyfile contents into our presets
2382 count = ghb_array_len(std_presets);
2383 for (ii = count-1; ii >= 0; ii--)
2389 std_dict = ghb_array_get_nth(std_presets, ii);
2390 copy_dict = ghb_value_dup(std_dict);
2391 ghb_presets_insert(presetsPlist, copy_dict, &indices, 1);
2392 presets_list_insert(ud, &indices, 1);
2394 import_xlat_presets(presetsPlist);
2403 count = ghb_array_len(presetsPlist);
2404 for (ii = count-1; ii >= 0; ii--)
2409 dict = ghb_array_get_nth(presetsPlist, ii);
2410 type = ghb_dict_lookup(dict, "Type");
2420 presetsPlist = load_plist("presets");
2421 if (presetsPlist == NULL)
2423 presetsPlist = ghb_value_dup(ghb_resource_get("standard-presets"));
2424 import_xlat_presets(presetsPlist);
2427 else if (G_VALUE_TYPE(presetsPlist) == ghb_dict_get_type())
2428 { // Presets is older dictionary format. Convert to array
2429 ghb_value_free(presetsPlist);
2430 presetsPlist = ghb_value_dup(ghb_resource_get("standard-presets"));
2431 import_xlat_presets(presetsPlist);
2434 else if (check_old_presets())
2436 ghb_value_free(presetsPlist);
2437 presetsPlist = ghb_value_dup(ghb_resource_get("standard-presets"));
2438 import_xlat_presets(presetsPlist);
2441 import_xlat_presets(presetsPlist);
2445 settings_save(signal_user_data_t *ud, const GValue *path)
2447 GValue *dict, *internal;
2448 GHashTableIter iter;
2452 gint *indices, len, count;
2454 gboolean replace = FALSE;
2456 g_debug("settings_save");
2457 if (internalPlist == NULL) return;
2458 count = ghb_array_len(path);
2459 name = g_value_get_string(ghb_array_get_nth(path, count-1));
2460 indices = ghb_preset_indices_from_path(presetsPlist, path, &len);
2463 if (ghb_presets_get_folder(presetsPlist, indices, len))
2466 message = g_strdup_printf(
2467 "%s: Folder already exists.\n"
2468 "You can not replace it with a preset.",
2470 ghb_message_dialog(GTK_MESSAGE_ERROR, message, "Cancel", NULL);
2474 dict = ghb_dict_value_new();
2475 ghb_presets_replace(presetsPlist, dict, indices, len);
2480 indices = presets_find_pos(path, PRESETS_CUSTOM, &len);
2483 dict = ghb_dict_value_new();
2484 ghb_presets_insert(presetsPlist, dict, indices, len);
2488 g_warning("failed to find insert path");
2492 current_preset = dict;
2493 autoscale = ghb_settings_get_boolean(ud->settings, "autoscale");
2494 ghb_settings_set_int64(ud->settings, "Type", PRESETS_CUSTOM);
2496 internal = plist_get_dict(internalPlist, "Presets");
2497 ghb_dict_iter_init(&iter, internal);
2498 // middle (void*) cast prevents gcc warning "defreferencing type-punned
2499 // pointer will break strict-aliasing rules"
2500 while (g_hash_table_iter_next(
2501 &iter, (gpointer*)(void*)&key, (gpointer*)(void*)&value))
2509 if (strcmp(key, "PictureWidth") == 0)
2511 key2 = "scale_width";
2513 else if (strcmp(key, "PictureHeight") == 0)
2515 key2 = "scale_height";
2518 gval = ghb_settings_get_value(ud->settings, key2);
2523 ghb_dict_insert(dict, g_strdup(key), ghb_value_dup(gval));
2525 internal = plist_get_dict(internalPlist, "XlatPresets");
2526 ghb_dict_iter_init(&iter, internal);
2527 // middle (void*) cast prevents gcc warning "defreferencing type-punned
2528 // pointer will break strict-aliasing rules"
2529 while (g_hash_table_iter_next(
2530 &iter, (gpointer*)(void*)&key, (gpointer*)(void*)&value))
2534 gval = ghb_settings_get_value(ud->settings, key);
2539 ghb_dict_insert(dict, g_strdup(key), ghb_value_dup(gval));
2541 ghb_dict_insert(dict, g_strdup("PresetName"), ghb_string_value_new(name));
2543 presets_list_update_item(ud, indices, len);
2546 ghb_dict_insert(dict, g_strdup("Default"),
2547 ghb_boolean_value_new(FALSE));
2548 presets_list_insert(ud, indices, len);
2551 ud->dont_clear_presets = TRUE;
2552 // Make the new preset the selected item
2553 ghb_select_preset2(ud->builder, indices, len);
2555 ud->dont_clear_presets = FALSE;
2560 folder_save(signal_user_data_t *ud, const GValue *path)
2562 GValue *dict, *folder;
2563 gint *indices, len, count;
2566 count = ghb_array_len(path);
2567 name = g_value_get_string(ghb_array_get_nth(path, count-1));
2568 indices = ghb_preset_indices_from_path(presetsPlist, path, &len);
2571 if (!ghb_presets_get_folder(presetsPlist, indices, len))
2574 message = g_strdup_printf(
2575 "%s: Preset already exists.\n"
2576 "You can not replace it with a folder.",
2578 ghb_message_dialog(GTK_MESSAGE_ERROR, message, "Cancel", NULL);
2583 // Already exists, update its description
2584 dict = presets_get_dict(presetsPlist, indices, len);
2585 ghb_dict_insert(dict, g_strdup("PresetDescription"),
2586 ghb_value_dup(preset_dict_get_value(
2587 ud->settings, "PresetDescription")));
2593 indices = presets_find_pos(path, PRESETS_CUSTOM, &len);
2596 dict = ghb_dict_value_new();
2597 ghb_presets_insert(presetsPlist, dict, indices, len);
2601 g_warning("failed to find insert path");
2605 ghb_dict_insert(dict, g_strdup("PresetDescription"),
2606 ghb_value_dup(preset_dict_get_value(
2607 ud->settings, "PresetDescription")));
2608 ghb_dict_insert(dict, g_strdup("PresetName"), ghb_string_value_new(name));
2609 folder = ghb_array_value_new(8);
2610 ghb_dict_insert(dict, g_strdup("ChildrenArray"), folder);
2611 ghb_dict_insert(dict, g_strdup("Type"),
2612 ghb_int64_value_new(PRESETS_CUSTOM));
2613 ghb_dict_insert(dict, g_strdup("Folder"), ghb_boolean_value_new(TRUE));
2615 presets_list_insert(ud, indices, len);
2622 ghb_presets_list_default(signal_user_data_t *ud)
2624 GtkTreeView *treeview;
2625 GtkTreePath *treepath;
2627 GtkTreeStore *store;
2630 g_debug("ghb_presets_list_default ()");
2631 treeview = GTK_TREE_VIEW(GHB_WIDGET(ud->builder, "presets_list"));
2632 store = GTK_TREE_STORE(gtk_tree_view_get_model(treeview));
2633 indices = presets_find_default(presetsPlist, &len);
2634 if (indices == NULL) return;
2635 treepath = ghb_tree_path_new_from_indices(indices, len);
2638 if (gtk_tree_model_get_iter(GTK_TREE_MODEL(store), &iter, treepath))
2640 gtk_tree_store_set(store, &iter,
2645 gtk_tree_path_free(treepath);
2651 ghb_presets_list_clear_default(signal_user_data_t *ud)
2653 GtkTreeView *treeview;
2654 GtkTreePath *treepath;
2656 GtkTreeStore *store;
2659 g_debug("ghb_presets_list_clear_default ()");
2660 treeview = GTK_TREE_VIEW(GHB_WIDGET(ud->builder, "presets_list"));
2661 store = GTK_TREE_STORE(gtk_tree_view_get_model(treeview));
2662 indices = presets_find_default(presetsPlist, &len);
2663 if (indices == NULL) return;
2664 treepath = ghb_tree_path_new_from_indices(indices, len);
2667 if (gtk_tree_model_get_iter(GTK_TREE_MODEL(store), &iter, treepath))
2669 gtk_tree_store_set(store, &iter,
2674 gtk_tree_path_free(treepath);
2680 update_audio_presets(signal_user_data_t *ud)
2682 g_debug("update_audio_presets");
2683 const GValue *audio_list;
2685 audio_list = ghb_settings_get_value(ud->settings, "audio_list");
2686 ghb_settings_set_value(ud->settings, "AudioList", audio_list);
2690 enforce_preset_type(signal_user_data_t *ud, const GValue *path)
2693 GtkWidget *normal, *folder;
2696 normal = GHB_WIDGET(ud->builder, "preset_type_normal");
2697 folder = GHB_WIDGET(ud->builder, "preset_type_folder");
2698 indices = ghb_preset_indices_from_path(presetsPlist, path, &len);
2701 fold = ghb_presets_get_folder(presetsPlist, indices, len);
2703 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(folder),
2706 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(normal),
2708 gtk_widget_set_sensitive(folder, fold);
2709 gtk_widget_set_sensitive(normal, !fold);
2714 gtk_widget_set_sensitive(folder, TRUE);
2715 gtk_widget_set_sensitive(normal, TRUE);
2720 presets_save_clicked_cb(GtkWidget *xwidget, signal_user_data_t *ud)
2725 GtkResponseType response;
2727 const gchar *name = "";
2728 gint count, *indices, len;
2730 g_debug("presets_save_clicked_cb ()");
2731 preset = ghb_settings_get_value (ud->settings, "preset_selection");
2733 count = ghb_array_len(preset);
2735 name = g_value_get_string(ghb_array_get_nth(preset, count-1));
2738 // Clear the description
2739 desc = GTK_TEXT_VIEW(GHB_WIDGET(ud->builder, "PresetDescription"));
2740 dialog = GHB_WIDGET(ud->builder, "preset_save_dialog");
2741 entry = GTK_ENTRY(GHB_WIDGET(ud->builder, "PresetName"));
2742 gtk_entry_set_text(entry, name);
2743 enforce_preset_type(ud, preset);
2744 response = gtk_dialog_run(GTK_DIALOG(dialog));
2745 gtk_widget_hide(dialog);
2746 if (response == GTK_RESPONSE_OK)
2749 const gchar *name = gtk_entry_get_text(entry);
2752 if (ghb_settings_get_boolean(ud->settings, "preset_type_folder"))
2754 if (count > MAX_NESTED_PRESET-1)
2756 count = MAX_NESTED_PRESET-1;
2759 dest = ghb_array_value_new(MAX_NESTED_PRESET);
2760 indices = ghb_preset_indices_from_path(presetsPlist, preset, &len);
2765 ptype = ghb_presets_get_type(presetsPlist, indices, len);
2766 if (ptype == PRESETS_CUSTOM)
2768 ghb_array_copy(dest, preset, count-1);
2771 ghb_array_append(dest, ghb_string_value_new(name));
2773 ghb_widget_to_setting(ud->settings, GTK_WIDGET(desc));
2774 if (ghb_settings_get_boolean(ud->settings, "preset_type_folder"))
2776 folder_save(ud, dest);
2780 // Construct the audio settings presets from the current audio list
2781 update_audio_presets(ud);
2782 settings_save(ud, dest);
2784 ghb_value_free(dest);
2789 preset_type_changed_cb(GtkWidget *widget, signal_user_data_t *ud)
2791 ghb_widget_to_setting(ud->settings, widget);
2795 preset_name_changed_cb(GtkWidget *entry, signal_user_data_t *ud)
2798 GValue *preset, *dest;
2801 preset = ghb_settings_get_value (ud->settings, "preset_selection");
2802 name = ghb_widget_string(entry);
2803 dest = ghb_value_dup(preset);
2804 count = ghb_array_len(dest);
2805 ghb_array_replace(dest, count-1, ghb_string_value_new(name));
2806 enforce_preset_type(ud, dest);
2807 ghb_value_free(dest);
2811 presets_restore_clicked_cb(GtkWidget *xwidget, signal_user_data_t *ud)
2815 g_debug("presets_restore_clicked_cb ()");
2816 // Reload only the standard presets
2817 ghb_presets_reload(ud);
2818 // Updating the presets list shuffles things around
2819 // need to make sure the proper preset is selected
2820 preset = ghb_settings_get_value (ud->settings, "preset");
2821 ghb_select_preset(ud->builder, preset);
2825 presets_remove_clicked_cb(GtkWidget *xwidget, signal_user_data_t *ud)
2827 GtkTreeView *treeview;
2828 GtkTreeSelection *selection;
2829 GtkTreeModel *store;
2832 GtkResponseType response;
2834 g_debug("presets_remove_clicked_cb ()");
2835 treeview = GTK_TREE_VIEW(GHB_WIDGET(ud->builder, "presets_list"));
2836 selection = gtk_tree_view_get_selection (treeview);
2837 if (gtk_tree_selection_get_selected(selection, &store, &iter))
2844 gtk_tree_model_get(store, &iter, 0, &preset, -1);
2845 path = gtk_tree_model_get_path(store, &iter);
2846 indices = gtk_tree_path_get_indices(path);
2847 len = gtk_tree_path_get_depth(path);
2849 folder = ghb_presets_get_folder(presetsPlist, indices, len);
2850 dialog = gtk_message_dialog_new(NULL, GTK_DIALOG_MODAL,
2851 GTK_MESSAGE_QUESTION, GTK_BUTTONS_YES_NO,
2852 "Confirm deletion of %s:\n\n%s",
2853 folder ? "folder" : "preset",
2855 response = gtk_dialog_run(GTK_DIALOG(dialog));
2856 gtk_widget_destroy (dialog);
2857 if (response == GTK_RESPONSE_YES)
2859 GtkTreeIter nextIter = iter;
2860 gboolean valid = TRUE;
2861 if (!gtk_tree_model_iter_next(store, &nextIter))
2863 if (!gtk_tree_model_iter_parent(store, &nextIter, &iter))
2868 // Remove the selected item
2869 // First unselect it so that selecting the new item works properly
2870 gtk_tree_selection_unselect_iter (selection, &iter);
2871 if (ghb_presets_remove(presetsPlist, indices, len))
2874 presets_list_remove(ud, indices, len);
2877 valid = gtk_tree_model_get_iter_first(store, &nextIter);
2880 gtk_tree_path_free(path);
2881 path = gtk_tree_model_get_path(store, &nextIter);
2882 indices = gtk_tree_path_get_indices(path);
2883 len = gtk_tree_path_get_depth(path);
2884 ghb_select_preset2(ud->builder, indices, len);
2888 gtk_tree_path_free(path);
2892 // controls where valid drop locations are
2894 presets_drag_motion_cb(
2896 GdkDragContext *ctx,
2900 signal_user_data_t *ud)
2902 GtkTreePath *path = NULL;
2903 GtkTreeViewDropPosition drop_pos;
2907 GtkTreeModel *model;
2908 GtkTreeSelection *select;
2909 gint src_ptype, dst_ptype;
2910 gboolean src_folder, dst_folder;
2912 gint tree_depth, ii;
2914 // Get the type of the object being dragged
2915 srctv = GTK_TREE_VIEW(gtk_drag_get_source_widget(ctx));
2916 select = gtk_tree_view_get_selection (srctv);
2917 gtk_tree_selection_get_selected (select, &model, &iter);
2918 path = gtk_tree_model_get_path (model, &iter);
2919 indices = gtk_tree_path_get_indices(path);
2920 len = gtk_tree_path_get_depth(path);
2922 preset = presets_get_dict(presetsPlist, indices, len);
2923 tree_depth = preset_tree_depth(preset);
2925 src_ptype = ghb_presets_get_type(presetsPlist, indices, len);
2926 src_folder = ghb_presets_get_folder(presetsPlist, indices, len);
2927 gtk_tree_path_free(path);
2929 if (src_folder && tree_depth == 1)
2932 // The rest checks that the destination is a valid position
2934 gtk_tree_view_get_dest_row_at_pos (tv, x, y, &path, &drop_pos);
2937 gdk_drag_status(ctx, 0, time);
2940 // Don't allow repositioning of builtin presets
2941 if (src_ptype != PRESETS_CUSTOM)
2943 gdk_drag_status(ctx, 0, time);
2947 len = gtk_tree_path_get_depth(path);
2948 if (len+tree_depth-1 >= MAX_NESTED_PRESET)
2950 if (drop_pos == GTK_TREE_VIEW_DROP_INTO_OR_BEFORE)
2951 drop_pos = GTK_TREE_VIEW_DROP_BEFORE;
2952 if (drop_pos == GTK_TREE_VIEW_DROP_INTO_OR_AFTER)
2953 drop_pos = GTK_TREE_VIEW_DROP_AFTER;
2955 for (ii = len+tree_depth-1; ii > MAX_NESTED_PRESET; ii--)
2956 gtk_tree_path_up(path);
2957 indices = gtk_tree_path_get_indices(path);
2958 len = gtk_tree_path_get_depth(path);
2959 dst_ptype = ghb_presets_get_type(presetsPlist, indices, len);
2960 dst_folder = ghb_presets_get_folder(presetsPlist, indices, len);
2961 // Don't allow mixing custom presets in the builtins
2962 if (dst_ptype != PRESETS_CUSTOM)
2964 gdk_drag_status(ctx, 0, time);
2968 // Only allow *drop into* for folders
2971 if (drop_pos == GTK_TREE_VIEW_DROP_INTO_OR_BEFORE)
2972 drop_pos = GTK_TREE_VIEW_DROP_BEFORE;
2973 if (drop_pos == GTK_TREE_VIEW_DROP_INTO_OR_AFTER)
2974 drop_pos = GTK_TREE_VIEW_DROP_AFTER;
2977 len = gtk_tree_path_get_depth(path);
2978 gtk_tree_view_set_drag_dest_row(tv, path, drop_pos);
2979 gtk_tree_path_free(path);
2980 gdk_drag_status(ctx, GDK_ACTION_MOVE, time);
2986 GtkTreeView *dstwidget,
2989 GtkSelectionData *selection_data,
2990 guint info, guint t,
2991 signal_user_data_t *ud)
2993 GtkTreePath *path = NULL;
2994 GtkTreeViewDropPosition drop_pos;
2995 GtkTreeIter dstiter, srciter;
2996 gint *dst_indices, dst_len, *src_indices, src_len;
2998 gboolean src_folder, dst_folder;
3000 GtkTreeModel *dstmodel = gtk_tree_view_get_model(dstwidget);
3002 g_debug("preset_drag_cb ()");
3003 // This doesn't work here for some reason...
3004 // gtk_tree_view_get_drag_dest_row(dstwidget, &path, &drop_pos);
3005 gtk_tree_view_get_dest_row_at_pos (dstwidget, x, y, &path, &drop_pos);
3006 // This little hack is needed because attempting to drop after
3007 // the last item gives us no path or drop_pos.
3012 n_children = gtk_tree_model_iter_n_children(dstmodel, NULL);
3015 drop_pos = GTK_TREE_VIEW_DROP_AFTER;
3016 path = gtk_tree_path_new_from_indices(n_children-1, -1);
3020 drop_pos = GTK_TREE_VIEW_DROP_BEFORE;
3021 path = gtk_tree_path_new_from_indices(0, -1);
3026 GtkTreeView *srcwidget;
3027 GtkTreeModel *srcmodel;
3028 GtkTreeSelection *select;
3029 GtkTreePath *srcpath = NULL;
3031 gint tree_depth, ii;
3033 srcwidget = GTK_TREE_VIEW(gtk_drag_get_source_widget(dc));
3034 select = gtk_tree_view_get_selection (srcwidget);
3035 gtk_tree_selection_get_selected (select, &srcmodel, &srciter);
3037 srcpath = gtk_tree_model_get_path (srcmodel, &srciter);
3038 src_indices = gtk_tree_path_get_indices(srcpath);
3039 src_len = gtk_tree_path_get_depth(srcpath);
3040 src_ptype = ghb_presets_get_type(presetsPlist, src_indices, src_len);
3041 src_folder = ghb_presets_get_folder(presetsPlist, src_indices, src_len);
3042 preset = ghb_value_dup(
3043 presets_get_dict(presetsPlist, src_indices, src_len));
3044 gtk_tree_path_free(srcpath);
3046 // Don't allow repositioning of builtin presets
3047 if (src_ptype != PRESETS_CUSTOM)
3050 tree_depth = preset_tree_depth(preset);
3051 if (src_folder && tree_depth == 1)
3054 dst_len = gtk_tree_path_get_depth(path);
3055 if (dst_len+tree_depth-1 >= MAX_NESTED_PRESET)
3057 if (drop_pos == GTK_TREE_VIEW_DROP_INTO_OR_BEFORE)
3058 drop_pos = GTK_TREE_VIEW_DROP_BEFORE;
3059 if (drop_pos == GTK_TREE_VIEW_DROP_INTO_OR_AFTER)
3060 drop_pos = GTK_TREE_VIEW_DROP_AFTER;
3063 for (ii = dst_len+tree_depth-1; ii > MAX_NESTED_PRESET; ii--)
3064 gtk_tree_path_up(path);
3065 dst_indices = gtk_tree_path_get_indices(path);
3066 dst_len = gtk_tree_path_get_depth(path);
3067 dst_folder = ghb_presets_get_folder(presetsPlist, dst_indices, dst_len);
3068 // Only allow *drop into* for folders
3071 if (drop_pos == GTK_TREE_VIEW_DROP_INTO_OR_BEFORE)
3072 drop_pos = GTK_TREE_VIEW_DROP_BEFORE;
3073 if (drop_pos == GTK_TREE_VIEW_DROP_INTO_OR_AFTER)
3074 drop_pos = GTK_TREE_VIEW_DROP_AFTER;
3076 if (gtk_tree_model_get_iter (dstmodel, &dstiter, path))
3079 GtkTreePath *dstpath = NULL;
3083 case GTK_TREE_VIEW_DROP_BEFORE:
3084 gtk_tree_store_insert_before(GTK_TREE_STORE (dstmodel),
3085 &iter, NULL, &dstiter);
3088 case GTK_TREE_VIEW_DROP_INTO_OR_BEFORE:
3089 gtk_tree_store_insert(GTK_TREE_STORE (dstmodel),
3090 &iter, &dstiter, 0);
3093 case GTK_TREE_VIEW_DROP_AFTER:
3094 gtk_tree_store_insert_after(GTK_TREE_STORE (dstmodel),
3095 &iter, NULL, &dstiter);
3098 case GTK_TREE_VIEW_DROP_INTO_OR_AFTER:
3099 gtk_tree_store_insert_after(GTK_TREE_STORE (dstmodel),
3100 &iter, &dstiter, 0);
3107 dstpath = gtk_tree_model_get_path (dstmodel, &iter);
3108 dst_indices = gtk_tree_path_get_indices(dstpath);
3109 dst_len = gtk_tree_path_get_depth(dstpath);
3110 ghb_presets_insert(presetsPlist, preset, dst_indices, dst_len);
3111 gtk_tree_path_free(dstpath);
3113 srcpath = gtk_tree_model_get_path (srcmodel, &srciter);
3114 src_indices = gtk_tree_path_get_indices(srcpath);
3115 src_len = gtk_tree_path_get_depth(srcpath);
3116 ghb_presets_remove(presetsPlist, src_indices, src_len);
3117 gtk_tree_path_free(srcpath);
3119 gtk_tree_store_remove (GTK_TREE_STORE (srcmodel), &srciter);
3121 dstpath = gtk_tree_model_get_path (dstmodel, &iter);
3122 dst_indices = gtk_tree_path_get_indices(dstpath);
3123 dst_len = gtk_tree_path_get_depth(dstpath);
3124 presets_list_update_item(ud, dst_indices, dst_len);
3125 gtk_tree_path_free(dstpath);
3129 gtk_tree_path_free(path);
3134 preset_update_title_deps(signal_user_data_t *ud, ghb_title_info_t *tinfo)
3138 ghb_ui_update(ud, "scale_width",
3139 ghb_int64_value(tinfo->width - tinfo->crop[2] - tinfo->crop[3]));
3140 // If anamorphic or keep_aspect, the hight will be automatically calculated
3141 gboolean keep_aspect, anamorphic;
3142 keep_aspect = ghb_settings_get_boolean(ud->settings, "PictureKeepRatio");
3143 anamorphic = ghb_settings_get_boolean(ud->settings, "anamorphic");
3144 if (!(keep_aspect || anamorphic))
3146 ghb_ui_update(ud, "scale_height",
3147 ghb_int64_value(tinfo->height - tinfo->crop[0] - tinfo->crop[1]));
3150 // Set the limits of cropping. hb_set_anamorphic_size crashes if
3151 // you pass it a cropped width or height == 0.
3153 bound = tinfo->height / 2 - 2;
3154 widget = GHB_WIDGET (ud->builder, "PictureTopCrop");
3155 gtk_spin_button_set_range (GTK_SPIN_BUTTON(widget), 0, bound);
3156 widget = GHB_WIDGET (ud->builder, "PictureBottomCrop");
3157 gtk_spin_button_set_range (GTK_SPIN_BUTTON(widget), 0, bound);
3158 bound = tinfo->width / 2 - 2;
3159 widget = GHB_WIDGET (ud->builder, "PictureLeftCrop");
3160 gtk_spin_button_set_range (GTK_SPIN_BUTTON(widget), 0, bound);
3161 widget = GHB_WIDGET (ud->builder, "PictureRightCrop");
3162 gtk_spin_button_set_range (GTK_SPIN_BUTTON(widget), 0, bound);
3163 if (ghb_settings_get_boolean(ud->settings, "PictureAutoCrop"))
3165 ghb_ui_update(ud, "PictureTopCrop", ghb_int64_value(tinfo->crop[0]));
3166 ghb_ui_update(ud, "PictureBottomCrop", ghb_int64_value(tinfo->crop[1]));
3167 ghb_ui_update(ud, "PictureLeftCrop", ghb_int64_value(tinfo->crop[2]));
3168 ghb_ui_update(ud, "PictureRightCrop", ghb_int64_value(tinfo->crop[3]));
3173 presets_list_selection_changed_cb(GtkTreeSelection *selection, signal_user_data_t *ud)
3175 GtkTreeModel *store;
3177 ghb_title_info_t tinfo;
3180 g_debug("presets_list_selection_changed_cb ()");
3181 widget = GHB_WIDGET (ud->builder, "presets_remove");
3182 if (gtk_tree_selection_get_selected(selection, &store, &iter))
3184 GtkTreePath *treepath;
3189 treepath = gtk_tree_model_get_path(store, &iter);
3190 indices = gtk_tree_path_get_indices(treepath);
3191 len = gtk_tree_path_get_depth(treepath);
3193 path = preset_path_from_indices(presetsPlist, indices, len);
3194 ghb_settings_take_value(ud->settings, "preset_selection", path);
3196 folder = ghb_presets_get_folder(presetsPlist, indices, len);
3199 ud->dont_clear_presets = TRUE;
3200 // Temporarily set the video_quality range to (0,100)
3201 // This is needed so the video_quality value does not get
3202 // truncated when set. The range will be readjusted below
3203 GtkWidget *qp = GHB_WIDGET(ud->builder, "VideoQualitySlider");
3204 gtk_range_set_range (GTK_RANGE(qp), 0, 100);
3205 gtk_scale_set_digits(GTK_SCALE(qp), 3);
3206 // Clear the audio list prior to changing the preset. Existing
3207 // audio can cause the container extension to be automatically
3208 // changed when it shouldn't be
3209 ghb_clear_audio_list(ud);
3210 ghb_set_preset_from_indices(ud, indices, len);
3211 gtk_tree_path_free(treepath);
3213 titleindex = ghb_settings_combo_int(ud->settings, "title");
3214 ghb_set_pref_audio(titleindex, ud);
3215 ghb_settings_set_boolean(ud->settings, "preset_modified", FALSE);
3216 ud->dont_clear_presets = FALSE;
3217 if (ghb_get_title_info (&tinfo, titleindex))
3219 preset_update_title_deps(ud, &tinfo);
3221 ghb_set_scale (ud, GHB_SCALE_KEEP_NONE);
3223 gdouble vqmin, vqmax, step, page;
3227 ghb_vquality_range(ud, &vqmin, &vqmax, &step,
3228 &page, &digits, &inverted);
3229 gtk_range_set_range (GTK_RANGE(qp), vqmin, vqmax);
3230 gtk_range_set_increments (GTK_RANGE(qp), step, page);
3231 gtk_scale_set_digits(GTK_SCALE(qp), digits);
3232 gtk_range_set_inverted (GTK_RANGE(qp), inverted);
3236 GtkWidget *crop_widget;
3237 crop[0] = ghb_settings_get_int(ud->settings, "PictureTopCrop");
3238 crop[1] = ghb_settings_get_int(ud->settings, "PictureBottomCrop");
3239 crop[2] = ghb_settings_get_int(ud->settings, "PictureLeftCrop");
3240 crop[3] = ghb_settings_get_int(ud->settings, "PictureRightCrop");
3241 crop_widget = GHB_WIDGET (ud->builder, "crop_values");
3242 text = g_strdup_printf("%d:%d:%d:%d",
3243 crop[0], crop[1], crop[2], crop[3]);
3244 gtk_label_set_text (GTK_LABEL(crop_widget), text);
3247 gtk_widget_set_sensitive(widget, TRUE);
3251 g_debug("No selection??? Perhaps unselected.");
3252 gtk_widget_set_sensitive(widget, FALSE);
3257 ghb_clear_presets_selection(signal_user_data_t *ud)
3259 GtkTreeView *treeview;
3260 GtkTreeSelection *selection;
3262 if (ud->dont_clear_presets) return;
3263 g_debug("ghb_clear_presets_selection()");
3264 treeview = GTK_TREE_VIEW(GHB_WIDGET(ud->builder, "presets_list"));
3265 selection = gtk_tree_view_get_selection (treeview);
3266 gtk_tree_selection_unselect_all (selection);
3267 ghb_settings_set_boolean(ud->settings, "preset_modified", TRUE);
3271 presets_frame_size_allocate_cb(GtkWidget *widget, GtkAllocation *allocation, signal_user_data_t *ud)
3273 GtkTreeView *treeview;
3274 GtkTreeSelection *selection;
3275 GtkTreeModel *store;
3278 treeview = GTK_TREE_VIEW(GHB_WIDGET(ud->builder, "presets_list"));
3279 selection = gtk_tree_view_get_selection(treeview);
3280 if (gtk_tree_selection_get_selected(selection, &store, &iter))
3283 path = gtk_tree_model_get_path (store, &iter);
3284 // Make the parent visible in scroll window if it is not.
3285 gtk_tree_view_scroll_to_cell (treeview, path, NULL, FALSE, 0, 0);
3286 gtk_tree_path_free(path);
3291 presets_default_clicked_cb(GtkWidget *xwidget, signal_user_data_t *ud)
3296 g_debug("presets_default_clicked_cb ()");
3297 preset = ghb_settings_get_value(ud->settings, "preset_selection");
3298 indices = ghb_preset_indices_from_path(presetsPlist, preset, &len);
3301 if (!ghb_presets_get_folder(presetsPlist, indices, len))
3303 ghb_presets_list_clear_default(ud);
3304 presets_set_default(indices, len);
3305 ghb_presets_list_default(ud);