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_customize(GValue *presets)
525 count = ghb_array_len(presets);
526 for (ii = 0; ii < count; ii++)
532 dict = ghb_array_get_nth(presets, ii);
534 ptype = ghb_value_int(preset_dict_get_value(dict, "Type"));
535 if (ptype != PRESETS_CUSTOM)
537 ghb_dict_insert(dict, g_strdup("Type"),
538 ghb_int64_value_new(PRESETS_CUSTOM));
540 folder = ghb_value_boolean(preset_dict_get_value(dict, "Folder"));
545 nested = ghb_dict_lookup(dict, "ChildrenArray");
546 presets_customize(nested);
552 presets_find_default2(GValue *presets, gint *len)
557 count = ghb_array_len(presets);
558 for (ii = 0; ii < count; ii++)
563 dict = ghb_array_get_nth(presets, ii);
564 folder = ghb_value_boolean(preset_dict_get_value(dict, "Folder"));
570 nested = ghb_dict_lookup(dict, "ChildrenArray");
572 indices = presets_find_default2(nested, len);
583 if (preset_is_default(dict))
585 indices = g_malloc(MAX_NESTED_PRESET * sizeof(gint));
596 presets_find_default(GValue *presets, gint *len)
599 return presets_find_default2(presets, len);
603 ghb_preset_indices_from_path(
611 gint *indices = NULL;
616 g_debug("ghb_preset_indices_from_path () ");
618 count = ghb_array_len(path);
620 indices = g_malloc(MAX_NESTED_PRESET * sizeof(gint));
622 for (ii = 0; ii < count; ii++)
624 val = ghb_array_get_nth(path, ii);
625 name = g_value_get_string(val);
626 indices[ii] = presets_find_element(nested, name);
627 if (indices[ii] == -1)
634 dict = ghb_array_get_nth(nested, indices[ii]);
635 folder = ghb_value_boolean(preset_dict_get_value(dict, "Folder"));
641 nested = ghb_dict_lookup(dict, "ChildrenArray");
649 ghb_presets_get_type(
657 dict = presets_get_dict(presets, indices, len);
660 type = ghb_preset_type(dict);
664 g_warning("ghb_presets_get_type (): internal preset lookup error");
670 ghb_presets_get_folder(
676 gboolean folder = FALSE;
678 dict = presets_get_dict(presets, indices, len);
681 folder = ghb_preset_folder(dict);
685 g_warning("ghb_presets_get_folder (): internal preset lookup error");
691 presets_set_default(gint *indices, gint len)
695 g_debug("presets_set_default ()");
696 presets_clear_default(presetsPlist);
697 dict = presets_get_dict(presetsPlist, indices, len);
700 ghb_dict_insert(dict, g_strdup("Default"), ghb_boolean_value_new(TRUE));
706 presets_set_folder_open(gboolean open, gint *indices, gint len)
710 g_debug("presets_set_folder_open ()");
711 dict = presets_get_dict(presetsPlist, indices, len);
714 ghb_dict_insert(dict, g_strdup("FolderOpen"),
715 ghb_boolean_value_new(open));
719 // Used for sorting dictionaries.
721 key_cmp(gconstpointer a, gconstpointer b)
723 gchar *stra = (gchar*)a;
724 gchar *strb = (gchar*)b;
726 return strcmp(stra, strb);
730 preset_dict_get_value(GValue *dict, const gchar *key)
732 const GValue *gval = NULL;
736 gval = ghb_dict_lookup(dict, key);
738 if (internalPlist == NULL) return NULL;
741 dict = plist_get_dict(internalPlist, "Presets");
742 if (dict == NULL) return NULL;
743 gval = ghb_dict_lookup(dict, key);
749 ghb_presets_get_description(GValue *pdict)
753 if (pdict == NULL) return NULL;
754 desc = g_value_get_string(
755 preset_dict_get_value(pdict, "PresetDescription"));
756 if (desc[0] == 0) return NULL;
761 static void init_settings_from_dict(
762 GValue *dest, GValue *internal, GValue *dict);
765 init_settings_from_array(
773 count = ghb_array_len(array);
774 // The first element of the internal version is always the
775 // template for the allowed values
776 gval = ghb_array_get_nth(internal, 0);
777 for (ii = 0; ii < count; ii++)
780 val = ghb_array_get_nth(array, ii);
783 if (G_VALUE_TYPE(gval) == ghb_dict_get_type())
786 new_dict = ghb_dict_value_new();
787 ghb_array_append(dest, new_dict);
788 if (G_VALUE_TYPE(val) == ghb_dict_get_type())
789 init_settings_from_dict(new_dict, gval, val);
791 init_settings_from_dict(new_dict, gval, gval);
793 else if (G_VALUE_TYPE(gval) == ghb_array_get_type())
796 new_array = ghb_array_value_new(8);
797 ghb_array_append(dest, new_array);
798 if (G_VALUE_TYPE(val) == ghb_array_get_type())
799 init_settings_from_array(new_array, gval, val);
801 init_settings_from_array(new_array, gval, gval);
805 ghb_array_append(dest, val);
811 init_settings_from_dict(
820 ghb_dict_iter_init(&iter, internal);
821 // middle (void*) cast prevents gcc warning "defreferencing type-punned
822 // pointer will break strict-aliasing rules"
823 while (g_hash_table_iter_next(
824 &iter, (gpointer*)(void*)&key, (gpointer*)(void*)&gval))
828 val = ghb_dict_lookup(dict, key);
831 if (G_VALUE_TYPE(gval) == ghb_dict_get_type())
834 new_dict = ghb_dict_value_new();
835 ghb_settings_take_value(dest, key, new_dict);
836 if (G_VALUE_TYPE(val) == ghb_dict_get_type())
837 init_settings_from_dict(new_dict, gval, val);
839 init_settings_from_dict(new_dict, gval, gval);
841 else if (G_VALUE_TYPE(gval) == ghb_array_get_type())
844 new_array = ghb_array_value_new(8);
845 ghb_settings_take_value(dest, key, new_array);
846 if (G_VALUE_TYPE(val) == ghb_array_get_type())
847 init_settings_from_array(new_array, gval, val);
849 init_settings_from_array(new_array, gval, gval);
854 ghb_settings_set_value(dest, key, val);
861 signal_user_data_t *ud,
869 ghb_dict_iter_init(&iter, internal);
870 // middle (void*) cast prevents gcc warning "defreferencing type-punned
871 // pointer will break strict-aliasing rules"
872 while (g_hash_table_iter_next(
873 &iter, (gpointer*)(void*)&key, (gpointer*)(void*)&gval))
877 val = ghb_dict_lookup(dict, key);
880 ghb_ui_update(ud, key, val);
885 preset_to_ui(signal_user_data_t *ud, GValue *dict)
887 g_debug("preset_to_ui()\n");
888 // Initialize the ui from presets file.
889 GValue *internal, *hidden;
891 // Get key list from internal default presets. This way we do not
892 // load any unknown keys.
893 if (internalPlist == NULL) return;
894 internal = plist_get_dict(internalPlist, "Presets");
895 hidden = plist_get_dict(internalPlist, "XlatPresets");
896 // Setting a ui widget will cause the corresponding setting
897 // to be set, but it also triggers a callback that can
898 // have the side effect of using other settings values
899 // that have not yet been set. So set *all* settings first
900 // then update the ui.
901 init_settings_from_dict(ud->settings, internal, dict);
902 init_settings_from_dict(ud->settings, hidden, dict);
903 init_ui_from_dict(ud, internal, dict);
904 init_ui_from_dict(ud, hidden, dict);
908 ghb_settings_to_ui(signal_user_data_t *ud, GValue *dict)
910 init_ui_from_dict(ud, dict, dict);
913 static GValue *current_preset = NULL;
916 ghb_preset_is_custom()
920 if (current_preset == NULL) return FALSE;
921 val = preset_dict_get_value(current_preset, "Type");
922 return (ghb_value_int(val) == 1);
926 ghb_set_preset_from_indices(signal_user_data_t *ud, gint *indices, gint len)
929 gint fallback[2] = {0, -1};
932 dict = presets_get_dict(presetsPlist, indices, len);
937 dict = presets_get_dict(presetsPlist, indices, len);
941 preset_to_ui(ud, NULL);
942 current_preset = NULL;
949 current_preset = dict;
950 folder = ghb_value_boolean(preset_dict_get_value(dict, "Folder"));
952 preset_to_ui(ud, NULL);
954 preset_to_ui(ud, dict);
955 path = preset_path_from_indices(presetsPlist, indices, len);
956 ghb_settings_set_value(ud->settings, "preset", path);
957 ghb_value_free(path);
962 curr_preset_get_value(const gchar *key)
964 if (current_preset == NULL) return NULL;
965 return preset_dict_get_value(current_preset, key);
969 ghb_update_from_preset(
970 signal_user_data_t *ud,
975 g_debug("ghb_update_from_preset() %s", key);
976 gval = curr_preset_get_value(key);
979 ghb_ui_update(ud, key, gval);
989 GtkTreeView *treeview;
990 GtkTreeSelection *selection;
995 g_debug("ghb_select_preset2()");
996 treeview = GTK_TREE_VIEW(GHB_WIDGET(builder, "presets_list"));
997 selection = gtk_tree_view_get_selection (treeview);
998 store = gtk_tree_view_get_model (treeview);
999 path = ghb_tree_path_new_from_indices(indices, len);
1002 if (gtk_tree_model_get_iter(store, &iter, path))
1004 gtk_tree_selection_select_iter (selection, &iter);
1008 if (gtk_tree_model_get_iter_first(store, &iter))
1009 gtk_tree_selection_select_iter (selection, &iter);
1011 gtk_tree_path_free(path);
1016 ghb_select_preset(GtkBuilder *builder, const GValue *path)
1020 g_debug("ghb_select_preset()");
1021 indices = ghb_preset_indices_from_path(presetsPlist, path, &len);
1024 ghb_select_preset2(builder, indices, len);
1030 ghb_select_default_preset(GtkBuilder *builder)
1034 g_debug("ghb_select_default_preset()");
1035 indices = presets_find_default(presetsPlist, &len);
1038 ghb_select_preset2(builder, indices, len);
1044 ghb_get_user_config_dir(gchar *subdir)
1049 dir = g_get_user_config_dir();
1050 if (!g_file_test(dir, G_FILE_TEST_IS_DIR))
1052 dir = g_get_home_dir();
1053 config = g_strdup_printf ("%s/.ghb", dir);
1054 if (!g_file_test(config, G_FILE_TEST_IS_DIR))
1055 g_mkdir (config, 0755);
1059 config = g_strdup_printf ("%s/ghb", dir);
1060 if (!g_file_test(config, G_FILE_TEST_IS_DIR))
1061 g_mkdir (config, 0755);
1068 split = g_strsplit(subdir, G_DIR_SEPARATOR_S, -1);
1069 for (ii = 0; split[ii] != NULL; ii++)
1073 tmp = g_strdup_printf ("%s/%s", config, split[ii]);
1076 if (!g_file_test(config, G_FILE_TEST_IS_DIR))
1077 g_mkdir (config, 0755);
1084 store_plist(GValue *plist, const gchar *name)
1086 gchar *config, *path;
1089 config = ghb_get_user_config_dir(NULL);
1090 path = g_strdup_printf ("%s/%s", config, name);
1091 file = g_fopen(path, "w");
1094 ghb_plist_write(file, plist);
1099 load_plist(const gchar *name)
1101 gchar *config, *path;
1102 GValue *plist = NULL;
1104 config = ghb_get_user_config_dir(NULL);
1105 path = g_strdup_printf ("%s/%s", config, name);
1106 if (g_file_test(path, G_FILE_TEST_IS_REGULAR))
1108 plist = ghb_plist_parse_file(path);
1116 remove_plist(const gchar *name)
1118 gchar *config, *path;
1120 config = ghb_get_user_config_dir(NULL);
1121 path = g_strdup_printf ("%s/%s", config, name);
1122 if (g_file_test(path, G_FILE_TEST_IS_REGULAR))
1130 static gboolean prefs_initializing = FALSE;
1133 ghb_prefs_to_ui(signal_user_data_t *ud)
1138 GValue *internal, *dict;
1139 GHashTableIter iter;
1142 g_debug("ghb_prefs_to_ui");
1143 prefs_initializing = TRUE;
1145 // Setting a ui widget will cause the corresponding setting
1146 // to be set, but it also triggers a callback that can
1147 // have the side effect of using other settings values
1148 // that have not yet been set. So set *all* settings first
1149 // then update the ui.
1150 internal = plist_get_dict(internalPlist, "Initialization");
1151 ghb_dict_iter_init(&iter, internal);
1152 // middle (void*) cast prevents gcc warning "defreferencing type-punned
1153 // pointer will break strict-aliasing rules"
1154 while (g_hash_table_iter_next(
1155 &iter, (gpointer*)(void*)&key, (gpointer*)(void*)&gval))
1157 ghb_ui_update(ud, key, gval);
1160 dict = plist_get_dict(prefsPlist, "Preferences");
1161 internal = plist_get_dict(internalPlist, "Preferences");
1162 ghb_dict_iter_init(&iter, internal);
1163 // middle (void*) cast prevents gcc warning "defreferencing type-punned
1164 // pointer will break strict-aliasing rules"
1165 while (g_hash_table_iter_next(
1166 &iter, (gpointer*)(void*)&key, (gpointer*)(void*)&gval))
1168 const GValue *value = NULL;
1170 value = ghb_dict_lookup(dict, key);
1173 ghb_settings_set_value(ud->settings, key, value);
1175 internal = plist_get_dict(internalPlist, "Preferences");
1176 ghb_dict_iter_init(&iter, internal);
1177 // middle (void*) cast prevents gcc warning "defreferencing type-punned
1178 // pointer will break strict-aliasing rules"
1179 while (g_hash_table_iter_next(
1180 &iter, (gpointer*)(void*)&key, (gpointer*)(void*)&gval))
1182 const GValue *value = NULL;
1184 value = ghb_dict_lookup(dict, key);
1187 ghb_ui_update(ud, key, value);
1190 val = ghb_settings_get_value(ud->settings, "show_presets");
1191 ghb_ui_update(ud, "show_presets", val);
1192 if (ghb_settings_get_boolean(ud->settings, "hbfd_feature"))
1195 val = ghb_settings_get_value(ud->settings, "hbfd");
1196 ghb_ui_update(ud, "hbfd", val);
1197 action = GHB_ACTION (ud->builder, "hbfd");
1198 gtk_action_set_visible(action, TRUE);
1202 ghb_ui_update(ud, "hbfd", ghb_int64_value(0));
1204 gval = ghb_settings_get_value(ud->settings, "default_source");
1205 ghb_settings_set_value (ud->settings, "source", gval);
1207 str = ghb_settings_get_string(ud->settings, "destination_dir");
1208 ghb_ui_update(ud, "dest_dir", ghb_string_value(str));
1210 gchar *file = g_strdup_printf ("new_video.mp4");
1211 ghb_ui_update(ud, "dest_file", ghb_string_value(file));
1215 prefs_initializing = FALSE;
1219 ghb_prefs_save(GValue *settings)
1223 GHashTableIter iter;
1225 const GValue *value;
1227 if (prefs_initializing) return;
1228 dict = plist_get_dict(internalPlist, "Preferences");
1229 if (dict == NULL) return;
1230 pref_dict = plist_get_dict(prefsPlist, "Preferences");
1231 if (pref_dict == NULL) return;
1232 ghb_dict_iter_init(&iter, dict);
1233 // middle (void*) cast prevents gcc warning "defreferencing type-punned
1234 // pointer will break strict-aliasing rules"
1235 while (g_hash_table_iter_next(
1236 &iter, (gpointer*)(void*)&key, (gpointer*)(void*)&value))
1238 value = ghb_settings_get_value(settings, key);
1241 ghb_dict_insert(pref_dict, g_strdup(key), ghb_value_dup(value));
1245 prefs_modified = FALSE;
1249 ghb_pref_set(GValue *settings, const gchar *key)
1251 const GValue *value, *value2;
1253 if (prefs_initializing) return;
1254 value = ghb_settings_get_value(settings, key);
1258 dict = plist_get_dict(prefsPlist, "Preferences");
1259 if (dict == NULL) return;
1260 value2 = ghb_dict_lookup(dict, key);
1261 if (ghb_value_cmp(value, value2) != 0)
1263 ghb_dict_insert(dict, g_strdup(key), ghb_value_dup(value));
1265 prefs_modified = TRUE;
1271 ghb_pref_save(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 = FALSE;
1293 ghb_prefs_store(void)
1298 prefs_modified = FALSE;
1303 ghb_settings_init(signal_user_data_t *ud)
1306 GHashTableIter iter;
1311 g_debug("ghb_settings_init");
1312 prefs_initializing = TRUE;
1314 internalPlist = ghb_resource_get("internal-defaults");
1315 // Setting a ui widget will cause the corresponding setting
1316 // to be set, but it also triggers a callback that can
1317 // have the side effect of using other settings values
1318 // that have not yet been set. So set *all* settings first
1319 // then update the ui.
1320 internal = plist_get_dict(internalPlist, "Initialization");
1321 ghb_dict_iter_init(&iter, internal);
1322 // middle (void*) cast prevents gcc warning "defreferencing type-punned
1323 // pointer will break strict-aliasing rules"
1324 while (g_hash_table_iter_next(
1325 &iter, (gpointer*)(void*)&key, (gpointer*)(void*)&gval))
1327 ghb_settings_set_value(ud->settings, key, gval);
1330 internal = plist_get_dict(internalPlist, "Presets");
1331 ghb_dict_iter_init(&iter, internal);
1332 // middle (void*) cast prevents gcc warning "defreferencing type-punned
1333 // pointer will break strict-aliasing rules"
1334 while (g_hash_table_iter_next(
1335 &iter, (gpointer*)(void*)&key, (gpointer*)(void*)&gval))
1337 ghb_settings_set_value(ud->settings, key, gval);
1340 internal = plist_get_dict(internalPlist, "Preferences");
1341 ghb_dict_iter_init(&iter, internal);
1342 // middle (void*) cast prevents gcc warning "defreferencing type-punned
1343 // pointer will break strict-aliasing rules"
1344 while (g_hash_table_iter_next(
1345 &iter, (gpointer*)(void*)&key, (gpointer*)(void*)&gval))
1347 ghb_settings_set_value(ud->settings, key, gval);
1349 prefs_initializing = FALSE;
1353 ghb_settings_close()
1356 ghb_value_free(internalPlist);
1358 ghb_value_free(presetsPlist);
1360 ghb_value_free(prefsPlist);
1365 FindFirstCDROM(void)
1370 strcpy(drive, "A:" G_DIR_SEPARATOR_S);
1371 drives = GetLogicalDrives();
1372 for (ii = 0; ii < 26; ii++)
1378 drive[0] = 'A' + ii;
1379 dtype = GetDriveType(drive);
1380 if (dtype == DRIVE_CDROM)
1382 return g_strdup(drive);
1392 ghb_prefs_load(signal_user_data_t *ud)
1394 GValue *dict, *internal;
1395 GHashTableIter iter;
1397 GValue *gval, *path;
1399 g_debug("ghb_prefs_load");
1400 prefsPlist = load_plist("preferences");
1401 if (prefsPlist == NULL)
1402 prefsPlist = ghb_dict_value_new();
1403 dict = plist_get_dict(prefsPlist, "Preferences");
1404 internal = plist_get_dict(internalPlist, "Preferences");
1405 if (dict == NULL && internal)
1407 dict = ghb_dict_value_new();
1408 ghb_dict_insert(prefsPlist, g_strdup("Preferences"), dict);
1410 // Get defaults from internal defaults
1411 ghb_dict_iter_init(&iter, internal);
1412 // middle (void*) cast prevents gcc warning "defreferencing type-punned
1413 // pointer will break strict-aliasing rules"
1414 while (g_hash_table_iter_next(
1415 &iter, (gpointer*)(void*)&key, (gpointer*)(void*)&gval))
1417 ghb_dict_insert(dict, g_strdup(key), ghb_value_dup(gval));
1420 const gchar *dir = g_get_user_special_dir (G_USER_DIRECTORY_DESKTOP);
1425 ghb_dict_insert(dict,
1426 g_strdup("ExportDirectory"), ghb_value_dup(ghb_string_value(dir)));
1428 dir = g_get_user_special_dir (G_USER_DIRECTORY_VIDEOS);
1433 ghb_dict_insert(dict,
1434 g_strdup("destination_dir"), ghb_value_dup(ghb_string_value(dir)));
1436 ghb_dict_insert(dict,
1437 g_strdup("SrtDir"), ghb_value_dup(ghb_string_value(dir)));
1441 source = FindFirstCDROM();
1444 source = g_strdup("C:" G_DIR_SEPARATOR_S);
1446 ghb_dict_insert(dict, g_strdup("default_source"),
1447 ghb_value_dup(ghb_string_value(source)));
1452 // Read legacy default_preset preference and update accordingly
1453 path = ghb_dict_lookup(dict, "default_preset");
1458 if (G_VALUE_TYPE(path) == G_TYPE_STRING)
1462 path = ghb_array_value_new(1);
1463 ghb_array_append(path, ghb_value_dup(str));
1464 indices = ghb_preset_indices_from_path(presetsPlist, path, &len);
1465 ghb_value_free(path);
1468 indices = ghb_preset_indices_from_path(presetsPlist, path, &len);
1472 presets_set_default(indices, len);
1475 ghb_dict_remove(dict, "default_preset");
1481 get_preset_color(gint type, gboolean folder)
1485 if (type == PRESETS_CUSTOM)
1505 ghb_presets_list_init(
1506 signal_user_data_t *ud,
1510 GtkTreeView *treeview;
1511 GtkTreeIter iter, titer, *piter;
1513 GtkTreeStore *store;
1514 const gchar *preset;
1515 GtkTreePath *parent_path;
1516 const gchar *description;
1521 GValue *presets = NULL;
1523 g_debug("ghb_presets_list_init ()");
1524 more_indices = g_malloc((len+1)*sizeof(gint));
1525 memcpy(more_indices, indices, len*sizeof(gint));
1526 presets = presets_get_folder(presetsPlist, indices, len);
1527 if (presets == NULL)
1529 g_warning("Failed to find parent folder when adding child.");
1532 count = ghb_array_len(presets);
1533 treeview = GTK_TREE_VIEW(GHB_WIDGET(ud->builder, "presets_list"));
1534 store = GTK_TREE_STORE(gtk_tree_view_get_model(treeview));
1535 parent_path = ghb_tree_path_new_from_indices(indices, len);
1538 gtk_tree_model_get_iter(GTK_TREE_MODEL(store), &titer, parent_path);
1540 gtk_tree_path_free(parent_path);
1546 for (ii = 0; ii < count; ii++)
1552 // Additional settings, add row
1553 dict = ghb_array_get_nth(presets, ii);
1554 preset = preset_get_name(dict);
1555 more_indices[len] = ii;
1556 def = preset_is_default(dict);
1558 description = ghb_presets_get_description(dict);
1559 gtk_tree_store_append(store, &iter, piter);
1560 type = ghb_preset_type(dict);
1561 folder = ghb_preset_folder(dict);
1562 color = get_preset_color(type, folder);
1563 gtk_tree_store_set(store, &iter, 0, preset,
1574 if (gtk_tree_model_iter_parent(
1575 GTK_TREE_MODEL(store), &ppiter, piter))
1577 path = gtk_tree_model_get_path(GTK_TREE_MODEL(store), &ppiter);
1578 gtk_tree_view_expand_row(treeview, path, FALSE);
1579 gtk_tree_path_free(path);
1581 path = gtk_tree_model_get_path(GTK_TREE_MODEL(store), piter);
1582 gtk_tree_view_expand_row(treeview, path, FALSE);
1583 gtk_tree_path_free(path);
1587 ghb_presets_list_init(ud, more_indices, len+1);
1588 if (preset_folder_is_open(dict))
1594 path = gtk_tree_model_get_path(GTK_TREE_MODEL(store), piter);
1595 gtk_tree_view_expand_row(treeview, path, FALSE);
1596 gtk_tree_path_free(path);
1598 path = gtk_tree_model_get_path(GTK_TREE_MODEL(store), &iter);
1599 gtk_tree_view_expand_row(treeview, path, FALSE);
1600 gtk_tree_path_free(path);
1604 g_free(more_indices);
1608 presets_list_update_item(
1609 signal_user_data_t *ud,
1613 GtkTreeView *treeview;
1614 GtkTreeStore *store;
1616 GtkTreePath *treepath;
1618 const gchar *description;
1620 gboolean def, folder;
1624 g_debug("presets_list_update_item ()");
1625 dict = presets_get_dict(presetsPlist, indices, len);
1628 treeview = GTK_TREE_VIEW(GHB_WIDGET(ud->builder, "presets_list"));
1629 store = GTK_TREE_STORE(gtk_tree_view_get_model(treeview));
1630 treepath = ghb_tree_path_new_from_indices(indices, len);
1631 gtk_tree_model_get_iter(GTK_TREE_MODEL(store), &iter, treepath);
1632 // Additional settings, add row
1633 name = preset_get_name(dict);
1634 def = preset_is_default(dict);
1636 description = ghb_presets_get_description(dict);
1637 type = ghb_preset_type(dict);
1638 folder = ghb_preset_folder(dict);
1639 color = get_preset_color(type, folder);
1640 gtk_tree_store_set(store, &iter, 0, name,
1648 ghb_presets_list_init(ud, indices, len);
1653 presets_list_insert(
1654 signal_user_data_t *ud,
1658 GtkTreeView *treeview;
1659 GtkTreeIter iter, titer, *piter;
1660 GtkTreeStore *store;
1661 const gchar *preset;
1662 const gchar *description;
1664 gboolean def, folder;
1667 GtkTreePath *parent_path;
1671 g_debug("presets_list_insert ()");
1672 treeview = GTK_TREE_VIEW(GHB_WIDGET(ud->builder, "presets_list"));
1673 store = GTK_TREE_STORE(gtk_tree_view_get_model(treeview));
1674 presets = presets_get_folder(presetsPlist, indices, len-1);
1675 if (presets == NULL)
1677 g_warning("Failed to find parent folder while adding child.");
1680 parent_path = ghb_tree_path_new_from_indices(indices, len-1);
1683 gtk_tree_model_get_iter(GTK_TREE_MODEL(store), &titer, parent_path);
1685 gtk_tree_path_free(parent_path);
1691 count = ghb_array_len(presets);
1692 if (indices[len-1] >= count)
1694 // Additional settings, add row
1695 dict = ghb_array_get_nth(presets, indices[len-1]);
1696 preset = preset_get_name(dict);
1697 def = preset_is_default(dict);
1699 description = ghb_presets_get_description(dict);
1700 gtk_tree_store_insert(store, &iter, piter, indices[len-1]);
1701 type = ghb_preset_type(dict);
1702 folder = ghb_preset_folder(dict);
1703 color = get_preset_color(type, folder);
1704 gtk_tree_store_set(store, &iter, 0, preset,
1712 ghb_presets_list_init(ud, indices, len);
1717 presets_list_remove(
1718 signal_user_data_t *ud,
1722 GtkTreeView *treeview;
1723 GtkTreePath *treepath;
1725 GtkTreeStore *store;
1727 g_debug("presets_list_remove ()");
1728 treeview = GTK_TREE_VIEW(GHB_WIDGET(ud->builder, "presets_list"));
1729 store = GTK_TREE_STORE(gtk_tree_view_get_model(treeview));
1730 treepath = ghb_tree_path_new_from_indices(indices, len);
1733 if (gtk_tree_model_get_iter(GTK_TREE_MODEL(store), &iter, treepath))
1734 gtk_tree_store_remove(store, &iter);
1735 gtk_tree_path_free(treepath);
1740 remove_std_presets(signal_user_data_t *ud)
1745 count = ghb_array_len(presetsPlist);
1746 for (ii = count-1; ii >= 0; ii--)
1751 dict = ghb_array_get_nth(presetsPlist, ii);
1752 ptype = ghb_value_int(preset_dict_get_value(dict, "Type"));
1753 if (ptype == PRESETS_BUILTIN)
1755 if (ghb_presets_remove(presetsPlist, &indices, 1))
1757 presets_list_remove(ud, &indices, 1);
1764 ghb_save_queue(GValue *queue)
1766 store_plist(queue, "queue");
1772 return load_plist("queue");
1776 ghb_remove_queue_file()
1778 remove_plist("queue");
1787 static value_map_t vcodec_xlat[] =
1789 {"MPEG-4 (FFmpeg)", "ffmpeg"},
1790 {"MPEG-4 (XviD)", "ffmpeg"},
1791 {"H.264 (x264)", "x264"},
1792 {"VP3 (Theora)", "theora"},
1796 static value_map_t acodec_xlat[] =
1798 {"AAC (faac)", "faac"},
1799 {"AAC (CoreAudio)", "faac"},
1800 {"AC3 Passthru", "ac3"},
1801 {"MP3 (lame)", "lame"},
1802 {"Vorbis (vorbis)", "vorbis"},
1806 value_map_t container_xlat[] =
1808 {"MP4 file", "mp4"},
1809 {"M4V file", "mp4"},
1810 {"MKV file", "mkv"},
1811 {"AVI file", "mkv"},
1812 {"OGM file", "mkv"},
1816 value_map_t framerate_xlat[] =
1818 {"Same as source", "source"},
1823 {"23.976", "23.976"},
1830 value_map_t samplerate_xlat[] =
1841 value_map_t mix_xlat[] =
1844 {"Stereo", "stereo"},
1845 {"Dolby Surround", "dpl1"},
1846 {"Dolby Pro Logic II", "dpl2"},
1847 {"6-channel discrete", "6ch"},
1848 {"AC3 Passthru", "none"},
1852 value_map_t deint_xlat[] =
1862 value_map_t denoise_xlat[] =
1872 value_map_t detel_xlat[] =
1880 value_map_t decomb_xlat[] =
1888 extern iso639_lang_t ghb_language_table[];
1891 export_lang_xlat2(GValue *lin_val)
1895 if (lin_val == NULL) return NULL;
1899 str = ghb_value_string(lin_val);
1900 for (ii = 0; ghb_language_table[ii].eng_name; ii++)
1902 if (strcmp(str, ghb_language_table[ii].iso639_2) == 0)
1904 gval = ghb_string_value_new(ghb_language_table[ii].eng_name);
1909 g_debug("Can't map language value: (%s)", str);
1915 export_subtitle_xlat2(GValue *lin_val)
1920 if (lin_val == NULL) return NULL;
1921 str = ghb_value_string(lin_val);
1922 if (strcmp(str, "none") == 0)
1924 gval = ghb_string_value_new("None");
1926 else if (strcmp(str, "auto") == 0)
1928 gval = ghb_string_value_new("Autoselect");
1932 gval = export_lang_xlat2(lin_val);
1939 import_lang_xlat2(GValue *mac_val)
1943 if (mac_val == NULL) return NULL;
1947 str = ghb_value_string(mac_val);
1948 for (ii = 0; ghb_language_table[ii].eng_name; ii++)
1950 if (strcmp(str, ghb_language_table[ii].eng_name) == 0)
1952 gval = ghb_string_value_new(ghb_language_table[ii].iso639_2);
1957 g_debug("Can't map language value: (%s)", str);
1963 import_subtitle_xlat2(GValue *mac_val)
1968 if (mac_val == NULL) return NULL;
1969 str = ghb_value_string(mac_val);
1970 if (strcmp(str, "None") == 0)
1972 gval = ghb_string_value_new("none");
1974 else if (strcmp(str, "Autoselect") == 0)
1976 gval = ghb_string_value_new("auto");
1980 gval = import_lang_xlat2(mac_val);
1987 export_audio_track_xlat2(GValue *lin_val)
1990 GValue *gval = NULL;
1992 if (lin_val == NULL) return NULL;
1993 str = ghb_value_string(lin_val);
1994 if (strcmp(str, "none") == 0)
1996 gval = ghb_int_value_new(1);
2000 gint val = ghb_value_int(lin_val) + 1;
2001 gval = ghb_int_value_new(val);
2008 import_audio_track_xlat2(GValue *mac_val)
2014 if (mac_val == NULL) return NULL;
2015 val = ghb_value_int(mac_val);
2024 str = g_strdup_printf("%d", val);
2025 gval = ghb_string_value_new(str);
2031 export_value_xlat2(value_map_t *value_map, GValue *lin_val, GType mac_type)
2035 if (lin_val == NULL) return NULL;
2040 str = ghb_value_string(lin_val);
2041 for (ii = 0; value_map[ii].mac_val; ii++)
2043 if (strcmp(str, value_map[ii].lin_val) == 0)
2045 sval = ghb_string_value_new(value_map[ii].mac_val);
2047 gval = ghb_value_new(mac_type);
2048 if (!g_value_transform(sval, gval))
2050 g_warning("can't transform");
2051 ghb_value_free(gval);
2052 ghb_value_free(sval);
2055 ghb_value_free(sval);
2059 g_debug("Can't map value: (%s)", str);
2065 export_value_xlat(GValue *dict)
2067 GValue *lin_val, *gval;
2070 key = "VideoEncoder";
2071 lin_val = ghb_dict_lookup(dict, key);
2072 gval = export_value_xlat2(vcodec_xlat, lin_val, G_TYPE_STRING);
2074 ghb_dict_insert(dict, g_strdup(key), gval);
2076 lin_val = ghb_dict_lookup(dict, key);
2077 gval = export_value_xlat2(container_xlat, lin_val, G_TYPE_STRING);
2079 ghb_dict_insert(dict, g_strdup(key), gval);
2080 key = "VideoFramerate";
2081 lin_val = ghb_dict_lookup(dict, key);
2082 gval = export_value_xlat2(framerate_xlat, lin_val, G_TYPE_STRING);
2084 ghb_dict_insert(dict, g_strdup(key), gval);
2085 key = "PictureDetelecine";
2086 lin_val = ghb_dict_lookup(dict, key);
2087 gval = export_value_xlat2(detel_xlat, lin_val, G_TYPE_INT);
2089 ghb_dict_insert(dict, g_strdup(key), gval);
2090 key = "PictureDecomb";
2091 lin_val = ghb_dict_lookup(dict, key);
2092 gval = export_value_xlat2(decomb_xlat, lin_val, G_TYPE_INT);
2094 ghb_dict_insert(dict, g_strdup(key), gval);
2095 key = "PictureDeinterlace";
2096 lin_val = ghb_dict_lookup(dict, key);
2097 gval = export_value_xlat2(deint_xlat, lin_val, G_TYPE_INT);
2099 ghb_dict_insert(dict, g_strdup(key), gval);
2100 key = "PictureDenoise";
2101 lin_val = ghb_dict_lookup(dict, key);
2102 gval = export_value_xlat2(denoise_xlat, lin_val, G_TYPE_INT);
2104 ghb_dict_insert(dict, g_strdup(key), gval);
2110 slist = ghb_dict_lookup(dict, "SubtitleList");
2111 count = ghb_array_len(slist);
2112 for (ii = 0; ii < count; ii++)
2114 sdict = ghb_array_get_nth(slist, ii);
2115 key = "SubtitleLanguage";
2116 lin_val = ghb_dict_lookup(sdict, key);
2117 gval = export_subtitle_xlat2(lin_val);
2119 ghb_dict_insert(sdict, g_strdup(key), gval);
2125 alist = ghb_dict_lookup(dict, "AudioList");
2126 count = ghb_array_len(alist);
2127 for (ii = 0; ii < count; ii++)
2129 adict = ghb_array_get_nth(alist, ii);
2131 lin_val = ghb_dict_lookup(adict, key);
2132 gval = export_audio_track_xlat2(lin_val);
2134 ghb_dict_insert(adict, g_strdup(key), gval);
2135 key = "AudioEncoder";
2136 lin_val = ghb_dict_lookup(adict, key);
2137 gval = export_value_xlat2(acodec_xlat, lin_val, G_TYPE_STRING);
2139 ghb_dict_insert(adict, g_strdup(key), gval);
2140 key = "AudioSamplerate";
2141 lin_val = ghb_dict_lookup(adict, key);
2142 gval = export_value_xlat2(samplerate_xlat, lin_val, G_TYPE_STRING);
2144 ghb_dict_insert(adict, g_strdup(key), gval);
2145 key = "AudioMixdown";
2146 lin_val = ghb_dict_lookup(adict, key);
2147 gval = export_value_xlat2(mix_xlat, lin_val, G_TYPE_STRING);
2149 ghb_dict_insert(adict, g_strdup(key), gval);
2157 value_map_t *value_map,
2161 GValue *gval, *def_val;
2163 if (mac_val == NULL) return NULL;
2164 def_val = ghb_dict_lookup(defaults, key);
2171 str = ghb_value_string(mac_val);
2172 for (ii = 0; value_map[ii].mac_val; ii++)
2174 if (strcmp(str, value_map[ii].mac_val) == 0)
2176 sval = ghb_string_value_new(value_map[ii].lin_val);
2178 gval = ghb_value_new(G_VALUE_TYPE(def_val));
2179 if (!g_value_transform(sval, gval))
2181 g_warning("can't transform");
2182 ghb_value_free(gval);
2183 ghb_value_free(sval);
2186 ghb_value_free(sval);
2198 str = ghb_value_string(mac_val);
2199 for (ii = 0; value_map[ii].mac_val; ii++)
2201 if (strcmp(str, value_map[ii].mac_val) == 0)
2203 sval = ghb_string_value_new(value_map[ii].lin_val);
2205 gval = ghb_value_new(G_VALUE_TYPE(mac_val));
2206 if (!g_value_transform(sval, gval))
2208 g_warning("can't transform");
2209 ghb_value_free(gval);
2210 ghb_value_free(sval);
2213 ghb_value_free(sval);
2223 import_value_xlat(GValue *dict)
2225 GValue *defaults, *mac_val, *gval;
2228 defaults = plist_get_dict(internalPlist, "Presets");
2229 key = "VideoEncoder";
2230 mac_val = ghb_dict_lookup(dict, key);
2231 gval = import_value_xlat2(defaults, vcodec_xlat, key, mac_val);
2233 ghb_dict_insert(dict, g_strdup(key), gval);
2235 mac_val = ghb_dict_lookup(dict, key);
2236 gval = import_value_xlat2(defaults, container_xlat, key, mac_val);
2238 ghb_dict_insert(dict, g_strdup(key), gval);
2239 key = "VideoFramerate";
2240 mac_val = ghb_dict_lookup(dict, key);
2241 gval = import_value_xlat2(defaults, framerate_xlat, key, mac_val);
2243 ghb_dict_insert(dict, g_strdup(key), gval);
2244 key = "PictureDetelecine";
2245 mac_val = ghb_dict_lookup(dict, key);
2246 gval = import_value_xlat2(defaults, detel_xlat, key, mac_val);
2248 ghb_dict_insert(dict, g_strdup(key), gval);
2249 key = "PictureDecomb";
2250 mac_val = ghb_dict_lookup(dict, key);
2251 gval = import_value_xlat2(defaults, decomb_xlat, key, mac_val);
2253 ghb_dict_insert(dict, g_strdup(key), gval);
2254 key = "PictureDeinterlace";
2255 mac_val = ghb_dict_lookup(dict, key);
2256 gval = import_value_xlat2(defaults, deint_xlat, key, mac_val);
2258 ghb_dict_insert(dict, g_strdup(key), gval);
2259 key = "PictureDenoise";
2260 mac_val = ghb_dict_lookup(dict, key);
2261 gval = import_value_xlat2(defaults, denoise_xlat, key, mac_val);
2263 ghb_dict_insert(dict, g_strdup(key), gval);
2272 sdeflist = ghb_dict_lookup(defaults, "SubtitleList");
2275 slist = ghb_dict_lookup(dict, "SubtitleList");
2278 sdefaults = ghb_array_get_nth(sdeflist, 0);
2279 count = ghb_array_len(slist);
2280 for (ii = 0; ii < count; ii++)
2282 sdict = ghb_array_get_nth(slist, ii);
2283 key = "SubtitleLanguage";
2284 mac_val = ghb_dict_lookup(sdict, key);
2285 gval = import_subtitle_xlat2(mac_val);
2287 ghb_dict_insert(sdict, g_strdup(key), gval);
2294 mac_val = ghb_dict_lookup(dict, key);
2295 slist = ghb_array_value_new(8);
2296 ghb_dict_insert(dict, g_strdup("SubtitleList"), slist);
2301 gval = import_subtitle_xlat2(mac_val);
2302 lang = ghb_value_string(gval);
2303 if (lang && strcasecmp(lang, "none") != 0 && !slist)
2305 sdict = ghb_dict_value_new();
2306 ghb_array_append(slist, sdict);
2307 ghb_dict_insert(sdict, g_strdup("SubtitleLanguage"), gval);
2308 gval = ghb_dict_lookup(dict, "SubtitlesForced");
2311 ghb_dict_insert(sdict, g_strdup("SubtitleForced"),
2312 ghb_value_dup(gval));
2316 ghb_dict_insert(sdict, g_strdup("SubtitleForced"),
2317 ghb_boolean_value_new(FALSE));
2319 ghb_dict_insert(sdict, g_strdup("SubtitleBurned"),
2320 ghb_boolean_value_new(TRUE));
2321 ghb_dict_insert(sdict, g_strdup("SubtitleDefaultTrack"),
2322 ghb_boolean_value_new(FALSE));
2326 ghb_value_free(gval);
2333 ghb_dict_remove(dict, "Subtitles");
2334 ghb_dict_remove(dict, "SubtitlesForced");
2342 adeflist = ghb_dict_lookup(defaults, "AudioList");
2345 adefaults = ghb_array_get_nth(adeflist, 0);
2346 alist = ghb_dict_lookup(dict, "AudioList");
2347 count = ghb_array_len(alist);
2348 for (ii = 0; ii < count; ii++)
2350 adict = ghb_array_get_nth(alist, ii);
2352 mac_val = ghb_dict_lookup(adict, key);
2353 gval = import_audio_track_xlat2(mac_val);
2355 ghb_dict_insert(adict, g_strdup(key), gval);
2356 key = "AudioEncoder";
2357 mac_val = ghb_dict_lookup(adict, key);
2358 gval = import_value_xlat2(adefaults, acodec_xlat, key, mac_val);
2360 ghb_dict_insert(adict, g_strdup(key), gval);
2361 key = "AudioSamplerate";
2362 mac_val = ghb_dict_lookup(adict, key);
2363 gval = import_value_xlat2(adefaults, samplerate_xlat, key, mac_val);
2365 ghb_dict_insert(adict, g_strdup(key), gval);
2366 key = "AudioMixdown";
2367 mac_val = ghb_dict_lookup(adict, key);
2368 gval = import_value_xlat2(adefaults, mix_xlat, key, mac_val);
2370 ghb_dict_insert(adict, g_strdup(key), gval);
2372 mac_val = ghb_dict_lookup(adict, "AudioTrackDRCSlider");
2373 if (mac_val != NULL)
2376 drc = ghb_value_double(mac_val);
2377 if (drc < 1.0 && drc > 0.0)
2379 ghb_dict_insert(adict, g_strdup("AudioTrackDRCSlider"),
2380 ghb_double_value_new(0.0));
2388 import_xlat_preset(GValue *dict)
2395 g_debug("import_xlat_preset ()");
2396 uses_max = ghb_value_boolean(
2397 preset_dict_get_value(dict, "UsesMaxPictureSettings"));
2398 uses_pic = ghb_value_int(
2399 preset_dict_get_value(dict, "UsesPictureSettings"));
2400 par = ghb_value_int(preset_dict_get_value(dict, "PicturePAR"));
2401 vqtype = ghb_value_int(preset_dict_get_value(dict, "VideoQualityType"));
2403 if (uses_max || uses_pic == 2)
2405 ghb_dict_insert(dict, g_strdup("autoscale"),
2406 ghb_boolean_value_new(TRUE));
2412 if (ghb_dict_lookup(dict, "PictureModulus") == NULL)
2413 ghb_dict_insert(dict, g_strdup("PictureModulus"),
2414 ghb_int_value_new(16));
2418 ghb_dict_insert(dict, g_strdup("PictureModulus"),
2419 ghb_int_value_new(1));
2423 if (ghb_dict_lookup(dict, "PictureModulus") == NULL)
2424 ghb_dict_insert(dict, g_strdup("PictureModulus"),
2425 ghb_int_value_new(16));
2429 if (ghb_dict_lookup(dict, "PictureModulus") == NULL)
2430 ghb_dict_insert(dict, g_strdup("PictureModulus"),
2431 ghb_int_value_new(16));
2434 // VideoQualityType/0/1/2 - vquality_type_/target/bitrate/constant
2439 ghb_dict_insert(dict, g_strdup("vquality_type_target"),
2440 ghb_boolean_value_new(TRUE));
2441 ghb_dict_insert(dict, g_strdup("vquality_type_bitrate"),
2442 ghb_boolean_value_new(FALSE));
2443 ghb_dict_insert(dict, g_strdup("vquality_type_constant"),
2444 ghb_boolean_value_new(FALSE));
2448 ghb_dict_insert(dict, g_strdup("vquality_type_target"),
2449 ghb_boolean_value_new(FALSE));
2450 ghb_dict_insert(dict, g_strdup("vquality_type_bitrate"),
2451 ghb_boolean_value_new(TRUE));
2452 ghb_dict_insert(dict, g_strdup("vquality_type_constant"),
2453 ghb_boolean_value_new(FALSE));
2457 ghb_dict_insert(dict, g_strdup("vquality_type_target"),
2458 ghb_boolean_value_new(FALSE));
2459 ghb_dict_insert(dict, g_strdup("vquality_type_bitrate"),
2460 ghb_boolean_value_new(FALSE));
2461 ghb_dict_insert(dict, g_strdup("vquality_type_constant"),
2462 ghb_boolean_value_new(TRUE));
2466 ghb_dict_insert(dict, g_strdup("vquality_type_target"),
2467 ghb_boolean_value_new(FALSE));
2468 ghb_dict_insert(dict, g_strdup("vquality_type_bitrate"),
2469 ghb_boolean_value_new(FALSE));
2470 ghb_dict_insert(dict, g_strdup("vquality_type_constant"),
2471 ghb_boolean_value_new(TRUE));
2474 import_value_xlat(dict);
2479 vquality = ghb_value_double(preset_dict_get_value(dict, "VideoQualitySlider"));
2484 gval = preset_dict_get_value(dict, "VideoEncoder");
2485 vcodec = ghb_lookup_combo_int("VideoEncoder", gval);
2488 case HB_VCODEC_X264:
2490 vquality = 51. - vquality * 51.;
2493 case HB_VCODEC_FFMPEG:
2495 vquality = 31. - vquality * 30.;
2498 case HB_VCODEC_THEORA:
2500 vquality = vquality * 63.;
2508 ghb_dict_insert(dict, g_strdup("VideoQualitySlider"),
2509 ghb_double_value_new(vquality));
2514 import_xlat_presets(GValue *presets)
2520 g_debug("import_xlat_presets ()");
2521 if (presets == NULL) return;
2522 count = ghb_array_len(presets);
2523 for (ii = 0; ii < count; ii++)
2525 dict = ghb_array_get_nth(presets, ii);
2526 folder = ghb_value_boolean(preset_dict_get_value(dict, "Folder"));
2531 nested = ghb_dict_lookup(dict, "ChildrenArray");
2532 import_xlat_presets(nested);
2536 import_xlat_preset(dict);
2542 export_xlat_preset(GValue *dict)
2544 gboolean autoscale, target, br, constant;
2546 g_debug("export_xlat_prest ()");
2547 autoscale = ghb_value_boolean(preset_dict_get_value(dict, "autoscale"));
2548 target = ghb_value_boolean(
2549 preset_dict_get_value(dict, "vquality_type_target"));
2550 br = ghb_value_boolean(
2551 preset_dict_get_value(dict, "vquality_type_bitrate"));
2552 constant = ghb_value_boolean(
2553 preset_dict_get_value(dict, "vquality_type_constant"));
2556 ghb_dict_insert(dict, g_strdup("UsesPictureSettings"),
2557 ghb_int_value_new(2));
2559 ghb_dict_insert(dict, g_strdup("UsesPictureSettings"),
2560 ghb_int_value_new(1));
2562 // VideoQualityType/0/1/2 - vquality_type_/target/bitrate/constant
2565 ghb_dict_insert(dict, g_strdup("VideoQualityType"),
2566 ghb_int_value_new(0));
2570 ghb_dict_insert(dict, g_strdup("VideoQualityType"),
2571 ghb_int_value_new(1));
2575 ghb_dict_insert(dict, g_strdup("VideoQualityType"),
2576 ghb_int_value_new(2));
2579 GValue *alist, *adict;
2582 alist = ghb_dict_lookup(dict, "AudioList");
2583 count = ghb_array_len(alist);
2584 for (ii = 0; ii < count; ii++)
2588 adict = ghb_array_get_nth(alist, ii);
2589 drc = ghb_value_double(
2590 preset_dict_get_value(adict, "AudioTrackDRCSlider"));
2591 if (drc < 1.0 && drc > 0.0)
2593 ghb_dict_insert(adict, g_strdup("AudioTrackDRCSlider"),
2594 ghb_double_value_new(0.0));
2598 ghb_dict_remove(dict, "UsesMaxPictureSettings");
2599 ghb_dict_remove(dict, "autoscale");
2600 ghb_dict_remove(dict, "vquality_type_target");
2601 ghb_dict_remove(dict, "vquality_type_bitrate");
2602 ghb_dict_remove(dict, "vquality_type_constant");
2603 export_value_xlat(dict);
2607 export_xlat_presets(GValue *presets)
2613 if (presets == NULL) return;
2614 count = ghb_array_len(presets);
2615 for (ii = 0; ii < count; ii++)
2617 dict = ghb_array_get_nth(presets, ii);
2618 folder = ghb_value_boolean(preset_dict_get_value(dict, "Folder"));
2623 nested = ghb_dict_lookup(dict, "ChildrenArray");
2624 export_xlat_presets(nested);
2628 export_xlat_preset(dict);
2633 static guint prefs_timeout_id = 0;
2636 delayed_store_prefs(gpointer data)
2638 store_plist(prefsPlist, "preferences");
2639 prefs_timeout_id = 0;
2648 export = ghb_value_dup(presetsPlist);
2649 export_xlat_presets(export);
2650 store_plist(export, "presets");
2651 ghb_value_free(export);
2657 if (prefs_timeout_id != 0)
2662 mc = g_main_context_default();
2663 source = g_main_context_find_source_by_id(mc, prefs_timeout_id);
2665 g_source_destroy(source);
2667 prefs_timeout_id = g_timeout_add_seconds(1, (GSourceFunc)delayed_store_prefs, NULL);
2671 ghb_presets_reload(signal_user_data_t *ud)
2673 GValue *std_presets;
2677 g_debug("ghb_presets_reload()\n");
2678 std_presets = ghb_resource_get("standard-presets");
2679 if (std_presets == NULL) return;
2681 remove_std_presets(ud);
2682 indices = presets_find_default(presetsPlist, &len);
2685 presets_clear_default(std_presets);
2688 // Merge the keyfile contents into our presets
2689 count = ghb_array_len(std_presets);
2690 for (ii = count-1; ii >= 0; ii--)
2696 std_dict = ghb_array_get_nth(std_presets, ii);
2697 copy_dict = ghb_value_dup(std_dict);
2698 ghb_dict_insert(copy_dict, g_strdup("PresetBuildNumber"),
2699 ghb_int64_value_new(hb_get_build(NULL)));
2700 ghb_presets_insert(presetsPlist, copy_dict, &indices, 1);
2701 presets_list_insert(ud, &indices, 1);
2703 import_xlat_presets(presetsPlist);
2712 count = ghb_array_len(presetsPlist);
2713 for (ii = count-1; ii >= 0; ii--)
2718 dict = ghb_array_get_nth(presetsPlist, ii);
2719 type = ghb_dict_lookup(dict, "Type");
2727 replace_standard_presets()
2729 GValue *std_presets;
2733 count = ghb_array_len(presetsPlist);
2734 for (ii = count-1; ii >= 0; ii--)
2739 dict = ghb_array_get_nth(presetsPlist, ii);
2740 ptype = ghb_value_int(preset_dict_get_value(dict, "Type"));
2741 if (ptype == PRESETS_BUILTIN)
2744 ghb_presets_remove(presetsPlist, &indices, 1);
2748 std_presets = ghb_resource_get("standard-presets");
2749 if (std_presets == NULL) return;
2751 indices = presets_find_default(presetsPlist, &len);
2754 presets_clear_default(std_presets);
2757 // Merge the keyfile contents into our presets
2758 count = ghb_array_len(std_presets);
2759 for (ii = count-1; ii >= 0; ii--)
2765 std_dict = ghb_array_get_nth(std_presets, ii);
2766 copy_dict = ghb_value_dup(std_dict);
2767 ghb_dict_insert(copy_dict, g_strdup("PresetBuildNumber"),
2768 ghb_int64_value_new(hb_get_build(NULL)));
2769 ghb_presets_insert(presetsPlist, copy_dict, &indices, 1);
2771 import_xlat_presets(presetsPlist);
2776 update_standard_presets(signal_user_data_t *ud)
2780 count = ghb_array_len(presetsPlist);
2781 for (ii = count-1; ii >= 0; ii--)
2788 dict = ghb_array_get_nth(presetsPlist, ii);
2789 gval = ghb_dict_lookup(dict, "Type");
2792 // Old preset that doesn't have a Type
2793 replace_standard_presets();
2797 type = ghb_value_int(gval);
2800 gval = ghb_dict_lookup(dict, "PresetBuildNumber");
2803 // Old preset that doesn't have a build number
2804 replace_standard_presets();
2808 build = ghb_value_int64(gval);
2809 if (build != hb_get_build(NULL))
2811 // Build number does not match
2812 replace_standard_presets();
2821 ghb_presets_load(signal_user_data_t *ud)
2823 presetsPlist = load_plist("presets");
2824 if (presetsPlist == NULL)
2826 presetsPlist = ghb_value_dup(ghb_resource_get("standard-presets"));
2827 import_xlat_presets(presetsPlist);
2830 else if (G_VALUE_TYPE(presetsPlist) == ghb_dict_get_type())
2831 { // Presets is older dictionary format. Convert to array
2832 ghb_value_free(presetsPlist);
2833 presetsPlist = ghb_value_dup(ghb_resource_get("standard-presets"));
2834 import_xlat_presets(presetsPlist);
2837 else if (check_old_presets())
2839 ghb_value_free(presetsPlist);
2840 presetsPlist = ghb_value_dup(ghb_resource_get("standard-presets"));
2841 import_xlat_presets(presetsPlist);
2844 update_standard_presets(ud);
2845 import_xlat_presets(presetsPlist);
2849 settings_save(signal_user_data_t *ud, const GValue *path)
2851 GValue *dict, *internal;
2852 GHashTableIter iter;
2856 gint *indices, len, count;
2857 gint *def_indices, def_len;
2859 gboolean replace = FALSE;
2861 g_debug("settings_save");
2862 if (internalPlist == NULL) return;
2863 count = ghb_array_len(path);
2864 name = g_value_get_string(ghb_array_get_nth(path, count-1));
2865 indices = ghb_preset_indices_from_path(presetsPlist, path, &len);
2868 if (ghb_presets_get_folder(presetsPlist, indices, len))
2871 message = g_strdup_printf(
2872 "%s: Folder already exists.\n"
2873 "You can not replace it with a preset.",
2875 ghb_message_dialog(GTK_MESSAGE_ERROR, message, "Cancel", NULL);
2879 dict = ghb_dict_value_new();
2880 ghb_presets_replace(presetsPlist, dict, indices, len);
2885 indices = presets_find_pos(path, PRESETS_CUSTOM, &len);
2888 dict = ghb_dict_value_new();
2889 ghb_presets_insert(presetsPlist, dict, indices, len);
2893 g_warning("failed to find insert path");
2897 current_preset = dict;
2898 autoscale = ghb_settings_get_boolean(ud->settings, "autoscale");
2899 ghb_settings_set_int64(ud->settings, "Type", PRESETS_CUSTOM);
2900 ghb_settings_set_int64(ud->settings, "PresetBuildNumber", hb_get_build(NULL));
2902 internal = plist_get_dict(internalPlist, "Presets");
2903 ghb_dict_iter_init(&iter, internal);
2904 // middle (void*) cast prevents gcc warning "defreferencing type-punned
2905 // pointer will break strict-aliasing rules"
2906 while (g_hash_table_iter_next(
2907 &iter, (gpointer*)(void*)&key, (gpointer*)(void*)&value))
2915 if (strcmp(key, "PictureWidth") == 0)
2917 key2 = "scale_width";
2919 else if (strcmp(key, "PictureHeight") == 0)
2921 key2 = "scale_height";
2924 gval = ghb_settings_get_value(ud->settings, key2);
2929 ghb_dict_insert(dict, g_strdup(key), ghb_value_dup(gval));
2931 internal = plist_get_dict(internalPlist, "XlatPresets");
2932 ghb_dict_iter_init(&iter, internal);
2933 // middle (void*) cast prevents gcc warning "defreferencing type-punned
2934 // pointer will break strict-aliasing rules"
2935 while (g_hash_table_iter_next(
2936 &iter, (gpointer*)(void*)&key, (gpointer*)(void*)&value))
2940 gval = ghb_settings_get_value(ud->settings, key);
2945 ghb_dict_insert(dict, g_strdup(key), ghb_value_dup(gval));
2947 ghb_dict_insert(dict, g_strdup("PresetName"), ghb_string_value_new(name));
2950 def_indices = presets_find_default(presetsPlist, &def_len);
2951 if (def_indices != NULL &&
2952 preset_path_cmp(indices, len, def_indices, def_len) != 0)
2954 ghb_dict_insert(dict, g_strdup("Default"),
2955 ghb_boolean_value_new(FALSE));
2957 presets_list_update_item(ud, indices, len);
2961 ghb_dict_insert(dict, g_strdup("Default"),
2962 ghb_boolean_value_new(FALSE));
2963 presets_list_insert(ud, indices, len);
2966 ud->dont_clear_presets = TRUE;
2967 // Make the new preset the selected item
2968 ghb_select_preset2(ud->builder, indices, len);
2970 ud->dont_clear_presets = FALSE;
2975 folder_save(signal_user_data_t *ud, const GValue *path)
2977 GValue *dict, *folder;
2978 gint *indices, len, count;
2981 count = ghb_array_len(path);
2982 name = g_value_get_string(ghb_array_get_nth(path, count-1));
2983 indices = ghb_preset_indices_from_path(presetsPlist, path, &len);
2986 if (!ghb_presets_get_folder(presetsPlist, indices, len))
2989 message = g_strdup_printf(
2990 "%s: Preset already exists.\n"
2991 "You can not replace it with a folder.",
2993 ghb_message_dialog(GTK_MESSAGE_ERROR, message, "Cancel", NULL);
2998 // Already exists, update its description
2999 dict = presets_get_dict(presetsPlist, indices, len);
3000 ghb_dict_insert(dict, g_strdup("PresetDescription"),
3001 ghb_value_dup(preset_dict_get_value(
3002 ud->settings, "PresetDescription")));
3008 indices = presets_find_pos(path, PRESETS_CUSTOM, &len);
3011 dict = ghb_dict_value_new();
3012 ghb_presets_insert(presetsPlist, dict, indices, len);
3016 g_warning("failed to find insert path");
3020 ghb_dict_insert(dict, g_strdup("PresetDescription"),
3021 ghb_value_dup(preset_dict_get_value(
3022 ud->settings, "PresetDescription")));
3023 ghb_dict_insert(dict, g_strdup("PresetName"), ghb_string_value_new(name));
3024 folder = ghb_array_value_new(8);
3025 ghb_dict_insert(dict, g_strdup("ChildrenArray"), folder);
3026 ghb_dict_insert(dict, g_strdup("Type"),
3027 ghb_int64_value_new(PRESETS_CUSTOM));
3028 ghb_dict_insert(dict, g_strdup("Folder"), ghb_boolean_value_new(TRUE));
3030 presets_list_insert(ud, indices, len);
3037 ghb_presets_list_default(signal_user_data_t *ud)
3039 GtkTreeView *treeview;
3040 GtkTreePath *treepath;
3042 GtkTreeStore *store;
3045 g_debug("ghb_presets_list_default ()");
3046 treeview = GTK_TREE_VIEW(GHB_WIDGET(ud->builder, "presets_list"));
3047 store = GTK_TREE_STORE(gtk_tree_view_get_model(treeview));
3048 indices = presets_find_default(presetsPlist, &len);
3049 if (indices == NULL) return;
3050 treepath = ghb_tree_path_new_from_indices(indices, len);
3053 if (gtk_tree_model_get_iter(GTK_TREE_MODEL(store), &iter, treepath))
3055 gtk_tree_store_set(store, &iter,
3060 gtk_tree_path_free(treepath);
3066 ghb_presets_list_clear_default(signal_user_data_t *ud)
3068 GtkTreeView *treeview;
3069 GtkTreePath *treepath;
3071 GtkTreeStore *store;
3074 g_debug("ghb_presets_list_clear_default ()");
3075 treeview = GTK_TREE_VIEW(GHB_WIDGET(ud->builder, "presets_list"));
3076 store = GTK_TREE_STORE(gtk_tree_view_get_model(treeview));
3077 indices = presets_find_default(presetsPlist, &len);
3078 if (indices == NULL) return;
3079 treepath = ghb_tree_path_new_from_indices(indices, len);
3082 if (gtk_tree_model_get_iter(GTK_TREE_MODEL(store), &iter, treepath))
3084 gtk_tree_store_set(store, &iter,
3089 gtk_tree_path_free(treepath);
3095 update_audio_presets(signal_user_data_t *ud)
3097 g_debug("update_audio_presets");
3098 const GValue *audio_list;
3100 audio_list = ghb_settings_get_value(ud->settings, "audio_list");
3101 ghb_settings_set_value(ud->settings, "AudioList", audio_list);
3105 update_subtitle_presets(signal_user_data_t *ud)
3107 g_debug("update_subtitle_presets");
3108 const GValue *subtitle_list, *subtitle;
3109 GValue *slist, *dict;
3110 gint count, ii, source;
3112 subtitle_list = ghb_settings_get_value(ud->settings, "subtitle_list");
3113 slist = ghb_array_value_new(8);
3114 count = ghb_array_len(subtitle_list);
3115 for (ii = 0; ii < count; ii++)
3117 subtitle = ghb_array_get_nth(subtitle_list, ii);
3118 source = ghb_settings_get_int(subtitle, "SubtitleSource");
3119 if (source != SRTSUB)
3121 dict = ghb_value_dup(subtitle);
3122 ghb_array_append(slist, dict);
3125 ghb_settings_take_value(ud->settings, "SubtitleList", slist);
3129 enforce_preset_type(signal_user_data_t *ud, const GValue *path)
3132 GtkWidget *normal, *folder;
3135 normal = GHB_WIDGET(ud->builder, "preset_type_normal");
3136 folder = GHB_WIDGET(ud->builder, "preset_type_folder");
3137 indices = ghb_preset_indices_from_path(presetsPlist, path, &len);
3140 fold = ghb_presets_get_folder(presetsPlist, indices, len);
3142 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(folder),
3145 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(normal),
3147 gtk_widget_set_sensitive(folder, fold);
3148 gtk_widget_set_sensitive(normal, !fold);
3153 gtk_widget_set_sensitive(folder, TRUE);
3154 gtk_widget_set_sensitive(normal, TRUE);
3158 G_MODULE_EXPORT void
3159 presets_menu_clicked_cb(GtkWidget *xwidget, signal_user_data_t *ud)
3163 menu = GTK_MENU(GHB_WIDGET(ud->builder, "presets_menu"));
3164 gtk_menu_popup(menu, NULL, NULL, NULL, NULL, 1,
3165 gtk_get_current_event_time());
3168 G_MODULE_EXPORT void
3169 preset_import_clicked_cb(GtkWidget *xwidget, signal_user_data_t *ud)
3172 GtkResponseType response;
3175 GtkFileFilter *filter;
3177 g_debug("preset_import_clicked_cb ()");
3179 dialog = gtk_file_chooser_dialog_new("Export Preset", NULL,
3180 GTK_FILE_CHOOSER_ACTION_OPEN,
3181 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
3182 GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
3185 filter = gtk_file_filter_new();
3186 gtk_file_filter_set_name(filter, "All (*)");
3187 gtk_file_filter_add_pattern(filter, "*");
3188 gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(dialog), filter);
3190 filter = gtk_file_filter_new();
3191 gtk_file_filter_set_name(filter, "Presets (*.plist)");
3192 gtk_file_filter_add_pattern(filter, "*.plist");
3193 gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(dialog), filter);
3194 gtk_file_chooser_set_filter(GTK_FILE_CHOOSER(dialog), filter);
3196 exportDir = ghb_settings_get_string(ud->settings, "ExportDirectory");
3197 if (exportDir == NULL || exportDir[0] == '\0')
3199 exportDir = g_strdup(".");
3201 gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(dialog), exportDir);
3204 response = gtk_dialog_run(GTK_DIALOG(dialog));
3205 gtk_widget_hide(dialog);
3206 if (response == GTK_RESPONSE_ACCEPT)
3208 GValue *dict, *array;
3212 filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog));
3214 // import the preset
3215 if (!g_file_test(filename, G_FILE_TEST_IS_REGULAR))
3217 gtk_widget_destroy(dialog);
3221 array = ghb_plist_parse_file(filename);
3224 import_xlat_presets(array);
3225 presets_clear_default(array);
3226 presets_customize(array);
3228 count = ghb_array_len(array);
3229 for (ii = 0; ii < count; ii++)
3231 GValue *path, *name;
3235 dict = ghb_array_get_nth(array, ii);
3236 path = ghb_array_value_new(1);
3237 name = ghb_value_dup(ghb_dict_lookup(dict, "PresetName"));
3238 ghb_array_append(path, name);
3239 indices = ghb_preset_indices_from_path(presetsPlist, path, &len);
3240 // Modify the preset name till we make it unique
3241 while (indices != NULL)
3243 gchar *str = ghb_value_string(name);
3245 ghb_value_free(path);
3248 str = g_strdup_printf("%s %d", str, index);
3249 path = ghb_array_value_new(1);
3250 name = ghb_string_value_new(str);
3251 ghb_array_append(path, name);
3255 indices = ghb_preset_indices_from_path(presetsPlist, path, &len);
3257 ghb_dict_insert(dict, g_strdup("PresetName"), ghb_value_dup(name));
3258 indices = presets_find_pos(path, PRESETS_CUSTOM, &len);
3259 ghb_presets_insert(presetsPlist, ghb_value_dup(dict), indices, len);
3260 presets_list_insert(ud, indices, len);
3261 ghb_value_free(path);
3263 ghb_value_free(array);
3265 exportDir = ghb_settings_get_string(ud->settings, "ExportDirectory");
3266 dir = g_path_get_dirname(filename);
3267 if (strcmp(dir, exportDir) != 0)
3269 ghb_settings_set_string(ud->settings, "ExportDirectory", dir);
3270 ghb_pref_save(ud->settings, "ExportDirectory");
3275 gtk_widget_destroy(dialog);
3278 G_MODULE_EXPORT void
3279 preset_export_clicked_cb(GtkWidget *xwidget, signal_user_data_t *ud)
3282 GtkResponseType response;
3284 const gchar *name = "";
3285 gint count, *indices, len;
3289 g_debug("preset_export_clicked_cb ()");
3290 preset = ghb_settings_get_value (ud->settings, "preset_selection");
3294 count = ghb_array_len(preset);
3298 name = g_value_get_string(ghb_array_get_nth(preset, count-1));
3300 dialog = gtk_file_chooser_dialog_new("Export Preset", NULL,
3301 GTK_FILE_CHOOSER_ACTION_SAVE,
3302 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
3303 GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT,
3306 exportDir = ghb_settings_get_string(ud->settings, "ExportDirectory");
3307 if (exportDir == NULL || exportDir[0] == '\0')
3309 exportDir = g_strdup(".");
3311 filename = g_strdup_printf("%s.plist", name);
3312 gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(dialog), exportDir);
3313 gtk_file_chooser_set_current_name(GTK_FILE_CHOOSER(dialog), filename);
3317 indices = ghb_preset_indices_from_path(presetsPlist, preset, &len);
3318 if (indices == NULL)
3321 response = gtk_dialog_run(GTK_DIALOG(dialog));
3322 gtk_widget_hide(dialog);
3323 if (response == GTK_RESPONSE_ACCEPT)
3325 GValue *export, *dict, *array;
3329 filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog));
3331 // export the preset
3332 dict = presets_get_dict(presetsPlist, indices, len);
3334 export = ghb_value_dup(dict);
3335 array = ghb_array_value_new(1);
3336 ghb_array_append(array, export);
3337 presets_clear_default(array);
3338 presets_customize(array);
3339 export_xlat_presets(array);
3341 file = g_fopen(filename, "w");
3344 ghb_plist_write(file, array);
3347 ghb_value_free(array);
3349 exportDir = ghb_settings_get_string(ud->settings, "ExportDirectory");
3350 dir = g_path_get_dirname(filename);
3351 if (strcmp(dir, exportDir) != 0)
3353 ghb_settings_set_string(ud->settings, "ExportDirectory", dir);
3354 ghb_pref_save(ud->settings, "ExportDirectory");
3360 gtk_widget_destroy(dialog);
3364 G_MODULE_EXPORT void
3365 presets_save_clicked_cb(GtkWidget *xwidget, signal_user_data_t *ud)
3370 GtkResponseType response;
3372 const gchar *name = "";
3373 gint count, *indices, len;
3375 g_debug("presets_save_clicked_cb ()");
3376 preset = ghb_settings_get_value (ud->settings, "preset_selection");
3378 count = ghb_array_len(preset);
3380 name = g_value_get_string(ghb_array_get_nth(preset, count-1));
3383 // Clear the description
3384 desc = GTK_TEXT_VIEW(GHB_WIDGET(ud->builder, "PresetDescription"));
3385 dialog = GHB_WIDGET(ud->builder, "preset_save_dialog");
3386 entry = GTK_ENTRY(GHB_WIDGET(ud->builder, "PresetName"));
3387 gtk_entry_set_text(entry, name);
3388 enforce_preset_type(ud, preset);
3389 response = gtk_dialog_run(GTK_DIALOG(dialog));
3390 gtk_widget_hide(dialog);
3391 if (response == GTK_RESPONSE_OK)
3394 const gchar *name = gtk_entry_get_text(entry);
3397 if (ghb_settings_get_boolean(ud->settings, "preset_type_folder"))
3399 if (count > MAX_NESTED_PRESET-1)
3401 count = MAX_NESTED_PRESET-1;
3404 dest = ghb_array_value_new(MAX_NESTED_PRESET);
3405 indices = ghb_preset_indices_from_path(presetsPlist, preset, &len);
3410 ptype = ghb_presets_get_type(presetsPlist, indices, len);
3411 if (ptype == PRESETS_CUSTOM)
3413 ghb_array_copy(dest, preset, count-1);
3416 ghb_array_append(dest, ghb_string_value_new(name));
3418 ghb_widget_to_setting(ud->settings, GTK_WIDGET(desc));
3419 if (ghb_settings_get_boolean(ud->settings, "preset_type_folder"))
3421 folder_save(ud, dest);
3425 // Construct the audio settings presets from the current audio list
3426 update_audio_presets(ud);
3427 update_subtitle_presets(ud);
3428 settings_save(ud, dest);
3430 ghb_value_free(dest);
3434 G_MODULE_EXPORT void
3435 preset_type_changed_cb(GtkWidget *widget, signal_user_data_t *ud)
3437 ghb_widget_to_setting(ud->settings, widget);
3440 G_MODULE_EXPORT void
3441 preset_name_changed_cb(GtkWidget *entry, signal_user_data_t *ud)
3444 GValue *preset, *dest;
3447 preset = ghb_settings_get_value (ud->settings, "preset_selection");
3448 name = ghb_widget_string(entry);
3449 dest = ghb_value_dup(preset);
3450 count = ghb_array_len(dest);
3451 ghb_array_replace(dest, count-1, ghb_string_value_new(name));
3452 enforce_preset_type(ud, dest);
3453 ghb_value_free(dest);
3456 G_MODULE_EXPORT void
3457 presets_restore_clicked_cb(GtkWidget *xwidget, signal_user_data_t *ud)
3461 g_debug("presets_restore_clicked_cb ()");
3462 // Reload only the standard presets
3463 ghb_presets_reload(ud);
3464 // Updating the presets list shuffles things around
3465 // need to make sure the proper preset is selected
3466 preset = ghb_settings_get_value (ud->settings, "preset");
3467 ghb_select_preset(ud->builder, preset);
3470 G_MODULE_EXPORT void
3471 presets_remove_clicked_cb(GtkWidget *xwidget, signal_user_data_t *ud)
3473 GtkTreeView *treeview;
3474 GtkTreeSelection *selection;
3475 GtkTreeModel *store;
3478 GtkResponseType response;
3480 g_debug("presets_remove_clicked_cb ()");
3481 treeview = GTK_TREE_VIEW(GHB_WIDGET(ud->builder, "presets_list"));
3482 selection = gtk_tree_view_get_selection (treeview);
3483 if (gtk_tree_selection_get_selected(selection, &store, &iter))
3490 gtk_tree_model_get(store, &iter, 0, &preset, -1);
3491 path = gtk_tree_model_get_path(store, &iter);
3492 indices = gtk_tree_path_get_indices(path);
3493 len = gtk_tree_path_get_depth(path);
3495 folder = ghb_presets_get_folder(presetsPlist, indices, len);
3496 dialog = gtk_message_dialog_new(NULL, GTK_DIALOG_MODAL,
3497 GTK_MESSAGE_QUESTION, GTK_BUTTONS_YES_NO,
3498 "Confirm deletion of %s:\n\n%s",
3499 folder ? "folder" : "preset",
3501 response = gtk_dialog_run(GTK_DIALOG(dialog));
3502 gtk_widget_destroy (dialog);
3503 if (response == GTK_RESPONSE_YES)
3505 GtkTreeIter nextIter = iter;
3506 gboolean valid = TRUE;
3507 if (!gtk_tree_model_iter_next(store, &nextIter))
3509 if (!gtk_tree_model_iter_parent(store, &nextIter, &iter))
3514 // Remove the selected item
3515 // First unselect it so that selecting the new item works properly
3516 gtk_tree_selection_unselect_iter (selection, &iter);
3517 if (ghb_presets_remove(presetsPlist, indices, len))
3520 presets_list_remove(ud, indices, len);
3523 valid = gtk_tree_model_get_iter_first(store, &nextIter);
3526 gtk_tree_path_free(path);
3527 path = gtk_tree_model_get_path(store, &nextIter);
3528 indices = gtk_tree_path_get_indices(path);
3529 len = gtk_tree_path_get_depth(path);
3530 ghb_select_preset2(ud->builder, indices, len);
3534 gtk_tree_path_free(path);
3538 // controls where valid drop locations are
3539 G_MODULE_EXPORT gboolean
3540 presets_drag_motion_cb(
3542 GdkDragContext *ctx,
3546 signal_user_data_t *ud)
3548 GtkTreePath *path = NULL;
3549 GtkTreeViewDropPosition drop_pos;
3553 GtkTreeModel *model;
3554 GtkTreeSelection *select;
3555 gint src_ptype, dst_ptype;
3556 gboolean src_folder, dst_folder;
3558 gint tree_depth, ii;
3561 widget = gtk_drag_get_source_widget(ctx);
3562 if (widget == NULL || widget != GTK_WIDGET(tv))
3565 // Get the type of the object being dragged
3566 srctv = GTK_TREE_VIEW(gtk_drag_get_source_widget(ctx));
3567 select = gtk_tree_view_get_selection (srctv);
3568 gtk_tree_selection_get_selected (select, &model, &iter);
3569 path = gtk_tree_model_get_path (model, &iter);
3570 indices = gtk_tree_path_get_indices(path);
3571 len = gtk_tree_path_get_depth(path);
3573 preset = presets_get_dict(presetsPlist, indices, len);
3574 tree_depth = preset_tree_depth(preset);
3576 src_ptype = ghb_presets_get_type(presetsPlist, indices, len);
3577 src_folder = ghb_presets_get_folder(presetsPlist, indices, len);
3578 gtk_tree_path_free(path);
3580 if (src_folder && tree_depth == 1)
3583 // The rest checks that the destination is a valid position
3585 gtk_tree_view_get_dest_row_at_pos (tv, x, y, &path, &drop_pos);
3588 gdk_drag_status(ctx, 0, time);
3591 // Don't allow repositioning of builtin presets
3592 if (src_ptype != PRESETS_CUSTOM)
3594 gdk_drag_status(ctx, 0, time);
3598 len = gtk_tree_path_get_depth(path);
3599 if (len+tree_depth-1 >= MAX_NESTED_PRESET)
3601 if (drop_pos == GTK_TREE_VIEW_DROP_INTO_OR_BEFORE)
3602 drop_pos = GTK_TREE_VIEW_DROP_BEFORE;
3603 if (drop_pos == GTK_TREE_VIEW_DROP_INTO_OR_AFTER)
3604 drop_pos = GTK_TREE_VIEW_DROP_AFTER;
3606 for (ii = len+tree_depth-1; ii > MAX_NESTED_PRESET; ii--)
3607 gtk_tree_path_up(path);
3608 indices = gtk_tree_path_get_indices(path);
3609 len = gtk_tree_path_get_depth(path);
3610 dst_ptype = ghb_presets_get_type(presetsPlist, indices, len);
3611 dst_folder = ghb_presets_get_folder(presetsPlist, indices, len);
3612 // Don't allow mixing custom presets in the builtins
3613 if (dst_ptype != PRESETS_CUSTOM)
3615 gdk_drag_status(ctx, 0, time);
3619 // Only allow *drop into* for folders
3622 if (drop_pos == GTK_TREE_VIEW_DROP_INTO_OR_BEFORE)
3623 drop_pos = GTK_TREE_VIEW_DROP_BEFORE;
3624 if (drop_pos == GTK_TREE_VIEW_DROP_INTO_OR_AFTER)
3625 drop_pos = GTK_TREE_VIEW_DROP_AFTER;
3628 len = gtk_tree_path_get_depth(path);
3629 gtk_tree_view_set_drag_dest_row(tv, path, drop_pos);
3630 gtk_tree_path_free(path);
3631 gdk_drag_status(ctx, GDK_ACTION_MOVE, time);
3635 G_MODULE_EXPORT void
3637 GtkTreeView *dstwidget,
3640 GtkSelectionData *selection_data,
3641 guint info, guint t,
3642 signal_user_data_t *ud)
3644 GtkTreePath *path = NULL;
3645 GtkTreeViewDropPosition drop_pos;
3646 GtkTreeIter dstiter, srciter;
3647 gint *dst_indices, dst_len, *src_indices, src_len;
3649 gboolean src_folder, dst_folder;
3651 GtkTreeModel *dstmodel = gtk_tree_view_get_model(dstwidget);
3653 g_debug("preset_drag_cb ()");
3654 // This doesn't work here for some reason...
3655 // gtk_tree_view_get_drag_dest_row(dstwidget, &path, &drop_pos);
3656 gtk_tree_view_get_dest_row_at_pos (dstwidget, x, y, &path, &drop_pos);
3657 // This little hack is needed because attempting to drop after
3658 // the last item gives us no path or drop_pos.
3663 n_children = gtk_tree_model_iter_n_children(dstmodel, NULL);
3666 drop_pos = GTK_TREE_VIEW_DROP_AFTER;
3667 path = gtk_tree_path_new_from_indices(n_children-1, -1);
3671 drop_pos = GTK_TREE_VIEW_DROP_BEFORE;
3672 path = gtk_tree_path_new_from_indices(0, -1);
3677 GtkTreeView *srcwidget;
3678 GtkTreeModel *srcmodel;
3679 GtkTreeSelection *select;
3680 GtkTreePath *srcpath = NULL;
3682 gint tree_depth, ii;
3684 srcwidget = GTK_TREE_VIEW(gtk_drag_get_source_widget(dc));
3685 select = gtk_tree_view_get_selection (srcwidget);
3686 gtk_tree_selection_get_selected (select, &srcmodel, &srciter);
3688 srcpath = gtk_tree_model_get_path (srcmodel, &srciter);
3689 src_indices = gtk_tree_path_get_indices(srcpath);
3690 src_len = gtk_tree_path_get_depth(srcpath);
3691 src_ptype = ghb_presets_get_type(presetsPlist, src_indices, src_len);
3692 src_folder = ghb_presets_get_folder(presetsPlist, src_indices, src_len);
3693 preset = ghb_value_dup(
3694 presets_get_dict(presetsPlist, src_indices, src_len));
3695 gtk_tree_path_free(srcpath);
3697 // Don't allow repositioning of builtin presets
3698 if (src_ptype != PRESETS_CUSTOM)
3701 tree_depth = preset_tree_depth(preset);
3702 if (src_folder && tree_depth == 1)
3705 dst_len = gtk_tree_path_get_depth(path);
3706 if (dst_len+tree_depth-1 >= MAX_NESTED_PRESET)
3708 if (drop_pos == GTK_TREE_VIEW_DROP_INTO_OR_BEFORE)
3709 drop_pos = GTK_TREE_VIEW_DROP_BEFORE;
3710 if (drop_pos == GTK_TREE_VIEW_DROP_INTO_OR_AFTER)
3711 drop_pos = GTK_TREE_VIEW_DROP_AFTER;
3714 for (ii = dst_len+tree_depth-1; ii > MAX_NESTED_PRESET; ii--)
3715 gtk_tree_path_up(path);
3716 dst_indices = gtk_tree_path_get_indices(path);
3717 dst_len = gtk_tree_path_get_depth(path);
3718 dst_folder = ghb_presets_get_folder(presetsPlist, dst_indices, dst_len);
3719 // Only allow *drop into* for folders
3722 if (drop_pos == GTK_TREE_VIEW_DROP_INTO_OR_BEFORE)
3723 drop_pos = GTK_TREE_VIEW_DROP_BEFORE;
3724 if (drop_pos == GTK_TREE_VIEW_DROP_INTO_OR_AFTER)
3725 drop_pos = GTK_TREE_VIEW_DROP_AFTER;
3727 if (gtk_tree_model_get_iter (dstmodel, &dstiter, path))
3730 GtkTreePath *dstpath = NULL;
3734 case GTK_TREE_VIEW_DROP_BEFORE:
3735 gtk_tree_store_insert_before(GTK_TREE_STORE (dstmodel),
3736 &iter, NULL, &dstiter);
3739 case GTK_TREE_VIEW_DROP_INTO_OR_BEFORE:
3740 gtk_tree_store_insert(GTK_TREE_STORE (dstmodel),
3741 &iter, &dstiter, 0);
3744 case GTK_TREE_VIEW_DROP_AFTER:
3745 gtk_tree_store_insert_after(GTK_TREE_STORE (dstmodel),
3746 &iter, NULL, &dstiter);
3749 case GTK_TREE_VIEW_DROP_INTO_OR_AFTER:
3750 gtk_tree_store_insert_after(GTK_TREE_STORE (dstmodel),
3751 &iter, &dstiter, 0);
3758 dstpath = gtk_tree_model_get_path (dstmodel, &iter);
3759 dst_indices = gtk_tree_path_get_indices(dstpath);
3760 dst_len = gtk_tree_path_get_depth(dstpath);
3761 ghb_presets_insert(presetsPlist, preset, dst_indices, dst_len);
3762 gtk_tree_path_free(dstpath);
3764 srcpath = gtk_tree_model_get_path (srcmodel, &srciter);
3765 src_indices = gtk_tree_path_get_indices(srcpath);
3766 src_len = gtk_tree_path_get_depth(srcpath);
3767 ghb_presets_remove(presetsPlist, src_indices, src_len);
3768 gtk_tree_path_free(srcpath);
3770 gtk_tree_store_remove (GTK_TREE_STORE (srcmodel), &srciter);
3772 dstpath = gtk_tree_model_get_path (dstmodel, &iter);
3773 dst_indices = gtk_tree_path_get_indices(dstpath);
3774 dst_len = gtk_tree_path_get_depth(dstpath);
3775 presets_list_update_item(ud, dst_indices, dst_len);
3776 gtk_tree_path_free(dstpath);
3780 gtk_tree_path_free(path);
3785 presets_row_expanded_cb(
3786 GtkTreeView *treeview,
3789 signal_user_data_t *ud)
3792 gboolean expanded, folder;
3795 expanded = gtk_tree_view_row_expanded(treeview, path);
3796 indices = gtk_tree_path_get_indices(path);
3797 len = gtk_tree_path_get_depth(path);
3798 dict = presets_get_dict(presetsPlist, indices, len);
3799 if (preset_folder_is_open(dict))
3808 folder = ghb_presets_get_folder(presetsPlist, indices, len);
3811 presets_set_folder_open(expanded, indices, len);
3814 // Collapsing parent folder collapses all children
3817 GValue *presets = NULL;
3818 gint *more_indices, count, ii;
3820 more_indices = g_malloc((len+1)*sizeof(gint));
3821 memcpy(more_indices, indices, len*sizeof(gint));
3823 presets = presets_get_folder(presetsPlist, indices, len);
3824 count = ghb_array_len(presets);
3825 for (ii = 0; ii < count; ii++)
3827 dict = ghb_array_get_nth(presets, ii);
3828 folder = ghb_preset_folder(dict);
3831 more_indices[len] = ii;
3832 presets_set_folder_open(expanded, more_indices, len+1);
3835 g_free(more_indices);
3841 preset_update_title_deps(signal_user_data_t *ud, ghb_title_info_t *tinfo)
3845 ghb_ui_update(ud, "scale_width",
3846 ghb_int64_value(tinfo->width - tinfo->crop[2] - tinfo->crop[3]));
3847 // If anamorphic or keep_aspect, the hight will be automatically calculated
3848 gboolean keep_aspect;
3850 keep_aspect = ghb_settings_get_boolean(ud->settings, "PictureKeepRatio");
3851 pic_par = ghb_settings_combo_int(ud->settings, "PicturePAR");
3852 if (!(keep_aspect || pic_par) || pic_par == 3)
3854 ghb_ui_update(ud, "scale_height",
3855 ghb_int64_value(tinfo->height - tinfo->crop[0] - tinfo->crop[1]));
3858 // Set the limits of cropping. hb_set_anamorphic_size crashes if
3859 // you pass it a cropped width or height == 0.
3861 bound = tinfo->height / 2 - 2;
3862 widget = GHB_WIDGET (ud->builder, "PictureTopCrop");
3863 gtk_spin_button_set_range (GTK_SPIN_BUTTON(widget), 0, bound);
3864 widget = GHB_WIDGET (ud->builder, "PictureBottomCrop");
3865 gtk_spin_button_set_range (GTK_SPIN_BUTTON(widget), 0, bound);
3866 bound = tinfo->width / 2 - 2;
3867 widget = GHB_WIDGET (ud->builder, "PictureLeftCrop");
3868 gtk_spin_button_set_range (GTK_SPIN_BUTTON(widget), 0, bound);
3869 widget = GHB_WIDGET (ud->builder, "PictureRightCrop");
3870 gtk_spin_button_set_range (GTK_SPIN_BUTTON(widget), 0, bound);
3871 if (ghb_settings_get_boolean(ud->settings, "PictureAutoCrop"))
3873 ghb_ui_update(ud, "PictureTopCrop", ghb_int64_value(tinfo->crop[0]));
3874 ghb_ui_update(ud, "PictureBottomCrop", ghb_int64_value(tinfo->crop[1]));
3875 ghb_ui_update(ud, "PictureLeftCrop", ghb_int64_value(tinfo->crop[2]));
3876 ghb_ui_update(ud, "PictureRightCrop", ghb_int64_value(tinfo->crop[3]));
3880 G_MODULE_EXPORT void
3881 presets_list_selection_changed_cb(GtkTreeSelection *selection, signal_user_data_t *ud)
3883 GtkTreeModel *store;
3885 ghb_title_info_t tinfo;
3888 g_debug("presets_list_selection_changed_cb ()");
3889 widget = GHB_WIDGET (ud->builder, "presets_remove");
3890 if (gtk_tree_selection_get_selected(selection, &store, &iter))
3892 GtkTreePath *treepath;
3897 treepath = gtk_tree_model_get_path(store, &iter);
3898 indices = gtk_tree_path_get_indices(treepath);
3899 len = gtk_tree_path_get_depth(treepath);
3901 path = preset_path_from_indices(presetsPlist, indices, len);
3902 ghb_settings_take_value(ud->settings, "preset_selection", path);
3904 folder = ghb_presets_get_folder(presetsPlist, indices, len);
3907 ud->dont_clear_presets = TRUE;
3908 // Temporarily set the video_quality range to (0,100)
3909 // This is needed so the video_quality value does not get
3910 // truncated when set. The range will be readjusted below
3911 GtkWidget *qp = GHB_WIDGET(ud->builder, "VideoQualitySlider");
3912 gtk_range_set_range (GTK_RANGE(qp), 0, 100);
3913 gtk_scale_set_digits(GTK_SCALE(qp), 3);
3914 // Clear the audio list prior to changing the preset. Existing
3915 // audio can cause the container extension to be automatically
3916 // changed when it shouldn't be
3917 ghb_clear_audio_list(ud);
3918 ghb_set_preset_from_indices(ud, indices, len);
3919 gtk_tree_path_free(treepath);
3921 titleindex = ghb_settings_combo_int(ud->settings, "title");
3922 ghb_set_pref_audio(titleindex, ud);
3923 ghb_set_pref_subtitle(titleindex, ud);
3924 ghb_settings_set_boolean(ud->settings, "preset_modified", FALSE);
3925 if (ghb_get_title_info (&tinfo, titleindex))
3927 preset_update_title_deps(ud, &tinfo);
3929 ghb_set_scale (ud, GHB_PIC_KEEP_PAR);
3930 ud->dont_clear_presets = FALSE;
3932 gdouble vqmin, vqmax, step, page;
3936 ghb_vquality_range(ud, &vqmin, &vqmax, &step,
3937 &page, &digits, &inverted);
3938 gtk_range_set_range (GTK_RANGE(qp), vqmin, vqmax);
3939 gtk_range_set_increments (GTK_RANGE(qp), step, page);
3940 gtk_scale_set_digits(GTK_SCALE(qp), digits);
3941 gtk_range_set_inverted (GTK_RANGE(qp), inverted);
3945 GtkWidget *crop_widget;
3946 crop[0] = ghb_settings_get_int(ud->settings, "PictureTopCrop");
3947 crop[1] = ghb_settings_get_int(ud->settings, "PictureBottomCrop");
3948 crop[2] = ghb_settings_get_int(ud->settings, "PictureLeftCrop");
3949 crop[3] = ghb_settings_get_int(ud->settings, "PictureRightCrop");
3950 crop_widget = GHB_WIDGET (ud->builder, "crop_values");
3951 text = g_strdup_printf("%d:%d:%d:%d",
3952 crop[0], crop[1], crop[2], crop[3]);
3953 gtk_label_set_text (GTK_LABEL(crop_widget), text);
3956 gtk_widget_set_sensitive(widget, TRUE);
3960 g_debug("No selection??? Perhaps unselected.");
3961 gtk_widget_set_sensitive(widget, FALSE);
3966 ghb_clear_presets_selection(signal_user_data_t *ud)
3968 GtkTreeView *treeview;
3969 GtkTreeSelection *selection;
3971 if (ud->dont_clear_presets) return;
3972 g_debug("ghb_clear_presets_selection()");
3973 treeview = GTK_TREE_VIEW(GHB_WIDGET(ud->builder, "presets_list"));
3974 selection = gtk_tree_view_get_selection (treeview);
3975 gtk_tree_selection_unselect_all (selection);
3976 ghb_settings_set_boolean(ud->settings, "preset_modified", TRUE);
3979 G_MODULE_EXPORT void
3980 presets_frame_size_allocate_cb(GtkWidget *widget, GtkAllocation *allocation, signal_user_data_t *ud)
3982 GtkTreeView *treeview;
3983 GtkTreeSelection *selection;
3984 GtkTreeModel *store;
3987 treeview = GTK_TREE_VIEW(GHB_WIDGET(ud->builder, "presets_list"));
3988 selection = gtk_tree_view_get_selection(treeview);
3989 if (gtk_tree_selection_get_selected(selection, &store, &iter))
3992 path = gtk_tree_model_get_path (store, &iter);
3993 // Make the parent visible in scroll window if it is not.
3994 gtk_tree_view_scroll_to_cell (treeview, path, NULL, FALSE, 0, 0);
3995 gtk_tree_path_free(path);
3999 G_MODULE_EXPORT void
4000 presets_default_clicked_cb(GtkWidget *xwidget, signal_user_data_t *ud)
4005 g_debug("presets_default_clicked_cb ()");
4006 preset = ghb_settings_get_value(ud->settings, "preset_selection");
4007 indices = ghb_preset_indices_from_path(presetsPlist, preset, &len);
4010 if (!ghb_presets_get_folder(presetsPlist, indices, len))
4012 ghb_presets_list_clear_default(ud);
4013 presets_set_default(indices, len);
4014 ghb_presets_list_default(ud);