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 "hb-backend.h"
25 #include "resources.h"
30 #define MAX_NESTED_PRESET 3
38 static GValue *presetsPlist = NULL;
39 static GValue *internalPlist = NULL;
40 static GValue *prefsPlist = NULL;
41 static gboolean prefs_modified = FALSE;
43 static const GValue* preset_dict_get_value(GValue *dict, const gchar *key);
44 static void store_plist(GValue *plist, const gchar *name);
45 static void store_presets(void);
47 // This only handle limited depth
49 ghb_tree_path_new_from_indices(gint *indices, gint len)
54 return gtk_tree_path_new_from_indices(
57 return gtk_tree_path_new_from_indices(
58 indices[0], indices[1], -1);
60 return gtk_tree_path_new_from_indices(
61 indices[0], indices[1], indices[2], -1);
63 return gtk_tree_path_new_from_indices(
64 indices[0], indices[1], indices[2], indices[3], -1);
66 return gtk_tree_path_new_from_indices(
67 indices[0], indices[1], indices[2], indices[3], indices[4], -1);
74 ghb_parse_preset_path(const gchar *path)
80 preset = ghb_array_value_new(MAX_NESTED_PRESET);
81 split = g_strsplit(path, "#", MAX_NESTED_PRESET);
82 for (ii = 0; split[ii] != NULL; ii++)
84 ghb_array_append(preset, ghb_string_value_new(split[ii]));
91 preset_path_from_indices(GValue *presets, gint *indices, gint len)
96 g_debug("preset_path_from_indices");
97 path = ghb_array_value_new(MAX_NESTED_PRESET);
98 for (ii = 0; ii < len; ii++)
104 count = ghb_array_len(presets);
105 if (indices[ii] >= count) break;
106 dict = ghb_array_get_nth(presets, indices[ii]);
107 name = ghb_dict_lookup(dict, "PresetName");
109 ghb_array_append(path, ghb_value_dup(name));
110 folder = ghb_value_boolean(preset_dict_get_value(dict, "Folder"));
113 presets = ghb_dict_lookup(dict, "ChildrenArray");
119 ghb_preset_path_string(const GValue *path)
126 gstr = g_string_new("");
129 count = ghb_array_len(path);
130 for (ii = 0; ii < count; ii++)
132 val = ghb_array_get_nth(path, ii);
133 str = ghb_value_string(val);
134 g_string_append(gstr, str);
136 g_string_append(gstr, "->");
140 str = g_string_free(gstr, FALSE);
145 dump_preset_path(const gchar *msg, const GValue *path)
150 debug_show_type (G_VALUE_TYPE(path));
151 str = ghb_preset_path_string(path);
152 g_message("%s path: (%s)", msg, str);
157 dump_preset_indices(const gchar *msg, gint *indices, gint len)
161 g_message("%s indices: len %d", msg, len);
162 for (ii = 0; ii < len; ii++)
164 printf("%d ", indices[ii]);
171 preset_path_cmp(const GValue *path1, const GValue *path2)
178 count = ghb_array_len(path1);
179 ii = ghb_array_len(path2);
182 for (ii = 0; ii < count; ii++)
184 val = ghb_array_get_nth(path1, ii);
185 str1 = ghb_value_string(val);
186 val = ghb_array_get_nth(path2, ii);
187 str2 = ghb_value_string(val);
188 result = strcmp(str1, str2);
199 presets_get_dict(GValue *presets, gint *indices, gint len)
201 gint ii, count, folder;
204 g_debug("presets_get_dict ()");
205 for (ii = 0; ii < len; ii++)
207 count = ghb_array_len(presets);
208 if (indices[ii] >= count) return NULL;
209 dict = ghb_array_get_nth(presets, indices[ii]);
212 folder = ghb_value_boolean(preset_dict_get_value(dict, "Folder"));
215 presets = ghb_dict_lookup(dict, "ChildrenArray");
224 presets_get_folder(GValue *presets, gint *indices, gint len)
226 gint ii, count, folder;
229 g_debug("presets_get_folder ()");
230 for (ii = 0; ii < len; ii++)
232 count = ghb_array_len(presets);
233 if (indices[ii] >= count) return NULL;
234 dict = ghb_array_get_nth(presets, indices[ii]);
235 folder = ghb_value_boolean(preset_dict_get_value(dict, "Folder"));
238 presets = ghb_dict_lookup(dict, "ChildrenArray");
246 plist_get_dict(GValue *presets, const gchar *name)
248 if (presets == NULL || name == NULL) return NULL;
249 return ghb_dict_lookup(presets, name);
253 preset_get_name(GValue *dict)
255 return g_value_get_string(preset_dict_get_value(dict, "PresetName"));
259 preset_folder_is_open(GValue *dict)
263 gval = preset_dict_get_value(dict, "FolderOpen");
265 return g_value_get_boolean(gval);
270 ghb_preset_folder(GValue *dict)
272 return ghb_value_int(preset_dict_get_value(dict, "Folder"));
276 ghb_preset_type(GValue *dict)
278 return ghb_value_int(preset_dict_get_value(dict, "Type"));
282 presets_remove_nth(GValue *presets, gint pos)
287 if (presets == NULL || pos < 0) return;
288 count = ghb_array_len(presets);
289 if (pos >= count) return;
290 dict = ghb_array_get_nth(presets, pos);
291 ghb_array_remove(presets, pos);
292 ghb_value_free(dict);
301 GValue *folder = NULL;
303 folder = presets_get_folder(presets, indices, len-1);
305 presets_remove_nth(folder, indices[len-1]);
308 g_warning("ghb_presets_remove (): internal preset lookup error");
321 GValue *folder = NULL;
323 folder = presets_get_folder(presets, indices, len-1);
325 ghb_array_replace(folder, indices[len-1], dict);
328 g_warning("ghb_presets_replace (): internal preset lookup error");
339 GValue *folder = NULL;
341 folder = presets_get_folder(presets, indices, len-1);
343 ghb_array_insert(folder, indices[len-1], dict);
346 g_warning("ghb_presets_insert (): internal preset lookup error");
351 presets_find_element(GValue *presets, const gchar *name)
356 g_debug("presets_find_element () (%s)", name);
357 if (presets == NULL || name == NULL) return -1;
358 count = ghb_array_len(presets);
359 for (ii = 0; ii < count; ii++)
362 dict = ghb_array_get_nth(presets, ii);
363 str = preset_get_name(dict);
364 if (strcmp(name, str) == 0)
373 single_find_pos(GValue *presets, const gchar *name, gint type)
376 gint count, ii, ptype, last;
378 if (presets == NULL || name == NULL) return -1;
379 last = count = ghb_array_len(presets);
380 for (ii = 0; ii < count; ii++)
383 dict = ghb_array_get_nth(presets, ii);
384 str = preset_get_name(dict);
385 ptype = ghb_value_int(preset_dict_get_value(dict, "Type"));
386 if (strcasecmp(name, str) <= 0 && ptype == type)
397 presets_find_pos(const GValue *path, gint type, gint *len)
403 gint *indices = NULL;
407 g_debug("presets_find_pos () ");
408 nested = presetsPlist;
409 count = ghb_array_len(path);
410 indices = g_malloc(MAX_NESTED_PRESET * sizeof(gint));
411 for (ii = 0; ii < count-1; ii++)
413 val = ghb_array_get_nth(path, ii);
414 name = g_value_get_string(val);
415 indices[ii] = presets_find_element(nested, name);
416 if (indices[ii] == -1) return NULL;
417 dict = ghb_array_get_nth(nested, indices[ii]);
418 folder = ghb_value_boolean(preset_dict_get_value(dict, "Folder"));
422 nested = ghb_dict_lookup(dict, "ChildrenArray");
428 name = g_value_get_string(ghb_array_get_nth(path, count-1));
429 indices[ii] = single_find_pos(nested, name, type);
437 preset_tree_depth(GValue *dict)
441 folder = ghb_value_boolean(preset_dict_get_value(dict, "Folder"));
448 presets = ghb_dict_lookup(dict, "ChildrenArray");
449 count = ghb_array_len(presets);
450 for (ii = 0; ii < count; ii++)
454 dict = ghb_array_get_nth(presets, ii);
455 tmp = preset_tree_depth(dict);
456 depth = MAX(depth, tmp);
467 preset_is_default(GValue *dict)
471 val = preset_dict_get_value(dict, "Default");
472 return ghb_value_boolean(val);
476 presets_clear_default(GValue *presets)
480 count = ghb_array_len(presets);
481 for (ii = 0; ii < count; ii++)
486 dict = ghb_array_get_nth(presets, ii);
487 folder = ghb_value_boolean(preset_dict_get_value(dict, "Folder"));
492 nested = ghb_dict_lookup(dict, "ChildrenArray");
493 presets_clear_default(nested);
497 if (preset_is_default(dict))
499 ghb_dict_insert(dict, g_strdup("Default"),
500 ghb_boolean_value_new(FALSE));
507 presets_find_default2(GValue *presets, gint *len)
512 count = ghb_array_len(presets);
513 for (ii = 0; ii < count; ii++)
518 dict = ghb_array_get_nth(presets, ii);
519 folder = ghb_value_boolean(preset_dict_get_value(dict, "Folder"));
525 nested = ghb_dict_lookup(dict, "ChildrenArray");
527 indices = presets_find_default2(nested, len);
538 if (preset_is_default(dict))
540 indices = g_malloc(MAX_NESTED_PRESET * sizeof(gint));
551 presets_find_default(GValue *presets, gint *len)
554 return presets_find_default2(presets, len);
558 ghb_preset_indices_from_path(
566 gint *indices = NULL;
571 g_debug("ghb_preset_indices_from_path () ");
573 count = ghb_array_len(path);
575 indices = g_malloc(MAX_NESTED_PRESET * sizeof(gint));
577 for (ii = 0; ii < count; ii++)
579 val = ghb_array_get_nth(path, ii);
580 name = g_value_get_string(val);
581 indices[ii] = presets_find_element(nested, name);
582 if (indices[ii] == -1)
589 dict = ghb_array_get_nth(nested, indices[ii]);
590 folder = ghb_value_boolean(preset_dict_get_value(dict, "Folder"));
596 nested = ghb_dict_lookup(dict, "ChildrenArray");
604 ghb_presets_get_type(
612 dict = presets_get_dict(presets, indices, len);
615 type = ghb_preset_type(dict);
619 g_warning("ghb_presets_get_type (): internal preset lookup error");
625 ghb_presets_get_folder(
631 gboolean folder = FALSE;
633 dict = presets_get_dict(presets, indices, len);
636 folder = ghb_preset_folder(dict);
640 g_warning("ghb_presets_get_folder (): internal preset lookup error");
646 presets_set_default(gint *indices, gint len)
650 g_debug("presets_set_default ()");
651 presets_clear_default(presetsPlist);
652 dict = presets_get_dict(presetsPlist, indices, len);
655 ghb_dict_insert(dict, g_strdup("Default"), ghb_boolean_value_new(TRUE));
661 presets_set_folder_open(gboolean open, gint *indices, gint len)
665 g_debug("presets_set_folder_open ()");
666 dict = presets_get_dict(presetsPlist, indices, len);
669 ghb_dict_insert(dict, g_strdup("FolderOpen"),
670 ghb_boolean_value_new(open));
674 // Used for sorting dictionaries.
676 key_cmp(gconstpointer a, gconstpointer b)
678 gchar *stra = (gchar*)a;
679 gchar *strb = (gchar*)b;
681 return strcmp(stra, strb);
685 preset_dict_get_value(GValue *dict, const gchar *key)
687 const GValue *gval = NULL;
691 gval = ghb_dict_lookup(dict, key);
693 if (internalPlist == NULL) return NULL;
696 dict = plist_get_dict(internalPlist, "Presets");
697 if (dict == NULL) return NULL;
698 gval = ghb_dict_lookup(dict, key);
704 ghb_presets_get_description(GValue *pdict)
708 if (pdict == NULL) return NULL;
709 desc = g_value_get_string(
710 preset_dict_get_value(pdict, "PresetDescription"));
711 if (desc[0] == 0) return NULL;
716 static void init_settings_from_dict(
717 GValue *dest, GValue *internal, GValue *dict);
720 init_settings_from_array(
728 count = ghb_array_len(array);
729 // The first element of the internal version is always the
730 // template for the allowed values
731 gval = ghb_array_get_nth(internal, 0);
732 for (ii = 0; ii < count; ii++)
735 val = ghb_array_get_nth(array, ii);
738 if (G_VALUE_TYPE(gval) == ghb_dict_get_type())
741 new_dict = ghb_dict_value_new();
742 ghb_array_append(dest, new_dict);
743 if (G_VALUE_TYPE(val) == ghb_dict_get_type())
744 init_settings_from_dict(new_dict, gval, val);
746 init_settings_from_dict(new_dict, gval, gval);
748 else if (G_VALUE_TYPE(gval) == ghb_array_get_type())
751 new_array = ghb_array_value_new(8);
752 ghb_array_append(dest, new_array);
753 if (G_VALUE_TYPE(val) == ghb_array_get_type())
754 init_settings_from_array(new_array, gval, val);
756 init_settings_from_array(new_array, gval, gval);
760 ghb_array_append(dest, val);
766 init_settings_from_dict(
775 ghb_dict_iter_init(&iter, internal);
776 // middle (void*) cast prevents gcc warning "defreferencing type-punned
777 // pointer will break strict-aliasing rules"
778 while (g_hash_table_iter_next(
779 &iter, (gpointer*)(void*)&key, (gpointer*)(void*)&gval))
783 val = ghb_dict_lookup(dict, key);
786 if (G_VALUE_TYPE(gval) == ghb_dict_get_type())
789 new_dict = ghb_dict_value_new();
790 ghb_settings_take_value(dest, key, new_dict);
791 if (G_VALUE_TYPE(val) == ghb_dict_get_type())
792 init_settings_from_dict(new_dict, gval, val);
794 init_settings_from_dict(new_dict, gval, gval);
796 else if (G_VALUE_TYPE(gval) == ghb_array_get_type())
799 new_array = ghb_array_value_new(8);
800 ghb_settings_take_value(dest, key, new_array);
801 if (G_VALUE_TYPE(val) == ghb_array_get_type())
802 init_settings_from_array(new_array, gval, val);
804 init_settings_from_array(new_array, gval, gval);
809 ghb_settings_set_value(dest, key, val);
816 signal_user_data_t *ud,
824 ghb_dict_iter_init(&iter, internal);
825 // middle (void*) cast prevents gcc warning "defreferencing type-punned
826 // pointer will break strict-aliasing rules"
827 while (g_hash_table_iter_next(
828 &iter, (gpointer*)(void*)&key, (gpointer*)(void*)&gval))
832 val = ghb_dict_lookup(dict, key);
835 ghb_ui_update(ud, key, val);
840 preset_to_ui(signal_user_data_t *ud, GValue *dict)
842 g_debug("preset_to_ui()\n");
843 // Initialize the ui from presets file.
844 GValue *internal, *hidden;
846 // Get key list from internal default presets. This way we do not
847 // load any unknown keys.
848 if (internalPlist == NULL) return;
849 internal = plist_get_dict(internalPlist, "Presets");
850 hidden = plist_get_dict(internalPlist, "XlatPresets");
851 // Setting a ui widget will cause the corresponding setting
852 // to be set, but it also triggers a callback that can
853 // have the side effect of using other settings values
854 // that have not yet been set. So set *all* settings first
855 // then update the ui.
856 init_settings_from_dict(ud->settings, internal, dict);
857 init_settings_from_dict(ud->settings, hidden, dict);
858 init_ui_from_dict(ud, internal, dict);
859 init_ui_from_dict(ud, hidden, dict);
863 ghb_settings_to_ui(signal_user_data_t *ud, GValue *dict)
865 init_ui_from_dict(ud, dict, dict);
868 static GValue *current_preset = NULL;
871 ghb_preset_is_custom()
875 if (current_preset == NULL) return FALSE;
876 val = preset_dict_get_value(current_preset, "Type");
877 return (ghb_value_int(val) == 1);
881 ghb_set_preset_from_indices(signal_user_data_t *ud, gint *indices, gint len)
884 gint fallback[2] = {0, -1};
887 dict = presets_get_dict(presetsPlist, indices, len);
892 dict = presets_get_dict(presetsPlist, indices, len);
896 preset_to_ui(ud, NULL);
897 current_preset = NULL;
904 current_preset = dict;
905 folder = ghb_value_boolean(preset_dict_get_value(dict, "Folder"));
907 preset_to_ui(ud, NULL);
909 preset_to_ui(ud, dict);
910 path = preset_path_from_indices(presetsPlist, indices, len);
911 ghb_settings_set_value(ud->settings, "preset", path);
912 ghb_value_free(path);
917 curr_preset_get_value(const gchar *key)
919 if (current_preset == NULL) return NULL;
920 return preset_dict_get_value(current_preset, key);
924 ghb_update_from_preset(
925 signal_user_data_t *ud,
930 g_debug("ghb_update_from_preset() %s", key);
931 gval = curr_preset_get_value(key);
934 ghb_ui_update(ud, key, gval);
944 GtkTreeView *treeview;
945 GtkTreeSelection *selection;
950 g_debug("ghb_select_preset2()");
951 treeview = GTK_TREE_VIEW(GHB_WIDGET(builder, "presets_list"));
952 selection = gtk_tree_view_get_selection (treeview);
953 store = gtk_tree_view_get_model (treeview);
954 path = ghb_tree_path_new_from_indices(indices, len);
957 if (gtk_tree_model_get_iter(store, &iter, path))
959 gtk_tree_selection_select_iter (selection, &iter);
963 if (gtk_tree_model_get_iter_first(store, &iter))
964 gtk_tree_selection_select_iter (selection, &iter);
966 gtk_tree_path_free(path);
971 ghb_select_preset(GtkBuilder *builder, const GValue *path)
975 g_debug("ghb_select_preset()");
976 indices = ghb_preset_indices_from_path(presetsPlist, path, &len);
979 ghb_select_preset2(builder, indices, len);
985 ghb_select_default_preset(GtkBuilder *builder)
989 g_debug("ghb_select_default_preset()");
990 indices = presets_find_default(presetsPlist, &len);
993 ghb_select_preset2(builder, indices, len);
999 ghb_get_user_config_dir(gchar *subdir)
1004 dir = g_get_user_config_dir();
1005 if (!g_file_test(dir, G_FILE_TEST_IS_DIR))
1007 dir = g_get_home_dir();
1008 config = g_strdup_printf ("%s/.ghb", dir);
1009 if (!g_file_test(config, G_FILE_TEST_IS_DIR))
1010 g_mkdir (config, 0755);
1014 config = g_strdup_printf ("%s/ghb", dir);
1015 if (!g_file_test(config, G_FILE_TEST_IS_DIR))
1016 g_mkdir (config, 0755);
1023 split = g_strsplit(subdir, "/", -1);
1024 for (ii = 0; split[ii] != NULL; ii++)
1028 tmp = g_strdup_printf ("%s/%s", config, split[ii]);
1031 if (!g_file_test(config, G_FILE_TEST_IS_DIR))
1032 g_mkdir (config, 0755);
1039 store_plist(GValue *plist, const gchar *name)
1041 gchar *config, *path;
1044 config = ghb_get_user_config_dir(NULL);
1045 path = g_strdup_printf ("%s/%s", config, name);
1046 file = g_fopen(path, "w");
1049 ghb_plist_write(file, plist);
1054 load_plist(const gchar *name)
1056 gchar *config, *path;
1057 GValue *plist = NULL;
1059 config = ghb_get_user_config_dir(NULL);
1060 path = g_strdup_printf ("%s/%s", config, name);
1061 if (g_file_test(path, G_FILE_TEST_IS_REGULAR))
1063 plist = ghb_plist_parse_file(path);
1071 remove_plist(const gchar *name)
1073 gchar *config, *path;
1075 config = ghb_get_user_config_dir(NULL);
1076 path = g_strdup_printf ("%s/%s", config, name);
1077 if (g_file_test(path, G_FILE_TEST_IS_REGULAR))
1085 static gboolean prefs_initializing = FALSE;
1088 ghb_prefs_to_ui(signal_user_data_t *ud)
1093 GValue *internal, *dict;
1094 GHashTableIter iter;
1097 g_debug("ghb_prefs_to_ui");
1098 prefs_initializing = TRUE;
1100 // Setting a ui widget will cause the corresponding setting
1101 // to be set, but it also triggers a callback that can
1102 // have the side effect of using other settings values
1103 // that have not yet been set. So set *all* settings first
1104 // then update the ui.
1105 internal = plist_get_dict(internalPlist, "Initialization");
1106 ghb_dict_iter_init(&iter, internal);
1107 // middle (void*) cast prevents gcc warning "defreferencing type-punned
1108 // pointer will break strict-aliasing rules"
1109 while (g_hash_table_iter_next(
1110 &iter, (gpointer*)(void*)&key, (gpointer*)(void*)&gval))
1112 ghb_ui_update(ud, key, gval);
1115 dict = plist_get_dict(prefsPlist, "Preferences");
1116 internal = plist_get_dict(internalPlist, "Preferences");
1117 ghb_dict_iter_init(&iter, internal);
1118 // middle (void*) cast prevents gcc warning "defreferencing type-punned
1119 // pointer will break strict-aliasing rules"
1120 while (g_hash_table_iter_next(
1121 &iter, (gpointer*)(void*)&key, (gpointer*)(void*)&gval))
1123 const GValue *value = NULL;
1125 value = ghb_dict_lookup(dict, key);
1128 ghb_settings_set_value(ud->settings, key, value);
1130 internal = plist_get_dict(internalPlist, "Preferences");
1131 ghb_dict_iter_init(&iter, internal);
1132 // middle (void*) cast prevents gcc warning "defreferencing type-punned
1133 // pointer will break strict-aliasing rules"
1134 while (g_hash_table_iter_next(
1135 &iter, (gpointer*)(void*)&key, (gpointer*)(void*)&gval))
1137 const GValue *value = NULL;
1139 value = ghb_dict_lookup(dict, key);
1142 ghb_ui_update(ud, key, value);
1145 val = ghb_settings_get_value(ud->settings, "show_presets");
1146 ghb_ui_update(ud, "show_presets", val);
1147 if (ghb_settings_get_boolean(ud->settings, "hbfd_feature"))
1150 val = ghb_settings_get_value(ud->settings, "hbfd");
1151 ghb_ui_update(ud, "hbfd", val);
1152 action = GHB_ACTION (ud->builder, "hbfd");
1153 gtk_action_set_visible(action, TRUE);
1157 ghb_ui_update(ud, "hbfd", ghb_int64_value(0));
1159 gval = ghb_settings_get_value(ud->settings, "default_source");
1160 ghb_settings_set_value (ud->settings, "source", gval);
1162 str = ghb_settings_get_string(ud->settings, "destination_dir");
1163 ghb_ui_update(ud, "dest_dir", ghb_string_value(str));
1165 gchar *file = g_strdup_printf ("new_video.mp4");
1166 ghb_ui_update(ud, "dest_file", ghb_string_value(file));
1170 prefs_initializing = FALSE;
1174 ghb_prefs_save(GValue *settings)
1178 GHashTableIter iter;
1180 const GValue *value;
1182 if (prefs_initializing) return;
1183 dict = plist_get_dict(internalPlist, "Preferences");
1184 if (dict == NULL) return;
1185 pref_dict = plist_get_dict(prefsPlist, "Preferences");
1186 if (pref_dict == NULL) return;
1187 ghb_dict_iter_init(&iter, dict);
1188 // middle (void*) cast prevents gcc warning "defreferencing type-punned
1189 // pointer will break strict-aliasing rules"
1190 while (g_hash_table_iter_next(
1191 &iter, (gpointer*)(void*)&key, (gpointer*)(void*)&value))
1193 value = ghb_settings_get_value(settings, key);
1196 ghb_dict_insert(pref_dict, g_strdup(key), ghb_value_dup(value));
1199 store_plist(prefsPlist, "preferences");
1200 prefs_modified = FALSE;
1204 ghb_pref_set(GValue *settings, const gchar *key)
1206 const GValue *value, *value2;
1208 if (prefs_initializing) return;
1209 value = ghb_settings_get_value(settings, key);
1213 dict = plist_get_dict(prefsPlist, "Preferences");
1214 if (dict == NULL) return;
1215 value2 = ghb_dict_lookup(dict, key);
1216 if (ghb_value_cmp(value, value2) != 0)
1218 ghb_dict_insert(dict, g_strdup(key), ghb_value_dup(value));
1219 store_plist(prefsPlist, "preferences");
1220 prefs_modified = TRUE;
1226 ghb_pref_save(GValue *settings, const gchar *key)
1228 const GValue *value, *value2;
1230 if (prefs_initializing) return;
1231 value = ghb_settings_get_value(settings, key);
1235 dict = plist_get_dict(prefsPlist, "Preferences");
1236 if (dict == NULL) return;
1237 value2 = ghb_dict_lookup(dict, key);
1238 if (ghb_value_cmp(value, value2) != 0)
1240 ghb_dict_insert(dict, g_strdup(key), ghb_value_dup(value));
1241 store_plist(prefsPlist, "preferences");
1242 prefs_modified = FALSE;
1248 ghb_prefs_store(void)
1252 store_plist(prefsPlist, "preferences");
1253 prefs_modified = FALSE;
1258 ghb_settings_init(signal_user_data_t *ud)
1261 GHashTableIter iter;
1266 g_debug("ghb_settings_init");
1267 prefs_initializing = TRUE;
1269 internalPlist = ghb_resource_get("internal-defaults");
1270 // Setting a ui widget will cause the corresponding setting
1271 // to be set, but it also triggers a callback that can
1272 // have the side effect of using other settings values
1273 // that have not yet been set. So set *all* settings first
1274 // then update the ui.
1275 internal = plist_get_dict(internalPlist, "Initialization");
1276 ghb_dict_iter_init(&iter, internal);
1277 // middle (void*) cast prevents gcc warning "defreferencing type-punned
1278 // pointer will break strict-aliasing rules"
1279 while (g_hash_table_iter_next(
1280 &iter, (gpointer*)(void*)&key, (gpointer*)(void*)&gval))
1282 ghb_settings_set_value(ud->settings, key, gval);
1285 internal = plist_get_dict(internalPlist, "Presets");
1286 ghb_dict_iter_init(&iter, internal);
1287 // middle (void*) cast prevents gcc warning "defreferencing type-punned
1288 // pointer will break strict-aliasing rules"
1289 while (g_hash_table_iter_next(
1290 &iter, (gpointer*)(void*)&key, (gpointer*)(void*)&gval))
1292 ghb_settings_set_value(ud->settings, key, gval);
1295 internal = plist_get_dict(internalPlist, "Preferences");
1296 ghb_dict_iter_init(&iter, internal);
1297 // middle (void*) cast prevents gcc warning "defreferencing type-punned
1298 // pointer will break strict-aliasing rules"
1299 while (g_hash_table_iter_next(
1300 &iter, (gpointer*)(void*)&key, (gpointer*)(void*)&gval))
1302 ghb_settings_set_value(ud->settings, key, gval);
1304 prefs_initializing = FALSE;
1308 ghb_settings_close()
1311 ghb_value_free(internalPlist);
1313 ghb_value_free(presetsPlist);
1315 ghb_value_free(prefsPlist);
1319 ghb_prefs_load(signal_user_data_t *ud)
1321 GValue *dict, *internal;
1322 GHashTableIter iter;
1324 GValue *gval, *path;
1326 g_debug("ghb_prefs_load");
1327 prefsPlist = load_plist("preferences");
1328 if (prefsPlist == NULL)
1329 prefsPlist = ghb_dict_value_new();
1330 dict = plist_get_dict(prefsPlist, "Preferences");
1331 internal = plist_get_dict(internalPlist, "Preferences");
1332 if (dict == NULL && internal)
1334 dict = ghb_dict_value_new();
1335 ghb_dict_insert(prefsPlist, g_strdup("Preferences"), dict);
1337 // Get defaults from internal defaults
1338 ghb_dict_iter_init(&iter, internal);
1339 // middle (void*) cast prevents gcc warning "defreferencing type-punned
1340 // pointer will break strict-aliasing rules"
1341 while (g_hash_table_iter_next(
1342 &iter, (gpointer*)(void*)&key, (gpointer*)(void*)&gval))
1344 ghb_dict_insert(dict, g_strdup(key), ghb_value_dup(gval));
1346 const gchar *dir = g_get_user_special_dir (G_USER_DIRECTORY_VIDEOS);
1351 ghb_dict_insert(dict,
1352 g_strdup("destination_dir"), ghb_value_dup(ghb_string_value(dir)));
1353 store_plist(prefsPlist, "preferences");
1355 // Read legacy default_preset preference and update accordingly
1356 path = ghb_dict_lookup(dict, "default_preset");
1361 if (G_VALUE_TYPE(path) == G_TYPE_STRING)
1365 path = ghb_array_value_new(1);
1366 ghb_array_append(path, ghb_value_dup(str));
1367 indices = ghb_preset_indices_from_path(presetsPlist, path, &len);
1368 ghb_value_free(path);
1371 indices = ghb_preset_indices_from_path(presetsPlist, path, &len);
1375 presets_set_default(indices, len);
1378 ghb_dict_remove(dict, "default_preset");
1379 store_plist(prefsPlist, "preferences");
1384 get_preset_color(gint type, gboolean folder)
1388 if (type == PRESETS_CUSTOM)
1408 ghb_presets_list_init(
1409 signal_user_data_t *ud,
1413 GtkTreeView *treeview;
1414 GtkTreeIter iter, titer, *piter;
1416 GtkTreeStore *store;
1417 const gchar *preset;
1418 GtkTreePath *parent_path;
1419 const gchar *description;
1424 GValue *presets = NULL;
1426 g_debug("ghb_presets_list_init ()");
1427 more_indices = g_malloc((len+1)*sizeof(gint));
1428 memcpy(more_indices, indices, len*sizeof(gint));
1429 presets = presets_get_folder(presetsPlist, indices, len);
1430 if (presets == NULL)
1432 g_warning("Failed to find parent folder when adding child.");
1435 count = ghb_array_len(presets);
1436 treeview = GTK_TREE_VIEW(GHB_WIDGET(ud->builder, "presets_list"));
1437 store = GTK_TREE_STORE(gtk_tree_view_get_model(treeview));
1438 parent_path = ghb_tree_path_new_from_indices(indices, len);
1441 gtk_tree_model_get_iter(GTK_TREE_MODEL(store), &titer, parent_path);
1443 gtk_tree_path_free(parent_path);
1449 for (ii = 0; ii < count; ii++)
1455 // Additional settings, add row
1456 dict = ghb_array_get_nth(presets, ii);
1457 preset = preset_get_name(dict);
1458 more_indices[len] = ii;
1459 def = preset_is_default(dict);
1461 description = ghb_presets_get_description(dict);
1462 gtk_tree_store_append(store, &iter, piter);
1463 type = ghb_preset_type(dict);
1464 folder = ghb_preset_folder(dict);
1465 color = get_preset_color(type, folder);
1466 gtk_tree_store_set(store, &iter, 0, preset,
1477 if (gtk_tree_model_iter_parent(
1478 GTK_TREE_MODEL(store), &ppiter, piter))
1480 path = gtk_tree_model_get_path(GTK_TREE_MODEL(store), &ppiter);
1481 gtk_tree_view_expand_row(treeview, path, FALSE);
1482 gtk_tree_path_free(path);
1484 path = gtk_tree_model_get_path(GTK_TREE_MODEL(store), piter);
1485 gtk_tree_view_expand_row(treeview, path, FALSE);
1486 gtk_tree_path_free(path);
1490 ghb_presets_list_init(ud, more_indices, len+1);
1491 if (preset_folder_is_open(dict))
1497 path = gtk_tree_model_get_path(GTK_TREE_MODEL(store), piter);
1498 gtk_tree_view_expand_row(treeview, path, FALSE);
1499 gtk_tree_path_free(path);
1501 path = gtk_tree_model_get_path(GTK_TREE_MODEL(store), &iter);
1502 gtk_tree_view_expand_row(treeview, path, FALSE);
1503 gtk_tree_path_free(path);
1507 g_free(more_indices);
1511 presets_list_update_item(
1512 signal_user_data_t *ud,
1516 GtkTreeView *treeview;
1517 GtkTreeStore *store;
1519 GtkTreePath *treepath;
1521 const gchar *description;
1523 gboolean def, folder;
1527 g_debug("presets_list_update_item ()");
1528 dict = presets_get_dict(presetsPlist, indices, len);
1531 treeview = GTK_TREE_VIEW(GHB_WIDGET(ud->builder, "presets_list"));
1532 store = GTK_TREE_STORE(gtk_tree_view_get_model(treeview));
1533 treepath = ghb_tree_path_new_from_indices(indices, len);
1534 gtk_tree_model_get_iter(GTK_TREE_MODEL(store), &iter, treepath);
1535 // Additional settings, add row
1536 name = preset_get_name(dict);
1537 def = preset_is_default(dict);
1539 description = ghb_presets_get_description(dict);
1540 type = ghb_preset_type(dict);
1541 folder = ghb_preset_folder(dict);
1542 color = get_preset_color(type, folder);
1543 gtk_tree_store_set(store, &iter, 0, name,
1551 ghb_presets_list_init(ud, indices, len);
1556 presets_list_insert(
1557 signal_user_data_t *ud,
1561 GtkTreeView *treeview;
1562 GtkTreeIter iter, titer, *piter;
1563 GtkTreeStore *store;
1564 const gchar *preset;
1565 const gchar *description;
1567 gboolean def, folder;
1570 GtkTreePath *parent_path;
1574 g_debug("presets_list_insert ()");
1575 treeview = GTK_TREE_VIEW(GHB_WIDGET(ud->builder, "presets_list"));
1576 store = GTK_TREE_STORE(gtk_tree_view_get_model(treeview));
1577 presets = presets_get_folder(presetsPlist, indices, len-1);
1578 if (presets == NULL)
1580 g_warning("Failed to find parent folder while adding child.");
1583 parent_path = ghb_tree_path_new_from_indices(indices, len-1);
1586 gtk_tree_model_get_iter(GTK_TREE_MODEL(store), &titer, parent_path);
1588 gtk_tree_path_free(parent_path);
1594 count = ghb_array_len(presets);
1595 if (indices[len-1] >= count)
1597 // Additional settings, add row
1598 dict = ghb_array_get_nth(presets, indices[len-1]);
1599 preset = preset_get_name(dict);
1600 def = preset_is_default(dict);
1602 description = ghb_presets_get_description(dict);
1603 gtk_tree_store_insert(store, &iter, piter, indices[len-1]);
1604 type = ghb_preset_type(dict);
1605 folder = ghb_preset_folder(dict);
1606 color = get_preset_color(type, folder);
1607 gtk_tree_store_set(store, &iter, 0, preset,
1615 ghb_presets_list_init(ud, indices, len);
1620 presets_list_remove(
1621 signal_user_data_t *ud,
1625 GtkTreeView *treeview;
1626 GtkTreePath *treepath;
1628 GtkTreeStore *store;
1630 g_debug("presets_list_remove ()");
1631 treeview = GTK_TREE_VIEW(GHB_WIDGET(ud->builder, "presets_list"));
1632 store = GTK_TREE_STORE(gtk_tree_view_get_model(treeview));
1633 treepath = ghb_tree_path_new_from_indices(indices, len);
1636 if (gtk_tree_model_get_iter(GTK_TREE_MODEL(store), &iter, treepath))
1637 gtk_tree_store_remove(store, &iter);
1638 gtk_tree_path_free(treepath);
1643 remove_std_presets(signal_user_data_t *ud)
1648 count = ghb_array_len(presetsPlist);
1649 for (ii = count-1; ii >= 0; ii--)
1654 dict = ghb_array_get_nth(presetsPlist, ii);
1655 ptype = ghb_value_int(preset_dict_get_value(dict, "Type"));
1656 if (ptype == PRESETS_BUILTIN)
1658 if (ghb_presets_remove(presetsPlist, &indices, 1))
1660 presets_list_remove(ud, &indices, 1);
1667 ghb_save_queue(GValue *queue)
1669 store_plist(queue, "queue");
1675 return load_plist("queue");
1679 ghb_remove_queue_file()
1681 remove_plist("queue");
1690 static value_map_t vcodec_xlat[] =
1692 {"MPEG-4 (FFmpeg)", "ffmpeg"},
1693 {"MPEG-4 (XviD)", "xvid"},
1694 {"H.264 (x264)", "x264"},
1695 {"VP3 (Theora)", "theora"},
1699 static value_map_t acodec_xlat[] =
1701 {"AAC (faac)", "faac"},
1702 {"AC3 Passthru", "ac3"},
1703 {"MP3 (lame)", "lame"},
1704 {"Vorbis (vorbis)", "vorbis"},
1708 value_map_t container_xlat[] =
1710 {"MP4 file", "mp4"},
1711 {"M4V file", "m4v"},
1712 {"MKV file", "mkv"},
1713 {"AVI file", "avi"},
1714 {"OGM file", "ogm"},
1718 value_map_t framerate_xlat[] =
1720 {"Same as source", "source"},
1725 {"23.976", "23.976"},
1732 value_map_t samplerate_xlat[] =
1743 value_map_t mix_xlat[] =
1746 {"Stereo", "stereo"},
1747 {"Dolby Surround", "dpl1"},
1748 {"Dolby Pro Logic II", "dpl2"},
1749 {"6-channel discrete", "6ch"},
1750 {"AC3 Passthru", "none"},
1754 value_map_t deint_xlat[] =
1764 value_map_t denoise_xlat[] =
1774 value_map_t detel_xlat[] =
1782 value_map_t decomb_xlat[] =
1790 extern iso639_lang_t ghb_language_table[];
1793 export_lang_xlat2(GValue *lin_val)
1797 if (lin_val == NULL) return NULL;
1801 str = ghb_value_string(lin_val);
1802 for (ii = 0; ghb_language_table[ii].eng_name; ii++)
1804 if (strcmp(str, ghb_language_table[ii].iso639_2) == 0)
1806 gval = ghb_string_value_new(ghb_language_table[ii].eng_name);
1811 g_debug("Can't map language value: (%s)", str);
1817 export_subtitle_xlat2(GValue *lin_val)
1822 if (lin_val == NULL) return NULL;
1823 str = ghb_value_string(lin_val);
1824 if (strcmp(str, "none") == 0)
1826 gval = ghb_string_value_new("None");
1828 else if (strcmp(str, "auto") == 0)
1830 gval = ghb_string_value_new("Autoselect");
1834 gval = export_lang_xlat2(lin_val);
1841 import_lang_xlat2(GValue *mac_val)
1845 if (mac_val == NULL) return NULL;
1849 str = ghb_value_string(mac_val);
1850 for (ii = 0; ghb_language_table[ii].eng_name; ii++)
1852 if (strcmp(str, ghb_language_table[ii].eng_name) == 0)
1854 gval = ghb_string_value_new(ghb_language_table[ii].iso639_2);
1859 g_debug("Can't map language value: (%s)", str);
1865 import_subtitle_xlat2(GValue *mac_val)
1870 if (mac_val == NULL) return NULL;
1871 str = ghb_value_string(mac_val);
1872 if (strcmp(str, "None") == 0)
1874 gval = ghb_string_value_new("none");
1876 else if (strcmp(str, "Autoselect") == 0)
1878 gval = ghb_string_value_new("auto");
1882 gval = import_lang_xlat2(mac_val);
1889 export_audio_track_xlat2(GValue *lin_val)
1892 GValue *gval = NULL;
1894 if (lin_val == NULL) return NULL;
1895 str = ghb_value_string(lin_val);
1896 if (strcmp(str, "none") == 0)
1898 gval = ghb_int_value_new(1);
1902 gint val = ghb_value_int(lin_val) + 1;
1903 gval = ghb_int_value_new(val);
1910 import_audio_track_xlat2(GValue *mac_val)
1916 if (mac_val == NULL) return NULL;
1917 val = ghb_value_int(mac_val);
1926 str = g_strdup_printf("%d", val);
1927 gval = ghb_string_value_new(str);
1933 export_value_xlat2(value_map_t *value_map, GValue *lin_val, GType mac_type)
1937 if (lin_val == NULL) return NULL;
1942 str = ghb_value_string(lin_val);
1943 for (ii = 0; value_map[ii].mac_val; ii++)
1945 if (strcmp(str, value_map[ii].lin_val) == 0)
1947 sval = ghb_string_value_new(value_map[ii].mac_val);
1949 gval = ghb_value_new(mac_type);
1950 if (!g_value_transform(sval, gval))
1952 g_warning("can't transform");
1953 ghb_value_free(gval);
1954 ghb_value_free(sval);
1957 ghb_value_free(sval);
1961 g_debug("Can't map value: (%s)", str);
1967 export_value_xlat(GValue *dict)
1969 GValue *lin_val, *gval;
1972 key = "VideoEncoder";
1973 lin_val = ghb_dict_lookup(dict, key);
1974 gval = export_value_xlat2(vcodec_xlat, lin_val, G_TYPE_STRING);
1976 ghb_dict_insert(dict, g_strdup(key), gval);
1978 lin_val = ghb_dict_lookup(dict, key);
1979 gval = export_value_xlat2(container_xlat, lin_val, G_TYPE_STRING);
1981 ghb_dict_insert(dict, g_strdup(key), gval);
1982 key = "VideoFramerate";
1983 lin_val = ghb_dict_lookup(dict, key);
1984 gval = export_value_xlat2(framerate_xlat, lin_val, G_TYPE_STRING);
1986 ghb_dict_insert(dict, g_strdup(key), gval);
1987 key = "PictureDetelecine";
1988 lin_val = ghb_dict_lookup(dict, key);
1989 gval = export_value_xlat2(detel_xlat, lin_val, G_TYPE_INT);
1991 ghb_dict_insert(dict, g_strdup(key), gval);
1992 key = "PictureDecomb";
1993 lin_val = ghb_dict_lookup(dict, key);
1994 gval = export_value_xlat2(decomb_xlat, lin_val, G_TYPE_INT);
1996 ghb_dict_insert(dict, g_strdup(key), gval);
1997 key = "PictureDeinterlace";
1998 lin_val = ghb_dict_lookup(dict, key);
1999 gval = export_value_xlat2(deint_xlat, lin_val, G_TYPE_INT);
2001 ghb_dict_insert(dict, g_strdup(key), gval);
2002 key = "PictureDenoise";
2003 lin_val = ghb_dict_lookup(dict, key);
2004 gval = export_value_xlat2(denoise_xlat, lin_val, G_TYPE_INT);
2006 ghb_dict_insert(dict, g_strdup(key), gval);
2008 lin_val = ghb_dict_lookup(dict, key);
2009 gval = export_subtitle_xlat2(lin_val);
2011 ghb_dict_insert(dict, g_strdup(key), gval);
2017 alist = ghb_dict_lookup(dict, "AudioList");
2018 count = ghb_array_len(alist);
2019 for (ii = 0; ii < count; ii++)
2021 adict = ghb_array_get_nth(alist, ii);
2023 lin_val = ghb_dict_lookup(adict, key);
2024 gval = export_audio_track_xlat2(lin_val);
2026 ghb_dict_insert(adict, g_strdup(key), gval);
2027 key = "AudioEncoder";
2028 lin_val = ghb_dict_lookup(adict, key);
2029 gval = export_value_xlat2(acodec_xlat, lin_val, G_TYPE_STRING);
2031 ghb_dict_insert(adict, g_strdup(key), gval);
2032 key = "AudioSamplerate";
2033 lin_val = ghb_dict_lookup(adict, key);
2034 gval = export_value_xlat2(samplerate_xlat, lin_val, G_TYPE_STRING);
2036 ghb_dict_insert(adict, g_strdup(key), gval);
2037 key = "AudioMixdown";
2038 lin_val = ghb_dict_lookup(adict, key);
2039 gval = export_value_xlat2(mix_xlat, lin_val, G_TYPE_STRING);
2041 ghb_dict_insert(adict, g_strdup(key), gval);
2049 value_map_t *value_map,
2053 GValue *gval, *def_val;
2055 if (mac_val == NULL) return NULL;
2056 def_val = ghb_dict_lookup(defaults, key);
2063 str = ghb_value_string(mac_val);
2064 for (ii = 0; value_map[ii].mac_val; ii++)
2066 if (strcmp(str, value_map[ii].mac_val) == 0)
2068 sval = ghb_string_value_new(value_map[ii].lin_val);
2070 gval = ghb_value_new(G_VALUE_TYPE(def_val));
2071 if (!g_value_transform(sval, gval))
2073 g_warning("can't transform");
2074 ghb_value_free(gval);
2075 ghb_value_free(sval);
2078 ghb_value_free(sval);
2082 //g_warning("Can't map value: (%s)", str);
2087 g_warning("Bad key: (%s)", key);
2094 import_value_xlat(GValue *dict)
2096 GValue *defaults, *mac_val, *gval;
2099 defaults = plist_get_dict(internalPlist, "Presets");
2100 key = "VideoEncoder";
2101 mac_val = ghb_dict_lookup(dict, key);
2102 gval = import_value_xlat2(defaults, vcodec_xlat, key, mac_val);
2104 ghb_dict_insert(dict, g_strdup(key), gval);
2106 mac_val = ghb_dict_lookup(dict, key);
2107 gval = import_value_xlat2(defaults, container_xlat, key, mac_val);
2109 ghb_dict_insert(dict, g_strdup(key), gval);
2110 key = "VideoFramerate";
2111 mac_val = ghb_dict_lookup(dict, key);
2112 gval = import_value_xlat2(defaults, framerate_xlat, key, mac_val);
2114 ghb_dict_insert(dict, g_strdup(key), gval);
2115 key = "PictureDetelecine";
2116 mac_val = ghb_dict_lookup(dict, key);
2117 gval = import_value_xlat2(defaults, detel_xlat, key, mac_val);
2119 ghb_dict_insert(dict, g_strdup(key), gval);
2120 key = "PictureDecomb";
2121 mac_val = ghb_dict_lookup(dict, key);
2122 gval = import_value_xlat2(defaults, decomb_xlat, key, mac_val);
2124 ghb_dict_insert(dict, g_strdup(key), gval);
2125 key = "PictureDeinterlace";
2126 mac_val = ghb_dict_lookup(dict, key);
2127 gval = import_value_xlat2(defaults, deint_xlat, key, mac_val);
2129 ghb_dict_insert(dict, g_strdup(key), gval);
2130 key = "PictureDenoise";
2131 mac_val = ghb_dict_lookup(dict, key);
2132 gval = import_value_xlat2(defaults, denoise_xlat, key, mac_val);
2134 ghb_dict_insert(dict, g_strdup(key), gval);
2136 mac_val = ghb_dict_lookup(dict, key);
2137 gval = import_subtitle_xlat2(mac_val);
2139 ghb_dict_insert(dict, g_strdup(key), gval);
2147 adeflist = ghb_dict_lookup(dict, "AudioList");
2150 adefaults = ghb_array_get_nth(adeflist, 0);
2151 alist = ghb_dict_lookup(dict, "AudioList");
2152 count = ghb_array_len(alist);
2153 for (ii = 0; ii < count; ii++)
2155 adict = ghb_array_get_nth(alist, ii);
2157 mac_val = ghb_dict_lookup(adict, key);
2158 gval = import_audio_track_xlat2(mac_val);
2160 ghb_dict_insert(adict, g_strdup(key), gval);
2161 key = "AudioEncoder";
2162 mac_val = ghb_dict_lookup(adict, key);
2163 gval = import_value_xlat2(adefaults, acodec_xlat, key, mac_val);
2165 ghb_dict_insert(adict, g_strdup(key), gval);
2166 key = "AudioSamplerate";
2167 mac_val = ghb_dict_lookup(adict, key);
2168 gval = import_value_xlat2(adefaults, samplerate_xlat, key, mac_val);
2170 ghb_dict_insert(adict, g_strdup(key), gval);
2171 key = "AudioMixdown";
2172 mac_val = ghb_dict_lookup(adict, key);
2173 gval = import_value_xlat2(adefaults, mix_xlat, key, mac_val);
2175 ghb_dict_insert(adict, g_strdup(key), gval);
2181 import_xlat_preset(GValue *dict)
2188 g_debug("import_xlat_preset ()");
2189 uses_max = ghb_value_boolean(
2190 preset_dict_get_value(dict, "UsesMaxPictureSettings"));
2191 uses_pic = ghb_value_int(
2192 preset_dict_get_value(dict, "UsesPictureSettings"));
2193 par = ghb_value_int(preset_dict_get_value(dict, "PicturePAR"));
2194 vqtype = ghb_value_int(preset_dict_get_value(dict, "VideoQualityType"));
2196 if (uses_max || uses_pic == 2)
2198 ghb_dict_insert(dict, g_strdup("autoscale"),
2199 ghb_boolean_value_new(TRUE));
2205 ghb_dict_insert(dict, g_strdup("anamorphic"),
2206 ghb_boolean_value_new(FALSE));
2207 if (ghb_dict_lookup(dict, "ModDimensions") == NULL)
2208 ghb_dict_insert(dict, g_strdup("ModDimensions"),
2209 ghb_boolean_value_new(TRUE));
2213 ghb_dict_insert(dict, g_strdup("anamorphic"),
2214 ghb_boolean_value_new(TRUE));
2215 ghb_dict_insert(dict, g_strdup("ModDimensions"),
2216 ghb_boolean_value_new(FALSE));
2220 ghb_dict_insert(dict, g_strdup("anamorphic"),
2221 ghb_boolean_value_new(TRUE));
2222 ghb_dict_insert(dict, g_strdup("ModDimensions"),
2223 ghb_boolean_value_new(TRUE));
2227 ghb_dict_insert(dict, g_strdup("anamorphic"),
2228 ghb_boolean_value_new(TRUE));
2229 ghb_dict_insert(dict, g_strdup("ModDimensions"),
2230 ghb_boolean_value_new(TRUE));
2233 // VideoQualityType/0/1/2 - vquality_type_/target/bitrate/constant
2238 ghb_dict_insert(dict, g_strdup("vquality_type_target"),
2239 ghb_boolean_value_new(TRUE));
2240 ghb_dict_insert(dict, g_strdup("vquality_type_bitrate"),
2241 ghb_boolean_value_new(FALSE));
2242 ghb_dict_insert(dict, g_strdup("vquality_type_constant"),
2243 ghb_boolean_value_new(FALSE));
2247 ghb_dict_insert(dict, g_strdup("vquality_type_target"),
2248 ghb_boolean_value_new(FALSE));
2249 ghb_dict_insert(dict, g_strdup("vquality_type_bitrate"),
2250 ghb_boolean_value_new(TRUE));
2251 ghb_dict_insert(dict, g_strdup("vquality_type_constant"),
2252 ghb_boolean_value_new(FALSE));
2256 ghb_dict_insert(dict, g_strdup("vquality_type_target"),
2257 ghb_boolean_value_new(FALSE));
2258 ghb_dict_insert(dict, g_strdup("vquality_type_bitrate"),
2259 ghb_boolean_value_new(FALSE));
2260 ghb_dict_insert(dict, g_strdup("vquality_type_constant"),
2261 ghb_boolean_value_new(TRUE));
2265 ghb_dict_insert(dict, g_strdup("vquality_type_target"),
2266 ghb_boolean_value_new(FALSE));
2267 ghb_dict_insert(dict, g_strdup("vquality_type_bitrate"),
2268 ghb_boolean_value_new(FALSE));
2269 ghb_dict_insert(dict, g_strdup("vquality_type_constant"),
2270 ghb_boolean_value_new(TRUE));
2273 import_value_xlat(dict);
2278 vquality = ghb_value_double(preset_dict_get_value(dict, "VideoQualitySlider"));
2283 gval = preset_dict_get_value(dict, "VideoEncoder");
2284 vcodec = ghb_lookup_combo_int("VideoEncoder", gval);
2287 case HB_VCODEC_X264:
2289 vquality = 51. - vquality * 51.;
2292 case HB_VCODEC_XVID:
2293 case HB_VCODEC_FFMPEG:
2295 vquality = 31. - vquality * 30.;
2298 case HB_VCODEC_THEORA:
2300 vquality = vquality * 63.;
2308 ghb_dict_insert(dict, g_strdup("VideoQualitySlider"),
2309 ghb_double_value_new(vquality));
2314 import_xlat_presets(GValue *presets)
2320 g_debug("import_xlat_presets ()");
2321 if (presets == NULL) return;
2322 count = ghb_array_len(presets);
2323 for (ii = 0; ii < count; ii++)
2325 dict = ghb_array_get_nth(presets, ii);
2326 folder = ghb_value_boolean(preset_dict_get_value(dict, "Folder"));
2331 nested = ghb_dict_lookup(dict, "ChildrenArray");
2332 import_xlat_presets(nested);
2336 import_xlat_preset(dict);
2342 export_xlat_preset(GValue *dict)
2344 gboolean ana, round, autoscale, target, br, constant;
2346 g_debug("export_xlat_prest ()");
2347 autoscale = ghb_value_boolean(preset_dict_get_value(dict, "autoscale"));
2348 ana = ghb_value_boolean(preset_dict_get_value(dict, "anamorphic"));
2349 round = ghb_value_boolean(preset_dict_get_value(dict, "ModDimensions"));
2350 target = ghb_value_boolean(
2351 preset_dict_get_value(dict, "vquality_type_target"));
2352 br = ghb_value_boolean(
2353 preset_dict_get_value(dict, "vquality_type_bitrate"));
2354 constant = ghb_value_boolean(
2355 preset_dict_get_value(dict, "vquality_type_constant"));
2358 ghb_dict_insert(dict, g_strdup("UsesPictureSettings"),
2359 ghb_int_value_new(2));
2361 ghb_dict_insert(dict, g_strdup("UsesPictureSettings"),
2362 ghb_int_value_new(1));
2367 ghb_dict_insert(dict, g_strdup("PicturePAR"),
2368 ghb_int_value_new(2));
2370 ghb_dict_insert(dict, g_strdup("PicturePAR"),
2371 ghb_int_value_new(1));
2375 ghb_dict_insert(dict, g_strdup("PicturePAR"),
2376 ghb_int_value_new(0));
2378 // VideoQualityType/0/1/2 - vquality_type_/target/bitrate/constant
2381 ghb_dict_insert(dict, g_strdup("VideoQualityType"),
2382 ghb_int_value_new(0));
2386 ghb_dict_insert(dict, g_strdup("VideoQualityType"),
2387 ghb_int_value_new(1));
2391 ghb_dict_insert(dict, g_strdup("VideoQualityType"),
2392 ghb_int_value_new(2));
2394 ghb_dict_remove(dict, "UsesMaxPictureSettings");
2395 ghb_dict_remove(dict, "autoscale");
2396 ghb_dict_remove(dict, "anamorphic");
2397 ghb_dict_remove(dict, "vquality_type_target");
2398 ghb_dict_remove(dict, "vquality_type_bitrate");
2399 ghb_dict_remove(dict, "vquality_type_constant");
2400 export_value_xlat(dict);
2404 export_xlat_presets(GValue *presets)
2410 if (presets == NULL) return;
2411 count = ghb_array_len(presets);
2412 for (ii = 0; ii < count; ii++)
2414 dict = ghb_array_get_nth(presets, ii);
2415 folder = ghb_value_boolean(preset_dict_get_value(dict, "Folder"));
2420 nested = ghb_dict_lookup(dict, "ChildrenArray");
2421 export_xlat_presets(nested);
2425 export_xlat_preset(dict);
2435 export = ghb_value_dup(presetsPlist);
2436 export_xlat_presets(export);
2437 store_plist(export, "presets");
2438 ghb_value_free(export);
2442 ghb_presets_reload(signal_user_data_t *ud)
2444 GValue *std_presets;
2448 g_debug("ghb_presets_reload()\n");
2449 std_presets = ghb_resource_get("standard-presets");
2450 if (std_presets == NULL) return;
2452 remove_std_presets(ud);
2453 indices = presets_find_default(presetsPlist, &len);
2456 presets_clear_default(std_presets);
2459 // Merge the keyfile contents into our presets
2460 count = ghb_array_len(std_presets);
2461 for (ii = count-1; ii >= 0; ii--)
2467 std_dict = ghb_array_get_nth(std_presets, ii);
2468 copy_dict = ghb_value_dup(std_dict);
2469 ghb_presets_insert(presetsPlist, copy_dict, &indices, 1);
2470 presets_list_insert(ud, &indices, 1);
2472 import_xlat_presets(presetsPlist);
2481 count = ghb_array_len(presetsPlist);
2482 for (ii = count-1; ii >= 0; ii--)
2487 dict = ghb_array_get_nth(presetsPlist, ii);
2488 type = ghb_dict_lookup(dict, "Type");
2498 presetsPlist = load_plist("presets");
2499 if (presetsPlist == NULL)
2501 presetsPlist = ghb_value_dup(ghb_resource_get("standard-presets"));
2502 import_xlat_presets(presetsPlist);
2505 else if (G_VALUE_TYPE(presetsPlist) == ghb_dict_get_type())
2506 { // Presets is older dictionary format. Convert to array
2507 ghb_value_free(presetsPlist);
2508 presetsPlist = ghb_value_dup(ghb_resource_get("standard-presets"));
2509 import_xlat_presets(presetsPlist);
2512 else if (check_old_presets())
2514 ghb_value_free(presetsPlist);
2515 presetsPlist = ghb_value_dup(ghb_resource_get("standard-presets"));
2516 import_xlat_presets(presetsPlist);
2519 import_xlat_presets(presetsPlist);
2523 settings_save(signal_user_data_t *ud, const GValue *path)
2525 GValue *dict, *internal;
2526 GHashTableIter iter;
2530 gint *indices, len, count;
2532 gboolean replace = FALSE;
2534 g_debug("settings_save");
2535 if (internalPlist == NULL) return;
2536 count = ghb_array_len(path);
2537 name = g_value_get_string(ghb_array_get_nth(path, count-1));
2538 indices = ghb_preset_indices_from_path(presetsPlist, path, &len);
2541 if (ghb_presets_get_folder(presetsPlist, indices, len))
2544 message = g_strdup_printf(
2545 "%s: Folder already exists.\n"
2546 "You can not replace it with a preset.",
2548 ghb_message_dialog(GTK_MESSAGE_ERROR, message, "Cancel", NULL);
2552 dict = ghb_dict_value_new();
2553 ghb_presets_replace(presetsPlist, dict, indices, len);
2558 indices = presets_find_pos(path, PRESETS_CUSTOM, &len);
2561 dict = ghb_dict_value_new();
2562 ghb_presets_insert(presetsPlist, dict, indices, len);
2566 g_warning("failed to find insert path");
2570 current_preset = dict;
2571 autoscale = ghb_settings_get_boolean(ud->settings, "autoscale");
2572 ghb_settings_set_int64(ud->settings, "Type", PRESETS_CUSTOM);
2574 internal = plist_get_dict(internalPlist, "Presets");
2575 ghb_dict_iter_init(&iter, internal);
2576 // middle (void*) cast prevents gcc warning "defreferencing type-punned
2577 // pointer will break strict-aliasing rules"
2578 while (g_hash_table_iter_next(
2579 &iter, (gpointer*)(void*)&key, (gpointer*)(void*)&value))
2587 if (strcmp(key, "PictureWidth") == 0)
2589 key2 = "scale_width";
2591 else if (strcmp(key, "PictureHeight") == 0)
2593 key2 = "scale_height";
2596 gval = ghb_settings_get_value(ud->settings, key2);
2601 ghb_dict_insert(dict, g_strdup(key), ghb_value_dup(gval));
2603 internal = plist_get_dict(internalPlist, "XlatPresets");
2604 ghb_dict_iter_init(&iter, internal);
2605 // middle (void*) cast prevents gcc warning "defreferencing type-punned
2606 // pointer will break strict-aliasing rules"
2607 while (g_hash_table_iter_next(
2608 &iter, (gpointer*)(void*)&key, (gpointer*)(void*)&value))
2612 gval = ghb_settings_get_value(ud->settings, key);
2617 ghb_dict_insert(dict, g_strdup(key), ghb_value_dup(gval));
2619 ghb_dict_insert(dict, g_strdup("PresetName"), ghb_string_value_new(name));
2621 presets_list_update_item(ud, indices, len);
2624 ghb_dict_insert(dict, g_strdup("Default"),
2625 ghb_boolean_value_new(FALSE));
2626 presets_list_insert(ud, indices, len);
2629 ud->dont_clear_presets = TRUE;
2630 // Make the new preset the selected item
2631 ghb_select_preset2(ud->builder, indices, len);
2633 ud->dont_clear_presets = FALSE;
2638 folder_save(signal_user_data_t *ud, const GValue *path)
2640 GValue *dict, *folder;
2641 gint *indices, len, count;
2644 count = ghb_array_len(path);
2645 name = g_value_get_string(ghb_array_get_nth(path, count-1));
2646 indices = ghb_preset_indices_from_path(presetsPlist, path, &len);
2649 if (!ghb_presets_get_folder(presetsPlist, indices, len))
2652 message = g_strdup_printf(
2653 "%s: Preset already exists.\n"
2654 "You can not replace it with a folder.",
2656 ghb_message_dialog(GTK_MESSAGE_ERROR, message, "Cancel", NULL);
2661 // Already exists, update its description
2662 dict = presets_get_dict(presetsPlist, indices, len);
2663 ghb_dict_insert(dict, g_strdup("PresetDescription"),
2664 ghb_value_dup(preset_dict_get_value(
2665 ud->settings, "PresetDescription")));
2671 indices = presets_find_pos(path, PRESETS_CUSTOM, &len);
2674 dict = ghb_dict_value_new();
2675 ghb_presets_insert(presetsPlist, dict, indices, len);
2679 g_warning("failed to find insert path");
2683 ghb_dict_insert(dict, g_strdup("PresetDescription"),
2684 ghb_value_dup(preset_dict_get_value(
2685 ud->settings, "PresetDescription")));
2686 ghb_dict_insert(dict, g_strdup("PresetName"), ghb_string_value_new(name));
2687 folder = ghb_array_value_new(8);
2688 ghb_dict_insert(dict, g_strdup("ChildrenArray"), folder);
2689 ghb_dict_insert(dict, g_strdup("Type"),
2690 ghb_int64_value_new(PRESETS_CUSTOM));
2691 ghb_dict_insert(dict, g_strdup("Folder"), ghb_boolean_value_new(TRUE));
2693 presets_list_insert(ud, indices, len);
2700 ghb_presets_list_default(signal_user_data_t *ud)
2702 GtkTreeView *treeview;
2703 GtkTreePath *treepath;
2705 GtkTreeStore *store;
2708 g_debug("ghb_presets_list_default ()");
2709 treeview = GTK_TREE_VIEW(GHB_WIDGET(ud->builder, "presets_list"));
2710 store = GTK_TREE_STORE(gtk_tree_view_get_model(treeview));
2711 indices = presets_find_default(presetsPlist, &len);
2712 if (indices == NULL) return;
2713 treepath = ghb_tree_path_new_from_indices(indices, len);
2716 if (gtk_tree_model_get_iter(GTK_TREE_MODEL(store), &iter, treepath))
2718 gtk_tree_store_set(store, &iter,
2723 gtk_tree_path_free(treepath);
2729 ghb_presets_list_clear_default(signal_user_data_t *ud)
2731 GtkTreeView *treeview;
2732 GtkTreePath *treepath;
2734 GtkTreeStore *store;
2737 g_debug("ghb_presets_list_clear_default ()");
2738 treeview = GTK_TREE_VIEW(GHB_WIDGET(ud->builder, "presets_list"));
2739 store = GTK_TREE_STORE(gtk_tree_view_get_model(treeview));
2740 indices = presets_find_default(presetsPlist, &len);
2741 if (indices == NULL) return;
2742 treepath = ghb_tree_path_new_from_indices(indices, len);
2745 if (gtk_tree_model_get_iter(GTK_TREE_MODEL(store), &iter, treepath))
2747 gtk_tree_store_set(store, &iter,
2752 gtk_tree_path_free(treepath);
2758 update_audio_presets(signal_user_data_t *ud)
2760 g_debug("update_audio_presets");
2761 const GValue *audio_list;
2763 audio_list = ghb_settings_get_value(ud->settings, "audio_list");
2764 ghb_settings_set_value(ud->settings, "AudioList", audio_list);
2768 enforce_preset_type(signal_user_data_t *ud, const GValue *path)
2771 GtkWidget *normal, *folder;
2774 normal = GHB_WIDGET(ud->builder, "preset_type_normal");
2775 folder = GHB_WIDGET(ud->builder, "preset_type_folder");
2776 indices = ghb_preset_indices_from_path(presetsPlist, path, &len);
2779 fold = ghb_presets_get_folder(presetsPlist, indices, len);
2781 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(folder),
2784 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(normal),
2786 gtk_widget_set_sensitive(folder, fold);
2787 gtk_widget_set_sensitive(normal, !fold);
2792 gtk_widget_set_sensitive(folder, TRUE);
2793 gtk_widget_set_sensitive(normal, TRUE);
2798 presets_save_clicked_cb(GtkWidget *xwidget, signal_user_data_t *ud)
2803 GtkResponseType response;
2805 const gchar *name = "";
2806 gint count, *indices, len;
2808 g_debug("presets_save_clicked_cb ()");
2809 preset = ghb_settings_get_value (ud->settings, "preset_selection");
2811 count = ghb_array_len(preset);
2813 name = g_value_get_string(ghb_array_get_nth(preset, count-1));
2816 // Clear the description
2817 desc = GTK_TEXT_VIEW(GHB_WIDGET(ud->builder, "PresetDescription"));
2818 dialog = GHB_WIDGET(ud->builder, "preset_save_dialog");
2819 entry = GTK_ENTRY(GHB_WIDGET(ud->builder, "PresetName"));
2820 gtk_entry_set_text(entry, name);
2821 enforce_preset_type(ud, preset);
2822 response = gtk_dialog_run(GTK_DIALOG(dialog));
2823 gtk_widget_hide(dialog);
2824 if (response == GTK_RESPONSE_OK)
2827 const gchar *name = gtk_entry_get_text(entry);
2830 if (ghb_settings_get_boolean(ud->settings, "preset_type_folder"))
2832 if (count > MAX_NESTED_PRESET-1)
2834 count = MAX_NESTED_PRESET-1;
2837 dest = ghb_array_value_new(MAX_NESTED_PRESET);
2838 indices = ghb_preset_indices_from_path(presetsPlist, preset, &len);
2843 ptype = ghb_presets_get_type(presetsPlist, indices, len);
2844 if (ptype == PRESETS_CUSTOM)
2846 ghb_array_copy(dest, preset, count-1);
2849 ghb_array_append(dest, ghb_string_value_new(name));
2851 ghb_widget_to_setting(ud->settings, GTK_WIDGET(desc));
2852 if (ghb_settings_get_boolean(ud->settings, "preset_type_folder"))
2854 folder_save(ud, dest);
2858 // Construct the audio settings presets from the current audio list
2859 update_audio_presets(ud);
2860 settings_save(ud, dest);
2862 ghb_value_free(dest);
2867 preset_type_changed_cb(GtkWidget *widget, signal_user_data_t *ud)
2869 ghb_widget_to_setting(ud->settings, widget);
2873 preset_name_changed_cb(GtkWidget *entry, signal_user_data_t *ud)
2876 GValue *preset, *dest;
2879 preset = ghb_settings_get_value (ud->settings, "preset_selection");
2880 name = ghb_widget_string(entry);
2881 dest = ghb_value_dup(preset);
2882 count = ghb_array_len(dest);
2883 ghb_array_replace(dest, count-1, ghb_string_value_new(name));
2884 enforce_preset_type(ud, dest);
2885 ghb_value_free(dest);
2889 presets_restore_clicked_cb(GtkWidget *xwidget, signal_user_data_t *ud)
2893 g_debug("presets_restore_clicked_cb ()");
2894 // Reload only the standard presets
2895 ghb_presets_reload(ud);
2896 // Updating the presets list shuffles things around
2897 // need to make sure the proper preset is selected
2898 preset = ghb_settings_get_value (ud->settings, "preset");
2899 ghb_select_preset(ud->builder, preset);
2903 presets_remove_clicked_cb(GtkWidget *xwidget, signal_user_data_t *ud)
2905 GtkTreeView *treeview;
2906 GtkTreeSelection *selection;
2907 GtkTreeModel *store;
2910 GtkResponseType response;
2912 g_debug("presets_remove_clicked_cb ()");
2913 treeview = GTK_TREE_VIEW(GHB_WIDGET(ud->builder, "presets_list"));
2914 selection = gtk_tree_view_get_selection (treeview);
2915 if (gtk_tree_selection_get_selected(selection, &store, &iter))
2922 gtk_tree_model_get(store, &iter, 0, &preset, -1);
2923 path = gtk_tree_model_get_path(store, &iter);
2924 indices = gtk_tree_path_get_indices(path);
2925 len = gtk_tree_path_get_depth(path);
2927 folder = ghb_presets_get_folder(presetsPlist, indices, len);
2928 dialog = gtk_message_dialog_new(NULL, GTK_DIALOG_MODAL,
2929 GTK_MESSAGE_QUESTION, GTK_BUTTONS_YES_NO,
2930 "Confirm deletion of %s:\n\n%s",
2931 folder ? "folder" : "preset",
2933 response = gtk_dialog_run(GTK_DIALOG(dialog));
2934 gtk_widget_destroy (dialog);
2935 if (response == GTK_RESPONSE_YES)
2937 GtkTreeIter nextIter = iter;
2938 gboolean valid = TRUE;
2939 if (!gtk_tree_model_iter_next(store, &nextIter))
2941 if (!gtk_tree_model_iter_parent(store, &nextIter, &iter))
2946 // Remove the selected item
2947 // First unselect it so that selecting the new item works properly
2948 gtk_tree_selection_unselect_iter (selection, &iter);
2949 if (ghb_presets_remove(presetsPlist, indices, len))
2952 presets_list_remove(ud, indices, len);
2955 valid = gtk_tree_model_get_iter_first(store, &nextIter);
2958 gtk_tree_path_free(path);
2959 path = gtk_tree_model_get_path(store, &nextIter);
2960 indices = gtk_tree_path_get_indices(path);
2961 len = gtk_tree_path_get_depth(path);
2962 ghb_select_preset2(ud->builder, indices, len);
2966 gtk_tree_path_free(path);
2970 // controls where valid drop locations are
2972 presets_drag_motion_cb(
2974 GdkDragContext *ctx,
2978 signal_user_data_t *ud)
2980 GtkTreePath *path = NULL;
2981 GtkTreeViewDropPosition drop_pos;
2985 GtkTreeModel *model;
2986 GtkTreeSelection *select;
2987 gint src_ptype, dst_ptype;
2988 gboolean src_folder, dst_folder;
2990 gint tree_depth, ii;
2992 // Get the type of the object being dragged
2993 srctv = GTK_TREE_VIEW(gtk_drag_get_source_widget(ctx));
2994 select = gtk_tree_view_get_selection (srctv);
2995 gtk_tree_selection_get_selected (select, &model, &iter);
2996 path = gtk_tree_model_get_path (model, &iter);
2997 indices = gtk_tree_path_get_indices(path);
2998 len = gtk_tree_path_get_depth(path);
3000 preset = presets_get_dict(presetsPlist, indices, len);
3001 tree_depth = preset_tree_depth(preset);
3003 src_ptype = ghb_presets_get_type(presetsPlist, indices, len);
3004 src_folder = ghb_presets_get_folder(presetsPlist, indices, len);
3005 gtk_tree_path_free(path);
3007 if (src_folder && tree_depth == 1)
3010 // The rest checks that the destination is a valid position
3012 gtk_tree_view_get_dest_row_at_pos (tv, x, y, &path, &drop_pos);
3015 gdk_drag_status(ctx, 0, time);
3018 // Don't allow repositioning of builtin presets
3019 if (src_ptype != PRESETS_CUSTOM)
3021 gdk_drag_status(ctx, 0, time);
3025 len = gtk_tree_path_get_depth(path);
3026 if (len+tree_depth-1 >= MAX_NESTED_PRESET)
3028 if (drop_pos == GTK_TREE_VIEW_DROP_INTO_OR_BEFORE)
3029 drop_pos = GTK_TREE_VIEW_DROP_BEFORE;
3030 if (drop_pos == GTK_TREE_VIEW_DROP_INTO_OR_AFTER)
3031 drop_pos = GTK_TREE_VIEW_DROP_AFTER;
3033 for (ii = len+tree_depth-1; ii > MAX_NESTED_PRESET; ii--)
3034 gtk_tree_path_up(path);
3035 indices = gtk_tree_path_get_indices(path);
3036 len = gtk_tree_path_get_depth(path);
3037 dst_ptype = ghb_presets_get_type(presetsPlist, indices, len);
3038 dst_folder = ghb_presets_get_folder(presetsPlist, indices, len);
3039 // Don't allow mixing custom presets in the builtins
3040 if (dst_ptype != PRESETS_CUSTOM)
3042 gdk_drag_status(ctx, 0, time);
3046 // Only allow *drop into* for folders
3049 if (drop_pos == GTK_TREE_VIEW_DROP_INTO_OR_BEFORE)
3050 drop_pos = GTK_TREE_VIEW_DROP_BEFORE;
3051 if (drop_pos == GTK_TREE_VIEW_DROP_INTO_OR_AFTER)
3052 drop_pos = GTK_TREE_VIEW_DROP_AFTER;
3055 len = gtk_tree_path_get_depth(path);
3056 gtk_tree_view_set_drag_dest_row(tv, path, drop_pos);
3057 gtk_tree_path_free(path);
3058 gdk_drag_status(ctx, GDK_ACTION_MOVE, time);
3064 GtkTreeView *dstwidget,
3067 GtkSelectionData *selection_data,
3068 guint info, guint t,
3069 signal_user_data_t *ud)
3071 GtkTreePath *path = NULL;
3072 GtkTreeViewDropPosition drop_pos;
3073 GtkTreeIter dstiter, srciter;
3074 gint *dst_indices, dst_len, *src_indices, src_len;
3076 gboolean src_folder, dst_folder;
3078 GtkTreeModel *dstmodel = gtk_tree_view_get_model(dstwidget);
3080 g_debug("preset_drag_cb ()");
3081 // This doesn't work here for some reason...
3082 // gtk_tree_view_get_drag_dest_row(dstwidget, &path, &drop_pos);
3083 gtk_tree_view_get_dest_row_at_pos (dstwidget, x, y, &path, &drop_pos);
3084 // This little hack is needed because attempting to drop after
3085 // the last item gives us no path or drop_pos.
3090 n_children = gtk_tree_model_iter_n_children(dstmodel, NULL);
3093 drop_pos = GTK_TREE_VIEW_DROP_AFTER;
3094 path = gtk_tree_path_new_from_indices(n_children-1, -1);
3098 drop_pos = GTK_TREE_VIEW_DROP_BEFORE;
3099 path = gtk_tree_path_new_from_indices(0, -1);
3104 GtkTreeView *srcwidget;
3105 GtkTreeModel *srcmodel;
3106 GtkTreeSelection *select;
3107 GtkTreePath *srcpath = NULL;
3109 gint tree_depth, ii;
3111 srcwidget = GTK_TREE_VIEW(gtk_drag_get_source_widget(dc));
3112 select = gtk_tree_view_get_selection (srcwidget);
3113 gtk_tree_selection_get_selected (select, &srcmodel, &srciter);
3115 srcpath = gtk_tree_model_get_path (srcmodel, &srciter);
3116 src_indices = gtk_tree_path_get_indices(srcpath);
3117 src_len = gtk_tree_path_get_depth(srcpath);
3118 src_ptype = ghb_presets_get_type(presetsPlist, src_indices, src_len);
3119 src_folder = ghb_presets_get_folder(presetsPlist, src_indices, src_len);
3120 preset = ghb_value_dup(
3121 presets_get_dict(presetsPlist, src_indices, src_len));
3122 gtk_tree_path_free(srcpath);
3124 // Don't allow repositioning of builtin presets
3125 if (src_ptype != PRESETS_CUSTOM)
3128 tree_depth = preset_tree_depth(preset);
3129 if (src_folder && tree_depth == 1)
3132 dst_len = gtk_tree_path_get_depth(path);
3133 if (dst_len+tree_depth-1 >= MAX_NESTED_PRESET)
3135 if (drop_pos == GTK_TREE_VIEW_DROP_INTO_OR_BEFORE)
3136 drop_pos = GTK_TREE_VIEW_DROP_BEFORE;
3137 if (drop_pos == GTK_TREE_VIEW_DROP_INTO_OR_AFTER)
3138 drop_pos = GTK_TREE_VIEW_DROP_AFTER;
3141 for (ii = dst_len+tree_depth-1; ii > MAX_NESTED_PRESET; ii--)
3142 gtk_tree_path_up(path);
3143 dst_indices = gtk_tree_path_get_indices(path);
3144 dst_len = gtk_tree_path_get_depth(path);
3145 dst_folder = ghb_presets_get_folder(presetsPlist, dst_indices, dst_len);
3146 // Only allow *drop into* for folders
3149 if (drop_pos == GTK_TREE_VIEW_DROP_INTO_OR_BEFORE)
3150 drop_pos = GTK_TREE_VIEW_DROP_BEFORE;
3151 if (drop_pos == GTK_TREE_VIEW_DROP_INTO_OR_AFTER)
3152 drop_pos = GTK_TREE_VIEW_DROP_AFTER;
3154 if (gtk_tree_model_get_iter (dstmodel, &dstiter, path))
3157 GtkTreePath *dstpath = NULL;
3161 case GTK_TREE_VIEW_DROP_BEFORE:
3162 gtk_tree_store_insert_before(GTK_TREE_STORE (dstmodel),
3163 &iter, NULL, &dstiter);
3166 case GTK_TREE_VIEW_DROP_INTO_OR_BEFORE:
3167 gtk_tree_store_insert(GTK_TREE_STORE (dstmodel),
3168 &iter, &dstiter, 0);
3171 case GTK_TREE_VIEW_DROP_AFTER:
3172 gtk_tree_store_insert_after(GTK_TREE_STORE (dstmodel),
3173 &iter, NULL, &dstiter);
3176 case GTK_TREE_VIEW_DROP_INTO_OR_AFTER:
3177 gtk_tree_store_insert_after(GTK_TREE_STORE (dstmodel),
3178 &iter, &dstiter, 0);
3185 dstpath = gtk_tree_model_get_path (dstmodel, &iter);
3186 dst_indices = gtk_tree_path_get_indices(dstpath);
3187 dst_len = gtk_tree_path_get_depth(dstpath);
3188 ghb_presets_insert(presetsPlist, preset, dst_indices, dst_len);
3189 gtk_tree_path_free(dstpath);
3191 srcpath = gtk_tree_model_get_path (srcmodel, &srciter);
3192 src_indices = gtk_tree_path_get_indices(srcpath);
3193 src_len = gtk_tree_path_get_depth(srcpath);
3194 ghb_presets_remove(presetsPlist, src_indices, src_len);
3195 gtk_tree_path_free(srcpath);
3197 gtk_tree_store_remove (GTK_TREE_STORE (srcmodel), &srciter);
3199 dstpath = gtk_tree_model_get_path (dstmodel, &iter);
3200 dst_indices = gtk_tree_path_get_indices(dstpath);
3201 dst_len = gtk_tree_path_get_depth(dstpath);
3202 presets_list_update_item(ud, dst_indices, dst_len);
3203 gtk_tree_path_free(dstpath);
3207 gtk_tree_path_free(path);
3212 presets_row_expanded_cb(
3213 GtkTreeView *treeview,
3216 signal_user_data_t *ud)
3219 gboolean expanded, folder;
3221 expanded = gtk_tree_view_row_expanded(treeview, path);
3222 indices = gtk_tree_path_get_indices(path);
3223 len = gtk_tree_path_get_depth(path);
3224 folder = ghb_presets_get_folder(presetsPlist, indices, len);
3227 presets_set_folder_open(expanded, indices, len);
3230 // Collapsing parent folder collapses all children
3233 GValue *presets = NULL;
3235 gint *more_indices, count, ii;
3237 more_indices = g_malloc((len+1)*sizeof(gint));
3238 memcpy(more_indices, indices, len*sizeof(gint));
3240 presets = presets_get_folder(presetsPlist, indices, len);
3241 count = ghb_array_len(presets);
3242 for (ii = 0; ii < count; ii++)
3244 dict = ghb_array_get_nth(presets, ii);
3245 folder = ghb_preset_folder(dict);
3248 more_indices[len] = ii;
3249 presets_set_folder_open(expanded, more_indices, len+1);
3252 g_free(more_indices);
3258 preset_update_title_deps(signal_user_data_t *ud, ghb_title_info_t *tinfo)
3262 ghb_ui_update(ud, "scale_width",
3263 ghb_int64_value(tinfo->width - tinfo->crop[2] - tinfo->crop[3]));
3264 // If anamorphic or keep_aspect, the hight will be automatically calculated
3265 gboolean keep_aspect, anamorphic;
3266 keep_aspect = ghb_settings_get_boolean(ud->settings, "PictureKeepRatio");
3267 anamorphic = ghb_settings_get_boolean(ud->settings, "anamorphic");
3268 if (!(keep_aspect || anamorphic))
3270 ghb_ui_update(ud, "scale_height",
3271 ghb_int64_value(tinfo->height - tinfo->crop[0] - tinfo->crop[1]));
3274 // Set the limits of cropping. hb_set_anamorphic_size crashes if
3275 // you pass it a cropped width or height == 0.
3277 bound = tinfo->height / 2 - 2;
3278 widget = GHB_WIDGET (ud->builder, "PictureTopCrop");
3279 gtk_spin_button_set_range (GTK_SPIN_BUTTON(widget), 0, bound);
3280 widget = GHB_WIDGET (ud->builder, "PictureBottomCrop");
3281 gtk_spin_button_set_range (GTK_SPIN_BUTTON(widget), 0, bound);
3282 bound = tinfo->width / 2 - 2;
3283 widget = GHB_WIDGET (ud->builder, "PictureLeftCrop");
3284 gtk_spin_button_set_range (GTK_SPIN_BUTTON(widget), 0, bound);
3285 widget = GHB_WIDGET (ud->builder, "PictureRightCrop");
3286 gtk_spin_button_set_range (GTK_SPIN_BUTTON(widget), 0, bound);
3287 if (ghb_settings_get_boolean(ud->settings, "PictureAutoCrop"))
3289 ghb_ui_update(ud, "PictureTopCrop", ghb_int64_value(tinfo->crop[0]));
3290 ghb_ui_update(ud, "PictureBottomCrop", ghb_int64_value(tinfo->crop[1]));
3291 ghb_ui_update(ud, "PictureLeftCrop", ghb_int64_value(tinfo->crop[2]));
3292 ghb_ui_update(ud, "PictureRightCrop", ghb_int64_value(tinfo->crop[3]));
3297 presets_list_selection_changed_cb(GtkTreeSelection *selection, signal_user_data_t *ud)
3299 GtkTreeModel *store;
3301 ghb_title_info_t tinfo;
3304 g_debug("presets_list_selection_changed_cb ()");
3305 widget = GHB_WIDGET (ud->builder, "presets_remove");
3306 if (gtk_tree_selection_get_selected(selection, &store, &iter))
3308 GtkTreePath *treepath;
3313 treepath = gtk_tree_model_get_path(store, &iter);
3314 indices = gtk_tree_path_get_indices(treepath);
3315 len = gtk_tree_path_get_depth(treepath);
3317 path = preset_path_from_indices(presetsPlist, indices, len);
3318 ghb_settings_take_value(ud->settings, "preset_selection", path);
3320 folder = ghb_presets_get_folder(presetsPlist, indices, len);
3323 ud->dont_clear_presets = TRUE;
3324 // Temporarily set the video_quality range to (0,100)
3325 // This is needed so the video_quality value does not get
3326 // truncated when set. The range will be readjusted below
3327 GtkWidget *qp = GHB_WIDGET(ud->builder, "VideoQualitySlider");
3328 gtk_range_set_range (GTK_RANGE(qp), 0, 100);
3329 gtk_scale_set_digits(GTK_SCALE(qp), 3);
3330 // Clear the audio list prior to changing the preset. Existing
3331 // audio can cause the container extension to be automatically
3332 // changed when it shouldn't be
3333 ghb_clear_audio_list(ud);
3334 ghb_set_preset_from_indices(ud, indices, len);
3335 gtk_tree_path_free(treepath);
3337 titleindex = ghb_settings_combo_int(ud->settings, "title");
3338 ghb_set_pref_audio(titleindex, ud);
3339 ghb_settings_set_boolean(ud->settings, "preset_modified", FALSE);
3340 ud->dont_clear_presets = FALSE;
3341 if (ghb_get_title_info (&tinfo, titleindex))
3343 preset_update_title_deps(ud, &tinfo);
3345 ghb_set_scale (ud, GHB_SCALE_KEEP_NONE);
3347 gdouble vqmin, vqmax, step, page;
3351 ghb_vquality_range(ud, &vqmin, &vqmax, &step,
3352 &page, &digits, &inverted);
3353 gtk_range_set_range (GTK_RANGE(qp), vqmin, vqmax);
3354 gtk_range_set_increments (GTK_RANGE(qp), step, page);
3355 gtk_scale_set_digits(GTK_SCALE(qp), digits);
3356 gtk_range_set_inverted (GTK_RANGE(qp), inverted);
3360 GtkWidget *crop_widget;
3361 crop[0] = ghb_settings_get_int(ud->settings, "PictureTopCrop");
3362 crop[1] = ghb_settings_get_int(ud->settings, "PictureBottomCrop");
3363 crop[2] = ghb_settings_get_int(ud->settings, "PictureLeftCrop");
3364 crop[3] = ghb_settings_get_int(ud->settings, "PictureRightCrop");
3365 crop_widget = GHB_WIDGET (ud->builder, "crop_values");
3366 text = g_strdup_printf("%d:%d:%d:%d",
3367 crop[0], crop[1], crop[2], crop[3]);
3368 gtk_label_set_text (GTK_LABEL(crop_widget), text);
3371 gtk_widget_set_sensitive(widget, TRUE);
3375 g_debug("No selection??? Perhaps unselected.");
3376 gtk_widget_set_sensitive(widget, FALSE);
3381 ghb_clear_presets_selection(signal_user_data_t *ud)
3383 GtkTreeView *treeview;
3384 GtkTreeSelection *selection;
3386 if (ud->dont_clear_presets) return;
3387 g_debug("ghb_clear_presets_selection()");
3388 treeview = GTK_TREE_VIEW(GHB_WIDGET(ud->builder, "presets_list"));
3389 selection = gtk_tree_view_get_selection (treeview);
3390 gtk_tree_selection_unselect_all (selection);
3391 ghb_settings_set_boolean(ud->settings, "preset_modified", TRUE);
3395 presets_frame_size_allocate_cb(GtkWidget *widget, GtkAllocation *allocation, signal_user_data_t *ud)
3397 GtkTreeView *treeview;
3398 GtkTreeSelection *selection;
3399 GtkTreeModel *store;
3402 treeview = GTK_TREE_VIEW(GHB_WIDGET(ud->builder, "presets_list"));
3403 selection = gtk_tree_view_get_selection(treeview);
3404 if (gtk_tree_selection_get_selected(selection, &store, &iter))
3407 path = gtk_tree_model_get_path (store, &iter);
3408 // Make the parent visible in scroll window if it is not.
3409 gtk_tree_view_scroll_to_cell (treeview, path, NULL, FALSE, 0, 0);
3410 gtk_tree_path_free(path);
3415 presets_default_clicked_cb(GtkWidget *xwidget, signal_user_data_t *ud)
3420 g_debug("presets_default_clicked_cb ()");
3421 preset = ghb_settings_get_value(ud->settings, "preset_selection");
3422 indices = ghb_preset_indices_from_path(presetsPlist, preset, &len);
3425 if (!ghb_presets_get_folder(presetsPlist, indices, len))
3427 ghb_presets_list_clear_default(ud);
3428 presets_set_default(indices, len);
3429 ghb_presets_list_default(ud);