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,
1568 5, type == PRESETS_BUILTIN ? 0 : 1,
1575 if (gtk_tree_model_iter_parent(
1576 GTK_TREE_MODEL(store), &ppiter, piter))
1578 path = gtk_tree_model_get_path(GTK_TREE_MODEL(store), &ppiter);
1579 gtk_tree_view_expand_row(treeview, path, FALSE);
1580 gtk_tree_path_free(path);
1582 path = gtk_tree_model_get_path(GTK_TREE_MODEL(store), piter);
1583 gtk_tree_view_expand_row(treeview, path, FALSE);
1584 gtk_tree_path_free(path);
1588 ghb_presets_list_init(ud, more_indices, len+1);
1589 if (preset_folder_is_open(dict))
1595 path = gtk_tree_model_get_path(GTK_TREE_MODEL(store), piter);
1596 gtk_tree_view_expand_row(treeview, path, FALSE);
1597 gtk_tree_path_free(path);
1599 path = gtk_tree_model_get_path(GTK_TREE_MODEL(store), &iter);
1600 gtk_tree_view_expand_row(treeview, path, FALSE);
1601 gtk_tree_path_free(path);
1605 g_free(more_indices);
1609 presets_list_update_item(
1610 signal_user_data_t *ud,
1615 GtkTreeView *treeview;
1616 GtkTreeStore *store;
1618 GtkTreePath *treepath;
1620 const gchar *description;
1622 gboolean def, folder;
1626 g_debug("presets_list_update_item ()");
1627 dict = presets_get_dict(presetsPlist, indices, len);
1630 treeview = GTK_TREE_VIEW(GHB_WIDGET(ud->builder, "presets_list"));
1631 store = GTK_TREE_STORE(gtk_tree_view_get_model(treeview));
1632 treepath = ghb_tree_path_new_from_indices(indices, len);
1633 gtk_tree_model_get_iter(GTK_TREE_MODEL(store), &iter, treepath);
1634 // Additional settings, add row
1635 name = preset_get_name(dict);
1636 def = preset_is_default(dict);
1638 description = ghb_presets_get_description(dict);
1639 type = ghb_preset_type(dict);
1640 folder = ghb_preset_folder(dict);
1641 color = get_preset_color(type, folder);
1642 gtk_tree_store_set(store, &iter, 0, name,
1647 5, type == PRESETS_BUILTIN ? 0 : 1,
1649 if (recurse && folder)
1651 ghb_presets_list_init(ud, indices, len);
1656 presets_list_insert(
1657 signal_user_data_t *ud,
1661 GtkTreeView *treeview;
1662 GtkTreeIter iter, titer, *piter;
1663 GtkTreeStore *store;
1664 const gchar *preset;
1665 const gchar *description;
1667 gboolean def, folder;
1670 GtkTreePath *parent_path;
1674 g_debug("presets_list_insert ()");
1675 treeview = GTK_TREE_VIEW(GHB_WIDGET(ud->builder, "presets_list"));
1676 store = GTK_TREE_STORE(gtk_tree_view_get_model(treeview));
1677 presets = presets_get_folder(presetsPlist, indices, len-1);
1678 if (presets == NULL)
1680 g_warning("Failed to find parent folder while adding child.");
1683 parent_path = ghb_tree_path_new_from_indices(indices, len-1);
1686 gtk_tree_model_get_iter(GTK_TREE_MODEL(store), &titer, parent_path);
1688 gtk_tree_path_free(parent_path);
1694 count = ghb_array_len(presets);
1695 if (indices[len-1] >= count)
1697 // Additional settings, add row
1698 dict = ghb_array_get_nth(presets, indices[len-1]);
1699 preset = preset_get_name(dict);
1700 def = preset_is_default(dict);
1702 description = ghb_presets_get_description(dict);
1703 gtk_tree_store_insert(store, &iter, piter, indices[len-1]);
1704 type = ghb_preset_type(dict);
1705 folder = ghb_preset_folder(dict);
1706 color = get_preset_color(type, folder);
1707 gtk_tree_store_set(store, &iter, 0, preset,
1712 5, type == PRESETS_BUILTIN ? 0 : 1,
1716 ghb_presets_list_init(ud, indices, len);
1721 presets_list_remove(
1722 signal_user_data_t *ud,
1726 GtkTreeView *treeview;
1727 GtkTreePath *treepath;
1729 GtkTreeStore *store;
1731 g_debug("presets_list_remove ()");
1732 treeview = GTK_TREE_VIEW(GHB_WIDGET(ud->builder, "presets_list"));
1733 store = GTK_TREE_STORE(gtk_tree_view_get_model(treeview));
1734 treepath = ghb_tree_path_new_from_indices(indices, len);
1737 if (gtk_tree_model_get_iter(GTK_TREE_MODEL(store), &iter, treepath))
1738 gtk_tree_store_remove(store, &iter);
1739 gtk_tree_path_free(treepath);
1744 remove_std_presets(signal_user_data_t *ud)
1749 count = ghb_array_len(presetsPlist);
1750 for (ii = count-1; ii >= 0; ii--)
1755 dict = ghb_array_get_nth(presetsPlist, ii);
1756 ptype = ghb_value_int(preset_dict_get_value(dict, "Type"));
1757 if (ptype == PRESETS_BUILTIN)
1759 if (ghb_presets_remove(presetsPlist, &indices, 1))
1761 presets_list_remove(ud, &indices, 1);
1768 ghb_save_queue(GValue *queue)
1770 store_plist(queue, "queue");
1776 return load_plist("queue");
1780 ghb_remove_queue_file()
1782 remove_plist("queue");
1791 static value_map_t vcodec_xlat[] =
1793 {"MPEG-4 (FFmpeg)", "ffmpeg"},
1794 {"MPEG-4 (XviD)", "ffmpeg"},
1795 {"H.264 (x264)", "x264"},
1796 {"VP3 (Theora)", "theora"},
1800 static value_map_t acodec_xlat[] =
1802 {"AAC (faac)", "faac"},
1803 {"AAC (CoreAudio)", "faac"},
1804 {"AC3 Passthru", "ac3"},
1805 {"MP3 (lame)", "lame"},
1806 {"Vorbis (vorbis)", "vorbis"},
1810 value_map_t container_xlat[] =
1812 {"MP4 file", "mp4"},
1813 {"M4V file", "mp4"},
1814 {"MKV file", "mkv"},
1815 {"AVI file", "mkv"},
1816 {"OGM file", "mkv"},
1820 value_map_t framerate_xlat[] =
1822 {"Same as source", "source"},
1827 {"23.976", "23.976"},
1834 value_map_t samplerate_xlat[] =
1845 value_map_t mix_xlat[] =
1848 {"Stereo", "stereo"},
1849 {"Dolby Surround", "dpl1"},
1850 {"Dolby Pro Logic II", "dpl2"},
1851 {"6-channel discrete", "6ch"},
1852 {"AC3 Passthru", "none"},
1856 value_map_t deint_xlat[] =
1866 value_map_t denoise_xlat[] =
1876 value_map_t detel_xlat[] =
1884 value_map_t decomb_xlat[] =
1892 extern iso639_lang_t ghb_language_table[];
1895 export_lang_xlat2(GValue *lin_val)
1899 if (lin_val == NULL) return NULL;
1903 str = ghb_value_string(lin_val);
1904 for (ii = 0; ghb_language_table[ii].eng_name; ii++)
1906 if (strcmp(str, ghb_language_table[ii].iso639_2) == 0)
1910 if (ghb_language_table[ii].native_name[0] != 0)
1911 lang = ghb_language_table[ii].native_name;
1913 lang = ghb_language_table[ii].eng_name;
1915 gval = ghb_string_value_new(lang);
1920 g_debug("Can't map language value: (%s)", str);
1926 export_subtitle_xlat2(GValue *lin_val)
1931 if (lin_val == NULL) return NULL;
1932 str = ghb_value_string(lin_val);
1933 if (strcmp(str, "none") == 0)
1935 gval = ghb_string_value_new("None");
1937 else if (strcmp(str, "auto") == 0)
1939 gval = ghb_string_value_new("Autoselect");
1943 gval = export_lang_xlat2(lin_val);
1950 import_lang_xlat2(GValue *mac_val)
1954 if (mac_val == NULL) return NULL;
1958 str = ghb_value_string(mac_val);
1959 for (ii = 0; ghb_language_table[ii].eng_name; ii++)
1961 if ((strcmp(str, ghb_language_table[ii].eng_name) == 0) ||
1962 (strcmp(str, ghb_language_table[ii].native_name) == 0))
1964 gval = ghb_string_value_new(ghb_language_table[ii].iso639_2);
1969 g_debug("Can't map language value: (%s)", str);
1975 import_subtitle_xlat2(GValue *mac_val)
1980 if (mac_val == NULL) return NULL;
1981 str = ghb_value_string(mac_val);
1982 if (strcmp(str, "None") == 0)
1984 gval = ghb_string_value_new("none");
1986 else if (strcmp(str, "Autoselect") == 0)
1988 gval = ghb_string_value_new("auto");
1992 gval = import_lang_xlat2(mac_val);
1999 export_audio_track_xlat2(GValue *lin_val)
2002 GValue *gval = NULL;
2004 if (lin_val == NULL) return NULL;
2005 str = ghb_value_string(lin_val);
2006 if (strcmp(str, "none") == 0)
2008 gval = ghb_int_value_new(1);
2012 gint val = ghb_value_int(lin_val) + 1;
2013 gval = ghb_int_value_new(val);
2020 import_audio_track_xlat2(GValue *mac_val)
2026 if (mac_val == NULL) return NULL;
2027 val = ghb_value_int(mac_val);
2036 str = g_strdup_printf("%d", val);
2037 gval = ghb_string_value_new(str);
2043 export_value_xlat2(value_map_t *value_map, GValue *lin_val, GType mac_type)
2047 if (lin_val == NULL) return NULL;
2052 str = ghb_value_string(lin_val);
2053 for (ii = 0; value_map[ii].mac_val; ii++)
2055 if (strcmp(str, value_map[ii].lin_val) == 0)
2057 sval = ghb_string_value_new(value_map[ii].mac_val);
2059 gval = ghb_value_new(mac_type);
2060 if (!g_value_transform(sval, gval))
2062 g_warning("can't transform");
2063 ghb_value_free(gval);
2064 ghb_value_free(sval);
2067 ghb_value_free(sval);
2071 g_debug("Can't map value: (%s)", str);
2077 export_value_xlat(GValue *dict)
2079 GValue *lin_val, *gval;
2082 key = "VideoEncoder";
2083 lin_val = ghb_dict_lookup(dict, key);
2084 gval = export_value_xlat2(vcodec_xlat, lin_val, G_TYPE_STRING);
2086 ghb_dict_insert(dict, g_strdup(key), gval);
2088 lin_val = ghb_dict_lookup(dict, key);
2089 gval = export_value_xlat2(container_xlat, lin_val, G_TYPE_STRING);
2091 ghb_dict_insert(dict, g_strdup(key), gval);
2092 key = "VideoFramerate";
2093 lin_val = ghb_dict_lookup(dict, key);
2094 gval = export_value_xlat2(framerate_xlat, lin_val, G_TYPE_STRING);
2096 ghb_dict_insert(dict, g_strdup(key), gval);
2097 key = "PictureDetelecine";
2098 lin_val = ghb_dict_lookup(dict, key);
2099 gval = export_value_xlat2(detel_xlat, lin_val, G_TYPE_INT);
2101 ghb_dict_insert(dict, g_strdup(key), gval);
2102 key = "PictureDecomb";
2103 lin_val = ghb_dict_lookup(dict, key);
2104 gval = export_value_xlat2(decomb_xlat, lin_val, G_TYPE_INT);
2106 ghb_dict_insert(dict, g_strdup(key), gval);
2107 key = "PictureDeinterlace";
2108 lin_val = ghb_dict_lookup(dict, key);
2109 gval = export_value_xlat2(deint_xlat, lin_val, G_TYPE_INT);
2111 ghb_dict_insert(dict, g_strdup(key), gval);
2112 key = "PictureDenoise";
2113 lin_val = ghb_dict_lookup(dict, key);
2114 gval = export_value_xlat2(denoise_xlat, lin_val, G_TYPE_INT);
2116 ghb_dict_insert(dict, g_strdup(key), gval);
2122 slist = ghb_dict_lookup(dict, "SubtitleList");
2123 count = ghb_array_len(slist);
2124 for (ii = 0; ii < count; ii++)
2126 sdict = ghb_array_get_nth(slist, ii);
2127 key = "SubtitleLanguage";
2128 lin_val = ghb_dict_lookup(sdict, key);
2129 gval = export_subtitle_xlat2(lin_val);
2131 ghb_dict_insert(sdict, g_strdup(key), gval);
2137 alist = ghb_dict_lookup(dict, "AudioList");
2138 count = ghb_array_len(alist);
2139 for (ii = 0; ii < count; ii++)
2141 adict = ghb_array_get_nth(alist, ii);
2143 lin_val = ghb_dict_lookup(adict, key);
2144 gval = export_audio_track_xlat2(lin_val);
2146 ghb_dict_insert(adict, g_strdup(key), gval);
2147 key = "AudioEncoder";
2148 lin_val = ghb_dict_lookup(adict, key);
2149 gval = export_value_xlat2(acodec_xlat, lin_val, G_TYPE_STRING);
2151 ghb_dict_insert(adict, g_strdup(key), gval);
2152 key = "AudioSamplerate";
2153 lin_val = ghb_dict_lookup(adict, key);
2154 gval = export_value_xlat2(samplerate_xlat, lin_val, G_TYPE_STRING);
2156 ghb_dict_insert(adict, g_strdup(key), gval);
2157 key = "AudioMixdown";
2158 lin_val = ghb_dict_lookup(adict, key);
2159 gval = export_value_xlat2(mix_xlat, lin_val, G_TYPE_STRING);
2161 ghb_dict_insert(adict, g_strdup(key), gval);
2169 value_map_t *value_map,
2173 GValue *gval, *def_val;
2175 if (mac_val == NULL) return NULL;
2176 def_val = ghb_dict_lookup(defaults, key);
2183 str = ghb_value_string(mac_val);
2184 for (ii = 0; value_map[ii].mac_val; ii++)
2186 if (strcmp(str, value_map[ii].mac_val) == 0)
2188 sval = ghb_string_value_new(value_map[ii].lin_val);
2190 gval = ghb_value_new(G_VALUE_TYPE(def_val));
2191 if (!g_value_transform(sval, gval))
2193 g_warning("can't transform");
2194 ghb_value_free(gval);
2195 ghb_value_free(sval);
2198 ghb_value_free(sval);
2210 str = ghb_value_string(mac_val);
2211 for (ii = 0; value_map[ii].mac_val; ii++)
2213 if (strcmp(str, value_map[ii].mac_val) == 0)
2215 sval = ghb_string_value_new(value_map[ii].lin_val);
2217 gval = ghb_value_new(G_VALUE_TYPE(mac_val));
2218 if (!g_value_transform(sval, gval))
2220 g_warning("can't transform");
2221 ghb_value_free(gval);
2222 ghb_value_free(sval);
2225 ghb_value_free(sval);
2235 import_value_xlat(GValue *dict)
2237 GValue *defaults, *mac_val, *gval;
2240 defaults = plist_get_dict(internalPlist, "Presets");
2241 key = "VideoEncoder";
2242 mac_val = ghb_dict_lookup(dict, key);
2243 gval = import_value_xlat2(defaults, vcodec_xlat, key, mac_val);
2245 ghb_dict_insert(dict, g_strdup(key), gval);
2247 mac_val = ghb_dict_lookup(dict, key);
2248 gval = import_value_xlat2(defaults, container_xlat, key, mac_val);
2250 ghb_dict_insert(dict, g_strdup(key), gval);
2251 key = "VideoFramerate";
2252 mac_val = ghb_dict_lookup(dict, key);
2253 gval = import_value_xlat2(defaults, framerate_xlat, key, mac_val);
2255 ghb_dict_insert(dict, g_strdup(key), gval);
2256 key = "PictureDetelecine";
2257 mac_val = ghb_dict_lookup(dict, key);
2258 gval = import_value_xlat2(defaults, detel_xlat, key, mac_val);
2260 ghb_dict_insert(dict, g_strdup(key), gval);
2261 key = "PictureDecomb";
2262 mac_val = ghb_dict_lookup(dict, key);
2263 gval = import_value_xlat2(defaults, decomb_xlat, key, mac_val);
2265 ghb_dict_insert(dict, g_strdup(key), gval);
2266 key = "PictureDeinterlace";
2267 mac_val = ghb_dict_lookup(dict, key);
2268 gval = import_value_xlat2(defaults, deint_xlat, key, mac_val);
2270 ghb_dict_insert(dict, g_strdup(key), gval);
2271 key = "PictureDenoise";
2272 mac_val = ghb_dict_lookup(dict, key);
2273 gval = import_value_xlat2(defaults, denoise_xlat, key, mac_val);
2275 ghb_dict_insert(dict, g_strdup(key), gval);
2284 sdeflist = ghb_dict_lookup(defaults, "SubtitleList");
2287 slist = ghb_dict_lookup(dict, "SubtitleList");
2290 sdefaults = ghb_array_get_nth(sdeflist, 0);
2291 count = ghb_array_len(slist);
2292 for (ii = 0; ii < count; ii++)
2294 sdict = ghb_array_get_nth(slist, ii);
2295 key = "SubtitleLanguage";
2296 mac_val = ghb_dict_lookup(sdict, key);
2297 gval = import_subtitle_xlat2(mac_val);
2299 ghb_dict_insert(sdict, g_strdup(key), gval);
2306 mac_val = ghb_dict_lookup(dict, key);
2307 slist = ghb_array_value_new(8);
2308 ghb_dict_insert(dict, g_strdup("SubtitleList"), slist);
2313 gval = import_subtitle_xlat2(mac_val);
2314 lang = ghb_value_string(gval);
2315 if (lang && strcasecmp(lang, "none") != 0 && !slist)
2317 sdict = ghb_dict_value_new();
2318 ghb_array_append(slist, sdict);
2319 ghb_dict_insert(sdict, g_strdup("SubtitleLanguage"), gval);
2320 gval = ghb_dict_lookup(dict, "SubtitlesForced");
2323 ghb_dict_insert(sdict, g_strdup("SubtitleForced"),
2324 ghb_value_dup(gval));
2328 ghb_dict_insert(sdict, g_strdup("SubtitleForced"),
2329 ghb_boolean_value_new(FALSE));
2331 ghb_dict_insert(sdict, g_strdup("SubtitleBurned"),
2332 ghb_boolean_value_new(TRUE));
2333 ghb_dict_insert(sdict, g_strdup("SubtitleDefaultTrack"),
2334 ghb_boolean_value_new(FALSE));
2338 ghb_value_free(gval);
2345 ghb_dict_remove(dict, "Subtitles");
2346 ghb_dict_remove(dict, "SubtitlesForced");
2354 adeflist = ghb_dict_lookup(defaults, "AudioList");
2357 adefaults = ghb_array_get_nth(adeflist, 0);
2358 alist = ghb_dict_lookup(dict, "AudioList");
2359 count = ghb_array_len(alist);
2360 for (ii = 0; ii < count; ii++)
2362 adict = ghb_array_get_nth(alist, ii);
2364 mac_val = ghb_dict_lookup(adict, key);
2365 gval = import_audio_track_xlat2(mac_val);
2367 ghb_dict_insert(adict, g_strdup(key), gval);
2368 key = "AudioEncoder";
2369 mac_val = ghb_dict_lookup(adict, key);
2370 gval = import_value_xlat2(adefaults, acodec_xlat, key, mac_val);
2372 ghb_dict_insert(adict, g_strdup(key), gval);
2373 key = "AudioSamplerate";
2374 mac_val = ghb_dict_lookup(adict, key);
2375 gval = import_value_xlat2(adefaults, samplerate_xlat, key, mac_val);
2377 ghb_dict_insert(adict, g_strdup(key), gval);
2378 key = "AudioMixdown";
2379 mac_val = ghb_dict_lookup(adict, key);
2380 gval = import_value_xlat2(adefaults, mix_xlat, key, mac_val);
2382 ghb_dict_insert(adict, g_strdup(key), gval);
2384 mac_val = ghb_dict_lookup(adict, "AudioTrackDRCSlider");
2385 if (mac_val != NULL)
2388 drc = ghb_value_double(mac_val);
2389 if (drc < 1.0 && drc > 0.0)
2391 ghb_dict_insert(adict, g_strdup("AudioTrackDRCSlider"),
2392 ghb_double_value_new(0.0));
2400 import_xlat_preset(GValue *dict)
2407 g_debug("import_xlat_preset ()");
2408 uses_max = ghb_value_boolean(
2409 preset_dict_get_value(dict, "UsesMaxPictureSettings"));
2410 uses_pic = ghb_value_int(
2411 preset_dict_get_value(dict, "UsesPictureSettings"));
2412 par = ghb_value_int(preset_dict_get_value(dict, "PicturePAR"));
2413 vqtype = ghb_value_int(preset_dict_get_value(dict, "VideoQualityType"));
2415 if (uses_max || uses_pic == 2)
2417 ghb_dict_insert(dict, g_strdup("autoscale"),
2418 ghb_boolean_value_new(TRUE));
2424 if (ghb_dict_lookup(dict, "PictureModulus") == NULL)
2425 ghb_dict_insert(dict, g_strdup("PictureModulus"),
2426 ghb_int_value_new(16));
2430 ghb_dict_insert(dict, g_strdup("PictureModulus"),
2431 ghb_int_value_new(1));
2435 if (ghb_dict_lookup(dict, "PictureModulus") == NULL)
2436 ghb_dict_insert(dict, g_strdup("PictureModulus"),
2437 ghb_int_value_new(16));
2441 if (ghb_dict_lookup(dict, "PictureModulus") == NULL)
2442 ghb_dict_insert(dict, g_strdup("PictureModulus"),
2443 ghb_int_value_new(16));
2446 // VideoQualityType/0/1/2 - vquality_type_/target/bitrate/constant
2451 ghb_dict_insert(dict, g_strdup("vquality_type_target"),
2452 ghb_boolean_value_new(TRUE));
2453 ghb_dict_insert(dict, g_strdup("vquality_type_bitrate"),
2454 ghb_boolean_value_new(FALSE));
2455 ghb_dict_insert(dict, g_strdup("vquality_type_constant"),
2456 ghb_boolean_value_new(FALSE));
2460 ghb_dict_insert(dict, g_strdup("vquality_type_target"),
2461 ghb_boolean_value_new(FALSE));
2462 ghb_dict_insert(dict, g_strdup("vquality_type_bitrate"),
2463 ghb_boolean_value_new(TRUE));
2464 ghb_dict_insert(dict, g_strdup("vquality_type_constant"),
2465 ghb_boolean_value_new(FALSE));
2469 ghb_dict_insert(dict, g_strdup("vquality_type_target"),
2470 ghb_boolean_value_new(FALSE));
2471 ghb_dict_insert(dict, g_strdup("vquality_type_bitrate"),
2472 ghb_boolean_value_new(FALSE));
2473 ghb_dict_insert(dict, g_strdup("vquality_type_constant"),
2474 ghb_boolean_value_new(TRUE));
2478 ghb_dict_insert(dict, g_strdup("vquality_type_target"),
2479 ghb_boolean_value_new(FALSE));
2480 ghb_dict_insert(dict, g_strdup("vquality_type_bitrate"),
2481 ghb_boolean_value_new(FALSE));
2482 ghb_dict_insert(dict, g_strdup("vquality_type_constant"),
2483 ghb_boolean_value_new(TRUE));
2486 import_value_xlat(dict);
2491 vquality = ghb_value_double(preset_dict_get_value(dict, "VideoQualitySlider"));
2496 gval = preset_dict_get_value(dict, "VideoEncoder");
2497 vcodec = ghb_lookup_combo_int("VideoEncoder", gval);
2500 case HB_VCODEC_X264:
2502 vquality = 51. - vquality * 51.;
2505 case HB_VCODEC_FFMPEG:
2507 vquality = 31. - vquality * 30.;
2510 case HB_VCODEC_THEORA:
2512 vquality = vquality * 63.;
2520 ghb_dict_insert(dict, g_strdup("VideoQualitySlider"),
2521 ghb_double_value_new(vquality));
2526 import_xlat_presets(GValue *presets)
2532 g_debug("import_xlat_presets ()");
2533 if (presets == NULL) return;
2534 count = ghb_array_len(presets);
2535 for (ii = 0; ii < count; ii++)
2537 dict = ghb_array_get_nth(presets, ii);
2538 folder = ghb_value_boolean(preset_dict_get_value(dict, "Folder"));
2543 nested = ghb_dict_lookup(dict, "ChildrenArray");
2544 import_xlat_presets(nested);
2548 import_xlat_preset(dict);
2554 export_xlat_preset(GValue *dict)
2556 gboolean autoscale, target, br, constant;
2558 g_debug("export_xlat_prest ()");
2559 autoscale = ghb_value_boolean(preset_dict_get_value(dict, "autoscale"));
2560 target = ghb_value_boolean(
2561 preset_dict_get_value(dict, "vquality_type_target"));
2562 br = ghb_value_boolean(
2563 preset_dict_get_value(dict, "vquality_type_bitrate"));
2564 constant = ghb_value_boolean(
2565 preset_dict_get_value(dict, "vquality_type_constant"));
2568 ghb_dict_insert(dict, g_strdup("UsesPictureSettings"),
2569 ghb_int_value_new(2));
2571 ghb_dict_insert(dict, g_strdup("UsesPictureSettings"),
2572 ghb_int_value_new(1));
2574 // VideoQualityType/0/1/2 - vquality_type_/target/bitrate/constant
2577 ghb_dict_insert(dict, g_strdup("VideoQualityType"),
2578 ghb_int_value_new(0));
2582 ghb_dict_insert(dict, g_strdup("VideoQualityType"),
2583 ghb_int_value_new(1));
2587 ghb_dict_insert(dict, g_strdup("VideoQualityType"),
2588 ghb_int_value_new(2));
2591 GValue *alist, *adict;
2594 alist = ghb_dict_lookup(dict, "AudioList");
2595 count = ghb_array_len(alist);
2596 for (ii = 0; ii < count; ii++)
2600 adict = ghb_array_get_nth(alist, ii);
2601 drc = ghb_value_double(
2602 preset_dict_get_value(adict, "AudioTrackDRCSlider"));
2603 if (drc < 1.0 && drc > 0.0)
2605 ghb_dict_insert(adict, g_strdup("AudioTrackDRCSlider"),
2606 ghb_double_value_new(0.0));
2610 ghb_dict_remove(dict, "UsesMaxPictureSettings");
2611 ghb_dict_remove(dict, "autoscale");
2612 ghb_dict_remove(dict, "vquality_type_target");
2613 ghb_dict_remove(dict, "vquality_type_bitrate");
2614 ghb_dict_remove(dict, "vquality_type_constant");
2615 export_value_xlat(dict);
2619 export_xlat_presets(GValue *presets)
2625 if (presets == NULL) return;
2626 count = ghb_array_len(presets);
2627 for (ii = 0; ii < count; ii++)
2629 dict = ghb_array_get_nth(presets, ii);
2630 folder = ghb_value_boolean(preset_dict_get_value(dict, "Folder"));
2635 nested = ghb_dict_lookup(dict, "ChildrenArray");
2636 export_xlat_presets(nested);
2640 export_xlat_preset(dict);
2645 static guint prefs_timeout_id = 0;
2648 delayed_store_prefs(gpointer data)
2650 store_plist(prefsPlist, "preferences");
2651 prefs_timeout_id = 0;
2660 export = ghb_value_dup(presetsPlist);
2661 export_xlat_presets(export);
2662 store_plist(export, "presets");
2663 ghb_value_free(export);
2669 if (prefs_timeout_id != 0)
2674 mc = g_main_context_default();
2675 source = g_main_context_find_source_by_id(mc, prefs_timeout_id);
2677 g_source_destroy(source);
2679 prefs_timeout_id = g_timeout_add_seconds(1, (GSourceFunc)delayed_store_prefs, NULL);
2683 ghb_presets_reload(signal_user_data_t *ud)
2685 GValue *std_presets;
2689 g_debug("ghb_presets_reload()\n");
2690 std_presets = ghb_resource_get("standard-presets");
2691 if (std_presets == NULL) return;
2693 remove_std_presets(ud);
2694 indices = presets_find_default(presetsPlist, &len);
2697 presets_clear_default(std_presets);
2700 // Merge the keyfile contents into our presets
2701 count = ghb_array_len(std_presets);
2702 for (ii = count-1; ii >= 0; ii--)
2708 std_dict = ghb_array_get_nth(std_presets, ii);
2709 copy_dict = ghb_value_dup(std_dict);
2710 ghb_dict_insert(copy_dict, g_strdup("PresetBuildNumber"),
2711 ghb_int64_value_new(hb_get_build(NULL)));
2712 ghb_presets_insert(presetsPlist, copy_dict, &indices, 1);
2713 presets_list_insert(ud, &indices, 1);
2715 import_xlat_presets(presetsPlist);
2724 count = ghb_array_len(presetsPlist);
2725 for (ii = count-1; ii >= 0; ii--)
2730 dict = ghb_array_get_nth(presetsPlist, ii);
2731 type = ghb_dict_lookup(dict, "Type");
2739 replace_standard_presets()
2741 GValue *std_presets;
2745 count = ghb_array_len(presetsPlist);
2746 for (ii = count-1; ii >= 0; ii--)
2751 dict = ghb_array_get_nth(presetsPlist, ii);
2752 ptype = ghb_value_int(preset_dict_get_value(dict, "Type"));
2753 if (ptype == PRESETS_BUILTIN)
2756 ghb_presets_remove(presetsPlist, &indices, 1);
2760 std_presets = ghb_resource_get("standard-presets");
2761 if (std_presets == NULL) return;
2763 indices = presets_find_default(presetsPlist, &len);
2766 presets_clear_default(std_presets);
2769 // Merge the keyfile contents into our presets
2770 count = ghb_array_len(std_presets);
2771 for (ii = count-1; ii >= 0; ii--)
2777 std_dict = ghb_array_get_nth(std_presets, ii);
2778 copy_dict = ghb_value_dup(std_dict);
2779 ghb_dict_insert(copy_dict, g_strdup("PresetBuildNumber"),
2780 ghb_int64_value_new(hb_get_build(NULL)));
2781 ghb_presets_insert(presetsPlist, copy_dict, &indices, 1);
2783 import_xlat_presets(presetsPlist);
2788 update_standard_presets(signal_user_data_t *ud)
2792 count = ghb_array_len(presetsPlist);
2793 for (ii = count-1; ii >= 0; ii--)
2800 dict = ghb_array_get_nth(presetsPlist, ii);
2801 gval = ghb_dict_lookup(dict, "Type");
2804 // Old preset that doesn't have a Type
2805 replace_standard_presets();
2809 type = ghb_value_int(gval);
2812 gval = ghb_dict_lookup(dict, "PresetBuildNumber");
2815 // Old preset that doesn't have a build number
2816 replace_standard_presets();
2820 build = ghb_value_int64(gval);
2821 if (build != hb_get_build(NULL))
2823 // Build number does not match
2824 replace_standard_presets();
2833 ghb_presets_load(signal_user_data_t *ud)
2835 presetsPlist = load_plist("presets");
2836 if (presetsPlist == NULL)
2838 presetsPlist = ghb_value_dup(ghb_resource_get("standard-presets"));
2839 import_xlat_presets(presetsPlist);
2842 else if (G_VALUE_TYPE(presetsPlist) == ghb_dict_get_type())
2843 { // Presets is older dictionary format. Convert to array
2844 ghb_value_free(presetsPlist);
2845 presetsPlist = ghb_value_dup(ghb_resource_get("standard-presets"));
2846 import_xlat_presets(presetsPlist);
2849 else if (check_old_presets())
2851 ghb_value_free(presetsPlist);
2852 presetsPlist = ghb_value_dup(ghb_resource_get("standard-presets"));
2853 import_xlat_presets(presetsPlist);
2856 update_standard_presets(ud);
2857 import_xlat_presets(presetsPlist);
2861 settings_save(signal_user_data_t *ud, const GValue *path)
2863 GValue *dict, *internal;
2864 GHashTableIter iter;
2868 gint *indices, len, count;
2869 gint *def_indices, def_len;
2871 gboolean replace = FALSE;
2873 g_debug("settings_save");
2874 if (internalPlist == NULL) return;
2875 count = ghb_array_len(path);
2876 name = g_value_get_string(ghb_array_get_nth(path, count-1));
2877 indices = ghb_preset_indices_from_path(presetsPlist, path, &len);
2880 if (ghb_presets_get_folder(presetsPlist, indices, len))
2883 message = g_strdup_printf(
2884 "%s: Folder already exists.\n"
2885 "You can not replace it with a preset.",
2887 ghb_message_dialog(GTK_MESSAGE_ERROR, message, "Cancel", NULL);
2891 dict = ghb_dict_value_new();
2892 ghb_presets_replace(presetsPlist, dict, indices, len);
2897 indices = presets_find_pos(path, PRESETS_CUSTOM, &len);
2900 dict = ghb_dict_value_new();
2901 ghb_presets_insert(presetsPlist, dict, indices, len);
2905 g_warning("failed to find insert path");
2909 current_preset = dict;
2910 autoscale = ghb_settings_get_boolean(ud->settings, "autoscale");
2911 ghb_settings_set_int64(ud->settings, "Type", PRESETS_CUSTOM);
2912 ghb_settings_set_int64(ud->settings, "PresetBuildNumber", hb_get_build(NULL));
2914 internal = plist_get_dict(internalPlist, "Presets");
2915 ghb_dict_iter_init(&iter, internal);
2916 // middle (void*) cast prevents gcc warning "defreferencing type-punned
2917 // pointer will break strict-aliasing rules"
2918 while (g_hash_table_iter_next(
2919 &iter, (gpointer*)(void*)&key, (gpointer*)(void*)&value))
2927 if (strcmp(key, "PictureWidth") == 0)
2929 key2 = "scale_width";
2931 else if (strcmp(key, "PictureHeight") == 0)
2933 key2 = "scale_height";
2936 gval = ghb_settings_get_value(ud->settings, key2);
2941 ghb_dict_insert(dict, g_strdup(key), ghb_value_dup(gval));
2943 internal = plist_get_dict(internalPlist, "XlatPresets");
2944 ghb_dict_iter_init(&iter, internal);
2945 // middle (void*) cast prevents gcc warning "defreferencing type-punned
2946 // pointer will break strict-aliasing rules"
2947 while (g_hash_table_iter_next(
2948 &iter, (gpointer*)(void*)&key, (gpointer*)(void*)&value))
2952 gval = ghb_settings_get_value(ud->settings, key);
2957 ghb_dict_insert(dict, g_strdup(key), ghb_value_dup(gval));
2959 ghb_dict_insert(dict, g_strdup("PresetName"), ghb_string_value_new(name));
2962 def_indices = presets_find_default(presetsPlist, &def_len);
2963 if (def_indices != NULL &&
2964 preset_path_cmp(indices, len, def_indices, def_len) != 0)
2966 ghb_dict_insert(dict, g_strdup("Default"),
2967 ghb_boolean_value_new(FALSE));
2969 presets_list_update_item(ud, indices, len, FALSE);
2973 ghb_dict_insert(dict, g_strdup("Default"),
2974 ghb_boolean_value_new(FALSE));
2975 presets_list_insert(ud, indices, len);
2978 ud->dont_clear_presets = TRUE;
2979 // Make the new preset the selected item
2980 ghb_select_preset2(ud->builder, indices, len);
2982 ud->dont_clear_presets = FALSE;
2987 folder_save(signal_user_data_t *ud, const GValue *path)
2989 GValue *dict, *folder;
2990 gint *indices, len, count;
2993 count = ghb_array_len(path);
2994 name = g_value_get_string(ghb_array_get_nth(path, count-1));
2995 indices = ghb_preset_indices_from_path(presetsPlist, path, &len);
2998 if (!ghb_presets_get_folder(presetsPlist, indices, len))
3001 message = g_strdup_printf(
3002 "%s: Preset already exists.\n"
3003 "You can not replace it with a folder.",
3005 ghb_message_dialog(GTK_MESSAGE_ERROR, message, "Cancel", NULL);
3010 // Already exists, update its description
3011 dict = presets_get_dict(presetsPlist, indices, len);
3012 ghb_dict_insert(dict, g_strdup("PresetDescription"),
3013 ghb_value_dup(preset_dict_get_value(
3014 ud->settings, "PresetDescription")));
3015 presets_list_update_item(ud, indices, len, FALSE);
3022 indices = presets_find_pos(path, PRESETS_CUSTOM, &len);
3025 dict = ghb_dict_value_new();
3026 ghb_presets_insert(presetsPlist, dict, indices, len);
3030 g_warning("failed to find insert path");
3034 ghb_dict_insert(dict, g_strdup("PresetDescription"),
3035 ghb_value_dup(preset_dict_get_value(
3036 ud->settings, "PresetDescription")));
3037 ghb_dict_insert(dict, g_strdup("PresetName"), ghb_string_value_new(name));
3038 folder = ghb_array_value_new(8);
3039 ghb_dict_insert(dict, g_strdup("ChildrenArray"), folder);
3040 ghb_dict_insert(dict, g_strdup("Type"),
3041 ghb_int64_value_new(PRESETS_CUSTOM));
3042 ghb_dict_insert(dict, g_strdup("Folder"), ghb_boolean_value_new(TRUE));
3044 presets_list_insert(ud, indices, len);
3051 ghb_presets_list_default(signal_user_data_t *ud)
3053 GtkTreeView *treeview;
3054 GtkTreePath *treepath;
3056 GtkTreeStore *store;
3059 g_debug("ghb_presets_list_default ()");
3060 treeview = GTK_TREE_VIEW(GHB_WIDGET(ud->builder, "presets_list"));
3061 store = GTK_TREE_STORE(gtk_tree_view_get_model(treeview));
3062 indices = presets_find_default(presetsPlist, &len);
3063 if (indices == NULL) return;
3064 treepath = ghb_tree_path_new_from_indices(indices, len);
3067 if (gtk_tree_model_get_iter(GTK_TREE_MODEL(store), &iter, treepath))
3069 gtk_tree_store_set(store, &iter,
3074 gtk_tree_path_free(treepath);
3080 ghb_presets_list_clear_default(signal_user_data_t *ud)
3082 GtkTreeView *treeview;
3083 GtkTreePath *treepath;
3085 GtkTreeStore *store;
3088 g_debug("ghb_presets_list_clear_default ()");
3089 treeview = GTK_TREE_VIEW(GHB_WIDGET(ud->builder, "presets_list"));
3090 store = GTK_TREE_STORE(gtk_tree_view_get_model(treeview));
3091 indices = presets_find_default(presetsPlist, &len);
3092 if (indices == NULL) return;
3093 treepath = ghb_tree_path_new_from_indices(indices, len);
3096 if (gtk_tree_model_get_iter(GTK_TREE_MODEL(store), &iter, treepath))
3098 gtk_tree_store_set(store, &iter,
3103 gtk_tree_path_free(treepath);
3109 update_audio_presets(signal_user_data_t *ud)
3111 g_debug("update_audio_presets");
3112 const GValue *audio_list;
3114 audio_list = ghb_settings_get_value(ud->settings, "audio_list");
3115 ghb_settings_set_value(ud->settings, "AudioList", audio_list);
3119 update_subtitle_presets(signal_user_data_t *ud)
3121 g_debug("update_subtitle_presets");
3122 const GValue *subtitle_list, *subtitle;
3123 GValue *slist, *dict;
3124 gint count, ii, source;
3126 subtitle_list = ghb_settings_get_value(ud->settings, "subtitle_list");
3127 slist = ghb_array_value_new(8);
3128 count = ghb_array_len(subtitle_list);
3129 for (ii = 0; ii < count; ii++)
3131 subtitle = ghb_array_get_nth(subtitle_list, ii);
3132 source = ghb_settings_get_int(subtitle, "SubtitleSource");
3133 if (source != SRTSUB)
3135 dict = ghb_value_dup(subtitle);
3136 ghb_array_append(slist, dict);
3139 ghb_settings_take_value(ud->settings, "SubtitleList", slist);
3142 G_MODULE_EXPORT void
3143 presets_menu_clicked_cb(GtkWidget *xwidget, signal_user_data_t *ud)
3147 menu = GTK_MENU(GHB_WIDGET(ud->builder, "presets_menu"));
3148 gtk_menu_popup(menu, NULL, NULL, NULL, NULL, 1,
3149 gtk_get_current_event_time());
3152 G_MODULE_EXPORT void
3153 preset_import_clicked_cb(GtkWidget *xwidget, signal_user_data_t *ud)
3156 GtkResponseType response;
3159 GtkFileFilter *filter;
3161 g_debug("preset_import_clicked_cb ()");
3163 dialog = gtk_file_chooser_dialog_new("Import Preset", NULL,
3164 GTK_FILE_CHOOSER_ACTION_OPEN,
3165 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
3166 GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
3169 filter = gtk_file_filter_new();
3170 gtk_file_filter_set_name(filter, "All (*)");
3171 gtk_file_filter_add_pattern(filter, "*");
3172 gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(dialog), filter);
3174 filter = gtk_file_filter_new();
3175 gtk_file_filter_set_name(filter, "Presets (*.plist)");
3176 gtk_file_filter_add_pattern(filter, "*.plist");
3177 gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(dialog), filter);
3178 gtk_file_chooser_set_filter(GTK_FILE_CHOOSER(dialog), filter);
3180 exportDir = ghb_settings_get_string(ud->settings, "ExportDirectory");
3181 if (exportDir == NULL || exportDir[0] == '\0')
3183 exportDir = g_strdup(".");
3185 gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(dialog), exportDir);
3188 response = gtk_dialog_run(GTK_DIALOG(dialog));
3189 gtk_widget_hide(dialog);
3190 if (response == GTK_RESPONSE_ACCEPT)
3192 GValue *dict, *array;
3196 filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog));
3198 // import the preset
3199 if (!g_file_test(filename, G_FILE_TEST_IS_REGULAR))
3201 gtk_widget_destroy(dialog);
3205 array = ghb_plist_parse_file(filename);
3208 import_xlat_presets(array);
3209 presets_clear_default(array);
3210 presets_customize(array);
3212 count = ghb_array_len(array);
3213 for (ii = 0; ii < count; ii++)
3215 GValue *path, *name;
3219 dict = ghb_array_get_nth(array, ii);
3220 path = ghb_array_value_new(1);
3221 name = ghb_value_dup(ghb_dict_lookup(dict, "PresetName"));
3222 ghb_array_append(path, name);
3223 indices = ghb_preset_indices_from_path(presetsPlist, path, &len);
3224 // Modify the preset name till we make it unique
3225 while (indices != NULL)
3227 gchar *str = ghb_value_string(name);
3229 ghb_value_free(path);
3232 str = g_strdup_printf("%s %d", str, index);
3233 path = ghb_array_value_new(1);
3234 name = ghb_string_value_new(str);
3235 ghb_array_append(path, name);
3239 indices = ghb_preset_indices_from_path(presetsPlist, path, &len);
3241 ghb_dict_insert(dict, g_strdup("PresetName"), ghb_value_dup(name));
3242 indices = presets_find_pos(path, PRESETS_CUSTOM, &len);
3243 ghb_presets_insert(presetsPlist, ghb_value_dup(dict), indices, len);
3244 presets_list_insert(ud, indices, len);
3245 ghb_value_free(path);
3247 ghb_value_free(array);
3249 exportDir = ghb_settings_get_string(ud->settings, "ExportDirectory");
3250 dir = g_path_get_dirname(filename);
3251 if (strcmp(dir, exportDir) != 0)
3253 ghb_settings_set_string(ud->settings, "ExportDirectory", dir);
3254 ghb_pref_save(ud->settings, "ExportDirectory");
3259 gtk_widget_destroy(dialog);
3262 G_MODULE_EXPORT void
3263 preset_export_clicked_cb(GtkWidget *xwidget, signal_user_data_t *ud)
3266 GtkResponseType response;
3268 const gchar *name = "";
3269 gint count, *indices, len;
3273 g_debug("preset_export_clicked_cb ()");
3274 preset = ghb_settings_get_value (ud->settings, "preset_selection");
3278 count = ghb_array_len(preset);
3282 name = g_value_get_string(ghb_array_get_nth(preset, count-1));
3284 dialog = gtk_file_chooser_dialog_new("Export Preset", NULL,
3285 GTK_FILE_CHOOSER_ACTION_SAVE,
3286 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
3287 GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT,
3290 exportDir = ghb_settings_get_string(ud->settings, "ExportDirectory");
3291 if (exportDir == NULL || exportDir[0] == '\0')
3293 exportDir = g_strdup(".");
3295 filename = g_strdup_printf("%s.plist", name);
3296 gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(dialog), exportDir);
3297 gtk_file_chooser_set_current_name(GTK_FILE_CHOOSER(dialog), filename);
3301 indices = ghb_preset_indices_from_path(presetsPlist, preset, &len);
3302 if (indices == NULL)
3305 response = gtk_dialog_run(GTK_DIALOG(dialog));
3306 gtk_widget_hide(dialog);
3307 if (response == GTK_RESPONSE_ACCEPT)
3309 GValue *export, *dict, *array;
3313 filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog));
3315 // export the preset
3316 dict = presets_get_dict(presetsPlist, indices, len);
3318 export = ghb_value_dup(dict);
3319 array = ghb_array_value_new(1);
3320 ghb_array_append(array, export);
3321 presets_clear_default(array);
3322 presets_customize(array);
3323 export_xlat_presets(array);
3325 file = g_fopen(filename, "w");
3328 ghb_plist_write(file, array);
3331 ghb_value_free(array);
3333 exportDir = ghb_settings_get_string(ud->settings, "ExportDirectory");
3334 dir = g_path_get_dirname(filename);
3335 if (strcmp(dir, exportDir) != 0)
3337 ghb_settings_set_string(ud->settings, "ExportDirectory", dir);
3338 ghb_pref_save(ud->settings, "ExportDirectory");
3344 gtk_widget_destroy(dialog);
3348 G_MODULE_EXPORT void
3349 presets_new_folder_clicked_cb(GtkWidget *xwidget, signal_user_data_t *ud)
3354 GtkResponseType response;
3355 GValue *preset, *dict;
3356 const gchar *name = "";
3357 const gchar *description = "";
3358 gint count, *indices, len;
3360 g_debug("presets_save_clicked_cb ()");
3361 preset = ghb_settings_get_value (ud->settings, "preset_selection");
3363 count = ghb_array_len(preset);
3365 name = g_value_get_string(ghb_array_get_nth(preset, count-1));
3369 indices = ghb_preset_indices_from_path(presetsPlist, preset, &len);
3370 dict = presets_get_dict(presetsPlist, indices, len);
3373 description = g_value_get_string(
3374 ghb_dict_lookup(dict, "PresetDescription"));
3375 ghb_ui_update(ud, "PresetDescription", ghb_string_value(description));
3378 desc = GTK_TEXT_VIEW(GHB_WIDGET(ud->builder, "PresetDescription"));
3379 dialog = GHB_WIDGET(ud->builder, "preset_save_dialog");
3380 entry = GTK_ENTRY(GHB_WIDGET(ud->builder, "PresetName"));
3381 gtk_entry_set_text(entry, name);
3382 response = gtk_dialog_run(GTK_DIALOG(dialog));
3383 gtk_widget_hide(dialog);
3384 if (response == GTK_RESPONSE_OK)
3387 const gchar *name = gtk_entry_get_text(entry);
3390 if (count > MAX_NESTED_PRESET-1)
3391 count = MAX_NESTED_PRESET-1;
3393 dest = ghb_array_value_new(MAX_NESTED_PRESET);
3394 if (indices != NULL)
3398 ptype = ghb_presets_get_type(presetsPlist, indices, len);
3399 if (ptype == PRESETS_CUSTOM)
3401 ghb_array_copy(dest, preset, count-1);
3404 ghb_array_append(dest, ghb_string_value_new(name));
3405 ghb_widget_to_setting(ud->settings, GTK_WIDGET(desc));
3406 folder_save(ud, dest);
3407 ghb_value_free(dest);
3409 if (indices != NULL)
3413 G_MODULE_EXPORT void
3414 presets_save_clicked_cb(GtkWidget *xwidget, signal_user_data_t *ud)
3419 GtkResponseType response;
3421 const gchar *name = "";
3422 gint count, *indices, len;
3424 g_debug("presets_save_clicked_cb ()");
3425 preset = ghb_settings_get_value (ud->settings, "preset_selection");
3427 count = ghb_array_len(preset);
3429 name = g_value_get_string(ghb_array_get_nth(preset, count-1));
3433 desc = GTK_TEXT_VIEW(GHB_WIDGET(ud->builder, "PresetDescription"));
3434 dialog = GHB_WIDGET(ud->builder, "preset_save_dialog");
3435 entry = GTK_ENTRY(GHB_WIDGET(ud->builder, "PresetName"));
3436 gtk_entry_set_text(entry, name);
3437 response = gtk_dialog_run(GTK_DIALOG(dialog));
3438 gtk_widget_hide(dialog);
3439 if (response == GTK_RESPONSE_OK)
3442 const gchar *name = gtk_entry_get_text(entry);
3445 dest = ghb_array_value_new(MAX_NESTED_PRESET);
3446 indices = ghb_preset_indices_from_path(presetsPlist, preset, &len);
3451 ptype = ghb_presets_get_type(presetsPlist, indices, len);
3452 if (ptype == PRESETS_CUSTOM)
3454 ghb_array_copy(dest, preset, count-1);
3458 ghb_array_append(dest, ghb_string_value_new(name));
3460 ghb_widget_to_setting(ud->settings, GTK_WIDGET(desc));
3462 // Construct the audio settings presets from the current audio list
3463 update_audio_presets(ud);
3464 update_subtitle_presets(ud);
3465 settings_save(ud, dest);
3466 ghb_value_free(dest);
3470 G_MODULE_EXPORT void
3471 preset_type_changed_cb(GtkWidget *widget, signal_user_data_t *ud)
3473 ghb_widget_to_setting(ud->settings, widget);
3476 G_MODULE_EXPORT void
3477 presets_restore_clicked_cb(GtkWidget *xwidget, signal_user_data_t *ud)
3481 g_debug("presets_restore_clicked_cb ()");
3482 // Reload only the standard presets
3483 ghb_presets_reload(ud);
3484 // Updating the presets list shuffles things around
3485 // need to make sure the proper preset is selected
3486 preset = ghb_settings_get_value (ud->settings, "preset");
3487 ghb_select_preset(ud->builder, preset);
3490 G_MODULE_EXPORT void
3491 presets_remove_clicked_cb(GtkWidget *xwidget, signal_user_data_t *ud)
3493 GtkTreeView *treeview;
3494 GtkTreeSelection *selection;
3495 GtkTreeModel *store;
3498 GtkResponseType response;
3500 g_debug("presets_remove_clicked_cb ()");
3501 treeview = GTK_TREE_VIEW(GHB_WIDGET(ud->builder, "presets_list"));
3502 selection = gtk_tree_view_get_selection (treeview);
3503 if (gtk_tree_selection_get_selected(selection, &store, &iter))
3510 gtk_tree_model_get(store, &iter, 0, &preset, -1);
3511 path = gtk_tree_model_get_path(store, &iter);
3512 indices = gtk_tree_path_get_indices(path);
3513 len = gtk_tree_path_get_depth(path);
3515 folder = ghb_presets_get_folder(presetsPlist, indices, len);
3516 dialog = gtk_message_dialog_new(NULL, GTK_DIALOG_MODAL,
3517 GTK_MESSAGE_QUESTION, GTK_BUTTONS_YES_NO,
3518 "Confirm deletion of %s:\n\n%s",
3519 folder ? "folder" : "preset",
3521 response = gtk_dialog_run(GTK_DIALOG(dialog));
3522 gtk_widget_destroy (dialog);
3523 if (response == GTK_RESPONSE_YES)
3525 GtkTreeIter nextIter = iter;
3526 gboolean valid = TRUE;
3527 if (!gtk_tree_model_iter_next(store, &nextIter))
3529 if (!gtk_tree_model_iter_parent(store, &nextIter, &iter))
3534 // Remove the selected item
3535 // First unselect it so that selecting the new item works properly
3536 gtk_tree_selection_unselect_iter (selection, &iter);
3537 if (ghb_presets_remove(presetsPlist, indices, len))
3540 presets_list_remove(ud, indices, len);
3543 valid = gtk_tree_model_get_iter_first(store, &nextIter);
3546 gtk_tree_path_free(path);
3547 path = gtk_tree_model_get_path(store, &nextIter);
3548 indices = gtk_tree_path_get_indices(path);
3549 len = gtk_tree_path_get_depth(path);
3550 ghb_select_preset2(ud->builder, indices, len);
3554 gtk_tree_path_free(path);
3558 // controls where valid drop locations are
3559 G_MODULE_EXPORT gboolean
3560 presets_drag_motion_cb(
3562 GdkDragContext *ctx,
3566 signal_user_data_t *ud)
3568 GtkTreePath *path = NULL;
3569 GtkTreeViewDropPosition drop_pos;
3573 GtkTreeModel *model;
3574 GtkTreeSelection *select;
3575 gint src_ptype, dst_ptype;
3576 gboolean src_folder, dst_folder;
3578 gint tree_depth, ii;
3581 widget = gtk_drag_get_source_widget(ctx);
3582 if (widget == NULL || widget != GTK_WIDGET(tv))
3585 // Get the type of the object being dragged
3586 srctv = GTK_TREE_VIEW(gtk_drag_get_source_widget(ctx));
3587 select = gtk_tree_view_get_selection (srctv);
3588 gtk_tree_selection_get_selected (select, &model, &iter);
3589 path = gtk_tree_model_get_path (model, &iter);
3590 indices = gtk_tree_path_get_indices(path);
3591 len = gtk_tree_path_get_depth(path);
3593 preset = presets_get_dict(presetsPlist, indices, len);
3594 tree_depth = preset_tree_depth(preset);
3596 src_ptype = ghb_presets_get_type(presetsPlist, indices, len);
3597 src_folder = ghb_presets_get_folder(presetsPlist, indices, len);
3598 gtk_tree_path_free(path);
3600 if (src_folder && tree_depth == 1)
3603 // The rest checks that the destination is a valid position
3605 gtk_tree_view_get_dest_row_at_pos (tv, x, y, &path, &drop_pos);
3608 gdk_drag_status(ctx, 0, time);
3611 // Don't allow repositioning of builtin presets
3612 if (src_ptype != PRESETS_CUSTOM)
3614 gdk_drag_status(ctx, 0, time);
3618 len = gtk_tree_path_get_depth(path);
3619 if (len+tree_depth-1 >= MAX_NESTED_PRESET)
3621 if (drop_pos == GTK_TREE_VIEW_DROP_INTO_OR_BEFORE)
3622 drop_pos = GTK_TREE_VIEW_DROP_BEFORE;
3623 if (drop_pos == GTK_TREE_VIEW_DROP_INTO_OR_AFTER)
3624 drop_pos = GTK_TREE_VIEW_DROP_AFTER;
3626 for (ii = len+tree_depth-1; ii > MAX_NESTED_PRESET; ii--)
3627 gtk_tree_path_up(path);
3628 indices = gtk_tree_path_get_indices(path);
3629 len = gtk_tree_path_get_depth(path);
3630 dst_ptype = ghb_presets_get_type(presetsPlist, indices, len);
3631 dst_folder = ghb_presets_get_folder(presetsPlist, indices, len);
3632 // Don't allow mixing custom presets in the builtins
3633 if (dst_ptype != PRESETS_CUSTOM)
3635 gdk_drag_status(ctx, 0, time);
3639 // Only allow *drop into* for folders
3642 if (drop_pos == GTK_TREE_VIEW_DROP_INTO_OR_BEFORE)
3643 drop_pos = GTK_TREE_VIEW_DROP_BEFORE;
3644 if (drop_pos == GTK_TREE_VIEW_DROP_INTO_OR_AFTER)
3645 drop_pos = GTK_TREE_VIEW_DROP_AFTER;
3648 len = gtk_tree_path_get_depth(path);
3649 gtk_tree_view_set_drag_dest_row(tv, path, drop_pos);
3650 gtk_tree_path_free(path);
3651 gdk_drag_status(ctx, GDK_ACTION_MOVE, time);
3655 G_MODULE_EXPORT void
3657 GtkTreeView *dstwidget,
3660 GtkSelectionData *selection_data,
3661 guint info, guint t,
3662 signal_user_data_t *ud)
3664 GtkTreePath *path = NULL;
3665 GtkTreeViewDropPosition drop_pos;
3666 GtkTreeIter dstiter, srciter;
3667 gint *dst_indices, dst_len, *src_indices, src_len;
3669 gboolean src_folder, dst_folder;
3671 GtkTreeModel *dstmodel = gtk_tree_view_get_model(dstwidget);
3673 g_debug("preset_drag_cb ()");
3674 // This doesn't work here for some reason...
3675 // gtk_tree_view_get_drag_dest_row(dstwidget, &path, &drop_pos);
3676 gtk_tree_view_get_dest_row_at_pos (dstwidget, x, y, &path, &drop_pos);
3677 // This little hack is needed because attempting to drop after
3678 // the last item gives us no path or drop_pos.
3683 n_children = gtk_tree_model_iter_n_children(dstmodel, NULL);
3686 drop_pos = GTK_TREE_VIEW_DROP_AFTER;
3687 path = gtk_tree_path_new_from_indices(n_children-1, -1);
3691 drop_pos = GTK_TREE_VIEW_DROP_BEFORE;
3692 path = gtk_tree_path_new_from_indices(0, -1);
3697 GtkTreeView *srcwidget;
3698 GtkTreeModel *srcmodel;
3699 GtkTreeSelection *select;
3700 GtkTreePath *srcpath = NULL;
3702 gint tree_depth, ii;
3704 srcwidget = GTK_TREE_VIEW(gtk_drag_get_source_widget(dc));
3705 select = gtk_tree_view_get_selection (srcwidget);
3706 gtk_tree_selection_get_selected (select, &srcmodel, &srciter);
3708 srcpath = gtk_tree_model_get_path (srcmodel, &srciter);
3709 src_indices = gtk_tree_path_get_indices(srcpath);
3710 src_len = gtk_tree_path_get_depth(srcpath);
3711 src_ptype = ghb_presets_get_type(presetsPlist, src_indices, src_len);
3712 src_folder = ghb_presets_get_folder(presetsPlist, src_indices, src_len);
3713 preset = ghb_value_dup(
3714 presets_get_dict(presetsPlist, src_indices, src_len));
3715 gtk_tree_path_free(srcpath);
3717 // Don't allow repositioning of builtin presets
3718 if (src_ptype != PRESETS_CUSTOM)
3721 tree_depth = preset_tree_depth(preset);
3722 if (src_folder && tree_depth == 1)
3725 dst_len = gtk_tree_path_get_depth(path);
3726 if (dst_len+tree_depth-1 >= MAX_NESTED_PRESET)
3728 if (drop_pos == GTK_TREE_VIEW_DROP_INTO_OR_BEFORE)
3729 drop_pos = GTK_TREE_VIEW_DROP_BEFORE;
3730 if (drop_pos == GTK_TREE_VIEW_DROP_INTO_OR_AFTER)
3731 drop_pos = GTK_TREE_VIEW_DROP_AFTER;
3734 for (ii = dst_len+tree_depth-1; ii > MAX_NESTED_PRESET; ii--)
3735 gtk_tree_path_up(path);
3736 dst_indices = gtk_tree_path_get_indices(path);
3737 dst_len = gtk_tree_path_get_depth(path);
3738 dst_folder = ghb_presets_get_folder(presetsPlist, dst_indices, dst_len);
3739 // Only allow *drop into* for folders
3742 if (drop_pos == GTK_TREE_VIEW_DROP_INTO_OR_BEFORE)
3743 drop_pos = GTK_TREE_VIEW_DROP_BEFORE;
3744 if (drop_pos == GTK_TREE_VIEW_DROP_INTO_OR_AFTER)
3745 drop_pos = GTK_TREE_VIEW_DROP_AFTER;
3747 if (gtk_tree_model_get_iter (dstmodel, &dstiter, path))
3750 GtkTreePath *dstpath = NULL;
3754 case GTK_TREE_VIEW_DROP_BEFORE:
3755 gtk_tree_store_insert_before(GTK_TREE_STORE (dstmodel),
3756 &iter, NULL, &dstiter);
3759 case GTK_TREE_VIEW_DROP_INTO_OR_BEFORE:
3760 gtk_tree_store_insert(GTK_TREE_STORE (dstmodel),
3761 &iter, &dstiter, 0);
3764 case GTK_TREE_VIEW_DROP_AFTER:
3765 gtk_tree_store_insert_after(GTK_TREE_STORE (dstmodel),
3766 &iter, NULL, &dstiter);
3769 case GTK_TREE_VIEW_DROP_INTO_OR_AFTER:
3770 gtk_tree_store_insert_after(GTK_TREE_STORE (dstmodel),
3771 &iter, &dstiter, 0);
3778 dstpath = gtk_tree_model_get_path (dstmodel, &iter);
3779 dst_indices = gtk_tree_path_get_indices(dstpath);
3780 dst_len = gtk_tree_path_get_depth(dstpath);
3781 ghb_presets_insert(presetsPlist, preset, dst_indices, dst_len);
3782 gtk_tree_path_free(dstpath);
3784 srcpath = gtk_tree_model_get_path (srcmodel, &srciter);
3785 src_indices = gtk_tree_path_get_indices(srcpath);
3786 src_len = gtk_tree_path_get_depth(srcpath);
3787 ghb_presets_remove(presetsPlist, src_indices, src_len);
3788 gtk_tree_path_free(srcpath);
3790 gtk_tree_store_remove (GTK_TREE_STORE (srcmodel), &srciter);
3792 dstpath = gtk_tree_model_get_path (dstmodel, &iter);
3793 dst_indices = gtk_tree_path_get_indices(dstpath);
3794 dst_len = gtk_tree_path_get_depth(dstpath);
3795 presets_list_update_item(ud, dst_indices, dst_len, TRUE);
3796 gtk_tree_path_free(dstpath);
3800 gtk_tree_path_free(path);
3805 presets_row_expanded_cb(
3806 GtkTreeView *treeview,
3809 signal_user_data_t *ud)
3812 gboolean expanded, folder;
3815 expanded = gtk_tree_view_row_expanded(treeview, path);
3816 indices = gtk_tree_path_get_indices(path);
3817 len = gtk_tree_path_get_depth(path);
3818 dict = presets_get_dict(presetsPlist, indices, len);
3819 if (preset_folder_is_open(dict))
3828 folder = ghb_presets_get_folder(presetsPlist, indices, len);
3831 presets_set_folder_open(expanded, indices, len);
3834 // Collapsing parent folder collapses all children
3837 GValue *presets = NULL;
3838 gint *more_indices, count, ii;
3840 more_indices = g_malloc((len+1)*sizeof(gint));
3841 memcpy(more_indices, indices, len*sizeof(gint));
3843 presets = presets_get_folder(presetsPlist, indices, len);
3844 count = ghb_array_len(presets);
3845 for (ii = 0; ii < count; ii++)
3847 dict = ghb_array_get_nth(presets, ii);
3848 folder = ghb_preset_folder(dict);
3851 more_indices[len] = ii;
3852 presets_set_folder_open(expanded, more_indices, len+1);
3855 g_free(more_indices);
3861 preset_update_title_deps(signal_user_data_t *ud, ghb_title_info_t *tinfo)
3865 ghb_ui_update(ud, "scale_width",
3866 ghb_int64_value(tinfo->width - tinfo->crop[2] - tinfo->crop[3]));
3867 // If anamorphic or keep_aspect, the hight will be automatically calculated
3868 gboolean keep_aspect;
3870 keep_aspect = ghb_settings_get_boolean(ud->settings, "PictureKeepRatio");
3871 pic_par = ghb_settings_combo_int(ud->settings, "PicturePAR");
3872 if (!(keep_aspect || pic_par) || pic_par == 3)
3874 ghb_ui_update(ud, "scale_height",
3875 ghb_int64_value(tinfo->height - tinfo->crop[0] - tinfo->crop[1]));
3878 // Set the limits of cropping. hb_set_anamorphic_size crashes if
3879 // you pass it a cropped width or height == 0.
3881 bound = tinfo->height / 2 - 2;
3882 widget = GHB_WIDGET (ud->builder, "PictureTopCrop");
3883 gtk_spin_button_set_range (GTK_SPIN_BUTTON(widget), 0, bound);
3884 widget = GHB_WIDGET (ud->builder, "PictureBottomCrop");
3885 gtk_spin_button_set_range (GTK_SPIN_BUTTON(widget), 0, bound);
3886 bound = tinfo->width / 2 - 2;
3887 widget = GHB_WIDGET (ud->builder, "PictureLeftCrop");
3888 gtk_spin_button_set_range (GTK_SPIN_BUTTON(widget), 0, bound);
3889 widget = GHB_WIDGET (ud->builder, "PictureRightCrop");
3890 gtk_spin_button_set_range (GTK_SPIN_BUTTON(widget), 0, bound);
3891 if (ghb_settings_get_boolean(ud->settings, "PictureAutoCrop"))
3893 ghb_ui_update(ud, "PictureTopCrop", ghb_int64_value(tinfo->crop[0]));
3894 ghb_ui_update(ud, "PictureBottomCrop", ghb_int64_value(tinfo->crop[1]));
3895 ghb_ui_update(ud, "PictureLeftCrop", ghb_int64_value(tinfo->crop[2]));
3896 ghb_ui_update(ud, "PictureRightCrop", ghb_int64_value(tinfo->crop[3]));
3900 G_MODULE_EXPORT void
3901 presets_list_selection_changed_cb(GtkTreeSelection *selection, signal_user_data_t *ud)
3903 GtkTreeModel *store;
3905 ghb_title_info_t tinfo;
3908 g_debug("presets_list_selection_changed_cb ()");
3909 widget = GHB_WIDGET (ud->builder, "presets_remove");
3910 if (gtk_tree_selection_get_selected(selection, &store, &iter))
3912 GtkTreePath *treepath;
3917 treepath = gtk_tree_model_get_path(store, &iter);
3918 indices = gtk_tree_path_get_indices(treepath);
3919 len = gtk_tree_path_get_depth(treepath);
3921 path = preset_path_from_indices(presetsPlist, indices, len);
3922 ghb_settings_take_value(ud->settings, "preset_selection", path);
3924 folder = ghb_presets_get_folder(presetsPlist, indices, len);
3927 ud->dont_clear_presets = TRUE;
3928 // Temporarily set the video_quality range to (0,100)
3929 // This is needed so the video_quality value does not get
3930 // truncated when set. The range will be readjusted below
3931 GtkWidget *qp = GHB_WIDGET(ud->builder, "VideoQualitySlider");
3932 gtk_range_set_range (GTK_RANGE(qp), 0, 100);
3933 gtk_scale_set_digits(GTK_SCALE(qp), 3);
3934 // Clear the audio list prior to changing the preset. Existing
3935 // audio can cause the container extension to be automatically
3936 // changed when it shouldn't be
3937 ghb_clear_audio_list(ud);
3938 ghb_set_preset_from_indices(ud, indices, len);
3939 gtk_tree_path_free(treepath);
3941 titleindex = ghb_settings_combo_int(ud->settings, "title");
3942 ghb_set_pref_audio(titleindex, ud);
3943 ghb_set_pref_subtitle(titleindex, ud);
3944 ghb_settings_set_boolean(ud->settings, "preset_modified", FALSE);
3945 if (ghb_get_title_info (&tinfo, titleindex))
3947 preset_update_title_deps(ud, &tinfo);
3949 ghb_set_scale (ud, GHB_PIC_KEEP_PAR);
3950 ud->dont_clear_presets = FALSE;
3952 gdouble vqmin, vqmax, step, page;
3956 ghb_vquality_range(ud, &vqmin, &vqmax, &step,
3957 &page, &digits, &inverted);
3958 gtk_range_set_range (GTK_RANGE(qp), vqmin, vqmax);
3959 gtk_range_set_increments (GTK_RANGE(qp), step, page);
3960 gtk_scale_set_digits(GTK_SCALE(qp), digits);
3961 gtk_range_set_inverted (GTK_RANGE(qp), inverted);
3965 GtkWidget *crop_widget;
3966 crop[0] = ghb_settings_get_int(ud->settings, "PictureTopCrop");
3967 crop[1] = ghb_settings_get_int(ud->settings, "PictureBottomCrop");
3968 crop[2] = ghb_settings_get_int(ud->settings, "PictureLeftCrop");
3969 crop[3] = ghb_settings_get_int(ud->settings, "PictureRightCrop");
3970 crop_widget = GHB_WIDGET (ud->builder, "crop_values");
3971 text = g_strdup_printf("%d:%d:%d:%d",
3972 crop[0], crop[1], crop[2], crop[3]);
3973 gtk_label_set_text (GTK_LABEL(crop_widget), text);
3976 gtk_widget_set_sensitive(widget, TRUE);
3980 g_debug("No selection??? Perhaps unselected.");
3981 gtk_widget_set_sensitive(widget, FALSE);
3986 ghb_clear_presets_selection(signal_user_data_t *ud)
3988 GtkTreeView *treeview;
3989 GtkTreeSelection *selection;
3991 if (ud->dont_clear_presets) return;
3992 g_debug("ghb_clear_presets_selection()");
3993 treeview = GTK_TREE_VIEW(GHB_WIDGET(ud->builder, "presets_list"));
3994 selection = gtk_tree_view_get_selection (treeview);
3995 gtk_tree_selection_unselect_all (selection);
3996 ghb_settings_set_boolean(ud->settings, "preset_modified", TRUE);
3999 G_MODULE_EXPORT void
4000 presets_frame_size_allocate_cb(GtkWidget *widget, GtkAllocation *allocation, signal_user_data_t *ud)
4002 GtkTreeView *treeview;
4003 GtkTreeSelection *selection;
4004 GtkTreeModel *store;
4007 treeview = GTK_TREE_VIEW(GHB_WIDGET(ud->builder, "presets_list"));
4008 selection = gtk_tree_view_get_selection(treeview);
4009 if (gtk_tree_selection_get_selected(selection, &store, &iter))
4012 path = gtk_tree_model_get_path (store, &iter);
4013 // Make the parent visible in scroll window if it is not.
4014 gtk_tree_view_scroll_to_cell (treeview, path, NULL, FALSE, 0, 0);
4015 gtk_tree_path_free(path);
4019 G_MODULE_EXPORT void
4020 presets_default_clicked_cb(GtkWidget *xwidget, signal_user_data_t *ud)
4025 g_debug("presets_default_clicked_cb ()");
4026 preset = ghb_settings_get_value(ud->settings, "preset_selection");
4027 indices = ghb_preset_indices_from_path(presetsPlist, preset, &len);
4030 if (!ghb_presets_get_folder(presetsPlist, indices, len))
4032 ghb_presets_list_clear_default(ud);
4033 presets_set_default(indices, len);
4034 ghb_presets_list_default(ud);
4040 G_MODULE_EXPORT void
4042 GtkCellRendererText *cell,
4045 signal_user_data_t *ud)
4047 GtkTreePath *treepath;
4048 GtkTreeStore *store;
4049 GtkTreeView *treeview;
4051 gint *indices, len, count;
4053 GValue *preset, *dest;
4055 g_debug("preset_edited_cb ()");
4056 g_debug("path (%s)", path);
4057 g_debug("text (%s)", text);
4059 preset = ghb_settings_get_value (ud->settings, "preset_selection");
4060 dest = ghb_array_value_new(MAX_NESTED_PRESET);
4061 count = ghb_array_len(preset);
4062 ghb_array_copy(dest, preset, count-1);
4063 ghb_array_append(dest, ghb_string_value_new(text));
4064 indices = ghb_preset_indices_from_path(presetsPlist, dest, &len);
4065 ghb_value_free(dest);
4066 if (indices != NULL)
4073 treeview = GTK_TREE_VIEW(GHB_WIDGET(ud->builder, "presets_list"));
4074 store = GTK_TREE_STORE(gtk_tree_view_get_model(treeview));
4075 treepath = gtk_tree_path_new_from_string (path);
4076 indices = gtk_tree_path_get_indices(treepath);
4077 len = gtk_tree_path_get_depth(treepath);
4078 gtk_tree_model_get_iter(GTK_TREE_MODEL(store), &iter, treepath);
4079 gtk_tree_store_set(store, &iter, 0, text, -1);
4081 dict = presets_get_dict(presetsPlist, indices, len);
4082 ghb_dict_insert(dict, g_strdup("PresetName"), ghb_string_value_new(text));
4084 gtk_tree_path_free (treepath);