1 /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
4 * Copyright (C) John Stebbins 2008 <stebbins@stebbins>
6 * presets.c is free software.
8 * You may redistribute it and/or modify it under the terms of the
9 * GNU General Public License, as published by the Free Software
10 * Foundation; either version 2 of the License, or (at your option)
15 #include <glib-object.h>
16 #include <glib/gstdio.h>
21 #include "callbacks.h"
22 #include "audiohandler.h"
23 #include "subtitlehandler.h"
24 #include "hb-backend.h"
26 #include "resources.h"
31 #define MAX_NESTED_PRESET 3
39 static GValue *presetsPlist = NULL;
40 static GValue *internalPlist = NULL;
41 static GValue *prefsPlist = NULL;
42 static gboolean prefs_modified = FALSE;
44 static const GValue* preset_dict_get_value(GValue *dict, const gchar *key);
45 static void store_plist(GValue *plist, const gchar *name);
46 static void store_presets(void);
47 static void store_prefs(void);
50 preset_path_cmp(gint *indices1, gint len1, gint *indices2, gint len2)
53 for (ii = 0; ii < len1 && ii < len2; ii++)
55 if (indices1[ii] != indices2[ii])
56 return indices1[ii] - indices2[ii];
61 // This only handle limited depth
63 ghb_tree_path_new_from_indices(gint *indices, gint len)
68 return gtk_tree_path_new_from_indices(
71 return gtk_tree_path_new_from_indices(
72 indices[0], indices[1], -1);
74 return gtk_tree_path_new_from_indices(
75 indices[0], indices[1], indices[2], -1);
77 return gtk_tree_path_new_from_indices(
78 indices[0], indices[1], indices[2], indices[3], -1);
80 return gtk_tree_path_new_from_indices(
81 indices[0], indices[1], indices[2], indices[3], indices[4], -1);
88 ghb_parse_preset_path(const gchar *path)
94 preset = ghb_array_value_new(MAX_NESTED_PRESET);
95 split = g_strsplit(path, "#", MAX_NESTED_PRESET);
96 for (ii = 0; split[ii] != NULL; ii++)
98 ghb_array_append(preset, ghb_string_value_new(split[ii]));
105 preset_path_from_indices(GValue *presets, gint *indices, gint len)
110 g_debug("preset_path_from_indices");
111 path = ghb_array_value_new(MAX_NESTED_PRESET);
112 for (ii = 0; ii < len; ii++)
118 count = ghb_array_len(presets);
119 if (indices[ii] >= count) break;
120 dict = ghb_array_get_nth(presets, indices[ii]);
121 name = ghb_dict_lookup(dict, "PresetName");
123 ghb_array_append(path, ghb_value_dup(name));
124 folder = ghb_value_boolean(preset_dict_get_value(dict, "Folder"));
127 presets = ghb_dict_lookup(dict, "ChildrenArray");
133 ghb_preset_path_string(const GValue *path)
140 gstr = g_string_new("");
143 count = ghb_array_len(path);
144 for (ii = 0; ii < count; ii++)
146 val = ghb_array_get_nth(path, ii);
147 str = ghb_value_string(val);
148 g_string_append(gstr, str);
150 g_string_append(gstr, "->");
154 str = g_string_free(gstr, FALSE);
159 dump_preset_path(const gchar *msg, const GValue *path)
164 debug_show_type (G_VALUE_TYPE(path));
165 str = ghb_preset_path_string(path);
166 g_message("%s path: (%s)", msg, str);
171 dump_preset_indices(const gchar *msg, gint *indices, gint len)
175 g_message("%s indices: len %d", msg, len);
176 for (ii = 0; ii < len; ii++)
178 printf("%d ", indices[ii]);
185 preset_path_cmp(const GValue *path1, const GValue *path2)
192 count = ghb_array_len(path1);
193 ii = ghb_array_len(path2);
196 for (ii = 0; ii < count; ii++)
198 val = ghb_array_get_nth(path1, ii);
199 str1 = ghb_value_string(val);
200 val = ghb_array_get_nth(path2, ii);
201 str2 = ghb_value_string(val);
202 result = strcmp(str1, str2);
213 presets_get_dict(GValue *presets, gint *indices, gint len)
215 gint ii, count, folder;
218 g_debug("presets_get_dict ()");
219 for (ii = 0; ii < len; ii++)
221 count = ghb_array_len(presets);
222 if (indices[ii] >= count) return NULL;
223 dict = ghb_array_get_nth(presets, indices[ii]);
226 folder = ghb_value_boolean(preset_dict_get_value(dict, "Folder"));
229 presets = ghb_dict_lookup(dict, "ChildrenArray");
238 presets_get_folder(GValue *presets, gint *indices, gint len)
240 gint ii, count, folder;
243 g_debug("presets_get_folder ()");
244 for (ii = 0; ii < len; ii++)
246 count = ghb_array_len(presets);
247 if (indices[ii] >= count) return NULL;
248 dict = ghb_array_get_nth(presets, indices[ii]);
249 folder = ghb_value_boolean(preset_dict_get_value(dict, "Folder"));
252 presets = ghb_dict_lookup(dict, "ChildrenArray");
260 plist_get_dict(GValue *presets, const gchar *name)
262 if (presets == NULL || name == NULL) return NULL;
263 return ghb_dict_lookup(presets, name);
267 preset_get_name(GValue *dict)
269 return g_value_get_string(preset_dict_get_value(dict, "PresetName"));
273 preset_folder_is_open(GValue *dict)
277 gval = preset_dict_get_value(dict, "FolderOpen");
279 return g_value_get_boolean(gval);
284 ghb_preset_folder(GValue *dict)
286 return ghb_value_int(preset_dict_get_value(dict, "Folder"));
290 ghb_preset_type(GValue *dict)
292 return ghb_value_int(preset_dict_get_value(dict, "Type"));
296 presets_remove_nth(GValue *presets, gint pos)
301 if (presets == NULL || pos < 0) return;
302 count = ghb_array_len(presets);
303 if (pos >= count) return;
304 dict = ghb_array_get_nth(presets, pos);
305 ghb_array_remove(presets, pos);
306 ghb_value_free(dict);
315 GValue *folder = NULL;
317 folder = presets_get_folder(presets, indices, len-1);
319 presets_remove_nth(folder, indices[len-1]);
322 g_warning("ghb_presets_remove (): internal preset lookup error");
335 GValue *folder = NULL;
337 folder = presets_get_folder(presets, indices, len-1);
339 ghb_array_replace(folder, indices[len-1], dict);
342 g_warning("ghb_presets_replace (): internal preset lookup error");
353 GValue *folder = NULL;
355 folder = presets_get_folder(presets, indices, len-1);
357 ghb_array_insert(folder, indices[len-1], dict);
360 g_warning("ghb_presets_insert (): internal preset lookup error");
365 presets_find_element(GValue *presets, const gchar *name)
370 g_debug("presets_find_element () (%s)", name);
371 if (presets == NULL || name == NULL) return -1;
372 count = ghb_array_len(presets);
373 for (ii = 0; ii < count; ii++)
376 dict = ghb_array_get_nth(presets, ii);
377 str = preset_get_name(dict);
378 if (strcmp(name, str) == 0)
387 single_find_pos(GValue *presets, const gchar *name, gint type)
390 gint count, ii, ptype, last;
392 if (presets == NULL || name == NULL) return -1;
393 last = count = ghb_array_len(presets);
394 for (ii = 0; ii < count; ii++)
397 dict = ghb_array_get_nth(presets, ii);
398 str = preset_get_name(dict);
399 ptype = ghb_value_int(preset_dict_get_value(dict, "Type"));
400 if (strcasecmp(name, str) <= 0 && ptype == type)
411 presets_find_pos(const GValue *path, gint type, gint *len)
417 gint *indices = NULL;
421 g_debug("presets_find_pos () ");
422 nested = presetsPlist;
423 count = ghb_array_len(path);
424 indices = g_malloc(MAX_NESTED_PRESET * sizeof(gint));
425 for (ii = 0; ii < count-1; ii++)
427 val = ghb_array_get_nth(path, ii);
428 name = g_value_get_string(val);
429 indices[ii] = presets_find_element(nested, name);
430 if (indices[ii] == -1) return NULL;
431 dict = ghb_array_get_nth(nested, indices[ii]);
432 folder = ghb_value_boolean(preset_dict_get_value(dict, "Folder"));
436 nested = ghb_dict_lookup(dict, "ChildrenArray");
442 name = g_value_get_string(ghb_array_get_nth(path, count-1));
443 indices[ii] = single_find_pos(nested, name, type);
451 preset_tree_depth(GValue *dict)
455 folder = ghb_value_boolean(preset_dict_get_value(dict, "Folder"));
462 presets = ghb_dict_lookup(dict, "ChildrenArray");
463 count = ghb_array_len(presets);
464 for (ii = 0; ii < count; ii++)
468 dict = ghb_array_get_nth(presets, ii);
469 tmp = preset_tree_depth(dict);
470 depth = MAX(depth, tmp);
481 preset_is_default(GValue *dict)
485 val = preset_dict_get_value(dict, "Default");
486 return ghb_value_boolean(val);
490 presets_clear_default(GValue *presets)
494 count = ghb_array_len(presets);
495 for (ii = 0; ii < count; ii++)
500 dict = ghb_array_get_nth(presets, ii);
501 folder = ghb_value_boolean(preset_dict_get_value(dict, "Folder"));
506 nested = ghb_dict_lookup(dict, "ChildrenArray");
507 presets_clear_default(nested);
511 if (preset_is_default(dict))
513 ghb_dict_insert(dict, g_strdup("Default"),
514 ghb_boolean_value_new(FALSE));
521 presets_find_default2(GValue *presets, gint *len)
526 count = ghb_array_len(presets);
527 for (ii = 0; ii < count; ii++)
532 dict = ghb_array_get_nth(presets, ii);
533 folder = ghb_value_boolean(preset_dict_get_value(dict, "Folder"));
539 nested = ghb_dict_lookup(dict, "ChildrenArray");
541 indices = presets_find_default2(nested, len);
552 if (preset_is_default(dict))
554 indices = g_malloc(MAX_NESTED_PRESET * sizeof(gint));
565 presets_find_default(GValue *presets, gint *len)
568 return presets_find_default2(presets, len);
572 ghb_preset_indices_from_path(
580 gint *indices = NULL;
585 g_debug("ghb_preset_indices_from_path () ");
587 count = ghb_array_len(path);
589 indices = g_malloc(MAX_NESTED_PRESET * sizeof(gint));
591 for (ii = 0; ii < count; ii++)
593 val = ghb_array_get_nth(path, ii);
594 name = g_value_get_string(val);
595 indices[ii] = presets_find_element(nested, name);
596 if (indices[ii] == -1)
603 dict = ghb_array_get_nth(nested, indices[ii]);
604 folder = ghb_value_boolean(preset_dict_get_value(dict, "Folder"));
610 nested = ghb_dict_lookup(dict, "ChildrenArray");
618 ghb_presets_get_type(
626 dict = presets_get_dict(presets, indices, len);
629 type = ghb_preset_type(dict);
633 g_warning("ghb_presets_get_type (): internal preset lookup error");
639 ghb_presets_get_folder(
645 gboolean folder = FALSE;
647 dict = presets_get_dict(presets, indices, len);
650 folder = ghb_preset_folder(dict);
654 g_warning("ghb_presets_get_folder (): internal preset lookup error");
660 presets_set_default(gint *indices, gint len)
664 g_debug("presets_set_default ()");
665 presets_clear_default(presetsPlist);
666 dict = presets_get_dict(presetsPlist, indices, len);
669 ghb_dict_insert(dict, g_strdup("Default"), ghb_boolean_value_new(TRUE));
675 presets_set_folder_open(gboolean open, gint *indices, gint len)
679 g_debug("presets_set_folder_open ()");
680 dict = presets_get_dict(presetsPlist, indices, len);
683 ghb_dict_insert(dict, g_strdup("FolderOpen"),
684 ghb_boolean_value_new(open));
688 // Used for sorting dictionaries.
690 key_cmp(gconstpointer a, gconstpointer b)
692 gchar *stra = (gchar*)a;
693 gchar *strb = (gchar*)b;
695 return strcmp(stra, strb);
699 preset_dict_get_value(GValue *dict, const gchar *key)
701 const GValue *gval = NULL;
705 gval = ghb_dict_lookup(dict, key);
707 if (internalPlist == NULL) return NULL;
710 dict = plist_get_dict(internalPlist, "Presets");
711 if (dict == NULL) return NULL;
712 gval = ghb_dict_lookup(dict, key);
718 ghb_presets_get_description(GValue *pdict)
722 if (pdict == NULL) return NULL;
723 desc = g_value_get_string(
724 preset_dict_get_value(pdict, "PresetDescription"));
725 if (desc[0] == 0) return NULL;
730 static void init_settings_from_dict(
731 GValue *dest, GValue *internal, GValue *dict);
734 init_settings_from_array(
742 count = ghb_array_len(array);
743 // The first element of the internal version is always the
744 // template for the allowed values
745 gval = ghb_array_get_nth(internal, 0);
746 for (ii = 0; ii < count; ii++)
749 val = ghb_array_get_nth(array, ii);
752 if (G_VALUE_TYPE(gval) == ghb_dict_get_type())
755 new_dict = ghb_dict_value_new();
756 ghb_array_append(dest, new_dict);
757 if (G_VALUE_TYPE(val) == ghb_dict_get_type())
758 init_settings_from_dict(new_dict, gval, val);
760 init_settings_from_dict(new_dict, gval, gval);
762 else if (G_VALUE_TYPE(gval) == ghb_array_get_type())
765 new_array = ghb_array_value_new(8);
766 ghb_array_append(dest, new_array);
767 if (G_VALUE_TYPE(val) == ghb_array_get_type())
768 init_settings_from_array(new_array, gval, val);
770 init_settings_from_array(new_array, gval, gval);
774 ghb_array_append(dest, val);
780 init_settings_from_dict(
789 ghb_dict_iter_init(&iter, internal);
790 // middle (void*) cast prevents gcc warning "defreferencing type-punned
791 // pointer will break strict-aliasing rules"
792 while (g_hash_table_iter_next(
793 &iter, (gpointer*)(void*)&key, (gpointer*)(void*)&gval))
797 val = ghb_dict_lookup(dict, key);
800 if (G_VALUE_TYPE(gval) == ghb_dict_get_type())
803 new_dict = ghb_dict_value_new();
804 ghb_settings_take_value(dest, key, new_dict);
805 if (G_VALUE_TYPE(val) == ghb_dict_get_type())
806 init_settings_from_dict(new_dict, gval, val);
808 init_settings_from_dict(new_dict, gval, gval);
810 else if (G_VALUE_TYPE(gval) == ghb_array_get_type())
813 new_array = ghb_array_value_new(8);
814 ghb_settings_take_value(dest, key, new_array);
815 if (G_VALUE_TYPE(val) == ghb_array_get_type())
816 init_settings_from_array(new_array, gval, val);
818 init_settings_from_array(new_array, gval, gval);
823 ghb_settings_set_value(dest, key, val);
830 signal_user_data_t *ud,
838 ghb_dict_iter_init(&iter, internal);
839 // middle (void*) cast prevents gcc warning "defreferencing type-punned
840 // pointer will break strict-aliasing rules"
841 while (g_hash_table_iter_next(
842 &iter, (gpointer*)(void*)&key, (gpointer*)(void*)&gval))
846 val = ghb_dict_lookup(dict, key);
849 ghb_ui_update(ud, key, val);
854 preset_to_ui(signal_user_data_t *ud, GValue *dict)
856 g_debug("preset_to_ui()\n");
857 // Initialize the ui from presets file.
858 GValue *internal, *hidden;
860 // Get key list from internal default presets. This way we do not
861 // load any unknown keys.
862 if (internalPlist == NULL) return;
863 internal = plist_get_dict(internalPlist, "Presets");
864 hidden = plist_get_dict(internalPlist, "XlatPresets");
865 // Setting a ui widget will cause the corresponding setting
866 // to be set, but it also triggers a callback that can
867 // have the side effect of using other settings values
868 // that have not yet been set. So set *all* settings first
869 // then update the ui.
870 init_settings_from_dict(ud->settings, internal, dict);
871 init_settings_from_dict(ud->settings, hidden, dict);
872 init_ui_from_dict(ud, internal, dict);
873 init_ui_from_dict(ud, hidden, dict);
877 ghb_settings_to_ui(signal_user_data_t *ud, GValue *dict)
879 init_ui_from_dict(ud, dict, dict);
882 static GValue *current_preset = NULL;
885 ghb_preset_is_custom()
889 if (current_preset == NULL) return FALSE;
890 val = preset_dict_get_value(current_preset, "Type");
891 return (ghb_value_int(val) == 1);
895 ghb_set_preset_from_indices(signal_user_data_t *ud, gint *indices, gint len)
898 gint fallback[2] = {0, -1};
901 dict = presets_get_dict(presetsPlist, indices, len);
906 dict = presets_get_dict(presetsPlist, indices, len);
910 preset_to_ui(ud, NULL);
911 current_preset = NULL;
918 current_preset = dict;
919 folder = ghb_value_boolean(preset_dict_get_value(dict, "Folder"));
921 preset_to_ui(ud, NULL);
923 preset_to_ui(ud, dict);
924 path = preset_path_from_indices(presetsPlist, indices, len);
925 ghb_settings_set_value(ud->settings, "preset", path);
926 ghb_value_free(path);
931 curr_preset_get_value(const gchar *key)
933 if (current_preset == NULL) return NULL;
934 return preset_dict_get_value(current_preset, key);
938 ghb_update_from_preset(
939 signal_user_data_t *ud,
944 g_debug("ghb_update_from_preset() %s", key);
945 gval = curr_preset_get_value(key);
948 ghb_ui_update(ud, key, gval);
958 GtkTreeView *treeview;
959 GtkTreeSelection *selection;
964 g_debug("ghb_select_preset2()");
965 treeview = GTK_TREE_VIEW(GHB_WIDGET(builder, "presets_list"));
966 selection = gtk_tree_view_get_selection (treeview);
967 store = gtk_tree_view_get_model (treeview);
968 path = ghb_tree_path_new_from_indices(indices, len);
971 if (gtk_tree_model_get_iter(store, &iter, path))
973 gtk_tree_selection_select_iter (selection, &iter);
977 if (gtk_tree_model_get_iter_first(store, &iter))
978 gtk_tree_selection_select_iter (selection, &iter);
980 gtk_tree_path_free(path);
985 ghb_select_preset(GtkBuilder *builder, const GValue *path)
989 g_debug("ghb_select_preset()");
990 indices = ghb_preset_indices_from_path(presetsPlist, path, &len);
993 ghb_select_preset2(builder, indices, len);
999 ghb_select_default_preset(GtkBuilder *builder)
1003 g_debug("ghb_select_default_preset()");
1004 indices = presets_find_default(presetsPlist, &len);
1007 ghb_select_preset2(builder, indices, len);
1013 ghb_get_user_config_dir(gchar *subdir)
1018 dir = g_get_user_config_dir();
1019 if (!g_file_test(dir, G_FILE_TEST_IS_DIR))
1021 dir = g_get_home_dir();
1022 config = g_strdup_printf ("%s/.ghb", dir);
1023 if (!g_file_test(config, G_FILE_TEST_IS_DIR))
1024 g_mkdir (config, 0755);
1028 config = g_strdup_printf ("%s/ghb", dir);
1029 if (!g_file_test(config, G_FILE_TEST_IS_DIR))
1030 g_mkdir (config, 0755);
1037 split = g_strsplit(subdir, G_DIR_SEPARATOR_S, -1);
1038 for (ii = 0; split[ii] != NULL; ii++)
1042 tmp = g_strdup_printf ("%s/%s", config, split[ii]);
1045 if (!g_file_test(config, G_FILE_TEST_IS_DIR))
1046 g_mkdir (config, 0755);
1053 store_plist(GValue *plist, const gchar *name)
1055 gchar *config, *path;
1058 config = ghb_get_user_config_dir(NULL);
1059 path = g_strdup_printf ("%s/%s", config, name);
1060 file = g_fopen(path, "w");
1063 ghb_plist_write(file, plist);
1068 load_plist(const gchar *name)
1070 gchar *config, *path;
1071 GValue *plist = NULL;
1073 config = ghb_get_user_config_dir(NULL);
1074 path = g_strdup_printf ("%s/%s", config, name);
1075 if (g_file_test(path, G_FILE_TEST_IS_REGULAR))
1077 plist = ghb_plist_parse_file(path);
1085 remove_plist(const gchar *name)
1087 gchar *config, *path;
1089 config = ghb_get_user_config_dir(NULL);
1090 path = g_strdup_printf ("%s/%s", config, name);
1091 if (g_file_test(path, G_FILE_TEST_IS_REGULAR))
1099 static gboolean prefs_initializing = FALSE;
1102 ghb_prefs_to_ui(signal_user_data_t *ud)
1107 GValue *internal, *dict;
1108 GHashTableIter iter;
1111 g_debug("ghb_prefs_to_ui");
1112 prefs_initializing = TRUE;
1114 // Setting a ui widget will cause the corresponding setting
1115 // to be set, but it also triggers a callback that can
1116 // have the side effect of using other settings values
1117 // that have not yet been set. So set *all* settings first
1118 // then update the ui.
1119 internal = plist_get_dict(internalPlist, "Initialization");
1120 ghb_dict_iter_init(&iter, internal);
1121 // middle (void*) cast prevents gcc warning "defreferencing type-punned
1122 // pointer will break strict-aliasing rules"
1123 while (g_hash_table_iter_next(
1124 &iter, (gpointer*)(void*)&key, (gpointer*)(void*)&gval))
1126 ghb_ui_update(ud, key, gval);
1129 dict = plist_get_dict(prefsPlist, "Preferences");
1130 internal = plist_get_dict(internalPlist, "Preferences");
1131 ghb_dict_iter_init(&iter, internal);
1132 // middle (void*) cast prevents gcc warning "defreferencing type-punned
1133 // pointer will break strict-aliasing rules"
1134 while (g_hash_table_iter_next(
1135 &iter, (gpointer*)(void*)&key, (gpointer*)(void*)&gval))
1137 const GValue *value = NULL;
1139 value = ghb_dict_lookup(dict, key);
1142 ghb_settings_set_value(ud->settings, key, value);
1144 internal = plist_get_dict(internalPlist, "Preferences");
1145 ghb_dict_iter_init(&iter, internal);
1146 // middle (void*) cast prevents gcc warning "defreferencing type-punned
1147 // pointer will break strict-aliasing rules"
1148 while (g_hash_table_iter_next(
1149 &iter, (gpointer*)(void*)&key, (gpointer*)(void*)&gval))
1151 const GValue *value = NULL;
1153 value = ghb_dict_lookup(dict, key);
1156 ghb_ui_update(ud, key, value);
1159 val = ghb_settings_get_value(ud->settings, "show_presets");
1160 ghb_ui_update(ud, "show_presets", val);
1161 if (ghb_settings_get_boolean(ud->settings, "hbfd_feature"))
1164 val = ghb_settings_get_value(ud->settings, "hbfd");
1165 ghb_ui_update(ud, "hbfd", val);
1166 action = GHB_ACTION (ud->builder, "hbfd");
1167 gtk_action_set_visible(action, TRUE);
1171 ghb_ui_update(ud, "hbfd", ghb_int64_value(0));
1173 gval = ghb_settings_get_value(ud->settings, "default_source");
1174 ghb_settings_set_value (ud->settings, "source", gval);
1176 str = ghb_settings_get_string(ud->settings, "destination_dir");
1177 ghb_ui_update(ud, "dest_dir", ghb_string_value(str));
1179 gchar *file = g_strdup_printf ("new_video.mp4");
1180 ghb_ui_update(ud, "dest_file", ghb_string_value(file));
1184 prefs_initializing = FALSE;
1188 ghb_prefs_save(GValue *settings)
1192 GHashTableIter iter;
1194 const GValue *value;
1196 if (prefs_initializing) return;
1197 dict = plist_get_dict(internalPlist, "Preferences");
1198 if (dict == NULL) return;
1199 pref_dict = plist_get_dict(prefsPlist, "Preferences");
1200 if (pref_dict == NULL) return;
1201 ghb_dict_iter_init(&iter, dict);
1202 // middle (void*) cast prevents gcc warning "defreferencing type-punned
1203 // pointer will break strict-aliasing rules"
1204 while (g_hash_table_iter_next(
1205 &iter, (gpointer*)(void*)&key, (gpointer*)(void*)&value))
1207 value = ghb_settings_get_value(settings, key);
1210 ghb_dict_insert(pref_dict, g_strdup(key), ghb_value_dup(value));
1214 prefs_modified = FALSE;
1218 ghb_pref_set(GValue *settings, const gchar *key)
1220 const GValue *value, *value2;
1222 if (prefs_initializing) return;
1223 value = ghb_settings_get_value(settings, key);
1227 dict = plist_get_dict(prefsPlist, "Preferences");
1228 if (dict == NULL) return;
1229 value2 = ghb_dict_lookup(dict, key);
1230 if (ghb_value_cmp(value, value2) != 0)
1232 ghb_dict_insert(dict, g_strdup(key), ghb_value_dup(value));
1234 prefs_modified = TRUE;
1240 ghb_pref_save(GValue *settings, const gchar *key)
1242 const GValue *value, *value2;
1244 if (prefs_initializing) return;
1245 value = ghb_settings_get_value(settings, key);
1249 dict = plist_get_dict(prefsPlist, "Preferences");
1250 if (dict == NULL) return;
1251 value2 = ghb_dict_lookup(dict, key);
1252 if (ghb_value_cmp(value, value2) != 0)
1254 ghb_dict_insert(dict, g_strdup(key), ghb_value_dup(value));
1256 prefs_modified = FALSE;
1262 ghb_prefs_store(void)
1267 prefs_modified = FALSE;
1272 ghb_settings_init(signal_user_data_t *ud)
1275 GHashTableIter iter;
1280 g_debug("ghb_settings_init");
1281 prefs_initializing = TRUE;
1283 internalPlist = ghb_resource_get("internal-defaults");
1284 // Setting a ui widget will cause the corresponding setting
1285 // to be set, but it also triggers a callback that can
1286 // have the side effect of using other settings values
1287 // that have not yet been set. So set *all* settings first
1288 // then update the ui.
1289 internal = plist_get_dict(internalPlist, "Initialization");
1290 ghb_dict_iter_init(&iter, internal);
1291 // middle (void*) cast prevents gcc warning "defreferencing type-punned
1292 // pointer will break strict-aliasing rules"
1293 while (g_hash_table_iter_next(
1294 &iter, (gpointer*)(void*)&key, (gpointer*)(void*)&gval))
1296 ghb_settings_set_value(ud->settings, key, gval);
1299 internal = plist_get_dict(internalPlist, "Presets");
1300 ghb_dict_iter_init(&iter, internal);
1301 // middle (void*) cast prevents gcc warning "defreferencing type-punned
1302 // pointer will break strict-aliasing rules"
1303 while (g_hash_table_iter_next(
1304 &iter, (gpointer*)(void*)&key, (gpointer*)(void*)&gval))
1306 ghb_settings_set_value(ud->settings, key, gval);
1309 internal = plist_get_dict(internalPlist, "Preferences");
1310 ghb_dict_iter_init(&iter, internal);
1311 // middle (void*) cast prevents gcc warning "defreferencing type-punned
1312 // pointer will break strict-aliasing rules"
1313 while (g_hash_table_iter_next(
1314 &iter, (gpointer*)(void*)&key, (gpointer*)(void*)&gval))
1316 ghb_settings_set_value(ud->settings, key, gval);
1318 prefs_initializing = FALSE;
1322 ghb_settings_close()
1325 ghb_value_free(internalPlist);
1327 ghb_value_free(presetsPlist);
1329 ghb_value_free(prefsPlist);
1334 FindFirstCDROM(void)
1339 strcpy(drive, "A:" G_DIR_SEPARATOR_S);
1340 drives = GetLogicalDrives();
1341 for (ii = 0; ii < 26; ii++)
1347 drive[0] = 'A' + ii;
1348 dtype = GetDriveType(drive);
1349 if (dtype == DRIVE_CDROM)
1351 return g_strdup(drive);
1361 ghb_prefs_load(signal_user_data_t *ud)
1363 GValue *dict, *internal;
1364 GHashTableIter iter;
1366 GValue *gval, *path;
1368 g_debug("ghb_prefs_load");
1369 prefsPlist = load_plist("preferences");
1370 if (prefsPlist == NULL)
1371 prefsPlist = ghb_dict_value_new();
1372 dict = plist_get_dict(prefsPlist, "Preferences");
1373 internal = plist_get_dict(internalPlist, "Preferences");
1374 if (dict == NULL && internal)
1376 dict = ghb_dict_value_new();
1377 ghb_dict_insert(prefsPlist, g_strdup("Preferences"), dict);
1379 // Get defaults from internal defaults
1380 ghb_dict_iter_init(&iter, internal);
1381 // middle (void*) cast prevents gcc warning "defreferencing type-punned
1382 // pointer will break strict-aliasing rules"
1383 while (g_hash_table_iter_next(
1384 &iter, (gpointer*)(void*)&key, (gpointer*)(void*)&gval))
1386 ghb_dict_insert(dict, g_strdup(key), ghb_value_dup(gval));
1388 const gchar *dir = g_get_user_special_dir (G_USER_DIRECTORY_VIDEOS);
1393 ghb_dict_insert(dict,
1394 g_strdup("destination_dir"), ghb_value_dup(ghb_string_value(dir)));
1398 source = FindFirstCDROM();
1401 source = g_strdup("C:" G_DIR_SEPARATOR_S);
1403 ghb_dict_insert(dict, g_strdup("default_source"),
1404 ghb_value_dup(ghb_string_value(source)));
1409 // Read legacy default_preset preference and update accordingly
1410 path = ghb_dict_lookup(dict, "default_preset");
1415 if (G_VALUE_TYPE(path) == G_TYPE_STRING)
1419 path = ghb_array_value_new(1);
1420 ghb_array_append(path, ghb_value_dup(str));
1421 indices = ghb_preset_indices_from_path(presetsPlist, path, &len);
1422 ghb_value_free(path);
1425 indices = ghb_preset_indices_from_path(presetsPlist, path, &len);
1429 presets_set_default(indices, len);
1432 ghb_dict_remove(dict, "default_preset");
1438 get_preset_color(gint type, gboolean folder)
1442 if (type == PRESETS_CUSTOM)
1462 ghb_presets_list_init(
1463 signal_user_data_t *ud,
1467 GtkTreeView *treeview;
1468 GtkTreeIter iter, titer, *piter;
1470 GtkTreeStore *store;
1471 const gchar *preset;
1472 GtkTreePath *parent_path;
1473 const gchar *description;
1478 GValue *presets = NULL;
1480 g_debug("ghb_presets_list_init ()");
1481 more_indices = g_malloc((len+1)*sizeof(gint));
1482 memcpy(more_indices, indices, len*sizeof(gint));
1483 presets = presets_get_folder(presetsPlist, indices, len);
1484 if (presets == NULL)
1486 g_warning("Failed to find parent folder when adding child.");
1489 count = ghb_array_len(presets);
1490 treeview = GTK_TREE_VIEW(GHB_WIDGET(ud->builder, "presets_list"));
1491 store = GTK_TREE_STORE(gtk_tree_view_get_model(treeview));
1492 parent_path = ghb_tree_path_new_from_indices(indices, len);
1495 gtk_tree_model_get_iter(GTK_TREE_MODEL(store), &titer, parent_path);
1497 gtk_tree_path_free(parent_path);
1503 for (ii = 0; ii < count; ii++)
1509 // Additional settings, add row
1510 dict = ghb_array_get_nth(presets, ii);
1511 preset = preset_get_name(dict);
1512 more_indices[len] = ii;
1513 def = preset_is_default(dict);
1515 description = ghb_presets_get_description(dict);
1516 gtk_tree_store_append(store, &iter, piter);
1517 type = ghb_preset_type(dict);
1518 folder = ghb_preset_folder(dict);
1519 color = get_preset_color(type, folder);
1520 gtk_tree_store_set(store, &iter, 0, preset,
1531 if (gtk_tree_model_iter_parent(
1532 GTK_TREE_MODEL(store), &ppiter, piter))
1534 path = gtk_tree_model_get_path(GTK_TREE_MODEL(store), &ppiter);
1535 gtk_tree_view_expand_row(treeview, path, FALSE);
1536 gtk_tree_path_free(path);
1538 path = gtk_tree_model_get_path(GTK_TREE_MODEL(store), piter);
1539 gtk_tree_view_expand_row(treeview, path, FALSE);
1540 gtk_tree_path_free(path);
1544 ghb_presets_list_init(ud, more_indices, len+1);
1545 if (preset_folder_is_open(dict))
1551 path = gtk_tree_model_get_path(GTK_TREE_MODEL(store), piter);
1552 gtk_tree_view_expand_row(treeview, path, FALSE);
1553 gtk_tree_path_free(path);
1555 path = gtk_tree_model_get_path(GTK_TREE_MODEL(store), &iter);
1556 gtk_tree_view_expand_row(treeview, path, FALSE);
1557 gtk_tree_path_free(path);
1561 g_free(more_indices);
1565 presets_list_update_item(
1566 signal_user_data_t *ud,
1570 GtkTreeView *treeview;
1571 GtkTreeStore *store;
1573 GtkTreePath *treepath;
1575 const gchar *description;
1577 gboolean def, folder;
1581 g_debug("presets_list_update_item ()");
1582 dict = presets_get_dict(presetsPlist, indices, len);
1585 treeview = GTK_TREE_VIEW(GHB_WIDGET(ud->builder, "presets_list"));
1586 store = GTK_TREE_STORE(gtk_tree_view_get_model(treeview));
1587 treepath = ghb_tree_path_new_from_indices(indices, len);
1588 gtk_tree_model_get_iter(GTK_TREE_MODEL(store), &iter, treepath);
1589 // Additional settings, add row
1590 name = preset_get_name(dict);
1591 def = preset_is_default(dict);
1593 description = ghb_presets_get_description(dict);
1594 type = ghb_preset_type(dict);
1595 folder = ghb_preset_folder(dict);
1596 color = get_preset_color(type, folder);
1597 gtk_tree_store_set(store, &iter, 0, name,
1605 ghb_presets_list_init(ud, indices, len);
1610 presets_list_insert(
1611 signal_user_data_t *ud,
1615 GtkTreeView *treeview;
1616 GtkTreeIter iter, titer, *piter;
1617 GtkTreeStore *store;
1618 const gchar *preset;
1619 const gchar *description;
1621 gboolean def, folder;
1624 GtkTreePath *parent_path;
1628 g_debug("presets_list_insert ()");
1629 treeview = GTK_TREE_VIEW(GHB_WIDGET(ud->builder, "presets_list"));
1630 store = GTK_TREE_STORE(gtk_tree_view_get_model(treeview));
1631 presets = presets_get_folder(presetsPlist, indices, len-1);
1632 if (presets == NULL)
1634 g_warning("Failed to find parent folder while adding child.");
1637 parent_path = ghb_tree_path_new_from_indices(indices, len-1);
1640 gtk_tree_model_get_iter(GTK_TREE_MODEL(store), &titer, parent_path);
1642 gtk_tree_path_free(parent_path);
1648 count = ghb_array_len(presets);
1649 if (indices[len-1] >= count)
1651 // Additional settings, add row
1652 dict = ghb_array_get_nth(presets, indices[len-1]);
1653 preset = preset_get_name(dict);
1654 def = preset_is_default(dict);
1656 description = ghb_presets_get_description(dict);
1657 gtk_tree_store_insert(store, &iter, piter, indices[len-1]);
1658 type = ghb_preset_type(dict);
1659 folder = ghb_preset_folder(dict);
1660 color = get_preset_color(type, folder);
1661 gtk_tree_store_set(store, &iter, 0, preset,
1669 ghb_presets_list_init(ud, indices, len);
1674 presets_list_remove(
1675 signal_user_data_t *ud,
1679 GtkTreeView *treeview;
1680 GtkTreePath *treepath;
1682 GtkTreeStore *store;
1684 g_debug("presets_list_remove ()");
1685 treeview = GTK_TREE_VIEW(GHB_WIDGET(ud->builder, "presets_list"));
1686 store = GTK_TREE_STORE(gtk_tree_view_get_model(treeview));
1687 treepath = ghb_tree_path_new_from_indices(indices, len);
1690 if (gtk_tree_model_get_iter(GTK_TREE_MODEL(store), &iter, treepath))
1691 gtk_tree_store_remove(store, &iter);
1692 gtk_tree_path_free(treepath);
1697 remove_std_presets(signal_user_data_t *ud)
1702 count = ghb_array_len(presetsPlist);
1703 for (ii = count-1; ii >= 0; ii--)
1708 dict = ghb_array_get_nth(presetsPlist, ii);
1709 ptype = ghb_value_int(preset_dict_get_value(dict, "Type"));
1710 if (ptype == PRESETS_BUILTIN)
1712 if (ghb_presets_remove(presetsPlist, &indices, 1))
1714 presets_list_remove(ud, &indices, 1);
1721 ghb_save_queue(GValue *queue)
1723 store_plist(queue, "queue");
1729 return load_plist("queue");
1733 ghb_remove_queue_file()
1735 remove_plist("queue");
1744 static value_map_t vcodec_xlat[] =
1746 {"MPEG-4 (FFmpeg)", "ffmpeg"},
1747 {"MPEG-4 (XviD)", "ffmpeg"},
1748 {"H.264 (x264)", "x264"},
1749 {"VP3 (Theora)", "theora"},
1753 static value_map_t acodec_xlat[] =
1755 {"AAC (faac)", "faac"},
1756 {"AAC (CoreAudio)", "faac"},
1757 {"AC3 Passthru", "ac3"},
1758 {"MP3 (lame)", "lame"},
1759 {"Vorbis (vorbis)", "vorbis"},
1763 value_map_t container_xlat[] =
1765 {"MP4 file", "mp4"},
1766 {"M4V file", "m4v"},
1767 {"MKV file", "mkv"},
1768 {"AVI file", "mkv"},
1769 {"OGM file", "mkv"},
1773 value_map_t framerate_xlat[] =
1775 {"Same as source", "source"},
1780 {"23.976", "23.976"},
1787 value_map_t samplerate_xlat[] =
1798 value_map_t mix_xlat[] =
1801 {"Stereo", "stereo"},
1802 {"Dolby Surround", "dpl1"},
1803 {"Dolby Pro Logic II", "dpl2"},
1804 {"6-channel discrete", "6ch"},
1805 {"AC3 Passthru", "none"},
1809 value_map_t deint_xlat[] =
1819 value_map_t denoise_xlat[] =
1829 value_map_t detel_xlat[] =
1837 value_map_t decomb_xlat[] =
1845 extern iso639_lang_t ghb_language_table[];
1848 export_lang_xlat2(GValue *lin_val)
1852 if (lin_val == NULL) return NULL;
1856 str = ghb_value_string(lin_val);
1857 for (ii = 0; ghb_language_table[ii].eng_name; ii++)
1859 if (strcmp(str, ghb_language_table[ii].iso639_2) == 0)
1861 gval = ghb_string_value_new(ghb_language_table[ii].eng_name);
1866 g_debug("Can't map language value: (%s)", str);
1872 export_subtitle_xlat2(GValue *lin_val)
1877 if (lin_val == NULL) return NULL;
1878 str = ghb_value_string(lin_val);
1879 if (strcmp(str, "none") == 0)
1881 gval = ghb_string_value_new("None");
1883 else if (strcmp(str, "auto") == 0)
1885 gval = ghb_string_value_new("Autoselect");
1889 gval = export_lang_xlat2(lin_val);
1896 import_lang_xlat2(GValue *mac_val)
1900 if (mac_val == NULL) return NULL;
1904 str = ghb_value_string(mac_val);
1905 for (ii = 0; ghb_language_table[ii].eng_name; ii++)
1907 if (strcmp(str, ghb_language_table[ii].eng_name) == 0)
1909 gval = ghb_string_value_new(ghb_language_table[ii].iso639_2);
1914 g_debug("Can't map language value: (%s)", str);
1920 import_subtitle_xlat2(GValue *mac_val)
1925 if (mac_val == NULL) return NULL;
1926 str = ghb_value_string(mac_val);
1927 if (strcmp(str, "None") == 0)
1929 gval = ghb_string_value_new("none");
1931 else if (strcmp(str, "Autoselect") == 0)
1933 gval = ghb_string_value_new("auto");
1937 gval = import_lang_xlat2(mac_val);
1944 export_audio_track_xlat2(GValue *lin_val)
1947 GValue *gval = NULL;
1949 if (lin_val == NULL) return NULL;
1950 str = ghb_value_string(lin_val);
1951 if (strcmp(str, "none") == 0)
1953 gval = ghb_int_value_new(1);
1957 gint val = ghb_value_int(lin_val) + 1;
1958 gval = ghb_int_value_new(val);
1965 import_audio_track_xlat2(GValue *mac_val)
1971 if (mac_val == NULL) return NULL;
1972 val = ghb_value_int(mac_val);
1981 str = g_strdup_printf("%d", val);
1982 gval = ghb_string_value_new(str);
1988 export_value_xlat2(value_map_t *value_map, GValue *lin_val, GType mac_type)
1992 if (lin_val == NULL) return NULL;
1997 str = ghb_value_string(lin_val);
1998 for (ii = 0; value_map[ii].mac_val; ii++)
2000 if (strcmp(str, value_map[ii].lin_val) == 0)
2002 sval = ghb_string_value_new(value_map[ii].mac_val);
2004 gval = ghb_value_new(mac_type);
2005 if (!g_value_transform(sval, gval))
2007 g_warning("can't transform");
2008 ghb_value_free(gval);
2009 ghb_value_free(sval);
2012 ghb_value_free(sval);
2016 g_debug("Can't map value: (%s)", str);
2022 export_value_xlat(GValue *dict)
2024 GValue *lin_val, *gval;
2027 key = "VideoEncoder";
2028 lin_val = ghb_dict_lookup(dict, key);
2029 gval = export_value_xlat2(vcodec_xlat, lin_val, G_TYPE_STRING);
2031 ghb_dict_insert(dict, g_strdup(key), gval);
2033 lin_val = ghb_dict_lookup(dict, key);
2034 gval = export_value_xlat2(container_xlat, lin_val, G_TYPE_STRING);
2036 ghb_dict_insert(dict, g_strdup(key), gval);
2037 key = "VideoFramerate";
2038 lin_val = ghb_dict_lookup(dict, key);
2039 gval = export_value_xlat2(framerate_xlat, lin_val, G_TYPE_STRING);
2041 ghb_dict_insert(dict, g_strdup(key), gval);
2042 key = "PictureDetelecine";
2043 lin_val = ghb_dict_lookup(dict, key);
2044 gval = export_value_xlat2(detel_xlat, lin_val, G_TYPE_INT);
2046 ghb_dict_insert(dict, g_strdup(key), gval);
2047 key = "PictureDecomb";
2048 lin_val = ghb_dict_lookup(dict, key);
2049 gval = export_value_xlat2(decomb_xlat, lin_val, G_TYPE_INT);
2051 ghb_dict_insert(dict, g_strdup(key), gval);
2052 key = "PictureDeinterlace";
2053 lin_val = ghb_dict_lookup(dict, key);
2054 gval = export_value_xlat2(deint_xlat, lin_val, G_TYPE_INT);
2056 ghb_dict_insert(dict, g_strdup(key), gval);
2057 key = "PictureDenoise";
2058 lin_val = ghb_dict_lookup(dict, key);
2059 gval = export_value_xlat2(denoise_xlat, lin_val, G_TYPE_INT);
2061 ghb_dict_insert(dict, g_strdup(key), gval);
2067 slist = ghb_dict_lookup(dict, "SubtitleList");
2068 count = ghb_array_len(slist);
2069 for (ii = 0; ii < count; ii++)
2071 sdict = ghb_array_get_nth(slist, ii);
2072 key = "SubtitleLanguage";
2073 lin_val = ghb_dict_lookup(sdict, key);
2074 gval = export_subtitle_xlat2(lin_val);
2076 ghb_dict_insert(sdict, g_strdup(key), gval);
2082 alist = ghb_dict_lookup(dict, "AudioList");
2083 count = ghb_array_len(alist);
2084 for (ii = 0; ii < count; ii++)
2086 adict = ghb_array_get_nth(alist, ii);
2088 lin_val = ghb_dict_lookup(adict, key);
2089 gval = export_audio_track_xlat2(lin_val);
2091 ghb_dict_insert(adict, g_strdup(key), gval);
2092 key = "AudioEncoder";
2093 lin_val = ghb_dict_lookup(adict, key);
2094 gval = export_value_xlat2(acodec_xlat, lin_val, G_TYPE_STRING);
2096 ghb_dict_insert(adict, g_strdup(key), gval);
2097 key = "AudioSamplerate";
2098 lin_val = ghb_dict_lookup(adict, key);
2099 gval = export_value_xlat2(samplerate_xlat, lin_val, G_TYPE_STRING);
2101 ghb_dict_insert(adict, g_strdup(key), gval);
2102 key = "AudioMixdown";
2103 lin_val = ghb_dict_lookup(adict, key);
2104 gval = export_value_xlat2(mix_xlat, lin_val, G_TYPE_STRING);
2106 ghb_dict_insert(adict, g_strdup(key), gval);
2114 value_map_t *value_map,
2118 GValue *gval, *def_val;
2120 if (mac_val == NULL) return NULL;
2121 def_val = ghb_dict_lookup(defaults, key);
2128 str = ghb_value_string(mac_val);
2129 for (ii = 0; value_map[ii].mac_val; ii++)
2131 if (strcmp(str, value_map[ii].mac_val) == 0)
2133 sval = ghb_string_value_new(value_map[ii].lin_val);
2135 gval = ghb_value_new(G_VALUE_TYPE(def_val));
2136 if (!g_value_transform(sval, gval))
2138 g_warning("can't transform");
2139 ghb_value_free(gval);
2140 ghb_value_free(sval);
2143 ghb_value_free(sval);
2155 str = ghb_value_string(mac_val);
2156 for (ii = 0; value_map[ii].mac_val; ii++)
2158 if (strcmp(str, value_map[ii].mac_val) == 0)
2160 sval = ghb_string_value_new(value_map[ii].lin_val);
2162 gval = ghb_value_new(G_VALUE_TYPE(mac_val));
2163 if (!g_value_transform(sval, gval))
2165 g_warning("can't transform");
2166 ghb_value_free(gval);
2167 ghb_value_free(sval);
2170 ghb_value_free(sval);
2180 import_value_xlat(GValue *dict)
2182 GValue *defaults, *mac_val, *gval;
2185 defaults = plist_get_dict(internalPlist, "Presets");
2186 key = "VideoEncoder";
2187 mac_val = ghb_dict_lookup(dict, key);
2188 gval = import_value_xlat2(defaults, vcodec_xlat, key, mac_val);
2190 ghb_dict_insert(dict, g_strdup(key), gval);
2192 mac_val = ghb_dict_lookup(dict, key);
2193 gval = import_value_xlat2(defaults, container_xlat, key, mac_val);
2195 ghb_dict_insert(dict, g_strdup(key), gval);
2196 key = "VideoFramerate";
2197 mac_val = ghb_dict_lookup(dict, key);
2198 gval = import_value_xlat2(defaults, framerate_xlat, key, mac_val);
2200 ghb_dict_insert(dict, g_strdup(key), gval);
2201 key = "PictureDetelecine";
2202 mac_val = ghb_dict_lookup(dict, key);
2203 gval = import_value_xlat2(defaults, detel_xlat, key, mac_val);
2205 ghb_dict_insert(dict, g_strdup(key), gval);
2206 key = "PictureDecomb";
2207 mac_val = ghb_dict_lookup(dict, key);
2208 gval = import_value_xlat2(defaults, decomb_xlat, key, mac_val);
2210 ghb_dict_insert(dict, g_strdup(key), gval);
2211 key = "PictureDeinterlace";
2212 mac_val = ghb_dict_lookup(dict, key);
2213 gval = import_value_xlat2(defaults, deint_xlat, key, mac_val);
2215 ghb_dict_insert(dict, g_strdup(key), gval);
2216 key = "PictureDenoise";
2217 mac_val = ghb_dict_lookup(dict, key);
2218 gval = import_value_xlat2(defaults, denoise_xlat, key, mac_val);
2220 ghb_dict_insert(dict, g_strdup(key), gval);
2228 sdeflist = ghb_dict_lookup(defaults, "SubtitleList");
2231 slist = ghb_dict_lookup(dict, "SubtitleList");
2234 sdefaults = ghb_array_get_nth(sdeflist, 0);
2235 count = ghb_array_len(slist);
2236 for (ii = 0; ii < count; ii++)
2238 sdict = ghb_array_get_nth(slist, ii);
2239 key = "SubtitleLanguage";
2240 mac_val = ghb_dict_lookup(sdict, key);
2241 gval = import_subtitle_xlat2(mac_val);
2243 ghb_dict_insert(sdict, g_strdup(key), gval);
2250 mac_val = ghb_dict_lookup(dict, key);
2255 gval = import_subtitle_xlat2(mac_val);
2256 lang = ghb_value_string(gval);
2257 if (lang && strcmp(lang, "none") != 0 && !slist)
2259 slist = ghb_array_value_new(8);
2260 sdict = ghb_dict_value_new();
2261 ghb_dict_insert(dict, g_strdup("SubtitleList"), slist);
2262 ghb_array_append(slist, sdict);
2263 ghb_dict_insert(sdict, g_strdup("SubtitleLanguage"), gval);
2264 gval = ghb_dict_lookup(dict, "SubtitlesForced");
2267 ghb_dict_insert(sdict, g_strdup("SubtitleForced"),
2268 ghb_value_dup(gval));
2272 ghb_dict_insert(sdict, g_strdup("SubtitleForced"),
2273 ghb_boolean_value_new(FALSE));
2275 ghb_dict_insert(sdict, g_strdup("SubtitleBurned"),
2276 ghb_boolean_value_new(TRUE));
2277 ghb_dict_insert(sdict, g_strdup("SubtitleDefaultTrack"),
2278 ghb_boolean_value_new(FALSE));
2282 ghb_value_free(gval);
2289 ghb_dict_remove(dict, "Subtitles");
2290 ghb_dict_remove(dict, "SubtitlesForced");
2298 adeflist = ghb_dict_lookup(defaults, "AudioList");
2301 adefaults = ghb_array_get_nth(adeflist, 0);
2302 alist = ghb_dict_lookup(dict, "AudioList");
2303 count = ghb_array_len(alist);
2304 for (ii = 0; ii < count; ii++)
2306 adict = ghb_array_get_nth(alist, ii);
2308 mac_val = ghb_dict_lookup(adict, key);
2309 gval = import_audio_track_xlat2(mac_val);
2311 ghb_dict_insert(adict, g_strdup(key), gval);
2312 key = "AudioEncoder";
2313 mac_val = ghb_dict_lookup(adict, key);
2314 gval = import_value_xlat2(adefaults, acodec_xlat, key, mac_val);
2316 ghb_dict_insert(adict, g_strdup(key), gval);
2317 key = "AudioSamplerate";
2318 mac_val = ghb_dict_lookup(adict, key);
2319 gval = import_value_xlat2(adefaults, samplerate_xlat, key, mac_val);
2321 ghb_dict_insert(adict, g_strdup(key), gval);
2322 key = "AudioMixdown";
2323 mac_val = ghb_dict_lookup(adict, key);
2324 gval = import_value_xlat2(adefaults, mix_xlat, key, mac_val);
2326 ghb_dict_insert(adict, g_strdup(key), gval);
2332 import_xlat_preset(GValue *dict)
2336 gint par, par_width, par_height;
2339 g_debug("import_xlat_preset ()");
2340 uses_max = ghb_value_boolean(
2341 preset_dict_get_value(dict, "UsesMaxPictureSettings"));
2342 uses_pic = ghb_value_int(
2343 preset_dict_get_value(dict, "UsesPictureSettings"));
2344 par = ghb_value_int(preset_dict_get_value(dict, "PicturePAR"));
2345 vqtype = ghb_value_int(preset_dict_get_value(dict, "VideoQualityType"));
2346 par_width = ghb_value_int(preset_dict_get_value(dict, "PicturePARWidth"));
2347 par_height = ghb_value_int(preset_dict_get_value(dict, "PicturePARHeight"));
2348 ghb_dict_insert(dict, g_strdup("par_width"),
2349 ghb_int_value_new(par_width));
2350 ghb_dict_insert(dict, g_strdup("par_height"),
2351 ghb_int_value_new(par_height));
2353 if (uses_max || uses_pic == 2)
2355 ghb_dict_insert(dict, g_strdup("autoscale"),
2356 ghb_boolean_value_new(TRUE));
2362 if (ghb_dict_lookup(dict, "PictureModulus") == NULL)
2363 ghb_dict_insert(dict, g_strdup("PictureModulus"),
2364 ghb_int_value_new(16));
2368 ghb_dict_insert(dict, g_strdup("PictureModulus"),
2369 ghb_int_value_new(1));
2373 if (ghb_dict_lookup(dict, "PictureModulus") == NULL)
2374 ghb_dict_insert(dict, g_strdup("PictureModulus"),
2375 ghb_int_value_new(16));
2379 if (ghb_dict_lookup(dict, "PictureModulus") == NULL)
2380 ghb_dict_insert(dict, g_strdup("PictureModulus"),
2381 ghb_int_value_new(16));
2384 // VideoQualityType/0/1/2 - vquality_type_/target/bitrate/constant
2389 ghb_dict_insert(dict, g_strdup("vquality_type_target"),
2390 ghb_boolean_value_new(TRUE));
2391 ghb_dict_insert(dict, g_strdup("vquality_type_bitrate"),
2392 ghb_boolean_value_new(FALSE));
2393 ghb_dict_insert(dict, g_strdup("vquality_type_constant"),
2394 ghb_boolean_value_new(FALSE));
2398 ghb_dict_insert(dict, g_strdup("vquality_type_target"),
2399 ghb_boolean_value_new(FALSE));
2400 ghb_dict_insert(dict, g_strdup("vquality_type_bitrate"),
2401 ghb_boolean_value_new(TRUE));
2402 ghb_dict_insert(dict, g_strdup("vquality_type_constant"),
2403 ghb_boolean_value_new(FALSE));
2407 ghb_dict_insert(dict, g_strdup("vquality_type_target"),
2408 ghb_boolean_value_new(FALSE));
2409 ghb_dict_insert(dict, g_strdup("vquality_type_bitrate"),
2410 ghb_boolean_value_new(FALSE));
2411 ghb_dict_insert(dict, g_strdup("vquality_type_constant"),
2412 ghb_boolean_value_new(TRUE));
2416 ghb_dict_insert(dict, g_strdup("vquality_type_target"),
2417 ghb_boolean_value_new(FALSE));
2418 ghb_dict_insert(dict, g_strdup("vquality_type_bitrate"),
2419 ghb_boolean_value_new(FALSE));
2420 ghb_dict_insert(dict, g_strdup("vquality_type_constant"),
2421 ghb_boolean_value_new(TRUE));
2424 import_value_xlat(dict);
2429 vquality = ghb_value_double(preset_dict_get_value(dict, "VideoQualitySlider"));
2434 gval = preset_dict_get_value(dict, "VideoEncoder");
2435 vcodec = ghb_lookup_combo_int("VideoEncoder", gval);
2438 case HB_VCODEC_X264:
2440 vquality = 51. - vquality * 51.;
2443 case HB_VCODEC_FFMPEG:
2445 vquality = 31. - vquality * 30.;
2448 case HB_VCODEC_THEORA:
2450 vquality = vquality * 63.;
2458 ghb_dict_insert(dict, g_strdup("VideoQualitySlider"),
2459 ghb_double_value_new(vquality));
2464 import_xlat_presets(GValue *presets)
2470 g_debug("import_xlat_presets ()");
2471 if (presets == NULL) return;
2472 count = ghb_array_len(presets);
2473 for (ii = 0; ii < count; ii++)
2475 dict = ghb_array_get_nth(presets, ii);
2476 folder = ghb_value_boolean(preset_dict_get_value(dict, "Folder"));
2481 nested = ghb_dict_lookup(dict, "ChildrenArray");
2482 import_xlat_presets(nested);
2486 import_xlat_preset(dict);
2492 export_xlat_preset(GValue *dict)
2494 gboolean autoscale, target, br, constant;
2495 gint par_width, par_height;
2497 g_debug("export_xlat_prest ()");
2498 autoscale = ghb_value_boolean(preset_dict_get_value(dict, "autoscale"));
2499 target = ghb_value_boolean(
2500 preset_dict_get_value(dict, "vquality_type_target"));
2501 br = ghb_value_boolean(
2502 preset_dict_get_value(dict, "vquality_type_bitrate"));
2503 constant = ghb_value_boolean(
2504 preset_dict_get_value(dict, "vquality_type_constant"));
2505 par_width = ghb_value_int(
2506 preset_dict_get_value(dict, "par_width"));
2507 par_height = ghb_value_int(
2508 preset_dict_get_value(dict, "par_height"));
2511 ghb_dict_insert(dict, g_strdup("UsesPictureSettings"),
2512 ghb_int_value_new(2));
2514 ghb_dict_insert(dict, g_strdup("UsesPictureSettings"),
2515 ghb_int_value_new(1));
2517 // VideoQualityType/0/1/2 - vquality_type_/target/bitrate/constant
2520 ghb_dict_insert(dict, g_strdup("VideoQualityType"),
2521 ghb_int_value_new(0));
2525 ghb_dict_insert(dict, g_strdup("VideoQualityType"),
2526 ghb_int_value_new(1));
2530 ghb_dict_insert(dict, g_strdup("VideoQualityType"),
2531 ghb_int_value_new(2));
2533 ghb_dict_insert(dict, g_strdup("PicturePARWidth"),
2534 ghb_int_value_new(par_width));
2535 ghb_dict_insert(dict, g_strdup("PicturePARHeight"),
2536 ghb_int_value_new(par_height));
2537 ghb_dict_remove(dict, "UsesMaxPictureSettings");
2538 ghb_dict_remove(dict, "autoscale");
2539 ghb_dict_remove(dict, "vquality_type_target");
2540 ghb_dict_remove(dict, "vquality_type_bitrate");
2541 ghb_dict_remove(dict, "vquality_type_constant");
2542 ghb_dict_remove(dict, "par_width");
2543 ghb_dict_remove(dict, "par_height");
2544 export_value_xlat(dict);
2548 export_xlat_presets(GValue *presets)
2554 if (presets == NULL) return;
2555 count = ghb_array_len(presets);
2556 for (ii = 0; ii < count; ii++)
2558 dict = ghb_array_get_nth(presets, ii);
2559 folder = ghb_value_boolean(preset_dict_get_value(dict, "Folder"));
2564 nested = ghb_dict_lookup(dict, "ChildrenArray");
2565 export_xlat_presets(nested);
2569 export_xlat_preset(dict);
2574 static guint prefs_timeout_id = 0;
2577 delayed_store_prefs(gpointer data)
2579 store_plist(prefsPlist, "preferences");
2580 prefs_timeout_id = 0;
2589 export = ghb_value_dup(presetsPlist);
2590 export_xlat_presets(export);
2591 store_plist(export, "presets");
2592 ghb_value_free(export);
2598 if (prefs_timeout_id != 0)
2603 mc = g_main_context_default();
2604 source = g_main_context_find_source_by_id(mc, prefs_timeout_id);
2606 g_source_destroy(source);
2608 prefs_timeout_id = g_timeout_add_seconds(1, (GSourceFunc)delayed_store_prefs, NULL);
2612 ghb_presets_reload(signal_user_data_t *ud)
2614 GValue *std_presets;
2618 g_debug("ghb_presets_reload()\n");
2619 std_presets = ghb_resource_get("standard-presets");
2620 if (std_presets == NULL) return;
2622 remove_std_presets(ud);
2623 indices = presets_find_default(presetsPlist, &len);
2626 presets_clear_default(std_presets);
2629 // Merge the keyfile contents into our presets
2630 count = ghb_array_len(std_presets);
2631 for (ii = count-1; ii >= 0; ii--)
2637 std_dict = ghb_array_get_nth(std_presets, ii);
2638 copy_dict = ghb_value_dup(std_dict);
2639 ghb_dict_insert(copy_dict, g_strdup("PresetBuildNumber"),
2640 ghb_int64_value_new(hb_get_build(NULL)));
2641 ghb_presets_insert(presetsPlist, copy_dict, &indices, 1);
2642 presets_list_insert(ud, &indices, 1);
2644 import_xlat_presets(presetsPlist);
2653 count = ghb_array_len(presetsPlist);
2654 for (ii = count-1; ii >= 0; ii--)
2659 dict = ghb_array_get_nth(presetsPlist, ii);
2660 type = ghb_dict_lookup(dict, "Type");
2668 replace_standard_presets()
2670 GValue *std_presets;
2674 count = ghb_array_len(presetsPlist);
2675 for (ii = count-1; ii >= 0; ii--)
2680 dict = ghb_array_get_nth(presetsPlist, ii);
2681 ptype = ghb_value_int(preset_dict_get_value(dict, "Type"));
2682 if (ptype == PRESETS_BUILTIN)
2685 ghb_presets_remove(presetsPlist, &indices, 1);
2689 std_presets = ghb_resource_get("standard-presets");
2690 if (std_presets == NULL) return;
2692 indices = presets_find_default(presetsPlist, &len);
2695 presets_clear_default(std_presets);
2698 // Merge the keyfile contents into our presets
2699 count = ghb_array_len(std_presets);
2700 for (ii = count-1; ii >= 0; ii--)
2706 std_dict = ghb_array_get_nth(std_presets, ii);
2707 copy_dict = ghb_value_dup(std_dict);
2708 ghb_dict_insert(copy_dict, g_strdup("PresetBuildNumber"),
2709 ghb_int64_value_new(hb_get_build(NULL)));
2710 ghb_presets_insert(presetsPlist, copy_dict, &indices, 1);
2712 import_xlat_presets(presetsPlist);
2717 update_standard_presets(signal_user_data_t *ud)
2721 count = ghb_array_len(presetsPlist);
2722 for (ii = count-1; ii >= 0; ii--)
2729 dict = ghb_array_get_nth(presetsPlist, ii);
2730 gval = ghb_dict_lookup(dict, "Type");
2733 // Old preset that doesn't have a Type
2734 replace_standard_presets();
2738 type = ghb_value_int(gval);
2741 gval = ghb_dict_lookup(dict, "PresetBuildNumber");
2744 // Old preset that doesn't have a build number
2745 replace_standard_presets();
2749 build = ghb_value_int64(gval);
2750 if (build != hb_get_build(NULL))
2752 // Build number does not match
2753 replace_standard_presets();
2762 ghb_presets_load(signal_user_data_t *ud)
2764 presetsPlist = load_plist("presets");
2765 if (presetsPlist == NULL)
2767 presetsPlist = ghb_value_dup(ghb_resource_get("standard-presets"));
2768 import_xlat_presets(presetsPlist);
2771 else if (G_VALUE_TYPE(presetsPlist) == ghb_dict_get_type())
2772 { // Presets is older dictionary format. Convert to array
2773 ghb_value_free(presetsPlist);
2774 presetsPlist = ghb_value_dup(ghb_resource_get("standard-presets"));
2775 import_xlat_presets(presetsPlist);
2778 else if (check_old_presets())
2780 ghb_value_free(presetsPlist);
2781 presetsPlist = ghb_value_dup(ghb_resource_get("standard-presets"));
2782 import_xlat_presets(presetsPlist);
2785 update_standard_presets(ud);
2786 import_xlat_presets(presetsPlist);
2790 settings_save(signal_user_data_t *ud, const GValue *path)
2792 GValue *dict, *internal;
2793 GHashTableIter iter;
2797 gint *indices, len, count;
2798 gint *def_indices, def_len;
2800 gboolean replace = FALSE;
2802 g_debug("settings_save");
2803 if (internalPlist == NULL) return;
2804 count = ghb_array_len(path);
2805 name = g_value_get_string(ghb_array_get_nth(path, count-1));
2806 indices = ghb_preset_indices_from_path(presetsPlist, path, &len);
2809 if (ghb_presets_get_folder(presetsPlist, indices, len))
2812 message = g_strdup_printf(
2813 "%s: Folder already exists.\n"
2814 "You can not replace it with a preset.",
2816 ghb_message_dialog(GTK_MESSAGE_ERROR, message, "Cancel", NULL);
2820 dict = ghb_dict_value_new();
2821 ghb_presets_replace(presetsPlist, dict, indices, len);
2826 indices = presets_find_pos(path, PRESETS_CUSTOM, &len);
2829 dict = ghb_dict_value_new();
2830 ghb_presets_insert(presetsPlist, dict, indices, len);
2834 g_warning("failed to find insert path");
2838 current_preset = dict;
2839 autoscale = ghb_settings_get_boolean(ud->settings, "autoscale");
2840 ghb_settings_set_int64(ud->settings, "Type", PRESETS_CUSTOM);
2841 ghb_settings_set_int64(ud->settings, "PresetBuildNumber", hb_get_build(NULL));
2843 internal = plist_get_dict(internalPlist, "Presets");
2844 ghb_dict_iter_init(&iter, internal);
2845 // middle (void*) cast prevents gcc warning "defreferencing type-punned
2846 // pointer will break strict-aliasing rules"
2847 while (g_hash_table_iter_next(
2848 &iter, (gpointer*)(void*)&key, (gpointer*)(void*)&value))
2856 if (strcmp(key, "PictureWidth") == 0)
2858 key2 = "scale_width";
2860 else if (strcmp(key, "PictureHeight") == 0)
2862 key2 = "scale_height";
2865 gval = ghb_settings_get_value(ud->settings, key2);
2870 ghb_dict_insert(dict, g_strdup(key), ghb_value_dup(gval));
2872 internal = plist_get_dict(internalPlist, "XlatPresets");
2873 ghb_dict_iter_init(&iter, internal);
2874 // middle (void*) cast prevents gcc warning "defreferencing type-punned
2875 // pointer will break strict-aliasing rules"
2876 while (g_hash_table_iter_next(
2877 &iter, (gpointer*)(void*)&key, (gpointer*)(void*)&value))
2881 gval = ghb_settings_get_value(ud->settings, key);
2886 ghb_dict_insert(dict, g_strdup(key), ghb_value_dup(gval));
2888 ghb_dict_insert(dict, g_strdup("PresetName"), ghb_string_value_new(name));
2891 def_indices = presets_find_default(presetsPlist, &def_len);
2892 if (def_indices != NULL &&
2893 preset_path_cmp(indices, len, def_indices, def_len) != 0)
2895 ghb_dict_insert(dict, g_strdup("Default"),
2896 ghb_boolean_value_new(FALSE));
2898 presets_list_update_item(ud, indices, len);
2902 ghb_dict_insert(dict, g_strdup("Default"),
2903 ghb_boolean_value_new(FALSE));
2904 presets_list_insert(ud, indices, len);
2907 ud->dont_clear_presets = TRUE;
2908 // Make the new preset the selected item
2909 ghb_select_preset2(ud->builder, indices, len);
2911 ud->dont_clear_presets = FALSE;
2916 folder_save(signal_user_data_t *ud, const GValue *path)
2918 GValue *dict, *folder;
2919 gint *indices, len, count;
2922 count = ghb_array_len(path);
2923 name = g_value_get_string(ghb_array_get_nth(path, count-1));
2924 indices = ghb_preset_indices_from_path(presetsPlist, path, &len);
2927 if (!ghb_presets_get_folder(presetsPlist, indices, len))
2930 message = g_strdup_printf(
2931 "%s: Preset already exists.\n"
2932 "You can not replace it with a folder.",
2934 ghb_message_dialog(GTK_MESSAGE_ERROR, message, "Cancel", NULL);
2939 // Already exists, update its description
2940 dict = presets_get_dict(presetsPlist, indices, len);
2941 ghb_dict_insert(dict, g_strdup("PresetDescription"),
2942 ghb_value_dup(preset_dict_get_value(
2943 ud->settings, "PresetDescription")));
2949 indices = presets_find_pos(path, PRESETS_CUSTOM, &len);
2952 dict = ghb_dict_value_new();
2953 ghb_presets_insert(presetsPlist, dict, indices, len);
2957 g_warning("failed to find insert path");
2961 ghb_dict_insert(dict, g_strdup("PresetDescription"),
2962 ghb_value_dup(preset_dict_get_value(
2963 ud->settings, "PresetDescription")));
2964 ghb_dict_insert(dict, g_strdup("PresetName"), ghb_string_value_new(name));
2965 folder = ghb_array_value_new(8);
2966 ghb_dict_insert(dict, g_strdup("ChildrenArray"), folder);
2967 ghb_dict_insert(dict, g_strdup("Type"),
2968 ghb_int64_value_new(PRESETS_CUSTOM));
2969 ghb_dict_insert(dict, g_strdup("Folder"), ghb_boolean_value_new(TRUE));
2971 presets_list_insert(ud, indices, len);
2978 ghb_presets_list_default(signal_user_data_t *ud)
2980 GtkTreeView *treeview;
2981 GtkTreePath *treepath;
2983 GtkTreeStore *store;
2986 g_debug("ghb_presets_list_default ()");
2987 treeview = GTK_TREE_VIEW(GHB_WIDGET(ud->builder, "presets_list"));
2988 store = GTK_TREE_STORE(gtk_tree_view_get_model(treeview));
2989 indices = presets_find_default(presetsPlist, &len);
2990 if (indices == NULL) return;
2991 treepath = ghb_tree_path_new_from_indices(indices, len);
2994 if (gtk_tree_model_get_iter(GTK_TREE_MODEL(store), &iter, treepath))
2996 gtk_tree_store_set(store, &iter,
3001 gtk_tree_path_free(treepath);
3007 ghb_presets_list_clear_default(signal_user_data_t *ud)
3009 GtkTreeView *treeview;
3010 GtkTreePath *treepath;
3012 GtkTreeStore *store;
3015 g_debug("ghb_presets_list_clear_default ()");
3016 treeview = GTK_TREE_VIEW(GHB_WIDGET(ud->builder, "presets_list"));
3017 store = GTK_TREE_STORE(gtk_tree_view_get_model(treeview));
3018 indices = presets_find_default(presetsPlist, &len);
3019 if (indices == NULL) return;
3020 treepath = ghb_tree_path_new_from_indices(indices, len);
3023 if (gtk_tree_model_get_iter(GTK_TREE_MODEL(store), &iter, treepath))
3025 gtk_tree_store_set(store, &iter,
3030 gtk_tree_path_free(treepath);
3036 update_audio_presets(signal_user_data_t *ud)
3038 g_debug("update_audio_presets");
3039 const GValue *audio_list;
3041 audio_list = ghb_settings_get_value(ud->settings, "audio_list");
3042 ghb_settings_set_value(ud->settings, "AudioList", audio_list);
3046 update_subtitle_presets(signal_user_data_t *ud)
3048 g_debug("update_subtitle_presets");
3049 const GValue *subtitle_list, *subtitle;
3050 GValue *slist, *dict;
3053 subtitle_list = ghb_settings_get_value(ud->settings, "subtitle_list");
3054 slist = ghb_array_value_new(8);
3055 count = ghb_array_len(subtitle_list);
3056 for (ii = 0; ii < count; ii++)
3058 subtitle = ghb_array_get_nth(subtitle_list, ii);
3059 dict = ghb_value_dup(subtitle);
3060 ghb_array_append(slist, dict);
3062 ghb_settings_set_value(ud->settings, "SubtitleList", slist);
3066 enforce_preset_type(signal_user_data_t *ud, const GValue *path)
3069 GtkWidget *normal, *folder;
3072 normal = GHB_WIDGET(ud->builder, "preset_type_normal");
3073 folder = GHB_WIDGET(ud->builder, "preset_type_folder");
3074 indices = ghb_preset_indices_from_path(presetsPlist, path, &len);
3077 fold = ghb_presets_get_folder(presetsPlist, indices, len);
3079 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(folder),
3082 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(normal),
3084 gtk_widget_set_sensitive(folder, fold);
3085 gtk_widget_set_sensitive(normal, !fold);
3090 gtk_widget_set_sensitive(folder, TRUE);
3091 gtk_widget_set_sensitive(normal, TRUE);
3095 G_MODULE_EXPORT void
3096 presets_save_clicked_cb(GtkWidget *xwidget, signal_user_data_t *ud)
3101 GtkResponseType response;
3103 const gchar *name = "";
3104 gint count, *indices, len;
3106 g_debug("presets_save_clicked_cb ()");
3107 preset = ghb_settings_get_value (ud->settings, "preset_selection");
3109 count = ghb_array_len(preset);
3111 name = g_value_get_string(ghb_array_get_nth(preset, count-1));
3114 // Clear the description
3115 desc = GTK_TEXT_VIEW(GHB_WIDGET(ud->builder, "PresetDescription"));
3116 dialog = GHB_WIDGET(ud->builder, "preset_save_dialog");
3117 entry = GTK_ENTRY(GHB_WIDGET(ud->builder, "PresetName"));
3118 gtk_entry_set_text(entry, name);
3119 enforce_preset_type(ud, preset);
3120 response = gtk_dialog_run(GTK_DIALOG(dialog));
3121 gtk_widget_hide(dialog);
3122 if (response == GTK_RESPONSE_OK)
3125 const gchar *name = gtk_entry_get_text(entry);
3128 if (ghb_settings_get_boolean(ud->settings, "preset_type_folder"))
3130 if (count > MAX_NESTED_PRESET-1)
3132 count = MAX_NESTED_PRESET-1;
3135 dest = ghb_array_value_new(MAX_NESTED_PRESET);
3136 indices = ghb_preset_indices_from_path(presetsPlist, preset, &len);
3141 ptype = ghb_presets_get_type(presetsPlist, indices, len);
3142 if (ptype == PRESETS_CUSTOM)
3144 ghb_array_copy(dest, preset, count-1);
3147 ghb_array_append(dest, ghb_string_value_new(name));
3149 ghb_widget_to_setting(ud->settings, GTK_WIDGET(desc));
3150 if (ghb_settings_get_boolean(ud->settings, "preset_type_folder"))
3152 folder_save(ud, dest);
3156 // Construct the audio settings presets from the current audio list
3157 update_audio_presets(ud);
3158 update_subtitle_presets(ud);
3159 settings_save(ud, dest);
3161 ghb_value_free(dest);
3165 G_MODULE_EXPORT void
3166 preset_type_changed_cb(GtkWidget *widget, signal_user_data_t *ud)
3168 ghb_widget_to_setting(ud->settings, widget);
3171 G_MODULE_EXPORT void
3172 preset_name_changed_cb(GtkWidget *entry, signal_user_data_t *ud)
3175 GValue *preset, *dest;
3178 preset = ghb_settings_get_value (ud->settings, "preset_selection");
3179 name = ghb_widget_string(entry);
3180 dest = ghb_value_dup(preset);
3181 count = ghb_array_len(dest);
3182 ghb_array_replace(dest, count-1, ghb_string_value_new(name));
3183 enforce_preset_type(ud, dest);
3184 ghb_value_free(dest);
3187 G_MODULE_EXPORT void
3188 presets_restore_clicked_cb(GtkWidget *xwidget, signal_user_data_t *ud)
3192 g_debug("presets_restore_clicked_cb ()");
3193 // Reload only the standard presets
3194 ghb_presets_reload(ud);
3195 // Updating the presets list shuffles things around
3196 // need to make sure the proper preset is selected
3197 preset = ghb_settings_get_value (ud->settings, "preset");
3198 ghb_select_preset(ud->builder, preset);
3201 G_MODULE_EXPORT void
3202 presets_remove_clicked_cb(GtkWidget *xwidget, signal_user_data_t *ud)
3204 GtkTreeView *treeview;
3205 GtkTreeSelection *selection;
3206 GtkTreeModel *store;
3209 GtkResponseType response;
3211 g_debug("presets_remove_clicked_cb ()");
3212 treeview = GTK_TREE_VIEW(GHB_WIDGET(ud->builder, "presets_list"));
3213 selection = gtk_tree_view_get_selection (treeview);
3214 if (gtk_tree_selection_get_selected(selection, &store, &iter))
3221 gtk_tree_model_get(store, &iter, 0, &preset, -1);
3222 path = gtk_tree_model_get_path(store, &iter);
3223 indices = gtk_tree_path_get_indices(path);
3224 len = gtk_tree_path_get_depth(path);
3226 folder = ghb_presets_get_folder(presetsPlist, indices, len);
3227 dialog = gtk_message_dialog_new(NULL, GTK_DIALOG_MODAL,
3228 GTK_MESSAGE_QUESTION, GTK_BUTTONS_YES_NO,
3229 "Confirm deletion of %s:\n\n%s",
3230 folder ? "folder" : "preset",
3232 response = gtk_dialog_run(GTK_DIALOG(dialog));
3233 gtk_widget_destroy (dialog);
3234 if (response == GTK_RESPONSE_YES)
3236 GtkTreeIter nextIter = iter;
3237 gboolean valid = TRUE;
3238 if (!gtk_tree_model_iter_next(store, &nextIter))
3240 if (!gtk_tree_model_iter_parent(store, &nextIter, &iter))
3245 // Remove the selected item
3246 // First unselect it so that selecting the new item works properly
3247 gtk_tree_selection_unselect_iter (selection, &iter);
3248 if (ghb_presets_remove(presetsPlist, indices, len))
3251 presets_list_remove(ud, indices, len);
3254 valid = gtk_tree_model_get_iter_first(store, &nextIter);
3257 gtk_tree_path_free(path);
3258 path = gtk_tree_model_get_path(store, &nextIter);
3259 indices = gtk_tree_path_get_indices(path);
3260 len = gtk_tree_path_get_depth(path);
3261 ghb_select_preset2(ud->builder, indices, len);
3265 gtk_tree_path_free(path);
3269 // controls where valid drop locations are
3270 G_MODULE_EXPORT gboolean
3271 presets_drag_motion_cb(
3273 GdkDragContext *ctx,
3277 signal_user_data_t *ud)
3279 GtkTreePath *path = NULL;
3280 GtkTreeViewDropPosition drop_pos;
3284 GtkTreeModel *model;
3285 GtkTreeSelection *select;
3286 gint src_ptype, dst_ptype;
3287 gboolean src_folder, dst_folder;
3289 gint tree_depth, ii;
3292 widget = gtk_drag_get_source_widget(ctx);
3293 if (widget == NULL || widget != GTK_WIDGET(tv))
3296 // Get the type of the object being dragged
3297 srctv = GTK_TREE_VIEW(gtk_drag_get_source_widget(ctx));
3298 select = gtk_tree_view_get_selection (srctv);
3299 gtk_tree_selection_get_selected (select, &model, &iter);
3300 path = gtk_tree_model_get_path (model, &iter);
3301 indices = gtk_tree_path_get_indices(path);
3302 len = gtk_tree_path_get_depth(path);
3304 preset = presets_get_dict(presetsPlist, indices, len);
3305 tree_depth = preset_tree_depth(preset);
3307 src_ptype = ghb_presets_get_type(presetsPlist, indices, len);
3308 src_folder = ghb_presets_get_folder(presetsPlist, indices, len);
3309 gtk_tree_path_free(path);
3311 if (src_folder && tree_depth == 1)
3314 // The rest checks that the destination is a valid position
3316 gtk_tree_view_get_dest_row_at_pos (tv, x, y, &path, &drop_pos);
3319 gdk_drag_status(ctx, 0, time);
3322 // Don't allow repositioning of builtin presets
3323 if (src_ptype != PRESETS_CUSTOM)
3325 gdk_drag_status(ctx, 0, time);
3329 len = gtk_tree_path_get_depth(path);
3330 if (len+tree_depth-1 >= MAX_NESTED_PRESET)
3332 if (drop_pos == GTK_TREE_VIEW_DROP_INTO_OR_BEFORE)
3333 drop_pos = GTK_TREE_VIEW_DROP_BEFORE;
3334 if (drop_pos == GTK_TREE_VIEW_DROP_INTO_OR_AFTER)
3335 drop_pos = GTK_TREE_VIEW_DROP_AFTER;
3337 for (ii = len+tree_depth-1; ii > MAX_NESTED_PRESET; ii--)
3338 gtk_tree_path_up(path);
3339 indices = gtk_tree_path_get_indices(path);
3340 len = gtk_tree_path_get_depth(path);
3341 dst_ptype = ghb_presets_get_type(presetsPlist, indices, len);
3342 dst_folder = ghb_presets_get_folder(presetsPlist, indices, len);
3343 // Don't allow mixing custom presets in the builtins
3344 if (dst_ptype != PRESETS_CUSTOM)
3346 gdk_drag_status(ctx, 0, time);
3350 // Only allow *drop into* for folders
3353 if (drop_pos == GTK_TREE_VIEW_DROP_INTO_OR_BEFORE)
3354 drop_pos = GTK_TREE_VIEW_DROP_BEFORE;
3355 if (drop_pos == GTK_TREE_VIEW_DROP_INTO_OR_AFTER)
3356 drop_pos = GTK_TREE_VIEW_DROP_AFTER;
3359 len = gtk_tree_path_get_depth(path);
3360 gtk_tree_view_set_drag_dest_row(tv, path, drop_pos);
3361 gtk_tree_path_free(path);
3362 gdk_drag_status(ctx, GDK_ACTION_MOVE, time);
3366 G_MODULE_EXPORT void
3368 GtkTreeView *dstwidget,
3371 GtkSelectionData *selection_data,
3372 guint info, guint t,
3373 signal_user_data_t *ud)
3375 GtkTreePath *path = NULL;
3376 GtkTreeViewDropPosition drop_pos;
3377 GtkTreeIter dstiter, srciter;
3378 gint *dst_indices, dst_len, *src_indices, src_len;
3380 gboolean src_folder, dst_folder;
3382 GtkTreeModel *dstmodel = gtk_tree_view_get_model(dstwidget);
3384 g_debug("preset_drag_cb ()");
3385 // This doesn't work here for some reason...
3386 // gtk_tree_view_get_drag_dest_row(dstwidget, &path, &drop_pos);
3387 gtk_tree_view_get_dest_row_at_pos (dstwidget, x, y, &path, &drop_pos);
3388 // This little hack is needed because attempting to drop after
3389 // the last item gives us no path or drop_pos.
3394 n_children = gtk_tree_model_iter_n_children(dstmodel, NULL);
3397 drop_pos = GTK_TREE_VIEW_DROP_AFTER;
3398 path = gtk_tree_path_new_from_indices(n_children-1, -1);
3402 drop_pos = GTK_TREE_VIEW_DROP_BEFORE;
3403 path = gtk_tree_path_new_from_indices(0, -1);
3408 GtkTreeView *srcwidget;
3409 GtkTreeModel *srcmodel;
3410 GtkTreeSelection *select;
3411 GtkTreePath *srcpath = NULL;
3413 gint tree_depth, ii;
3415 srcwidget = GTK_TREE_VIEW(gtk_drag_get_source_widget(dc));
3416 select = gtk_tree_view_get_selection (srcwidget);
3417 gtk_tree_selection_get_selected (select, &srcmodel, &srciter);
3419 srcpath = gtk_tree_model_get_path (srcmodel, &srciter);
3420 src_indices = gtk_tree_path_get_indices(srcpath);
3421 src_len = gtk_tree_path_get_depth(srcpath);
3422 src_ptype = ghb_presets_get_type(presetsPlist, src_indices, src_len);
3423 src_folder = ghb_presets_get_folder(presetsPlist, src_indices, src_len);
3424 preset = ghb_value_dup(
3425 presets_get_dict(presetsPlist, src_indices, src_len));
3426 gtk_tree_path_free(srcpath);
3428 // Don't allow repositioning of builtin presets
3429 if (src_ptype != PRESETS_CUSTOM)
3432 tree_depth = preset_tree_depth(preset);
3433 if (src_folder && tree_depth == 1)
3436 dst_len = gtk_tree_path_get_depth(path);
3437 if (dst_len+tree_depth-1 >= MAX_NESTED_PRESET)
3439 if (drop_pos == GTK_TREE_VIEW_DROP_INTO_OR_BEFORE)
3440 drop_pos = GTK_TREE_VIEW_DROP_BEFORE;
3441 if (drop_pos == GTK_TREE_VIEW_DROP_INTO_OR_AFTER)
3442 drop_pos = GTK_TREE_VIEW_DROP_AFTER;
3445 for (ii = dst_len+tree_depth-1; ii > MAX_NESTED_PRESET; ii--)
3446 gtk_tree_path_up(path);
3447 dst_indices = gtk_tree_path_get_indices(path);
3448 dst_len = gtk_tree_path_get_depth(path);
3449 dst_folder = ghb_presets_get_folder(presetsPlist, dst_indices, dst_len);
3450 // Only allow *drop into* for folders
3453 if (drop_pos == GTK_TREE_VIEW_DROP_INTO_OR_BEFORE)
3454 drop_pos = GTK_TREE_VIEW_DROP_BEFORE;
3455 if (drop_pos == GTK_TREE_VIEW_DROP_INTO_OR_AFTER)
3456 drop_pos = GTK_TREE_VIEW_DROP_AFTER;
3458 if (gtk_tree_model_get_iter (dstmodel, &dstiter, path))
3461 GtkTreePath *dstpath = NULL;
3465 case GTK_TREE_VIEW_DROP_BEFORE:
3466 gtk_tree_store_insert_before(GTK_TREE_STORE (dstmodel),
3467 &iter, NULL, &dstiter);
3470 case GTK_TREE_VIEW_DROP_INTO_OR_BEFORE:
3471 gtk_tree_store_insert(GTK_TREE_STORE (dstmodel),
3472 &iter, &dstiter, 0);
3475 case GTK_TREE_VIEW_DROP_AFTER:
3476 gtk_tree_store_insert_after(GTK_TREE_STORE (dstmodel),
3477 &iter, NULL, &dstiter);
3480 case GTK_TREE_VIEW_DROP_INTO_OR_AFTER:
3481 gtk_tree_store_insert_after(GTK_TREE_STORE (dstmodel),
3482 &iter, &dstiter, 0);
3489 dstpath = gtk_tree_model_get_path (dstmodel, &iter);
3490 dst_indices = gtk_tree_path_get_indices(dstpath);
3491 dst_len = gtk_tree_path_get_depth(dstpath);
3492 ghb_presets_insert(presetsPlist, preset, dst_indices, dst_len);
3493 gtk_tree_path_free(dstpath);
3495 srcpath = gtk_tree_model_get_path (srcmodel, &srciter);
3496 src_indices = gtk_tree_path_get_indices(srcpath);
3497 src_len = gtk_tree_path_get_depth(srcpath);
3498 ghb_presets_remove(presetsPlist, src_indices, src_len);
3499 gtk_tree_path_free(srcpath);
3501 gtk_tree_store_remove (GTK_TREE_STORE (srcmodel), &srciter);
3503 dstpath = gtk_tree_model_get_path (dstmodel, &iter);
3504 dst_indices = gtk_tree_path_get_indices(dstpath);
3505 dst_len = gtk_tree_path_get_depth(dstpath);
3506 presets_list_update_item(ud, dst_indices, dst_len);
3507 gtk_tree_path_free(dstpath);
3511 gtk_tree_path_free(path);
3516 presets_row_expanded_cb(
3517 GtkTreeView *treeview,
3520 signal_user_data_t *ud)
3523 gboolean expanded, folder;
3526 expanded = gtk_tree_view_row_expanded(treeview, path);
3527 indices = gtk_tree_path_get_indices(path);
3528 len = gtk_tree_path_get_depth(path);
3529 dict = presets_get_dict(presetsPlist, indices, len);
3530 if (preset_folder_is_open(dict))
3539 folder = ghb_presets_get_folder(presetsPlist, indices, len);
3542 presets_set_folder_open(expanded, indices, len);
3545 // Collapsing parent folder collapses all children
3548 GValue *presets = NULL;
3549 gint *more_indices, count, ii;
3551 more_indices = g_malloc((len+1)*sizeof(gint));
3552 memcpy(more_indices, indices, len*sizeof(gint));
3554 presets = presets_get_folder(presetsPlist, indices, len);
3555 count = ghb_array_len(presets);
3556 for (ii = 0; ii < count; ii++)
3558 dict = ghb_array_get_nth(presets, ii);
3559 folder = ghb_preset_folder(dict);
3562 more_indices[len] = ii;
3563 presets_set_folder_open(expanded, more_indices, len+1);
3566 g_free(more_indices);
3572 preset_update_title_deps(signal_user_data_t *ud, ghb_title_info_t *tinfo)
3576 ghb_ui_update(ud, "scale_width",
3577 ghb_int64_value(tinfo->width - tinfo->crop[2] - tinfo->crop[3]));
3578 // If anamorphic or keep_aspect, the hight will be automatically calculated
3579 gboolean keep_aspect;
3581 keep_aspect = ghb_settings_get_boolean(ud->settings, "PictureKeepRatio");
3582 pic_par = ghb_settings_combo_int(ud->settings, "PicturePAR");
3583 if (!(keep_aspect || pic_par) || pic_par == 3)
3585 ghb_ui_update(ud, "scale_height",
3586 ghb_int64_value(tinfo->height - tinfo->crop[0] - tinfo->crop[1]));
3589 // Set the limits of cropping. hb_set_anamorphic_size crashes if
3590 // you pass it a cropped width or height == 0.
3592 bound = tinfo->height / 2 - 2;
3593 widget = GHB_WIDGET (ud->builder, "PictureTopCrop");
3594 gtk_spin_button_set_range (GTK_SPIN_BUTTON(widget), 0, bound);
3595 widget = GHB_WIDGET (ud->builder, "PictureBottomCrop");
3596 gtk_spin_button_set_range (GTK_SPIN_BUTTON(widget), 0, bound);
3597 bound = tinfo->width / 2 - 2;
3598 widget = GHB_WIDGET (ud->builder, "PictureLeftCrop");
3599 gtk_spin_button_set_range (GTK_SPIN_BUTTON(widget), 0, bound);
3600 widget = GHB_WIDGET (ud->builder, "PictureRightCrop");
3601 gtk_spin_button_set_range (GTK_SPIN_BUTTON(widget), 0, bound);
3602 if (ghb_settings_get_boolean(ud->settings, "PictureAutoCrop"))
3604 ghb_ui_update(ud, "PictureTopCrop", ghb_int64_value(tinfo->crop[0]));
3605 ghb_ui_update(ud, "PictureBottomCrop", ghb_int64_value(tinfo->crop[1]));
3606 ghb_ui_update(ud, "PictureLeftCrop", ghb_int64_value(tinfo->crop[2]));
3607 ghb_ui_update(ud, "PictureRightCrop", ghb_int64_value(tinfo->crop[3]));
3611 G_MODULE_EXPORT void
3612 presets_list_selection_changed_cb(GtkTreeSelection *selection, signal_user_data_t *ud)
3614 GtkTreeModel *store;
3616 ghb_title_info_t tinfo;
3619 g_debug("presets_list_selection_changed_cb ()");
3620 widget = GHB_WIDGET (ud->builder, "presets_remove");
3621 if (gtk_tree_selection_get_selected(selection, &store, &iter))
3623 GtkTreePath *treepath;
3628 treepath = gtk_tree_model_get_path(store, &iter);
3629 indices = gtk_tree_path_get_indices(treepath);
3630 len = gtk_tree_path_get_depth(treepath);
3632 path = preset_path_from_indices(presetsPlist, indices, len);
3633 ghb_settings_take_value(ud->settings, "preset_selection", path);
3635 folder = ghb_presets_get_folder(presetsPlist, indices, len);
3638 ud->dont_clear_presets = TRUE;
3639 // Temporarily set the video_quality range to (0,100)
3640 // This is needed so the video_quality value does not get
3641 // truncated when set. The range will be readjusted below
3642 GtkWidget *qp = GHB_WIDGET(ud->builder, "VideoQualitySlider");
3643 gtk_range_set_range (GTK_RANGE(qp), 0, 100);
3644 gtk_scale_set_digits(GTK_SCALE(qp), 3);
3645 // Clear the audio list prior to changing the preset. Existing
3646 // audio can cause the container extension to be automatically
3647 // changed when it shouldn't be
3648 ghb_clear_audio_list(ud);
3649 ghb_set_preset_from_indices(ud, indices, len);
3650 gtk_tree_path_free(treepath);
3652 titleindex = ghb_settings_combo_int(ud->settings, "title");
3653 ghb_set_pref_audio(titleindex, ud);
3654 ghb_set_pref_subtitle(titleindex, ud);
3655 ghb_settings_set_boolean(ud->settings, "preset_modified", FALSE);
3656 if (ghb_get_title_info (&tinfo, titleindex))
3658 preset_update_title_deps(ud, &tinfo);
3660 ghb_set_scale (ud, GHB_PIC_KEEP_PAR);
3661 ud->dont_clear_presets = FALSE;
3663 gdouble vqmin, vqmax, step, page;
3667 ghb_vquality_range(ud, &vqmin, &vqmax, &step,
3668 &page, &digits, &inverted);
3669 gtk_range_set_range (GTK_RANGE(qp), vqmin, vqmax);
3670 gtk_range_set_increments (GTK_RANGE(qp), step, page);
3671 gtk_scale_set_digits(GTK_SCALE(qp), digits);
3672 gtk_range_set_inverted (GTK_RANGE(qp), inverted);
3676 GtkWidget *crop_widget;
3677 crop[0] = ghb_settings_get_int(ud->settings, "PictureTopCrop");
3678 crop[1] = ghb_settings_get_int(ud->settings, "PictureBottomCrop");
3679 crop[2] = ghb_settings_get_int(ud->settings, "PictureLeftCrop");
3680 crop[3] = ghb_settings_get_int(ud->settings, "PictureRightCrop");
3681 crop_widget = GHB_WIDGET (ud->builder, "crop_values");
3682 text = g_strdup_printf("%d:%d:%d:%d",
3683 crop[0], crop[1], crop[2], crop[3]);
3684 gtk_label_set_text (GTK_LABEL(crop_widget), text);
3687 gtk_widget_set_sensitive(widget, TRUE);
3691 g_debug("No selection??? Perhaps unselected.");
3692 gtk_widget_set_sensitive(widget, FALSE);
3697 ghb_clear_presets_selection(signal_user_data_t *ud)
3699 GtkTreeView *treeview;
3700 GtkTreeSelection *selection;
3702 if (ud->dont_clear_presets) return;
3703 g_debug("ghb_clear_presets_selection()");
3704 treeview = GTK_TREE_VIEW(GHB_WIDGET(ud->builder, "presets_list"));
3705 selection = gtk_tree_view_get_selection (treeview);
3706 gtk_tree_selection_unselect_all (selection);
3707 ghb_settings_set_boolean(ud->settings, "preset_modified", TRUE);
3710 G_MODULE_EXPORT void
3711 presets_frame_size_allocate_cb(GtkWidget *widget, GtkAllocation *allocation, signal_user_data_t *ud)
3713 GtkTreeView *treeview;
3714 GtkTreeSelection *selection;
3715 GtkTreeModel *store;
3718 treeview = GTK_TREE_VIEW(GHB_WIDGET(ud->builder, "presets_list"));
3719 selection = gtk_tree_view_get_selection(treeview);
3720 if (gtk_tree_selection_get_selected(selection, &store, &iter))
3723 path = gtk_tree_model_get_path (store, &iter);
3724 // Make the parent visible in scroll window if it is not.
3725 gtk_tree_view_scroll_to_cell (treeview, path, NULL, FALSE, 0, 0);
3726 gtk_tree_path_free(path);
3730 G_MODULE_EXPORT void
3731 presets_default_clicked_cb(GtkWidget *xwidget, signal_user_data_t *ud)
3736 g_debug("presets_default_clicked_cb ()");
3737 preset = ghb_settings_get_value(ud->settings, "preset_selection");
3738 indices = ghb_preset_indices_from_path(presetsPlist, preset, &len);
3741 if (!ghb_presets_get_folder(presetsPlist, indices, len))
3743 ghb_presets_list_clear_default(ud);
3744 presets_set_default(indices, len);
3745 ghb_presets_list_default(ud);