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)", "xvid"},
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", "avi"},
1715 {"OGM file", "ogm"},
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 ghb_dict_insert(dict, g_strdup("anamorphic"),
2207 ghb_boolean_value_new(FALSE));
2208 if (ghb_dict_lookup(dict, "ModDimensions") == NULL)
2209 ghb_dict_insert(dict, g_strdup("ModDimensions"),
2210 ghb_boolean_value_new(TRUE));
2214 ghb_dict_insert(dict, g_strdup("anamorphic"),
2215 ghb_boolean_value_new(TRUE));
2216 ghb_dict_insert(dict, g_strdup("ModDimensions"),
2217 ghb_boolean_value_new(FALSE));
2221 ghb_dict_insert(dict, g_strdup("anamorphic"),
2222 ghb_boolean_value_new(TRUE));
2223 ghb_dict_insert(dict, g_strdup("ModDimensions"),
2224 ghb_boolean_value_new(TRUE));
2228 ghb_dict_insert(dict, g_strdup("anamorphic"),
2229 ghb_boolean_value_new(TRUE));
2230 ghb_dict_insert(dict, g_strdup("ModDimensions"),
2231 ghb_boolean_value_new(TRUE));
2234 // VideoQualityType/0/1/2 - vquality_type_/target/bitrate/constant
2239 ghb_dict_insert(dict, g_strdup("vquality_type_target"),
2240 ghb_boolean_value_new(TRUE));
2241 ghb_dict_insert(dict, g_strdup("vquality_type_bitrate"),
2242 ghb_boolean_value_new(FALSE));
2243 ghb_dict_insert(dict, g_strdup("vquality_type_constant"),
2244 ghb_boolean_value_new(FALSE));
2248 ghb_dict_insert(dict, g_strdup("vquality_type_target"),
2249 ghb_boolean_value_new(FALSE));
2250 ghb_dict_insert(dict, g_strdup("vquality_type_bitrate"),
2251 ghb_boolean_value_new(TRUE));
2252 ghb_dict_insert(dict, g_strdup("vquality_type_constant"),
2253 ghb_boolean_value_new(FALSE));
2257 ghb_dict_insert(dict, g_strdup("vquality_type_target"),
2258 ghb_boolean_value_new(FALSE));
2259 ghb_dict_insert(dict, g_strdup("vquality_type_bitrate"),
2260 ghb_boolean_value_new(FALSE));
2261 ghb_dict_insert(dict, g_strdup("vquality_type_constant"),
2262 ghb_boolean_value_new(TRUE));
2266 ghb_dict_insert(dict, g_strdup("vquality_type_target"),
2267 ghb_boolean_value_new(FALSE));
2268 ghb_dict_insert(dict, g_strdup("vquality_type_bitrate"),
2269 ghb_boolean_value_new(FALSE));
2270 ghb_dict_insert(dict, g_strdup("vquality_type_constant"),
2271 ghb_boolean_value_new(TRUE));
2274 import_value_xlat(dict);
2279 vquality = ghb_value_double(preset_dict_get_value(dict, "VideoQualitySlider"));
2284 gval = preset_dict_get_value(dict, "VideoEncoder");
2285 vcodec = ghb_lookup_combo_int("VideoEncoder", gval);
2288 case HB_VCODEC_X264:
2290 vquality = 51. - vquality * 51.;
2293 case HB_VCODEC_XVID:
2294 case HB_VCODEC_FFMPEG:
2296 vquality = 31. - vquality * 30.;
2299 case HB_VCODEC_THEORA:
2301 vquality = vquality * 63.;
2309 ghb_dict_insert(dict, g_strdup("VideoQualitySlider"),
2310 ghb_double_value_new(vquality));
2315 import_xlat_presets(GValue *presets)
2321 g_debug("import_xlat_presets ()");
2322 if (presets == NULL) return;
2323 count = ghb_array_len(presets);
2324 for (ii = 0; ii < count; ii++)
2326 dict = ghb_array_get_nth(presets, ii);
2327 folder = ghb_value_boolean(preset_dict_get_value(dict, "Folder"));
2332 nested = ghb_dict_lookup(dict, "ChildrenArray");
2333 import_xlat_presets(nested);
2337 import_xlat_preset(dict);
2343 export_xlat_preset(GValue *dict)
2345 gboolean ana, round, autoscale, target, br, constant;
2347 g_debug("export_xlat_prest ()");
2348 autoscale = ghb_value_boolean(preset_dict_get_value(dict, "autoscale"));
2349 ana = ghb_value_boolean(preset_dict_get_value(dict, "anamorphic"));
2350 round = ghb_value_boolean(preset_dict_get_value(dict, "ModDimensions"));
2351 target = ghb_value_boolean(
2352 preset_dict_get_value(dict, "vquality_type_target"));
2353 br = ghb_value_boolean(
2354 preset_dict_get_value(dict, "vquality_type_bitrate"));
2355 constant = ghb_value_boolean(
2356 preset_dict_get_value(dict, "vquality_type_constant"));
2359 ghb_dict_insert(dict, g_strdup("UsesPictureSettings"),
2360 ghb_int_value_new(2));
2362 ghb_dict_insert(dict, g_strdup("UsesPictureSettings"),
2363 ghb_int_value_new(1));
2368 ghb_dict_insert(dict, g_strdup("PicturePAR"),
2369 ghb_int_value_new(2));
2371 ghb_dict_insert(dict, g_strdup("PicturePAR"),
2372 ghb_int_value_new(1));
2376 ghb_dict_insert(dict, g_strdup("PicturePAR"),
2377 ghb_int_value_new(0));
2379 // VideoQualityType/0/1/2 - vquality_type_/target/bitrate/constant
2382 ghb_dict_insert(dict, g_strdup("VideoQualityType"),
2383 ghb_int_value_new(0));
2387 ghb_dict_insert(dict, g_strdup("VideoQualityType"),
2388 ghb_int_value_new(1));
2392 ghb_dict_insert(dict, g_strdup("VideoQualityType"),
2393 ghb_int_value_new(2));
2395 ghb_dict_remove(dict, "UsesMaxPictureSettings");
2396 ghb_dict_remove(dict, "autoscale");
2397 ghb_dict_remove(dict, "anamorphic");
2398 ghb_dict_remove(dict, "vquality_type_target");
2399 ghb_dict_remove(dict, "vquality_type_bitrate");
2400 ghb_dict_remove(dict, "vquality_type_constant");
2401 export_value_xlat(dict);
2405 export_xlat_presets(GValue *presets)
2411 if (presets == NULL) return;
2412 count = ghb_array_len(presets);
2413 for (ii = 0; ii < count; ii++)
2415 dict = ghb_array_get_nth(presets, ii);
2416 folder = ghb_value_boolean(preset_dict_get_value(dict, "Folder"));
2421 nested = ghb_dict_lookup(dict, "ChildrenArray");
2422 export_xlat_presets(nested);
2426 export_xlat_preset(dict);
2431 static guint prefs_timeout_id = 0;
2434 delayed_store_prefs(gpointer data)
2436 store_plist(prefsPlist, "preferences");
2437 prefs_timeout_id = 0;
2446 export = ghb_value_dup(presetsPlist);
2447 export_xlat_presets(export);
2448 store_plist(export, "presets");
2449 ghb_value_free(export);
2455 if (prefs_timeout_id != 0)
2460 mc = g_main_context_default();
2461 source = g_main_context_find_source_by_id(mc, prefs_timeout_id);
2463 g_source_destroy(source);
2465 prefs_timeout_id = g_timeout_add_seconds(1, (GSourceFunc)delayed_store_prefs, NULL);
2469 ghb_presets_reload(signal_user_data_t *ud)
2471 GValue *std_presets;
2475 g_debug("ghb_presets_reload()\n");
2476 std_presets = ghb_resource_get("standard-presets");
2477 if (std_presets == NULL) return;
2479 remove_std_presets(ud);
2480 indices = presets_find_default(presetsPlist, &len);
2483 presets_clear_default(std_presets);
2486 // Merge the keyfile contents into our presets
2487 count = ghb_array_len(std_presets);
2488 for (ii = count-1; ii >= 0; ii--)
2494 std_dict = ghb_array_get_nth(std_presets, ii);
2495 copy_dict = ghb_value_dup(std_dict);
2496 ghb_presets_insert(presetsPlist, copy_dict, &indices, 1);
2497 presets_list_insert(ud, &indices, 1);
2499 import_xlat_presets(presetsPlist);
2508 count = ghb_array_len(presetsPlist);
2509 for (ii = count-1; ii >= 0; ii--)
2514 dict = ghb_array_get_nth(presetsPlist, ii);
2515 type = ghb_dict_lookup(dict, "Type");
2525 presetsPlist = load_plist("presets");
2526 if (presetsPlist == NULL)
2528 presetsPlist = ghb_value_dup(ghb_resource_get("standard-presets"));
2529 import_xlat_presets(presetsPlist);
2532 else if (G_VALUE_TYPE(presetsPlist) == ghb_dict_get_type())
2533 { // Presets is older dictionary format. Convert to array
2534 ghb_value_free(presetsPlist);
2535 presetsPlist = ghb_value_dup(ghb_resource_get("standard-presets"));
2536 import_xlat_presets(presetsPlist);
2539 else if (check_old_presets())
2541 ghb_value_free(presetsPlist);
2542 presetsPlist = ghb_value_dup(ghb_resource_get("standard-presets"));
2543 import_xlat_presets(presetsPlist);
2546 import_xlat_presets(presetsPlist);
2550 settings_save(signal_user_data_t *ud, const GValue *path)
2552 GValue *dict, *internal;
2553 GHashTableIter iter;
2557 gint *indices, len, count;
2559 gboolean replace = FALSE;
2561 g_debug("settings_save");
2562 if (internalPlist == NULL) return;
2563 count = ghb_array_len(path);
2564 name = g_value_get_string(ghb_array_get_nth(path, count-1));
2565 indices = ghb_preset_indices_from_path(presetsPlist, path, &len);
2568 if (ghb_presets_get_folder(presetsPlist, indices, len))
2571 message = g_strdup_printf(
2572 "%s: Folder already exists.\n"
2573 "You can not replace it with a preset.",
2575 ghb_message_dialog(GTK_MESSAGE_ERROR, message, "Cancel", NULL);
2579 dict = ghb_dict_value_new();
2580 ghb_presets_replace(presetsPlist, dict, indices, len);
2585 indices = presets_find_pos(path, PRESETS_CUSTOM, &len);
2588 dict = ghb_dict_value_new();
2589 ghb_presets_insert(presetsPlist, dict, indices, len);
2593 g_warning("failed to find insert path");
2597 current_preset = dict;
2598 autoscale = ghb_settings_get_boolean(ud->settings, "autoscale");
2599 ghb_settings_set_int64(ud->settings, "Type", PRESETS_CUSTOM);
2601 internal = plist_get_dict(internalPlist, "Presets");
2602 ghb_dict_iter_init(&iter, internal);
2603 // middle (void*) cast prevents gcc warning "defreferencing type-punned
2604 // pointer will break strict-aliasing rules"
2605 while (g_hash_table_iter_next(
2606 &iter, (gpointer*)(void*)&key, (gpointer*)(void*)&value))
2614 if (strcmp(key, "PictureWidth") == 0)
2616 key2 = "scale_width";
2618 else if (strcmp(key, "PictureHeight") == 0)
2620 key2 = "scale_height";
2623 gval = ghb_settings_get_value(ud->settings, key2);
2628 ghb_dict_insert(dict, g_strdup(key), ghb_value_dup(gval));
2630 internal = plist_get_dict(internalPlist, "XlatPresets");
2631 ghb_dict_iter_init(&iter, internal);
2632 // middle (void*) cast prevents gcc warning "defreferencing type-punned
2633 // pointer will break strict-aliasing rules"
2634 while (g_hash_table_iter_next(
2635 &iter, (gpointer*)(void*)&key, (gpointer*)(void*)&value))
2639 gval = ghb_settings_get_value(ud->settings, key);
2644 ghb_dict_insert(dict, g_strdup(key), ghb_value_dup(gval));
2646 ghb_dict_insert(dict, g_strdup("PresetName"), ghb_string_value_new(name));
2648 presets_list_update_item(ud, indices, len);
2651 ghb_dict_insert(dict, g_strdup("Default"),
2652 ghb_boolean_value_new(FALSE));
2653 presets_list_insert(ud, indices, len);
2656 ud->dont_clear_presets = TRUE;
2657 // Make the new preset the selected item
2658 ghb_select_preset2(ud->builder, indices, len);
2660 ud->dont_clear_presets = FALSE;
2665 folder_save(signal_user_data_t *ud, const GValue *path)
2667 GValue *dict, *folder;
2668 gint *indices, len, count;
2671 count = ghb_array_len(path);
2672 name = g_value_get_string(ghb_array_get_nth(path, count-1));
2673 indices = ghb_preset_indices_from_path(presetsPlist, path, &len);
2676 if (!ghb_presets_get_folder(presetsPlist, indices, len))
2679 message = g_strdup_printf(
2680 "%s: Preset already exists.\n"
2681 "You can not replace it with a folder.",
2683 ghb_message_dialog(GTK_MESSAGE_ERROR, message, "Cancel", NULL);
2688 // Already exists, update its description
2689 dict = presets_get_dict(presetsPlist, indices, len);
2690 ghb_dict_insert(dict, g_strdup("PresetDescription"),
2691 ghb_value_dup(preset_dict_get_value(
2692 ud->settings, "PresetDescription")));
2698 indices = presets_find_pos(path, PRESETS_CUSTOM, &len);
2701 dict = ghb_dict_value_new();
2702 ghb_presets_insert(presetsPlist, dict, indices, len);
2706 g_warning("failed to find insert path");
2710 ghb_dict_insert(dict, g_strdup("PresetDescription"),
2711 ghb_value_dup(preset_dict_get_value(
2712 ud->settings, "PresetDescription")));
2713 ghb_dict_insert(dict, g_strdup("PresetName"), ghb_string_value_new(name));
2714 folder = ghb_array_value_new(8);
2715 ghb_dict_insert(dict, g_strdup("ChildrenArray"), folder);
2716 ghb_dict_insert(dict, g_strdup("Type"),
2717 ghb_int64_value_new(PRESETS_CUSTOM));
2718 ghb_dict_insert(dict, g_strdup("Folder"), ghb_boolean_value_new(TRUE));
2720 presets_list_insert(ud, indices, len);
2727 ghb_presets_list_default(signal_user_data_t *ud)
2729 GtkTreeView *treeview;
2730 GtkTreePath *treepath;
2732 GtkTreeStore *store;
2735 g_debug("ghb_presets_list_default ()");
2736 treeview = GTK_TREE_VIEW(GHB_WIDGET(ud->builder, "presets_list"));
2737 store = GTK_TREE_STORE(gtk_tree_view_get_model(treeview));
2738 indices = presets_find_default(presetsPlist, &len);
2739 if (indices == NULL) return;
2740 treepath = ghb_tree_path_new_from_indices(indices, len);
2743 if (gtk_tree_model_get_iter(GTK_TREE_MODEL(store), &iter, treepath))
2745 gtk_tree_store_set(store, &iter,
2750 gtk_tree_path_free(treepath);
2756 ghb_presets_list_clear_default(signal_user_data_t *ud)
2758 GtkTreeView *treeview;
2759 GtkTreePath *treepath;
2761 GtkTreeStore *store;
2764 g_debug("ghb_presets_list_clear_default ()");
2765 treeview = GTK_TREE_VIEW(GHB_WIDGET(ud->builder, "presets_list"));
2766 store = GTK_TREE_STORE(gtk_tree_view_get_model(treeview));
2767 indices = presets_find_default(presetsPlist, &len);
2768 if (indices == NULL) return;
2769 treepath = ghb_tree_path_new_from_indices(indices, len);
2772 if (gtk_tree_model_get_iter(GTK_TREE_MODEL(store), &iter, treepath))
2774 gtk_tree_store_set(store, &iter,
2779 gtk_tree_path_free(treepath);
2785 update_audio_presets(signal_user_data_t *ud)
2787 g_debug("update_audio_presets");
2788 const GValue *audio_list;
2790 audio_list = ghb_settings_get_value(ud->settings, "audio_list");
2791 ghb_settings_set_value(ud->settings, "AudioList", audio_list);
2795 enforce_preset_type(signal_user_data_t *ud, const GValue *path)
2798 GtkWidget *normal, *folder;
2801 normal = GHB_WIDGET(ud->builder, "preset_type_normal");
2802 folder = GHB_WIDGET(ud->builder, "preset_type_folder");
2803 indices = ghb_preset_indices_from_path(presetsPlist, path, &len);
2806 fold = ghb_presets_get_folder(presetsPlist, indices, len);
2808 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(folder),
2811 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(normal),
2813 gtk_widget_set_sensitive(folder, fold);
2814 gtk_widget_set_sensitive(normal, !fold);
2819 gtk_widget_set_sensitive(folder, TRUE);
2820 gtk_widget_set_sensitive(normal, TRUE);
2825 presets_save_clicked_cb(GtkWidget *xwidget, signal_user_data_t *ud)
2830 GtkResponseType response;
2832 const gchar *name = "";
2833 gint count, *indices, len;
2835 g_debug("presets_save_clicked_cb ()");
2836 preset = ghb_settings_get_value (ud->settings, "preset_selection");
2838 count = ghb_array_len(preset);
2840 name = g_value_get_string(ghb_array_get_nth(preset, count-1));
2843 // Clear the description
2844 desc = GTK_TEXT_VIEW(GHB_WIDGET(ud->builder, "PresetDescription"));
2845 dialog = GHB_WIDGET(ud->builder, "preset_save_dialog");
2846 entry = GTK_ENTRY(GHB_WIDGET(ud->builder, "PresetName"));
2847 gtk_entry_set_text(entry, name);
2848 enforce_preset_type(ud, preset);
2849 response = gtk_dialog_run(GTK_DIALOG(dialog));
2850 gtk_widget_hide(dialog);
2851 if (response == GTK_RESPONSE_OK)
2854 const gchar *name = gtk_entry_get_text(entry);
2857 if (ghb_settings_get_boolean(ud->settings, "preset_type_folder"))
2859 if (count > MAX_NESTED_PRESET-1)
2861 count = MAX_NESTED_PRESET-1;
2864 dest = ghb_array_value_new(MAX_NESTED_PRESET);
2865 indices = ghb_preset_indices_from_path(presetsPlist, preset, &len);
2870 ptype = ghb_presets_get_type(presetsPlist, indices, len);
2871 if (ptype == PRESETS_CUSTOM)
2873 ghb_array_copy(dest, preset, count-1);
2876 ghb_array_append(dest, ghb_string_value_new(name));
2878 ghb_widget_to_setting(ud->settings, GTK_WIDGET(desc));
2879 if (ghb_settings_get_boolean(ud->settings, "preset_type_folder"))
2881 folder_save(ud, dest);
2885 // Construct the audio settings presets from the current audio list
2886 update_audio_presets(ud);
2887 settings_save(ud, dest);
2889 ghb_value_free(dest);
2894 preset_type_changed_cb(GtkWidget *widget, signal_user_data_t *ud)
2896 ghb_widget_to_setting(ud->settings, widget);
2900 preset_name_changed_cb(GtkWidget *entry, signal_user_data_t *ud)
2903 GValue *preset, *dest;
2906 preset = ghb_settings_get_value (ud->settings, "preset_selection");
2907 name = ghb_widget_string(entry);
2908 dest = ghb_value_dup(preset);
2909 count = ghb_array_len(dest);
2910 ghb_array_replace(dest, count-1, ghb_string_value_new(name));
2911 enforce_preset_type(ud, dest);
2912 ghb_value_free(dest);
2916 presets_restore_clicked_cb(GtkWidget *xwidget, signal_user_data_t *ud)
2920 g_debug("presets_restore_clicked_cb ()");
2921 // Reload only the standard presets
2922 ghb_presets_reload(ud);
2923 // Updating the presets list shuffles things around
2924 // need to make sure the proper preset is selected
2925 preset = ghb_settings_get_value (ud->settings, "preset");
2926 ghb_select_preset(ud->builder, preset);
2930 presets_remove_clicked_cb(GtkWidget *xwidget, signal_user_data_t *ud)
2932 GtkTreeView *treeview;
2933 GtkTreeSelection *selection;
2934 GtkTreeModel *store;
2937 GtkResponseType response;
2939 g_debug("presets_remove_clicked_cb ()");
2940 treeview = GTK_TREE_VIEW(GHB_WIDGET(ud->builder, "presets_list"));
2941 selection = gtk_tree_view_get_selection (treeview);
2942 if (gtk_tree_selection_get_selected(selection, &store, &iter))
2949 gtk_tree_model_get(store, &iter, 0, &preset, -1);
2950 path = gtk_tree_model_get_path(store, &iter);
2951 indices = gtk_tree_path_get_indices(path);
2952 len = gtk_tree_path_get_depth(path);
2954 folder = ghb_presets_get_folder(presetsPlist, indices, len);
2955 dialog = gtk_message_dialog_new(NULL, GTK_DIALOG_MODAL,
2956 GTK_MESSAGE_QUESTION, GTK_BUTTONS_YES_NO,
2957 "Confirm deletion of %s:\n\n%s",
2958 folder ? "folder" : "preset",
2960 response = gtk_dialog_run(GTK_DIALOG(dialog));
2961 gtk_widget_destroy (dialog);
2962 if (response == GTK_RESPONSE_YES)
2964 GtkTreeIter nextIter = iter;
2965 gboolean valid = TRUE;
2966 if (!gtk_tree_model_iter_next(store, &nextIter))
2968 if (!gtk_tree_model_iter_parent(store, &nextIter, &iter))
2973 // Remove the selected item
2974 // First unselect it so that selecting the new item works properly
2975 gtk_tree_selection_unselect_iter (selection, &iter);
2976 if (ghb_presets_remove(presetsPlist, indices, len))
2979 presets_list_remove(ud, indices, len);
2982 valid = gtk_tree_model_get_iter_first(store, &nextIter);
2985 gtk_tree_path_free(path);
2986 path = gtk_tree_model_get_path(store, &nextIter);
2987 indices = gtk_tree_path_get_indices(path);
2988 len = gtk_tree_path_get_depth(path);
2989 ghb_select_preset2(ud->builder, indices, len);
2993 gtk_tree_path_free(path);
2997 // controls where valid drop locations are
2999 presets_drag_motion_cb(
3001 GdkDragContext *ctx,
3005 signal_user_data_t *ud)
3007 GtkTreePath *path = NULL;
3008 GtkTreeViewDropPosition drop_pos;
3012 GtkTreeModel *model;
3013 GtkTreeSelection *select;
3014 gint src_ptype, dst_ptype;
3015 gboolean src_folder, dst_folder;
3017 gint tree_depth, ii;
3019 // Get the type of the object being dragged
3020 srctv = GTK_TREE_VIEW(gtk_drag_get_source_widget(ctx));
3021 select = gtk_tree_view_get_selection (srctv);
3022 gtk_tree_selection_get_selected (select, &model, &iter);
3023 path = gtk_tree_model_get_path (model, &iter);
3024 indices = gtk_tree_path_get_indices(path);
3025 len = gtk_tree_path_get_depth(path);
3027 preset = presets_get_dict(presetsPlist, indices, len);
3028 tree_depth = preset_tree_depth(preset);
3030 src_ptype = ghb_presets_get_type(presetsPlist, indices, len);
3031 src_folder = ghb_presets_get_folder(presetsPlist, indices, len);
3032 gtk_tree_path_free(path);
3034 if (src_folder && tree_depth == 1)
3037 // The rest checks that the destination is a valid position
3039 gtk_tree_view_get_dest_row_at_pos (tv, x, y, &path, &drop_pos);
3042 gdk_drag_status(ctx, 0, time);
3045 // Don't allow repositioning of builtin presets
3046 if (src_ptype != PRESETS_CUSTOM)
3048 gdk_drag_status(ctx, 0, time);
3052 len = gtk_tree_path_get_depth(path);
3053 if (len+tree_depth-1 >= MAX_NESTED_PRESET)
3055 if (drop_pos == GTK_TREE_VIEW_DROP_INTO_OR_BEFORE)
3056 drop_pos = GTK_TREE_VIEW_DROP_BEFORE;
3057 if (drop_pos == GTK_TREE_VIEW_DROP_INTO_OR_AFTER)
3058 drop_pos = GTK_TREE_VIEW_DROP_AFTER;
3060 for (ii = len+tree_depth-1; ii > MAX_NESTED_PRESET; ii--)
3061 gtk_tree_path_up(path);
3062 indices = gtk_tree_path_get_indices(path);
3063 len = gtk_tree_path_get_depth(path);
3064 dst_ptype = ghb_presets_get_type(presetsPlist, indices, len);
3065 dst_folder = ghb_presets_get_folder(presetsPlist, indices, len);
3066 // Don't allow mixing custom presets in the builtins
3067 if (dst_ptype != PRESETS_CUSTOM)
3069 gdk_drag_status(ctx, 0, time);
3073 // Only allow *drop into* for folders
3076 if (drop_pos == GTK_TREE_VIEW_DROP_INTO_OR_BEFORE)
3077 drop_pos = GTK_TREE_VIEW_DROP_BEFORE;
3078 if (drop_pos == GTK_TREE_VIEW_DROP_INTO_OR_AFTER)
3079 drop_pos = GTK_TREE_VIEW_DROP_AFTER;
3082 len = gtk_tree_path_get_depth(path);
3083 gtk_tree_view_set_drag_dest_row(tv, path, drop_pos);
3084 gtk_tree_path_free(path);
3085 gdk_drag_status(ctx, GDK_ACTION_MOVE, time);
3091 GtkTreeView *dstwidget,
3094 GtkSelectionData *selection_data,
3095 guint info, guint t,
3096 signal_user_data_t *ud)
3098 GtkTreePath *path = NULL;
3099 GtkTreeViewDropPosition drop_pos;
3100 GtkTreeIter dstiter, srciter;
3101 gint *dst_indices, dst_len, *src_indices, src_len;
3103 gboolean src_folder, dst_folder;
3105 GtkTreeModel *dstmodel = gtk_tree_view_get_model(dstwidget);
3107 g_debug("preset_drag_cb ()");
3108 // This doesn't work here for some reason...
3109 // gtk_tree_view_get_drag_dest_row(dstwidget, &path, &drop_pos);
3110 gtk_tree_view_get_dest_row_at_pos (dstwidget, x, y, &path, &drop_pos);
3111 // This little hack is needed because attempting to drop after
3112 // the last item gives us no path or drop_pos.
3117 n_children = gtk_tree_model_iter_n_children(dstmodel, NULL);
3120 drop_pos = GTK_TREE_VIEW_DROP_AFTER;
3121 path = gtk_tree_path_new_from_indices(n_children-1, -1);
3125 drop_pos = GTK_TREE_VIEW_DROP_BEFORE;
3126 path = gtk_tree_path_new_from_indices(0, -1);
3131 GtkTreeView *srcwidget;
3132 GtkTreeModel *srcmodel;
3133 GtkTreeSelection *select;
3134 GtkTreePath *srcpath = NULL;
3136 gint tree_depth, ii;
3138 srcwidget = GTK_TREE_VIEW(gtk_drag_get_source_widget(dc));
3139 select = gtk_tree_view_get_selection (srcwidget);
3140 gtk_tree_selection_get_selected (select, &srcmodel, &srciter);
3142 srcpath = gtk_tree_model_get_path (srcmodel, &srciter);
3143 src_indices = gtk_tree_path_get_indices(srcpath);
3144 src_len = gtk_tree_path_get_depth(srcpath);
3145 src_ptype = ghb_presets_get_type(presetsPlist, src_indices, src_len);
3146 src_folder = ghb_presets_get_folder(presetsPlist, src_indices, src_len);
3147 preset = ghb_value_dup(
3148 presets_get_dict(presetsPlist, src_indices, src_len));
3149 gtk_tree_path_free(srcpath);
3151 // Don't allow repositioning of builtin presets
3152 if (src_ptype != PRESETS_CUSTOM)
3155 tree_depth = preset_tree_depth(preset);
3156 if (src_folder && tree_depth == 1)
3159 dst_len = gtk_tree_path_get_depth(path);
3160 if (dst_len+tree_depth-1 >= MAX_NESTED_PRESET)
3162 if (drop_pos == GTK_TREE_VIEW_DROP_INTO_OR_BEFORE)
3163 drop_pos = GTK_TREE_VIEW_DROP_BEFORE;
3164 if (drop_pos == GTK_TREE_VIEW_DROP_INTO_OR_AFTER)
3165 drop_pos = GTK_TREE_VIEW_DROP_AFTER;
3168 for (ii = dst_len+tree_depth-1; ii > MAX_NESTED_PRESET; ii--)
3169 gtk_tree_path_up(path);
3170 dst_indices = gtk_tree_path_get_indices(path);
3171 dst_len = gtk_tree_path_get_depth(path);
3172 dst_folder = ghb_presets_get_folder(presetsPlist, dst_indices, dst_len);
3173 // Only allow *drop into* for folders
3176 if (drop_pos == GTK_TREE_VIEW_DROP_INTO_OR_BEFORE)
3177 drop_pos = GTK_TREE_VIEW_DROP_BEFORE;
3178 if (drop_pos == GTK_TREE_VIEW_DROP_INTO_OR_AFTER)
3179 drop_pos = GTK_TREE_VIEW_DROP_AFTER;
3181 if (gtk_tree_model_get_iter (dstmodel, &dstiter, path))
3184 GtkTreePath *dstpath = NULL;
3188 case GTK_TREE_VIEW_DROP_BEFORE:
3189 gtk_tree_store_insert_before(GTK_TREE_STORE (dstmodel),
3190 &iter, NULL, &dstiter);
3193 case GTK_TREE_VIEW_DROP_INTO_OR_BEFORE:
3194 gtk_tree_store_insert(GTK_TREE_STORE (dstmodel),
3195 &iter, &dstiter, 0);
3198 case GTK_TREE_VIEW_DROP_AFTER:
3199 gtk_tree_store_insert_after(GTK_TREE_STORE (dstmodel),
3200 &iter, NULL, &dstiter);
3203 case GTK_TREE_VIEW_DROP_INTO_OR_AFTER:
3204 gtk_tree_store_insert_after(GTK_TREE_STORE (dstmodel),
3205 &iter, &dstiter, 0);
3212 dstpath = gtk_tree_model_get_path (dstmodel, &iter);
3213 dst_indices = gtk_tree_path_get_indices(dstpath);
3214 dst_len = gtk_tree_path_get_depth(dstpath);
3215 ghb_presets_insert(presetsPlist, preset, dst_indices, dst_len);
3216 gtk_tree_path_free(dstpath);
3218 srcpath = gtk_tree_model_get_path (srcmodel, &srciter);
3219 src_indices = gtk_tree_path_get_indices(srcpath);
3220 src_len = gtk_tree_path_get_depth(srcpath);
3221 ghb_presets_remove(presetsPlist, src_indices, src_len);
3222 gtk_tree_path_free(srcpath);
3224 gtk_tree_store_remove (GTK_TREE_STORE (srcmodel), &srciter);
3226 dstpath = gtk_tree_model_get_path (dstmodel, &iter);
3227 dst_indices = gtk_tree_path_get_indices(dstpath);
3228 dst_len = gtk_tree_path_get_depth(dstpath);
3229 presets_list_update_item(ud, dst_indices, dst_len);
3230 gtk_tree_path_free(dstpath);
3234 gtk_tree_path_free(path);
3239 presets_row_expanded_cb(
3240 GtkTreeView *treeview,
3243 signal_user_data_t *ud)
3246 gboolean expanded, folder;
3248 expanded = gtk_tree_view_row_expanded(treeview, path);
3249 indices = gtk_tree_path_get_indices(path);
3250 len = gtk_tree_path_get_depth(path);
3251 folder = ghb_presets_get_folder(presetsPlist, indices, len);
3254 presets_set_folder_open(expanded, indices, len);
3257 // Collapsing parent folder collapses all children
3260 GValue *presets = NULL;
3262 gint *more_indices, count, ii;
3264 more_indices = g_malloc((len+1)*sizeof(gint));
3265 memcpy(more_indices, indices, len*sizeof(gint));
3267 presets = presets_get_folder(presetsPlist, indices, len);
3268 count = ghb_array_len(presets);
3269 for (ii = 0; ii < count; ii++)
3271 dict = ghb_array_get_nth(presets, ii);
3272 folder = ghb_preset_folder(dict);
3275 more_indices[len] = ii;
3276 presets_set_folder_open(expanded, more_indices, len+1);
3279 g_free(more_indices);
3285 preset_update_title_deps(signal_user_data_t *ud, ghb_title_info_t *tinfo)
3289 ghb_ui_update(ud, "scale_width",
3290 ghb_int64_value(tinfo->width - tinfo->crop[2] - tinfo->crop[3]));
3291 // If anamorphic or keep_aspect, the hight will be automatically calculated
3292 gboolean keep_aspect, anamorphic;
3293 keep_aspect = ghb_settings_get_boolean(ud->settings, "PictureKeepRatio");
3294 anamorphic = ghb_settings_get_boolean(ud->settings, "anamorphic");
3295 if (!(keep_aspect || anamorphic))
3297 ghb_ui_update(ud, "scale_height",
3298 ghb_int64_value(tinfo->height - tinfo->crop[0] - tinfo->crop[1]));
3301 // Set the limits of cropping. hb_set_anamorphic_size crashes if
3302 // you pass it a cropped width or height == 0.
3304 bound = tinfo->height / 2 - 2;
3305 widget = GHB_WIDGET (ud->builder, "PictureTopCrop");
3306 gtk_spin_button_set_range (GTK_SPIN_BUTTON(widget), 0, bound);
3307 widget = GHB_WIDGET (ud->builder, "PictureBottomCrop");
3308 gtk_spin_button_set_range (GTK_SPIN_BUTTON(widget), 0, bound);
3309 bound = tinfo->width / 2 - 2;
3310 widget = GHB_WIDGET (ud->builder, "PictureLeftCrop");
3311 gtk_spin_button_set_range (GTK_SPIN_BUTTON(widget), 0, bound);
3312 widget = GHB_WIDGET (ud->builder, "PictureRightCrop");
3313 gtk_spin_button_set_range (GTK_SPIN_BUTTON(widget), 0, bound);
3314 if (ghb_settings_get_boolean(ud->settings, "PictureAutoCrop"))
3316 ghb_ui_update(ud, "PictureTopCrop", ghb_int64_value(tinfo->crop[0]));
3317 ghb_ui_update(ud, "PictureBottomCrop", ghb_int64_value(tinfo->crop[1]));
3318 ghb_ui_update(ud, "PictureLeftCrop", ghb_int64_value(tinfo->crop[2]));
3319 ghb_ui_update(ud, "PictureRightCrop", ghb_int64_value(tinfo->crop[3]));
3324 presets_list_selection_changed_cb(GtkTreeSelection *selection, signal_user_data_t *ud)
3326 GtkTreeModel *store;
3328 ghb_title_info_t tinfo;
3331 g_debug("presets_list_selection_changed_cb ()");
3332 widget = GHB_WIDGET (ud->builder, "presets_remove");
3333 if (gtk_tree_selection_get_selected(selection, &store, &iter))
3335 GtkTreePath *treepath;
3340 treepath = gtk_tree_model_get_path(store, &iter);
3341 indices = gtk_tree_path_get_indices(treepath);
3342 len = gtk_tree_path_get_depth(treepath);
3344 path = preset_path_from_indices(presetsPlist, indices, len);
3345 ghb_settings_take_value(ud->settings, "preset_selection", path);
3347 folder = ghb_presets_get_folder(presetsPlist, indices, len);
3350 ud->dont_clear_presets = TRUE;
3351 // Temporarily set the video_quality range to (0,100)
3352 // This is needed so the video_quality value does not get
3353 // truncated when set. The range will be readjusted below
3354 GtkWidget *qp = GHB_WIDGET(ud->builder, "VideoQualitySlider");
3355 gtk_range_set_range (GTK_RANGE(qp), 0, 100);
3356 gtk_scale_set_digits(GTK_SCALE(qp), 3);
3357 // Clear the audio list prior to changing the preset. Existing
3358 // audio can cause the container extension to be automatically
3359 // changed when it shouldn't be
3360 ghb_clear_audio_list(ud);
3361 ghb_set_preset_from_indices(ud, indices, len);
3362 gtk_tree_path_free(treepath);
3364 titleindex = ghb_settings_combo_int(ud->settings, "title");
3365 ghb_set_pref_audio(titleindex, ud);
3366 ghb_settings_set_boolean(ud->settings, "preset_modified", FALSE);
3367 ud->dont_clear_presets = FALSE;
3368 if (ghb_get_title_info (&tinfo, titleindex))
3370 preset_update_title_deps(ud, &tinfo);
3372 ghb_set_scale (ud, GHB_SCALE_KEEP_NONE);
3374 gdouble vqmin, vqmax, step, page;
3378 ghb_vquality_range(ud, &vqmin, &vqmax, &step,
3379 &page, &digits, &inverted);
3380 gtk_range_set_range (GTK_RANGE(qp), vqmin, vqmax);
3381 gtk_range_set_increments (GTK_RANGE(qp), step, page);
3382 gtk_scale_set_digits(GTK_SCALE(qp), digits);
3383 gtk_range_set_inverted (GTK_RANGE(qp), inverted);
3387 GtkWidget *crop_widget;
3388 crop[0] = ghb_settings_get_int(ud->settings, "PictureTopCrop");
3389 crop[1] = ghb_settings_get_int(ud->settings, "PictureBottomCrop");
3390 crop[2] = ghb_settings_get_int(ud->settings, "PictureLeftCrop");
3391 crop[3] = ghb_settings_get_int(ud->settings, "PictureRightCrop");
3392 crop_widget = GHB_WIDGET (ud->builder, "crop_values");
3393 text = g_strdup_printf("%d:%d:%d:%d",
3394 crop[0], crop[1], crop[2], crop[3]);
3395 gtk_label_set_text (GTK_LABEL(crop_widget), text);
3398 gtk_widget_set_sensitive(widget, TRUE);
3402 g_debug("No selection??? Perhaps unselected.");
3403 gtk_widget_set_sensitive(widget, FALSE);
3408 ghb_clear_presets_selection(signal_user_data_t *ud)
3410 GtkTreeView *treeview;
3411 GtkTreeSelection *selection;
3413 if (ud->dont_clear_presets) return;
3414 g_debug("ghb_clear_presets_selection()");
3415 treeview = GTK_TREE_VIEW(GHB_WIDGET(ud->builder, "presets_list"));
3416 selection = gtk_tree_view_get_selection (treeview);
3417 gtk_tree_selection_unselect_all (selection);
3418 ghb_settings_set_boolean(ud->settings, "preset_modified", TRUE);
3422 presets_frame_size_allocate_cb(GtkWidget *widget, GtkAllocation *allocation, signal_user_data_t *ud)
3424 GtkTreeView *treeview;
3425 GtkTreeSelection *selection;
3426 GtkTreeModel *store;
3429 treeview = GTK_TREE_VIEW(GHB_WIDGET(ud->builder, "presets_list"));
3430 selection = gtk_tree_view_get_selection(treeview);
3431 if (gtk_tree_selection_get_selected(selection, &store, &iter))
3434 path = gtk_tree_model_get_path (store, &iter);
3435 // Make the parent visible in scroll window if it is not.
3436 gtk_tree_view_scroll_to_cell (treeview, path, NULL, FALSE, 0, 0);
3437 gtk_tree_path_free(path);
3442 presets_default_clicked_cb(GtkWidget *xwidget, signal_user_data_t *ud)
3447 g_debug("presets_default_clicked_cb ()");
3448 preset = ghb_settings_get_value(ud->settings, "preset_selection");
3449 indices = ghb_preset_indices_from_path(presetsPlist, preset, &len);
3452 if (!ghb_presets_get_folder(presetsPlist, indices, len))
3454 ghb_presets_list_clear_default(ud);
3455 presets_set_default(indices, len);
3456 ghb_presets_list_default(ud);