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, G_DIR_SEPARATOR_S, -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);
1333 FindFirstCDROM(void)
1338 strcpy(drive, "A:" G_DIR_SEPARATOR_S);
1339 drives = GetLogicalDrives();
1340 for (ii = 0; ii < 26; ii++)
1346 drive[0] = 'A' + ii;
1347 dtype = GetDriveType(drive);
1348 if (dtype == DRIVE_CDROM)
1350 return g_strdup(drive);
1360 ghb_prefs_load(signal_user_data_t *ud)
1362 GValue *dict, *internal;
1363 GHashTableIter iter;
1365 GValue *gval, *path;
1367 g_debug("ghb_prefs_load");
1368 prefsPlist = load_plist("preferences");
1369 if (prefsPlist == NULL)
1370 prefsPlist = ghb_dict_value_new();
1371 dict = plist_get_dict(prefsPlist, "Preferences");
1372 internal = plist_get_dict(internalPlist, "Preferences");
1373 if (dict == NULL && internal)
1375 dict = ghb_dict_value_new();
1376 ghb_dict_insert(prefsPlist, g_strdup("Preferences"), dict);
1378 // Get defaults from internal defaults
1379 ghb_dict_iter_init(&iter, internal);
1380 // middle (void*) cast prevents gcc warning "defreferencing type-punned
1381 // pointer will break strict-aliasing rules"
1382 while (g_hash_table_iter_next(
1383 &iter, (gpointer*)(void*)&key, (gpointer*)(void*)&gval))
1385 ghb_dict_insert(dict, g_strdup(key), ghb_value_dup(gval));
1387 const gchar *dir = g_get_user_special_dir (G_USER_DIRECTORY_VIDEOS);
1392 ghb_dict_insert(dict,
1393 g_strdup("destination_dir"), ghb_value_dup(ghb_string_value(dir)));
1397 source = FindFirstCDROM();
1400 source = g_strdup("C:" G_DIR_SEPARATOR_S);
1402 ghb_dict_insert(dict, g_strdup("default_source"),
1403 ghb_value_dup(ghb_string_value(source)));
1408 // Read legacy default_preset preference and update accordingly
1409 path = ghb_dict_lookup(dict, "default_preset");
1414 if (G_VALUE_TYPE(path) == G_TYPE_STRING)
1418 path = ghb_array_value_new(1);
1419 ghb_array_append(path, ghb_value_dup(str));
1420 indices = ghb_preset_indices_from_path(presetsPlist, path, &len);
1421 ghb_value_free(path);
1424 indices = ghb_preset_indices_from_path(presetsPlist, path, &len);
1428 presets_set_default(indices, len);
1431 ghb_dict_remove(dict, "default_preset");
1437 get_preset_color(gint type, gboolean folder)
1441 if (type == PRESETS_CUSTOM)
1461 ghb_presets_list_init(
1462 signal_user_data_t *ud,
1466 GtkTreeView *treeview;
1467 GtkTreeIter iter, titer, *piter;
1469 GtkTreeStore *store;
1470 const gchar *preset;
1471 GtkTreePath *parent_path;
1472 const gchar *description;
1477 GValue *presets = NULL;
1479 g_debug("ghb_presets_list_init ()");
1480 more_indices = g_malloc((len+1)*sizeof(gint));
1481 memcpy(more_indices, indices, len*sizeof(gint));
1482 presets = presets_get_folder(presetsPlist, indices, len);
1483 if (presets == NULL)
1485 g_warning("Failed to find parent folder when adding child.");
1488 count = ghb_array_len(presets);
1489 treeview = GTK_TREE_VIEW(GHB_WIDGET(ud->builder, "presets_list"));
1490 store = GTK_TREE_STORE(gtk_tree_view_get_model(treeview));
1491 parent_path = ghb_tree_path_new_from_indices(indices, len);
1494 gtk_tree_model_get_iter(GTK_TREE_MODEL(store), &titer, parent_path);
1496 gtk_tree_path_free(parent_path);
1502 for (ii = 0; ii < count; ii++)
1508 // Additional settings, add row
1509 dict = ghb_array_get_nth(presets, ii);
1510 preset = preset_get_name(dict);
1511 more_indices[len] = ii;
1512 def = preset_is_default(dict);
1514 description = ghb_presets_get_description(dict);
1515 gtk_tree_store_append(store, &iter, piter);
1516 type = ghb_preset_type(dict);
1517 folder = ghb_preset_folder(dict);
1518 color = get_preset_color(type, folder);
1519 gtk_tree_store_set(store, &iter, 0, preset,
1530 if (gtk_tree_model_iter_parent(
1531 GTK_TREE_MODEL(store), &ppiter, piter))
1533 path = gtk_tree_model_get_path(GTK_TREE_MODEL(store), &ppiter);
1534 gtk_tree_view_expand_row(treeview, path, FALSE);
1535 gtk_tree_path_free(path);
1537 path = gtk_tree_model_get_path(GTK_TREE_MODEL(store), piter);
1538 gtk_tree_view_expand_row(treeview, path, FALSE);
1539 gtk_tree_path_free(path);
1543 ghb_presets_list_init(ud, more_indices, len+1);
1544 if (preset_folder_is_open(dict))
1550 path = gtk_tree_model_get_path(GTK_TREE_MODEL(store), piter);
1551 gtk_tree_view_expand_row(treeview, path, FALSE);
1552 gtk_tree_path_free(path);
1554 path = gtk_tree_model_get_path(GTK_TREE_MODEL(store), &iter);
1555 gtk_tree_view_expand_row(treeview, path, FALSE);
1556 gtk_tree_path_free(path);
1560 g_free(more_indices);
1564 presets_list_update_item(
1565 signal_user_data_t *ud,
1569 GtkTreeView *treeview;
1570 GtkTreeStore *store;
1572 GtkTreePath *treepath;
1574 const gchar *description;
1576 gboolean def, folder;
1580 g_debug("presets_list_update_item ()");
1581 dict = presets_get_dict(presetsPlist, indices, len);
1584 treeview = GTK_TREE_VIEW(GHB_WIDGET(ud->builder, "presets_list"));
1585 store = GTK_TREE_STORE(gtk_tree_view_get_model(treeview));
1586 treepath = ghb_tree_path_new_from_indices(indices, len);
1587 gtk_tree_model_get_iter(GTK_TREE_MODEL(store), &iter, treepath);
1588 // Additional settings, add row
1589 name = preset_get_name(dict);
1590 def = preset_is_default(dict);
1592 description = ghb_presets_get_description(dict);
1593 type = ghb_preset_type(dict);
1594 folder = ghb_preset_folder(dict);
1595 color = get_preset_color(type, folder);
1596 gtk_tree_store_set(store, &iter, 0, name,
1604 ghb_presets_list_init(ud, indices, len);
1609 presets_list_insert(
1610 signal_user_data_t *ud,
1614 GtkTreeView *treeview;
1615 GtkTreeIter iter, titer, *piter;
1616 GtkTreeStore *store;
1617 const gchar *preset;
1618 const gchar *description;
1620 gboolean def, folder;
1623 GtkTreePath *parent_path;
1627 g_debug("presets_list_insert ()");
1628 treeview = GTK_TREE_VIEW(GHB_WIDGET(ud->builder, "presets_list"));
1629 store = GTK_TREE_STORE(gtk_tree_view_get_model(treeview));
1630 presets = presets_get_folder(presetsPlist, indices, len-1);
1631 if (presets == NULL)
1633 g_warning("Failed to find parent folder while adding child.");
1636 parent_path = ghb_tree_path_new_from_indices(indices, len-1);
1639 gtk_tree_model_get_iter(GTK_TREE_MODEL(store), &titer, parent_path);
1641 gtk_tree_path_free(parent_path);
1647 count = ghb_array_len(presets);
1648 if (indices[len-1] >= count)
1650 // Additional settings, add row
1651 dict = ghb_array_get_nth(presets, indices[len-1]);
1652 preset = preset_get_name(dict);
1653 def = preset_is_default(dict);
1655 description = ghb_presets_get_description(dict);
1656 gtk_tree_store_insert(store, &iter, piter, indices[len-1]);
1657 type = ghb_preset_type(dict);
1658 folder = ghb_preset_folder(dict);
1659 color = get_preset_color(type, folder);
1660 gtk_tree_store_set(store, &iter, 0, preset,
1668 ghb_presets_list_init(ud, indices, len);
1673 presets_list_remove(
1674 signal_user_data_t *ud,
1678 GtkTreeView *treeview;
1679 GtkTreePath *treepath;
1681 GtkTreeStore *store;
1683 g_debug("presets_list_remove ()");
1684 treeview = GTK_TREE_VIEW(GHB_WIDGET(ud->builder, "presets_list"));
1685 store = GTK_TREE_STORE(gtk_tree_view_get_model(treeview));
1686 treepath = ghb_tree_path_new_from_indices(indices, len);
1689 if (gtk_tree_model_get_iter(GTK_TREE_MODEL(store), &iter, treepath))
1690 gtk_tree_store_remove(store, &iter);
1691 gtk_tree_path_free(treepath);
1696 remove_std_presets(signal_user_data_t *ud)
1701 count = ghb_array_len(presetsPlist);
1702 for (ii = count-1; ii >= 0; ii--)
1707 dict = ghb_array_get_nth(presetsPlist, ii);
1708 ptype = ghb_value_int(preset_dict_get_value(dict, "Type"));
1709 if (ptype == PRESETS_BUILTIN)
1711 if (ghb_presets_remove(presetsPlist, &indices, 1))
1713 presets_list_remove(ud, &indices, 1);
1720 ghb_save_queue(GValue *queue)
1722 store_plist(queue, "queue");
1728 return load_plist("queue");
1732 ghb_remove_queue_file()
1734 remove_plist("queue");
1743 static value_map_t vcodec_xlat[] =
1745 {"MPEG-4 (FFmpeg)", "ffmpeg"},
1746 {"MPEG-4 (XviD)", "ffmpeg"},
1747 {"H.264 (x264)", "x264"},
1748 {"VP3 (Theora)", "theora"},
1752 static value_map_t acodec_xlat[] =
1754 {"AAC (faac)", "faac"},
1755 {"AC3 Passthru", "ac3"},
1756 {"MP3 (lame)", "lame"},
1757 {"Vorbis (vorbis)", "vorbis"},
1761 value_map_t container_xlat[] =
1763 {"MP4 file", "mp4"},
1764 {"M4V file", "m4v"},
1765 {"MKV file", "mkv"},
1766 {"AVI file", "mkv"},
1767 {"OGM file", "mkv"},
1771 value_map_t framerate_xlat[] =
1773 {"Same as source", "source"},
1778 {"23.976", "23.976"},
1785 value_map_t samplerate_xlat[] =
1796 value_map_t mix_xlat[] =
1799 {"Stereo", "stereo"},
1800 {"Dolby Surround", "dpl1"},
1801 {"Dolby Pro Logic II", "dpl2"},
1802 {"6-channel discrete", "6ch"},
1803 {"AC3 Passthru", "none"},
1807 value_map_t deint_xlat[] =
1817 value_map_t denoise_xlat[] =
1827 value_map_t detel_xlat[] =
1835 value_map_t decomb_xlat[] =
1843 extern iso639_lang_t ghb_language_table[];
1846 export_lang_xlat2(GValue *lin_val)
1850 if (lin_val == NULL) return NULL;
1854 str = ghb_value_string(lin_val);
1855 for (ii = 0; ghb_language_table[ii].eng_name; ii++)
1857 if (strcmp(str, ghb_language_table[ii].iso639_2) == 0)
1859 gval = ghb_string_value_new(ghb_language_table[ii].eng_name);
1864 g_debug("Can't map language value: (%s)", str);
1870 export_subtitle_xlat2(GValue *lin_val)
1875 if (lin_val == NULL) return NULL;
1876 str = ghb_value_string(lin_val);
1877 if (strcmp(str, "none") == 0)
1879 gval = ghb_string_value_new("None");
1881 else if (strcmp(str, "auto") == 0)
1883 gval = ghb_string_value_new("Autoselect");
1887 gval = export_lang_xlat2(lin_val);
1894 import_lang_xlat2(GValue *mac_val)
1898 if (mac_val == NULL) return NULL;
1902 str = ghb_value_string(mac_val);
1903 for (ii = 0; ghb_language_table[ii].eng_name; ii++)
1905 if (strcmp(str, ghb_language_table[ii].eng_name) == 0)
1907 gval = ghb_string_value_new(ghb_language_table[ii].iso639_2);
1912 g_debug("Can't map language value: (%s)", str);
1918 import_subtitle_xlat2(GValue *mac_val)
1923 if (mac_val == NULL) return NULL;
1924 str = ghb_value_string(mac_val);
1925 if (strcmp(str, "None") == 0)
1927 gval = ghb_string_value_new("none");
1929 else if (strcmp(str, "Autoselect") == 0)
1931 gval = ghb_string_value_new("auto");
1935 gval = import_lang_xlat2(mac_val);
1942 export_audio_track_xlat2(GValue *lin_val)
1945 GValue *gval = NULL;
1947 if (lin_val == NULL) return NULL;
1948 str = ghb_value_string(lin_val);
1949 if (strcmp(str, "none") == 0)
1951 gval = ghb_int_value_new(1);
1955 gint val = ghb_value_int(lin_val) + 1;
1956 gval = ghb_int_value_new(val);
1963 import_audio_track_xlat2(GValue *mac_val)
1969 if (mac_val == NULL) return NULL;
1970 val = ghb_value_int(mac_val);
1979 str = g_strdup_printf("%d", val);
1980 gval = ghb_string_value_new(str);
1986 export_value_xlat2(value_map_t *value_map, GValue *lin_val, GType mac_type)
1990 if (lin_val == NULL) return NULL;
1995 str = ghb_value_string(lin_val);
1996 for (ii = 0; value_map[ii].mac_val; ii++)
1998 if (strcmp(str, value_map[ii].lin_val) == 0)
2000 sval = ghb_string_value_new(value_map[ii].mac_val);
2002 gval = ghb_value_new(mac_type);
2003 if (!g_value_transform(sval, gval))
2005 g_warning("can't transform");
2006 ghb_value_free(gval);
2007 ghb_value_free(sval);
2010 ghb_value_free(sval);
2014 g_debug("Can't map value: (%s)", str);
2020 export_value_xlat(GValue *dict)
2022 GValue *lin_val, *gval;
2025 key = "VideoEncoder";
2026 lin_val = ghb_dict_lookup(dict, key);
2027 gval = export_value_xlat2(vcodec_xlat, lin_val, G_TYPE_STRING);
2029 ghb_dict_insert(dict, g_strdup(key), gval);
2031 lin_val = ghb_dict_lookup(dict, key);
2032 gval = export_value_xlat2(container_xlat, lin_val, G_TYPE_STRING);
2034 ghb_dict_insert(dict, g_strdup(key), gval);
2035 key = "VideoFramerate";
2036 lin_val = ghb_dict_lookup(dict, key);
2037 gval = export_value_xlat2(framerate_xlat, lin_val, G_TYPE_STRING);
2039 ghb_dict_insert(dict, g_strdup(key), gval);
2040 key = "PictureDetelecine";
2041 lin_val = ghb_dict_lookup(dict, key);
2042 gval = export_value_xlat2(detel_xlat, lin_val, G_TYPE_INT);
2044 ghb_dict_insert(dict, g_strdup(key), gval);
2045 key = "PictureDecomb";
2046 lin_val = ghb_dict_lookup(dict, key);
2047 gval = export_value_xlat2(decomb_xlat, lin_val, G_TYPE_INT);
2049 ghb_dict_insert(dict, g_strdup(key), gval);
2050 key = "PictureDeinterlace";
2051 lin_val = ghb_dict_lookup(dict, key);
2052 gval = export_value_xlat2(deint_xlat, lin_val, G_TYPE_INT);
2054 ghb_dict_insert(dict, g_strdup(key), gval);
2055 key = "PictureDenoise";
2056 lin_val = ghb_dict_lookup(dict, key);
2057 gval = export_value_xlat2(denoise_xlat, lin_val, G_TYPE_INT);
2059 ghb_dict_insert(dict, g_strdup(key), gval);
2061 lin_val = ghb_dict_lookup(dict, key);
2062 gval = export_subtitle_xlat2(lin_val);
2064 ghb_dict_insert(dict, g_strdup(key), gval);
2070 alist = ghb_dict_lookup(dict, "AudioList");
2071 count = ghb_array_len(alist);
2072 for (ii = 0; ii < count; ii++)
2074 adict = ghb_array_get_nth(alist, ii);
2076 lin_val = ghb_dict_lookup(adict, key);
2077 gval = export_audio_track_xlat2(lin_val);
2079 ghb_dict_insert(adict, g_strdup(key), gval);
2080 key = "AudioEncoder";
2081 lin_val = ghb_dict_lookup(adict, key);
2082 gval = export_value_xlat2(acodec_xlat, lin_val, G_TYPE_STRING);
2084 ghb_dict_insert(adict, g_strdup(key), gval);
2085 key = "AudioSamplerate";
2086 lin_val = ghb_dict_lookup(adict, key);
2087 gval = export_value_xlat2(samplerate_xlat, lin_val, G_TYPE_STRING);
2089 ghb_dict_insert(adict, g_strdup(key), gval);
2090 key = "AudioMixdown";
2091 lin_val = ghb_dict_lookup(adict, key);
2092 gval = export_value_xlat2(mix_xlat, lin_val, G_TYPE_STRING);
2094 ghb_dict_insert(adict, g_strdup(key), gval);
2102 value_map_t *value_map,
2106 GValue *gval, *def_val;
2108 if (mac_val == NULL) return NULL;
2109 def_val = ghb_dict_lookup(defaults, key);
2116 str = ghb_value_string(mac_val);
2117 for (ii = 0; value_map[ii].mac_val; ii++)
2119 if (strcmp(str, value_map[ii].mac_val) == 0)
2121 sval = ghb_string_value_new(value_map[ii].lin_val);
2123 gval = ghb_value_new(G_VALUE_TYPE(def_val));
2124 if (!g_value_transform(sval, gval))
2126 g_warning("can't transform");
2127 ghb_value_free(gval);
2128 ghb_value_free(sval);
2131 ghb_value_free(sval);
2135 //g_warning("Can't map value: (%s)", str);
2140 g_warning("Bad key: (%s)", key);
2147 import_value_xlat(GValue *dict)
2149 GValue *defaults, *mac_val, *gval;
2152 defaults = plist_get_dict(internalPlist, "Presets");
2153 key = "VideoEncoder";
2154 mac_val = ghb_dict_lookup(dict, key);
2155 gval = import_value_xlat2(defaults, vcodec_xlat, key, mac_val);
2157 ghb_dict_insert(dict, g_strdup(key), gval);
2159 mac_val = ghb_dict_lookup(dict, key);
2160 gval = import_value_xlat2(defaults, container_xlat, key, mac_val);
2162 ghb_dict_insert(dict, g_strdup(key), gval);
2163 key = "VideoFramerate";
2164 mac_val = ghb_dict_lookup(dict, key);
2165 gval = import_value_xlat2(defaults, framerate_xlat, key, mac_val);
2167 ghb_dict_insert(dict, g_strdup(key), gval);
2168 key = "PictureDetelecine";
2169 mac_val = ghb_dict_lookup(dict, key);
2170 gval = import_value_xlat2(defaults, detel_xlat, key, mac_val);
2172 ghb_dict_insert(dict, g_strdup(key), gval);
2173 key = "PictureDecomb";
2174 mac_val = ghb_dict_lookup(dict, key);
2175 gval = import_value_xlat2(defaults, decomb_xlat, key, mac_val);
2177 ghb_dict_insert(dict, g_strdup(key), gval);
2178 key = "PictureDeinterlace";
2179 mac_val = ghb_dict_lookup(dict, key);
2180 gval = import_value_xlat2(defaults, deint_xlat, key, mac_val);
2182 ghb_dict_insert(dict, g_strdup(key), gval);
2183 key = "PictureDenoise";
2184 mac_val = ghb_dict_lookup(dict, key);
2185 gval = import_value_xlat2(defaults, denoise_xlat, key, mac_val);
2187 ghb_dict_insert(dict, g_strdup(key), gval);
2189 mac_val = ghb_dict_lookup(dict, key);
2190 gval = import_subtitle_xlat2(mac_val);
2192 ghb_dict_insert(dict, g_strdup(key), gval);
2200 adeflist = ghb_dict_lookup(dict, "AudioList");
2203 adefaults = ghb_array_get_nth(adeflist, 0);
2204 alist = ghb_dict_lookup(dict, "AudioList");
2205 count = ghb_array_len(alist);
2206 for (ii = 0; ii < count; ii++)
2208 adict = ghb_array_get_nth(alist, ii);
2210 mac_val = ghb_dict_lookup(adict, key);
2211 gval = import_audio_track_xlat2(mac_val);
2213 ghb_dict_insert(adict, g_strdup(key), gval);
2214 key = "AudioEncoder";
2215 mac_val = ghb_dict_lookup(adict, key);
2216 gval = import_value_xlat2(adefaults, acodec_xlat, key, mac_val);
2218 ghb_dict_insert(adict, g_strdup(key), gval);
2219 key = "AudioSamplerate";
2220 mac_val = ghb_dict_lookup(adict, key);
2221 gval = import_value_xlat2(adefaults, samplerate_xlat, key, mac_val);
2223 ghb_dict_insert(adict, g_strdup(key), gval);
2224 key = "AudioMixdown";
2225 mac_val = ghb_dict_lookup(adict, key);
2226 gval = import_value_xlat2(adefaults, mix_xlat, key, mac_val);
2228 ghb_dict_insert(adict, g_strdup(key), gval);
2234 import_xlat_preset(GValue *dict)
2238 gint par, par_width, par_height;
2241 g_debug("import_xlat_preset ()");
2242 uses_max = ghb_value_boolean(
2243 preset_dict_get_value(dict, "UsesMaxPictureSettings"));
2244 uses_pic = ghb_value_int(
2245 preset_dict_get_value(dict, "UsesPictureSettings"));
2246 par = ghb_value_int(preset_dict_get_value(dict, "PicturePAR"));
2247 vqtype = ghb_value_int(preset_dict_get_value(dict, "VideoQualityType"));
2248 par_width = ghb_value_int(preset_dict_get_value(dict, "PicturePARWidth"));
2249 par_height = ghb_value_int(preset_dict_get_value(dict, "PicturePARHeight"));
2250 ghb_dict_insert(dict, g_strdup("par_width"),
2251 ghb_int_value_new(par_width));
2252 ghb_dict_insert(dict, g_strdup("par_height"),
2253 ghb_int_value_new(par_height));
2255 if (uses_max || uses_pic == 2)
2257 ghb_dict_insert(dict, g_strdup("autoscale"),
2258 ghb_boolean_value_new(TRUE));
2264 if (ghb_dict_lookup(dict, "PictureAlignment") == NULL)
2265 ghb_dict_insert(dict, g_strdup("PictureAlignment"),
2266 ghb_int_value_new(16));
2270 ghb_dict_insert(dict, g_strdup("PictureAlignment"),
2271 ghb_int_value_new(1));
2275 if (ghb_dict_lookup(dict, "PictureAlignment") == NULL)
2276 ghb_dict_insert(dict, g_strdup("PictureAlignment"),
2277 ghb_int_value_new(16));
2281 if (ghb_dict_lookup(dict, "PictureAlignment") == NULL)
2282 ghb_dict_insert(dict, g_strdup("PictureAlignment"),
2283 ghb_int_value_new(16));
2286 // VideoQualityType/0/1/2 - vquality_type_/target/bitrate/constant
2291 ghb_dict_insert(dict, g_strdup("vquality_type_target"),
2292 ghb_boolean_value_new(TRUE));
2293 ghb_dict_insert(dict, g_strdup("vquality_type_bitrate"),
2294 ghb_boolean_value_new(FALSE));
2295 ghb_dict_insert(dict, g_strdup("vquality_type_constant"),
2296 ghb_boolean_value_new(FALSE));
2300 ghb_dict_insert(dict, g_strdup("vquality_type_target"),
2301 ghb_boolean_value_new(FALSE));
2302 ghb_dict_insert(dict, g_strdup("vquality_type_bitrate"),
2303 ghb_boolean_value_new(TRUE));
2304 ghb_dict_insert(dict, g_strdup("vquality_type_constant"),
2305 ghb_boolean_value_new(FALSE));
2309 ghb_dict_insert(dict, g_strdup("vquality_type_target"),
2310 ghb_boolean_value_new(FALSE));
2311 ghb_dict_insert(dict, g_strdup("vquality_type_bitrate"),
2312 ghb_boolean_value_new(FALSE));
2313 ghb_dict_insert(dict, g_strdup("vquality_type_constant"),
2314 ghb_boolean_value_new(TRUE));
2318 ghb_dict_insert(dict, g_strdup("vquality_type_target"),
2319 ghb_boolean_value_new(FALSE));
2320 ghb_dict_insert(dict, g_strdup("vquality_type_bitrate"),
2321 ghb_boolean_value_new(FALSE));
2322 ghb_dict_insert(dict, g_strdup("vquality_type_constant"),
2323 ghb_boolean_value_new(TRUE));
2326 import_value_xlat(dict);
2331 vquality = ghb_value_double(preset_dict_get_value(dict, "VideoQualitySlider"));
2336 gval = preset_dict_get_value(dict, "VideoEncoder");
2337 vcodec = ghb_lookup_combo_int("VideoEncoder", gval);
2340 case HB_VCODEC_X264:
2342 vquality = 51. - vquality * 51.;
2345 case HB_VCODEC_XVID:
2346 case HB_VCODEC_FFMPEG:
2348 vquality = 31. - vquality * 30.;
2351 case HB_VCODEC_THEORA:
2353 vquality = vquality * 63.;
2361 ghb_dict_insert(dict, g_strdup("VideoQualitySlider"),
2362 ghb_double_value_new(vquality));
2367 import_xlat_presets(GValue *presets)
2373 g_debug("import_xlat_presets ()");
2374 if (presets == NULL) return;
2375 count = ghb_array_len(presets);
2376 for (ii = 0; ii < count; ii++)
2378 dict = ghb_array_get_nth(presets, ii);
2379 folder = ghb_value_boolean(preset_dict_get_value(dict, "Folder"));
2384 nested = ghb_dict_lookup(dict, "ChildrenArray");
2385 import_xlat_presets(nested);
2389 import_xlat_preset(dict);
2395 export_xlat_preset(GValue *dict)
2397 gboolean autoscale, target, br, constant;
2398 gint par_width, par_height;
2400 g_debug("export_xlat_prest ()");
2401 autoscale = ghb_value_boolean(preset_dict_get_value(dict, "autoscale"));
2402 target = ghb_value_boolean(
2403 preset_dict_get_value(dict, "vquality_type_target"));
2404 br = ghb_value_boolean(
2405 preset_dict_get_value(dict, "vquality_type_bitrate"));
2406 constant = ghb_value_boolean(
2407 preset_dict_get_value(dict, "vquality_type_constant"));
2408 par_width = ghb_value_int(
2409 preset_dict_get_value(dict, "par_width"));
2410 par_height = ghb_value_int(
2411 preset_dict_get_value(dict, "par_height"));
2414 ghb_dict_insert(dict, g_strdup("UsesPictureSettings"),
2415 ghb_int_value_new(2));
2417 ghb_dict_insert(dict, g_strdup("UsesPictureSettings"),
2418 ghb_int_value_new(1));
2420 // VideoQualityType/0/1/2 - vquality_type_/target/bitrate/constant
2423 ghb_dict_insert(dict, g_strdup("VideoQualityType"),
2424 ghb_int_value_new(0));
2428 ghb_dict_insert(dict, g_strdup("VideoQualityType"),
2429 ghb_int_value_new(1));
2433 ghb_dict_insert(dict, g_strdup("VideoQualityType"),
2434 ghb_int_value_new(2));
2436 ghb_dict_insert(dict, g_strdup("PicturePARWidth"),
2437 ghb_int_value_new(par_width));
2438 ghb_dict_insert(dict, g_strdup("PicturePARHeight"),
2439 ghb_int_value_new(par_height));
2440 ghb_dict_remove(dict, "UsesMaxPictureSettings");
2441 ghb_dict_remove(dict, "autoscale");
2442 ghb_dict_remove(dict, "vquality_type_target");
2443 ghb_dict_remove(dict, "vquality_type_bitrate");
2444 ghb_dict_remove(dict, "vquality_type_constant");
2445 ghb_dict_remove(dict, "par_width");
2446 ghb_dict_remove(dict, "par_height");
2447 export_value_xlat(dict);
2451 export_xlat_presets(GValue *presets)
2457 if (presets == NULL) return;
2458 count = ghb_array_len(presets);
2459 for (ii = 0; ii < count; ii++)
2461 dict = ghb_array_get_nth(presets, ii);
2462 folder = ghb_value_boolean(preset_dict_get_value(dict, "Folder"));
2467 nested = ghb_dict_lookup(dict, "ChildrenArray");
2468 export_xlat_presets(nested);
2472 export_xlat_preset(dict);
2477 static guint prefs_timeout_id = 0;
2480 delayed_store_prefs(gpointer data)
2482 store_plist(prefsPlist, "preferences");
2483 prefs_timeout_id = 0;
2492 export = ghb_value_dup(presetsPlist);
2493 export_xlat_presets(export);
2494 store_plist(export, "presets");
2495 ghb_value_free(export);
2501 if (prefs_timeout_id != 0)
2506 mc = g_main_context_default();
2507 source = g_main_context_find_source_by_id(mc, prefs_timeout_id);
2509 g_source_destroy(source);
2511 prefs_timeout_id = g_timeout_add_seconds(1, (GSourceFunc)delayed_store_prefs, NULL);
2515 ghb_presets_reload(signal_user_data_t *ud)
2517 GValue *std_presets;
2521 g_debug("ghb_presets_reload()\n");
2522 std_presets = ghb_resource_get("standard-presets");
2523 if (std_presets == NULL) return;
2525 remove_std_presets(ud);
2526 indices = presets_find_default(presetsPlist, &len);
2529 presets_clear_default(std_presets);
2532 // Merge the keyfile contents into our presets
2533 count = ghb_array_len(std_presets);
2534 for (ii = count-1; ii >= 0; ii--)
2540 std_dict = ghb_array_get_nth(std_presets, ii);
2541 copy_dict = ghb_value_dup(std_dict);
2542 ghb_presets_insert(presetsPlist, copy_dict, &indices, 1);
2543 presets_list_insert(ud, &indices, 1);
2545 import_xlat_presets(presetsPlist);
2554 count = ghb_array_len(presetsPlist);
2555 for (ii = count-1; ii >= 0; ii--)
2560 dict = ghb_array_get_nth(presetsPlist, ii);
2561 type = ghb_dict_lookup(dict, "Type");
2571 presetsPlist = load_plist("presets");
2572 if (presetsPlist == NULL)
2574 presetsPlist = ghb_value_dup(ghb_resource_get("standard-presets"));
2575 import_xlat_presets(presetsPlist);
2578 else if (G_VALUE_TYPE(presetsPlist) == ghb_dict_get_type())
2579 { // Presets is older dictionary format. Convert to array
2580 ghb_value_free(presetsPlist);
2581 presetsPlist = ghb_value_dup(ghb_resource_get("standard-presets"));
2582 import_xlat_presets(presetsPlist);
2585 else if (check_old_presets())
2587 ghb_value_free(presetsPlist);
2588 presetsPlist = ghb_value_dup(ghb_resource_get("standard-presets"));
2589 import_xlat_presets(presetsPlist);
2592 import_xlat_presets(presetsPlist);
2596 settings_save(signal_user_data_t *ud, const GValue *path)
2598 GValue *dict, *internal;
2599 GHashTableIter iter;
2603 gint *indices, len, count;
2604 gint *def_indices, def_len;
2606 gboolean replace = FALSE;
2608 g_debug("settings_save");
2609 if (internalPlist == NULL) return;
2610 count = ghb_array_len(path);
2611 name = g_value_get_string(ghb_array_get_nth(path, count-1));
2612 indices = ghb_preset_indices_from_path(presetsPlist, path, &len);
2615 if (ghb_presets_get_folder(presetsPlist, indices, len))
2618 message = g_strdup_printf(
2619 "%s: Folder already exists.\n"
2620 "You can not replace it with a preset.",
2622 ghb_message_dialog(GTK_MESSAGE_ERROR, message, "Cancel", NULL);
2626 dict = ghb_dict_value_new();
2627 ghb_presets_replace(presetsPlist, dict, indices, len);
2632 indices = presets_find_pos(path, PRESETS_CUSTOM, &len);
2635 dict = ghb_dict_value_new();
2636 ghb_presets_insert(presetsPlist, dict, indices, len);
2640 g_warning("failed to find insert path");
2644 current_preset = dict;
2645 autoscale = ghb_settings_get_boolean(ud->settings, "autoscale");
2646 ghb_settings_set_int64(ud->settings, "Type", PRESETS_CUSTOM);
2648 internal = plist_get_dict(internalPlist, "Presets");
2649 ghb_dict_iter_init(&iter, internal);
2650 // middle (void*) cast prevents gcc warning "defreferencing type-punned
2651 // pointer will break strict-aliasing rules"
2652 while (g_hash_table_iter_next(
2653 &iter, (gpointer*)(void*)&key, (gpointer*)(void*)&value))
2661 if (strcmp(key, "PictureWidth") == 0)
2663 key2 = "scale_width";
2665 else if (strcmp(key, "PictureHeight") == 0)
2667 key2 = "scale_height";
2670 gval = ghb_settings_get_value(ud->settings, key2);
2675 ghb_dict_insert(dict, g_strdup(key), ghb_value_dup(gval));
2677 internal = plist_get_dict(internalPlist, "XlatPresets");
2678 ghb_dict_iter_init(&iter, internal);
2679 // middle (void*) cast prevents gcc warning "defreferencing type-punned
2680 // pointer will break strict-aliasing rules"
2681 while (g_hash_table_iter_next(
2682 &iter, (gpointer*)(void*)&key, (gpointer*)(void*)&value))
2686 gval = ghb_settings_get_value(ud->settings, key);
2691 ghb_dict_insert(dict, g_strdup(key), ghb_value_dup(gval));
2693 ghb_dict_insert(dict, g_strdup("PresetName"), ghb_string_value_new(name));
2696 def_indices = presets_find_default(presetsPlist, &def_len);
2697 if (def_indices != NULL &&
2698 preset_path_cmp(indices, len, def_indices, def_len) != 0)
2700 ghb_dict_insert(dict, g_strdup("Default"),
2701 ghb_boolean_value_new(FALSE));
2703 presets_list_update_item(ud, indices, len);
2707 ghb_dict_insert(dict, g_strdup("Default"),
2708 ghb_boolean_value_new(FALSE));
2709 presets_list_insert(ud, indices, len);
2712 ud->dont_clear_presets = TRUE;
2713 // Make the new preset the selected item
2714 ghb_select_preset2(ud->builder, indices, len);
2716 ud->dont_clear_presets = FALSE;
2721 folder_save(signal_user_data_t *ud, const GValue *path)
2723 GValue *dict, *folder;
2724 gint *indices, len, count;
2727 count = ghb_array_len(path);
2728 name = g_value_get_string(ghb_array_get_nth(path, count-1));
2729 indices = ghb_preset_indices_from_path(presetsPlist, path, &len);
2732 if (!ghb_presets_get_folder(presetsPlist, indices, len))
2735 message = g_strdup_printf(
2736 "%s: Preset already exists.\n"
2737 "You can not replace it with a folder.",
2739 ghb_message_dialog(GTK_MESSAGE_ERROR, message, "Cancel", NULL);
2744 // Already exists, update its description
2745 dict = presets_get_dict(presetsPlist, indices, len);
2746 ghb_dict_insert(dict, g_strdup("PresetDescription"),
2747 ghb_value_dup(preset_dict_get_value(
2748 ud->settings, "PresetDescription")));
2754 indices = presets_find_pos(path, PRESETS_CUSTOM, &len);
2757 dict = ghb_dict_value_new();
2758 ghb_presets_insert(presetsPlist, dict, indices, len);
2762 g_warning("failed to find insert path");
2766 ghb_dict_insert(dict, g_strdup("PresetDescription"),
2767 ghb_value_dup(preset_dict_get_value(
2768 ud->settings, "PresetDescription")));
2769 ghb_dict_insert(dict, g_strdup("PresetName"), ghb_string_value_new(name));
2770 folder = ghb_array_value_new(8);
2771 ghb_dict_insert(dict, g_strdup("ChildrenArray"), folder);
2772 ghb_dict_insert(dict, g_strdup("Type"),
2773 ghb_int64_value_new(PRESETS_CUSTOM));
2774 ghb_dict_insert(dict, g_strdup("Folder"), ghb_boolean_value_new(TRUE));
2776 presets_list_insert(ud, indices, len);
2783 ghb_presets_list_default(signal_user_data_t *ud)
2785 GtkTreeView *treeview;
2786 GtkTreePath *treepath;
2788 GtkTreeStore *store;
2791 g_debug("ghb_presets_list_default ()");
2792 treeview = GTK_TREE_VIEW(GHB_WIDGET(ud->builder, "presets_list"));
2793 store = GTK_TREE_STORE(gtk_tree_view_get_model(treeview));
2794 indices = presets_find_default(presetsPlist, &len);
2795 if (indices == NULL) return;
2796 treepath = ghb_tree_path_new_from_indices(indices, len);
2799 if (gtk_tree_model_get_iter(GTK_TREE_MODEL(store), &iter, treepath))
2801 gtk_tree_store_set(store, &iter,
2806 gtk_tree_path_free(treepath);
2812 ghb_presets_list_clear_default(signal_user_data_t *ud)
2814 GtkTreeView *treeview;
2815 GtkTreePath *treepath;
2817 GtkTreeStore *store;
2820 g_debug("ghb_presets_list_clear_default ()");
2821 treeview = GTK_TREE_VIEW(GHB_WIDGET(ud->builder, "presets_list"));
2822 store = GTK_TREE_STORE(gtk_tree_view_get_model(treeview));
2823 indices = presets_find_default(presetsPlist, &len);
2824 if (indices == NULL) return;
2825 treepath = ghb_tree_path_new_from_indices(indices, len);
2828 if (gtk_tree_model_get_iter(GTK_TREE_MODEL(store), &iter, treepath))
2830 gtk_tree_store_set(store, &iter,
2835 gtk_tree_path_free(treepath);
2841 update_audio_presets(signal_user_data_t *ud)
2843 g_debug("update_audio_presets");
2844 const GValue *audio_list;
2846 audio_list = ghb_settings_get_value(ud->settings, "audio_list");
2847 ghb_settings_set_value(ud->settings, "AudioList", audio_list);
2851 enforce_preset_type(signal_user_data_t *ud, const GValue *path)
2854 GtkWidget *normal, *folder;
2857 normal = GHB_WIDGET(ud->builder, "preset_type_normal");
2858 folder = GHB_WIDGET(ud->builder, "preset_type_folder");
2859 indices = ghb_preset_indices_from_path(presetsPlist, path, &len);
2862 fold = ghb_presets_get_folder(presetsPlist, indices, len);
2864 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(folder),
2867 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(normal),
2869 gtk_widget_set_sensitive(folder, fold);
2870 gtk_widget_set_sensitive(normal, !fold);
2875 gtk_widget_set_sensitive(folder, TRUE);
2876 gtk_widget_set_sensitive(normal, TRUE);
2880 G_MODULE_EXPORT void
2881 presets_save_clicked_cb(GtkWidget *xwidget, signal_user_data_t *ud)
2886 GtkResponseType response;
2888 const gchar *name = "";
2889 gint count, *indices, len;
2891 g_debug("presets_save_clicked_cb ()");
2892 preset = ghb_settings_get_value (ud->settings, "preset_selection");
2894 count = ghb_array_len(preset);
2896 name = g_value_get_string(ghb_array_get_nth(preset, count-1));
2899 // Clear the description
2900 desc = GTK_TEXT_VIEW(GHB_WIDGET(ud->builder, "PresetDescription"));
2901 dialog = GHB_WIDGET(ud->builder, "preset_save_dialog");
2902 entry = GTK_ENTRY(GHB_WIDGET(ud->builder, "PresetName"));
2903 gtk_entry_set_text(entry, name);
2904 enforce_preset_type(ud, preset);
2905 response = gtk_dialog_run(GTK_DIALOG(dialog));
2906 gtk_widget_hide(dialog);
2907 if (response == GTK_RESPONSE_OK)
2910 const gchar *name = gtk_entry_get_text(entry);
2913 if (ghb_settings_get_boolean(ud->settings, "preset_type_folder"))
2915 if (count > MAX_NESTED_PRESET-1)
2917 count = MAX_NESTED_PRESET-1;
2920 dest = ghb_array_value_new(MAX_NESTED_PRESET);
2921 indices = ghb_preset_indices_from_path(presetsPlist, preset, &len);
2926 ptype = ghb_presets_get_type(presetsPlist, indices, len);
2927 if (ptype == PRESETS_CUSTOM)
2929 ghb_array_copy(dest, preset, count-1);
2932 ghb_array_append(dest, ghb_string_value_new(name));
2934 ghb_widget_to_setting(ud->settings, GTK_WIDGET(desc));
2935 if (ghb_settings_get_boolean(ud->settings, "preset_type_folder"))
2937 folder_save(ud, dest);
2941 // Construct the audio settings presets from the current audio list
2942 update_audio_presets(ud);
2943 settings_save(ud, dest);
2945 ghb_value_free(dest);
2949 G_MODULE_EXPORT void
2950 preset_type_changed_cb(GtkWidget *widget, signal_user_data_t *ud)
2952 ghb_widget_to_setting(ud->settings, widget);
2955 G_MODULE_EXPORT void
2956 preset_name_changed_cb(GtkWidget *entry, signal_user_data_t *ud)
2959 GValue *preset, *dest;
2962 preset = ghb_settings_get_value (ud->settings, "preset_selection");
2963 name = ghb_widget_string(entry);
2964 dest = ghb_value_dup(preset);
2965 count = ghb_array_len(dest);
2966 ghb_array_replace(dest, count-1, ghb_string_value_new(name));
2967 enforce_preset_type(ud, dest);
2968 ghb_value_free(dest);
2971 G_MODULE_EXPORT void
2972 presets_restore_clicked_cb(GtkWidget *xwidget, signal_user_data_t *ud)
2976 g_debug("presets_restore_clicked_cb ()");
2977 // Reload only the standard presets
2978 ghb_presets_reload(ud);
2979 // Updating the presets list shuffles things around
2980 // need to make sure the proper preset is selected
2981 preset = ghb_settings_get_value (ud->settings, "preset");
2982 ghb_select_preset(ud->builder, preset);
2985 G_MODULE_EXPORT void
2986 presets_remove_clicked_cb(GtkWidget *xwidget, signal_user_data_t *ud)
2988 GtkTreeView *treeview;
2989 GtkTreeSelection *selection;
2990 GtkTreeModel *store;
2993 GtkResponseType response;
2995 g_debug("presets_remove_clicked_cb ()");
2996 treeview = GTK_TREE_VIEW(GHB_WIDGET(ud->builder, "presets_list"));
2997 selection = gtk_tree_view_get_selection (treeview);
2998 if (gtk_tree_selection_get_selected(selection, &store, &iter))
3005 gtk_tree_model_get(store, &iter, 0, &preset, -1);
3006 path = gtk_tree_model_get_path(store, &iter);
3007 indices = gtk_tree_path_get_indices(path);
3008 len = gtk_tree_path_get_depth(path);
3010 folder = ghb_presets_get_folder(presetsPlist, indices, len);
3011 dialog = gtk_message_dialog_new(NULL, GTK_DIALOG_MODAL,
3012 GTK_MESSAGE_QUESTION, GTK_BUTTONS_YES_NO,
3013 "Confirm deletion of %s:\n\n%s",
3014 folder ? "folder" : "preset",
3016 response = gtk_dialog_run(GTK_DIALOG(dialog));
3017 gtk_widget_destroy (dialog);
3018 if (response == GTK_RESPONSE_YES)
3020 GtkTreeIter nextIter = iter;
3021 gboolean valid = TRUE;
3022 if (!gtk_tree_model_iter_next(store, &nextIter))
3024 if (!gtk_tree_model_iter_parent(store, &nextIter, &iter))
3029 // Remove the selected item
3030 // First unselect it so that selecting the new item works properly
3031 gtk_tree_selection_unselect_iter (selection, &iter);
3032 if (ghb_presets_remove(presetsPlist, indices, len))
3035 presets_list_remove(ud, indices, len);
3038 valid = gtk_tree_model_get_iter_first(store, &nextIter);
3041 gtk_tree_path_free(path);
3042 path = gtk_tree_model_get_path(store, &nextIter);
3043 indices = gtk_tree_path_get_indices(path);
3044 len = gtk_tree_path_get_depth(path);
3045 ghb_select_preset2(ud->builder, indices, len);
3049 gtk_tree_path_free(path);
3053 // controls where valid drop locations are
3054 G_MODULE_EXPORT gboolean
3055 presets_drag_motion_cb(
3057 GdkDragContext *ctx,
3061 signal_user_data_t *ud)
3063 GtkTreePath *path = NULL;
3064 GtkTreeViewDropPosition drop_pos;
3068 GtkTreeModel *model;
3069 GtkTreeSelection *select;
3070 gint src_ptype, dst_ptype;
3071 gboolean src_folder, dst_folder;
3073 gint tree_depth, ii;
3075 // Get the type of the object being dragged
3076 srctv = GTK_TREE_VIEW(gtk_drag_get_source_widget(ctx));
3077 select = gtk_tree_view_get_selection (srctv);
3078 gtk_tree_selection_get_selected (select, &model, &iter);
3079 path = gtk_tree_model_get_path (model, &iter);
3080 indices = gtk_tree_path_get_indices(path);
3081 len = gtk_tree_path_get_depth(path);
3083 preset = presets_get_dict(presetsPlist, indices, len);
3084 tree_depth = preset_tree_depth(preset);
3086 src_ptype = ghb_presets_get_type(presetsPlist, indices, len);
3087 src_folder = ghb_presets_get_folder(presetsPlist, indices, len);
3088 gtk_tree_path_free(path);
3090 if (src_folder && tree_depth == 1)
3093 // The rest checks that the destination is a valid position
3095 gtk_tree_view_get_dest_row_at_pos (tv, x, y, &path, &drop_pos);
3098 gdk_drag_status(ctx, 0, time);
3101 // Don't allow repositioning of builtin presets
3102 if (src_ptype != PRESETS_CUSTOM)
3104 gdk_drag_status(ctx, 0, time);
3108 len = gtk_tree_path_get_depth(path);
3109 if (len+tree_depth-1 >= MAX_NESTED_PRESET)
3111 if (drop_pos == GTK_TREE_VIEW_DROP_INTO_OR_BEFORE)
3112 drop_pos = GTK_TREE_VIEW_DROP_BEFORE;
3113 if (drop_pos == GTK_TREE_VIEW_DROP_INTO_OR_AFTER)
3114 drop_pos = GTK_TREE_VIEW_DROP_AFTER;
3116 for (ii = len+tree_depth-1; ii > MAX_NESTED_PRESET; ii--)
3117 gtk_tree_path_up(path);
3118 indices = gtk_tree_path_get_indices(path);
3119 len = gtk_tree_path_get_depth(path);
3120 dst_ptype = ghb_presets_get_type(presetsPlist, indices, len);
3121 dst_folder = ghb_presets_get_folder(presetsPlist, indices, len);
3122 // Don't allow mixing custom presets in the builtins
3123 if (dst_ptype != PRESETS_CUSTOM)
3125 gdk_drag_status(ctx, 0, time);
3129 // Only allow *drop into* for folders
3132 if (drop_pos == GTK_TREE_VIEW_DROP_INTO_OR_BEFORE)
3133 drop_pos = GTK_TREE_VIEW_DROP_BEFORE;
3134 if (drop_pos == GTK_TREE_VIEW_DROP_INTO_OR_AFTER)
3135 drop_pos = GTK_TREE_VIEW_DROP_AFTER;
3138 len = gtk_tree_path_get_depth(path);
3139 gtk_tree_view_set_drag_dest_row(tv, path, drop_pos);
3140 gtk_tree_path_free(path);
3141 gdk_drag_status(ctx, GDK_ACTION_MOVE, time);
3145 G_MODULE_EXPORT void
3147 GtkTreeView *dstwidget,
3150 GtkSelectionData *selection_data,
3151 guint info, guint t,
3152 signal_user_data_t *ud)
3154 GtkTreePath *path = NULL;
3155 GtkTreeViewDropPosition drop_pos;
3156 GtkTreeIter dstiter, srciter;
3157 gint *dst_indices, dst_len, *src_indices, src_len;
3159 gboolean src_folder, dst_folder;
3161 GtkTreeModel *dstmodel = gtk_tree_view_get_model(dstwidget);
3163 g_debug("preset_drag_cb ()");
3164 // This doesn't work here for some reason...
3165 // gtk_tree_view_get_drag_dest_row(dstwidget, &path, &drop_pos);
3166 gtk_tree_view_get_dest_row_at_pos (dstwidget, x, y, &path, &drop_pos);
3167 // This little hack is needed because attempting to drop after
3168 // the last item gives us no path or drop_pos.
3173 n_children = gtk_tree_model_iter_n_children(dstmodel, NULL);
3176 drop_pos = GTK_TREE_VIEW_DROP_AFTER;
3177 path = gtk_tree_path_new_from_indices(n_children-1, -1);
3181 drop_pos = GTK_TREE_VIEW_DROP_BEFORE;
3182 path = gtk_tree_path_new_from_indices(0, -1);
3187 GtkTreeView *srcwidget;
3188 GtkTreeModel *srcmodel;
3189 GtkTreeSelection *select;
3190 GtkTreePath *srcpath = NULL;
3192 gint tree_depth, ii;
3194 srcwidget = GTK_TREE_VIEW(gtk_drag_get_source_widget(dc));
3195 select = gtk_tree_view_get_selection (srcwidget);
3196 gtk_tree_selection_get_selected (select, &srcmodel, &srciter);
3198 srcpath = gtk_tree_model_get_path (srcmodel, &srciter);
3199 src_indices = gtk_tree_path_get_indices(srcpath);
3200 src_len = gtk_tree_path_get_depth(srcpath);
3201 src_ptype = ghb_presets_get_type(presetsPlist, src_indices, src_len);
3202 src_folder = ghb_presets_get_folder(presetsPlist, src_indices, src_len);
3203 preset = ghb_value_dup(
3204 presets_get_dict(presetsPlist, src_indices, src_len));
3205 gtk_tree_path_free(srcpath);
3207 // Don't allow repositioning of builtin presets
3208 if (src_ptype != PRESETS_CUSTOM)
3211 tree_depth = preset_tree_depth(preset);
3212 if (src_folder && tree_depth == 1)
3215 dst_len = gtk_tree_path_get_depth(path);
3216 if (dst_len+tree_depth-1 >= MAX_NESTED_PRESET)
3218 if (drop_pos == GTK_TREE_VIEW_DROP_INTO_OR_BEFORE)
3219 drop_pos = GTK_TREE_VIEW_DROP_BEFORE;
3220 if (drop_pos == GTK_TREE_VIEW_DROP_INTO_OR_AFTER)
3221 drop_pos = GTK_TREE_VIEW_DROP_AFTER;
3224 for (ii = dst_len+tree_depth-1; ii > MAX_NESTED_PRESET; ii--)
3225 gtk_tree_path_up(path);
3226 dst_indices = gtk_tree_path_get_indices(path);
3227 dst_len = gtk_tree_path_get_depth(path);
3228 dst_folder = ghb_presets_get_folder(presetsPlist, dst_indices, dst_len);
3229 // Only allow *drop into* for folders
3232 if (drop_pos == GTK_TREE_VIEW_DROP_INTO_OR_BEFORE)
3233 drop_pos = GTK_TREE_VIEW_DROP_BEFORE;
3234 if (drop_pos == GTK_TREE_VIEW_DROP_INTO_OR_AFTER)
3235 drop_pos = GTK_TREE_VIEW_DROP_AFTER;
3237 if (gtk_tree_model_get_iter (dstmodel, &dstiter, path))
3240 GtkTreePath *dstpath = NULL;
3244 case GTK_TREE_VIEW_DROP_BEFORE:
3245 gtk_tree_store_insert_before(GTK_TREE_STORE (dstmodel),
3246 &iter, NULL, &dstiter);
3249 case GTK_TREE_VIEW_DROP_INTO_OR_BEFORE:
3250 gtk_tree_store_insert(GTK_TREE_STORE (dstmodel),
3251 &iter, &dstiter, 0);
3254 case GTK_TREE_VIEW_DROP_AFTER:
3255 gtk_tree_store_insert_after(GTK_TREE_STORE (dstmodel),
3256 &iter, NULL, &dstiter);
3259 case GTK_TREE_VIEW_DROP_INTO_OR_AFTER:
3260 gtk_tree_store_insert_after(GTK_TREE_STORE (dstmodel),
3261 &iter, &dstiter, 0);
3268 dstpath = gtk_tree_model_get_path (dstmodel, &iter);
3269 dst_indices = gtk_tree_path_get_indices(dstpath);
3270 dst_len = gtk_tree_path_get_depth(dstpath);
3271 ghb_presets_insert(presetsPlist, preset, dst_indices, dst_len);
3272 gtk_tree_path_free(dstpath);
3274 srcpath = gtk_tree_model_get_path (srcmodel, &srciter);
3275 src_indices = gtk_tree_path_get_indices(srcpath);
3276 src_len = gtk_tree_path_get_depth(srcpath);
3277 ghb_presets_remove(presetsPlist, src_indices, src_len);
3278 gtk_tree_path_free(srcpath);
3280 gtk_tree_store_remove (GTK_TREE_STORE (srcmodel), &srciter);
3282 dstpath = gtk_tree_model_get_path (dstmodel, &iter);
3283 dst_indices = gtk_tree_path_get_indices(dstpath);
3284 dst_len = gtk_tree_path_get_depth(dstpath);
3285 presets_list_update_item(ud, dst_indices, dst_len);
3286 gtk_tree_path_free(dstpath);
3290 gtk_tree_path_free(path);
3295 presets_row_expanded_cb(
3296 GtkTreeView *treeview,
3299 signal_user_data_t *ud)
3302 gboolean expanded, folder;
3305 expanded = gtk_tree_view_row_expanded(treeview, path);
3306 indices = gtk_tree_path_get_indices(path);
3307 len = gtk_tree_path_get_depth(path);
3308 dict = presets_get_dict(presetsPlist, indices, len);
3309 if (preset_folder_is_open(dict))
3318 folder = ghb_presets_get_folder(presetsPlist, indices, len);
3321 presets_set_folder_open(expanded, indices, len);
3324 // Collapsing parent folder collapses all children
3327 GValue *presets = NULL;
3328 gint *more_indices, count, ii;
3330 more_indices = g_malloc((len+1)*sizeof(gint));
3331 memcpy(more_indices, indices, len*sizeof(gint));
3333 presets = presets_get_folder(presetsPlist, indices, len);
3334 count = ghb_array_len(presets);
3335 for (ii = 0; ii < count; ii++)
3337 dict = ghb_array_get_nth(presets, ii);
3338 folder = ghb_preset_folder(dict);
3341 more_indices[len] = ii;
3342 presets_set_folder_open(expanded, more_indices, len+1);
3345 g_free(more_indices);
3351 preset_update_title_deps(signal_user_data_t *ud, ghb_title_info_t *tinfo)
3355 ghb_ui_update(ud, "scale_width",
3356 ghb_int64_value(tinfo->width - tinfo->crop[2] - tinfo->crop[3]));
3357 // If anamorphic or keep_aspect, the hight will be automatically calculated
3358 gboolean keep_aspect;
3360 keep_aspect = ghb_settings_get_boolean(ud->settings, "PictureKeepRatio");
3361 pic_par = ghb_settings_combo_int(ud->settings, "PicturePAR");
3362 if (!(keep_aspect || pic_par) || pic_par == 3)
3364 ghb_ui_update(ud, "scale_height",
3365 ghb_int64_value(tinfo->height - tinfo->crop[0] - tinfo->crop[1]));
3368 // Set the limits of cropping. hb_set_anamorphic_size crashes if
3369 // you pass it a cropped width or height == 0.
3371 bound = tinfo->height / 2 - 2;
3372 widget = GHB_WIDGET (ud->builder, "PictureTopCrop");
3373 gtk_spin_button_set_range (GTK_SPIN_BUTTON(widget), 0, bound);
3374 widget = GHB_WIDGET (ud->builder, "PictureBottomCrop");
3375 gtk_spin_button_set_range (GTK_SPIN_BUTTON(widget), 0, bound);
3376 bound = tinfo->width / 2 - 2;
3377 widget = GHB_WIDGET (ud->builder, "PictureLeftCrop");
3378 gtk_spin_button_set_range (GTK_SPIN_BUTTON(widget), 0, bound);
3379 widget = GHB_WIDGET (ud->builder, "PictureRightCrop");
3380 gtk_spin_button_set_range (GTK_SPIN_BUTTON(widget), 0, bound);
3381 if (ghb_settings_get_boolean(ud->settings, "PictureAutoCrop"))
3383 ghb_ui_update(ud, "PictureTopCrop", ghb_int64_value(tinfo->crop[0]));
3384 ghb_ui_update(ud, "PictureBottomCrop", ghb_int64_value(tinfo->crop[1]));
3385 ghb_ui_update(ud, "PictureLeftCrop", ghb_int64_value(tinfo->crop[2]));
3386 ghb_ui_update(ud, "PictureRightCrop", ghb_int64_value(tinfo->crop[3]));
3390 G_MODULE_EXPORT void
3391 presets_list_selection_changed_cb(GtkTreeSelection *selection, signal_user_data_t *ud)
3393 GtkTreeModel *store;
3395 ghb_title_info_t tinfo;
3398 g_debug("presets_list_selection_changed_cb ()");
3399 widget = GHB_WIDGET (ud->builder, "presets_remove");
3400 if (gtk_tree_selection_get_selected(selection, &store, &iter))
3402 GtkTreePath *treepath;
3407 treepath = gtk_tree_model_get_path(store, &iter);
3408 indices = gtk_tree_path_get_indices(treepath);
3409 len = gtk_tree_path_get_depth(treepath);
3411 path = preset_path_from_indices(presetsPlist, indices, len);
3412 ghb_settings_take_value(ud->settings, "preset_selection", path);
3414 folder = ghb_presets_get_folder(presetsPlist, indices, len);
3417 ud->dont_clear_presets = TRUE;
3418 // Temporarily set the video_quality range to (0,100)
3419 // This is needed so the video_quality value does not get
3420 // truncated when set. The range will be readjusted below
3421 GtkWidget *qp = GHB_WIDGET(ud->builder, "VideoQualitySlider");
3422 gtk_range_set_range (GTK_RANGE(qp), 0, 100);
3423 gtk_scale_set_digits(GTK_SCALE(qp), 3);
3424 // Clear the audio list prior to changing the preset. Existing
3425 // audio can cause the container extension to be automatically
3426 // changed when it shouldn't be
3427 ghb_clear_audio_list(ud);
3428 ghb_set_preset_from_indices(ud, indices, len);
3429 gtk_tree_path_free(treepath);
3431 titleindex = ghb_settings_combo_int(ud->settings, "title");
3432 ghb_set_pref_audio(titleindex, ud);
3433 ghb_settings_set_boolean(ud->settings, "preset_modified", FALSE);
3434 if (ghb_get_title_info (&tinfo, titleindex))
3436 preset_update_title_deps(ud, &tinfo);
3438 ghb_set_scale (ud, GHB_PIC_KEEP_PAR);
3439 ud->dont_clear_presets = FALSE;
3441 gdouble vqmin, vqmax, step, page;
3445 ghb_vquality_range(ud, &vqmin, &vqmax, &step,
3446 &page, &digits, &inverted);
3447 gtk_range_set_range (GTK_RANGE(qp), vqmin, vqmax);
3448 gtk_range_set_increments (GTK_RANGE(qp), step, page);
3449 gtk_scale_set_digits(GTK_SCALE(qp), digits);
3450 gtk_range_set_inverted (GTK_RANGE(qp), inverted);
3454 GtkWidget *crop_widget;
3455 crop[0] = ghb_settings_get_int(ud->settings, "PictureTopCrop");
3456 crop[1] = ghb_settings_get_int(ud->settings, "PictureBottomCrop");
3457 crop[2] = ghb_settings_get_int(ud->settings, "PictureLeftCrop");
3458 crop[3] = ghb_settings_get_int(ud->settings, "PictureRightCrop");
3459 crop_widget = GHB_WIDGET (ud->builder, "crop_values");
3460 text = g_strdup_printf("%d:%d:%d:%d",
3461 crop[0], crop[1], crop[2], crop[3]);
3462 gtk_label_set_text (GTK_LABEL(crop_widget), text);
3465 gtk_widget_set_sensitive(widget, TRUE);
3469 g_debug("No selection??? Perhaps unselected.");
3470 gtk_widget_set_sensitive(widget, FALSE);
3475 ghb_clear_presets_selection(signal_user_data_t *ud)
3477 GtkTreeView *treeview;
3478 GtkTreeSelection *selection;
3480 if (ud->dont_clear_presets) return;
3481 g_debug("ghb_clear_presets_selection()");
3482 treeview = GTK_TREE_VIEW(GHB_WIDGET(ud->builder, "presets_list"));
3483 selection = gtk_tree_view_get_selection (treeview);
3484 gtk_tree_selection_unselect_all (selection);
3485 ghb_settings_set_boolean(ud->settings, "preset_modified", TRUE);
3488 G_MODULE_EXPORT void
3489 presets_frame_size_allocate_cb(GtkWidget *widget, GtkAllocation *allocation, signal_user_data_t *ud)
3491 GtkTreeView *treeview;
3492 GtkTreeSelection *selection;
3493 GtkTreeModel *store;
3496 treeview = GTK_TREE_VIEW(GHB_WIDGET(ud->builder, "presets_list"));
3497 selection = gtk_tree_view_get_selection(treeview);
3498 if (gtk_tree_selection_get_selected(selection, &store, &iter))
3501 path = gtk_tree_model_get_path (store, &iter);
3502 // Make the parent visible in scroll window if it is not.
3503 gtk_tree_view_scroll_to_cell (treeview, path, NULL, FALSE, 0, 0);
3504 gtk_tree_path_free(path);
3508 G_MODULE_EXPORT void
3509 presets_default_clicked_cb(GtkWidget *xwidget, signal_user_data_t *ud)
3514 g_debug("presets_default_clicked_cb ()");
3515 preset = ghb_settings_get_value(ud->settings, "preset_selection");
3516 indices = ghb_preset_indices_from_path(presetsPlist, preset, &len);
3519 if (!ghb_presets_get_folder(presetsPlist, indices, len))
3521 ghb_presets_list_clear_default(ud);
3522 presets_set_default(indices, len);
3523 ghb_presets_list_default(ud);