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 dump_preset_path(const gchar *msg, const GValue *path)
148 debug_show_type (G_VALUE_TYPE(path));
149 str = ghb_preset_path_string(path);
150 g_message("%s path: (%s)", msg, str);
155 dump_preset_indices(const gchar *msg, gint *indices, gint len)
159 g_message("%s indices: len %d", msg, len);
160 for (ii = 0; ii < len; ii++)
162 printf("%d ", indices[ii]);
169 preset_path_cmp(const GValue *path1, const GValue *path2)
176 count = ghb_array_len(path1);
177 ii = ghb_array_len(path2);
180 for (ii = 0; ii < count; ii++)
182 val = ghb_array_get_nth(path1, ii);
183 str1 = ghb_value_string(val);
184 val = ghb_array_get_nth(path2, ii);
185 str2 = ghb_value_string(val);
186 result = strcmp(str1, str2);
197 presets_get_dict(GValue *presets, gint *indices, gint len)
199 gint ii, count, folder;
202 g_debug("presets_get_dict ()");
203 for (ii = 0; ii < len; ii++)
205 count = ghb_array_len(presets);
206 if (indices[ii] >= count) return NULL;
207 dict = ghb_array_get_nth(presets, indices[ii]);
210 folder = ghb_value_boolean(preset_dict_get_value(dict, "Folder"));
213 presets = ghb_dict_lookup(dict, "ChildrenArray");
222 presets_get_folder(GValue *presets, gint *indices, gint len)
224 gint ii, count, folder;
227 g_debug("presets_get_folder ()");
228 for (ii = 0; ii < len; ii++)
230 count = ghb_array_len(presets);
231 if (indices[ii] >= count) return NULL;
232 dict = ghb_array_get_nth(presets, indices[ii]);
233 folder = ghb_value_boolean(preset_dict_get_value(dict, "Folder"));
236 presets = ghb_dict_lookup(dict, "ChildrenArray");
244 plist_get_dict(GValue *presets, const gchar *name)
246 if (presets == NULL || name == NULL) return NULL;
247 return ghb_dict_lookup(presets, name);
251 preset_get_name(GValue *dict)
253 return g_value_get_string(preset_dict_get_value(dict, "PresetName"));
257 ghb_preset_folder(GValue *dict)
259 return ghb_value_int(preset_dict_get_value(dict, "Folder"));
263 ghb_preset_type(GValue *dict)
265 return ghb_value_int(preset_dict_get_value(dict, "Type"));
269 presets_remove_nth(GValue *presets, gint pos)
274 if (presets == NULL || pos < 0) return;
275 count = ghb_array_len(presets);
276 if (pos >= count) return;
277 dict = ghb_array_get_nth(presets, pos);
278 ghb_array_remove(presets, pos);
279 ghb_value_free(dict);
288 GValue *folder = NULL;
290 folder = presets_get_folder(presets, indices, len-1);
292 presets_remove_nth(folder, indices[len-1]);
295 g_warning("ghb_presets_remove (): internal preset lookup error");
308 GValue *folder = NULL;
310 folder = presets_get_folder(presets, indices, len-1);
312 ghb_array_replace(folder, indices[len-1], dict);
315 g_warning("ghb_presets_replace (): internal preset lookup error");
326 GValue *folder = NULL;
328 folder = presets_get_folder(presets, indices, len-1);
330 ghb_array_insert(folder, indices[len-1], dict);
333 g_warning("ghb_presets_insert (): internal preset lookup error");
338 presets_find_element(GValue *presets, const gchar *name)
343 g_debug("presets_find_element () (%s)", name);
344 if (presets == NULL || name == NULL) return -1;
345 count = ghb_array_len(presets);
346 for (ii = 0; ii < count; ii++)
349 dict = ghb_array_get_nth(presets, ii);
350 str = preset_get_name(dict);
351 if (strcmp(name, str) == 0)
360 single_find_pos(GValue *presets, const gchar *name, gint type)
363 gint count, ii, ptype, last;
365 if (presets == NULL || name == NULL) return -1;
366 last = count = ghb_array_len(presets);
367 for (ii = 0; ii < count; ii++)
370 dict = ghb_array_get_nth(presets, ii);
371 str = preset_get_name(dict);
372 ptype = ghb_value_int(preset_dict_get_value(dict, "Type"));
373 if (strcasecmp(name, str) <= 0 && ptype == type)
384 presets_find_pos(const GValue *path, gint type, gint *len)
390 gint *indices = NULL;
394 g_debug("presets_find_pos () ");
395 nested = presetsPlist;
396 count = ghb_array_len(path);
397 indices = g_malloc(MAX_NESTED_PRESET * sizeof(gint));
398 for (ii = 0; ii < count-1; ii++)
400 val = ghb_array_get_nth(path, ii);
401 name = g_value_get_string(val);
402 indices[ii] = presets_find_element(nested, name);
403 if (indices[ii] == -1) return NULL;
404 dict = ghb_array_get_nth(nested, indices[ii]);
405 folder = ghb_value_boolean(preset_dict_get_value(dict, "Folder"));
409 nested = ghb_dict_lookup(dict, "ChildrenArray");
415 name = g_value_get_string(ghb_array_get_nth(path, count-1));
416 indices[ii] = single_find_pos(nested, name, type);
424 preset_tree_depth(GValue *dict)
428 folder = ghb_value_boolean(preset_dict_get_value(dict, "Folder"));
435 presets = ghb_dict_lookup(dict, "ChildrenArray");
436 count = ghb_array_len(presets);
437 for (ii = 0; ii < count; ii++)
441 dict = ghb_array_get_nth(presets, ii);
442 tmp = preset_tree_depth(dict);
443 depth = MAX(depth, tmp);
454 preset_is_default(GValue *dict)
458 val = preset_dict_get_value(dict, "Default");
459 return ghb_value_boolean(val);
463 presets_clear_default(GValue *presets)
467 count = ghb_array_len(presets);
468 for (ii = 0; ii < count; ii++)
473 dict = ghb_array_get_nth(presets, ii);
474 folder = ghb_value_boolean(preset_dict_get_value(dict, "Folder"));
479 nested = ghb_dict_lookup(dict, "ChildrenArray");
480 presets_clear_default(nested);
484 if (preset_is_default(dict))
486 ghb_dict_insert(dict, g_strdup("Default"),
487 ghb_boolean_value_new(FALSE));
494 presets_find_default2(GValue *presets, gint *len)
499 count = ghb_array_len(presets);
500 for (ii = 0; ii < count; ii++)
505 dict = ghb_array_get_nth(presets, ii);
506 folder = ghb_value_boolean(preset_dict_get_value(dict, "Folder"));
512 nested = ghb_dict_lookup(dict, "ChildrenArray");
514 indices = presets_find_default2(nested, len);
525 if (preset_is_default(dict))
527 indices = g_malloc(MAX_NESTED_PRESET * sizeof(gint));
538 presets_find_default(GValue *presets, gint *len)
541 return presets_find_default2(presets, len);
545 ghb_preset_indices_from_path(
553 gint *indices = NULL;
558 g_debug("ghb_preset_indices_from_path () ");
560 count = ghb_array_len(path);
562 indices = g_malloc(MAX_NESTED_PRESET * sizeof(gint));
564 for (ii = 0; ii < count; ii++)
566 val = ghb_array_get_nth(path, ii);
567 name = g_value_get_string(val);
568 indices[ii] = presets_find_element(nested, name);
569 if (indices[ii] == -1)
576 dict = ghb_array_get_nth(nested, indices[ii]);
577 folder = ghb_value_boolean(preset_dict_get_value(dict, "Folder"));
583 nested = ghb_dict_lookup(dict, "ChildrenArray");
591 ghb_presets_get_type(
599 dict = presets_get_dict(presets, indices, len);
602 type = ghb_preset_type(dict);
606 g_warning("ghb_presets_get_type (): internal preset lookup error");
612 ghb_presets_get_folder(
618 gboolean folder = FALSE;
620 dict = presets_get_dict(presets, indices, len);
623 folder = ghb_preset_folder(dict);
627 g_warning("ghb_presets_get_folder (): internal preset lookup error");
633 presets_set_default(gint *indices, gint len)
637 g_debug("presets_set_default ()");
638 presets_clear_default(presetsPlist);
639 dict = presets_get_dict(presetsPlist, indices, len);
642 ghb_dict_insert(dict, g_strdup("Default"), ghb_boolean_value_new(TRUE));
647 // Used for sorting dictionaries.
649 key_cmp(gconstpointer a, gconstpointer b)
651 gchar *stra = (gchar*)a;
652 gchar *strb = (gchar*)b;
654 return strcmp(stra, strb);
658 preset_dict_get_value(GValue *dict, const gchar *key)
660 const GValue *gval = NULL;
664 gval = ghb_dict_lookup(dict, key);
666 if (internalPlist == NULL) return NULL;
669 dict = plist_get_dict(internalPlist, "Presets");
670 if (dict == NULL) return NULL;
671 gval = ghb_dict_lookup(dict, key);
677 ghb_presets_get_description(GValue *pdict)
681 if (pdict == NULL) return NULL;
682 desc = g_value_get_string(
683 preset_dict_get_value(pdict, "PresetDescription"));
684 if (desc[0] == 0) return NULL;
689 static void init_settings_from_dict(
690 GValue *dest, GValue *internal, GValue *dict);
693 init_settings_from_array(
701 count = ghb_array_len(array);
702 // The first element of the internal version is always the
703 // template for the allowed values
704 gval = ghb_array_get_nth(internal, 0);
705 for (ii = 0; ii < count; ii++)
708 val = ghb_array_get_nth(array, ii);
711 if (G_VALUE_TYPE(gval) == ghb_dict_get_type())
714 new_dict = ghb_dict_value_new();
715 ghb_array_append(dest, new_dict);
716 if (G_VALUE_TYPE(val) == ghb_dict_get_type())
717 init_settings_from_dict(new_dict, gval, val);
719 init_settings_from_dict(new_dict, gval, gval);
721 else if (G_VALUE_TYPE(gval) == ghb_array_get_type())
724 new_array = ghb_array_value_new(8);
725 ghb_array_append(dest, new_array);
726 if (G_VALUE_TYPE(val) == ghb_array_get_type())
727 init_settings_from_array(new_array, gval, val);
729 init_settings_from_array(new_array, gval, gval);
733 ghb_array_append(dest, val);
739 init_settings_from_dict(
748 ghb_dict_iter_init(&iter, internal);
749 // middle (void*) cast prevents gcc warning "defreferencing type-punned
750 // pointer will break strict-aliasing rules"
751 while (g_hash_table_iter_next(
752 &iter, (gpointer*)(void*)&key, (gpointer*)(void*)&gval))
756 val = ghb_dict_lookup(dict, key);
759 if (G_VALUE_TYPE(gval) == ghb_dict_get_type())
762 new_dict = ghb_dict_value_new();
763 ghb_settings_take_value(dest, key, new_dict);
764 if (G_VALUE_TYPE(val) == ghb_dict_get_type())
765 init_settings_from_dict(new_dict, gval, val);
767 init_settings_from_dict(new_dict, gval, gval);
769 else if (G_VALUE_TYPE(gval) == ghb_array_get_type())
772 new_array = ghb_array_value_new(8);
773 ghb_settings_take_value(dest, key, new_array);
774 if (G_VALUE_TYPE(val) == ghb_array_get_type())
775 init_settings_from_array(new_array, gval, val);
777 init_settings_from_array(new_array, gval, gval);
782 ghb_settings_set_value(dest, key, val);
789 signal_user_data_t *ud,
797 ghb_dict_iter_init(&iter, internal);
798 // middle (void*) cast prevents gcc warning "defreferencing type-punned
799 // pointer will break strict-aliasing rules"
800 while (g_hash_table_iter_next(
801 &iter, (gpointer*)(void*)&key, (gpointer*)(void*)&gval))
805 val = ghb_dict_lookup(dict, key);
808 ghb_ui_update(ud, key, val);
813 preset_to_ui(signal_user_data_t *ud, GValue *dict)
815 g_debug("preset_to_ui()\n");
816 // Initialize the ui from presets file.
817 GValue *internal, *hidden;
819 // Get key list from internal default presets. This way we do not
820 // load any unknown keys.
821 if (internalPlist == NULL) return;
822 internal = plist_get_dict(internalPlist, "Presets");
823 hidden = plist_get_dict(internalPlist, "XlatPresets");
824 // Setting a ui widget will cause the corresponding setting
825 // to be set, but it also triggers a callback that can
826 // have the side effect of using other settings values
827 // that have not yet been set. So set *all* settings first
828 // then update the ui.
829 init_settings_from_dict(ud->settings, internal, dict);
830 init_settings_from_dict(ud->settings, hidden, dict);
831 init_ui_from_dict(ud, internal, dict);
832 init_ui_from_dict(ud, hidden, dict);
836 ghb_settings_to_ui(signal_user_data_t *ud, GValue *dict)
838 init_ui_from_dict(ud, dict, dict);
841 static GValue *current_preset = NULL;
844 ghb_preset_is_custom()
848 if (current_preset == NULL) return FALSE;
849 val = preset_dict_get_value(current_preset, "Type");
850 return (ghb_value_int(val) == 1);
854 ghb_set_preset_from_indices(signal_user_data_t *ud, gint *indices, gint len)
857 gint fallback[2] = {0, -1};
860 dict = presets_get_dict(presetsPlist, indices, len);
865 dict = presets_get_dict(presetsPlist, indices, len);
869 preset_to_ui(ud, NULL);
870 current_preset = NULL;
877 current_preset = dict;
878 folder = ghb_value_boolean(preset_dict_get_value(dict, "Folder"));
880 preset_to_ui(ud, NULL);
882 preset_to_ui(ud, dict);
883 path = preset_path_from_indices(presetsPlist, indices, len);
884 ghb_settings_set_value(ud->settings, "preset", path);
885 ghb_value_free(path);
890 curr_preset_get_value(const gchar *key)
892 if (current_preset == NULL) return NULL;
893 return preset_dict_get_value(current_preset, key);
897 ghb_update_from_preset(
898 signal_user_data_t *ud,
903 g_debug("ghb_update_from_preset() %s", key);
904 gval = curr_preset_get_value(key);
907 ghb_ui_update(ud, key, gval);
917 GtkTreeView *treeview;
918 GtkTreeSelection *selection;
923 g_debug("ghb_select_preset2()");
924 treeview = GTK_TREE_VIEW(GHB_WIDGET(builder, "presets_list"));
925 selection = gtk_tree_view_get_selection (treeview);
926 store = gtk_tree_view_get_model (treeview);
927 path = ghb_tree_path_new_from_indices(indices, len);
930 if (gtk_tree_model_get_iter(store, &iter, path))
932 gtk_tree_selection_select_iter (selection, &iter);
936 if (gtk_tree_model_get_iter_first(store, &iter))
937 gtk_tree_selection_select_iter (selection, &iter);
939 gtk_tree_path_free(path);
944 ghb_select_preset(GtkBuilder *builder, const GValue *path)
948 g_debug("ghb_select_preset()");
949 indices = ghb_preset_indices_from_path(presetsPlist, path, &len);
952 ghb_select_preset2(builder, indices, len);
958 ghb_select_default_preset(GtkBuilder *builder)
962 g_debug("ghb_select_default_preset()");
963 indices = presets_find_default(presetsPlist, &len);
966 ghb_select_preset2(builder, indices, len);
972 ghb_get_user_config_dir(gchar *subdir)
977 dir = g_get_user_config_dir();
978 if (!g_file_test(dir, G_FILE_TEST_IS_DIR))
980 dir = g_get_home_dir();
981 config = g_strdup_printf ("%s/.ghb", dir);
982 if (!g_file_test(config, G_FILE_TEST_IS_DIR))
983 g_mkdir (config, 0755);
987 config = g_strdup_printf ("%s/ghb", dir);
988 if (!g_file_test(config, G_FILE_TEST_IS_DIR))
989 g_mkdir (config, 0755);
996 split = g_strsplit(subdir, "/", -1);
997 for (ii = 0; split[ii] != NULL; ii++)
1001 tmp = g_strdup_printf ("%s/%s", config, split[ii]);
1004 if (!g_file_test(config, G_FILE_TEST_IS_DIR))
1005 g_mkdir (config, 0755);
1012 store_plist(GValue *plist, const gchar *name)
1014 gchar *config, *path;
1017 config = ghb_get_user_config_dir(NULL);
1018 path = g_strdup_printf ("%s/%s", config, name);
1019 file = g_fopen(path, "w");
1022 ghb_plist_write(file, plist);
1027 load_plist(const gchar *name)
1029 gchar *config, *path;
1030 GValue *plist = NULL;
1032 config = ghb_get_user_config_dir(NULL);
1033 path = g_strdup_printf ("%s/%s", config, name);
1034 if (g_file_test(path, G_FILE_TEST_IS_REGULAR))
1036 plist = ghb_plist_parse_file(path);
1044 remove_plist(const gchar *name)
1046 gchar *config, *path;
1048 config = ghb_get_user_config_dir(NULL);
1049 path = g_strdup_printf ("%s/%s", config, name);
1050 if (g_file_test(path, G_FILE_TEST_IS_REGULAR))
1058 static gboolean prefs_initializing = FALSE;
1061 ghb_prefs_to_ui(signal_user_data_t *ud)
1066 GValue *internal, *dict;
1067 GHashTableIter iter;
1070 g_debug("ghb_prefs_to_ui");
1071 prefs_initializing = TRUE;
1073 // Setting a ui widget will cause the corresponding setting
1074 // to be set, but it also triggers a callback that can
1075 // have the side effect of using other settings values
1076 // that have not yet been set. So set *all* settings first
1077 // then update the ui.
1078 internal = plist_get_dict(internalPlist, "Initialization");
1079 ghb_dict_iter_init(&iter, internal);
1080 // middle (void*) cast prevents gcc warning "defreferencing type-punned
1081 // pointer will break strict-aliasing rules"
1082 while (g_hash_table_iter_next(
1083 &iter, (gpointer*)(void*)&key, (gpointer*)(void*)&gval))
1085 ghb_ui_update(ud, key, gval);
1088 dict = plist_get_dict(prefsPlist, "Preferences");
1089 internal = plist_get_dict(internalPlist, "Preferences");
1090 ghb_dict_iter_init(&iter, internal);
1091 // middle (void*) cast prevents gcc warning "defreferencing type-punned
1092 // pointer will break strict-aliasing rules"
1093 while (g_hash_table_iter_next(
1094 &iter, (gpointer*)(void*)&key, (gpointer*)(void*)&gval))
1096 const GValue *value = NULL;
1098 value = ghb_dict_lookup(dict, key);
1101 ghb_settings_set_value(ud->settings, key, value);
1103 internal = plist_get_dict(internalPlist, "Preferences");
1104 ghb_dict_iter_init(&iter, internal);
1105 // middle (void*) cast prevents gcc warning "defreferencing type-punned
1106 // pointer will break strict-aliasing rules"
1107 while (g_hash_table_iter_next(
1108 &iter, (gpointer*)(void*)&key, (gpointer*)(void*)&gval))
1110 const GValue *value = NULL;
1112 value = ghb_dict_lookup(dict, key);
1115 ghb_ui_update(ud, key, value);
1118 val = ghb_settings_get_value(ud->settings, "show_presets");
1119 ghb_ui_update(ud, "show_presets", val);
1120 if (ghb_settings_get_boolean(ud->settings, "hbfd_feature"))
1123 val = ghb_settings_get_value(ud->settings, "hbfd");
1124 ghb_ui_update(ud, "hbfd", val);
1125 action = GHB_ACTION (ud->builder, "hbfd");
1126 gtk_action_set_visible(action, TRUE);
1130 ghb_ui_update(ud, "hbfd", ghb_int64_value(0));
1132 gval = ghb_settings_get_value(ud->settings, "default_source");
1133 ghb_settings_set_value (ud->settings, "source", gval);
1135 str = ghb_settings_get_string(ud->settings, "destination_dir");
1136 ghb_ui_update(ud, "dest_dir", ghb_string_value(str));
1138 gchar *file = g_strdup_printf ("new_video.mp4");
1139 ghb_ui_update(ud, "dest_file", ghb_string_value(file));
1143 prefs_initializing = FALSE;
1147 ghb_prefs_save(GValue *settings)
1151 GHashTableIter iter;
1153 const GValue *value;
1155 if (prefs_initializing) return;
1156 dict = plist_get_dict(internalPlist, "Preferences");
1157 if (dict == NULL) return;
1158 pref_dict = plist_get_dict(prefsPlist, "Preferences");
1159 if (pref_dict == NULL) return;
1160 ghb_dict_iter_init(&iter, dict);
1161 // middle (void*) cast prevents gcc warning "defreferencing type-punned
1162 // pointer will break strict-aliasing rules"
1163 while (g_hash_table_iter_next(
1164 &iter, (gpointer*)(void*)&key, (gpointer*)(void*)&value))
1166 value = ghb_settings_get_value(settings, key);
1169 ghb_dict_insert(pref_dict, g_strdup(key), ghb_value_dup(value));
1172 store_plist(prefsPlist, "preferences");
1176 ghb_pref_save(GValue *settings, const gchar *key)
1178 const GValue *value;
1180 if (prefs_initializing) return;
1181 value = ghb_settings_get_value(settings, key);
1185 dict = plist_get_dict(prefsPlist, "Preferences");
1186 if (dict == NULL) return;
1187 ghb_dict_insert(dict, g_strdup(key), ghb_value_dup(value));
1188 store_plist(prefsPlist, "preferences");
1193 ghb_settings_init(signal_user_data_t *ud)
1196 GHashTableIter iter;
1201 g_debug("ghb_settings_init");
1202 prefs_initializing = TRUE;
1204 internalPlist = ghb_resource_get("internal-defaults");
1205 // Setting a ui widget will cause the corresponding setting
1206 // to be set, but it also triggers a callback that can
1207 // have the side effect of using other settings values
1208 // that have not yet been set. So set *all* settings first
1209 // then update the ui.
1210 internal = plist_get_dict(internalPlist, "Initialization");
1211 ghb_dict_iter_init(&iter, internal);
1212 // middle (void*) cast prevents gcc warning "defreferencing type-punned
1213 // pointer will break strict-aliasing rules"
1214 while (g_hash_table_iter_next(
1215 &iter, (gpointer*)(void*)&key, (gpointer*)(void*)&gval))
1217 ghb_settings_set_value(ud->settings, key, gval);
1220 internal = plist_get_dict(internalPlist, "Presets");
1221 ghb_dict_iter_init(&iter, internal);
1222 // middle (void*) cast prevents gcc warning "defreferencing type-punned
1223 // pointer will break strict-aliasing rules"
1224 while (g_hash_table_iter_next(
1225 &iter, (gpointer*)(void*)&key, (gpointer*)(void*)&gval))
1227 ghb_settings_set_value(ud->settings, key, gval);
1230 internal = plist_get_dict(internalPlist, "Preferences");
1231 ghb_dict_iter_init(&iter, internal);
1232 // middle (void*) cast prevents gcc warning "defreferencing type-punned
1233 // pointer will break strict-aliasing rules"
1234 while (g_hash_table_iter_next(
1235 &iter, (gpointer*)(void*)&key, (gpointer*)(void*)&gval))
1237 ghb_settings_set_value(ud->settings, key, gval);
1239 prefs_initializing = FALSE;
1243 ghb_settings_close()
1246 ghb_value_free(internalPlist);
1248 ghb_value_free(presetsPlist);
1250 ghb_value_free(prefsPlist);
1254 ghb_prefs_load(signal_user_data_t *ud)
1256 GValue *dict, *internal;
1257 GHashTableIter iter;
1259 GValue *gval, *path;
1261 g_debug("ghb_prefs_load");
1262 prefsPlist = load_plist("preferences");
1263 if (prefsPlist == NULL)
1264 prefsPlist = ghb_dict_value_new();
1265 dict = plist_get_dict(prefsPlist, "Preferences");
1266 internal = plist_get_dict(internalPlist, "Preferences");
1267 if (dict == NULL && internal)
1269 dict = ghb_dict_value_new();
1270 ghb_dict_insert(prefsPlist, g_strdup("Preferences"), dict);
1272 // Get defaults from internal defaults
1273 ghb_dict_iter_init(&iter, internal);
1274 // middle (void*) cast prevents gcc warning "defreferencing type-punned
1275 // pointer will break strict-aliasing rules"
1276 while (g_hash_table_iter_next(
1277 &iter, (gpointer*)(void*)&key, (gpointer*)(void*)&gval))
1279 ghb_dict_insert(dict, g_strdup(key), ghb_value_dup(gval));
1281 const gchar *dir = g_get_user_special_dir (G_USER_DIRECTORY_VIDEOS);
1286 ghb_dict_insert(dict,
1287 g_strdup("destination_dir"), ghb_value_dup(ghb_string_value(dir)));
1288 store_plist(prefsPlist, "preferences");
1290 // Read legacy default_preset preference and update accordingly
1291 path = ghb_dict_lookup(dict, "default_preset");
1296 if (G_VALUE_TYPE(path) == G_TYPE_STRING)
1300 path = ghb_array_value_new(1);
1301 ghb_array_append(path, ghb_value_dup(str));
1302 indices = ghb_preset_indices_from_path(presetsPlist, path, &len);
1303 ghb_value_free(path);
1306 indices = ghb_preset_indices_from_path(presetsPlist, path, &len);
1310 presets_set_default(indices, len);
1313 ghb_dict_remove(dict, "default_preset");
1314 store_plist(prefsPlist, "preferences");
1319 get_preset_color(gint type, gboolean folder)
1323 if (type == PRESETS_CUSTOM)
1343 ghb_presets_list_init(
1344 signal_user_data_t *ud,
1348 GtkTreeView *treeview;
1349 GtkTreeIter iter, titer, *piter;
1351 GtkTreeStore *store;
1352 const gchar *preset;
1353 GtkTreePath *parent_path;
1354 const gchar *description;
1359 GValue *presets = NULL;
1361 g_debug("ghb_presets_list_init ()");
1362 more_indices = g_malloc((len+1)*sizeof(gint));
1363 memcpy(more_indices, indices, len*sizeof(gint));
1364 presets = presets_get_folder(presetsPlist, indices, len);
1365 if (presets == NULL)
1367 g_warning("Failed to find parent folder when adding child.");
1370 count = ghb_array_len(presets);
1371 treeview = GTK_TREE_VIEW(GHB_WIDGET(ud->builder, "presets_list"));
1372 store = GTK_TREE_STORE(gtk_tree_view_get_model(treeview));
1373 parent_path = ghb_tree_path_new_from_indices(indices, len);
1376 gtk_tree_model_get_iter(GTK_TREE_MODEL(store), &titer, parent_path);
1378 gtk_tree_path_free(parent_path);
1384 for (ii = 0; ii < count; ii++)
1390 // Additional settings, add row
1391 dict = ghb_array_get_nth(presets, ii);
1392 preset = preset_get_name(dict);
1393 more_indices[len] = ii;
1394 def = preset_is_default(dict);
1396 description = ghb_presets_get_description(dict);
1397 gtk_tree_store_append(store, &iter, piter);
1398 type = ghb_preset_type(dict);
1399 folder = ghb_preset_folder(dict);
1400 color = get_preset_color(type, folder);
1401 gtk_tree_store_set(store, &iter, 0, preset,
1412 if (gtk_tree_model_iter_parent(
1413 GTK_TREE_MODEL(store), &ppiter, piter))
1415 path = gtk_tree_model_get_path(GTK_TREE_MODEL(store), &ppiter);
1416 gtk_tree_view_expand_row(treeview, path, FALSE);
1417 gtk_tree_path_free(path);
1419 path = gtk_tree_model_get_path(GTK_TREE_MODEL(store), piter);
1420 gtk_tree_view_expand_row(treeview, path, FALSE);
1421 gtk_tree_path_free(path);
1425 ghb_presets_list_init(ud, more_indices, len+1);
1428 g_free(more_indices);
1432 presets_list_update_item(
1433 signal_user_data_t *ud,
1437 GtkTreeView *treeview;
1438 GtkTreeStore *store;
1440 GtkTreePath *treepath;
1442 const gchar *description;
1444 gboolean def, folder;
1448 g_debug("presets_list_update_item ()");
1449 dict = presets_get_dict(presetsPlist, indices, len);
1452 treeview = GTK_TREE_VIEW(GHB_WIDGET(ud->builder, "presets_list"));
1453 store = GTK_TREE_STORE(gtk_tree_view_get_model(treeview));
1454 treepath = ghb_tree_path_new_from_indices(indices, len);
1455 gtk_tree_model_get_iter(GTK_TREE_MODEL(store), &iter, treepath);
1456 // Additional settings, add row
1457 name = preset_get_name(dict);
1458 def = preset_is_default(dict);
1460 description = ghb_presets_get_description(dict);
1461 type = ghb_preset_type(dict);
1462 folder = ghb_preset_folder(dict);
1463 color = get_preset_color(type, folder);
1464 gtk_tree_store_set(store, &iter, 0, name,
1472 ghb_presets_list_init(ud, indices, len);
1477 presets_list_insert(
1478 signal_user_data_t *ud,
1482 GtkTreeView *treeview;
1483 GtkTreeIter iter, titer, *piter;
1484 GtkTreeStore *store;
1485 const gchar *preset;
1486 const gchar *description;
1488 gboolean def, folder;
1491 GtkTreePath *parent_path;
1495 g_debug("presets_list_insert ()");
1496 treeview = GTK_TREE_VIEW(GHB_WIDGET(ud->builder, "presets_list"));
1497 store = GTK_TREE_STORE(gtk_tree_view_get_model(treeview));
1498 presets = presets_get_folder(presetsPlist, indices, len-1);
1499 if (presets == NULL)
1501 g_warning("Failed to find parent folder while adding child.");
1504 parent_path = ghb_tree_path_new_from_indices(indices, len-1);
1507 gtk_tree_model_get_iter(GTK_TREE_MODEL(store), &titer, parent_path);
1509 gtk_tree_path_free(parent_path);
1515 count = ghb_array_len(presets);
1516 if (indices[len-1] >= count)
1518 // Additional settings, add row
1519 dict = ghb_array_get_nth(presets, indices[len-1]);
1520 preset = preset_get_name(dict);
1521 def = preset_is_default(dict);
1523 description = ghb_presets_get_description(dict);
1524 gtk_tree_store_insert(store, &iter, piter, indices[len-1]);
1525 type = ghb_preset_type(dict);
1526 folder = ghb_preset_folder(dict);
1527 color = get_preset_color(type, folder);
1528 gtk_tree_store_set(store, &iter, 0, preset,
1536 ghb_presets_list_init(ud, indices, len);
1541 presets_list_remove(
1542 signal_user_data_t *ud,
1546 GtkTreeView *treeview;
1547 GtkTreePath *treepath;
1549 GtkTreeStore *store;
1551 g_debug("presets_list_remove ()");
1552 treeview = GTK_TREE_VIEW(GHB_WIDGET(ud->builder, "presets_list"));
1553 store = GTK_TREE_STORE(gtk_tree_view_get_model(treeview));
1554 treepath = ghb_tree_path_new_from_indices(indices, len);
1557 if (gtk_tree_model_get_iter(GTK_TREE_MODEL(store), &iter, treepath))
1558 gtk_tree_store_remove(store, &iter);
1559 gtk_tree_path_free(treepath);
1564 remove_std_presets(signal_user_data_t *ud)
1569 count = ghb_array_len(presetsPlist);
1570 for (ii = count-1; ii >= 0; ii--)
1575 dict = ghb_array_get_nth(presetsPlist, ii);
1576 ptype = ghb_value_int(preset_dict_get_value(dict, "Type"));
1577 if (ptype == PRESETS_BUILTIN)
1579 if (ghb_presets_remove(presetsPlist, &indices, 1))
1581 presets_list_remove(ud, &indices, 1);
1588 ghb_save_queue(GValue *queue)
1590 store_plist(queue, "queue");
1596 return load_plist("queue");
1600 ghb_remove_queue_file()
1602 remove_plist("queue");
1611 static value_map_t vcodec_xlat[] =
1613 {"MPEG-4 (FFmpeg)", "ffmpeg"},
1614 {"MPEG-4 (XviD)", "xvid"},
1615 {"H.264 (x264)", "x264"},
1616 {"VP3 (Theora)", "theora"},
1620 static value_map_t acodec_xlat[] =
1622 {"AAC (faac)", "faac"},
1623 {"AC3 Passthru", "ac3"},
1624 {"MP3 (lame)", "lame"},
1625 {"Vorbis (vorbis)", "vorbis"},
1629 value_map_t container_xlat[] =
1631 {"MP4 file", "mp4"},
1632 {"M4V file", "m4v"},
1633 {"MKV file", "mkv"},
1634 {"AVI file", "avi"},
1635 {"OGM file", "ogm"},
1639 value_map_t framerate_xlat[] =
1641 {"Same as source", "source"},
1646 {"23.976", "23.976"},
1653 value_map_t samplerate_xlat[] =
1664 value_map_t mix_xlat[] =
1667 {"Stereo", "stereo"},
1668 {"Dolby Surround", "dpl1"},
1669 {"Dolby Pro Logic II", "dpl2"},
1670 {"6-channel discrete", "6ch"},
1671 {"AC3 Passthru", "none"},
1675 value_map_t deint_xlat[] =
1685 value_map_t denoise_xlat[] =
1695 value_map_t detel_xlat[] =
1703 value_map_t decomb_xlat[] =
1711 extern iso639_lang_t ghb_language_table[];
1714 export_lang_xlat2(GValue *lin_val)
1718 if (lin_val == NULL) return NULL;
1722 str = ghb_value_string(lin_val);
1723 for (ii = 0; ghb_language_table[ii].eng_name; ii++)
1725 if (strcmp(str, ghb_language_table[ii].iso639_2) == 0)
1727 gval = ghb_string_value_new(ghb_language_table[ii].eng_name);
1732 g_debug("Can't map language value: (%s)", str);
1738 export_subtitle_xlat2(GValue *lin_val)
1743 if (lin_val == NULL) return NULL;
1744 str = ghb_value_string(lin_val);
1745 if (strcmp(str, "none") == 0)
1747 gval = ghb_string_value_new("None");
1749 else if (strcmp(str, "auto") == 0)
1751 gval = ghb_string_value_new("Autoselect");
1755 gval = export_lang_xlat2(lin_val);
1762 import_lang_xlat2(GValue *mac_val)
1766 if (mac_val == NULL) return NULL;
1770 str = ghb_value_string(mac_val);
1771 for (ii = 0; ghb_language_table[ii].eng_name; ii++)
1773 if (strcmp(str, ghb_language_table[ii].eng_name) == 0)
1775 gval = ghb_string_value_new(ghb_language_table[ii].iso639_2);
1780 g_debug("Can't map language value: (%s)", str);
1786 import_subtitle_xlat2(GValue *mac_val)
1791 if (mac_val == NULL) return NULL;
1792 str = ghb_value_string(mac_val);
1793 if (strcmp(str, "None") == 0)
1795 gval = ghb_string_value_new("none");
1797 else if (strcmp(str, "Autoselect") == 0)
1799 gval = ghb_string_value_new("auto");
1803 gval = import_lang_xlat2(mac_val);
1810 export_audio_track_xlat2(GValue *lin_val)
1813 GValue *gval = NULL;
1815 if (lin_val == NULL) return NULL;
1816 str = ghb_value_string(lin_val);
1817 if (strcmp(str, "none") == 0)
1819 gval = ghb_int_value_new(1);
1823 gint val = ghb_value_int(lin_val) + 1;
1824 gval = ghb_int_value_new(val);
1831 import_audio_track_xlat2(GValue *mac_val)
1837 if (mac_val == NULL) return NULL;
1838 val = ghb_value_int(mac_val);
1847 str = g_strdup_printf("%d", val);
1848 gval = ghb_string_value_new(str);
1854 export_value_xlat2(value_map_t *value_map, GValue *lin_val, GType mac_type)
1858 if (lin_val == NULL) return NULL;
1863 str = ghb_value_string(lin_val);
1864 for (ii = 0; value_map[ii].mac_val; ii++)
1866 if (strcmp(str, value_map[ii].lin_val) == 0)
1868 sval = ghb_string_value_new(value_map[ii].mac_val);
1870 gval = ghb_value_new(mac_type);
1871 if (!g_value_transform(sval, gval))
1873 g_warning("can't transform");
1874 ghb_value_free(gval);
1875 ghb_value_free(sval);
1878 ghb_value_free(sval);
1882 g_debug("Can't map value: (%s)", str);
1888 export_value_xlat(GValue *dict)
1890 GValue *lin_val, *gval;
1893 key = "VideoEncoder";
1894 lin_val = ghb_dict_lookup(dict, key);
1895 gval = export_value_xlat2(vcodec_xlat, lin_val, G_TYPE_STRING);
1897 ghb_dict_insert(dict, g_strdup(key), gval);
1899 lin_val = ghb_dict_lookup(dict, key);
1900 gval = export_value_xlat2(container_xlat, lin_val, G_TYPE_STRING);
1902 ghb_dict_insert(dict, g_strdup(key), gval);
1903 key = "VideoFramerate";
1904 lin_val = ghb_dict_lookup(dict, key);
1905 gval = export_value_xlat2(framerate_xlat, lin_val, G_TYPE_STRING);
1907 ghb_dict_insert(dict, g_strdup(key), gval);
1908 key = "PictureDetelecine";
1909 lin_val = ghb_dict_lookup(dict, key);
1910 gval = export_value_xlat2(detel_xlat, lin_val, G_TYPE_INT);
1912 ghb_dict_insert(dict, g_strdup(key), gval);
1913 key = "PictureDecomb";
1914 lin_val = ghb_dict_lookup(dict, key);
1915 gval = export_value_xlat2(decomb_xlat, lin_val, G_TYPE_INT);
1917 ghb_dict_insert(dict, g_strdup(key), gval);
1918 key = "PictureDeinterlace";
1919 lin_val = ghb_dict_lookup(dict, key);
1920 gval = export_value_xlat2(deint_xlat, lin_val, G_TYPE_INT);
1922 ghb_dict_insert(dict, g_strdup(key), gval);
1923 key = "PictureDenoise";
1924 lin_val = ghb_dict_lookup(dict, key);
1925 gval = export_value_xlat2(denoise_xlat, lin_val, G_TYPE_INT);
1927 ghb_dict_insert(dict, g_strdup(key), gval);
1929 lin_val = ghb_dict_lookup(dict, key);
1930 gval = export_subtitle_xlat2(lin_val);
1932 ghb_dict_insert(dict, g_strdup(key), gval);
1938 alist = ghb_dict_lookup(dict, "AudioList");
1939 count = ghb_array_len(alist);
1940 for (ii = 0; ii < count; ii++)
1942 adict = ghb_array_get_nth(alist, ii);
1944 lin_val = ghb_dict_lookup(adict, key);
1945 gval = export_audio_track_xlat2(lin_val);
1947 ghb_dict_insert(adict, g_strdup(key), gval);
1948 key = "AudioEncoder";
1949 lin_val = ghb_dict_lookup(adict, key);
1950 gval = export_value_xlat2(acodec_xlat, lin_val, G_TYPE_STRING);
1952 ghb_dict_insert(adict, g_strdup(key), gval);
1953 key = "AudioSamplerate";
1954 lin_val = ghb_dict_lookup(adict, key);
1955 gval = export_value_xlat2(samplerate_xlat, lin_val, G_TYPE_STRING);
1957 ghb_dict_insert(adict, g_strdup(key), gval);
1958 key = "AudioMixdown";
1959 lin_val = ghb_dict_lookup(adict, key);
1960 gval = export_value_xlat2(mix_xlat, lin_val, G_TYPE_STRING);
1962 ghb_dict_insert(adict, g_strdup(key), gval);
1970 value_map_t *value_map,
1974 GValue *gval, *def_val;
1976 if (mac_val == NULL) return NULL;
1977 def_val = ghb_dict_lookup(defaults, key);
1984 str = ghb_value_string(mac_val);
1985 for (ii = 0; value_map[ii].mac_val; ii++)
1987 if (strcmp(str, value_map[ii].mac_val) == 0)
1989 sval = ghb_string_value_new(value_map[ii].lin_val);
1991 gval = ghb_value_new(G_VALUE_TYPE(def_val));
1992 if (!g_value_transform(sval, gval))
1994 g_warning("can't transform");
1995 ghb_value_free(gval);
1996 ghb_value_free(sval);
1999 ghb_value_free(sval);
2003 //g_warning("Can't map value: (%s)", str);
2008 g_warning("Bad key: (%s)", key);
2015 import_value_xlat(GValue *dict)
2017 GValue *defaults, *mac_val, *gval;
2020 defaults = plist_get_dict(internalPlist, "Presets");
2021 key = "VideoEncoder";
2022 mac_val = ghb_dict_lookup(dict, key);
2023 gval = import_value_xlat2(defaults, vcodec_xlat, key, mac_val);
2025 ghb_dict_insert(dict, g_strdup(key), gval);
2027 mac_val = ghb_dict_lookup(dict, key);
2028 gval = import_value_xlat2(defaults, container_xlat, key, mac_val);
2030 ghb_dict_insert(dict, g_strdup(key), gval);
2031 key = "VideoFramerate";
2032 mac_val = ghb_dict_lookup(dict, key);
2033 gval = import_value_xlat2(defaults, framerate_xlat, key, mac_val);
2035 ghb_dict_insert(dict, g_strdup(key), gval);
2036 key = "PictureDetelecine";
2037 mac_val = ghb_dict_lookup(dict, key);
2038 gval = import_value_xlat2(defaults, detel_xlat, key, mac_val);
2040 ghb_dict_insert(dict, g_strdup(key), gval);
2041 key = "PictureDecomb";
2042 mac_val = ghb_dict_lookup(dict, key);
2043 gval = import_value_xlat2(defaults, decomb_xlat, key, mac_val);
2045 ghb_dict_insert(dict, g_strdup(key), gval);
2046 key = "PictureDeinterlace";
2047 mac_val = ghb_dict_lookup(dict, key);
2048 gval = import_value_xlat2(defaults, deint_xlat, key, mac_val);
2050 ghb_dict_insert(dict, g_strdup(key), gval);
2051 key = "PictureDenoise";
2052 mac_val = ghb_dict_lookup(dict, key);
2053 gval = import_value_xlat2(defaults, denoise_xlat, key, mac_val);
2055 ghb_dict_insert(dict, g_strdup(key), gval);
2057 mac_val = ghb_dict_lookup(dict, key);
2058 gval = import_subtitle_xlat2(mac_val);
2060 ghb_dict_insert(dict, g_strdup(key), gval);
2068 adeflist = ghb_dict_lookup(dict, "AudioList");
2071 adefaults = ghb_array_get_nth(adeflist, 0);
2072 alist = ghb_dict_lookup(dict, "AudioList");
2073 count = ghb_array_len(alist);
2074 for (ii = 0; ii < count; ii++)
2076 adict = ghb_array_get_nth(alist, ii);
2078 mac_val = ghb_dict_lookup(adict, key);
2079 gval = import_audio_track_xlat2(mac_val);
2081 ghb_dict_insert(adict, g_strdup(key), gval);
2082 key = "AudioEncoder";
2083 mac_val = ghb_dict_lookup(adict, key);
2084 gval = import_value_xlat2(adefaults, acodec_xlat, key, mac_val);
2086 ghb_dict_insert(adict, g_strdup(key), gval);
2087 key = "AudioSamplerate";
2088 mac_val = ghb_dict_lookup(adict, key);
2089 gval = import_value_xlat2(adefaults, samplerate_xlat, key, mac_val);
2091 ghb_dict_insert(adict, g_strdup(key), gval);
2092 key = "AudioMixdown";
2093 mac_val = ghb_dict_lookup(adict, key);
2094 gval = import_value_xlat2(adefaults, mix_xlat, key, mac_val);
2096 ghb_dict_insert(adict, g_strdup(key), gval);
2102 import_xlat_preset(GValue *dict)
2109 g_debug("import_xlat_preset ()");
2110 uses_max = ghb_value_boolean(
2111 preset_dict_get_value(dict, "UsesMaxPictureSettings"));
2112 uses_pic = ghb_value_int(
2113 preset_dict_get_value(dict, "UsesPictureSettings"));
2114 par = ghb_value_int(preset_dict_get_value(dict, "PicturePAR"));
2115 vqtype = ghb_value_int(preset_dict_get_value(dict, "VideoQualityType"));
2117 if (uses_max || uses_pic == 2)
2119 ghb_dict_insert(dict, g_strdup("autoscale"),
2120 ghb_boolean_value_new(TRUE));
2126 ghb_dict_insert(dict, g_strdup("anamorphic"),
2127 ghb_boolean_value_new(FALSE));
2128 if (ghb_dict_lookup(dict, "ModDimensions") == NULL)
2129 ghb_dict_insert(dict, g_strdup("ModDimensions"),
2130 ghb_boolean_value_new(TRUE));
2134 ghb_dict_insert(dict, g_strdup("anamorphic"),
2135 ghb_boolean_value_new(TRUE));
2136 ghb_dict_insert(dict, g_strdup("ModDimensions"),
2137 ghb_boolean_value_new(FALSE));
2141 ghb_dict_insert(dict, g_strdup("anamorphic"),
2142 ghb_boolean_value_new(TRUE));
2143 ghb_dict_insert(dict, g_strdup("ModDimensions"),
2144 ghb_boolean_value_new(TRUE));
2148 ghb_dict_insert(dict, g_strdup("anamorphic"),
2149 ghb_boolean_value_new(TRUE));
2150 ghb_dict_insert(dict, g_strdup("ModDimensions"),
2151 ghb_boolean_value_new(TRUE));
2154 // VideoQualityType/0/1/2 - vquality_type_/target/bitrate/constant
2159 ghb_dict_insert(dict, g_strdup("vquality_type_target"),
2160 ghb_boolean_value_new(TRUE));
2161 ghb_dict_insert(dict, g_strdup("vquality_type_bitrate"),
2162 ghb_boolean_value_new(FALSE));
2163 ghb_dict_insert(dict, g_strdup("vquality_type_constant"),
2164 ghb_boolean_value_new(FALSE));
2168 ghb_dict_insert(dict, g_strdup("vquality_type_target"),
2169 ghb_boolean_value_new(FALSE));
2170 ghb_dict_insert(dict, g_strdup("vquality_type_bitrate"),
2171 ghb_boolean_value_new(TRUE));
2172 ghb_dict_insert(dict, g_strdup("vquality_type_constant"),
2173 ghb_boolean_value_new(FALSE));
2177 ghb_dict_insert(dict, g_strdup("vquality_type_target"),
2178 ghb_boolean_value_new(FALSE));
2179 ghb_dict_insert(dict, g_strdup("vquality_type_bitrate"),
2180 ghb_boolean_value_new(FALSE));
2181 ghb_dict_insert(dict, g_strdup("vquality_type_constant"),
2182 ghb_boolean_value_new(TRUE));
2186 ghb_dict_insert(dict, g_strdup("vquality_type_target"),
2187 ghb_boolean_value_new(FALSE));
2188 ghb_dict_insert(dict, g_strdup("vquality_type_bitrate"),
2189 ghb_boolean_value_new(FALSE));
2190 ghb_dict_insert(dict, g_strdup("vquality_type_constant"),
2191 ghb_boolean_value_new(TRUE));
2194 import_value_xlat(dict);
2198 import_xlat_presets(GValue *presets)
2204 g_debug("import_xlat_presets ()");
2205 if (presets == NULL) return;
2206 count = ghb_array_len(presets);
2207 for (ii = 0; ii < count; ii++)
2209 dict = ghb_array_get_nth(presets, ii);
2210 folder = ghb_value_boolean(preset_dict_get_value(dict, "Folder"));
2215 nested = ghb_dict_lookup(dict, "ChildrenArray");
2216 import_xlat_presets(nested);
2220 import_xlat_preset(dict);
2226 export_xlat_preset(GValue *dict)
2228 gboolean ana, round, autoscale, target, br, constant;
2230 g_debug("export_xlat_prest ()");
2231 autoscale = ghb_value_boolean(preset_dict_get_value(dict, "autoscale"));
2232 ana = ghb_value_boolean(preset_dict_get_value(dict, "anamorphic"));
2233 round = ghb_value_boolean(preset_dict_get_value(dict, "ModDimensions"));
2234 target = ghb_value_boolean(
2235 preset_dict_get_value(dict, "vquality_type_target"));
2236 br = ghb_value_boolean(
2237 preset_dict_get_value(dict, "vquality_type_bitrate"));
2238 constant = ghb_value_boolean(
2239 preset_dict_get_value(dict, "vquality_type_constant"));
2242 ghb_dict_insert(dict, g_strdup("UsesPictureSettings"),
2243 ghb_int_value_new(2));
2245 ghb_dict_insert(dict, g_strdup("UsesPictureSettings"),
2246 ghb_int_value_new(1));
2251 ghb_dict_insert(dict, g_strdup("PicturePAR"),
2252 ghb_int_value_new(2));
2254 ghb_dict_insert(dict, g_strdup("PicturePAR"),
2255 ghb_int_value_new(1));
2259 ghb_dict_insert(dict, g_strdup("PicturePAR"),
2260 ghb_int_value_new(0));
2262 // VideoQualityType/0/1/2 - vquality_type_/target/bitrate/constant
2265 ghb_dict_insert(dict, g_strdup("VideoQualityType"),
2266 ghb_int_value_new(0));
2270 ghb_dict_insert(dict, g_strdup("VideoQualityType"),
2271 ghb_int_value_new(1));
2275 ghb_dict_insert(dict, g_strdup("VideoQualityType"),
2276 ghb_int_value_new(2));
2278 ghb_dict_remove(dict, "UsesMaxPictureSettings");
2279 ghb_dict_remove(dict, "autoscale");
2280 ghb_dict_remove(dict, "anamorphic");
2281 ghb_dict_remove(dict, "vquality_type_target");
2282 ghb_dict_remove(dict, "vquality_type_bitrate");
2283 ghb_dict_remove(dict, "vquality_type_constant");
2284 export_value_xlat(dict);
2288 export_xlat_presets(GValue *presets)
2294 if (presets == NULL) return;
2295 count = ghb_array_len(presets);
2296 for (ii = 0; ii < count; ii++)
2298 dict = ghb_array_get_nth(presets, ii);
2299 folder = ghb_value_boolean(preset_dict_get_value(dict, "Folder"));
2304 nested = ghb_dict_lookup(dict, "ChildrenArray");
2305 export_xlat_presets(nested);
2309 export_xlat_preset(dict);
2319 export = ghb_value_dup(presetsPlist);
2320 export_xlat_presets(export);
2321 store_plist(export, "presets");
2322 ghb_value_free(export);
2326 ghb_presets_reload(signal_user_data_t *ud)
2328 GValue *std_presets;
2332 g_debug("ghb_presets_reload()\n");
2333 std_presets = ghb_resource_get("standard-presets");
2334 if (std_presets == NULL) return;
2336 remove_std_presets(ud);
2337 indices = presets_find_default(presetsPlist, &len);
2340 presets_clear_default(std_presets);
2343 // Merge the keyfile contents into our presets
2344 count = ghb_array_len(std_presets);
2345 for (ii = count-1; ii >= 0; ii--)
2351 std_dict = ghb_array_get_nth(std_presets, ii);
2352 copy_dict = ghb_value_dup(std_dict);
2353 ghb_presets_insert(presetsPlist, copy_dict, &indices, 1);
2354 presets_list_insert(ud, &indices, 1);
2356 import_xlat_presets(presetsPlist);
2365 count = ghb_array_len(presetsPlist);
2366 for (ii = count-1; ii >= 0; ii--)
2371 dict = ghb_array_get_nth(presetsPlist, ii);
2372 type = ghb_dict_lookup(dict, "Type");
2382 presetsPlist = load_plist("presets");
2383 if (presetsPlist == NULL)
2385 presetsPlist = ghb_value_dup(ghb_resource_get("standard-presets"));
2386 import_xlat_presets(presetsPlist);
2389 else if (G_VALUE_TYPE(presetsPlist) == ghb_dict_get_type())
2390 { // Presets is older dictionary format. Convert to array
2391 ghb_value_free(presetsPlist);
2392 presetsPlist = ghb_value_dup(ghb_resource_get("standard-presets"));
2393 import_xlat_presets(presetsPlist);
2396 else if (check_old_presets())
2398 ghb_value_free(presetsPlist);
2399 presetsPlist = ghb_value_dup(ghb_resource_get("standard-presets"));
2400 import_xlat_presets(presetsPlist);
2403 import_xlat_presets(presetsPlist);
2407 settings_save(signal_user_data_t *ud, const GValue *path)
2409 GValue *dict, *internal;
2410 GHashTableIter iter;
2414 gint *indices, len, count;
2416 gboolean replace = FALSE;
2418 g_debug("settings_save");
2419 if (internalPlist == NULL) return;
2420 count = ghb_array_len(path);
2421 name = g_value_get_string(ghb_array_get_nth(path, count-1));
2422 indices = ghb_preset_indices_from_path(presetsPlist, path, &len);
2425 if (ghb_presets_get_folder(presetsPlist, indices, len))
2428 message = g_strdup_printf(
2429 "%s: Folder already exists.\n"
2430 "You can not replace it with a preset.",
2432 ghb_message_dialog(GTK_MESSAGE_ERROR, message, "Cancel", NULL);
2436 dict = ghb_dict_value_new();
2437 ghb_presets_replace(presetsPlist, dict, indices, len);
2442 indices = presets_find_pos(path, PRESETS_CUSTOM, &len);
2445 dict = ghb_dict_value_new();
2446 ghb_presets_insert(presetsPlist, dict, indices, len);
2450 g_warning("failed to find insert path");
2454 current_preset = dict;
2455 autoscale = ghb_settings_get_boolean(ud->settings, "autoscale");
2456 ghb_settings_set_int64(ud->settings, "Type", PRESETS_CUSTOM);
2458 internal = plist_get_dict(internalPlist, "Presets");
2459 ghb_dict_iter_init(&iter, internal);
2460 // middle (void*) cast prevents gcc warning "defreferencing type-punned
2461 // pointer will break strict-aliasing rules"
2462 while (g_hash_table_iter_next(
2463 &iter, (gpointer*)(void*)&key, (gpointer*)(void*)&value))
2471 if (strcmp(key, "PictureWidth") == 0)
2473 key2 = "scale_width";
2475 else if (strcmp(key, "PictureHeight") == 0)
2477 key2 = "scale_height";
2480 gval = ghb_settings_get_value(ud->settings, key2);
2485 ghb_dict_insert(dict, g_strdup(key), ghb_value_dup(gval));
2487 internal = plist_get_dict(internalPlist, "XlatPresets");
2488 ghb_dict_iter_init(&iter, internal);
2489 // middle (void*) cast prevents gcc warning "defreferencing type-punned
2490 // pointer will break strict-aliasing rules"
2491 while (g_hash_table_iter_next(
2492 &iter, (gpointer*)(void*)&key, (gpointer*)(void*)&value))
2496 gval = ghb_settings_get_value(ud->settings, key);
2501 ghb_dict_insert(dict, g_strdup(key), ghb_value_dup(gval));
2503 ghb_dict_insert(dict, g_strdup("PresetName"), ghb_string_value_new(name));
2505 presets_list_update_item(ud, indices, len);
2508 ghb_dict_insert(dict, g_strdup("Default"),
2509 ghb_boolean_value_new(FALSE));
2510 presets_list_insert(ud, indices, len);
2513 ud->dont_clear_presets = TRUE;
2514 // Make the new preset the selected item
2515 ghb_select_preset2(ud->builder, indices, len);
2517 ud->dont_clear_presets = FALSE;
2522 folder_save(signal_user_data_t *ud, const GValue *path)
2524 GValue *dict, *folder;
2525 gint *indices, len, count;
2528 count = ghb_array_len(path);
2529 name = g_value_get_string(ghb_array_get_nth(path, count-1));
2530 indices = ghb_preset_indices_from_path(presetsPlist, path, &len);
2533 if (!ghb_presets_get_folder(presetsPlist, indices, len))
2536 message = g_strdup_printf(
2537 "%s: Preset already exists.\n"
2538 "You can not replace it with a folder.",
2540 ghb_message_dialog(GTK_MESSAGE_ERROR, message, "Cancel", NULL);
2545 // Already exists, update its description
2546 dict = presets_get_dict(presetsPlist, indices, len);
2547 ghb_dict_insert(dict, g_strdup("PresetDescription"),
2548 ghb_value_dup(preset_dict_get_value(
2549 ud->settings, "PresetDescription")));
2555 indices = presets_find_pos(path, PRESETS_CUSTOM, &len);
2558 dict = ghb_dict_value_new();
2559 ghb_presets_insert(presetsPlist, dict, indices, len);
2563 g_warning("failed to find insert path");
2567 ghb_dict_insert(dict, g_strdup("PresetDescription"),
2568 ghb_value_dup(preset_dict_get_value(
2569 ud->settings, "PresetDescription")));
2570 ghb_dict_insert(dict, g_strdup("PresetName"), ghb_string_value_new(name));
2571 folder = ghb_array_value_new(8);
2572 ghb_dict_insert(dict, g_strdup("ChildrenArray"), folder);
2573 ghb_dict_insert(dict, g_strdup("Type"),
2574 ghb_int64_value_new(PRESETS_CUSTOM));
2575 ghb_dict_insert(dict, g_strdup("Folder"), ghb_boolean_value_new(TRUE));
2577 presets_list_insert(ud, indices, len);
2584 ghb_presets_list_default(signal_user_data_t *ud)
2586 GtkTreeView *treeview;
2587 GtkTreePath *treepath;
2589 GtkTreeStore *store;
2592 g_debug("ghb_presets_list_default ()");
2593 treeview = GTK_TREE_VIEW(GHB_WIDGET(ud->builder, "presets_list"));
2594 store = GTK_TREE_STORE(gtk_tree_view_get_model(treeview));
2595 indices = presets_find_default(presetsPlist, &len);
2596 if (indices == NULL) return;
2597 treepath = ghb_tree_path_new_from_indices(indices, len);
2600 if (gtk_tree_model_get_iter(GTK_TREE_MODEL(store), &iter, treepath))
2602 gtk_tree_store_set(store, &iter,
2607 gtk_tree_path_free(treepath);
2613 ghb_presets_list_clear_default(signal_user_data_t *ud)
2615 GtkTreeView *treeview;
2616 GtkTreePath *treepath;
2618 GtkTreeStore *store;
2621 g_debug("ghb_presets_list_clear_default ()");
2622 treeview = GTK_TREE_VIEW(GHB_WIDGET(ud->builder, "presets_list"));
2623 store = GTK_TREE_STORE(gtk_tree_view_get_model(treeview));
2624 indices = presets_find_default(presetsPlist, &len);
2625 if (indices == NULL) return;
2626 treepath = ghb_tree_path_new_from_indices(indices, len);
2629 if (gtk_tree_model_get_iter(GTK_TREE_MODEL(store), &iter, treepath))
2631 gtk_tree_store_set(store, &iter,
2636 gtk_tree_path_free(treepath);
2642 update_audio_presets(signal_user_data_t *ud)
2644 g_debug("update_audio_presets");
2645 const GValue *audio_list;
2647 audio_list = ghb_settings_get_value(ud->settings, "audio_list");
2648 ghb_settings_set_value(ud->settings, "AudioList", audio_list);
2652 enforce_preset_type(signal_user_data_t *ud, const GValue *path)
2655 GtkWidget *normal, *folder;
2658 normal = GHB_WIDGET(ud->builder, "preset_type_normal");
2659 folder = GHB_WIDGET(ud->builder, "preset_type_folder");
2660 indices = ghb_preset_indices_from_path(presetsPlist, path, &len);
2663 fold = ghb_presets_get_folder(presetsPlist, indices, len);
2665 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(folder),
2668 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(normal),
2670 gtk_widget_set_sensitive(folder, fold);
2671 gtk_widget_set_sensitive(normal, !fold);
2676 gtk_widget_set_sensitive(folder, TRUE);
2677 gtk_widget_set_sensitive(normal, TRUE);
2682 presets_save_clicked_cb(GtkWidget *xwidget, signal_user_data_t *ud)
2687 GtkResponseType response;
2689 const gchar *name = "";
2690 gint count, *indices, len;
2692 g_debug("presets_save_clicked_cb ()");
2693 preset = ghb_settings_get_value (ud->settings, "preset_selection");
2695 count = ghb_array_len(preset);
2697 name = g_value_get_string(ghb_array_get_nth(preset, count-1));
2700 // Clear the description
2701 desc = GTK_TEXT_VIEW(GHB_WIDGET(ud->builder, "PresetDescription"));
2702 dialog = GHB_WIDGET(ud->builder, "preset_save_dialog");
2703 entry = GTK_ENTRY(GHB_WIDGET(ud->builder, "PresetName"));
2704 gtk_entry_set_text(entry, name);
2705 enforce_preset_type(ud, preset);
2706 response = gtk_dialog_run(GTK_DIALOG(dialog));
2707 gtk_widget_hide(dialog);
2708 if (response == GTK_RESPONSE_OK)
2711 const gchar *name = gtk_entry_get_text(entry);
2714 if (ghb_settings_get_boolean(ud->settings, "preset_type_folder"))
2716 if (count > MAX_NESTED_PRESET-1)
2718 count = MAX_NESTED_PRESET-1;
2721 dest = ghb_array_value_new(MAX_NESTED_PRESET);
2722 indices = ghb_preset_indices_from_path(presetsPlist, preset, &len);
2727 ptype = ghb_presets_get_type(presetsPlist, indices, len);
2728 if (ptype == PRESETS_CUSTOM)
2730 ghb_array_copy(dest, preset, count-1);
2733 ghb_array_append(dest, ghb_string_value_new(name));
2735 ghb_widget_to_setting(ud->settings, GTK_WIDGET(desc));
2736 if (ghb_settings_get_boolean(ud->settings, "preset_type_folder"))
2738 folder_save(ud, dest);
2742 // Construct the audio settings presets from the current audio list
2743 update_audio_presets(ud);
2744 settings_save(ud, dest);
2746 ghb_value_free(dest);
2751 preset_type_changed_cb(GtkWidget *widget, signal_user_data_t *ud)
2753 ghb_widget_to_setting(ud->settings, widget);
2757 preset_name_changed_cb(GtkWidget *entry, signal_user_data_t *ud)
2760 GValue *preset, *dest;
2763 preset = ghb_settings_get_value (ud->settings, "preset_selection");
2764 name = ghb_widget_string(entry);
2765 dest = ghb_value_dup(preset);
2766 count = ghb_array_len(dest);
2767 ghb_array_replace(dest, count-1, ghb_string_value_new(name));
2768 enforce_preset_type(ud, dest);
2769 ghb_value_free(dest);
2773 presets_restore_clicked_cb(GtkWidget *xwidget, signal_user_data_t *ud)
2777 g_debug("presets_restore_clicked_cb ()");
2778 // Reload only the standard presets
2779 ghb_presets_reload(ud);
2780 // Updating the presets list shuffles things around
2781 // need to make sure the proper preset is selected
2782 preset = ghb_settings_get_value (ud->settings, "preset");
2783 ghb_select_preset(ud->builder, preset);
2787 presets_remove_clicked_cb(GtkWidget *xwidget, signal_user_data_t *ud)
2789 GtkTreeView *treeview;
2790 GtkTreeSelection *selection;
2791 GtkTreeModel *store;
2794 GtkResponseType response;
2796 g_debug("presets_remove_clicked_cb ()");
2797 treeview = GTK_TREE_VIEW(GHB_WIDGET(ud->builder, "presets_list"));
2798 selection = gtk_tree_view_get_selection (treeview);
2799 if (gtk_tree_selection_get_selected(selection, &store, &iter))
2806 gtk_tree_model_get(store, &iter, 0, &preset, -1);
2807 path = gtk_tree_model_get_path(store, &iter);
2808 indices = gtk_tree_path_get_indices(path);
2809 len = gtk_tree_path_get_depth(path);
2811 folder = ghb_presets_get_folder(presetsPlist, indices, len);
2812 dialog = gtk_message_dialog_new(NULL, GTK_DIALOG_MODAL,
2813 GTK_MESSAGE_QUESTION, GTK_BUTTONS_YES_NO,
2814 "Confirm deletion of %s:\n\n%s",
2815 folder ? "folder" : "preset",
2817 response = gtk_dialog_run(GTK_DIALOG(dialog));
2818 gtk_widget_destroy (dialog);
2819 if (response == GTK_RESPONSE_YES)
2821 GtkTreeIter nextIter = iter;
2822 gboolean valid = TRUE;
2823 if (!gtk_tree_model_iter_next(store, &nextIter))
2825 if (!gtk_tree_model_iter_parent(store, &nextIter, &iter))
2830 // Remove the selected item
2831 // First unselect it so that selecting the new item works properly
2832 gtk_tree_selection_unselect_iter (selection, &iter);
2833 if (ghb_presets_remove(presetsPlist, indices, len))
2836 presets_list_remove(ud, indices, len);
2839 valid = gtk_tree_model_get_iter_first(store, &nextIter);
2842 gtk_tree_path_free(path);
2843 path = gtk_tree_model_get_path(store, &nextIter);
2844 indices = gtk_tree_path_get_indices(path);
2845 len = gtk_tree_path_get_depth(path);
2846 ghb_select_preset2(ud->builder, indices, len);
2850 gtk_tree_path_free(path);
2854 // controls where valid drop locations are
2856 presets_drag_motion_cb(
2858 GdkDragContext *ctx,
2862 signal_user_data_t *ud)
2864 GtkTreePath *path = NULL;
2865 GtkTreeViewDropPosition drop_pos;
2869 GtkTreeModel *model;
2870 GtkTreeSelection *select;
2871 gint src_ptype, dst_ptype;
2872 gboolean src_folder, dst_folder;
2874 gint tree_depth, ii;
2876 // Get the type of the object being dragged
2877 srctv = GTK_TREE_VIEW(gtk_drag_get_source_widget(ctx));
2878 select = gtk_tree_view_get_selection (srctv);
2879 gtk_tree_selection_get_selected (select, &model, &iter);
2880 path = gtk_tree_model_get_path (model, &iter);
2881 indices = gtk_tree_path_get_indices(path);
2882 len = gtk_tree_path_get_depth(path);
2884 preset = presets_get_dict(presetsPlist, indices, len);
2885 tree_depth = preset_tree_depth(preset);
2887 src_ptype = ghb_presets_get_type(presetsPlist, indices, len);
2888 src_folder = ghb_presets_get_folder(presetsPlist, indices, len);
2889 gtk_tree_path_free(path);
2891 if (src_folder && tree_depth == 1)
2894 // The rest checks that the destination is a valid position
2896 gtk_tree_view_get_dest_row_at_pos (tv, x, y, &path, &drop_pos);
2899 gdk_drag_status(ctx, 0, time);
2902 // Don't allow repositioning of builtin presets
2903 if (src_ptype != PRESETS_CUSTOM)
2905 gdk_drag_status(ctx, 0, time);
2909 len = gtk_tree_path_get_depth(path);
2910 if (len+tree_depth-1 >= MAX_NESTED_PRESET)
2912 if (drop_pos == GTK_TREE_VIEW_DROP_INTO_OR_BEFORE)
2913 drop_pos = GTK_TREE_VIEW_DROP_BEFORE;
2914 if (drop_pos == GTK_TREE_VIEW_DROP_INTO_OR_AFTER)
2915 drop_pos = GTK_TREE_VIEW_DROP_AFTER;
2917 for (ii = len+tree_depth-1; ii > MAX_NESTED_PRESET; ii--)
2918 gtk_tree_path_up(path);
2919 indices = gtk_tree_path_get_indices(path);
2920 len = gtk_tree_path_get_depth(path);
2921 dst_ptype = ghb_presets_get_type(presetsPlist, indices, len);
2922 dst_folder = ghb_presets_get_folder(presetsPlist, indices, len);
2923 // Don't allow mixing custom presets in the builtins
2924 if (dst_ptype != PRESETS_CUSTOM)
2926 gdk_drag_status(ctx, 0, time);
2930 // Only allow *drop into* for folders
2933 if (drop_pos == GTK_TREE_VIEW_DROP_INTO_OR_BEFORE)
2934 drop_pos = GTK_TREE_VIEW_DROP_BEFORE;
2935 if (drop_pos == GTK_TREE_VIEW_DROP_INTO_OR_AFTER)
2936 drop_pos = GTK_TREE_VIEW_DROP_AFTER;
2939 len = gtk_tree_path_get_depth(path);
2940 gtk_tree_view_set_drag_dest_row(tv, path, drop_pos);
2941 gtk_tree_path_free(path);
2942 gdk_drag_status(ctx, GDK_ACTION_MOVE, time);
2948 GtkTreeView *dstwidget,
2951 GtkSelectionData *selection_data,
2952 guint info, guint t,
2953 signal_user_data_t *ud)
2955 GtkTreePath *path = NULL;
2956 GtkTreeViewDropPosition drop_pos;
2957 GtkTreeIter dstiter, srciter;
2958 gint *dst_indices, dst_len, *src_indices, src_len;
2960 gboolean src_folder, dst_folder;
2962 GtkTreeModel *dstmodel = gtk_tree_view_get_model(dstwidget);
2964 g_debug("preset_drag_cb ()");
2965 // This doesn't work here for some reason...
2966 // gtk_tree_view_get_drag_dest_row(dstwidget, &path, &drop_pos);
2967 gtk_tree_view_get_dest_row_at_pos (dstwidget, x, y, &path, &drop_pos);
2968 // This little hack is needed because attempting to drop after
2969 // the last item gives us no path or drop_pos.
2974 n_children = gtk_tree_model_iter_n_children(dstmodel, NULL);
2977 drop_pos = GTK_TREE_VIEW_DROP_AFTER;
2978 path = gtk_tree_path_new_from_indices(n_children-1, -1);
2982 drop_pos = GTK_TREE_VIEW_DROP_BEFORE;
2983 path = gtk_tree_path_new_from_indices(0, -1);
2988 GtkTreeView *srcwidget;
2989 GtkTreeModel *srcmodel;
2990 GtkTreeSelection *select;
2991 GtkTreePath *srcpath = NULL;
2993 gint tree_depth, ii;
2995 srcwidget = GTK_TREE_VIEW(gtk_drag_get_source_widget(dc));
2996 select = gtk_tree_view_get_selection (srcwidget);
2997 gtk_tree_selection_get_selected (select, &srcmodel, &srciter);
2999 srcpath = gtk_tree_model_get_path (srcmodel, &srciter);
3000 src_indices = gtk_tree_path_get_indices(srcpath);
3001 src_len = gtk_tree_path_get_depth(srcpath);
3002 src_ptype = ghb_presets_get_type(presetsPlist, src_indices, src_len);
3003 src_folder = ghb_presets_get_folder(presetsPlist, src_indices, src_len);
3004 preset = ghb_value_dup(
3005 presets_get_dict(presetsPlist, src_indices, src_len));
3006 gtk_tree_path_free(srcpath);
3008 // Don't allow repositioning of builtin presets
3009 if (src_ptype != PRESETS_CUSTOM)
3012 tree_depth = preset_tree_depth(preset);
3013 if (src_folder && tree_depth == 1)
3016 dst_len = gtk_tree_path_get_depth(path);
3017 if (dst_len+tree_depth-1 >= MAX_NESTED_PRESET)
3019 if (drop_pos == GTK_TREE_VIEW_DROP_INTO_OR_BEFORE)
3020 drop_pos = GTK_TREE_VIEW_DROP_BEFORE;
3021 if (drop_pos == GTK_TREE_VIEW_DROP_INTO_OR_AFTER)
3022 drop_pos = GTK_TREE_VIEW_DROP_AFTER;
3025 for (ii = dst_len+tree_depth-1; ii > MAX_NESTED_PRESET; ii--)
3026 gtk_tree_path_up(path);
3027 dst_indices = gtk_tree_path_get_indices(path);
3028 dst_len = gtk_tree_path_get_depth(path);
3029 dst_folder = ghb_presets_get_folder(presetsPlist, dst_indices, dst_len);
3030 // Only allow *drop into* for folders
3033 if (drop_pos == GTK_TREE_VIEW_DROP_INTO_OR_BEFORE)
3034 drop_pos = GTK_TREE_VIEW_DROP_BEFORE;
3035 if (drop_pos == GTK_TREE_VIEW_DROP_INTO_OR_AFTER)
3036 drop_pos = GTK_TREE_VIEW_DROP_AFTER;
3038 if (gtk_tree_model_get_iter (dstmodel, &dstiter, path))
3041 GtkTreePath *dstpath = NULL;
3045 case GTK_TREE_VIEW_DROP_BEFORE:
3046 gtk_tree_store_insert_before(GTK_TREE_STORE (dstmodel),
3047 &iter, NULL, &dstiter);
3050 case GTK_TREE_VIEW_DROP_INTO_OR_BEFORE:
3051 gtk_tree_store_insert(GTK_TREE_STORE (dstmodel),
3052 &iter, &dstiter, 0);
3055 case GTK_TREE_VIEW_DROP_AFTER:
3056 gtk_tree_store_insert_after(GTK_TREE_STORE (dstmodel),
3057 &iter, NULL, &dstiter);
3060 case GTK_TREE_VIEW_DROP_INTO_OR_AFTER:
3061 gtk_tree_store_insert_after(GTK_TREE_STORE (dstmodel),
3062 &iter, &dstiter, 0);
3069 dstpath = gtk_tree_model_get_path (dstmodel, &iter);
3070 dst_indices = gtk_tree_path_get_indices(dstpath);
3071 dst_len = gtk_tree_path_get_depth(dstpath);
3072 ghb_presets_insert(presetsPlist, preset, dst_indices, dst_len);
3073 gtk_tree_path_free(dstpath);
3075 srcpath = gtk_tree_model_get_path (srcmodel, &srciter);
3076 src_indices = gtk_tree_path_get_indices(srcpath);
3077 src_len = gtk_tree_path_get_depth(srcpath);
3078 ghb_presets_remove(presetsPlist, src_indices, src_len);
3079 gtk_tree_path_free(srcpath);
3081 gtk_tree_store_remove (GTK_TREE_STORE (srcmodel), &srciter);
3083 dstpath = gtk_tree_model_get_path (dstmodel, &iter);
3084 dst_indices = gtk_tree_path_get_indices(dstpath);
3085 dst_len = gtk_tree_path_get_depth(dstpath);
3086 presets_list_update_item(ud, dst_indices, dst_len);
3087 gtk_tree_path_free(dstpath);
3091 gtk_tree_path_free(path);
3096 preset_update_title_deps(signal_user_data_t *ud, ghb_title_info_t *tinfo)
3100 ghb_ui_update(ud, "scale_width",
3101 ghb_int64_value(tinfo->width - tinfo->crop[2] - tinfo->crop[3]));
3102 // If anamorphic or keep_aspect, the hight will be automatically calculated
3103 gboolean keep_aspect, anamorphic;
3104 keep_aspect = ghb_settings_get_boolean(ud->settings, "PictureKeepRatio");
3105 anamorphic = ghb_settings_get_boolean(ud->settings, "anamorphic");
3106 if (!(keep_aspect || anamorphic))
3108 ghb_ui_update(ud, "scale_height",
3109 ghb_int64_value(tinfo->height - tinfo->crop[0] - tinfo->crop[1]));
3112 // Set the limits of cropping. hb_set_anamorphic_size crashes if
3113 // you pass it a cropped width or height == 0.
3115 bound = tinfo->height / 2 - 2;
3116 widget = GHB_WIDGET (ud->builder, "PictureTopCrop");
3117 gtk_spin_button_set_range (GTK_SPIN_BUTTON(widget), 0, bound);
3118 widget = GHB_WIDGET (ud->builder, "PictureBottomCrop");
3119 gtk_spin_button_set_range (GTK_SPIN_BUTTON(widget), 0, bound);
3120 bound = tinfo->width / 2 - 2;
3121 widget = GHB_WIDGET (ud->builder, "PictureLeftCrop");
3122 gtk_spin_button_set_range (GTK_SPIN_BUTTON(widget), 0, bound);
3123 widget = GHB_WIDGET (ud->builder, "PictureRightCrop");
3124 gtk_spin_button_set_range (GTK_SPIN_BUTTON(widget), 0, bound);
3125 if (ghb_settings_get_boolean(ud->settings, "PictureAutoCrop"))
3127 ghb_ui_update(ud, "PictureTopCrop", ghb_int64_value(tinfo->crop[0]));
3128 ghb_ui_update(ud, "PictureBottomCrop", ghb_int64_value(tinfo->crop[1]));
3129 ghb_ui_update(ud, "PictureLeftCrop", ghb_int64_value(tinfo->crop[2]));
3130 ghb_ui_update(ud, "PictureRightCrop", ghb_int64_value(tinfo->crop[3]));
3135 presets_list_selection_changed_cb(GtkTreeSelection *selection, signal_user_data_t *ud)
3137 GtkTreeModel *store;
3139 ghb_title_info_t tinfo;
3142 g_debug("presets_list_selection_changed_cb ()");
3143 widget = GHB_WIDGET (ud->builder, "presets_remove");
3144 if (gtk_tree_selection_get_selected(selection, &store, &iter))
3146 GtkTreePath *treepath;
3151 treepath = gtk_tree_model_get_path(store, &iter);
3152 indices = gtk_tree_path_get_indices(treepath);
3153 len = gtk_tree_path_get_depth(treepath);
3155 path = preset_path_from_indices(presetsPlist, indices, len);
3156 ghb_settings_take_value(ud->settings, "preset_selection", path);
3158 folder = ghb_presets_get_folder(presetsPlist, indices, len);
3161 ud->dont_clear_presets = TRUE;
3162 // Temporarily set the video_quality range to (0,100)
3163 // This is needed so the video_quality value does not get
3164 // truncated when set. The range will be readjusted below
3165 GtkWidget *qp = GHB_WIDGET(ud->builder, "VideoQualitySlider");
3166 gtk_range_set_range (GTK_RANGE(qp), 0, 100);
3167 gtk_scale_set_digits(GTK_SCALE(qp), 3);
3168 // Clear the audio list prior to changing the preset. Existing
3169 // audio can cause the container extension to be automatically
3170 // changed when it shouldn't be
3171 ghb_clear_audio_list(ud);
3172 ghb_set_preset_from_indices(ud, indices, len);
3173 gtk_tree_path_free(treepath);
3175 titleindex = ghb_settings_combo_int(ud->settings, "title");
3176 ghb_set_pref_audio(titleindex, ud);
3177 ghb_settings_set_boolean(ud->settings, "preset_modified", FALSE);
3178 ud->dont_clear_presets = FALSE;
3179 if (ghb_get_title_info (&tinfo, titleindex))
3181 preset_update_title_deps(ud, &tinfo);
3183 ghb_set_scale (ud, GHB_SCALE_KEEP_NONE);
3185 gdouble vqmin, vqmax, step, page;
3187 ghb_vquality_range(ud, &vqmin, &vqmax, &step, &page, &digits);
3188 gtk_range_set_range (GTK_RANGE(qp), vqmin, vqmax);
3189 gtk_range_set_increments (GTK_RANGE(qp), step, page);
3190 gtk_scale_set_digits(GTK_SCALE(qp), digits);
3194 GtkWidget *crop_widget;
3195 crop[0] = ghb_settings_get_int(ud->settings, "PictureTopCrop");
3196 crop[1] = ghb_settings_get_int(ud->settings, "PictureBottomCrop");
3197 crop[2] = ghb_settings_get_int(ud->settings, "PictureLeftCrop");
3198 crop[3] = ghb_settings_get_int(ud->settings, "PictureRightCrop");
3199 crop_widget = GHB_WIDGET (ud->builder, "crop_values");
3200 text = g_strdup_printf("%d:%d:%d:%d",
3201 crop[0], crop[1], crop[2], crop[3]);
3202 gtk_label_set_text (GTK_LABEL(crop_widget), text);
3205 gtk_widget_set_sensitive(widget, TRUE);
3209 g_debug("No selection??? Perhaps unselected.");
3210 gtk_widget_set_sensitive(widget, FALSE);
3215 ghb_clear_presets_selection(signal_user_data_t *ud)
3217 GtkTreeView *treeview;
3218 GtkTreeSelection *selection;
3220 if (ud->dont_clear_presets) return;
3221 g_debug("ghb_clear_presets_selection()");
3222 treeview = GTK_TREE_VIEW(GHB_WIDGET(ud->builder, "presets_list"));
3223 selection = gtk_tree_view_get_selection (treeview);
3224 gtk_tree_selection_unselect_all (selection);
3225 ghb_settings_set_boolean(ud->settings, "preset_modified", TRUE);
3229 presets_frame_size_allocate_cb(GtkWidget *widget, GtkAllocation *allocation, signal_user_data_t *ud)
3231 GtkTreeView *treeview;
3232 GtkTreeSelection *selection;
3233 GtkTreeModel *store;
3236 treeview = GTK_TREE_VIEW(GHB_WIDGET(ud->builder, "presets_list"));
3237 selection = gtk_tree_view_get_selection(treeview);
3238 if (gtk_tree_selection_get_selected(selection, &store, &iter))
3241 path = gtk_tree_model_get_path (store, &iter);
3242 // Make the parent visible in scroll window if it is not.
3243 gtk_tree_view_scroll_to_cell (treeview, path, NULL, FALSE, 0, 0);
3244 gtk_tree_path_free(path);
3249 presets_default_clicked_cb(GtkWidget *xwidget, signal_user_data_t *ud)
3254 g_debug("presets_default_clicked_cb ()");
3255 preset = ghb_settings_get_value(ud->settings, "preset_selection");
3256 indices = ghb_preset_indices_from_path(presetsPlist, preset, &len);
3259 if (!ghb_presets_get_folder(presetsPlist, indices, len))
3261 ghb_presets_list_clear_default(ud);
3262 presets_set_default(indices, len);
3263 ghb_presets_list_default(ud);