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)
14 #include <sys/types.h>
19 #include <glib-object.h>
20 #include <glib/gstdio.h>
25 #include "callbacks.h"
26 #include "audiohandler.h"
27 #include "subtitlehandler.h"
28 #include "hb-backend.h"
30 #include "resources.h"
35 #define MAX_NESTED_PRESET 3
43 static GValue *presetsPlist = NULL;
44 static GValue *internalPlist = NULL;
45 static GValue *prefsPlist = NULL;
46 static gboolean prefs_modified = FALSE;
48 static const GValue* preset_dict_get_value(GValue *dict, const gchar *key);
49 static void store_plist(GValue *plist, const gchar *name);
50 static void store_presets(void);
51 static void store_prefs(void);
54 preset_path_cmp(gint *indices1, gint len1, gint *indices2, gint len2)
57 for (ii = 0; ii < len1 && ii < len2; ii++)
59 if (indices1[ii] != indices2[ii])
60 return indices1[ii] - indices2[ii];
65 // This only handle limited depth
67 ghb_tree_path_new_from_indices(gint *indices, gint len)
72 return gtk_tree_path_new_from_indices(
75 return gtk_tree_path_new_from_indices(
76 indices[0], indices[1], -1);
78 return gtk_tree_path_new_from_indices(
79 indices[0], indices[1], indices[2], -1);
81 return gtk_tree_path_new_from_indices(
82 indices[0], indices[1], indices[2], indices[3], -1);
84 return gtk_tree_path_new_from_indices(
85 indices[0], indices[1], indices[2], indices[3], indices[4], -1);
92 ghb_parse_preset_path(const gchar *path)
98 preset = ghb_array_value_new(MAX_NESTED_PRESET);
99 split = g_strsplit(path, "#", MAX_NESTED_PRESET);
100 for (ii = 0; split[ii] != NULL; ii++)
102 ghb_array_append(preset, ghb_string_value_new(split[ii]));
109 preset_path_from_indices(GValue *presets, gint *indices, gint len)
114 g_debug("preset_path_from_indices");
115 path = ghb_array_value_new(MAX_NESTED_PRESET);
116 for (ii = 0; ii < len; ii++)
122 count = ghb_array_len(presets);
123 if (indices[ii] >= count) break;
124 dict = ghb_array_get_nth(presets, indices[ii]);
125 name = ghb_dict_lookup(dict, "PresetName");
127 ghb_array_append(path, ghb_value_dup(name));
128 folder = ghb_value_boolean(preset_dict_get_value(dict, "Folder"));
131 presets = ghb_dict_lookup(dict, "ChildrenArray");
137 ghb_preset_path_string(const GValue *path)
144 gstr = g_string_new("");
147 count = ghb_array_len(path);
148 for (ii = 0; ii < count; ii++)
150 val = ghb_array_get_nth(path, ii);
151 str = ghb_value_string(val);
152 g_string_append(gstr, str);
154 g_string_append(gstr, "->");
158 str = g_string_free(gstr, FALSE);
163 dump_preset_path(const gchar *msg, const GValue *path)
168 debug_show_type (G_VALUE_TYPE(path));
169 str = ghb_preset_path_string(path);
170 g_message("%s path: (%s)", msg, str);
175 dump_preset_indices(const gchar *msg, gint *indices, gint len)
179 g_message("%s indices: len %d", msg, len);
180 for (ii = 0; ii < len; ii++)
182 printf("%d ", indices[ii]);
189 preset_path_cmp(const GValue *path1, const GValue *path2)
196 count = ghb_array_len(path1);
197 ii = ghb_array_len(path2);
200 for (ii = 0; ii < count; ii++)
202 val = ghb_array_get_nth(path1, ii);
203 str1 = ghb_value_string(val);
204 val = ghb_array_get_nth(path2, ii);
205 str2 = ghb_value_string(val);
206 result = strcmp(str1, str2);
217 presets_get_dict(GValue *presets, gint *indices, gint len)
219 gint ii, count, folder;
222 g_debug("presets_get_dict ()");
223 for (ii = 0; ii < len; ii++)
225 count = ghb_array_len(presets);
226 if (indices[ii] >= count) return NULL;
227 dict = ghb_array_get_nth(presets, indices[ii]);
230 folder = ghb_value_boolean(preset_dict_get_value(dict, "Folder"));
233 presets = ghb_dict_lookup(dict, "ChildrenArray");
242 presets_get_folder(GValue *presets, gint *indices, gint len)
244 gint ii, count, folder;
247 g_debug("presets_get_folder ()");
248 for (ii = 0; ii < len; ii++)
250 count = ghb_array_len(presets);
251 if (indices[ii] >= count) return NULL;
252 dict = ghb_array_get_nth(presets, indices[ii]);
253 folder = ghb_value_boolean(preset_dict_get_value(dict, "Folder"));
256 presets = ghb_dict_lookup(dict, "ChildrenArray");
264 plist_get_dict(GValue *presets, const gchar *name)
266 if (presets == NULL || name == NULL) return NULL;
267 return ghb_dict_lookup(presets, name);
271 preset_get_name(GValue *dict)
273 return g_value_get_string(preset_dict_get_value(dict, "PresetName"));
277 preset_folder_is_open(GValue *dict)
281 gval = preset_dict_get_value(dict, "FolderOpen");
283 return g_value_get_boolean(gval);
288 ghb_preset_folder(GValue *dict)
290 return ghb_value_int(preset_dict_get_value(dict, "Folder"));
294 ghb_preset_type(GValue *dict)
296 return ghb_value_int(preset_dict_get_value(dict, "Type"));
300 presets_remove_nth(GValue *presets, gint pos)
305 if (presets == NULL || pos < 0) return;
306 count = ghb_array_len(presets);
307 if (pos >= count) return;
308 dict = ghb_array_get_nth(presets, pos);
309 ghb_array_remove(presets, pos);
310 ghb_value_free(dict);
319 GValue *folder = NULL;
321 folder = presets_get_folder(presets, indices, len-1);
323 presets_remove_nth(folder, indices[len-1]);
326 g_warning("ghb_presets_remove (): internal preset lookup error");
339 GValue *folder = NULL;
341 folder = presets_get_folder(presets, indices, len-1);
343 ghb_array_replace(folder, indices[len-1], dict);
346 g_warning("ghb_presets_replace (): internal preset lookup error");
357 GValue *folder = NULL;
359 folder = presets_get_folder(presets, indices, len-1);
361 ghb_array_insert(folder, indices[len-1], dict);
364 g_warning("ghb_presets_insert (): internal preset lookup error");
369 presets_find_element(GValue *presets, const gchar *name)
374 g_debug("presets_find_element () (%s)", name);
375 if (presets == NULL || name == NULL) return -1;
376 count = ghb_array_len(presets);
377 for (ii = 0; ii < count; ii++)
380 dict = ghb_array_get_nth(presets, ii);
381 str = preset_get_name(dict);
382 if (strcmp(name, str) == 0)
391 single_find_pos(GValue *presets, const gchar *name, gint type)
394 gint count, ii, ptype, last;
396 if (presets == NULL || name == NULL) return -1;
397 last = count = ghb_array_len(presets);
398 for (ii = 0; ii < count; ii++)
401 dict = ghb_array_get_nth(presets, ii);
402 str = preset_get_name(dict);
403 ptype = ghb_value_int(preset_dict_get_value(dict, "Type"));
404 if (strcasecmp(name, str) <= 0 && ptype == type)
415 presets_find_pos(const GValue *path, gint type, gint *len)
421 gint *indices = NULL;
425 g_debug("presets_find_pos () ");
426 nested = presetsPlist;
427 count = ghb_array_len(path);
428 indices = g_malloc(MAX_NESTED_PRESET * sizeof(gint));
429 for (ii = 0; ii < count-1; ii++)
431 val = ghb_array_get_nth(path, ii);
432 name = g_value_get_string(val);
433 indices[ii] = presets_find_element(nested, name);
434 if (indices[ii] == -1) return NULL;
435 dict = ghb_array_get_nth(nested, indices[ii]);
436 folder = ghb_value_boolean(preset_dict_get_value(dict, "Folder"));
440 nested = ghb_dict_lookup(dict, "ChildrenArray");
446 name = g_value_get_string(ghb_array_get_nth(path, count-1));
447 indices[ii] = single_find_pos(nested, name, type);
455 preset_tree_depth(GValue *dict)
459 folder = ghb_value_boolean(preset_dict_get_value(dict, "Folder"));
466 presets = ghb_dict_lookup(dict, "ChildrenArray");
467 count = ghb_array_len(presets);
468 for (ii = 0; ii < count; ii++)
472 dict = ghb_array_get_nth(presets, ii);
473 tmp = preset_tree_depth(dict);
474 depth = MAX(depth, tmp);
485 preset_is_default(GValue *dict)
489 val = preset_dict_get_value(dict, "Default");
490 return ghb_value_boolean(val);
494 presets_clear_default(GValue *presets)
498 count = ghb_array_len(presets);
499 for (ii = 0; ii < count; ii++)
504 dict = ghb_array_get_nth(presets, ii);
505 folder = ghb_value_boolean(preset_dict_get_value(dict, "Folder"));
510 nested = ghb_dict_lookup(dict, "ChildrenArray");
511 presets_clear_default(nested);
515 if (preset_is_default(dict))
517 ghb_dict_insert(dict, g_strdup("Default"),
518 ghb_boolean_value_new(FALSE));
525 presets_customize(GValue *presets)
529 count = ghb_array_len(presets);
530 for (ii = 0; ii < count; ii++)
536 dict = ghb_array_get_nth(presets, ii);
538 ptype = ghb_value_int(preset_dict_get_value(dict, "Type"));
539 if (ptype != PRESETS_CUSTOM)
541 ghb_dict_insert(dict, g_strdup("Type"),
542 ghb_int64_value_new(PRESETS_CUSTOM));
544 folder = ghb_value_boolean(preset_dict_get_value(dict, "Folder"));
549 nested = ghb_dict_lookup(dict, "ChildrenArray");
550 presets_customize(nested);
556 presets_find_default2(GValue *presets, gint *len)
561 count = ghb_array_len(presets);
562 for (ii = 0; ii < count; ii++)
567 dict = ghb_array_get_nth(presets, ii);
568 folder = ghb_value_boolean(preset_dict_get_value(dict, "Folder"));
574 nested = ghb_dict_lookup(dict, "ChildrenArray");
576 indices = presets_find_default2(nested, len);
587 if (preset_is_default(dict))
589 indices = g_malloc(MAX_NESTED_PRESET * sizeof(gint));
600 presets_find_default(GValue *presets, gint *len)
603 return presets_find_default2(presets, len);
607 ghb_preset_indices_from_path(
615 gint *indices = NULL;
620 g_debug("ghb_preset_indices_from_path () ");
622 count = ghb_array_len(path);
624 indices = g_malloc(MAX_NESTED_PRESET * sizeof(gint));
626 for (ii = 0; ii < count; ii++)
628 val = ghb_array_get_nth(path, ii);
629 name = g_value_get_string(val);
630 indices[ii] = presets_find_element(nested, name);
631 if (indices[ii] == -1)
638 dict = ghb_array_get_nth(nested, indices[ii]);
639 folder = ghb_value_boolean(preset_dict_get_value(dict, "Folder"));
645 nested = ghb_dict_lookup(dict, "ChildrenArray");
653 ghb_presets_get_type(
661 dict = presets_get_dict(presets, indices, len);
664 type = ghb_preset_type(dict);
668 g_warning("ghb_presets_get_type (): internal preset lookup error");
674 ghb_presets_get_folder(
680 gboolean folder = FALSE;
682 dict = presets_get_dict(presets, indices, len);
685 folder = ghb_preset_folder(dict);
689 g_warning("ghb_presets_get_folder (): internal preset lookup error");
695 presets_set_default(gint *indices, gint len)
699 g_debug("presets_set_default ()");
700 presets_clear_default(presetsPlist);
701 dict = presets_get_dict(presetsPlist, indices, len);
704 ghb_dict_insert(dict, g_strdup("Default"), ghb_boolean_value_new(TRUE));
710 presets_set_folder_open(gboolean open, gint *indices, gint len)
714 g_debug("presets_set_folder_open ()");
715 dict = presets_get_dict(presetsPlist, indices, len);
718 ghb_dict_insert(dict, g_strdup("FolderOpen"),
719 ghb_boolean_value_new(open));
723 // Used for sorting dictionaries.
725 key_cmp(gconstpointer a, gconstpointer b)
727 gchar *stra = (gchar*)a;
728 gchar *strb = (gchar*)b;
730 return strcmp(stra, strb);
734 preset_dict_get_value(GValue *dict, const gchar *key)
736 const GValue *gval = NULL;
740 gval = ghb_dict_lookup(dict, key);
742 if (internalPlist == NULL) return NULL;
745 dict = plist_get_dict(internalPlist, "Presets");
746 if (dict == NULL) return NULL;
747 gval = ghb_dict_lookup(dict, key);
753 ghb_presets_get_description(GValue *pdict)
757 if (pdict == NULL) return NULL;
758 desc = g_value_get_string(
759 preset_dict_get_value(pdict, "PresetDescription"));
760 if (desc[0] == 0) return NULL;
765 static void init_settings_from_dict(
766 GValue *dest, GValue *internal, GValue *dict);
769 init_settings_from_array(
777 count = ghb_array_len(array);
778 // The first element of the internal version is always the
779 // template for the allowed values
780 gval = ghb_array_get_nth(internal, 0);
781 for (ii = 0; ii < count; ii++)
784 val = ghb_array_get_nth(array, ii);
787 if (G_VALUE_TYPE(gval) == ghb_dict_get_type())
790 new_dict = ghb_dict_value_new();
791 ghb_array_append(dest, new_dict);
792 if (G_VALUE_TYPE(val) == ghb_dict_get_type())
793 init_settings_from_dict(new_dict, gval, val);
795 init_settings_from_dict(new_dict, gval, gval);
797 else if (G_VALUE_TYPE(gval) == ghb_array_get_type())
800 new_array = ghb_array_value_new(8);
801 ghb_array_append(dest, new_array);
802 if (G_VALUE_TYPE(val) == ghb_array_get_type())
803 init_settings_from_array(new_array, gval, val);
805 init_settings_from_array(new_array, gval, gval);
809 ghb_array_append(dest, val);
815 init_settings_from_dict(
824 ghb_dict_iter_init(&iter, internal);
825 // middle (void*) cast prevents gcc warning "defreferencing type-punned
826 // pointer will break strict-aliasing rules"
827 while (g_hash_table_iter_next(
828 &iter, (gpointer*)(void*)&key, (gpointer*)(void*)&gval))
832 val = ghb_dict_lookup(dict, key);
835 if (G_VALUE_TYPE(gval) == ghb_dict_get_type())
838 new_dict = ghb_dict_value_new();
839 ghb_settings_take_value(dest, key, new_dict);
840 if (G_VALUE_TYPE(val) == ghb_dict_get_type())
841 init_settings_from_dict(new_dict, gval, val);
843 init_settings_from_dict(new_dict, gval, gval);
845 else if (G_VALUE_TYPE(gval) == ghb_array_get_type())
848 new_array = ghb_array_value_new(8);
849 ghb_settings_take_value(dest, key, new_array);
850 if (G_VALUE_TYPE(val) == ghb_array_get_type())
851 init_settings_from_array(new_array, gval, val);
853 init_settings_from_array(new_array, gval, gval);
858 ghb_settings_set_value(dest, key, val);
865 signal_user_data_t *ud,
873 ghb_dict_iter_init(&iter, internal);
874 // middle (void*) cast prevents gcc warning "defreferencing type-punned
875 // pointer will break strict-aliasing rules"
876 while (g_hash_table_iter_next(
877 &iter, (gpointer*)(void*)&key, (gpointer*)(void*)&gval))
881 val = ghb_dict_lookup(dict, key);
884 ghb_ui_update(ud, key, val);
889 preset_to_ui(signal_user_data_t *ud, GValue *dict)
891 g_debug("preset_to_ui()\n");
892 // Initialize the ui from presets file.
893 GValue *internal, *hidden;
895 // Get key list from internal default presets. This way we do not
896 // load any unknown keys.
897 if (internalPlist == NULL) return;
898 internal = plist_get_dict(internalPlist, "Presets");
899 hidden = plist_get_dict(internalPlist, "XlatPresets");
900 // Setting a ui widget will cause the corresponding setting
901 // to be set, but it also triggers a callback that can
902 // have the side effect of using other settings values
903 // that have not yet been set. So set *all* settings first
904 // then update the ui.
905 init_settings_from_dict(ud->settings, internal, dict);
906 init_settings_from_dict(ud->settings, hidden, dict);
907 init_ui_from_dict(ud, internal, dict);
908 init_ui_from_dict(ud, hidden, dict);
915 val = ghb_dict_lookup(dict, "PictureDecombDeinterlace");
918 dd = ghb_value_boolean(val);
919 ghb_ui_update(ud, "PictureDeinterlaceDecomb", ghb_boolean_value(!dd));
925 ghb_settings_to_ui(signal_user_data_t *ud, GValue *dict)
927 init_ui_from_dict(ud, dict, dict);
930 static GValue *current_preset = NULL;
933 ghb_preset_is_custom()
937 if (current_preset == NULL) return FALSE;
938 val = preset_dict_get_value(current_preset, "Type");
939 return (ghb_value_int(val) == 1);
943 ghb_set_preset_from_indices(signal_user_data_t *ud, gint *indices, gint len)
946 gint fallback[2] = {0, -1};
949 dict = presets_get_dict(presetsPlist, indices, len);
954 dict = presets_get_dict(presetsPlist, indices, len);
958 preset_to_ui(ud, NULL);
959 current_preset = NULL;
966 current_preset = dict;
967 folder = ghb_value_boolean(preset_dict_get_value(dict, "Folder"));
969 preset_to_ui(ud, NULL);
971 preset_to_ui(ud, dict);
972 path = preset_path_from_indices(presetsPlist, indices, len);
973 ghb_settings_set_value(ud->settings, "preset", path);
974 ghb_value_free(path);
979 curr_preset_get_value(const gchar *key)
981 if (current_preset == NULL) return NULL;
982 return preset_dict_get_value(current_preset, key);
986 ghb_update_from_preset(
987 signal_user_data_t *ud,
992 g_debug("ghb_update_from_preset() %s", key);
993 gval = curr_preset_get_value(key);
996 ghb_ui_update(ud, key, gval);
1002 GtkBuilder *builder,
1006 GtkTreeView *treeview;
1007 GtkTreeSelection *selection;
1008 GtkTreeModel *store;
1012 g_debug("ghb_select_preset2()");
1013 treeview = GTK_TREE_VIEW(GHB_WIDGET(builder, "presets_list"));
1014 selection = gtk_tree_view_get_selection (treeview);
1015 store = gtk_tree_view_get_model (treeview);
1016 path = ghb_tree_path_new_from_indices(indices, len);
1019 if (gtk_tree_model_get_iter(store, &iter, path))
1021 gtk_tree_selection_select_iter (selection, &iter);
1025 if (gtk_tree_model_get_iter_first(store, &iter))
1026 gtk_tree_selection_select_iter (selection, &iter);
1028 gtk_tree_path_free(path);
1033 ghb_select_preset(GtkBuilder *builder, const GValue *path)
1037 g_debug("ghb_select_preset()");
1038 indices = ghb_preset_indices_from_path(presetsPlist, path, &len);
1041 ghb_select_preset2(builder, indices, len);
1047 ghb_select_default_preset(GtkBuilder *builder)
1051 g_debug("ghb_select_default_preset()");
1052 indices = presets_find_default(presetsPlist, &len);
1055 ghb_select_preset2(builder, indices, len);
1061 ghb_get_user_config_dir(gchar *subdir)
1066 dir = g_get_user_config_dir();
1067 if (!g_file_test(dir, G_FILE_TEST_IS_DIR))
1069 dir = g_get_home_dir();
1070 config = g_strdup_printf ("%s/.ghb", dir);
1071 if (!g_file_test(config, G_FILE_TEST_IS_DIR))
1072 g_mkdir (config, 0755);
1076 config = g_strdup_printf ("%s/ghb", dir);
1077 if (!g_file_test(config, G_FILE_TEST_IS_DIR))
1078 g_mkdir (config, 0755);
1085 split = g_strsplit(subdir, G_DIR_SEPARATOR_S, -1);
1086 for (ii = 0; split[ii] != NULL; ii++)
1090 tmp = g_strdup_printf ("%s/%s", config, split[ii]);
1093 if (!g_file_test(config, G_FILE_TEST_IS_DIR))
1094 g_mkdir (config, 0755);
1101 store_plist(GValue *plist, const gchar *name)
1103 gchar *config, *path;
1106 config = ghb_get_user_config_dir(NULL);
1107 path = g_strdup_printf ("%s/%s", config, name);
1108 file = g_fopen(path, "w");
1111 ghb_plist_write(file, plist);
1116 load_plist(const gchar *name)
1118 gchar *config, *path;
1119 GValue *plist = NULL;
1121 config = ghb_get_user_config_dir(NULL);
1122 path = g_strdup_printf ("%s/%s", config, name);
1123 if (g_file_test(path, G_FILE_TEST_IS_REGULAR))
1125 plist = ghb_plist_parse_file(path);
1133 ghb_lock_file(const gchar *name)
1135 #if !defined(_WIN32)
1136 gchar *config, *path;
1139 config = ghb_get_user_config_dir(NULL);
1140 path = g_strdup_printf ("%s/%s", config, name);
1141 fd = open(path, O_RDWR|O_CREAT, S_IRUSR|S_IWUSR);
1143 lock = lockf(fd, F_TLOCK, 0);
1155 remove_plist(const gchar *name)
1157 gchar *config, *path;
1159 config = ghb_get_user_config_dir(NULL);
1160 path = g_strdup_printf ("%s/%s", config, name);
1161 if (g_file_test(path, G_FILE_TEST_IS_REGULAR))
1169 static gboolean prefs_initializing = FALSE;
1172 ghb_prefs_to_ui(signal_user_data_t *ud)
1177 GValue *internal, *dict;
1178 GHashTableIter iter;
1181 g_debug("ghb_prefs_to_ui");
1182 prefs_initializing = TRUE;
1184 // Setting a ui widget will cause the corresponding setting
1185 // to be set, but it also triggers a callback that can
1186 // have the side effect of using other settings values
1187 // that have not yet been set. So set *all* settings first
1188 // then update the ui.
1189 internal = plist_get_dict(internalPlist, "Initialization");
1190 ghb_dict_iter_init(&iter, internal);
1191 // middle (void*) cast prevents gcc warning "defreferencing type-punned
1192 // pointer will break strict-aliasing rules"
1193 while (g_hash_table_iter_next(
1194 &iter, (gpointer*)(void*)&key, (gpointer*)(void*)&gval))
1196 ghb_ui_update(ud, key, gval);
1199 dict = plist_get_dict(prefsPlist, "Preferences");
1200 internal = plist_get_dict(internalPlist, "Preferences");
1201 ghb_dict_iter_init(&iter, internal);
1202 // middle (void*) cast prevents gcc warning "defreferencing type-punned
1203 // pointer will break strict-aliasing rules"
1204 while (g_hash_table_iter_next(
1205 &iter, (gpointer*)(void*)&key, (gpointer*)(void*)&gval))
1207 const GValue *value = NULL;
1209 value = ghb_dict_lookup(dict, key);
1212 ghb_settings_set_value(ud->settings, key, value);
1214 internal = plist_get_dict(internalPlist, "Preferences");
1215 ghb_dict_iter_init(&iter, internal);
1216 // middle (void*) cast prevents gcc warning "defreferencing type-punned
1217 // pointer will break strict-aliasing rules"
1218 while (g_hash_table_iter_next(
1219 &iter, (gpointer*)(void*)&key, (gpointer*)(void*)&gval))
1221 const GValue *value = NULL;
1223 value = ghb_dict_lookup(dict, key);
1226 ghb_ui_update(ud, key, value);
1229 val = ghb_settings_get_value(ud->settings, "show_presets");
1230 ghb_ui_update(ud, "show_presets", val);
1231 if (ghb_settings_get_boolean(ud->settings, "hbfd_feature"))
1234 val = ghb_settings_get_value(ud->settings, "hbfd");
1235 ghb_ui_update(ud, "hbfd", val);
1236 action = GHB_ACTION (ud->builder, "hbfd");
1237 gtk_action_set_visible(action, TRUE);
1241 ghb_ui_update(ud, "hbfd", ghb_int64_value(0));
1243 gval = ghb_settings_get_value(ud->settings, "default_source");
1244 ghb_settings_set_value (ud->settings, "source", gval);
1246 str = ghb_settings_get_string(ud->settings, "destination_dir");
1247 ghb_ui_update(ud, "dest_dir", ghb_string_value(str));
1249 gchar *file = g_strdup_printf ("new_video.mp4");
1250 ghb_ui_update(ud, "dest_file", ghb_string_value(file));
1254 prefs_initializing = FALSE;
1258 ghb_prefs_save(GValue *settings)
1262 GHashTableIter iter;
1264 const GValue *value;
1266 if (prefs_initializing) return;
1267 dict = plist_get_dict(internalPlist, "Preferences");
1268 if (dict == NULL) return;
1269 pref_dict = plist_get_dict(prefsPlist, "Preferences");
1270 if (pref_dict == NULL) return;
1271 ghb_dict_iter_init(&iter, dict);
1272 // middle (void*) cast prevents gcc warning "defreferencing type-punned
1273 // pointer will break strict-aliasing rules"
1274 while (g_hash_table_iter_next(
1275 &iter, (gpointer*)(void*)&key, (gpointer*)(void*)&value))
1277 value = ghb_settings_get_value(settings, key);
1280 ghb_dict_insert(pref_dict, g_strdup(key), ghb_value_dup(value));
1284 prefs_modified = FALSE;
1288 ghb_pref_set(GValue *settings, const gchar *key)
1290 const GValue *value, *value2;
1292 if (prefs_initializing) return;
1293 value = ghb_settings_get_value(settings, key);
1297 dict = plist_get_dict(prefsPlist, "Preferences");
1298 if (dict == NULL) return;
1299 value2 = ghb_dict_lookup(dict, key);
1300 if (ghb_value_cmp(value, value2) != 0)
1302 ghb_dict_insert(dict, g_strdup(key), ghb_value_dup(value));
1304 prefs_modified = TRUE;
1310 ghb_pref_save(GValue *settings, const gchar *key)
1312 const GValue *value, *value2;
1314 if (prefs_initializing) return;
1315 value = ghb_settings_get_value(settings, key);
1319 dict = plist_get_dict(prefsPlist, "Preferences");
1320 if (dict == NULL) return;
1321 value2 = ghb_dict_lookup(dict, key);
1322 if (ghb_value_cmp(value, value2) != 0)
1324 ghb_dict_insert(dict, g_strdup(key), ghb_value_dup(value));
1326 prefs_modified = FALSE;
1332 ghb_prefs_store(void)
1337 prefs_modified = FALSE;
1342 ghb_settings_init(signal_user_data_t *ud)
1345 GHashTableIter iter;
1350 g_debug("ghb_settings_init");
1351 prefs_initializing = TRUE;
1353 internalPlist = ghb_resource_get("internal-defaults");
1354 // Setting a ui widget will cause the corresponding setting
1355 // to be set, but it also triggers a callback that can
1356 // have the side effect of using other settings values
1357 // that have not yet been set. So set *all* settings first
1358 // then update the ui.
1359 internal = plist_get_dict(internalPlist, "Initialization");
1360 ghb_dict_iter_init(&iter, internal);
1361 // middle (void*) cast prevents gcc warning "defreferencing type-punned
1362 // pointer will break strict-aliasing rules"
1363 while (g_hash_table_iter_next(
1364 &iter, (gpointer*)(void*)&key, (gpointer*)(void*)&gval))
1366 ghb_settings_set_value(ud->settings, key, gval);
1369 internal = plist_get_dict(internalPlist, "Presets");
1370 ghb_dict_iter_init(&iter, internal);
1371 // middle (void*) cast prevents gcc warning "defreferencing type-punned
1372 // pointer will break strict-aliasing rules"
1373 while (g_hash_table_iter_next(
1374 &iter, (gpointer*)(void*)&key, (gpointer*)(void*)&gval))
1376 ghb_settings_set_value(ud->settings, key, gval);
1379 internal = plist_get_dict(internalPlist, "Preferences");
1380 ghb_dict_iter_init(&iter, internal);
1381 // middle (void*) cast prevents gcc warning "defreferencing type-punned
1382 // pointer will break strict-aliasing rules"
1383 while (g_hash_table_iter_next(
1384 &iter, (gpointer*)(void*)&key, (gpointer*)(void*)&gval))
1386 ghb_settings_set_value(ud->settings, key, gval);
1388 prefs_initializing = FALSE;
1392 ghb_settings_close()
1395 ghb_value_free(internalPlist);
1397 ghb_value_free(presetsPlist);
1399 ghb_value_free(prefsPlist);
1404 FindFirstCDROM(void)
1409 strcpy(drive, "A:" G_DIR_SEPARATOR_S);
1410 drives = GetLogicalDrives();
1411 for (ii = 0; ii < 26; ii++)
1417 drive[0] = 'A' + ii;
1418 dtype = GetDriveType(drive);
1419 if (dtype == DRIVE_CDROM)
1421 return g_strdup(drive);
1431 ghb_prefs_load(signal_user_data_t *ud)
1433 GValue *dict, *internal;
1434 GHashTableIter iter;
1436 GValue *gval, *path;
1438 g_debug("ghb_prefs_load");
1439 prefsPlist = load_plist("preferences");
1440 if (prefsPlist == NULL)
1441 prefsPlist = ghb_dict_value_new();
1442 dict = plist_get_dict(prefsPlist, "Preferences");
1443 internal = plist_get_dict(internalPlist, "Preferences");
1444 if (dict == NULL && internal)
1446 dict = ghb_dict_value_new();
1447 ghb_dict_insert(prefsPlist, g_strdup("Preferences"), dict);
1449 // Get defaults from internal defaults
1450 ghb_dict_iter_init(&iter, internal);
1451 // middle (void*) cast prevents gcc warning "defreferencing type-punned
1452 // pointer will break strict-aliasing rules"
1453 while (g_hash_table_iter_next(
1454 &iter, (gpointer*)(void*)&key, (gpointer*)(void*)&gval))
1456 ghb_dict_insert(dict, g_strdup(key), ghb_value_dup(gval));
1459 const gchar *dir = g_get_user_special_dir (G_USER_DIRECTORY_DESKTOP);
1464 ghb_dict_insert(dict,
1465 g_strdup("ExportDirectory"), ghb_value_dup(ghb_string_value(dir)));
1467 dir = g_get_user_special_dir (G_USER_DIRECTORY_VIDEOS);
1472 ghb_dict_insert(dict,
1473 g_strdup("destination_dir"), ghb_value_dup(ghb_string_value(dir)));
1475 ghb_dict_insert(dict,
1476 g_strdup("SrtDir"), ghb_value_dup(ghb_string_value(dir)));
1480 source = FindFirstCDROM();
1483 source = g_strdup("C:" G_DIR_SEPARATOR_S);
1485 ghb_dict_insert(dict, g_strdup("default_source"),
1486 ghb_value_dup(ghb_string_value(source)));
1491 // Read legacy default_preset preference and update accordingly
1492 path = ghb_dict_lookup(dict, "default_preset");
1497 if (G_VALUE_TYPE(path) == G_TYPE_STRING)
1501 path = ghb_array_value_new(1);
1502 ghb_array_append(path, ghb_value_dup(str));
1503 indices = ghb_preset_indices_from_path(presetsPlist, path, &len);
1504 ghb_value_free(path);
1507 indices = ghb_preset_indices_from_path(presetsPlist, path, &len);
1511 presets_set_default(indices, len);
1514 ghb_dict_remove(dict, "default_preset");
1520 get_preset_color(gint type, gboolean folder)
1524 if (type == PRESETS_CUSTOM)
1544 ghb_presets_list_init(
1545 signal_user_data_t *ud,
1549 GtkTreeView *treeview;
1550 GtkTreeIter iter, titer, *piter;
1552 GtkTreeStore *store;
1553 const gchar *preset;
1554 GtkTreePath *parent_path;
1555 const gchar *description;
1560 GValue *presets = NULL;
1562 g_debug("ghb_presets_list_init ()");
1563 more_indices = g_malloc((len+1)*sizeof(gint));
1564 memcpy(more_indices, indices, len*sizeof(gint));
1565 presets = presets_get_folder(presetsPlist, indices, len);
1566 if (presets == NULL)
1568 g_warning("Failed to find parent folder when adding child.");
1571 count = ghb_array_len(presets);
1572 treeview = GTK_TREE_VIEW(GHB_WIDGET(ud->builder, "presets_list"));
1573 store = GTK_TREE_STORE(gtk_tree_view_get_model(treeview));
1574 parent_path = ghb_tree_path_new_from_indices(indices, len);
1577 gtk_tree_model_get_iter(GTK_TREE_MODEL(store), &titer, parent_path);
1579 gtk_tree_path_free(parent_path);
1585 for (ii = 0; ii < count; ii++)
1591 // Additional settings, add row
1592 dict = ghb_array_get_nth(presets, ii);
1593 preset = preset_get_name(dict);
1594 more_indices[len] = ii;
1595 def = preset_is_default(dict);
1597 description = ghb_presets_get_description(dict);
1598 gtk_tree_store_append(store, &iter, piter);
1599 type = ghb_preset_type(dict);
1600 folder = ghb_preset_folder(dict);
1601 color = get_preset_color(type, folder);
1602 gtk_tree_store_set(store, &iter, 0, preset,
1607 5, type == PRESETS_BUILTIN ? 0 : 1,
1614 if (gtk_tree_model_iter_parent(
1615 GTK_TREE_MODEL(store), &ppiter, piter))
1617 path = gtk_tree_model_get_path(GTK_TREE_MODEL(store), &ppiter);
1618 gtk_tree_view_expand_row(treeview, path, FALSE);
1619 gtk_tree_path_free(path);
1621 path = gtk_tree_model_get_path(GTK_TREE_MODEL(store), piter);
1622 gtk_tree_view_expand_row(treeview, path, FALSE);
1623 gtk_tree_path_free(path);
1627 ghb_presets_list_init(ud, more_indices, len+1);
1628 if (preset_folder_is_open(dict))
1634 path = gtk_tree_model_get_path(GTK_TREE_MODEL(store), piter);
1635 gtk_tree_view_expand_row(treeview, path, FALSE);
1636 gtk_tree_path_free(path);
1638 path = gtk_tree_model_get_path(GTK_TREE_MODEL(store), &iter);
1639 gtk_tree_view_expand_row(treeview, path, FALSE);
1640 gtk_tree_path_free(path);
1644 g_free(more_indices);
1648 presets_list_update_item(
1649 signal_user_data_t *ud,
1654 GtkTreeView *treeview;
1655 GtkTreeStore *store;
1657 GtkTreePath *treepath;
1659 const gchar *description;
1661 gboolean def, folder;
1665 g_debug("presets_list_update_item ()");
1666 dict = presets_get_dict(presetsPlist, indices, len);
1669 treeview = GTK_TREE_VIEW(GHB_WIDGET(ud->builder, "presets_list"));
1670 store = GTK_TREE_STORE(gtk_tree_view_get_model(treeview));
1671 treepath = ghb_tree_path_new_from_indices(indices, len);
1672 gtk_tree_model_get_iter(GTK_TREE_MODEL(store), &iter, treepath);
1673 // Additional settings, add row
1674 name = preset_get_name(dict);
1675 def = preset_is_default(dict);
1677 description = ghb_presets_get_description(dict);
1678 type = ghb_preset_type(dict);
1679 folder = ghb_preset_folder(dict);
1680 color = get_preset_color(type, folder);
1681 gtk_tree_store_set(store, &iter, 0, name,
1686 5, type == PRESETS_BUILTIN ? 0 : 1,
1688 if (recurse && folder)
1690 ghb_presets_list_init(ud, indices, len);
1695 presets_list_insert(
1696 signal_user_data_t *ud,
1700 GtkTreeView *treeview;
1701 GtkTreeIter iter, titer, *piter;
1702 GtkTreeStore *store;
1703 const gchar *preset;
1704 const gchar *description;
1706 gboolean def, folder;
1709 GtkTreePath *parent_path;
1713 g_debug("presets_list_insert ()");
1714 treeview = GTK_TREE_VIEW(GHB_WIDGET(ud->builder, "presets_list"));
1715 store = GTK_TREE_STORE(gtk_tree_view_get_model(treeview));
1716 presets = presets_get_folder(presetsPlist, indices, len-1);
1717 if (presets == NULL)
1719 g_warning("Failed to find parent folder while adding child.");
1722 parent_path = ghb_tree_path_new_from_indices(indices, len-1);
1725 gtk_tree_model_get_iter(GTK_TREE_MODEL(store), &titer, parent_path);
1727 gtk_tree_path_free(parent_path);
1733 count = ghb_array_len(presets);
1734 if (indices[len-1] >= count)
1736 // Additional settings, add row
1737 dict = ghb_array_get_nth(presets, indices[len-1]);
1738 preset = preset_get_name(dict);
1739 def = preset_is_default(dict);
1741 description = ghb_presets_get_description(dict);
1742 gtk_tree_store_insert(store, &iter, piter, indices[len-1]);
1743 type = ghb_preset_type(dict);
1744 folder = ghb_preset_folder(dict);
1745 color = get_preset_color(type, folder);
1746 gtk_tree_store_set(store, &iter, 0, preset,
1751 5, type == PRESETS_BUILTIN ? 0 : 1,
1755 ghb_presets_list_init(ud, indices, len);
1760 presets_list_remove(
1761 signal_user_data_t *ud,
1765 GtkTreeView *treeview;
1766 GtkTreePath *treepath;
1768 GtkTreeStore *store;
1770 g_debug("presets_list_remove ()");
1771 treeview = GTK_TREE_VIEW(GHB_WIDGET(ud->builder, "presets_list"));
1772 store = GTK_TREE_STORE(gtk_tree_view_get_model(treeview));
1773 treepath = ghb_tree_path_new_from_indices(indices, len);
1776 if (gtk_tree_model_get_iter(GTK_TREE_MODEL(store), &iter, treepath))
1777 gtk_tree_store_remove(store, &iter);
1778 gtk_tree_path_free(treepath);
1783 remove_std_presets(signal_user_data_t *ud)
1788 count = ghb_array_len(presetsPlist);
1789 for (ii = count-1; ii >= 0; ii--)
1794 dict = ghb_array_get_nth(presetsPlist, ii);
1795 ptype = ghb_value_int(preset_dict_get_value(dict, "Type"));
1796 if (ptype == PRESETS_BUILTIN)
1798 if (ghb_presets_remove(presetsPlist, &indices, 1))
1800 presets_list_remove(ud, &indices, 1);
1807 ghb_save_queue(GValue *queue)
1809 store_plist(queue, "queue");
1815 return load_plist("queue");
1819 ghb_remove_queue_file()
1821 remove_plist("queue");
1830 static value_map_t vcodec_xlat[] =
1832 {"MPEG-4 (FFmpeg)", "ffmpeg"},
1833 {"MPEG-4 (XviD)", "ffmpeg"},
1834 {"H.264 (x264)", "x264"},
1835 {"VP3 (Theora)", "theora"},
1839 static value_map_t acodec_xlat[] =
1841 {"AAC (faac)", "faac"},
1842 {"AAC (CoreAudio)", "faac"},
1843 {"AC3 Passthru", "ac3"},
1844 {"MP3 (lame)", "lame"},
1845 {"Vorbis (vorbis)", "vorbis"},
1849 value_map_t container_xlat[] =
1851 {"MP4 file", "mp4"},
1852 {"M4V file", "mp4"},
1853 {"MKV file", "mkv"},
1854 {"AVI file", "mkv"},
1855 {"OGM file", "mkv"},
1859 value_map_t framerate_xlat[] =
1861 {"Same as source", "source"},
1866 {"23.976", "23.976"},
1873 value_map_t samplerate_xlat[] =
1884 value_map_t mix_xlat[] =
1887 {"Stereo", "stereo"},
1888 {"Dolby Surround", "dpl1"},
1889 {"Dolby Pro Logic II", "dpl2"},
1890 {"6-channel discrete", "6ch"},
1891 {"AC3 Passthru", "none"},
1895 value_map_t deint_xlat[] =
1905 value_map_t denoise_xlat[] =
1915 value_map_t detel_xlat[] =
1923 value_map_t decomb_xlat[] =
1931 extern iso639_lang_t ghb_language_table[];
1934 export_lang_xlat2(GValue *lin_val)
1938 if (lin_val == NULL) return NULL;
1942 str = ghb_value_string(lin_val);
1943 for (ii = 0; ghb_language_table[ii].eng_name; ii++)
1945 if (strcmp(str, ghb_language_table[ii].iso639_2) == 0)
1949 if (ghb_language_table[ii].native_name[0] != 0)
1950 lang = ghb_language_table[ii].native_name;
1952 lang = ghb_language_table[ii].eng_name;
1954 gval = ghb_string_value_new(lang);
1959 g_debug("Can't map language value: (%s)", str);
1965 export_subtitle_xlat2(GValue *lin_val)
1970 if (lin_val == NULL) return NULL;
1971 str = ghb_value_string(lin_val);
1972 if (strcmp(str, "none") == 0)
1974 gval = ghb_string_value_new("None");
1976 else if (strcmp(str, "auto") == 0)
1978 gval = ghb_string_value_new("Autoselect");
1982 gval = export_lang_xlat2(lin_val);
1989 import_lang_xlat2(GValue *mac_val)
1993 if (mac_val == NULL) return NULL;
1997 str = ghb_value_string(mac_val);
1998 for (ii = 0; ghb_language_table[ii].eng_name; ii++)
2000 if ((strcmp(str, ghb_language_table[ii].eng_name) == 0) ||
2001 (strcmp(str, ghb_language_table[ii].native_name) == 0))
2003 gval = ghb_string_value_new(ghb_language_table[ii].iso639_2);
2008 g_debug("Can't map language value: (%s)", str);
2014 import_subtitle_xlat2(GValue *mac_val)
2019 if (mac_val == NULL) return NULL;
2020 str = ghb_value_string(mac_val);
2021 if (strcmp(str, "None") == 0)
2023 gval = ghb_string_value_new("none");
2025 else if (strcmp(str, "Autoselect") == 0)
2027 gval = ghb_string_value_new("auto");
2031 gval = import_lang_xlat2(mac_val);
2038 export_audio_track_xlat2(GValue *lin_val)
2041 GValue *gval = NULL;
2043 if (lin_val == NULL) return NULL;
2044 str = ghb_value_string(lin_val);
2045 if (strcmp(str, "none") == 0)
2047 gval = ghb_int_value_new(1);
2051 gint val = ghb_value_int(lin_val) + 1;
2052 gval = ghb_int_value_new(val);
2059 import_audio_track_xlat2(GValue *mac_val)
2065 if (mac_val == NULL) return NULL;
2066 val = ghb_value_int(mac_val);
2075 str = g_strdup_printf("%d", val);
2076 gval = ghb_string_value_new(str);
2082 export_value_xlat2(value_map_t *value_map, GValue *lin_val, GType mac_type)
2086 if (lin_val == NULL) return NULL;
2091 str = ghb_value_string(lin_val);
2092 for (ii = 0; value_map[ii].mac_val; ii++)
2094 if (strcmp(str, value_map[ii].lin_val) == 0)
2096 sval = ghb_string_value_new(value_map[ii].mac_val);
2098 gval = ghb_value_new(mac_type);
2099 if (!g_value_transform(sval, gval))
2101 g_warning("can't transform");
2102 ghb_value_free(gval);
2103 ghb_value_free(sval);
2106 ghb_value_free(sval);
2110 g_debug("Can't map value: (%s)", str);
2116 export_value_xlat(GValue *dict)
2118 GValue *lin_val, *gval;
2121 key = "VideoEncoder";
2122 lin_val = ghb_dict_lookup(dict, key);
2123 gval = export_value_xlat2(vcodec_xlat, lin_val, G_TYPE_STRING);
2125 ghb_dict_insert(dict, g_strdup(key), gval);
2127 lin_val = ghb_dict_lookup(dict, key);
2128 gval = export_value_xlat2(container_xlat, lin_val, G_TYPE_STRING);
2130 ghb_dict_insert(dict, g_strdup(key), gval);
2131 key = "VideoFramerate";
2132 lin_val = ghb_dict_lookup(dict, key);
2133 gval = export_value_xlat2(framerate_xlat, lin_val, G_TYPE_STRING);
2135 ghb_dict_insert(dict, g_strdup(key), gval);
2136 key = "PictureDetelecine";
2137 lin_val = ghb_dict_lookup(dict, key);
2138 gval = export_value_xlat2(detel_xlat, lin_val, G_TYPE_INT);
2140 ghb_dict_insert(dict, g_strdup(key), gval);
2141 key = "PictureDecomb";
2142 lin_val = ghb_dict_lookup(dict, key);
2143 gval = export_value_xlat2(decomb_xlat, lin_val, G_TYPE_INT);
2145 ghb_dict_insert(dict, g_strdup(key), gval);
2146 key = "PictureDeinterlace";
2147 lin_val = ghb_dict_lookup(dict, key);
2148 gval = export_value_xlat2(deint_xlat, lin_val, G_TYPE_INT);
2150 ghb_dict_insert(dict, g_strdup(key), gval);
2151 key = "PictureDenoise";
2152 lin_val = ghb_dict_lookup(dict, key);
2153 gval = export_value_xlat2(denoise_xlat, lin_val, G_TYPE_INT);
2155 ghb_dict_insert(dict, g_strdup(key), gval);
2161 slist = ghb_dict_lookup(dict, "SubtitleList");
2162 count = ghb_array_len(slist);
2163 for (ii = 0; ii < count; ii++)
2165 sdict = ghb_array_get_nth(slist, ii);
2166 key = "SubtitleLanguage";
2167 lin_val = ghb_dict_lookup(sdict, key);
2168 gval = export_subtitle_xlat2(lin_val);
2170 ghb_dict_insert(sdict, g_strdup(key), gval);
2176 alist = ghb_dict_lookup(dict, "AudioList");
2177 count = ghb_array_len(alist);
2178 for (ii = 0; ii < count; ii++)
2180 adict = ghb_array_get_nth(alist, ii);
2182 lin_val = ghb_dict_lookup(adict, key);
2183 gval = export_audio_track_xlat2(lin_val);
2185 ghb_dict_insert(adict, g_strdup(key), gval);
2186 key = "AudioEncoder";
2187 lin_val = ghb_dict_lookup(adict, key);
2188 gval = export_value_xlat2(acodec_xlat, lin_val, G_TYPE_STRING);
2190 ghb_dict_insert(adict, g_strdup(key), gval);
2191 key = "AudioSamplerate";
2192 lin_val = ghb_dict_lookup(adict, key);
2193 gval = export_value_xlat2(samplerate_xlat, lin_val, G_TYPE_STRING);
2195 ghb_dict_insert(adict, g_strdup(key), gval);
2196 key = "AudioMixdown";
2197 lin_val = ghb_dict_lookup(adict, key);
2198 gval = export_value_xlat2(mix_xlat, lin_val, G_TYPE_STRING);
2200 ghb_dict_insert(adict, g_strdup(key), gval);
2208 value_map_t *value_map,
2212 GValue *gval, *def_val;
2214 if (mac_val == NULL) return NULL;
2215 def_val = ghb_dict_lookup(defaults, key);
2222 str = ghb_value_string(mac_val);
2223 for (ii = 0; value_map[ii].mac_val; ii++)
2225 if (strcmp(str, value_map[ii].mac_val) == 0)
2227 sval = ghb_string_value_new(value_map[ii].lin_val);
2229 gval = ghb_value_new(G_VALUE_TYPE(def_val));
2230 if (!g_value_transform(sval, gval))
2232 g_warning("can't transform");
2233 ghb_value_free(gval);
2234 ghb_value_free(sval);
2237 ghb_value_free(sval);
2249 str = ghb_value_string(mac_val);
2250 for (ii = 0; value_map[ii].mac_val; ii++)
2252 if (strcmp(str, value_map[ii].mac_val) == 0)
2254 sval = ghb_string_value_new(value_map[ii].lin_val);
2256 gval = ghb_value_new(G_VALUE_TYPE(mac_val));
2257 if (!g_value_transform(sval, gval))
2259 g_warning("can't transform");
2260 ghb_value_free(gval);
2261 ghb_value_free(sval);
2264 ghb_value_free(sval);
2274 import_value_xlat(GValue *dict)
2276 GValue *defaults, *mac_val, *gval;
2279 defaults = plist_get_dict(internalPlist, "Presets");
2280 key = "VideoEncoder";
2281 mac_val = ghb_dict_lookup(dict, key);
2282 gval = import_value_xlat2(defaults, vcodec_xlat, key, mac_val);
2284 ghb_dict_insert(dict, g_strdup(key), gval);
2286 mac_val = ghb_dict_lookup(dict, key);
2287 gval = import_value_xlat2(defaults, container_xlat, key, mac_val);
2289 ghb_dict_insert(dict, g_strdup(key), gval);
2290 key = "VideoFramerate";
2291 mac_val = ghb_dict_lookup(dict, key);
2292 gval = import_value_xlat2(defaults, framerate_xlat, key, mac_val);
2294 ghb_dict_insert(dict, g_strdup(key), gval);
2295 key = "PictureDetelecine";
2296 mac_val = ghb_dict_lookup(dict, key);
2297 gval = import_value_xlat2(defaults, detel_xlat, key, mac_val);
2299 ghb_dict_insert(dict, g_strdup(key), gval);
2300 key = "PictureDecomb";
2301 mac_val = ghb_dict_lookup(dict, key);
2302 gval = import_value_xlat2(defaults, decomb_xlat, key, mac_val);
2304 ghb_dict_insert(dict, g_strdup(key), gval);
2305 key = "PictureDeinterlace";
2306 mac_val = ghb_dict_lookup(dict, key);
2307 gval = import_value_xlat2(defaults, deint_xlat, key, mac_val);
2309 ghb_dict_insert(dict, g_strdup(key), gval);
2310 key = "PictureDenoise";
2311 mac_val = ghb_dict_lookup(dict, key);
2312 gval = import_value_xlat2(defaults, denoise_xlat, key, mac_val);
2314 ghb_dict_insert(dict, g_strdup(key), gval);
2323 sdeflist = ghb_dict_lookup(defaults, "SubtitleList");
2326 slist = ghb_dict_lookup(dict, "SubtitleList");
2329 sdefaults = ghb_array_get_nth(sdeflist, 0);
2330 count = ghb_array_len(slist);
2331 for (ii = 0; ii < count; ii++)
2333 sdict = ghb_array_get_nth(slist, ii);
2334 key = "SubtitleLanguage";
2335 mac_val = ghb_dict_lookup(sdict, key);
2336 gval = import_subtitle_xlat2(mac_val);
2338 ghb_dict_insert(sdict, g_strdup(key), gval);
2345 mac_val = ghb_dict_lookup(dict, key);
2346 slist = ghb_array_value_new(8);
2347 ghb_dict_insert(dict, g_strdup("SubtitleList"), slist);
2352 gval = import_subtitle_xlat2(mac_val);
2353 lang = ghb_value_string(gval);
2354 if (lang && strcasecmp(lang, "none") != 0 && !slist)
2356 sdict = ghb_dict_value_new();
2357 ghb_array_append(slist, sdict);
2358 ghb_dict_insert(sdict, g_strdup("SubtitleLanguage"), gval);
2359 gval = ghb_dict_lookup(dict, "SubtitlesForced");
2362 ghb_dict_insert(sdict, g_strdup("SubtitleForced"),
2363 ghb_value_dup(gval));
2367 ghb_dict_insert(sdict, g_strdup("SubtitleForced"),
2368 ghb_boolean_value_new(FALSE));
2370 ghb_dict_insert(sdict, g_strdup("SubtitleBurned"),
2371 ghb_boolean_value_new(TRUE));
2372 ghb_dict_insert(sdict, g_strdup("SubtitleDefaultTrack"),
2373 ghb_boolean_value_new(FALSE));
2377 ghb_value_free(gval);
2384 ghb_dict_remove(dict, "Subtitles");
2385 ghb_dict_remove(dict, "SubtitlesForced");
2393 adeflist = ghb_dict_lookup(defaults, "AudioList");
2396 adefaults = ghb_array_get_nth(adeflist, 0);
2397 alist = ghb_dict_lookup(dict, "AudioList");
2398 count = ghb_array_len(alist);
2399 for (ii = 0; ii < count; ii++)
2401 adict = ghb_array_get_nth(alist, ii);
2403 mac_val = ghb_dict_lookup(adict, key);
2404 gval = import_audio_track_xlat2(mac_val);
2406 ghb_dict_insert(adict, g_strdup(key), gval);
2407 key = "AudioEncoder";
2408 mac_val = ghb_dict_lookup(adict, key);
2409 gval = import_value_xlat2(adefaults, acodec_xlat, key, mac_val);
2411 ghb_dict_insert(adict, g_strdup(key), gval);
2412 key = "AudioSamplerate";
2413 mac_val = ghb_dict_lookup(adict, key);
2414 gval = import_value_xlat2(adefaults, samplerate_xlat, key, mac_val);
2416 ghb_dict_insert(adict, g_strdup(key), gval);
2417 key = "AudioMixdown";
2418 mac_val = ghb_dict_lookup(adict, key);
2419 gval = import_value_xlat2(adefaults, mix_xlat, key, mac_val);
2421 ghb_dict_insert(adict, g_strdup(key), gval);
2423 mac_val = ghb_dict_lookup(adict, "AudioTrackDRCSlider");
2424 if (mac_val != NULL)
2427 drc = ghb_value_double(mac_val);
2428 if (drc < 1.0 && drc > 0.0)
2430 ghb_dict_insert(adict, g_strdup("AudioTrackDRCSlider"),
2431 ghb_double_value_new(0.0));
2439 import_xlat_preset(GValue *dict)
2446 g_debug("import_xlat_preset ()");
2447 uses_max = ghb_value_boolean(
2448 preset_dict_get_value(dict, "UsesMaxPictureSettings"));
2449 uses_pic = ghb_value_int(
2450 preset_dict_get_value(dict, "UsesPictureSettings"));
2451 par = ghb_value_int(preset_dict_get_value(dict, "PicturePAR"));
2452 vqtype = ghb_value_int(preset_dict_get_value(dict, "VideoQualityType"));
2454 if (uses_max || uses_pic == 2)
2456 ghb_dict_insert(dict, g_strdup("autoscale"),
2457 ghb_boolean_value_new(TRUE));
2463 if (ghb_dict_lookup(dict, "PictureModulus") == NULL)
2464 ghb_dict_insert(dict, g_strdup("PictureModulus"),
2465 ghb_int_value_new(16));
2469 ghb_dict_insert(dict, g_strdup("PictureModulus"),
2470 ghb_int_value_new(1));
2474 if (ghb_dict_lookup(dict, "PictureModulus") == NULL)
2475 ghb_dict_insert(dict, g_strdup("PictureModulus"),
2476 ghb_int_value_new(16));
2480 if (ghb_dict_lookup(dict, "PictureModulus") == NULL)
2481 ghb_dict_insert(dict, g_strdup("PictureModulus"),
2482 ghb_int_value_new(16));
2485 // VideoQualityType/0/1/2 - vquality_type_/target/bitrate/constant
2490 ghb_dict_insert(dict, g_strdup("vquality_type_target"),
2491 ghb_boolean_value_new(TRUE));
2492 ghb_dict_insert(dict, g_strdup("vquality_type_bitrate"),
2493 ghb_boolean_value_new(FALSE));
2494 ghb_dict_insert(dict, g_strdup("vquality_type_constant"),
2495 ghb_boolean_value_new(FALSE));
2499 ghb_dict_insert(dict, g_strdup("vquality_type_target"),
2500 ghb_boolean_value_new(FALSE));
2501 ghb_dict_insert(dict, g_strdup("vquality_type_bitrate"),
2502 ghb_boolean_value_new(TRUE));
2503 ghb_dict_insert(dict, g_strdup("vquality_type_constant"),
2504 ghb_boolean_value_new(FALSE));
2508 ghb_dict_insert(dict, g_strdup("vquality_type_target"),
2509 ghb_boolean_value_new(FALSE));
2510 ghb_dict_insert(dict, g_strdup("vquality_type_bitrate"),
2511 ghb_boolean_value_new(FALSE));
2512 ghb_dict_insert(dict, g_strdup("vquality_type_constant"),
2513 ghb_boolean_value_new(TRUE));
2517 ghb_dict_insert(dict, g_strdup("vquality_type_target"),
2518 ghb_boolean_value_new(FALSE));
2519 ghb_dict_insert(dict, g_strdup("vquality_type_bitrate"),
2520 ghb_boolean_value_new(FALSE));
2521 ghb_dict_insert(dict, g_strdup("vquality_type_constant"),
2522 ghb_boolean_value_new(TRUE));
2525 import_value_xlat(dict);
2530 vquality = ghb_value_double(preset_dict_get_value(dict, "VideoQualitySlider"));
2535 gval = preset_dict_get_value(dict, "VideoEncoder");
2536 vcodec = ghb_lookup_combo_int("VideoEncoder", gval);
2539 case HB_VCODEC_X264:
2541 vquality = 51. - vquality * 51.;
2544 case HB_VCODEC_FFMPEG:
2546 vquality = 31. - vquality * 30.;
2549 case HB_VCODEC_THEORA:
2551 vquality = vquality * 63.;
2559 ghb_dict_insert(dict, g_strdup("VideoQualitySlider"),
2560 ghb_double_value_new(vquality));
2565 import_xlat_presets(GValue *presets)
2571 g_debug("import_xlat_presets ()");
2572 if (presets == NULL) return;
2573 count = ghb_array_len(presets);
2574 for (ii = 0; ii < count; ii++)
2576 dict = ghb_array_get_nth(presets, ii);
2577 folder = ghb_value_boolean(preset_dict_get_value(dict, "Folder"));
2582 nested = ghb_dict_lookup(dict, "ChildrenArray");
2583 import_xlat_presets(nested);
2587 import_xlat_preset(dict);
2593 export_xlat_preset(GValue *dict)
2595 gboolean autoscale, target, br, constant;
2597 g_debug("export_xlat_prest ()");
2598 autoscale = ghb_value_boolean(preset_dict_get_value(dict, "autoscale"));
2599 target = ghb_value_boolean(
2600 preset_dict_get_value(dict, "vquality_type_target"));
2601 br = ghb_value_boolean(
2602 preset_dict_get_value(dict, "vquality_type_bitrate"));
2603 constant = ghb_value_boolean(
2604 preset_dict_get_value(dict, "vquality_type_constant"));
2607 ghb_dict_insert(dict, g_strdup("UsesPictureSettings"),
2608 ghb_int_value_new(2));
2610 ghb_dict_insert(dict, g_strdup("UsesPictureSettings"),
2611 ghb_int_value_new(1));
2613 // VideoQualityType/0/1/2 - vquality_type_/target/bitrate/constant
2616 ghb_dict_insert(dict, g_strdup("VideoQualityType"),
2617 ghb_int_value_new(0));
2621 ghb_dict_insert(dict, g_strdup("VideoQualityType"),
2622 ghb_int_value_new(1));
2626 ghb_dict_insert(dict, g_strdup("VideoQualityType"),
2627 ghb_int_value_new(2));
2630 GValue *alist, *adict;
2633 alist = ghb_dict_lookup(dict, "AudioList");
2634 count = ghb_array_len(alist);
2635 for (ii = 0; ii < count; ii++)
2639 adict = ghb_array_get_nth(alist, ii);
2640 drc = ghb_value_double(
2641 preset_dict_get_value(adict, "AudioTrackDRCSlider"));
2642 if (drc < 1.0 && drc > 0.0)
2644 ghb_dict_insert(adict, g_strdup("AudioTrackDRCSlider"),
2645 ghb_double_value_new(0.0));
2649 ghb_dict_remove(dict, "UsesMaxPictureSettings");
2650 ghb_dict_remove(dict, "autoscale");
2651 ghb_dict_remove(dict, "vquality_type_target");
2652 ghb_dict_remove(dict, "vquality_type_bitrate");
2653 ghb_dict_remove(dict, "vquality_type_constant");
2654 export_value_xlat(dict);
2658 export_xlat_presets(GValue *presets)
2664 if (presets == NULL) return;
2665 count = ghb_array_len(presets);
2666 for (ii = 0; ii < count; ii++)
2668 dict = ghb_array_get_nth(presets, ii);
2669 folder = ghb_value_boolean(preset_dict_get_value(dict, "Folder"));
2674 nested = ghb_dict_lookup(dict, "ChildrenArray");
2675 export_xlat_presets(nested);
2679 export_xlat_preset(dict);
2684 static guint prefs_timeout_id = 0;
2687 delayed_store_prefs(gpointer data)
2689 store_plist(prefsPlist, "preferences");
2690 prefs_timeout_id = 0;
2699 export = ghb_value_dup(presetsPlist);
2700 export_xlat_presets(export);
2701 store_plist(export, "presets");
2702 ghb_value_free(export);
2708 if (prefs_timeout_id != 0)
2713 mc = g_main_context_default();
2714 source = g_main_context_find_source_by_id(mc, prefs_timeout_id);
2716 g_source_destroy(source);
2718 prefs_timeout_id = g_timeout_add_seconds(1, (GSourceFunc)delayed_store_prefs, NULL);
2722 ghb_presets_reload(signal_user_data_t *ud)
2724 GValue *std_presets;
2728 g_debug("ghb_presets_reload()\n");
2729 std_presets = ghb_resource_get("standard-presets");
2730 if (std_presets == NULL) return;
2732 remove_std_presets(ud);
2733 indices = presets_find_default(presetsPlist, &len);
2736 presets_clear_default(std_presets);
2739 // Merge the keyfile contents into our presets
2740 count = ghb_array_len(std_presets);
2741 for (ii = count-1; ii >= 0; ii--)
2747 std_dict = ghb_array_get_nth(std_presets, ii);
2748 copy_dict = ghb_value_dup(std_dict);
2749 ghb_dict_insert(copy_dict, g_strdup("PresetBuildNumber"),
2750 ghb_int64_value_new(hb_get_build(NULL)));
2751 ghb_presets_insert(presetsPlist, copy_dict, &indices, 1);
2752 presets_list_insert(ud, &indices, 1);
2754 import_xlat_presets(presetsPlist);
2763 count = ghb_array_len(presetsPlist);
2764 for (ii = count-1; ii >= 0; ii--)
2769 dict = ghb_array_get_nth(presetsPlist, ii);
2770 type = ghb_dict_lookup(dict, "Type");
2778 replace_standard_presets()
2780 GValue *std_presets;
2784 count = ghb_array_len(presetsPlist);
2785 for (ii = count-1; ii >= 0; ii--)
2790 dict = ghb_array_get_nth(presetsPlist, ii);
2791 ptype = ghb_value_int(preset_dict_get_value(dict, "Type"));
2792 if (ptype == PRESETS_BUILTIN)
2795 ghb_presets_remove(presetsPlist, &indices, 1);
2799 std_presets = ghb_resource_get("standard-presets");
2800 if (std_presets == NULL) return;
2802 indices = presets_find_default(presetsPlist, &len);
2805 presets_clear_default(std_presets);
2808 // Merge the keyfile contents into our presets
2809 count = ghb_array_len(std_presets);
2810 for (ii = count-1; ii >= 0; ii--)
2816 std_dict = ghb_array_get_nth(std_presets, ii);
2817 copy_dict = ghb_value_dup(std_dict);
2818 ghb_dict_insert(copy_dict, g_strdup("PresetBuildNumber"),
2819 ghb_int64_value_new(hb_get_build(NULL)));
2820 ghb_presets_insert(presetsPlist, copy_dict, &indices, 1);
2822 import_xlat_presets(presetsPlist);
2827 update_standard_presets(signal_user_data_t *ud)
2831 count = ghb_array_len(presetsPlist);
2832 for (ii = count-1; ii >= 0; ii--)
2839 dict = ghb_array_get_nth(presetsPlist, ii);
2840 gval = ghb_dict_lookup(dict, "Type");
2843 // Old preset that doesn't have a Type
2844 replace_standard_presets();
2848 type = ghb_value_int(gval);
2851 gval = ghb_dict_lookup(dict, "PresetBuildNumber");
2854 // Old preset that doesn't have a build number
2855 replace_standard_presets();
2859 build = ghb_value_int64(gval);
2860 if (build != hb_get_build(NULL))
2862 // Build number does not match
2863 replace_standard_presets();
2872 ghb_presets_load(signal_user_data_t *ud)
2874 presetsPlist = load_plist("presets");
2875 if (presetsPlist == NULL)
2877 presetsPlist = ghb_value_dup(ghb_resource_get("standard-presets"));
2878 import_xlat_presets(presetsPlist);
2881 else if (G_VALUE_TYPE(presetsPlist) == ghb_dict_get_type())
2882 { // Presets is older dictionary format. Convert to array
2883 ghb_value_free(presetsPlist);
2884 presetsPlist = ghb_value_dup(ghb_resource_get("standard-presets"));
2885 import_xlat_presets(presetsPlist);
2888 else if (check_old_presets())
2890 ghb_value_free(presetsPlist);
2891 presetsPlist = ghb_value_dup(ghb_resource_get("standard-presets"));
2892 import_xlat_presets(presetsPlist);
2895 update_standard_presets(ud);
2896 import_xlat_presets(presetsPlist);
2900 settings_save(signal_user_data_t *ud, const GValue *path)
2902 GValue *dict, *internal;
2903 GHashTableIter iter;
2907 gint *indices, len, count;
2908 gint *def_indices, def_len;
2910 gboolean replace = FALSE;
2912 g_debug("settings_save");
2913 if (internalPlist == NULL) return;
2914 count = ghb_array_len(path);
2915 name = g_value_get_string(ghb_array_get_nth(path, count-1));
2916 indices = ghb_preset_indices_from_path(presetsPlist, path, &len);
2919 if (ghb_presets_get_folder(presetsPlist, indices, len))
2922 message = g_strdup_printf(
2923 "%s: Folder already exists.\n"
2924 "You can not replace it with a preset.",
2926 ghb_message_dialog(GTK_MESSAGE_ERROR, message, "Cancel", NULL);
2930 dict = ghb_dict_value_new();
2931 ghb_presets_replace(presetsPlist, dict, indices, len);
2936 indices = presets_find_pos(path, PRESETS_CUSTOM, &len);
2939 dict = ghb_dict_value_new();
2940 ghb_presets_insert(presetsPlist, dict, indices, len);
2944 g_warning("failed to find insert path");
2948 current_preset = dict;
2949 autoscale = ghb_settings_get_boolean(ud->settings, "autoscale");
2950 ghb_settings_set_int64(ud->settings, "Type", PRESETS_CUSTOM);
2951 ghb_settings_set_int64(ud->settings, "PresetBuildNumber", hb_get_build(NULL));
2953 internal = plist_get_dict(internalPlist, "Presets");
2954 ghb_dict_iter_init(&iter, internal);
2955 // middle (void*) cast prevents gcc warning "defreferencing type-punned
2956 // pointer will break strict-aliasing rules"
2957 while (g_hash_table_iter_next(
2958 &iter, (gpointer*)(void*)&key, (gpointer*)(void*)&value))
2966 if (strcmp(key, "PictureWidth") == 0)
2968 key2 = "scale_width";
2970 else if (strcmp(key, "PictureHeight") == 0)
2972 key2 = "scale_height";
2975 gval = ghb_settings_get_value(ud->settings, key2);
2980 ghb_dict_insert(dict, g_strdup(key), ghb_value_dup(gval));
2982 internal = plist_get_dict(internalPlist, "XlatPresets");
2983 ghb_dict_iter_init(&iter, internal);
2984 // middle (void*) cast prevents gcc warning "defreferencing type-punned
2985 // pointer will break strict-aliasing rules"
2986 while (g_hash_table_iter_next(
2987 &iter, (gpointer*)(void*)&key, (gpointer*)(void*)&value))
2991 gval = ghb_settings_get_value(ud->settings, key);
2996 ghb_dict_insert(dict, g_strdup(key), ghb_value_dup(gval));
2998 ghb_dict_insert(dict, g_strdup("PresetName"), ghb_string_value_new(name));
3001 def_indices = presets_find_default(presetsPlist, &def_len);
3002 if (def_indices != NULL &&
3003 preset_path_cmp(indices, len, def_indices, def_len) != 0)
3005 ghb_dict_insert(dict, g_strdup("Default"),
3006 ghb_boolean_value_new(FALSE));
3008 presets_list_update_item(ud, indices, len, FALSE);
3012 ghb_dict_insert(dict, g_strdup("Default"),
3013 ghb_boolean_value_new(FALSE));
3014 presets_list_insert(ud, indices, len);
3017 ud->dont_clear_presets = TRUE;
3018 // Make the new preset the selected item
3019 ghb_select_preset2(ud->builder, indices, len);
3021 ud->dont_clear_presets = FALSE;
3026 folder_save(signal_user_data_t *ud, const GValue *path)
3028 GValue *dict, *folder;
3029 gint *indices, len, count;
3032 count = ghb_array_len(path);
3033 name = g_value_get_string(ghb_array_get_nth(path, count-1));
3034 indices = ghb_preset_indices_from_path(presetsPlist, path, &len);
3037 if (!ghb_presets_get_folder(presetsPlist, indices, len))
3040 message = g_strdup_printf(
3041 "%s: Preset already exists.\n"
3042 "You can not replace it with a folder.",
3044 ghb_message_dialog(GTK_MESSAGE_ERROR, message, "Cancel", NULL);
3049 // Already exists, update its description
3050 dict = presets_get_dict(presetsPlist, indices, len);
3051 ghb_dict_insert(dict, g_strdup("PresetDescription"),
3052 ghb_value_dup(preset_dict_get_value(
3053 ud->settings, "PresetDescription")));
3054 presets_list_update_item(ud, indices, len, FALSE);
3061 indices = presets_find_pos(path, PRESETS_CUSTOM, &len);
3064 dict = ghb_dict_value_new();
3065 ghb_presets_insert(presetsPlist, dict, indices, len);
3069 g_warning("failed to find insert path");
3073 ghb_dict_insert(dict, g_strdup("PresetDescription"),
3074 ghb_value_dup(preset_dict_get_value(
3075 ud->settings, "PresetDescription")));
3076 ghb_dict_insert(dict, g_strdup("PresetName"), ghb_string_value_new(name));
3077 folder = ghb_array_value_new(8);
3078 ghb_dict_insert(dict, g_strdup("ChildrenArray"), folder);
3079 ghb_dict_insert(dict, g_strdup("Type"),
3080 ghb_int64_value_new(PRESETS_CUSTOM));
3081 ghb_dict_insert(dict, g_strdup("Folder"), ghb_boolean_value_new(TRUE));
3083 presets_list_insert(ud, indices, len);
3090 ghb_presets_list_default(signal_user_data_t *ud)
3092 GtkTreeView *treeview;
3093 GtkTreePath *treepath;
3095 GtkTreeStore *store;
3098 g_debug("ghb_presets_list_default ()");
3099 treeview = GTK_TREE_VIEW(GHB_WIDGET(ud->builder, "presets_list"));
3100 store = GTK_TREE_STORE(gtk_tree_view_get_model(treeview));
3101 indices = presets_find_default(presetsPlist, &len);
3102 if (indices == NULL) return;
3103 treepath = ghb_tree_path_new_from_indices(indices, len);
3106 if (gtk_tree_model_get_iter(GTK_TREE_MODEL(store), &iter, treepath))
3108 gtk_tree_store_set(store, &iter,
3113 gtk_tree_path_free(treepath);
3119 ghb_presets_list_clear_default(signal_user_data_t *ud)
3121 GtkTreeView *treeview;
3122 GtkTreePath *treepath;
3124 GtkTreeStore *store;
3127 g_debug("ghb_presets_list_clear_default ()");
3128 treeview = GTK_TREE_VIEW(GHB_WIDGET(ud->builder, "presets_list"));
3129 store = GTK_TREE_STORE(gtk_tree_view_get_model(treeview));
3130 indices = presets_find_default(presetsPlist, &len);
3131 if (indices == NULL) return;
3132 treepath = ghb_tree_path_new_from_indices(indices, len);
3135 if (gtk_tree_model_get_iter(GTK_TREE_MODEL(store), &iter, treepath))
3137 gtk_tree_store_set(store, &iter,
3142 gtk_tree_path_free(treepath);
3148 update_audio_presets(signal_user_data_t *ud)
3150 g_debug("update_audio_presets");
3151 const GValue *audio_list;
3153 audio_list = ghb_settings_get_value(ud->settings, "audio_list");
3154 ghb_settings_set_value(ud->settings, "AudioList", audio_list);
3158 update_subtitle_presets(signal_user_data_t *ud)
3160 g_debug("update_subtitle_presets");
3161 const GValue *subtitle_list, *subtitle;
3162 GValue *slist, *dict;
3163 gint count, ii, source;
3165 subtitle_list = ghb_settings_get_value(ud->settings, "subtitle_list");
3166 slist = ghb_array_value_new(8);
3167 count = ghb_array_len(subtitle_list);
3168 for (ii = 0; ii < count; ii++)
3170 subtitle = ghb_array_get_nth(subtitle_list, ii);
3171 source = ghb_settings_get_int(subtitle, "SubtitleSource");
3172 if (source != SRTSUB)
3174 dict = ghb_value_dup(subtitle);
3175 ghb_array_append(slist, dict);
3178 ghb_settings_take_value(ud->settings, "SubtitleList", slist);
3181 G_MODULE_EXPORT void
3182 presets_menu_clicked_cb(GtkWidget *xwidget, signal_user_data_t *ud)
3186 menu = GTK_MENU(GHB_WIDGET(ud->builder, "presets_menu"));
3187 gtk_menu_popup(menu, NULL, NULL, NULL, NULL, 1,
3188 gtk_get_current_event_time());
3191 G_MODULE_EXPORT void
3192 preset_import_clicked_cb(GtkWidget *xwidget, signal_user_data_t *ud)
3195 GtkResponseType response;
3198 GtkFileFilter *filter;
3200 g_debug("preset_import_clicked_cb ()");
3202 dialog = gtk_file_chooser_dialog_new("Import Preset", NULL,
3203 GTK_FILE_CHOOSER_ACTION_OPEN,
3204 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
3205 GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
3208 filter = gtk_file_filter_new();
3209 gtk_file_filter_set_name(filter, "All (*)");
3210 gtk_file_filter_add_pattern(filter, "*");
3211 gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(dialog), filter);
3213 filter = gtk_file_filter_new();
3214 gtk_file_filter_set_name(filter, "Presets (*.plist)");
3215 gtk_file_filter_add_pattern(filter, "*.plist");
3216 gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(dialog), filter);
3217 gtk_file_chooser_set_filter(GTK_FILE_CHOOSER(dialog), filter);
3219 exportDir = ghb_settings_get_string(ud->settings, "ExportDirectory");
3220 if (exportDir == NULL || exportDir[0] == '\0')
3222 exportDir = g_strdup(".");
3224 gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(dialog), exportDir);
3227 response = gtk_dialog_run(GTK_DIALOG(dialog));
3228 gtk_widget_hide(dialog);
3229 if (response == GTK_RESPONSE_ACCEPT)
3231 GValue *dict, *array;
3235 filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog));
3237 // import the preset
3238 if (!g_file_test(filename, G_FILE_TEST_IS_REGULAR))
3240 gtk_widget_destroy(dialog);
3244 array = ghb_plist_parse_file(filename);
3247 import_xlat_presets(array);
3248 presets_clear_default(array);
3249 presets_customize(array);
3251 count = ghb_array_len(array);
3252 for (ii = 0; ii < count; ii++)
3254 GValue *path, *name;
3258 dict = ghb_array_get_nth(array, ii);
3259 path = ghb_array_value_new(1);
3260 name = ghb_value_dup(ghb_dict_lookup(dict, "PresetName"));
3261 ghb_array_append(path, name);
3262 indices = ghb_preset_indices_from_path(presetsPlist, path, &len);
3263 // Modify the preset name till we make it unique
3264 while (indices != NULL)
3266 gchar *str = ghb_value_string(name);
3268 ghb_value_free(path);
3271 str = g_strdup_printf("%s %d", str, index);
3272 path = ghb_array_value_new(1);
3273 name = ghb_string_value_new(str);
3274 ghb_array_append(path, name);
3278 indices = ghb_preset_indices_from_path(presetsPlist, path, &len);
3280 ghb_dict_insert(dict, g_strdup("PresetName"), ghb_value_dup(name));
3281 indices = presets_find_pos(path, PRESETS_CUSTOM, &len);
3282 ghb_presets_insert(presetsPlist, ghb_value_dup(dict), indices, len);
3283 presets_list_insert(ud, indices, len);
3284 ghb_value_free(path);
3286 ghb_value_free(array);
3288 exportDir = ghb_settings_get_string(ud->settings, "ExportDirectory");
3289 dir = g_path_get_dirname(filename);
3290 if (strcmp(dir, exportDir) != 0)
3292 ghb_settings_set_string(ud->settings, "ExportDirectory", dir);
3293 ghb_pref_save(ud->settings, "ExportDirectory");
3298 gtk_widget_destroy(dialog);
3301 G_MODULE_EXPORT void
3302 preset_export_clicked_cb(GtkWidget *xwidget, signal_user_data_t *ud)
3305 GtkResponseType response;
3307 const gchar *name = "";
3308 gint count, *indices, len;
3312 g_debug("preset_export_clicked_cb ()");
3313 preset = ghb_settings_get_value (ud->settings, "preset_selection");
3317 count = ghb_array_len(preset);
3321 name = g_value_get_string(ghb_array_get_nth(preset, count-1));
3323 dialog = gtk_file_chooser_dialog_new("Export Preset", NULL,
3324 GTK_FILE_CHOOSER_ACTION_SAVE,
3325 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
3326 GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT,
3329 exportDir = ghb_settings_get_string(ud->settings, "ExportDirectory");
3330 if (exportDir == NULL || exportDir[0] == '\0')
3332 exportDir = g_strdup(".");
3334 filename = g_strdup_printf("%s.plist", name);
3335 gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(dialog), exportDir);
3336 gtk_file_chooser_set_current_name(GTK_FILE_CHOOSER(dialog), filename);
3340 indices = ghb_preset_indices_from_path(presetsPlist, preset, &len);
3341 if (indices == NULL)
3344 response = gtk_dialog_run(GTK_DIALOG(dialog));
3345 gtk_widget_hide(dialog);
3346 if (response == GTK_RESPONSE_ACCEPT)
3348 GValue *export, *dict, *array;
3352 filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog));
3354 // export the preset
3355 dict = presets_get_dict(presetsPlist, indices, len);
3357 export = ghb_value_dup(dict);
3358 array = ghb_array_value_new(1);
3359 ghb_array_append(array, export);
3360 presets_clear_default(array);
3361 presets_customize(array);
3362 export_xlat_presets(array);
3364 file = g_fopen(filename, "w");
3367 ghb_plist_write(file, array);
3370 ghb_value_free(array);
3372 exportDir = ghb_settings_get_string(ud->settings, "ExportDirectory");
3373 dir = g_path_get_dirname(filename);
3374 if (strcmp(dir, exportDir) != 0)
3376 ghb_settings_set_string(ud->settings, "ExportDirectory", dir);
3377 ghb_pref_save(ud->settings, "ExportDirectory");
3383 gtk_widget_destroy(dialog);
3387 G_MODULE_EXPORT void
3388 presets_new_folder_clicked_cb(GtkWidget *xwidget, signal_user_data_t *ud)
3393 GtkResponseType response;
3394 GValue *preset, *dict;
3395 const gchar *name = "";
3396 const gchar *description = "";
3397 gint count, *indices, len;
3399 g_debug("presets_save_clicked_cb ()");
3400 preset = ghb_settings_get_value (ud->settings, "preset_selection");
3402 count = ghb_array_len(preset);
3404 name = g_value_get_string(ghb_array_get_nth(preset, count-1));
3408 indices = ghb_preset_indices_from_path(presetsPlist, preset, &len);
3409 dict = presets_get_dict(presetsPlist, indices, len);
3412 description = g_value_get_string(
3413 ghb_dict_lookup(dict, "PresetDescription"));
3414 ghb_ui_update(ud, "PresetDescription", ghb_string_value(description));
3417 desc = GTK_TEXT_VIEW(GHB_WIDGET(ud->builder, "PresetDescription"));
3418 dialog = GHB_WIDGET(ud->builder, "preset_save_dialog");
3419 entry = GTK_ENTRY(GHB_WIDGET(ud->builder, "PresetName"));
3420 gtk_entry_set_text(entry, name);
3421 response = gtk_dialog_run(GTK_DIALOG(dialog));
3422 gtk_widget_hide(dialog);
3423 if (response == GTK_RESPONSE_OK)
3426 const gchar *name = gtk_entry_get_text(entry);
3429 if (count > MAX_NESTED_PRESET-1)
3430 count = MAX_NESTED_PRESET-1;
3432 dest = ghb_array_value_new(MAX_NESTED_PRESET);
3433 if (indices != NULL)
3437 ptype = ghb_presets_get_type(presetsPlist, indices, len);
3438 if (ptype == PRESETS_CUSTOM)
3440 ghb_array_copy(dest, preset, count-1);
3443 ghb_array_append(dest, ghb_string_value_new(name));
3444 ghb_widget_to_setting(ud->settings, GTK_WIDGET(desc));
3445 folder_save(ud, dest);
3446 ghb_value_free(dest);
3448 if (indices != NULL)
3452 G_MODULE_EXPORT void
3453 presets_save_clicked_cb(GtkWidget *xwidget, signal_user_data_t *ud)
3458 GtkResponseType response;
3460 const gchar *name = "";
3461 gint count, *indices, len;
3463 g_debug("presets_save_clicked_cb ()");
3464 preset = ghb_settings_get_value (ud->settings, "preset_selection");
3466 count = ghb_array_len(preset);
3468 name = g_value_get_string(ghb_array_get_nth(preset, count-1));
3472 desc = GTK_TEXT_VIEW(GHB_WIDGET(ud->builder, "PresetDescription"));
3473 dialog = GHB_WIDGET(ud->builder, "preset_save_dialog");
3474 entry = GTK_ENTRY(GHB_WIDGET(ud->builder, "PresetName"));
3475 gtk_entry_set_text(entry, name);
3476 response = gtk_dialog_run(GTK_DIALOG(dialog));
3477 gtk_widget_hide(dialog);
3478 if (response == GTK_RESPONSE_OK)
3481 const gchar *name = gtk_entry_get_text(entry);
3484 dest = ghb_array_value_new(MAX_NESTED_PRESET);
3485 indices = ghb_preset_indices_from_path(presetsPlist, preset, &len);
3490 ptype = ghb_presets_get_type(presetsPlist, indices, len);
3491 if (ptype == PRESETS_CUSTOM)
3493 ghb_array_copy(dest, preset, count-1);
3497 ghb_array_append(dest, ghb_string_value_new(name));
3499 ghb_widget_to_setting(ud->settings, GTK_WIDGET(desc));
3501 // Construct the audio settings presets from the current audio list
3502 update_audio_presets(ud);
3503 update_subtitle_presets(ud);
3504 settings_save(ud, dest);
3505 ghb_value_free(dest);
3509 G_MODULE_EXPORT void
3510 preset_type_changed_cb(GtkWidget *widget, signal_user_data_t *ud)
3512 ghb_widget_to_setting(ud->settings, widget);
3515 G_MODULE_EXPORT void
3516 presets_restore_clicked_cb(GtkWidget *xwidget, signal_user_data_t *ud)
3520 g_debug("presets_restore_clicked_cb ()");
3521 // Reload only the standard presets
3522 ghb_presets_reload(ud);
3523 // Updating the presets list shuffles things around
3524 // need to make sure the proper preset is selected
3525 preset = ghb_settings_get_value (ud->settings, "preset");
3526 ghb_select_preset(ud->builder, preset);
3529 G_MODULE_EXPORT void
3530 presets_remove_clicked_cb(GtkWidget *xwidget, signal_user_data_t *ud)
3532 GtkTreeView *treeview;
3533 GtkTreeSelection *selection;
3534 GtkTreeModel *store;
3537 GtkResponseType response;
3539 g_debug("presets_remove_clicked_cb ()");
3540 treeview = GTK_TREE_VIEW(GHB_WIDGET(ud->builder, "presets_list"));
3541 selection = gtk_tree_view_get_selection (treeview);
3542 if (gtk_tree_selection_get_selected(selection, &store, &iter))
3549 gtk_tree_model_get(store, &iter, 0, &preset, -1);
3550 path = gtk_tree_model_get_path(store, &iter);
3551 indices = gtk_tree_path_get_indices(path);
3552 len = gtk_tree_path_get_depth(path);
3554 folder = ghb_presets_get_folder(presetsPlist, indices, len);
3555 dialog = gtk_message_dialog_new(NULL, GTK_DIALOG_MODAL,
3556 GTK_MESSAGE_QUESTION, GTK_BUTTONS_YES_NO,
3557 "Confirm deletion of %s:\n\n%s",
3558 folder ? "folder" : "preset",
3560 response = gtk_dialog_run(GTK_DIALOG(dialog));
3561 gtk_widget_destroy (dialog);
3562 if (response == GTK_RESPONSE_YES)
3564 GtkTreeIter nextIter = iter;
3565 gboolean valid = TRUE;
3566 if (!gtk_tree_model_iter_next(store, &nextIter))
3568 if (!gtk_tree_model_iter_parent(store, &nextIter, &iter))
3573 // Remove the selected item
3574 // First unselect it so that selecting the new item works properly
3575 gtk_tree_selection_unselect_iter (selection, &iter);
3576 if (ghb_presets_remove(presetsPlist, indices, len))
3579 presets_list_remove(ud, indices, len);
3582 valid = gtk_tree_model_get_iter_first(store, &nextIter);
3585 gtk_tree_path_free(path);
3586 path = gtk_tree_model_get_path(store, &nextIter);
3587 indices = gtk_tree_path_get_indices(path);
3588 len = gtk_tree_path_get_depth(path);
3589 ghb_select_preset2(ud->builder, indices, len);
3593 gtk_tree_path_free(path);
3597 // controls where valid drop locations are
3598 G_MODULE_EXPORT gboolean
3599 presets_drag_motion_cb(
3601 GdkDragContext *ctx,
3605 signal_user_data_t *ud)
3607 GtkTreePath *path = NULL;
3608 GtkTreeViewDropPosition drop_pos;
3612 GtkTreeModel *model;
3613 GtkTreeSelection *select;
3614 gint src_ptype, dst_ptype;
3615 gboolean src_folder, dst_folder;
3617 gint tree_depth, ii;
3620 widget = gtk_drag_get_source_widget(ctx);
3621 if (widget == NULL || widget != GTK_WIDGET(tv))
3624 // Get the type of the object being dragged
3625 srctv = GTK_TREE_VIEW(gtk_drag_get_source_widget(ctx));
3626 select = gtk_tree_view_get_selection (srctv);
3627 gtk_tree_selection_get_selected (select, &model, &iter);
3628 path = gtk_tree_model_get_path (model, &iter);
3629 indices = gtk_tree_path_get_indices(path);
3630 len = gtk_tree_path_get_depth(path);
3632 preset = presets_get_dict(presetsPlist, indices, len);
3633 tree_depth = preset_tree_depth(preset);
3635 src_ptype = ghb_presets_get_type(presetsPlist, indices, len);
3636 src_folder = ghb_presets_get_folder(presetsPlist, indices, len);
3637 gtk_tree_path_free(path);
3639 if (src_folder && tree_depth == 1)
3642 // The rest checks that the destination is a valid position
3644 gtk_tree_view_get_dest_row_at_pos (tv, x, y, &path, &drop_pos);
3647 gdk_drag_status(ctx, 0, time);
3650 // Don't allow repositioning of builtin presets
3651 if (src_ptype != PRESETS_CUSTOM)
3653 gdk_drag_status(ctx, 0, time);
3657 len = gtk_tree_path_get_depth(path);
3658 if (len+tree_depth-1 >= MAX_NESTED_PRESET)
3660 if (drop_pos == GTK_TREE_VIEW_DROP_INTO_OR_BEFORE)
3661 drop_pos = GTK_TREE_VIEW_DROP_BEFORE;
3662 if (drop_pos == GTK_TREE_VIEW_DROP_INTO_OR_AFTER)
3663 drop_pos = GTK_TREE_VIEW_DROP_AFTER;
3665 for (ii = len+tree_depth-1; ii > MAX_NESTED_PRESET; ii--)
3666 gtk_tree_path_up(path);
3667 indices = gtk_tree_path_get_indices(path);
3668 len = gtk_tree_path_get_depth(path);
3669 dst_ptype = ghb_presets_get_type(presetsPlist, indices, len);
3670 dst_folder = ghb_presets_get_folder(presetsPlist, indices, len);
3671 // Don't allow mixing custom presets in the builtins
3672 if (dst_ptype != PRESETS_CUSTOM)
3674 gdk_drag_status(ctx, 0, time);
3678 // Only allow *drop into* for folders
3681 if (drop_pos == GTK_TREE_VIEW_DROP_INTO_OR_BEFORE)
3682 drop_pos = GTK_TREE_VIEW_DROP_BEFORE;
3683 if (drop_pos == GTK_TREE_VIEW_DROP_INTO_OR_AFTER)
3684 drop_pos = GTK_TREE_VIEW_DROP_AFTER;
3687 len = gtk_tree_path_get_depth(path);
3688 gtk_tree_view_set_drag_dest_row(tv, path, drop_pos);
3689 gtk_tree_path_free(path);
3690 gdk_drag_status(ctx, GDK_ACTION_MOVE, time);
3694 G_MODULE_EXPORT void
3696 GtkTreeView *dstwidget,
3699 GtkSelectionData *selection_data,
3700 guint info, guint t,
3701 signal_user_data_t *ud)
3703 GtkTreePath *path = NULL;
3704 GtkTreeViewDropPosition drop_pos;
3705 GtkTreeIter dstiter, srciter;
3706 gint *dst_indices, dst_len, *src_indices, src_len;
3708 gboolean src_folder, dst_folder;
3710 GtkTreeModel *dstmodel = gtk_tree_view_get_model(dstwidget);
3712 g_debug("preset_drag_cb ()");
3713 // This doesn't work here for some reason...
3714 // gtk_tree_view_get_drag_dest_row(dstwidget, &path, &drop_pos);
3715 gtk_tree_view_get_dest_row_at_pos (dstwidget, x, y, &path, &drop_pos);
3716 // This little hack is needed because attempting to drop after
3717 // the last item gives us no path or drop_pos.
3722 n_children = gtk_tree_model_iter_n_children(dstmodel, NULL);
3725 drop_pos = GTK_TREE_VIEW_DROP_AFTER;
3726 path = gtk_tree_path_new_from_indices(n_children-1, -1);
3730 drop_pos = GTK_TREE_VIEW_DROP_BEFORE;
3731 path = gtk_tree_path_new_from_indices(0, -1);
3736 GtkTreeView *srcwidget;
3737 GtkTreeModel *srcmodel;
3738 GtkTreeSelection *select;
3739 GtkTreePath *srcpath = NULL;
3741 gint tree_depth, ii;
3743 srcwidget = GTK_TREE_VIEW(gtk_drag_get_source_widget(dc));
3744 select = gtk_tree_view_get_selection (srcwidget);
3745 gtk_tree_selection_get_selected (select, &srcmodel, &srciter);
3747 srcpath = gtk_tree_model_get_path (srcmodel, &srciter);
3748 src_indices = gtk_tree_path_get_indices(srcpath);
3749 src_len = gtk_tree_path_get_depth(srcpath);
3750 src_ptype = ghb_presets_get_type(presetsPlist, src_indices, src_len);
3751 src_folder = ghb_presets_get_folder(presetsPlist, src_indices, src_len);
3752 preset = ghb_value_dup(
3753 presets_get_dict(presetsPlist, src_indices, src_len));
3754 gtk_tree_path_free(srcpath);
3756 // Don't allow repositioning of builtin presets
3757 if (src_ptype != PRESETS_CUSTOM)
3760 tree_depth = preset_tree_depth(preset);
3761 if (src_folder && tree_depth == 1)
3764 dst_len = gtk_tree_path_get_depth(path);
3765 if (dst_len+tree_depth-1 >= MAX_NESTED_PRESET)
3767 if (drop_pos == GTK_TREE_VIEW_DROP_INTO_OR_BEFORE)
3768 drop_pos = GTK_TREE_VIEW_DROP_BEFORE;
3769 if (drop_pos == GTK_TREE_VIEW_DROP_INTO_OR_AFTER)
3770 drop_pos = GTK_TREE_VIEW_DROP_AFTER;
3773 for (ii = dst_len+tree_depth-1; ii > MAX_NESTED_PRESET; ii--)
3774 gtk_tree_path_up(path);
3775 dst_indices = gtk_tree_path_get_indices(path);
3776 dst_len = gtk_tree_path_get_depth(path);
3777 dst_folder = ghb_presets_get_folder(presetsPlist, dst_indices, dst_len);
3778 // Only allow *drop into* for folders
3781 if (drop_pos == GTK_TREE_VIEW_DROP_INTO_OR_BEFORE)
3782 drop_pos = GTK_TREE_VIEW_DROP_BEFORE;
3783 if (drop_pos == GTK_TREE_VIEW_DROP_INTO_OR_AFTER)
3784 drop_pos = GTK_TREE_VIEW_DROP_AFTER;
3786 if (gtk_tree_model_get_iter (dstmodel, &dstiter, path))
3789 GtkTreePath *dstpath = NULL;
3793 case GTK_TREE_VIEW_DROP_BEFORE:
3794 gtk_tree_store_insert_before(GTK_TREE_STORE (dstmodel),
3795 &iter, NULL, &dstiter);
3798 case GTK_TREE_VIEW_DROP_INTO_OR_BEFORE:
3799 gtk_tree_store_insert(GTK_TREE_STORE (dstmodel),
3800 &iter, &dstiter, 0);
3803 case GTK_TREE_VIEW_DROP_AFTER:
3804 gtk_tree_store_insert_after(GTK_TREE_STORE (dstmodel),
3805 &iter, NULL, &dstiter);
3808 case GTK_TREE_VIEW_DROP_INTO_OR_AFTER:
3809 gtk_tree_store_insert_after(GTK_TREE_STORE (dstmodel),
3810 &iter, &dstiter, 0);
3817 dstpath = gtk_tree_model_get_path (dstmodel, &iter);
3818 dst_indices = gtk_tree_path_get_indices(dstpath);
3819 dst_len = gtk_tree_path_get_depth(dstpath);
3820 ghb_presets_insert(presetsPlist, preset, dst_indices, dst_len);
3821 gtk_tree_path_free(dstpath);
3823 srcpath = gtk_tree_model_get_path (srcmodel, &srciter);
3824 src_indices = gtk_tree_path_get_indices(srcpath);
3825 src_len = gtk_tree_path_get_depth(srcpath);
3826 ghb_presets_remove(presetsPlist, src_indices, src_len);
3827 gtk_tree_path_free(srcpath);
3829 gtk_tree_store_remove (GTK_TREE_STORE (srcmodel), &srciter);
3831 dstpath = gtk_tree_model_get_path (dstmodel, &iter);
3832 dst_indices = gtk_tree_path_get_indices(dstpath);
3833 dst_len = gtk_tree_path_get_depth(dstpath);
3834 presets_list_update_item(ud, dst_indices, dst_len, TRUE);
3835 gtk_tree_path_free(dstpath);
3839 gtk_tree_path_free(path);
3844 presets_row_expanded_cb(
3845 GtkTreeView *treeview,
3848 signal_user_data_t *ud)
3851 gboolean expanded, folder;
3854 expanded = gtk_tree_view_row_expanded(treeview, path);
3855 indices = gtk_tree_path_get_indices(path);
3856 len = gtk_tree_path_get_depth(path);
3857 dict = presets_get_dict(presetsPlist, indices, len);
3858 if (preset_folder_is_open(dict))
3867 folder = ghb_presets_get_folder(presetsPlist, indices, len);
3870 presets_set_folder_open(expanded, indices, len);
3873 // Collapsing parent folder collapses all children
3876 GValue *presets = NULL;
3877 gint *more_indices, count, ii;
3879 more_indices = g_malloc((len+1)*sizeof(gint));
3880 memcpy(more_indices, indices, len*sizeof(gint));
3882 presets = presets_get_folder(presetsPlist, indices, len);
3883 count = ghb_array_len(presets);
3884 for (ii = 0; ii < count; ii++)
3886 dict = ghb_array_get_nth(presets, ii);
3887 folder = ghb_preset_folder(dict);
3890 more_indices[len] = ii;
3891 presets_set_folder_open(expanded, more_indices, len+1);
3894 g_free(more_indices);
3900 preset_update_title_deps(signal_user_data_t *ud, ghb_title_info_t *tinfo)
3904 ghb_ui_update(ud, "scale_width",
3905 ghb_int64_value(tinfo->width - tinfo->crop[2] - tinfo->crop[3]));
3906 // If anamorphic or keep_aspect, the hight will be automatically calculated
3907 gboolean keep_aspect;
3909 keep_aspect = ghb_settings_get_boolean(ud->settings, "PictureKeepRatio");
3910 pic_par = ghb_settings_combo_int(ud->settings, "PicturePAR");
3911 if (!(keep_aspect || pic_par) || pic_par == 3)
3913 ghb_ui_update(ud, "scale_height",
3914 ghb_int64_value(tinfo->height - tinfo->crop[0] - tinfo->crop[1]));
3917 // Set the limits of cropping. hb_set_anamorphic_size crashes if
3918 // you pass it a cropped width or height == 0.
3920 bound = tinfo->height / 2 - 2;
3921 widget = GHB_WIDGET (ud->builder, "PictureTopCrop");
3922 gtk_spin_button_set_range (GTK_SPIN_BUTTON(widget), 0, bound);
3923 widget = GHB_WIDGET (ud->builder, "PictureBottomCrop");
3924 gtk_spin_button_set_range (GTK_SPIN_BUTTON(widget), 0, bound);
3925 bound = tinfo->width / 2 - 2;
3926 widget = GHB_WIDGET (ud->builder, "PictureLeftCrop");
3927 gtk_spin_button_set_range (GTK_SPIN_BUTTON(widget), 0, bound);
3928 widget = GHB_WIDGET (ud->builder, "PictureRightCrop");
3929 gtk_spin_button_set_range (GTK_SPIN_BUTTON(widget), 0, bound);
3930 if (ghb_settings_get_boolean(ud->settings, "PictureAutoCrop"))
3932 ghb_ui_update(ud, "PictureTopCrop", ghb_int64_value(tinfo->crop[0]));
3933 ghb_ui_update(ud, "PictureBottomCrop", ghb_int64_value(tinfo->crop[1]));
3934 ghb_ui_update(ud, "PictureLeftCrop", ghb_int64_value(tinfo->crop[2]));
3935 ghb_ui_update(ud, "PictureRightCrop", ghb_int64_value(tinfo->crop[3]));
3939 G_MODULE_EXPORT void
3940 presets_list_selection_changed_cb(GtkTreeSelection *selection, signal_user_data_t *ud)
3942 GtkTreeModel *store;
3944 ghb_title_info_t tinfo;
3947 g_debug("presets_list_selection_changed_cb ()");
3948 widget = GHB_WIDGET (ud->builder, "presets_remove");
3949 if (gtk_tree_selection_get_selected(selection, &store, &iter))
3951 GtkTreePath *treepath;
3956 treepath = gtk_tree_model_get_path(store, &iter);
3957 indices = gtk_tree_path_get_indices(treepath);
3958 len = gtk_tree_path_get_depth(treepath);
3960 path = preset_path_from_indices(presetsPlist, indices, len);
3961 ghb_settings_take_value(ud->settings, "preset_selection", path);
3963 folder = ghb_presets_get_folder(presetsPlist, indices, len);
3966 ud->dont_clear_presets = TRUE;
3967 // Temporarily set the video_quality range to (0,100)
3968 // This is needed so the video_quality value does not get
3969 // truncated when set. The range will be readjusted below
3970 GtkWidget *qp = GHB_WIDGET(ud->builder, "VideoQualitySlider");
3971 gtk_range_set_range (GTK_RANGE(qp), 0, 100);
3972 gtk_scale_set_digits(GTK_SCALE(qp), 3);
3973 // Clear the audio list prior to changing the preset. Existing
3974 // audio can cause the container extension to be automatically
3975 // changed when it shouldn't be
3976 ghb_clear_audio_list(ud);
3977 ghb_set_preset_from_indices(ud, indices, len);
3978 gtk_tree_path_free(treepath);
3980 titleindex = ghb_settings_combo_int(ud->settings, "title");
3981 ghb_set_pref_audio(titleindex, ud);
3982 ghb_set_pref_subtitle(titleindex, ud);
3983 ghb_settings_set_boolean(ud->settings, "preset_modified", FALSE);
3984 if (ghb_get_title_info (&tinfo, titleindex))
3986 preset_update_title_deps(ud, &tinfo);
3988 ghb_set_scale (ud, GHB_PIC_KEEP_PAR);
3989 ud->dont_clear_presets = FALSE;
3991 gdouble vqmin, vqmax, step, page;
3995 ghb_vquality_range(ud, &vqmin, &vqmax, &step,
3996 &page, &digits, &inverted);
3997 gtk_range_set_range (GTK_RANGE(qp), vqmin, vqmax);
3998 gtk_range_set_increments (GTK_RANGE(qp), step, page);
3999 gtk_scale_set_digits(GTK_SCALE(qp), digits);
4000 gtk_range_set_inverted (GTK_RANGE(qp), inverted);
4004 GtkWidget *crop_widget;
4005 crop[0] = ghb_settings_get_int(ud->settings, "PictureTopCrop");
4006 crop[1] = ghb_settings_get_int(ud->settings, "PictureBottomCrop");
4007 crop[2] = ghb_settings_get_int(ud->settings, "PictureLeftCrop");
4008 crop[3] = ghb_settings_get_int(ud->settings, "PictureRightCrop");
4009 crop_widget = GHB_WIDGET (ud->builder, "crop_values");
4010 text = g_strdup_printf("%d:%d:%d:%d",
4011 crop[0], crop[1], crop[2], crop[3]);
4012 gtk_label_set_text (GTK_LABEL(crop_widget), text);
4015 gtk_widget_set_sensitive(widget, TRUE);
4019 g_debug("No selection??? Perhaps unselected.");
4020 gtk_widget_set_sensitive(widget, FALSE);
4025 ghb_clear_presets_selection(signal_user_data_t *ud)
4027 GtkTreeView *treeview;
4028 GtkTreeSelection *selection;
4030 if (ud->dont_clear_presets) return;
4031 g_debug("ghb_clear_presets_selection()");
4032 treeview = GTK_TREE_VIEW(GHB_WIDGET(ud->builder, "presets_list"));
4033 selection = gtk_tree_view_get_selection (treeview);
4034 gtk_tree_selection_unselect_all (selection);
4035 ghb_settings_set_boolean(ud->settings, "preset_modified", TRUE);
4038 G_MODULE_EXPORT void
4039 presets_frame_size_allocate_cb(GtkWidget *widget, GtkAllocation *allocation, signal_user_data_t *ud)
4041 GtkTreeView *treeview;
4042 GtkTreeSelection *selection;
4043 GtkTreeModel *store;
4046 treeview = GTK_TREE_VIEW(GHB_WIDGET(ud->builder, "presets_list"));
4047 selection = gtk_tree_view_get_selection(treeview);
4048 if (gtk_tree_selection_get_selected(selection, &store, &iter))
4051 path = gtk_tree_model_get_path (store, &iter);
4052 // Make the parent visible in scroll window if it is not.
4053 gtk_tree_view_scroll_to_cell (treeview, path, NULL, FALSE, 0, 0);
4054 gtk_tree_path_free(path);
4058 G_MODULE_EXPORT void
4059 presets_default_clicked_cb(GtkWidget *xwidget, signal_user_data_t *ud)
4064 g_debug("presets_default_clicked_cb ()");
4065 preset = ghb_settings_get_value(ud->settings, "preset_selection");
4066 indices = ghb_preset_indices_from_path(presetsPlist, preset, &len);
4069 if (!ghb_presets_get_folder(presetsPlist, indices, len))
4071 ghb_presets_list_clear_default(ud);
4072 presets_set_default(indices, len);
4073 ghb_presets_list_default(ud);
4079 G_MODULE_EXPORT void
4081 GtkCellRendererText *cell,
4084 signal_user_data_t *ud)
4086 GtkTreePath *treepath;
4087 GtkTreeStore *store;
4088 GtkTreeView *treeview;
4090 gint *indices, len, count;
4092 GValue *preset, *dest;
4094 g_debug("preset_edited_cb ()");
4095 g_debug("path (%s)", path);
4096 g_debug("text (%s)", text);
4098 preset = ghb_settings_get_value (ud->settings, "preset_selection");
4099 dest = ghb_array_value_new(MAX_NESTED_PRESET);
4100 count = ghb_array_len(preset);
4101 ghb_array_copy(dest, preset, count-1);
4102 ghb_array_append(dest, ghb_string_value_new(text));
4103 indices = ghb_preset_indices_from_path(presetsPlist, dest, &len);
4104 ghb_value_free(dest);
4105 if (indices != NULL)
4112 treeview = GTK_TREE_VIEW(GHB_WIDGET(ud->builder, "presets_list"));
4113 store = GTK_TREE_STORE(gtk_tree_view_get_model(treeview));
4114 treepath = gtk_tree_path_new_from_string (path);
4115 indices = gtk_tree_path_get_indices(treepath);
4116 len = gtk_tree_path_get_depth(treepath);
4117 gtk_tree_model_get_iter(GTK_TREE_MODEL(store), &iter, treepath);
4118 gtk_tree_store_set(store, &iter, 0, text, -1);
4120 dict = presets_get_dict(presetsPlist, indices, len);
4121 ghb_dict_insert(dict, g_strdup("PresetName"), ghb_string_value_new(text));
4123 gtk_tree_path_free (treepath);