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);
49 preset_path_cmp(gint *indices1, gint len1, gint *indices2, gint len2)
52 for (ii = 0; ii < len1 && ii < len2; ii++)
54 if (indices1[ii] != indices2[ii])
55 return indices1[ii] - indices2[ii];
60 // This only handle limited depth
62 ghb_tree_path_new_from_indices(gint *indices, gint len)
67 return gtk_tree_path_new_from_indices(
70 return gtk_tree_path_new_from_indices(
71 indices[0], indices[1], -1);
73 return gtk_tree_path_new_from_indices(
74 indices[0], indices[1], indices[2], -1);
76 return gtk_tree_path_new_from_indices(
77 indices[0], indices[1], indices[2], indices[3], -1);
79 return gtk_tree_path_new_from_indices(
80 indices[0], indices[1], indices[2], indices[3], indices[4], -1);
87 ghb_parse_preset_path(const gchar *path)
93 preset = ghb_array_value_new(MAX_NESTED_PRESET);
94 split = g_strsplit(path, "#", MAX_NESTED_PRESET);
95 for (ii = 0; split[ii] != NULL; ii++)
97 ghb_array_append(preset, ghb_string_value_new(split[ii]));
104 preset_path_from_indices(GValue *presets, gint *indices, gint len)
109 g_debug("preset_path_from_indices");
110 path = ghb_array_value_new(MAX_NESTED_PRESET);
111 for (ii = 0; ii < len; ii++)
117 count = ghb_array_len(presets);
118 if (indices[ii] >= count) break;
119 dict = ghb_array_get_nth(presets, indices[ii]);
120 name = ghb_dict_lookup(dict, "PresetName");
122 ghb_array_append(path, ghb_value_dup(name));
123 folder = ghb_value_boolean(preset_dict_get_value(dict, "Folder"));
126 presets = ghb_dict_lookup(dict, "ChildrenArray");
132 ghb_preset_path_string(const GValue *path)
139 gstr = g_string_new("");
142 count = ghb_array_len(path);
143 for (ii = 0; ii < count; ii++)
145 val = ghb_array_get_nth(path, ii);
146 str = ghb_value_string(val);
147 g_string_append(gstr, str);
149 g_string_append(gstr, "->");
153 str = g_string_free(gstr, FALSE);
158 dump_preset_path(const gchar *msg, const GValue *path)
163 debug_show_type (G_VALUE_TYPE(path));
164 str = ghb_preset_path_string(path);
165 g_message("%s path: (%s)", msg, str);
170 dump_preset_indices(const gchar *msg, gint *indices, gint len)
174 g_message("%s indices: len %d", msg, len);
175 for (ii = 0; ii < len; ii++)
177 printf("%d ", indices[ii]);
184 preset_path_cmp(const GValue *path1, const GValue *path2)
191 count = ghb_array_len(path1);
192 ii = ghb_array_len(path2);
195 for (ii = 0; ii < count; ii++)
197 val = ghb_array_get_nth(path1, ii);
198 str1 = ghb_value_string(val);
199 val = ghb_array_get_nth(path2, ii);
200 str2 = ghb_value_string(val);
201 result = strcmp(str1, str2);
212 presets_get_dict(GValue *presets, gint *indices, gint len)
214 gint ii, count, folder;
217 g_debug("presets_get_dict ()");
218 for (ii = 0; ii < len; ii++)
220 count = ghb_array_len(presets);
221 if (indices[ii] >= count) return NULL;
222 dict = ghb_array_get_nth(presets, indices[ii]);
225 folder = ghb_value_boolean(preset_dict_get_value(dict, "Folder"));
228 presets = ghb_dict_lookup(dict, "ChildrenArray");
237 presets_get_folder(GValue *presets, gint *indices, gint len)
239 gint ii, count, folder;
242 g_debug("presets_get_folder ()");
243 for (ii = 0; ii < len; ii++)
245 count = ghb_array_len(presets);
246 if (indices[ii] >= count) return NULL;
247 dict = ghb_array_get_nth(presets, indices[ii]);
248 folder = ghb_value_boolean(preset_dict_get_value(dict, "Folder"));
251 presets = ghb_dict_lookup(dict, "ChildrenArray");
259 plist_get_dict(GValue *presets, const gchar *name)
261 if (presets == NULL || name == NULL) return NULL;
262 return ghb_dict_lookup(presets, name);
266 preset_get_name(GValue *dict)
268 return g_value_get_string(preset_dict_get_value(dict, "PresetName"));
272 preset_folder_is_open(GValue *dict)
276 gval = preset_dict_get_value(dict, "FolderOpen");
278 return g_value_get_boolean(gval);
283 ghb_preset_folder(GValue *dict)
285 return ghb_value_int(preset_dict_get_value(dict, "Folder"));
289 ghb_preset_type(GValue *dict)
291 return ghb_value_int(preset_dict_get_value(dict, "Type"));
295 presets_remove_nth(GValue *presets, gint pos)
300 if (presets == NULL || pos < 0) return;
301 count = ghb_array_len(presets);
302 if (pos >= count) return;
303 dict = ghb_array_get_nth(presets, pos);
304 ghb_array_remove(presets, pos);
305 ghb_value_free(dict);
314 GValue *folder = NULL;
316 folder = presets_get_folder(presets, indices, len-1);
318 presets_remove_nth(folder, indices[len-1]);
321 g_warning("ghb_presets_remove (): internal preset lookup error");
334 GValue *folder = NULL;
336 folder = presets_get_folder(presets, indices, len-1);
338 ghb_array_replace(folder, indices[len-1], dict);
341 g_warning("ghb_presets_replace (): internal preset lookup error");
352 GValue *folder = NULL;
354 folder = presets_get_folder(presets, indices, len-1);
356 ghb_array_insert(folder, indices[len-1], dict);
359 g_warning("ghb_presets_insert (): internal preset lookup error");
364 presets_find_element(GValue *presets, const gchar *name)
369 g_debug("presets_find_element () (%s)", name);
370 if (presets == NULL || name == NULL) return -1;
371 count = ghb_array_len(presets);
372 for (ii = 0; ii < count; ii++)
375 dict = ghb_array_get_nth(presets, ii);
376 str = preset_get_name(dict);
377 if (strcmp(name, str) == 0)
386 single_find_pos(GValue *presets, const gchar *name, gint type)
389 gint count, ii, ptype, last;
391 if (presets == NULL || name == NULL) return -1;
392 last = count = ghb_array_len(presets);
393 for (ii = 0; ii < count; ii++)
396 dict = ghb_array_get_nth(presets, ii);
397 str = preset_get_name(dict);
398 ptype = ghb_value_int(preset_dict_get_value(dict, "Type"));
399 if (strcasecmp(name, str) <= 0 && ptype == type)
410 presets_find_pos(const GValue *path, gint type, gint *len)
416 gint *indices = NULL;
420 g_debug("presets_find_pos () ");
421 nested = presetsPlist;
422 count = ghb_array_len(path);
423 indices = g_malloc(MAX_NESTED_PRESET * sizeof(gint));
424 for (ii = 0; ii < count-1; ii++)
426 val = ghb_array_get_nth(path, ii);
427 name = g_value_get_string(val);
428 indices[ii] = presets_find_element(nested, name);
429 if (indices[ii] == -1) return NULL;
430 dict = ghb_array_get_nth(nested, indices[ii]);
431 folder = ghb_value_boolean(preset_dict_get_value(dict, "Folder"));
435 nested = ghb_dict_lookup(dict, "ChildrenArray");
441 name = g_value_get_string(ghb_array_get_nth(path, count-1));
442 indices[ii] = single_find_pos(nested, name, type);
450 preset_tree_depth(GValue *dict)
454 folder = ghb_value_boolean(preset_dict_get_value(dict, "Folder"));
461 presets = ghb_dict_lookup(dict, "ChildrenArray");
462 count = ghb_array_len(presets);
463 for (ii = 0; ii < count; ii++)
467 dict = ghb_array_get_nth(presets, ii);
468 tmp = preset_tree_depth(dict);
469 depth = MAX(depth, tmp);
480 preset_is_default(GValue *dict)
484 val = preset_dict_get_value(dict, "Default");
485 return ghb_value_boolean(val);
489 presets_clear_default(GValue *presets)
493 count = ghb_array_len(presets);
494 for (ii = 0; ii < count; ii++)
499 dict = ghb_array_get_nth(presets, ii);
500 folder = ghb_value_boolean(preset_dict_get_value(dict, "Folder"));
505 nested = ghb_dict_lookup(dict, "ChildrenArray");
506 presets_clear_default(nested);
510 if (preset_is_default(dict))
512 ghb_dict_insert(dict, g_strdup("Default"),
513 ghb_boolean_value_new(FALSE));
520 presets_find_default2(GValue *presets, gint *len)
525 count = ghb_array_len(presets);
526 for (ii = 0; ii < count; ii++)
531 dict = ghb_array_get_nth(presets, ii);
532 folder = ghb_value_boolean(preset_dict_get_value(dict, "Folder"));
538 nested = ghb_dict_lookup(dict, "ChildrenArray");
540 indices = presets_find_default2(nested, len);
551 if (preset_is_default(dict))
553 indices = g_malloc(MAX_NESTED_PRESET * sizeof(gint));
564 presets_find_default(GValue *presets, gint *len)
567 return presets_find_default2(presets, len);
571 ghb_preset_indices_from_path(
579 gint *indices = NULL;
584 g_debug("ghb_preset_indices_from_path () ");
586 count = ghb_array_len(path);
588 indices = g_malloc(MAX_NESTED_PRESET * sizeof(gint));
590 for (ii = 0; ii < count; ii++)
592 val = ghb_array_get_nth(path, ii);
593 name = g_value_get_string(val);
594 indices[ii] = presets_find_element(nested, name);
595 if (indices[ii] == -1)
602 dict = ghb_array_get_nth(nested, indices[ii]);
603 folder = ghb_value_boolean(preset_dict_get_value(dict, "Folder"));
609 nested = ghb_dict_lookup(dict, "ChildrenArray");
617 ghb_presets_get_type(
625 dict = presets_get_dict(presets, indices, len);
628 type = ghb_preset_type(dict);
632 g_warning("ghb_presets_get_type (): internal preset lookup error");
638 ghb_presets_get_folder(
644 gboolean folder = FALSE;
646 dict = presets_get_dict(presets, indices, len);
649 folder = ghb_preset_folder(dict);
653 g_warning("ghb_presets_get_folder (): internal preset lookup error");
659 presets_set_default(gint *indices, gint len)
663 g_debug("presets_set_default ()");
664 presets_clear_default(presetsPlist);
665 dict = presets_get_dict(presetsPlist, indices, len);
668 ghb_dict_insert(dict, g_strdup("Default"), ghb_boolean_value_new(TRUE));
674 presets_set_folder_open(gboolean open, gint *indices, gint len)
678 g_debug("presets_set_folder_open ()");
679 dict = presets_get_dict(presetsPlist, indices, len);
682 ghb_dict_insert(dict, g_strdup("FolderOpen"),
683 ghb_boolean_value_new(open));
687 // Used for sorting dictionaries.
689 key_cmp(gconstpointer a, gconstpointer b)
691 gchar *stra = (gchar*)a;
692 gchar *strb = (gchar*)b;
694 return strcmp(stra, strb);
698 preset_dict_get_value(GValue *dict, const gchar *key)
700 const GValue *gval = NULL;
704 gval = ghb_dict_lookup(dict, key);
706 if (internalPlist == NULL) return NULL;
709 dict = plist_get_dict(internalPlist, "Presets");
710 if (dict == NULL) return NULL;
711 gval = ghb_dict_lookup(dict, key);
717 ghb_presets_get_description(GValue *pdict)
721 if (pdict == NULL) return NULL;
722 desc = g_value_get_string(
723 preset_dict_get_value(pdict, "PresetDescription"));
724 if (desc[0] == 0) return NULL;
729 static void init_settings_from_dict(
730 GValue *dest, GValue *internal, GValue *dict);
733 init_settings_from_array(
741 count = ghb_array_len(array);
742 // The first element of the internal version is always the
743 // template for the allowed values
744 gval = ghb_array_get_nth(internal, 0);
745 for (ii = 0; ii < count; ii++)
748 val = ghb_array_get_nth(array, ii);
751 if (G_VALUE_TYPE(gval) == ghb_dict_get_type())
754 new_dict = ghb_dict_value_new();
755 ghb_array_append(dest, new_dict);
756 if (G_VALUE_TYPE(val) == ghb_dict_get_type())
757 init_settings_from_dict(new_dict, gval, val);
759 init_settings_from_dict(new_dict, gval, gval);
761 else if (G_VALUE_TYPE(gval) == ghb_array_get_type())
764 new_array = ghb_array_value_new(8);
765 ghb_array_append(dest, new_array);
766 if (G_VALUE_TYPE(val) == ghb_array_get_type())
767 init_settings_from_array(new_array, gval, val);
769 init_settings_from_array(new_array, gval, gval);
773 ghb_array_append(dest, val);
779 init_settings_from_dict(
788 ghb_dict_iter_init(&iter, internal);
789 // middle (void*) cast prevents gcc warning "defreferencing type-punned
790 // pointer will break strict-aliasing rules"
791 while (g_hash_table_iter_next(
792 &iter, (gpointer*)(void*)&key, (gpointer*)(void*)&gval))
796 val = ghb_dict_lookup(dict, key);
799 if (G_VALUE_TYPE(gval) == ghb_dict_get_type())
802 new_dict = ghb_dict_value_new();
803 ghb_settings_take_value(dest, key, new_dict);
804 if (G_VALUE_TYPE(val) == ghb_dict_get_type())
805 init_settings_from_dict(new_dict, gval, val);
807 init_settings_from_dict(new_dict, gval, gval);
809 else if (G_VALUE_TYPE(gval) == ghb_array_get_type())
812 new_array = ghb_array_value_new(8);
813 ghb_settings_take_value(dest, key, new_array);
814 if (G_VALUE_TYPE(val) == ghb_array_get_type())
815 init_settings_from_array(new_array, gval, val);
817 init_settings_from_array(new_array, gval, gval);
822 ghb_settings_set_value(dest, key, val);
829 signal_user_data_t *ud,
837 ghb_dict_iter_init(&iter, internal);
838 // middle (void*) cast prevents gcc warning "defreferencing type-punned
839 // pointer will break strict-aliasing rules"
840 while (g_hash_table_iter_next(
841 &iter, (gpointer*)(void*)&key, (gpointer*)(void*)&gval))
845 val = ghb_dict_lookup(dict, key);
848 ghb_ui_update(ud, key, val);
853 preset_to_ui(signal_user_data_t *ud, GValue *dict)
855 g_debug("preset_to_ui()\n");
856 // Initialize the ui from presets file.
857 GValue *internal, *hidden;
859 // Get key list from internal default presets. This way we do not
860 // load any unknown keys.
861 if (internalPlist == NULL) return;
862 internal = plist_get_dict(internalPlist, "Presets");
863 hidden = plist_get_dict(internalPlist, "XlatPresets");
864 // Setting a ui widget will cause the corresponding setting
865 // to be set, but it also triggers a callback that can
866 // have the side effect of using other settings values
867 // that have not yet been set. So set *all* settings first
868 // then update the ui.
869 init_settings_from_dict(ud->settings, internal, dict);
870 init_settings_from_dict(ud->settings, hidden, dict);
871 init_ui_from_dict(ud, internal, dict);
872 init_ui_from_dict(ud, hidden, dict);
876 ghb_settings_to_ui(signal_user_data_t *ud, GValue *dict)
878 init_ui_from_dict(ud, dict, dict);
881 static GValue *current_preset = NULL;
884 ghb_preset_is_custom()
888 if (current_preset == NULL) return FALSE;
889 val = preset_dict_get_value(current_preset, "Type");
890 return (ghb_value_int(val) == 1);
894 ghb_set_preset_from_indices(signal_user_data_t *ud, gint *indices, gint len)
897 gint fallback[2] = {0, -1};
900 dict = presets_get_dict(presetsPlist, indices, len);
905 dict = presets_get_dict(presetsPlist, indices, len);
909 preset_to_ui(ud, NULL);
910 current_preset = NULL;
917 current_preset = dict;
918 folder = ghb_value_boolean(preset_dict_get_value(dict, "Folder"));
920 preset_to_ui(ud, NULL);
922 preset_to_ui(ud, dict);
923 path = preset_path_from_indices(presetsPlist, indices, len);
924 ghb_settings_set_value(ud->settings, "preset", path);
925 ghb_value_free(path);
930 curr_preset_get_value(const gchar *key)
932 if (current_preset == NULL) return NULL;
933 return preset_dict_get_value(current_preset, key);
937 ghb_update_from_preset(
938 signal_user_data_t *ud,
943 g_debug("ghb_update_from_preset() %s", key);
944 gval = curr_preset_get_value(key);
947 ghb_ui_update(ud, key, gval);
957 GtkTreeView *treeview;
958 GtkTreeSelection *selection;
963 g_debug("ghb_select_preset2()");
964 treeview = GTK_TREE_VIEW(GHB_WIDGET(builder, "presets_list"));
965 selection = gtk_tree_view_get_selection (treeview);
966 store = gtk_tree_view_get_model (treeview);
967 path = ghb_tree_path_new_from_indices(indices, len);
970 if (gtk_tree_model_get_iter(store, &iter, path))
972 gtk_tree_selection_select_iter (selection, &iter);
976 if (gtk_tree_model_get_iter_first(store, &iter))
977 gtk_tree_selection_select_iter (selection, &iter);
979 gtk_tree_path_free(path);
984 ghb_select_preset(GtkBuilder *builder, const GValue *path)
988 g_debug("ghb_select_preset()");
989 indices = ghb_preset_indices_from_path(presetsPlist, path, &len);
992 ghb_select_preset2(builder, indices, len);
998 ghb_select_default_preset(GtkBuilder *builder)
1002 g_debug("ghb_select_default_preset()");
1003 indices = presets_find_default(presetsPlist, &len);
1006 ghb_select_preset2(builder, indices, len);
1012 ghb_get_user_config_dir(gchar *subdir)
1017 dir = g_get_user_config_dir();
1018 if (!g_file_test(dir, G_FILE_TEST_IS_DIR))
1020 dir = g_get_home_dir();
1021 config = g_strdup_printf ("%s/.ghb", dir);
1022 if (!g_file_test(config, G_FILE_TEST_IS_DIR))
1023 g_mkdir (config, 0755);
1027 config = g_strdup_printf ("%s/ghb", dir);
1028 if (!g_file_test(config, G_FILE_TEST_IS_DIR))
1029 g_mkdir (config, 0755);
1036 split = g_strsplit(subdir, "/", -1);
1037 for (ii = 0; split[ii] != NULL; ii++)
1041 tmp = g_strdup_printf ("%s/%s", config, split[ii]);
1044 if (!g_file_test(config, G_FILE_TEST_IS_DIR))
1045 g_mkdir (config, 0755);
1052 store_plist(GValue *plist, const gchar *name)
1054 gchar *config, *path;
1057 config = ghb_get_user_config_dir(NULL);
1058 path = g_strdup_printf ("%s/%s", config, name);
1059 file = g_fopen(path, "w");
1062 ghb_plist_write(file, plist);
1067 load_plist(const gchar *name)
1069 gchar *config, *path;
1070 GValue *plist = NULL;
1072 config = ghb_get_user_config_dir(NULL);
1073 path = g_strdup_printf ("%s/%s", config, name);
1074 if (g_file_test(path, G_FILE_TEST_IS_REGULAR))
1076 plist = ghb_plist_parse_file(path);
1084 remove_plist(const gchar *name)
1086 gchar *config, *path;
1088 config = ghb_get_user_config_dir(NULL);
1089 path = g_strdup_printf ("%s/%s", config, name);
1090 if (g_file_test(path, G_FILE_TEST_IS_REGULAR))
1098 static gboolean prefs_initializing = FALSE;
1101 ghb_prefs_to_ui(signal_user_data_t *ud)
1106 GValue *internal, *dict;
1107 GHashTableIter iter;
1110 g_debug("ghb_prefs_to_ui");
1111 prefs_initializing = TRUE;
1113 // Setting a ui widget will cause the corresponding setting
1114 // to be set, but it also triggers a callback that can
1115 // have the side effect of using other settings values
1116 // that have not yet been set. So set *all* settings first
1117 // then update the ui.
1118 internal = plist_get_dict(internalPlist, "Initialization");
1119 ghb_dict_iter_init(&iter, internal);
1120 // middle (void*) cast prevents gcc warning "defreferencing type-punned
1121 // pointer will break strict-aliasing rules"
1122 while (g_hash_table_iter_next(
1123 &iter, (gpointer*)(void*)&key, (gpointer*)(void*)&gval))
1125 ghb_ui_update(ud, key, gval);
1128 dict = plist_get_dict(prefsPlist, "Preferences");
1129 internal = plist_get_dict(internalPlist, "Preferences");
1130 ghb_dict_iter_init(&iter, internal);
1131 // middle (void*) cast prevents gcc warning "defreferencing type-punned
1132 // pointer will break strict-aliasing rules"
1133 while (g_hash_table_iter_next(
1134 &iter, (gpointer*)(void*)&key, (gpointer*)(void*)&gval))
1136 const GValue *value = NULL;
1138 value = ghb_dict_lookup(dict, key);
1141 ghb_settings_set_value(ud->settings, key, value);
1143 internal = plist_get_dict(internalPlist, "Preferences");
1144 ghb_dict_iter_init(&iter, internal);
1145 // middle (void*) cast prevents gcc warning "defreferencing type-punned
1146 // pointer will break strict-aliasing rules"
1147 while (g_hash_table_iter_next(
1148 &iter, (gpointer*)(void*)&key, (gpointer*)(void*)&gval))
1150 const GValue *value = NULL;
1152 value = ghb_dict_lookup(dict, key);
1155 ghb_ui_update(ud, key, value);
1158 val = ghb_settings_get_value(ud->settings, "show_presets");
1159 ghb_ui_update(ud, "show_presets", val);
1160 if (ghb_settings_get_boolean(ud->settings, "hbfd_feature"))
1163 val = ghb_settings_get_value(ud->settings, "hbfd");
1164 ghb_ui_update(ud, "hbfd", val);
1165 action = GHB_ACTION (ud->builder, "hbfd");
1166 gtk_action_set_visible(action, TRUE);
1170 ghb_ui_update(ud, "hbfd", ghb_int64_value(0));
1172 gval = ghb_settings_get_value(ud->settings, "default_source");
1173 ghb_settings_set_value (ud->settings, "source", gval);
1175 str = ghb_settings_get_string(ud->settings, "destination_dir");
1176 ghb_ui_update(ud, "dest_dir", ghb_string_value(str));
1178 gchar *file = g_strdup_printf ("new_video.mp4");
1179 ghb_ui_update(ud, "dest_file", ghb_string_value(file));
1183 prefs_initializing = FALSE;
1187 ghb_prefs_save(GValue *settings)
1191 GHashTableIter iter;
1193 const GValue *value;
1195 if (prefs_initializing) return;
1196 dict = plist_get_dict(internalPlist, "Preferences");
1197 if (dict == NULL) return;
1198 pref_dict = plist_get_dict(prefsPlist, "Preferences");
1199 if (pref_dict == NULL) return;
1200 ghb_dict_iter_init(&iter, dict);
1201 // middle (void*) cast prevents gcc warning "defreferencing type-punned
1202 // pointer will break strict-aliasing rules"
1203 while (g_hash_table_iter_next(
1204 &iter, (gpointer*)(void*)&key, (gpointer*)(void*)&value))
1206 value = ghb_settings_get_value(settings, key);
1209 ghb_dict_insert(pref_dict, g_strdup(key), ghb_value_dup(value));
1213 prefs_modified = FALSE;
1217 ghb_pref_set(GValue *settings, const gchar *key)
1219 const GValue *value, *value2;
1221 if (prefs_initializing) return;
1222 value = ghb_settings_get_value(settings, key);
1226 dict = plist_get_dict(prefsPlist, "Preferences");
1227 if (dict == NULL) return;
1228 value2 = ghb_dict_lookup(dict, key);
1229 if (ghb_value_cmp(value, value2) != 0)
1231 ghb_dict_insert(dict, g_strdup(key), ghb_value_dup(value));
1233 prefs_modified = TRUE;
1239 ghb_pref_save(GValue *settings, const gchar *key)
1241 const GValue *value, *value2;
1243 if (prefs_initializing) return;
1244 value = ghb_settings_get_value(settings, key);
1248 dict = plist_get_dict(prefsPlist, "Preferences");
1249 if (dict == NULL) return;
1250 value2 = ghb_dict_lookup(dict, key);
1251 if (ghb_value_cmp(value, value2) != 0)
1253 ghb_dict_insert(dict, g_strdup(key), ghb_value_dup(value));
1255 prefs_modified = FALSE;
1261 ghb_prefs_store(void)
1266 prefs_modified = FALSE;
1271 ghb_settings_init(signal_user_data_t *ud)
1274 GHashTableIter iter;
1279 g_debug("ghb_settings_init");
1280 prefs_initializing = TRUE;
1282 internalPlist = ghb_resource_get("internal-defaults");
1283 // Setting a ui widget will cause the corresponding setting
1284 // to be set, but it also triggers a callback that can
1285 // have the side effect of using other settings values
1286 // that have not yet been set. So set *all* settings first
1287 // then update the ui.
1288 internal = plist_get_dict(internalPlist, "Initialization");
1289 ghb_dict_iter_init(&iter, internal);
1290 // middle (void*) cast prevents gcc warning "defreferencing type-punned
1291 // pointer will break strict-aliasing rules"
1292 while (g_hash_table_iter_next(
1293 &iter, (gpointer*)(void*)&key, (gpointer*)(void*)&gval))
1295 ghb_settings_set_value(ud->settings, key, gval);
1298 internal = plist_get_dict(internalPlist, "Presets");
1299 ghb_dict_iter_init(&iter, internal);
1300 // middle (void*) cast prevents gcc warning "defreferencing type-punned
1301 // pointer will break strict-aliasing rules"
1302 while (g_hash_table_iter_next(
1303 &iter, (gpointer*)(void*)&key, (gpointer*)(void*)&gval))
1305 ghb_settings_set_value(ud->settings, key, gval);
1308 internal = plist_get_dict(internalPlist, "Preferences");
1309 ghb_dict_iter_init(&iter, internal);
1310 // middle (void*) cast prevents gcc warning "defreferencing type-punned
1311 // pointer will break strict-aliasing rules"
1312 while (g_hash_table_iter_next(
1313 &iter, (gpointer*)(void*)&key, (gpointer*)(void*)&gval))
1315 ghb_settings_set_value(ud->settings, key, gval);
1317 prefs_initializing = FALSE;
1321 ghb_settings_close()
1324 ghb_value_free(internalPlist);
1326 ghb_value_free(presetsPlist);
1328 ghb_value_free(prefsPlist);
1332 ghb_prefs_load(signal_user_data_t *ud)
1334 GValue *dict, *internal;
1335 GHashTableIter iter;
1337 GValue *gval, *path;
1339 g_debug("ghb_prefs_load");
1340 prefsPlist = load_plist("preferences");
1341 if (prefsPlist == NULL)
1342 prefsPlist = ghb_dict_value_new();
1343 dict = plist_get_dict(prefsPlist, "Preferences");
1344 internal = plist_get_dict(internalPlist, "Preferences");
1345 if (dict == NULL && internal)
1347 dict = ghb_dict_value_new();
1348 ghb_dict_insert(prefsPlist, g_strdup("Preferences"), dict);
1350 // Get defaults from internal defaults
1351 ghb_dict_iter_init(&iter, internal);
1352 // middle (void*) cast prevents gcc warning "defreferencing type-punned
1353 // pointer will break strict-aliasing rules"
1354 while (g_hash_table_iter_next(
1355 &iter, (gpointer*)(void*)&key, (gpointer*)(void*)&gval))
1357 ghb_dict_insert(dict, g_strdup(key), ghb_value_dup(gval));
1359 const gchar *dir = g_get_user_special_dir (G_USER_DIRECTORY_VIDEOS);
1364 ghb_dict_insert(dict,
1365 g_strdup("destination_dir"), ghb_value_dup(ghb_string_value(dir)));
1368 // Read legacy default_preset preference and update accordingly
1369 path = ghb_dict_lookup(dict, "default_preset");
1374 if (G_VALUE_TYPE(path) == G_TYPE_STRING)
1378 path = ghb_array_value_new(1);
1379 ghb_array_append(path, ghb_value_dup(str));
1380 indices = ghb_preset_indices_from_path(presetsPlist, path, &len);
1381 ghb_value_free(path);
1384 indices = ghb_preset_indices_from_path(presetsPlist, path, &len);
1388 presets_set_default(indices, len);
1391 ghb_dict_remove(dict, "default_preset");
1397 get_preset_color(gint type, gboolean folder)
1401 if (type == PRESETS_CUSTOM)
1421 ghb_presets_list_init(
1422 signal_user_data_t *ud,
1426 GtkTreeView *treeview;
1427 GtkTreeIter iter, titer, *piter;
1429 GtkTreeStore *store;
1430 const gchar *preset;
1431 GtkTreePath *parent_path;
1432 const gchar *description;
1437 GValue *presets = NULL;
1439 g_debug("ghb_presets_list_init ()");
1440 more_indices = g_malloc((len+1)*sizeof(gint));
1441 memcpy(more_indices, indices, len*sizeof(gint));
1442 presets = presets_get_folder(presetsPlist, indices, len);
1443 if (presets == NULL)
1445 g_warning("Failed to find parent folder when adding child.");
1448 count = ghb_array_len(presets);
1449 treeview = GTK_TREE_VIEW(GHB_WIDGET(ud->builder, "presets_list"));
1450 store = GTK_TREE_STORE(gtk_tree_view_get_model(treeview));
1451 parent_path = ghb_tree_path_new_from_indices(indices, len);
1454 gtk_tree_model_get_iter(GTK_TREE_MODEL(store), &titer, parent_path);
1456 gtk_tree_path_free(parent_path);
1462 for (ii = 0; ii < count; ii++)
1468 // Additional settings, add row
1469 dict = ghb_array_get_nth(presets, ii);
1470 preset = preset_get_name(dict);
1471 more_indices[len] = ii;
1472 def = preset_is_default(dict);
1474 description = ghb_presets_get_description(dict);
1475 gtk_tree_store_append(store, &iter, piter);
1476 type = ghb_preset_type(dict);
1477 folder = ghb_preset_folder(dict);
1478 color = get_preset_color(type, folder);
1479 gtk_tree_store_set(store, &iter, 0, preset,
1490 if (gtk_tree_model_iter_parent(
1491 GTK_TREE_MODEL(store), &ppiter, piter))
1493 path = gtk_tree_model_get_path(GTK_TREE_MODEL(store), &ppiter);
1494 gtk_tree_view_expand_row(treeview, path, FALSE);
1495 gtk_tree_path_free(path);
1497 path = gtk_tree_model_get_path(GTK_TREE_MODEL(store), piter);
1498 gtk_tree_view_expand_row(treeview, path, FALSE);
1499 gtk_tree_path_free(path);
1503 ghb_presets_list_init(ud, more_indices, len+1);
1504 if (preset_folder_is_open(dict))
1510 path = gtk_tree_model_get_path(GTK_TREE_MODEL(store), piter);
1511 gtk_tree_view_expand_row(treeview, path, FALSE);
1512 gtk_tree_path_free(path);
1514 path = gtk_tree_model_get_path(GTK_TREE_MODEL(store), &iter);
1515 gtk_tree_view_expand_row(treeview, path, FALSE);
1516 gtk_tree_path_free(path);
1520 g_free(more_indices);
1524 presets_list_update_item(
1525 signal_user_data_t *ud,
1529 GtkTreeView *treeview;
1530 GtkTreeStore *store;
1532 GtkTreePath *treepath;
1534 const gchar *description;
1536 gboolean def, folder;
1540 g_debug("presets_list_update_item ()");
1541 dict = presets_get_dict(presetsPlist, indices, len);
1544 treeview = GTK_TREE_VIEW(GHB_WIDGET(ud->builder, "presets_list"));
1545 store = GTK_TREE_STORE(gtk_tree_view_get_model(treeview));
1546 treepath = ghb_tree_path_new_from_indices(indices, len);
1547 gtk_tree_model_get_iter(GTK_TREE_MODEL(store), &iter, treepath);
1548 // Additional settings, add row
1549 name = preset_get_name(dict);
1550 def = preset_is_default(dict);
1552 description = ghb_presets_get_description(dict);
1553 type = ghb_preset_type(dict);
1554 folder = ghb_preset_folder(dict);
1555 color = get_preset_color(type, folder);
1556 gtk_tree_store_set(store, &iter, 0, name,
1564 ghb_presets_list_init(ud, indices, len);
1569 presets_list_insert(
1570 signal_user_data_t *ud,
1574 GtkTreeView *treeview;
1575 GtkTreeIter iter, titer, *piter;
1576 GtkTreeStore *store;
1577 const gchar *preset;
1578 const gchar *description;
1580 gboolean def, folder;
1583 GtkTreePath *parent_path;
1587 g_debug("presets_list_insert ()");
1588 treeview = GTK_TREE_VIEW(GHB_WIDGET(ud->builder, "presets_list"));
1589 store = GTK_TREE_STORE(gtk_tree_view_get_model(treeview));
1590 presets = presets_get_folder(presetsPlist, indices, len-1);
1591 if (presets == NULL)
1593 g_warning("Failed to find parent folder while adding child.");
1596 parent_path = ghb_tree_path_new_from_indices(indices, len-1);
1599 gtk_tree_model_get_iter(GTK_TREE_MODEL(store), &titer, parent_path);
1601 gtk_tree_path_free(parent_path);
1607 count = ghb_array_len(presets);
1608 if (indices[len-1] >= count)
1610 // Additional settings, add row
1611 dict = ghb_array_get_nth(presets, indices[len-1]);
1612 preset = preset_get_name(dict);
1613 def = preset_is_default(dict);
1615 description = ghb_presets_get_description(dict);
1616 gtk_tree_store_insert(store, &iter, piter, indices[len-1]);
1617 type = ghb_preset_type(dict);
1618 folder = ghb_preset_folder(dict);
1619 color = get_preset_color(type, folder);
1620 gtk_tree_store_set(store, &iter, 0, preset,
1628 ghb_presets_list_init(ud, indices, len);
1633 presets_list_remove(
1634 signal_user_data_t *ud,
1638 GtkTreeView *treeview;
1639 GtkTreePath *treepath;
1641 GtkTreeStore *store;
1643 g_debug("presets_list_remove ()");
1644 treeview = GTK_TREE_VIEW(GHB_WIDGET(ud->builder, "presets_list"));
1645 store = GTK_TREE_STORE(gtk_tree_view_get_model(treeview));
1646 treepath = ghb_tree_path_new_from_indices(indices, len);
1649 if (gtk_tree_model_get_iter(GTK_TREE_MODEL(store), &iter, treepath))
1650 gtk_tree_store_remove(store, &iter);
1651 gtk_tree_path_free(treepath);
1656 remove_std_presets(signal_user_data_t *ud)
1661 count = ghb_array_len(presetsPlist);
1662 for (ii = count-1; ii >= 0; ii--)
1667 dict = ghb_array_get_nth(presetsPlist, ii);
1668 ptype = ghb_value_int(preset_dict_get_value(dict, "Type"));
1669 if (ptype == PRESETS_BUILTIN)
1671 if (ghb_presets_remove(presetsPlist, &indices, 1))
1673 presets_list_remove(ud, &indices, 1);
1680 ghb_save_queue(GValue *queue)
1682 store_plist(queue, "queue");
1688 return load_plist("queue");
1692 ghb_remove_queue_file()
1694 remove_plist("queue");
1703 static value_map_t vcodec_xlat[] =
1705 {"MPEG-4 (FFmpeg)", "ffmpeg"},
1706 {"MPEG-4 (XviD)", "ffmpeg"},
1707 {"H.264 (x264)", "x264"},
1708 {"VP3 (Theora)", "theora"},
1712 static value_map_t acodec_xlat[] =
1714 {"AAC (faac)", "faac"},
1715 {"AC3 Passthru", "ac3"},
1716 {"MP3 (lame)", "lame"},
1717 {"Vorbis (vorbis)", "vorbis"},
1721 value_map_t container_xlat[] =
1723 {"MP4 file", "mp4"},
1724 {"M4V file", "m4v"},
1725 {"MKV file", "mkv"},
1726 {"AVI file", "mkv"},
1727 {"OGM file", "mkv"},
1731 value_map_t framerate_xlat[] =
1733 {"Same as source", "source"},
1738 {"23.976", "23.976"},
1745 value_map_t samplerate_xlat[] =
1756 value_map_t mix_xlat[] =
1759 {"Stereo", "stereo"},
1760 {"Dolby Surround", "dpl1"},
1761 {"Dolby Pro Logic II", "dpl2"},
1762 {"6-channel discrete", "6ch"},
1763 {"AC3 Passthru", "none"},
1767 value_map_t deint_xlat[] =
1777 value_map_t denoise_xlat[] =
1787 value_map_t detel_xlat[] =
1795 value_map_t decomb_xlat[] =
1803 extern iso639_lang_t ghb_language_table[];
1806 export_lang_xlat2(GValue *lin_val)
1810 if (lin_val == NULL) return NULL;
1814 str = ghb_value_string(lin_val);
1815 for (ii = 0; ghb_language_table[ii].eng_name; ii++)
1817 if (strcmp(str, ghb_language_table[ii].iso639_2) == 0)
1819 gval = ghb_string_value_new(ghb_language_table[ii].eng_name);
1824 g_debug("Can't map language value: (%s)", str);
1830 export_subtitle_xlat2(GValue *lin_val)
1835 if (lin_val == NULL) return NULL;
1836 str = ghb_value_string(lin_val);
1837 if (strcmp(str, "none") == 0)
1839 gval = ghb_string_value_new("None");
1841 else if (strcmp(str, "auto") == 0)
1843 gval = ghb_string_value_new("Autoselect");
1847 gval = export_lang_xlat2(lin_val);
1854 import_lang_xlat2(GValue *mac_val)
1858 if (mac_val == NULL) return NULL;
1862 str = ghb_value_string(mac_val);
1863 for (ii = 0; ghb_language_table[ii].eng_name; ii++)
1865 if (strcmp(str, ghb_language_table[ii].eng_name) == 0)
1867 gval = ghb_string_value_new(ghb_language_table[ii].iso639_2);
1872 g_debug("Can't map language value: (%s)", str);
1878 import_subtitle_xlat2(GValue *mac_val)
1883 if (mac_val == NULL) return NULL;
1884 str = ghb_value_string(mac_val);
1885 if (strcmp(str, "None") == 0)
1887 gval = ghb_string_value_new("none");
1889 else if (strcmp(str, "Autoselect") == 0)
1891 gval = ghb_string_value_new("auto");
1895 gval = import_lang_xlat2(mac_val);
1902 export_audio_track_xlat2(GValue *lin_val)
1905 GValue *gval = NULL;
1907 if (lin_val == NULL) return NULL;
1908 str = ghb_value_string(lin_val);
1909 if (strcmp(str, "none") == 0)
1911 gval = ghb_int_value_new(1);
1915 gint val = ghb_value_int(lin_val) + 1;
1916 gval = ghb_int_value_new(val);
1923 import_audio_track_xlat2(GValue *mac_val)
1929 if (mac_val == NULL) return NULL;
1930 val = ghb_value_int(mac_val);
1939 str = g_strdup_printf("%d", val);
1940 gval = ghb_string_value_new(str);
1946 export_value_xlat2(value_map_t *value_map, GValue *lin_val, GType mac_type)
1950 if (lin_val == NULL) return NULL;
1955 str = ghb_value_string(lin_val);
1956 for (ii = 0; value_map[ii].mac_val; ii++)
1958 if (strcmp(str, value_map[ii].lin_val) == 0)
1960 sval = ghb_string_value_new(value_map[ii].mac_val);
1962 gval = ghb_value_new(mac_type);
1963 if (!g_value_transform(sval, gval))
1965 g_warning("can't transform");
1966 ghb_value_free(gval);
1967 ghb_value_free(sval);
1970 ghb_value_free(sval);
1974 g_debug("Can't map value: (%s)", str);
1980 export_value_xlat(GValue *dict)
1982 GValue *lin_val, *gval;
1985 key = "VideoEncoder";
1986 lin_val = ghb_dict_lookup(dict, key);
1987 gval = export_value_xlat2(vcodec_xlat, lin_val, G_TYPE_STRING);
1989 ghb_dict_insert(dict, g_strdup(key), gval);
1991 lin_val = ghb_dict_lookup(dict, key);
1992 gval = export_value_xlat2(container_xlat, lin_val, G_TYPE_STRING);
1994 ghb_dict_insert(dict, g_strdup(key), gval);
1995 key = "VideoFramerate";
1996 lin_val = ghb_dict_lookup(dict, key);
1997 gval = export_value_xlat2(framerate_xlat, lin_val, G_TYPE_STRING);
1999 ghb_dict_insert(dict, g_strdup(key), gval);
2000 key = "PictureDetelecine";
2001 lin_val = ghb_dict_lookup(dict, key);
2002 gval = export_value_xlat2(detel_xlat, lin_val, G_TYPE_INT);
2004 ghb_dict_insert(dict, g_strdup(key), gval);
2005 key = "PictureDecomb";
2006 lin_val = ghb_dict_lookup(dict, key);
2007 gval = export_value_xlat2(decomb_xlat, lin_val, G_TYPE_INT);
2009 ghb_dict_insert(dict, g_strdup(key), gval);
2010 key = "PictureDeinterlace";
2011 lin_val = ghb_dict_lookup(dict, key);
2012 gval = export_value_xlat2(deint_xlat, lin_val, G_TYPE_INT);
2014 ghb_dict_insert(dict, g_strdup(key), gval);
2015 key = "PictureDenoise";
2016 lin_val = ghb_dict_lookup(dict, key);
2017 gval = export_value_xlat2(denoise_xlat, lin_val, G_TYPE_INT);
2019 ghb_dict_insert(dict, g_strdup(key), gval);
2021 lin_val = ghb_dict_lookup(dict, key);
2022 gval = export_subtitle_xlat2(lin_val);
2024 ghb_dict_insert(dict, g_strdup(key), gval);
2030 alist = ghb_dict_lookup(dict, "AudioList");
2031 count = ghb_array_len(alist);
2032 for (ii = 0; ii < count; ii++)
2034 adict = ghb_array_get_nth(alist, ii);
2036 lin_val = ghb_dict_lookup(adict, key);
2037 gval = export_audio_track_xlat2(lin_val);
2039 ghb_dict_insert(adict, g_strdup(key), gval);
2040 key = "AudioEncoder";
2041 lin_val = ghb_dict_lookup(adict, key);
2042 gval = export_value_xlat2(acodec_xlat, lin_val, G_TYPE_STRING);
2044 ghb_dict_insert(adict, g_strdup(key), gval);
2045 key = "AudioSamplerate";
2046 lin_val = ghb_dict_lookup(adict, key);
2047 gval = export_value_xlat2(samplerate_xlat, lin_val, G_TYPE_STRING);
2049 ghb_dict_insert(adict, g_strdup(key), gval);
2050 key = "AudioMixdown";
2051 lin_val = ghb_dict_lookup(adict, key);
2052 gval = export_value_xlat2(mix_xlat, lin_val, G_TYPE_STRING);
2054 ghb_dict_insert(adict, g_strdup(key), gval);
2062 value_map_t *value_map,
2066 GValue *gval, *def_val;
2068 if (mac_val == NULL) return NULL;
2069 def_val = ghb_dict_lookup(defaults, key);
2076 str = ghb_value_string(mac_val);
2077 for (ii = 0; value_map[ii].mac_val; ii++)
2079 if (strcmp(str, value_map[ii].mac_val) == 0)
2081 sval = ghb_string_value_new(value_map[ii].lin_val);
2083 gval = ghb_value_new(G_VALUE_TYPE(def_val));
2084 if (!g_value_transform(sval, gval))
2086 g_warning("can't transform");
2087 ghb_value_free(gval);
2088 ghb_value_free(sval);
2091 ghb_value_free(sval);
2095 //g_warning("Can't map value: (%s)", str);
2100 g_warning("Bad key: (%s)", key);
2107 import_value_xlat(GValue *dict)
2109 GValue *defaults, *mac_val, *gval;
2112 defaults = plist_get_dict(internalPlist, "Presets");
2113 key = "VideoEncoder";
2114 mac_val = ghb_dict_lookup(dict, key);
2115 gval = import_value_xlat2(defaults, vcodec_xlat, key, mac_val);
2117 ghb_dict_insert(dict, g_strdup(key), gval);
2119 mac_val = ghb_dict_lookup(dict, key);
2120 gval = import_value_xlat2(defaults, container_xlat, key, mac_val);
2122 ghb_dict_insert(dict, g_strdup(key), gval);
2123 key = "VideoFramerate";
2124 mac_val = ghb_dict_lookup(dict, key);
2125 gval = import_value_xlat2(defaults, framerate_xlat, key, mac_val);
2127 ghb_dict_insert(dict, g_strdup(key), gval);
2128 key = "PictureDetelecine";
2129 mac_val = ghb_dict_lookup(dict, key);
2130 gval = import_value_xlat2(defaults, detel_xlat, key, mac_val);
2132 ghb_dict_insert(dict, g_strdup(key), gval);
2133 key = "PictureDecomb";
2134 mac_val = ghb_dict_lookup(dict, key);
2135 gval = import_value_xlat2(defaults, decomb_xlat, key, mac_val);
2137 ghb_dict_insert(dict, g_strdup(key), gval);
2138 key = "PictureDeinterlace";
2139 mac_val = ghb_dict_lookup(dict, key);
2140 gval = import_value_xlat2(defaults, deint_xlat, key, mac_val);
2142 ghb_dict_insert(dict, g_strdup(key), gval);
2143 key = "PictureDenoise";
2144 mac_val = ghb_dict_lookup(dict, key);
2145 gval = import_value_xlat2(defaults, denoise_xlat, key, mac_val);
2147 ghb_dict_insert(dict, g_strdup(key), gval);
2149 mac_val = ghb_dict_lookup(dict, key);
2150 gval = import_subtitle_xlat2(mac_val);
2152 ghb_dict_insert(dict, g_strdup(key), gval);
2160 adeflist = ghb_dict_lookup(dict, "AudioList");
2163 adefaults = ghb_array_get_nth(adeflist, 0);
2164 alist = ghb_dict_lookup(dict, "AudioList");
2165 count = ghb_array_len(alist);
2166 for (ii = 0; ii < count; ii++)
2168 adict = ghb_array_get_nth(alist, ii);
2170 mac_val = ghb_dict_lookup(adict, key);
2171 gval = import_audio_track_xlat2(mac_val);
2173 ghb_dict_insert(adict, g_strdup(key), gval);
2174 key = "AudioEncoder";
2175 mac_val = ghb_dict_lookup(adict, key);
2176 gval = import_value_xlat2(adefaults, acodec_xlat, key, mac_val);
2178 ghb_dict_insert(adict, g_strdup(key), gval);
2179 key = "AudioSamplerate";
2180 mac_val = ghb_dict_lookup(adict, key);
2181 gval = import_value_xlat2(adefaults, samplerate_xlat, key, mac_val);
2183 ghb_dict_insert(adict, g_strdup(key), gval);
2184 key = "AudioMixdown";
2185 mac_val = ghb_dict_lookup(adict, key);
2186 gval = import_value_xlat2(adefaults, mix_xlat, key, mac_val);
2188 ghb_dict_insert(adict, g_strdup(key), gval);
2194 import_xlat_preset(GValue *dict)
2198 gint par, par_width, par_height;
2201 g_debug("import_xlat_preset ()");
2202 uses_max = ghb_value_boolean(
2203 preset_dict_get_value(dict, "UsesMaxPictureSettings"));
2204 uses_pic = ghb_value_int(
2205 preset_dict_get_value(dict, "UsesPictureSettings"));
2206 par = ghb_value_int(preset_dict_get_value(dict, "PicturePAR"));
2207 vqtype = ghb_value_int(preset_dict_get_value(dict, "VideoQualityType"));
2208 par_width = ghb_value_int(preset_dict_get_value(dict, "PicturePARWidth"));
2209 par_height = ghb_value_int(preset_dict_get_value(dict, "PicturePARHeight"));
2210 ghb_dict_insert(dict, g_strdup("par_width"),
2211 ghb_int_value_new(par_width));
2212 ghb_dict_insert(dict, g_strdup("par_height"),
2213 ghb_int_value_new(par_height));
2215 if (uses_max || uses_pic == 2)
2217 ghb_dict_insert(dict, g_strdup("autoscale"),
2218 ghb_boolean_value_new(TRUE));
2224 if (ghb_dict_lookup(dict, "PictureAlignment") == NULL)
2225 ghb_dict_insert(dict, g_strdup("PictureAlignment"),
2226 ghb_int_value_new(16));
2230 ghb_dict_insert(dict, g_strdup("PictureAlignment"),
2231 ghb_int_value_new(1));
2235 if (ghb_dict_lookup(dict, "PictureAlignment") == NULL)
2236 ghb_dict_insert(dict, g_strdup("PictureAlignment"),
2237 ghb_int_value_new(16));
2241 if (ghb_dict_lookup(dict, "PictureAlignment") == NULL)
2242 ghb_dict_insert(dict, g_strdup("PictureAlignment"),
2243 ghb_int_value_new(16));
2246 // VideoQualityType/0/1/2 - vquality_type_/target/bitrate/constant
2251 ghb_dict_insert(dict, g_strdup("vquality_type_target"),
2252 ghb_boolean_value_new(TRUE));
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(FALSE));
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(TRUE));
2264 ghb_dict_insert(dict, g_strdup("vquality_type_constant"),
2265 ghb_boolean_value_new(FALSE));
2269 ghb_dict_insert(dict, g_strdup("vquality_type_target"),
2270 ghb_boolean_value_new(FALSE));
2271 ghb_dict_insert(dict, g_strdup("vquality_type_bitrate"),
2272 ghb_boolean_value_new(FALSE));
2273 ghb_dict_insert(dict, g_strdup("vquality_type_constant"),
2274 ghb_boolean_value_new(TRUE));
2278 ghb_dict_insert(dict, g_strdup("vquality_type_target"),
2279 ghb_boolean_value_new(FALSE));
2280 ghb_dict_insert(dict, g_strdup("vquality_type_bitrate"),
2281 ghb_boolean_value_new(FALSE));
2282 ghb_dict_insert(dict, g_strdup("vquality_type_constant"),
2283 ghb_boolean_value_new(TRUE));
2286 import_value_xlat(dict);
2291 vquality = ghb_value_double(preset_dict_get_value(dict, "VideoQualitySlider"));
2296 gval = preset_dict_get_value(dict, "VideoEncoder");
2297 vcodec = ghb_lookup_combo_int("VideoEncoder", gval);
2300 case HB_VCODEC_X264:
2302 vquality = 51. - vquality * 51.;
2305 case HB_VCODEC_XVID:
2306 case HB_VCODEC_FFMPEG:
2308 vquality = 31. - vquality * 30.;
2311 case HB_VCODEC_THEORA:
2313 vquality = vquality * 63.;
2321 ghb_dict_insert(dict, g_strdup("VideoQualitySlider"),
2322 ghb_double_value_new(vquality));
2327 import_xlat_presets(GValue *presets)
2333 g_debug("import_xlat_presets ()");
2334 if (presets == NULL) return;
2335 count = ghb_array_len(presets);
2336 for (ii = 0; ii < count; ii++)
2338 dict = ghb_array_get_nth(presets, ii);
2339 folder = ghb_value_boolean(preset_dict_get_value(dict, "Folder"));
2344 nested = ghb_dict_lookup(dict, "ChildrenArray");
2345 import_xlat_presets(nested);
2349 import_xlat_preset(dict);
2355 export_xlat_preset(GValue *dict)
2357 gboolean autoscale, target, br, constant;
2358 gint par_width, par_height;
2360 g_debug("export_xlat_prest ()");
2361 autoscale = ghb_value_boolean(preset_dict_get_value(dict, "autoscale"));
2362 target = ghb_value_boolean(
2363 preset_dict_get_value(dict, "vquality_type_target"));
2364 br = ghb_value_boolean(
2365 preset_dict_get_value(dict, "vquality_type_bitrate"));
2366 constant = ghb_value_boolean(
2367 preset_dict_get_value(dict, "vquality_type_constant"));
2368 par_width = ghb_value_int(
2369 preset_dict_get_value(dict, "par_width"));
2370 par_height = ghb_value_int(
2371 preset_dict_get_value(dict, "par_height"));
2374 ghb_dict_insert(dict, g_strdup("UsesPictureSettings"),
2375 ghb_int_value_new(2));
2377 ghb_dict_insert(dict, g_strdup("UsesPictureSettings"),
2378 ghb_int_value_new(1));
2380 // VideoQualityType/0/1/2 - vquality_type_/target/bitrate/constant
2383 ghb_dict_insert(dict, g_strdup("VideoQualityType"),
2384 ghb_int_value_new(0));
2388 ghb_dict_insert(dict, g_strdup("VideoQualityType"),
2389 ghb_int_value_new(1));
2393 ghb_dict_insert(dict, g_strdup("VideoQualityType"),
2394 ghb_int_value_new(2));
2396 ghb_dict_insert(dict, g_strdup("PicturePARWidth"),
2397 ghb_int_value_new(par_width));
2398 ghb_dict_insert(dict, g_strdup("PicturePARHeight"),
2399 ghb_int_value_new(par_height));
2400 ghb_dict_remove(dict, "UsesMaxPictureSettings");
2401 ghb_dict_remove(dict, "autoscale");
2402 ghb_dict_remove(dict, "vquality_type_target");
2403 ghb_dict_remove(dict, "vquality_type_bitrate");
2404 ghb_dict_remove(dict, "vquality_type_constant");
2405 ghb_dict_remove(dict, "par_width");
2406 ghb_dict_remove(dict, "par_height");
2407 export_value_xlat(dict);
2411 export_xlat_presets(GValue *presets)
2417 if (presets == NULL) return;
2418 count = ghb_array_len(presets);
2419 for (ii = 0; ii < count; ii++)
2421 dict = ghb_array_get_nth(presets, ii);
2422 folder = ghb_value_boolean(preset_dict_get_value(dict, "Folder"));
2427 nested = ghb_dict_lookup(dict, "ChildrenArray");
2428 export_xlat_presets(nested);
2432 export_xlat_preset(dict);
2437 static guint prefs_timeout_id = 0;
2440 delayed_store_prefs(gpointer data)
2442 store_plist(prefsPlist, "preferences");
2443 prefs_timeout_id = 0;
2452 export = ghb_value_dup(presetsPlist);
2453 export_xlat_presets(export);
2454 store_plist(export, "presets");
2455 ghb_value_free(export);
2461 if (prefs_timeout_id != 0)
2466 mc = g_main_context_default();
2467 source = g_main_context_find_source_by_id(mc, prefs_timeout_id);
2469 g_source_destroy(source);
2471 prefs_timeout_id = g_timeout_add_seconds(1, (GSourceFunc)delayed_store_prefs, NULL);
2475 ghb_presets_reload(signal_user_data_t *ud)
2477 GValue *std_presets;
2481 g_debug("ghb_presets_reload()\n");
2482 std_presets = ghb_resource_get("standard-presets");
2483 if (std_presets == NULL) return;
2485 remove_std_presets(ud);
2486 indices = presets_find_default(presetsPlist, &len);
2489 presets_clear_default(std_presets);
2492 // Merge the keyfile contents into our presets
2493 count = ghb_array_len(std_presets);
2494 for (ii = count-1; ii >= 0; ii--)
2500 std_dict = ghb_array_get_nth(std_presets, ii);
2501 copy_dict = ghb_value_dup(std_dict);
2502 ghb_presets_insert(presetsPlist, copy_dict, &indices, 1);
2503 presets_list_insert(ud, &indices, 1);
2505 import_xlat_presets(presetsPlist);
2514 count = ghb_array_len(presetsPlist);
2515 for (ii = count-1; ii >= 0; ii--)
2520 dict = ghb_array_get_nth(presetsPlist, ii);
2521 type = ghb_dict_lookup(dict, "Type");
2531 presetsPlist = load_plist("presets");
2532 if (presetsPlist == NULL)
2534 presetsPlist = ghb_value_dup(ghb_resource_get("standard-presets"));
2535 import_xlat_presets(presetsPlist);
2538 else if (G_VALUE_TYPE(presetsPlist) == ghb_dict_get_type())
2539 { // Presets is older dictionary format. Convert to array
2540 ghb_value_free(presetsPlist);
2541 presetsPlist = ghb_value_dup(ghb_resource_get("standard-presets"));
2542 import_xlat_presets(presetsPlist);
2545 else if (check_old_presets())
2547 ghb_value_free(presetsPlist);
2548 presetsPlist = ghb_value_dup(ghb_resource_get("standard-presets"));
2549 import_xlat_presets(presetsPlist);
2552 import_xlat_presets(presetsPlist);
2556 settings_save(signal_user_data_t *ud, const GValue *path)
2558 GValue *dict, *internal;
2559 GHashTableIter iter;
2563 gint *indices, len, count;
2564 gint *def_indices, def_len;
2566 gboolean replace = FALSE;
2568 g_debug("settings_save");
2569 if (internalPlist == NULL) return;
2570 count = ghb_array_len(path);
2571 name = g_value_get_string(ghb_array_get_nth(path, count-1));
2572 indices = ghb_preset_indices_from_path(presetsPlist, path, &len);
2575 if (ghb_presets_get_folder(presetsPlist, indices, len))
2578 message = g_strdup_printf(
2579 "%s: Folder already exists.\n"
2580 "You can not replace it with a preset.",
2582 ghb_message_dialog(GTK_MESSAGE_ERROR, message, "Cancel", NULL);
2586 dict = ghb_dict_value_new();
2587 ghb_presets_replace(presetsPlist, dict, indices, len);
2592 indices = presets_find_pos(path, PRESETS_CUSTOM, &len);
2595 dict = ghb_dict_value_new();
2596 ghb_presets_insert(presetsPlist, dict, indices, len);
2600 g_warning("failed to find insert path");
2604 current_preset = dict;
2605 autoscale = ghb_settings_get_boolean(ud->settings, "autoscale");
2606 ghb_settings_set_int64(ud->settings, "Type", PRESETS_CUSTOM);
2608 internal = plist_get_dict(internalPlist, "Presets");
2609 ghb_dict_iter_init(&iter, internal);
2610 // middle (void*) cast prevents gcc warning "defreferencing type-punned
2611 // pointer will break strict-aliasing rules"
2612 while (g_hash_table_iter_next(
2613 &iter, (gpointer*)(void*)&key, (gpointer*)(void*)&value))
2621 if (strcmp(key, "PictureWidth") == 0)
2623 key2 = "scale_width";
2625 else if (strcmp(key, "PictureHeight") == 0)
2627 key2 = "scale_height";
2630 gval = ghb_settings_get_value(ud->settings, key2);
2635 ghb_dict_insert(dict, g_strdup(key), ghb_value_dup(gval));
2637 internal = plist_get_dict(internalPlist, "XlatPresets");
2638 ghb_dict_iter_init(&iter, internal);
2639 // middle (void*) cast prevents gcc warning "defreferencing type-punned
2640 // pointer will break strict-aliasing rules"
2641 while (g_hash_table_iter_next(
2642 &iter, (gpointer*)(void*)&key, (gpointer*)(void*)&value))
2646 gval = ghb_settings_get_value(ud->settings, key);
2651 ghb_dict_insert(dict, g_strdup(key), ghb_value_dup(gval));
2653 ghb_dict_insert(dict, g_strdup("PresetName"), ghb_string_value_new(name));
2656 def_indices = presets_find_default(presetsPlist, &def_len);
2657 if (def_indices != NULL &&
2658 preset_path_cmp(indices, len, def_indices, def_len) != 0)
2660 ghb_dict_insert(dict, g_strdup("Default"),
2661 ghb_boolean_value_new(FALSE));
2663 presets_list_update_item(ud, indices, len);
2667 ghb_dict_insert(dict, g_strdup("Default"),
2668 ghb_boolean_value_new(FALSE));
2669 presets_list_insert(ud, indices, len);
2672 ud->dont_clear_presets = TRUE;
2673 // Make the new preset the selected item
2674 ghb_select_preset2(ud->builder, indices, len);
2676 ud->dont_clear_presets = FALSE;
2681 folder_save(signal_user_data_t *ud, const GValue *path)
2683 GValue *dict, *folder;
2684 gint *indices, len, count;
2687 count = ghb_array_len(path);
2688 name = g_value_get_string(ghb_array_get_nth(path, count-1));
2689 indices = ghb_preset_indices_from_path(presetsPlist, path, &len);
2692 if (!ghb_presets_get_folder(presetsPlist, indices, len))
2695 message = g_strdup_printf(
2696 "%s: Preset already exists.\n"
2697 "You can not replace it with a folder.",
2699 ghb_message_dialog(GTK_MESSAGE_ERROR, message, "Cancel", NULL);
2704 // Already exists, update its description
2705 dict = presets_get_dict(presetsPlist, indices, len);
2706 ghb_dict_insert(dict, g_strdup("PresetDescription"),
2707 ghb_value_dup(preset_dict_get_value(
2708 ud->settings, "PresetDescription")));
2714 indices = presets_find_pos(path, PRESETS_CUSTOM, &len);
2717 dict = ghb_dict_value_new();
2718 ghb_presets_insert(presetsPlist, dict, indices, len);
2722 g_warning("failed to find insert path");
2726 ghb_dict_insert(dict, g_strdup("PresetDescription"),
2727 ghb_value_dup(preset_dict_get_value(
2728 ud->settings, "PresetDescription")));
2729 ghb_dict_insert(dict, g_strdup("PresetName"), ghb_string_value_new(name));
2730 folder = ghb_array_value_new(8);
2731 ghb_dict_insert(dict, g_strdup("ChildrenArray"), folder);
2732 ghb_dict_insert(dict, g_strdup("Type"),
2733 ghb_int64_value_new(PRESETS_CUSTOM));
2734 ghb_dict_insert(dict, g_strdup("Folder"), ghb_boolean_value_new(TRUE));
2736 presets_list_insert(ud, indices, len);
2743 ghb_presets_list_default(signal_user_data_t *ud)
2745 GtkTreeView *treeview;
2746 GtkTreePath *treepath;
2748 GtkTreeStore *store;
2751 g_debug("ghb_presets_list_default ()");
2752 treeview = GTK_TREE_VIEW(GHB_WIDGET(ud->builder, "presets_list"));
2753 store = GTK_TREE_STORE(gtk_tree_view_get_model(treeview));
2754 indices = presets_find_default(presetsPlist, &len);
2755 if (indices == NULL) return;
2756 treepath = ghb_tree_path_new_from_indices(indices, len);
2759 if (gtk_tree_model_get_iter(GTK_TREE_MODEL(store), &iter, treepath))
2761 gtk_tree_store_set(store, &iter,
2766 gtk_tree_path_free(treepath);
2772 ghb_presets_list_clear_default(signal_user_data_t *ud)
2774 GtkTreeView *treeview;
2775 GtkTreePath *treepath;
2777 GtkTreeStore *store;
2780 g_debug("ghb_presets_list_clear_default ()");
2781 treeview = GTK_TREE_VIEW(GHB_WIDGET(ud->builder, "presets_list"));
2782 store = GTK_TREE_STORE(gtk_tree_view_get_model(treeview));
2783 indices = presets_find_default(presetsPlist, &len);
2784 if (indices == NULL) return;
2785 treepath = ghb_tree_path_new_from_indices(indices, len);
2788 if (gtk_tree_model_get_iter(GTK_TREE_MODEL(store), &iter, treepath))
2790 gtk_tree_store_set(store, &iter,
2795 gtk_tree_path_free(treepath);
2801 update_audio_presets(signal_user_data_t *ud)
2803 g_debug("update_audio_presets");
2804 const GValue *audio_list;
2806 audio_list = ghb_settings_get_value(ud->settings, "audio_list");
2807 ghb_settings_set_value(ud->settings, "AudioList", audio_list);
2811 enforce_preset_type(signal_user_data_t *ud, const GValue *path)
2814 GtkWidget *normal, *folder;
2817 normal = GHB_WIDGET(ud->builder, "preset_type_normal");
2818 folder = GHB_WIDGET(ud->builder, "preset_type_folder");
2819 indices = ghb_preset_indices_from_path(presetsPlist, path, &len);
2822 fold = ghb_presets_get_folder(presetsPlist, indices, len);
2824 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(folder),
2827 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(normal),
2829 gtk_widget_set_sensitive(folder, fold);
2830 gtk_widget_set_sensitive(normal, !fold);
2835 gtk_widget_set_sensitive(folder, TRUE);
2836 gtk_widget_set_sensitive(normal, TRUE);
2841 presets_save_clicked_cb(GtkWidget *xwidget, signal_user_data_t *ud)
2846 GtkResponseType response;
2848 const gchar *name = "";
2849 gint count, *indices, len;
2851 g_debug("presets_save_clicked_cb ()");
2852 preset = ghb_settings_get_value (ud->settings, "preset_selection");
2854 count = ghb_array_len(preset);
2856 name = g_value_get_string(ghb_array_get_nth(preset, count-1));
2859 // Clear the description
2860 desc = GTK_TEXT_VIEW(GHB_WIDGET(ud->builder, "PresetDescription"));
2861 dialog = GHB_WIDGET(ud->builder, "preset_save_dialog");
2862 entry = GTK_ENTRY(GHB_WIDGET(ud->builder, "PresetName"));
2863 gtk_entry_set_text(entry, name);
2864 enforce_preset_type(ud, preset);
2865 response = gtk_dialog_run(GTK_DIALOG(dialog));
2866 gtk_widget_hide(dialog);
2867 if (response == GTK_RESPONSE_OK)
2870 const gchar *name = gtk_entry_get_text(entry);
2873 if (ghb_settings_get_boolean(ud->settings, "preset_type_folder"))
2875 if (count > MAX_NESTED_PRESET-1)
2877 count = MAX_NESTED_PRESET-1;
2880 dest = ghb_array_value_new(MAX_NESTED_PRESET);
2881 indices = ghb_preset_indices_from_path(presetsPlist, preset, &len);
2886 ptype = ghb_presets_get_type(presetsPlist, indices, len);
2887 if (ptype == PRESETS_CUSTOM)
2889 ghb_array_copy(dest, preset, count-1);
2892 ghb_array_append(dest, ghb_string_value_new(name));
2894 ghb_widget_to_setting(ud->settings, GTK_WIDGET(desc));
2895 if (ghb_settings_get_boolean(ud->settings, "preset_type_folder"))
2897 folder_save(ud, dest);
2901 // Construct the audio settings presets from the current audio list
2902 update_audio_presets(ud);
2903 settings_save(ud, dest);
2905 ghb_value_free(dest);
2910 preset_type_changed_cb(GtkWidget *widget, signal_user_data_t *ud)
2912 ghb_widget_to_setting(ud->settings, widget);
2916 preset_name_changed_cb(GtkWidget *entry, signal_user_data_t *ud)
2919 GValue *preset, *dest;
2922 preset = ghb_settings_get_value (ud->settings, "preset_selection");
2923 name = ghb_widget_string(entry);
2924 dest = ghb_value_dup(preset);
2925 count = ghb_array_len(dest);
2926 ghb_array_replace(dest, count-1, ghb_string_value_new(name));
2927 enforce_preset_type(ud, dest);
2928 ghb_value_free(dest);
2932 presets_restore_clicked_cb(GtkWidget *xwidget, signal_user_data_t *ud)
2936 g_debug("presets_restore_clicked_cb ()");
2937 // Reload only the standard presets
2938 ghb_presets_reload(ud);
2939 // Updating the presets list shuffles things around
2940 // need to make sure the proper preset is selected
2941 preset = ghb_settings_get_value (ud->settings, "preset");
2942 ghb_select_preset(ud->builder, preset);
2946 presets_remove_clicked_cb(GtkWidget *xwidget, signal_user_data_t *ud)
2948 GtkTreeView *treeview;
2949 GtkTreeSelection *selection;
2950 GtkTreeModel *store;
2953 GtkResponseType response;
2955 g_debug("presets_remove_clicked_cb ()");
2956 treeview = GTK_TREE_VIEW(GHB_WIDGET(ud->builder, "presets_list"));
2957 selection = gtk_tree_view_get_selection (treeview);
2958 if (gtk_tree_selection_get_selected(selection, &store, &iter))
2965 gtk_tree_model_get(store, &iter, 0, &preset, -1);
2966 path = gtk_tree_model_get_path(store, &iter);
2967 indices = gtk_tree_path_get_indices(path);
2968 len = gtk_tree_path_get_depth(path);
2970 folder = ghb_presets_get_folder(presetsPlist, indices, len);
2971 dialog = gtk_message_dialog_new(NULL, GTK_DIALOG_MODAL,
2972 GTK_MESSAGE_QUESTION, GTK_BUTTONS_YES_NO,
2973 "Confirm deletion of %s:\n\n%s",
2974 folder ? "folder" : "preset",
2976 response = gtk_dialog_run(GTK_DIALOG(dialog));
2977 gtk_widget_destroy (dialog);
2978 if (response == GTK_RESPONSE_YES)
2980 GtkTreeIter nextIter = iter;
2981 gboolean valid = TRUE;
2982 if (!gtk_tree_model_iter_next(store, &nextIter))
2984 if (!gtk_tree_model_iter_parent(store, &nextIter, &iter))
2989 // Remove the selected item
2990 // First unselect it so that selecting the new item works properly
2991 gtk_tree_selection_unselect_iter (selection, &iter);
2992 if (ghb_presets_remove(presetsPlist, indices, len))
2995 presets_list_remove(ud, indices, len);
2998 valid = gtk_tree_model_get_iter_first(store, &nextIter);
3001 gtk_tree_path_free(path);
3002 path = gtk_tree_model_get_path(store, &nextIter);
3003 indices = gtk_tree_path_get_indices(path);
3004 len = gtk_tree_path_get_depth(path);
3005 ghb_select_preset2(ud->builder, indices, len);
3009 gtk_tree_path_free(path);
3013 // controls where valid drop locations are
3015 presets_drag_motion_cb(
3017 GdkDragContext *ctx,
3021 signal_user_data_t *ud)
3023 GtkTreePath *path = NULL;
3024 GtkTreeViewDropPosition drop_pos;
3028 GtkTreeModel *model;
3029 GtkTreeSelection *select;
3030 gint src_ptype, dst_ptype;
3031 gboolean src_folder, dst_folder;
3033 gint tree_depth, ii;
3035 // Get the type of the object being dragged
3036 srctv = GTK_TREE_VIEW(gtk_drag_get_source_widget(ctx));
3037 select = gtk_tree_view_get_selection (srctv);
3038 gtk_tree_selection_get_selected (select, &model, &iter);
3039 path = gtk_tree_model_get_path (model, &iter);
3040 indices = gtk_tree_path_get_indices(path);
3041 len = gtk_tree_path_get_depth(path);
3043 preset = presets_get_dict(presetsPlist, indices, len);
3044 tree_depth = preset_tree_depth(preset);
3046 src_ptype = ghb_presets_get_type(presetsPlist, indices, len);
3047 src_folder = ghb_presets_get_folder(presetsPlist, indices, len);
3048 gtk_tree_path_free(path);
3050 if (src_folder && tree_depth == 1)
3053 // The rest checks that the destination is a valid position
3055 gtk_tree_view_get_dest_row_at_pos (tv, x, y, &path, &drop_pos);
3058 gdk_drag_status(ctx, 0, time);
3061 // Don't allow repositioning of builtin presets
3062 if (src_ptype != PRESETS_CUSTOM)
3064 gdk_drag_status(ctx, 0, time);
3068 len = gtk_tree_path_get_depth(path);
3069 if (len+tree_depth-1 >= MAX_NESTED_PRESET)
3071 if (drop_pos == GTK_TREE_VIEW_DROP_INTO_OR_BEFORE)
3072 drop_pos = GTK_TREE_VIEW_DROP_BEFORE;
3073 if (drop_pos == GTK_TREE_VIEW_DROP_INTO_OR_AFTER)
3074 drop_pos = GTK_TREE_VIEW_DROP_AFTER;
3076 for (ii = len+tree_depth-1; ii > MAX_NESTED_PRESET; ii--)
3077 gtk_tree_path_up(path);
3078 indices = gtk_tree_path_get_indices(path);
3079 len = gtk_tree_path_get_depth(path);
3080 dst_ptype = ghb_presets_get_type(presetsPlist, indices, len);
3081 dst_folder = ghb_presets_get_folder(presetsPlist, indices, len);
3082 // Don't allow mixing custom presets in the builtins
3083 if (dst_ptype != PRESETS_CUSTOM)
3085 gdk_drag_status(ctx, 0, time);
3089 // Only allow *drop into* for folders
3092 if (drop_pos == GTK_TREE_VIEW_DROP_INTO_OR_BEFORE)
3093 drop_pos = GTK_TREE_VIEW_DROP_BEFORE;
3094 if (drop_pos == GTK_TREE_VIEW_DROP_INTO_OR_AFTER)
3095 drop_pos = GTK_TREE_VIEW_DROP_AFTER;
3098 len = gtk_tree_path_get_depth(path);
3099 gtk_tree_view_set_drag_dest_row(tv, path, drop_pos);
3100 gtk_tree_path_free(path);
3101 gdk_drag_status(ctx, GDK_ACTION_MOVE, time);
3107 GtkTreeView *dstwidget,
3110 GtkSelectionData *selection_data,
3111 guint info, guint t,
3112 signal_user_data_t *ud)
3114 GtkTreePath *path = NULL;
3115 GtkTreeViewDropPosition drop_pos;
3116 GtkTreeIter dstiter, srciter;
3117 gint *dst_indices, dst_len, *src_indices, src_len;
3119 gboolean src_folder, dst_folder;
3121 GtkTreeModel *dstmodel = gtk_tree_view_get_model(dstwidget);
3123 g_debug("preset_drag_cb ()");
3124 // This doesn't work here for some reason...
3125 // gtk_tree_view_get_drag_dest_row(dstwidget, &path, &drop_pos);
3126 gtk_tree_view_get_dest_row_at_pos (dstwidget, x, y, &path, &drop_pos);
3127 // This little hack is needed because attempting to drop after
3128 // the last item gives us no path or drop_pos.
3133 n_children = gtk_tree_model_iter_n_children(dstmodel, NULL);
3136 drop_pos = GTK_TREE_VIEW_DROP_AFTER;
3137 path = gtk_tree_path_new_from_indices(n_children-1, -1);
3141 drop_pos = GTK_TREE_VIEW_DROP_BEFORE;
3142 path = gtk_tree_path_new_from_indices(0, -1);
3147 GtkTreeView *srcwidget;
3148 GtkTreeModel *srcmodel;
3149 GtkTreeSelection *select;
3150 GtkTreePath *srcpath = NULL;
3152 gint tree_depth, ii;
3154 srcwidget = GTK_TREE_VIEW(gtk_drag_get_source_widget(dc));
3155 select = gtk_tree_view_get_selection (srcwidget);
3156 gtk_tree_selection_get_selected (select, &srcmodel, &srciter);
3158 srcpath = gtk_tree_model_get_path (srcmodel, &srciter);
3159 src_indices = gtk_tree_path_get_indices(srcpath);
3160 src_len = gtk_tree_path_get_depth(srcpath);
3161 src_ptype = ghb_presets_get_type(presetsPlist, src_indices, src_len);
3162 src_folder = ghb_presets_get_folder(presetsPlist, src_indices, src_len);
3163 preset = ghb_value_dup(
3164 presets_get_dict(presetsPlist, src_indices, src_len));
3165 gtk_tree_path_free(srcpath);
3167 // Don't allow repositioning of builtin presets
3168 if (src_ptype != PRESETS_CUSTOM)
3171 tree_depth = preset_tree_depth(preset);
3172 if (src_folder && tree_depth == 1)
3175 dst_len = gtk_tree_path_get_depth(path);
3176 if (dst_len+tree_depth-1 >= MAX_NESTED_PRESET)
3178 if (drop_pos == GTK_TREE_VIEW_DROP_INTO_OR_BEFORE)
3179 drop_pos = GTK_TREE_VIEW_DROP_BEFORE;
3180 if (drop_pos == GTK_TREE_VIEW_DROP_INTO_OR_AFTER)
3181 drop_pos = GTK_TREE_VIEW_DROP_AFTER;
3184 for (ii = dst_len+tree_depth-1; ii > MAX_NESTED_PRESET; ii--)
3185 gtk_tree_path_up(path);
3186 dst_indices = gtk_tree_path_get_indices(path);
3187 dst_len = gtk_tree_path_get_depth(path);
3188 dst_folder = ghb_presets_get_folder(presetsPlist, dst_indices, dst_len);
3189 // Only allow *drop into* for folders
3192 if (drop_pos == GTK_TREE_VIEW_DROP_INTO_OR_BEFORE)
3193 drop_pos = GTK_TREE_VIEW_DROP_BEFORE;
3194 if (drop_pos == GTK_TREE_VIEW_DROP_INTO_OR_AFTER)
3195 drop_pos = GTK_TREE_VIEW_DROP_AFTER;
3197 if (gtk_tree_model_get_iter (dstmodel, &dstiter, path))
3200 GtkTreePath *dstpath = NULL;
3204 case GTK_TREE_VIEW_DROP_BEFORE:
3205 gtk_tree_store_insert_before(GTK_TREE_STORE (dstmodel),
3206 &iter, NULL, &dstiter);
3209 case GTK_TREE_VIEW_DROP_INTO_OR_BEFORE:
3210 gtk_tree_store_insert(GTK_TREE_STORE (dstmodel),
3211 &iter, &dstiter, 0);
3214 case GTK_TREE_VIEW_DROP_AFTER:
3215 gtk_tree_store_insert_after(GTK_TREE_STORE (dstmodel),
3216 &iter, NULL, &dstiter);
3219 case GTK_TREE_VIEW_DROP_INTO_OR_AFTER:
3220 gtk_tree_store_insert_after(GTK_TREE_STORE (dstmodel),
3221 &iter, &dstiter, 0);
3228 dstpath = gtk_tree_model_get_path (dstmodel, &iter);
3229 dst_indices = gtk_tree_path_get_indices(dstpath);
3230 dst_len = gtk_tree_path_get_depth(dstpath);
3231 ghb_presets_insert(presetsPlist, preset, dst_indices, dst_len);
3232 gtk_tree_path_free(dstpath);
3234 srcpath = gtk_tree_model_get_path (srcmodel, &srciter);
3235 src_indices = gtk_tree_path_get_indices(srcpath);
3236 src_len = gtk_tree_path_get_depth(srcpath);
3237 ghb_presets_remove(presetsPlist, src_indices, src_len);
3238 gtk_tree_path_free(srcpath);
3240 gtk_tree_store_remove (GTK_TREE_STORE (srcmodel), &srciter);
3242 dstpath = gtk_tree_model_get_path (dstmodel, &iter);
3243 dst_indices = gtk_tree_path_get_indices(dstpath);
3244 dst_len = gtk_tree_path_get_depth(dstpath);
3245 presets_list_update_item(ud, dst_indices, dst_len);
3246 gtk_tree_path_free(dstpath);
3250 gtk_tree_path_free(path);
3255 presets_row_expanded_cb(
3256 GtkTreeView *treeview,
3259 signal_user_data_t *ud)
3262 gboolean expanded, folder;
3265 expanded = gtk_tree_view_row_expanded(treeview, path);
3266 indices = gtk_tree_path_get_indices(path);
3267 len = gtk_tree_path_get_depth(path);
3268 dict = presets_get_dict(presetsPlist, indices, len);
3269 if (preset_folder_is_open(dict))
3278 folder = ghb_presets_get_folder(presetsPlist, indices, len);
3281 presets_set_folder_open(expanded, indices, len);
3284 // Collapsing parent folder collapses all children
3287 GValue *presets = NULL;
3288 gint *more_indices, count, ii;
3290 more_indices = g_malloc((len+1)*sizeof(gint));
3291 memcpy(more_indices, indices, len*sizeof(gint));
3293 presets = presets_get_folder(presetsPlist, indices, len);
3294 count = ghb_array_len(presets);
3295 for (ii = 0; ii < count; ii++)
3297 dict = ghb_array_get_nth(presets, ii);
3298 folder = ghb_preset_folder(dict);
3301 more_indices[len] = ii;
3302 presets_set_folder_open(expanded, more_indices, len+1);
3305 g_free(more_indices);
3311 preset_update_title_deps(signal_user_data_t *ud, ghb_title_info_t *tinfo)
3315 ghb_ui_update(ud, "scale_width",
3316 ghb_int64_value(tinfo->width - tinfo->crop[2] - tinfo->crop[3]));
3317 // If anamorphic or keep_aspect, the hight will be automatically calculated
3318 gboolean keep_aspect;
3320 keep_aspect = ghb_settings_get_boolean(ud->settings, "PictureKeepRatio");
3321 pic_par = ghb_settings_combo_int(ud->settings, "PicturePAR");
3322 if (!(keep_aspect || pic_par) || pic_par == 3)
3324 ghb_ui_update(ud, "scale_height",
3325 ghb_int64_value(tinfo->height - tinfo->crop[0] - tinfo->crop[1]));
3328 // Set the limits of cropping. hb_set_anamorphic_size crashes if
3329 // you pass it a cropped width or height == 0.
3331 bound = tinfo->height / 2 - 2;
3332 widget = GHB_WIDGET (ud->builder, "PictureTopCrop");
3333 gtk_spin_button_set_range (GTK_SPIN_BUTTON(widget), 0, bound);
3334 widget = GHB_WIDGET (ud->builder, "PictureBottomCrop");
3335 gtk_spin_button_set_range (GTK_SPIN_BUTTON(widget), 0, bound);
3336 bound = tinfo->width / 2 - 2;
3337 widget = GHB_WIDGET (ud->builder, "PictureLeftCrop");
3338 gtk_spin_button_set_range (GTK_SPIN_BUTTON(widget), 0, bound);
3339 widget = GHB_WIDGET (ud->builder, "PictureRightCrop");
3340 gtk_spin_button_set_range (GTK_SPIN_BUTTON(widget), 0, bound);
3341 if (ghb_settings_get_boolean(ud->settings, "PictureAutoCrop"))
3343 ghb_ui_update(ud, "PictureTopCrop", ghb_int64_value(tinfo->crop[0]));
3344 ghb_ui_update(ud, "PictureBottomCrop", ghb_int64_value(tinfo->crop[1]));
3345 ghb_ui_update(ud, "PictureLeftCrop", ghb_int64_value(tinfo->crop[2]));
3346 ghb_ui_update(ud, "PictureRightCrop", ghb_int64_value(tinfo->crop[3]));
3351 presets_list_selection_changed_cb(GtkTreeSelection *selection, signal_user_data_t *ud)
3353 GtkTreeModel *store;
3355 ghb_title_info_t tinfo;
3358 g_debug("presets_list_selection_changed_cb ()");
3359 widget = GHB_WIDGET (ud->builder, "presets_remove");
3360 if (gtk_tree_selection_get_selected(selection, &store, &iter))
3362 GtkTreePath *treepath;
3367 treepath = gtk_tree_model_get_path(store, &iter);
3368 indices = gtk_tree_path_get_indices(treepath);
3369 len = gtk_tree_path_get_depth(treepath);
3371 path = preset_path_from_indices(presetsPlist, indices, len);
3372 ghb_settings_take_value(ud->settings, "preset_selection", path);
3374 folder = ghb_presets_get_folder(presetsPlist, indices, len);
3377 ud->dont_clear_presets = TRUE;
3378 // Temporarily set the video_quality range to (0,100)
3379 // This is needed so the video_quality value does not get
3380 // truncated when set. The range will be readjusted below
3381 GtkWidget *qp = GHB_WIDGET(ud->builder, "VideoQualitySlider");
3382 gtk_range_set_range (GTK_RANGE(qp), 0, 100);
3383 gtk_scale_set_digits(GTK_SCALE(qp), 3);
3384 // Clear the audio list prior to changing the preset. Existing
3385 // audio can cause the container extension to be automatically
3386 // changed when it shouldn't be
3387 ghb_clear_audio_list(ud);
3388 ghb_set_preset_from_indices(ud, indices, len);
3389 gtk_tree_path_free(treepath);
3391 titleindex = ghb_settings_combo_int(ud->settings, "title");
3392 ghb_set_pref_audio(titleindex, ud);
3393 ghb_settings_set_boolean(ud->settings, "preset_modified", FALSE);
3394 if (ghb_get_title_info (&tinfo, titleindex))
3396 preset_update_title_deps(ud, &tinfo);
3398 ghb_set_scale (ud, GHB_PIC_KEEP_PAR);
3399 ud->dont_clear_presets = FALSE;
3401 gdouble vqmin, vqmax, step, page;
3405 ghb_vquality_range(ud, &vqmin, &vqmax, &step,
3406 &page, &digits, &inverted);
3407 gtk_range_set_range (GTK_RANGE(qp), vqmin, vqmax);
3408 gtk_range_set_increments (GTK_RANGE(qp), step, page);
3409 gtk_scale_set_digits(GTK_SCALE(qp), digits);
3410 gtk_range_set_inverted (GTK_RANGE(qp), inverted);
3414 GtkWidget *crop_widget;
3415 crop[0] = ghb_settings_get_int(ud->settings, "PictureTopCrop");
3416 crop[1] = ghb_settings_get_int(ud->settings, "PictureBottomCrop");
3417 crop[2] = ghb_settings_get_int(ud->settings, "PictureLeftCrop");
3418 crop[3] = ghb_settings_get_int(ud->settings, "PictureRightCrop");
3419 crop_widget = GHB_WIDGET (ud->builder, "crop_values");
3420 text = g_strdup_printf("%d:%d:%d:%d",
3421 crop[0], crop[1], crop[2], crop[3]);
3422 gtk_label_set_text (GTK_LABEL(crop_widget), text);
3425 gtk_widget_set_sensitive(widget, TRUE);
3429 g_debug("No selection??? Perhaps unselected.");
3430 gtk_widget_set_sensitive(widget, FALSE);
3435 ghb_clear_presets_selection(signal_user_data_t *ud)
3437 GtkTreeView *treeview;
3438 GtkTreeSelection *selection;
3440 if (ud->dont_clear_presets) return;
3441 g_debug("ghb_clear_presets_selection()");
3442 treeview = GTK_TREE_VIEW(GHB_WIDGET(ud->builder, "presets_list"));
3443 selection = gtk_tree_view_get_selection (treeview);
3444 gtk_tree_selection_unselect_all (selection);
3445 ghb_settings_set_boolean(ud->settings, "preset_modified", TRUE);
3449 presets_frame_size_allocate_cb(GtkWidget *widget, GtkAllocation *allocation, signal_user_data_t *ud)
3451 GtkTreeView *treeview;
3452 GtkTreeSelection *selection;
3453 GtkTreeModel *store;
3456 treeview = GTK_TREE_VIEW(GHB_WIDGET(ud->builder, "presets_list"));
3457 selection = gtk_tree_view_get_selection(treeview);
3458 if (gtk_tree_selection_get_selected(selection, &store, &iter))
3461 path = gtk_tree_model_get_path (store, &iter);
3462 // Make the parent visible in scroll window if it is not.
3463 gtk_tree_view_scroll_to_cell (treeview, path, NULL, FALSE, 0, 0);
3464 gtk_tree_path_free(path);
3469 presets_default_clicked_cb(GtkWidget *xwidget, signal_user_data_t *ud)
3474 g_debug("presets_default_clicked_cb ()");
3475 preset = ghb_settings_get_value(ud->settings, "preset_selection");
3476 indices = ghb_preset_indices_from_path(presetsPlist, preset, &len);
3479 if (!ghb_presets_get_folder(presetsPlist, indices, len))
3481 ghb_presets_list_clear_default(ud);
3482 presets_set_default(indices, len);
3483 ghb_presets_list_default(ud);