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)
14 #include <sys/types.h>
19 #include <glib-object.h>
20 #include <glib/gstdio.h>
25 #include "callbacks.h"
26 #include "audiohandler.h"
27 #include "subtitlehandler.h"
28 #include "hb-backend.h"
30 #include "resources.h"
35 #define MAX_NESTED_PRESET 3
43 static GValue *presetsPlist = NULL;
44 static GValue *internalPlist = NULL;
45 static GValue *prefsPlist = NULL;
46 static gboolean prefs_modified = FALSE;
48 static const GValue* preset_dict_get_value(GValue *dict, const gchar *key);
49 static void store_plist(GValue *plist, const gchar *name);
50 static void store_presets(void);
51 static void store_prefs(void);
54 preset_path_cmp(gint *indices1, gint len1, gint *indices2, gint len2)
57 for (ii = 0; ii < len1 && ii < len2; ii++)
59 if (indices1[ii] != indices2[ii])
60 return indices1[ii] - indices2[ii];
65 // This only handle limited depth
67 ghb_tree_path_new_from_indices(gint *indices, gint len)
72 return gtk_tree_path_new_from_indices(
75 return gtk_tree_path_new_from_indices(
76 indices[0], indices[1], -1);
78 return gtk_tree_path_new_from_indices(
79 indices[0], indices[1], indices[2], -1);
81 return gtk_tree_path_new_from_indices(
82 indices[0], indices[1], indices[2], indices[3], -1);
84 return gtk_tree_path_new_from_indices(
85 indices[0], indices[1], indices[2], indices[3], indices[4], -1);
92 ghb_parse_preset_path(const gchar *path)
98 preset = ghb_array_value_new(MAX_NESTED_PRESET);
99 split = g_strsplit(path, "#", MAX_NESTED_PRESET);
100 for (ii = 0; split[ii] != NULL; ii++)
102 ghb_array_append(preset, ghb_string_value_new(split[ii]));
109 preset_path_from_indices(GValue *presets, gint *indices, gint len)
114 g_debug("preset_path_from_indices");
115 path = ghb_array_value_new(MAX_NESTED_PRESET);
116 for (ii = 0; ii < len; ii++)
122 count = ghb_array_len(presets);
123 if (indices[ii] >= count) break;
124 dict = ghb_array_get_nth(presets, indices[ii]);
125 name = ghb_dict_lookup(dict, "PresetName");
127 ghb_array_append(path, ghb_value_dup(name));
128 folder = ghb_value_boolean(preset_dict_get_value(dict, "Folder"));
131 presets = ghb_dict_lookup(dict, "ChildrenArray");
137 ghb_preset_path_string(const GValue *path)
144 gstr = g_string_new("");
147 count = ghb_array_len(path);
148 for (ii = 0; ii < count; ii++)
150 val = ghb_array_get_nth(path, ii);
151 str = ghb_value_string(val);
152 g_string_append(gstr, str);
154 g_string_append(gstr, "->");
158 str = g_string_free(gstr, FALSE);
163 dump_preset_path(const gchar *msg, const GValue *path)
168 debug_show_type (G_VALUE_TYPE(path));
169 str = ghb_preset_path_string(path);
170 g_message("%s path: (%s)", msg, str);
175 dump_preset_indices(const gchar *msg, gint *indices, gint len)
179 g_message("%s indices: len %d", msg, len);
180 for (ii = 0; ii < len; ii++)
182 printf("%d ", indices[ii]);
189 preset_path_cmp(const GValue *path1, const GValue *path2)
196 count = ghb_array_len(path1);
197 ii = ghb_array_len(path2);
200 for (ii = 0; ii < count; ii++)
202 val = ghb_array_get_nth(path1, ii);
203 str1 = ghb_value_string(val);
204 val = ghb_array_get_nth(path2, ii);
205 str2 = ghb_value_string(val);
206 result = strcmp(str1, str2);
217 presets_get_dict(GValue *presets, gint *indices, gint len)
219 gint ii, count, folder;
222 g_debug("presets_get_dict ()");
223 for (ii = 0; ii < len; ii++)
225 count = ghb_array_len(presets);
226 if (indices[ii] >= count) return NULL;
227 dict = ghb_array_get_nth(presets, indices[ii]);
230 folder = ghb_value_boolean(preset_dict_get_value(dict, "Folder"));
233 presets = ghb_dict_lookup(dict, "ChildrenArray");
242 presets_get_folder(GValue *presets, gint *indices, gint len)
244 gint ii, count, folder;
247 g_debug("presets_get_folder ()");
248 for (ii = 0; ii < len; ii++)
250 count = ghb_array_len(presets);
251 if (indices[ii] >= count) return NULL;
252 dict = ghb_array_get_nth(presets, indices[ii]);
253 folder = ghb_value_boolean(preset_dict_get_value(dict, "Folder"));
256 presets = ghb_dict_lookup(dict, "ChildrenArray");
264 plist_get_dict(GValue *presets, const gchar *name)
266 if (presets == NULL || name == NULL) return NULL;
267 return ghb_dict_lookup(presets, name);
271 preset_get_name(GValue *dict)
273 return g_value_get_string(preset_dict_get_value(dict, "PresetName"));
277 preset_folder_is_open(GValue *dict)
281 gval = preset_dict_get_value(dict, "FolderOpen");
283 return g_value_get_boolean(gval);
288 ghb_preset_folder(GValue *dict)
290 return ghb_value_int(preset_dict_get_value(dict, "Folder"));
294 ghb_preset_type(GValue *dict)
296 return ghb_value_int(preset_dict_get_value(dict, "Type"));
300 presets_remove_nth(GValue *presets, gint pos)
305 if (presets == NULL || pos < 0) return;
306 count = ghb_array_len(presets);
307 if (pos >= count) return;
308 dict = ghb_array_get_nth(presets, pos);
309 ghb_array_remove(presets, pos);
310 ghb_value_free(dict);
319 GValue *folder = NULL;
321 folder = presets_get_folder(presets, indices, len-1);
323 presets_remove_nth(folder, indices[len-1]);
326 g_warning("ghb_presets_remove (): internal preset lookup error");
339 GValue *folder = NULL;
341 folder = presets_get_folder(presets, indices, len-1);
343 ghb_array_replace(folder, indices[len-1], dict);
346 g_warning("ghb_presets_replace (): internal preset lookup error");
357 GValue *folder = NULL;
359 folder = presets_get_folder(presets, indices, len-1);
361 ghb_array_insert(folder, indices[len-1], dict);
364 g_warning("ghb_presets_insert (): internal preset lookup error");
369 presets_find_element(GValue *presets, const gchar *name)
374 g_debug("presets_find_element () (%s)", name);
375 if (presets == NULL || name == NULL) return -1;
376 count = ghb_array_len(presets);
377 for (ii = 0; ii < count; ii++)
380 dict = ghb_array_get_nth(presets, ii);
381 str = preset_get_name(dict);
382 if (strcmp(name, str) == 0)
391 single_find_pos(GValue *presets, const gchar *name, gint type)
394 gint count, ii, ptype, last;
396 if (presets == NULL || name == NULL) return -1;
397 last = count = ghb_array_len(presets);
398 for (ii = 0; ii < count; ii++)
401 dict = ghb_array_get_nth(presets, ii);
402 str = preset_get_name(dict);
403 ptype = ghb_value_int(preset_dict_get_value(dict, "Type"));
404 if (strcasecmp(name, str) <= 0 && ptype == type)
415 presets_find_pos(const GValue *path, gint type, gint *len)
421 gint *indices = NULL;
425 g_debug("presets_find_pos () ");
426 nested = presetsPlist;
427 count = ghb_array_len(path);
428 indices = g_malloc(MAX_NESTED_PRESET * sizeof(gint));
429 for (ii = 0; ii < count-1; ii++)
431 val = ghb_array_get_nth(path, ii);
432 name = g_value_get_string(val);
433 indices[ii] = presets_find_element(nested, name);
434 if (indices[ii] == -1) return NULL;
435 dict = ghb_array_get_nth(nested, indices[ii]);
436 folder = ghb_value_boolean(preset_dict_get_value(dict, "Folder"));
440 nested = ghb_dict_lookup(dict, "ChildrenArray");
446 name = g_value_get_string(ghb_array_get_nth(path, count-1));
447 indices[ii] = single_find_pos(nested, name, type);
455 preset_tree_depth(GValue *dict)
459 folder = ghb_value_boolean(preset_dict_get_value(dict, "Folder"));
466 presets = ghb_dict_lookup(dict, "ChildrenArray");
467 count = ghb_array_len(presets);
468 for (ii = 0; ii < count; ii++)
472 dict = ghb_array_get_nth(presets, ii);
473 tmp = preset_tree_depth(dict);
474 depth = MAX(depth, tmp);
485 preset_is_default(GValue *dict)
489 val = preset_dict_get_value(dict, "Default");
490 return ghb_value_boolean(val);
494 presets_clear_default(GValue *presets)
498 count = ghb_array_len(presets);
499 for (ii = 0; ii < count; ii++)
504 dict = ghb_array_get_nth(presets, ii);
505 folder = ghb_value_boolean(preset_dict_get_value(dict, "Folder"));
510 nested = ghb_dict_lookup(dict, "ChildrenArray");
511 presets_clear_default(nested);
515 if (preset_is_default(dict))
517 ghb_dict_insert(dict, g_strdup("Default"),
518 ghb_boolean_value_new(FALSE));
525 presets_customize(GValue *presets)
529 count = ghb_array_len(presets);
530 for (ii = 0; ii < count; ii++)
536 dict = ghb_array_get_nth(presets, ii);
538 ptype = ghb_value_int(preset_dict_get_value(dict, "Type"));
539 if (ptype != PRESETS_CUSTOM)
541 ghb_dict_insert(dict, g_strdup("Type"),
542 ghb_int64_value_new(PRESETS_CUSTOM));
544 folder = ghb_value_boolean(preset_dict_get_value(dict, "Folder"));
549 nested = ghb_dict_lookup(dict, "ChildrenArray");
550 presets_customize(nested);
556 presets_find_default2(GValue *presets, gint *len)
561 count = ghb_array_len(presets);
562 for (ii = 0; ii < count; ii++)
567 dict = ghb_array_get_nth(presets, ii);
568 folder = ghb_value_boolean(preset_dict_get_value(dict, "Folder"));
574 nested = ghb_dict_lookup(dict, "ChildrenArray");
576 indices = presets_find_default2(nested, len);
587 if (preset_is_default(dict))
589 indices = g_malloc(MAX_NESTED_PRESET * sizeof(gint));
600 presets_find_default(GValue *presets, gint *len)
603 return presets_find_default2(presets, len);
607 ghb_preset_indices_from_path(
615 gint *indices = NULL;
620 g_debug("ghb_preset_indices_from_path () ");
622 count = ghb_array_len(path);
624 indices = g_malloc(MAX_NESTED_PRESET * sizeof(gint));
626 for (ii = 0; ii < count; ii++)
628 val = ghb_array_get_nth(path, ii);
629 name = g_value_get_string(val);
630 indices[ii] = presets_find_element(nested, name);
631 if (indices[ii] == -1)
638 dict = ghb_array_get_nth(nested, indices[ii]);
639 folder = ghb_value_boolean(preset_dict_get_value(dict, "Folder"));
645 nested = ghb_dict_lookup(dict, "ChildrenArray");
653 ghb_presets_get_type(
661 dict = presets_get_dict(presets, indices, len);
664 type = ghb_preset_type(dict);
668 g_warning("ghb_presets_get_type (): internal preset lookup error");
674 ghb_presets_get_folder(
680 gboolean folder = FALSE;
682 dict = presets_get_dict(presets, indices, len);
685 folder = ghb_preset_folder(dict);
689 g_warning("ghb_presets_get_folder (): internal preset lookup error");
695 presets_set_default(gint *indices, gint len)
699 g_debug("presets_set_default ()");
700 presets_clear_default(presetsPlist);
701 dict = presets_get_dict(presetsPlist, indices, len);
704 ghb_dict_insert(dict, g_strdup("Default"), ghb_boolean_value_new(TRUE));
710 presets_set_folder_open(gboolean open, gint *indices, gint len)
714 g_debug("presets_set_folder_open ()");
715 dict = presets_get_dict(presetsPlist, indices, len);
718 ghb_dict_insert(dict, g_strdup("FolderOpen"),
719 ghb_boolean_value_new(open));
723 // Used for sorting dictionaries.
725 key_cmp(gconstpointer a, gconstpointer b)
727 gchar *stra = (gchar*)a;
728 gchar *strb = (gchar*)b;
730 return strcmp(stra, strb);
734 preset_dict_get_value(GValue *dict, const gchar *key)
736 const GValue *gval = NULL;
740 gval = ghb_dict_lookup(dict, key);
742 if (internalPlist == NULL) return NULL;
745 dict = plist_get_dict(internalPlist, "Presets");
746 if (dict == NULL) return NULL;
747 gval = ghb_dict_lookup(dict, key);
753 ghb_presets_get_description(GValue *pdict)
757 if (pdict == NULL) return NULL;
758 desc = g_value_get_string(
759 preset_dict_get_value(pdict, "PresetDescription"));
760 if (desc[0] == 0) return NULL;
765 static void init_settings_from_dict(
766 GValue *dest, GValue *internal, GValue *dict);
769 init_settings_from_array(
777 count = ghb_array_len(array);
778 // The first element of the internal version is always the
779 // template for the allowed values
780 gval = ghb_array_get_nth(internal, 0);
781 for (ii = 0; ii < count; ii++)
784 val = ghb_array_get_nth(array, ii);
787 if (G_VALUE_TYPE(gval) == ghb_dict_get_type())
790 new_dict = ghb_dict_value_new();
791 ghb_array_append(dest, new_dict);
792 if (G_VALUE_TYPE(val) == ghb_dict_get_type())
793 init_settings_from_dict(new_dict, gval, val);
795 init_settings_from_dict(new_dict, gval, gval);
797 else if (G_VALUE_TYPE(gval) == ghb_array_get_type())
800 new_array = ghb_array_value_new(8);
801 ghb_array_append(dest, new_array);
802 if (G_VALUE_TYPE(val) == ghb_array_get_type())
803 init_settings_from_array(new_array, gval, val);
805 init_settings_from_array(new_array, gval, gval);
809 ghb_array_append(dest, val);
815 init_settings_from_dict(
824 ghb_dict_iter_init(&iter, internal);
825 // middle (void*) cast prevents gcc warning "defreferencing type-punned
826 // pointer will break strict-aliasing rules"
827 while (g_hash_table_iter_next(
828 &iter, (gpointer*)(void*)&key, (gpointer*)(void*)&gval))
832 val = ghb_dict_lookup(dict, key);
835 if (G_VALUE_TYPE(gval) == ghb_dict_get_type())
838 new_dict = ghb_dict_value_new();
839 ghb_settings_take_value(dest, key, new_dict);
840 if (G_VALUE_TYPE(val) == ghb_dict_get_type())
841 init_settings_from_dict(new_dict, gval, val);
843 init_settings_from_dict(new_dict, gval, gval);
845 else if (G_VALUE_TYPE(gval) == ghb_array_get_type())
848 new_array = ghb_array_value_new(8);
849 ghb_settings_take_value(dest, key, new_array);
850 if (G_VALUE_TYPE(val) == ghb_array_get_type())
851 init_settings_from_array(new_array, gval, val);
853 init_settings_from_array(new_array, gval, gval);
858 ghb_settings_set_value(dest, key, val);
865 signal_user_data_t *ud,
873 ghb_dict_iter_init(&iter, internal);
874 // middle (void*) cast prevents gcc warning "defreferencing type-punned
875 // pointer will break strict-aliasing rules"
876 while (g_hash_table_iter_next(
877 &iter, (gpointer*)(void*)&key, (gpointer*)(void*)&gval))
881 val = ghb_dict_lookup(dict, key);
884 ghb_ui_update(ud, key, val);
889 preset_to_ui(signal_user_data_t *ud, GValue *dict)
891 g_debug("preset_to_ui()\n");
892 // Initialize the ui from presets file.
893 GValue *internal, *hidden;
895 // Get key list from internal default presets. This way we do not
896 // load any unknown keys.
897 if (internalPlist == NULL) return;
898 internal = plist_get_dict(internalPlist, "Presets");
899 hidden = plist_get_dict(internalPlist, "XlatPresets");
900 // Setting a ui widget will cause the corresponding setting
901 // to be set, but it also triggers a callback that can
902 // have the side effect of using other settings values
903 // that have not yet been set. So set *all* settings first
904 // then update the ui.
905 init_settings_from_dict(ud->settings, internal, dict);
906 init_settings_from_dict(ud->settings, hidden, dict);
907 init_ui_from_dict(ud, internal, dict);
908 init_ui_from_dict(ud, hidden, dict);
915 val = ghb_dict_lookup(dict, "PictureDecombDeinterlace");
918 dd = ghb_value_boolean(val);
919 ghb_ui_update(ud, "PictureDeinterlaceDecomb", ghb_boolean_value(!dd));
925 ghb_settings_to_ui(signal_user_data_t *ud, GValue *dict)
927 init_ui_from_dict(ud, dict, dict);
930 static GValue *current_preset = NULL;
933 ghb_preset_is_custom()
937 if (current_preset == NULL) return FALSE;
938 val = preset_dict_get_value(current_preset, "Type");
939 return (ghb_value_int(val) == 1);
943 ghb_set_preset_from_indices(signal_user_data_t *ud, gint *indices, gint len)
946 gint fallback[2] = {0, -1};
949 dict = presets_get_dict(presetsPlist, indices, len);
954 dict = presets_get_dict(presetsPlist, indices, len);
958 preset_to_ui(ud, NULL);
959 current_preset = NULL;
966 current_preset = dict;
967 folder = ghb_value_boolean(preset_dict_get_value(dict, "Folder"));
969 preset_to_ui(ud, NULL);
971 preset_to_ui(ud, dict);
972 path = preset_path_from_indices(presetsPlist, indices, len);
973 ghb_settings_set_value(ud->settings, "preset", path);
974 ghb_value_free(path);
979 curr_preset_get_value(const gchar *key)
981 if (current_preset == NULL) return NULL;
982 return preset_dict_get_value(current_preset, key);
986 ghb_update_from_preset(
987 signal_user_data_t *ud,
992 g_debug("ghb_update_from_preset() %s", key);
993 gval = curr_preset_get_value(key);
996 ghb_ui_update(ud, key, gval);
1002 GtkBuilder *builder,
1006 GtkTreeView *treeview;
1007 GtkTreeSelection *selection;
1008 GtkTreeModel *store;
1012 g_debug("ghb_select_preset2()");
1013 treeview = GTK_TREE_VIEW(GHB_WIDGET(builder, "presets_list"));
1014 selection = gtk_tree_view_get_selection (treeview);
1015 store = gtk_tree_view_get_model (treeview);
1016 path = ghb_tree_path_new_from_indices(indices, len);
1019 if (gtk_tree_model_get_iter(store, &iter, path))
1021 gtk_tree_selection_select_iter (selection, &iter);
1025 if (gtk_tree_model_get_iter_first(store, &iter))
1026 gtk_tree_selection_select_iter (selection, &iter);
1028 gtk_tree_path_free(path);
1033 ghb_select_preset(GtkBuilder *builder, const GValue *path)
1037 g_debug("ghb_select_preset()");
1038 indices = ghb_preset_indices_from_path(presetsPlist, path, &len);
1041 ghb_select_preset2(builder, indices, len);
1047 ghb_select_default_preset(GtkBuilder *builder)
1051 g_debug("ghb_select_default_preset()");
1052 indices = presets_find_default(presetsPlist, &len);
1055 ghb_select_preset2(builder, indices, len);
1061 ghb_get_user_config_dir(gchar *subdir)
1066 dir = g_get_user_config_dir();
1067 if (!g_file_test(dir, G_FILE_TEST_IS_DIR))
1069 dir = g_get_home_dir();
1070 config = g_strdup_printf ("%s/.ghb", dir);
1071 if (!g_file_test(config, G_FILE_TEST_IS_DIR))
1072 g_mkdir (config, 0755);
1076 config = g_strdup_printf ("%s/ghb", dir);
1077 if (!g_file_test(config, G_FILE_TEST_IS_DIR))
1078 g_mkdir (config, 0755);
1085 split = g_strsplit(subdir, G_DIR_SEPARATOR_S, -1);
1086 for (ii = 0; split[ii] != NULL; ii++)
1090 tmp = g_strdup_printf ("%s/%s", config, split[ii]);
1093 if (!g_file_test(config, G_FILE_TEST_IS_DIR))
1094 g_mkdir (config, 0755);
1101 store_plist(GValue *plist, const gchar *name)
1103 gchar *config, *path;
1106 config = ghb_get_user_config_dir(NULL);
1107 path = g_strdup_printf ("%s/%s", config, name);
1108 file = g_fopen(path, "w");
1111 ghb_plist_write(file, plist);
1116 load_plist(const gchar *name)
1118 gchar *config, *path;
1119 GValue *plist = NULL;
1121 config = ghb_get_user_config_dir(NULL);
1122 path = g_strdup_printf ("%s/%s", config, name);
1123 if (g_file_test(path, G_FILE_TEST_IS_REGULAR))
1125 plist = ghb_plist_parse_file(path);
1133 ghb_lock_file(const gchar *name)
1135 #if !defined(_WIN32)
1136 gchar *config, *path;
1139 config = ghb_get_user_config_dir(NULL);
1140 path = g_strdup_printf ("%s/%s", config, name);
1141 fd = open(path, O_RDWR|O_CREAT, S_IRUSR|S_IWUSR);
1143 lock = lockf(fd, F_TLOCK, 0);
1155 ghb_write_pid_file()
1157 #if !defined(_WIN32)
1158 gchar *config, *path;
1165 config = ghb_get_user_config_dir(NULL);
1166 path = g_strdup_printf ("%s/ghb.pid.%d", config, pid);
1168 fp = g_fopen(path, "w");
1169 fprintf(fp, "%d\n", pid);
1172 fd = open(path, O_RDWR|O_CREAT, S_IRUSR|S_IWUSR);
1173 lock = lockf(fd, F_TLOCK, 0);
1181 ghb_unlink_pid_file(int pid)
1183 gchar *config, *path;
1185 config = ghb_get_user_config_dir(NULL);
1186 path = g_strdup_printf ("%s/ghb.pid.%d", config, pid);
1188 if (g_file_test(path, G_FILE_TEST_IS_REGULAR))
1203 config = ghb_get_user_config_dir(NULL);
1205 if (g_file_test(config, G_FILE_TEST_IS_DIR))
1207 GDir *gdir = g_dir_open(config, 0, NULL);
1208 file = g_dir_read_name(gdir);
1211 if (strncmp(file, "ghb.pid.", 8) == 0)
1217 sscanf(file, "ghb.pid.%d", &pid);
1221 file = g_dir_read_name(gdir);
1224 path = g_strdup_printf("%s/%s", config, file);
1226 #if !defined(_WIN32)
1229 fd = open(path, O_RDWR);
1232 lock = lockf(fd, F_TLOCK, 0);
1253 file = g_dir_read_name(gdir);
1262 remove_plist(const gchar *name)
1264 gchar *config, *path;
1266 config = ghb_get_user_config_dir(NULL);
1267 path = g_strdup_printf ("%s/%s", config, name);
1268 if (g_file_test(path, G_FILE_TEST_IS_REGULAR))
1276 static gboolean prefs_initializing = FALSE;
1279 ghb_prefs_to_ui(signal_user_data_t *ud)
1284 GValue *internal, *dict;
1285 GHashTableIter iter;
1288 g_debug("ghb_prefs_to_ui");
1289 prefs_initializing = TRUE;
1291 // Setting a ui widget will cause the corresponding setting
1292 // to be set, but it also triggers a callback that can
1293 // have the side effect of using other settings values
1294 // that have not yet been set. So set *all* settings first
1295 // then update the ui.
1296 internal = plist_get_dict(internalPlist, "Initialization");
1297 ghb_dict_iter_init(&iter, internal);
1298 // middle (void*) cast prevents gcc warning "defreferencing type-punned
1299 // pointer will break strict-aliasing rules"
1300 while (g_hash_table_iter_next(
1301 &iter, (gpointer*)(void*)&key, (gpointer*)(void*)&gval))
1303 ghb_ui_update(ud, key, gval);
1306 dict = plist_get_dict(prefsPlist, "Preferences");
1307 internal = plist_get_dict(internalPlist, "Preferences");
1308 ghb_dict_iter_init(&iter, internal);
1309 // middle (void*) cast prevents gcc warning "defreferencing type-punned
1310 // pointer will break strict-aliasing rules"
1311 while (g_hash_table_iter_next(
1312 &iter, (gpointer*)(void*)&key, (gpointer*)(void*)&gval))
1314 const GValue *value = NULL;
1316 value = ghb_dict_lookup(dict, key);
1319 ghb_settings_set_value(ud->settings, key, value);
1321 internal = plist_get_dict(internalPlist, "Preferences");
1322 ghb_dict_iter_init(&iter, internal);
1323 // middle (void*) cast prevents gcc warning "defreferencing type-punned
1324 // pointer will break strict-aliasing rules"
1325 while (g_hash_table_iter_next(
1326 &iter, (gpointer*)(void*)&key, (gpointer*)(void*)&gval))
1328 const GValue *value = NULL;
1330 value = ghb_dict_lookup(dict, key);
1333 ghb_ui_update(ud, key, value);
1336 val = ghb_settings_get_value(ud->settings, "show_presets");
1337 ghb_ui_update(ud, "show_presets", val);
1338 if (ghb_settings_get_boolean(ud->settings, "hbfd_feature"))
1341 val = ghb_settings_get_value(ud->settings, "hbfd");
1342 ghb_ui_update(ud, "hbfd", val);
1343 action = GHB_ACTION (ud->builder, "hbfd");
1344 gtk_action_set_visible(action, TRUE);
1348 ghb_ui_update(ud, "hbfd", ghb_int64_value(0));
1350 gval = ghb_settings_get_value(ud->settings, "default_source");
1351 ghb_settings_set_value (ud->settings, "scan_source", gval);
1353 str = ghb_settings_get_string(ud->settings, "destination_dir");
1354 ghb_ui_update(ud, "dest_dir", ghb_string_value(str));
1356 gchar *file = g_strdup_printf ("new_video.mp4");
1357 ghb_ui_update(ud, "dest_file", ghb_string_value(file));
1361 prefs_initializing = FALSE;
1365 ghb_prefs_save(GValue *settings)
1369 GHashTableIter iter;
1371 const GValue *value;
1373 if (prefs_initializing) return;
1374 dict = plist_get_dict(internalPlist, "Preferences");
1375 if (dict == NULL) return;
1376 pref_dict = plist_get_dict(prefsPlist, "Preferences");
1377 if (pref_dict == NULL) return;
1378 ghb_dict_iter_init(&iter, dict);
1379 // middle (void*) cast prevents gcc warning "defreferencing type-punned
1380 // pointer will break strict-aliasing rules"
1381 while (g_hash_table_iter_next(
1382 &iter, (gpointer*)(void*)&key, (gpointer*)(void*)&value))
1384 value = ghb_settings_get_value(settings, key);
1387 ghb_dict_insert(pref_dict, g_strdup(key), ghb_value_dup(value));
1391 prefs_modified = FALSE;
1395 ghb_pref_set(GValue *settings, const gchar *key)
1397 const GValue *value, *value2;
1399 if (prefs_initializing) return;
1400 value = ghb_settings_get_value(settings, key);
1404 dict = plist_get_dict(prefsPlist, "Preferences");
1405 if (dict == NULL) return;
1406 value2 = ghb_dict_lookup(dict, key);
1407 if (ghb_value_cmp(value, value2) != 0)
1409 ghb_dict_insert(dict, g_strdup(key), ghb_value_dup(value));
1411 prefs_modified = TRUE;
1417 ghb_pref_save(GValue *settings, const gchar *key)
1419 const GValue *value, *value2;
1421 if (prefs_initializing) return;
1422 value = ghb_settings_get_value(settings, key);
1426 dict = plist_get_dict(prefsPlist, "Preferences");
1427 if (dict == NULL) return;
1428 value2 = ghb_dict_lookup(dict, key);
1429 if (ghb_value_cmp(value, value2) != 0)
1431 ghb_dict_insert(dict, g_strdup(key), ghb_value_dup(value));
1433 prefs_modified = FALSE;
1439 ghb_prefs_store(void)
1444 prefs_modified = FALSE;
1449 ghb_settings_init(signal_user_data_t *ud)
1452 GHashTableIter iter;
1457 g_debug("ghb_settings_init");
1458 prefs_initializing = TRUE;
1460 internalPlist = ghb_resource_get("internal-defaults");
1461 // Setting a ui widget will cause the corresponding setting
1462 // to be set, but it also triggers a callback that can
1463 // have the side effect of using other settings values
1464 // that have not yet been set. So set *all* settings first
1465 // then update the ui.
1466 internal = plist_get_dict(internalPlist, "Initialization");
1467 ghb_dict_iter_init(&iter, internal);
1468 // middle (void*) cast prevents gcc warning "defreferencing type-punned
1469 // pointer will break strict-aliasing rules"
1470 while (g_hash_table_iter_next(
1471 &iter, (gpointer*)(void*)&key, (gpointer*)(void*)&gval))
1473 ghb_settings_set_value(ud->settings, key, gval);
1476 internal = plist_get_dict(internalPlist, "Presets");
1477 ghb_dict_iter_init(&iter, internal);
1478 // middle (void*) cast prevents gcc warning "defreferencing type-punned
1479 // pointer will break strict-aliasing rules"
1480 while (g_hash_table_iter_next(
1481 &iter, (gpointer*)(void*)&key, (gpointer*)(void*)&gval))
1483 ghb_settings_set_value(ud->settings, key, gval);
1486 internal = plist_get_dict(internalPlist, "Preferences");
1487 ghb_dict_iter_init(&iter, internal);
1488 // middle (void*) cast prevents gcc warning "defreferencing type-punned
1489 // pointer will break strict-aliasing rules"
1490 while (g_hash_table_iter_next(
1491 &iter, (gpointer*)(void*)&key, (gpointer*)(void*)&gval))
1493 ghb_settings_set_value(ud->settings, key, gval);
1495 prefs_initializing = FALSE;
1499 ghb_settings_close()
1502 ghb_value_free(internalPlist);
1504 ghb_value_free(presetsPlist);
1506 ghb_value_free(prefsPlist);
1511 FindFirstCDROM(void)
1516 strcpy(drive, "A:" G_DIR_SEPARATOR_S);
1517 drives = GetLogicalDrives();
1518 for (ii = 0; ii < 26; ii++)
1524 drive[0] = 'A' + ii;
1525 dtype = GetDriveType(drive);
1526 if (dtype == DRIVE_CDROM)
1528 return g_strdup(drive);
1538 ghb_prefs_load(signal_user_data_t *ud)
1540 GValue *dict, *internal;
1541 GHashTableIter iter;
1543 GValue *gval, *path;
1545 g_debug("ghb_prefs_load");
1546 prefsPlist = load_plist("preferences");
1547 if (prefsPlist == NULL)
1548 prefsPlist = ghb_dict_value_new();
1549 dict = plist_get_dict(prefsPlist, "Preferences");
1550 internal = plist_get_dict(internalPlist, "Preferences");
1551 if (dict == NULL && internal)
1553 dict = ghb_dict_value_new();
1554 ghb_dict_insert(prefsPlist, g_strdup("Preferences"), dict);
1556 // Get defaults from internal defaults
1557 ghb_dict_iter_init(&iter, internal);
1558 // middle (void*) cast prevents gcc warning "defreferencing type-punned
1559 // pointer will break strict-aliasing rules"
1560 while (g_hash_table_iter_next(
1561 &iter, (gpointer*)(void*)&key, (gpointer*)(void*)&gval))
1563 ghb_dict_insert(dict, g_strdup(key), ghb_value_dup(gval));
1566 const gchar *dir = g_get_user_special_dir (G_USER_DIRECTORY_DESKTOP);
1571 ghb_dict_insert(dict,
1572 g_strdup("ExportDirectory"), ghb_value_dup(ghb_string_value(dir)));
1574 dir = g_get_user_special_dir (G_USER_DIRECTORY_VIDEOS);
1579 ghb_dict_insert(dict,
1580 g_strdup("destination_dir"), ghb_value_dup(ghb_string_value(dir)));
1582 ghb_dict_insert(dict,
1583 g_strdup("SrtDir"), ghb_value_dup(ghb_string_value(dir)));
1587 source = FindFirstCDROM();
1590 source = g_strdup("C:" G_DIR_SEPARATOR_S);
1592 ghb_dict_insert(dict, g_strdup("default_source"),
1593 ghb_value_dup(ghb_string_value(source)));
1598 // Read legacy default_preset preference and update accordingly
1599 path = ghb_dict_lookup(dict, "default_preset");
1604 if (G_VALUE_TYPE(path) == G_TYPE_STRING)
1608 path = ghb_array_value_new(1);
1609 ghb_array_append(path, ghb_value_dup(str));
1610 indices = ghb_preset_indices_from_path(presetsPlist, path, &len);
1611 ghb_value_free(path);
1614 indices = ghb_preset_indices_from_path(presetsPlist, path, &len);
1618 presets_set_default(indices, len);
1621 ghb_dict_remove(dict, "default_preset");
1627 get_preset_color(gint type, gboolean folder)
1631 if (type == PRESETS_CUSTOM)
1651 ghb_presets_list_init(
1652 signal_user_data_t *ud,
1656 GtkTreeView *treeview;
1657 GtkTreeIter iter, titer, *piter;
1659 GtkTreeStore *store;
1660 const gchar *preset;
1661 GtkTreePath *parent_path;
1662 const gchar *description;
1667 GValue *presets = NULL;
1669 g_debug("ghb_presets_list_init ()");
1670 more_indices = g_malloc((len+1)*sizeof(gint));
1671 memcpy(more_indices, indices, len*sizeof(gint));
1672 presets = presets_get_folder(presetsPlist, indices, len);
1673 if (presets == NULL)
1675 g_warning("Failed to find parent folder when adding child.");
1678 count = ghb_array_len(presets);
1679 treeview = GTK_TREE_VIEW(GHB_WIDGET(ud->builder, "presets_list"));
1680 store = GTK_TREE_STORE(gtk_tree_view_get_model(treeview));
1681 parent_path = ghb_tree_path_new_from_indices(indices, len);
1684 gtk_tree_model_get_iter(GTK_TREE_MODEL(store), &titer, parent_path);
1686 gtk_tree_path_free(parent_path);
1692 for (ii = 0; ii < count; ii++)
1698 // Additional settings, add row
1699 dict = ghb_array_get_nth(presets, ii);
1700 preset = preset_get_name(dict);
1701 more_indices[len] = ii;
1702 def = preset_is_default(dict);
1704 description = ghb_presets_get_description(dict);
1705 gtk_tree_store_append(store, &iter, piter);
1706 type = ghb_preset_type(dict);
1707 folder = ghb_preset_folder(dict);
1708 color = get_preset_color(type, folder);
1709 gtk_tree_store_set(store, &iter, 0, preset,
1714 5, type == PRESETS_BUILTIN ? 0 : 1,
1721 if (gtk_tree_model_iter_parent(
1722 GTK_TREE_MODEL(store), &ppiter, piter))
1724 path = gtk_tree_model_get_path(GTK_TREE_MODEL(store), &ppiter);
1725 gtk_tree_view_expand_row(treeview, path, FALSE);
1726 gtk_tree_path_free(path);
1728 path = gtk_tree_model_get_path(GTK_TREE_MODEL(store), piter);
1729 gtk_tree_view_expand_row(treeview, path, FALSE);
1730 gtk_tree_path_free(path);
1734 ghb_presets_list_init(ud, more_indices, len+1);
1735 if (preset_folder_is_open(dict))
1741 path = gtk_tree_model_get_path(GTK_TREE_MODEL(store), piter);
1742 gtk_tree_view_expand_row(treeview, path, FALSE);
1743 gtk_tree_path_free(path);
1745 path = gtk_tree_model_get_path(GTK_TREE_MODEL(store), &iter);
1746 gtk_tree_view_expand_row(treeview, path, FALSE);
1747 gtk_tree_path_free(path);
1751 g_free(more_indices);
1755 presets_list_update_item(
1756 signal_user_data_t *ud,
1761 GtkTreeView *treeview;
1762 GtkTreeStore *store;
1764 GtkTreePath *treepath;
1766 const gchar *description;
1768 gboolean def, folder;
1772 g_debug("presets_list_update_item ()");
1773 dict = presets_get_dict(presetsPlist, indices, len);
1776 treeview = GTK_TREE_VIEW(GHB_WIDGET(ud->builder, "presets_list"));
1777 store = GTK_TREE_STORE(gtk_tree_view_get_model(treeview));
1778 treepath = ghb_tree_path_new_from_indices(indices, len);
1779 gtk_tree_model_get_iter(GTK_TREE_MODEL(store), &iter, treepath);
1780 // Additional settings, add row
1781 name = preset_get_name(dict);
1782 def = preset_is_default(dict);
1784 description = ghb_presets_get_description(dict);
1785 type = ghb_preset_type(dict);
1786 folder = ghb_preset_folder(dict);
1787 color = get_preset_color(type, folder);
1788 gtk_tree_store_set(store, &iter, 0, name,
1793 5, type == PRESETS_BUILTIN ? 0 : 1,
1795 if (recurse && folder)
1797 ghb_presets_list_init(ud, indices, len);
1802 presets_list_insert(
1803 signal_user_data_t *ud,
1807 GtkTreeView *treeview;
1808 GtkTreeIter iter, titer, *piter;
1809 GtkTreeStore *store;
1810 const gchar *preset;
1811 const gchar *description;
1813 gboolean def, folder;
1816 GtkTreePath *parent_path;
1820 g_debug("presets_list_insert ()");
1821 treeview = GTK_TREE_VIEW(GHB_WIDGET(ud->builder, "presets_list"));
1822 store = GTK_TREE_STORE(gtk_tree_view_get_model(treeview));
1823 presets = presets_get_folder(presetsPlist, indices, len-1);
1824 if (presets == NULL)
1826 g_warning("Failed to find parent folder while adding child.");
1829 parent_path = ghb_tree_path_new_from_indices(indices, len-1);
1832 gtk_tree_model_get_iter(GTK_TREE_MODEL(store), &titer, parent_path);
1834 gtk_tree_path_free(parent_path);
1840 count = ghb_array_len(presets);
1841 if (indices[len-1] >= count)
1843 // Additional settings, add row
1844 dict = ghb_array_get_nth(presets, indices[len-1]);
1845 preset = preset_get_name(dict);
1846 def = preset_is_default(dict);
1848 description = ghb_presets_get_description(dict);
1849 gtk_tree_store_insert(store, &iter, piter, indices[len-1]);
1850 type = ghb_preset_type(dict);
1851 folder = ghb_preset_folder(dict);
1852 color = get_preset_color(type, folder);
1853 gtk_tree_store_set(store, &iter, 0, preset,
1858 5, type == PRESETS_BUILTIN ? 0 : 1,
1862 ghb_presets_list_init(ud, indices, len);
1867 presets_list_remove(
1868 signal_user_data_t *ud,
1872 GtkTreeView *treeview;
1873 GtkTreePath *treepath;
1875 GtkTreeStore *store;
1877 g_debug("presets_list_remove ()");
1878 treeview = GTK_TREE_VIEW(GHB_WIDGET(ud->builder, "presets_list"));
1879 store = GTK_TREE_STORE(gtk_tree_view_get_model(treeview));
1880 treepath = ghb_tree_path_new_from_indices(indices, len);
1883 if (gtk_tree_model_get_iter(GTK_TREE_MODEL(store), &iter, treepath))
1884 gtk_tree_store_remove(store, &iter);
1885 gtk_tree_path_free(treepath);
1890 remove_std_presets(signal_user_data_t *ud)
1895 count = ghb_array_len(presetsPlist);
1896 for (ii = count-1; ii >= 0; ii--)
1901 dict = ghb_array_get_nth(presetsPlist, ii);
1902 ptype = ghb_value_int(preset_dict_get_value(dict, "Type"));
1903 if (ptype == PRESETS_BUILTIN)
1905 if (ghb_presets_remove(presetsPlist, &indices, 1))
1907 presets_list_remove(ud, &indices, 1);
1914 ghb_save_queue(GValue *queue)
1920 path = g_strdup_printf ("queue.%d", pid);
1921 store_plist(queue, path);
1933 path = g_strdup_printf ("queue.%d", pid);
1934 queue = load_plist(path);
1940 ghb_load_old_queue(int pid)
1945 path = g_strdup_printf ("queue.%d", pid);
1946 queue = load_plist(path);
1952 ghb_remove_old_queue_file(int pid)
1956 path = g_strdup_printf ("queue.%d", pid);
1962 ghb_remove_queue_file()
1968 path = g_strdup_printf ("queue.%d", pid);
1979 static value_map_t vcodec_xlat[] =
1981 {"MPEG-4 (FFmpeg)", "ffmpeg"},
1982 {"MPEG-4 (XviD)", "ffmpeg"},
1983 {"H.264 (x264)", "x264"},
1984 {"VP3 (Theora)", "theora"},
1988 static value_map_t acodec_xlat[] =
1990 {"AAC (faac)", "faac"},
1991 {"AAC (CoreAudio)", "faac"},
1992 {"AC3 Passthru", "ac3"},
1993 {"MP3 (lame)", "lame"},
1994 {"Vorbis (vorbis)", "vorbis"},
1998 value_map_t container_xlat[] =
2000 {"MP4 file", "mp4"},
2001 {"M4V file", "mp4"},
2002 {"MKV file", "mkv"},
2003 {"AVI file", "mkv"},
2004 {"OGM file", "mkv"},
2008 value_map_t framerate_xlat[] =
2010 {"Same as source", "source"},
2015 {"23.976", "23.976"},
2022 value_map_t samplerate_xlat[] =
2033 value_map_t mix_xlat[] =
2036 {"Stereo", "stereo"},
2037 {"Dolby Surround", "dpl1"},
2038 {"Dolby Pro Logic II", "dpl2"},
2039 {"6-channel discrete", "6ch"},
2040 {"AC3 Passthru", "none"},
2044 value_map_t deint_xlat[] =
2054 value_map_t denoise_xlat[] =
2064 value_map_t detel_xlat[] =
2072 value_map_t decomb_xlat[] =
2080 extern iso639_lang_t ghb_language_table[];
2083 export_lang_xlat2(GValue *lin_val)
2087 if (lin_val == NULL) return NULL;
2091 str = ghb_value_string(lin_val);
2092 for (ii = 0; ghb_language_table[ii].eng_name; ii++)
2094 if (strcmp(str, ghb_language_table[ii].iso639_2) == 0)
2098 if (ghb_language_table[ii].native_name[0] != 0)
2099 lang = ghb_language_table[ii].native_name;
2101 lang = ghb_language_table[ii].eng_name;
2103 gval = ghb_string_value_new(lang);
2108 g_debug("Can't map language value: (%s)", str);
2114 export_subtitle_xlat2(GValue *lin_val)
2119 if (lin_val == NULL) return NULL;
2120 str = ghb_value_string(lin_val);
2121 if (strcmp(str, "none") == 0)
2123 gval = ghb_string_value_new("None");
2125 else if (strcmp(str, "auto") == 0)
2127 gval = ghb_string_value_new("Autoselect");
2131 gval = export_lang_xlat2(lin_val);
2138 import_lang_xlat2(GValue *mac_val)
2142 if (mac_val == NULL) return NULL;
2146 str = ghb_value_string(mac_val);
2147 for (ii = 0; ghb_language_table[ii].eng_name; ii++)
2149 if ((strcmp(str, ghb_language_table[ii].eng_name) == 0) ||
2150 (strcmp(str, ghb_language_table[ii].native_name) == 0))
2152 gval = ghb_string_value_new(ghb_language_table[ii].iso639_2);
2157 g_debug("Can't map language value: (%s)", str);
2163 import_subtitle_xlat2(GValue *mac_val)
2168 if (mac_val == NULL) return NULL;
2169 str = ghb_value_string(mac_val);
2170 if (strcmp(str, "None") == 0)
2172 gval = ghb_string_value_new("none");
2174 else if (strcmp(str, "Autoselect") == 0)
2176 gval = ghb_string_value_new("auto");
2180 gval = import_lang_xlat2(mac_val);
2187 export_audio_track_xlat2(GValue *lin_val)
2190 GValue *gval = NULL;
2192 if (lin_val == NULL) return NULL;
2193 str = ghb_value_string(lin_val);
2194 if (strcmp(str, "none") == 0)
2196 gval = ghb_int_value_new(1);
2200 gint val = ghb_value_int(lin_val) + 1;
2201 gval = ghb_int_value_new(val);
2208 import_audio_track_xlat2(GValue *mac_val)
2214 if (mac_val == NULL) return NULL;
2215 val = ghb_value_int(mac_val);
2224 str = g_strdup_printf("%d", val);
2225 gval = ghb_string_value_new(str);
2231 export_value_xlat2(value_map_t *value_map, GValue *lin_val, GType mac_type)
2235 if (lin_val == NULL) return NULL;
2240 str = ghb_value_string(lin_val);
2241 for (ii = 0; value_map[ii].mac_val; ii++)
2243 if (strcmp(str, value_map[ii].lin_val) == 0)
2245 sval = ghb_string_value_new(value_map[ii].mac_val);
2247 gval = ghb_value_new(mac_type);
2248 if (!g_value_transform(sval, gval))
2250 g_warning("can't transform");
2251 ghb_value_free(gval);
2252 ghb_value_free(sval);
2255 ghb_value_free(sval);
2259 g_debug("Can't map value: (%s)", str);
2265 export_value_xlat(GValue *dict)
2267 GValue *lin_val, *gval;
2270 key = "VideoEncoder";
2271 lin_val = ghb_dict_lookup(dict, key);
2272 gval = export_value_xlat2(vcodec_xlat, lin_val, G_TYPE_STRING);
2274 ghb_dict_insert(dict, g_strdup(key), gval);
2276 lin_val = ghb_dict_lookup(dict, key);
2277 gval = export_value_xlat2(container_xlat, lin_val, G_TYPE_STRING);
2279 ghb_dict_insert(dict, g_strdup(key), gval);
2280 key = "VideoFramerate";
2281 lin_val = ghb_dict_lookup(dict, key);
2282 gval = export_value_xlat2(framerate_xlat, lin_val, G_TYPE_STRING);
2284 ghb_dict_insert(dict, g_strdup(key), gval);
2285 key = "PictureDetelecine";
2286 lin_val = ghb_dict_lookup(dict, key);
2287 gval = export_value_xlat2(detel_xlat, lin_val, G_TYPE_INT);
2289 ghb_dict_insert(dict, g_strdup(key), gval);
2290 key = "PictureDecomb";
2291 lin_val = ghb_dict_lookup(dict, key);
2292 gval = export_value_xlat2(decomb_xlat, lin_val, G_TYPE_INT);
2294 ghb_dict_insert(dict, g_strdup(key), gval);
2295 key = "PictureDeinterlace";
2296 lin_val = ghb_dict_lookup(dict, key);
2297 gval = export_value_xlat2(deint_xlat, lin_val, G_TYPE_INT);
2299 ghb_dict_insert(dict, g_strdup(key), gval);
2300 key = "PictureDenoise";
2301 lin_val = ghb_dict_lookup(dict, key);
2302 gval = export_value_xlat2(denoise_xlat, lin_val, G_TYPE_INT);
2304 ghb_dict_insert(dict, g_strdup(key), gval);
2310 slist = ghb_dict_lookup(dict, "SubtitleList");
2311 count = ghb_array_len(slist);
2312 for (ii = 0; ii < count; ii++)
2314 sdict = ghb_array_get_nth(slist, ii);
2315 key = "SubtitleLanguage";
2316 lin_val = ghb_dict_lookup(sdict, key);
2317 gval = export_subtitle_xlat2(lin_val);
2319 ghb_dict_insert(sdict, g_strdup(key), gval);
2325 alist = ghb_dict_lookup(dict, "AudioList");
2326 count = ghb_array_len(alist);
2327 for (ii = 0; ii < count; ii++)
2329 adict = ghb_array_get_nth(alist, ii);
2331 lin_val = ghb_dict_lookup(adict, key);
2332 gval = export_audio_track_xlat2(lin_val);
2334 ghb_dict_insert(adict, g_strdup(key), gval);
2335 key = "AudioEncoder";
2336 lin_val = ghb_dict_lookup(adict, key);
2337 gval = export_value_xlat2(acodec_xlat, lin_val, G_TYPE_STRING);
2339 ghb_dict_insert(adict, g_strdup(key), gval);
2340 key = "AudioSamplerate";
2341 lin_val = ghb_dict_lookup(adict, key);
2342 gval = export_value_xlat2(samplerate_xlat, lin_val, G_TYPE_STRING);
2344 ghb_dict_insert(adict, g_strdup(key), gval);
2345 key = "AudioMixdown";
2346 lin_val = ghb_dict_lookup(adict, key);
2347 gval = export_value_xlat2(mix_xlat, lin_val, G_TYPE_STRING);
2349 ghb_dict_insert(adict, g_strdup(key), gval);
2357 value_map_t *value_map,
2361 GValue *gval, *def_val;
2363 if (mac_val == NULL) return NULL;
2364 def_val = ghb_dict_lookup(defaults, key);
2371 str = ghb_value_string(mac_val);
2372 for (ii = 0; value_map[ii].mac_val; ii++)
2374 if (strcmp(str, value_map[ii].mac_val) == 0)
2376 sval = ghb_string_value_new(value_map[ii].lin_val);
2378 gval = ghb_value_new(G_VALUE_TYPE(def_val));
2379 if (!g_value_transform(sval, gval))
2381 g_warning("can't transform");
2382 ghb_value_free(gval);
2383 ghb_value_free(sval);
2386 ghb_value_free(sval);
2398 str = ghb_value_string(mac_val);
2399 for (ii = 0; value_map[ii].mac_val; ii++)
2401 if (strcmp(str, value_map[ii].mac_val) == 0)
2403 sval = ghb_string_value_new(value_map[ii].lin_val);
2405 gval = ghb_value_new(G_VALUE_TYPE(mac_val));
2406 if (!g_value_transform(sval, gval))
2408 g_warning("can't transform");
2409 ghb_value_free(gval);
2410 ghb_value_free(sval);
2413 ghb_value_free(sval);
2423 import_value_xlat(GValue *dict)
2425 GValue *defaults, *mac_val, *gval;
2428 defaults = plist_get_dict(internalPlist, "Presets");
2429 key = "VideoEncoder";
2430 mac_val = ghb_dict_lookup(dict, key);
2431 gval = import_value_xlat2(defaults, vcodec_xlat, key, mac_val);
2433 ghb_dict_insert(dict, g_strdup(key), gval);
2435 mac_val = ghb_dict_lookup(dict, key);
2436 gval = import_value_xlat2(defaults, container_xlat, key, mac_val);
2438 ghb_dict_insert(dict, g_strdup(key), gval);
2439 key = "VideoFramerate";
2440 mac_val = ghb_dict_lookup(dict, key);
2441 gval = import_value_xlat2(defaults, framerate_xlat, key, mac_val);
2443 ghb_dict_insert(dict, g_strdup(key), gval);
2444 key = "PictureDetelecine";
2445 mac_val = ghb_dict_lookup(dict, key);
2446 gval = import_value_xlat2(defaults, detel_xlat, key, mac_val);
2448 ghb_dict_insert(dict, g_strdup(key), gval);
2449 key = "PictureDecomb";
2450 mac_val = ghb_dict_lookup(dict, key);
2451 gval = import_value_xlat2(defaults, decomb_xlat, key, mac_val);
2453 ghb_dict_insert(dict, g_strdup(key), gval);
2454 key = "PictureDeinterlace";
2455 mac_val = ghb_dict_lookup(dict, key);
2456 gval = import_value_xlat2(defaults, deint_xlat, key, mac_val);
2458 ghb_dict_insert(dict, g_strdup(key), gval);
2459 key = "PictureDenoise";
2460 mac_val = ghb_dict_lookup(dict, key);
2461 gval = import_value_xlat2(defaults, denoise_xlat, key, mac_val);
2463 ghb_dict_insert(dict, g_strdup(key), gval);
2472 sdeflist = ghb_dict_lookup(defaults, "SubtitleList");
2475 slist = ghb_dict_lookup(dict, "SubtitleList");
2478 sdefaults = ghb_array_get_nth(sdeflist, 0);
2479 count = ghb_array_len(slist);
2480 for (ii = 0; ii < count; ii++)
2482 sdict = ghb_array_get_nth(slist, ii);
2483 key = "SubtitleLanguage";
2484 mac_val = ghb_dict_lookup(sdict, key);
2485 gval = import_subtitle_xlat2(mac_val);
2487 ghb_dict_insert(sdict, g_strdup(key), gval);
2494 mac_val = ghb_dict_lookup(dict, key);
2495 slist = ghb_array_value_new(8);
2496 ghb_dict_insert(dict, g_strdup("SubtitleList"), slist);
2501 gval = import_subtitle_xlat2(mac_val);
2502 lang = ghb_value_string(gval);
2503 if (lang && strcasecmp(lang, "none") != 0 && !slist)
2505 sdict = ghb_dict_value_new();
2506 ghb_array_append(slist, sdict);
2507 ghb_dict_insert(sdict, g_strdup("SubtitleLanguage"), gval);
2508 gval = ghb_dict_lookup(dict, "SubtitlesForced");
2511 ghb_dict_insert(sdict, g_strdup("SubtitleForced"),
2512 ghb_value_dup(gval));
2516 ghb_dict_insert(sdict, g_strdup("SubtitleForced"),
2517 ghb_boolean_value_new(FALSE));
2519 ghb_dict_insert(sdict, g_strdup("SubtitleBurned"),
2520 ghb_boolean_value_new(TRUE));
2521 ghb_dict_insert(sdict, g_strdup("SubtitleDefaultTrack"),
2522 ghb_boolean_value_new(FALSE));
2526 ghb_value_free(gval);
2533 ghb_dict_remove(dict, "Subtitles");
2534 ghb_dict_remove(dict, "SubtitlesForced");
2542 adeflist = ghb_dict_lookup(defaults, "AudioList");
2545 adefaults = ghb_array_get_nth(adeflist, 0);
2546 alist = ghb_dict_lookup(dict, "AudioList");
2547 count = ghb_array_len(alist);
2548 for (ii = 0; ii < count; ii++)
2550 adict = ghb_array_get_nth(alist, ii);
2552 mac_val = ghb_dict_lookup(adict, key);
2553 gval = import_audio_track_xlat2(mac_val);
2555 ghb_dict_insert(adict, g_strdup(key), gval);
2556 key = "AudioEncoder";
2557 mac_val = ghb_dict_lookup(adict, key);
2558 gval = import_value_xlat2(adefaults, acodec_xlat, key, mac_val);
2560 ghb_dict_insert(adict, g_strdup(key), gval);
2561 key = "AudioSamplerate";
2562 mac_val = ghb_dict_lookup(adict, key);
2563 gval = import_value_xlat2(adefaults, samplerate_xlat, key, mac_val);
2565 ghb_dict_insert(adict, g_strdup(key), gval);
2566 key = "AudioMixdown";
2567 mac_val = ghb_dict_lookup(adict, key);
2568 gval = import_value_xlat2(adefaults, mix_xlat, key, mac_val);
2570 ghb_dict_insert(adict, g_strdup(key), gval);
2572 mac_val = ghb_dict_lookup(adict, "AudioTrackDRCSlider");
2573 if (mac_val != NULL)
2576 drc = ghb_value_double(mac_val);
2577 if (drc < 1.0 && drc > 0.0)
2579 ghb_dict_insert(adict, g_strdup("AudioTrackDRCSlider"),
2580 ghb_double_value_new(0.0));
2588 import_xlat_preset(GValue *dict)
2595 g_debug("import_xlat_preset ()");
2596 uses_max = ghb_value_boolean(
2597 preset_dict_get_value(dict, "UsesMaxPictureSettings"));
2598 uses_pic = ghb_value_int(
2599 preset_dict_get_value(dict, "UsesPictureSettings"));
2600 par = ghb_value_int(preset_dict_get_value(dict, "PicturePAR"));
2601 vqtype = ghb_value_int(preset_dict_get_value(dict, "VideoQualityType"));
2603 if (uses_max || uses_pic == 2)
2605 ghb_dict_insert(dict, g_strdup("autoscale"),
2606 ghb_boolean_value_new(TRUE));
2612 if (ghb_dict_lookup(dict, "PictureModulus") == NULL)
2613 ghb_dict_insert(dict, g_strdup("PictureModulus"),
2614 ghb_int_value_new(16));
2618 ghb_dict_insert(dict, g_strdup("PictureModulus"),
2619 ghb_int_value_new(1));
2623 if (ghb_dict_lookup(dict, "PictureModulus") == NULL)
2624 ghb_dict_insert(dict, g_strdup("PictureModulus"),
2625 ghb_int_value_new(16));
2629 if (ghb_dict_lookup(dict, "PictureModulus") == NULL)
2630 ghb_dict_insert(dict, g_strdup("PictureModulus"),
2631 ghb_int_value_new(16));
2634 // VideoQualityType/0/1/2 - vquality_type_/target/bitrate/constant
2639 ghb_dict_insert(dict, g_strdup("vquality_type_target"),
2640 ghb_boolean_value_new(TRUE));
2641 ghb_dict_insert(dict, g_strdup("vquality_type_bitrate"),
2642 ghb_boolean_value_new(FALSE));
2643 ghb_dict_insert(dict, g_strdup("vquality_type_constant"),
2644 ghb_boolean_value_new(FALSE));
2648 ghb_dict_insert(dict, g_strdup("vquality_type_target"),
2649 ghb_boolean_value_new(FALSE));
2650 ghb_dict_insert(dict, g_strdup("vquality_type_bitrate"),
2651 ghb_boolean_value_new(TRUE));
2652 ghb_dict_insert(dict, g_strdup("vquality_type_constant"),
2653 ghb_boolean_value_new(FALSE));
2657 ghb_dict_insert(dict, g_strdup("vquality_type_target"),
2658 ghb_boolean_value_new(FALSE));
2659 ghb_dict_insert(dict, g_strdup("vquality_type_bitrate"),
2660 ghb_boolean_value_new(FALSE));
2661 ghb_dict_insert(dict, g_strdup("vquality_type_constant"),
2662 ghb_boolean_value_new(TRUE));
2666 ghb_dict_insert(dict, g_strdup("vquality_type_target"),
2667 ghb_boolean_value_new(FALSE));
2668 ghb_dict_insert(dict, g_strdup("vquality_type_bitrate"),
2669 ghb_boolean_value_new(FALSE));
2670 ghb_dict_insert(dict, g_strdup("vquality_type_constant"),
2671 ghb_boolean_value_new(TRUE));
2674 import_value_xlat(dict);
2679 vquality = ghb_value_double(preset_dict_get_value(dict, "VideoQualitySlider"));
2680 if (vquality > 0.0 && vquality < 1.0)
2684 gval = preset_dict_get_value(dict, "VideoEncoder");
2685 vcodec = ghb_lookup_combo_int("VideoEncoder", gval);
2688 case HB_VCODEC_X264:
2690 vquality = 51. - vquality * 51.;
2693 case HB_VCODEC_FFMPEG:
2695 vquality = 31. - vquality * 30.;
2698 case HB_VCODEC_THEORA:
2700 vquality = vquality * 63.;
2708 ghb_dict_insert(dict, g_strdup("VideoQualitySlider"),
2709 ghb_double_value_new(vquality));
2714 import_xlat_presets(GValue *presets)
2720 g_debug("import_xlat_presets ()");
2721 if (presets == NULL) return;
2722 count = ghb_array_len(presets);
2723 for (ii = 0; ii < count; ii++)
2725 dict = ghb_array_get_nth(presets, ii);
2726 folder = ghb_value_boolean(preset_dict_get_value(dict, "Folder"));
2731 nested = ghb_dict_lookup(dict, "ChildrenArray");
2732 import_xlat_presets(nested);
2736 import_xlat_preset(dict);
2742 export_xlat_preset(GValue *dict)
2744 gboolean autoscale, target, br, constant;
2746 g_debug("export_xlat_prest ()");
2747 autoscale = ghb_value_boolean(preset_dict_get_value(dict, "autoscale"));
2748 target = ghb_value_boolean(
2749 preset_dict_get_value(dict, "vquality_type_target"));
2750 br = ghb_value_boolean(
2751 preset_dict_get_value(dict, "vquality_type_bitrate"));
2752 constant = ghb_value_boolean(
2753 preset_dict_get_value(dict, "vquality_type_constant"));
2756 ghb_dict_insert(dict, g_strdup("UsesPictureSettings"),
2757 ghb_int_value_new(2));
2759 ghb_dict_insert(dict, g_strdup("UsesPictureSettings"),
2760 ghb_int_value_new(1));
2762 // VideoQualityType/0/1/2 - vquality_type_/target/bitrate/constant
2765 ghb_dict_insert(dict, g_strdup("VideoQualityType"),
2766 ghb_int_value_new(0));
2770 ghb_dict_insert(dict, g_strdup("VideoQualityType"),
2771 ghb_int_value_new(1));
2775 ghb_dict_insert(dict, g_strdup("VideoQualityType"),
2776 ghb_int_value_new(2));
2779 GValue *alist, *adict;
2782 alist = ghb_dict_lookup(dict, "AudioList");
2783 count = ghb_array_len(alist);
2784 for (ii = 0; ii < count; ii++)
2788 adict = ghb_array_get_nth(alist, ii);
2789 drc = ghb_value_double(
2790 preset_dict_get_value(adict, "AudioTrackDRCSlider"));
2791 if (drc < 1.0 && drc > 0.0)
2793 ghb_dict_insert(adict, g_strdup("AudioTrackDRCSlider"),
2794 ghb_double_value_new(0.0));
2798 ghb_dict_remove(dict, "UsesMaxPictureSettings");
2799 ghb_dict_remove(dict, "autoscale");
2800 ghb_dict_remove(dict, "vquality_type_target");
2801 ghb_dict_remove(dict, "vquality_type_bitrate");
2802 ghb_dict_remove(dict, "vquality_type_constant");
2803 export_value_xlat(dict);
2807 export_xlat_presets(GValue *presets)
2813 if (presets == NULL) return;
2814 count = ghb_array_len(presets);
2815 for (ii = 0; ii < count; ii++)
2817 dict = ghb_array_get_nth(presets, ii);
2818 folder = ghb_value_boolean(preset_dict_get_value(dict, "Folder"));
2823 nested = ghb_dict_lookup(dict, "ChildrenArray");
2824 export_xlat_presets(nested);
2828 export_xlat_preset(dict);
2833 static guint prefs_timeout_id = 0;
2836 delayed_store_prefs(gpointer data)
2838 store_plist(prefsPlist, "preferences");
2839 prefs_timeout_id = 0;
2848 export = ghb_value_dup(presetsPlist);
2849 export_xlat_presets(export);
2850 store_plist(export, "presets");
2851 ghb_value_free(export);
2857 if (prefs_timeout_id != 0)
2862 mc = g_main_context_default();
2863 source = g_main_context_find_source_by_id(mc, prefs_timeout_id);
2865 g_source_destroy(source);
2867 prefs_timeout_id = g_timeout_add_seconds(1, (GSourceFunc)delayed_store_prefs, NULL);
2871 ghb_presets_reload(signal_user_data_t *ud)
2873 GValue *std_presets;
2877 g_debug("ghb_presets_reload()\n");
2878 std_presets = ghb_resource_get("standard-presets");
2879 if (std_presets == NULL) return;
2881 remove_std_presets(ud);
2882 indices = presets_find_default(presetsPlist, &len);
2885 presets_clear_default(std_presets);
2888 // Merge the keyfile contents into our presets
2889 count = ghb_array_len(std_presets);
2890 for (ii = count-1; ii >= 0; ii--)
2896 std_dict = ghb_array_get_nth(std_presets, ii);
2897 copy_dict = ghb_value_dup(std_dict);
2898 ghb_dict_insert(copy_dict, g_strdup("PresetBuildNumber"),
2899 ghb_int64_value_new(hb_get_build(NULL)));
2900 ghb_presets_insert(presetsPlist, copy_dict, &indices, 1);
2901 presets_list_insert(ud, &indices, 1);
2903 import_xlat_presets(presetsPlist);
2912 count = ghb_array_len(presetsPlist);
2913 for (ii = count-1; ii >= 0; ii--)
2918 dict = ghb_array_get_nth(presetsPlist, ii);
2919 type = ghb_dict_lookup(dict, "Type");
2927 replace_standard_presets()
2929 GValue *std_presets;
2933 count = ghb_array_len(presetsPlist);
2934 for (ii = count-1; ii >= 0; ii--)
2939 dict = ghb_array_get_nth(presetsPlist, ii);
2940 ptype = ghb_value_int(preset_dict_get_value(dict, "Type"));
2941 if (ptype == PRESETS_BUILTIN)
2944 ghb_presets_remove(presetsPlist, &indices, 1);
2948 std_presets = ghb_resource_get("standard-presets");
2949 if (std_presets == NULL) return;
2951 indices = presets_find_default(presetsPlist, &len);
2954 presets_clear_default(std_presets);
2957 // Merge the keyfile contents into our presets
2958 count = ghb_array_len(std_presets);
2959 for (ii = count-1; ii >= 0; ii--)
2965 std_dict = ghb_array_get_nth(std_presets, ii);
2966 copy_dict = ghb_value_dup(std_dict);
2967 ghb_dict_insert(copy_dict, g_strdup("PresetBuildNumber"),
2968 ghb_int64_value_new(hb_get_build(NULL)));
2969 ghb_presets_insert(presetsPlist, copy_dict, &indices, 1);
2971 import_xlat_presets(presetsPlist);
2976 update_standard_presets(signal_user_data_t *ud)
2980 count = ghb_array_len(presetsPlist);
2981 for (ii = count-1; ii >= 0; ii--)
2988 dict = ghb_array_get_nth(presetsPlist, ii);
2989 gval = ghb_dict_lookup(dict, "Type");
2992 // Old preset that doesn't have a Type
2993 replace_standard_presets();
2997 type = ghb_value_int(gval);
3000 gval = ghb_dict_lookup(dict, "PresetBuildNumber");
3003 // Old preset that doesn't have a build number
3004 replace_standard_presets();
3008 build = ghb_value_int64(gval);
3009 if (build != hb_get_build(NULL))
3011 // Build number does not match
3012 replace_standard_presets();
3021 ghb_presets_load(signal_user_data_t *ud)
3023 presetsPlist = load_plist("presets");
3024 if (presetsPlist == NULL)
3026 presetsPlist = ghb_value_dup(ghb_resource_get("standard-presets"));
3027 import_xlat_presets(presetsPlist);
3030 else if (G_VALUE_TYPE(presetsPlist) == ghb_dict_get_type())
3031 { // Presets is older dictionary format. Convert to array
3032 ghb_value_free(presetsPlist);
3033 presetsPlist = ghb_value_dup(ghb_resource_get("standard-presets"));
3034 import_xlat_presets(presetsPlist);
3037 else if (check_old_presets())
3039 ghb_value_free(presetsPlist);
3040 presetsPlist = ghb_value_dup(ghb_resource_get("standard-presets"));
3041 import_xlat_presets(presetsPlist);
3044 update_standard_presets(ud);
3045 import_xlat_presets(presetsPlist);
3049 settings_save(signal_user_data_t *ud, const GValue *path)
3051 GValue *dict, *internal;
3052 GHashTableIter iter;
3056 gint *indices, len, count;
3057 gint *def_indices, def_len;
3059 gboolean replace = FALSE;
3061 g_debug("settings_save");
3062 if (internalPlist == NULL) return;
3063 count = ghb_array_len(path);
3064 name = g_value_get_string(ghb_array_get_nth(path, count-1));
3065 indices = ghb_preset_indices_from_path(presetsPlist, path, &len);
3068 if (ghb_presets_get_folder(presetsPlist, indices, len))
3071 message = g_strdup_printf(
3072 "%s: Folder already exists.\n"
3073 "You can not replace it with a preset.",
3075 ghb_message_dialog(GTK_MESSAGE_ERROR, message, "Cancel", NULL);
3079 dict = ghb_dict_value_new();
3080 ghb_presets_replace(presetsPlist, dict, indices, len);
3085 indices = presets_find_pos(path, PRESETS_CUSTOM, &len);
3088 dict = ghb_dict_value_new();
3089 ghb_presets_insert(presetsPlist, dict, indices, len);
3093 g_warning("failed to find insert path");
3097 current_preset = dict;
3098 autoscale = ghb_settings_get_boolean(ud->settings, "autoscale");
3099 ghb_settings_set_int64(ud->settings, "Type", PRESETS_CUSTOM);
3100 ghb_settings_set_int64(ud->settings, "PresetBuildNumber", hb_get_build(NULL));
3102 internal = plist_get_dict(internalPlist, "Presets");
3103 ghb_dict_iter_init(&iter, internal);
3104 // middle (void*) cast prevents gcc warning "defreferencing type-punned
3105 // pointer will break strict-aliasing rules"
3106 while (g_hash_table_iter_next(
3107 &iter, (gpointer*)(void*)&key, (gpointer*)(void*)&value))
3115 if (strcmp(key, "PictureWidth") == 0)
3117 key2 = "scale_width";
3119 else if (strcmp(key, "PictureHeight") == 0)
3121 key2 = "scale_height";
3124 gval = ghb_settings_get_value(ud->settings, key2);
3129 ghb_dict_insert(dict, g_strdup(key), ghb_value_dup(gval));
3131 internal = plist_get_dict(internalPlist, "XlatPresets");
3132 ghb_dict_iter_init(&iter, internal);
3133 // middle (void*) cast prevents gcc warning "defreferencing type-punned
3134 // pointer will break strict-aliasing rules"
3135 while (g_hash_table_iter_next(
3136 &iter, (gpointer*)(void*)&key, (gpointer*)(void*)&value))
3140 gval = ghb_settings_get_value(ud->settings, key);
3145 ghb_dict_insert(dict, g_strdup(key), ghb_value_dup(gval));
3147 ghb_dict_insert(dict, g_strdup("PresetName"), ghb_string_value_new(name));
3150 def_indices = presets_find_default(presetsPlist, &def_len);
3151 if (def_indices != NULL &&
3152 preset_path_cmp(indices, len, def_indices, def_len) != 0)
3154 ghb_dict_insert(dict, g_strdup("Default"),
3155 ghb_boolean_value_new(FALSE));
3157 presets_list_update_item(ud, indices, len, FALSE);
3161 ghb_dict_insert(dict, g_strdup("Default"),
3162 ghb_boolean_value_new(FALSE));
3163 presets_list_insert(ud, indices, len);
3166 ud->dont_clear_presets = TRUE;
3167 // Make the new preset the selected item
3168 ghb_select_preset2(ud->builder, indices, len);
3170 ud->dont_clear_presets = FALSE;
3175 folder_save(signal_user_data_t *ud, const GValue *path)
3177 GValue *dict, *folder;
3178 gint *indices, len, count;
3181 count = ghb_array_len(path);
3182 name = g_value_get_string(ghb_array_get_nth(path, count-1));
3183 indices = ghb_preset_indices_from_path(presetsPlist, path, &len);
3186 if (!ghb_presets_get_folder(presetsPlist, indices, len))
3189 message = g_strdup_printf(
3190 "%s: Preset already exists.\n"
3191 "You can not replace it with a folder.",
3193 ghb_message_dialog(GTK_MESSAGE_ERROR, message, "Cancel", NULL);
3198 // Already exists, update its description
3199 dict = presets_get_dict(presetsPlist, indices, len);
3200 ghb_dict_insert(dict, g_strdup("PresetDescription"),
3201 ghb_value_dup(preset_dict_get_value(
3202 ud->settings, "PresetDescription")));
3203 presets_list_update_item(ud, indices, len, FALSE);
3210 indices = presets_find_pos(path, PRESETS_CUSTOM, &len);
3213 dict = ghb_dict_value_new();
3214 ghb_presets_insert(presetsPlist, dict, indices, len);
3218 g_warning("failed to find insert path");
3222 ghb_dict_insert(dict, g_strdup("PresetDescription"),
3223 ghb_value_dup(preset_dict_get_value(
3224 ud->settings, "PresetDescription")));
3225 ghb_dict_insert(dict, g_strdup("PresetName"), ghb_string_value_new(name));
3226 folder = ghb_array_value_new(8);
3227 ghb_dict_insert(dict, g_strdup("ChildrenArray"), folder);
3228 ghb_dict_insert(dict, g_strdup("Type"),
3229 ghb_int64_value_new(PRESETS_CUSTOM));
3230 ghb_dict_insert(dict, g_strdup("Folder"), ghb_boolean_value_new(TRUE));
3232 presets_list_insert(ud, indices, len);
3239 ghb_presets_list_default(signal_user_data_t *ud)
3241 GtkTreeView *treeview;
3242 GtkTreePath *treepath;
3244 GtkTreeStore *store;
3247 g_debug("ghb_presets_list_default ()");
3248 treeview = GTK_TREE_VIEW(GHB_WIDGET(ud->builder, "presets_list"));
3249 store = GTK_TREE_STORE(gtk_tree_view_get_model(treeview));
3250 indices = presets_find_default(presetsPlist, &len);
3251 if (indices == NULL) return;
3252 treepath = ghb_tree_path_new_from_indices(indices, len);
3255 if (gtk_tree_model_get_iter(GTK_TREE_MODEL(store), &iter, treepath))
3257 gtk_tree_store_set(store, &iter,
3262 gtk_tree_path_free(treepath);
3268 ghb_presets_list_clear_default(signal_user_data_t *ud)
3270 GtkTreeView *treeview;
3271 GtkTreePath *treepath;
3273 GtkTreeStore *store;
3276 g_debug("ghb_presets_list_clear_default ()");
3277 treeview = GTK_TREE_VIEW(GHB_WIDGET(ud->builder, "presets_list"));
3278 store = GTK_TREE_STORE(gtk_tree_view_get_model(treeview));
3279 indices = presets_find_default(presetsPlist, &len);
3280 if (indices == NULL) return;
3281 treepath = ghb_tree_path_new_from_indices(indices, len);
3284 if (gtk_tree_model_get_iter(GTK_TREE_MODEL(store), &iter, treepath))
3286 gtk_tree_store_set(store, &iter,
3291 gtk_tree_path_free(treepath);
3297 update_audio_presets(signal_user_data_t *ud)
3299 g_debug("update_audio_presets");
3300 const GValue *audio_list;
3302 audio_list = ghb_settings_get_value(ud->settings, "audio_list");
3303 ghb_settings_set_value(ud->settings, "AudioList", audio_list);
3307 update_subtitle_presets(signal_user_data_t *ud)
3309 g_debug("update_subtitle_presets");
3310 const GValue *subtitle_list, *subtitle;
3311 GValue *slist, *dict;
3312 gint count, ii, source;
3314 subtitle_list = ghb_settings_get_value(ud->settings, "subtitle_list");
3315 slist = ghb_array_value_new(8);
3316 count = ghb_array_len(subtitle_list);
3317 for (ii = 0; ii < count; ii++)
3319 subtitle = ghb_array_get_nth(subtitle_list, ii);
3320 source = ghb_settings_get_int(subtitle, "SubtitleSource");
3321 if (source != SRTSUB)
3323 dict = ghb_value_dup(subtitle);
3324 ghb_array_append(slist, dict);
3327 ghb_settings_take_value(ud->settings, "SubtitleList", slist);
3330 G_MODULE_EXPORT void
3331 presets_menu_clicked_cb(GtkWidget *xwidget, signal_user_data_t *ud)
3335 menu = GTK_MENU(GHB_WIDGET(ud->builder, "presets_menu"));
3336 gtk_menu_popup(menu, NULL, NULL, NULL, NULL, 1,
3337 gtk_get_current_event_time());
3340 G_MODULE_EXPORT void
3341 preset_import_clicked_cb(GtkWidget *xwidget, signal_user_data_t *ud)
3344 GtkResponseType response;
3347 GtkFileFilter *filter;
3349 g_debug("preset_import_clicked_cb ()");
3351 dialog = gtk_file_chooser_dialog_new("Import Preset", NULL,
3352 GTK_FILE_CHOOSER_ACTION_OPEN,
3353 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
3354 GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
3357 filter = gtk_file_filter_new();
3358 gtk_file_filter_set_name(filter, "All (*)");
3359 gtk_file_filter_add_pattern(filter, "*");
3360 gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(dialog), filter);
3362 filter = gtk_file_filter_new();
3363 gtk_file_filter_set_name(filter, "Presets (*.plist)");
3364 gtk_file_filter_add_pattern(filter, "*.plist");
3365 gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(dialog), filter);
3366 gtk_file_chooser_set_filter(GTK_FILE_CHOOSER(dialog), filter);
3368 exportDir = ghb_settings_get_string(ud->settings, "ExportDirectory");
3369 if (exportDir == NULL || exportDir[0] == '\0')
3371 exportDir = g_strdup(".");
3373 gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(dialog), exportDir);
3376 response = gtk_dialog_run(GTK_DIALOG(dialog));
3377 gtk_widget_hide(dialog);
3378 if (response == GTK_RESPONSE_ACCEPT)
3380 GValue *dict, *array;
3384 filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog));
3386 // import the preset
3387 if (!g_file_test(filename, G_FILE_TEST_IS_REGULAR))
3389 gtk_widget_destroy(dialog);
3393 array = ghb_plist_parse_file(filename);
3395 import_xlat_presets(array);
3396 presets_clear_default(array);
3397 presets_customize(array);
3399 count = ghb_array_len(array);
3400 for (ii = 0; ii < count; ii++)
3402 GValue *path, *name;
3406 dict = ghb_array_get_nth(array, ii);
3407 path = ghb_array_value_new(1);
3408 name = ghb_value_dup(ghb_dict_lookup(dict, "PresetName"));
3409 ghb_array_append(path, name);
3410 indices = ghb_preset_indices_from_path(presetsPlist, path, &len);
3411 // Modify the preset name till we make it unique
3412 while (indices != NULL)
3414 gchar *str = ghb_value_string(name);
3416 ghb_value_free(path);
3419 str = g_strdup_printf("%s %d", str, index);
3420 path = ghb_array_value_new(1);
3421 name = ghb_string_value_new(str);
3422 ghb_array_append(path, name);
3426 indices = ghb_preset_indices_from_path(presetsPlist, path, &len);
3428 ghb_dict_insert(dict, g_strdup("PresetName"), ghb_value_dup(name));
3429 indices = presets_find_pos(path, PRESETS_CUSTOM, &len);
3430 ghb_presets_insert(presetsPlist, ghb_value_dup(dict), indices, len);
3431 presets_list_insert(ud, indices, len);
3432 ghb_value_free(path);
3434 ghb_value_free(array);
3436 exportDir = ghb_settings_get_string(ud->settings, "ExportDirectory");
3437 dir = g_path_get_dirname(filename);
3438 if (strcmp(dir, exportDir) != 0)
3440 ghb_settings_set_string(ud->settings, "ExportDirectory", dir);
3441 ghb_pref_save(ud->settings, "ExportDirectory");
3448 gtk_widget_destroy(dialog);
3451 G_MODULE_EXPORT void
3452 preset_export_clicked_cb(GtkWidget *xwidget, signal_user_data_t *ud)
3455 GtkResponseType response;
3457 const gchar *name = "";
3458 gint count, *indices, len;
3462 g_debug("preset_export_clicked_cb ()");
3463 preset = ghb_settings_get_value (ud->settings, "preset_selection");
3467 count = ghb_array_len(preset);
3471 name = g_value_get_string(ghb_array_get_nth(preset, count-1));
3473 dialog = gtk_file_chooser_dialog_new("Export Preset", NULL,
3474 GTK_FILE_CHOOSER_ACTION_SAVE,
3475 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
3476 GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT,
3479 exportDir = ghb_settings_get_string(ud->settings, "ExportDirectory");
3480 if (exportDir == NULL || exportDir[0] == '\0')
3482 exportDir = g_strdup(".");
3484 filename = g_strdup_printf("%s.plist", name);
3485 gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(dialog), exportDir);
3486 gtk_file_chooser_set_current_name(GTK_FILE_CHOOSER(dialog), filename);
3490 indices = ghb_preset_indices_from_path(presetsPlist, preset, &len);
3491 if (indices == NULL)
3494 response = gtk_dialog_run(GTK_DIALOG(dialog));
3495 gtk_widget_hide(dialog);
3496 if (response == GTK_RESPONSE_ACCEPT)
3498 GValue *export, *dict, *array;
3502 filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog));
3504 // export the preset
3505 dict = presets_get_dict(presetsPlist, indices, len);
3507 export = ghb_value_dup(dict);
3508 array = ghb_array_value_new(1);
3509 ghb_array_append(array, export);
3510 presets_clear_default(array);
3511 presets_customize(array);
3512 export_xlat_presets(array);
3514 file = g_fopen(filename, "w");
3517 ghb_plist_write(file, array);
3520 ghb_value_free(array);
3522 exportDir = ghb_settings_get_string(ud->settings, "ExportDirectory");
3523 dir = g_path_get_dirname(filename);
3524 if (strcmp(dir, exportDir) != 0)
3526 ghb_settings_set_string(ud->settings, "ExportDirectory", dir);
3527 ghb_pref_save(ud->settings, "ExportDirectory");
3533 gtk_widget_destroy(dialog);
3537 G_MODULE_EXPORT void
3538 presets_new_folder_clicked_cb(GtkWidget *xwidget, signal_user_data_t *ud)
3543 GtkResponseType response;
3544 GValue *preset, *dict;
3545 const gchar *name = "";
3546 const gchar *description = "";
3547 gint count, *indices, len;
3549 g_debug("presets_save_clicked_cb ()");
3550 preset = ghb_settings_get_value (ud->settings, "preset_selection");
3552 count = ghb_array_len(preset);
3554 name = g_value_get_string(ghb_array_get_nth(preset, count-1));
3558 indices = ghb_preset_indices_from_path(presetsPlist, preset, &len);
3559 dict = presets_get_dict(presetsPlist, indices, len);
3562 description = g_value_get_string(
3563 ghb_dict_lookup(dict, "PresetDescription"));
3564 ghb_ui_update(ud, "PresetDescription", ghb_string_value(description));
3567 desc = GTK_TEXT_VIEW(GHB_WIDGET(ud->builder, "PresetDescription"));
3568 dialog = GHB_WIDGET(ud->builder, "preset_save_dialog");
3569 entry = GTK_ENTRY(GHB_WIDGET(ud->builder, "PresetName"));
3570 gtk_entry_set_text(entry, name);
3571 response = gtk_dialog_run(GTK_DIALOG(dialog));
3572 gtk_widget_hide(dialog);
3573 if (response == GTK_RESPONSE_OK)
3576 const gchar *name = gtk_entry_get_text(entry);
3579 if (count > MAX_NESTED_PRESET-1)
3580 count = MAX_NESTED_PRESET-1;
3582 dest = ghb_array_value_new(MAX_NESTED_PRESET);
3583 if (indices != NULL)
3587 ptype = ghb_presets_get_type(presetsPlist, indices, len);
3588 if (ptype == PRESETS_CUSTOM)
3590 ghb_array_copy(dest, preset, count-1);
3593 ghb_array_append(dest, ghb_string_value_new(name));
3594 ghb_widget_to_setting(ud->settings, GTK_WIDGET(desc));
3595 folder_save(ud, dest);
3596 ghb_value_free(dest);
3598 if (indices != NULL)
3602 G_MODULE_EXPORT void
3603 presets_save_clicked_cb(GtkWidget *xwidget, signal_user_data_t *ud)
3608 GtkResponseType response;
3610 const gchar *name = "";
3611 gint count, *indices, len;
3613 g_debug("presets_save_clicked_cb ()");
3614 preset = ghb_settings_get_value (ud->settings, "preset_selection");
3616 count = ghb_array_len(preset);
3618 name = g_value_get_string(ghb_array_get_nth(preset, count-1));
3622 desc = GTK_TEXT_VIEW(GHB_WIDGET(ud->builder, "PresetDescription"));
3623 dialog = GHB_WIDGET(ud->builder, "preset_save_dialog");
3624 entry = GTK_ENTRY(GHB_WIDGET(ud->builder, "PresetName"));
3625 gtk_entry_set_text(entry, name);
3626 response = gtk_dialog_run(GTK_DIALOG(dialog));
3627 gtk_widget_hide(dialog);
3628 if (response == GTK_RESPONSE_OK)
3631 const gchar *name = gtk_entry_get_text(entry);
3634 dest = ghb_array_value_new(MAX_NESTED_PRESET);
3635 indices = ghb_preset_indices_from_path(presetsPlist, preset, &len);
3640 ptype = ghb_presets_get_type(presetsPlist, indices, len);
3641 if (ptype == PRESETS_CUSTOM)
3643 ghb_array_copy(dest, preset, count-1);
3647 ghb_array_append(dest, ghb_string_value_new(name));
3649 ghb_widget_to_setting(ud->settings, GTK_WIDGET(desc));
3651 // Construct the audio settings presets from the current audio list
3652 update_audio_presets(ud);
3653 update_subtitle_presets(ud);
3654 settings_save(ud, dest);
3655 ghb_value_free(dest);
3659 G_MODULE_EXPORT void
3660 preset_type_changed_cb(GtkWidget *widget, signal_user_data_t *ud)
3662 ghb_widget_to_setting(ud->settings, widget);
3665 G_MODULE_EXPORT void
3666 presets_restore_clicked_cb(GtkWidget *xwidget, signal_user_data_t *ud)
3670 g_debug("presets_restore_clicked_cb ()");
3671 // Reload only the standard presets
3672 ghb_presets_reload(ud);
3673 // Updating the presets list shuffles things around
3674 // need to make sure the proper preset is selected
3675 preset = ghb_settings_get_value (ud->settings, "preset");
3676 ghb_select_preset(ud->builder, preset);
3679 G_MODULE_EXPORT void
3680 presets_remove_clicked_cb(GtkWidget *xwidget, signal_user_data_t *ud)
3682 GtkTreeView *treeview;
3683 GtkTreeSelection *selection;
3684 GtkTreeModel *store;
3687 GtkResponseType response;
3689 g_debug("presets_remove_clicked_cb ()");
3690 treeview = GTK_TREE_VIEW(GHB_WIDGET(ud->builder, "presets_list"));
3691 selection = gtk_tree_view_get_selection (treeview);
3692 if (gtk_tree_selection_get_selected(selection, &store, &iter))
3699 gtk_tree_model_get(store, &iter, 0, &preset, -1);
3700 path = gtk_tree_model_get_path(store, &iter);
3701 indices = gtk_tree_path_get_indices(path);
3702 len = gtk_tree_path_get_depth(path);
3704 folder = ghb_presets_get_folder(presetsPlist, indices, len);
3705 dialog = gtk_message_dialog_new(NULL, GTK_DIALOG_MODAL,
3706 GTK_MESSAGE_QUESTION, GTK_BUTTONS_YES_NO,
3707 "Confirm deletion of %s:\n\n%s",
3708 folder ? "folder" : "preset",
3710 response = gtk_dialog_run(GTK_DIALOG(dialog));
3711 gtk_widget_destroy (dialog);
3712 if (response == GTK_RESPONSE_YES)
3714 GtkTreeIter nextIter = iter;
3715 gboolean valid = TRUE;
3716 if (!gtk_tree_model_iter_next(store, &nextIter))
3718 if (!gtk_tree_model_iter_parent(store, &nextIter, &iter))
3723 // Remove the selected item
3724 // First unselect it so that selecting the new item works properly
3725 gtk_tree_selection_unselect_iter (selection, &iter);
3726 if (ghb_presets_remove(presetsPlist, indices, len))
3729 presets_list_remove(ud, indices, len);
3732 valid = gtk_tree_model_get_iter_first(store, &nextIter);
3735 gtk_tree_path_free(path);
3736 path = gtk_tree_model_get_path(store, &nextIter);
3737 indices = gtk_tree_path_get_indices(path);
3738 len = gtk_tree_path_get_depth(path);
3739 ghb_select_preset2(ud->builder, indices, len);
3743 gtk_tree_path_free(path);
3747 // controls where valid drop locations are
3748 G_MODULE_EXPORT gboolean
3749 presets_drag_motion_cb(
3751 GdkDragContext *ctx,
3755 signal_user_data_t *ud)
3757 GtkTreePath *path = NULL;
3758 GtkTreeViewDropPosition drop_pos;
3762 GtkTreeModel *model;
3763 GtkTreeSelection *select;
3764 gint src_ptype, dst_ptype;
3765 gboolean src_folder, dst_folder;
3767 gint tree_depth, ii;
3770 widget = gtk_drag_get_source_widget(ctx);
3771 if (widget == NULL || widget != GTK_WIDGET(tv))
3774 // Get the type of the object being dragged
3775 srctv = GTK_TREE_VIEW(gtk_drag_get_source_widget(ctx));
3776 select = gtk_tree_view_get_selection (srctv);
3777 gtk_tree_selection_get_selected (select, &model, &iter);
3778 path = gtk_tree_model_get_path (model, &iter);
3779 indices = gtk_tree_path_get_indices(path);
3780 len = gtk_tree_path_get_depth(path);
3782 preset = presets_get_dict(presetsPlist, indices, len);
3783 tree_depth = preset_tree_depth(preset);
3785 src_ptype = ghb_presets_get_type(presetsPlist, indices, len);
3786 src_folder = ghb_presets_get_folder(presetsPlist, indices, len);
3787 gtk_tree_path_free(path);
3789 if (src_folder && tree_depth == 1)
3792 // The rest checks that the destination is a valid position
3794 gtk_tree_view_get_dest_row_at_pos (tv, x, y, &path, &drop_pos);
3797 gdk_drag_status(ctx, 0, time);
3800 // Don't allow repositioning of builtin presets
3801 if (src_ptype != PRESETS_CUSTOM)
3803 gdk_drag_status(ctx, 0, time);
3807 len = gtk_tree_path_get_depth(path);
3808 if (len+tree_depth-1 >= MAX_NESTED_PRESET)
3810 if (drop_pos == GTK_TREE_VIEW_DROP_INTO_OR_BEFORE)
3811 drop_pos = GTK_TREE_VIEW_DROP_BEFORE;
3812 if (drop_pos == GTK_TREE_VIEW_DROP_INTO_OR_AFTER)
3813 drop_pos = GTK_TREE_VIEW_DROP_AFTER;
3815 for (ii = len+tree_depth-1; ii > MAX_NESTED_PRESET; ii--)
3816 gtk_tree_path_up(path);
3817 indices = gtk_tree_path_get_indices(path);
3818 len = gtk_tree_path_get_depth(path);
3819 dst_ptype = ghb_presets_get_type(presetsPlist, indices, len);
3820 dst_folder = ghb_presets_get_folder(presetsPlist, indices, len);
3821 // Don't allow mixing custom presets in the builtins
3822 if (dst_ptype != PRESETS_CUSTOM)
3824 gdk_drag_status(ctx, 0, time);
3828 // Only allow *drop into* for folders
3831 if (drop_pos == GTK_TREE_VIEW_DROP_INTO_OR_BEFORE)
3832 drop_pos = GTK_TREE_VIEW_DROP_BEFORE;
3833 if (drop_pos == GTK_TREE_VIEW_DROP_INTO_OR_AFTER)
3834 drop_pos = GTK_TREE_VIEW_DROP_AFTER;
3837 len = gtk_tree_path_get_depth(path);
3838 gtk_tree_view_set_drag_dest_row(tv, path, drop_pos);
3839 gtk_tree_path_free(path);
3840 gdk_drag_status(ctx, GDK_ACTION_MOVE, time);
3844 G_MODULE_EXPORT void
3846 GtkTreeView *dstwidget,
3849 GtkSelectionData *selection_data,
3850 guint info, guint t,
3851 signal_user_data_t *ud)
3853 GtkTreePath *path = NULL;
3854 GtkTreeViewDropPosition drop_pos;
3855 GtkTreeIter dstiter, srciter;
3856 gint *dst_indices, dst_len, *src_indices, src_len;
3858 gboolean src_folder, dst_folder;
3860 GtkTreeModel *dstmodel = gtk_tree_view_get_model(dstwidget);
3862 g_debug("preset_drag_cb ()");
3863 // This doesn't work here for some reason...
3864 // gtk_tree_view_get_drag_dest_row(dstwidget, &path, &drop_pos);
3865 gtk_tree_view_get_dest_row_at_pos (dstwidget, x, y, &path, &drop_pos);
3866 // This little hack is needed because attempting to drop after
3867 // the last item gives us no path or drop_pos.
3872 n_children = gtk_tree_model_iter_n_children(dstmodel, NULL);
3875 drop_pos = GTK_TREE_VIEW_DROP_AFTER;
3876 path = gtk_tree_path_new_from_indices(n_children-1, -1);
3880 drop_pos = GTK_TREE_VIEW_DROP_BEFORE;
3881 path = gtk_tree_path_new_from_indices(0, -1);
3886 GtkTreeView *srcwidget;
3887 GtkTreeModel *srcmodel;
3888 GtkTreeSelection *select;
3889 GtkTreePath *srcpath = NULL;
3891 gint tree_depth, ii;
3893 srcwidget = GTK_TREE_VIEW(gtk_drag_get_source_widget(dc));
3894 select = gtk_tree_view_get_selection (srcwidget);
3895 gtk_tree_selection_get_selected (select, &srcmodel, &srciter);
3897 srcpath = gtk_tree_model_get_path (srcmodel, &srciter);
3898 src_indices = gtk_tree_path_get_indices(srcpath);
3899 src_len = gtk_tree_path_get_depth(srcpath);
3900 src_ptype = ghb_presets_get_type(presetsPlist, src_indices, src_len);
3901 src_folder = ghb_presets_get_folder(presetsPlist, src_indices, src_len);
3902 preset = ghb_value_dup(
3903 presets_get_dict(presetsPlist, src_indices, src_len));
3904 gtk_tree_path_free(srcpath);
3906 // Don't allow repositioning of builtin presets
3907 if (src_ptype != PRESETS_CUSTOM)
3910 tree_depth = preset_tree_depth(preset);
3911 if (src_folder && tree_depth == 1)
3914 dst_len = gtk_tree_path_get_depth(path);
3915 if (dst_len+tree_depth-1 >= MAX_NESTED_PRESET)
3917 if (drop_pos == GTK_TREE_VIEW_DROP_INTO_OR_BEFORE)
3918 drop_pos = GTK_TREE_VIEW_DROP_BEFORE;
3919 if (drop_pos == GTK_TREE_VIEW_DROP_INTO_OR_AFTER)
3920 drop_pos = GTK_TREE_VIEW_DROP_AFTER;
3923 for (ii = dst_len+tree_depth-1; ii > MAX_NESTED_PRESET; ii--)
3924 gtk_tree_path_up(path);
3925 dst_indices = gtk_tree_path_get_indices(path);
3926 dst_len = gtk_tree_path_get_depth(path);
3927 dst_folder = ghb_presets_get_folder(presetsPlist, dst_indices, dst_len);
3928 // Only allow *drop into* for folders
3931 if (drop_pos == GTK_TREE_VIEW_DROP_INTO_OR_BEFORE)
3932 drop_pos = GTK_TREE_VIEW_DROP_BEFORE;
3933 if (drop_pos == GTK_TREE_VIEW_DROP_INTO_OR_AFTER)
3934 drop_pos = GTK_TREE_VIEW_DROP_AFTER;
3936 if (gtk_tree_model_get_iter (dstmodel, &dstiter, path))
3939 GtkTreePath *dstpath = NULL;
3943 case GTK_TREE_VIEW_DROP_BEFORE:
3944 gtk_tree_store_insert_before(GTK_TREE_STORE (dstmodel),
3945 &iter, NULL, &dstiter);
3948 case GTK_TREE_VIEW_DROP_INTO_OR_BEFORE:
3949 gtk_tree_store_insert(GTK_TREE_STORE (dstmodel),
3950 &iter, &dstiter, 0);
3953 case GTK_TREE_VIEW_DROP_AFTER:
3954 gtk_tree_store_insert_after(GTK_TREE_STORE (dstmodel),
3955 &iter, NULL, &dstiter);
3958 case GTK_TREE_VIEW_DROP_INTO_OR_AFTER:
3959 gtk_tree_store_insert_after(GTK_TREE_STORE (dstmodel),
3960 &iter, &dstiter, 0);
3967 dstpath = gtk_tree_model_get_path (dstmodel, &iter);
3968 dst_indices = gtk_tree_path_get_indices(dstpath);
3969 dst_len = gtk_tree_path_get_depth(dstpath);
3970 ghb_presets_insert(presetsPlist, preset, dst_indices, dst_len);
3971 gtk_tree_path_free(dstpath);
3973 srcpath = gtk_tree_model_get_path (srcmodel, &srciter);
3974 src_indices = gtk_tree_path_get_indices(srcpath);
3975 src_len = gtk_tree_path_get_depth(srcpath);
3976 ghb_presets_remove(presetsPlist, src_indices, src_len);
3977 gtk_tree_path_free(srcpath);
3979 gtk_tree_store_remove (GTK_TREE_STORE (srcmodel), &srciter);
3981 dstpath = gtk_tree_model_get_path (dstmodel, &iter);
3982 dst_indices = gtk_tree_path_get_indices(dstpath);
3983 dst_len = gtk_tree_path_get_depth(dstpath);
3984 presets_list_update_item(ud, dst_indices, dst_len, TRUE);
3985 gtk_tree_path_free(dstpath);
3989 gtk_tree_path_free(path);
3994 presets_row_expanded_cb(
3995 GtkTreeView *treeview,
3998 signal_user_data_t *ud)
4001 gboolean expanded, folder;
4004 expanded = gtk_tree_view_row_expanded(treeview, path);
4005 indices = gtk_tree_path_get_indices(path);
4006 len = gtk_tree_path_get_depth(path);
4007 dict = presets_get_dict(presetsPlist, indices, len);
4008 if (preset_folder_is_open(dict))
4017 folder = ghb_presets_get_folder(presetsPlist, indices, len);
4020 presets_set_folder_open(expanded, indices, len);
4023 // Collapsing parent folder collapses all children
4026 GValue *presets = NULL;
4027 gint *more_indices, count, ii;
4029 more_indices = g_malloc((len+1)*sizeof(gint));
4030 memcpy(more_indices, indices, len*sizeof(gint));
4032 presets = presets_get_folder(presetsPlist, indices, len);
4033 count = ghb_array_len(presets);
4034 for (ii = 0; ii < count; ii++)
4036 dict = ghb_array_get_nth(presets, ii);
4037 folder = ghb_preset_folder(dict);
4040 more_indices[len] = ii;
4041 presets_set_folder_open(expanded, more_indices, len+1);
4044 g_free(more_indices);
4050 preset_update_title_deps(signal_user_data_t *ud, ghb_title_info_t *tinfo)
4054 ghb_ui_update(ud, "scale_width",
4055 ghb_int64_value(tinfo->width - tinfo->crop[2] - tinfo->crop[3]));
4056 // If anamorphic or keep_aspect, the hight will be automatically calculated
4057 gboolean keep_aspect;
4059 keep_aspect = ghb_settings_get_boolean(ud->settings, "PictureKeepRatio");
4060 pic_par = ghb_settings_combo_int(ud->settings, "PicturePAR");
4061 if (!(keep_aspect || pic_par) || pic_par == 3)
4063 ghb_ui_update(ud, "scale_height",
4064 ghb_int64_value(tinfo->height - tinfo->crop[0] - tinfo->crop[1]));
4067 // Set the limits of cropping. hb_set_anamorphic_size crashes if
4068 // you pass it a cropped width or height == 0.
4070 bound = tinfo->height / 2 - 2;
4071 widget = GHB_WIDGET (ud->builder, "PictureTopCrop");
4072 gtk_spin_button_set_range (GTK_SPIN_BUTTON(widget), 0, bound);
4073 widget = GHB_WIDGET (ud->builder, "PictureBottomCrop");
4074 gtk_spin_button_set_range (GTK_SPIN_BUTTON(widget), 0, bound);
4075 bound = tinfo->width / 2 - 2;
4076 widget = GHB_WIDGET (ud->builder, "PictureLeftCrop");
4077 gtk_spin_button_set_range (GTK_SPIN_BUTTON(widget), 0, bound);
4078 widget = GHB_WIDGET (ud->builder, "PictureRightCrop");
4079 gtk_spin_button_set_range (GTK_SPIN_BUTTON(widget), 0, bound);
4080 if (ghb_settings_get_boolean(ud->settings, "PictureAutoCrop"))
4082 ghb_ui_update(ud, "PictureTopCrop", ghb_int64_value(tinfo->crop[0]));
4083 ghb_ui_update(ud, "PictureBottomCrop", ghb_int64_value(tinfo->crop[1]));
4084 ghb_ui_update(ud, "PictureLeftCrop", ghb_int64_value(tinfo->crop[2]));
4085 ghb_ui_update(ud, "PictureRightCrop", ghb_int64_value(tinfo->crop[3]));
4090 ghb_refresh_preset(signal_user_data_t *ud)
4092 ghb_title_info_t tinfo;
4096 g_debug("ghb_refresh_preset ()");
4097 preset = ghb_settings_get_value(ud->settings, "preset_selection");
4098 indices = ghb_preset_indices_from_path(presetsPlist, preset, &len);
4103 folder = ghb_presets_get_folder(presetsPlist, indices, len);
4106 ud->dont_clear_presets = TRUE;
4107 // Temporarily set the video_quality range to (0,100)
4108 // This is needed so the video_quality value does not get
4109 // truncated when set. The range will be readjusted below
4110 GtkWidget *qp = GHB_WIDGET(ud->builder, "VideoQualitySlider");
4111 gtk_range_set_range (GTK_RANGE(qp), 0, 100);
4112 gtk_scale_set_digits(GTK_SCALE(qp), 3);
4113 // Clear the audio list prior to changing the preset. Existing
4114 // audio can cause the container extension to be automatically
4115 // changed when it shouldn't be
4116 ghb_clear_audio_list(ud);
4117 ghb_set_preset_from_indices(ud, indices, len);
4119 titleindex = ghb_settings_combo_int(ud->settings, "title");
4120 ghb_set_pref_audio(titleindex, ud);
4121 ghb_set_pref_subtitle(titleindex, ud);
4122 ghb_settings_set_boolean(ud->settings, "preset_modified", FALSE);
4123 if (ghb_get_title_info (&tinfo, titleindex))
4125 preset_update_title_deps(ud, &tinfo);
4127 ghb_set_scale (ud, GHB_PIC_KEEP_PAR);
4128 ud->dont_clear_presets = FALSE;
4130 gdouble vqmin, vqmax, step, page;
4134 ghb_vquality_range(ud, &vqmin, &vqmax, &step,
4135 &page, &digits, &inverted);
4136 gtk_range_set_range (GTK_RANGE(qp), vqmin, vqmax);
4137 gtk_range_set_increments (GTK_RANGE(qp), step, page);
4138 gtk_scale_set_digits(GTK_SCALE(qp), digits);
4139 gtk_range_set_inverted (GTK_RANGE(qp), inverted);
4143 GtkWidget *crop_widget;
4144 crop[0] = ghb_settings_get_int(ud->settings, "PictureTopCrop");
4145 crop[1] = ghb_settings_get_int(ud->settings, "PictureBottomCrop");
4146 crop[2] = ghb_settings_get_int(ud->settings, "PictureLeftCrop");
4147 crop[3] = ghb_settings_get_int(ud->settings, "PictureRightCrop");
4148 crop_widget = GHB_WIDGET (ud->builder, "crop_values");
4149 text = g_strdup_printf("%d:%d:%d:%d",
4150 crop[0], crop[1], crop[2], crop[3]);
4151 gtk_label_set_text (GTK_LABEL(crop_widget), text);
4157 G_MODULE_EXPORT void
4158 presets_list_selection_changed_cb(GtkTreeSelection *selection, signal_user_data_t *ud)
4160 GtkTreeModel *store;
4162 ghb_title_info_t tinfo;
4165 g_debug("presets_list_selection_changed_cb ()");
4166 widget = GHB_WIDGET (ud->builder, "presets_remove");
4167 if (gtk_tree_selection_get_selected(selection, &store, &iter))
4169 GtkTreePath *treepath;
4174 treepath = gtk_tree_model_get_path(store, &iter);
4175 indices = gtk_tree_path_get_indices(treepath);
4176 len = gtk_tree_path_get_depth(treepath);
4178 path = preset_path_from_indices(presetsPlist, indices, len);
4179 ghb_settings_take_value(ud->settings, "preset_selection", path);
4181 folder = ghb_presets_get_folder(presetsPlist, indices, len);
4184 ud->dont_clear_presets = TRUE;
4185 // Temporarily set the video_quality range to (0,100)
4186 // This is needed so the video_quality value does not get
4187 // truncated when set. The range will be readjusted below
4188 GtkWidget *qp = GHB_WIDGET(ud->builder, "VideoQualitySlider");
4189 gtk_range_set_range (GTK_RANGE(qp), 0, 100);
4190 gtk_scale_set_digits(GTK_SCALE(qp), 3);
4191 // Clear the audio list prior to changing the preset. Existing
4192 // audio can cause the container extension to be automatically
4193 // changed when it shouldn't be
4194 ghb_clear_audio_list(ud);
4195 ghb_set_preset_from_indices(ud, indices, len);
4197 titleindex = ghb_settings_combo_int(ud->settings, "title");
4198 ghb_set_pref_audio(titleindex, ud);
4199 ghb_set_pref_subtitle(titleindex, ud);
4200 ghb_settings_set_boolean(ud->settings, "preset_modified", FALSE);
4201 if (ghb_get_title_info (&tinfo, titleindex))
4203 preset_update_title_deps(ud, &tinfo);
4205 ghb_set_scale (ud, GHB_PIC_KEEP_PAR);
4206 ud->dont_clear_presets = FALSE;
4208 gdouble vqmin, vqmax, step, page;
4212 ghb_vquality_range(ud, &vqmin, &vqmax, &step,
4213 &page, &digits, &inverted);
4214 gtk_range_set_range (GTK_RANGE(qp), vqmin, vqmax);
4215 gtk_range_set_increments (GTK_RANGE(qp), step, page);
4216 gtk_scale_set_digits(GTK_SCALE(qp), digits);
4217 gtk_range_set_inverted (GTK_RANGE(qp), inverted);
4221 GtkWidget *crop_widget;
4222 crop[0] = ghb_settings_get_int(ud->settings, "PictureTopCrop");
4223 crop[1] = ghb_settings_get_int(ud->settings, "PictureBottomCrop");
4224 crop[2] = ghb_settings_get_int(ud->settings, "PictureLeftCrop");
4225 crop[3] = ghb_settings_get_int(ud->settings, "PictureRightCrop");
4226 crop_widget = GHB_WIDGET (ud->builder, "crop_values");
4227 text = g_strdup_printf("%d:%d:%d:%d",
4228 crop[0], crop[1], crop[2], crop[3]);
4229 gtk_label_set_text (GTK_LABEL(crop_widget), text);
4232 gtk_tree_path_free(treepath);
4233 gtk_widget_set_sensitive(widget, TRUE);
4237 g_debug("No selection??? Perhaps unselected.");
4238 gtk_widget_set_sensitive(widget, FALSE);
4240 if (ghb_settings_combo_int(ud->settings, "PtoPType") == 0)
4243 start = ghb_settings_get_int(ud->settings, "start_point");
4244 end = ghb_settings_get_int(ud->settings, "end_point");
4245 widget = GHB_WIDGET (ud->builder, "ChapterMarkers");
4246 gtk_widget_set_sensitive(widget, TRUE);
4249 ud->dont_clear_presets = TRUE;
4250 ghb_ui_update(ud, "ChapterMarkers", ghb_boolean_value(FALSE));
4251 ud->dont_clear_presets = FALSE;
4252 gtk_widget_set_sensitive(widget, FALSE);
4258 ghb_clear_presets_selection(signal_user_data_t *ud)
4260 GtkTreeView *treeview;
4261 GtkTreeSelection *selection;
4263 if (ud->dont_clear_presets) return;
4264 g_debug("ghb_clear_presets_selection()");
4265 treeview = GTK_TREE_VIEW(GHB_WIDGET(ud->builder, "presets_list"));
4266 selection = gtk_tree_view_get_selection (treeview);
4267 gtk_tree_selection_unselect_all (selection);
4268 ghb_settings_set_boolean(ud->settings, "preset_modified", TRUE);
4271 G_MODULE_EXPORT void
4272 presets_frame_size_allocate_cb(GtkWidget *widget, GtkAllocation *allocation, signal_user_data_t *ud)
4274 GtkTreeView *treeview;
4275 GtkTreeSelection *selection;
4276 GtkTreeModel *store;
4279 treeview = GTK_TREE_VIEW(GHB_WIDGET(ud->builder, "presets_list"));
4280 selection = gtk_tree_view_get_selection(treeview);
4281 if (gtk_tree_selection_get_selected(selection, &store, &iter))
4284 path = gtk_tree_model_get_path (store, &iter);
4285 // Make the parent visible in scroll window if it is not.
4286 gtk_tree_view_scroll_to_cell (treeview, path, NULL, FALSE, 0, 0);
4287 gtk_tree_path_free(path);
4291 G_MODULE_EXPORT void
4292 presets_default_clicked_cb(GtkWidget *xwidget, signal_user_data_t *ud)
4297 g_debug("presets_default_clicked_cb ()");
4298 preset = ghb_settings_get_value(ud->settings, "preset_selection");
4299 indices = ghb_preset_indices_from_path(presetsPlist, preset, &len);
4302 if (!ghb_presets_get_folder(presetsPlist, indices, len))
4304 ghb_presets_list_clear_default(ud);
4305 presets_set_default(indices, len);
4306 ghb_presets_list_default(ud);
4312 G_MODULE_EXPORT void
4314 GtkCellRendererText *cell,
4317 signal_user_data_t *ud)
4319 GtkTreePath *treepath;
4320 GtkTreeStore *store;
4321 GtkTreeView *treeview;
4323 gint *indices, len, count;
4325 GValue *preset, *dest;
4327 g_debug("preset_edited_cb ()");
4328 g_debug("path (%s)", path);
4329 g_debug("text (%s)", text);
4331 preset = ghb_settings_get_value (ud->settings, "preset_selection");
4332 dest = ghb_array_value_new(MAX_NESTED_PRESET);
4333 count = ghb_array_len(preset);
4334 ghb_array_copy(dest, preset, count-1);
4335 ghb_array_append(dest, ghb_string_value_new(text));
4336 indices = ghb_preset_indices_from_path(presetsPlist, dest, &len);
4337 ghb_value_free(dest);
4338 if (indices != NULL)
4345 treeview = GTK_TREE_VIEW(GHB_WIDGET(ud->builder, "presets_list"));
4346 store = GTK_TREE_STORE(gtk_tree_view_get_model(treeview));
4347 treepath = gtk_tree_path_new_from_string (path);
4348 indices = gtk_tree_path_get_indices(treepath);
4349 len = gtk_tree_path_get_depth(treepath);
4350 gtk_tree_model_get_iter(GTK_TREE_MODEL(store), &iter, treepath);
4351 gtk_tree_store_set(store, &iter, 0, text, -1);
4353 dict = presets_get_dict(presetsPlist, indices, len);
4354 ghb_dict_insert(dict, g_strdup("PresetName"), ghb_string_value_new(text));
4356 gtk_tree_path_free (treepath);