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 gchar *config, *path;
1125 config = ghb_get_user_config_dir(NULL);
1126 path = g_strdup_printf ("%s/%s", config, name);
1127 fd = open(path, O_RDWR|O_CREAT, S_IRUSR|S_IWUSR);
1129 lock = lockf(fd, F_TLOCK, 0);
1138 remove_plist(const gchar *name)
1140 gchar *config, *path;
1142 config = ghb_get_user_config_dir(NULL);
1143 path = g_strdup_printf ("%s/%s", config, name);
1144 if (g_file_test(path, G_FILE_TEST_IS_REGULAR))
1152 static gboolean prefs_initializing = FALSE;
1155 ghb_prefs_to_ui(signal_user_data_t *ud)
1160 GValue *internal, *dict;
1161 GHashTableIter iter;
1164 g_debug("ghb_prefs_to_ui");
1165 prefs_initializing = TRUE;
1167 // Setting a ui widget will cause the corresponding setting
1168 // to be set, but it also triggers a callback that can
1169 // have the side effect of using other settings values
1170 // that have not yet been set. So set *all* settings first
1171 // then update the ui.
1172 internal = plist_get_dict(internalPlist, "Initialization");
1173 ghb_dict_iter_init(&iter, internal);
1174 // middle (void*) cast prevents gcc warning "defreferencing type-punned
1175 // pointer will break strict-aliasing rules"
1176 while (g_hash_table_iter_next(
1177 &iter, (gpointer*)(void*)&key, (gpointer*)(void*)&gval))
1179 ghb_ui_update(ud, key, gval);
1182 dict = plist_get_dict(prefsPlist, "Preferences");
1183 internal = plist_get_dict(internalPlist, "Preferences");
1184 ghb_dict_iter_init(&iter, internal);
1185 // middle (void*) cast prevents gcc warning "defreferencing type-punned
1186 // pointer will break strict-aliasing rules"
1187 while (g_hash_table_iter_next(
1188 &iter, (gpointer*)(void*)&key, (gpointer*)(void*)&gval))
1190 const GValue *value = NULL;
1192 value = ghb_dict_lookup(dict, key);
1195 ghb_settings_set_value(ud->settings, key, value);
1197 internal = plist_get_dict(internalPlist, "Preferences");
1198 ghb_dict_iter_init(&iter, internal);
1199 // middle (void*) cast prevents gcc warning "defreferencing type-punned
1200 // pointer will break strict-aliasing rules"
1201 while (g_hash_table_iter_next(
1202 &iter, (gpointer*)(void*)&key, (gpointer*)(void*)&gval))
1204 const GValue *value = NULL;
1206 value = ghb_dict_lookup(dict, key);
1209 ghb_ui_update(ud, key, value);
1212 val = ghb_settings_get_value(ud->settings, "show_presets");
1213 ghb_ui_update(ud, "show_presets", val);
1214 if (ghb_settings_get_boolean(ud->settings, "hbfd_feature"))
1217 val = ghb_settings_get_value(ud->settings, "hbfd");
1218 ghb_ui_update(ud, "hbfd", val);
1219 action = GHB_ACTION (ud->builder, "hbfd");
1220 gtk_action_set_visible(action, TRUE);
1224 ghb_ui_update(ud, "hbfd", ghb_int64_value(0));
1226 gval = ghb_settings_get_value(ud->settings, "default_source");
1227 ghb_settings_set_value (ud->settings, "source", gval);
1229 str = ghb_settings_get_string(ud->settings, "destination_dir");
1230 ghb_ui_update(ud, "dest_dir", ghb_string_value(str));
1232 gchar *file = g_strdup_printf ("new_video.mp4");
1233 ghb_ui_update(ud, "dest_file", ghb_string_value(file));
1237 prefs_initializing = FALSE;
1241 ghb_prefs_save(GValue *settings)
1245 GHashTableIter iter;
1247 const GValue *value;
1249 if (prefs_initializing) return;
1250 dict = plist_get_dict(internalPlist, "Preferences");
1251 if (dict == NULL) return;
1252 pref_dict = plist_get_dict(prefsPlist, "Preferences");
1253 if (pref_dict == NULL) return;
1254 ghb_dict_iter_init(&iter, dict);
1255 // middle (void*) cast prevents gcc warning "defreferencing type-punned
1256 // pointer will break strict-aliasing rules"
1257 while (g_hash_table_iter_next(
1258 &iter, (gpointer*)(void*)&key, (gpointer*)(void*)&value))
1260 value = ghb_settings_get_value(settings, key);
1263 ghb_dict_insert(pref_dict, g_strdup(key), ghb_value_dup(value));
1267 prefs_modified = FALSE;
1271 ghb_pref_set(GValue *settings, const gchar *key)
1273 const GValue *value, *value2;
1275 if (prefs_initializing) return;
1276 value = ghb_settings_get_value(settings, key);
1280 dict = plist_get_dict(prefsPlist, "Preferences");
1281 if (dict == NULL) return;
1282 value2 = ghb_dict_lookup(dict, key);
1283 if (ghb_value_cmp(value, value2) != 0)
1285 ghb_dict_insert(dict, g_strdup(key), ghb_value_dup(value));
1287 prefs_modified = TRUE;
1293 ghb_pref_save(GValue *settings, const gchar *key)
1295 const GValue *value, *value2;
1297 if (prefs_initializing) return;
1298 value = ghb_settings_get_value(settings, key);
1302 dict = plist_get_dict(prefsPlist, "Preferences");
1303 if (dict == NULL) return;
1304 value2 = ghb_dict_lookup(dict, key);
1305 if (ghb_value_cmp(value, value2) != 0)
1307 ghb_dict_insert(dict, g_strdup(key), ghb_value_dup(value));
1309 prefs_modified = FALSE;
1315 ghb_prefs_store(void)
1320 prefs_modified = FALSE;
1325 ghb_settings_init(signal_user_data_t *ud)
1328 GHashTableIter iter;
1333 g_debug("ghb_settings_init");
1334 prefs_initializing = TRUE;
1336 internalPlist = ghb_resource_get("internal-defaults");
1337 // Setting a ui widget will cause the corresponding setting
1338 // to be set, but it also triggers a callback that can
1339 // have the side effect of using other settings values
1340 // that have not yet been set. So set *all* settings first
1341 // then update the ui.
1342 internal = plist_get_dict(internalPlist, "Initialization");
1343 ghb_dict_iter_init(&iter, internal);
1344 // middle (void*) cast prevents gcc warning "defreferencing type-punned
1345 // pointer will break strict-aliasing rules"
1346 while (g_hash_table_iter_next(
1347 &iter, (gpointer*)(void*)&key, (gpointer*)(void*)&gval))
1349 ghb_settings_set_value(ud->settings, key, gval);
1352 internal = plist_get_dict(internalPlist, "Presets");
1353 ghb_dict_iter_init(&iter, internal);
1354 // middle (void*) cast prevents gcc warning "defreferencing type-punned
1355 // pointer will break strict-aliasing rules"
1356 while (g_hash_table_iter_next(
1357 &iter, (gpointer*)(void*)&key, (gpointer*)(void*)&gval))
1359 ghb_settings_set_value(ud->settings, key, gval);
1362 internal = plist_get_dict(internalPlist, "Preferences");
1363 ghb_dict_iter_init(&iter, internal);
1364 // middle (void*) cast prevents gcc warning "defreferencing type-punned
1365 // pointer will break strict-aliasing rules"
1366 while (g_hash_table_iter_next(
1367 &iter, (gpointer*)(void*)&key, (gpointer*)(void*)&gval))
1369 ghb_settings_set_value(ud->settings, key, gval);
1371 prefs_initializing = FALSE;
1375 ghb_settings_close()
1378 ghb_value_free(internalPlist);
1380 ghb_value_free(presetsPlist);
1382 ghb_value_free(prefsPlist);
1387 FindFirstCDROM(void)
1392 strcpy(drive, "A:" G_DIR_SEPARATOR_S);
1393 drives = GetLogicalDrives();
1394 for (ii = 0; ii < 26; ii++)
1400 drive[0] = 'A' + ii;
1401 dtype = GetDriveType(drive);
1402 if (dtype == DRIVE_CDROM)
1404 return g_strdup(drive);
1414 ghb_prefs_load(signal_user_data_t *ud)
1416 GValue *dict, *internal;
1417 GHashTableIter iter;
1419 GValue *gval, *path;
1421 g_debug("ghb_prefs_load");
1422 prefsPlist = load_plist("preferences");
1423 if (prefsPlist == NULL)
1424 prefsPlist = ghb_dict_value_new();
1425 dict = plist_get_dict(prefsPlist, "Preferences");
1426 internal = plist_get_dict(internalPlist, "Preferences");
1427 if (dict == NULL && internal)
1429 dict = ghb_dict_value_new();
1430 ghb_dict_insert(prefsPlist, g_strdup("Preferences"), dict);
1432 // Get defaults from internal defaults
1433 ghb_dict_iter_init(&iter, internal);
1434 // middle (void*) cast prevents gcc warning "defreferencing type-punned
1435 // pointer will break strict-aliasing rules"
1436 while (g_hash_table_iter_next(
1437 &iter, (gpointer*)(void*)&key, (gpointer*)(void*)&gval))
1439 ghb_dict_insert(dict, g_strdup(key), ghb_value_dup(gval));
1442 const gchar *dir = g_get_user_special_dir (G_USER_DIRECTORY_DESKTOP);
1447 ghb_dict_insert(dict,
1448 g_strdup("ExportDirectory"), ghb_value_dup(ghb_string_value(dir)));
1450 dir = g_get_user_special_dir (G_USER_DIRECTORY_VIDEOS);
1455 ghb_dict_insert(dict,
1456 g_strdup("destination_dir"), ghb_value_dup(ghb_string_value(dir)));
1458 ghb_dict_insert(dict,
1459 g_strdup("SrtDir"), ghb_value_dup(ghb_string_value(dir)));
1463 source = FindFirstCDROM();
1466 source = g_strdup("C:" G_DIR_SEPARATOR_S);
1468 ghb_dict_insert(dict, g_strdup("default_source"),
1469 ghb_value_dup(ghb_string_value(source)));
1474 // Read legacy default_preset preference and update accordingly
1475 path = ghb_dict_lookup(dict, "default_preset");
1480 if (G_VALUE_TYPE(path) == G_TYPE_STRING)
1484 path = ghb_array_value_new(1);
1485 ghb_array_append(path, ghb_value_dup(str));
1486 indices = ghb_preset_indices_from_path(presetsPlist, path, &len);
1487 ghb_value_free(path);
1490 indices = ghb_preset_indices_from_path(presetsPlist, path, &len);
1494 presets_set_default(indices, len);
1497 ghb_dict_remove(dict, "default_preset");
1503 get_preset_color(gint type, gboolean folder)
1507 if (type == PRESETS_CUSTOM)
1527 ghb_presets_list_init(
1528 signal_user_data_t *ud,
1532 GtkTreeView *treeview;
1533 GtkTreeIter iter, titer, *piter;
1535 GtkTreeStore *store;
1536 const gchar *preset;
1537 GtkTreePath *parent_path;
1538 const gchar *description;
1543 GValue *presets = NULL;
1545 g_debug("ghb_presets_list_init ()");
1546 more_indices = g_malloc((len+1)*sizeof(gint));
1547 memcpy(more_indices, indices, len*sizeof(gint));
1548 presets = presets_get_folder(presetsPlist, indices, len);
1549 if (presets == NULL)
1551 g_warning("Failed to find parent folder when adding child.");
1554 count = ghb_array_len(presets);
1555 treeview = GTK_TREE_VIEW(GHB_WIDGET(ud->builder, "presets_list"));
1556 store = GTK_TREE_STORE(gtk_tree_view_get_model(treeview));
1557 parent_path = ghb_tree_path_new_from_indices(indices, len);
1560 gtk_tree_model_get_iter(GTK_TREE_MODEL(store), &titer, parent_path);
1562 gtk_tree_path_free(parent_path);
1568 for (ii = 0; ii < count; ii++)
1574 // Additional settings, add row
1575 dict = ghb_array_get_nth(presets, ii);
1576 preset = preset_get_name(dict);
1577 more_indices[len] = ii;
1578 def = preset_is_default(dict);
1580 description = ghb_presets_get_description(dict);
1581 gtk_tree_store_append(store, &iter, piter);
1582 type = ghb_preset_type(dict);
1583 folder = ghb_preset_folder(dict);
1584 color = get_preset_color(type, folder);
1585 gtk_tree_store_set(store, &iter, 0, preset,
1590 5, type == PRESETS_BUILTIN ? 0 : 1,
1597 if (gtk_tree_model_iter_parent(
1598 GTK_TREE_MODEL(store), &ppiter, piter))
1600 path = gtk_tree_model_get_path(GTK_TREE_MODEL(store), &ppiter);
1601 gtk_tree_view_expand_row(treeview, path, FALSE);
1602 gtk_tree_path_free(path);
1604 path = gtk_tree_model_get_path(GTK_TREE_MODEL(store), piter);
1605 gtk_tree_view_expand_row(treeview, path, FALSE);
1606 gtk_tree_path_free(path);
1610 ghb_presets_list_init(ud, more_indices, len+1);
1611 if (preset_folder_is_open(dict))
1617 path = gtk_tree_model_get_path(GTK_TREE_MODEL(store), piter);
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), &iter);
1622 gtk_tree_view_expand_row(treeview, path, FALSE);
1623 gtk_tree_path_free(path);
1627 g_free(more_indices);
1631 presets_list_update_item(
1632 signal_user_data_t *ud,
1637 GtkTreeView *treeview;
1638 GtkTreeStore *store;
1640 GtkTreePath *treepath;
1642 const gchar *description;
1644 gboolean def, folder;
1648 g_debug("presets_list_update_item ()");
1649 dict = presets_get_dict(presetsPlist, indices, len);
1652 treeview = GTK_TREE_VIEW(GHB_WIDGET(ud->builder, "presets_list"));
1653 store = GTK_TREE_STORE(gtk_tree_view_get_model(treeview));
1654 treepath = ghb_tree_path_new_from_indices(indices, len);
1655 gtk_tree_model_get_iter(GTK_TREE_MODEL(store), &iter, treepath);
1656 // Additional settings, add row
1657 name = preset_get_name(dict);
1658 def = preset_is_default(dict);
1660 description = ghb_presets_get_description(dict);
1661 type = ghb_preset_type(dict);
1662 folder = ghb_preset_folder(dict);
1663 color = get_preset_color(type, folder);
1664 gtk_tree_store_set(store, &iter, 0, name,
1669 5, type == PRESETS_BUILTIN ? 0 : 1,
1671 if (recurse && folder)
1673 ghb_presets_list_init(ud, indices, len);
1678 presets_list_insert(
1679 signal_user_data_t *ud,
1683 GtkTreeView *treeview;
1684 GtkTreeIter iter, titer, *piter;
1685 GtkTreeStore *store;
1686 const gchar *preset;
1687 const gchar *description;
1689 gboolean def, folder;
1692 GtkTreePath *parent_path;
1696 g_debug("presets_list_insert ()");
1697 treeview = GTK_TREE_VIEW(GHB_WIDGET(ud->builder, "presets_list"));
1698 store = GTK_TREE_STORE(gtk_tree_view_get_model(treeview));
1699 presets = presets_get_folder(presetsPlist, indices, len-1);
1700 if (presets == NULL)
1702 g_warning("Failed to find parent folder while adding child.");
1705 parent_path = ghb_tree_path_new_from_indices(indices, len-1);
1708 gtk_tree_model_get_iter(GTK_TREE_MODEL(store), &titer, parent_path);
1710 gtk_tree_path_free(parent_path);
1716 count = ghb_array_len(presets);
1717 if (indices[len-1] >= count)
1719 // Additional settings, add row
1720 dict = ghb_array_get_nth(presets, indices[len-1]);
1721 preset = preset_get_name(dict);
1722 def = preset_is_default(dict);
1724 description = ghb_presets_get_description(dict);
1725 gtk_tree_store_insert(store, &iter, piter, indices[len-1]);
1726 type = ghb_preset_type(dict);
1727 folder = ghb_preset_folder(dict);
1728 color = get_preset_color(type, folder);
1729 gtk_tree_store_set(store, &iter, 0, preset,
1734 5, type == PRESETS_BUILTIN ? 0 : 1,
1738 ghb_presets_list_init(ud, indices, len);
1743 presets_list_remove(
1744 signal_user_data_t *ud,
1748 GtkTreeView *treeview;
1749 GtkTreePath *treepath;
1751 GtkTreeStore *store;
1753 g_debug("presets_list_remove ()");
1754 treeview = GTK_TREE_VIEW(GHB_WIDGET(ud->builder, "presets_list"));
1755 store = GTK_TREE_STORE(gtk_tree_view_get_model(treeview));
1756 treepath = ghb_tree_path_new_from_indices(indices, len);
1759 if (gtk_tree_model_get_iter(GTK_TREE_MODEL(store), &iter, treepath))
1760 gtk_tree_store_remove(store, &iter);
1761 gtk_tree_path_free(treepath);
1766 remove_std_presets(signal_user_data_t *ud)
1771 count = ghb_array_len(presetsPlist);
1772 for (ii = count-1; ii >= 0; ii--)
1777 dict = ghb_array_get_nth(presetsPlist, ii);
1778 ptype = ghb_value_int(preset_dict_get_value(dict, "Type"));
1779 if (ptype == PRESETS_BUILTIN)
1781 if (ghb_presets_remove(presetsPlist, &indices, 1))
1783 presets_list_remove(ud, &indices, 1);
1790 ghb_save_queue(GValue *queue)
1792 store_plist(queue, "queue");
1798 return load_plist("queue");
1802 ghb_remove_queue_file()
1804 remove_plist("queue");
1813 static value_map_t vcodec_xlat[] =
1815 {"MPEG-4 (FFmpeg)", "ffmpeg"},
1816 {"MPEG-4 (XviD)", "ffmpeg"},
1817 {"H.264 (x264)", "x264"},
1818 {"VP3 (Theora)", "theora"},
1822 static value_map_t acodec_xlat[] =
1824 {"AAC (faac)", "faac"},
1825 {"AAC (CoreAudio)", "faac"},
1826 {"AC3 Passthru", "ac3"},
1827 {"MP3 (lame)", "lame"},
1828 {"Vorbis (vorbis)", "vorbis"},
1832 value_map_t container_xlat[] =
1834 {"MP4 file", "mp4"},
1835 {"M4V file", "mp4"},
1836 {"MKV file", "mkv"},
1837 {"AVI file", "mkv"},
1838 {"OGM file", "mkv"},
1842 value_map_t framerate_xlat[] =
1844 {"Same as source", "source"},
1849 {"23.976", "23.976"},
1856 value_map_t samplerate_xlat[] =
1867 value_map_t mix_xlat[] =
1870 {"Stereo", "stereo"},
1871 {"Dolby Surround", "dpl1"},
1872 {"Dolby Pro Logic II", "dpl2"},
1873 {"6-channel discrete", "6ch"},
1874 {"AC3 Passthru", "none"},
1878 value_map_t deint_xlat[] =
1888 value_map_t denoise_xlat[] =
1898 value_map_t detel_xlat[] =
1906 value_map_t decomb_xlat[] =
1914 extern iso639_lang_t ghb_language_table[];
1917 export_lang_xlat2(GValue *lin_val)
1921 if (lin_val == NULL) return NULL;
1925 str = ghb_value_string(lin_val);
1926 for (ii = 0; ghb_language_table[ii].eng_name; ii++)
1928 if (strcmp(str, ghb_language_table[ii].iso639_2) == 0)
1932 if (ghb_language_table[ii].native_name[0] != 0)
1933 lang = ghb_language_table[ii].native_name;
1935 lang = ghb_language_table[ii].eng_name;
1937 gval = ghb_string_value_new(lang);
1942 g_debug("Can't map language value: (%s)", str);
1948 export_subtitle_xlat2(GValue *lin_val)
1953 if (lin_val == NULL) return NULL;
1954 str = ghb_value_string(lin_val);
1955 if (strcmp(str, "none") == 0)
1957 gval = ghb_string_value_new("None");
1959 else if (strcmp(str, "auto") == 0)
1961 gval = ghb_string_value_new("Autoselect");
1965 gval = export_lang_xlat2(lin_val);
1972 import_lang_xlat2(GValue *mac_val)
1976 if (mac_val == NULL) return NULL;
1980 str = ghb_value_string(mac_val);
1981 for (ii = 0; ghb_language_table[ii].eng_name; ii++)
1983 if ((strcmp(str, ghb_language_table[ii].eng_name) == 0) ||
1984 (strcmp(str, ghb_language_table[ii].native_name) == 0))
1986 gval = ghb_string_value_new(ghb_language_table[ii].iso639_2);
1991 g_debug("Can't map language value: (%s)", str);
1997 import_subtitle_xlat2(GValue *mac_val)
2002 if (mac_val == NULL) return NULL;
2003 str = ghb_value_string(mac_val);
2004 if (strcmp(str, "None") == 0)
2006 gval = ghb_string_value_new("none");
2008 else if (strcmp(str, "Autoselect") == 0)
2010 gval = ghb_string_value_new("auto");
2014 gval = import_lang_xlat2(mac_val);
2021 export_audio_track_xlat2(GValue *lin_val)
2024 GValue *gval = NULL;
2026 if (lin_val == NULL) return NULL;
2027 str = ghb_value_string(lin_val);
2028 if (strcmp(str, "none") == 0)
2030 gval = ghb_int_value_new(1);
2034 gint val = ghb_value_int(lin_val) + 1;
2035 gval = ghb_int_value_new(val);
2042 import_audio_track_xlat2(GValue *mac_val)
2048 if (mac_val == NULL) return NULL;
2049 val = ghb_value_int(mac_val);
2058 str = g_strdup_printf("%d", val);
2059 gval = ghb_string_value_new(str);
2065 export_value_xlat2(value_map_t *value_map, GValue *lin_val, GType mac_type)
2069 if (lin_val == NULL) return NULL;
2074 str = ghb_value_string(lin_val);
2075 for (ii = 0; value_map[ii].mac_val; ii++)
2077 if (strcmp(str, value_map[ii].lin_val) == 0)
2079 sval = ghb_string_value_new(value_map[ii].mac_val);
2081 gval = ghb_value_new(mac_type);
2082 if (!g_value_transform(sval, gval))
2084 g_warning("can't transform");
2085 ghb_value_free(gval);
2086 ghb_value_free(sval);
2089 ghb_value_free(sval);
2093 g_debug("Can't map value: (%s)", str);
2099 export_value_xlat(GValue *dict)
2101 GValue *lin_val, *gval;
2104 key = "VideoEncoder";
2105 lin_val = ghb_dict_lookup(dict, key);
2106 gval = export_value_xlat2(vcodec_xlat, lin_val, G_TYPE_STRING);
2108 ghb_dict_insert(dict, g_strdup(key), gval);
2110 lin_val = ghb_dict_lookup(dict, key);
2111 gval = export_value_xlat2(container_xlat, lin_val, G_TYPE_STRING);
2113 ghb_dict_insert(dict, g_strdup(key), gval);
2114 key = "VideoFramerate";
2115 lin_val = ghb_dict_lookup(dict, key);
2116 gval = export_value_xlat2(framerate_xlat, lin_val, G_TYPE_STRING);
2118 ghb_dict_insert(dict, g_strdup(key), gval);
2119 key = "PictureDetelecine";
2120 lin_val = ghb_dict_lookup(dict, key);
2121 gval = export_value_xlat2(detel_xlat, lin_val, G_TYPE_INT);
2123 ghb_dict_insert(dict, g_strdup(key), gval);
2124 key = "PictureDecomb";
2125 lin_val = ghb_dict_lookup(dict, key);
2126 gval = export_value_xlat2(decomb_xlat, lin_val, G_TYPE_INT);
2128 ghb_dict_insert(dict, g_strdup(key), gval);
2129 key = "PictureDeinterlace";
2130 lin_val = ghb_dict_lookup(dict, key);
2131 gval = export_value_xlat2(deint_xlat, lin_val, G_TYPE_INT);
2133 ghb_dict_insert(dict, g_strdup(key), gval);
2134 key = "PictureDenoise";
2135 lin_val = ghb_dict_lookup(dict, key);
2136 gval = export_value_xlat2(denoise_xlat, lin_val, G_TYPE_INT);
2138 ghb_dict_insert(dict, g_strdup(key), gval);
2144 slist = ghb_dict_lookup(dict, "SubtitleList");
2145 count = ghb_array_len(slist);
2146 for (ii = 0; ii < count; ii++)
2148 sdict = ghb_array_get_nth(slist, ii);
2149 key = "SubtitleLanguage";
2150 lin_val = ghb_dict_lookup(sdict, key);
2151 gval = export_subtitle_xlat2(lin_val);
2153 ghb_dict_insert(sdict, g_strdup(key), gval);
2159 alist = ghb_dict_lookup(dict, "AudioList");
2160 count = ghb_array_len(alist);
2161 for (ii = 0; ii < count; ii++)
2163 adict = ghb_array_get_nth(alist, ii);
2165 lin_val = ghb_dict_lookup(adict, key);
2166 gval = export_audio_track_xlat2(lin_val);
2168 ghb_dict_insert(adict, g_strdup(key), gval);
2169 key = "AudioEncoder";
2170 lin_val = ghb_dict_lookup(adict, key);
2171 gval = export_value_xlat2(acodec_xlat, lin_val, G_TYPE_STRING);
2173 ghb_dict_insert(adict, g_strdup(key), gval);
2174 key = "AudioSamplerate";
2175 lin_val = ghb_dict_lookup(adict, key);
2176 gval = export_value_xlat2(samplerate_xlat, lin_val, G_TYPE_STRING);
2178 ghb_dict_insert(adict, g_strdup(key), gval);
2179 key = "AudioMixdown";
2180 lin_val = ghb_dict_lookup(adict, key);
2181 gval = export_value_xlat2(mix_xlat, lin_val, G_TYPE_STRING);
2183 ghb_dict_insert(adict, g_strdup(key), gval);
2191 value_map_t *value_map,
2195 GValue *gval, *def_val;
2197 if (mac_val == NULL) return NULL;
2198 def_val = ghb_dict_lookup(defaults, key);
2205 str = ghb_value_string(mac_val);
2206 for (ii = 0; value_map[ii].mac_val; ii++)
2208 if (strcmp(str, value_map[ii].mac_val) == 0)
2210 sval = ghb_string_value_new(value_map[ii].lin_val);
2212 gval = ghb_value_new(G_VALUE_TYPE(def_val));
2213 if (!g_value_transform(sval, gval))
2215 g_warning("can't transform");
2216 ghb_value_free(gval);
2217 ghb_value_free(sval);
2220 ghb_value_free(sval);
2232 str = ghb_value_string(mac_val);
2233 for (ii = 0; value_map[ii].mac_val; ii++)
2235 if (strcmp(str, value_map[ii].mac_val) == 0)
2237 sval = ghb_string_value_new(value_map[ii].lin_val);
2239 gval = ghb_value_new(G_VALUE_TYPE(mac_val));
2240 if (!g_value_transform(sval, gval))
2242 g_warning("can't transform");
2243 ghb_value_free(gval);
2244 ghb_value_free(sval);
2247 ghb_value_free(sval);
2257 import_value_xlat(GValue *dict)
2259 GValue *defaults, *mac_val, *gval;
2262 defaults = plist_get_dict(internalPlist, "Presets");
2263 key = "VideoEncoder";
2264 mac_val = ghb_dict_lookup(dict, key);
2265 gval = import_value_xlat2(defaults, vcodec_xlat, key, mac_val);
2267 ghb_dict_insert(dict, g_strdup(key), gval);
2269 mac_val = ghb_dict_lookup(dict, key);
2270 gval = import_value_xlat2(defaults, container_xlat, key, mac_val);
2272 ghb_dict_insert(dict, g_strdup(key), gval);
2273 key = "VideoFramerate";
2274 mac_val = ghb_dict_lookup(dict, key);
2275 gval = import_value_xlat2(defaults, framerate_xlat, key, mac_val);
2277 ghb_dict_insert(dict, g_strdup(key), gval);
2278 key = "PictureDetelecine";
2279 mac_val = ghb_dict_lookup(dict, key);
2280 gval = import_value_xlat2(defaults, detel_xlat, key, mac_val);
2282 ghb_dict_insert(dict, g_strdup(key), gval);
2283 key = "PictureDecomb";
2284 mac_val = ghb_dict_lookup(dict, key);
2285 gval = import_value_xlat2(defaults, decomb_xlat, key, mac_val);
2287 ghb_dict_insert(dict, g_strdup(key), gval);
2288 key = "PictureDeinterlace";
2289 mac_val = ghb_dict_lookup(dict, key);
2290 gval = import_value_xlat2(defaults, deint_xlat, key, mac_val);
2292 ghb_dict_insert(dict, g_strdup(key), gval);
2293 key = "PictureDenoise";
2294 mac_val = ghb_dict_lookup(dict, key);
2295 gval = import_value_xlat2(defaults, denoise_xlat, key, mac_val);
2297 ghb_dict_insert(dict, g_strdup(key), gval);
2306 sdeflist = ghb_dict_lookup(defaults, "SubtitleList");
2309 slist = ghb_dict_lookup(dict, "SubtitleList");
2312 sdefaults = ghb_array_get_nth(sdeflist, 0);
2313 count = ghb_array_len(slist);
2314 for (ii = 0; ii < count; ii++)
2316 sdict = ghb_array_get_nth(slist, ii);
2317 key = "SubtitleLanguage";
2318 mac_val = ghb_dict_lookup(sdict, key);
2319 gval = import_subtitle_xlat2(mac_val);
2321 ghb_dict_insert(sdict, g_strdup(key), gval);
2328 mac_val = ghb_dict_lookup(dict, key);
2329 slist = ghb_array_value_new(8);
2330 ghb_dict_insert(dict, g_strdup("SubtitleList"), slist);
2335 gval = import_subtitle_xlat2(mac_val);
2336 lang = ghb_value_string(gval);
2337 if (lang && strcasecmp(lang, "none") != 0 && !slist)
2339 sdict = ghb_dict_value_new();
2340 ghb_array_append(slist, sdict);
2341 ghb_dict_insert(sdict, g_strdup("SubtitleLanguage"), gval);
2342 gval = ghb_dict_lookup(dict, "SubtitlesForced");
2345 ghb_dict_insert(sdict, g_strdup("SubtitleForced"),
2346 ghb_value_dup(gval));
2350 ghb_dict_insert(sdict, g_strdup("SubtitleForced"),
2351 ghb_boolean_value_new(FALSE));
2353 ghb_dict_insert(sdict, g_strdup("SubtitleBurned"),
2354 ghb_boolean_value_new(TRUE));
2355 ghb_dict_insert(sdict, g_strdup("SubtitleDefaultTrack"),
2356 ghb_boolean_value_new(FALSE));
2360 ghb_value_free(gval);
2367 ghb_dict_remove(dict, "Subtitles");
2368 ghb_dict_remove(dict, "SubtitlesForced");
2376 adeflist = ghb_dict_lookup(defaults, "AudioList");
2379 adefaults = ghb_array_get_nth(adeflist, 0);
2380 alist = ghb_dict_lookup(dict, "AudioList");
2381 count = ghb_array_len(alist);
2382 for (ii = 0; ii < count; ii++)
2384 adict = ghb_array_get_nth(alist, ii);
2386 mac_val = ghb_dict_lookup(adict, key);
2387 gval = import_audio_track_xlat2(mac_val);
2389 ghb_dict_insert(adict, g_strdup(key), gval);
2390 key = "AudioEncoder";
2391 mac_val = ghb_dict_lookup(adict, key);
2392 gval = import_value_xlat2(adefaults, acodec_xlat, key, mac_val);
2394 ghb_dict_insert(adict, g_strdup(key), gval);
2395 key = "AudioSamplerate";
2396 mac_val = ghb_dict_lookup(adict, key);
2397 gval = import_value_xlat2(adefaults, samplerate_xlat, key, mac_val);
2399 ghb_dict_insert(adict, g_strdup(key), gval);
2400 key = "AudioMixdown";
2401 mac_val = ghb_dict_lookup(adict, key);
2402 gval = import_value_xlat2(adefaults, mix_xlat, key, mac_val);
2404 ghb_dict_insert(adict, g_strdup(key), gval);
2406 mac_val = ghb_dict_lookup(adict, "AudioTrackDRCSlider");
2407 if (mac_val != NULL)
2410 drc = ghb_value_double(mac_val);
2411 if (drc < 1.0 && drc > 0.0)
2413 ghb_dict_insert(adict, g_strdup("AudioTrackDRCSlider"),
2414 ghb_double_value_new(0.0));
2422 import_xlat_preset(GValue *dict)
2429 g_debug("import_xlat_preset ()");
2430 uses_max = ghb_value_boolean(
2431 preset_dict_get_value(dict, "UsesMaxPictureSettings"));
2432 uses_pic = ghb_value_int(
2433 preset_dict_get_value(dict, "UsesPictureSettings"));
2434 par = ghb_value_int(preset_dict_get_value(dict, "PicturePAR"));
2435 vqtype = ghb_value_int(preset_dict_get_value(dict, "VideoQualityType"));
2437 if (uses_max || uses_pic == 2)
2439 ghb_dict_insert(dict, g_strdup("autoscale"),
2440 ghb_boolean_value_new(TRUE));
2446 if (ghb_dict_lookup(dict, "PictureModulus") == NULL)
2447 ghb_dict_insert(dict, g_strdup("PictureModulus"),
2448 ghb_int_value_new(16));
2452 ghb_dict_insert(dict, g_strdup("PictureModulus"),
2453 ghb_int_value_new(1));
2457 if (ghb_dict_lookup(dict, "PictureModulus") == NULL)
2458 ghb_dict_insert(dict, g_strdup("PictureModulus"),
2459 ghb_int_value_new(16));
2463 if (ghb_dict_lookup(dict, "PictureModulus") == NULL)
2464 ghb_dict_insert(dict, g_strdup("PictureModulus"),
2465 ghb_int_value_new(16));
2468 // VideoQualityType/0/1/2 - vquality_type_/target/bitrate/constant
2473 ghb_dict_insert(dict, g_strdup("vquality_type_target"),
2474 ghb_boolean_value_new(TRUE));
2475 ghb_dict_insert(dict, g_strdup("vquality_type_bitrate"),
2476 ghb_boolean_value_new(FALSE));
2477 ghb_dict_insert(dict, g_strdup("vquality_type_constant"),
2478 ghb_boolean_value_new(FALSE));
2482 ghb_dict_insert(dict, g_strdup("vquality_type_target"),
2483 ghb_boolean_value_new(FALSE));
2484 ghb_dict_insert(dict, g_strdup("vquality_type_bitrate"),
2485 ghb_boolean_value_new(TRUE));
2486 ghb_dict_insert(dict, g_strdup("vquality_type_constant"),
2487 ghb_boolean_value_new(FALSE));
2491 ghb_dict_insert(dict, g_strdup("vquality_type_target"),
2492 ghb_boolean_value_new(FALSE));
2493 ghb_dict_insert(dict, g_strdup("vquality_type_bitrate"),
2494 ghb_boolean_value_new(FALSE));
2495 ghb_dict_insert(dict, g_strdup("vquality_type_constant"),
2496 ghb_boolean_value_new(TRUE));
2500 ghb_dict_insert(dict, g_strdup("vquality_type_target"),
2501 ghb_boolean_value_new(FALSE));
2502 ghb_dict_insert(dict, g_strdup("vquality_type_bitrate"),
2503 ghb_boolean_value_new(FALSE));
2504 ghb_dict_insert(dict, g_strdup("vquality_type_constant"),
2505 ghb_boolean_value_new(TRUE));
2508 import_value_xlat(dict);
2513 vquality = ghb_value_double(preset_dict_get_value(dict, "VideoQualitySlider"));
2518 gval = preset_dict_get_value(dict, "VideoEncoder");
2519 vcodec = ghb_lookup_combo_int("VideoEncoder", gval);
2522 case HB_VCODEC_X264:
2524 vquality = 51. - vquality * 51.;
2527 case HB_VCODEC_FFMPEG:
2529 vquality = 31. - vquality * 30.;
2532 case HB_VCODEC_THEORA:
2534 vquality = vquality * 63.;
2542 ghb_dict_insert(dict, g_strdup("VideoQualitySlider"),
2543 ghb_double_value_new(vquality));
2548 import_xlat_presets(GValue *presets)
2554 g_debug("import_xlat_presets ()");
2555 if (presets == NULL) return;
2556 count = ghb_array_len(presets);
2557 for (ii = 0; ii < count; ii++)
2559 dict = ghb_array_get_nth(presets, ii);
2560 folder = ghb_value_boolean(preset_dict_get_value(dict, "Folder"));
2565 nested = ghb_dict_lookup(dict, "ChildrenArray");
2566 import_xlat_presets(nested);
2570 import_xlat_preset(dict);
2576 export_xlat_preset(GValue *dict)
2578 gboolean autoscale, target, br, constant;
2580 g_debug("export_xlat_prest ()");
2581 autoscale = ghb_value_boolean(preset_dict_get_value(dict, "autoscale"));
2582 target = ghb_value_boolean(
2583 preset_dict_get_value(dict, "vquality_type_target"));
2584 br = ghb_value_boolean(
2585 preset_dict_get_value(dict, "vquality_type_bitrate"));
2586 constant = ghb_value_boolean(
2587 preset_dict_get_value(dict, "vquality_type_constant"));
2590 ghb_dict_insert(dict, g_strdup("UsesPictureSettings"),
2591 ghb_int_value_new(2));
2593 ghb_dict_insert(dict, g_strdup("UsesPictureSettings"),
2594 ghb_int_value_new(1));
2596 // VideoQualityType/0/1/2 - vquality_type_/target/bitrate/constant
2599 ghb_dict_insert(dict, g_strdup("VideoQualityType"),
2600 ghb_int_value_new(0));
2604 ghb_dict_insert(dict, g_strdup("VideoQualityType"),
2605 ghb_int_value_new(1));
2609 ghb_dict_insert(dict, g_strdup("VideoQualityType"),
2610 ghb_int_value_new(2));
2613 GValue *alist, *adict;
2616 alist = ghb_dict_lookup(dict, "AudioList");
2617 count = ghb_array_len(alist);
2618 for (ii = 0; ii < count; ii++)
2622 adict = ghb_array_get_nth(alist, ii);
2623 drc = ghb_value_double(
2624 preset_dict_get_value(adict, "AudioTrackDRCSlider"));
2625 if (drc < 1.0 && drc > 0.0)
2627 ghb_dict_insert(adict, g_strdup("AudioTrackDRCSlider"),
2628 ghb_double_value_new(0.0));
2632 ghb_dict_remove(dict, "UsesMaxPictureSettings");
2633 ghb_dict_remove(dict, "autoscale");
2634 ghb_dict_remove(dict, "vquality_type_target");
2635 ghb_dict_remove(dict, "vquality_type_bitrate");
2636 ghb_dict_remove(dict, "vquality_type_constant");
2637 export_value_xlat(dict);
2641 export_xlat_presets(GValue *presets)
2647 if (presets == NULL) return;
2648 count = ghb_array_len(presets);
2649 for (ii = 0; ii < count; ii++)
2651 dict = ghb_array_get_nth(presets, ii);
2652 folder = ghb_value_boolean(preset_dict_get_value(dict, "Folder"));
2657 nested = ghb_dict_lookup(dict, "ChildrenArray");
2658 export_xlat_presets(nested);
2662 export_xlat_preset(dict);
2667 static guint prefs_timeout_id = 0;
2670 delayed_store_prefs(gpointer data)
2672 store_plist(prefsPlist, "preferences");
2673 prefs_timeout_id = 0;
2682 export = ghb_value_dup(presetsPlist);
2683 export_xlat_presets(export);
2684 store_plist(export, "presets");
2685 ghb_value_free(export);
2691 if (prefs_timeout_id != 0)
2696 mc = g_main_context_default();
2697 source = g_main_context_find_source_by_id(mc, prefs_timeout_id);
2699 g_source_destroy(source);
2701 prefs_timeout_id = g_timeout_add_seconds(1, (GSourceFunc)delayed_store_prefs, NULL);
2705 ghb_presets_reload(signal_user_data_t *ud)
2707 GValue *std_presets;
2711 g_debug("ghb_presets_reload()\n");
2712 std_presets = ghb_resource_get("standard-presets");
2713 if (std_presets == NULL) return;
2715 remove_std_presets(ud);
2716 indices = presets_find_default(presetsPlist, &len);
2719 presets_clear_default(std_presets);
2722 // Merge the keyfile contents into our presets
2723 count = ghb_array_len(std_presets);
2724 for (ii = count-1; ii >= 0; ii--)
2730 std_dict = ghb_array_get_nth(std_presets, ii);
2731 copy_dict = ghb_value_dup(std_dict);
2732 ghb_dict_insert(copy_dict, g_strdup("PresetBuildNumber"),
2733 ghb_int64_value_new(hb_get_build(NULL)));
2734 ghb_presets_insert(presetsPlist, copy_dict, &indices, 1);
2735 presets_list_insert(ud, &indices, 1);
2737 import_xlat_presets(presetsPlist);
2746 count = ghb_array_len(presetsPlist);
2747 for (ii = count-1; ii >= 0; ii--)
2752 dict = ghb_array_get_nth(presetsPlist, ii);
2753 type = ghb_dict_lookup(dict, "Type");
2761 replace_standard_presets()
2763 GValue *std_presets;
2767 count = ghb_array_len(presetsPlist);
2768 for (ii = count-1; ii >= 0; ii--)
2773 dict = ghb_array_get_nth(presetsPlist, ii);
2774 ptype = ghb_value_int(preset_dict_get_value(dict, "Type"));
2775 if (ptype == PRESETS_BUILTIN)
2778 ghb_presets_remove(presetsPlist, &indices, 1);
2782 std_presets = ghb_resource_get("standard-presets");
2783 if (std_presets == NULL) return;
2785 indices = presets_find_default(presetsPlist, &len);
2788 presets_clear_default(std_presets);
2791 // Merge the keyfile contents into our presets
2792 count = ghb_array_len(std_presets);
2793 for (ii = count-1; ii >= 0; ii--)
2799 std_dict = ghb_array_get_nth(std_presets, ii);
2800 copy_dict = ghb_value_dup(std_dict);
2801 ghb_dict_insert(copy_dict, g_strdup("PresetBuildNumber"),
2802 ghb_int64_value_new(hb_get_build(NULL)));
2803 ghb_presets_insert(presetsPlist, copy_dict, &indices, 1);
2805 import_xlat_presets(presetsPlist);
2810 update_standard_presets(signal_user_data_t *ud)
2814 count = ghb_array_len(presetsPlist);
2815 for (ii = count-1; ii >= 0; ii--)
2822 dict = ghb_array_get_nth(presetsPlist, ii);
2823 gval = ghb_dict_lookup(dict, "Type");
2826 // Old preset that doesn't have a Type
2827 replace_standard_presets();
2831 type = ghb_value_int(gval);
2834 gval = ghb_dict_lookup(dict, "PresetBuildNumber");
2837 // Old preset that doesn't have a build number
2838 replace_standard_presets();
2842 build = ghb_value_int64(gval);
2843 if (build != hb_get_build(NULL))
2845 // Build number does not match
2846 replace_standard_presets();
2855 ghb_presets_load(signal_user_data_t *ud)
2857 presetsPlist = load_plist("presets");
2858 if (presetsPlist == NULL)
2860 presetsPlist = ghb_value_dup(ghb_resource_get("standard-presets"));
2861 import_xlat_presets(presetsPlist);
2864 else if (G_VALUE_TYPE(presetsPlist) == ghb_dict_get_type())
2865 { // Presets is older dictionary format. Convert to array
2866 ghb_value_free(presetsPlist);
2867 presetsPlist = ghb_value_dup(ghb_resource_get("standard-presets"));
2868 import_xlat_presets(presetsPlist);
2871 else if (check_old_presets())
2873 ghb_value_free(presetsPlist);
2874 presetsPlist = ghb_value_dup(ghb_resource_get("standard-presets"));
2875 import_xlat_presets(presetsPlist);
2878 update_standard_presets(ud);
2879 import_xlat_presets(presetsPlist);
2883 settings_save(signal_user_data_t *ud, const GValue *path)
2885 GValue *dict, *internal;
2886 GHashTableIter iter;
2890 gint *indices, len, count;
2891 gint *def_indices, def_len;
2893 gboolean replace = FALSE;
2895 g_debug("settings_save");
2896 if (internalPlist == NULL) return;
2897 count = ghb_array_len(path);
2898 name = g_value_get_string(ghb_array_get_nth(path, count-1));
2899 indices = ghb_preset_indices_from_path(presetsPlist, path, &len);
2902 if (ghb_presets_get_folder(presetsPlist, indices, len))
2905 message = g_strdup_printf(
2906 "%s: Folder already exists.\n"
2907 "You can not replace it with a preset.",
2909 ghb_message_dialog(GTK_MESSAGE_ERROR, message, "Cancel", NULL);
2913 dict = ghb_dict_value_new();
2914 ghb_presets_replace(presetsPlist, dict, indices, len);
2919 indices = presets_find_pos(path, PRESETS_CUSTOM, &len);
2922 dict = ghb_dict_value_new();
2923 ghb_presets_insert(presetsPlist, dict, indices, len);
2927 g_warning("failed to find insert path");
2931 current_preset = dict;
2932 autoscale = ghb_settings_get_boolean(ud->settings, "autoscale");
2933 ghb_settings_set_int64(ud->settings, "Type", PRESETS_CUSTOM);
2934 ghb_settings_set_int64(ud->settings, "PresetBuildNumber", hb_get_build(NULL));
2936 internal = plist_get_dict(internalPlist, "Presets");
2937 ghb_dict_iter_init(&iter, internal);
2938 // middle (void*) cast prevents gcc warning "defreferencing type-punned
2939 // pointer will break strict-aliasing rules"
2940 while (g_hash_table_iter_next(
2941 &iter, (gpointer*)(void*)&key, (gpointer*)(void*)&value))
2949 if (strcmp(key, "PictureWidth") == 0)
2951 key2 = "scale_width";
2953 else if (strcmp(key, "PictureHeight") == 0)
2955 key2 = "scale_height";
2958 gval = ghb_settings_get_value(ud->settings, key2);
2963 ghb_dict_insert(dict, g_strdup(key), ghb_value_dup(gval));
2965 internal = plist_get_dict(internalPlist, "XlatPresets");
2966 ghb_dict_iter_init(&iter, internal);
2967 // middle (void*) cast prevents gcc warning "defreferencing type-punned
2968 // pointer will break strict-aliasing rules"
2969 while (g_hash_table_iter_next(
2970 &iter, (gpointer*)(void*)&key, (gpointer*)(void*)&value))
2974 gval = ghb_settings_get_value(ud->settings, key);
2979 ghb_dict_insert(dict, g_strdup(key), ghb_value_dup(gval));
2981 ghb_dict_insert(dict, g_strdup("PresetName"), ghb_string_value_new(name));
2984 def_indices = presets_find_default(presetsPlist, &def_len);
2985 if (def_indices != NULL &&
2986 preset_path_cmp(indices, len, def_indices, def_len) != 0)
2988 ghb_dict_insert(dict, g_strdup("Default"),
2989 ghb_boolean_value_new(FALSE));
2991 presets_list_update_item(ud, indices, len, FALSE);
2995 ghb_dict_insert(dict, g_strdup("Default"),
2996 ghb_boolean_value_new(FALSE));
2997 presets_list_insert(ud, indices, len);
3000 ud->dont_clear_presets = TRUE;
3001 // Make the new preset the selected item
3002 ghb_select_preset2(ud->builder, indices, len);
3004 ud->dont_clear_presets = FALSE;
3009 folder_save(signal_user_data_t *ud, const GValue *path)
3011 GValue *dict, *folder;
3012 gint *indices, len, count;
3015 count = ghb_array_len(path);
3016 name = g_value_get_string(ghb_array_get_nth(path, count-1));
3017 indices = ghb_preset_indices_from_path(presetsPlist, path, &len);
3020 if (!ghb_presets_get_folder(presetsPlist, indices, len))
3023 message = g_strdup_printf(
3024 "%s: Preset already exists.\n"
3025 "You can not replace it with a folder.",
3027 ghb_message_dialog(GTK_MESSAGE_ERROR, message, "Cancel", NULL);
3032 // Already exists, update its description
3033 dict = presets_get_dict(presetsPlist, indices, len);
3034 ghb_dict_insert(dict, g_strdup("PresetDescription"),
3035 ghb_value_dup(preset_dict_get_value(
3036 ud->settings, "PresetDescription")));
3037 presets_list_update_item(ud, indices, len, FALSE);
3044 indices = presets_find_pos(path, PRESETS_CUSTOM, &len);
3047 dict = ghb_dict_value_new();
3048 ghb_presets_insert(presetsPlist, dict, indices, len);
3052 g_warning("failed to find insert path");
3056 ghb_dict_insert(dict, g_strdup("PresetDescription"),
3057 ghb_value_dup(preset_dict_get_value(
3058 ud->settings, "PresetDescription")));
3059 ghb_dict_insert(dict, g_strdup("PresetName"), ghb_string_value_new(name));
3060 folder = ghb_array_value_new(8);
3061 ghb_dict_insert(dict, g_strdup("ChildrenArray"), folder);
3062 ghb_dict_insert(dict, g_strdup("Type"),
3063 ghb_int64_value_new(PRESETS_CUSTOM));
3064 ghb_dict_insert(dict, g_strdup("Folder"), ghb_boolean_value_new(TRUE));
3066 presets_list_insert(ud, indices, len);
3073 ghb_presets_list_default(signal_user_data_t *ud)
3075 GtkTreeView *treeview;
3076 GtkTreePath *treepath;
3078 GtkTreeStore *store;
3081 g_debug("ghb_presets_list_default ()");
3082 treeview = GTK_TREE_VIEW(GHB_WIDGET(ud->builder, "presets_list"));
3083 store = GTK_TREE_STORE(gtk_tree_view_get_model(treeview));
3084 indices = presets_find_default(presetsPlist, &len);
3085 if (indices == NULL) return;
3086 treepath = ghb_tree_path_new_from_indices(indices, len);
3089 if (gtk_tree_model_get_iter(GTK_TREE_MODEL(store), &iter, treepath))
3091 gtk_tree_store_set(store, &iter,
3096 gtk_tree_path_free(treepath);
3102 ghb_presets_list_clear_default(signal_user_data_t *ud)
3104 GtkTreeView *treeview;
3105 GtkTreePath *treepath;
3107 GtkTreeStore *store;
3110 g_debug("ghb_presets_list_clear_default ()");
3111 treeview = GTK_TREE_VIEW(GHB_WIDGET(ud->builder, "presets_list"));
3112 store = GTK_TREE_STORE(gtk_tree_view_get_model(treeview));
3113 indices = presets_find_default(presetsPlist, &len);
3114 if (indices == NULL) return;
3115 treepath = ghb_tree_path_new_from_indices(indices, len);
3118 if (gtk_tree_model_get_iter(GTK_TREE_MODEL(store), &iter, treepath))
3120 gtk_tree_store_set(store, &iter,
3125 gtk_tree_path_free(treepath);
3131 update_audio_presets(signal_user_data_t *ud)
3133 g_debug("update_audio_presets");
3134 const GValue *audio_list;
3136 audio_list = ghb_settings_get_value(ud->settings, "audio_list");
3137 ghb_settings_set_value(ud->settings, "AudioList", audio_list);
3141 update_subtitle_presets(signal_user_data_t *ud)
3143 g_debug("update_subtitle_presets");
3144 const GValue *subtitle_list, *subtitle;
3145 GValue *slist, *dict;
3146 gint count, ii, source;
3148 subtitle_list = ghb_settings_get_value(ud->settings, "subtitle_list");
3149 slist = ghb_array_value_new(8);
3150 count = ghb_array_len(subtitle_list);
3151 for (ii = 0; ii < count; ii++)
3153 subtitle = ghb_array_get_nth(subtitle_list, ii);
3154 source = ghb_settings_get_int(subtitle, "SubtitleSource");
3155 if (source != SRTSUB)
3157 dict = ghb_value_dup(subtitle);
3158 ghb_array_append(slist, dict);
3161 ghb_settings_take_value(ud->settings, "SubtitleList", slist);
3164 G_MODULE_EXPORT void
3165 presets_menu_clicked_cb(GtkWidget *xwidget, signal_user_data_t *ud)
3169 menu = GTK_MENU(GHB_WIDGET(ud->builder, "presets_menu"));
3170 gtk_menu_popup(menu, NULL, NULL, NULL, NULL, 1,
3171 gtk_get_current_event_time());
3174 G_MODULE_EXPORT void
3175 preset_import_clicked_cb(GtkWidget *xwidget, signal_user_data_t *ud)
3178 GtkResponseType response;
3181 GtkFileFilter *filter;
3183 g_debug("preset_import_clicked_cb ()");
3185 dialog = gtk_file_chooser_dialog_new("Import Preset", NULL,
3186 GTK_FILE_CHOOSER_ACTION_OPEN,
3187 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
3188 GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
3191 filter = gtk_file_filter_new();
3192 gtk_file_filter_set_name(filter, "All (*)");
3193 gtk_file_filter_add_pattern(filter, "*");
3194 gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(dialog), filter);
3196 filter = gtk_file_filter_new();
3197 gtk_file_filter_set_name(filter, "Presets (*.plist)");
3198 gtk_file_filter_add_pattern(filter, "*.plist");
3199 gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(dialog), filter);
3200 gtk_file_chooser_set_filter(GTK_FILE_CHOOSER(dialog), filter);
3202 exportDir = ghb_settings_get_string(ud->settings, "ExportDirectory");
3203 if (exportDir == NULL || exportDir[0] == '\0')
3205 exportDir = g_strdup(".");
3207 gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(dialog), exportDir);
3210 response = gtk_dialog_run(GTK_DIALOG(dialog));
3211 gtk_widget_hide(dialog);
3212 if (response == GTK_RESPONSE_ACCEPT)
3214 GValue *dict, *array;
3218 filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog));
3220 // import the preset
3221 if (!g_file_test(filename, G_FILE_TEST_IS_REGULAR))
3223 gtk_widget_destroy(dialog);
3227 array = ghb_plist_parse_file(filename);
3230 import_xlat_presets(array);
3231 presets_clear_default(array);
3232 presets_customize(array);
3234 count = ghb_array_len(array);
3235 for (ii = 0; ii < count; ii++)
3237 GValue *path, *name;
3241 dict = ghb_array_get_nth(array, ii);
3242 path = ghb_array_value_new(1);
3243 name = ghb_value_dup(ghb_dict_lookup(dict, "PresetName"));
3244 ghb_array_append(path, name);
3245 indices = ghb_preset_indices_from_path(presetsPlist, path, &len);
3246 // Modify the preset name till we make it unique
3247 while (indices != NULL)
3249 gchar *str = ghb_value_string(name);
3251 ghb_value_free(path);
3254 str = g_strdup_printf("%s %d", str, index);
3255 path = ghb_array_value_new(1);
3256 name = ghb_string_value_new(str);
3257 ghb_array_append(path, name);
3261 indices = ghb_preset_indices_from_path(presetsPlist, path, &len);
3263 ghb_dict_insert(dict, g_strdup("PresetName"), ghb_value_dup(name));
3264 indices = presets_find_pos(path, PRESETS_CUSTOM, &len);
3265 ghb_presets_insert(presetsPlist, ghb_value_dup(dict), indices, len);
3266 presets_list_insert(ud, indices, len);
3267 ghb_value_free(path);
3269 ghb_value_free(array);
3271 exportDir = ghb_settings_get_string(ud->settings, "ExportDirectory");
3272 dir = g_path_get_dirname(filename);
3273 if (strcmp(dir, exportDir) != 0)
3275 ghb_settings_set_string(ud->settings, "ExportDirectory", dir);
3276 ghb_pref_save(ud->settings, "ExportDirectory");
3281 gtk_widget_destroy(dialog);
3284 G_MODULE_EXPORT void
3285 preset_export_clicked_cb(GtkWidget *xwidget, signal_user_data_t *ud)
3288 GtkResponseType response;
3290 const gchar *name = "";
3291 gint count, *indices, len;
3295 g_debug("preset_export_clicked_cb ()");
3296 preset = ghb_settings_get_value (ud->settings, "preset_selection");
3300 count = ghb_array_len(preset);
3304 name = g_value_get_string(ghb_array_get_nth(preset, count-1));
3306 dialog = gtk_file_chooser_dialog_new("Export Preset", NULL,
3307 GTK_FILE_CHOOSER_ACTION_SAVE,
3308 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
3309 GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT,
3312 exportDir = ghb_settings_get_string(ud->settings, "ExportDirectory");
3313 if (exportDir == NULL || exportDir[0] == '\0')
3315 exportDir = g_strdup(".");
3317 filename = g_strdup_printf("%s.plist", name);
3318 gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(dialog), exportDir);
3319 gtk_file_chooser_set_current_name(GTK_FILE_CHOOSER(dialog), filename);
3323 indices = ghb_preset_indices_from_path(presetsPlist, preset, &len);
3324 if (indices == NULL)
3327 response = gtk_dialog_run(GTK_DIALOG(dialog));
3328 gtk_widget_hide(dialog);
3329 if (response == GTK_RESPONSE_ACCEPT)
3331 GValue *export, *dict, *array;
3335 filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog));
3337 // export the preset
3338 dict = presets_get_dict(presetsPlist, indices, len);
3340 export = ghb_value_dup(dict);
3341 array = ghb_array_value_new(1);
3342 ghb_array_append(array, export);
3343 presets_clear_default(array);
3344 presets_customize(array);
3345 export_xlat_presets(array);
3347 file = g_fopen(filename, "w");
3350 ghb_plist_write(file, array);
3353 ghb_value_free(array);
3355 exportDir = ghb_settings_get_string(ud->settings, "ExportDirectory");
3356 dir = g_path_get_dirname(filename);
3357 if (strcmp(dir, exportDir) != 0)
3359 ghb_settings_set_string(ud->settings, "ExportDirectory", dir);
3360 ghb_pref_save(ud->settings, "ExportDirectory");
3366 gtk_widget_destroy(dialog);
3370 G_MODULE_EXPORT void
3371 presets_new_folder_clicked_cb(GtkWidget *xwidget, signal_user_data_t *ud)
3376 GtkResponseType response;
3377 GValue *preset, *dict;
3378 const gchar *name = "";
3379 const gchar *description = "";
3380 gint count, *indices, len;
3382 g_debug("presets_save_clicked_cb ()");
3383 preset = ghb_settings_get_value (ud->settings, "preset_selection");
3385 count = ghb_array_len(preset);
3387 name = g_value_get_string(ghb_array_get_nth(preset, count-1));
3391 indices = ghb_preset_indices_from_path(presetsPlist, preset, &len);
3392 dict = presets_get_dict(presetsPlist, indices, len);
3395 description = g_value_get_string(
3396 ghb_dict_lookup(dict, "PresetDescription"));
3397 ghb_ui_update(ud, "PresetDescription", ghb_string_value(description));
3400 desc = GTK_TEXT_VIEW(GHB_WIDGET(ud->builder, "PresetDescription"));
3401 dialog = GHB_WIDGET(ud->builder, "preset_save_dialog");
3402 entry = GTK_ENTRY(GHB_WIDGET(ud->builder, "PresetName"));
3403 gtk_entry_set_text(entry, name);
3404 response = gtk_dialog_run(GTK_DIALOG(dialog));
3405 gtk_widget_hide(dialog);
3406 if (response == GTK_RESPONSE_OK)
3409 const gchar *name = gtk_entry_get_text(entry);
3412 if (count > MAX_NESTED_PRESET-1)
3413 count = MAX_NESTED_PRESET-1;
3415 dest = ghb_array_value_new(MAX_NESTED_PRESET);
3416 if (indices != NULL)
3420 ptype = ghb_presets_get_type(presetsPlist, indices, len);
3421 if (ptype == PRESETS_CUSTOM)
3423 ghb_array_copy(dest, preset, count-1);
3426 ghb_array_append(dest, ghb_string_value_new(name));
3427 ghb_widget_to_setting(ud->settings, GTK_WIDGET(desc));
3428 folder_save(ud, dest);
3429 ghb_value_free(dest);
3431 if (indices != NULL)
3435 G_MODULE_EXPORT void
3436 presets_save_clicked_cb(GtkWidget *xwidget, signal_user_data_t *ud)
3441 GtkResponseType response;
3443 const gchar *name = "";
3444 gint count, *indices, len;
3446 g_debug("presets_save_clicked_cb ()");
3447 preset = ghb_settings_get_value (ud->settings, "preset_selection");
3449 count = ghb_array_len(preset);
3451 name = g_value_get_string(ghb_array_get_nth(preset, count-1));
3455 desc = GTK_TEXT_VIEW(GHB_WIDGET(ud->builder, "PresetDescription"));
3456 dialog = GHB_WIDGET(ud->builder, "preset_save_dialog");
3457 entry = GTK_ENTRY(GHB_WIDGET(ud->builder, "PresetName"));
3458 gtk_entry_set_text(entry, name);
3459 response = gtk_dialog_run(GTK_DIALOG(dialog));
3460 gtk_widget_hide(dialog);
3461 if (response == GTK_RESPONSE_OK)
3464 const gchar *name = gtk_entry_get_text(entry);
3467 dest = ghb_array_value_new(MAX_NESTED_PRESET);
3468 indices = ghb_preset_indices_from_path(presetsPlist, preset, &len);
3473 ptype = ghb_presets_get_type(presetsPlist, indices, len);
3474 if (ptype == PRESETS_CUSTOM)
3476 ghb_array_copy(dest, preset, count-1);
3480 ghb_array_append(dest, ghb_string_value_new(name));
3482 ghb_widget_to_setting(ud->settings, GTK_WIDGET(desc));
3484 // Construct the audio settings presets from the current audio list
3485 update_audio_presets(ud);
3486 update_subtitle_presets(ud);
3487 settings_save(ud, dest);
3488 ghb_value_free(dest);
3492 G_MODULE_EXPORT void
3493 preset_type_changed_cb(GtkWidget *widget, signal_user_data_t *ud)
3495 ghb_widget_to_setting(ud->settings, widget);
3498 G_MODULE_EXPORT void
3499 presets_restore_clicked_cb(GtkWidget *xwidget, signal_user_data_t *ud)
3503 g_debug("presets_restore_clicked_cb ()");
3504 // Reload only the standard presets
3505 ghb_presets_reload(ud);
3506 // Updating the presets list shuffles things around
3507 // need to make sure the proper preset is selected
3508 preset = ghb_settings_get_value (ud->settings, "preset");
3509 ghb_select_preset(ud->builder, preset);
3512 G_MODULE_EXPORT void
3513 presets_remove_clicked_cb(GtkWidget *xwidget, signal_user_data_t *ud)
3515 GtkTreeView *treeview;
3516 GtkTreeSelection *selection;
3517 GtkTreeModel *store;
3520 GtkResponseType response;
3522 g_debug("presets_remove_clicked_cb ()");
3523 treeview = GTK_TREE_VIEW(GHB_WIDGET(ud->builder, "presets_list"));
3524 selection = gtk_tree_view_get_selection (treeview);
3525 if (gtk_tree_selection_get_selected(selection, &store, &iter))
3532 gtk_tree_model_get(store, &iter, 0, &preset, -1);
3533 path = gtk_tree_model_get_path(store, &iter);
3534 indices = gtk_tree_path_get_indices(path);
3535 len = gtk_tree_path_get_depth(path);
3537 folder = ghb_presets_get_folder(presetsPlist, indices, len);
3538 dialog = gtk_message_dialog_new(NULL, GTK_DIALOG_MODAL,
3539 GTK_MESSAGE_QUESTION, GTK_BUTTONS_YES_NO,
3540 "Confirm deletion of %s:\n\n%s",
3541 folder ? "folder" : "preset",
3543 response = gtk_dialog_run(GTK_DIALOG(dialog));
3544 gtk_widget_destroy (dialog);
3545 if (response == GTK_RESPONSE_YES)
3547 GtkTreeIter nextIter = iter;
3548 gboolean valid = TRUE;
3549 if (!gtk_tree_model_iter_next(store, &nextIter))
3551 if (!gtk_tree_model_iter_parent(store, &nextIter, &iter))
3556 // Remove the selected item
3557 // First unselect it so that selecting the new item works properly
3558 gtk_tree_selection_unselect_iter (selection, &iter);
3559 if (ghb_presets_remove(presetsPlist, indices, len))
3562 presets_list_remove(ud, indices, len);
3565 valid = gtk_tree_model_get_iter_first(store, &nextIter);
3568 gtk_tree_path_free(path);
3569 path = gtk_tree_model_get_path(store, &nextIter);
3570 indices = gtk_tree_path_get_indices(path);
3571 len = gtk_tree_path_get_depth(path);
3572 ghb_select_preset2(ud->builder, indices, len);
3576 gtk_tree_path_free(path);
3580 // controls where valid drop locations are
3581 G_MODULE_EXPORT gboolean
3582 presets_drag_motion_cb(
3584 GdkDragContext *ctx,
3588 signal_user_data_t *ud)
3590 GtkTreePath *path = NULL;
3591 GtkTreeViewDropPosition drop_pos;
3595 GtkTreeModel *model;
3596 GtkTreeSelection *select;
3597 gint src_ptype, dst_ptype;
3598 gboolean src_folder, dst_folder;
3600 gint tree_depth, ii;
3603 widget = gtk_drag_get_source_widget(ctx);
3604 if (widget == NULL || widget != GTK_WIDGET(tv))
3607 // Get the type of the object being dragged
3608 srctv = GTK_TREE_VIEW(gtk_drag_get_source_widget(ctx));
3609 select = gtk_tree_view_get_selection (srctv);
3610 gtk_tree_selection_get_selected (select, &model, &iter);
3611 path = gtk_tree_model_get_path (model, &iter);
3612 indices = gtk_tree_path_get_indices(path);
3613 len = gtk_tree_path_get_depth(path);
3615 preset = presets_get_dict(presetsPlist, indices, len);
3616 tree_depth = preset_tree_depth(preset);
3618 src_ptype = ghb_presets_get_type(presetsPlist, indices, len);
3619 src_folder = ghb_presets_get_folder(presetsPlist, indices, len);
3620 gtk_tree_path_free(path);
3622 if (src_folder && tree_depth == 1)
3625 // The rest checks that the destination is a valid position
3627 gtk_tree_view_get_dest_row_at_pos (tv, x, y, &path, &drop_pos);
3630 gdk_drag_status(ctx, 0, time);
3633 // Don't allow repositioning of builtin presets
3634 if (src_ptype != PRESETS_CUSTOM)
3636 gdk_drag_status(ctx, 0, time);
3640 len = gtk_tree_path_get_depth(path);
3641 if (len+tree_depth-1 >= MAX_NESTED_PRESET)
3643 if (drop_pos == GTK_TREE_VIEW_DROP_INTO_OR_BEFORE)
3644 drop_pos = GTK_TREE_VIEW_DROP_BEFORE;
3645 if (drop_pos == GTK_TREE_VIEW_DROP_INTO_OR_AFTER)
3646 drop_pos = GTK_TREE_VIEW_DROP_AFTER;
3648 for (ii = len+tree_depth-1; ii > MAX_NESTED_PRESET; ii--)
3649 gtk_tree_path_up(path);
3650 indices = gtk_tree_path_get_indices(path);
3651 len = gtk_tree_path_get_depth(path);
3652 dst_ptype = ghb_presets_get_type(presetsPlist, indices, len);
3653 dst_folder = ghb_presets_get_folder(presetsPlist, indices, len);
3654 // Don't allow mixing custom presets in the builtins
3655 if (dst_ptype != PRESETS_CUSTOM)
3657 gdk_drag_status(ctx, 0, time);
3661 // Only allow *drop into* for folders
3664 if (drop_pos == GTK_TREE_VIEW_DROP_INTO_OR_BEFORE)
3665 drop_pos = GTK_TREE_VIEW_DROP_BEFORE;
3666 if (drop_pos == GTK_TREE_VIEW_DROP_INTO_OR_AFTER)
3667 drop_pos = GTK_TREE_VIEW_DROP_AFTER;
3670 len = gtk_tree_path_get_depth(path);
3671 gtk_tree_view_set_drag_dest_row(tv, path, drop_pos);
3672 gtk_tree_path_free(path);
3673 gdk_drag_status(ctx, GDK_ACTION_MOVE, time);
3677 G_MODULE_EXPORT void
3679 GtkTreeView *dstwidget,
3682 GtkSelectionData *selection_data,
3683 guint info, guint t,
3684 signal_user_data_t *ud)
3686 GtkTreePath *path = NULL;
3687 GtkTreeViewDropPosition drop_pos;
3688 GtkTreeIter dstiter, srciter;
3689 gint *dst_indices, dst_len, *src_indices, src_len;
3691 gboolean src_folder, dst_folder;
3693 GtkTreeModel *dstmodel = gtk_tree_view_get_model(dstwidget);
3695 g_debug("preset_drag_cb ()");
3696 // This doesn't work here for some reason...
3697 // gtk_tree_view_get_drag_dest_row(dstwidget, &path, &drop_pos);
3698 gtk_tree_view_get_dest_row_at_pos (dstwidget, x, y, &path, &drop_pos);
3699 // This little hack is needed because attempting to drop after
3700 // the last item gives us no path or drop_pos.
3705 n_children = gtk_tree_model_iter_n_children(dstmodel, NULL);
3708 drop_pos = GTK_TREE_VIEW_DROP_AFTER;
3709 path = gtk_tree_path_new_from_indices(n_children-1, -1);
3713 drop_pos = GTK_TREE_VIEW_DROP_BEFORE;
3714 path = gtk_tree_path_new_from_indices(0, -1);
3719 GtkTreeView *srcwidget;
3720 GtkTreeModel *srcmodel;
3721 GtkTreeSelection *select;
3722 GtkTreePath *srcpath = NULL;
3724 gint tree_depth, ii;
3726 srcwidget = GTK_TREE_VIEW(gtk_drag_get_source_widget(dc));
3727 select = gtk_tree_view_get_selection (srcwidget);
3728 gtk_tree_selection_get_selected (select, &srcmodel, &srciter);
3730 srcpath = gtk_tree_model_get_path (srcmodel, &srciter);
3731 src_indices = gtk_tree_path_get_indices(srcpath);
3732 src_len = gtk_tree_path_get_depth(srcpath);
3733 src_ptype = ghb_presets_get_type(presetsPlist, src_indices, src_len);
3734 src_folder = ghb_presets_get_folder(presetsPlist, src_indices, src_len);
3735 preset = ghb_value_dup(
3736 presets_get_dict(presetsPlist, src_indices, src_len));
3737 gtk_tree_path_free(srcpath);
3739 // Don't allow repositioning of builtin presets
3740 if (src_ptype != PRESETS_CUSTOM)
3743 tree_depth = preset_tree_depth(preset);
3744 if (src_folder && tree_depth == 1)
3747 dst_len = gtk_tree_path_get_depth(path);
3748 if (dst_len+tree_depth-1 >= MAX_NESTED_PRESET)
3750 if (drop_pos == GTK_TREE_VIEW_DROP_INTO_OR_BEFORE)
3751 drop_pos = GTK_TREE_VIEW_DROP_BEFORE;
3752 if (drop_pos == GTK_TREE_VIEW_DROP_INTO_OR_AFTER)
3753 drop_pos = GTK_TREE_VIEW_DROP_AFTER;
3756 for (ii = dst_len+tree_depth-1; ii > MAX_NESTED_PRESET; ii--)
3757 gtk_tree_path_up(path);
3758 dst_indices = gtk_tree_path_get_indices(path);
3759 dst_len = gtk_tree_path_get_depth(path);
3760 dst_folder = ghb_presets_get_folder(presetsPlist, dst_indices, dst_len);
3761 // Only allow *drop into* for folders
3764 if (drop_pos == GTK_TREE_VIEW_DROP_INTO_OR_BEFORE)
3765 drop_pos = GTK_TREE_VIEW_DROP_BEFORE;
3766 if (drop_pos == GTK_TREE_VIEW_DROP_INTO_OR_AFTER)
3767 drop_pos = GTK_TREE_VIEW_DROP_AFTER;
3769 if (gtk_tree_model_get_iter (dstmodel, &dstiter, path))
3772 GtkTreePath *dstpath = NULL;
3776 case GTK_TREE_VIEW_DROP_BEFORE:
3777 gtk_tree_store_insert_before(GTK_TREE_STORE (dstmodel),
3778 &iter, NULL, &dstiter);
3781 case GTK_TREE_VIEW_DROP_INTO_OR_BEFORE:
3782 gtk_tree_store_insert(GTK_TREE_STORE (dstmodel),
3783 &iter, &dstiter, 0);
3786 case GTK_TREE_VIEW_DROP_AFTER:
3787 gtk_tree_store_insert_after(GTK_TREE_STORE (dstmodel),
3788 &iter, NULL, &dstiter);
3791 case GTK_TREE_VIEW_DROP_INTO_OR_AFTER:
3792 gtk_tree_store_insert_after(GTK_TREE_STORE (dstmodel),
3793 &iter, &dstiter, 0);
3800 dstpath = gtk_tree_model_get_path (dstmodel, &iter);
3801 dst_indices = gtk_tree_path_get_indices(dstpath);
3802 dst_len = gtk_tree_path_get_depth(dstpath);
3803 ghb_presets_insert(presetsPlist, preset, dst_indices, dst_len);
3804 gtk_tree_path_free(dstpath);
3806 srcpath = gtk_tree_model_get_path (srcmodel, &srciter);
3807 src_indices = gtk_tree_path_get_indices(srcpath);
3808 src_len = gtk_tree_path_get_depth(srcpath);
3809 ghb_presets_remove(presetsPlist, src_indices, src_len);
3810 gtk_tree_path_free(srcpath);
3812 gtk_tree_store_remove (GTK_TREE_STORE (srcmodel), &srciter);
3814 dstpath = gtk_tree_model_get_path (dstmodel, &iter);
3815 dst_indices = gtk_tree_path_get_indices(dstpath);
3816 dst_len = gtk_tree_path_get_depth(dstpath);
3817 presets_list_update_item(ud, dst_indices, dst_len, TRUE);
3818 gtk_tree_path_free(dstpath);
3822 gtk_tree_path_free(path);
3827 presets_row_expanded_cb(
3828 GtkTreeView *treeview,
3831 signal_user_data_t *ud)
3834 gboolean expanded, folder;
3837 expanded = gtk_tree_view_row_expanded(treeview, path);
3838 indices = gtk_tree_path_get_indices(path);
3839 len = gtk_tree_path_get_depth(path);
3840 dict = presets_get_dict(presetsPlist, indices, len);
3841 if (preset_folder_is_open(dict))
3850 folder = ghb_presets_get_folder(presetsPlist, indices, len);
3853 presets_set_folder_open(expanded, indices, len);
3856 // Collapsing parent folder collapses all children
3859 GValue *presets = NULL;
3860 gint *more_indices, count, ii;
3862 more_indices = g_malloc((len+1)*sizeof(gint));
3863 memcpy(more_indices, indices, len*sizeof(gint));
3865 presets = presets_get_folder(presetsPlist, indices, len);
3866 count = ghb_array_len(presets);
3867 for (ii = 0; ii < count; ii++)
3869 dict = ghb_array_get_nth(presets, ii);
3870 folder = ghb_preset_folder(dict);
3873 more_indices[len] = ii;
3874 presets_set_folder_open(expanded, more_indices, len+1);
3877 g_free(more_indices);
3883 preset_update_title_deps(signal_user_data_t *ud, ghb_title_info_t *tinfo)
3887 ghb_ui_update(ud, "scale_width",
3888 ghb_int64_value(tinfo->width - tinfo->crop[2] - tinfo->crop[3]));
3889 // If anamorphic or keep_aspect, the hight will be automatically calculated
3890 gboolean keep_aspect;
3892 keep_aspect = ghb_settings_get_boolean(ud->settings, "PictureKeepRatio");
3893 pic_par = ghb_settings_combo_int(ud->settings, "PicturePAR");
3894 if (!(keep_aspect || pic_par) || pic_par == 3)
3896 ghb_ui_update(ud, "scale_height",
3897 ghb_int64_value(tinfo->height - tinfo->crop[0] - tinfo->crop[1]));
3900 // Set the limits of cropping. hb_set_anamorphic_size crashes if
3901 // you pass it a cropped width or height == 0.
3903 bound = tinfo->height / 2 - 2;
3904 widget = GHB_WIDGET (ud->builder, "PictureTopCrop");
3905 gtk_spin_button_set_range (GTK_SPIN_BUTTON(widget), 0, bound);
3906 widget = GHB_WIDGET (ud->builder, "PictureBottomCrop");
3907 gtk_spin_button_set_range (GTK_SPIN_BUTTON(widget), 0, bound);
3908 bound = tinfo->width / 2 - 2;
3909 widget = GHB_WIDGET (ud->builder, "PictureLeftCrop");
3910 gtk_spin_button_set_range (GTK_SPIN_BUTTON(widget), 0, bound);
3911 widget = GHB_WIDGET (ud->builder, "PictureRightCrop");
3912 gtk_spin_button_set_range (GTK_SPIN_BUTTON(widget), 0, bound);
3913 if (ghb_settings_get_boolean(ud->settings, "PictureAutoCrop"))
3915 ghb_ui_update(ud, "PictureTopCrop", ghb_int64_value(tinfo->crop[0]));
3916 ghb_ui_update(ud, "PictureBottomCrop", ghb_int64_value(tinfo->crop[1]));
3917 ghb_ui_update(ud, "PictureLeftCrop", ghb_int64_value(tinfo->crop[2]));
3918 ghb_ui_update(ud, "PictureRightCrop", ghb_int64_value(tinfo->crop[3]));
3922 G_MODULE_EXPORT void
3923 presets_list_selection_changed_cb(GtkTreeSelection *selection, signal_user_data_t *ud)
3925 GtkTreeModel *store;
3927 ghb_title_info_t tinfo;
3930 g_debug("presets_list_selection_changed_cb ()");
3931 widget = GHB_WIDGET (ud->builder, "presets_remove");
3932 if (gtk_tree_selection_get_selected(selection, &store, &iter))
3934 GtkTreePath *treepath;
3939 treepath = gtk_tree_model_get_path(store, &iter);
3940 indices = gtk_tree_path_get_indices(treepath);
3941 len = gtk_tree_path_get_depth(treepath);
3943 path = preset_path_from_indices(presetsPlist, indices, len);
3944 ghb_settings_take_value(ud->settings, "preset_selection", path);
3946 folder = ghb_presets_get_folder(presetsPlist, indices, len);
3949 ud->dont_clear_presets = TRUE;
3950 // Temporarily set the video_quality range to (0,100)
3951 // This is needed so the video_quality value does not get
3952 // truncated when set. The range will be readjusted below
3953 GtkWidget *qp = GHB_WIDGET(ud->builder, "VideoQualitySlider");
3954 gtk_range_set_range (GTK_RANGE(qp), 0, 100);
3955 gtk_scale_set_digits(GTK_SCALE(qp), 3);
3956 // Clear the audio list prior to changing the preset. Existing
3957 // audio can cause the container extension to be automatically
3958 // changed when it shouldn't be
3959 ghb_clear_audio_list(ud);
3960 ghb_set_preset_from_indices(ud, indices, len);
3961 gtk_tree_path_free(treepath);
3963 titleindex = ghb_settings_combo_int(ud->settings, "title");
3964 ghb_set_pref_audio(titleindex, ud);
3965 ghb_set_pref_subtitle(titleindex, ud);
3966 ghb_settings_set_boolean(ud->settings, "preset_modified", FALSE);
3967 if (ghb_get_title_info (&tinfo, titleindex))
3969 preset_update_title_deps(ud, &tinfo);
3971 ghb_set_scale (ud, GHB_PIC_KEEP_PAR);
3972 ud->dont_clear_presets = FALSE;
3974 gdouble vqmin, vqmax, step, page;
3978 ghb_vquality_range(ud, &vqmin, &vqmax, &step,
3979 &page, &digits, &inverted);
3980 gtk_range_set_range (GTK_RANGE(qp), vqmin, vqmax);
3981 gtk_range_set_increments (GTK_RANGE(qp), step, page);
3982 gtk_scale_set_digits(GTK_SCALE(qp), digits);
3983 gtk_range_set_inverted (GTK_RANGE(qp), inverted);
3987 GtkWidget *crop_widget;
3988 crop[0] = ghb_settings_get_int(ud->settings, "PictureTopCrop");
3989 crop[1] = ghb_settings_get_int(ud->settings, "PictureBottomCrop");
3990 crop[2] = ghb_settings_get_int(ud->settings, "PictureLeftCrop");
3991 crop[3] = ghb_settings_get_int(ud->settings, "PictureRightCrop");
3992 crop_widget = GHB_WIDGET (ud->builder, "crop_values");
3993 text = g_strdup_printf("%d:%d:%d:%d",
3994 crop[0], crop[1], crop[2], crop[3]);
3995 gtk_label_set_text (GTK_LABEL(crop_widget), text);
3998 gtk_widget_set_sensitive(widget, TRUE);
4002 g_debug("No selection??? Perhaps unselected.");
4003 gtk_widget_set_sensitive(widget, FALSE);
4008 ghb_clear_presets_selection(signal_user_data_t *ud)
4010 GtkTreeView *treeview;
4011 GtkTreeSelection *selection;
4013 if (ud->dont_clear_presets) return;
4014 g_debug("ghb_clear_presets_selection()");
4015 treeview = GTK_TREE_VIEW(GHB_WIDGET(ud->builder, "presets_list"));
4016 selection = gtk_tree_view_get_selection (treeview);
4017 gtk_tree_selection_unselect_all (selection);
4018 ghb_settings_set_boolean(ud->settings, "preset_modified", TRUE);
4021 G_MODULE_EXPORT void
4022 presets_frame_size_allocate_cb(GtkWidget *widget, GtkAllocation *allocation, signal_user_data_t *ud)
4024 GtkTreeView *treeview;
4025 GtkTreeSelection *selection;
4026 GtkTreeModel *store;
4029 treeview = GTK_TREE_VIEW(GHB_WIDGET(ud->builder, "presets_list"));
4030 selection = gtk_tree_view_get_selection(treeview);
4031 if (gtk_tree_selection_get_selected(selection, &store, &iter))
4034 path = gtk_tree_model_get_path (store, &iter);
4035 // Make the parent visible in scroll window if it is not.
4036 gtk_tree_view_scroll_to_cell (treeview, path, NULL, FALSE, 0, 0);
4037 gtk_tree_path_free(path);
4041 G_MODULE_EXPORT void
4042 presets_default_clicked_cb(GtkWidget *xwidget, signal_user_data_t *ud)
4047 g_debug("presets_default_clicked_cb ()");
4048 preset = ghb_settings_get_value(ud->settings, "preset_selection");
4049 indices = ghb_preset_indices_from_path(presetsPlist, preset, &len);
4052 if (!ghb_presets_get_folder(presetsPlist, indices, len))
4054 ghb_presets_list_clear_default(ud);
4055 presets_set_default(indices, len);
4056 ghb_presets_list_default(ud);
4062 G_MODULE_EXPORT void
4064 GtkCellRendererText *cell,
4067 signal_user_data_t *ud)
4069 GtkTreePath *treepath;
4070 GtkTreeStore *store;
4071 GtkTreeView *treeview;
4073 gint *indices, len, count;
4075 GValue *preset, *dest;
4077 g_debug("preset_edited_cb ()");
4078 g_debug("path (%s)", path);
4079 g_debug("text (%s)", text);
4081 preset = ghb_settings_get_value (ud->settings, "preset_selection");
4082 dest = ghb_array_value_new(MAX_NESTED_PRESET);
4083 count = ghb_array_len(preset);
4084 ghb_array_copy(dest, preset, count-1);
4085 ghb_array_append(dest, ghb_string_value_new(text));
4086 indices = ghb_preset_indices_from_path(presetsPlist, dest, &len);
4087 ghb_value_free(dest);
4088 if (indices != NULL)
4095 treeview = GTK_TREE_VIEW(GHB_WIDGET(ud->builder, "presets_list"));
4096 store = GTK_TREE_STORE(gtk_tree_view_get_model(treeview));
4097 treepath = gtk_tree_path_new_from_string (path);
4098 indices = gtk_tree_path_get_indices(treepath);
4099 len = gtk_tree_path_get_depth(treepath);
4100 gtk_tree_model_get_iter(GTK_TREE_MODEL(store), &iter, treepath);
4101 gtk_tree_store_set(store, &iter, 0, text, -1);
4103 dict = presets_get_dict(presetsPlist, indices, len);
4104 ghb_dict_insert(dict, g_strdup("PresetName"), ghb_string_value_new(text));
4106 gtk_tree_path_free (treepath);