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);
912 ghb_settings_to_ui(signal_user_data_t *ud, GValue *dict)
914 init_ui_from_dict(ud, dict, dict);
917 static GValue *current_preset = NULL;
920 ghb_preset_is_custom()
924 if (current_preset == NULL) return FALSE;
925 val = preset_dict_get_value(current_preset, "Type");
926 return (ghb_value_int(val) == 1);
930 ghb_set_preset_from_indices(signal_user_data_t *ud, gint *indices, gint len)
933 gint fallback[2] = {0, -1};
936 dict = presets_get_dict(presetsPlist, indices, len);
941 dict = presets_get_dict(presetsPlist, indices, len);
945 preset_to_ui(ud, NULL);
946 current_preset = NULL;
953 current_preset = dict;
954 folder = ghb_value_boolean(preset_dict_get_value(dict, "Folder"));
956 preset_to_ui(ud, NULL);
958 preset_to_ui(ud, dict);
959 path = preset_path_from_indices(presetsPlist, indices, len);
960 ghb_settings_set_value(ud->settings, "preset", path);
961 ghb_value_free(path);
966 curr_preset_get_value(const gchar *key)
968 if (current_preset == NULL) return NULL;
969 return preset_dict_get_value(current_preset, key);
973 ghb_update_from_preset(
974 signal_user_data_t *ud,
979 g_debug("ghb_update_from_preset() %s", key);
980 gval = curr_preset_get_value(key);
983 ghb_ui_update(ud, key, gval);
993 GtkTreeView *treeview;
994 GtkTreeSelection *selection;
999 g_debug("ghb_select_preset2()");
1000 treeview = GTK_TREE_VIEW(GHB_WIDGET(builder, "presets_list"));
1001 selection = gtk_tree_view_get_selection (treeview);
1002 store = gtk_tree_view_get_model (treeview);
1003 path = ghb_tree_path_new_from_indices(indices, len);
1006 if (gtk_tree_model_get_iter(store, &iter, path))
1008 gtk_tree_selection_select_iter (selection, &iter);
1012 if (gtk_tree_model_get_iter_first(store, &iter))
1013 gtk_tree_selection_select_iter (selection, &iter);
1015 gtk_tree_path_free(path);
1020 ghb_select_preset(GtkBuilder *builder, const GValue *path)
1024 g_debug("ghb_select_preset()");
1025 indices = ghb_preset_indices_from_path(presetsPlist, path, &len);
1028 ghb_select_preset2(builder, indices, len);
1034 ghb_select_default_preset(GtkBuilder *builder)
1038 g_debug("ghb_select_default_preset()");
1039 indices = presets_find_default(presetsPlist, &len);
1042 ghb_select_preset2(builder, indices, len);
1048 ghb_get_user_config_dir(gchar *subdir)
1053 dir = g_get_user_config_dir();
1054 if (!g_file_test(dir, G_FILE_TEST_IS_DIR))
1056 dir = g_get_home_dir();
1057 config = g_strdup_printf ("%s/.ghb", dir);
1058 if (!g_file_test(config, G_FILE_TEST_IS_DIR))
1059 g_mkdir (config, 0755);
1063 config = g_strdup_printf ("%s/ghb", dir);
1064 if (!g_file_test(config, G_FILE_TEST_IS_DIR))
1065 g_mkdir (config, 0755);
1072 split = g_strsplit(subdir, G_DIR_SEPARATOR_S, -1);
1073 for (ii = 0; split[ii] != NULL; ii++)
1077 tmp = g_strdup_printf ("%s/%s", config, split[ii]);
1080 if (!g_file_test(config, G_FILE_TEST_IS_DIR))
1081 g_mkdir (config, 0755);
1088 store_plist(GValue *plist, const gchar *name)
1090 gchar *config, *path;
1093 config = ghb_get_user_config_dir(NULL);
1094 path = g_strdup_printf ("%s/%s", config, name);
1095 file = g_fopen(path, "w");
1098 ghb_plist_write(file, plist);
1103 load_plist(const gchar *name)
1105 gchar *config, *path;
1106 GValue *plist = NULL;
1108 config = ghb_get_user_config_dir(NULL);
1109 path = g_strdup_printf ("%s/%s", config, name);
1110 if (g_file_test(path, G_FILE_TEST_IS_REGULAR))
1112 plist = ghb_plist_parse_file(path);
1120 ghb_lock_file(const gchar *name)
1122 #if !defined(_WIN32)
1123 gchar *config, *path;
1126 config = ghb_get_user_config_dir(NULL);
1127 path = g_strdup_printf ("%s/%s", config, name);
1128 fd = open(path, O_RDWR|O_CREAT, S_IRUSR|S_IWUSR);
1130 lock = lockf(fd, F_TLOCK, 0);
1142 remove_plist(const gchar *name)
1144 gchar *config, *path;
1146 config = ghb_get_user_config_dir(NULL);
1147 path = g_strdup_printf ("%s/%s", config, name);
1148 if (g_file_test(path, G_FILE_TEST_IS_REGULAR))
1156 static gboolean prefs_initializing = FALSE;
1159 ghb_prefs_to_ui(signal_user_data_t *ud)
1164 GValue *internal, *dict;
1165 GHashTableIter iter;
1168 g_debug("ghb_prefs_to_ui");
1169 prefs_initializing = TRUE;
1171 // Setting a ui widget will cause the corresponding setting
1172 // to be set, but it also triggers a callback that can
1173 // have the side effect of using other settings values
1174 // that have not yet been set. So set *all* settings first
1175 // then update the ui.
1176 internal = plist_get_dict(internalPlist, "Initialization");
1177 ghb_dict_iter_init(&iter, internal);
1178 // middle (void*) cast prevents gcc warning "defreferencing type-punned
1179 // pointer will break strict-aliasing rules"
1180 while (g_hash_table_iter_next(
1181 &iter, (gpointer*)(void*)&key, (gpointer*)(void*)&gval))
1183 ghb_ui_update(ud, key, gval);
1186 dict = plist_get_dict(prefsPlist, "Preferences");
1187 internal = plist_get_dict(internalPlist, "Preferences");
1188 ghb_dict_iter_init(&iter, internal);
1189 // middle (void*) cast prevents gcc warning "defreferencing type-punned
1190 // pointer will break strict-aliasing rules"
1191 while (g_hash_table_iter_next(
1192 &iter, (gpointer*)(void*)&key, (gpointer*)(void*)&gval))
1194 const GValue *value = NULL;
1196 value = ghb_dict_lookup(dict, key);
1199 ghb_settings_set_value(ud->settings, key, value);
1201 internal = plist_get_dict(internalPlist, "Preferences");
1202 ghb_dict_iter_init(&iter, internal);
1203 // middle (void*) cast prevents gcc warning "defreferencing type-punned
1204 // pointer will break strict-aliasing rules"
1205 while (g_hash_table_iter_next(
1206 &iter, (gpointer*)(void*)&key, (gpointer*)(void*)&gval))
1208 const GValue *value = NULL;
1210 value = ghb_dict_lookup(dict, key);
1213 ghb_ui_update(ud, key, value);
1216 val = ghb_settings_get_value(ud->settings, "show_presets");
1217 ghb_ui_update(ud, "show_presets", val);
1218 if (ghb_settings_get_boolean(ud->settings, "hbfd_feature"))
1221 val = ghb_settings_get_value(ud->settings, "hbfd");
1222 ghb_ui_update(ud, "hbfd", val);
1223 action = GHB_ACTION (ud->builder, "hbfd");
1224 gtk_action_set_visible(action, TRUE);
1228 ghb_ui_update(ud, "hbfd", ghb_int64_value(0));
1230 gval = ghb_settings_get_value(ud->settings, "default_source");
1231 ghb_settings_set_value (ud->settings, "source", gval);
1233 str = ghb_settings_get_string(ud->settings, "destination_dir");
1234 ghb_ui_update(ud, "dest_dir", ghb_string_value(str));
1236 gchar *file = g_strdup_printf ("new_video.mp4");
1237 ghb_ui_update(ud, "dest_file", ghb_string_value(file));
1241 prefs_initializing = FALSE;
1245 ghb_prefs_save(GValue *settings)
1249 GHashTableIter iter;
1251 const GValue *value;
1253 if (prefs_initializing) return;
1254 dict = plist_get_dict(internalPlist, "Preferences");
1255 if (dict == NULL) return;
1256 pref_dict = plist_get_dict(prefsPlist, "Preferences");
1257 if (pref_dict == NULL) return;
1258 ghb_dict_iter_init(&iter, dict);
1259 // middle (void*) cast prevents gcc warning "defreferencing type-punned
1260 // pointer will break strict-aliasing rules"
1261 while (g_hash_table_iter_next(
1262 &iter, (gpointer*)(void*)&key, (gpointer*)(void*)&value))
1264 value = ghb_settings_get_value(settings, key);
1267 ghb_dict_insert(pref_dict, g_strdup(key), ghb_value_dup(value));
1271 prefs_modified = FALSE;
1275 ghb_pref_set(GValue *settings, const gchar *key)
1277 const GValue *value, *value2;
1279 if (prefs_initializing) return;
1280 value = ghb_settings_get_value(settings, key);
1284 dict = plist_get_dict(prefsPlist, "Preferences");
1285 if (dict == NULL) return;
1286 value2 = ghb_dict_lookup(dict, key);
1287 if (ghb_value_cmp(value, value2) != 0)
1289 ghb_dict_insert(dict, g_strdup(key), ghb_value_dup(value));
1291 prefs_modified = TRUE;
1297 ghb_pref_save(GValue *settings, const gchar *key)
1299 const GValue *value, *value2;
1301 if (prefs_initializing) return;
1302 value = ghb_settings_get_value(settings, key);
1306 dict = plist_get_dict(prefsPlist, "Preferences");
1307 if (dict == NULL) return;
1308 value2 = ghb_dict_lookup(dict, key);
1309 if (ghb_value_cmp(value, value2) != 0)
1311 ghb_dict_insert(dict, g_strdup(key), ghb_value_dup(value));
1313 prefs_modified = FALSE;
1319 ghb_prefs_store(void)
1324 prefs_modified = FALSE;
1329 ghb_settings_init(signal_user_data_t *ud)
1332 GHashTableIter iter;
1337 g_debug("ghb_settings_init");
1338 prefs_initializing = TRUE;
1340 internalPlist = ghb_resource_get("internal-defaults");
1341 // Setting a ui widget will cause the corresponding setting
1342 // to be set, but it also triggers a callback that can
1343 // have the side effect of using other settings values
1344 // that have not yet been set. So set *all* settings first
1345 // then update the ui.
1346 internal = plist_get_dict(internalPlist, "Initialization");
1347 ghb_dict_iter_init(&iter, internal);
1348 // middle (void*) cast prevents gcc warning "defreferencing type-punned
1349 // pointer will break strict-aliasing rules"
1350 while (g_hash_table_iter_next(
1351 &iter, (gpointer*)(void*)&key, (gpointer*)(void*)&gval))
1353 ghb_settings_set_value(ud->settings, key, gval);
1356 internal = plist_get_dict(internalPlist, "Presets");
1357 ghb_dict_iter_init(&iter, internal);
1358 // middle (void*) cast prevents gcc warning "defreferencing type-punned
1359 // pointer will break strict-aliasing rules"
1360 while (g_hash_table_iter_next(
1361 &iter, (gpointer*)(void*)&key, (gpointer*)(void*)&gval))
1363 ghb_settings_set_value(ud->settings, key, gval);
1366 internal = plist_get_dict(internalPlist, "Preferences");
1367 ghb_dict_iter_init(&iter, internal);
1368 // middle (void*) cast prevents gcc warning "defreferencing type-punned
1369 // pointer will break strict-aliasing rules"
1370 while (g_hash_table_iter_next(
1371 &iter, (gpointer*)(void*)&key, (gpointer*)(void*)&gval))
1373 ghb_settings_set_value(ud->settings, key, gval);
1375 prefs_initializing = FALSE;
1379 ghb_settings_close()
1382 ghb_value_free(internalPlist);
1384 ghb_value_free(presetsPlist);
1386 ghb_value_free(prefsPlist);
1391 FindFirstCDROM(void)
1396 strcpy(drive, "A:" G_DIR_SEPARATOR_S);
1397 drives = GetLogicalDrives();
1398 for (ii = 0; ii < 26; ii++)
1404 drive[0] = 'A' + ii;
1405 dtype = GetDriveType(drive);
1406 if (dtype == DRIVE_CDROM)
1408 return g_strdup(drive);
1418 ghb_prefs_load(signal_user_data_t *ud)
1420 GValue *dict, *internal;
1421 GHashTableIter iter;
1423 GValue *gval, *path;
1425 g_debug("ghb_prefs_load");
1426 prefsPlist = load_plist("preferences");
1427 if (prefsPlist == NULL)
1428 prefsPlist = ghb_dict_value_new();
1429 dict = plist_get_dict(prefsPlist, "Preferences");
1430 internal = plist_get_dict(internalPlist, "Preferences");
1431 if (dict == NULL && internal)
1433 dict = ghb_dict_value_new();
1434 ghb_dict_insert(prefsPlist, g_strdup("Preferences"), dict);
1436 // Get defaults from internal defaults
1437 ghb_dict_iter_init(&iter, internal);
1438 // middle (void*) cast prevents gcc warning "defreferencing type-punned
1439 // pointer will break strict-aliasing rules"
1440 while (g_hash_table_iter_next(
1441 &iter, (gpointer*)(void*)&key, (gpointer*)(void*)&gval))
1443 ghb_dict_insert(dict, g_strdup(key), ghb_value_dup(gval));
1446 const gchar *dir = g_get_user_special_dir (G_USER_DIRECTORY_DESKTOP);
1451 ghb_dict_insert(dict,
1452 g_strdup("ExportDirectory"), ghb_value_dup(ghb_string_value(dir)));
1454 dir = g_get_user_special_dir (G_USER_DIRECTORY_VIDEOS);
1459 ghb_dict_insert(dict,
1460 g_strdup("destination_dir"), ghb_value_dup(ghb_string_value(dir)));
1462 ghb_dict_insert(dict,
1463 g_strdup("SrtDir"), ghb_value_dup(ghb_string_value(dir)));
1467 source = FindFirstCDROM();
1470 source = g_strdup("C:" G_DIR_SEPARATOR_S);
1472 ghb_dict_insert(dict, g_strdup("default_source"),
1473 ghb_value_dup(ghb_string_value(source)));
1478 // Read legacy default_preset preference and update accordingly
1479 path = ghb_dict_lookup(dict, "default_preset");
1484 if (G_VALUE_TYPE(path) == G_TYPE_STRING)
1488 path = ghb_array_value_new(1);
1489 ghb_array_append(path, ghb_value_dup(str));
1490 indices = ghb_preset_indices_from_path(presetsPlist, path, &len);
1491 ghb_value_free(path);
1494 indices = ghb_preset_indices_from_path(presetsPlist, path, &len);
1498 presets_set_default(indices, len);
1501 ghb_dict_remove(dict, "default_preset");
1507 get_preset_color(gint type, gboolean folder)
1511 if (type == PRESETS_CUSTOM)
1531 ghb_presets_list_init(
1532 signal_user_data_t *ud,
1536 GtkTreeView *treeview;
1537 GtkTreeIter iter, titer, *piter;
1539 GtkTreeStore *store;
1540 const gchar *preset;
1541 GtkTreePath *parent_path;
1542 const gchar *description;
1547 GValue *presets = NULL;
1549 g_debug("ghb_presets_list_init ()");
1550 more_indices = g_malloc((len+1)*sizeof(gint));
1551 memcpy(more_indices, indices, len*sizeof(gint));
1552 presets = presets_get_folder(presetsPlist, indices, len);
1553 if (presets == NULL)
1555 g_warning("Failed to find parent folder when adding child.");
1558 count = ghb_array_len(presets);
1559 treeview = GTK_TREE_VIEW(GHB_WIDGET(ud->builder, "presets_list"));
1560 store = GTK_TREE_STORE(gtk_tree_view_get_model(treeview));
1561 parent_path = ghb_tree_path_new_from_indices(indices, len);
1564 gtk_tree_model_get_iter(GTK_TREE_MODEL(store), &titer, parent_path);
1566 gtk_tree_path_free(parent_path);
1572 for (ii = 0; ii < count; ii++)
1578 // Additional settings, add row
1579 dict = ghb_array_get_nth(presets, ii);
1580 preset = preset_get_name(dict);
1581 more_indices[len] = ii;
1582 def = preset_is_default(dict);
1584 description = ghb_presets_get_description(dict);
1585 gtk_tree_store_append(store, &iter, piter);
1586 type = ghb_preset_type(dict);
1587 folder = ghb_preset_folder(dict);
1588 color = get_preset_color(type, folder);
1589 gtk_tree_store_set(store, &iter, 0, preset,
1594 5, type == PRESETS_BUILTIN ? 0 : 1,
1601 if (gtk_tree_model_iter_parent(
1602 GTK_TREE_MODEL(store), &ppiter, piter))
1604 path = gtk_tree_model_get_path(GTK_TREE_MODEL(store), &ppiter);
1605 gtk_tree_view_expand_row(treeview, path, FALSE);
1606 gtk_tree_path_free(path);
1608 path = gtk_tree_model_get_path(GTK_TREE_MODEL(store), piter);
1609 gtk_tree_view_expand_row(treeview, path, FALSE);
1610 gtk_tree_path_free(path);
1614 ghb_presets_list_init(ud, more_indices, len+1);
1615 if (preset_folder_is_open(dict))
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);
1625 path = gtk_tree_model_get_path(GTK_TREE_MODEL(store), &iter);
1626 gtk_tree_view_expand_row(treeview, path, FALSE);
1627 gtk_tree_path_free(path);
1631 g_free(more_indices);
1635 presets_list_update_item(
1636 signal_user_data_t *ud,
1641 GtkTreeView *treeview;
1642 GtkTreeStore *store;
1644 GtkTreePath *treepath;
1646 const gchar *description;
1648 gboolean def, folder;
1652 g_debug("presets_list_update_item ()");
1653 dict = presets_get_dict(presetsPlist, indices, len);
1656 treeview = GTK_TREE_VIEW(GHB_WIDGET(ud->builder, "presets_list"));
1657 store = GTK_TREE_STORE(gtk_tree_view_get_model(treeview));
1658 treepath = ghb_tree_path_new_from_indices(indices, len);
1659 gtk_tree_model_get_iter(GTK_TREE_MODEL(store), &iter, treepath);
1660 // Additional settings, add row
1661 name = preset_get_name(dict);
1662 def = preset_is_default(dict);
1664 description = ghb_presets_get_description(dict);
1665 type = ghb_preset_type(dict);
1666 folder = ghb_preset_folder(dict);
1667 color = get_preset_color(type, folder);
1668 gtk_tree_store_set(store, &iter, 0, name,
1673 5, type == PRESETS_BUILTIN ? 0 : 1,
1675 if (recurse && folder)
1677 ghb_presets_list_init(ud, indices, len);
1682 presets_list_insert(
1683 signal_user_data_t *ud,
1687 GtkTreeView *treeview;
1688 GtkTreeIter iter, titer, *piter;
1689 GtkTreeStore *store;
1690 const gchar *preset;
1691 const gchar *description;
1693 gboolean def, folder;
1696 GtkTreePath *parent_path;
1700 g_debug("presets_list_insert ()");
1701 treeview = GTK_TREE_VIEW(GHB_WIDGET(ud->builder, "presets_list"));
1702 store = GTK_TREE_STORE(gtk_tree_view_get_model(treeview));
1703 presets = presets_get_folder(presetsPlist, indices, len-1);
1704 if (presets == NULL)
1706 g_warning("Failed to find parent folder while adding child.");
1709 parent_path = ghb_tree_path_new_from_indices(indices, len-1);
1712 gtk_tree_model_get_iter(GTK_TREE_MODEL(store), &titer, parent_path);
1714 gtk_tree_path_free(parent_path);
1720 count = ghb_array_len(presets);
1721 if (indices[len-1] >= count)
1723 // Additional settings, add row
1724 dict = ghb_array_get_nth(presets, indices[len-1]);
1725 preset = preset_get_name(dict);
1726 def = preset_is_default(dict);
1728 description = ghb_presets_get_description(dict);
1729 gtk_tree_store_insert(store, &iter, piter, indices[len-1]);
1730 type = ghb_preset_type(dict);
1731 folder = ghb_preset_folder(dict);
1732 color = get_preset_color(type, folder);
1733 gtk_tree_store_set(store, &iter, 0, preset,
1738 5, type == PRESETS_BUILTIN ? 0 : 1,
1742 ghb_presets_list_init(ud, indices, len);
1747 presets_list_remove(
1748 signal_user_data_t *ud,
1752 GtkTreeView *treeview;
1753 GtkTreePath *treepath;
1755 GtkTreeStore *store;
1757 g_debug("presets_list_remove ()");
1758 treeview = GTK_TREE_VIEW(GHB_WIDGET(ud->builder, "presets_list"));
1759 store = GTK_TREE_STORE(gtk_tree_view_get_model(treeview));
1760 treepath = ghb_tree_path_new_from_indices(indices, len);
1763 if (gtk_tree_model_get_iter(GTK_TREE_MODEL(store), &iter, treepath))
1764 gtk_tree_store_remove(store, &iter);
1765 gtk_tree_path_free(treepath);
1770 remove_std_presets(signal_user_data_t *ud)
1775 count = ghb_array_len(presetsPlist);
1776 for (ii = count-1; ii >= 0; ii--)
1781 dict = ghb_array_get_nth(presetsPlist, ii);
1782 ptype = ghb_value_int(preset_dict_get_value(dict, "Type"));
1783 if (ptype == PRESETS_BUILTIN)
1785 if (ghb_presets_remove(presetsPlist, &indices, 1))
1787 presets_list_remove(ud, &indices, 1);
1794 ghb_save_queue(GValue *queue)
1796 store_plist(queue, "queue");
1802 return load_plist("queue");
1806 ghb_remove_queue_file()
1808 remove_plist("queue");
1817 static value_map_t vcodec_xlat[] =
1819 {"MPEG-4 (FFmpeg)", "ffmpeg"},
1820 {"MPEG-4 (XviD)", "ffmpeg"},
1821 {"H.264 (x264)", "x264"},
1822 {"VP3 (Theora)", "theora"},
1826 static value_map_t acodec_xlat[] =
1828 {"AAC (faac)", "faac"},
1829 {"AAC (CoreAudio)", "faac"},
1830 {"AC3 Passthru", "ac3"},
1831 {"MP3 (lame)", "lame"},
1832 {"Vorbis (vorbis)", "vorbis"},
1836 value_map_t container_xlat[] =
1838 {"MP4 file", "mp4"},
1839 {"M4V file", "mp4"},
1840 {"MKV file", "mkv"},
1841 {"AVI file", "mkv"},
1842 {"OGM file", "mkv"},
1846 value_map_t framerate_xlat[] =
1848 {"Same as source", "source"},
1853 {"23.976", "23.976"},
1860 value_map_t samplerate_xlat[] =
1871 value_map_t mix_xlat[] =
1874 {"Stereo", "stereo"},
1875 {"Dolby Surround", "dpl1"},
1876 {"Dolby Pro Logic II", "dpl2"},
1877 {"6-channel discrete", "6ch"},
1878 {"AC3 Passthru", "none"},
1882 value_map_t deint_xlat[] =
1892 value_map_t denoise_xlat[] =
1902 value_map_t detel_xlat[] =
1910 value_map_t decomb_xlat[] =
1918 extern iso639_lang_t ghb_language_table[];
1921 export_lang_xlat2(GValue *lin_val)
1925 if (lin_val == NULL) return NULL;
1929 str = ghb_value_string(lin_val);
1930 for (ii = 0; ghb_language_table[ii].eng_name; ii++)
1932 if (strcmp(str, ghb_language_table[ii].iso639_2) == 0)
1936 if (ghb_language_table[ii].native_name[0] != 0)
1937 lang = ghb_language_table[ii].native_name;
1939 lang = ghb_language_table[ii].eng_name;
1941 gval = ghb_string_value_new(lang);
1946 g_debug("Can't map language value: (%s)", str);
1952 export_subtitle_xlat2(GValue *lin_val)
1957 if (lin_val == NULL) return NULL;
1958 str = ghb_value_string(lin_val);
1959 if (strcmp(str, "none") == 0)
1961 gval = ghb_string_value_new("None");
1963 else if (strcmp(str, "auto") == 0)
1965 gval = ghb_string_value_new("Autoselect");
1969 gval = export_lang_xlat2(lin_val);
1976 import_lang_xlat2(GValue *mac_val)
1980 if (mac_val == NULL) return NULL;
1984 str = ghb_value_string(mac_val);
1985 for (ii = 0; ghb_language_table[ii].eng_name; ii++)
1987 if ((strcmp(str, ghb_language_table[ii].eng_name) == 0) ||
1988 (strcmp(str, ghb_language_table[ii].native_name) == 0))
1990 gval = ghb_string_value_new(ghb_language_table[ii].iso639_2);
1995 g_debug("Can't map language value: (%s)", str);
2001 import_subtitle_xlat2(GValue *mac_val)
2006 if (mac_val == NULL) return NULL;
2007 str = ghb_value_string(mac_val);
2008 if (strcmp(str, "None") == 0)
2010 gval = ghb_string_value_new("none");
2012 else if (strcmp(str, "Autoselect") == 0)
2014 gval = ghb_string_value_new("auto");
2018 gval = import_lang_xlat2(mac_val);
2025 export_audio_track_xlat2(GValue *lin_val)
2028 GValue *gval = NULL;
2030 if (lin_val == NULL) return NULL;
2031 str = ghb_value_string(lin_val);
2032 if (strcmp(str, "none") == 0)
2034 gval = ghb_int_value_new(1);
2038 gint val = ghb_value_int(lin_val) + 1;
2039 gval = ghb_int_value_new(val);
2046 import_audio_track_xlat2(GValue *mac_val)
2052 if (mac_val == NULL) return NULL;
2053 val = ghb_value_int(mac_val);
2062 str = g_strdup_printf("%d", val);
2063 gval = ghb_string_value_new(str);
2069 export_value_xlat2(value_map_t *value_map, GValue *lin_val, GType mac_type)
2073 if (lin_val == NULL) return NULL;
2078 str = ghb_value_string(lin_val);
2079 for (ii = 0; value_map[ii].mac_val; ii++)
2081 if (strcmp(str, value_map[ii].lin_val) == 0)
2083 sval = ghb_string_value_new(value_map[ii].mac_val);
2085 gval = ghb_value_new(mac_type);
2086 if (!g_value_transform(sval, gval))
2088 g_warning("can't transform");
2089 ghb_value_free(gval);
2090 ghb_value_free(sval);
2093 ghb_value_free(sval);
2097 g_debug("Can't map value: (%s)", str);
2103 export_value_xlat(GValue *dict)
2105 GValue *lin_val, *gval;
2108 key = "VideoEncoder";
2109 lin_val = ghb_dict_lookup(dict, key);
2110 gval = export_value_xlat2(vcodec_xlat, lin_val, G_TYPE_STRING);
2112 ghb_dict_insert(dict, g_strdup(key), gval);
2114 lin_val = ghb_dict_lookup(dict, key);
2115 gval = export_value_xlat2(container_xlat, lin_val, G_TYPE_STRING);
2117 ghb_dict_insert(dict, g_strdup(key), gval);
2118 key = "VideoFramerate";
2119 lin_val = ghb_dict_lookup(dict, key);
2120 gval = export_value_xlat2(framerate_xlat, lin_val, G_TYPE_STRING);
2122 ghb_dict_insert(dict, g_strdup(key), gval);
2123 key = "PictureDetelecine";
2124 lin_val = ghb_dict_lookup(dict, key);
2125 gval = export_value_xlat2(detel_xlat, lin_val, G_TYPE_INT);
2127 ghb_dict_insert(dict, g_strdup(key), gval);
2128 key = "PictureDecomb";
2129 lin_val = ghb_dict_lookup(dict, key);
2130 gval = export_value_xlat2(decomb_xlat, lin_val, G_TYPE_INT);
2132 ghb_dict_insert(dict, g_strdup(key), gval);
2133 key = "PictureDeinterlace";
2134 lin_val = ghb_dict_lookup(dict, key);
2135 gval = export_value_xlat2(deint_xlat, lin_val, G_TYPE_INT);
2137 ghb_dict_insert(dict, g_strdup(key), gval);
2138 key = "PictureDenoise";
2139 lin_val = ghb_dict_lookup(dict, key);
2140 gval = export_value_xlat2(denoise_xlat, lin_val, G_TYPE_INT);
2142 ghb_dict_insert(dict, g_strdup(key), gval);
2148 slist = ghb_dict_lookup(dict, "SubtitleList");
2149 count = ghb_array_len(slist);
2150 for (ii = 0; ii < count; ii++)
2152 sdict = ghb_array_get_nth(slist, ii);
2153 key = "SubtitleLanguage";
2154 lin_val = ghb_dict_lookup(sdict, key);
2155 gval = export_subtitle_xlat2(lin_val);
2157 ghb_dict_insert(sdict, g_strdup(key), gval);
2163 alist = ghb_dict_lookup(dict, "AudioList");
2164 count = ghb_array_len(alist);
2165 for (ii = 0; ii < count; ii++)
2167 adict = ghb_array_get_nth(alist, ii);
2169 lin_val = ghb_dict_lookup(adict, key);
2170 gval = export_audio_track_xlat2(lin_val);
2172 ghb_dict_insert(adict, g_strdup(key), gval);
2173 key = "AudioEncoder";
2174 lin_val = ghb_dict_lookup(adict, key);
2175 gval = export_value_xlat2(acodec_xlat, lin_val, G_TYPE_STRING);
2177 ghb_dict_insert(adict, g_strdup(key), gval);
2178 key = "AudioSamplerate";
2179 lin_val = ghb_dict_lookup(adict, key);
2180 gval = export_value_xlat2(samplerate_xlat, lin_val, G_TYPE_STRING);
2182 ghb_dict_insert(adict, g_strdup(key), gval);
2183 key = "AudioMixdown";
2184 lin_val = ghb_dict_lookup(adict, key);
2185 gval = export_value_xlat2(mix_xlat, lin_val, G_TYPE_STRING);
2187 ghb_dict_insert(adict, g_strdup(key), gval);
2195 value_map_t *value_map,
2199 GValue *gval, *def_val;
2201 if (mac_val == NULL) return NULL;
2202 def_val = ghb_dict_lookup(defaults, key);
2209 str = ghb_value_string(mac_val);
2210 for (ii = 0; value_map[ii].mac_val; ii++)
2212 if (strcmp(str, value_map[ii].mac_val) == 0)
2214 sval = ghb_string_value_new(value_map[ii].lin_val);
2216 gval = ghb_value_new(G_VALUE_TYPE(def_val));
2217 if (!g_value_transform(sval, gval))
2219 g_warning("can't transform");
2220 ghb_value_free(gval);
2221 ghb_value_free(sval);
2224 ghb_value_free(sval);
2236 str = ghb_value_string(mac_val);
2237 for (ii = 0; value_map[ii].mac_val; ii++)
2239 if (strcmp(str, value_map[ii].mac_val) == 0)
2241 sval = ghb_string_value_new(value_map[ii].lin_val);
2243 gval = ghb_value_new(G_VALUE_TYPE(mac_val));
2244 if (!g_value_transform(sval, gval))
2246 g_warning("can't transform");
2247 ghb_value_free(gval);
2248 ghb_value_free(sval);
2251 ghb_value_free(sval);
2261 import_value_xlat(GValue *dict)
2263 GValue *defaults, *mac_val, *gval;
2266 defaults = plist_get_dict(internalPlist, "Presets");
2267 key = "VideoEncoder";
2268 mac_val = ghb_dict_lookup(dict, key);
2269 gval = import_value_xlat2(defaults, vcodec_xlat, key, mac_val);
2271 ghb_dict_insert(dict, g_strdup(key), gval);
2273 mac_val = ghb_dict_lookup(dict, key);
2274 gval = import_value_xlat2(defaults, container_xlat, key, mac_val);
2276 ghb_dict_insert(dict, g_strdup(key), gval);
2277 key = "VideoFramerate";
2278 mac_val = ghb_dict_lookup(dict, key);
2279 gval = import_value_xlat2(defaults, framerate_xlat, key, mac_val);
2281 ghb_dict_insert(dict, g_strdup(key), gval);
2282 key = "PictureDetelecine";
2283 mac_val = ghb_dict_lookup(dict, key);
2284 gval = import_value_xlat2(defaults, detel_xlat, key, mac_val);
2286 ghb_dict_insert(dict, g_strdup(key), gval);
2287 key = "PictureDecomb";
2288 mac_val = ghb_dict_lookup(dict, key);
2289 gval = import_value_xlat2(defaults, decomb_xlat, key, mac_val);
2291 ghb_dict_insert(dict, g_strdup(key), gval);
2292 key = "PictureDeinterlace";
2293 mac_val = ghb_dict_lookup(dict, key);
2294 gval = import_value_xlat2(defaults, deint_xlat, key, mac_val);
2296 ghb_dict_insert(dict, g_strdup(key), gval);
2297 key = "PictureDenoise";
2298 mac_val = ghb_dict_lookup(dict, key);
2299 gval = import_value_xlat2(defaults, denoise_xlat, key, mac_val);
2301 ghb_dict_insert(dict, g_strdup(key), gval);
2310 sdeflist = ghb_dict_lookup(defaults, "SubtitleList");
2313 slist = ghb_dict_lookup(dict, "SubtitleList");
2316 sdefaults = ghb_array_get_nth(sdeflist, 0);
2317 count = ghb_array_len(slist);
2318 for (ii = 0; ii < count; ii++)
2320 sdict = ghb_array_get_nth(slist, ii);
2321 key = "SubtitleLanguage";
2322 mac_val = ghb_dict_lookup(sdict, key);
2323 gval = import_subtitle_xlat2(mac_val);
2325 ghb_dict_insert(sdict, g_strdup(key), gval);
2332 mac_val = ghb_dict_lookup(dict, key);
2333 slist = ghb_array_value_new(8);
2334 ghb_dict_insert(dict, g_strdup("SubtitleList"), slist);
2339 gval = import_subtitle_xlat2(mac_val);
2340 lang = ghb_value_string(gval);
2341 if (lang && strcasecmp(lang, "none") != 0 && !slist)
2343 sdict = ghb_dict_value_new();
2344 ghb_array_append(slist, sdict);
2345 ghb_dict_insert(sdict, g_strdup("SubtitleLanguage"), gval);
2346 gval = ghb_dict_lookup(dict, "SubtitlesForced");
2349 ghb_dict_insert(sdict, g_strdup("SubtitleForced"),
2350 ghb_value_dup(gval));
2354 ghb_dict_insert(sdict, g_strdup("SubtitleForced"),
2355 ghb_boolean_value_new(FALSE));
2357 ghb_dict_insert(sdict, g_strdup("SubtitleBurned"),
2358 ghb_boolean_value_new(TRUE));
2359 ghb_dict_insert(sdict, g_strdup("SubtitleDefaultTrack"),
2360 ghb_boolean_value_new(FALSE));
2364 ghb_value_free(gval);
2371 ghb_dict_remove(dict, "Subtitles");
2372 ghb_dict_remove(dict, "SubtitlesForced");
2380 adeflist = ghb_dict_lookup(defaults, "AudioList");
2383 adefaults = ghb_array_get_nth(adeflist, 0);
2384 alist = ghb_dict_lookup(dict, "AudioList");
2385 count = ghb_array_len(alist);
2386 for (ii = 0; ii < count; ii++)
2388 adict = ghb_array_get_nth(alist, ii);
2390 mac_val = ghb_dict_lookup(adict, key);
2391 gval = import_audio_track_xlat2(mac_val);
2393 ghb_dict_insert(adict, g_strdup(key), gval);
2394 key = "AudioEncoder";
2395 mac_val = ghb_dict_lookup(adict, key);
2396 gval = import_value_xlat2(adefaults, acodec_xlat, key, mac_val);
2398 ghb_dict_insert(adict, g_strdup(key), gval);
2399 key = "AudioSamplerate";
2400 mac_val = ghb_dict_lookup(adict, key);
2401 gval = import_value_xlat2(adefaults, samplerate_xlat, key, mac_val);
2403 ghb_dict_insert(adict, g_strdup(key), gval);
2404 key = "AudioMixdown";
2405 mac_val = ghb_dict_lookup(adict, key);
2406 gval = import_value_xlat2(adefaults, mix_xlat, key, mac_val);
2408 ghb_dict_insert(adict, g_strdup(key), gval);
2410 mac_val = ghb_dict_lookup(adict, "AudioTrackDRCSlider");
2411 if (mac_val != NULL)
2414 drc = ghb_value_double(mac_val);
2415 if (drc < 1.0 && drc > 0.0)
2417 ghb_dict_insert(adict, g_strdup("AudioTrackDRCSlider"),
2418 ghb_double_value_new(0.0));
2426 import_xlat_preset(GValue *dict)
2433 g_debug("import_xlat_preset ()");
2434 uses_max = ghb_value_boolean(
2435 preset_dict_get_value(dict, "UsesMaxPictureSettings"));
2436 uses_pic = ghb_value_int(
2437 preset_dict_get_value(dict, "UsesPictureSettings"));
2438 par = ghb_value_int(preset_dict_get_value(dict, "PicturePAR"));
2439 vqtype = ghb_value_int(preset_dict_get_value(dict, "VideoQualityType"));
2441 if (uses_max || uses_pic == 2)
2443 ghb_dict_insert(dict, g_strdup("autoscale"),
2444 ghb_boolean_value_new(TRUE));
2450 if (ghb_dict_lookup(dict, "PictureModulus") == NULL)
2451 ghb_dict_insert(dict, g_strdup("PictureModulus"),
2452 ghb_int_value_new(16));
2456 ghb_dict_insert(dict, g_strdup("PictureModulus"),
2457 ghb_int_value_new(1));
2461 if (ghb_dict_lookup(dict, "PictureModulus") == NULL)
2462 ghb_dict_insert(dict, g_strdup("PictureModulus"),
2463 ghb_int_value_new(16));
2467 if (ghb_dict_lookup(dict, "PictureModulus") == NULL)
2468 ghb_dict_insert(dict, g_strdup("PictureModulus"),
2469 ghb_int_value_new(16));
2472 // VideoQualityType/0/1/2 - vquality_type_/target/bitrate/constant
2477 ghb_dict_insert(dict, g_strdup("vquality_type_target"),
2478 ghb_boolean_value_new(TRUE));
2479 ghb_dict_insert(dict, g_strdup("vquality_type_bitrate"),
2480 ghb_boolean_value_new(FALSE));
2481 ghb_dict_insert(dict, g_strdup("vquality_type_constant"),
2482 ghb_boolean_value_new(FALSE));
2486 ghb_dict_insert(dict, g_strdup("vquality_type_target"),
2487 ghb_boolean_value_new(FALSE));
2488 ghb_dict_insert(dict, g_strdup("vquality_type_bitrate"),
2489 ghb_boolean_value_new(TRUE));
2490 ghb_dict_insert(dict, g_strdup("vquality_type_constant"),
2491 ghb_boolean_value_new(FALSE));
2495 ghb_dict_insert(dict, g_strdup("vquality_type_target"),
2496 ghb_boolean_value_new(FALSE));
2497 ghb_dict_insert(dict, g_strdup("vquality_type_bitrate"),
2498 ghb_boolean_value_new(FALSE));
2499 ghb_dict_insert(dict, g_strdup("vquality_type_constant"),
2500 ghb_boolean_value_new(TRUE));
2504 ghb_dict_insert(dict, g_strdup("vquality_type_target"),
2505 ghb_boolean_value_new(FALSE));
2506 ghb_dict_insert(dict, g_strdup("vquality_type_bitrate"),
2507 ghb_boolean_value_new(FALSE));
2508 ghb_dict_insert(dict, g_strdup("vquality_type_constant"),
2509 ghb_boolean_value_new(TRUE));
2512 import_value_xlat(dict);
2517 vquality = ghb_value_double(preset_dict_get_value(dict, "VideoQualitySlider"));
2522 gval = preset_dict_get_value(dict, "VideoEncoder");
2523 vcodec = ghb_lookup_combo_int("VideoEncoder", gval);
2526 case HB_VCODEC_X264:
2528 vquality = 51. - vquality * 51.;
2531 case HB_VCODEC_FFMPEG:
2533 vquality = 31. - vquality * 30.;
2536 case HB_VCODEC_THEORA:
2538 vquality = vquality * 63.;
2546 ghb_dict_insert(dict, g_strdup("VideoQualitySlider"),
2547 ghb_double_value_new(vquality));
2552 import_xlat_presets(GValue *presets)
2558 g_debug("import_xlat_presets ()");
2559 if (presets == NULL) return;
2560 count = ghb_array_len(presets);
2561 for (ii = 0; ii < count; ii++)
2563 dict = ghb_array_get_nth(presets, ii);
2564 folder = ghb_value_boolean(preset_dict_get_value(dict, "Folder"));
2569 nested = ghb_dict_lookup(dict, "ChildrenArray");
2570 import_xlat_presets(nested);
2574 import_xlat_preset(dict);
2580 export_xlat_preset(GValue *dict)
2582 gboolean autoscale, target, br, constant;
2584 g_debug("export_xlat_prest ()");
2585 autoscale = ghb_value_boolean(preset_dict_get_value(dict, "autoscale"));
2586 target = ghb_value_boolean(
2587 preset_dict_get_value(dict, "vquality_type_target"));
2588 br = ghb_value_boolean(
2589 preset_dict_get_value(dict, "vquality_type_bitrate"));
2590 constant = ghb_value_boolean(
2591 preset_dict_get_value(dict, "vquality_type_constant"));
2594 ghb_dict_insert(dict, g_strdup("UsesPictureSettings"),
2595 ghb_int_value_new(2));
2597 ghb_dict_insert(dict, g_strdup("UsesPictureSettings"),
2598 ghb_int_value_new(1));
2600 // VideoQualityType/0/1/2 - vquality_type_/target/bitrate/constant
2603 ghb_dict_insert(dict, g_strdup("VideoQualityType"),
2604 ghb_int_value_new(0));
2608 ghb_dict_insert(dict, g_strdup("VideoQualityType"),
2609 ghb_int_value_new(1));
2613 ghb_dict_insert(dict, g_strdup("VideoQualityType"),
2614 ghb_int_value_new(2));
2617 GValue *alist, *adict;
2620 alist = ghb_dict_lookup(dict, "AudioList");
2621 count = ghb_array_len(alist);
2622 for (ii = 0; ii < count; ii++)
2626 adict = ghb_array_get_nth(alist, ii);
2627 drc = ghb_value_double(
2628 preset_dict_get_value(adict, "AudioTrackDRCSlider"));
2629 if (drc < 1.0 && drc > 0.0)
2631 ghb_dict_insert(adict, g_strdup("AudioTrackDRCSlider"),
2632 ghb_double_value_new(0.0));
2636 ghb_dict_remove(dict, "UsesMaxPictureSettings");
2637 ghb_dict_remove(dict, "autoscale");
2638 ghb_dict_remove(dict, "vquality_type_target");
2639 ghb_dict_remove(dict, "vquality_type_bitrate");
2640 ghb_dict_remove(dict, "vquality_type_constant");
2641 export_value_xlat(dict);
2645 export_xlat_presets(GValue *presets)
2651 if (presets == NULL) return;
2652 count = ghb_array_len(presets);
2653 for (ii = 0; ii < count; ii++)
2655 dict = ghb_array_get_nth(presets, ii);
2656 folder = ghb_value_boolean(preset_dict_get_value(dict, "Folder"));
2661 nested = ghb_dict_lookup(dict, "ChildrenArray");
2662 export_xlat_presets(nested);
2666 export_xlat_preset(dict);
2671 static guint prefs_timeout_id = 0;
2674 delayed_store_prefs(gpointer data)
2676 store_plist(prefsPlist, "preferences");
2677 prefs_timeout_id = 0;
2686 export = ghb_value_dup(presetsPlist);
2687 export_xlat_presets(export);
2688 store_plist(export, "presets");
2689 ghb_value_free(export);
2695 if (prefs_timeout_id != 0)
2700 mc = g_main_context_default();
2701 source = g_main_context_find_source_by_id(mc, prefs_timeout_id);
2703 g_source_destroy(source);
2705 prefs_timeout_id = g_timeout_add_seconds(1, (GSourceFunc)delayed_store_prefs, NULL);
2709 ghb_presets_reload(signal_user_data_t *ud)
2711 GValue *std_presets;
2715 g_debug("ghb_presets_reload()\n");
2716 std_presets = ghb_resource_get("standard-presets");
2717 if (std_presets == NULL) return;
2719 remove_std_presets(ud);
2720 indices = presets_find_default(presetsPlist, &len);
2723 presets_clear_default(std_presets);
2726 // Merge the keyfile contents into our presets
2727 count = ghb_array_len(std_presets);
2728 for (ii = count-1; ii >= 0; ii--)
2734 std_dict = ghb_array_get_nth(std_presets, ii);
2735 copy_dict = ghb_value_dup(std_dict);
2736 ghb_dict_insert(copy_dict, g_strdup("PresetBuildNumber"),
2737 ghb_int64_value_new(hb_get_build(NULL)));
2738 ghb_presets_insert(presetsPlist, copy_dict, &indices, 1);
2739 presets_list_insert(ud, &indices, 1);
2741 import_xlat_presets(presetsPlist);
2750 count = ghb_array_len(presetsPlist);
2751 for (ii = count-1; ii >= 0; ii--)
2756 dict = ghb_array_get_nth(presetsPlist, ii);
2757 type = ghb_dict_lookup(dict, "Type");
2765 replace_standard_presets()
2767 GValue *std_presets;
2771 count = ghb_array_len(presetsPlist);
2772 for (ii = count-1; ii >= 0; ii--)
2777 dict = ghb_array_get_nth(presetsPlist, ii);
2778 ptype = ghb_value_int(preset_dict_get_value(dict, "Type"));
2779 if (ptype == PRESETS_BUILTIN)
2782 ghb_presets_remove(presetsPlist, &indices, 1);
2786 std_presets = ghb_resource_get("standard-presets");
2787 if (std_presets == NULL) return;
2789 indices = presets_find_default(presetsPlist, &len);
2792 presets_clear_default(std_presets);
2795 // Merge the keyfile contents into our presets
2796 count = ghb_array_len(std_presets);
2797 for (ii = count-1; ii >= 0; ii--)
2803 std_dict = ghb_array_get_nth(std_presets, ii);
2804 copy_dict = ghb_value_dup(std_dict);
2805 ghb_dict_insert(copy_dict, g_strdup("PresetBuildNumber"),
2806 ghb_int64_value_new(hb_get_build(NULL)));
2807 ghb_presets_insert(presetsPlist, copy_dict, &indices, 1);
2809 import_xlat_presets(presetsPlist);
2814 update_standard_presets(signal_user_data_t *ud)
2818 count = ghb_array_len(presetsPlist);
2819 for (ii = count-1; ii >= 0; ii--)
2826 dict = ghb_array_get_nth(presetsPlist, ii);
2827 gval = ghb_dict_lookup(dict, "Type");
2830 // Old preset that doesn't have a Type
2831 replace_standard_presets();
2835 type = ghb_value_int(gval);
2838 gval = ghb_dict_lookup(dict, "PresetBuildNumber");
2841 // Old preset that doesn't have a build number
2842 replace_standard_presets();
2846 build = ghb_value_int64(gval);
2847 if (build != hb_get_build(NULL))
2849 // Build number does not match
2850 replace_standard_presets();
2859 ghb_presets_load(signal_user_data_t *ud)
2861 presetsPlist = load_plist("presets");
2862 if (presetsPlist == NULL)
2864 presetsPlist = ghb_value_dup(ghb_resource_get("standard-presets"));
2865 import_xlat_presets(presetsPlist);
2868 else if (G_VALUE_TYPE(presetsPlist) == ghb_dict_get_type())
2869 { // Presets is older dictionary format. Convert to array
2870 ghb_value_free(presetsPlist);
2871 presetsPlist = ghb_value_dup(ghb_resource_get("standard-presets"));
2872 import_xlat_presets(presetsPlist);
2875 else if (check_old_presets())
2877 ghb_value_free(presetsPlist);
2878 presetsPlist = ghb_value_dup(ghb_resource_get("standard-presets"));
2879 import_xlat_presets(presetsPlist);
2882 update_standard_presets(ud);
2883 import_xlat_presets(presetsPlist);
2887 settings_save(signal_user_data_t *ud, const GValue *path)
2889 GValue *dict, *internal;
2890 GHashTableIter iter;
2894 gint *indices, len, count;
2895 gint *def_indices, def_len;
2897 gboolean replace = FALSE;
2899 g_debug("settings_save");
2900 if (internalPlist == NULL) return;
2901 count = ghb_array_len(path);
2902 name = g_value_get_string(ghb_array_get_nth(path, count-1));
2903 indices = ghb_preset_indices_from_path(presetsPlist, path, &len);
2906 if (ghb_presets_get_folder(presetsPlist, indices, len))
2909 message = g_strdup_printf(
2910 "%s: Folder already exists.\n"
2911 "You can not replace it with a preset.",
2913 ghb_message_dialog(GTK_MESSAGE_ERROR, message, "Cancel", NULL);
2917 dict = ghb_dict_value_new();
2918 ghb_presets_replace(presetsPlist, dict, indices, len);
2923 indices = presets_find_pos(path, PRESETS_CUSTOM, &len);
2926 dict = ghb_dict_value_new();
2927 ghb_presets_insert(presetsPlist, dict, indices, len);
2931 g_warning("failed to find insert path");
2935 current_preset = dict;
2936 autoscale = ghb_settings_get_boolean(ud->settings, "autoscale");
2937 ghb_settings_set_int64(ud->settings, "Type", PRESETS_CUSTOM);
2938 ghb_settings_set_int64(ud->settings, "PresetBuildNumber", hb_get_build(NULL));
2940 internal = plist_get_dict(internalPlist, "Presets");
2941 ghb_dict_iter_init(&iter, internal);
2942 // middle (void*) cast prevents gcc warning "defreferencing type-punned
2943 // pointer will break strict-aliasing rules"
2944 while (g_hash_table_iter_next(
2945 &iter, (gpointer*)(void*)&key, (gpointer*)(void*)&value))
2953 if (strcmp(key, "PictureWidth") == 0)
2955 key2 = "scale_width";
2957 else if (strcmp(key, "PictureHeight") == 0)
2959 key2 = "scale_height";
2962 gval = ghb_settings_get_value(ud->settings, key2);
2967 ghb_dict_insert(dict, g_strdup(key), ghb_value_dup(gval));
2969 internal = plist_get_dict(internalPlist, "XlatPresets");
2970 ghb_dict_iter_init(&iter, internal);
2971 // middle (void*) cast prevents gcc warning "defreferencing type-punned
2972 // pointer will break strict-aliasing rules"
2973 while (g_hash_table_iter_next(
2974 &iter, (gpointer*)(void*)&key, (gpointer*)(void*)&value))
2978 gval = ghb_settings_get_value(ud->settings, key);
2983 ghb_dict_insert(dict, g_strdup(key), ghb_value_dup(gval));
2985 ghb_dict_insert(dict, g_strdup("PresetName"), ghb_string_value_new(name));
2988 def_indices = presets_find_default(presetsPlist, &def_len);
2989 if (def_indices != NULL &&
2990 preset_path_cmp(indices, len, def_indices, def_len) != 0)
2992 ghb_dict_insert(dict, g_strdup("Default"),
2993 ghb_boolean_value_new(FALSE));
2995 presets_list_update_item(ud, indices, len, FALSE);
2999 ghb_dict_insert(dict, g_strdup("Default"),
3000 ghb_boolean_value_new(FALSE));
3001 presets_list_insert(ud, indices, len);
3004 ud->dont_clear_presets = TRUE;
3005 // Make the new preset the selected item
3006 ghb_select_preset2(ud->builder, indices, len);
3008 ud->dont_clear_presets = FALSE;
3013 folder_save(signal_user_data_t *ud, const GValue *path)
3015 GValue *dict, *folder;
3016 gint *indices, len, count;
3019 count = ghb_array_len(path);
3020 name = g_value_get_string(ghb_array_get_nth(path, count-1));
3021 indices = ghb_preset_indices_from_path(presetsPlist, path, &len);
3024 if (!ghb_presets_get_folder(presetsPlist, indices, len))
3027 message = g_strdup_printf(
3028 "%s: Preset already exists.\n"
3029 "You can not replace it with a folder.",
3031 ghb_message_dialog(GTK_MESSAGE_ERROR, message, "Cancel", NULL);
3036 // Already exists, update its description
3037 dict = presets_get_dict(presetsPlist, indices, len);
3038 ghb_dict_insert(dict, g_strdup("PresetDescription"),
3039 ghb_value_dup(preset_dict_get_value(
3040 ud->settings, "PresetDescription")));
3041 presets_list_update_item(ud, indices, len, FALSE);
3048 indices = presets_find_pos(path, PRESETS_CUSTOM, &len);
3051 dict = ghb_dict_value_new();
3052 ghb_presets_insert(presetsPlist, dict, indices, len);
3056 g_warning("failed to find insert path");
3060 ghb_dict_insert(dict, g_strdup("PresetDescription"),
3061 ghb_value_dup(preset_dict_get_value(
3062 ud->settings, "PresetDescription")));
3063 ghb_dict_insert(dict, g_strdup("PresetName"), ghb_string_value_new(name));
3064 folder = ghb_array_value_new(8);
3065 ghb_dict_insert(dict, g_strdup("ChildrenArray"), folder);
3066 ghb_dict_insert(dict, g_strdup("Type"),
3067 ghb_int64_value_new(PRESETS_CUSTOM));
3068 ghb_dict_insert(dict, g_strdup("Folder"), ghb_boolean_value_new(TRUE));
3070 presets_list_insert(ud, indices, len);
3077 ghb_presets_list_default(signal_user_data_t *ud)
3079 GtkTreeView *treeview;
3080 GtkTreePath *treepath;
3082 GtkTreeStore *store;
3085 g_debug("ghb_presets_list_default ()");
3086 treeview = GTK_TREE_VIEW(GHB_WIDGET(ud->builder, "presets_list"));
3087 store = GTK_TREE_STORE(gtk_tree_view_get_model(treeview));
3088 indices = presets_find_default(presetsPlist, &len);
3089 if (indices == NULL) return;
3090 treepath = ghb_tree_path_new_from_indices(indices, len);
3093 if (gtk_tree_model_get_iter(GTK_TREE_MODEL(store), &iter, treepath))
3095 gtk_tree_store_set(store, &iter,
3100 gtk_tree_path_free(treepath);
3106 ghb_presets_list_clear_default(signal_user_data_t *ud)
3108 GtkTreeView *treeview;
3109 GtkTreePath *treepath;
3111 GtkTreeStore *store;
3114 g_debug("ghb_presets_list_clear_default ()");
3115 treeview = GTK_TREE_VIEW(GHB_WIDGET(ud->builder, "presets_list"));
3116 store = GTK_TREE_STORE(gtk_tree_view_get_model(treeview));
3117 indices = presets_find_default(presetsPlist, &len);
3118 if (indices == NULL) return;
3119 treepath = ghb_tree_path_new_from_indices(indices, len);
3122 if (gtk_tree_model_get_iter(GTK_TREE_MODEL(store), &iter, treepath))
3124 gtk_tree_store_set(store, &iter,
3129 gtk_tree_path_free(treepath);
3135 update_audio_presets(signal_user_data_t *ud)
3137 g_debug("update_audio_presets");
3138 const GValue *audio_list;
3140 audio_list = ghb_settings_get_value(ud->settings, "audio_list");
3141 ghb_settings_set_value(ud->settings, "AudioList", audio_list);
3145 update_subtitle_presets(signal_user_data_t *ud)
3147 g_debug("update_subtitle_presets");
3148 const GValue *subtitle_list, *subtitle;
3149 GValue *slist, *dict;
3150 gint count, ii, source;
3152 subtitle_list = ghb_settings_get_value(ud->settings, "subtitle_list");
3153 slist = ghb_array_value_new(8);
3154 count = ghb_array_len(subtitle_list);
3155 for (ii = 0; ii < count; ii++)
3157 subtitle = ghb_array_get_nth(subtitle_list, ii);
3158 source = ghb_settings_get_int(subtitle, "SubtitleSource");
3159 if (source != SRTSUB)
3161 dict = ghb_value_dup(subtitle);
3162 ghb_array_append(slist, dict);
3165 ghb_settings_take_value(ud->settings, "SubtitleList", slist);
3168 G_MODULE_EXPORT void
3169 presets_menu_clicked_cb(GtkWidget *xwidget, signal_user_data_t *ud)
3173 menu = GTK_MENU(GHB_WIDGET(ud->builder, "presets_menu"));
3174 gtk_menu_popup(menu, NULL, NULL, NULL, NULL, 1,
3175 gtk_get_current_event_time());
3178 G_MODULE_EXPORT void
3179 preset_import_clicked_cb(GtkWidget *xwidget, signal_user_data_t *ud)
3182 GtkResponseType response;
3185 GtkFileFilter *filter;
3187 g_debug("preset_import_clicked_cb ()");
3189 dialog = gtk_file_chooser_dialog_new("Import Preset", NULL,
3190 GTK_FILE_CHOOSER_ACTION_OPEN,
3191 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
3192 GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
3195 filter = gtk_file_filter_new();
3196 gtk_file_filter_set_name(filter, "All (*)");
3197 gtk_file_filter_add_pattern(filter, "*");
3198 gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(dialog), filter);
3200 filter = gtk_file_filter_new();
3201 gtk_file_filter_set_name(filter, "Presets (*.plist)");
3202 gtk_file_filter_add_pattern(filter, "*.plist");
3203 gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(dialog), filter);
3204 gtk_file_chooser_set_filter(GTK_FILE_CHOOSER(dialog), filter);
3206 exportDir = ghb_settings_get_string(ud->settings, "ExportDirectory");
3207 if (exportDir == NULL || exportDir[0] == '\0')
3209 exportDir = g_strdup(".");
3211 gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(dialog), exportDir);
3214 response = gtk_dialog_run(GTK_DIALOG(dialog));
3215 gtk_widget_hide(dialog);
3216 if (response == GTK_RESPONSE_ACCEPT)
3218 GValue *dict, *array;
3222 filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog));
3224 // import the preset
3225 if (!g_file_test(filename, G_FILE_TEST_IS_REGULAR))
3227 gtk_widget_destroy(dialog);
3231 array = ghb_plist_parse_file(filename);
3234 import_xlat_presets(array);
3235 presets_clear_default(array);
3236 presets_customize(array);
3238 count = ghb_array_len(array);
3239 for (ii = 0; ii < count; ii++)
3241 GValue *path, *name;
3245 dict = ghb_array_get_nth(array, ii);
3246 path = ghb_array_value_new(1);
3247 name = ghb_value_dup(ghb_dict_lookup(dict, "PresetName"));
3248 ghb_array_append(path, name);
3249 indices = ghb_preset_indices_from_path(presetsPlist, path, &len);
3250 // Modify the preset name till we make it unique
3251 while (indices != NULL)
3253 gchar *str = ghb_value_string(name);
3255 ghb_value_free(path);
3258 str = g_strdup_printf("%s %d", str, index);
3259 path = ghb_array_value_new(1);
3260 name = ghb_string_value_new(str);
3261 ghb_array_append(path, name);
3265 indices = ghb_preset_indices_from_path(presetsPlist, path, &len);
3267 ghb_dict_insert(dict, g_strdup("PresetName"), ghb_value_dup(name));
3268 indices = presets_find_pos(path, PRESETS_CUSTOM, &len);
3269 ghb_presets_insert(presetsPlist, ghb_value_dup(dict), indices, len);
3270 presets_list_insert(ud, indices, len);
3271 ghb_value_free(path);
3273 ghb_value_free(array);
3275 exportDir = ghb_settings_get_string(ud->settings, "ExportDirectory");
3276 dir = g_path_get_dirname(filename);
3277 if (strcmp(dir, exportDir) != 0)
3279 ghb_settings_set_string(ud->settings, "ExportDirectory", dir);
3280 ghb_pref_save(ud->settings, "ExportDirectory");
3285 gtk_widget_destroy(dialog);
3288 G_MODULE_EXPORT void
3289 preset_export_clicked_cb(GtkWidget *xwidget, signal_user_data_t *ud)
3292 GtkResponseType response;
3294 const gchar *name = "";
3295 gint count, *indices, len;
3299 g_debug("preset_export_clicked_cb ()");
3300 preset = ghb_settings_get_value (ud->settings, "preset_selection");
3304 count = ghb_array_len(preset);
3308 name = g_value_get_string(ghb_array_get_nth(preset, count-1));
3310 dialog = gtk_file_chooser_dialog_new("Export Preset", NULL,
3311 GTK_FILE_CHOOSER_ACTION_SAVE,
3312 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
3313 GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT,
3316 exportDir = ghb_settings_get_string(ud->settings, "ExportDirectory");
3317 if (exportDir == NULL || exportDir[0] == '\0')
3319 exportDir = g_strdup(".");
3321 filename = g_strdup_printf("%s.plist", name);
3322 gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(dialog), exportDir);
3323 gtk_file_chooser_set_current_name(GTK_FILE_CHOOSER(dialog), filename);
3327 indices = ghb_preset_indices_from_path(presetsPlist, preset, &len);
3328 if (indices == NULL)
3331 response = gtk_dialog_run(GTK_DIALOG(dialog));
3332 gtk_widget_hide(dialog);
3333 if (response == GTK_RESPONSE_ACCEPT)
3335 GValue *export, *dict, *array;
3339 filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog));
3341 // export the preset
3342 dict = presets_get_dict(presetsPlist, indices, len);
3344 export = ghb_value_dup(dict);
3345 array = ghb_array_value_new(1);
3346 ghb_array_append(array, export);
3347 presets_clear_default(array);
3348 presets_customize(array);
3349 export_xlat_presets(array);
3351 file = g_fopen(filename, "w");
3354 ghb_plist_write(file, array);
3357 ghb_value_free(array);
3359 exportDir = ghb_settings_get_string(ud->settings, "ExportDirectory");
3360 dir = g_path_get_dirname(filename);
3361 if (strcmp(dir, exportDir) != 0)
3363 ghb_settings_set_string(ud->settings, "ExportDirectory", dir);
3364 ghb_pref_save(ud->settings, "ExportDirectory");
3370 gtk_widget_destroy(dialog);
3374 G_MODULE_EXPORT void
3375 presets_new_folder_clicked_cb(GtkWidget *xwidget, signal_user_data_t *ud)
3380 GtkResponseType response;
3381 GValue *preset, *dict;
3382 const gchar *name = "";
3383 const gchar *description = "";
3384 gint count, *indices, len;
3386 g_debug("presets_save_clicked_cb ()");
3387 preset = ghb_settings_get_value (ud->settings, "preset_selection");
3389 count = ghb_array_len(preset);
3391 name = g_value_get_string(ghb_array_get_nth(preset, count-1));
3395 indices = ghb_preset_indices_from_path(presetsPlist, preset, &len);
3396 dict = presets_get_dict(presetsPlist, indices, len);
3399 description = g_value_get_string(
3400 ghb_dict_lookup(dict, "PresetDescription"));
3401 ghb_ui_update(ud, "PresetDescription", ghb_string_value(description));
3404 desc = GTK_TEXT_VIEW(GHB_WIDGET(ud->builder, "PresetDescription"));
3405 dialog = GHB_WIDGET(ud->builder, "preset_save_dialog");
3406 entry = GTK_ENTRY(GHB_WIDGET(ud->builder, "PresetName"));
3407 gtk_entry_set_text(entry, name);
3408 response = gtk_dialog_run(GTK_DIALOG(dialog));
3409 gtk_widget_hide(dialog);
3410 if (response == GTK_RESPONSE_OK)
3413 const gchar *name = gtk_entry_get_text(entry);
3416 if (count > MAX_NESTED_PRESET-1)
3417 count = MAX_NESTED_PRESET-1;
3419 dest = ghb_array_value_new(MAX_NESTED_PRESET);
3420 if (indices != NULL)
3424 ptype = ghb_presets_get_type(presetsPlist, indices, len);
3425 if (ptype == PRESETS_CUSTOM)
3427 ghb_array_copy(dest, preset, count-1);
3430 ghb_array_append(dest, ghb_string_value_new(name));
3431 ghb_widget_to_setting(ud->settings, GTK_WIDGET(desc));
3432 folder_save(ud, dest);
3433 ghb_value_free(dest);
3435 if (indices != NULL)
3439 G_MODULE_EXPORT void
3440 presets_save_clicked_cb(GtkWidget *xwidget, signal_user_data_t *ud)
3445 GtkResponseType response;
3447 const gchar *name = "";
3448 gint count, *indices, len;
3450 g_debug("presets_save_clicked_cb ()");
3451 preset = ghb_settings_get_value (ud->settings, "preset_selection");
3453 count = ghb_array_len(preset);
3455 name = g_value_get_string(ghb_array_get_nth(preset, count-1));
3459 desc = GTK_TEXT_VIEW(GHB_WIDGET(ud->builder, "PresetDescription"));
3460 dialog = GHB_WIDGET(ud->builder, "preset_save_dialog");
3461 entry = GTK_ENTRY(GHB_WIDGET(ud->builder, "PresetName"));
3462 gtk_entry_set_text(entry, name);
3463 response = gtk_dialog_run(GTK_DIALOG(dialog));
3464 gtk_widget_hide(dialog);
3465 if (response == GTK_RESPONSE_OK)
3468 const gchar *name = gtk_entry_get_text(entry);
3471 dest = ghb_array_value_new(MAX_NESTED_PRESET);
3472 indices = ghb_preset_indices_from_path(presetsPlist, preset, &len);
3477 ptype = ghb_presets_get_type(presetsPlist, indices, len);
3478 if (ptype == PRESETS_CUSTOM)
3480 ghb_array_copy(dest, preset, count-1);
3484 ghb_array_append(dest, ghb_string_value_new(name));
3486 ghb_widget_to_setting(ud->settings, GTK_WIDGET(desc));
3488 // Construct the audio settings presets from the current audio list
3489 update_audio_presets(ud);
3490 update_subtitle_presets(ud);
3491 settings_save(ud, dest);
3492 ghb_value_free(dest);
3496 G_MODULE_EXPORT void
3497 preset_type_changed_cb(GtkWidget *widget, signal_user_data_t *ud)
3499 ghb_widget_to_setting(ud->settings, widget);
3502 G_MODULE_EXPORT void
3503 presets_restore_clicked_cb(GtkWidget *xwidget, signal_user_data_t *ud)
3507 g_debug("presets_restore_clicked_cb ()");
3508 // Reload only the standard presets
3509 ghb_presets_reload(ud);
3510 // Updating the presets list shuffles things around
3511 // need to make sure the proper preset is selected
3512 preset = ghb_settings_get_value (ud->settings, "preset");
3513 ghb_select_preset(ud->builder, preset);
3516 G_MODULE_EXPORT void
3517 presets_remove_clicked_cb(GtkWidget *xwidget, signal_user_data_t *ud)
3519 GtkTreeView *treeview;
3520 GtkTreeSelection *selection;
3521 GtkTreeModel *store;
3524 GtkResponseType response;
3526 g_debug("presets_remove_clicked_cb ()");
3527 treeview = GTK_TREE_VIEW(GHB_WIDGET(ud->builder, "presets_list"));
3528 selection = gtk_tree_view_get_selection (treeview);
3529 if (gtk_tree_selection_get_selected(selection, &store, &iter))
3536 gtk_tree_model_get(store, &iter, 0, &preset, -1);
3537 path = gtk_tree_model_get_path(store, &iter);
3538 indices = gtk_tree_path_get_indices(path);
3539 len = gtk_tree_path_get_depth(path);
3541 folder = ghb_presets_get_folder(presetsPlist, indices, len);
3542 dialog = gtk_message_dialog_new(NULL, GTK_DIALOG_MODAL,
3543 GTK_MESSAGE_QUESTION, GTK_BUTTONS_YES_NO,
3544 "Confirm deletion of %s:\n\n%s",
3545 folder ? "folder" : "preset",
3547 response = gtk_dialog_run(GTK_DIALOG(dialog));
3548 gtk_widget_destroy (dialog);
3549 if (response == GTK_RESPONSE_YES)
3551 GtkTreeIter nextIter = iter;
3552 gboolean valid = TRUE;
3553 if (!gtk_tree_model_iter_next(store, &nextIter))
3555 if (!gtk_tree_model_iter_parent(store, &nextIter, &iter))
3560 // Remove the selected item
3561 // First unselect it so that selecting the new item works properly
3562 gtk_tree_selection_unselect_iter (selection, &iter);
3563 if (ghb_presets_remove(presetsPlist, indices, len))
3566 presets_list_remove(ud, indices, len);
3569 valid = gtk_tree_model_get_iter_first(store, &nextIter);
3572 gtk_tree_path_free(path);
3573 path = gtk_tree_model_get_path(store, &nextIter);
3574 indices = gtk_tree_path_get_indices(path);
3575 len = gtk_tree_path_get_depth(path);
3576 ghb_select_preset2(ud->builder, indices, len);
3580 gtk_tree_path_free(path);
3584 // controls where valid drop locations are
3585 G_MODULE_EXPORT gboolean
3586 presets_drag_motion_cb(
3588 GdkDragContext *ctx,
3592 signal_user_data_t *ud)
3594 GtkTreePath *path = NULL;
3595 GtkTreeViewDropPosition drop_pos;
3599 GtkTreeModel *model;
3600 GtkTreeSelection *select;
3601 gint src_ptype, dst_ptype;
3602 gboolean src_folder, dst_folder;
3604 gint tree_depth, ii;
3607 widget = gtk_drag_get_source_widget(ctx);
3608 if (widget == NULL || widget != GTK_WIDGET(tv))
3611 // Get the type of the object being dragged
3612 srctv = GTK_TREE_VIEW(gtk_drag_get_source_widget(ctx));
3613 select = gtk_tree_view_get_selection (srctv);
3614 gtk_tree_selection_get_selected (select, &model, &iter);
3615 path = gtk_tree_model_get_path (model, &iter);
3616 indices = gtk_tree_path_get_indices(path);
3617 len = gtk_tree_path_get_depth(path);
3619 preset = presets_get_dict(presetsPlist, indices, len);
3620 tree_depth = preset_tree_depth(preset);
3622 src_ptype = ghb_presets_get_type(presetsPlist, indices, len);
3623 src_folder = ghb_presets_get_folder(presetsPlist, indices, len);
3624 gtk_tree_path_free(path);
3626 if (src_folder && tree_depth == 1)
3629 // The rest checks that the destination is a valid position
3631 gtk_tree_view_get_dest_row_at_pos (tv, x, y, &path, &drop_pos);
3634 gdk_drag_status(ctx, 0, time);
3637 // Don't allow repositioning of builtin presets
3638 if (src_ptype != PRESETS_CUSTOM)
3640 gdk_drag_status(ctx, 0, time);
3644 len = gtk_tree_path_get_depth(path);
3645 if (len+tree_depth-1 >= MAX_NESTED_PRESET)
3647 if (drop_pos == GTK_TREE_VIEW_DROP_INTO_OR_BEFORE)
3648 drop_pos = GTK_TREE_VIEW_DROP_BEFORE;
3649 if (drop_pos == GTK_TREE_VIEW_DROP_INTO_OR_AFTER)
3650 drop_pos = GTK_TREE_VIEW_DROP_AFTER;
3652 for (ii = len+tree_depth-1; ii > MAX_NESTED_PRESET; ii--)
3653 gtk_tree_path_up(path);
3654 indices = gtk_tree_path_get_indices(path);
3655 len = gtk_tree_path_get_depth(path);
3656 dst_ptype = ghb_presets_get_type(presetsPlist, indices, len);
3657 dst_folder = ghb_presets_get_folder(presetsPlist, indices, len);
3658 // Don't allow mixing custom presets in the builtins
3659 if (dst_ptype != PRESETS_CUSTOM)
3661 gdk_drag_status(ctx, 0, time);
3665 // Only allow *drop into* for folders
3668 if (drop_pos == GTK_TREE_VIEW_DROP_INTO_OR_BEFORE)
3669 drop_pos = GTK_TREE_VIEW_DROP_BEFORE;
3670 if (drop_pos == GTK_TREE_VIEW_DROP_INTO_OR_AFTER)
3671 drop_pos = GTK_TREE_VIEW_DROP_AFTER;
3674 len = gtk_tree_path_get_depth(path);
3675 gtk_tree_view_set_drag_dest_row(tv, path, drop_pos);
3676 gtk_tree_path_free(path);
3677 gdk_drag_status(ctx, GDK_ACTION_MOVE, time);
3681 G_MODULE_EXPORT void
3683 GtkTreeView *dstwidget,
3686 GtkSelectionData *selection_data,
3687 guint info, guint t,
3688 signal_user_data_t *ud)
3690 GtkTreePath *path = NULL;
3691 GtkTreeViewDropPosition drop_pos;
3692 GtkTreeIter dstiter, srciter;
3693 gint *dst_indices, dst_len, *src_indices, src_len;
3695 gboolean src_folder, dst_folder;
3697 GtkTreeModel *dstmodel = gtk_tree_view_get_model(dstwidget);
3699 g_debug("preset_drag_cb ()");
3700 // This doesn't work here for some reason...
3701 // gtk_tree_view_get_drag_dest_row(dstwidget, &path, &drop_pos);
3702 gtk_tree_view_get_dest_row_at_pos (dstwidget, x, y, &path, &drop_pos);
3703 // This little hack is needed because attempting to drop after
3704 // the last item gives us no path or drop_pos.
3709 n_children = gtk_tree_model_iter_n_children(dstmodel, NULL);
3712 drop_pos = GTK_TREE_VIEW_DROP_AFTER;
3713 path = gtk_tree_path_new_from_indices(n_children-1, -1);
3717 drop_pos = GTK_TREE_VIEW_DROP_BEFORE;
3718 path = gtk_tree_path_new_from_indices(0, -1);
3723 GtkTreeView *srcwidget;
3724 GtkTreeModel *srcmodel;
3725 GtkTreeSelection *select;
3726 GtkTreePath *srcpath = NULL;
3728 gint tree_depth, ii;
3730 srcwidget = GTK_TREE_VIEW(gtk_drag_get_source_widget(dc));
3731 select = gtk_tree_view_get_selection (srcwidget);
3732 gtk_tree_selection_get_selected (select, &srcmodel, &srciter);
3734 srcpath = gtk_tree_model_get_path (srcmodel, &srciter);
3735 src_indices = gtk_tree_path_get_indices(srcpath);
3736 src_len = gtk_tree_path_get_depth(srcpath);
3737 src_ptype = ghb_presets_get_type(presetsPlist, src_indices, src_len);
3738 src_folder = ghb_presets_get_folder(presetsPlist, src_indices, src_len);
3739 preset = ghb_value_dup(
3740 presets_get_dict(presetsPlist, src_indices, src_len));
3741 gtk_tree_path_free(srcpath);
3743 // Don't allow repositioning of builtin presets
3744 if (src_ptype != PRESETS_CUSTOM)
3747 tree_depth = preset_tree_depth(preset);
3748 if (src_folder && tree_depth == 1)
3751 dst_len = gtk_tree_path_get_depth(path);
3752 if (dst_len+tree_depth-1 >= MAX_NESTED_PRESET)
3754 if (drop_pos == GTK_TREE_VIEW_DROP_INTO_OR_BEFORE)
3755 drop_pos = GTK_TREE_VIEW_DROP_BEFORE;
3756 if (drop_pos == GTK_TREE_VIEW_DROP_INTO_OR_AFTER)
3757 drop_pos = GTK_TREE_VIEW_DROP_AFTER;
3760 for (ii = dst_len+tree_depth-1; ii > MAX_NESTED_PRESET; ii--)
3761 gtk_tree_path_up(path);
3762 dst_indices = gtk_tree_path_get_indices(path);
3763 dst_len = gtk_tree_path_get_depth(path);
3764 dst_folder = ghb_presets_get_folder(presetsPlist, dst_indices, dst_len);
3765 // Only allow *drop into* for folders
3768 if (drop_pos == GTK_TREE_VIEW_DROP_INTO_OR_BEFORE)
3769 drop_pos = GTK_TREE_VIEW_DROP_BEFORE;
3770 if (drop_pos == GTK_TREE_VIEW_DROP_INTO_OR_AFTER)
3771 drop_pos = GTK_TREE_VIEW_DROP_AFTER;
3773 if (gtk_tree_model_get_iter (dstmodel, &dstiter, path))
3776 GtkTreePath *dstpath = NULL;
3780 case GTK_TREE_VIEW_DROP_BEFORE:
3781 gtk_tree_store_insert_before(GTK_TREE_STORE (dstmodel),
3782 &iter, NULL, &dstiter);
3785 case GTK_TREE_VIEW_DROP_INTO_OR_BEFORE:
3786 gtk_tree_store_insert(GTK_TREE_STORE (dstmodel),
3787 &iter, &dstiter, 0);
3790 case GTK_TREE_VIEW_DROP_AFTER:
3791 gtk_tree_store_insert_after(GTK_TREE_STORE (dstmodel),
3792 &iter, NULL, &dstiter);
3795 case GTK_TREE_VIEW_DROP_INTO_OR_AFTER:
3796 gtk_tree_store_insert_after(GTK_TREE_STORE (dstmodel),
3797 &iter, &dstiter, 0);
3804 dstpath = gtk_tree_model_get_path (dstmodel, &iter);
3805 dst_indices = gtk_tree_path_get_indices(dstpath);
3806 dst_len = gtk_tree_path_get_depth(dstpath);
3807 ghb_presets_insert(presetsPlist, preset, dst_indices, dst_len);
3808 gtk_tree_path_free(dstpath);
3810 srcpath = gtk_tree_model_get_path (srcmodel, &srciter);
3811 src_indices = gtk_tree_path_get_indices(srcpath);
3812 src_len = gtk_tree_path_get_depth(srcpath);
3813 ghb_presets_remove(presetsPlist, src_indices, src_len);
3814 gtk_tree_path_free(srcpath);
3816 gtk_tree_store_remove (GTK_TREE_STORE (srcmodel), &srciter);
3818 dstpath = gtk_tree_model_get_path (dstmodel, &iter);
3819 dst_indices = gtk_tree_path_get_indices(dstpath);
3820 dst_len = gtk_tree_path_get_depth(dstpath);
3821 presets_list_update_item(ud, dst_indices, dst_len, TRUE);
3822 gtk_tree_path_free(dstpath);
3826 gtk_tree_path_free(path);
3831 presets_row_expanded_cb(
3832 GtkTreeView *treeview,
3835 signal_user_data_t *ud)
3838 gboolean expanded, folder;
3841 expanded = gtk_tree_view_row_expanded(treeview, path);
3842 indices = gtk_tree_path_get_indices(path);
3843 len = gtk_tree_path_get_depth(path);
3844 dict = presets_get_dict(presetsPlist, indices, len);
3845 if (preset_folder_is_open(dict))
3854 folder = ghb_presets_get_folder(presetsPlist, indices, len);
3857 presets_set_folder_open(expanded, indices, len);
3860 // Collapsing parent folder collapses all children
3863 GValue *presets = NULL;
3864 gint *more_indices, count, ii;
3866 more_indices = g_malloc((len+1)*sizeof(gint));
3867 memcpy(more_indices, indices, len*sizeof(gint));
3869 presets = presets_get_folder(presetsPlist, indices, len);
3870 count = ghb_array_len(presets);
3871 for (ii = 0; ii < count; ii++)
3873 dict = ghb_array_get_nth(presets, ii);
3874 folder = ghb_preset_folder(dict);
3877 more_indices[len] = ii;
3878 presets_set_folder_open(expanded, more_indices, len+1);
3881 g_free(more_indices);
3887 preset_update_title_deps(signal_user_data_t *ud, ghb_title_info_t *tinfo)
3891 ghb_ui_update(ud, "scale_width",
3892 ghb_int64_value(tinfo->width - tinfo->crop[2] - tinfo->crop[3]));
3893 // If anamorphic or keep_aspect, the hight will be automatically calculated
3894 gboolean keep_aspect;
3896 keep_aspect = ghb_settings_get_boolean(ud->settings, "PictureKeepRatio");
3897 pic_par = ghb_settings_combo_int(ud->settings, "PicturePAR");
3898 if (!(keep_aspect || pic_par) || pic_par == 3)
3900 ghb_ui_update(ud, "scale_height",
3901 ghb_int64_value(tinfo->height - tinfo->crop[0] - tinfo->crop[1]));
3904 // Set the limits of cropping. hb_set_anamorphic_size crashes if
3905 // you pass it a cropped width or height == 0.
3907 bound = tinfo->height / 2 - 2;
3908 widget = GHB_WIDGET (ud->builder, "PictureTopCrop");
3909 gtk_spin_button_set_range (GTK_SPIN_BUTTON(widget), 0, bound);
3910 widget = GHB_WIDGET (ud->builder, "PictureBottomCrop");
3911 gtk_spin_button_set_range (GTK_SPIN_BUTTON(widget), 0, bound);
3912 bound = tinfo->width / 2 - 2;
3913 widget = GHB_WIDGET (ud->builder, "PictureLeftCrop");
3914 gtk_spin_button_set_range (GTK_SPIN_BUTTON(widget), 0, bound);
3915 widget = GHB_WIDGET (ud->builder, "PictureRightCrop");
3916 gtk_spin_button_set_range (GTK_SPIN_BUTTON(widget), 0, bound);
3917 if (ghb_settings_get_boolean(ud->settings, "PictureAutoCrop"))
3919 ghb_ui_update(ud, "PictureTopCrop", ghb_int64_value(tinfo->crop[0]));
3920 ghb_ui_update(ud, "PictureBottomCrop", ghb_int64_value(tinfo->crop[1]));
3921 ghb_ui_update(ud, "PictureLeftCrop", ghb_int64_value(tinfo->crop[2]));
3922 ghb_ui_update(ud, "PictureRightCrop", ghb_int64_value(tinfo->crop[3]));
3926 G_MODULE_EXPORT void
3927 presets_list_selection_changed_cb(GtkTreeSelection *selection, signal_user_data_t *ud)
3929 GtkTreeModel *store;
3931 ghb_title_info_t tinfo;
3934 g_debug("presets_list_selection_changed_cb ()");
3935 widget = GHB_WIDGET (ud->builder, "presets_remove");
3936 if (gtk_tree_selection_get_selected(selection, &store, &iter))
3938 GtkTreePath *treepath;
3943 treepath = gtk_tree_model_get_path(store, &iter);
3944 indices = gtk_tree_path_get_indices(treepath);
3945 len = gtk_tree_path_get_depth(treepath);
3947 path = preset_path_from_indices(presetsPlist, indices, len);
3948 ghb_settings_take_value(ud->settings, "preset_selection", path);
3950 folder = ghb_presets_get_folder(presetsPlist, indices, len);
3953 ud->dont_clear_presets = TRUE;
3954 // Temporarily set the video_quality range to (0,100)
3955 // This is needed so the video_quality value does not get
3956 // truncated when set. The range will be readjusted below
3957 GtkWidget *qp = GHB_WIDGET(ud->builder, "VideoQualitySlider");
3958 gtk_range_set_range (GTK_RANGE(qp), 0, 100);
3959 gtk_scale_set_digits(GTK_SCALE(qp), 3);
3960 // Clear the audio list prior to changing the preset. Existing
3961 // audio can cause the container extension to be automatically
3962 // changed when it shouldn't be
3963 ghb_clear_audio_list(ud);
3964 ghb_set_preset_from_indices(ud, indices, len);
3965 gtk_tree_path_free(treepath);
3967 titleindex = ghb_settings_combo_int(ud->settings, "title");
3968 ghb_set_pref_audio(titleindex, ud);
3969 ghb_set_pref_subtitle(titleindex, ud);
3970 ghb_settings_set_boolean(ud->settings, "preset_modified", FALSE);
3971 if (ghb_get_title_info (&tinfo, titleindex))
3973 preset_update_title_deps(ud, &tinfo);
3975 ghb_set_scale (ud, GHB_PIC_KEEP_PAR);
3976 ud->dont_clear_presets = FALSE;
3978 gdouble vqmin, vqmax, step, page;
3982 ghb_vquality_range(ud, &vqmin, &vqmax, &step,
3983 &page, &digits, &inverted);
3984 gtk_range_set_range (GTK_RANGE(qp), vqmin, vqmax);
3985 gtk_range_set_increments (GTK_RANGE(qp), step, page);
3986 gtk_scale_set_digits(GTK_SCALE(qp), digits);
3987 gtk_range_set_inverted (GTK_RANGE(qp), inverted);
3991 GtkWidget *crop_widget;
3992 crop[0] = ghb_settings_get_int(ud->settings, "PictureTopCrop");
3993 crop[1] = ghb_settings_get_int(ud->settings, "PictureBottomCrop");
3994 crop[2] = ghb_settings_get_int(ud->settings, "PictureLeftCrop");
3995 crop[3] = ghb_settings_get_int(ud->settings, "PictureRightCrop");
3996 crop_widget = GHB_WIDGET (ud->builder, "crop_values");
3997 text = g_strdup_printf("%d:%d:%d:%d",
3998 crop[0], crop[1], crop[2], crop[3]);
3999 gtk_label_set_text (GTK_LABEL(crop_widget), text);
4002 gtk_widget_set_sensitive(widget, TRUE);
4006 g_debug("No selection??? Perhaps unselected.");
4007 gtk_widget_set_sensitive(widget, FALSE);
4012 ghb_clear_presets_selection(signal_user_data_t *ud)
4014 GtkTreeView *treeview;
4015 GtkTreeSelection *selection;
4017 if (ud->dont_clear_presets) return;
4018 g_debug("ghb_clear_presets_selection()");
4019 treeview = GTK_TREE_VIEW(GHB_WIDGET(ud->builder, "presets_list"));
4020 selection = gtk_tree_view_get_selection (treeview);
4021 gtk_tree_selection_unselect_all (selection);
4022 ghb_settings_set_boolean(ud->settings, "preset_modified", TRUE);
4025 G_MODULE_EXPORT void
4026 presets_frame_size_allocate_cb(GtkWidget *widget, GtkAllocation *allocation, signal_user_data_t *ud)
4028 GtkTreeView *treeview;
4029 GtkTreeSelection *selection;
4030 GtkTreeModel *store;
4033 treeview = GTK_TREE_VIEW(GHB_WIDGET(ud->builder, "presets_list"));
4034 selection = gtk_tree_view_get_selection(treeview);
4035 if (gtk_tree_selection_get_selected(selection, &store, &iter))
4038 path = gtk_tree_model_get_path (store, &iter);
4039 // Make the parent visible in scroll window if it is not.
4040 gtk_tree_view_scroll_to_cell (treeview, path, NULL, FALSE, 0, 0);
4041 gtk_tree_path_free(path);
4045 G_MODULE_EXPORT void
4046 presets_default_clicked_cb(GtkWidget *xwidget, signal_user_data_t *ud)
4051 g_debug("presets_default_clicked_cb ()");
4052 preset = ghb_settings_get_value(ud->settings, "preset_selection");
4053 indices = ghb_preset_indices_from_path(presetsPlist, preset, &len);
4056 if (!ghb_presets_get_folder(presetsPlist, indices, len))
4058 ghb_presets_list_clear_default(ud);
4059 presets_set_default(indices, len);
4060 ghb_presets_list_default(ud);
4066 G_MODULE_EXPORT void
4068 GtkCellRendererText *cell,
4071 signal_user_data_t *ud)
4073 GtkTreePath *treepath;
4074 GtkTreeStore *store;
4075 GtkTreeView *treeview;
4077 gint *indices, len, count;
4079 GValue *preset, *dest;
4081 g_debug("preset_edited_cb ()");
4082 g_debug("path (%s)", path);
4083 g_debug("text (%s)", text);
4085 preset = ghb_settings_get_value (ud->settings, "preset_selection");
4086 dest = ghb_array_value_new(MAX_NESTED_PRESET);
4087 count = ghb_array_len(preset);
4088 ghb_array_copy(dest, preset, count-1);
4089 ghb_array_append(dest, ghb_string_value_new(text));
4090 indices = ghb_preset_indices_from_path(presetsPlist, dest, &len);
4091 ghb_value_free(dest);
4092 if (indices != NULL)
4099 treeview = GTK_TREE_VIEW(GHB_WIDGET(ud->builder, "presets_list"));
4100 store = GTK_TREE_STORE(gtk_tree_view_get_model(treeview));
4101 treepath = gtk_tree_path_new_from_string (path);
4102 indices = gtk_tree_path_get_indices(treepath);
4103 len = gtk_tree_path_get_depth(treepath);
4104 gtk_tree_model_get_iter(GTK_TREE_MODEL(store), &iter, treepath);
4105 gtk_tree_store_set(store, &iter, 0, text, -1);
4107 dict = presets_get_dict(presetsPlist, indices, len);
4108 ghb_dict_insert(dict, g_strdup("PresetName"), ghb_string_value_new(text));
4110 gtk_tree_path_free (treepath);