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);
46 static void store_prefs(void);
48 // This only handle limited depth
50 ghb_tree_path_new_from_indices(gint *indices, gint len)
55 return gtk_tree_path_new_from_indices(
58 return gtk_tree_path_new_from_indices(
59 indices[0], indices[1], -1);
61 return gtk_tree_path_new_from_indices(
62 indices[0], indices[1], indices[2], -1);
64 return gtk_tree_path_new_from_indices(
65 indices[0], indices[1], indices[2], indices[3], -1);
67 return gtk_tree_path_new_from_indices(
68 indices[0], indices[1], indices[2], indices[3], indices[4], -1);
75 ghb_parse_preset_path(const gchar *path)
81 preset = ghb_array_value_new(MAX_NESTED_PRESET);
82 split = g_strsplit(path, "#", MAX_NESTED_PRESET);
83 for (ii = 0; split[ii] != NULL; ii++)
85 ghb_array_append(preset, ghb_string_value_new(split[ii]));
92 preset_path_from_indices(GValue *presets, gint *indices, gint len)
97 g_debug("preset_path_from_indices");
98 path = ghb_array_value_new(MAX_NESTED_PRESET);
99 for (ii = 0; ii < len; ii++)
105 count = ghb_array_len(presets);
106 if (indices[ii] >= count) break;
107 dict = ghb_array_get_nth(presets, indices[ii]);
108 name = ghb_dict_lookup(dict, "PresetName");
110 ghb_array_append(path, ghb_value_dup(name));
111 folder = ghb_value_boolean(preset_dict_get_value(dict, "Folder"));
114 presets = ghb_dict_lookup(dict, "ChildrenArray");
120 ghb_preset_path_string(const GValue *path)
127 gstr = g_string_new("");
130 count = ghb_array_len(path);
131 for (ii = 0; ii < count; ii++)
133 val = ghb_array_get_nth(path, ii);
134 str = ghb_value_string(val);
135 g_string_append(gstr, str);
137 g_string_append(gstr, "->");
141 str = g_string_free(gstr, FALSE);
146 dump_preset_path(const gchar *msg, const GValue *path)
151 debug_show_type (G_VALUE_TYPE(path));
152 str = ghb_preset_path_string(path);
153 g_message("%s path: (%s)", msg, str);
158 dump_preset_indices(const gchar *msg, gint *indices, gint len)
162 g_message("%s indices: len %d", msg, len);
163 for (ii = 0; ii < len; ii++)
165 printf("%d ", indices[ii]);
172 preset_path_cmp(const GValue *path1, const GValue *path2)
179 count = ghb_array_len(path1);
180 ii = ghb_array_len(path2);
183 for (ii = 0; ii < count; ii++)
185 val = ghb_array_get_nth(path1, ii);
186 str1 = ghb_value_string(val);
187 val = ghb_array_get_nth(path2, ii);
188 str2 = ghb_value_string(val);
189 result = strcmp(str1, str2);
200 presets_get_dict(GValue *presets, gint *indices, gint len)
202 gint ii, count, folder;
205 g_debug("presets_get_dict ()");
206 for (ii = 0; ii < len; ii++)
208 count = ghb_array_len(presets);
209 if (indices[ii] >= count) return NULL;
210 dict = ghb_array_get_nth(presets, indices[ii]);
213 folder = ghb_value_boolean(preset_dict_get_value(dict, "Folder"));
216 presets = ghb_dict_lookup(dict, "ChildrenArray");
225 presets_get_folder(GValue *presets, gint *indices, gint len)
227 gint ii, count, folder;
230 g_debug("presets_get_folder ()");
231 for (ii = 0; ii < len; ii++)
233 count = ghb_array_len(presets);
234 if (indices[ii] >= count) return NULL;
235 dict = ghb_array_get_nth(presets, indices[ii]);
236 folder = ghb_value_boolean(preset_dict_get_value(dict, "Folder"));
239 presets = ghb_dict_lookup(dict, "ChildrenArray");
247 plist_get_dict(GValue *presets, const gchar *name)
249 if (presets == NULL || name == NULL) return NULL;
250 return ghb_dict_lookup(presets, name);
254 preset_get_name(GValue *dict)
256 return g_value_get_string(preset_dict_get_value(dict, "PresetName"));
260 preset_folder_is_open(GValue *dict)
264 gval = preset_dict_get_value(dict, "FolderOpen");
266 return g_value_get_boolean(gval);
271 ghb_preset_folder(GValue *dict)
273 return ghb_value_int(preset_dict_get_value(dict, "Folder"));
277 ghb_preset_type(GValue *dict)
279 return ghb_value_int(preset_dict_get_value(dict, "Type"));
283 presets_remove_nth(GValue *presets, gint pos)
288 if (presets == NULL || pos < 0) return;
289 count = ghb_array_len(presets);
290 if (pos >= count) return;
291 dict = ghb_array_get_nth(presets, pos);
292 ghb_array_remove(presets, pos);
293 ghb_value_free(dict);
302 GValue *folder = NULL;
304 folder = presets_get_folder(presets, indices, len-1);
306 presets_remove_nth(folder, indices[len-1]);
309 g_warning("ghb_presets_remove (): internal preset lookup error");
322 GValue *folder = NULL;
324 folder = presets_get_folder(presets, indices, len-1);
326 ghb_array_replace(folder, indices[len-1], dict);
329 g_warning("ghb_presets_replace (): internal preset lookup error");
340 GValue *folder = NULL;
342 folder = presets_get_folder(presets, indices, len-1);
344 ghb_array_insert(folder, indices[len-1], dict);
347 g_warning("ghb_presets_insert (): internal preset lookup error");
352 presets_find_element(GValue *presets, const gchar *name)
357 g_debug("presets_find_element () (%s)", name);
358 if (presets == NULL || name == NULL) return -1;
359 count = ghb_array_len(presets);
360 for (ii = 0; ii < count; ii++)
363 dict = ghb_array_get_nth(presets, ii);
364 str = preset_get_name(dict);
365 if (strcmp(name, str) == 0)
374 single_find_pos(GValue *presets, const gchar *name, gint type)
377 gint count, ii, ptype, last;
379 if (presets == NULL || name == NULL) return -1;
380 last = count = ghb_array_len(presets);
381 for (ii = 0; ii < count; ii++)
384 dict = ghb_array_get_nth(presets, ii);
385 str = preset_get_name(dict);
386 ptype = ghb_value_int(preset_dict_get_value(dict, "Type"));
387 if (strcasecmp(name, str) <= 0 && ptype == type)
398 presets_find_pos(const GValue *path, gint type, gint *len)
404 gint *indices = NULL;
408 g_debug("presets_find_pos () ");
409 nested = presetsPlist;
410 count = ghb_array_len(path);
411 indices = g_malloc(MAX_NESTED_PRESET * sizeof(gint));
412 for (ii = 0; ii < count-1; ii++)
414 val = ghb_array_get_nth(path, ii);
415 name = g_value_get_string(val);
416 indices[ii] = presets_find_element(nested, name);
417 if (indices[ii] == -1) return NULL;
418 dict = ghb_array_get_nth(nested, indices[ii]);
419 folder = ghb_value_boolean(preset_dict_get_value(dict, "Folder"));
423 nested = ghb_dict_lookup(dict, "ChildrenArray");
429 name = g_value_get_string(ghb_array_get_nth(path, count-1));
430 indices[ii] = single_find_pos(nested, name, type);
438 preset_tree_depth(GValue *dict)
442 folder = ghb_value_boolean(preset_dict_get_value(dict, "Folder"));
449 presets = ghb_dict_lookup(dict, "ChildrenArray");
450 count = ghb_array_len(presets);
451 for (ii = 0; ii < count; ii++)
455 dict = ghb_array_get_nth(presets, ii);
456 tmp = preset_tree_depth(dict);
457 depth = MAX(depth, tmp);
468 preset_is_default(GValue *dict)
472 val = preset_dict_get_value(dict, "Default");
473 return ghb_value_boolean(val);
477 presets_clear_default(GValue *presets)
481 count = ghb_array_len(presets);
482 for (ii = 0; ii < count; ii++)
487 dict = ghb_array_get_nth(presets, ii);
488 folder = ghb_value_boolean(preset_dict_get_value(dict, "Folder"));
493 nested = ghb_dict_lookup(dict, "ChildrenArray");
494 presets_clear_default(nested);
498 if (preset_is_default(dict))
500 ghb_dict_insert(dict, g_strdup("Default"),
501 ghb_boolean_value_new(FALSE));
508 presets_find_default2(GValue *presets, gint *len)
513 count = ghb_array_len(presets);
514 for (ii = 0; ii < count; ii++)
519 dict = ghb_array_get_nth(presets, ii);
520 folder = ghb_value_boolean(preset_dict_get_value(dict, "Folder"));
526 nested = ghb_dict_lookup(dict, "ChildrenArray");
528 indices = presets_find_default2(nested, len);
539 if (preset_is_default(dict))
541 indices = g_malloc(MAX_NESTED_PRESET * sizeof(gint));
552 presets_find_default(GValue *presets, gint *len)
555 return presets_find_default2(presets, len);
559 ghb_preset_indices_from_path(
567 gint *indices = NULL;
572 g_debug("ghb_preset_indices_from_path () ");
574 count = ghb_array_len(path);
576 indices = g_malloc(MAX_NESTED_PRESET * sizeof(gint));
578 for (ii = 0; ii < count; ii++)
580 val = ghb_array_get_nth(path, ii);
581 name = g_value_get_string(val);
582 indices[ii] = presets_find_element(nested, name);
583 if (indices[ii] == -1)
590 dict = ghb_array_get_nth(nested, indices[ii]);
591 folder = ghb_value_boolean(preset_dict_get_value(dict, "Folder"));
597 nested = ghb_dict_lookup(dict, "ChildrenArray");
605 ghb_presets_get_type(
613 dict = presets_get_dict(presets, indices, len);
616 type = ghb_preset_type(dict);
620 g_warning("ghb_presets_get_type (): internal preset lookup error");
626 ghb_presets_get_folder(
632 gboolean folder = FALSE;
634 dict = presets_get_dict(presets, indices, len);
637 folder = ghb_preset_folder(dict);
641 g_warning("ghb_presets_get_folder (): internal preset lookup error");
647 presets_set_default(gint *indices, gint len)
651 g_debug("presets_set_default ()");
652 presets_clear_default(presetsPlist);
653 dict = presets_get_dict(presetsPlist, indices, len);
656 ghb_dict_insert(dict, g_strdup("Default"), ghb_boolean_value_new(TRUE));
662 presets_set_folder_open(gboolean open, gint *indices, gint len)
666 g_debug("presets_set_folder_open ()");
667 dict = presets_get_dict(presetsPlist, indices, len);
670 ghb_dict_insert(dict, g_strdup("FolderOpen"),
671 ghb_boolean_value_new(open));
675 // Used for sorting dictionaries.
677 key_cmp(gconstpointer a, gconstpointer b)
679 gchar *stra = (gchar*)a;
680 gchar *strb = (gchar*)b;
682 return strcmp(stra, strb);
686 preset_dict_get_value(GValue *dict, const gchar *key)
688 const GValue *gval = NULL;
692 gval = ghb_dict_lookup(dict, key);
694 if (internalPlist == NULL) return NULL;
697 dict = plist_get_dict(internalPlist, "Presets");
698 if (dict == NULL) return NULL;
699 gval = ghb_dict_lookup(dict, key);
705 ghb_presets_get_description(GValue *pdict)
709 if (pdict == NULL) return NULL;
710 desc = g_value_get_string(
711 preset_dict_get_value(pdict, "PresetDescription"));
712 if (desc[0] == 0) return NULL;
717 static void init_settings_from_dict(
718 GValue *dest, GValue *internal, GValue *dict);
721 init_settings_from_array(
729 count = ghb_array_len(array);
730 // The first element of the internal version is always the
731 // template for the allowed values
732 gval = ghb_array_get_nth(internal, 0);
733 for (ii = 0; ii < count; ii++)
736 val = ghb_array_get_nth(array, ii);
739 if (G_VALUE_TYPE(gval) == ghb_dict_get_type())
742 new_dict = ghb_dict_value_new();
743 ghb_array_append(dest, new_dict);
744 if (G_VALUE_TYPE(val) == ghb_dict_get_type())
745 init_settings_from_dict(new_dict, gval, val);
747 init_settings_from_dict(new_dict, gval, gval);
749 else if (G_VALUE_TYPE(gval) == ghb_array_get_type())
752 new_array = ghb_array_value_new(8);
753 ghb_array_append(dest, new_array);
754 if (G_VALUE_TYPE(val) == ghb_array_get_type())
755 init_settings_from_array(new_array, gval, val);
757 init_settings_from_array(new_array, gval, gval);
761 ghb_array_append(dest, val);
767 init_settings_from_dict(
776 ghb_dict_iter_init(&iter, internal);
777 // middle (void*) cast prevents gcc warning "defreferencing type-punned
778 // pointer will break strict-aliasing rules"
779 while (g_hash_table_iter_next(
780 &iter, (gpointer*)(void*)&key, (gpointer*)(void*)&gval))
784 val = ghb_dict_lookup(dict, key);
787 if (G_VALUE_TYPE(gval) == ghb_dict_get_type())
790 new_dict = ghb_dict_value_new();
791 ghb_settings_take_value(dest, key, new_dict);
792 if (G_VALUE_TYPE(val) == ghb_dict_get_type())
793 init_settings_from_dict(new_dict, gval, val);
795 init_settings_from_dict(new_dict, gval, gval);
797 else if (G_VALUE_TYPE(gval) == ghb_array_get_type())
800 new_array = ghb_array_value_new(8);
801 ghb_settings_take_value(dest, key, new_array);
802 if (G_VALUE_TYPE(val) == ghb_array_get_type())
803 init_settings_from_array(new_array, gval, val);
805 init_settings_from_array(new_array, gval, gval);
810 ghb_settings_set_value(dest, key, val);
817 signal_user_data_t *ud,
825 ghb_dict_iter_init(&iter, internal);
826 // middle (void*) cast prevents gcc warning "defreferencing type-punned
827 // pointer will break strict-aliasing rules"
828 while (g_hash_table_iter_next(
829 &iter, (gpointer*)(void*)&key, (gpointer*)(void*)&gval))
833 val = ghb_dict_lookup(dict, key);
836 ghb_ui_update(ud, key, val);
841 preset_to_ui(signal_user_data_t *ud, GValue *dict)
843 g_debug("preset_to_ui()\n");
844 // Initialize the ui from presets file.
845 GValue *internal, *hidden;
847 // Get key list from internal default presets. This way we do not
848 // load any unknown keys.
849 if (internalPlist == NULL) return;
850 internal = plist_get_dict(internalPlist, "Presets");
851 hidden = plist_get_dict(internalPlist, "XlatPresets");
852 // Setting a ui widget will cause the corresponding setting
853 // to be set, but it also triggers a callback that can
854 // have the side effect of using other settings values
855 // that have not yet been set. So set *all* settings first
856 // then update the ui.
857 init_settings_from_dict(ud->settings, internal, dict);
858 init_settings_from_dict(ud->settings, hidden, dict);
859 init_ui_from_dict(ud, internal, dict);
860 init_ui_from_dict(ud, hidden, dict);
864 ghb_settings_to_ui(signal_user_data_t *ud, GValue *dict)
866 init_ui_from_dict(ud, dict, dict);
869 static GValue *current_preset = NULL;
872 ghb_preset_is_custom()
876 if (current_preset == NULL) return FALSE;
877 val = preset_dict_get_value(current_preset, "Type");
878 return (ghb_value_int(val) == 1);
882 ghb_set_preset_from_indices(signal_user_data_t *ud, gint *indices, gint len)
885 gint fallback[2] = {0, -1};
888 dict = presets_get_dict(presetsPlist, indices, len);
893 dict = presets_get_dict(presetsPlist, indices, len);
897 preset_to_ui(ud, NULL);
898 current_preset = NULL;
905 current_preset = dict;
906 folder = ghb_value_boolean(preset_dict_get_value(dict, "Folder"));
908 preset_to_ui(ud, NULL);
910 preset_to_ui(ud, dict);
911 path = preset_path_from_indices(presetsPlist, indices, len);
912 ghb_settings_set_value(ud->settings, "preset", path);
913 ghb_value_free(path);
918 curr_preset_get_value(const gchar *key)
920 if (current_preset == NULL) return NULL;
921 return preset_dict_get_value(current_preset, key);
925 ghb_update_from_preset(
926 signal_user_data_t *ud,
931 g_debug("ghb_update_from_preset() %s", key);
932 gval = curr_preset_get_value(key);
935 ghb_ui_update(ud, key, gval);
945 GtkTreeView *treeview;
946 GtkTreeSelection *selection;
951 g_debug("ghb_select_preset2()");
952 treeview = GTK_TREE_VIEW(GHB_WIDGET(builder, "presets_list"));
953 selection = gtk_tree_view_get_selection (treeview);
954 store = gtk_tree_view_get_model (treeview);
955 path = ghb_tree_path_new_from_indices(indices, len);
958 if (gtk_tree_model_get_iter(store, &iter, path))
960 gtk_tree_selection_select_iter (selection, &iter);
964 if (gtk_tree_model_get_iter_first(store, &iter))
965 gtk_tree_selection_select_iter (selection, &iter);
967 gtk_tree_path_free(path);
972 ghb_select_preset(GtkBuilder *builder, const GValue *path)
976 g_debug("ghb_select_preset()");
977 indices = ghb_preset_indices_from_path(presetsPlist, path, &len);
980 ghb_select_preset2(builder, indices, len);
986 ghb_select_default_preset(GtkBuilder *builder)
990 g_debug("ghb_select_default_preset()");
991 indices = presets_find_default(presetsPlist, &len);
994 ghb_select_preset2(builder, indices, len);
1000 ghb_get_user_config_dir(gchar *subdir)
1005 dir = g_get_user_config_dir();
1006 if (!g_file_test(dir, G_FILE_TEST_IS_DIR))
1008 dir = g_get_home_dir();
1009 config = g_strdup_printf ("%s/.ghb", dir);
1010 if (!g_file_test(config, G_FILE_TEST_IS_DIR))
1011 g_mkdir (config, 0755);
1015 config = g_strdup_printf ("%s/ghb", dir);
1016 if (!g_file_test(config, G_FILE_TEST_IS_DIR))
1017 g_mkdir (config, 0755);
1024 split = g_strsplit(subdir, "/", -1);
1025 for (ii = 0; split[ii] != NULL; ii++)
1029 tmp = g_strdup_printf ("%s/%s", config, split[ii]);
1032 if (!g_file_test(config, G_FILE_TEST_IS_DIR))
1033 g_mkdir (config, 0755);
1040 store_plist(GValue *plist, const gchar *name)
1042 gchar *config, *path;
1045 config = ghb_get_user_config_dir(NULL);
1046 path = g_strdup_printf ("%s/%s", config, name);
1047 file = g_fopen(path, "w");
1050 ghb_plist_write(file, plist);
1055 load_plist(const gchar *name)
1057 gchar *config, *path;
1058 GValue *plist = NULL;
1060 config = ghb_get_user_config_dir(NULL);
1061 path = g_strdup_printf ("%s/%s", config, name);
1062 if (g_file_test(path, G_FILE_TEST_IS_REGULAR))
1064 plist = ghb_plist_parse_file(path);
1072 remove_plist(const gchar *name)
1074 gchar *config, *path;
1076 config = ghb_get_user_config_dir(NULL);
1077 path = g_strdup_printf ("%s/%s", config, name);
1078 if (g_file_test(path, G_FILE_TEST_IS_REGULAR))
1086 static gboolean prefs_initializing = FALSE;
1089 ghb_prefs_to_ui(signal_user_data_t *ud)
1094 GValue *internal, *dict;
1095 GHashTableIter iter;
1098 g_debug("ghb_prefs_to_ui");
1099 prefs_initializing = TRUE;
1101 // Setting a ui widget will cause the corresponding setting
1102 // to be set, but it also triggers a callback that can
1103 // have the side effect of using other settings values
1104 // that have not yet been set. So set *all* settings first
1105 // then update the ui.
1106 internal = plist_get_dict(internalPlist, "Initialization");
1107 ghb_dict_iter_init(&iter, internal);
1108 // middle (void*) cast prevents gcc warning "defreferencing type-punned
1109 // pointer will break strict-aliasing rules"
1110 while (g_hash_table_iter_next(
1111 &iter, (gpointer*)(void*)&key, (gpointer*)(void*)&gval))
1113 ghb_ui_update(ud, key, gval);
1116 dict = plist_get_dict(prefsPlist, "Preferences");
1117 internal = plist_get_dict(internalPlist, "Preferences");
1118 ghb_dict_iter_init(&iter, internal);
1119 // middle (void*) cast prevents gcc warning "defreferencing type-punned
1120 // pointer will break strict-aliasing rules"
1121 while (g_hash_table_iter_next(
1122 &iter, (gpointer*)(void*)&key, (gpointer*)(void*)&gval))
1124 const GValue *value = NULL;
1126 value = ghb_dict_lookup(dict, key);
1129 ghb_settings_set_value(ud->settings, key, value);
1131 internal = plist_get_dict(internalPlist, "Preferences");
1132 ghb_dict_iter_init(&iter, internal);
1133 // middle (void*) cast prevents gcc warning "defreferencing type-punned
1134 // pointer will break strict-aliasing rules"
1135 while (g_hash_table_iter_next(
1136 &iter, (gpointer*)(void*)&key, (gpointer*)(void*)&gval))
1138 const GValue *value = NULL;
1140 value = ghb_dict_lookup(dict, key);
1143 ghb_ui_update(ud, key, value);
1146 val = ghb_settings_get_value(ud->settings, "show_presets");
1147 ghb_ui_update(ud, "show_presets", val);
1148 if (ghb_settings_get_boolean(ud->settings, "hbfd_feature"))
1151 val = ghb_settings_get_value(ud->settings, "hbfd");
1152 ghb_ui_update(ud, "hbfd", val);
1153 action = GHB_ACTION (ud->builder, "hbfd");
1154 gtk_action_set_visible(action, TRUE);
1158 ghb_ui_update(ud, "hbfd", ghb_int64_value(0));
1160 gval = ghb_settings_get_value(ud->settings, "default_source");
1161 ghb_settings_set_value (ud->settings, "source", gval);
1163 str = ghb_settings_get_string(ud->settings, "destination_dir");
1164 ghb_ui_update(ud, "dest_dir", ghb_string_value(str));
1166 gchar *file = g_strdup_printf ("new_video.mp4");
1167 ghb_ui_update(ud, "dest_file", ghb_string_value(file));
1171 prefs_initializing = FALSE;
1175 ghb_prefs_save(GValue *settings)
1179 GHashTableIter iter;
1181 const GValue *value;
1183 if (prefs_initializing) return;
1184 dict = plist_get_dict(internalPlist, "Preferences");
1185 if (dict == NULL) return;
1186 pref_dict = plist_get_dict(prefsPlist, "Preferences");
1187 if (pref_dict == NULL) return;
1188 ghb_dict_iter_init(&iter, dict);
1189 // middle (void*) cast prevents gcc warning "defreferencing type-punned
1190 // pointer will break strict-aliasing rules"
1191 while (g_hash_table_iter_next(
1192 &iter, (gpointer*)(void*)&key, (gpointer*)(void*)&value))
1194 value = ghb_settings_get_value(settings, key);
1197 ghb_dict_insert(pref_dict, g_strdup(key), ghb_value_dup(value));
1201 prefs_modified = FALSE;
1205 ghb_pref_set(GValue *settings, const gchar *key)
1207 const GValue *value, *value2;
1209 if (prefs_initializing) return;
1210 value = ghb_settings_get_value(settings, key);
1214 dict = plist_get_dict(prefsPlist, "Preferences");
1215 if (dict == NULL) return;
1216 value2 = ghb_dict_lookup(dict, key);
1217 if (ghb_value_cmp(value, value2) != 0)
1219 ghb_dict_insert(dict, g_strdup(key), ghb_value_dup(value));
1221 prefs_modified = TRUE;
1227 ghb_pref_save(GValue *settings, const gchar *key)
1229 const GValue *value, *value2;
1231 if (prefs_initializing) return;
1232 value = ghb_settings_get_value(settings, key);
1236 dict = plist_get_dict(prefsPlist, "Preferences");
1237 if (dict == NULL) return;
1238 value2 = ghb_dict_lookup(dict, key);
1239 if (ghb_value_cmp(value, value2) != 0)
1241 ghb_dict_insert(dict, g_strdup(key), ghb_value_dup(value));
1243 prefs_modified = FALSE;
1249 ghb_prefs_store(void)
1254 prefs_modified = FALSE;
1259 ghb_settings_init(signal_user_data_t *ud)
1262 GHashTableIter iter;
1267 g_debug("ghb_settings_init");
1268 prefs_initializing = TRUE;
1270 internalPlist = ghb_resource_get("internal-defaults");
1271 // Setting a ui widget will cause the corresponding setting
1272 // to be set, but it also triggers a callback that can
1273 // have the side effect of using other settings values
1274 // that have not yet been set. So set *all* settings first
1275 // then update the ui.
1276 internal = plist_get_dict(internalPlist, "Initialization");
1277 ghb_dict_iter_init(&iter, internal);
1278 // middle (void*) cast prevents gcc warning "defreferencing type-punned
1279 // pointer will break strict-aliasing rules"
1280 while (g_hash_table_iter_next(
1281 &iter, (gpointer*)(void*)&key, (gpointer*)(void*)&gval))
1283 ghb_settings_set_value(ud->settings, key, gval);
1286 internal = plist_get_dict(internalPlist, "Presets");
1287 ghb_dict_iter_init(&iter, internal);
1288 // middle (void*) cast prevents gcc warning "defreferencing type-punned
1289 // pointer will break strict-aliasing rules"
1290 while (g_hash_table_iter_next(
1291 &iter, (gpointer*)(void*)&key, (gpointer*)(void*)&gval))
1293 ghb_settings_set_value(ud->settings, key, gval);
1296 internal = plist_get_dict(internalPlist, "Preferences");
1297 ghb_dict_iter_init(&iter, internal);
1298 // middle (void*) cast prevents gcc warning "defreferencing type-punned
1299 // pointer will break strict-aliasing rules"
1300 while (g_hash_table_iter_next(
1301 &iter, (gpointer*)(void*)&key, (gpointer*)(void*)&gval))
1303 ghb_settings_set_value(ud->settings, key, gval);
1305 prefs_initializing = FALSE;
1309 ghb_settings_close()
1312 ghb_value_free(internalPlist);
1314 ghb_value_free(presetsPlist);
1316 ghb_value_free(prefsPlist);
1320 ghb_prefs_load(signal_user_data_t *ud)
1322 GValue *dict, *internal;
1323 GHashTableIter iter;
1325 GValue *gval, *path;
1327 g_debug("ghb_prefs_load");
1328 prefsPlist = load_plist("preferences");
1329 if (prefsPlist == NULL)
1330 prefsPlist = ghb_dict_value_new();
1331 dict = plist_get_dict(prefsPlist, "Preferences");
1332 internal = plist_get_dict(internalPlist, "Preferences");
1333 if (dict == NULL && internal)
1335 dict = ghb_dict_value_new();
1336 ghb_dict_insert(prefsPlist, g_strdup("Preferences"), dict);
1338 // Get defaults from internal defaults
1339 ghb_dict_iter_init(&iter, internal);
1340 // middle (void*) cast prevents gcc warning "defreferencing type-punned
1341 // pointer will break strict-aliasing rules"
1342 while (g_hash_table_iter_next(
1343 &iter, (gpointer*)(void*)&key, (gpointer*)(void*)&gval))
1345 ghb_dict_insert(dict, g_strdup(key), ghb_value_dup(gval));
1347 const gchar *dir = g_get_user_special_dir (G_USER_DIRECTORY_VIDEOS);
1352 ghb_dict_insert(dict,
1353 g_strdup("destination_dir"), ghb_value_dup(ghb_string_value(dir)));
1356 // Read legacy default_preset preference and update accordingly
1357 path = ghb_dict_lookup(dict, "default_preset");
1362 if (G_VALUE_TYPE(path) == G_TYPE_STRING)
1366 path = ghb_array_value_new(1);
1367 ghb_array_append(path, ghb_value_dup(str));
1368 indices = ghb_preset_indices_from_path(presetsPlist, path, &len);
1369 ghb_value_free(path);
1372 indices = ghb_preset_indices_from_path(presetsPlist, path, &len);
1376 presets_set_default(indices, len);
1379 ghb_dict_remove(dict, "default_preset");
1385 get_preset_color(gint type, gboolean folder)
1389 if (type == PRESETS_CUSTOM)
1409 ghb_presets_list_init(
1410 signal_user_data_t *ud,
1414 GtkTreeView *treeview;
1415 GtkTreeIter iter, titer, *piter;
1417 GtkTreeStore *store;
1418 const gchar *preset;
1419 GtkTreePath *parent_path;
1420 const gchar *description;
1425 GValue *presets = NULL;
1427 g_debug("ghb_presets_list_init ()");
1428 more_indices = g_malloc((len+1)*sizeof(gint));
1429 memcpy(more_indices, indices, len*sizeof(gint));
1430 presets = presets_get_folder(presetsPlist, indices, len);
1431 if (presets == NULL)
1433 g_warning("Failed to find parent folder when adding child.");
1436 count = ghb_array_len(presets);
1437 treeview = GTK_TREE_VIEW(GHB_WIDGET(ud->builder, "presets_list"));
1438 store = GTK_TREE_STORE(gtk_tree_view_get_model(treeview));
1439 parent_path = ghb_tree_path_new_from_indices(indices, len);
1442 gtk_tree_model_get_iter(GTK_TREE_MODEL(store), &titer, parent_path);
1444 gtk_tree_path_free(parent_path);
1450 for (ii = 0; ii < count; ii++)
1456 // Additional settings, add row
1457 dict = ghb_array_get_nth(presets, ii);
1458 preset = preset_get_name(dict);
1459 more_indices[len] = ii;
1460 def = preset_is_default(dict);
1462 description = ghb_presets_get_description(dict);
1463 gtk_tree_store_append(store, &iter, piter);
1464 type = ghb_preset_type(dict);
1465 folder = ghb_preset_folder(dict);
1466 color = get_preset_color(type, folder);
1467 gtk_tree_store_set(store, &iter, 0, preset,
1478 if (gtk_tree_model_iter_parent(
1479 GTK_TREE_MODEL(store), &ppiter, piter))
1481 path = gtk_tree_model_get_path(GTK_TREE_MODEL(store), &ppiter);
1482 gtk_tree_view_expand_row(treeview, path, FALSE);
1483 gtk_tree_path_free(path);
1485 path = gtk_tree_model_get_path(GTK_TREE_MODEL(store), piter);
1486 gtk_tree_view_expand_row(treeview, path, FALSE);
1487 gtk_tree_path_free(path);
1491 ghb_presets_list_init(ud, more_indices, len+1);
1492 if (preset_folder_is_open(dict))
1498 path = gtk_tree_model_get_path(GTK_TREE_MODEL(store), piter);
1499 gtk_tree_view_expand_row(treeview, path, FALSE);
1500 gtk_tree_path_free(path);
1502 path = gtk_tree_model_get_path(GTK_TREE_MODEL(store), &iter);
1503 gtk_tree_view_expand_row(treeview, path, FALSE);
1504 gtk_tree_path_free(path);
1508 g_free(more_indices);
1512 presets_list_update_item(
1513 signal_user_data_t *ud,
1517 GtkTreeView *treeview;
1518 GtkTreeStore *store;
1520 GtkTreePath *treepath;
1522 const gchar *description;
1524 gboolean def, folder;
1528 g_debug("presets_list_update_item ()");
1529 dict = presets_get_dict(presetsPlist, indices, len);
1532 treeview = GTK_TREE_VIEW(GHB_WIDGET(ud->builder, "presets_list"));
1533 store = GTK_TREE_STORE(gtk_tree_view_get_model(treeview));
1534 treepath = ghb_tree_path_new_from_indices(indices, len);
1535 gtk_tree_model_get_iter(GTK_TREE_MODEL(store), &iter, treepath);
1536 // Additional settings, add row
1537 name = preset_get_name(dict);
1538 def = preset_is_default(dict);
1540 description = ghb_presets_get_description(dict);
1541 type = ghb_preset_type(dict);
1542 folder = ghb_preset_folder(dict);
1543 color = get_preset_color(type, folder);
1544 gtk_tree_store_set(store, &iter, 0, name,
1552 ghb_presets_list_init(ud, indices, len);
1557 presets_list_insert(
1558 signal_user_data_t *ud,
1562 GtkTreeView *treeview;
1563 GtkTreeIter iter, titer, *piter;
1564 GtkTreeStore *store;
1565 const gchar *preset;
1566 const gchar *description;
1568 gboolean def, folder;
1571 GtkTreePath *parent_path;
1575 g_debug("presets_list_insert ()");
1576 treeview = GTK_TREE_VIEW(GHB_WIDGET(ud->builder, "presets_list"));
1577 store = GTK_TREE_STORE(gtk_tree_view_get_model(treeview));
1578 presets = presets_get_folder(presetsPlist, indices, len-1);
1579 if (presets == NULL)
1581 g_warning("Failed to find parent folder while adding child.");
1584 parent_path = ghb_tree_path_new_from_indices(indices, len-1);
1587 gtk_tree_model_get_iter(GTK_TREE_MODEL(store), &titer, parent_path);
1589 gtk_tree_path_free(parent_path);
1595 count = ghb_array_len(presets);
1596 if (indices[len-1] >= count)
1598 // Additional settings, add row
1599 dict = ghb_array_get_nth(presets, indices[len-1]);
1600 preset = preset_get_name(dict);
1601 def = preset_is_default(dict);
1603 description = ghb_presets_get_description(dict);
1604 gtk_tree_store_insert(store, &iter, piter, indices[len-1]);
1605 type = ghb_preset_type(dict);
1606 folder = ghb_preset_folder(dict);
1607 color = get_preset_color(type, folder);
1608 gtk_tree_store_set(store, &iter, 0, preset,
1616 ghb_presets_list_init(ud, indices, len);
1621 presets_list_remove(
1622 signal_user_data_t *ud,
1626 GtkTreeView *treeview;
1627 GtkTreePath *treepath;
1629 GtkTreeStore *store;
1631 g_debug("presets_list_remove ()");
1632 treeview = GTK_TREE_VIEW(GHB_WIDGET(ud->builder, "presets_list"));
1633 store = GTK_TREE_STORE(gtk_tree_view_get_model(treeview));
1634 treepath = ghb_tree_path_new_from_indices(indices, len);
1637 if (gtk_tree_model_get_iter(GTK_TREE_MODEL(store), &iter, treepath))
1638 gtk_tree_store_remove(store, &iter);
1639 gtk_tree_path_free(treepath);
1644 remove_std_presets(signal_user_data_t *ud)
1649 count = ghb_array_len(presetsPlist);
1650 for (ii = count-1; ii >= 0; ii--)
1655 dict = ghb_array_get_nth(presetsPlist, ii);
1656 ptype = ghb_value_int(preset_dict_get_value(dict, "Type"));
1657 if (ptype == PRESETS_BUILTIN)
1659 if (ghb_presets_remove(presetsPlist, &indices, 1))
1661 presets_list_remove(ud, &indices, 1);
1668 ghb_save_queue(GValue *queue)
1670 store_plist(queue, "queue");
1676 return load_plist("queue");
1680 ghb_remove_queue_file()
1682 remove_plist("queue");
1691 static value_map_t vcodec_xlat[] =
1693 {"MPEG-4 (FFmpeg)", "ffmpeg"},
1694 {"MPEG-4 (XviD)", "ffmpeg"},
1695 {"H.264 (x264)", "x264"},
1696 {"VP3 (Theora)", "theora"},
1700 static value_map_t acodec_xlat[] =
1702 {"AAC (faac)", "faac"},
1703 {"AC3 Passthru", "ac3"},
1704 {"MP3 (lame)", "lame"},
1705 {"Vorbis (vorbis)", "vorbis"},
1709 value_map_t container_xlat[] =
1711 {"MP4 file", "mp4"},
1712 {"M4V file", "m4v"},
1713 {"MKV file", "mkv"},
1714 {"AVI file", "mkv"},
1715 {"OGM file", "mkv"},
1719 value_map_t framerate_xlat[] =
1721 {"Same as source", "source"},
1726 {"23.976", "23.976"},
1733 value_map_t samplerate_xlat[] =
1744 value_map_t mix_xlat[] =
1747 {"Stereo", "stereo"},
1748 {"Dolby Surround", "dpl1"},
1749 {"Dolby Pro Logic II", "dpl2"},
1750 {"6-channel discrete", "6ch"},
1751 {"AC3 Passthru", "none"},
1755 value_map_t deint_xlat[] =
1765 value_map_t denoise_xlat[] =
1775 value_map_t detel_xlat[] =
1783 value_map_t decomb_xlat[] =
1791 extern iso639_lang_t ghb_language_table[];
1794 export_lang_xlat2(GValue *lin_val)
1798 if (lin_val == NULL) return NULL;
1802 str = ghb_value_string(lin_val);
1803 for (ii = 0; ghb_language_table[ii].eng_name; ii++)
1805 if (strcmp(str, ghb_language_table[ii].iso639_2) == 0)
1807 gval = ghb_string_value_new(ghb_language_table[ii].eng_name);
1812 g_debug("Can't map language value: (%s)", str);
1818 export_subtitle_xlat2(GValue *lin_val)
1823 if (lin_val == NULL) return NULL;
1824 str = ghb_value_string(lin_val);
1825 if (strcmp(str, "none") == 0)
1827 gval = ghb_string_value_new("None");
1829 else if (strcmp(str, "auto") == 0)
1831 gval = ghb_string_value_new("Autoselect");
1835 gval = export_lang_xlat2(lin_val);
1842 import_lang_xlat2(GValue *mac_val)
1846 if (mac_val == NULL) return NULL;
1850 str = ghb_value_string(mac_val);
1851 for (ii = 0; ghb_language_table[ii].eng_name; ii++)
1853 if (strcmp(str, ghb_language_table[ii].eng_name) == 0)
1855 gval = ghb_string_value_new(ghb_language_table[ii].iso639_2);
1860 g_debug("Can't map language value: (%s)", str);
1866 import_subtitle_xlat2(GValue *mac_val)
1871 if (mac_val == NULL) return NULL;
1872 str = ghb_value_string(mac_val);
1873 if (strcmp(str, "None") == 0)
1875 gval = ghb_string_value_new("none");
1877 else if (strcmp(str, "Autoselect") == 0)
1879 gval = ghb_string_value_new("auto");
1883 gval = import_lang_xlat2(mac_val);
1890 export_audio_track_xlat2(GValue *lin_val)
1893 GValue *gval = NULL;
1895 if (lin_val == NULL) return NULL;
1896 str = ghb_value_string(lin_val);
1897 if (strcmp(str, "none") == 0)
1899 gval = ghb_int_value_new(1);
1903 gint val = ghb_value_int(lin_val) + 1;
1904 gval = ghb_int_value_new(val);
1911 import_audio_track_xlat2(GValue *mac_val)
1917 if (mac_val == NULL) return NULL;
1918 val = ghb_value_int(mac_val);
1927 str = g_strdup_printf("%d", val);
1928 gval = ghb_string_value_new(str);
1934 export_value_xlat2(value_map_t *value_map, GValue *lin_val, GType mac_type)
1938 if (lin_val == NULL) return NULL;
1943 str = ghb_value_string(lin_val);
1944 for (ii = 0; value_map[ii].mac_val; ii++)
1946 if (strcmp(str, value_map[ii].lin_val) == 0)
1948 sval = ghb_string_value_new(value_map[ii].mac_val);
1950 gval = ghb_value_new(mac_type);
1951 if (!g_value_transform(sval, gval))
1953 g_warning("can't transform");
1954 ghb_value_free(gval);
1955 ghb_value_free(sval);
1958 ghb_value_free(sval);
1962 g_debug("Can't map value: (%s)", str);
1968 export_value_xlat(GValue *dict)
1970 GValue *lin_val, *gval;
1973 key = "VideoEncoder";
1974 lin_val = ghb_dict_lookup(dict, key);
1975 gval = export_value_xlat2(vcodec_xlat, lin_val, G_TYPE_STRING);
1977 ghb_dict_insert(dict, g_strdup(key), gval);
1979 lin_val = ghb_dict_lookup(dict, key);
1980 gval = export_value_xlat2(container_xlat, lin_val, G_TYPE_STRING);
1982 ghb_dict_insert(dict, g_strdup(key), gval);
1983 key = "VideoFramerate";
1984 lin_val = ghb_dict_lookup(dict, key);
1985 gval = export_value_xlat2(framerate_xlat, lin_val, G_TYPE_STRING);
1987 ghb_dict_insert(dict, g_strdup(key), gval);
1988 key = "PictureDetelecine";
1989 lin_val = ghb_dict_lookup(dict, key);
1990 gval = export_value_xlat2(detel_xlat, lin_val, G_TYPE_INT);
1992 ghb_dict_insert(dict, g_strdup(key), gval);
1993 key = "PictureDecomb";
1994 lin_val = ghb_dict_lookup(dict, key);
1995 gval = export_value_xlat2(decomb_xlat, lin_val, G_TYPE_INT);
1997 ghb_dict_insert(dict, g_strdup(key), gval);
1998 key = "PictureDeinterlace";
1999 lin_val = ghb_dict_lookup(dict, key);
2000 gval = export_value_xlat2(deint_xlat, lin_val, G_TYPE_INT);
2002 ghb_dict_insert(dict, g_strdup(key), gval);
2003 key = "PictureDenoise";
2004 lin_val = ghb_dict_lookup(dict, key);
2005 gval = export_value_xlat2(denoise_xlat, lin_val, G_TYPE_INT);
2007 ghb_dict_insert(dict, g_strdup(key), gval);
2009 lin_val = ghb_dict_lookup(dict, key);
2010 gval = export_subtitle_xlat2(lin_val);
2012 ghb_dict_insert(dict, g_strdup(key), gval);
2018 alist = ghb_dict_lookup(dict, "AudioList");
2019 count = ghb_array_len(alist);
2020 for (ii = 0; ii < count; ii++)
2022 adict = ghb_array_get_nth(alist, ii);
2024 lin_val = ghb_dict_lookup(adict, key);
2025 gval = export_audio_track_xlat2(lin_val);
2027 ghb_dict_insert(adict, g_strdup(key), gval);
2028 key = "AudioEncoder";
2029 lin_val = ghb_dict_lookup(adict, key);
2030 gval = export_value_xlat2(acodec_xlat, lin_val, G_TYPE_STRING);
2032 ghb_dict_insert(adict, g_strdup(key), gval);
2033 key = "AudioSamplerate";
2034 lin_val = ghb_dict_lookup(adict, key);
2035 gval = export_value_xlat2(samplerate_xlat, lin_val, G_TYPE_STRING);
2037 ghb_dict_insert(adict, g_strdup(key), gval);
2038 key = "AudioMixdown";
2039 lin_val = ghb_dict_lookup(adict, key);
2040 gval = export_value_xlat2(mix_xlat, lin_val, G_TYPE_STRING);
2042 ghb_dict_insert(adict, g_strdup(key), gval);
2050 value_map_t *value_map,
2054 GValue *gval, *def_val;
2056 if (mac_val == NULL) return NULL;
2057 def_val = ghb_dict_lookup(defaults, key);
2064 str = ghb_value_string(mac_val);
2065 for (ii = 0; value_map[ii].mac_val; ii++)
2067 if (strcmp(str, value_map[ii].mac_val) == 0)
2069 sval = ghb_string_value_new(value_map[ii].lin_val);
2071 gval = ghb_value_new(G_VALUE_TYPE(def_val));
2072 if (!g_value_transform(sval, gval))
2074 g_warning("can't transform");
2075 ghb_value_free(gval);
2076 ghb_value_free(sval);
2079 ghb_value_free(sval);
2083 //g_warning("Can't map value: (%s)", str);
2088 g_warning("Bad key: (%s)", key);
2095 import_value_xlat(GValue *dict)
2097 GValue *defaults, *mac_val, *gval;
2100 defaults = plist_get_dict(internalPlist, "Presets");
2101 key = "VideoEncoder";
2102 mac_val = ghb_dict_lookup(dict, key);
2103 gval = import_value_xlat2(defaults, vcodec_xlat, key, mac_val);
2105 ghb_dict_insert(dict, g_strdup(key), gval);
2107 mac_val = ghb_dict_lookup(dict, key);
2108 gval = import_value_xlat2(defaults, container_xlat, key, mac_val);
2110 ghb_dict_insert(dict, g_strdup(key), gval);
2111 key = "VideoFramerate";
2112 mac_val = ghb_dict_lookup(dict, key);
2113 gval = import_value_xlat2(defaults, framerate_xlat, key, mac_val);
2115 ghb_dict_insert(dict, g_strdup(key), gval);
2116 key = "PictureDetelecine";
2117 mac_val = ghb_dict_lookup(dict, key);
2118 gval = import_value_xlat2(defaults, detel_xlat, key, mac_val);
2120 ghb_dict_insert(dict, g_strdup(key), gval);
2121 key = "PictureDecomb";
2122 mac_val = ghb_dict_lookup(dict, key);
2123 gval = import_value_xlat2(defaults, decomb_xlat, key, mac_val);
2125 ghb_dict_insert(dict, g_strdup(key), gval);
2126 key = "PictureDeinterlace";
2127 mac_val = ghb_dict_lookup(dict, key);
2128 gval = import_value_xlat2(defaults, deint_xlat, key, mac_val);
2130 ghb_dict_insert(dict, g_strdup(key), gval);
2131 key = "PictureDenoise";
2132 mac_val = ghb_dict_lookup(dict, key);
2133 gval = import_value_xlat2(defaults, denoise_xlat, key, mac_val);
2135 ghb_dict_insert(dict, g_strdup(key), gval);
2137 mac_val = ghb_dict_lookup(dict, key);
2138 gval = import_subtitle_xlat2(mac_val);
2140 ghb_dict_insert(dict, g_strdup(key), gval);
2148 adeflist = ghb_dict_lookup(dict, "AudioList");
2151 adefaults = ghb_array_get_nth(adeflist, 0);
2152 alist = ghb_dict_lookup(dict, "AudioList");
2153 count = ghb_array_len(alist);
2154 for (ii = 0; ii < count; ii++)
2156 adict = ghb_array_get_nth(alist, ii);
2158 mac_val = ghb_dict_lookup(adict, key);
2159 gval = import_audio_track_xlat2(mac_val);
2161 ghb_dict_insert(adict, g_strdup(key), gval);
2162 key = "AudioEncoder";
2163 mac_val = ghb_dict_lookup(adict, key);
2164 gval = import_value_xlat2(adefaults, acodec_xlat, key, mac_val);
2166 ghb_dict_insert(adict, g_strdup(key), gval);
2167 key = "AudioSamplerate";
2168 mac_val = ghb_dict_lookup(adict, key);
2169 gval = import_value_xlat2(adefaults, samplerate_xlat, key, mac_val);
2171 ghb_dict_insert(adict, g_strdup(key), gval);
2172 key = "AudioMixdown";
2173 mac_val = ghb_dict_lookup(adict, key);
2174 gval = import_value_xlat2(adefaults, mix_xlat, key, mac_val);
2176 ghb_dict_insert(adict, g_strdup(key), gval);
2182 import_xlat_preset(GValue *dict)
2189 g_debug("import_xlat_preset ()");
2190 uses_max = ghb_value_boolean(
2191 preset_dict_get_value(dict, "UsesMaxPictureSettings"));
2192 uses_pic = ghb_value_int(
2193 preset_dict_get_value(dict, "UsesPictureSettings"));
2194 par = ghb_value_int(preset_dict_get_value(dict, "PicturePAR"));
2195 vqtype = ghb_value_int(preset_dict_get_value(dict, "VideoQualityType"));
2197 if (uses_max || uses_pic == 2)
2199 ghb_dict_insert(dict, g_strdup("autoscale"),
2200 ghb_boolean_value_new(TRUE));
2206 if (ghb_dict_lookup(dict, "PictureAlignment") == NULL)
2207 ghb_dict_insert(dict, g_strdup("PictureAlignment"),
2208 ghb_int_value_new(16));
2212 ghb_dict_insert(dict, g_strdup("PictureAlignment"),
2213 ghb_int_value_new(1));
2217 if (ghb_dict_lookup(dict, "PictureAlignment") == NULL)
2218 ghb_dict_insert(dict, g_strdup("PictureAlignment"),
2219 ghb_int_value_new(16));
2223 if (ghb_dict_lookup(dict, "PictureAlignment") == NULL)
2224 ghb_dict_insert(dict, g_strdup("PictureAlignment"),
2225 ghb_int_value_new(16));
2228 // VideoQualityType/0/1/2 - vquality_type_/target/bitrate/constant
2233 ghb_dict_insert(dict, g_strdup("vquality_type_target"),
2234 ghb_boolean_value_new(TRUE));
2235 ghb_dict_insert(dict, g_strdup("vquality_type_bitrate"),
2236 ghb_boolean_value_new(FALSE));
2237 ghb_dict_insert(dict, g_strdup("vquality_type_constant"),
2238 ghb_boolean_value_new(FALSE));
2242 ghb_dict_insert(dict, g_strdup("vquality_type_target"),
2243 ghb_boolean_value_new(FALSE));
2244 ghb_dict_insert(dict, g_strdup("vquality_type_bitrate"),
2245 ghb_boolean_value_new(TRUE));
2246 ghb_dict_insert(dict, g_strdup("vquality_type_constant"),
2247 ghb_boolean_value_new(FALSE));
2251 ghb_dict_insert(dict, g_strdup("vquality_type_target"),
2252 ghb_boolean_value_new(FALSE));
2253 ghb_dict_insert(dict, g_strdup("vquality_type_bitrate"),
2254 ghb_boolean_value_new(FALSE));
2255 ghb_dict_insert(dict, g_strdup("vquality_type_constant"),
2256 ghb_boolean_value_new(TRUE));
2260 ghb_dict_insert(dict, g_strdup("vquality_type_target"),
2261 ghb_boolean_value_new(FALSE));
2262 ghb_dict_insert(dict, g_strdup("vquality_type_bitrate"),
2263 ghb_boolean_value_new(FALSE));
2264 ghb_dict_insert(dict, g_strdup("vquality_type_constant"),
2265 ghb_boolean_value_new(TRUE));
2268 import_value_xlat(dict);
2273 vquality = ghb_value_double(preset_dict_get_value(dict, "VideoQualitySlider"));
2278 gval = preset_dict_get_value(dict, "VideoEncoder");
2279 vcodec = ghb_lookup_combo_int("VideoEncoder", gval);
2282 case HB_VCODEC_X264:
2284 vquality = 51. - vquality * 51.;
2287 case HB_VCODEC_XVID:
2288 case HB_VCODEC_FFMPEG:
2290 vquality = 31. - vquality * 30.;
2293 case HB_VCODEC_THEORA:
2295 vquality = vquality * 63.;
2303 ghb_dict_insert(dict, g_strdup("VideoQualitySlider"),
2304 ghb_double_value_new(vquality));
2309 import_xlat_presets(GValue *presets)
2315 g_debug("import_xlat_presets ()");
2316 if (presets == NULL) return;
2317 count = ghb_array_len(presets);
2318 for (ii = 0; ii < count; ii++)
2320 dict = ghb_array_get_nth(presets, ii);
2321 folder = ghb_value_boolean(preset_dict_get_value(dict, "Folder"));
2326 nested = ghb_dict_lookup(dict, "ChildrenArray");
2327 import_xlat_presets(nested);
2331 import_xlat_preset(dict);
2337 export_xlat_preset(GValue *dict)
2339 gboolean autoscale, target, br, constant;
2341 g_debug("export_xlat_prest ()");
2342 autoscale = ghb_value_boolean(preset_dict_get_value(dict, "autoscale"));
2343 target = ghb_value_boolean(
2344 preset_dict_get_value(dict, "vquality_type_target"));
2345 br = ghb_value_boolean(
2346 preset_dict_get_value(dict, "vquality_type_bitrate"));
2347 constant = ghb_value_boolean(
2348 preset_dict_get_value(dict, "vquality_type_constant"));
2351 ghb_dict_insert(dict, g_strdup("UsesPictureSettings"),
2352 ghb_int_value_new(2));
2354 ghb_dict_insert(dict, g_strdup("UsesPictureSettings"),
2355 ghb_int_value_new(1));
2357 // VideoQualityType/0/1/2 - vquality_type_/target/bitrate/constant
2360 ghb_dict_insert(dict, g_strdup("VideoQualityType"),
2361 ghb_int_value_new(0));
2365 ghb_dict_insert(dict, g_strdup("VideoQualityType"),
2366 ghb_int_value_new(1));
2370 ghb_dict_insert(dict, g_strdup("VideoQualityType"),
2371 ghb_int_value_new(2));
2373 ghb_dict_remove(dict, "UsesMaxPictureSettings");
2374 ghb_dict_remove(dict, "autoscale");
2375 ghb_dict_remove(dict, "vquality_type_target");
2376 ghb_dict_remove(dict, "vquality_type_bitrate");
2377 ghb_dict_remove(dict, "vquality_type_constant");
2378 export_value_xlat(dict);
2382 export_xlat_presets(GValue *presets)
2388 if (presets == NULL) return;
2389 count = ghb_array_len(presets);
2390 for (ii = 0; ii < count; ii++)
2392 dict = ghb_array_get_nth(presets, ii);
2393 folder = ghb_value_boolean(preset_dict_get_value(dict, "Folder"));
2398 nested = ghb_dict_lookup(dict, "ChildrenArray");
2399 export_xlat_presets(nested);
2403 export_xlat_preset(dict);
2408 static guint prefs_timeout_id = 0;
2411 delayed_store_prefs(gpointer data)
2413 store_plist(prefsPlist, "preferences");
2414 prefs_timeout_id = 0;
2423 export = ghb_value_dup(presetsPlist);
2424 export_xlat_presets(export);
2425 store_plist(export, "presets");
2426 ghb_value_free(export);
2432 if (prefs_timeout_id != 0)
2437 mc = g_main_context_default();
2438 source = g_main_context_find_source_by_id(mc, prefs_timeout_id);
2440 g_source_destroy(source);
2442 prefs_timeout_id = g_timeout_add_seconds(1, (GSourceFunc)delayed_store_prefs, NULL);
2446 ghb_presets_reload(signal_user_data_t *ud)
2448 GValue *std_presets;
2452 g_debug("ghb_presets_reload()\n");
2453 std_presets = ghb_resource_get("standard-presets");
2454 if (std_presets == NULL) return;
2456 remove_std_presets(ud);
2457 indices = presets_find_default(presetsPlist, &len);
2460 presets_clear_default(std_presets);
2463 // Merge the keyfile contents into our presets
2464 count = ghb_array_len(std_presets);
2465 for (ii = count-1; ii >= 0; ii--)
2471 std_dict = ghb_array_get_nth(std_presets, ii);
2472 copy_dict = ghb_value_dup(std_dict);
2473 ghb_presets_insert(presetsPlist, copy_dict, &indices, 1);
2474 presets_list_insert(ud, &indices, 1);
2476 import_xlat_presets(presetsPlist);
2485 count = ghb_array_len(presetsPlist);
2486 for (ii = count-1; ii >= 0; ii--)
2491 dict = ghb_array_get_nth(presetsPlist, ii);
2492 type = ghb_dict_lookup(dict, "Type");
2502 presetsPlist = load_plist("presets");
2503 if (presetsPlist == NULL)
2505 presetsPlist = ghb_value_dup(ghb_resource_get("standard-presets"));
2506 import_xlat_presets(presetsPlist);
2509 else if (G_VALUE_TYPE(presetsPlist) == ghb_dict_get_type())
2510 { // Presets is older dictionary format. Convert to array
2511 ghb_value_free(presetsPlist);
2512 presetsPlist = ghb_value_dup(ghb_resource_get("standard-presets"));
2513 import_xlat_presets(presetsPlist);
2516 else if (check_old_presets())
2518 ghb_value_free(presetsPlist);
2519 presetsPlist = ghb_value_dup(ghb_resource_get("standard-presets"));
2520 import_xlat_presets(presetsPlist);
2523 import_xlat_presets(presetsPlist);
2527 settings_save(signal_user_data_t *ud, const GValue *path)
2529 GValue *dict, *internal;
2530 GHashTableIter iter;
2534 gint *indices, len, count;
2536 gboolean replace = FALSE;
2538 g_debug("settings_save");
2539 if (internalPlist == NULL) return;
2540 count = ghb_array_len(path);
2541 name = g_value_get_string(ghb_array_get_nth(path, count-1));
2542 indices = ghb_preset_indices_from_path(presetsPlist, path, &len);
2545 if (ghb_presets_get_folder(presetsPlist, indices, len))
2548 message = g_strdup_printf(
2549 "%s: Folder already exists.\n"
2550 "You can not replace it with a preset.",
2552 ghb_message_dialog(GTK_MESSAGE_ERROR, message, "Cancel", NULL);
2556 dict = ghb_dict_value_new();
2557 ghb_presets_replace(presetsPlist, dict, indices, len);
2562 indices = presets_find_pos(path, PRESETS_CUSTOM, &len);
2565 dict = ghb_dict_value_new();
2566 ghb_presets_insert(presetsPlist, dict, indices, len);
2570 g_warning("failed to find insert path");
2574 current_preset = dict;
2575 autoscale = ghb_settings_get_boolean(ud->settings, "autoscale");
2576 ghb_settings_set_int64(ud->settings, "Type", PRESETS_CUSTOM);
2578 internal = plist_get_dict(internalPlist, "Presets");
2579 ghb_dict_iter_init(&iter, internal);
2580 // middle (void*) cast prevents gcc warning "defreferencing type-punned
2581 // pointer will break strict-aliasing rules"
2582 while (g_hash_table_iter_next(
2583 &iter, (gpointer*)(void*)&key, (gpointer*)(void*)&value))
2591 if (strcmp(key, "PictureWidth") == 0)
2593 key2 = "scale_width";
2595 else if (strcmp(key, "PictureHeight") == 0)
2597 key2 = "scale_height";
2600 gval = ghb_settings_get_value(ud->settings, key2);
2605 ghb_dict_insert(dict, g_strdup(key), ghb_value_dup(gval));
2607 internal = plist_get_dict(internalPlist, "XlatPresets");
2608 ghb_dict_iter_init(&iter, internal);
2609 // middle (void*) cast prevents gcc warning "defreferencing type-punned
2610 // pointer will break strict-aliasing rules"
2611 while (g_hash_table_iter_next(
2612 &iter, (gpointer*)(void*)&key, (gpointer*)(void*)&value))
2616 gval = ghb_settings_get_value(ud->settings, key);
2621 ghb_dict_insert(dict, g_strdup(key), ghb_value_dup(gval));
2623 ghb_dict_insert(dict, g_strdup("PresetName"), ghb_string_value_new(name));
2625 presets_list_update_item(ud, indices, len);
2628 ghb_dict_insert(dict, g_strdup("Default"),
2629 ghb_boolean_value_new(FALSE));
2630 presets_list_insert(ud, indices, len);
2633 ud->dont_clear_presets = TRUE;
2634 // Make the new preset the selected item
2635 ghb_select_preset2(ud->builder, indices, len);
2637 ud->dont_clear_presets = FALSE;
2642 folder_save(signal_user_data_t *ud, const GValue *path)
2644 GValue *dict, *folder;
2645 gint *indices, len, count;
2648 count = ghb_array_len(path);
2649 name = g_value_get_string(ghb_array_get_nth(path, count-1));
2650 indices = ghb_preset_indices_from_path(presetsPlist, path, &len);
2653 if (!ghb_presets_get_folder(presetsPlist, indices, len))
2656 message = g_strdup_printf(
2657 "%s: Preset already exists.\n"
2658 "You can not replace it with a folder.",
2660 ghb_message_dialog(GTK_MESSAGE_ERROR, message, "Cancel", NULL);
2665 // Already exists, update its description
2666 dict = presets_get_dict(presetsPlist, indices, len);
2667 ghb_dict_insert(dict, g_strdup("PresetDescription"),
2668 ghb_value_dup(preset_dict_get_value(
2669 ud->settings, "PresetDescription")));
2675 indices = presets_find_pos(path, PRESETS_CUSTOM, &len);
2678 dict = ghb_dict_value_new();
2679 ghb_presets_insert(presetsPlist, dict, indices, len);
2683 g_warning("failed to find insert path");
2687 ghb_dict_insert(dict, g_strdup("PresetDescription"),
2688 ghb_value_dup(preset_dict_get_value(
2689 ud->settings, "PresetDescription")));
2690 ghb_dict_insert(dict, g_strdup("PresetName"), ghb_string_value_new(name));
2691 folder = ghb_array_value_new(8);
2692 ghb_dict_insert(dict, g_strdup("ChildrenArray"), folder);
2693 ghb_dict_insert(dict, g_strdup("Type"),
2694 ghb_int64_value_new(PRESETS_CUSTOM));
2695 ghb_dict_insert(dict, g_strdup("Folder"), ghb_boolean_value_new(TRUE));
2697 presets_list_insert(ud, indices, len);
2704 ghb_presets_list_default(signal_user_data_t *ud)
2706 GtkTreeView *treeview;
2707 GtkTreePath *treepath;
2709 GtkTreeStore *store;
2712 g_debug("ghb_presets_list_default ()");
2713 treeview = GTK_TREE_VIEW(GHB_WIDGET(ud->builder, "presets_list"));
2714 store = GTK_TREE_STORE(gtk_tree_view_get_model(treeview));
2715 indices = presets_find_default(presetsPlist, &len);
2716 if (indices == NULL) return;
2717 treepath = ghb_tree_path_new_from_indices(indices, len);
2720 if (gtk_tree_model_get_iter(GTK_TREE_MODEL(store), &iter, treepath))
2722 gtk_tree_store_set(store, &iter,
2727 gtk_tree_path_free(treepath);
2733 ghb_presets_list_clear_default(signal_user_data_t *ud)
2735 GtkTreeView *treeview;
2736 GtkTreePath *treepath;
2738 GtkTreeStore *store;
2741 g_debug("ghb_presets_list_clear_default ()");
2742 treeview = GTK_TREE_VIEW(GHB_WIDGET(ud->builder, "presets_list"));
2743 store = GTK_TREE_STORE(gtk_tree_view_get_model(treeview));
2744 indices = presets_find_default(presetsPlist, &len);
2745 if (indices == NULL) return;
2746 treepath = ghb_tree_path_new_from_indices(indices, len);
2749 if (gtk_tree_model_get_iter(GTK_TREE_MODEL(store), &iter, treepath))
2751 gtk_tree_store_set(store, &iter,
2756 gtk_tree_path_free(treepath);
2762 update_audio_presets(signal_user_data_t *ud)
2764 g_debug("update_audio_presets");
2765 const GValue *audio_list;
2767 audio_list = ghb_settings_get_value(ud->settings, "audio_list");
2768 ghb_settings_set_value(ud->settings, "AudioList", audio_list);
2772 enforce_preset_type(signal_user_data_t *ud, const GValue *path)
2775 GtkWidget *normal, *folder;
2778 normal = GHB_WIDGET(ud->builder, "preset_type_normal");
2779 folder = GHB_WIDGET(ud->builder, "preset_type_folder");
2780 indices = ghb_preset_indices_from_path(presetsPlist, path, &len);
2783 fold = ghb_presets_get_folder(presetsPlist, indices, len);
2785 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(folder),
2788 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(normal),
2790 gtk_widget_set_sensitive(folder, fold);
2791 gtk_widget_set_sensitive(normal, !fold);
2796 gtk_widget_set_sensitive(folder, TRUE);
2797 gtk_widget_set_sensitive(normal, TRUE);
2802 presets_save_clicked_cb(GtkWidget *xwidget, signal_user_data_t *ud)
2807 GtkResponseType response;
2809 const gchar *name = "";
2810 gint count, *indices, len;
2812 g_debug("presets_save_clicked_cb ()");
2813 preset = ghb_settings_get_value (ud->settings, "preset_selection");
2815 count = ghb_array_len(preset);
2817 name = g_value_get_string(ghb_array_get_nth(preset, count-1));
2820 // Clear the description
2821 desc = GTK_TEXT_VIEW(GHB_WIDGET(ud->builder, "PresetDescription"));
2822 dialog = GHB_WIDGET(ud->builder, "preset_save_dialog");
2823 entry = GTK_ENTRY(GHB_WIDGET(ud->builder, "PresetName"));
2824 gtk_entry_set_text(entry, name);
2825 enforce_preset_type(ud, preset);
2826 response = gtk_dialog_run(GTK_DIALOG(dialog));
2827 gtk_widget_hide(dialog);
2828 if (response == GTK_RESPONSE_OK)
2831 const gchar *name = gtk_entry_get_text(entry);
2834 if (ghb_settings_get_boolean(ud->settings, "preset_type_folder"))
2836 if (count > MAX_NESTED_PRESET-1)
2838 count = MAX_NESTED_PRESET-1;
2841 dest = ghb_array_value_new(MAX_NESTED_PRESET);
2842 indices = ghb_preset_indices_from_path(presetsPlist, preset, &len);
2847 ptype = ghb_presets_get_type(presetsPlist, indices, len);
2848 if (ptype == PRESETS_CUSTOM)
2850 ghb_array_copy(dest, preset, count-1);
2853 ghb_array_append(dest, ghb_string_value_new(name));
2855 ghb_widget_to_setting(ud->settings, GTK_WIDGET(desc));
2856 if (ghb_settings_get_boolean(ud->settings, "preset_type_folder"))
2858 folder_save(ud, dest);
2862 // Construct the audio settings presets from the current audio list
2863 update_audio_presets(ud);
2864 settings_save(ud, dest);
2866 ghb_value_free(dest);
2871 preset_type_changed_cb(GtkWidget *widget, signal_user_data_t *ud)
2873 ghb_widget_to_setting(ud->settings, widget);
2877 preset_name_changed_cb(GtkWidget *entry, signal_user_data_t *ud)
2880 GValue *preset, *dest;
2883 preset = ghb_settings_get_value (ud->settings, "preset_selection");
2884 name = ghb_widget_string(entry);
2885 dest = ghb_value_dup(preset);
2886 count = ghb_array_len(dest);
2887 ghb_array_replace(dest, count-1, ghb_string_value_new(name));
2888 enforce_preset_type(ud, dest);
2889 ghb_value_free(dest);
2893 presets_restore_clicked_cb(GtkWidget *xwidget, signal_user_data_t *ud)
2897 g_debug("presets_restore_clicked_cb ()");
2898 // Reload only the standard presets
2899 ghb_presets_reload(ud);
2900 // Updating the presets list shuffles things around
2901 // need to make sure the proper preset is selected
2902 preset = ghb_settings_get_value (ud->settings, "preset");
2903 ghb_select_preset(ud->builder, preset);
2907 presets_remove_clicked_cb(GtkWidget *xwidget, signal_user_data_t *ud)
2909 GtkTreeView *treeview;
2910 GtkTreeSelection *selection;
2911 GtkTreeModel *store;
2914 GtkResponseType response;
2916 g_debug("presets_remove_clicked_cb ()");
2917 treeview = GTK_TREE_VIEW(GHB_WIDGET(ud->builder, "presets_list"));
2918 selection = gtk_tree_view_get_selection (treeview);
2919 if (gtk_tree_selection_get_selected(selection, &store, &iter))
2926 gtk_tree_model_get(store, &iter, 0, &preset, -1);
2927 path = gtk_tree_model_get_path(store, &iter);
2928 indices = gtk_tree_path_get_indices(path);
2929 len = gtk_tree_path_get_depth(path);
2931 folder = ghb_presets_get_folder(presetsPlist, indices, len);
2932 dialog = gtk_message_dialog_new(NULL, GTK_DIALOG_MODAL,
2933 GTK_MESSAGE_QUESTION, GTK_BUTTONS_YES_NO,
2934 "Confirm deletion of %s:\n\n%s",
2935 folder ? "folder" : "preset",
2937 response = gtk_dialog_run(GTK_DIALOG(dialog));
2938 gtk_widget_destroy (dialog);
2939 if (response == GTK_RESPONSE_YES)
2941 GtkTreeIter nextIter = iter;
2942 gboolean valid = TRUE;
2943 if (!gtk_tree_model_iter_next(store, &nextIter))
2945 if (!gtk_tree_model_iter_parent(store, &nextIter, &iter))
2950 // Remove the selected item
2951 // First unselect it so that selecting the new item works properly
2952 gtk_tree_selection_unselect_iter (selection, &iter);
2953 if (ghb_presets_remove(presetsPlist, indices, len))
2956 presets_list_remove(ud, indices, len);
2959 valid = gtk_tree_model_get_iter_first(store, &nextIter);
2962 gtk_tree_path_free(path);
2963 path = gtk_tree_model_get_path(store, &nextIter);
2964 indices = gtk_tree_path_get_indices(path);
2965 len = gtk_tree_path_get_depth(path);
2966 ghb_select_preset2(ud->builder, indices, len);
2970 gtk_tree_path_free(path);
2974 // controls where valid drop locations are
2976 presets_drag_motion_cb(
2978 GdkDragContext *ctx,
2982 signal_user_data_t *ud)
2984 GtkTreePath *path = NULL;
2985 GtkTreeViewDropPosition drop_pos;
2989 GtkTreeModel *model;
2990 GtkTreeSelection *select;
2991 gint src_ptype, dst_ptype;
2992 gboolean src_folder, dst_folder;
2994 gint tree_depth, ii;
2996 // Get the type of the object being dragged
2997 srctv = GTK_TREE_VIEW(gtk_drag_get_source_widget(ctx));
2998 select = gtk_tree_view_get_selection (srctv);
2999 gtk_tree_selection_get_selected (select, &model, &iter);
3000 path = gtk_tree_model_get_path (model, &iter);
3001 indices = gtk_tree_path_get_indices(path);
3002 len = gtk_tree_path_get_depth(path);
3004 preset = presets_get_dict(presetsPlist, indices, len);
3005 tree_depth = preset_tree_depth(preset);
3007 src_ptype = ghb_presets_get_type(presetsPlist, indices, len);
3008 src_folder = ghb_presets_get_folder(presetsPlist, indices, len);
3009 gtk_tree_path_free(path);
3011 if (src_folder && tree_depth == 1)
3014 // The rest checks that the destination is a valid position
3016 gtk_tree_view_get_dest_row_at_pos (tv, x, y, &path, &drop_pos);
3019 gdk_drag_status(ctx, 0, time);
3022 // Don't allow repositioning of builtin presets
3023 if (src_ptype != PRESETS_CUSTOM)
3025 gdk_drag_status(ctx, 0, time);
3029 len = gtk_tree_path_get_depth(path);
3030 if (len+tree_depth-1 >= MAX_NESTED_PRESET)
3032 if (drop_pos == GTK_TREE_VIEW_DROP_INTO_OR_BEFORE)
3033 drop_pos = GTK_TREE_VIEW_DROP_BEFORE;
3034 if (drop_pos == GTK_TREE_VIEW_DROP_INTO_OR_AFTER)
3035 drop_pos = GTK_TREE_VIEW_DROP_AFTER;
3037 for (ii = len+tree_depth-1; ii > MAX_NESTED_PRESET; ii--)
3038 gtk_tree_path_up(path);
3039 indices = gtk_tree_path_get_indices(path);
3040 len = gtk_tree_path_get_depth(path);
3041 dst_ptype = ghb_presets_get_type(presetsPlist, indices, len);
3042 dst_folder = ghb_presets_get_folder(presetsPlist, indices, len);
3043 // Don't allow mixing custom presets in the builtins
3044 if (dst_ptype != PRESETS_CUSTOM)
3046 gdk_drag_status(ctx, 0, time);
3050 // Only allow *drop into* for folders
3053 if (drop_pos == GTK_TREE_VIEW_DROP_INTO_OR_BEFORE)
3054 drop_pos = GTK_TREE_VIEW_DROP_BEFORE;
3055 if (drop_pos == GTK_TREE_VIEW_DROP_INTO_OR_AFTER)
3056 drop_pos = GTK_TREE_VIEW_DROP_AFTER;
3059 len = gtk_tree_path_get_depth(path);
3060 gtk_tree_view_set_drag_dest_row(tv, path, drop_pos);
3061 gtk_tree_path_free(path);
3062 gdk_drag_status(ctx, GDK_ACTION_MOVE, time);
3068 GtkTreeView *dstwidget,
3071 GtkSelectionData *selection_data,
3072 guint info, guint t,
3073 signal_user_data_t *ud)
3075 GtkTreePath *path = NULL;
3076 GtkTreeViewDropPosition drop_pos;
3077 GtkTreeIter dstiter, srciter;
3078 gint *dst_indices, dst_len, *src_indices, src_len;
3080 gboolean src_folder, dst_folder;
3082 GtkTreeModel *dstmodel = gtk_tree_view_get_model(dstwidget);
3084 g_debug("preset_drag_cb ()");
3085 // This doesn't work here for some reason...
3086 // gtk_tree_view_get_drag_dest_row(dstwidget, &path, &drop_pos);
3087 gtk_tree_view_get_dest_row_at_pos (dstwidget, x, y, &path, &drop_pos);
3088 // This little hack is needed because attempting to drop after
3089 // the last item gives us no path or drop_pos.
3094 n_children = gtk_tree_model_iter_n_children(dstmodel, NULL);
3097 drop_pos = GTK_TREE_VIEW_DROP_AFTER;
3098 path = gtk_tree_path_new_from_indices(n_children-1, -1);
3102 drop_pos = GTK_TREE_VIEW_DROP_BEFORE;
3103 path = gtk_tree_path_new_from_indices(0, -1);
3108 GtkTreeView *srcwidget;
3109 GtkTreeModel *srcmodel;
3110 GtkTreeSelection *select;
3111 GtkTreePath *srcpath = NULL;
3113 gint tree_depth, ii;
3115 srcwidget = GTK_TREE_VIEW(gtk_drag_get_source_widget(dc));
3116 select = gtk_tree_view_get_selection (srcwidget);
3117 gtk_tree_selection_get_selected (select, &srcmodel, &srciter);
3119 srcpath = gtk_tree_model_get_path (srcmodel, &srciter);
3120 src_indices = gtk_tree_path_get_indices(srcpath);
3121 src_len = gtk_tree_path_get_depth(srcpath);
3122 src_ptype = ghb_presets_get_type(presetsPlist, src_indices, src_len);
3123 src_folder = ghb_presets_get_folder(presetsPlist, src_indices, src_len);
3124 preset = ghb_value_dup(
3125 presets_get_dict(presetsPlist, src_indices, src_len));
3126 gtk_tree_path_free(srcpath);
3128 // Don't allow repositioning of builtin presets
3129 if (src_ptype != PRESETS_CUSTOM)
3132 tree_depth = preset_tree_depth(preset);
3133 if (src_folder && tree_depth == 1)
3136 dst_len = gtk_tree_path_get_depth(path);
3137 if (dst_len+tree_depth-1 >= MAX_NESTED_PRESET)
3139 if (drop_pos == GTK_TREE_VIEW_DROP_INTO_OR_BEFORE)
3140 drop_pos = GTK_TREE_VIEW_DROP_BEFORE;
3141 if (drop_pos == GTK_TREE_VIEW_DROP_INTO_OR_AFTER)
3142 drop_pos = GTK_TREE_VIEW_DROP_AFTER;
3145 for (ii = dst_len+tree_depth-1; ii > MAX_NESTED_PRESET; ii--)
3146 gtk_tree_path_up(path);
3147 dst_indices = gtk_tree_path_get_indices(path);
3148 dst_len = gtk_tree_path_get_depth(path);
3149 dst_folder = ghb_presets_get_folder(presetsPlist, dst_indices, dst_len);
3150 // Only allow *drop into* for folders
3153 if (drop_pos == GTK_TREE_VIEW_DROP_INTO_OR_BEFORE)
3154 drop_pos = GTK_TREE_VIEW_DROP_BEFORE;
3155 if (drop_pos == GTK_TREE_VIEW_DROP_INTO_OR_AFTER)
3156 drop_pos = GTK_TREE_VIEW_DROP_AFTER;
3158 if (gtk_tree_model_get_iter (dstmodel, &dstiter, path))
3161 GtkTreePath *dstpath = NULL;
3165 case GTK_TREE_VIEW_DROP_BEFORE:
3166 gtk_tree_store_insert_before(GTK_TREE_STORE (dstmodel),
3167 &iter, NULL, &dstiter);
3170 case GTK_TREE_VIEW_DROP_INTO_OR_BEFORE:
3171 gtk_tree_store_insert(GTK_TREE_STORE (dstmodel),
3172 &iter, &dstiter, 0);
3175 case GTK_TREE_VIEW_DROP_AFTER:
3176 gtk_tree_store_insert_after(GTK_TREE_STORE (dstmodel),
3177 &iter, NULL, &dstiter);
3180 case GTK_TREE_VIEW_DROP_INTO_OR_AFTER:
3181 gtk_tree_store_insert_after(GTK_TREE_STORE (dstmodel),
3182 &iter, &dstiter, 0);
3189 dstpath = gtk_tree_model_get_path (dstmodel, &iter);
3190 dst_indices = gtk_tree_path_get_indices(dstpath);
3191 dst_len = gtk_tree_path_get_depth(dstpath);
3192 ghb_presets_insert(presetsPlist, preset, dst_indices, dst_len);
3193 gtk_tree_path_free(dstpath);
3195 srcpath = gtk_tree_model_get_path (srcmodel, &srciter);
3196 src_indices = gtk_tree_path_get_indices(srcpath);
3197 src_len = gtk_tree_path_get_depth(srcpath);
3198 ghb_presets_remove(presetsPlist, src_indices, src_len);
3199 gtk_tree_path_free(srcpath);
3201 gtk_tree_store_remove (GTK_TREE_STORE (srcmodel), &srciter);
3203 dstpath = gtk_tree_model_get_path (dstmodel, &iter);
3204 dst_indices = gtk_tree_path_get_indices(dstpath);
3205 dst_len = gtk_tree_path_get_depth(dstpath);
3206 presets_list_update_item(ud, dst_indices, dst_len);
3207 gtk_tree_path_free(dstpath);
3211 gtk_tree_path_free(path);
3216 presets_row_expanded_cb(
3217 GtkTreeView *treeview,
3220 signal_user_data_t *ud)
3223 gboolean expanded, folder;
3225 expanded = gtk_tree_view_row_expanded(treeview, path);
3226 indices = gtk_tree_path_get_indices(path);
3227 len = gtk_tree_path_get_depth(path);
3228 folder = ghb_presets_get_folder(presetsPlist, indices, len);
3231 presets_set_folder_open(expanded, indices, len);
3234 // Collapsing parent folder collapses all children
3237 GValue *presets = NULL;
3239 gint *more_indices, count, ii;
3241 more_indices = g_malloc((len+1)*sizeof(gint));
3242 memcpy(more_indices, indices, len*sizeof(gint));
3244 presets = presets_get_folder(presetsPlist, indices, len);
3245 count = ghb_array_len(presets);
3246 for (ii = 0; ii < count; ii++)
3248 dict = ghb_array_get_nth(presets, ii);
3249 folder = ghb_preset_folder(dict);
3252 more_indices[len] = ii;
3253 presets_set_folder_open(expanded, more_indices, len+1);
3256 g_free(more_indices);
3262 preset_update_title_deps(signal_user_data_t *ud, ghb_title_info_t *tinfo)
3266 ghb_ui_update(ud, "scale_width",
3267 ghb_int64_value(tinfo->width - tinfo->crop[2] - tinfo->crop[3]));
3268 // If anamorphic or keep_aspect, the hight will be automatically calculated
3269 gboolean keep_aspect;
3271 keep_aspect = ghb_settings_get_boolean(ud->settings, "PictureKeepRatio");
3272 pic_par = ghb_settings_combo_int(ud->settings, "PicturePAR");
3273 if (!(keep_aspect || pic_par) || pic_par == 3)
3275 ghb_ui_update(ud, "scale_height",
3276 ghb_int64_value(tinfo->height - tinfo->crop[0] - tinfo->crop[1]));
3279 // Set the limits of cropping. hb_set_anamorphic_size crashes if
3280 // you pass it a cropped width or height == 0.
3282 bound = tinfo->height / 2 - 2;
3283 widget = GHB_WIDGET (ud->builder, "PictureTopCrop");
3284 gtk_spin_button_set_range (GTK_SPIN_BUTTON(widget), 0, bound);
3285 widget = GHB_WIDGET (ud->builder, "PictureBottomCrop");
3286 gtk_spin_button_set_range (GTK_SPIN_BUTTON(widget), 0, bound);
3287 bound = tinfo->width / 2 - 2;
3288 widget = GHB_WIDGET (ud->builder, "PictureLeftCrop");
3289 gtk_spin_button_set_range (GTK_SPIN_BUTTON(widget), 0, bound);
3290 widget = GHB_WIDGET (ud->builder, "PictureRightCrop");
3291 gtk_spin_button_set_range (GTK_SPIN_BUTTON(widget), 0, bound);
3292 if (ghb_settings_get_boolean(ud->settings, "PictureAutoCrop"))
3294 ghb_ui_update(ud, "PictureTopCrop", ghb_int64_value(tinfo->crop[0]));
3295 ghb_ui_update(ud, "PictureBottomCrop", ghb_int64_value(tinfo->crop[1]));
3296 ghb_ui_update(ud, "PictureLeftCrop", ghb_int64_value(tinfo->crop[2]));
3297 ghb_ui_update(ud, "PictureRightCrop", ghb_int64_value(tinfo->crop[3]));
3302 presets_list_selection_changed_cb(GtkTreeSelection *selection, signal_user_data_t *ud)
3304 GtkTreeModel *store;
3306 ghb_title_info_t tinfo;
3309 g_debug("presets_list_selection_changed_cb ()");
3310 widget = GHB_WIDGET (ud->builder, "presets_remove");
3311 if (gtk_tree_selection_get_selected(selection, &store, &iter))
3313 GtkTreePath *treepath;
3318 treepath = gtk_tree_model_get_path(store, &iter);
3319 indices = gtk_tree_path_get_indices(treepath);
3320 len = gtk_tree_path_get_depth(treepath);
3322 path = preset_path_from_indices(presetsPlist, indices, len);
3323 ghb_settings_take_value(ud->settings, "preset_selection", path);
3325 folder = ghb_presets_get_folder(presetsPlist, indices, len);
3328 ud->dont_clear_presets = TRUE;
3329 // Temporarily set the video_quality range to (0,100)
3330 // This is needed so the video_quality value does not get
3331 // truncated when set. The range will be readjusted below
3332 GtkWidget *qp = GHB_WIDGET(ud->builder, "VideoQualitySlider");
3333 gtk_range_set_range (GTK_RANGE(qp), 0, 100);
3334 gtk_scale_set_digits(GTK_SCALE(qp), 3);
3335 // Clear the audio list prior to changing the preset. Existing
3336 // audio can cause the container extension to be automatically
3337 // changed when it shouldn't be
3338 ghb_clear_audio_list(ud);
3339 ghb_set_preset_from_indices(ud, indices, len);
3340 gtk_tree_path_free(treepath);
3342 titleindex = ghb_settings_combo_int(ud->settings, "title");
3343 ghb_set_pref_audio(titleindex, ud);
3344 ghb_settings_set_boolean(ud->settings, "preset_modified", FALSE);
3345 ud->dont_clear_presets = FALSE;
3346 if (ghb_get_title_info (&tinfo, titleindex))
3348 preset_update_title_deps(ud, &tinfo);
3350 ghb_set_scale (ud, GHB_SCALE_KEEP_NONE);
3352 gdouble vqmin, vqmax, step, page;
3356 ghb_vquality_range(ud, &vqmin, &vqmax, &step,
3357 &page, &digits, &inverted);
3358 gtk_range_set_range (GTK_RANGE(qp), vqmin, vqmax);
3359 gtk_range_set_increments (GTK_RANGE(qp), step, page);
3360 gtk_scale_set_digits(GTK_SCALE(qp), digits);
3361 gtk_range_set_inverted (GTK_RANGE(qp), inverted);
3365 GtkWidget *crop_widget;
3366 crop[0] = ghb_settings_get_int(ud->settings, "PictureTopCrop");
3367 crop[1] = ghb_settings_get_int(ud->settings, "PictureBottomCrop");
3368 crop[2] = ghb_settings_get_int(ud->settings, "PictureLeftCrop");
3369 crop[3] = ghb_settings_get_int(ud->settings, "PictureRightCrop");
3370 crop_widget = GHB_WIDGET (ud->builder, "crop_values");
3371 text = g_strdup_printf("%d:%d:%d:%d",
3372 crop[0], crop[1], crop[2], crop[3]);
3373 gtk_label_set_text (GTK_LABEL(crop_widget), text);
3376 gtk_widget_set_sensitive(widget, TRUE);
3380 g_debug("No selection??? Perhaps unselected.");
3381 gtk_widget_set_sensitive(widget, FALSE);
3386 ghb_clear_presets_selection(signal_user_data_t *ud)
3388 GtkTreeView *treeview;
3389 GtkTreeSelection *selection;
3391 if (ud->dont_clear_presets) return;
3392 g_debug("ghb_clear_presets_selection()");
3393 treeview = GTK_TREE_VIEW(GHB_WIDGET(ud->builder, "presets_list"));
3394 selection = gtk_tree_view_get_selection (treeview);
3395 gtk_tree_selection_unselect_all (selection);
3396 ghb_settings_set_boolean(ud->settings, "preset_modified", TRUE);
3400 presets_frame_size_allocate_cb(GtkWidget *widget, GtkAllocation *allocation, signal_user_data_t *ud)
3402 GtkTreeView *treeview;
3403 GtkTreeSelection *selection;
3404 GtkTreeModel *store;
3407 treeview = GTK_TREE_VIEW(GHB_WIDGET(ud->builder, "presets_list"));
3408 selection = gtk_tree_view_get_selection(treeview);
3409 if (gtk_tree_selection_get_selected(selection, &store, &iter))
3412 path = gtk_tree_model_get_path (store, &iter);
3413 // Make the parent visible in scroll window if it is not.
3414 gtk_tree_view_scroll_to_cell (treeview, path, NULL, FALSE, 0, 0);
3415 gtk_tree_path_free(path);
3420 presets_default_clicked_cb(GtkWidget *xwidget, signal_user_data_t *ud)
3425 g_debug("presets_default_clicked_cb ()");
3426 preset = ghb_settings_get_value(ud->settings, "preset_selection");
3427 indices = ghb_preset_indices_from_path(presetsPlist, preset, &len);
3430 if (!ghb_presets_get_folder(presetsPlist, indices, len))
3432 ghb_presets_list_clear_default(ud);
3433 presets_set_default(indices, len);
3434 ghb_presets_list_default(ud);