1 /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
4 * Copyright (C) John Stebbins 2008-2011 <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));
921 val = ghb_dict_lookup(dict, "PictureHeight");
924 ghb_ui_update(ud, "scale_height", val);
926 val = ghb_dict_lookup(dict, "PictureWidth");
929 ghb_ui_update(ud, "scale_width", val);
935 ghb_settings_to_ui(signal_user_data_t *ud, GValue *dict)
937 init_ui_from_dict(ud, dict, dict);
940 static GValue *current_preset = NULL;
943 ghb_preset_is_custom()
947 if (current_preset == NULL) return FALSE;
948 val = preset_dict_get_value(current_preset, "Type");
949 return (ghb_value_int(val) == 1);
953 ghb_set_preset_from_indices(signal_user_data_t *ud, gint *indices, gint len)
956 gint fallback[2] = {0, -1};
959 dict = presets_get_dict(presetsPlist, indices, len);
964 dict = presets_get_dict(presetsPlist, indices, len);
968 preset_to_ui(ud, NULL);
969 current_preset = NULL;
976 current_preset = dict;
977 folder = ghb_value_boolean(preset_dict_get_value(dict, "Folder"));
979 preset_to_ui(ud, NULL);
981 preset_to_ui(ud, dict);
982 path = preset_path_from_indices(presetsPlist, indices, len);
983 ghb_settings_set_value(ud->settings, "preset", path);
984 ghb_value_free(path);
989 curr_preset_get_value(const gchar *key)
991 if (current_preset == NULL) return NULL;
992 return preset_dict_get_value(current_preset, key);
996 ghb_update_from_preset(
997 signal_user_data_t *ud,
1002 g_debug("ghb_update_from_preset() %s", key);
1003 gval = curr_preset_get_value(key);
1006 ghb_ui_update(ud, key, gval);
1012 GtkBuilder *builder,
1016 GtkTreeView *treeview;
1017 GtkTreeSelection *selection;
1018 GtkTreeModel *store;
1022 g_debug("ghb_select_preset2()");
1023 treeview = GTK_TREE_VIEW(GHB_WIDGET(builder, "presets_list"));
1024 selection = gtk_tree_view_get_selection (treeview);
1025 store = gtk_tree_view_get_model (treeview);
1026 path = ghb_tree_path_new_from_indices(indices, len);
1029 if (gtk_tree_model_get_iter(store, &iter, path))
1031 gtk_tree_selection_select_iter (selection, &iter);
1035 if (gtk_tree_model_get_iter_first(store, &iter))
1036 gtk_tree_selection_select_iter (selection, &iter);
1038 gtk_tree_path_free(path);
1043 ghb_select_preset(GtkBuilder *builder, const GValue *path)
1047 g_debug("ghb_select_preset()");
1048 indices = ghb_preset_indices_from_path(presetsPlist, path, &len);
1051 ghb_select_preset2(builder, indices, len);
1057 ghb_select_default_preset(GtkBuilder *builder)
1061 g_debug("ghb_select_default_preset()");
1062 indices = presets_find_default(presetsPlist, &len);
1065 ghb_select_preset2(builder, indices, len);
1071 ghb_get_user_config_dir(gchar *subdir)
1076 dir = g_get_user_config_dir();
1077 if (!g_file_test(dir, G_FILE_TEST_IS_DIR))
1079 dir = g_get_home_dir();
1080 config = g_strdup_printf ("%s/.ghb", dir);
1081 if (!g_file_test(config, G_FILE_TEST_IS_DIR))
1082 g_mkdir (config, 0755);
1086 config = g_strdup_printf ("%s/ghb", dir);
1087 if (!g_file_test(config, G_FILE_TEST_IS_DIR))
1088 g_mkdir (config, 0755);
1095 split = g_strsplit(subdir, G_DIR_SEPARATOR_S, -1);
1096 for (ii = 0; split[ii] != NULL; ii++)
1100 tmp = g_strdup_printf ("%s/%s", config, split[ii]);
1103 if (!g_file_test(config, G_FILE_TEST_IS_DIR))
1104 g_mkdir (config, 0755);
1111 store_plist(GValue *plist, const gchar *name)
1113 gchar *config, *path;
1116 config = ghb_get_user_config_dir(NULL);
1117 path = g_strdup_printf ("%s/%s", config, name);
1118 file = g_fopen(path, "w");
1121 ghb_plist_write(file, plist);
1126 load_plist(const gchar *name)
1128 gchar *config, *path;
1129 GValue *plist = NULL;
1131 config = ghb_get_user_config_dir(NULL);
1132 path = g_strdup_printf ("%s/%s", config, name);
1133 if (g_file_test(path, G_FILE_TEST_IS_REGULAR))
1135 plist = ghb_plist_parse_file(path);
1143 ghb_lock_file(const gchar *name)
1145 #if !defined(_WIN32)
1146 gchar *config, *path;
1149 config = ghb_get_user_config_dir(NULL);
1150 path = g_strdup_printf ("%s/%s", config, name);
1151 fd = open(path, O_RDWR|O_CREAT, S_IRUSR|S_IWUSR);
1153 lock = lockf(fd, F_TLOCK, 0);
1165 ghb_write_pid_file()
1167 #if !defined(_WIN32)
1168 gchar *config, *path;
1175 config = ghb_get_user_config_dir(NULL);
1176 path = g_strdup_printf ("%s/ghb.pid.%d", config, pid);
1178 fp = g_fopen(path, "w");
1179 fprintf(fp, "%d\n", pid);
1182 fd = open(path, O_RDWR|O_CREAT, S_IRUSR|S_IWUSR);
1183 lock = lockf(fd, F_TLOCK, 0);
1191 ghb_unlink_pid_file(int pid)
1193 gchar *config, *path;
1195 config = ghb_get_user_config_dir(NULL);
1196 path = g_strdup_printf ("%s/ghb.pid.%d", config, pid);
1198 if (g_file_test(path, G_FILE_TEST_IS_REGULAR))
1213 config = ghb_get_user_config_dir(NULL);
1215 if (g_file_test(config, G_FILE_TEST_IS_DIR))
1217 GDir *gdir = g_dir_open(config, 0, NULL);
1218 file = g_dir_read_name(gdir);
1221 if (strncmp(file, "ghb.pid.", 8) == 0)
1227 sscanf(file, "ghb.pid.%d", &pid);
1231 file = g_dir_read_name(gdir);
1234 path = g_strdup_printf("%s/%s", config, file);
1236 #if !defined(_WIN32)
1239 fd = open(path, O_RDWR);
1242 lock = lockf(fd, F_TLOCK, 0);
1263 file = g_dir_read_name(gdir);
1272 remove_plist(const gchar *name)
1274 gchar *config, *path;
1276 config = ghb_get_user_config_dir(NULL);
1277 path = g_strdup_printf ("%s/%s", config, name);
1278 if (g_file_test(path, G_FILE_TEST_IS_REGULAR))
1286 static gboolean prefs_initializing = FALSE;
1289 ghb_prefs_to_ui(signal_user_data_t *ud)
1294 GValue *internal, *dict;
1295 GHashTableIter iter;
1298 g_debug("ghb_prefs_to_ui");
1299 prefs_initializing = TRUE;
1301 // Setting a ui widget will cause the corresponding setting
1302 // to be set, but it also triggers a callback that can
1303 // have the side effect of using other settings values
1304 // that have not yet been set. So set *all* settings first
1305 // then update the ui.
1306 internal = plist_get_dict(internalPlist, "Initialization");
1307 ghb_dict_iter_init(&iter, internal);
1308 // middle (void*) cast prevents gcc warning "defreferencing type-punned
1309 // pointer will break strict-aliasing rules"
1310 while (g_hash_table_iter_next(
1311 &iter, (gpointer*)(void*)&key, (gpointer*)(void*)&gval))
1313 ghb_ui_update(ud, key, gval);
1316 dict = plist_get_dict(prefsPlist, "Preferences");
1317 internal = plist_get_dict(internalPlist, "Preferences");
1318 ghb_dict_iter_init(&iter, internal);
1319 // middle (void*) cast prevents gcc warning "defreferencing type-punned
1320 // pointer will break strict-aliasing rules"
1321 while (g_hash_table_iter_next(
1322 &iter, (gpointer*)(void*)&key, (gpointer*)(void*)&gval))
1324 const GValue *value = NULL;
1326 value = ghb_dict_lookup(dict, key);
1329 ghb_settings_set_value(ud->settings, key, value);
1331 internal = plist_get_dict(internalPlist, "Preferences");
1332 ghb_dict_iter_init(&iter, internal);
1333 // middle (void*) cast prevents gcc warning "defreferencing type-punned
1334 // pointer will break strict-aliasing rules"
1335 while (g_hash_table_iter_next(
1336 &iter, (gpointer*)(void*)&key, (gpointer*)(void*)&gval))
1338 const GValue *value = NULL;
1340 value = ghb_dict_lookup(dict, key);
1343 ghb_ui_update(ud, key, value);
1346 val = ghb_settings_get_value(ud->settings, "show_presets");
1347 ghb_ui_update(ud, "show_presets", val);
1348 if (ghb_settings_get_boolean(ud->settings, "hbfd_feature"))
1351 val = ghb_settings_get_value(ud->settings, "hbfd");
1352 ghb_ui_update(ud, "hbfd", val);
1353 action = GHB_ACTION (ud->builder, "hbfd");
1354 gtk_action_set_visible(action, TRUE);
1358 ghb_ui_update(ud, "hbfd", ghb_int64_value(0));
1360 gval = ghb_settings_get_value(ud->settings, "default_source");
1361 ghb_settings_set_value (ud->settings, "scan_source", gval);
1363 str = ghb_settings_get_string(ud->settings, "destination_dir");
1364 ghb_ui_update(ud, "dest_dir", ghb_string_value(str));
1366 gchar *file = g_strdup_printf ("new_video.mp4");
1367 ghb_ui_update(ud, "dest_file", ghb_string_value(file));
1371 prefs_initializing = FALSE;
1375 ghb_prefs_save(GValue *settings)
1379 GHashTableIter iter;
1381 const GValue *value;
1383 if (prefs_initializing) return;
1384 dict = plist_get_dict(internalPlist, "Preferences");
1385 if (dict == NULL) return;
1386 pref_dict = plist_get_dict(prefsPlist, "Preferences");
1387 if (pref_dict == NULL) return;
1388 ghb_dict_iter_init(&iter, dict);
1389 // middle (void*) cast prevents gcc warning "defreferencing type-punned
1390 // pointer will break strict-aliasing rules"
1391 while (g_hash_table_iter_next(
1392 &iter, (gpointer*)(void*)&key, (gpointer*)(void*)&value))
1394 value = ghb_settings_get_value(settings, key);
1397 ghb_dict_insert(pref_dict, g_strdup(key), ghb_value_dup(value));
1401 prefs_modified = FALSE;
1405 ghb_pref_set(GValue *settings, const gchar *key)
1407 const GValue *value, *value2;
1409 if (prefs_initializing) return;
1410 value = ghb_settings_get_value(settings, key);
1414 dict = plist_get_dict(prefsPlist, "Preferences");
1415 if (dict == NULL) return;
1416 value2 = ghb_dict_lookup(dict, key);
1417 if (ghb_value_cmp(value, value2) != 0)
1419 ghb_dict_insert(dict, g_strdup(key), ghb_value_dup(value));
1421 prefs_modified = TRUE;
1427 ghb_pref_save(GValue *settings, const gchar *key)
1429 const GValue *value, *value2;
1431 if (prefs_initializing) return;
1432 value = ghb_settings_get_value(settings, key);
1436 dict = plist_get_dict(prefsPlist, "Preferences");
1437 if (dict == NULL) return;
1438 value2 = ghb_dict_lookup(dict, key);
1439 if (ghb_value_cmp(value, value2) != 0)
1441 ghb_dict_insert(dict, g_strdup(key), ghb_value_dup(value));
1443 prefs_modified = FALSE;
1449 ghb_prefs_store(void)
1454 prefs_modified = FALSE;
1459 ghb_settings_init(signal_user_data_t *ud)
1462 GHashTableIter iter;
1467 g_debug("ghb_settings_init");
1468 prefs_initializing = TRUE;
1470 internalPlist = ghb_resource_get("internal-defaults");
1471 // Setting a ui widget will cause the corresponding setting
1472 // to be set, but it also triggers a callback that can
1473 // have the side effect of using other settings values
1474 // that have not yet been set. So set *all* settings first
1475 // then update the ui.
1476 internal = plist_get_dict(internalPlist, "Initialization");
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, "Presets");
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);
1496 internal = plist_get_dict(internalPlist, "Preferences");
1497 ghb_dict_iter_init(&iter, internal);
1498 // middle (void*) cast prevents gcc warning "defreferencing type-punned
1499 // pointer will break strict-aliasing rules"
1500 while (g_hash_table_iter_next(
1501 &iter, (gpointer*)(void*)&key, (gpointer*)(void*)&gval))
1503 ghb_settings_set_value(ud->settings, key, gval);
1505 prefs_initializing = FALSE;
1509 ghb_settings_close()
1512 ghb_value_free(internalPlist);
1514 ghb_value_free(presetsPlist);
1516 ghb_value_free(prefsPlist);
1521 FindFirstCDROM(void)
1526 strcpy(drive, "A:" G_DIR_SEPARATOR_S);
1527 drives = GetLogicalDrives();
1528 for (ii = 0; ii < 26; ii++)
1534 drive[0] = 'A' + ii;
1535 dtype = GetDriveType(drive);
1536 if (dtype == DRIVE_CDROM)
1538 return g_strdup(drive);
1548 ghb_prefs_load(signal_user_data_t *ud)
1550 GValue *dict, *internal;
1551 GHashTableIter iter;
1553 GValue *gval, *path;
1555 g_debug("ghb_prefs_load");
1556 prefsPlist = load_plist("preferences");
1557 if (prefsPlist == NULL)
1558 prefsPlist = ghb_dict_value_new();
1559 dict = plist_get_dict(prefsPlist, "Preferences");
1560 internal = plist_get_dict(internalPlist, "Preferences");
1561 if (dict == NULL && internal)
1563 dict = ghb_dict_value_new();
1564 ghb_dict_insert(prefsPlist, g_strdup("Preferences"), dict);
1566 // Get defaults from internal defaults
1567 ghb_dict_iter_init(&iter, internal);
1568 // middle (void*) cast prevents gcc warning "defreferencing type-punned
1569 // pointer will break strict-aliasing rules"
1570 while (g_hash_table_iter_next(
1571 &iter, (gpointer*)(void*)&key, (gpointer*)(void*)&gval))
1573 ghb_dict_insert(dict, g_strdup(key), ghb_value_dup(gval));
1576 const gchar *dir = g_get_user_special_dir (G_USER_DIRECTORY_DESKTOP);
1581 ghb_dict_insert(dict,
1582 g_strdup("ExportDirectory"), ghb_value_dup(ghb_string_value(dir)));
1584 dir = g_get_user_special_dir (G_USER_DIRECTORY_VIDEOS);
1589 ghb_dict_insert(dict,
1590 g_strdup("destination_dir"), ghb_value_dup(ghb_string_value(dir)));
1592 ghb_dict_insert(dict,
1593 g_strdup("SrtDir"), ghb_value_dup(ghb_string_value(dir)));
1597 source = FindFirstCDROM();
1600 source = g_strdup("C:" G_DIR_SEPARATOR_S);
1602 ghb_dict_insert(dict, g_strdup("default_source"),
1603 ghb_value_dup(ghb_string_value(source)));
1608 // Read legacy default_preset preference and update accordingly
1609 path = ghb_dict_lookup(dict, "default_preset");
1614 if (G_VALUE_TYPE(path) == G_TYPE_STRING)
1618 path = ghb_array_value_new(1);
1619 ghb_array_append(path, ghb_value_dup(str));
1620 indices = ghb_preset_indices_from_path(presetsPlist, path, &len);
1621 ghb_value_free(path);
1624 indices = ghb_preset_indices_from_path(presetsPlist, path, &len);
1628 presets_set_default(indices, len);
1631 ghb_dict_remove(dict, "default_preset");
1637 get_preset_color(gint type, gboolean folder)
1641 if (type == PRESETS_CUSTOM)
1661 ghb_presets_list_init(
1662 signal_user_data_t *ud,
1666 GtkTreeView *treeview;
1667 GtkTreeIter iter, titer, *piter;
1669 GtkTreeStore *store;
1670 const gchar *preset;
1671 GtkTreePath *parent_path;
1672 const gchar *description;
1677 GValue *presets = NULL;
1679 g_debug("ghb_presets_list_init ()");
1680 more_indices = g_malloc((len+1)*sizeof(gint));
1681 memcpy(more_indices, indices, len*sizeof(gint));
1682 presets = presets_get_folder(presetsPlist, indices, len);
1683 if (presets == NULL)
1685 g_warning("Failed to find parent folder when adding child.");
1688 count = ghb_array_len(presets);
1689 treeview = GTK_TREE_VIEW(GHB_WIDGET(ud->builder, "presets_list"));
1690 store = GTK_TREE_STORE(gtk_tree_view_get_model(treeview));
1691 parent_path = ghb_tree_path_new_from_indices(indices, len);
1694 gtk_tree_model_get_iter(GTK_TREE_MODEL(store), &titer, parent_path);
1696 gtk_tree_path_free(parent_path);
1702 for (ii = 0; ii < count; ii++)
1708 // Additional settings, add row
1709 dict = ghb_array_get_nth(presets, ii);
1710 preset = preset_get_name(dict);
1711 more_indices[len] = ii;
1712 def = preset_is_default(dict);
1714 description = ghb_presets_get_description(dict);
1715 gtk_tree_store_append(store, &iter, piter);
1716 type = ghb_preset_type(dict);
1717 folder = ghb_preset_folder(dict);
1718 color = get_preset_color(type, folder);
1719 gtk_tree_store_set(store, &iter, 0, preset,
1724 5, type == PRESETS_BUILTIN ? 0 : 1,
1731 if (gtk_tree_model_iter_parent(
1732 GTK_TREE_MODEL(store), &ppiter, piter))
1734 path = gtk_tree_model_get_path(GTK_TREE_MODEL(store), &ppiter);
1735 gtk_tree_view_expand_row(treeview, path, FALSE);
1736 gtk_tree_path_free(path);
1738 path = gtk_tree_model_get_path(GTK_TREE_MODEL(store), piter);
1739 gtk_tree_view_expand_row(treeview, path, FALSE);
1740 gtk_tree_path_free(path);
1744 ghb_presets_list_init(ud, more_indices, len+1);
1745 if (preset_folder_is_open(dict))
1751 path = gtk_tree_model_get_path(GTK_TREE_MODEL(store), piter);
1752 gtk_tree_view_expand_row(treeview, path, FALSE);
1753 gtk_tree_path_free(path);
1755 path = gtk_tree_model_get_path(GTK_TREE_MODEL(store), &iter);
1756 gtk_tree_view_expand_row(treeview, path, FALSE);
1757 gtk_tree_path_free(path);
1761 g_free(more_indices);
1765 presets_list_update_item(
1766 signal_user_data_t *ud,
1771 GtkTreeView *treeview;
1772 GtkTreeStore *store;
1774 GtkTreePath *treepath;
1776 const gchar *description;
1778 gboolean def, folder;
1782 g_debug("presets_list_update_item ()");
1783 dict = presets_get_dict(presetsPlist, indices, len);
1786 treeview = GTK_TREE_VIEW(GHB_WIDGET(ud->builder, "presets_list"));
1787 store = GTK_TREE_STORE(gtk_tree_view_get_model(treeview));
1788 treepath = ghb_tree_path_new_from_indices(indices, len);
1789 gtk_tree_model_get_iter(GTK_TREE_MODEL(store), &iter, treepath);
1790 // Additional settings, add row
1791 name = preset_get_name(dict);
1792 def = preset_is_default(dict);
1794 description = ghb_presets_get_description(dict);
1795 type = ghb_preset_type(dict);
1796 folder = ghb_preset_folder(dict);
1797 color = get_preset_color(type, folder);
1798 gtk_tree_store_set(store, &iter, 0, name,
1803 5, type == PRESETS_BUILTIN ? 0 : 1,
1805 if (recurse && folder)
1807 ghb_presets_list_init(ud, indices, len);
1812 presets_list_insert(
1813 signal_user_data_t *ud,
1817 GtkTreeView *treeview;
1818 GtkTreeIter iter, titer, *piter;
1819 GtkTreeStore *store;
1820 const gchar *preset;
1821 const gchar *description;
1823 gboolean def, folder;
1826 GtkTreePath *parent_path;
1830 g_debug("presets_list_insert ()");
1831 treeview = GTK_TREE_VIEW(GHB_WIDGET(ud->builder, "presets_list"));
1832 store = GTK_TREE_STORE(gtk_tree_view_get_model(treeview));
1833 presets = presets_get_folder(presetsPlist, indices, len-1);
1834 if (presets == NULL)
1836 g_warning("Failed to find parent folder while adding child.");
1839 parent_path = ghb_tree_path_new_from_indices(indices, len-1);
1842 gtk_tree_model_get_iter(GTK_TREE_MODEL(store), &titer, parent_path);
1844 gtk_tree_path_free(parent_path);
1850 count = ghb_array_len(presets);
1851 if (indices[len-1] >= count)
1853 // Additional settings, add row
1854 dict = ghb_array_get_nth(presets, indices[len-1]);
1855 preset = preset_get_name(dict);
1856 def = preset_is_default(dict);
1858 description = ghb_presets_get_description(dict);
1859 gtk_tree_store_insert(store, &iter, piter, indices[len-1]);
1860 type = ghb_preset_type(dict);
1861 folder = ghb_preset_folder(dict);
1862 color = get_preset_color(type, folder);
1863 gtk_tree_store_set(store, &iter, 0, preset,
1868 5, type == PRESETS_BUILTIN ? 0 : 1,
1872 ghb_presets_list_init(ud, indices, len);
1877 presets_list_remove(
1878 signal_user_data_t *ud,
1882 GtkTreeView *treeview;
1883 GtkTreePath *treepath;
1885 GtkTreeStore *store;
1887 g_debug("presets_list_remove ()");
1888 treeview = GTK_TREE_VIEW(GHB_WIDGET(ud->builder, "presets_list"));
1889 store = GTK_TREE_STORE(gtk_tree_view_get_model(treeview));
1890 treepath = ghb_tree_path_new_from_indices(indices, len);
1893 if (gtk_tree_model_get_iter(GTK_TREE_MODEL(store), &iter, treepath))
1894 gtk_tree_store_remove(store, &iter);
1895 gtk_tree_path_free(treepath);
1900 remove_std_presets(signal_user_data_t *ud)
1905 count = ghb_array_len(presetsPlist);
1906 for (ii = count-1; ii >= 0; ii--)
1911 dict = ghb_array_get_nth(presetsPlist, ii);
1912 ptype = ghb_value_int(preset_dict_get_value(dict, "Type"));
1913 if (ptype == PRESETS_BUILTIN)
1915 if (ghb_presets_remove(presetsPlist, &indices, 1))
1917 presets_list_remove(ud, &indices, 1);
1924 ghb_save_queue(GValue *queue)
1930 path = g_strdup_printf ("queue.%d", pid);
1931 store_plist(queue, path);
1943 path = g_strdup_printf ("queue.%d", pid);
1944 queue = load_plist(path);
1950 ghb_load_old_queue(int pid)
1955 path = g_strdup_printf ("queue.%d", pid);
1956 queue = load_plist(path);
1962 ghb_remove_old_queue_file(int pid)
1966 path = g_strdup_printf ("queue.%d", pid);
1972 ghb_remove_queue_file()
1978 path = g_strdup_printf ("queue.%d", pid);
1989 static value_map_t vcodec_xlat[] =
1991 {"MPEG-4 (FFmpeg)", "ffmpeg"},
1992 {"MPEG-4 (XviD)", "ffmpeg"},
1993 {"H.264 (x264)", "x264"},
1994 {"VP3 (Theora)", "theora"},
1998 static value_map_t acodec_xlat[] =
2000 {"AAC (faac)", "faac"},
2001 {"AAC (CoreAudio)", "faac"},
2002 {"AC3 Passthru", "ac3pass"},
2003 {"DTS Passthru", "dtspass"},
2004 {"MP3 (lame)", "lame"},
2005 {"Vorbis (vorbis)", "vorbis"},
2009 value_map_t container_xlat[] =
2011 {"MP4 file", "mp4"},
2012 {"M4V file", "mp4"},
2013 {"MKV file", "mkv"},
2014 {"AVI file", "mkv"},
2015 {"OGM file", "mkv"},
2019 value_map_t framerate_xlat[] =
2021 {"Same as source", "source"},
2026 {"23.976 (NTSC Film)", "23.976"},
2028 {"25 (PAL Film/Video)", "25"},
2029 {"29.97 (NTSC Video)", "29.97"},
2033 value_map_t samplerate_xlat[] =
2044 value_map_t mix_xlat[] =
2047 {"Stereo", "stereo"},
2048 {"Dolby Surround", "dpl1"},
2049 {"Dolby Pro Logic II", "dpl2"},
2050 {"6-channel discrete", "6ch"},
2051 {"AC3 Passthru", "none"},
2055 value_map_t deint_xlat[] =
2065 value_map_t denoise_xlat[] =
2075 value_map_t detel_xlat[] =
2083 value_map_t decomb_xlat[] =
2091 extern iso639_lang_t ghb_language_table[];
2094 export_lang_xlat2(GValue *lin_val)
2098 if (lin_val == NULL) return NULL;
2102 str = ghb_value_string(lin_val);
2103 for (ii = 0; ghb_language_table[ii].eng_name; ii++)
2105 if (strcmp(str, ghb_language_table[ii].iso639_2) == 0)
2109 if (ghb_language_table[ii].native_name[0] != 0)
2110 lang = ghb_language_table[ii].native_name;
2112 lang = ghb_language_table[ii].eng_name;
2114 gval = ghb_string_value_new(lang);
2119 g_debug("Can't map language value: (%s)", str);
2125 export_subtitle_xlat2(GValue *lin_val)
2130 if (lin_val == NULL) return NULL;
2131 str = ghb_value_string(lin_val);
2132 if (strcmp(str, "none") == 0)
2134 gval = ghb_string_value_new("None");
2136 else if (strcmp(str, "auto") == 0)
2138 gval = ghb_string_value_new("Autoselect");
2142 gval = export_lang_xlat2(lin_val);
2149 import_lang_xlat2(GValue *mac_val)
2153 if (mac_val == NULL) return NULL;
2157 str = ghb_value_string(mac_val);
2158 for (ii = 0; ghb_language_table[ii].eng_name; ii++)
2160 if ((strcmp(str, ghb_language_table[ii].eng_name) == 0) ||
2161 (strcmp(str, ghb_language_table[ii].native_name) == 0))
2163 gval = ghb_string_value_new(ghb_language_table[ii].iso639_2);
2168 g_debug("Can't map language value: (%s)", str);
2174 import_subtitle_xlat2(GValue *mac_val)
2179 if (mac_val == NULL) return NULL;
2180 str = ghb_value_string(mac_val);
2181 if (strcmp(str, "None") == 0)
2183 gval = ghb_string_value_new("none");
2185 else if (strcmp(str, "Autoselect") == 0)
2187 gval = ghb_string_value_new("auto");
2191 gval = import_lang_xlat2(mac_val);
2198 export_audio_track_xlat2(GValue *lin_val)
2201 GValue *gval = NULL;
2203 if (lin_val == NULL) return NULL;
2204 str = ghb_value_string(lin_val);
2205 if (strcmp(str, "none") == 0)
2207 gval = ghb_int_value_new(1);
2211 gint val = ghb_value_int(lin_val) + 1;
2212 gval = ghb_int_value_new(val);
2219 import_audio_track_xlat2(GValue *mac_val)
2225 if (mac_val == NULL) return NULL;
2226 val = ghb_value_int(mac_val);
2235 str = g_strdup_printf("%d", val);
2236 gval = ghb_string_value_new(str);
2242 export_value_xlat2(value_map_t *value_map, GValue *lin_val, GType mac_type)
2246 if (lin_val == NULL) return NULL;
2251 str = ghb_value_string(lin_val);
2252 for (ii = 0; value_map[ii].mac_val; ii++)
2254 if (strcmp(str, value_map[ii].lin_val) == 0)
2256 sval = ghb_string_value_new(value_map[ii].mac_val);
2258 gval = ghb_value_new(mac_type);
2259 if (!g_value_transform(sval, gval))
2261 g_warning("can't transform");
2262 ghb_value_free(gval);
2263 ghb_value_free(sval);
2266 ghb_value_free(sval);
2270 g_debug("Can't map value: (%s)", str);
2276 export_value_xlat(GValue *dict)
2278 GValue *lin_val, *gval;
2281 key = "VideoEncoder";
2282 lin_val = ghb_dict_lookup(dict, key);
2283 gval = export_value_xlat2(vcodec_xlat, lin_val, G_TYPE_STRING);
2285 ghb_dict_insert(dict, g_strdup(key), gval);
2287 lin_val = ghb_dict_lookup(dict, key);
2288 gval = export_value_xlat2(container_xlat, lin_val, G_TYPE_STRING);
2290 ghb_dict_insert(dict, g_strdup(key), gval);
2291 key = "VideoFramerate";
2292 lin_val = ghb_dict_lookup(dict, key);
2293 gval = export_value_xlat2(framerate_xlat, lin_val, G_TYPE_STRING);
2295 ghb_dict_insert(dict, g_strdup(key), gval);
2296 key = "PictureDetelecine";
2297 lin_val = ghb_dict_lookup(dict, key);
2298 gval = export_value_xlat2(detel_xlat, lin_val, G_TYPE_INT);
2300 ghb_dict_insert(dict, g_strdup(key), gval);
2301 key = "PictureDecomb";
2302 lin_val = ghb_dict_lookup(dict, key);
2303 gval = export_value_xlat2(decomb_xlat, lin_val, G_TYPE_INT);
2305 ghb_dict_insert(dict, g_strdup(key), gval);
2306 key = "PictureDeinterlace";
2307 lin_val = ghb_dict_lookup(dict, key);
2308 gval = export_value_xlat2(deint_xlat, lin_val, G_TYPE_INT);
2310 ghb_dict_insert(dict, g_strdup(key), gval);
2311 key = "PictureDenoise";
2312 lin_val = ghb_dict_lookup(dict, key);
2313 gval = export_value_xlat2(denoise_xlat, lin_val, G_TYPE_INT);
2315 ghb_dict_insert(dict, g_strdup(key), gval);
2321 slist = ghb_dict_lookup(dict, "SubtitleList");
2322 count = ghb_array_len(slist);
2323 for (ii = 0; ii < count; ii++)
2325 sdict = ghb_array_get_nth(slist, ii);
2326 key = "SubtitleLanguage";
2327 lin_val = ghb_dict_lookup(sdict, key);
2328 gval = export_subtitle_xlat2(lin_val);
2330 ghb_dict_insert(sdict, g_strdup(key), gval);
2336 alist = ghb_dict_lookup(dict, "AudioList");
2337 count = ghb_array_len(alist);
2338 for (ii = 0; ii < count; ii++)
2340 adict = ghb_array_get_nth(alist, ii);
2342 lin_val = ghb_dict_lookup(adict, key);
2343 gval = export_audio_track_xlat2(lin_val);
2345 ghb_dict_insert(adict, g_strdup(key), gval);
2346 key = "AudioEncoder";
2347 lin_val = ghb_dict_lookup(adict, key);
2348 gval = export_value_xlat2(acodec_xlat, lin_val, G_TYPE_STRING);
2350 ghb_dict_insert(adict, g_strdup(key), gval);
2351 key = "AudioSamplerate";
2352 lin_val = ghb_dict_lookup(adict, key);
2353 gval = export_value_xlat2(samplerate_xlat, lin_val, G_TYPE_STRING);
2355 ghb_dict_insert(adict, g_strdup(key), gval);
2356 key = "AudioMixdown";
2357 lin_val = ghb_dict_lookup(adict, key);
2358 gval = export_value_xlat2(mix_xlat, lin_val, G_TYPE_STRING);
2360 ghb_dict_insert(adict, g_strdup(key), gval);
2368 value_map_t *value_map,
2372 GValue *gval, *def_val;
2374 if (mac_val == NULL) return NULL;
2375 def_val = ghb_dict_lookup(defaults, key);
2382 str = ghb_value_string(mac_val);
2383 for (ii = 0; value_map[ii].mac_val; ii++)
2385 if (strcmp(str, value_map[ii].mac_val) == 0)
2387 sval = ghb_string_value_new(value_map[ii].lin_val);
2389 gval = ghb_value_new(G_VALUE_TYPE(def_val));
2390 if (!g_value_transform(sval, gval))
2392 g_warning("can't transform");
2393 ghb_value_free(gval);
2394 ghb_value_free(sval);
2397 ghb_value_free(sval);
2409 str = ghb_value_string(mac_val);
2410 for (ii = 0; value_map[ii].mac_val; ii++)
2412 if (strcmp(str, value_map[ii].mac_val) == 0)
2414 sval = ghb_string_value_new(value_map[ii].lin_val);
2416 gval = ghb_value_new(G_VALUE_TYPE(mac_val));
2417 if (!g_value_transform(sval, gval))
2419 g_warning("can't transform");
2420 ghb_value_free(gval);
2421 ghb_value_free(sval);
2424 ghb_value_free(sval);
2434 import_value_xlat(GValue *dict)
2436 GValue *defaults, *mac_val, *gval;
2439 defaults = plist_get_dict(internalPlist, "Presets");
2440 key = "VideoEncoder";
2441 mac_val = ghb_dict_lookup(dict, key);
2442 gval = import_value_xlat2(defaults, vcodec_xlat, key, mac_val);
2444 ghb_dict_insert(dict, g_strdup(key), gval);
2446 mac_val = ghb_dict_lookup(dict, key);
2447 gval = import_value_xlat2(defaults, container_xlat, key, mac_val);
2449 ghb_dict_insert(dict, g_strdup(key), gval);
2450 key = "VideoFramerate";
2451 mac_val = ghb_dict_lookup(dict, key);
2452 gval = import_value_xlat2(defaults, framerate_xlat, key, mac_val);
2454 ghb_dict_insert(dict, g_strdup(key), gval);
2455 key = "PictureDetelecine";
2456 mac_val = ghb_dict_lookup(dict, key);
2457 gval = import_value_xlat2(defaults, detel_xlat, key, mac_val);
2459 ghb_dict_insert(dict, g_strdup(key), gval);
2460 key = "PictureDecomb";
2461 mac_val = ghb_dict_lookup(dict, key);
2462 gval = import_value_xlat2(defaults, decomb_xlat, key, mac_val);
2464 ghb_dict_insert(dict, g_strdup(key), gval);
2465 key = "PictureDeinterlace";
2466 mac_val = ghb_dict_lookup(dict, key);
2467 gval = import_value_xlat2(defaults, deint_xlat, key, mac_val);
2469 ghb_dict_insert(dict, g_strdup(key), gval);
2470 key = "PictureDenoise";
2471 mac_val = ghb_dict_lookup(dict, key);
2472 gval = import_value_xlat2(defaults, denoise_xlat, key, mac_val);
2474 ghb_dict_insert(dict, g_strdup(key), gval);
2483 sdeflist = ghb_dict_lookup(defaults, "SubtitleList");
2486 slist = ghb_dict_lookup(dict, "SubtitleList");
2489 sdefaults = ghb_array_get_nth(sdeflist, 0);
2490 count = ghb_array_len(slist);
2491 for (ii = 0; ii < count; ii++)
2493 sdict = ghb_array_get_nth(slist, ii);
2494 key = "SubtitleLanguage";
2495 mac_val = ghb_dict_lookup(sdict, key);
2496 gval = import_subtitle_xlat2(mac_val);
2498 ghb_dict_insert(sdict, g_strdup(key), gval);
2505 mac_val = ghb_dict_lookup(dict, key);
2506 slist = ghb_array_value_new(8);
2507 ghb_dict_insert(dict, g_strdup("SubtitleList"), slist);
2512 gval = import_subtitle_xlat2(mac_val);
2513 lang = ghb_value_string(gval);
2514 if (lang && strcasecmp(lang, "none") != 0 && !slist)
2516 sdict = ghb_dict_value_new();
2517 ghb_array_append(slist, sdict);
2518 ghb_dict_insert(sdict, g_strdup("SubtitleLanguage"), gval);
2519 gval = ghb_dict_lookup(dict, "SubtitlesForced");
2522 ghb_dict_insert(sdict, g_strdup("SubtitleForced"),
2523 ghb_value_dup(gval));
2527 ghb_dict_insert(sdict, g_strdup("SubtitleForced"),
2528 ghb_boolean_value_new(FALSE));
2530 ghb_dict_insert(sdict, g_strdup("SubtitleBurned"),
2531 ghb_boolean_value_new(TRUE));
2532 ghb_dict_insert(sdict, g_strdup("SubtitleDefaultTrack"),
2533 ghb_boolean_value_new(FALSE));
2537 ghb_value_free(gval);
2544 ghb_dict_remove(dict, "Subtitles");
2545 ghb_dict_remove(dict, "SubtitlesForced");
2553 adeflist = ghb_dict_lookup(defaults, "AudioList");
2556 adefaults = ghb_array_get_nth(adeflist, 0);
2557 alist = ghb_dict_lookup(dict, "AudioList");
2558 count = ghb_array_len(alist);
2559 for (ii = 0; ii < count; ii++)
2561 adict = ghb_array_get_nth(alist, ii);
2563 mac_val = ghb_dict_lookup(adict, key);
2564 gval = import_audio_track_xlat2(mac_val);
2566 ghb_dict_insert(adict, g_strdup(key), gval);
2567 key = "AudioEncoder";
2568 mac_val = ghb_dict_lookup(adict, key);
2569 gval = import_value_xlat2(adefaults, acodec_xlat, key, mac_val);
2571 ghb_dict_insert(adict, g_strdup(key), gval);
2572 key = "AudioSamplerate";
2573 mac_val = ghb_dict_lookup(adict, key);
2574 gval = import_value_xlat2(adefaults, samplerate_xlat, key, mac_val);
2576 ghb_dict_insert(adict, g_strdup(key), gval);
2577 key = "AudioMixdown";
2578 mac_val = ghb_dict_lookup(adict, key);
2579 gval = import_value_xlat2(adefaults, mix_xlat, key, mac_val);
2581 ghb_dict_insert(adict, g_strdup(key), gval);
2583 mac_val = ghb_dict_lookup(adict, "AudioTrackDRCSlider");
2584 if (mac_val != NULL)
2587 drc = ghb_value_double(mac_val);
2588 if (drc < 1.0 && drc > 0.0)
2590 ghb_dict_insert(adict, g_strdup("AudioTrackDRCSlider"),
2591 ghb_double_value_new(0.0));
2599 import_xlat_preset(GValue *dict)
2606 g_debug("import_xlat_preset ()");
2607 uses_max = ghb_value_boolean(
2608 preset_dict_get_value(dict, "UsesMaxPictureSettings"));
2609 uses_pic = ghb_value_int(
2610 preset_dict_get_value(dict, "UsesPictureSettings"));
2611 par = ghb_value_int(preset_dict_get_value(dict, "PicturePAR"));
2612 vqtype = ghb_value_int(preset_dict_get_value(dict, "VideoQualityType"));
2614 if (uses_max || uses_pic == 2)
2616 ghb_dict_insert(dict, g_strdup("autoscale"),
2617 ghb_boolean_value_new(TRUE));
2623 if (ghb_dict_lookup(dict, "PictureModulus") == NULL)
2624 ghb_dict_insert(dict, g_strdup("PictureModulus"),
2625 ghb_int_value_new(16));
2629 ghb_dict_insert(dict, g_strdup("PictureModulus"),
2630 ghb_int_value_new(1));
2634 if (ghb_dict_lookup(dict, "PictureModulus") == NULL)
2635 ghb_dict_insert(dict, g_strdup("PictureModulus"),
2636 ghb_int_value_new(16));
2640 if (ghb_dict_lookup(dict, "PictureModulus") == NULL)
2641 ghb_dict_insert(dict, g_strdup("PictureModulus"),
2642 ghb_int_value_new(16));
2645 // VideoQualityType/0/1/2 - vquality_type_/target/bitrate/constant
2650 ghb_dict_insert(dict, g_strdup("vquality_type_target"),
2651 ghb_boolean_value_new(TRUE));
2652 ghb_dict_insert(dict, g_strdup("vquality_type_bitrate"),
2653 ghb_boolean_value_new(FALSE));
2654 ghb_dict_insert(dict, g_strdup("vquality_type_constant"),
2655 ghb_boolean_value_new(FALSE));
2659 ghb_dict_insert(dict, g_strdup("vquality_type_target"),
2660 ghb_boolean_value_new(FALSE));
2661 ghb_dict_insert(dict, g_strdup("vquality_type_bitrate"),
2662 ghb_boolean_value_new(TRUE));
2663 ghb_dict_insert(dict, g_strdup("vquality_type_constant"),
2664 ghb_boolean_value_new(FALSE));
2668 ghb_dict_insert(dict, g_strdup("vquality_type_target"),
2669 ghb_boolean_value_new(FALSE));
2670 ghb_dict_insert(dict, g_strdup("vquality_type_bitrate"),
2671 ghb_boolean_value_new(FALSE));
2672 ghb_dict_insert(dict, g_strdup("vquality_type_constant"),
2673 ghb_boolean_value_new(TRUE));
2677 ghb_dict_insert(dict, g_strdup("vquality_type_target"),
2678 ghb_boolean_value_new(FALSE));
2679 ghb_dict_insert(dict, g_strdup("vquality_type_bitrate"),
2680 ghb_boolean_value_new(FALSE));
2681 ghb_dict_insert(dict, g_strdup("vquality_type_constant"),
2682 ghb_boolean_value_new(TRUE));
2686 import_value_xlat(dict);
2688 GValue *mode = ghb_dict_lookup(dict, "VideoFramerateMode");
2691 GValue *fr = ghb_dict_lookup(dict, "VideoFramerate");
2695 gboolean pfr = FALSE;
2696 GValue *pfr_val = ghb_dict_lookup(dict, "VideoFrameratePFR");
2699 pfr = ghb_value_boolean(pfr_val);
2701 str = ghb_value_string(fr);
2702 if (strcmp(str, "source") == 0)
2704 ghb_dict_insert(dict, g_strdup("VideoFramerateCFR"),
2705 ghb_boolean_value_new(FALSE));
2706 ghb_dict_insert(dict, g_strdup("VideoFramerateVFR"),
2707 ghb_boolean_value_new(TRUE));
2711 ghb_dict_insert(dict, g_strdup("VideoFramerateCFR"),
2712 ghb_boolean_value_new(TRUE));
2713 ghb_dict_insert(dict, g_strdup("VideoFramerateVFR"),
2714 ghb_boolean_value_new(FALSE));
2718 ghb_dict_insert(dict, g_strdup("VideoFramerateCFR"),
2719 ghb_boolean_value_new(FALSE));
2720 ghb_dict_insert(dict, g_strdup("VideoFramerateVFR"),
2721 ghb_boolean_value_new(FALSE));
2729 str = ghb_value_string(mode);
2730 if (strcmp(str, "cfr") == 0)
2732 ghb_dict_insert(dict, g_strdup("VideoFramerateCFR"),
2733 ghb_boolean_value_new(TRUE));
2734 ghb_dict_insert(dict, g_strdup("VideoFrameratePFR"),
2735 ghb_boolean_value_new(FALSE));
2736 ghb_dict_insert(dict, g_strdup("VideoFramerateVFR"),
2737 ghb_boolean_value_new(FALSE));
2739 else if (strcmp(str, "pfr") == 0)
2741 ghb_dict_insert(dict, g_strdup("VideoFramerateCFR"),
2742 ghb_boolean_value_new(FALSE));
2743 ghb_dict_insert(dict, g_strdup("VideoFrameratePFR"),
2744 ghb_boolean_value_new(TRUE));
2745 ghb_dict_insert(dict, g_strdup("VideoFramerateVFR"),
2746 ghb_boolean_value_new(FALSE));
2750 ghb_dict_insert(dict, g_strdup("VideoFramerateCFR"),
2751 ghb_boolean_value_new(FALSE));
2752 ghb_dict_insert(dict, g_strdup("VideoFrameratePFR"),
2753 ghb_boolean_value_new(FALSE));
2754 ghb_dict_insert(dict, g_strdup("VideoFramerateVFR"),
2755 ghb_boolean_value_new(TRUE));
2763 vquality = ghb_value_double(preset_dict_get_value(dict, "VideoQualitySlider"));
2764 if (vquality > 0.0 && vquality < 1.0)
2768 gval = preset_dict_get_value(dict, "VideoEncoder");
2769 vcodec = ghb_lookup_combo_int("VideoEncoder", gval);
2772 case HB_VCODEC_X264:
2774 vquality = 51. - vquality * 51.;
2777 case HB_VCODEC_FFMPEG:
2779 vquality = 31. - vquality * 30.;
2782 case HB_VCODEC_THEORA:
2784 vquality = vquality * 63.;
2792 ghb_dict_insert(dict, g_strdup("VideoQualitySlider"),
2793 ghb_double_value_new(vquality));
2798 import_xlat_presets(GValue *presets)
2804 g_debug("import_xlat_presets ()");
2805 if (presets == NULL) return;
2806 count = ghb_array_len(presets);
2807 for (ii = 0; ii < count; ii++)
2809 dict = ghb_array_get_nth(presets, ii);
2810 folder = ghb_value_boolean(preset_dict_get_value(dict, "Folder"));
2815 nested = ghb_dict_lookup(dict, "ChildrenArray");
2816 import_xlat_presets(nested);
2820 import_xlat_preset(dict);
2826 export_xlat_preset(GValue *dict)
2828 gboolean autoscale, target, br, constant;
2830 g_debug("export_xlat_prest ()");
2831 autoscale = ghb_value_boolean(preset_dict_get_value(dict, "autoscale"));
2832 target = ghb_value_boolean(
2833 preset_dict_get_value(dict, "vquality_type_target"));
2834 br = ghb_value_boolean(
2835 preset_dict_get_value(dict, "vquality_type_bitrate"));
2836 constant = ghb_value_boolean(
2837 preset_dict_get_value(dict, "vquality_type_constant"));
2840 ghb_dict_insert(dict, g_strdup("UsesPictureSettings"),
2841 ghb_int_value_new(2));
2843 ghb_dict_insert(dict, g_strdup("UsesPictureSettings"),
2844 ghb_int_value_new(1));
2846 // VideoQualityType/0/1/2 - vquality_type_/target/bitrate/constant
2849 ghb_dict_insert(dict, g_strdup("VideoQualityType"),
2850 ghb_int_value_new(0));
2854 ghb_dict_insert(dict, g_strdup("VideoQualityType"),
2855 ghb_int_value_new(1));
2859 ghb_dict_insert(dict, g_strdup("VideoQualityType"),
2860 ghb_int_value_new(2));
2863 if (ghb_value_boolean(preset_dict_get_value(dict, "VideoFramerateCFR")))
2865 ghb_dict_insert(dict, g_strdup("VideoFramerateMode"),
2866 ghb_string_value_new("cfr"));
2868 else if (ghb_value_boolean(preset_dict_get_value(dict, "VideoFrameratePFR")))
2870 ghb_dict_insert(dict, g_strdup("VideoFramerateMode"),
2871 ghb_string_value_new("pfr"));
2875 ghb_dict_insert(dict, g_strdup("VideoFramerateMode"),
2876 ghb_string_value_new("vfr"));
2879 GValue *alist, *adict;
2882 alist = ghb_dict_lookup(dict, "AudioList");
2883 count = ghb_array_len(alist);
2884 for (ii = 0; ii < count; ii++)
2888 adict = ghb_array_get_nth(alist, ii);
2889 drc = ghb_value_double(
2890 preset_dict_get_value(adict, "AudioTrackDRCSlider"));
2891 if (drc < 1.0 && drc > 0.0)
2893 ghb_dict_insert(adict, g_strdup("AudioTrackDRCSlider"),
2894 ghb_double_value_new(0.0));
2899 GHashTableIter iter;
2902 internal = plist_get_dict(internalPlist, "XlatPresets");
2903 ghb_dict_iter_init(&iter, internal);
2904 // middle (void*) cast prevents gcc warning "defreferencing type-punned
2905 // pointer will break strict-aliasing rules"
2906 while (g_hash_table_iter_next(
2907 &iter, (gpointer*)(void*)&key, (gpointer*)(void*)&value))
2909 ghb_dict_remove(dict, key);
2912 // remove obsolete keys
2913 ghb_dict_remove(dict, "UsesMaxPictureSettings");
2914 ghb_dict_remove(dict, "VFR");
2915 ghb_dict_remove(dict, "VideoFrameratePFR");
2917 export_value_xlat(dict);
2921 export_xlat_presets(GValue *presets)
2927 if (presets == NULL) return;
2928 count = ghb_array_len(presets);
2929 for (ii = 0; ii < count; ii++)
2931 dict = ghb_array_get_nth(presets, ii);
2932 folder = ghb_value_boolean(preset_dict_get_value(dict, "Folder"));
2937 nested = ghb_dict_lookup(dict, "ChildrenArray");
2938 export_xlat_presets(nested);
2942 export_xlat_preset(dict);
2947 static guint prefs_timeout_id = 0;
2950 delayed_store_prefs(gpointer data)
2952 store_plist(prefsPlist, "preferences");
2953 prefs_timeout_id = 0;
2962 export = ghb_value_dup(presetsPlist);
2963 export_xlat_presets(export);
2964 store_plist(export, "presets");
2965 ghb_value_free(export);
2971 if (prefs_timeout_id != 0)
2976 mc = g_main_context_default();
2977 source = g_main_context_find_source_by_id(mc, prefs_timeout_id);
2979 g_source_destroy(source);
2981 prefs_timeout_id = g_timeout_add_seconds(1, (GSourceFunc)delayed_store_prefs, NULL);
2985 ghb_presets_reload(signal_user_data_t *ud)
2987 GValue *std_presets;
2991 g_debug("ghb_presets_reload()\n");
2992 std_presets = ghb_resource_get("standard-presets");
2993 if (std_presets == NULL) return;
2995 remove_std_presets(ud);
2996 indices = presets_find_default(presetsPlist, &len);
2999 presets_clear_default(std_presets);
3002 // Merge the keyfile contents into our presets
3003 count = ghb_array_len(std_presets);
3004 for (ii = count-1; ii >= 0; ii--)
3010 std_dict = ghb_array_get_nth(std_presets, ii);
3011 copy_dict = ghb_value_dup(std_dict);
3012 ghb_dict_insert(copy_dict, g_strdup("PresetBuildNumber"),
3013 ghb_int64_value_new(hb_get_build(NULL)));
3014 ghb_presets_insert(presetsPlist, copy_dict, &indices, 1);
3015 presets_list_insert(ud, &indices, 1);
3017 import_xlat_presets(presetsPlist);
3026 count = ghb_array_len(presetsPlist);
3027 for (ii = count-1; ii >= 0; ii--)
3032 dict = ghb_array_get_nth(presetsPlist, ii);
3033 type = ghb_dict_lookup(dict, "Type");
3041 replace_standard_presets()
3043 GValue *std_presets;
3047 count = ghb_array_len(presetsPlist);
3048 for (ii = count-1; ii >= 0; ii--)
3053 dict = ghb_array_get_nth(presetsPlist, ii);
3054 ptype = ghb_value_int(preset_dict_get_value(dict, "Type"));
3055 if (ptype == PRESETS_BUILTIN)
3058 ghb_presets_remove(presetsPlist, &indices, 1);
3062 std_presets = ghb_resource_get("standard-presets");
3063 if (std_presets == NULL) return;
3065 indices = presets_find_default(presetsPlist, &len);
3068 presets_clear_default(std_presets);
3071 // Merge the keyfile contents into our presets
3072 count = ghb_array_len(std_presets);
3073 for (ii = count-1; ii >= 0; ii--)
3079 std_dict = ghb_array_get_nth(std_presets, ii);
3080 copy_dict = ghb_value_dup(std_dict);
3081 ghb_dict_insert(copy_dict, g_strdup("PresetBuildNumber"),
3082 ghb_int64_value_new(hb_get_build(NULL)));
3083 ghb_presets_insert(presetsPlist, copy_dict, &indices, 1);
3085 import_xlat_presets(presetsPlist);
3090 update_standard_presets(signal_user_data_t *ud)
3094 count = ghb_array_len(presetsPlist);
3095 for (ii = count-1; ii >= 0; ii--)
3102 dict = ghb_array_get_nth(presetsPlist, ii);
3103 gval = ghb_dict_lookup(dict, "Type");
3106 // Old preset that doesn't have a Type
3107 replace_standard_presets();
3111 type = ghb_value_int(gval);
3114 gval = ghb_dict_lookup(dict, "PresetBuildNumber");
3117 // Old preset that doesn't have a build number
3118 replace_standard_presets();
3122 build = ghb_value_int64(gval);
3123 if (build != hb_get_build(NULL))
3125 // Build number does not match
3126 replace_standard_presets();
3135 ghb_presets_load(signal_user_data_t *ud)
3137 presetsPlist = load_plist("presets");
3138 if (presetsPlist == NULL)
3140 presetsPlist = ghb_value_dup(ghb_resource_get("standard-presets"));
3141 import_xlat_presets(presetsPlist);
3144 else if (G_VALUE_TYPE(presetsPlist) == ghb_dict_get_type())
3145 { // Presets is older dictionary format. Convert to array
3146 ghb_value_free(presetsPlist);
3147 presetsPlist = ghb_value_dup(ghb_resource_get("standard-presets"));
3148 import_xlat_presets(presetsPlist);
3151 else if (check_old_presets())
3153 ghb_value_free(presetsPlist);
3154 presetsPlist = ghb_value_dup(ghb_resource_get("standard-presets"));
3155 import_xlat_presets(presetsPlist);
3158 update_standard_presets(ud);
3159 import_xlat_presets(presetsPlist);
3163 settings_save(signal_user_data_t *ud, const GValue *path)
3165 GValue *dict, *internal;
3166 GHashTableIter iter;
3169 gint *indices, len, count;
3170 gint *def_indices, def_len;
3172 gboolean replace = FALSE;
3174 g_debug("settings_save");
3175 if (internalPlist == NULL) return;
3176 count = ghb_array_len(path);
3177 name = g_value_get_string(ghb_array_get_nth(path, count-1));
3178 indices = ghb_preset_indices_from_path(presetsPlist, path, &len);
3181 if (ghb_presets_get_folder(presetsPlist, indices, len))
3184 message = g_strdup_printf(
3185 "%s: Folder already exists.\n"
3186 "You can not replace it with a preset.",
3188 ghb_message_dialog(GTK_MESSAGE_ERROR, message, "Cancel", NULL);
3192 dict = ghb_dict_value_new();
3193 ghb_presets_replace(presetsPlist, dict, indices, len);
3198 indices = presets_find_pos(path, PRESETS_CUSTOM, &len);
3201 dict = ghb_dict_value_new();
3202 ghb_presets_insert(presetsPlist, dict, indices, len);
3206 g_warning("failed to find insert path");
3210 current_preset = dict;
3211 ghb_settings_set_int64(ud->settings, "Type", PRESETS_CUSTOM);
3212 ghb_settings_set_int64(ud->settings, "PresetBuildNumber", hb_get_build(NULL));
3214 internal = plist_get_dict(internalPlist, "Presets");
3215 ghb_dict_iter_init(&iter, internal);
3216 // middle (void*) cast prevents gcc warning "defreferencing type-punned
3217 // pointer will break strict-aliasing rules"
3218 while (g_hash_table_iter_next(
3219 &iter, (gpointer*)(void*)&key, (gpointer*)(void*)&value))
3223 gval = ghb_settings_get_value(ud->settings, key);
3228 ghb_dict_insert(dict, g_strdup(key), ghb_value_dup(gval));
3230 internal = plist_get_dict(internalPlist, "XlatPresets");
3231 ghb_dict_iter_init(&iter, internal);
3232 // middle (void*) cast prevents gcc warning "defreferencing type-punned
3233 // pointer will break strict-aliasing rules"
3234 while (g_hash_table_iter_next(
3235 &iter, (gpointer*)(void*)&key, (gpointer*)(void*)&value))
3239 gval = ghb_settings_get_value(ud->settings, key);
3244 ghb_dict_insert(dict, g_strdup(key), ghb_value_dup(gval));
3246 ghb_dict_insert(dict, g_strdup("PresetName"), ghb_string_value_new(name));
3249 def_indices = presets_find_default(presetsPlist, &def_len);
3250 if (def_indices != NULL &&
3251 preset_path_cmp(indices, len, def_indices, def_len) != 0)
3253 ghb_dict_insert(dict, g_strdup("Default"),
3254 ghb_boolean_value_new(FALSE));
3256 presets_list_update_item(ud, indices, len, FALSE);
3260 ghb_dict_insert(dict, g_strdup("Default"),
3261 ghb_boolean_value_new(FALSE));
3262 presets_list_insert(ud, indices, len);
3264 if (!ghb_settings_get_boolean( ud->settings, "PictureWidthEnable"))
3266 ghb_dict_remove(dict, "PictureWidth");
3268 if (!ghb_settings_get_boolean( ud->settings, "PictureHeightEnable"))
3270 ghb_dict_remove(dict, "PictureHeight");
3272 ghb_dict_insert(dict, g_strdup("autoscale"),
3273 ghb_boolean_value_new(
3274 !ghb_settings_get_boolean( ud->settings, "PictureWidthEnable") &&
3275 !ghb_settings_get_boolean( ud->settings, "PictureHeightEnable")
3279 ud->dont_clear_presets = TRUE;
3280 // Make the new preset the selected item
3281 ghb_select_preset2(ud->builder, indices, len);
3283 ud->dont_clear_presets = FALSE;
3288 folder_save(signal_user_data_t *ud, const GValue *path)
3290 GValue *dict, *folder;
3291 gint *indices, len, count;
3294 count = ghb_array_len(path);
3295 name = g_value_get_string(ghb_array_get_nth(path, count-1));
3296 indices = ghb_preset_indices_from_path(presetsPlist, path, &len);
3299 if (!ghb_presets_get_folder(presetsPlist, indices, len))
3302 message = g_strdup_printf(
3303 "%s: Preset already exists.\n"
3304 "You can not replace it with a folder.",
3306 ghb_message_dialog(GTK_MESSAGE_ERROR, message, "Cancel", NULL);
3311 // Already exists, update its description
3312 dict = presets_get_dict(presetsPlist, indices, len);
3313 ghb_dict_insert(dict, g_strdup("PresetDescription"),
3314 ghb_value_dup(preset_dict_get_value(
3315 ud->settings, "PresetDescription")));
3316 presets_list_update_item(ud, indices, len, FALSE);
3323 indices = presets_find_pos(path, PRESETS_CUSTOM, &len);
3326 dict = ghb_dict_value_new();
3327 ghb_presets_insert(presetsPlist, dict, indices, len);
3331 g_warning("failed to find insert path");
3335 ghb_dict_insert(dict, g_strdup("PresetDescription"),
3336 ghb_value_dup(preset_dict_get_value(
3337 ud->settings, "PresetDescription")));
3338 ghb_dict_insert(dict, g_strdup("PresetName"), ghb_string_value_new(name));
3339 folder = ghb_array_value_new(8);
3340 ghb_dict_insert(dict, g_strdup("ChildrenArray"), folder);
3341 ghb_dict_insert(dict, g_strdup("Type"),
3342 ghb_int64_value_new(PRESETS_CUSTOM));
3343 ghb_dict_insert(dict, g_strdup("Folder"), ghb_boolean_value_new(TRUE));
3345 presets_list_insert(ud, indices, len);
3352 ghb_presets_list_default(signal_user_data_t *ud)
3354 GtkTreeView *treeview;
3355 GtkTreePath *treepath;
3357 GtkTreeStore *store;
3360 g_debug("ghb_presets_list_default ()");
3361 treeview = GTK_TREE_VIEW(GHB_WIDGET(ud->builder, "presets_list"));
3362 store = GTK_TREE_STORE(gtk_tree_view_get_model(treeview));
3363 indices = presets_find_default(presetsPlist, &len);
3364 if (indices == NULL) return;
3365 treepath = ghb_tree_path_new_from_indices(indices, len);
3368 if (gtk_tree_model_get_iter(GTK_TREE_MODEL(store), &iter, treepath))
3370 gtk_tree_store_set(store, &iter,
3375 gtk_tree_path_free(treepath);
3381 ghb_presets_list_clear_default(signal_user_data_t *ud)
3383 GtkTreeView *treeview;
3384 GtkTreePath *treepath;
3386 GtkTreeStore *store;
3389 g_debug("ghb_presets_list_clear_default ()");
3390 treeview = GTK_TREE_VIEW(GHB_WIDGET(ud->builder, "presets_list"));
3391 store = GTK_TREE_STORE(gtk_tree_view_get_model(treeview));
3392 indices = presets_find_default(presetsPlist, &len);
3393 if (indices == NULL) return;
3394 treepath = ghb_tree_path_new_from_indices(indices, len);
3397 if (gtk_tree_model_get_iter(GTK_TREE_MODEL(store), &iter, treepath))
3399 gtk_tree_store_set(store, &iter,
3404 gtk_tree_path_free(treepath);
3410 update_audio_presets(signal_user_data_t *ud)
3412 g_debug("update_audio_presets");
3413 const GValue *audio_list;
3415 audio_list = ghb_settings_get_value(ud->settings, "audio_list");
3416 ghb_settings_set_value(ud->settings, "AudioList", audio_list);
3420 update_subtitle_presets(signal_user_data_t *ud)
3422 g_debug("update_subtitle_presets");
3423 const GValue *subtitle_list, *subtitle;
3424 GValue *slist, *dict;
3425 gint count, ii, source;
3427 subtitle_list = ghb_settings_get_value(ud->settings, "subtitle_list");
3428 slist = ghb_array_value_new(8);
3429 count = ghb_array_len(subtitle_list);
3430 for (ii = 0; ii < count; ii++)
3432 subtitle = ghb_array_get_nth(subtitle_list, ii);
3433 source = ghb_settings_get_int(subtitle, "SubtitleSource");
3434 if (source != SRTSUB)
3436 dict = ghb_value_dup(subtitle);
3437 ghb_array_append(slist, dict);
3440 ghb_settings_take_value(ud->settings, "SubtitleList", slist);
3443 G_MODULE_EXPORT void
3444 presets_menu_clicked_cb(GtkWidget *xwidget, signal_user_data_t *ud)
3448 menu = GTK_MENU(GHB_WIDGET(ud->builder, "presets_menu"));
3449 gtk_menu_popup(menu, NULL, NULL, NULL, NULL, 1,
3450 gtk_get_current_event_time());
3453 G_MODULE_EXPORT void
3454 preset_import_clicked_cb(GtkWidget *xwidget, signal_user_data_t *ud)
3457 GtkResponseType response;
3460 GtkFileFilter *filter;
3462 g_debug("preset_import_clicked_cb ()");
3464 dialog = gtk_file_chooser_dialog_new("Import Preset", NULL,
3465 GTK_FILE_CHOOSER_ACTION_OPEN,
3466 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
3467 GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
3470 filter = gtk_file_filter_new();
3471 gtk_file_filter_set_name(filter, "All (*)");
3472 gtk_file_filter_add_pattern(filter, "*");
3473 gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(dialog), filter);
3475 filter = gtk_file_filter_new();
3476 gtk_file_filter_set_name(filter, "Presets (*.plist)");
3477 gtk_file_filter_add_pattern(filter, "*.plist");
3478 gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(dialog), filter);
3479 gtk_file_chooser_set_filter(GTK_FILE_CHOOSER(dialog), filter);
3481 exportDir = ghb_settings_get_string(ud->settings, "ExportDirectory");
3482 if (exportDir == NULL || exportDir[0] == '\0')
3484 exportDir = g_strdup(".");
3486 gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(dialog), exportDir);
3489 response = gtk_dialog_run(GTK_DIALOG(dialog));
3490 gtk_widget_hide(dialog);
3491 if (response == GTK_RESPONSE_ACCEPT)
3493 GValue *dict, *array;
3497 filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog));
3499 // import the preset
3500 if (!g_file_test(filename, G_FILE_TEST_IS_REGULAR))
3502 gtk_widget_destroy(dialog);
3506 array = ghb_plist_parse_file(filename);
3508 import_xlat_presets(array);
3509 presets_clear_default(array);
3510 presets_customize(array);
3512 count = ghb_array_len(array);
3513 for (ii = 0; ii < count; ii++)
3515 GValue *path, *name;
3519 dict = ghb_array_get_nth(array, ii);
3520 path = ghb_array_value_new(1);
3521 name = ghb_value_dup(ghb_dict_lookup(dict, "PresetName"));
3522 ghb_array_append(path, name);
3523 indices = ghb_preset_indices_from_path(presetsPlist, path, &len);
3524 // Modify the preset name till we make it unique
3525 while (indices != NULL)
3527 gchar *str = ghb_value_string(name);
3529 ghb_value_free(path);
3532 str = g_strdup_printf("%s %d", str, index);
3533 path = ghb_array_value_new(1);
3534 name = ghb_string_value_new(str);
3535 ghb_array_append(path, name);
3539 indices = ghb_preset_indices_from_path(presetsPlist, path, &len);
3541 ghb_dict_insert(dict, g_strdup("PresetName"), ghb_value_dup(name));
3542 indices = presets_find_pos(path, PRESETS_CUSTOM, &len);
3543 ghb_presets_insert(presetsPlist, ghb_value_dup(dict), indices, len);
3544 presets_list_insert(ud, indices, len);
3545 ghb_value_free(path);
3547 ghb_value_free(array);
3549 exportDir = ghb_settings_get_string(ud->settings, "ExportDirectory");
3550 dir = g_path_get_dirname(filename);
3551 if (strcmp(dir, exportDir) != 0)
3553 ghb_settings_set_string(ud->settings, "ExportDirectory", dir);
3554 ghb_pref_save(ud->settings, "ExportDirectory");
3561 gtk_widget_destroy(dialog);
3564 G_MODULE_EXPORT void
3565 preset_export_clicked_cb(GtkWidget *xwidget, signal_user_data_t *ud)
3568 GtkResponseType response;
3570 const gchar *name = "";
3571 gint count, *indices, len;
3575 g_debug("preset_export_clicked_cb ()");
3576 preset = ghb_settings_get_value (ud->settings, "preset_selection");
3580 count = ghb_array_len(preset);
3584 name = g_value_get_string(ghb_array_get_nth(preset, count-1));
3586 dialog = gtk_file_chooser_dialog_new("Export Preset", NULL,
3587 GTK_FILE_CHOOSER_ACTION_SAVE,
3588 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
3589 GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT,
3592 exportDir = ghb_settings_get_string(ud->settings, "ExportDirectory");
3593 if (exportDir == NULL || exportDir[0] == '\0')
3595 exportDir = g_strdup(".");
3597 filename = g_strdup_printf("%s.plist", name);
3598 gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(dialog), exportDir);
3599 gtk_file_chooser_set_current_name(GTK_FILE_CHOOSER(dialog), filename);
3603 indices = ghb_preset_indices_from_path(presetsPlist, preset, &len);
3604 if (indices == NULL)
3607 response = gtk_dialog_run(GTK_DIALOG(dialog));
3608 gtk_widget_hide(dialog);
3609 if (response == GTK_RESPONSE_ACCEPT)
3611 GValue *export, *dict, *array;
3615 filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog));
3617 // export the preset
3618 dict = presets_get_dict(presetsPlist, indices, len);
3620 export = ghb_value_dup(dict);
3621 array = ghb_array_value_new(1);
3622 ghb_array_append(array, export);
3623 presets_clear_default(array);
3624 presets_customize(array);
3625 export_xlat_presets(array);
3627 file = g_fopen(filename, "w");
3630 ghb_plist_write(file, array);
3633 ghb_value_free(array);
3635 exportDir = ghb_settings_get_string(ud->settings, "ExportDirectory");
3636 dir = g_path_get_dirname(filename);
3637 if (strcmp(dir, exportDir) != 0)
3639 ghb_settings_set_string(ud->settings, "ExportDirectory", dir);
3640 ghb_pref_save(ud->settings, "ExportDirectory");
3646 gtk_widget_destroy(dialog);
3650 G_MODULE_EXPORT void
3651 presets_new_folder_clicked_cb(GtkWidget *xwidget, signal_user_data_t *ud)
3656 GtkResponseType response;
3657 GValue *preset, *dict;
3658 const gchar *name = "";
3659 const gchar *description = "";
3660 gint count, *indices, len;
3662 g_debug("presets_new_folder_clicked_cb ()");
3663 preset = ghb_settings_get_value (ud->settings, "preset_selection");
3665 count = ghb_array_len(preset);
3667 name = g_value_get_string(ghb_array_get_nth(preset, count-1));
3671 indices = ghb_preset_indices_from_path(presetsPlist, preset, &len);
3672 dict = presets_get_dict(presetsPlist, indices, len);
3675 description = g_value_get_string(
3676 ghb_dict_lookup(dict, "PresetDescription"));
3677 ghb_ui_update(ud, "FolderDescription", ghb_string_value(description));
3680 desc = GTK_TEXT_VIEW(GHB_WIDGET(ud->builder, "FolderDescription"));
3681 dialog = GHB_WIDGET(ud->builder, "preset_new_folder_dialog");
3682 entry = GTK_ENTRY(GHB_WIDGET(ud->builder, "FolderName"));
3683 gtk_entry_set_text(entry, name);
3684 response = gtk_dialog_run(GTK_DIALOG(dialog));
3685 gtk_widget_hide(dialog);
3686 if (response == GTK_RESPONSE_OK)
3689 const gchar *name = gtk_entry_get_text(entry);
3692 if (count > MAX_NESTED_PRESET-1)
3693 count = MAX_NESTED_PRESET-1;
3695 dest = ghb_array_value_new(MAX_NESTED_PRESET);
3696 if (indices != NULL)
3700 ptype = ghb_presets_get_type(presetsPlist, indices, len);
3701 if (ptype == PRESETS_CUSTOM)
3703 ghb_array_copy(dest, preset, count-1);
3706 ghb_array_append(dest, ghb_string_value_new(name));
3707 GValue *val = ghb_widget_value(GTK_WIDGET(desc));
3708 ghb_settings_set_value(ud->settings, "PresetDescription", val);
3709 folder_save(ud, dest);
3710 ghb_value_free(dest);
3712 if (indices != NULL)
3716 G_MODULE_EXPORT void
3717 presets_save_clicked_cb(GtkWidget *xwidget, signal_user_data_t *ud)
3722 GtkResponseType response;
3724 const gchar *name = "";
3725 gint count, *indices, len;
3727 g_debug("presets_save_clicked_cb ()");
3728 preset = ghb_settings_get_value (ud->settings, "preset_selection");
3730 count = ghb_array_len(preset);
3732 name = g_value_get_string(ghb_array_get_nth(preset, count-1));
3736 desc = GTK_TEXT_VIEW(GHB_WIDGET(ud->builder, "PresetDescription"));
3737 int width = ghb_settings_get_int(ud->settings, "PictureWidth");
3738 int height = ghb_settings_get_int(ud->settings, "PictureHeight");
3739 gboolean autoscale = ghb_settings_get_boolean(ud->settings, "autoscale");
3740 ghb_ui_update(ud, "PictureWidthEnable",
3741 ghb_boolean_value(width!=0&&!autoscale));
3742 ghb_ui_update(ud, "PictureHeightEnable",
3743 ghb_boolean_value(height!=0&&!autoscale));
3746 width = ghb_settings_get_int(ud->settings, "scale_width");
3747 ghb_ui_update(ud, "PictureWidth", ghb_int_value(width));
3751 height = ghb_settings_get_int(ud->settings, "scale_height");
3752 ghb_ui_update(ud, "PictureHeight", ghb_int_value(height));
3754 dialog = GHB_WIDGET(ud->builder, "preset_save_dialog");
3755 entry = GTK_ENTRY(GHB_WIDGET(ud->builder, "PresetName"));
3756 gtk_entry_set_text(entry, name);
3757 response = gtk_dialog_run(GTK_DIALOG(dialog));
3758 gtk_widget_hide(dialog);
3759 if (response == GTK_RESPONSE_OK)
3762 const gchar *name = gtk_entry_get_text(entry);
3765 dest = ghb_array_value_new(MAX_NESTED_PRESET);
3766 indices = ghb_preset_indices_from_path(presetsPlist, preset, &len);
3771 ptype = ghb_presets_get_type(presetsPlist, indices, len);
3772 if (ptype == PRESETS_CUSTOM)
3774 ghb_array_copy(dest, preset, count-1);
3778 ghb_array_append(dest, ghb_string_value_new(name));
3780 ghb_widget_to_setting(ud->settings, GTK_WIDGET(desc));
3782 // Construct the audio settings presets from the current audio list
3783 update_audio_presets(ud);
3784 update_subtitle_presets(ud);
3785 settings_save(ud, dest);
3786 ghb_value_free(dest);
3790 G_MODULE_EXPORT void
3791 preset_type_changed_cb(GtkWidget *widget, signal_user_data_t *ud)
3793 ghb_widget_to_setting(ud->settings, widget);
3796 G_MODULE_EXPORT void
3797 presets_restore_clicked_cb(GtkWidget *xwidget, signal_user_data_t *ud)
3801 g_debug("presets_restore_clicked_cb ()");
3802 // Reload only the standard presets
3803 ghb_presets_reload(ud);
3804 // Updating the presets list shuffles things around
3805 // need to make sure the proper preset is selected
3806 preset = ghb_settings_get_value (ud->settings, "preset");
3807 ghb_select_preset(ud->builder, preset);
3810 G_MODULE_EXPORT void
3811 presets_remove_clicked_cb(GtkWidget *xwidget, signal_user_data_t *ud)
3813 GtkTreeView *treeview;
3814 GtkTreeSelection *selection;
3815 GtkTreeModel *store;
3818 GtkResponseType response;
3820 g_debug("presets_remove_clicked_cb ()");
3821 treeview = GTK_TREE_VIEW(GHB_WIDGET(ud->builder, "presets_list"));
3822 selection = gtk_tree_view_get_selection (treeview);
3823 if (gtk_tree_selection_get_selected(selection, &store, &iter))
3830 gtk_tree_model_get(store, &iter, 0, &preset, -1);
3831 path = gtk_tree_model_get_path(store, &iter);
3832 indices = gtk_tree_path_get_indices(path);
3833 len = gtk_tree_path_get_depth(path);
3835 folder = ghb_presets_get_folder(presetsPlist, indices, len);
3836 dialog = gtk_message_dialog_new(NULL, GTK_DIALOG_MODAL,
3837 GTK_MESSAGE_QUESTION, GTK_BUTTONS_YES_NO,
3838 "Confirm deletion of %s:\n\n%s",
3839 folder ? "folder" : "preset",
3841 response = gtk_dialog_run(GTK_DIALOG(dialog));
3842 gtk_widget_destroy (dialog);
3843 if (response == GTK_RESPONSE_YES)
3845 GtkTreeIter nextIter = iter;
3846 gboolean valid = TRUE;
3847 if (!gtk_tree_model_iter_next(store, &nextIter))
3849 if (!gtk_tree_model_iter_parent(store, &nextIter, &iter))
3854 // Remove the selected item
3855 // First unselect it so that selecting the new item works properly
3856 gtk_tree_selection_unselect_iter (selection, &iter);
3857 if (ghb_presets_remove(presetsPlist, indices, len))
3860 presets_list_remove(ud, indices, len);
3863 valid = gtk_tree_model_get_iter_first(store, &nextIter);
3866 gtk_tree_path_free(path);
3867 path = gtk_tree_model_get_path(store, &nextIter);
3868 indices = gtk_tree_path_get_indices(path);
3869 len = gtk_tree_path_get_depth(path);
3870 ghb_select_preset2(ud->builder, indices, len);
3874 gtk_tree_path_free(path);
3878 // controls where valid drop locations are
3879 G_MODULE_EXPORT gboolean
3880 presets_drag_motion_cb(
3882 GdkDragContext *ctx,
3886 signal_user_data_t *ud)
3888 GtkTreePath *path = NULL;
3889 GtkTreeViewDropPosition drop_pos;
3893 GtkTreeModel *model;
3894 GtkTreeSelection *select;
3895 gint src_ptype, dst_ptype;
3896 gboolean src_folder, dst_folder;
3898 gint tree_depth, ii;
3901 widget = gtk_drag_get_source_widget(ctx);
3902 if (widget == NULL || widget != GTK_WIDGET(tv))
3905 // Get the type of the object being dragged
3906 srctv = GTK_TREE_VIEW(gtk_drag_get_source_widget(ctx));
3907 select = gtk_tree_view_get_selection (srctv);
3908 gtk_tree_selection_get_selected (select, &model, &iter);
3909 path = gtk_tree_model_get_path (model, &iter);
3910 indices = gtk_tree_path_get_indices(path);
3911 len = gtk_tree_path_get_depth(path);
3913 preset = presets_get_dict(presetsPlist, indices, len);
3914 tree_depth = preset_tree_depth(preset);
3916 src_ptype = ghb_presets_get_type(presetsPlist, indices, len);
3917 src_folder = ghb_presets_get_folder(presetsPlist, indices, len);
3918 gtk_tree_path_free(path);
3920 if (src_folder && tree_depth == 1)
3923 // The rest checks that the destination is a valid position
3925 gtk_tree_view_get_dest_row_at_pos (tv, x, y, &path, &drop_pos);
3928 gdk_drag_status(ctx, 0, time);
3931 // Don't allow repositioning of builtin presets
3932 if (src_ptype != PRESETS_CUSTOM)
3934 gdk_drag_status(ctx, 0, time);
3938 len = gtk_tree_path_get_depth(path);
3939 if (len+tree_depth-1 >= MAX_NESTED_PRESET)
3941 if (drop_pos == GTK_TREE_VIEW_DROP_INTO_OR_BEFORE)
3942 drop_pos = GTK_TREE_VIEW_DROP_BEFORE;
3943 if (drop_pos == GTK_TREE_VIEW_DROP_INTO_OR_AFTER)
3944 drop_pos = GTK_TREE_VIEW_DROP_AFTER;
3946 for (ii = len+tree_depth-1; ii > MAX_NESTED_PRESET; ii--)
3947 gtk_tree_path_up(path);
3948 indices = gtk_tree_path_get_indices(path);
3949 len = gtk_tree_path_get_depth(path);
3950 dst_ptype = ghb_presets_get_type(presetsPlist, indices, len);
3951 dst_folder = ghb_presets_get_folder(presetsPlist, indices, len);
3952 // Don't allow mixing custom presets in the builtins
3953 if (dst_ptype != PRESETS_CUSTOM)
3955 gdk_drag_status(ctx, 0, time);
3959 // Only allow *drop into* for folders
3962 if (drop_pos == GTK_TREE_VIEW_DROP_INTO_OR_BEFORE)
3963 drop_pos = GTK_TREE_VIEW_DROP_BEFORE;
3964 if (drop_pos == GTK_TREE_VIEW_DROP_INTO_OR_AFTER)
3965 drop_pos = GTK_TREE_VIEW_DROP_AFTER;
3968 len = gtk_tree_path_get_depth(path);
3969 gtk_tree_view_set_drag_dest_row(tv, path, drop_pos);
3970 gtk_tree_path_free(path);
3971 gdk_drag_status(ctx, GDK_ACTION_MOVE, time);
3975 G_MODULE_EXPORT void
3977 GtkTreeView *dstwidget,
3980 GtkSelectionData *selection_data,
3981 guint info, guint t,
3982 signal_user_data_t *ud)
3984 GtkTreePath *path = NULL;
3985 GtkTreeViewDropPosition drop_pos;
3986 GtkTreeIter dstiter, srciter;
3987 gint *dst_indices, dst_len, *src_indices, src_len;
3989 gboolean src_folder, dst_folder;
3991 GtkTreeModel *dstmodel = gtk_tree_view_get_model(dstwidget);
3993 g_debug("preset_drag_cb ()");
3994 // This doesn't work here for some reason...
3995 // gtk_tree_view_get_drag_dest_row(dstwidget, &path, &drop_pos);
3996 gtk_tree_view_get_dest_row_at_pos (dstwidget, x, y, &path, &drop_pos);
3997 // This little hack is needed because attempting to drop after
3998 // the last item gives us no path or drop_pos.
4003 n_children = gtk_tree_model_iter_n_children(dstmodel, NULL);
4006 drop_pos = GTK_TREE_VIEW_DROP_AFTER;
4007 path = gtk_tree_path_new_from_indices(n_children-1, -1);
4011 drop_pos = GTK_TREE_VIEW_DROP_BEFORE;
4012 path = gtk_tree_path_new_from_indices(0, -1);
4017 GtkTreeView *srcwidget;
4018 GtkTreeModel *srcmodel;
4019 GtkTreeSelection *select;
4020 GtkTreePath *srcpath = NULL;
4022 gint tree_depth, ii;
4024 srcwidget = GTK_TREE_VIEW(gtk_drag_get_source_widget(dc));
4025 select = gtk_tree_view_get_selection (srcwidget);
4026 gtk_tree_selection_get_selected (select, &srcmodel, &srciter);
4028 srcpath = gtk_tree_model_get_path (srcmodel, &srciter);
4029 src_indices = gtk_tree_path_get_indices(srcpath);
4030 src_len = gtk_tree_path_get_depth(srcpath);
4031 src_ptype = ghb_presets_get_type(presetsPlist, src_indices, src_len);
4032 src_folder = ghb_presets_get_folder(presetsPlist, src_indices, src_len);
4033 preset = ghb_value_dup(
4034 presets_get_dict(presetsPlist, src_indices, src_len));
4035 gtk_tree_path_free(srcpath);
4037 // Don't allow repositioning of builtin presets
4038 if (src_ptype != PRESETS_CUSTOM)
4041 tree_depth = preset_tree_depth(preset);
4042 if (src_folder && tree_depth == 1)
4045 dst_len = gtk_tree_path_get_depth(path);
4046 if (dst_len+tree_depth-1 >= MAX_NESTED_PRESET)
4048 if (drop_pos == GTK_TREE_VIEW_DROP_INTO_OR_BEFORE)
4049 drop_pos = GTK_TREE_VIEW_DROP_BEFORE;
4050 if (drop_pos == GTK_TREE_VIEW_DROP_INTO_OR_AFTER)
4051 drop_pos = GTK_TREE_VIEW_DROP_AFTER;
4054 for (ii = dst_len+tree_depth-1; ii > MAX_NESTED_PRESET; ii--)
4055 gtk_tree_path_up(path);
4056 dst_indices = gtk_tree_path_get_indices(path);
4057 dst_len = gtk_tree_path_get_depth(path);
4058 dst_folder = ghb_presets_get_folder(presetsPlist, dst_indices, dst_len);
4059 // Only allow *drop into* for folders
4062 if (drop_pos == GTK_TREE_VIEW_DROP_INTO_OR_BEFORE)
4063 drop_pos = GTK_TREE_VIEW_DROP_BEFORE;
4064 if (drop_pos == GTK_TREE_VIEW_DROP_INTO_OR_AFTER)
4065 drop_pos = GTK_TREE_VIEW_DROP_AFTER;
4067 if (gtk_tree_model_get_iter (dstmodel, &dstiter, path))
4070 GtkTreePath *dstpath = NULL;
4074 case GTK_TREE_VIEW_DROP_BEFORE:
4075 gtk_tree_store_insert_before(GTK_TREE_STORE (dstmodel),
4076 &iter, NULL, &dstiter);
4079 case GTK_TREE_VIEW_DROP_INTO_OR_BEFORE:
4080 gtk_tree_store_insert(GTK_TREE_STORE (dstmodel),
4081 &iter, &dstiter, 0);
4084 case GTK_TREE_VIEW_DROP_AFTER:
4085 gtk_tree_store_insert_after(GTK_TREE_STORE (dstmodel),
4086 &iter, NULL, &dstiter);
4089 case GTK_TREE_VIEW_DROP_INTO_OR_AFTER:
4090 gtk_tree_store_insert_after(GTK_TREE_STORE (dstmodel),
4091 &iter, &dstiter, 0);
4098 dstpath = gtk_tree_model_get_path (dstmodel, &iter);
4099 dst_indices = gtk_tree_path_get_indices(dstpath);
4100 dst_len = gtk_tree_path_get_depth(dstpath);
4101 ghb_presets_insert(presetsPlist, preset, dst_indices, dst_len);
4102 gtk_tree_path_free(dstpath);
4104 srcpath = gtk_tree_model_get_path (srcmodel, &srciter);
4105 src_indices = gtk_tree_path_get_indices(srcpath);
4106 src_len = gtk_tree_path_get_depth(srcpath);
4107 ghb_presets_remove(presetsPlist, src_indices, src_len);
4108 gtk_tree_path_free(srcpath);
4110 gtk_tree_store_remove (GTK_TREE_STORE (srcmodel), &srciter);
4112 dstpath = gtk_tree_model_get_path (dstmodel, &iter);
4113 dst_indices = gtk_tree_path_get_indices(dstpath);
4114 dst_len = gtk_tree_path_get_depth(dstpath);
4115 presets_list_update_item(ud, dst_indices, dst_len, TRUE);
4116 gtk_tree_path_free(dstpath);
4120 gtk_tree_path_free(path);
4125 presets_row_expanded_cb(
4126 GtkTreeView *treeview,
4129 signal_user_data_t *ud)
4132 gboolean expanded, folder;
4135 expanded = gtk_tree_view_row_expanded(treeview, path);
4136 indices = gtk_tree_path_get_indices(path);
4137 len = gtk_tree_path_get_depth(path);
4138 dict = presets_get_dict(presetsPlist, indices, len);
4139 if (preset_folder_is_open(dict))
4148 folder = ghb_presets_get_folder(presetsPlist, indices, len);
4151 presets_set_folder_open(expanded, indices, len);
4154 // Collapsing parent folder collapses all children
4157 GValue *presets = NULL;
4158 gint *more_indices, count, ii;
4160 more_indices = g_malloc((len+1)*sizeof(gint));
4161 memcpy(more_indices, indices, len*sizeof(gint));
4163 presets = presets_get_folder(presetsPlist, indices, len);
4164 count = ghb_array_len(presets);
4165 for (ii = 0; ii < count; ii++)
4167 dict = ghb_array_get_nth(presets, ii);
4168 folder = ghb_preset_folder(dict);
4171 more_indices[len] = ii;
4172 presets_set_folder_open(expanded, more_indices, len+1);
4175 g_free(more_indices);
4181 preset_update_title_deps(signal_user_data_t *ud, ghb_title_info_t *tinfo)
4185 ghb_ui_update(ud, "scale_width",
4186 ghb_int64_value(tinfo->width - tinfo->crop[2] - tinfo->crop[3]));
4187 // If anamorphic or keep_aspect, the hight will be automatically calculated
4188 gboolean keep_aspect;
4190 keep_aspect = ghb_settings_get_boolean(ud->settings, "PictureKeepRatio");
4191 pic_par = ghb_settings_combo_int(ud->settings, "PicturePAR");
4192 if (!(keep_aspect || pic_par) || pic_par == 3)
4194 ghb_ui_update(ud, "scale_height",
4195 ghb_int64_value(tinfo->height - tinfo->crop[0] - tinfo->crop[1]));
4198 // Set the limits of cropping. hb_set_anamorphic_size crashes if
4199 // you pass it a cropped width or height == 0.
4201 bound = tinfo->height / 2 - 2;
4202 widget = GHB_WIDGET (ud->builder, "PictureTopCrop");
4203 gtk_spin_button_set_range (GTK_SPIN_BUTTON(widget), 0, bound);
4204 widget = GHB_WIDGET (ud->builder, "PictureBottomCrop");
4205 gtk_spin_button_set_range (GTK_SPIN_BUTTON(widget), 0, bound);
4206 bound = tinfo->width / 2 - 2;
4207 widget = GHB_WIDGET (ud->builder, "PictureLeftCrop");
4208 gtk_spin_button_set_range (GTK_SPIN_BUTTON(widget), 0, bound);
4209 widget = GHB_WIDGET (ud->builder, "PictureRightCrop");
4210 gtk_spin_button_set_range (GTK_SPIN_BUTTON(widget), 0, bound);
4211 if (ghb_settings_get_boolean(ud->settings, "PictureAutoCrop"))
4213 ghb_ui_update(ud, "PictureTopCrop", ghb_int64_value(tinfo->crop[0]));
4214 ghb_ui_update(ud, "PictureBottomCrop", ghb_int64_value(tinfo->crop[1]));
4215 ghb_ui_update(ud, "PictureLeftCrop", ghb_int64_value(tinfo->crop[2]));
4216 ghb_ui_update(ud, "PictureRightCrop", ghb_int64_value(tinfo->crop[3]));
4221 ghb_refresh_preset(signal_user_data_t *ud)
4223 ghb_title_info_t tinfo;
4227 g_debug("ghb_refresh_preset ()");
4228 preset = ghb_settings_get_value(ud->settings, "preset_selection");
4229 indices = ghb_preset_indices_from_path(presetsPlist, preset, &len);
4234 folder = ghb_presets_get_folder(presetsPlist, indices, len);
4237 ud->dont_clear_presets = TRUE;
4238 ud->scale_busy = TRUE;
4239 // Temporarily set the video_quality range to (0,100)
4240 // This is needed so the video_quality value does not get
4241 // truncated when set. The range will be readjusted below
4242 GtkWidget *qp = GHB_WIDGET(ud->builder, "VideoQualitySlider");
4243 gtk_range_set_range (GTK_RANGE(qp), 0, 100);
4244 gtk_scale_set_digits(GTK_SCALE(qp), 3);
4245 // Clear the audio list prior to changing the preset. Existing
4246 // audio can cause the container extension to be automatically
4247 // changed when it shouldn't be
4248 ghb_clear_audio_list(ud);
4249 ghb_set_preset_from_indices(ud, indices, len);
4251 titleindex = ghb_settings_combo_int(ud->settings, "title");
4252 ghb_set_pref_audio(titleindex, ud);
4253 ghb_set_pref_subtitle(titleindex, ud);
4254 ghb_settings_set_boolean(ud->settings, "preset_modified", FALSE);
4255 if (ghb_get_title_info (&tinfo, titleindex))
4257 preset_update_title_deps(ud, &tinfo);
4259 ud->scale_busy = FALSE;
4260 ghb_set_scale (ud, GHB_PIC_KEEP_PAR|GHB_PIC_USE_MAX);
4261 ud->dont_clear_presets = FALSE;
4263 gdouble vqmin, vqmax, step, page;
4267 ghb_vquality_range(ud, &vqmin, &vqmax, &step,
4268 &page, &digits, &inverted);
4269 gtk_range_set_range (GTK_RANGE(qp), vqmin, vqmax);
4270 gtk_range_set_increments (GTK_RANGE(qp), step, page);
4271 gtk_scale_set_digits(GTK_SCALE(qp), digits);
4272 gtk_range_set_inverted (GTK_RANGE(qp), inverted);
4276 GtkWidget *crop_widget;
4277 crop[0] = ghb_settings_get_int(ud->settings, "PictureTopCrop");
4278 crop[1] = ghb_settings_get_int(ud->settings, "PictureBottomCrop");
4279 crop[2] = ghb_settings_get_int(ud->settings, "PictureLeftCrop");
4280 crop[3] = ghb_settings_get_int(ud->settings, "PictureRightCrop");
4281 crop_widget = GHB_WIDGET (ud->builder, "crop_values");
4282 text = g_strdup_printf("%d:%d:%d:%d",
4283 crop[0], crop[1], crop[2], crop[3]);
4284 gtk_label_set_text (GTK_LABEL(crop_widget), text);
4290 G_MODULE_EXPORT void
4291 presets_list_selection_changed_cb(GtkTreeSelection *selection, signal_user_data_t *ud)
4293 GtkTreeModel *store;
4295 ghb_title_info_t tinfo;
4298 g_debug("presets_list_selection_changed_cb ()");
4299 widget = GHB_WIDGET (ud->builder, "presets_remove");
4300 if (gtk_tree_selection_get_selected(selection, &store, &iter))
4302 GtkTreePath *treepath;
4307 treepath = gtk_tree_model_get_path(store, &iter);
4308 indices = gtk_tree_path_get_indices(treepath);
4309 len = gtk_tree_path_get_depth(treepath);
4311 path = preset_path_from_indices(presetsPlist, indices, len);
4312 ghb_settings_take_value(ud->settings, "preset_selection", path);
4314 folder = ghb_presets_get_folder(presetsPlist, indices, len);
4317 ud->dont_clear_presets = TRUE;
4318 ud->scale_busy = TRUE;
4319 // Temporarily set the video_quality range to (0,100)
4320 // This is needed so the video_quality value does not get
4321 // truncated when set. The range will be readjusted below
4322 GtkWidget *qp = GHB_WIDGET(ud->builder, "VideoQualitySlider");
4323 gtk_range_set_range (GTK_RANGE(qp), 0, 100);
4324 gtk_scale_set_digits(GTK_SCALE(qp), 3);
4325 // Clear the audio list prior to changing the preset. Existing
4326 // audio can cause the container extension to be automatically
4327 // changed when it shouldn't be
4328 ghb_clear_audio_list(ud);
4329 ghb_set_preset_from_indices(ud, indices, len);
4331 titleindex = ghb_settings_combo_int(ud->settings, "title");
4332 ghb_set_pref_audio(titleindex, ud);
4333 ghb_set_pref_subtitle(titleindex, ud);
4334 ghb_settings_set_boolean(ud->settings, "preset_modified", FALSE);
4335 if (ghb_get_title_info (&tinfo, titleindex))
4337 preset_update_title_deps(ud, &tinfo);
4339 ud->scale_busy = FALSE;
4340 ghb_set_scale (ud, GHB_PIC_KEEP_PAR|GHB_PIC_USE_MAX);
4341 ud->dont_clear_presets = FALSE;
4343 gdouble vqmin, vqmax, step, page;
4347 ghb_vquality_range(ud, &vqmin, &vqmax, &step,
4348 &page, &digits, &inverted);
4349 gtk_range_set_range (GTK_RANGE(qp), vqmin, vqmax);
4350 gtk_range_set_increments (GTK_RANGE(qp), step, page);
4351 gtk_scale_set_digits(GTK_SCALE(qp), digits);
4352 gtk_range_set_inverted (GTK_RANGE(qp), inverted);
4356 GtkWidget *crop_widget;
4357 crop[0] = ghb_settings_get_int(ud->settings, "PictureTopCrop");
4358 crop[1] = ghb_settings_get_int(ud->settings, "PictureBottomCrop");
4359 crop[2] = ghb_settings_get_int(ud->settings, "PictureLeftCrop");
4360 crop[3] = ghb_settings_get_int(ud->settings, "PictureRightCrop");
4361 crop_widget = GHB_WIDGET (ud->builder, "crop_values");
4362 text = g_strdup_printf("%d:%d:%d:%d",
4363 crop[0], crop[1], crop[2], crop[3]);
4364 gtk_label_set_text (GTK_LABEL(crop_widget), text);
4367 gtk_tree_path_free(treepath);
4368 gtk_widget_set_sensitive(widget, TRUE);
4372 g_debug("No selection??? Perhaps unselected.");
4373 gtk_widget_set_sensitive(widget, FALSE);
4375 if (ghb_settings_combo_int(ud->settings, "PtoPType") == 0)
4378 start = ghb_settings_get_int(ud->settings, "start_point");
4379 end = ghb_settings_get_int(ud->settings, "end_point");
4380 widget = GHB_WIDGET (ud->builder, "ChapterMarkers");
4381 gtk_widget_set_sensitive(widget, TRUE);
4384 ud->dont_clear_presets = TRUE;
4385 ghb_ui_update(ud, "ChapterMarkers", ghb_boolean_value(FALSE));
4386 ud->dont_clear_presets = FALSE;
4387 gtk_widget_set_sensitive(widget, FALSE);
4393 ghb_clear_presets_selection(signal_user_data_t *ud)
4395 GtkTreeView *treeview;
4396 GtkTreeSelection *selection;
4398 if (ud->dont_clear_presets) return;
4399 g_debug("ghb_clear_presets_selection()");
4400 treeview = GTK_TREE_VIEW(GHB_WIDGET(ud->builder, "presets_list"));
4401 selection = gtk_tree_view_get_selection (treeview);
4402 gtk_tree_selection_unselect_all (selection);
4403 ghb_settings_set_boolean(ud->settings, "preset_modified", TRUE);
4406 G_MODULE_EXPORT void
4407 presets_frame_size_allocate_cb(GtkWidget *widget, GtkAllocation *allocation, signal_user_data_t *ud)
4409 GtkTreeView *treeview;
4410 GtkTreeSelection *selection;
4411 GtkTreeModel *store;
4414 treeview = GTK_TREE_VIEW(GHB_WIDGET(ud->builder, "presets_list"));
4415 selection = gtk_tree_view_get_selection(treeview);
4416 if (gtk_tree_selection_get_selected(selection, &store, &iter))
4419 path = gtk_tree_model_get_path (store, &iter);
4420 // Make the parent visible in scroll window if it is not.
4421 gtk_tree_view_scroll_to_cell (treeview, path, NULL, FALSE, 0, 0);
4422 gtk_tree_path_free(path);
4426 G_MODULE_EXPORT void
4427 presets_default_clicked_cb(GtkWidget *xwidget, signal_user_data_t *ud)
4432 g_debug("presets_default_clicked_cb ()");
4433 preset = ghb_settings_get_value(ud->settings, "preset_selection");
4434 indices = ghb_preset_indices_from_path(presetsPlist, preset, &len);
4437 if (!ghb_presets_get_folder(presetsPlist, indices, len))
4439 ghb_presets_list_clear_default(ud);
4440 presets_set_default(indices, len);
4441 ghb_presets_list_default(ud);
4447 G_MODULE_EXPORT void
4449 GtkCellRendererText *cell,
4452 signal_user_data_t *ud)
4454 GtkTreePath *treepath;
4455 GtkTreeStore *store;
4456 GtkTreeView *treeview;
4458 gint *indices, len, count;
4460 GValue *preset, *dest;
4462 g_debug("preset_edited_cb ()");
4463 g_debug("path (%s)", path);
4464 g_debug("text (%s)", text);
4466 preset = ghb_settings_get_value (ud->settings, "preset_selection");
4467 dest = ghb_array_value_new(MAX_NESTED_PRESET);
4468 count = ghb_array_len(preset);
4469 ghb_array_copy(dest, preset, count-1);
4470 ghb_array_append(dest, ghb_string_value_new(text));
4471 indices = ghb_preset_indices_from_path(presetsPlist, dest, &len);
4472 ghb_value_free(dest);
4473 if (indices != NULL)
4480 treeview = GTK_TREE_VIEW(GHB_WIDGET(ud->builder, "presets_list"));
4481 store = GTK_TREE_STORE(gtk_tree_view_get_model(treeview));
4482 treepath = gtk_tree_path_new_from_string (path);
4483 indices = gtk_tree_path_get_indices(treepath);
4484 len = gtk_tree_path_get_depth(treepath);
4485 gtk_tree_model_get_iter(GTK_TREE_MODEL(store), &iter, treepath);
4486 gtk_tree_store_set(store, &iter, 0, text, -1);
4488 dict = presets_get_dict(presetsPlist, indices, len);
4489 ghb_dict_insert(dict, g_strdup("PresetName"), ghb_string_value_new(text));
4491 gtk_tree_path_free (treepath);