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)
1908 gval = ghb_string_value_new(ghb_language_table[ii].eng_name);
1913 g_debug("Can't map language value: (%s)", str);
1919 export_subtitle_xlat2(GValue *lin_val)
1924 if (lin_val == NULL) return NULL;
1925 str = ghb_value_string(lin_val);
1926 if (strcmp(str, "none") == 0)
1928 gval = ghb_string_value_new("None");
1930 else if (strcmp(str, "auto") == 0)
1932 gval = ghb_string_value_new("Autoselect");
1936 gval = export_lang_xlat2(lin_val);
1943 import_lang_xlat2(GValue *mac_val)
1947 if (mac_val == NULL) return NULL;
1951 str = ghb_value_string(mac_val);
1952 for (ii = 0; ghb_language_table[ii].eng_name; ii++)
1954 if (strcmp(str, ghb_language_table[ii].eng_name) == 0)
1956 gval = ghb_string_value_new(ghb_language_table[ii].iso639_2);
1961 g_debug("Can't map language value: (%s)", str);
1967 import_subtitle_xlat2(GValue *mac_val)
1972 if (mac_val == NULL) return NULL;
1973 str = ghb_value_string(mac_val);
1974 if (strcmp(str, "None") == 0)
1976 gval = ghb_string_value_new("none");
1978 else if (strcmp(str, "Autoselect") == 0)
1980 gval = ghb_string_value_new("auto");
1984 gval = import_lang_xlat2(mac_val);
1991 export_audio_track_xlat2(GValue *lin_val)
1994 GValue *gval = NULL;
1996 if (lin_val == NULL) return NULL;
1997 str = ghb_value_string(lin_val);
1998 if (strcmp(str, "none") == 0)
2000 gval = ghb_int_value_new(1);
2004 gint val = ghb_value_int(lin_val) + 1;
2005 gval = ghb_int_value_new(val);
2012 import_audio_track_xlat2(GValue *mac_val)
2018 if (mac_val == NULL) return NULL;
2019 val = ghb_value_int(mac_val);
2028 str = g_strdup_printf("%d", val);
2029 gval = ghb_string_value_new(str);
2035 export_value_xlat2(value_map_t *value_map, GValue *lin_val, GType mac_type)
2039 if (lin_val == NULL) return NULL;
2044 str = ghb_value_string(lin_val);
2045 for (ii = 0; value_map[ii].mac_val; ii++)
2047 if (strcmp(str, value_map[ii].lin_val) == 0)
2049 sval = ghb_string_value_new(value_map[ii].mac_val);
2051 gval = ghb_value_new(mac_type);
2052 if (!g_value_transform(sval, gval))
2054 g_warning("can't transform");
2055 ghb_value_free(gval);
2056 ghb_value_free(sval);
2059 ghb_value_free(sval);
2063 g_debug("Can't map value: (%s)", str);
2069 export_value_xlat(GValue *dict)
2071 GValue *lin_val, *gval;
2074 key = "VideoEncoder";
2075 lin_val = ghb_dict_lookup(dict, key);
2076 gval = export_value_xlat2(vcodec_xlat, lin_val, G_TYPE_STRING);
2078 ghb_dict_insert(dict, g_strdup(key), gval);
2080 lin_val = ghb_dict_lookup(dict, key);
2081 gval = export_value_xlat2(container_xlat, lin_val, G_TYPE_STRING);
2083 ghb_dict_insert(dict, g_strdup(key), gval);
2084 key = "VideoFramerate";
2085 lin_val = ghb_dict_lookup(dict, key);
2086 gval = export_value_xlat2(framerate_xlat, lin_val, G_TYPE_STRING);
2088 ghb_dict_insert(dict, g_strdup(key), gval);
2089 key = "PictureDetelecine";
2090 lin_val = ghb_dict_lookup(dict, key);
2091 gval = export_value_xlat2(detel_xlat, lin_val, G_TYPE_INT);
2093 ghb_dict_insert(dict, g_strdup(key), gval);
2094 key = "PictureDecomb";
2095 lin_val = ghb_dict_lookup(dict, key);
2096 gval = export_value_xlat2(decomb_xlat, lin_val, G_TYPE_INT);
2098 ghb_dict_insert(dict, g_strdup(key), gval);
2099 key = "PictureDeinterlace";
2100 lin_val = ghb_dict_lookup(dict, key);
2101 gval = export_value_xlat2(deint_xlat, lin_val, G_TYPE_INT);
2103 ghb_dict_insert(dict, g_strdup(key), gval);
2104 key = "PictureDenoise";
2105 lin_val = ghb_dict_lookup(dict, key);
2106 gval = export_value_xlat2(denoise_xlat, lin_val, G_TYPE_INT);
2108 ghb_dict_insert(dict, g_strdup(key), gval);
2114 slist = ghb_dict_lookup(dict, "SubtitleList");
2115 count = ghb_array_len(slist);
2116 for (ii = 0; ii < count; ii++)
2118 sdict = ghb_array_get_nth(slist, ii);
2119 key = "SubtitleLanguage";
2120 lin_val = ghb_dict_lookup(sdict, key);
2121 gval = export_subtitle_xlat2(lin_val);
2123 ghb_dict_insert(sdict, g_strdup(key), gval);
2129 alist = ghb_dict_lookup(dict, "AudioList");
2130 count = ghb_array_len(alist);
2131 for (ii = 0; ii < count; ii++)
2133 adict = ghb_array_get_nth(alist, ii);
2135 lin_val = ghb_dict_lookup(adict, key);
2136 gval = export_audio_track_xlat2(lin_val);
2138 ghb_dict_insert(adict, g_strdup(key), gval);
2139 key = "AudioEncoder";
2140 lin_val = ghb_dict_lookup(adict, key);
2141 gval = export_value_xlat2(acodec_xlat, lin_val, G_TYPE_STRING);
2143 ghb_dict_insert(adict, g_strdup(key), gval);
2144 key = "AudioSamplerate";
2145 lin_val = ghb_dict_lookup(adict, key);
2146 gval = export_value_xlat2(samplerate_xlat, lin_val, G_TYPE_STRING);
2148 ghb_dict_insert(adict, g_strdup(key), gval);
2149 key = "AudioMixdown";
2150 lin_val = ghb_dict_lookup(adict, key);
2151 gval = export_value_xlat2(mix_xlat, lin_val, G_TYPE_STRING);
2153 ghb_dict_insert(adict, g_strdup(key), gval);
2161 value_map_t *value_map,
2165 GValue *gval, *def_val;
2167 if (mac_val == NULL) return NULL;
2168 def_val = ghb_dict_lookup(defaults, key);
2175 str = ghb_value_string(mac_val);
2176 for (ii = 0; value_map[ii].mac_val; ii++)
2178 if (strcmp(str, value_map[ii].mac_val) == 0)
2180 sval = ghb_string_value_new(value_map[ii].lin_val);
2182 gval = ghb_value_new(G_VALUE_TYPE(def_val));
2183 if (!g_value_transform(sval, gval))
2185 g_warning("can't transform");
2186 ghb_value_free(gval);
2187 ghb_value_free(sval);
2190 ghb_value_free(sval);
2202 str = ghb_value_string(mac_val);
2203 for (ii = 0; value_map[ii].mac_val; ii++)
2205 if (strcmp(str, value_map[ii].mac_val) == 0)
2207 sval = ghb_string_value_new(value_map[ii].lin_val);
2209 gval = ghb_value_new(G_VALUE_TYPE(mac_val));
2210 if (!g_value_transform(sval, gval))
2212 g_warning("can't transform");
2213 ghb_value_free(gval);
2214 ghb_value_free(sval);
2217 ghb_value_free(sval);
2227 import_value_xlat(GValue *dict)
2229 GValue *defaults, *mac_val, *gval;
2232 defaults = plist_get_dict(internalPlist, "Presets");
2233 key = "VideoEncoder";
2234 mac_val = ghb_dict_lookup(dict, key);
2235 gval = import_value_xlat2(defaults, vcodec_xlat, key, mac_val);
2237 ghb_dict_insert(dict, g_strdup(key), gval);
2239 mac_val = ghb_dict_lookup(dict, key);
2240 gval = import_value_xlat2(defaults, container_xlat, key, mac_val);
2242 ghb_dict_insert(dict, g_strdup(key), gval);
2243 key = "VideoFramerate";
2244 mac_val = ghb_dict_lookup(dict, key);
2245 gval = import_value_xlat2(defaults, framerate_xlat, key, mac_val);
2247 ghb_dict_insert(dict, g_strdup(key), gval);
2248 key = "PictureDetelecine";
2249 mac_val = ghb_dict_lookup(dict, key);
2250 gval = import_value_xlat2(defaults, detel_xlat, key, mac_val);
2252 ghb_dict_insert(dict, g_strdup(key), gval);
2253 key = "PictureDecomb";
2254 mac_val = ghb_dict_lookup(dict, key);
2255 gval = import_value_xlat2(defaults, decomb_xlat, key, mac_val);
2257 ghb_dict_insert(dict, g_strdup(key), gval);
2258 key = "PictureDeinterlace";
2259 mac_val = ghb_dict_lookup(dict, key);
2260 gval = import_value_xlat2(defaults, deint_xlat, key, mac_val);
2262 ghb_dict_insert(dict, g_strdup(key), gval);
2263 key = "PictureDenoise";
2264 mac_val = ghb_dict_lookup(dict, key);
2265 gval = import_value_xlat2(defaults, denoise_xlat, key, mac_val);
2267 ghb_dict_insert(dict, g_strdup(key), gval);
2276 sdeflist = ghb_dict_lookup(defaults, "SubtitleList");
2279 slist = ghb_dict_lookup(dict, "SubtitleList");
2282 sdefaults = ghb_array_get_nth(sdeflist, 0);
2283 count = ghb_array_len(slist);
2284 for (ii = 0; ii < count; ii++)
2286 sdict = ghb_array_get_nth(slist, ii);
2287 key = "SubtitleLanguage";
2288 mac_val = ghb_dict_lookup(sdict, key);
2289 gval = import_subtitle_xlat2(mac_val);
2291 ghb_dict_insert(sdict, g_strdup(key), gval);
2298 mac_val = ghb_dict_lookup(dict, key);
2299 slist = ghb_array_value_new(8);
2300 ghb_dict_insert(dict, g_strdup("SubtitleList"), slist);
2305 gval = import_subtitle_xlat2(mac_val);
2306 lang = ghb_value_string(gval);
2307 if (lang && strcasecmp(lang, "none") != 0 && !slist)
2309 sdict = ghb_dict_value_new();
2310 ghb_array_append(slist, sdict);
2311 ghb_dict_insert(sdict, g_strdup("SubtitleLanguage"), gval);
2312 gval = ghb_dict_lookup(dict, "SubtitlesForced");
2315 ghb_dict_insert(sdict, g_strdup("SubtitleForced"),
2316 ghb_value_dup(gval));
2320 ghb_dict_insert(sdict, g_strdup("SubtitleForced"),
2321 ghb_boolean_value_new(FALSE));
2323 ghb_dict_insert(sdict, g_strdup("SubtitleBurned"),
2324 ghb_boolean_value_new(TRUE));
2325 ghb_dict_insert(sdict, g_strdup("SubtitleDefaultTrack"),
2326 ghb_boolean_value_new(FALSE));
2330 ghb_value_free(gval);
2337 ghb_dict_remove(dict, "Subtitles");
2338 ghb_dict_remove(dict, "SubtitlesForced");
2346 adeflist = ghb_dict_lookup(defaults, "AudioList");
2349 adefaults = ghb_array_get_nth(adeflist, 0);
2350 alist = ghb_dict_lookup(dict, "AudioList");
2351 count = ghb_array_len(alist);
2352 for (ii = 0; ii < count; ii++)
2354 adict = ghb_array_get_nth(alist, ii);
2356 mac_val = ghb_dict_lookup(adict, key);
2357 gval = import_audio_track_xlat2(mac_val);
2359 ghb_dict_insert(adict, g_strdup(key), gval);
2360 key = "AudioEncoder";
2361 mac_val = ghb_dict_lookup(adict, key);
2362 gval = import_value_xlat2(adefaults, acodec_xlat, key, mac_val);
2364 ghb_dict_insert(adict, g_strdup(key), gval);
2365 key = "AudioSamplerate";
2366 mac_val = ghb_dict_lookup(adict, key);
2367 gval = import_value_xlat2(adefaults, samplerate_xlat, key, mac_val);
2369 ghb_dict_insert(adict, g_strdup(key), gval);
2370 key = "AudioMixdown";
2371 mac_val = ghb_dict_lookup(adict, key);
2372 gval = import_value_xlat2(adefaults, mix_xlat, key, mac_val);
2374 ghb_dict_insert(adict, g_strdup(key), gval);
2376 mac_val = ghb_dict_lookup(adict, "AudioTrackDRCSlider");
2377 if (mac_val != NULL)
2380 drc = ghb_value_double(mac_val);
2381 if (drc < 1.0 && drc > 0.0)
2383 ghb_dict_insert(adict, g_strdup("AudioTrackDRCSlider"),
2384 ghb_double_value_new(0.0));
2392 import_xlat_preset(GValue *dict)
2399 g_debug("import_xlat_preset ()");
2400 uses_max = ghb_value_boolean(
2401 preset_dict_get_value(dict, "UsesMaxPictureSettings"));
2402 uses_pic = ghb_value_int(
2403 preset_dict_get_value(dict, "UsesPictureSettings"));
2404 par = ghb_value_int(preset_dict_get_value(dict, "PicturePAR"));
2405 vqtype = ghb_value_int(preset_dict_get_value(dict, "VideoQualityType"));
2407 if (uses_max || uses_pic == 2)
2409 ghb_dict_insert(dict, g_strdup("autoscale"),
2410 ghb_boolean_value_new(TRUE));
2416 if (ghb_dict_lookup(dict, "PictureModulus") == NULL)
2417 ghb_dict_insert(dict, g_strdup("PictureModulus"),
2418 ghb_int_value_new(16));
2422 ghb_dict_insert(dict, g_strdup("PictureModulus"),
2423 ghb_int_value_new(1));
2427 if (ghb_dict_lookup(dict, "PictureModulus") == NULL)
2428 ghb_dict_insert(dict, g_strdup("PictureModulus"),
2429 ghb_int_value_new(16));
2433 if (ghb_dict_lookup(dict, "PictureModulus") == NULL)
2434 ghb_dict_insert(dict, g_strdup("PictureModulus"),
2435 ghb_int_value_new(16));
2438 // VideoQualityType/0/1/2 - vquality_type_/target/bitrate/constant
2443 ghb_dict_insert(dict, g_strdup("vquality_type_target"),
2444 ghb_boolean_value_new(TRUE));
2445 ghb_dict_insert(dict, g_strdup("vquality_type_bitrate"),
2446 ghb_boolean_value_new(FALSE));
2447 ghb_dict_insert(dict, g_strdup("vquality_type_constant"),
2448 ghb_boolean_value_new(FALSE));
2452 ghb_dict_insert(dict, g_strdup("vquality_type_target"),
2453 ghb_boolean_value_new(FALSE));
2454 ghb_dict_insert(dict, g_strdup("vquality_type_bitrate"),
2455 ghb_boolean_value_new(TRUE));
2456 ghb_dict_insert(dict, g_strdup("vquality_type_constant"),
2457 ghb_boolean_value_new(FALSE));
2461 ghb_dict_insert(dict, g_strdup("vquality_type_target"),
2462 ghb_boolean_value_new(FALSE));
2463 ghb_dict_insert(dict, g_strdup("vquality_type_bitrate"),
2464 ghb_boolean_value_new(FALSE));
2465 ghb_dict_insert(dict, g_strdup("vquality_type_constant"),
2466 ghb_boolean_value_new(TRUE));
2470 ghb_dict_insert(dict, g_strdup("vquality_type_target"),
2471 ghb_boolean_value_new(FALSE));
2472 ghb_dict_insert(dict, g_strdup("vquality_type_bitrate"),
2473 ghb_boolean_value_new(FALSE));
2474 ghb_dict_insert(dict, g_strdup("vquality_type_constant"),
2475 ghb_boolean_value_new(TRUE));
2478 import_value_xlat(dict);
2483 vquality = ghb_value_double(preset_dict_get_value(dict, "VideoQualitySlider"));
2488 gval = preset_dict_get_value(dict, "VideoEncoder");
2489 vcodec = ghb_lookup_combo_int("VideoEncoder", gval);
2492 case HB_VCODEC_X264:
2494 vquality = 51. - vquality * 51.;
2497 case HB_VCODEC_FFMPEG:
2499 vquality = 31. - vquality * 30.;
2502 case HB_VCODEC_THEORA:
2504 vquality = vquality * 63.;
2512 ghb_dict_insert(dict, g_strdup("VideoQualitySlider"),
2513 ghb_double_value_new(vquality));
2518 import_xlat_presets(GValue *presets)
2524 g_debug("import_xlat_presets ()");
2525 if (presets == NULL) return;
2526 count = ghb_array_len(presets);
2527 for (ii = 0; ii < count; ii++)
2529 dict = ghb_array_get_nth(presets, ii);
2530 folder = ghb_value_boolean(preset_dict_get_value(dict, "Folder"));
2535 nested = ghb_dict_lookup(dict, "ChildrenArray");
2536 import_xlat_presets(nested);
2540 import_xlat_preset(dict);
2546 export_xlat_preset(GValue *dict)
2548 gboolean autoscale, target, br, constant;
2550 g_debug("export_xlat_prest ()");
2551 autoscale = ghb_value_boolean(preset_dict_get_value(dict, "autoscale"));
2552 target = ghb_value_boolean(
2553 preset_dict_get_value(dict, "vquality_type_target"));
2554 br = ghb_value_boolean(
2555 preset_dict_get_value(dict, "vquality_type_bitrate"));
2556 constant = ghb_value_boolean(
2557 preset_dict_get_value(dict, "vquality_type_constant"));
2560 ghb_dict_insert(dict, g_strdup("UsesPictureSettings"),
2561 ghb_int_value_new(2));
2563 ghb_dict_insert(dict, g_strdup("UsesPictureSettings"),
2564 ghb_int_value_new(1));
2566 // VideoQualityType/0/1/2 - vquality_type_/target/bitrate/constant
2569 ghb_dict_insert(dict, g_strdup("VideoQualityType"),
2570 ghb_int_value_new(0));
2574 ghb_dict_insert(dict, g_strdup("VideoQualityType"),
2575 ghb_int_value_new(1));
2579 ghb_dict_insert(dict, g_strdup("VideoQualityType"),
2580 ghb_int_value_new(2));
2583 GValue *alist, *adict;
2586 alist = ghb_dict_lookup(dict, "AudioList");
2587 count = ghb_array_len(alist);
2588 for (ii = 0; ii < count; ii++)
2592 adict = ghb_array_get_nth(alist, ii);
2593 drc = ghb_value_double(
2594 preset_dict_get_value(adict, "AudioTrackDRCSlider"));
2595 if (drc < 1.0 && drc > 0.0)
2597 ghb_dict_insert(adict, g_strdup("AudioTrackDRCSlider"),
2598 ghb_double_value_new(0.0));
2602 ghb_dict_remove(dict, "UsesMaxPictureSettings");
2603 ghb_dict_remove(dict, "autoscale");
2604 ghb_dict_remove(dict, "vquality_type_target");
2605 ghb_dict_remove(dict, "vquality_type_bitrate");
2606 ghb_dict_remove(dict, "vquality_type_constant");
2607 export_value_xlat(dict);
2611 export_xlat_presets(GValue *presets)
2617 if (presets == NULL) return;
2618 count = ghb_array_len(presets);
2619 for (ii = 0; ii < count; ii++)
2621 dict = ghb_array_get_nth(presets, ii);
2622 folder = ghb_value_boolean(preset_dict_get_value(dict, "Folder"));
2627 nested = ghb_dict_lookup(dict, "ChildrenArray");
2628 export_xlat_presets(nested);
2632 export_xlat_preset(dict);
2637 static guint prefs_timeout_id = 0;
2640 delayed_store_prefs(gpointer data)
2642 store_plist(prefsPlist, "preferences");
2643 prefs_timeout_id = 0;
2652 export = ghb_value_dup(presetsPlist);
2653 export_xlat_presets(export);
2654 store_plist(export, "presets");
2655 ghb_value_free(export);
2661 if (prefs_timeout_id != 0)
2666 mc = g_main_context_default();
2667 source = g_main_context_find_source_by_id(mc, prefs_timeout_id);
2669 g_source_destroy(source);
2671 prefs_timeout_id = g_timeout_add_seconds(1, (GSourceFunc)delayed_store_prefs, NULL);
2675 ghb_presets_reload(signal_user_data_t *ud)
2677 GValue *std_presets;
2681 g_debug("ghb_presets_reload()\n");
2682 std_presets = ghb_resource_get("standard-presets");
2683 if (std_presets == NULL) return;
2685 remove_std_presets(ud);
2686 indices = presets_find_default(presetsPlist, &len);
2689 presets_clear_default(std_presets);
2692 // Merge the keyfile contents into our presets
2693 count = ghb_array_len(std_presets);
2694 for (ii = count-1; ii >= 0; ii--)
2700 std_dict = ghb_array_get_nth(std_presets, ii);
2701 copy_dict = ghb_value_dup(std_dict);
2702 ghb_dict_insert(copy_dict, g_strdup("PresetBuildNumber"),
2703 ghb_int64_value_new(hb_get_build(NULL)));
2704 ghb_presets_insert(presetsPlist, copy_dict, &indices, 1);
2705 presets_list_insert(ud, &indices, 1);
2707 import_xlat_presets(presetsPlist);
2716 count = ghb_array_len(presetsPlist);
2717 for (ii = count-1; ii >= 0; ii--)
2722 dict = ghb_array_get_nth(presetsPlist, ii);
2723 type = ghb_dict_lookup(dict, "Type");
2731 replace_standard_presets()
2733 GValue *std_presets;
2737 count = ghb_array_len(presetsPlist);
2738 for (ii = count-1; ii >= 0; ii--)
2743 dict = ghb_array_get_nth(presetsPlist, ii);
2744 ptype = ghb_value_int(preset_dict_get_value(dict, "Type"));
2745 if (ptype == PRESETS_BUILTIN)
2748 ghb_presets_remove(presetsPlist, &indices, 1);
2752 std_presets = ghb_resource_get("standard-presets");
2753 if (std_presets == NULL) return;
2755 indices = presets_find_default(presetsPlist, &len);
2758 presets_clear_default(std_presets);
2761 // Merge the keyfile contents into our presets
2762 count = ghb_array_len(std_presets);
2763 for (ii = count-1; ii >= 0; ii--)
2769 std_dict = ghb_array_get_nth(std_presets, ii);
2770 copy_dict = ghb_value_dup(std_dict);
2771 ghb_dict_insert(copy_dict, g_strdup("PresetBuildNumber"),
2772 ghb_int64_value_new(hb_get_build(NULL)));
2773 ghb_presets_insert(presetsPlist, copy_dict, &indices, 1);
2775 import_xlat_presets(presetsPlist);
2780 update_standard_presets(signal_user_data_t *ud)
2784 count = ghb_array_len(presetsPlist);
2785 for (ii = count-1; ii >= 0; ii--)
2792 dict = ghb_array_get_nth(presetsPlist, ii);
2793 gval = ghb_dict_lookup(dict, "Type");
2796 // Old preset that doesn't have a Type
2797 replace_standard_presets();
2801 type = ghb_value_int(gval);
2804 gval = ghb_dict_lookup(dict, "PresetBuildNumber");
2807 // Old preset that doesn't have a build number
2808 replace_standard_presets();
2812 build = ghb_value_int64(gval);
2813 if (build != hb_get_build(NULL))
2815 // Build number does not match
2816 replace_standard_presets();
2825 ghb_presets_load(signal_user_data_t *ud)
2827 presetsPlist = load_plist("presets");
2828 if (presetsPlist == NULL)
2830 presetsPlist = ghb_value_dup(ghb_resource_get("standard-presets"));
2831 import_xlat_presets(presetsPlist);
2834 else if (G_VALUE_TYPE(presetsPlist) == ghb_dict_get_type())
2835 { // Presets is older dictionary format. Convert to array
2836 ghb_value_free(presetsPlist);
2837 presetsPlist = ghb_value_dup(ghb_resource_get("standard-presets"));
2838 import_xlat_presets(presetsPlist);
2841 else if (check_old_presets())
2843 ghb_value_free(presetsPlist);
2844 presetsPlist = ghb_value_dup(ghb_resource_get("standard-presets"));
2845 import_xlat_presets(presetsPlist);
2848 update_standard_presets(ud);
2849 import_xlat_presets(presetsPlist);
2853 settings_save(signal_user_data_t *ud, const GValue *path)
2855 GValue *dict, *internal;
2856 GHashTableIter iter;
2860 gint *indices, len, count;
2861 gint *def_indices, def_len;
2863 gboolean replace = FALSE;
2865 g_debug("settings_save");
2866 if (internalPlist == NULL) return;
2867 count = ghb_array_len(path);
2868 name = g_value_get_string(ghb_array_get_nth(path, count-1));
2869 indices = ghb_preset_indices_from_path(presetsPlist, path, &len);
2872 if (ghb_presets_get_folder(presetsPlist, indices, len))
2875 message = g_strdup_printf(
2876 "%s: Folder already exists.\n"
2877 "You can not replace it with a preset.",
2879 ghb_message_dialog(GTK_MESSAGE_ERROR, message, "Cancel", NULL);
2883 dict = ghb_dict_value_new();
2884 ghb_presets_replace(presetsPlist, dict, indices, len);
2889 indices = presets_find_pos(path, PRESETS_CUSTOM, &len);
2892 dict = ghb_dict_value_new();
2893 ghb_presets_insert(presetsPlist, dict, indices, len);
2897 g_warning("failed to find insert path");
2901 current_preset = dict;
2902 autoscale = ghb_settings_get_boolean(ud->settings, "autoscale");
2903 ghb_settings_set_int64(ud->settings, "Type", PRESETS_CUSTOM);
2904 ghb_settings_set_int64(ud->settings, "PresetBuildNumber", hb_get_build(NULL));
2906 internal = plist_get_dict(internalPlist, "Presets");
2907 ghb_dict_iter_init(&iter, internal);
2908 // middle (void*) cast prevents gcc warning "defreferencing type-punned
2909 // pointer will break strict-aliasing rules"
2910 while (g_hash_table_iter_next(
2911 &iter, (gpointer*)(void*)&key, (gpointer*)(void*)&value))
2919 if (strcmp(key, "PictureWidth") == 0)
2921 key2 = "scale_width";
2923 else if (strcmp(key, "PictureHeight") == 0)
2925 key2 = "scale_height";
2928 gval = ghb_settings_get_value(ud->settings, key2);
2933 ghb_dict_insert(dict, g_strdup(key), ghb_value_dup(gval));
2935 internal = plist_get_dict(internalPlist, "XlatPresets");
2936 ghb_dict_iter_init(&iter, internal);
2937 // middle (void*) cast prevents gcc warning "defreferencing type-punned
2938 // pointer will break strict-aliasing rules"
2939 while (g_hash_table_iter_next(
2940 &iter, (gpointer*)(void*)&key, (gpointer*)(void*)&value))
2944 gval = ghb_settings_get_value(ud->settings, key);
2949 ghb_dict_insert(dict, g_strdup(key), ghb_value_dup(gval));
2951 ghb_dict_insert(dict, g_strdup("PresetName"), ghb_string_value_new(name));
2954 def_indices = presets_find_default(presetsPlist, &def_len);
2955 if (def_indices != NULL &&
2956 preset_path_cmp(indices, len, def_indices, def_len) != 0)
2958 ghb_dict_insert(dict, g_strdup("Default"),
2959 ghb_boolean_value_new(FALSE));
2961 presets_list_update_item(ud, indices, len, FALSE);
2965 ghb_dict_insert(dict, g_strdup("Default"),
2966 ghb_boolean_value_new(FALSE));
2967 presets_list_insert(ud, indices, len);
2970 ud->dont_clear_presets = TRUE;
2971 // Make the new preset the selected item
2972 ghb_select_preset2(ud->builder, indices, len);
2974 ud->dont_clear_presets = FALSE;
2979 folder_save(signal_user_data_t *ud, const GValue *path)
2981 GValue *dict, *folder;
2982 gint *indices, len, count;
2985 count = ghb_array_len(path);
2986 name = g_value_get_string(ghb_array_get_nth(path, count-1));
2987 indices = ghb_preset_indices_from_path(presetsPlist, path, &len);
2990 if (!ghb_presets_get_folder(presetsPlist, indices, len))
2993 message = g_strdup_printf(
2994 "%s: Preset already exists.\n"
2995 "You can not replace it with a folder.",
2997 ghb_message_dialog(GTK_MESSAGE_ERROR, message, "Cancel", NULL);
3002 // Already exists, update its description
3003 dict = presets_get_dict(presetsPlist, indices, len);
3004 ghb_dict_insert(dict, g_strdup("PresetDescription"),
3005 ghb_value_dup(preset_dict_get_value(
3006 ud->settings, "PresetDescription")));
3007 presets_list_update_item(ud, indices, len, FALSE);
3014 indices = presets_find_pos(path, PRESETS_CUSTOM, &len);
3017 dict = ghb_dict_value_new();
3018 ghb_presets_insert(presetsPlist, dict, indices, len);
3022 g_warning("failed to find insert path");
3026 ghb_dict_insert(dict, g_strdup("PresetDescription"),
3027 ghb_value_dup(preset_dict_get_value(
3028 ud->settings, "PresetDescription")));
3029 ghb_dict_insert(dict, g_strdup("PresetName"), ghb_string_value_new(name));
3030 folder = ghb_array_value_new(8);
3031 ghb_dict_insert(dict, g_strdup("ChildrenArray"), folder);
3032 ghb_dict_insert(dict, g_strdup("Type"),
3033 ghb_int64_value_new(PRESETS_CUSTOM));
3034 ghb_dict_insert(dict, g_strdup("Folder"), ghb_boolean_value_new(TRUE));
3036 presets_list_insert(ud, indices, len);
3043 ghb_presets_list_default(signal_user_data_t *ud)
3045 GtkTreeView *treeview;
3046 GtkTreePath *treepath;
3048 GtkTreeStore *store;
3051 g_debug("ghb_presets_list_default ()");
3052 treeview = GTK_TREE_VIEW(GHB_WIDGET(ud->builder, "presets_list"));
3053 store = GTK_TREE_STORE(gtk_tree_view_get_model(treeview));
3054 indices = presets_find_default(presetsPlist, &len);
3055 if (indices == NULL) return;
3056 treepath = ghb_tree_path_new_from_indices(indices, len);
3059 if (gtk_tree_model_get_iter(GTK_TREE_MODEL(store), &iter, treepath))
3061 gtk_tree_store_set(store, &iter,
3066 gtk_tree_path_free(treepath);
3072 ghb_presets_list_clear_default(signal_user_data_t *ud)
3074 GtkTreeView *treeview;
3075 GtkTreePath *treepath;
3077 GtkTreeStore *store;
3080 g_debug("ghb_presets_list_clear_default ()");
3081 treeview = GTK_TREE_VIEW(GHB_WIDGET(ud->builder, "presets_list"));
3082 store = GTK_TREE_STORE(gtk_tree_view_get_model(treeview));
3083 indices = presets_find_default(presetsPlist, &len);
3084 if (indices == NULL) return;
3085 treepath = ghb_tree_path_new_from_indices(indices, len);
3088 if (gtk_tree_model_get_iter(GTK_TREE_MODEL(store), &iter, treepath))
3090 gtk_tree_store_set(store, &iter,
3095 gtk_tree_path_free(treepath);
3101 update_audio_presets(signal_user_data_t *ud)
3103 g_debug("update_audio_presets");
3104 const GValue *audio_list;
3106 audio_list = ghb_settings_get_value(ud->settings, "audio_list");
3107 ghb_settings_set_value(ud->settings, "AudioList", audio_list);
3111 update_subtitle_presets(signal_user_data_t *ud)
3113 g_debug("update_subtitle_presets");
3114 const GValue *subtitle_list, *subtitle;
3115 GValue *slist, *dict;
3116 gint count, ii, source;
3118 subtitle_list = ghb_settings_get_value(ud->settings, "subtitle_list");
3119 slist = ghb_array_value_new(8);
3120 count = ghb_array_len(subtitle_list);
3121 for (ii = 0; ii < count; ii++)
3123 subtitle = ghb_array_get_nth(subtitle_list, ii);
3124 source = ghb_settings_get_int(subtitle, "SubtitleSource");
3125 if (source != SRTSUB)
3127 dict = ghb_value_dup(subtitle);
3128 ghb_array_append(slist, dict);
3131 ghb_settings_take_value(ud->settings, "SubtitleList", slist);
3134 G_MODULE_EXPORT void
3135 presets_menu_clicked_cb(GtkWidget *xwidget, signal_user_data_t *ud)
3139 menu = GTK_MENU(GHB_WIDGET(ud->builder, "presets_menu"));
3140 gtk_menu_popup(menu, NULL, NULL, NULL, NULL, 1,
3141 gtk_get_current_event_time());
3144 G_MODULE_EXPORT void
3145 preset_import_clicked_cb(GtkWidget *xwidget, signal_user_data_t *ud)
3148 GtkResponseType response;
3151 GtkFileFilter *filter;
3153 g_debug("preset_import_clicked_cb ()");
3155 dialog = gtk_file_chooser_dialog_new("Import Preset", NULL,
3156 GTK_FILE_CHOOSER_ACTION_OPEN,
3157 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
3158 GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
3161 filter = gtk_file_filter_new();
3162 gtk_file_filter_set_name(filter, "All (*)");
3163 gtk_file_filter_add_pattern(filter, "*");
3164 gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(dialog), filter);
3166 filter = gtk_file_filter_new();
3167 gtk_file_filter_set_name(filter, "Presets (*.plist)");
3168 gtk_file_filter_add_pattern(filter, "*.plist");
3169 gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(dialog), filter);
3170 gtk_file_chooser_set_filter(GTK_FILE_CHOOSER(dialog), filter);
3172 exportDir = ghb_settings_get_string(ud->settings, "ExportDirectory");
3173 if (exportDir == NULL || exportDir[0] == '\0')
3175 exportDir = g_strdup(".");
3177 gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(dialog), exportDir);
3180 response = gtk_dialog_run(GTK_DIALOG(dialog));
3181 gtk_widget_hide(dialog);
3182 if (response == GTK_RESPONSE_ACCEPT)
3184 GValue *dict, *array;
3188 filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog));
3190 // import the preset
3191 if (!g_file_test(filename, G_FILE_TEST_IS_REGULAR))
3193 gtk_widget_destroy(dialog);
3197 array = ghb_plist_parse_file(filename);
3200 import_xlat_presets(array);
3201 presets_clear_default(array);
3202 presets_customize(array);
3204 count = ghb_array_len(array);
3205 for (ii = 0; ii < count; ii++)
3207 GValue *path, *name;
3211 dict = ghb_array_get_nth(array, ii);
3212 path = ghb_array_value_new(1);
3213 name = ghb_value_dup(ghb_dict_lookup(dict, "PresetName"));
3214 ghb_array_append(path, name);
3215 indices = ghb_preset_indices_from_path(presetsPlist, path, &len);
3216 // Modify the preset name till we make it unique
3217 while (indices != NULL)
3219 gchar *str = ghb_value_string(name);
3221 ghb_value_free(path);
3224 str = g_strdup_printf("%s %d", str, index);
3225 path = ghb_array_value_new(1);
3226 name = ghb_string_value_new(str);
3227 ghb_array_append(path, name);
3231 indices = ghb_preset_indices_from_path(presetsPlist, path, &len);
3233 ghb_dict_insert(dict, g_strdup("PresetName"), ghb_value_dup(name));
3234 indices = presets_find_pos(path, PRESETS_CUSTOM, &len);
3235 ghb_presets_insert(presetsPlist, ghb_value_dup(dict), indices, len);
3236 presets_list_insert(ud, indices, len);
3237 ghb_value_free(path);
3239 ghb_value_free(array);
3241 exportDir = ghb_settings_get_string(ud->settings, "ExportDirectory");
3242 dir = g_path_get_dirname(filename);
3243 if (strcmp(dir, exportDir) != 0)
3245 ghb_settings_set_string(ud->settings, "ExportDirectory", dir);
3246 ghb_pref_save(ud->settings, "ExportDirectory");
3251 gtk_widget_destroy(dialog);
3254 G_MODULE_EXPORT void
3255 preset_export_clicked_cb(GtkWidget *xwidget, signal_user_data_t *ud)
3258 GtkResponseType response;
3260 const gchar *name = "";
3261 gint count, *indices, len;
3265 g_debug("preset_export_clicked_cb ()");
3266 preset = ghb_settings_get_value (ud->settings, "preset_selection");
3270 count = ghb_array_len(preset);
3274 name = g_value_get_string(ghb_array_get_nth(preset, count-1));
3276 dialog = gtk_file_chooser_dialog_new("Export Preset", NULL,
3277 GTK_FILE_CHOOSER_ACTION_SAVE,
3278 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
3279 GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT,
3282 exportDir = ghb_settings_get_string(ud->settings, "ExportDirectory");
3283 if (exportDir == NULL || exportDir[0] == '\0')
3285 exportDir = g_strdup(".");
3287 filename = g_strdup_printf("%s.plist", name);
3288 gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(dialog), exportDir);
3289 gtk_file_chooser_set_current_name(GTK_FILE_CHOOSER(dialog), filename);
3293 indices = ghb_preset_indices_from_path(presetsPlist, preset, &len);
3294 if (indices == NULL)
3297 response = gtk_dialog_run(GTK_DIALOG(dialog));
3298 gtk_widget_hide(dialog);
3299 if (response == GTK_RESPONSE_ACCEPT)
3301 GValue *export, *dict, *array;
3305 filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog));
3307 // export the preset
3308 dict = presets_get_dict(presetsPlist, indices, len);
3310 export = ghb_value_dup(dict);
3311 array = ghb_array_value_new(1);
3312 ghb_array_append(array, export);
3313 presets_clear_default(array);
3314 presets_customize(array);
3315 export_xlat_presets(array);
3317 file = g_fopen(filename, "w");
3320 ghb_plist_write(file, array);
3323 ghb_value_free(array);
3325 exportDir = ghb_settings_get_string(ud->settings, "ExportDirectory");
3326 dir = g_path_get_dirname(filename);
3327 if (strcmp(dir, exportDir) != 0)
3329 ghb_settings_set_string(ud->settings, "ExportDirectory", dir);
3330 ghb_pref_save(ud->settings, "ExportDirectory");
3336 gtk_widget_destroy(dialog);
3340 G_MODULE_EXPORT void
3341 presets_new_folder_clicked_cb(GtkWidget *xwidget, signal_user_data_t *ud)
3346 GtkResponseType response;
3347 GValue *preset, *dict;
3348 const gchar *name = "";
3349 const gchar *description = "";
3350 gint count, *indices, len;
3352 g_debug("presets_save_clicked_cb ()");
3353 preset = ghb_settings_get_value (ud->settings, "preset_selection");
3355 count = ghb_array_len(preset);
3357 name = g_value_get_string(ghb_array_get_nth(preset, count-1));
3361 indices = ghb_preset_indices_from_path(presetsPlist, preset, &len);
3362 dict = presets_get_dict(presetsPlist, indices, len);
3365 description = g_value_get_string(
3366 ghb_dict_lookup(dict, "PresetDescription"));
3367 ghb_ui_update(ud, "PresetDescription", ghb_string_value(description));
3370 desc = GTK_TEXT_VIEW(GHB_WIDGET(ud->builder, "PresetDescription"));
3371 dialog = GHB_WIDGET(ud->builder, "preset_save_dialog");
3372 entry = GTK_ENTRY(GHB_WIDGET(ud->builder, "PresetName"));
3373 gtk_entry_set_text(entry, name);
3374 response = gtk_dialog_run(GTK_DIALOG(dialog));
3375 gtk_widget_hide(dialog);
3376 if (response == GTK_RESPONSE_OK)
3379 const gchar *name = gtk_entry_get_text(entry);
3382 if (count > MAX_NESTED_PRESET-1)
3383 count = MAX_NESTED_PRESET-1;
3385 dest = ghb_array_value_new(MAX_NESTED_PRESET);
3386 if (indices != NULL)
3390 ptype = ghb_presets_get_type(presetsPlist, indices, len);
3391 if (ptype == PRESETS_CUSTOM)
3393 ghb_array_copy(dest, preset, count-1);
3396 ghb_array_append(dest, ghb_string_value_new(name));
3397 ghb_widget_to_setting(ud->settings, GTK_WIDGET(desc));
3398 folder_save(ud, dest);
3399 ghb_value_free(dest);
3401 if (indices != NULL)
3405 G_MODULE_EXPORT void
3406 presets_save_clicked_cb(GtkWidget *xwidget, signal_user_data_t *ud)
3411 GtkResponseType response;
3413 const gchar *name = "";
3414 gint count, *indices, len;
3416 g_debug("presets_save_clicked_cb ()");
3417 preset = ghb_settings_get_value (ud->settings, "preset_selection");
3419 count = ghb_array_len(preset);
3421 name = g_value_get_string(ghb_array_get_nth(preset, count-1));
3425 desc = GTK_TEXT_VIEW(GHB_WIDGET(ud->builder, "PresetDescription"));
3426 dialog = GHB_WIDGET(ud->builder, "preset_save_dialog");
3427 entry = GTK_ENTRY(GHB_WIDGET(ud->builder, "PresetName"));
3428 gtk_entry_set_text(entry, name);
3429 response = gtk_dialog_run(GTK_DIALOG(dialog));
3430 gtk_widget_hide(dialog);
3431 if (response == GTK_RESPONSE_OK)
3434 const gchar *name = gtk_entry_get_text(entry);
3437 dest = ghb_array_value_new(MAX_NESTED_PRESET);
3438 indices = ghb_preset_indices_from_path(presetsPlist, preset, &len);
3443 ptype = ghb_presets_get_type(presetsPlist, indices, len);
3444 if (ptype == PRESETS_CUSTOM)
3446 ghb_array_copy(dest, preset, count-1);
3450 ghb_array_append(dest, ghb_string_value_new(name));
3452 ghb_widget_to_setting(ud->settings, GTK_WIDGET(desc));
3454 // Construct the audio settings presets from the current audio list
3455 update_audio_presets(ud);
3456 update_subtitle_presets(ud);
3457 settings_save(ud, dest);
3458 ghb_value_free(dest);
3462 G_MODULE_EXPORT void
3463 preset_type_changed_cb(GtkWidget *widget, signal_user_data_t *ud)
3465 ghb_widget_to_setting(ud->settings, widget);
3468 G_MODULE_EXPORT void
3469 presets_restore_clicked_cb(GtkWidget *xwidget, signal_user_data_t *ud)
3473 g_debug("presets_restore_clicked_cb ()");
3474 // Reload only the standard presets
3475 ghb_presets_reload(ud);
3476 // Updating the presets list shuffles things around
3477 // need to make sure the proper preset is selected
3478 preset = ghb_settings_get_value (ud->settings, "preset");
3479 ghb_select_preset(ud->builder, preset);
3482 G_MODULE_EXPORT void
3483 presets_remove_clicked_cb(GtkWidget *xwidget, signal_user_data_t *ud)
3485 GtkTreeView *treeview;
3486 GtkTreeSelection *selection;
3487 GtkTreeModel *store;
3490 GtkResponseType response;
3492 g_debug("presets_remove_clicked_cb ()");
3493 treeview = GTK_TREE_VIEW(GHB_WIDGET(ud->builder, "presets_list"));
3494 selection = gtk_tree_view_get_selection (treeview);
3495 if (gtk_tree_selection_get_selected(selection, &store, &iter))
3502 gtk_tree_model_get(store, &iter, 0, &preset, -1);
3503 path = gtk_tree_model_get_path(store, &iter);
3504 indices = gtk_tree_path_get_indices(path);
3505 len = gtk_tree_path_get_depth(path);
3507 folder = ghb_presets_get_folder(presetsPlist, indices, len);
3508 dialog = gtk_message_dialog_new(NULL, GTK_DIALOG_MODAL,
3509 GTK_MESSAGE_QUESTION, GTK_BUTTONS_YES_NO,
3510 "Confirm deletion of %s:\n\n%s",
3511 folder ? "folder" : "preset",
3513 response = gtk_dialog_run(GTK_DIALOG(dialog));
3514 gtk_widget_destroy (dialog);
3515 if (response == GTK_RESPONSE_YES)
3517 GtkTreeIter nextIter = iter;
3518 gboolean valid = TRUE;
3519 if (!gtk_tree_model_iter_next(store, &nextIter))
3521 if (!gtk_tree_model_iter_parent(store, &nextIter, &iter))
3526 // Remove the selected item
3527 // First unselect it so that selecting the new item works properly
3528 gtk_tree_selection_unselect_iter (selection, &iter);
3529 if (ghb_presets_remove(presetsPlist, indices, len))
3532 presets_list_remove(ud, indices, len);
3535 valid = gtk_tree_model_get_iter_first(store, &nextIter);
3538 gtk_tree_path_free(path);
3539 path = gtk_tree_model_get_path(store, &nextIter);
3540 indices = gtk_tree_path_get_indices(path);
3541 len = gtk_tree_path_get_depth(path);
3542 ghb_select_preset2(ud->builder, indices, len);
3546 gtk_tree_path_free(path);
3550 // controls where valid drop locations are
3551 G_MODULE_EXPORT gboolean
3552 presets_drag_motion_cb(
3554 GdkDragContext *ctx,
3558 signal_user_data_t *ud)
3560 GtkTreePath *path = NULL;
3561 GtkTreeViewDropPosition drop_pos;
3565 GtkTreeModel *model;
3566 GtkTreeSelection *select;
3567 gint src_ptype, dst_ptype;
3568 gboolean src_folder, dst_folder;
3570 gint tree_depth, ii;
3573 widget = gtk_drag_get_source_widget(ctx);
3574 if (widget == NULL || widget != GTK_WIDGET(tv))
3577 // Get the type of the object being dragged
3578 srctv = GTK_TREE_VIEW(gtk_drag_get_source_widget(ctx));
3579 select = gtk_tree_view_get_selection (srctv);
3580 gtk_tree_selection_get_selected (select, &model, &iter);
3581 path = gtk_tree_model_get_path (model, &iter);
3582 indices = gtk_tree_path_get_indices(path);
3583 len = gtk_tree_path_get_depth(path);
3585 preset = presets_get_dict(presetsPlist, indices, len);
3586 tree_depth = preset_tree_depth(preset);
3588 src_ptype = ghb_presets_get_type(presetsPlist, indices, len);
3589 src_folder = ghb_presets_get_folder(presetsPlist, indices, len);
3590 gtk_tree_path_free(path);
3592 if (src_folder && tree_depth == 1)
3595 // The rest checks that the destination is a valid position
3597 gtk_tree_view_get_dest_row_at_pos (tv, x, y, &path, &drop_pos);
3600 gdk_drag_status(ctx, 0, time);
3603 // Don't allow repositioning of builtin presets
3604 if (src_ptype != PRESETS_CUSTOM)
3606 gdk_drag_status(ctx, 0, time);
3610 len = gtk_tree_path_get_depth(path);
3611 if (len+tree_depth-1 >= MAX_NESTED_PRESET)
3613 if (drop_pos == GTK_TREE_VIEW_DROP_INTO_OR_BEFORE)
3614 drop_pos = GTK_TREE_VIEW_DROP_BEFORE;
3615 if (drop_pos == GTK_TREE_VIEW_DROP_INTO_OR_AFTER)
3616 drop_pos = GTK_TREE_VIEW_DROP_AFTER;
3618 for (ii = len+tree_depth-1; ii > MAX_NESTED_PRESET; ii--)
3619 gtk_tree_path_up(path);
3620 indices = gtk_tree_path_get_indices(path);
3621 len = gtk_tree_path_get_depth(path);
3622 dst_ptype = ghb_presets_get_type(presetsPlist, indices, len);
3623 dst_folder = ghb_presets_get_folder(presetsPlist, indices, len);
3624 // Don't allow mixing custom presets in the builtins
3625 if (dst_ptype != PRESETS_CUSTOM)
3627 gdk_drag_status(ctx, 0, time);
3631 // Only allow *drop into* for folders
3634 if (drop_pos == GTK_TREE_VIEW_DROP_INTO_OR_BEFORE)
3635 drop_pos = GTK_TREE_VIEW_DROP_BEFORE;
3636 if (drop_pos == GTK_TREE_VIEW_DROP_INTO_OR_AFTER)
3637 drop_pos = GTK_TREE_VIEW_DROP_AFTER;
3640 len = gtk_tree_path_get_depth(path);
3641 gtk_tree_view_set_drag_dest_row(tv, path, drop_pos);
3642 gtk_tree_path_free(path);
3643 gdk_drag_status(ctx, GDK_ACTION_MOVE, time);
3647 G_MODULE_EXPORT void
3649 GtkTreeView *dstwidget,
3652 GtkSelectionData *selection_data,
3653 guint info, guint t,
3654 signal_user_data_t *ud)
3656 GtkTreePath *path = NULL;
3657 GtkTreeViewDropPosition drop_pos;
3658 GtkTreeIter dstiter, srciter;
3659 gint *dst_indices, dst_len, *src_indices, src_len;
3661 gboolean src_folder, dst_folder;
3663 GtkTreeModel *dstmodel = gtk_tree_view_get_model(dstwidget);
3665 g_debug("preset_drag_cb ()");
3666 // This doesn't work here for some reason...
3667 // gtk_tree_view_get_drag_dest_row(dstwidget, &path, &drop_pos);
3668 gtk_tree_view_get_dest_row_at_pos (dstwidget, x, y, &path, &drop_pos);
3669 // This little hack is needed because attempting to drop after
3670 // the last item gives us no path or drop_pos.
3675 n_children = gtk_tree_model_iter_n_children(dstmodel, NULL);
3678 drop_pos = GTK_TREE_VIEW_DROP_AFTER;
3679 path = gtk_tree_path_new_from_indices(n_children-1, -1);
3683 drop_pos = GTK_TREE_VIEW_DROP_BEFORE;
3684 path = gtk_tree_path_new_from_indices(0, -1);
3689 GtkTreeView *srcwidget;
3690 GtkTreeModel *srcmodel;
3691 GtkTreeSelection *select;
3692 GtkTreePath *srcpath = NULL;
3694 gint tree_depth, ii;
3696 srcwidget = GTK_TREE_VIEW(gtk_drag_get_source_widget(dc));
3697 select = gtk_tree_view_get_selection (srcwidget);
3698 gtk_tree_selection_get_selected (select, &srcmodel, &srciter);
3700 srcpath = gtk_tree_model_get_path (srcmodel, &srciter);
3701 src_indices = gtk_tree_path_get_indices(srcpath);
3702 src_len = gtk_tree_path_get_depth(srcpath);
3703 src_ptype = ghb_presets_get_type(presetsPlist, src_indices, src_len);
3704 src_folder = ghb_presets_get_folder(presetsPlist, src_indices, src_len);
3705 preset = ghb_value_dup(
3706 presets_get_dict(presetsPlist, src_indices, src_len));
3707 gtk_tree_path_free(srcpath);
3709 // Don't allow repositioning of builtin presets
3710 if (src_ptype != PRESETS_CUSTOM)
3713 tree_depth = preset_tree_depth(preset);
3714 if (src_folder && tree_depth == 1)
3717 dst_len = gtk_tree_path_get_depth(path);
3718 if (dst_len+tree_depth-1 >= MAX_NESTED_PRESET)
3720 if (drop_pos == GTK_TREE_VIEW_DROP_INTO_OR_BEFORE)
3721 drop_pos = GTK_TREE_VIEW_DROP_BEFORE;
3722 if (drop_pos == GTK_TREE_VIEW_DROP_INTO_OR_AFTER)
3723 drop_pos = GTK_TREE_VIEW_DROP_AFTER;
3726 for (ii = dst_len+tree_depth-1; ii > MAX_NESTED_PRESET; ii--)
3727 gtk_tree_path_up(path);
3728 dst_indices = gtk_tree_path_get_indices(path);
3729 dst_len = gtk_tree_path_get_depth(path);
3730 dst_folder = ghb_presets_get_folder(presetsPlist, dst_indices, dst_len);
3731 // Only allow *drop into* for folders
3734 if (drop_pos == GTK_TREE_VIEW_DROP_INTO_OR_BEFORE)
3735 drop_pos = GTK_TREE_VIEW_DROP_BEFORE;
3736 if (drop_pos == GTK_TREE_VIEW_DROP_INTO_OR_AFTER)
3737 drop_pos = GTK_TREE_VIEW_DROP_AFTER;
3739 if (gtk_tree_model_get_iter (dstmodel, &dstiter, path))
3742 GtkTreePath *dstpath = NULL;
3746 case GTK_TREE_VIEW_DROP_BEFORE:
3747 gtk_tree_store_insert_before(GTK_TREE_STORE (dstmodel),
3748 &iter, NULL, &dstiter);
3751 case GTK_TREE_VIEW_DROP_INTO_OR_BEFORE:
3752 gtk_tree_store_insert(GTK_TREE_STORE (dstmodel),
3753 &iter, &dstiter, 0);
3756 case GTK_TREE_VIEW_DROP_AFTER:
3757 gtk_tree_store_insert_after(GTK_TREE_STORE (dstmodel),
3758 &iter, NULL, &dstiter);
3761 case GTK_TREE_VIEW_DROP_INTO_OR_AFTER:
3762 gtk_tree_store_insert_after(GTK_TREE_STORE (dstmodel),
3763 &iter, &dstiter, 0);
3770 dstpath = gtk_tree_model_get_path (dstmodel, &iter);
3771 dst_indices = gtk_tree_path_get_indices(dstpath);
3772 dst_len = gtk_tree_path_get_depth(dstpath);
3773 ghb_presets_insert(presetsPlist, preset, dst_indices, dst_len);
3774 gtk_tree_path_free(dstpath);
3776 srcpath = gtk_tree_model_get_path (srcmodel, &srciter);
3777 src_indices = gtk_tree_path_get_indices(srcpath);
3778 src_len = gtk_tree_path_get_depth(srcpath);
3779 ghb_presets_remove(presetsPlist, src_indices, src_len);
3780 gtk_tree_path_free(srcpath);
3782 gtk_tree_store_remove (GTK_TREE_STORE (srcmodel), &srciter);
3784 dstpath = gtk_tree_model_get_path (dstmodel, &iter);
3785 dst_indices = gtk_tree_path_get_indices(dstpath);
3786 dst_len = gtk_tree_path_get_depth(dstpath);
3787 presets_list_update_item(ud, dst_indices, dst_len, TRUE);
3788 gtk_tree_path_free(dstpath);
3792 gtk_tree_path_free(path);
3797 presets_row_expanded_cb(
3798 GtkTreeView *treeview,
3801 signal_user_data_t *ud)
3804 gboolean expanded, folder;
3807 expanded = gtk_tree_view_row_expanded(treeview, path);
3808 indices = gtk_tree_path_get_indices(path);
3809 len = gtk_tree_path_get_depth(path);
3810 dict = presets_get_dict(presetsPlist, indices, len);
3811 if (preset_folder_is_open(dict))
3820 folder = ghb_presets_get_folder(presetsPlist, indices, len);
3823 presets_set_folder_open(expanded, indices, len);
3826 // Collapsing parent folder collapses all children
3829 GValue *presets = NULL;
3830 gint *more_indices, count, ii;
3832 more_indices = g_malloc((len+1)*sizeof(gint));
3833 memcpy(more_indices, indices, len*sizeof(gint));
3835 presets = presets_get_folder(presetsPlist, indices, len);
3836 count = ghb_array_len(presets);
3837 for (ii = 0; ii < count; ii++)
3839 dict = ghb_array_get_nth(presets, ii);
3840 folder = ghb_preset_folder(dict);
3843 more_indices[len] = ii;
3844 presets_set_folder_open(expanded, more_indices, len+1);
3847 g_free(more_indices);
3853 preset_update_title_deps(signal_user_data_t *ud, ghb_title_info_t *tinfo)
3857 ghb_ui_update(ud, "scale_width",
3858 ghb_int64_value(tinfo->width - tinfo->crop[2] - tinfo->crop[3]));
3859 // If anamorphic or keep_aspect, the hight will be automatically calculated
3860 gboolean keep_aspect;
3862 keep_aspect = ghb_settings_get_boolean(ud->settings, "PictureKeepRatio");
3863 pic_par = ghb_settings_combo_int(ud->settings, "PicturePAR");
3864 if (!(keep_aspect || pic_par) || pic_par == 3)
3866 ghb_ui_update(ud, "scale_height",
3867 ghb_int64_value(tinfo->height - tinfo->crop[0] - tinfo->crop[1]));
3870 // Set the limits of cropping. hb_set_anamorphic_size crashes if
3871 // you pass it a cropped width or height == 0.
3873 bound = tinfo->height / 2 - 2;
3874 widget = GHB_WIDGET (ud->builder, "PictureTopCrop");
3875 gtk_spin_button_set_range (GTK_SPIN_BUTTON(widget), 0, bound);
3876 widget = GHB_WIDGET (ud->builder, "PictureBottomCrop");
3877 gtk_spin_button_set_range (GTK_SPIN_BUTTON(widget), 0, bound);
3878 bound = tinfo->width / 2 - 2;
3879 widget = GHB_WIDGET (ud->builder, "PictureLeftCrop");
3880 gtk_spin_button_set_range (GTK_SPIN_BUTTON(widget), 0, bound);
3881 widget = GHB_WIDGET (ud->builder, "PictureRightCrop");
3882 gtk_spin_button_set_range (GTK_SPIN_BUTTON(widget), 0, bound);
3883 if (ghb_settings_get_boolean(ud->settings, "PictureAutoCrop"))
3885 ghb_ui_update(ud, "PictureTopCrop", ghb_int64_value(tinfo->crop[0]));
3886 ghb_ui_update(ud, "PictureBottomCrop", ghb_int64_value(tinfo->crop[1]));
3887 ghb_ui_update(ud, "PictureLeftCrop", ghb_int64_value(tinfo->crop[2]));
3888 ghb_ui_update(ud, "PictureRightCrop", ghb_int64_value(tinfo->crop[3]));
3892 G_MODULE_EXPORT void
3893 presets_list_selection_changed_cb(GtkTreeSelection *selection, signal_user_data_t *ud)
3895 GtkTreeModel *store;
3897 ghb_title_info_t tinfo;
3900 g_debug("presets_list_selection_changed_cb ()");
3901 widget = GHB_WIDGET (ud->builder, "presets_remove");
3902 if (gtk_tree_selection_get_selected(selection, &store, &iter))
3904 GtkTreePath *treepath;
3909 treepath = gtk_tree_model_get_path(store, &iter);
3910 indices = gtk_tree_path_get_indices(treepath);
3911 len = gtk_tree_path_get_depth(treepath);
3913 path = preset_path_from_indices(presetsPlist, indices, len);
3914 ghb_settings_take_value(ud->settings, "preset_selection", path);
3916 folder = ghb_presets_get_folder(presetsPlist, indices, len);
3919 ud->dont_clear_presets = TRUE;
3920 // Temporarily set the video_quality range to (0,100)
3921 // This is needed so the video_quality value does not get
3922 // truncated when set. The range will be readjusted below
3923 GtkWidget *qp = GHB_WIDGET(ud->builder, "VideoQualitySlider");
3924 gtk_range_set_range (GTK_RANGE(qp), 0, 100);
3925 gtk_scale_set_digits(GTK_SCALE(qp), 3);
3926 // Clear the audio list prior to changing the preset. Existing
3927 // audio can cause the container extension to be automatically
3928 // changed when it shouldn't be
3929 ghb_clear_audio_list(ud);
3930 ghb_set_preset_from_indices(ud, indices, len);
3931 gtk_tree_path_free(treepath);
3933 titleindex = ghb_settings_combo_int(ud->settings, "title");
3934 ghb_set_pref_audio(titleindex, ud);
3935 ghb_set_pref_subtitle(titleindex, ud);
3936 ghb_settings_set_boolean(ud->settings, "preset_modified", FALSE);
3937 if (ghb_get_title_info (&tinfo, titleindex))
3939 preset_update_title_deps(ud, &tinfo);
3941 ghb_set_scale (ud, GHB_PIC_KEEP_PAR);
3942 ud->dont_clear_presets = FALSE;
3944 gdouble vqmin, vqmax, step, page;
3948 ghb_vquality_range(ud, &vqmin, &vqmax, &step,
3949 &page, &digits, &inverted);
3950 gtk_range_set_range (GTK_RANGE(qp), vqmin, vqmax);
3951 gtk_range_set_increments (GTK_RANGE(qp), step, page);
3952 gtk_scale_set_digits(GTK_SCALE(qp), digits);
3953 gtk_range_set_inverted (GTK_RANGE(qp), inverted);
3957 GtkWidget *crop_widget;
3958 crop[0] = ghb_settings_get_int(ud->settings, "PictureTopCrop");
3959 crop[1] = ghb_settings_get_int(ud->settings, "PictureBottomCrop");
3960 crop[2] = ghb_settings_get_int(ud->settings, "PictureLeftCrop");
3961 crop[3] = ghb_settings_get_int(ud->settings, "PictureRightCrop");
3962 crop_widget = GHB_WIDGET (ud->builder, "crop_values");
3963 text = g_strdup_printf("%d:%d:%d:%d",
3964 crop[0], crop[1], crop[2], crop[3]);
3965 gtk_label_set_text (GTK_LABEL(crop_widget), text);
3968 gtk_widget_set_sensitive(widget, TRUE);
3972 g_debug("No selection??? Perhaps unselected.");
3973 gtk_widget_set_sensitive(widget, FALSE);
3978 ghb_clear_presets_selection(signal_user_data_t *ud)
3980 GtkTreeView *treeview;
3981 GtkTreeSelection *selection;
3983 if (ud->dont_clear_presets) return;
3984 g_debug("ghb_clear_presets_selection()");
3985 treeview = GTK_TREE_VIEW(GHB_WIDGET(ud->builder, "presets_list"));
3986 selection = gtk_tree_view_get_selection (treeview);
3987 gtk_tree_selection_unselect_all (selection);
3988 ghb_settings_set_boolean(ud->settings, "preset_modified", TRUE);
3991 G_MODULE_EXPORT void
3992 presets_frame_size_allocate_cb(GtkWidget *widget, GtkAllocation *allocation, signal_user_data_t *ud)
3994 GtkTreeView *treeview;
3995 GtkTreeSelection *selection;
3996 GtkTreeModel *store;
3999 treeview = GTK_TREE_VIEW(GHB_WIDGET(ud->builder, "presets_list"));
4000 selection = gtk_tree_view_get_selection(treeview);
4001 if (gtk_tree_selection_get_selected(selection, &store, &iter))
4004 path = gtk_tree_model_get_path (store, &iter);
4005 // Make the parent visible in scroll window if it is not.
4006 gtk_tree_view_scroll_to_cell (treeview, path, NULL, FALSE, 0, 0);
4007 gtk_tree_path_free(path);
4011 G_MODULE_EXPORT void
4012 presets_default_clicked_cb(GtkWidget *xwidget, signal_user_data_t *ud)
4017 g_debug("presets_default_clicked_cb ()");
4018 preset = ghb_settings_get_value(ud->settings, "preset_selection");
4019 indices = ghb_preset_indices_from_path(presetsPlist, preset, &len);
4022 if (!ghb_presets_get_folder(presetsPlist, indices, len))
4024 ghb_presets_list_clear_default(ud);
4025 presets_set_default(indices, len);
4026 ghb_presets_list_default(ud);
4032 G_MODULE_EXPORT void
4034 GtkCellRendererText *cell,
4037 signal_user_data_t *ud)
4039 GtkTreePath *treepath;
4040 GtkTreeStore *store;
4041 GtkTreeView *treeview;
4043 gint *indices, len, count;
4045 GValue *preset, *dest;
4047 g_debug("preset_edited_cb ()");
4048 g_debug("path (%s)", path);
4049 g_debug("text (%s)", text);
4051 preset = ghb_settings_get_value (ud->settings, "preset_selection");
4052 dest = ghb_array_value_new(MAX_NESTED_PRESET);
4053 count = ghb_array_len(preset);
4054 ghb_array_copy(dest, preset, count-1);
4055 ghb_array_append(dest, ghb_string_value_new(text));
4056 indices = ghb_preset_indices_from_path(presetsPlist, dest, &len);
4057 ghb_value_free(dest);
4058 if (indices != NULL)
4065 treeview = GTK_TREE_VIEW(GHB_WIDGET(ud->builder, "presets_list"));
4066 store = GTK_TREE_STORE(gtk_tree_view_get_model(treeview));
4067 treepath = gtk_tree_path_new_from_string (path);
4068 indices = gtk_tree_path_get_indices(treepath);
4069 len = gtk_tree_path_get_depth(treepath);
4070 gtk_tree_model_get_iter(GTK_TREE_MODEL(store), &iter, treepath);
4071 gtk_tree_store_set(store, &iter, 0, text, -1);
4073 dict = presets_get_dict(presetsPlist, indices, len);
4074 ghb_dict_insert(dict, g_strdup("PresetName"), ghb_string_value_new(text));
4076 gtk_tree_path_free (treepath);