diff options
author | jstebbins <[email protected]> | 2015-05-14 17:11:48 +0000 |
---|---|---|
committer | jstebbins <[email protected]> | 2015-05-14 17:11:48 +0000 |
commit | 9ae7e30dc8daace92d17ea36a4f0bdede00b9471 (patch) | |
tree | 9485255c993389a6740b833e7aa30c5b5b2622aa /gtk | |
parent | 90cafad3e4c610b8b009769f922fabc283979231 (diff) |
lingui: use libhb preset management from linux gui
git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@7179 b64f7644-9d1e-0410-96f1-a4d463321fa5
Diffstat (limited to 'gtk')
-rw-r--r-- | gtk/src/Makefile.am | 8 | ||||
-rw-r--r-- | gtk/src/callbacks.c | 54 | ||||
-rw-r--r-- | gtk/src/callbacks.h | 1 | ||||
-rw-r--r-- | gtk/src/data_res.gresource.xml | 1 | ||||
-rw-r--r-- | gtk/src/ghb-3.12.ui | 4 | ||||
-rw-r--r-- | gtk/src/ghb-3.14.ui | 4 | ||||
-rw-r--r-- | gtk/src/ghb.ui | 4 | ||||
-rw-r--r-- | gtk/src/internal_defaults.json | 117 | ||||
-rw-r--r-- | gtk/src/main.c | 19 | ||||
-rw-r--r-- | gtk/src/presets.c | 4045 | ||||
-rw-r--r-- | gtk/src/presets.h | 19 | ||||
-rw-r--r-- | gtk/src/queuehandler.c | 11 | ||||
-rw-r--r-- | gtk/src/resources.c | 7 | ||||
-rw-r--r-- | gtk/src/standard_presets.json | 867 | ||||
-rw-r--r-- | gtk/src/values.c | 29 | ||||
-rw-r--r-- | gtk/src/values.h | 2 |
16 files changed, 1216 insertions, 3976 deletions
diff --git a/gtk/src/Makefile.am b/gtk/src/Makefile.am index dc9f48941..e72ba59af 100644 --- a/gtk/src/Makefile.am +++ b/gtk/src/Makefile.am @@ -100,12 +100,12 @@ icon_res.h : icon_res.gresource.xml $(icons_dep) icon_res.o: icon_res.c icon_res.h -data_res.c : data_res.gresource.xml $(srcdir)/internal_defaults.json $(srcdir)/standard_presets.json widget.deps widget_reverse.deps - cp $(srcdir)/internal_defaults.json $(srcdir)/standard_presets.json . +data_res.c : data_res.gresource.xml $(srcdir)/internal_defaults.json widget.deps widget_reverse.deps + cp $(srcdir)/internal_defaults.json . glib-compile-resources --generate --target=$@ --c-name ghb_data --manual-register $< -data_res.h : data_res.gresource.xml $(srcdir)/internal_defaults.json $(srcdir)/standard_presets.json widget.deps widget_reverse.deps - cp $(srcdir)/internal_defaults.json $(srcdir)/standard_presets.json . +data_res.h : data_res.gresource.xml $(srcdir)/internal_defaults.json widget.deps widget_reverse.deps + cp $(srcdir)/internal_defaults.json . glib-compile-resources --generate --target=$@ --c-name ghb_data --manual-register $< if GHB_GTK_3_14 diff --git a/gtk/src/callbacks.c b/gtk/src/callbacks.c index 5fc3d7589..5b5db99af 100644 --- a/gtk/src/callbacks.c +++ b/gtk/src/callbacks.c @@ -818,14 +818,14 @@ update_source_label(signal_user_data_t *ud, const gchar *source) if (label != NULL) { gtk_label_set_text (GTK_LABEL(widget), label); - ghb_dict_set_string(ud->settings, "volume_label", label); + ghb_dict_set_string(ud->globals, "volume_label", label); g_free(label); } else { label = _("No Title Found"); gtk_label_set_text (GTK_LABEL(widget), label); - ghb_dict_set_string(ud->settings, "volume_label", label); + ghb_dict_set_string(ud->globals, "volume_label", label); return FALSE; } return TRUE; @@ -1158,7 +1158,7 @@ show_settings(GhbValue *settings) void ghb_load_settings(signal_user_data_t * ud) { - GhbValue *preset; + const char *fullname; gboolean preset_modified; static gboolean busy = FALSE; @@ -1166,7 +1166,7 @@ ghb_load_settings(signal_user_data_t * ud) return; busy = TRUE; - preset = ghb_dict_get_value(ud->settings, "preset"); + fullname = ghb_dict_get_string(ud->settings, "PresetFullName"); preset_modified = ghb_dict_get_bool(ud->settings, "preset_modified"); if (preset_modified) { @@ -1175,10 +1175,23 @@ ghb_load_settings(signal_user_data_t * ud) else { ghb_dict_set_bool(ud->settings, "preset_reload", TRUE); - ghb_select_preset(ud->builder, preset); + ghb_select_preset(ud->builder, fullname); ghb_dict_set_bool(ud->settings, "preset_reload", FALSE); } + busy = FALSE; + + ghb_load_post_settings(ud); +} + +void +ghb_load_post_settings(signal_user_data_t * ud) +{ + static gboolean busy = FALSE; + if (busy) + return; + busy = TRUE; + ud->dont_clear_presets = TRUE; ud->scale_busy = TRUE; @@ -1831,7 +1844,7 @@ set_title_settings(signal_user_data_t *ud, GhbValue *settings) else { ghb_dict_set(settings, "volume_label", ghb_value_dup( - ghb_dict_get_value(ud->settings, "volume_label"))); + ghb_dict_get_value(ud->globals, "volume_label"))); } ghb_dict_set_int(settings, "scale_width", title->geometry.width - title->crop[2] - title->crop[3]); @@ -1909,7 +1922,7 @@ static void load_all_titles(signal_user_data_t *ud, int titleindex) { gint ii, count; - GhbValue *preset, *preset_path = NULL; + GhbValue *preset; GhbValue *settings_array; const hb_title_t *title; @@ -1924,28 +1937,21 @@ load_all_titles(signal_user_data_t *ud, int titleindex) preset = ghb_get_current_preset(ud); if (preset != NULL) { - preset_path = ghb_get_current_preset_path(ud); - } - else - { - preset = ud->settings; + ghb_preset_to_settings(ud->settings, preset); + ghb_value_free(&preset); } for (ii = 0; ii < count; ii++) { int index; - GhbValue *settings = ghb_dict_new(); + GhbValue *settings = ghb_value_dup(ud->settings); title = hb_list_item(list, ii); index = (title != NULL) ? title->index : -1; - ghb_settings_init(settings, "Initialization"); - ghb_preset_to_settings(settings, preset); - ghb_dict_set(settings, "preset", ghb_value_dup(preset_path)); ghb_dict_set_int(settings, "title", index); set_title_settings(ud, settings); ghb_array_append(settings_array, settings); } - ghb_value_free(&preset_path); if (titleindex < 0 || titleindex >= count) { titleindex = 0; @@ -2755,20 +2761,18 @@ static void submit_job(signal_user_data_t *ud, GhbValue *settings) { static gint unique_id = 1; - gchar *type, *modified, *preset; - const GhbValue *path; + gchar *type, *modified; + const char *name; GhbValue *js; gboolean preset_modified; g_debug("submit_job"); if (settings == NULL) return; preset_modified = ghb_dict_get_bool(settings, "preset_modified"); - path = ghb_dict_get_value(settings, "preset"); - preset = ghb_preset_path_string(path); - type = ghb_preset_is_custom() ? "Custom " : ""; + name = ghb_dict_get_string(settings, "PresetFullName"); + type = ghb_dict_get_int(settings, "Type") == 1 ? "Custom " : ""; modified = preset_modified ? "Modified " : ""; - ghb_log("%s%sPreset: %s", modified, type, preset); - g_free(preset); + ghb_log("%s%sPreset: %s", modified, type, name); ghb_dict_set_int(settings, "job_unique_id", unique_id); ghb_dict_set_int(settings, "job_status", GHB_QUEUE_RUNNING); @@ -3155,7 +3159,7 @@ ghb_backend_events(signal_user_data_t *ud) if (title == NULL) { gtk_label_set_text(label, _("No Title Found")); - ghb_ui_update(ud, "title", ghb_int_value(-1)); + ghb_ui_update(ud, "title", ghb_string_value("none")); } else { diff --git a/gtk/src/callbacks.h b/gtk/src/callbacks.h index 73003211e..02c8e0805 100644 --- a/gtk/src/callbacks.h +++ b/gtk/src/callbacks.h @@ -82,6 +82,7 @@ void ghb_add_all_titles(signal_user_data_t *ud); void ghb_update_title_info(signal_user_data_t *ud); void ghb_chapter_list_refresh_all(signal_user_data_t *ud); void ghb_load_settings(signal_user_data_t * ud); +void ghb_load_post_settings(signal_user_data_t * ud); void ghb_set_current_title_settings(signal_user_data_t *ud); void ghb_container_empty(GtkContainer *c); void ghb_show_container_options(signal_user_data_t *ud); diff --git a/gtk/src/data_res.gresource.xml b/gtk/src/data_res.gresource.xml index 5570e4bea..d0f75543b 100644 --- a/gtk/src/data_res.gresource.xml +++ b/gtk/src/data_res.gresource.xml @@ -2,7 +2,6 @@ <gresources> <gresource prefix="/org/handbrake/data"> <file>internal_defaults.json</file> - <file>standard_presets.json</file> <file>widget.deps</file> <file>widget_reverse.deps</file> </gresource> diff --git a/gtk/src/ghb-3.12.ui b/gtk/src/ghb-3.12.ui index 47cf3776f..74b9ba0af 100644 --- a/gtk/src/ghb-3.12.ui +++ b/gtk/src/ghb-3.12.ui @@ -841,7 +841,7 @@ libx264 authors: </child> <child> <object class="GtkMenuItem" id="presets_restore"> - <property name="label" translatable="yes">_Update Built-in Presets</property> + <property name="label" translatable="yes">_Reload Built-in Presets</property> <property name="visible">True</property> <property name="can_focus">False</property> <property name="use_underline">True</property> @@ -7568,7 +7568,7 @@ on the Video tab instead.</property> Check this if you want the queue to clean itself up by deleting completed jobs.</property> <property name="halign">start</property> <property name="draw_indicator">True</property> - <signal name="toggled" handler="advanced_video_changed_cb" swapped="no"/> + <signal name="toggled" handler="pref_changed_cb" swapped="no"/> </object> <packing> <property name="top_attach">6</property> diff --git a/gtk/src/ghb-3.14.ui b/gtk/src/ghb-3.14.ui index edd4dcdfb..101f17558 100644 --- a/gtk/src/ghb-3.14.ui +++ b/gtk/src/ghb-3.14.ui @@ -842,7 +842,7 @@ libx264 authors: </child> <child> <object class="GtkMenuItem" id="presets_restore"> - <property name="label" translatable="yes">_Update Built-in Presets</property> + <property name="label" translatable="yes">_Reload Built-in Presets</property> <property name="visible">True</property> <property name="can_focus">False</property> <property name="use_underline">True</property> @@ -7574,7 +7574,7 @@ on the Video tab instead.</property> Check this if you want the queue to clean itself up by deleting completed jobs.</property> <property name="halign">start</property> <property name="draw_indicator">True</property> - <signal name="toggled" handler="advanced_video_changed_cb" swapped="no"/> + <signal name="toggled" handler="pref_changed_cb" swapped="no"/> </object> <packing> <property name="top_attach">6</property> diff --git a/gtk/src/ghb.ui b/gtk/src/ghb.ui index bf82ac57f..4ec2c5ef7 100644 --- a/gtk/src/ghb.ui +++ b/gtk/src/ghb.ui @@ -841,7 +841,7 @@ libx264 authors: </child> <child> <object class="GtkMenuItem" id="presets_restore"> - <property name="label" translatable="yes">_Update Built-in Presets</property> + <property name="label" translatable="yes">_Reload Built-in Presets</property> <property name="visible">True</property> <property name="can_focus">False</property> <property name="use_underline">True</property> @@ -7568,7 +7568,7 @@ on the Video tab instead.</property> Check this if you want the queue to clean itself up by deleting completed jobs.</property> <property name="halign">start</property> <property name="draw_indicator">True</property> - <signal name="toggled" handler="advanced_video_changed_cb" swapped="no"/> + <signal name="toggled" handler="pref_changed_cb" swapped="no"/> </object> <packing> <property name="top_attach">6</property> diff --git a/gtk/src/internal_defaults.json b/gtk/src/internal_defaults.json index 0d4fd7657..d4a24ab15 100644 --- a/gtk/src/internal_defaults.json +++ b/gtk/src/internal_defaults.json @@ -1,9 +1,21 @@ { "Globals": { "show_preview": false, - "scan_source": "" + "scan_source": "", + "volume_label": "New Video" + }, + "OneTimeInitialization": { + "title": "none" }, "Initialization": { + "AudioAllowMP3Pass": false, + "AudioAllowAACPass": false, + "AudioAllowAC3Pass": false, + "AudioAllowDTSPass": false, + "AudioAllowDTSHDPass": false, + "AudioAllowEAC3Pass": false, + "AudioAllowFLACPass": false, + "AudioAllowTRUEHDPass": false, "AudioBitrate": "192", "AudioEncoder": "copy:ac3", "AudioTrack": 0, @@ -28,16 +40,9 @@ "MetaGenre": "", "MetaDescription": "", "MetaLongDescription": "", - "preset": [ - "Regular", - "Normal" - ], + "PresetFullName": "/Regular/Normal", "preset_modified": false, "preset_reload": false, - "preset_selection": [ - "Regular", - "Normal" - ], "PictureDisplayWidth": 720, "PictureDisplayHeight": 480, "PtoPType": "chapter", @@ -46,7 +51,6 @@ "single_title": 1, "start_point": 1.0, "start_frame": -1, - "title": 0, "title_selected": false, "volume_label": "New Video", "audio_list": [], @@ -103,98 +107,5 @@ "SrtDir": "", "window_width": 1, "window_height": 1 - }, - "Presets": { - "PictureAutoCrop": true, - "ChapterMarkers": true, - "FileFormat": "mp4", - "Folder": false, - "PictureLooseCrop": false, - "PictureModulus": 2, - "PictureDeblock": 0, - "PictureDecombDeinterlace": true, - "PictureDecomb": "off", - "PictureDecombCustom": "", - "Default": false, - "PictureBottomCrop": 0, - "PictureLeftCrop": 0, - "PictureRightCrop": 0, - "PictureTopCrop": 0, - "PictureDeinterlace": "off", - "PictureDeinterlaceCustom": "", - "PictureDenoiseFilter": "off", - "PictureDenoisePreset": "medium", - "PictureDenoiseTune": "none", - "PictureDenoiseCustom": "", - "PictureDetelecine": "off", - "PictureDetelecineCustom": "", - "PicturePAR": "loose", - "PicturePARWidth": 853, - "PicturePARHeight": 720, - "PictureHeight": 0, - "PictureWidth": 0, - "VideoFramerate": "auto", - "VideoFramerateMode": "vfr", - "VideoGrayScale": false, - "Mp4HttpOptimize": false, - "Mp4iPodCompatible": false, - "PictureKeepRatio": true, - "AudioAllowMP3Pass": false, - "AudioAllowAACPass": false, - "AudioAllowAC3Pass": true, - "AudioAllowDTSPass": false, - "AudioAllowDTSHDPass": false, - "AudioAllowEAC3Pass": false, - "AudioAllowFLACPass": false, - "AudioAllowTRUEHDPass": false, - "AudioCopyMask": [ - "copy:ac3" - ], - "AudioEncoderFallback": "ac3", - "AudioLanguageList": [ - "und" - ], - "AudioList": [ - { - "AudioBitrate": "192", - "AudioEncoder": "copy:ac3", - "AudioTrackQualityEnable": false, - "AudioTrackQuality": -1.0, - "AudioTrackGainSlider": 0.0, - "AudioTrackDRCSlider": 0.0, - "AudioMixdown": "dpl2", - "AudioSamplerate": "auto" - } - ], - "AudioSecondaryEncoderMode": true, - "AudioTrackSelectionBehavior": "first", - "PresetDescription": "", - "PresetName": "Name Missing", - "Type": 1, - "SubtitleLanguageList": [ - "und" - ], - "SubtitleTrackSelectionBehavior": "none", - "SubtitleAddCC": false, - "SubtitleAddForeignAudioSearch": false, - "SubtitleAddForeignAudioSubtitle": false, - "SubtitleBurnBehavior": "none", - "SubtitleBurnDVDSub": false, - "SubtitleBurnBDSub": false, - "VideoTurboTwoPass": false, - "UsesPictureFilters": true, - "UsesPictureSettings": 2, - "VideoTwoPass": false, - "VideoAvgBitrate": 1800, - "VideoEncoder": "x264", - "VideoQualityType": 2, - "VideoQualitySlider": 0.59999999999999998, - "x264Option": "", - "VideoPreset": "medium", - "VideoTune": "", - "VideoProfile": "", - "VideoLevel": "", - "x264UseAdvancedOptions": false, - "VideoOptionExtra": "" } } diff --git a/gtk/src/main.c b/gtk/src/main.c index 5b60252fe..de5b3813f 100644 --- a/gtk/src/main.c +++ b/gtk/src/main.c @@ -798,7 +798,6 @@ int main(int argc, char *argv[]) { signal_user_data_t *ud; - GhbValue *preset; GError *error = NULL; GOptionContext *context; @@ -1011,13 +1010,15 @@ main(int argc, char *argv[]) ghb_settings_init(ud->prefs, "Preferences"); ghb_settings_init(ud->globals, "Globals"); ghb_settings_init(ud->settings, "Initialization"); + ghb_settings_init(ud->settings, "OneTimeInitialization"); // Load user preferences file ghb_prefs_load(ud); // Store user preferences into ud->prefs ghb_prefs_to_settings(ud->prefs); - // Load all settings with default preset values - ghb_settings_init(ud->settings, "Presets"); + int logLevel = ghb_dict_get_int(ud->prefs, "LoggingLevel"); + ghb_backend_init(logLevel); + // Load the presets files ghb_presets_load(ud); // Note that ghb_preset_to_settings(ud->settings) is called when @@ -1028,9 +1029,6 @@ main(int argc, char *argv[]) // Note that ghb_settings_to_ui(ud->settings) happens when initial // empty title is initialized. - gint logLevel; - logLevel = ghb_dict_get_int(ud->prefs, "LoggingLevel"); - ghb_backend_init(logLevel); if (ghb_dict_get_bool(ud->prefs, "hbfd")) { @@ -1040,16 +1038,11 @@ main(int argc, char *argv[]) ghb_dvd_set_current(source, ud); // Populate the presets tree view - ghb_presets_list_init(ud, NULL, 0); + ghb_presets_list_init(ud, NULL); // Get the first preset name if (arg_preset != NULL) { - preset = ghb_parse_preset_path(arg_preset); - if (preset) - { - ghb_select_preset(ud->builder, preset); - ghb_value_free(&preset); - } + ghb_select_preset(ud->builder, arg_preset); } else { diff --git a/gtk/src/presets.c b/gtk/src/presets.c index 5c2825c7e..7f9c5f8c9 100644 --- a/gtk/src/presets.c +++ b/gtk/src/presets.c @@ -27,7 +27,6 @@ #include "audiohandler.h" #include "subtitlehandler.h" #include "hb-backend.h" -#include "plist.h" #include "resources.h" #include "presets.h" #include "values.h" @@ -38,484 +37,126 @@ enum { + PRESETS_INVALID = -1, PRESETS_BUILTIN = 0, PRESETS_CUSTOM }; -static GhbValue *presetsPlistFile = NULL; -static GhbValue *presetsPlist = NULL; -static GhbValue *prefsPlist = NULL; +static GhbValue *prefsDict = NULL; static gboolean prefs_modified = FALSE; -static void store_presets(void); static void store_prefs(void); +static void store_presets(void); -static void -dict_clean(GhbValue *dict, GhbValue *template) +hb_preset_index_t* +ghb_tree_get_index(GtkTreeModel *store, GtkTreeIter *iter) { - GhbValue *tmp = ghb_value_dup(dict); - GhbDictIter iter; - const gchar *key; - GhbValue *val; - GhbValue *template_val; + GtkTreePath *treepath; + int *indices, len; + hb_preset_index_t *path; - iter = ghb_dict_iter_init(tmp); - while (ghb_dict_iter_next(tmp, &iter, &key, &val)) - { - template_val = ghb_dict_get(template, key); - if (template_val == NULL) - { - ghb_dict_remove(dict, key); - } - if (ghb_value_type(val) == GHB_DICT && - ghb_value_type(template_val) == GHB_DICT) - { - val = ghb_dict_get(dict, key); - dict_clean(val, template_val); - } - if (ghb_value_type(val) == GHB_ARRAY && - ghb_value_type(template_val) == GHB_ARRAY && - ghb_array_len(template_val) > 0) - { - template_val = ghb_array_get(template_val, 0); - if (ghb_value_type(template_val) == GHB_DICT) - { - val = ghb_dict_get(dict, key); - int count = ghb_array_len(val); - int ii; - for (ii = 0; ii < count; ii++) - { - GhbValue *array_val; - array_val = ghb_array_get(val, ii); - if (ghb_value_type(array_val) == GHB_DICT) - { - dict_clean(array_val, template_val); - } - } - } - } - } - ghb_value_free(&tmp); + treepath = gtk_tree_model_get_path(store, iter); + indices = gtk_tree_path_get_indices(treepath); + len = gtk_tree_path_get_depth(treepath); + path = hb_preset_index_init(indices, len); + gtk_tree_path_free(treepath); + + return path; } -gint -preset_path_cmp(gint *indices1, gint len1, gint *indices2, gint len2) +hb_preset_index_t* +ghb_tree_path_get_index(GtkTreePath *treepath) { - gint ii; - for (ii = 0; ii < len1 && ii < len2; ii++) - { - if (indices1[ii] != indices2[ii]) - return indices1[ii] - indices2[ii]; - } - return len1 - len2; + int *indices, len; + + indices = gtk_tree_path_get_indices(treepath); + len = gtk_tree_path_get_depth(treepath); + + return hb_preset_index_init(indices, len); } // This only handle limited depth GtkTreePath* -ghb_tree_path_new_from_indices(gint *indices, gint len) +ghb_tree_path_new_from_index(const hb_preset_index_t *path) { - switch (len) + if (path == NULL || path->depth == 0) + return NULL; + +#if GTK_CHECK_VERSION(3, 12, 0) + return gtk_tree_path_new_from_indicesv((int*)path->index, path->depth); +#else + switch (path->depth) { case 1: return gtk_tree_path_new_from_indices( - indices[0], -1); + path->index[0], -1); case 2: return gtk_tree_path_new_from_indices( - indices[0], indices[1], -1); + path->index[0], path->index[1], -1); case 3: return gtk_tree_path_new_from_indices( - indices[0], indices[1], indices[2], -1); + path->index[0], path->index[1], path->index[2], -1); case 4: return gtk_tree_path_new_from_indices( - indices[0], indices[1], indices[2], indices[3], -1); + path->index[0], path->index[1], path->index[2], + path->index[3], -1); case 5: return gtk_tree_path_new_from_indices( - indices[0], indices[1], indices[2], indices[3], indices[4], -1); + path->index[0], path->index[1], path->index[2], + path->index[3], path->index[4], -1); + case 6: + return gtk_tree_path_new_from_indices( + path->index[0], path->index[1], path->index[2], + path->index[3], path->index[4], path->index[5], -1); + case 7: + return gtk_tree_path_new_from_indices( + path->index[0], path->index[1], path->index[2], + path->index[3], path->index[4], path->index[5], + path->index[6], -1); + case 8: + return gtk_tree_path_new_from_indices( + path->index[0], path->index[1], path->index[2], + path->index[3], path->index[4], path->index[5], + path->index[6], path->index[7], -1); default: + g_warning("Preset path depth too deep"); return NULL; } +#endif } -GhbValue* -ghb_parse_preset_path(const gchar *path) -{ - gchar **split; - GhbValue *preset; - gint ii; - - preset = ghb_array_new(); - split = g_strsplit(path, "#", MAX_NESTED_PRESET); - for (ii = 0; split[ii] != NULL; ii++) - { - ghb_array_append(preset, ghb_string_value_new(split[ii])); - } - g_strfreev(split); - return preset; -} - -static GhbValue* -preset_path_from_indices(GhbValue *presets, gint *indices, gint len) -{ - gint ii; - GhbValue *path; - - g_debug("preset_path_from_indices"); - path = ghb_array_new(); - for (ii = 0; ii < len; ii++) - { - GhbValue *dict; - gint count, folder; - const GhbValue *name; - - count = ghb_array_len(presets); - if (indices[ii] >= count) break; - dict = ghb_array_get(presets, indices[ii]); - name = ghb_dict_get(dict, "PresetName"); - if (name) - ghb_array_append(path, ghb_value_dup(name)); - folder = ghb_value_get_bool(ghb_dict_get(dict, "Folder")); - if (!folder) - break; - presets = ghb_dict_get(dict, "ChildrenArray"); - } - return path; -} - -gchar* -ghb_preset_path_string(const GhbValue *path) -{ - gint count, ii; - GString *gstr; - GhbValue *val; - gchar *str; - - gstr = g_string_new(""); - if (path != NULL) - { - count = ghb_array_len(path); - for (ii = 0; ii < count; ii++) - { - val = ghb_array_get(path, ii); - const char *tmp = ghb_value_get_string(val); - g_string_append(gstr, tmp); - if (ii < count-1) - g_string_append(gstr, "->"); - } - } - str = g_string_free(gstr, FALSE); - return str; -} - -void -dump_preset_path(const gchar *msg, const GhbValue *path) -{ - gchar *str; - - if (path) - debug_show_type (ghb_value_type(path)); - str = ghb_preset_path_string(path); - g_message("%s path: (%s)", msg, str); - g_free(str); -} - +#if 0 void -dump_preset_indices(const gchar *msg, gint *indices, gint len) +dump_preset_indices(const gchar *msg, hb_preset_index_t *path) { gint ii; - g_message("%s indices: len %d", msg, len); - for (ii = 0; ii < len; ii++) + g_message("%s indices: len %d", msg, path->depth); + for (ii = 0; ii < path->depth; ii++) { - printf("%d ", indices[ii]); + printf("%d ", path->index[ii]); } printf("\n"); } - -#if 0 -static gint -preset_path_cmp(const GhbValue *path1, const GhbValue *path2) -{ - gint count, ii; - GhbValue *val; - const gchar *str1, *str2; - gint result; - - count = ghb_array_len(path1); - ii = ghb_array_len(path2); - if (ii != count) - return ii - count; - for (ii = 0; ii < count; ii++) - { - val = ghb_array_get(path1, ii); - str1 = ghb_value_get_string(val); - val = ghb_array_get(path2, ii); - str2 = ghb_value_get_string(val); - result = strcmp(str1, str2); - if (result != 0) - return result; - } - return 0; -} #endif -static GhbValue* -presets_get_dict(GhbValue *presets, gint *indices, gint len) -{ - gint ii, count, folder; - GhbValue *dict = NULL; - - g_debug("presets_get_dict ()"); - for (ii = 0; ii < len; ii++) - { - count = ghb_array_len(presets); - if (indices[ii] >= count) return NULL; - dict = ghb_array_get(presets, indices[ii]); - if (ii < len-1) - { - folder = ghb_value_get_bool(ghb_dict_get(dict, "Folder")); - if (!folder) - return NULL; - presets = ghb_dict_get(dict, "ChildrenArray"); - } - } - if (ii < len) - return NULL; - return dict; -} - -static GhbValue* -presets_get_folder(GhbValue *presets, gint *indices, gint len) -{ - gint ii, count, folder; - GhbValue *dict; - - g_debug("presets_get_folder ()"); - for (ii = 0; ii < len; ii++) - { - count = ghb_array_len(presets); - if (indices[ii] >= count) return NULL; - dict = ghb_array_get(presets, indices[ii]); - folder = ghb_value_get_bool(ghb_dict_get(dict, "Folder")); - if (!folder) - break; - presets = ghb_dict_get(dict, "ChildrenArray"); - } - if (ii < len) - return NULL; - return presets; -} - -static GhbValue* -plist_get_dict(GhbValue *presets, const gchar *name) -{ - if (presets == NULL || name == NULL) return NULL; - return ghb_dict_get(presets, name); -} - -static const gchar* -preset_get_name(GhbValue *dict) -{ - return ghb_value_get_string(ghb_dict_get(dict, "PresetName")); -} - -static gboolean -preset_folder_is_open(GhbValue *dict) -{ - const GhbValue *gval; - - gval = ghb_dict_get(dict, "FolderOpen"); - if (gval != NULL) - return ghb_value_get_bool(gval); - return FALSE; -} - -gboolean -ghb_preset_folder(GhbValue *dict) -{ - return ghb_value_get_int(ghb_dict_get(dict, "Folder")); -} - -gint -ghb_preset_type(GhbValue *dict) -{ - return ghb_value_get_int(ghb_dict_get(dict, "Type")); -} - -static void -presets_remove_nth(GhbValue *presets, gint pos) -{ - gint count; - - if (presets == NULL || pos < 0) return; - count = ghb_array_len(presets); - if (pos >= count) return; - ghb_array_remove(presets, pos); -} - -gboolean -ghb_presets_remove( - GhbValue *presets, - gint *indices, - gint len) -{ - GhbValue *folder = NULL; - - folder = presets_get_folder(presets, indices, len-1); - if (folder) - presets_remove_nth(folder, indices[len-1]); - else - { - g_warning("ghb_presets_remove (): internal preset lookup error"); - return FALSE; - } - return TRUE; -} - -static void -ghb_presets_replace( - GhbValue *presets, - GhbValue *dict, - gint *indices, - gint len) -{ - GhbValue *folder = NULL; - - folder = presets_get_folder(presets, indices, len-1); - if (folder) - ghb_array_replace(folder, indices[len-1], dict); - else - { - g_warning("ghb_presets_replace (): internal preset lookup error"); - } -} - -static void -ghb_presets_insert( - GhbValue *presets, - GhbValue *dict, - gint *indices, - gint len) -{ - GhbValue *folder = NULL; - - folder = presets_get_folder(presets, indices, len-1); - if (folder) - ghb_array_insert(folder, indices[len-1], dict); - else - { - g_warning("ghb_presets_insert (): internal preset lookup error"); - } -} - -static gint -presets_find_element(GhbValue *presets, const gchar *name) -{ - GhbValue *dict; - gint count, ii; - - g_debug("presets_find_element () (%s)", name); - if (presets == NULL || name == NULL) return -1; - count = ghb_array_len(presets); - for (ii = 0; ii < count; ii++) - { - const gchar *str; - dict = ghb_array_get(presets, ii); - str = preset_get_name(dict); - if (strcmp(name, str) == 0) - { - return ii; - } - } - return -1; -} - -static gint -single_find_pos(GhbValue *presets, const gchar *name, gint type) -{ - GhbValue *dict; - gint count, ii, ptype, last; - - if (presets == NULL || name == NULL) return -1; - last = count = ghb_array_len(presets); - for (ii = 0; ii < count; ii++) - { - const gchar *str; - dict = ghb_array_get(presets, ii); - str = preset_get_name(dict); - ptype = ghb_value_get_int(ghb_dict_get(dict, "Type")); - if (strcasecmp(name, str) <= 0 && ptype == type) - { - return ii; - } - if (ptype == type) - last = ii+1; - } - return last; -} - -static gint* -presets_find_pos(const GhbValue *path, gint type, gint *len) -{ - GhbValue *nested; - GhbValue *val; - gint count, ii; - gboolean folder; - gint *indices = NULL; - const gchar *name; - GhbValue *dict; - - g_debug("presets_find_pos () "); - nested = presetsPlist; - count = ghb_array_len(path); - indices = g_malloc(MAX_NESTED_PRESET * sizeof(gint)); - for (ii = 0; ii < count-1; ii++) - { - val = ghb_array_get(path, ii); - name = ghb_value_get_string(val); - indices[ii] = presets_find_element(nested, name); - if (indices[ii] == -1) { - g_free(indices); - return NULL; - } - dict = ghb_array_get(nested, indices[ii]); - folder = ghb_value_get_bool(ghb_dict_get(dict, "Folder")); - nested = NULL; - if (!folder) - break; - nested = ghb_dict_get(dict, "ChildrenArray"); - } - if (nested) - { - const gchar *name; - - name = ghb_value_get_string(ghb_array_get(path, count-1)); - indices[ii] = single_find_pos(nested, name, type); - ii++; - } - *len = ii; - return indices; -} - static gint preset_tree_depth(GhbValue *dict) { - gboolean folder; - - folder = ghb_value_get_bool(ghb_dict_get(dict, "Folder")); - if (folder) + if (ghb_dict_get_bool(dict, "Folder")) { - gint depth = 0; - gint count, ii; + gint depth = 0; + gint count, ii; GhbValue *presets; presets = ghb_dict_get(dict, "ChildrenArray"); - count = ghb_array_len(presets); + count = ghb_array_len(presets); for (ii = 0; ii < count; ii++) { gint tmp; - dict = ghb_array_get(presets, ii); - tmp = preset_tree_depth(dict); + dict = ghb_array_get(presets, ii); + tmp = preset_tree_depth(dict); depth = MAX(depth, tmp); } return depth + 1; @@ -526,415 +167,331 @@ preset_tree_depth(GhbValue *dict) } } -static gboolean -preset_is_default(GhbValue *dict) -{ - const GhbValue *val; - - val = ghb_dict_get(dict, "Default"); - return ghb_value_get_bool(val); -} - -static void -presets_clear_default(GhbValue *presets) +void +ghb_presets_list_show_default(signal_user_data_t *ud) { - gint count, ii; - - count = ghb_array_len(presets); - for (ii = 0; ii < count; ii++) - { - GhbValue *dict; - gboolean folder; - - dict = ghb_array_get(presets, ii); - folder = ghb_value_get_bool(ghb_dict_get(dict, "Folder")); - if (folder) - { - GhbValue *nested; + hb_preset_index_t *path; - nested = ghb_dict_get(dict, "ChildrenArray"); - presets_clear_default(nested); - } - else - { - if (preset_is_default(dict)) - { - ghb_dict_set(dict, "Default", ghb_bool_value_new(FALSE)); - } - } - } -} + path = hb_presets_get_default_index(); + if (path == NULL || path->depth == 0) + return; -static void -presets_customize(GhbValue *presets) -{ - gint count, ii; + GtkTreeView *treeview; + GtkTreeStore *store; + GtkTreePath *treepath; + GtkTreeIter iter; - count = ghb_array_len(presets); - for (ii = 0; ii < count; ii++) + treeview = GTK_TREE_VIEW(GHB_WIDGET(ud->builder, "presets_list")); + store = GTK_TREE_STORE(gtk_tree_view_get_model(treeview)); + treepath = ghb_tree_path_new_from_index(path); + if (treepath) { - GhbValue *dict; - gboolean folder; - gint ptype; - - dict = ghb_array_get(presets, ii); - - ptype = ghb_value_get_int(ghb_dict_get(dict, "Type")); - if (ptype != PRESETS_CUSTOM) - { - ghb_dict_set(dict, "Type", ghb_int_value_new(PRESETS_CUSTOM)); - } - folder = ghb_value_get_bool(ghb_dict_get(dict, "Folder")); - if (folder) + if (gtk_tree_model_get_iter(GTK_TREE_MODEL(store), &iter, treepath)) { - GhbValue *nested; - - nested = ghb_dict_get(dict, "ChildrenArray"); - presets_customize(nested); + gtk_tree_store_set(store, &iter, + 1, 800, + 2, 2 , + -1); } + gtk_tree_path_free(treepath); } + free(path); } -static gint* -presets_find_default2(GhbValue *presets, gint *len) +void +ghb_presets_list_clear_default(signal_user_data_t *ud) { - gint count, ii; - gint *indices; - - count = ghb_array_len(presets); - for (ii = 0; ii < count; ii++) - { - GhbValue *dict; - gboolean folder; - - dict = ghb_array_get(presets, ii); - folder = ghb_value_get_bool(ghb_dict_get(dict, "Folder")); - if (folder) - { - GhbValue *nested; - gint pos = *len; + hb_preset_index_t *path; - nested = ghb_dict_get(dict, "ChildrenArray"); - (*len)++; - indices = presets_find_default2(nested, len); - if (indices) - { - indices[pos] = ii; - return indices; - } - else - *len = pos; - } - else - { - if (preset_is_default(dict)) - { - indices = g_malloc(MAX_NESTED_PRESET * sizeof(gint)); - indices[*len] = ii; - (*len)++; - return indices; - } - } - } - return NULL; -} + path = hb_presets_get_default_index(); + if (path == NULL || path->depth == 0) + return; -static gint* -presets_find_default(GhbValue *presets, gint *len) -{ - *len = 0; - return presets_find_default2(presets, len); -} + GtkTreeView *treeview; + GtkTreeStore *store; + GtkTreePath *treepath; + GtkTreeIter iter; -gint* -ghb_preset_indices_from_path( - GhbValue *presets, - const GhbValue *path, - gint *len) -{ - GhbValue *nested; - GhbValue *val; - gint count, ii; - gint *indices = NULL; - const gchar *name; - GhbValue *dict; - gboolean folder; - - g_debug("ghb_preset_indices_from_path () "); - nested = presets; - count = ghb_array_len(path); - if (count) - indices = g_malloc(MAX_NESTED_PRESET * sizeof(gint)); - *len = 0; - for (ii = 0; ii < count; ii++) + treeview = GTK_TREE_VIEW(GHB_WIDGET(ud->builder, "presets_list")); + store = GTK_TREE_STORE(gtk_tree_view_get_model(treeview)); + treepath = ghb_tree_path_new_from_index(path); + if (treepath) { - val = ghb_array_get(path, ii); - name = ghb_value_get_string(val); - indices[ii] = presets_find_element(nested, name); - if (indices[ii] == -1) - { - g_free(indices); - return NULL; - } - if (ii < count-1) + if (gtk_tree_model_get_iter(GTK_TREE_MODEL(store), &iter, treepath)) { - dict = ghb_array_get(nested, indices[ii]); - folder = ghb_value_get_bool(ghb_dict_get(dict, "Folder")); - if (!folder) - { - g_free(indices); - return NULL; - } - nested = ghb_dict_get(dict, "ChildrenArray"); + gtk_tree_store_set(store, &iter, + 1, 400, + 2, 0 , + -1); } + gtk_tree_path_free(treepath); } - *len = ii; - return indices; + free(path); } static gint -ghb_presets_get_type( - GhbValue *presets, - gint *indices, - gint len) +preset_get_type(hb_preset_index_t *path) { GhbValue *dict; - gint type = 0; - - dict = presets_get_dict(presets, indices, len); + dict = hb_preset_get(path); if (dict) { - type = ghb_preset_type(dict); + return ghb_dict_get_int(dict, "Type"); } else { - g_warning("ghb_presets_get_type (): internal preset lookup error"); + g_warning("ghb_preset_get_type (): internal preset lookup error"); + return 0; } - return type; + return 0; } static gboolean -ghb_presets_get_folder( - GhbValue *presets, - gint *indices, - gint len) +preset_is_folder(hb_preset_index_t *path) { GhbValue *dict; gboolean folder = FALSE; - dict = presets_get_dict(presets, indices, len); + dict = hb_preset_get(path); if (dict) { - folder = ghb_preset_folder(dict); - } - else - { - g_warning("ghb_presets_get_folder (): internal preset lookup error"); + folder = ghb_dict_get_bool(dict, "Folder"); } return folder; } void -presets_set_default(gint *indices, gint len) +ghb_preset_to_settings(GhbValue *settings, GhbValue *preset) { - GhbValue *dict; + // Remove troublesome x264Option + ghb_dict_remove(settings, "x264Option"); - g_debug("presets_set_default ()"); - presets_clear_default(presetsPlist); - dict = presets_get_dict(presetsPlist, indices, len); - if (dict) + // Initialize defaults + ghb_settings_init(settings, "Initialization"); + + // Initialize the ui settings from a preset + ghb_dict_copy(settings, preset); + + // Fix up all the internal settings that are derived from preset values. + ghb_dict_set_bool(settings, "PictureDeinterlaceDecomb", + !ghb_dict_get_bool(settings, "PictureDecombDeinterlace")); + + ghb_dict_set(settings, "scale_height", ghb_value_dup( + ghb_dict_get_value(settings, "PictureHeight"))); + + ghb_dict_set(settings, "scale_width", ghb_value_dup( + ghb_dict_get_value(settings, "PictureWidth"))); + + gint uses_pic; + gint vqtype; + + uses_pic = ghb_dict_get_int(settings, "UsesPictureSettings"); + vqtype = ghb_dict_get_int(settings, "VideoQualityType"); + + // "Use max" or "strict anamorphic" imply autoscale + if (uses_pic == 2) { - ghb_dict_set(dict, "Default", ghb_bool_value_new(TRUE)); + ghb_dict_set_bool(settings, "autoscale", TRUE); + } + else if (uses_pic == 1) + { + ghb_dict_set_bool(settings, "autoscale", FALSE); } - store_presets(); -} -static void -presets_set_folder_open(gboolean open, gint *indices, gint len) -{ - GhbValue *dict; + // VideoQualityType/0/1/2 - vquality_type_/target/bitrate/constant + // *note: target is no longer used + switch (vqtype) + { + case 0: + { + ghb_dict_set_bool(settings, "vquality_type_bitrate", TRUE); + ghb_dict_set_bool(settings, "vquality_type_constant", FALSE); + } break; + case 1: + { + ghb_dict_set_bool(settings, "vquality_type_bitrate", TRUE); + ghb_dict_set_bool(settings, "vquality_type_constant", FALSE); + } break; + case 2: + { + ghb_dict_set_bool(settings, "vquality_type_bitrate", FALSE); + ghb_dict_set_bool(settings, "vquality_type_constant", TRUE); + } break; + default: + { + ghb_dict_set_bool(settings, "vquality_type_bitrate", FALSE); + ghb_dict_set_bool(settings, "vquality_type_constant", TRUE); + } break; + } - g_debug("presets_set_folder_open ()"); - dict = presets_get_dict(presetsPlist, indices, len); - if (dict) + const gchar *mode = ghb_dict_get_string(settings, "VideoFramerateMode"); + if (strcmp(mode, "cfr") == 0) { - ghb_dict_set(dict, "FolderOpen", ghb_bool_value_new(open)); + ghb_dict_set_bool(settings, "VideoFramerateCFR", TRUE); + ghb_dict_set_bool(settings, "VideoFrameratePFR", FALSE); + ghb_dict_set_bool(settings, "VideoFramerateVFR", FALSE); + } + else if (strcmp(mode, "pfr") == 0) + { + ghb_dict_set_bool(settings, "VideoFramerateCFR", FALSE); + ghb_dict_set_bool(settings, "VideoFrameratePFR", TRUE); + ghb_dict_set_bool(settings, "VideoFramerateVFR", FALSE); + } + else + { + ghb_dict_set_bool(settings, "VideoFramerateCFR", FALSE); + ghb_dict_set_bool(settings, "VideoFrameratePFR", FALSE); + ghb_dict_set_bool(settings, "VideoFramerateVFR", TRUE); } -} -static void init_settings_from_dict( - GhbValue *dest, GhbValue *template, GhbValue *dict, gboolean filter); + if (ghb_dict_get_bool(settings, "x264UseAdvancedOptions")) + { + // Force preset/tune/profile/level/opts to conform to option string + ghb_dict_set_string(settings, "VideoPreset", "medium"); + ghb_dict_set_string(settings, "VideoTune", "none"); + ghb_dict_set_string(settings, "VideoProfile", "auto"); + ghb_dict_set_string(settings, "VideoLevel", "auto"); + ghb_dict_set(settings, "VideoOptionExtra", ghb_value_dup( + ghb_dict_get_value(settings, "x264Option"))); + } + else + { + ghb_dict_remove(settings, "x264Option"); + } -static void -init_settings_from_array( - GhbValue *dest, - GhbValue *template, - GhbValue *array, - gboolean filter) -{ - GhbValue *gval, *val, *new_val; - gint count, ii; + int ii, encoder; + const char * const *videoPresets; + const char *videoPreset; - if (ghb_array_len(template) == 0) + encoder = ghb_get_video_encoder(settings); + videoPresets = hb_video_encoder_get_presets(encoder); + videoPreset = ghb_dict_get_string(settings, "VideoPreset"); + for (ii = 0; videoPreset && videoPresets && videoPresets[ii]; ii++) { - if (!filter) + if (!strcasecmp(videoPreset, videoPresets[ii])) { - count = ghb_array_len(array); - for (ii = 0; ii < count; ii++) - { - val = ghb_array_get(array, ii); - ghb_array_append(dest, ghb_value_dup(val)); - } + ghb_dict_set_int(settings, "VideoPresetSlider", ii); + break; } - return; } + if (videoPreset != NULL) + ghb_dict_set_string(settings, "VideoPreset", videoPreset); - count = ghb_array_len(array); - // The first element of the template array is always the - // template for the allowed values - gval = ghb_array_get(template, 0); - for (ii = 0; ii < count; ii++) + char *videoTune; + char *tune = NULL; + char *saveptr; + char *tok; + + videoTune = g_strdup(ghb_dict_get_string(settings, "VideoTune")); + tok = strtok_r(videoTune, ",./-+", &saveptr); + ghb_dict_set_bool(settings, "x264FastDecode", FALSE); + ghb_dict_set_bool(settings, "x264ZeroLatency", FALSE); + while (tok != NULL) { - val = ghb_array_get(array, ii); - if (ghb_value_type(gval) == GHB_DICT) + if (!strcasecmp(tok, "fastdecode")) { - GhbValue *new_dict; - if (val != NULL && ghb_value_type(val) == GHB_DICT) - { - new_dict = ghb_dict_new(); - init_settings_from_dict(new_dict, gval, val, filter); - } - else - { - new_dict = ghb_value_dup(gval); - } - new_val = new_dict; + ghb_dict_set_bool(settings, "x264FastDecode", TRUE); } - else if (ghb_value_type(gval) == GHB_ARRAY) + else if (!strcasecmp(tok, "zerolatency")) { - GhbValue *new_array; - if (val != NULL && ghb_value_type(val) == GHB_ARRAY) - { - new_array = ghb_array_new(); - init_settings_from_array(new_array, gval, val, filter); - } - else - { - new_array = ghb_value_dup(gval); - } - new_val = new_array; + ghb_dict_set_bool(settings, "x264ZeroLatency", TRUE); + } + else if (tune == NULL) + { + tune = g_strdup(tok); } else { - if (val == NULL) - new_val = ghb_value_dup(gval); - else - new_val = ghb_value_dup(val); + ghb_log("Superfluous tunes! %s", tok); } - ghb_array_append(dest, new_val); + tok = strtok_r(NULL, ",./-+", &saveptr); + } + g_free(videoTune); + if (tune != NULL) + { + ghb_dict_set_string(settings, "VideoTune", tune); + g_free(tune); } -} -static void -init_settings_from_dict( - GhbValue *dest, - GhbValue *template, - GhbValue *dict, - gboolean filter) -{ - GhbDictIter iter; - const gchar *key; - GhbValue *gval, *val, *new_val; + const char *videoProfile; + videoProfile = ghb_dict_get_string(settings, "VideoProfile"); + if (videoProfile != NULL) + ghb_dict_set_string(settings, "VideoProfile", videoProfile); - iter = ghb_dict_iter_init(template); - // middle (void*) cast prevents gcc warning "defreferencing type-punned - // pointer will break strict-aliasing rules" - while (ghb_dict_iter_next(template, &iter, &key, &gval)) - { - val = NULL; - if (dict) - val = ghb_dict_get(dict, key); - if (ghb_value_type(gval) == GHB_DICT) - { - GhbValue *new_dict; - if (val != NULL && ghb_value_type(val) == GHB_DICT) - { - new_dict = ghb_dict_new(); - init_settings_from_dict(new_dict, gval, val, filter); - } - else - { - new_dict = ghb_value_dup(gval); - } - new_val = new_dict; - } - else if (ghb_value_type(gval) == GHB_ARRAY) - { - GhbValue *new_array; - if (val != NULL && ghb_value_type(val) == GHB_ARRAY) - { - new_array = ghb_array_new(); - init_settings_from_array(new_array, gval, val, filter); - } - else - { - new_array = ghb_value_dup(gval); - } - new_val = new_array; + const char *videoLevel; + videoLevel = ghb_dict_get_string(settings, "VideoLevel"); + if (videoLevel != NULL) + ghb_dict_set_string(settings, "VideoLevel", videoLevel); - } - else - { - if (val == NULL) - new_val = ghb_value_dup(gval); - else - new_val = ghb_value_dup(val); - } - ghb_dict_set(dest, key, new_val); + if (ghb_dict_get(settings, "x264OptionExtra") != NULL) + { + const char *optionExtra; + optionExtra = ghb_dict_get_string(settings, "x264OptionExtra"); + ghb_dict_set_string(settings, "VideoOptionExtra", optionExtra); } - if (filter || dict == NULL) - return; - - // If not filtering the source, copy source elements that - // were not in the template. - iter = ghb_dict_iter_init(dict); - // middle (void*) cast prevents gcc warning "defreferencing type-punned - // pointer will break strict-aliasing rules" - while (ghb_dict_iter_next(dict, &iter, &key, &gval)) + // Extract copy mask to check box booleans + GhbValue *copy_mask; + copy_mask = ghb_dict_get(preset, "AudioCopyMask"); + if (copy_mask != NULL) { - val = ghb_dict_get(template, key); - if (val == NULL) + int count = ghb_array_len(copy_mask); + int ii; + for (ii = 0; ii < count; ii++) { - ghb_dict_set(dest, key, ghb_value_dup(gval)); + GhbValue *val = ghb_array_get(copy_mask, ii); + const char *s = ghb_value_get_string(val); + int acodec = hb_audio_encoder_get_from_name(s); + switch (acodec) + { + default: + break; + case HB_ACODEC_LAME: + case HB_ACODEC_MP3_PASS: + ghb_dict_set_bool(settings, "AudioAllowMP3Pass", 1); + break; + case HB_ACODEC_CA_AAC: + case HB_ACODEC_FDK_AAC: + case HB_ACODEC_FFAAC: + case HB_ACODEC_AAC_PASS: + ghb_dict_set_bool(settings, "AudioAllowAACPass", 1); + break; + case HB_ACODEC_AC3: + case HB_ACODEC_AC3_PASS: + ghb_dict_set_bool(settings, "AudioAllowAC3Pass", 1); + break; + case HB_ACODEC_DCA: + case HB_ACODEC_DCA_PASS: + ghb_dict_set_bool(settings, "AudioAllowDTSPass", 1); + break; + case HB_ACODEC_DCA_HD: + case HB_ACODEC_DCA_HD_PASS: + ghb_dict_set_bool(settings, "AudioAllowDTSHDPass", 1); + break; + case HB_ACODEC_FFEAC3: + case HB_ACODEC_EAC3_PASS: + ghb_dict_set_bool(settings, "AudioAllowEAC3Pass", 1); + break; + case HB_ACODEC_FFFLAC: + case HB_ACODEC_FFFLAC24: + case HB_ACODEC_FLAC_PASS: + ghb_dict_set_bool(settings, "AudioAllowFLACPass", 1); + break; + case HB_ACODEC_FFTRUEHD: + case HB_ACODEC_TRUEHD_PASS: + ghb_dict_set_bool(settings, "AudioAllowTRUEHDPass", 1); + break; + } } } } -void -ghb_preset_to_settings(GhbValue *settings, GhbValue *preset) -{ - // Initialize the ui from presets file. - GhbValue *internal; - - // Get key list from internal default presets. This way we do not - // load any unknown keys. - GhbValue *internalPlist = ghb_resource_get("internal-defaults"); - if (internalPlist == NULL) return; - internal = plist_get_dict(internalPlist, "Presets"); - if (preset == NULL) - preset = internal; - - ghb_dict_remove(settings, "x264Option"); - init_settings_from_dict(settings, preset, NULL, TRUE); -} - // Initialization order of some widgets matter because the value of // these widgets are used to establich limits on the values that // other widgets are allowed to take. // // So make sure these get initialized first. -static const char *widget_priority_list[] = +static const char *widget_priority_list[] = { "preview_count", "PtoPType", @@ -947,11 +504,11 @@ static const char *widget_priority_list[] = void ghb_settings_to_ui(signal_user_data_t *ud, GhbValue *dict) { - GhbDictIter iter; + GhbDictIter iter; const gchar *key; - GhbValue *gval; - int ii; - GhbValue *tmp = ghb_value_dup(dict); + GhbValue *gval; + int ii; + GhbValue *tmp = ghb_value_dup(dict); if (dict == NULL) return; @@ -974,136 +531,61 @@ ghb_settings_to_ui(signal_user_data_t *ud, GhbValue *dict) ghb_value_free(&tmp); } -static GhbValue *current_preset = NULL; - -gboolean -ghb_preset_is_custom() -{ - const GhbValue *val; - - if (current_preset == NULL) return FALSE; - val = ghb_dict_get(current_preset, "Type"); - return (ghb_value_get_int(val) == 1); -} - -void -ghb_set_preset_settings_from_indices( - signal_user_data_t *ud, - gint *indices, - gint len) -{ - GhbValue *dict = NULL; - gint fallback[2] = {0, -1}; - - if (indices) - dict = presets_get_dict(presetsPlist, indices, len); - if (dict == NULL) - { - indices = fallback; - len = 1; - dict = presets_get_dict(presetsPlist, indices, len); - } - if (dict == NULL) - { - ghb_preset_to_settings(ud->settings, NULL); - current_preset = NULL; - } - else - { - GhbValue *path; - gboolean folder; - - current_preset = dict; - folder = ghb_value_get_bool(ghb_dict_get(dict, "Folder")); - if (folder) - ghb_preset_to_settings(ud->settings, NULL); - else - ghb_preset_to_settings(ud->settings, dict); - path = preset_path_from_indices(presetsPlist, indices, len); - ghb_dict_set(ud->settings, "preset", ghb_value_dup(path)); - ghb_value_free(&path); - } -} - -static const GhbValue* -curr_preset_get_value(const gchar *key) -{ - if (current_preset == NULL) return NULL; - return ghb_dict_get(current_preset, key); -} - -void -ghb_update_from_preset( - signal_user_data_t *ud, - const gchar *key) -{ - const GhbValue *gval; - - g_debug("ghb_update_from_preset() %s", key); - gval = curr_preset_get_value(key); - if (gval != NULL) - { - ghb_ui_update(ud, key, gval); - } -} - static void -ghb_select_preset2( - GtkBuilder *builder, - gint *indices, - gint len) +select_preset2(GtkBuilder *builder, hb_preset_index_t *path) { - GtkTreeView *treeview; + GtkTreeView *treeview; GtkTreeSelection *selection; - GtkTreeModel *store; - GtkTreeIter iter; - GtkTreePath *path; + GtkTreeModel *store; + GtkTreeIter iter; + GtkTreePath *treepath; - g_debug("ghb_select_preset2()"); - treeview = GTK_TREE_VIEW(GHB_WIDGET(builder, "presets_list")); + if (path == NULL || path->depth == 0) + return; + + treeview = GTK_TREE_VIEW(GHB_WIDGET(builder, "presets_list")); selection = gtk_tree_view_get_selection (treeview); - store = gtk_tree_view_get_model (treeview); - path = ghb_tree_path_new_from_indices(indices, len); - if (path) + store = gtk_tree_view_get_model (treeview); + treepath = ghb_tree_path_new_from_index(path); + if (treepath != NULL) { - if (gtk_tree_model_get_iter(store, &iter, path)) + gtk_tree_view_expand_to_path(treeview, treepath); + if (gtk_tree_model_get_iter(store, &iter, treepath)) { - gtk_tree_selection_select_iter (selection, &iter); + gtk_tree_selection_select_iter(selection, &iter); } else { if (gtk_tree_model_get_iter_first(store, &iter)) - gtk_tree_selection_select_iter (selection, &iter); + gtk_tree_selection_select_iter(selection, &iter); } - gtk_tree_path_free(path); + gtk_tree_path_free(treepath); } } void -ghb_select_preset(GtkBuilder *builder, const GhbValue *path) +ghb_select_preset(GtkBuilder *builder, const char *name) { - gint *indices, len; + hb_preset_index_t *path; - g_debug("ghb_select_preset()"); - indices = ghb_preset_indices_from_path(presetsPlist, path, &len); - if (indices) + path = hb_preset_search_index(name, 1); + if (path != NULL) { - ghb_select_preset2(builder, indices, len); - g_free(indices); + select_preset2(builder, path); + free(path); } } void ghb_select_default_preset(GtkBuilder *builder) { - gint *indices, len; + hb_preset_index_t *path; - g_debug("ghb_select_default_preset()"); - indices = presets_find_default(presetsPlist, &len); - if (indices) + path = hb_presets_get_default_index(); + if (path != NULL) { - ghb_select_preset2(builder, indices, len); - g_free(indices); + select_preset2(builder, path); + g_free(path); } } @@ -1111,12 +593,12 @@ gchar* ghb_get_user_config_dir(gchar *subdir) { const gchar *dir; - gchar *config; + gchar *config; dir = g_get_user_config_dir(); if (!g_file_test(dir, G_FILE_TEST_IS_DIR)) { - dir = g_get_home_dir(); + dir = g_get_home_dir(); config = g_strdup_printf ("%s/.ghb", dir); if (!g_file_test(config, G_FILE_TEST_IS_DIR)) g_mkdir (config, 0755); @@ -1130,7 +612,7 @@ ghb_get_user_config_dir(gchar *subdir) if (subdir) { gchar **split; - gint ii; + gint ii; split = g_strsplit(subdir, G_DIR_SEPARATOR_S, -1); for (ii = 0; split[ii] != NULL; ii++) @@ -1154,7 +636,7 @@ write_config_file(const gchar *name, GhbValue *dict) gchar *config, *path; config = ghb_get_user_config_dir(NULL); - path = g_strdup_printf ("%s/%s", config, name); + path = g_strdup_printf ("%s/%s", config, name); g_free(config); ghb_json_write_file(path, dict); g_free(path); @@ -1166,32 +648,52 @@ ghb_write_settings_file(const gchar *path, GhbValue *dict) ghb_json_write_file(path, dict); } -static void -store_plist(const gchar *name, GhbValue *plist) +static int +presets_add_config_file(const gchar *name) { - gchar *config, *path; + gchar *config, *path; + hb_value_t *preset; config = ghb_get_user_config_dir(NULL); - path = g_strdup_printf ("%s/%s", config, name); + path = g_strdup_printf ("%s/%s", config, name); g_free(config); - ghb_plist_write_file(path, plist); + if (!g_file_test(path, G_FILE_TEST_IS_REGULAR)) + return -1; + preset = hb_presets_read_file(path); g_free(path); + if (preset != NULL) + { + hb_presets_add(preset); + + int hb_major, hb_minor, hb_micro; + int major, minor, micro; + hb_presets_version(preset, &major, &minor, µ); + hb_presets_current_version(&hb_major, &hb_minor, &hb_micro); + if (major != hb_major || minor != hb_minor || micro != hb_micro) + { + // Reload hb builtin presets + hb_presets_builtin_update(); + store_presets(); + } + return 0; + } + return -1; } static GhbValue* read_config_file(const gchar *name) { - gchar *config, *path; + gchar *config, *path; GhbValue *gval = NULL; config = ghb_get_user_config_dir(NULL); - path = g_strdup_printf ("%s/%s", config, name); + path = g_strdup_printf ("%s/%s", config, name); g_free(config); if (g_file_test(path, G_FILE_TEST_IS_REGULAR)) { gval = ghb_json_parse_file(path); if (gval == NULL) - gval = ghb_plist_parse_file(path); + gval = hb_plist_parse_file(path); } g_free(path); return gval; @@ -1206,11 +708,13 @@ ghb_read_settings_file(const gchar *path) { gval = ghb_json_parse_file(path); if (gval == NULL) - gval = ghb_plist_parse_file(path); + gval = hb_plist_parse_file(path); } return gval; } +#if 0 +// Currently unused, but keeping around just in case... gboolean ghb_lock_file(const gchar *name) { @@ -1232,22 +736,22 @@ ghb_lock_file(const gchar *name) return 1; #endif } +#endif void ghb_write_pid_file() { #if !defined(_WIN32) gchar *config, *path; - pid_t pid; - FILE *fp; - int fd; - - pid = getpid(); + pid_t pid; + FILE *fp; + int fd; + pid = getpid(); config = ghb_get_user_config_dir(NULL); - path = g_strdup_printf ("%s/ghb.pid.%d", config, pid); + path = g_strdup_printf ("%s/ghb.pid.%d", config, pid); + fp = g_fopen(path, "w"); - fp = g_fopen(path, "w"); fprintf(fp, "%d\n", pid); fclose(fp); @@ -1259,42 +763,26 @@ ghb_write_pid_file() #endif } -void -ghb_unlink_pid_file(int pid) -{ - gchar *config, *path; - - config = ghb_get_user_config_dir(NULL); - path = g_strdup_printf ("%s/ghb.pid.%d", config, pid); - - if (g_file_test(path, G_FILE_TEST_IS_REGULAR)) - { - g_unlink(path); - } - - g_free(config); - g_free(path); -} - int ghb_find_pid_file() { const gchar *file; - gchar *config; + gchar *config; config = ghb_get_user_config_dir(NULL); if (g_file_test(config, G_FILE_TEST_IS_DIR)) { - GDir *gdir = g_dir_open(config, 0, NULL); + GDir *gdir; + gdir = g_dir_open(config, 0, NULL); file = g_dir_read_name(gdir); while (file) { if (strncmp(file, "ghb.pid.", 8) == 0) { gchar *path; - pid_t my_pid; - int pid; + pid_t my_pid; + int pid; sscanf(file, "ghb.pid.%d", &pid); my_pid = getpid(); @@ -1346,7 +834,7 @@ remove_config_file(const gchar *name) gchar *config, *path; config = ghb_get_user_config_dir(NULL); - path = g_strdup_printf ("%s/%s", config, name); + path = g_strdup_printf ("%s/%s", config, name); if (g_file_test(path, G_FILE_TEST_IS_REGULAR)) { g_unlink(path); @@ -1356,33 +844,6 @@ remove_config_file(const gchar *name) } void -ghb_prefs_save(GhbValue *settings) -{ - GhbValue *dict; - GhbValue *pref_dict; - GhbDictIter iter; - const gchar *key; - const GhbValue *value; - - GhbValue *internalPlist = ghb_resource_get("internal-defaults"); - dict = plist_get_dict(internalPlist, "Preferences"); - if (dict == NULL) return; - pref_dict = plist_get_dict(prefsPlist, "Preferences"); - if (pref_dict == NULL) return; - iter = ghb_dict_iter_init(dict); - while (ghb_dict_iter_next(dict, &iter, &key, NULL)) - { - value = ghb_dict_get_value(settings, key); - if (value != NULL) - { - ghb_dict_set(pref_dict, key, ghb_value_dup(value)); - } - } - store_prefs(); - prefs_modified = FALSE; -} - -void ghb_pref_save(GhbValue *settings, const gchar *key) { const GhbValue *value, *value2; @@ -1391,7 +852,7 @@ ghb_pref_save(GhbValue *settings, const gchar *key) if (value != NULL) { GhbValue *dict; - dict = plist_get_dict(prefsPlist, "Preferences"); + dict = ghb_dict_get(prefsDict, "Preferences"); if (dict == NULL) return; value2 = ghb_dict_get(dict, key); if (ghb_value_cmp(value, value2) != 0) @@ -1412,7 +873,7 @@ ghb_pref_set(GhbValue *settings, const gchar *key) if (value != NULL) { GhbValue *dict; - dict = plist_get_dict(prefsPlist, "Preferences"); + dict = ghb_dict_get(prefsDict, "Preferences"); if (dict == NULL) return; value2 = ghb_dict_get(dict, key); if (ghb_value_cmp(value, value2) != 0) @@ -1436,35 +897,23 @@ ghb_prefs_store(void) void ghb_settings_init(GhbValue *settings, const char *name) { - GhbValue *internal; - GhbDictIter iter; - const gchar *key; - GhbValue *gval; + GhbValue *internal; - g_debug("ghb_settings_init"); - GhbValue *internalPlist = ghb_resource_get("internal-defaults"); + GhbValue *internalDict = ghb_resource_get("internal-defaults"); // Setting a ui widget will cause the corresponding setting // to be set, but it also triggers a callback that can // have the side effect of using other settings values // that have not yet been set. So set *all* settings first // then update the ui. - internal = plist_get_dict(internalPlist, name); - iter = ghb_dict_iter_init(internal); - // middle (void*) cast prevents gcc warning "defreferencing type-punned - // pointer will break strict-aliasing rules" - while (ghb_dict_iter_next(internal, &iter, &key, &gval)) - { - ghb_dict_set(settings, key, ghb_value_dup(gval)); - } + internal = ghb_dict_get(internalDict, name); + ghb_dict_copy(settings, internal); } void ghb_settings_close() { - if (presetsPlist) - ghb_value_free(&presetsPlist); - if (prefsPlist) - ghb_value_free(&prefsPlist); + if (prefsDict) + ghb_value_free(&prefsDict); } #if defined(_WIN32) @@ -1498,47 +947,35 @@ FindFirstCDROM(void) void ghb_prefs_load(signal_user_data_t *ud) { - GhbValue *dict, *internal; - GhbDictIter iter; - const gchar *key; - GhbValue *gval; - - g_debug("ghb_prefs_load"); - GhbValue *internalPlist = ghb_resource_get("internal-defaults"); - prefsPlist = read_config_file("preferences"); - if (prefsPlist == NULL) - prefsPlist = ghb_dict_new(); - dict = plist_get_dict(prefsPlist, "Preferences"); - internal = plist_get_dict(internalPlist, "Preferences"); - if (dict == NULL && internal) - { - dict = ghb_dict_new(); - ghb_dict_set(prefsPlist, "Preferences", dict); + GhbValue *dict, *internal; + GhbValue *internalDict; - // Get defaults from internal defaults - iter = ghb_dict_iter_init(internal); - // middle (void*) cast prevents gcc warning "defreferencing type-punned - // pointer will break strict-aliasing rules" - while (ghb_dict_iter_next(internal, &iter, &key, &gval)) - { - ghb_dict_set(dict, key, ghb_value_dup(gval)); - } + internalDict = ghb_resource_get("internal-defaults"); + prefsDict = read_config_file("preferences"); + if (prefsDict == NULL) + prefsDict = ghb_dict_new(); + dict = ghb_dict_get(prefsDict, "Preferences"); + internal = ghb_dict_get(internalDict, "Preferences"); + if (dict == NULL && internal != NULL) + { + dict = ghb_value_dup(internal); + ghb_dict_set(prefsDict, "Preferences", dict); const gchar *dir = g_get_user_special_dir (G_USER_DIRECTORY_DESKTOP); if (dir == NULL) { dir = "."; } - ghb_dict_set(dict, "ExportDirectory", ghb_string_value_new(dir)); + ghb_dict_set_string(dict, "ExportDirectory", dir); dir = g_get_user_special_dir (G_USER_DIRECTORY_VIDEOS); if (dir == NULL) { dir = "."; } - ghb_dict_set(dict, "destination_dir", ghb_string_value_new(dir)); + ghb_dict_set_string(dict, "destination_dir", dir); - ghb_dict_set(dict, "SrtDir", ghb_string_value_new(dir)); + ghb_dict_set_string(dict, "SrtDir", dir); #if defined(_WIN32) gchar *source; @@ -1547,7 +984,7 @@ ghb_prefs_load(signal_user_data_t *ud) { source = g_strdup("C:" G_DIR_SEPARATOR_S); } - ghb_dict_set(dict, "default_source", ghb_string_value_new(source)); + ghb_dict_set_string(dict, "default_source", source); g_free(source); #endif store_prefs(); @@ -1558,34 +995,29 @@ void ghb_prefs_to_settings(GhbValue *settings) { // Initialize the ui from presets file. - GhbValue *internal, *dict; + GhbValue *dict; - if (prefsPlist == NULL) + if (prefsDict == NULL) return; - // Get key list from internal default presets. This way we do not - // load any unknown keys. - GhbValue *internalPlist = ghb_resource_get("internal-defaults"); - if (internalPlist == NULL) return; - internal = plist_get_dict(internalPlist, "Preferences"); - dict = plist_get_dict(prefsPlist, "Preferences"); // Setting a ui widget will cause the corresponding setting // to be set, but it also triggers a callback that can // have the side effect of using other settings values // that have not yet been set. So set *all* settings first // then update the ui. - init_settings_from_dict(settings, internal, dict, TRUE); + dict = ghb_dict_get(prefsDict, "Preferences"); + ghb_dict_copy(settings, dict); } static const gchar* -get_preset_color(gint type, gboolean folder) +get_preset_color(gint type, gboolean is_folder) { const gchar *color; if (type == PRESETS_CUSTOM) { color = "DimGray"; - if (folder) + if (is_folder) { color = "black"; } @@ -1593,7 +1025,7 @@ get_preset_color(gint type, gboolean folder) else { color = "blue"; - if (folder) + if (is_folder) { color = "Navy"; } @@ -1602,238 +1034,247 @@ get_preset_color(gint type, gboolean folder) } void -ghb_presets_list_init( - signal_user_data_t *ud, - gint *indices, - gint len) +ghb_presets_list_init(signal_user_data_t *ud, const hb_preset_index_t *path) { - GtkTreeView *treeview; - GtkTreeIter iter, titer, *piter; + hb_preset_index_t *next_path; + GhbValue *folder; + GtkTreeView *treeview; + GtkTreeStore *store; + GtkTreePath *parent_path; + GtkTreeIter iter, *piter; + gint count, ii; - GtkTreeStore *store; - const gchar *preset; - GtkTreePath *parent_path; - const gchar *description; - gboolean def; - gint count, ii; - GhbValue *dict; - gint *more_indices; - GhbValue *presets = NULL; - - g_debug("ghb_presets_list_init ()"); - more_indices = g_malloc((len+1)*sizeof(gint)); - memcpy(more_indices, indices, len*sizeof(gint)); - presets = presets_get_folder(presetsPlist, indices, len); - if (presets == NULL) + if (path == NULL) + { + hb_preset_index_t *p = hb_preset_index_init(NULL, 0); + ghb_presets_list_init(ud, p); + free(p); + return; + } + next_path = hb_preset_index_dup(path); + folder = hb_presets_get_folder_children(path); + if (folder == NULL) { g_warning(_("Failed to find parent folder when adding child.")); - g_free(more_indices); + g_free(next_path); return; } - count = ghb_array_len(presets); - treeview = GTK_TREE_VIEW(GHB_WIDGET(ud->builder, "presets_list")); - store = GTK_TREE_STORE(gtk_tree_view_get_model(treeview)); - parent_path = ghb_tree_path_new_from_indices(indices, len); - if (parent_path) + treeview = GTK_TREE_VIEW(GHB_WIDGET(ud->builder, "presets_list")); + store = GTK_TREE_STORE(gtk_tree_view_get_model(treeview)); + parent_path = ghb_tree_path_new_from_index(path); + if (parent_path != NULL) { - gtk_tree_model_get_iter(GTK_TREE_MODEL(store), &titer, parent_path); - piter = &titer; + GtkTreeIter tmp_iter; + gtk_tree_model_get_iter(GTK_TREE_MODEL(store), &tmp_iter, parent_path); + piter = &tmp_iter; gtk_tree_path_free(parent_path); } else { piter = NULL; } + count = ghb_array_len(folder); + next_path->depth++; for (ii = 0; ii < count; ii++) { + GhbValue *dict; + const gchar *name; const gchar *color; - gint type; - gboolean folder; + gint type; + const gchar *description; + gboolean is_folder; + gboolean def; + + next_path->index[next_path->depth-1] = ii; // Additional settings, add row - dict = ghb_array_get(presets, ii); - preset = preset_get_name(dict); - more_indices[len] = ii; - def = preset_is_default(dict); + dict = ghb_array_get(folder, ii); + name = ghb_dict_get_string(dict, "PresetName"); + description = ghb_dict_get_string(dict, "PresetDescription"); + type = ghb_dict_get_int(dict, "Type"); + is_folder = ghb_dict_get_bool(dict, "Folder"); + def = ghb_dict_get_bool(dict, "Default"); + color = get_preset_color(type, is_folder); - description = ghb_value_get_string( - ghb_dict_get(dict, "PresetDescription")); gtk_tree_store_append(store, &iter, piter); - type = ghb_preset_type(dict); - folder = ghb_preset_folder(dict); - color = get_preset_color(type, folder); - gtk_tree_store_set(store, &iter, 0, preset, + gtk_tree_store_set(store, &iter, + 0, name, 1, def ? 800 : 400, - 2, def ? 2 : 0, + 2, def ? 2 : 0, 3, color, 4, description, 5, type == PRESETS_BUILTIN ? 0 : 1, -1); - if (def && piter) - { - GtkTreePath *path; - GtkTreeIter ppiter; - - if (gtk_tree_model_iter_parent( - GTK_TREE_MODEL(store), &ppiter, piter)) - { - path = gtk_tree_model_get_path(GTK_TREE_MODEL(store), &ppiter); - gtk_tree_view_expand_row(treeview, path, FALSE); - gtk_tree_path_free(path); - } - path = gtk_tree_model_get_path(GTK_TREE_MODEL(store), piter); - gtk_tree_view_expand_row(treeview, path, FALSE); - gtk_tree_path_free(path); - } - if (folder) + if (is_folder) { - ghb_presets_list_init(ud, more_indices, len+1); - if (preset_folder_is_open(dict)) + ghb_presets_list_init(ud, next_path); + if (ghb_dict_get_bool(dict, "FolderOpen")) { GtkTreePath *path; - - if (piter != NULL) - { - path = gtk_tree_model_get_path(GTK_TREE_MODEL(store), piter); - gtk_tree_view_expand_row(treeview, path, FALSE); - gtk_tree_path_free(path); - } path = gtk_tree_model_get_path(GTK_TREE_MODEL(store), &iter); - gtk_tree_view_expand_row(treeview, path, FALSE); + gtk_tree_view_expand_to_path(treeview, path); gtk_tree_path_free(path); } } } - g_free(more_indices); + g_free(next_path); + if (path == NULL) + { + ghb_presets_list_show_default(ud); + } +} + +static void +presets_list_clear(signal_user_data_t *ud) +{ + GtkTreeView *treeview; + GtkTreeModel *store; + GtkTreeIter iter; + gboolean valid; + + treeview = GTK_TREE_VIEW(GHB_WIDGET(ud->builder, "presets_list")); + store = gtk_tree_view_get_model(treeview); + valid = gtk_tree_model_get_iter_first(store, &iter); + while (valid) + { + gtk_tree_store_remove(GTK_TREE_STORE(store), &iter); + valid = gtk_tree_model_get_iter_first(store, &iter); + } +} + +void +ghb_presets_list_reinit(signal_user_data_t *ud) +{ + presets_list_clear(ud); + ghb_presets_list_init(ud, NULL); } static void presets_list_update_item( - signal_user_data_t *ud, - gint *indices, - gint len, - gboolean recurse) + signal_user_data_t *ud, + const hb_preset_index_t *path, + gboolean recurse) { - GtkTreeView *treeview; + GhbValue *dict; + GtkTreeView *treeview; GtkTreeStore *store; - GtkTreeIter iter; - GtkTreePath *treepath; - const gchar *name; - const gchar *description; - gint type; - gboolean def, folder; - GhbValue *dict; - const gchar *color; - - g_debug("presets_list_update_item ()"); - dict = presets_get_dict(presetsPlist, indices, len); + GtkTreePath *treepath; + GtkTreeIter iter; + const gchar *name; + const gchar *description; + gint type; + gboolean is_folder; + gboolean def; + const gchar *color; + + dict = hb_preset_get(path); if (dict == NULL) return; + treeview = GTK_TREE_VIEW(GHB_WIDGET(ud->builder, "presets_list")); - store = GTK_TREE_STORE(gtk_tree_view_get_model(treeview)); - treepath = ghb_tree_path_new_from_indices(indices, len); + store = GTK_TREE_STORE(gtk_tree_view_get_model(treeview)); + treepath = ghb_tree_path_new_from_index(path); gtk_tree_model_get_iter(GTK_TREE_MODEL(store), &iter, treepath); + // Additional settings, add row - name = preset_get_name(dict); - def = preset_is_default(dict); - - description = ghb_value_get_string(ghb_dict_get(dict, "PresetDescription")); - type = ghb_preset_type(dict); - folder = ghb_preset_folder(dict); - color = get_preset_color(type, folder); - gtk_tree_store_set(store, &iter, 0, name, + name = ghb_dict_get_string(dict, "PresetName"); + description = ghb_dict_get_string(dict, "PresetDescription"); + type = ghb_dict_get_int(dict, "Type"); + is_folder = ghb_dict_get_bool(dict, "Folder"); + def = ghb_dict_get_bool(dict, "Default"); + color = get_preset_color(type, is_folder); + + gtk_tree_store_set(store, &iter, + 0, name, 1, def ? 800 : 400, - 2, def ? 2 : 0, + 2, def ? 2 : 0, 3, color, 4, description, 5, type == PRESETS_BUILTIN ? 0 : 1, -1); - if (recurse && folder) + if (recurse && is_folder) { - ghb_presets_list_init(ud, indices, len); + ghb_presets_list_init(ud, path); } } static void -presets_list_insert( - signal_user_data_t *ud, - gint *indices, - gint len) -{ - GtkTreeView *treeview; - GtkTreeIter iter, titer, *piter; - GtkTreeStore *store; - const gchar *preset; - const gchar *description; - gint type; - gboolean def, folder; - gint count; - GhbValue *presets; - GtkTreePath *parent_path; - GhbValue *dict; - const gchar *color; - - g_debug("presets_list_insert ()"); - treeview = GTK_TREE_VIEW(GHB_WIDGET(ud->builder, "presets_list")); - store = GTK_TREE_STORE(gtk_tree_view_get_model(treeview)); - presets = presets_get_folder(presetsPlist, indices, len-1); - if (presets == NULL) +presets_list_append(signal_user_data_t *ud, const hb_preset_index_t *path) +{ + hb_preset_index_t *folder_path; + hb_value_t *dict; + GtkTreeView *treeview; + GtkTreeStore *store; + GtkTreePath *folder_treepath; + GtkTreeIter iter, *piter; + const gchar *name; + const gchar *description; + gint type; + gboolean is_folder; + gboolean def; + const gchar *color; + + folder_path = hb_preset_index_dup(path); + folder_path->depth--; + + dict = hb_preset_get(path); + if (dict == NULL) { - g_warning(_("Failed to find parent folder while adding child.")); + g_message("Ack! Desync between presets and preset list"); return; } - parent_path = ghb_tree_path_new_from_indices(indices, len-1); - if (parent_path) + + treeview = GTK_TREE_VIEW(GHB_WIDGET(ud->builder, "presets_list")); + store = GTK_TREE_STORE(gtk_tree_view_get_model(treeview)); + + folder_treepath = ghb_tree_path_new_from_index(folder_path); + if (folder_treepath != NULL) { - gtk_tree_model_get_iter(GTK_TREE_MODEL(store), &titer, parent_path); - piter = &titer; - gtk_tree_path_free(parent_path); + GtkTreeIter tmp_iter; + gtk_tree_model_get_iter(GTK_TREE_MODEL(store), &tmp_iter, + folder_treepath); + piter = &tmp_iter; + gtk_tree_path_free(folder_treepath); } else { piter = NULL; } - count = ghb_array_len(presets); - if (indices[len-1] >= count) - return; + // Additional settings, add row - dict = ghb_array_get(presets, indices[len-1]); - preset = preset_get_name(dict); - def = preset_is_default(dict); - - description = ghb_value_get_string(ghb_dict_get(dict, "PresetDescription")); - gtk_tree_store_insert(store, &iter, piter, indices[len-1]); - type = ghb_preset_type(dict); - folder = ghb_preset_folder(dict); - color = get_preset_color(type, folder); - gtk_tree_store_set(store, &iter, 0, preset, + name = ghb_dict_get_string(dict, "PresetName"); + description = ghb_dict_get_string(dict, "PresetDescription"); + type = ghb_dict_get_int(dict, "Type"); + is_folder = ghb_dict_get_bool(dict, "Folder"); + def = ghb_dict_get_bool(dict, "Default"); + color = get_preset_color(type, is_folder); + + gtk_tree_store_append(store, &iter, piter); + gtk_tree_store_set(store, &iter, + 0, name, 1, def ? 800 : 400, - 2, def ? 2 : 0, + 2, def ? 2 : 0, 3, color, 4, description, 5, type == PRESETS_BUILTIN ? 0 : 1, -1); - if (folder) + if (is_folder) { - ghb_presets_list_init(ud, indices, len); + ghb_presets_list_init(ud, path); } } static void -presets_list_remove( - signal_user_data_t *ud, - gint *indices, - gint len) +presets_list_remove(signal_user_data_t *ud, hb_preset_index_t *path) { - GtkTreeView *treeview; - GtkTreePath *treepath; - GtkTreeIter iter; + GtkTreeView *treeview; + GtkTreePath *treepath; + GtkTreeIter iter; GtkTreeStore *store; - g_debug("presets_list_remove ()"); treeview = GTK_TREE_VIEW(GHB_WIDGET(ud->builder, "presets_list")); - store = GTK_TREE_STORE(gtk_tree_view_get_model(treeview)); - treepath = ghb_tree_path_new_from_indices(indices, len); + store = GTK_TREE_STORE(gtk_tree_view_get_model(treeview)); + treepath = ghb_tree_path_new_from_index(path); if (treepath) { if (gtk_tree_model_get_iter(GTK_TREE_MODEL(store), &iter, treepath)) @@ -1842,63 +1283,25 @@ presets_list_remove( } } -static void -remove_std_presets(signal_user_data_t *ud) -{ - gint count, ii; - gint indices = 0; - - count = ghb_array_len(presetsPlist); - for (ii = count-1; ii >= 0; ii--) - { - GhbValue *dict; - gint ptype; - - dict = ghb_array_get(presetsPlist, ii); - ptype = ghb_value_get_int(ghb_dict_get(dict, "Type")); - if (ptype == PRESETS_BUILTIN) - { - if (ghb_presets_remove(presetsPlist, &indices, 1)) - { - presets_list_remove(ud, &indices, 1); - } - } - } -} - void ghb_save_queue(GhbValue *queue) { - pid_t pid; - char *name; + pid_t pid; + char *name; - pid = getpid(); + pid = getpid(); name = g_strdup_printf ("queue.%d", pid); write_config_file(name, queue); g_free(name); } GhbValue* -ghb_load_queue() -{ - GhbValue *queue; - pid_t pid; - char *name; - - pid = getpid(); - name = g_strdup_printf ("queue.%d", pid); - queue = read_config_file(name); - g_free(name); - return queue; -} - -GhbValue* ghb_load_old_queue(int pid) { GhbValue *queue; - char *name; + char *name; - name = g_strdup_printf ("queue.%d", pid); + name = g_strdup_printf ("queue.%d", pid); queue = read_config_file(name); g_free(name); return queue; @@ -1914,963 +1317,157 @@ ghb_remove_old_queue_file(int pid) g_free(name); } -void -ghb_remove_queue_file() -{ - pid_t pid; - char *name; - - pid = getpid(); - name = g_strdup_printf ("queue.%d", pid); - remove_config_file(name); - g_free(name); -} - -typedef struct -{ - const gchar *mac_val; - const gchar *lin_val; -} value_map_t; - -value_map_t deint_xlat[] = -{ - {"0", "off"}, - {"1", "custom"}, - {"2", "fast"}, - {"3", "slow"}, - {"4", "slower"}, - {"5", "bob"}, - {NULL, NULL} -}; - -value_map_t denoise_xlat[] = -{ - {"0", "off"}, - {"1", "custom"}, - {"2", "light"}, - {"3", "medium"}, - {"4", "strong"}, - {"5", "ultralight"}, - {NULL, NULL} -}; - -value_map_t detel_xlat[] = -{ - {"0", "off"}, - {"1", "custom"}, - {"2", "default"}, - {NULL, NULL} -}; - -value_map_t decomb_xlat[] = -{ - {"0", "off"}, - {"1", "custom"}, - {"2", "default"}, - {"3", "fast"}, - {"4", "bob"}, - {NULL, NULL} -}; - -static GhbValue* -export_value_video_framerate(GhbValue *lin_val) -{ - GhbValue *sval = NULL; - gchar *str; - const gchar *fr; - - str = ghb_value_get_string_xform(lin_val); - fr = hb_video_framerate_get_name(hb_video_framerate_get_from_name(str)); - g_free(str); - if (fr != NULL) - sval = ghb_string_value_new(fr); - - return sval; -} - -static GhbValue* -export_value_audio_samplerate(GhbValue *lin_val) -{ - GhbValue *sval = NULL; - gchar *str; - const gchar *sr; - - str = ghb_value_get_string_xform(lin_val); - sr = hb_audio_samplerate_get_name(hb_audio_samplerate_get_from_name(str)); - g_free(str); - if (sr != NULL) - sval = ghb_string_value_new(sr); - - return sval; -} - -static GhbValue* -export_value_mixdown(GhbValue *lin_val) -{ - GhbValue *sval = NULL; - const gchar *str; - const gchar *mix; - - str = ghb_value_get_string(lin_val); - mix = hb_mixdown_get_short_name(hb_mixdown_get_from_name(str)); - if (mix != NULL) - sval = ghb_string_value_new(mix); - - return sval; -} - -static GhbValue* -export_value_video_encoder(GhbValue *lin_val) -{ - GhbValue *sval = NULL; - const gchar *str; - const gchar *enc; - - str = ghb_value_get_string(lin_val); - enc = hb_video_encoder_get_short_name(hb_video_encoder_get_from_name(str)); - if (enc != NULL) - sval = ghb_string_value_new(enc); - - return sval; -} - -static GhbValue* -export_value_audio_encoder(GhbValue *lin_val) -{ - GhbValue *sval = NULL; - const gchar *str; - const gchar *enc; - - str = ghb_value_get_string(lin_val); - enc = hb_audio_encoder_get_short_name(hb_audio_encoder_get_from_name(str)); - if (enc != NULL) - sval = ghb_string_value_new(enc); - - return sval; -} - -static GhbValue* -export_value_container(GhbValue *lin_val) -{ - GhbValue *sval = NULL; - const gchar *str; - const gchar *mux; - - str = ghb_value_get_string(lin_val); - mux = hb_container_get_short_name(hb_container_get_from_name(str)); - if (mux != NULL) - sval = ghb_string_value_new(mux); - - return sval; -} - -// Translate values for compatibility with other platforms -static void -export_value_xlat(GhbValue *dict) -{ - GhbValue *lin_val, *gval; - const gchar *key; - - // Convert PictureModulus to correct data type - key = "PictureModulus"; - lin_val = ghb_dict_get(dict, key); - gval = ghb_value_xform(lin_val, GHB_INT); - if (gval) - ghb_dict_set(dict, key, gval); - key = "VideoEncoder"; - lin_val = ghb_dict_get(dict, key); - gval = export_value_video_encoder(lin_val); - if (gval) - ghb_dict_set(dict, key, gval); - key = "FileFormat"; - lin_val = ghb_dict_get(dict, key); - gval = export_value_container(lin_val); - if (gval) - ghb_dict_set(dict, key, gval); - key = "VideoFramerate"; - lin_val = ghb_dict_get(dict, key); - gval = export_value_video_framerate(lin_val); - if (gval) - ghb_dict_set(dict, key, gval); - - gint count, ii; - GhbValue *alist; - GhbValue *adict; - - key = "AudioEncoderFallback"; - lin_val = ghb_dict_get(dict, key); - gval = export_value_audio_encoder(lin_val); - if (gval) - ghb_dict_set(dict, key, gval); - - alist = ghb_dict_get(dict, "AudioList"); - count = ghb_array_len(alist); - for (ii = 0; ii < count; ii++) - { - adict = ghb_array_get(alist, ii); - key = "AudioEncoder"; - lin_val = ghb_dict_get(adict, key); - gval = export_value_audio_encoder(lin_val); - if (gval) - ghb_dict_set(adict, key, gval); - key = "AudioSamplerate"; - lin_val = ghb_dict_get(adict, key); - gval = export_value_audio_samplerate(lin_val); - if (gval) - ghb_dict_set(adict, key, gval); - key = "AudioMixdown"; - lin_val = ghb_dict_get(adict, key); - gval = export_value_mixdown(lin_val); - if (gval) - ghb_dict_set(adict, key, gval); - } -} - - -static GhbValue* -import_value_xlat2( - GhbValue *defaults, - value_map_t *value_map, - const gchar *key, - GhbValue *mac_val) -{ - GhbValue *gval, *def_val; - - if (mac_val == NULL) return NULL; - def_val = ghb_dict_get(defaults, key); - if (def_val) - { - gint ii; - gchar *str; - GhbValue *sval; - - str = ghb_value_get_string_xform(mac_val); - for (ii = 0; value_map[ii].mac_val; ii++) - { - if (strcmp(str, value_map[ii].mac_val) == 0 || - strcmp(str, value_map[ii].lin_val) == 0) - { - sval = ghb_string_value_new(value_map[ii].lin_val); - g_free(str); - gval = ghb_value_xform(sval, ghb_value_type(def_val)); - if (gval == NULL) - { - g_warning("can't transform"); - ghb_value_free(&sval); - return NULL; - } - ghb_value_free(&sval); - return gval; - } - } - g_free(str); - return ghb_value_dup(def_val); - } - else - { - gint ii; - gchar *str; - GhbValue *sval; - - str = ghb_value_get_string_xform(mac_val); - for (ii = 0; value_map[ii].mac_val; ii++) - { - if (strcmp(str, value_map[ii].mac_val) == 0 || - strcmp(str, value_map[ii].lin_val) == 0) - { - sval = ghb_string_value_new(value_map[ii].lin_val); - g_free(str); - gval = ghb_value_xform(sval, ghb_value_type(mac_val)); - if (gval == NULL) - { - g_warning("can't transform"); - ghb_value_free(&sval); - return NULL; - } - ghb_value_free(&sval); - return gval; - } - } - g_free(str); - } - return NULL; -} - -static GhbValue* -import_value_video_framerate(GhbValue *mac_val) -{ - GhbValue *sval = NULL; - gchar *str; - const gchar *fr; - - str = ghb_value_get_string_xform(mac_val); - fr = hb_video_framerate_get_name(hb_video_framerate_get_from_name(str)); - g_free(str); - - if (fr != NULL) - sval = ghb_string_value_new(fr); - - return sval; -} - -static GhbValue* -import_value_audio_samplerate(GhbValue *mac_val) -{ - GhbValue *sval = NULL; - gchar *str; - const gchar *sr; - - str = ghb_value_get_string_xform(mac_val); - sr = hb_audio_samplerate_get_name(hb_audio_samplerate_get_from_name(str)); - g_free(str); - - if (sr != NULL) - sval = ghb_string_value_new(sr); - - return sval; -} - -static GhbValue* -import_value_mixdown(GhbValue *mac_val) -{ - GhbValue *sval = NULL; - const gchar *str; - const gchar *mix; - - str = ghb_value_get_string(mac_val); - mix = hb_mixdown_get_short_name(hb_mixdown_get_from_name(str)); - - if (mix != NULL) - sval = ghb_string_value_new(mix); - - return sval; -} - -static GhbValue* -import_value_video_encoder(GhbValue *mac_val) -{ - GhbValue *sval = NULL; - const gchar *str; - const gchar *enc; - - str = ghb_value_get_string(mac_val); - enc = hb_video_encoder_get_short_name(hb_video_encoder_get_from_name(str)); - - if (enc != NULL) - sval = ghb_string_value_new(enc); - - return sval; -} - -static GhbValue* -import_value_audio_encoder(GhbValue *mac_val) -{ - GhbValue *sval = NULL; - const gchar *str; - const gchar *enc; - - str = ghb_value_get_string(mac_val); - enc = hb_audio_encoder_get_short_name(hb_audio_encoder_get_from_name(str)); - - if (enc != NULL) - sval = ghb_string_value_new(enc); - - return sval; -} - -static GhbValue* -import_value_container(GhbValue *mac_val) -{ - GhbValue *sval = NULL; - const gchar *str; - const gchar *mux; - - str = ghb_value_get_string(mac_val); - mux = hb_container_get_short_name(hb_container_get_from_name(str)); - - if (mux != NULL) - sval = ghb_string_value_new(mux); - - return sval; -} - -static void -import_value_xlat(GhbValue *dict) -{ - GhbValue *defaults, *mac_val, *gval; - const gchar *key; - - GhbValue *internalPlist = ghb_resource_get("internal-defaults"); - defaults = plist_get_dict(internalPlist, "Presets"); - key = "VideoEncoder"; - mac_val = ghb_dict_get(dict, key); - gval = import_value_video_encoder(mac_val); - if (gval) - ghb_dict_set(dict, key, gval); - key = "FileFormat"; - mac_val = ghb_dict_get(dict, key); - gval = import_value_container(mac_val); - if (gval) - ghb_dict_set(dict, key, gval); - key = "VideoFramerate"; - mac_val = ghb_dict_get(dict, key); - gval = import_value_video_framerate(mac_val); - if (gval) - ghb_dict_set(dict, key, gval); - key = "PictureDetelecine"; - mac_val = ghb_dict_get(dict, key); - gval = import_value_xlat2(defaults, detel_xlat, key, mac_val); - if (gval) - ghb_dict_set(dict, key, gval); - key = "PictureDecomb"; - mac_val = ghb_dict_get(dict, key); - gval = import_value_xlat2(defaults, decomb_xlat, key, mac_val); - if (gval) - ghb_dict_set(dict, key, gval); - key = "PictureDeinterlace"; - mac_val = ghb_dict_get(dict, key); - gval = import_value_xlat2(defaults, deint_xlat, key, mac_val); - if (gval) - ghb_dict_set(dict, key, gval); - key = "PictureDenoisePreset"; - mac_val = ghb_dict_get(dict, key); - gval = import_value_xlat2(defaults, denoise_xlat, key, mac_val); - if (gval) - ghb_dict_set(dict, key, gval); - - ghb_dict_remove(dict, "Subtitles"); - ghb_dict_remove(dict, "SubtitlesForced"); - - gint count, ii; - GhbValue *alist; - GhbValue *adict; - GhbValue *adefaults; - GhbValue *adeflist; - - key = "AudioEncoderFallback"; - mac_val = ghb_dict_get(dict, key); - gval = import_value_audio_encoder(mac_val); - if (gval) - ghb_dict_set(dict, key, gval); - - adeflist = ghb_dict_get(defaults, "AudioList"); - if (adeflist) - { - adefaults = ghb_array_get(adeflist, 0); - alist = ghb_dict_get(dict, "AudioList"); - count = ghb_array_len(alist); - for (ii = 0; ii < count; ii++) - { - adict = ghb_array_get(alist, ii); - key = "AudioEncoder"; - mac_val = ghb_dict_get(adict, key); - gval = import_value_audio_encoder(mac_val); - if (gval == NULL) - gval = ghb_value_dup(ghb_dict_get(adefaults, key)); - if (gval) - ghb_dict_set(adict, key, gval); - key = "AudioSamplerate"; - mac_val = ghb_dict_get(adict, key); - gval = import_value_audio_samplerate(mac_val); - if (gval == NULL) - gval = ghb_value_dup(ghb_dict_get(adefaults, key)); - if (gval) - ghb_dict_set(adict, key, gval); - key = "AudioMixdown"; - mac_val = ghb_dict_get(adict, key); - gval = import_value_mixdown(mac_val); - if (gval == NULL) - gval = ghb_value_dup(ghb_dict_get(adefaults, key)); - if (gval) - ghb_dict_set(adict, key, gval); - - mac_val = ghb_dict_get(adict, "AudioTrackDRCSlider"); - if (mac_val != NULL) - { - gdouble drc; - drc = ghb_value_get_double(mac_val); - if (drc < 1.0) - { - ghb_dict_set(adict, "AudioTrackDRCSlider", - ghb_double_value_new(0.0)); - } - } - } - } -} - +// Translate internal values to preset key, value pairs static GhbValue* -import_xlat_preset(GhbValue *user_preset) +settings_to_preset(GhbValue *settings) { - GhbValue *dict, *internal; - - g_debug("import_xlat_preset ()"); - - dict = ghb_dict_new(); - - // First, initialize the preset with defaults. - // Then import user presets over top of defaults - GhbValue *internalPlist = ghb_resource_get("internal-defaults"); - internal = plist_get_dict(internalPlist, "Presets"); - init_settings_from_dict(dict, internal, user_preset, FALSE); - - // Initialize the AudioLanguageList from preferences PreferredLanguage - // and translate old AudioDUB preference option if found - GhbValue *list = ghb_dict_get(dict, "AudioLanguageList"); - if (list == NULL) - { - list = ghb_array_new(); - ghb_dict_set(dict, "AudioLanguageList", list); - } - if (ghb_array_len(list) == 0) - { - GhbValue *prefs = plist_get_dict(prefsPlist, "Preferences"); - GhbValue *gdub = ghb_dict_get(prefs, "AudioDUB"); - GhbValue *glang = ghb_dict_get(prefs, "PreferredLanguage"); - const char *lang = NULL; - if (glang != NULL) - { - lang = ghb_value_get_string(glang); - } - if (gdub != NULL && !ghb_value_get_bool(gdub)) - { - if (lang == NULL || strncmp(lang, "und", 4)) - { - ghb_array_append(list, ghb_string_value_new("und")); - } - } - if (glang != NULL) - { - ghb_array_append(list, ghb_value_dup(glang)); - } - } - - // Initialize the SubtitleLanguageList from preferences PreferredLanguage - // and translate old AudioDUB preference option if found - list = ghb_dict_get(dict, "SubtitleLanguageList"); - if (list == NULL) - { - list = ghb_array_new(); - ghb_dict_set(dict, "SubtitleLanguageList", list); - } - if (ghb_array_len(list) == 0) - { - GhbValue *prefs = plist_get_dict(prefsPlist, "Preferences"); - GhbValue *val = ghb_dict_get(prefs, "PreferredLanguage"); - if (val != NULL) - { - ghb_array_append(list, ghb_value_dup(val)); - - val = ghb_dict_get(prefs, "AudioDUB"); - if (val != NULL && !ghb_value_get_bool(val)) - { - ghb_dict_set(dict, - "SubtitleAddForeignAudioSubtitle", - ghb_bool_value_new(TRUE)); - } - } - } + GhbValue *preset = ghb_value_dup(settings); - GhbValue *addCC = ghb_dict_get(dict, "SubtitleAddCC"); - if (addCC == NULL) - { - GhbValue *prefs = plist_get_dict(prefsPlist, "Preferences"); - GhbValue *val = ghb_dict_get(prefs, "AddCC"); - if (val != NULL) - { - ghb_dict_set(dict, "SubtitleAddCC", - ghb_value_dup(val)); - } - } - - import_value_xlat(dict); - - // Fix up all the internal settings that are derived from preset values. - ghb_dict_set_bool(dict, "PictureDeinterlaceDecomb", - !ghb_dict_get_bool(dict, "PictureDecombDeinterlace")); - - ghb_dict_set(dict, "scale_height", ghb_value_dup( - ghb_dict_get_value(dict, "PictureHeight"))); - - ghb_dict_set(dict, "scale_width", ghb_value_dup( - ghb_dict_get_value(dict, "PictureWidth"))); - - gint uses_pic; - gint vqtype; - - uses_pic = ghb_dict_get_int(dict, "UsesPictureSettings"); - vqtype = ghb_dict_get_int(dict, "VideoQualityType"); - - // "Use max" or "strict anamorphic" imply autoscale - if (uses_pic == 2) - { - ghb_dict_set_bool(dict, "autoscale", TRUE); - } - else if (uses_pic == 1) - { - ghb_dict_set_bool(dict, "autoscale", FALSE); - } - - // VideoQualityType/0/1/2 - vquality_type_/target/bitrate/constant - // *note: target is no longer used - switch (vqtype) - { - case 0: - { - ghb_dict_set_bool(dict, "vquality_type_bitrate", TRUE); - ghb_dict_set_bool(dict, "vquality_type_constant", FALSE); - } break; - case 1: - { - ghb_dict_set_bool(dict, "vquality_type_bitrate", TRUE); - ghb_dict_set_bool(dict, "vquality_type_constant", FALSE); - } break; - case 2: - { - ghb_dict_set_bool(dict, "vquality_type_bitrate", FALSE); - ghb_dict_set_bool(dict, "vquality_type_constant", TRUE); - } break; - default: - { - ghb_dict_set_bool(dict, "vquality_type_bitrate", FALSE); - ghb_dict_set_bool(dict, "vquality_type_constant", TRUE); - } break; - } - - const gchar *mode = ghb_dict_get_string(dict, "VideoFramerateMode"); - if (strcmp(mode, "cfr") == 0) - { - ghb_dict_set_bool(dict, "VideoFramerateCFR", TRUE); - ghb_dict_set_bool(dict, "VideoFrameratePFR", FALSE); - ghb_dict_set_bool(dict, "VideoFramerateVFR", FALSE); - } - else if (strcmp(mode, "pfr") == 0) - { - ghb_dict_set_bool(dict, "VideoFramerateCFR", FALSE); - ghb_dict_set_bool(dict, "VideoFrameratePFR", TRUE); - ghb_dict_set_bool(dict, "VideoFramerateVFR", FALSE); - } - else - { - ghb_dict_set_bool(dict, "VideoFramerateCFR", FALSE); - ghb_dict_set_bool(dict, "VideoFrameratePFR", FALSE); - ghb_dict_set_bool(dict, "VideoFramerateVFR", TRUE); - } - - if (ghb_dict_get_bool(dict, "x264UseAdvancedOptions")) - { - // Force preset/tune/profile/level/opts to conform to option string - ghb_dict_set_string(dict, "VideoPreset", "medium"); - ghb_dict_set_string(dict, "VideoTune", "none"); - ghb_dict_set_string(dict, "VideoProfile", "auto"); - ghb_dict_set_string(dict, "VideoLevel", "auto"); - ghb_dict_set(dict, "VideoOptionExtra", ghb_value_dup( - ghb_dict_get_value(dict, "x264Option"))); - } - else - { - ghb_dict_remove(dict, "x264Option"); - } - - int encoder = ghb_get_video_encoder(dict); - const char * const *videoPresets; - videoPresets = hb_video_encoder_get_presets(encoder); - const char *videoPreset; - if (ghb_dict_get(user_preset, "x264Preset") != NULL) - videoPreset = ghb_dict_get_string(dict, "x264Preset"); - else - videoPreset = ghb_dict_get_string(dict, "VideoPreset"); - int ii; - for (ii = 0; videoPreset && videoPresets && videoPresets[ii]; ii++) - { - if (!strcasecmp(videoPreset, videoPresets[ii])) - { - ghb_dict_set_int(dict, "VideoPresetSlider", ii); - break; - } - } - if (videoPreset != NULL) - ghb_dict_set_string(dict, "VideoPreset", videoPreset); - - char *videoTune; - if (ghb_dict_get(user_preset, "x264Tune") != NULL) - videoTune = g_strdup(ghb_dict_get_string(dict, "x264Tune")); - else - videoTune = g_strdup(ghb_dict_get_string(dict, "VideoTune")); - char *tune = NULL; - char *saveptr; - char * tok = strtok_r(videoTune, ",./-+", &saveptr); - ghb_dict_set_bool(dict, "x264FastDecode", FALSE); - ghb_dict_set_bool(dict, "x264ZeroLatency", FALSE); - while (tok != NULL) - { - if (!strcasecmp(tok, "fastdecode")) - { - ghb_dict_set_bool(dict, "x264FastDecode", TRUE); - } - else if (!strcasecmp(tok, "zerolatency")) - { - ghb_dict_set_bool(dict, "x264ZeroLatency", TRUE); - } - else if (tune == NULL) - { - tune = g_strdup(tok); - } - else - { - ghb_log("Superfluous tunes! %s", tok); - } - tok = strtok_r(NULL, ",./-+", &saveptr); - } - g_free(videoTune); - if (tune != NULL) - { - ghb_dict_set_string(dict, "VideoTune", tune); - g_free(tune); - } - - const char *videoProfile; - if (ghb_dict_get(user_preset, "x264Profile") != NULL) - videoProfile = ghb_dict_get_string(dict, "x264Profile"); - else - videoProfile = ghb_dict_get_string(dict, "VideoProfile"); - if (videoProfile != NULL) - ghb_dict_set_string(dict, "VideoProfile", videoProfile); - - const char *videoLevel; - if (ghb_dict_get(user_preset, "x264Level") != NULL) - videoLevel = ghb_dict_get_string(dict, "x264Level"); - else - videoLevel = ghb_dict_get_string(dict, "VideoLevel"); - if (videoLevel != NULL) - ghb_dict_set_string(dict, "VideoLevel", videoLevel); + gboolean autoscale, br, constant; - if (ghb_dict_get(user_preset, "x264OptionExtra") != NULL) + ghb_dict_set_bool(preset, "Default", 0); + ghb_dict_set_int(preset, "Type", PRESETS_CUSTOM); + if (!ghb_dict_get_bool(preset, "PictureWidthEnable")) { - const char *optionExtra; - optionExtra = ghb_dict_get_string(dict, "x264OptionExtra"); - ghb_dict_set_string(dict, "VideoOptionExtra", optionExtra); + ghb_dict_remove(preset, "PictureWidth"); } - - return dict; -} - -static void -import_xlat_presets(GhbValue *presets) -{ - gint count, ii; - GhbValue *dict; - gboolean folder; - - g_debug("import_xlat_presets ()"); - if (presets == NULL) return; - count = ghb_array_len(presets); - for (ii = 0; ii < count; ii++) + if (!ghb_dict_get_bool(preset, "PictureHeightEnable")) { - dict = ghb_array_get(presets, ii); - folder = ghb_value_get_bool(ghb_dict_get(dict, "Folder")); - if (folder) - { - GhbValue *nested; - - nested = ghb_dict_get(dict, "ChildrenArray"); - import_xlat_presets(nested); - } - else - { - GhbValue *import_dict = import_xlat_preset(dict); - ghb_array_replace(presets, ii, import_dict); - } + ghb_dict_remove(preset, "PictureHeight"); } -} - -// Translate internal values to preset key, value pairs -static void -export_xlat_preset(GhbValue *dict) -{ - gboolean autoscale, br, constant; - - g_debug("export_xlat_prest ()"); - autoscale = ghb_value_get_bool(ghb_dict_get(dict, "autoscale")); - br = ghb_value_get_bool( - ghb_dict_get(dict, "vquality_type_bitrate")); - constant = ghb_value_get_bool( - ghb_dict_get(dict, "vquality_type_constant")); + autoscale = !ghb_dict_get_bool(preset, "PictureWidthEnable") && + !ghb_dict_get_bool(preset, "PictureHeightEnable"); + br = ghb_dict_get_bool(preset, "vquality_type_bitrate"); + constant = ghb_dict_get_bool(preset, "vquality_type_constant"); if (autoscale) { - ghb_dict_set(dict, "UsesPictureSettings", ghb_int_value_new(2)); + ghb_dict_set_int(preset, "UsesPictureSettings", 2); } else { - ghb_dict_set(dict, "UsesPictureSettings", ghb_int_value_new(1)); + ghb_dict_set_int(preset, "UsesPictureSettings", 1); } // VideoQualityType/0/1/2 - vquality_type_/target/bitrate/constant // *note: target is no longer used if (br) { - ghb_dict_set(dict, "VideoQualityType", ghb_int_value_new(1)); + ghb_dict_set_int(preset, "VideoQualityType", 1); } else if (constant) { - ghb_dict_set(dict, "VideoQualityType", ghb_int_value_new(2)); + ghb_dict_set_int(preset, "VideoQualityType", 2); } - if (ghb_value_get_bool(ghb_dict_get(dict, "VideoFramerateCFR"))) + if (ghb_dict_get_bool(preset, "VideoFramerateCFR")) { - ghb_dict_set(dict, "VideoFramerateMode", ghb_string_value_new("cfr")); + ghb_dict_set_string(preset, "VideoFramerateMode", "cfr"); } - else if (ghb_value_get_bool(ghb_dict_get(dict, "VideoFrameratePFR"))) + else if (ghb_dict_get_bool(preset, "VideoFrameratePFR")) { - ghb_dict_set(dict, "VideoFramerateMode", ghb_string_value_new("pfr")); + ghb_dict_set_string(preset, "VideoFramerateMode", "pfr"); } else { - ghb_dict_set(dict, "VideoFramerateMode", ghb_string_value_new("vfr")); + ghb_dict_set_string(preset, "VideoFramerateMode", "vfr"); } - if (ghb_value_get_int(ghb_dict_get(dict, "PictureDeblock")) < 5) + if (ghb_dict_get_int(preset, "PictureDeblock") < 5) { - ghb_dict_set(dict, "PictureDeblock", ghb_int_value_new(0)); + ghb_dict_set_int(preset, "PictureDeblock", 0); } GhbValue *alist, *adict; gint count, ii; - alist = ghb_dict_get(dict, "AudioList"); + alist = ghb_dict_get(preset, "AudioList"); count = ghb_array_len(alist); for (ii = 0; ii < count; ii++) { gdouble drc; adict = ghb_array_get(alist, ii); - drc = ghb_value_get_double( - ghb_dict_get(adict, "AudioTrackDRCSlider")); + drc = ghb_dict_get_double(adict, "AudioTrackDRCSlider"); if (drc < 1.0) { - ghb_dict_set(adict, "AudioTrackDRCSlider", - ghb_double_value_new(0.0)); + ghb_dict_set_double(adict, "AudioTrackDRCSlider", 0.0); } } GhbValue *copy_mask = ghb_array_new(); - if (ghb_value_get_bool(ghb_dict_get(dict, "AudioAllowMP3Pass"))) + if (ghb_dict_get_bool(preset, "AudioAllowMP3Pass")) { ghb_array_append(copy_mask, ghb_string_value_new("copy:mp3")); } - if (ghb_value_get_bool(ghb_dict_get(dict, "AudioAllowAACPass"))) + if (ghb_dict_get_bool(preset, "AudioAllowAACPass")) { ghb_array_append(copy_mask, ghb_string_value_new("copy:aac")); } - if (ghb_value_get_bool(ghb_dict_get(dict, "AudioAllowAC3Pass"))) + if (ghb_dict_get_bool(preset, "AudioAllowAC3Pass")) { ghb_array_append(copy_mask, ghb_string_value_new("copy:ac3")); } - if (ghb_value_get_bool(ghb_dict_get(dict, "AudioAllowDTSPass"))) + if (ghb_dict_get_bool(preset, "AudioAllowDTSPass")) { ghb_array_append(copy_mask, ghb_string_value_new("copy:dts")); } - if (ghb_value_get_bool(ghb_dict_get(dict, "AudioAllowDTSHDPass"))) + if (ghb_dict_get_bool(preset, "AudioAllowDTSHDPass")) { ghb_array_append(copy_mask, ghb_string_value_new("copy:dtshd")); } - if (ghb_value_get_bool(ghb_dict_get(dict, "AudioAllowEAC3Pass"))) + if (ghb_dict_get_bool(preset, "AudioAllowEAC3Pass")) { ghb_array_append(copy_mask, ghb_string_value_new("copy:eac3")); } - if (ghb_value_get_bool(ghb_dict_get(dict, "AudioAllowFLACPass"))) + if (ghb_dict_get_bool(preset, "AudioAllowFLACPass")) { ghb_array_append(copy_mask, ghb_string_value_new("copy:flac")); } - if (ghb_value_get_bool(ghb_dict_get(dict, "AudioAllowTRUEHDPass"))) + if (ghb_dict_get_bool(preset, "AudioAllowTRUEHDPass")) { ghb_array_append(copy_mask, ghb_string_value_new("copy:truehd")); } - ghb_dict_set(dict, "AudioCopyMask", copy_mask); + ghb_dict_set(preset, "AudioCopyMask", copy_mask); - if (ghb_value_get_bool(ghb_dict_get(dict, "x264UseAdvancedOptions"))) + if (ghb_dict_get_bool(preset, "x264UseAdvancedOptions")) { - ghb_dict_remove(dict, "VideoPreset"); - ghb_dict_remove(dict, "VideoTune"); - ghb_dict_remove(dict, "VideoProfile"); - ghb_dict_remove(dict, "VideoLevel"); - ghb_dict_remove(dict, "VideoOptionExtra"); + ghb_dict_remove(preset, "VideoPreset"); + ghb_dict_remove(preset, "VideoTune"); + ghb_dict_remove(preset, "VideoProfile"); + ghb_dict_remove(preset, "VideoLevel"); + ghb_dict_remove(preset, "VideoOptionExtra"); } - const char *tune = ghb_value_get_string(ghb_dict_get(dict, "VideoTune")); + const char *tune = ghb_dict_get_string(preset, "VideoTune"); if (tune != NULL) { GString *str = g_string_new(""); char *tunes; g_string_append_printf(str, "%s", tune); - if (ghb_value_get_bool(ghb_dict_get(dict, "x264FastDecode"))) + if (ghb_dict_get_bool(preset, "x264FastDecode")) { g_string_append_printf(str, ",%s", "fastdecode"); } - if (ghb_value_get_bool(ghb_dict_get(dict, "x264ZeroLatency"))) + if (ghb_dict_get_bool(preset, "x264ZeroLatency")) { g_string_append_printf(str, ",%s", "zerolatency"); } tunes = g_string_free(str, FALSE); - ghb_dict_set(dict, "VideoTune", ghb_string_value_new(tunes)); + ghb_dict_set_string(preset, "VideoTune", tunes); g_free(tunes); } - // Remove everything from dist that isn't in "Presets" - GhbValue *internal; - GhbValue *internalPlist = ghb_resource_get("internal-defaults"); - internal = plist_get_dict(internalPlist, "Presets"); - dict_clean(dict, internal); - - export_value_xlat(dict); -} - -static void export_xlat_presets(GhbValue *presets); - -static void -export_xlat_dict(GhbValue *dict) -{ - gboolean folder; - folder = ghb_value_get_bool(ghb_dict_get(dict, "Folder")); - if (folder) - { - GhbValue *nested; - - nested = ghb_dict_get(dict, "ChildrenArray"); - export_xlat_presets(nested); - } - else - { - export_xlat_preset(dict); - } -} + GhbValue *in_val, *out_val; -static void -export_xlat_presets(GhbValue *presets) -{ - gint count, ii; - GhbValue *dict; + // Convert PictureModulus to correct data type + in_val = ghb_dict_get(preset, "PictureModulus"); + out_val = ghb_value_xform(in_val, GHB_INT); + if (out_val != NULL) + ghb_dict_set(preset, "PictureModulus", out_val); - if (presets == NULL) return; - if (ghb_value_type(presets) == GHB_DICT) - { - export_xlat_dict(presets); - } - else if (ghb_value_type(presets) == GHB_ARRAY) - { - count = ghb_array_len(presets); - for (ii = 0; ii < count; ii++) - { - dict = ghb_array_get(presets, ii); - export_xlat_dict(dict); - } - } - else - { - g_warning("export_xlat_presets: Invalid presets format"); - } + return preset; } static guint prefs_timeout_id = 0; @@ -2878,7 +1475,7 @@ static guint prefs_timeout_id = 0; static gboolean delayed_store_prefs(gpointer data) { - write_config_file("preferences", prefsPlist); + write_config_file("preferences", prefsDict); prefs_timeout_id = 0; return FALSE; } @@ -2886,12 +1483,15 @@ delayed_store_prefs(gpointer data) static void store_presets() { - GhbValue *export; + gchar *config, *path; + hb_value_t *presets; - export = ghb_value_dup(presetsPlist); - export_xlat_presets(export); - store_plist("presets", export); - ghb_value_free(&export); + config = ghb_get_user_config_dir(NULL); + path = g_strdup_printf ("%s/%s", config, "presets.json"); + presets = hb_presets_get(); + hb_presets_write_json(presets, path); + g_free(config); + g_free(path); } static void @@ -2911,438 +1511,150 @@ store_prefs(void) } void -ghb_presets_reload(signal_user_data_t *ud) -{ - GhbValue *std_presets; - gint count, ii; - int *indices, len; - - g_debug("ghb_presets_reload()\n"); - std_presets = ghb_value_dup(ghb_resource_get("standard-presets")); - if (std_presets == NULL) return; - - remove_std_presets(ud); - indices = presets_find_default(presetsPlist, &len); - if (indices) - { - presets_clear_default(std_presets); - g_free(indices); - } - // Merge the keyfile contents into our presets - count = ghb_array_len(std_presets); - for (ii = count-1; ii >= 0; ii--) - { - GhbValue *std_dict; - GhbValue *copy_dict; - gint indices = 0; - - std_dict = ghb_array_get(std_presets, ii); - copy_dict = ghb_value_dup(std_dict); - ghb_presets_insert(presetsPlist, copy_dict, &indices, 1); - presets_list_insert(ud, &indices, 1); - } - import_xlat_presets(presetsPlist); - store_presets(); - ghb_value_free(&std_presets); -} - -static gboolean -check_old_presets(GhbValue *presetsArray) -{ - gint count, ii; - - count = ghb_array_len(presetsArray); - for (ii = count-1; ii >= 0; ii--) - { - GhbValue *dict; - GhbValue *type; - - dict = ghb_array_get(presetsArray, ii); - type = ghb_dict_get(dict, "Type"); - if (type == NULL) - return TRUE; - } - return FALSE; -} - -static void -replace_standard_presets(GhbValue *presetsArray) +ghb_presets_load(signal_user_data_t *ud) { - GhbValue *std_presets, *tmp; - int *indices, len; - gint count, ii; - - // Remove existing standard presets - count = ghb_array_len(presetsArray); - for (ii = count-1; ii >= 0; ii--) + if (presets_add_config_file("presets.json") < 0) { - GhbValue *dict; - gint ptype; - - dict = ghb_array_get(presetsArray, ii); - ptype = ghb_value_get_int(ghb_dict_get(dict, "Type")); - if (ptype == PRESETS_BUILTIN) + if (presets_add_config_file("presets") < 0) { - gint indices = 0; - ghb_presets_remove(presetsArray, &indices, 1); + g_warning("Failed to read preset file"); } } - - // Get the default standard presets - tmp = ghb_resource_get("standard-presets"); - if (tmp == NULL) return; - std_presets = ghb_value_dup(tmp); - - // Clear the default in the standard presets if one is already set - // in custom presets - indices = presets_find_default(presetsArray, &len); - if (indices) - { - presets_clear_default(std_presets); - g_free(indices); - } - - // Merge the keyfile contents into our presets - count = ghb_array_len(std_presets); - for (ii = count-1; ii >= 0; ii--) - { - GhbValue *std_dict; - GhbValue *copy_dict; - gint indices = 0; - - std_dict = ghb_array_get(std_presets, ii); - copy_dict = ghb_value_dup(std_dict); - ghb_presets_insert(presetsArray, copy_dict, &indices, 1); - } - ghb_value_free(&std_presets); } -static int -update_standard_presets(signal_user_data_t *ud, GhbValue *presetsArray) +static void +settings_save(signal_user_data_t *ud, hb_preset_index_t *path, const char *name) { - gint count, ii; + GhbValue *dict; + gboolean replace = FALSE; - count = ghb_array_len(presetsArray); - for (ii = count-1; ii >= 0; ii--) + dict = hb_preset_get(path); + if (dict != NULL) { - GhbValue *dict; - const GhbValue *gval; - gint type; - - dict = ghb_array_get(presetsArray, ii); - gval = ghb_dict_get(dict, "Type"); - if (gval == NULL) - { - // Old preset that doesn't have a Type - replace_standard_presets(presetsArray); - return 1; - } + gboolean is_folder; + int type; + const char *s; - type = ghb_value_get_int(gval); - if (type == 0) + is_folder = ghb_dict_get_bool(dict, "Folder"); + type = ghb_dict_get_int(dict, "Type"); + s = ghb_dict_get_string(dict, "PresetName"); + if (s == NULL || strcmp(s, name) || type != PRESETS_CUSTOM || is_folder) { - // TODO: check preset version -#if 0 - gint64 build; - - gval = ghb_dict_get(dict, "PresetBuildNumber"); - if (gval == NULL) - { - // Old preset that doesn't have a build number - replace_standard_presets(presetsArray); - return 1; - } - - build = ghb_value_get_int(gval); - if (build != hb_get_build(NULL)) + // Name changed or original preset was builtin or original + // was a folder. Don't replace it. + replace = FALSE; + path->depth--; + if (type != PRESETS_CUSTOM) { - // Build number does not match - replace_standard_presets(presetsArray); - return 1; + // Don't put new custom presets in a builtin folder + path->depth = 1; } -#endif - } - } - return 0; -} - -void -ghb_presets_load(signal_user_data_t *ud) -{ - gboolean store = FALSE; - presetsPlistFile = read_config_file("presets"); - if ((presetsPlistFile == NULL) || - (ghb_value_type(presetsPlistFile) == GHB_DICT) || - (check_old_presets(presetsPlistFile))) - { - presetsPlistFile = ghb_resource_get("standard-presets"); - store = TRUE; - } - else - { - update_standard_presets(ud, presetsPlistFile); - } - presetsPlist = ghb_value_dup(presetsPlistFile); - import_xlat_presets(presetsPlist); - if (store) - store_presets(); - -} - -static void -settings_save(signal_user_data_t *ud, const GhbValue *path) -{ - GhbValue *dict; - gint *indices, len, count; - const gchar *name; - gboolean replace = FALSE; - - g_debug("settings_save"); - GhbValue *internalPlist = ghb_resource_get("internal-defaults"); - if (internalPlist == NULL) return; - count = ghb_array_len(path); - name = ghb_value_get_string(ghb_array_get(path, count-1)); - indices = ghb_preset_indices_from_path(presetsPlist, path, &len); - if (indices) - { - if (ghb_presets_get_folder(presetsPlist, indices, len)) - { - GtkWindow *hb_window; - gchar *message; - hb_window = GTK_WINDOW(GHB_WIDGET(ud->builder, "hb_window")); - message = g_strdup_printf( - _("%s: Folder already exists.\n" - "You can not replace it with a preset."), - name); - ghb_message_dialog(hb_window, GTK_MESSAGE_ERROR, - message, _("Cancel"), NULL); - g_free(message); - return; - } - dict = ghb_value_dup(ud->settings); - ghb_presets_replace(presetsPlist, dict, indices, len); - replace = TRUE; - } - else - { - indices = presets_find_pos(path, PRESETS_CUSTOM, &len); - if (indices) - { - dict = ghb_value_dup(ud->settings); - ghb_presets_insert(presetsPlist, dict, indices, len); } else { - g_warning("failed to find insert path"); - return; + replace = TRUE; } } - current_preset = dict; - ghb_dict_set_int(dict, "Type", PRESETS_CUSTOM); - - ghb_dict_set(dict, "PresetName", ghb_string_value_new(name)); + dict = settings_to_preset(ud->settings); + ghb_dict_set_string(dict, "PresetName", name); if (replace) { - gint *def_indices, def_len; - def_indices = presets_find_default(presetsPlist, &def_len); - if (def_indices != NULL && - preset_path_cmp(indices, len, def_indices, def_len) != 0) + // Already exists, update its description + if (hb_preset_set(path, dict) >= 0) { - ghb_dict_set(dict, "Default", ghb_bool_value_new(FALSE)); + presets_list_update_item(ud, path, FALSE); } - presets_list_update_item(ud, indices, len, FALSE); - g_free(def_indices); } else { - ghb_dict_set(dict, "Default", ghb_bool_value_new(FALSE)); - presets_list_insert(ud, indices, len); - } - if (!ghb_dict_get_bool(ud->settings, "PictureWidthEnable")) - { - ghb_dict_remove(dict, "PictureWidth"); - } - if (!ghb_dict_get_bool(ud->settings, "PictureHeightEnable")) - { - ghb_dict_remove(dict, "PictureHeight"); + // Append to the folder list the source came from + int index = hb_preset_append(path, dict); + if (index >= 0) + { + path->index[path->depth++] = index; + presets_list_append(ud, path); + } } - ghb_dict_set(dict, "autoscale", - ghb_bool_value_new( - !ghb_dict_get_bool(ud->settings, "PictureWidthEnable") && - !ghb_dict_get_bool(ud->settings, "PictureHeightEnable") - ) - ); - + ghb_value_free(&dict); store_presets(); ud->dont_clear_presets = TRUE; // Make the new preset the selected item - ghb_select_preset2(ud->builder, indices, len); - g_free(indices); + select_preset2(ud->builder, path); ud->dont_clear_presets = FALSE; return; } static void -folder_save(signal_user_data_t *ud, const GhbValue *path) +folder_save(signal_user_data_t *ud, hb_preset_index_t *path, const char *name) { - GhbValue *dict, *folder; - gint *indices, len, count; - const gchar *name; - - count = ghb_array_len(path); - name = ghb_value_get_string(ghb_array_get(path, count-1)); - indices = ghb_preset_indices_from_path(presetsPlist, path, &len); - if (indices) + GhbValue *dict; + + dict = hb_preset_get(path); + if (dict != NULL) { - if (!ghb_presets_get_folder(presetsPlist, indices, len)) + gboolean is_folder; + int type; + const char *s; + + is_folder = ghb_dict_get_bool(dict, "Folder"); + type = ghb_dict_get_int(dict, "Type"); + s = ghb_dict_get_string(dict, "PresetName"); + if (s == NULL || strcmp(s, name) || type != PRESETS_CUSTOM || !is_folder) { - GtkWindow *hb_window; - gchar *message; - hb_window = GTK_WINDOW(GHB_WIDGET(ud->builder, "hb_window")); - message = g_strdup_printf( - _("%s: Preset already exists.\n" - "You can not replace it with a folder."), - name); - ghb_message_dialog(hb_window, GTK_MESSAGE_ERROR, - message, _("Cancel"), NULL); - g_free(message); - g_free(indices); - return; + // Name changed or original preset was builtin or original + // was a not a folder. Don't replace it. + dict = NULL; + path->depth--; + if (type != PRESETS_CUSTOM) + { + // Don't put new custom presets in a builtin folder + path->depth = 1; + } } + } + if (dict != NULL) + { // Already exists, update its description - dict = presets_get_dict(presetsPlist, indices, len); + dict = hb_preset_get(path); ghb_dict_set(dict, "PresetDescription", - ghb_value_dup(ghb_dict_get( - ud->settings, "PresetDescription"))); - presets_list_update_item(ud, indices, len, FALSE); - g_free(indices); - store_presets(); - return; + ghb_value_dup(ghb_dict_get(ud->settings, "PresetDescription"))); + presets_list_update_item(ud, path, FALSE); } else { - indices = presets_find_pos(path, PRESETS_CUSTOM, &len); - if (indices) - { - dict = ghb_dict_new(); - ghb_presets_insert(presetsPlist, dict, indices, len); - } - else + dict = ghb_dict_new(); + ghb_dict_set(dict, "PresetDescription", + ghb_value_dup(ghb_dict_get(ud->settings, "PresetDescription"))); + ghb_dict_set_string(dict, "PresetName", name); + ghb_dict_set(dict, "ChildrenArray", ghb_array_new()); + ghb_dict_set_int(dict, "Type", PRESETS_CUSTOM); + ghb_dict_set_bool(dict, "Folder", TRUE); + int index = hb_preset_append(path, dict); + if (index >= 0) { - g_warning("failed to find insert path"); - return; + path->index[path->depth++] = index; + presets_list_append(ud, path); } + ghb_value_free(&dict); } - ghb_dict_set(dict, "PresetDescription", - ghb_value_dup(ghb_dict_get( - ud->settings, "PresetDescription"))); - ghb_dict_set(dict, "PresetName", ghb_string_value_new(name)); - folder = ghb_array_new(); - ghb_dict_set(dict, "ChildrenArray", folder); - ghb_dict_set(dict, "Type", ghb_int_value_new(PRESETS_CUSTOM)); - ghb_dict_set(dict, "Folder", ghb_bool_value_new(TRUE)); - - presets_list_insert(ud, indices, len); - g_free(indices); store_presets(); - return; -} - -void -ghb_presets_list_show_default(signal_user_data_t *ud) -{ - GtkTreeView *treeview; - GtkTreePath *treepath; - GtkTreeIter iter; - GtkTreeStore *store; - gint *indices, len; - - g_debug("ghb_presets_list_show_default()"); - treeview = GTK_TREE_VIEW(GHB_WIDGET(ud->builder, "presets_list")); - store = GTK_TREE_STORE(gtk_tree_view_get_model(treeview)); - indices = presets_find_default(presetsPlist, &len); - if (indices == NULL) return; - treepath = ghb_tree_path_new_from_indices(indices, len); - if (treepath) - { - if (gtk_tree_model_get_iter(GTK_TREE_MODEL(store), &iter, treepath)) - { - gtk_tree_store_set(store, &iter, - 1, 800, - 2, 2 , - -1); - } - gtk_tree_path_free(treepath); - } - g_free(indices); -} - -void -ghb_presets_list_clear_default(signal_user_data_t *ud) -{ - GtkTreeView *treeview; - GtkTreePath *treepath; - GtkTreeIter iter; - GtkTreeStore *store; - gint *indices, len; - - g_debug("ghb_presets_list_clear_default ()"); - treeview = GTK_TREE_VIEW(GHB_WIDGET(ud->builder, "presets_list")); - store = GTK_TREE_STORE(gtk_tree_view_get_model(treeview)); - indices = presets_find_default(presetsPlist, &len); - if (indices == NULL) return; - treepath = ghb_tree_path_new_from_indices(indices, len); - if (treepath) - { - if (gtk_tree_model_get_iter(GTK_TREE_MODEL(store), &iter, treepath)) - { - gtk_tree_store_set(store, &iter, - 1, 400, - 2, 0 , - -1); - } - gtk_tree_path_free(treepath); - } - g_free(indices); -} -static void -update_subtitle_presets(signal_user_data_t *ud) -{ - g_debug("update_subtitle_presets"); - const GhbValue *subtitle_list, *subtitle; - GhbValue *slist, *dict; - gint count, ii, source; - - subtitle_list = ghb_dict_get_value(ud->settings, "subtitle_list"); - slist = ghb_array_new(); - count = ghb_array_len(subtitle_list); - for (ii = 0; ii < count; ii++) - { - subtitle = ghb_array_get(subtitle_list, ii); - source = ghb_dict_get_int(subtitle, "SubtitleSource"); - if (source != SRTSUB) - { - dict = ghb_value_dup(subtitle); - ghb_array_append(slist, dict); - } - } - ghb_dict_set(ud->settings, "SubtitleList", slist); + return; } G_MODULE_EXPORT void preset_import_clicked_cb(GtkWidget *xwidget, signal_user_data_t *ud) { - GtkWidget *dialog; - GtkResponseType response; - const gchar *exportDir; - gchar *filename; - GtkFileFilter *filter; + GtkWindow *hb_window; + GtkWidget *dialog; + GtkResponseType response; + const gchar *exportDir; + gchar *filename; + GtkFileFilter *filter; - g_debug("preset_import_clicked_cb ()"); - - dialog = gtk_file_chooser_dialog_new("Import Preset", NULL, + hb_window = GTK_WINDOW(GHB_WIDGET(ud->builder, "hb_window")); + dialog = gtk_file_chooser_dialog_new("Import Preset", hb_window, GTK_FILE_CHOOSER_ACTION_OPEN, GHB_STOCK_CANCEL, GTK_RESPONSE_CANCEL, GHB_STOCK_OPEN, GTK_RESPONSE_ACCEPT, @@ -3354,11 +1666,16 @@ preset_import_clicked_cb(GtkWidget *xwidget, signal_user_data_t *ud) gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(dialog), filter); filter = gtk_file_filter_new(); - gtk_file_filter_set_name(filter, _("Presets (*.plist)")); - gtk_file_filter_add_pattern(filter, "*.plist"); + gtk_file_filter_set_name(filter, _("Presets (*.json)")); + gtk_file_filter_add_pattern(filter, "*.json"); gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(dialog), filter); gtk_file_chooser_set_filter(GTK_FILE_CHOOSER(dialog), filter); + filter = gtk_file_filter_new(); + gtk_file_filter_set_name(filter, _("Legacy Presets (*.plist)")); + gtk_file_filter_add_pattern(filter, "*.plist"); + gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(dialog), filter); + exportDir = ghb_dict_get_string(ud->prefs, "ExportDirectory"); if (exportDir == NULL || exportDir[0] == '\0') { @@ -3370,62 +1687,18 @@ preset_import_clicked_cb(GtkWidget *xwidget, signal_user_data_t *ud) gtk_widget_hide(dialog); if (response == GTK_RESPONSE_ACCEPT) { - GhbValue *dict, *array; - gchar *dir; - gint count, ii; + gchar *dir; + int index; filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog)); - - // import the preset if (!g_file_test(filename, G_FILE_TEST_IS_REGULAR)) { gtk_widget_destroy(dialog); g_free(filename); return; } - array = ghb_read_settings_file(filename); - - import_xlat_presets(array); - presets_clear_default(array); - presets_customize(array); - - count = ghb_array_len(array); - for (ii = 0; ii < count; ii++) - { - GhbValue *path, *name; - gint *indices, len; - gint index = 1; - - dict = ghb_array_get(array, ii); - path = ghb_array_new(); - name = ghb_value_dup(ghb_dict_get(dict, "PresetName")); - ghb_array_append(path, name); - indices = ghb_preset_indices_from_path(presetsPlist, path, &len); - // Modify the preset name till we make it unique - while (indices != NULL) - { - const gchar *tmp = ghb_value_get_string(name); - - ghb_value_free(&path); - g_free(indices); - - char *str = g_strdup_printf("%s %d", tmp, index); - path = ghb_array_new(); - name = ghb_string_value_new(str); - ghb_array_append(path, name); - g_free(str); - - index++; - indices = ghb_preset_indices_from_path(presetsPlist, path, &len); - } - ghb_dict_set(dict, "PresetName", ghb_value_dup(name)); - indices = presets_find_pos(path, PRESETS_CUSTOM, &len); - ghb_presets_insert(presetsPlist, ghb_value_dup(dict), indices, len); - presets_list_insert(ud, indices, len); - ghb_value_free(&path); - g_free(indices); - } - ghb_value_free(&array); + // import the preset + index = hb_presets_add_path(filename); exportDir = ghb_dict_get_string(ud->prefs, "ExportDirectory"); dir = g_path_get_dirname(filename); @@ -3437,32 +1710,37 @@ preset_import_clicked_cb(GtkWidget *xwidget, signal_user_data_t *ud) g_free(filename); g_free(dir); store_presets(); + + // Re-init the UI preset list + ghb_presets_list_reinit(ud); + if (index < 0) + { + ghb_select_default_preset(ud->builder); + } + else + { + hb_preset_index_t path; + path.index[0] = index; + path.depth = 1; + select_preset2(ud->builder, &path); + } } gtk_widget_destroy(dialog); } -GhbValue* +hb_preset_index_t * get_selected_path(signal_user_data_t *ud) { - GtkTreeView *treeview; + GtkTreeView *treeview; GtkTreeSelection *selection; - GtkTreeModel *store; - GtkTreeIter iter; + GtkTreeModel *store; + GtkTreeIter iter; - treeview = GTK_TREE_VIEW(GHB_WIDGET(ud->builder, "presets_list")); + treeview = GTK_TREE_VIEW(GHB_WIDGET(ud->builder, "presets_list")); selection = gtk_tree_view_get_selection(treeview); if (gtk_tree_selection_get_selected(selection, &store, &iter)) { - GtkTreePath *treepath; - gint *indices, len; - GhbValue *path; - - treepath = gtk_tree_model_get_path(store, &iter); - indices = gtk_tree_path_get_indices(treepath); - len = gtk_tree_path_get_depth(treepath); - - path = preset_path_from_indices(presetsPlist, indices, len); - return path; + return ghb_tree_get_index(store, &iter); } return NULL; } @@ -3470,29 +1748,31 @@ get_selected_path(signal_user_data_t *ud) G_MODULE_EXPORT void preset_export_clicked_cb(GtkWidget *xwidget, signal_user_data_t *ud) { - GtkWidget *dialog; - GtkResponseType response; - GhbValue *preset; - const gchar *name = ""; - gint count, *indices, len; - const gchar *exportDir; - gchar *filename; - - g_debug("preset_export_clicked_cb ()"); - preset = get_selected_path(ud); - if (preset == NULL) - return; + hb_preset_index_t *path; + const gchar *name; + GtkWindow *hb_window; + GtkWidget *dialog; + GtkResponseType response; + const gchar *exportDir; + gchar *filename; - count = ghb_array_len(preset); - if (count <= 0) + path = get_selected_path(ud); + if (path == NULL || path->depth <= 0) { - ghb_value_free(&preset); + free(path); return; } - name = ghb_value_get_string(ghb_array_get(preset, count-1)); + GhbValue *dict = hb_preset_get(path); + free(path); + if (dict == NULL) + { + return; + } + name = ghb_dict_get_string(dict, "PresetName"); - dialog = gtk_file_chooser_dialog_new(_("Export Preset"), NULL, + hb_window = GTK_WINDOW(GHB_WIDGET(ud->builder, "hb_window")); + dialog = gtk_file_chooser_dialog_new(_("Export Preset"), hb_window, GTK_FILE_CHOOSER_ACTION_SAVE, GHB_STOCK_CANCEL, GTK_RESPONSE_CANCEL, GHB_STOCK_SAVE, GTK_RESPONSE_ACCEPT, @@ -3508,30 +1788,16 @@ preset_export_clicked_cb(GtkWidget *xwidget, signal_user_data_t *ud) gtk_file_chooser_set_current_name(GTK_FILE_CHOOSER(dialog), filename); g_free(filename); - indices = ghb_preset_indices_from_path(presetsPlist, preset, &len); - if (indices == NULL) - { - ghb_value_free(&preset); - return; - } - response = gtk_dialog_run(GTK_DIALOG(dialog)); gtk_widget_hide(dialog); if (response == GTK_RESPONSE_ACCEPT) { - GhbValue *export, *dict; - gchar *dir; + gchar *dir; filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog)); // export the preset - dict = presets_get_dict(presetsPlist, indices, len); - - export = ghb_value_dup(dict); - export_xlat_presets(export); - hb_preset_write_json(export, filename); - ghb_value_free(&export); - + hb_presets_write_json(dict, filename); exportDir = ghb_dict_get_string(ud->prefs, "ExportDirectory"); dir = g_path_get_dirname(filename); if (strcmp(dir, exportDir) != 0) @@ -3543,42 +1809,27 @@ preset_export_clicked_cb(GtkWidget *xwidget, signal_user_data_t *ud) g_free(filename); } gtk_widget_destroy(dialog); - g_free(indices); - ghb_value_free(&preset); } G_MODULE_EXPORT void presets_new_folder_clicked_cb(GtkWidget *xwidget, signal_user_data_t *ud) { - GtkWidget *dialog; - GtkEntry *entry; - GtkTextView *desc; - GtkResponseType response; - GhbValue *preset, *dict; - const gchar *name = ""; - const gchar *description = ""; - gint count, *indices, len; - - g_debug("presets_new_folder_clicked_cb ()"); - preset = get_selected_path(ud); - count = ghb_array_len(preset); - if (count > 0) - name = ghb_value_get_string(ghb_array_get(preset, count-1)); - else - count = 1; + GtkWidget *dialog; + GtkEntry *entry; + GtkTextView *desc; + GtkResponseType response; + hb_preset_index_t *path; + const gchar *name; + const gchar *description; - indices = ghb_preset_indices_from_path(presetsPlist, preset, &len); - dict = presets_get_dict(presetsPlist, indices, len); - if (dict != NULL) - { - description = ghb_value_get_string( - ghb_dict_get(dict, "PresetDescription")); - ghb_ui_update(ud, "FolderDescription", ghb_string_value(description)); - } + path = get_selected_path(ud); + name = ghb_dict_get_string(ud->settings, "PresetName"); + description = ghb_dict_get_string(ud->settings, "PresetDescription"); + ghb_ui_update(ud, "FolderDescription", ghb_string_value(description)); - desc = GTK_TEXT_VIEW(GHB_WIDGET(ud->builder, "FolderDescription")); + desc = GTK_TEXT_VIEW(GHB_WIDGET(ud->builder, "FolderDescription")); dialog = GHB_WIDGET(ud->builder, "preset_new_folder_dialog"); - entry = GTK_ENTRY(GHB_WIDGET(ud->builder, "FolderName")); + entry = GTK_ENTRY(GHB_WIDGET(ud->builder, "FolderName")); gtk_entry_set_text(entry, name); response = gtk_dialog_run(GTK_DIALOG(dialog)); gtk_widget_hide(dialog); @@ -3586,60 +1837,37 @@ presets_new_folder_clicked_cb(GtkWidget *xwidget, signal_user_data_t *ud) { // save the preset const gchar *name = gtk_entry_get_text(entry); - GhbValue *dest; - - if (count > MAX_NESTED_PRESET-1) - count = MAX_NESTED_PRESET-1; - - dest = ghb_array_new(); - if (indices != NULL) - { - gint ptype; - - ptype = ghb_presets_get_type(presetsPlist, indices, len); - if (ptype == PRESETS_CUSTOM) - { - ghb_array_copy(dest, preset, count-1); - } - } - ghb_array_append(dest, ghb_string_value_new(name)); - GhbValue *val = ghb_widget_value(GTK_WIDGET(desc)); + GhbValue *val = ghb_widget_value(GTK_WIDGET(desc)); ghb_dict_set(ud->settings, "PresetDescription", ghb_value_dup(val)); - folder_save(ud, dest); - ghb_value_free(&dest); + folder_save(ud, path, name); } - g_free(indices); - ghb_value_free(&preset); + free(path); } G_MODULE_EXPORT void presets_save_clicked_cb(GtkWidget *xwidget, signal_user_data_t *ud) { - GtkWidget *dialog; - GtkEntry *entry; - GtkTextView *desc; - GtkResponseType response; - GhbValue *preset; - const gchar *name = ""; - gint count, *indices, len; - - g_debug("presets_save_clicked_cb ()"); - preset = get_selected_path(ud); - if (preset == NULL) - preset = ghb_value_dup(ghb_dict_get_value(ud->settings, "preset")); - - count = ghb_array_len(preset); - if (count > 0) - name = ghb_value_get_string(ghb_array_get(preset, count-1)); - else - count = 1; + const gchar *name; + const gchar *fullname; + hb_preset_index_t *path; + int width, height; + gboolean autoscale; + GtkWidget *dialog; + GtkEntry *entry; + GtkTextView *desc; + GtkResponseType response; + + name = ghb_dict_get_string(ud->settings, "PresetName"); + fullname = ghb_dict_get_string(ud->settings, "PresetFullName"); + width = ghb_dict_get_int(ud->settings, "PictureWidth"); + height = ghb_dict_get_int(ud->settings, "PictureHeight"); + autoscale = ghb_dict_get_bool(ud->settings, "autoscale"); - desc = GTK_TEXT_VIEW(GHB_WIDGET(ud->builder, "PresetDescription")); - int width = ghb_dict_get_int(ud->settings, "PictureWidth"); - int height = ghb_dict_get_int(ud->settings, "PictureHeight"); - gboolean autoscale = ghb_dict_get_bool(ud->settings, "autoscale"); ghb_ui_update(ud, "PictureWidthEnable", ghb_boolean_value(!autoscale)); ghb_ui_update(ud, "PictureHeightEnable", ghb_boolean_value(!autoscale)); + + path = hb_preset_search_index(fullname, 0); + desc = GTK_TEXT_VIEW(GHB_WIDGET(ud->builder, "PresetDescription")); if (!width) { width = ghb_dict_get_int(ud->settings, "scale_width"); @@ -3650,39 +1878,20 @@ presets_save_clicked_cb(GtkWidget *xwidget, signal_user_data_t *ud) height = ghb_dict_get_int(ud->settings, "scale_height"); ghb_ui_update(ud, "PictureHeight", ghb_int_value(height)); } - dialog = GHB_WIDGET(ud->builder, "preset_save_dialog"); - entry = GTK_ENTRY(GHB_WIDGET(ud->builder, "PresetName")); + + dialog = GHB_WIDGET(ud->builder, "preset_save_dialog"); + entry = GTK_ENTRY(GHB_WIDGET(ud->builder, "PresetName")); gtk_entry_set_text(entry, name); response = gtk_dialog_run(GTK_DIALOG(dialog)); gtk_widget_hide(dialog); if (response == GTK_RESPONSE_OK) { // save the preset - const gchar *name = gtk_entry_get_text(entry); - GhbValue *dest; - - dest = ghb_array_new(); - indices = ghb_preset_indices_from_path(presetsPlist, preset, &len); - if (indices) - { - gint ptype; - - ptype = ghb_presets_get_type(presetsPlist, indices, len); - if (ptype == PRESETS_CUSTOM) - { - ghb_array_copy(dest, preset, count-1); - } - g_free(indices); - } - ghb_array_append(dest, ghb_string_value_new(name)); - + name = gtk_entry_get_text(entry); ghb_widget_to_setting(ud->settings, GTK_WIDGET(desc)); - - update_subtitle_presets(ud); - settings_save(ud, dest); - ghb_value_free(&dest); + settings_save(ud, path, name); } - ghb_value_free(&preset); + free(path); } G_MODULE_EXPORT void @@ -3694,86 +1903,83 @@ preset_type_changed_cb(GtkWidget *widget, signal_user_data_t *ud) G_MODULE_EXPORT void presets_restore_clicked_cb(GtkWidget *xwidget, signal_user_data_t *ud) { - GhbValue *preset; - - g_debug("presets_restore_clicked_cb ()"); - // Reload only the standard presets - ghb_presets_reload(ud); - // Updating the presets list shuffles things around - // need to make sure the proper preset is selected - preset = ghb_dict_get_value(ud->settings, "preset"); - ghb_select_preset(ud->builder, preset); + // Reload the builtin presets + hb_presets_builtin_update(); + store_presets(); + + ghb_presets_list_reinit(ud); + ghb_select_default_preset(ud->builder); } G_MODULE_EXPORT void presets_remove_clicked_cb(GtkWidget *xwidget, signal_user_data_t *ud) { - GtkTreeView *treeview; + GtkTreeView *treeview; GtkTreeSelection *selection; - GtkTreeModel *store; - GtkTreeIter iter; - gchar *preset; - GtkResponseType response; + GtkTreeModel *store; + GtkTreeIter iter; + gchar *preset; + GtkResponseType response; - g_debug("presets_remove_clicked_cb ()"); - treeview = GTK_TREE_VIEW(GHB_WIDGET(ud->builder, "presets_list")); + treeview = GTK_TREE_VIEW(GHB_WIDGET(ud->builder, "presets_list")); selection = gtk_tree_view_get_selection (treeview); if (gtk_tree_selection_get_selected(selection, &store, &iter)) { - GtkWindow *hb_window; - GtkWidget *dialog; - GtkTreePath *path; - gint *indices, len; - gboolean folder; + GtkWindow *hb_window; + GtkWidget *dialog; + gboolean is_folder; + hb_preset_index_t *path; gtk_tree_model_get(store, &iter, 0, &preset, -1); - path = gtk_tree_model_get_path(store, &iter); - indices = gtk_tree_path_get_indices(path); - len = gtk_tree_path_get_depth(path); - folder = ghb_presets_get_folder(presetsPlist, indices, len); + path = ghb_tree_get_index(store, &iter); + is_folder = preset_is_folder(path); hb_window = GTK_WINDOW(GHB_WIDGET(ud->builder, "hb_window")); dialog = gtk_message_dialog_new(hb_window, GTK_DIALOG_MODAL, GTK_MESSAGE_QUESTION, GTK_BUTTONS_YES_NO, _("Confirm deletion of %s:\n\n%s"), - folder ? _("folder") : _("preset"), + is_folder ? _("folder") : _("preset"), preset); response = gtk_dialog_run(GTK_DIALOG(dialog)); gtk_widget_destroy (dialog); if (response == GTK_RESPONSE_YES) { GtkTreeIter nextIter = iter; - gboolean valid = TRUE; + gboolean valid = TRUE; + + // Determine which preset to highlight after deletion done if (!gtk_tree_model_iter_next(store, &nextIter)) { - if (!gtk_tree_model_iter_parent(store, &nextIter, &iter)) + nextIter = iter; + if (!gtk_tree_model_iter_previous(store, &nextIter)) { - valid = FALSE; + nextIter = iter; + if (!gtk_tree_model_iter_parent(store, &nextIter, &iter)) + { + nextIter = iter; + valid = gtk_tree_model_get_iter_first(store, &nextIter); + } } } + // Remove the selected item // First unselect it so that selecting the new item works properly - gtk_tree_selection_unselect_iter (selection, &iter); - if (ghb_presets_remove(presetsPlist, indices, len)) + gtk_tree_selection_unselect_iter(selection, &iter); + if (hb_preset_delete(path) >= 0) { store_presets(); - presets_list_remove(ud, indices, len); + presets_list_remove(ud, path); } - if (!valid) - valid = gtk_tree_model_get_iter_first(store, &nextIter); if (valid) { - GtkTreePath *path; - gint *indices; + hb_preset_index_t *path; - path = gtk_tree_model_get_path(store, &nextIter); - indices = gtk_tree_path_get_indices(path); - len = gtk_tree_path_get_depth(path); - ghb_select_preset2(ud->builder, indices, len); - gtk_tree_path_free(path); + path = ghb_tree_get_index(store, &nextIter); + select_preset2(ud->builder, path); + free(path); } } - gtk_tree_path_free(path); + free(path); g_free(preset); } } @@ -3781,52 +1987,55 @@ presets_remove_clicked_cb(GtkWidget *xwidget, signal_user_data_t *ud) // controls where valid drop locations are G_MODULE_EXPORT gboolean presets_drag_motion_cb( - GtkTreeView *tv, - GdkDragContext *ctx, - gint x, - gint y, - guint time, + GtkTreeView *tv, + GdkDragContext *ctx, + gint x, + gint y, + guint time, signal_user_data_t *ud) { - GtkTreePath *path = NULL; - GtkTreeViewDropPosition drop_pos; - gint *indices, len; - GtkTreeIter iter; - GtkTreeView *srctv; - GtkTreeModel *model; - GtkTreeSelection *select; - gint src_ptype, dst_ptype; - gboolean src_folder, dst_folder; - GhbValue *preset; - gint tree_depth, ii; - GtkWidget *widget; + GtkTreeViewDropPosition drop_pos; + GtkTreeIter iter; + GtkTreeView *srctv; + GtkTreeModel *model; + GtkTreeSelection *select; + GtkTreePath *treepath; + hb_preset_index_t *path; + gint src_ptype, dst_ptype; + gboolean src_folder, dst_folder; + GhbValue *src_preset, *dst_preset; + gint tree_depth, ii; + GtkWidget *widget; widget = gtk_drag_get_source_widget(ctx); if (widget == NULL || widget != GTK_WIDGET(tv)) return TRUE; // Get the type of the object being dragged - srctv = GTK_TREE_VIEW(gtk_drag_get_source_widget(ctx)); - select = gtk_tree_view_get_selection (srctv); + srctv = GTK_TREE_VIEW(gtk_drag_get_source_widget(ctx)); + select = gtk_tree_view_get_selection(srctv); gtk_tree_selection_get_selected (select, &model, &iter); - path = gtk_tree_model_get_path (model, &iter); - indices = gtk_tree_path_get_indices(path); - len = gtk_tree_path_get_depth(path); + path = ghb_tree_get_index(model, &iter); - preset = presets_get_dict(presetsPlist, indices, len); - tree_depth = preset_tree_depth(preset); + src_preset = hb_preset_get(path); + free(path); + if (src_preset == NULL) + { + gdk_drag_status(ctx, 0, time); + return TRUE; + } - src_ptype = ghb_presets_get_type(presetsPlist, indices, len); - src_folder = ghb_presets_get_folder(presetsPlist, indices, len); - gtk_tree_path_free(path); + tree_depth = preset_tree_depth(src_preset); + src_ptype = ghb_dict_get_int(src_preset, "Type"); + src_folder = ghb_dict_get_bool(src_preset, "Folder"); if (src_folder && tree_depth == 1) tree_depth = 2; // The rest checks that the destination is a valid position // in the list. - gtk_tree_view_get_dest_row_at_pos (tv, x, y, &path, &drop_pos); - if (path == NULL) + gtk_tree_view_get_dest_row_at_pos(tv, x, y, &treepath, &drop_pos); + if (treepath == NULL) { gdk_drag_status(ctx, 0, time); return TRUE; @@ -3838,7 +2047,7 @@ presets_drag_motion_cb( return TRUE; } - len = gtk_tree_path_get_depth(path); + int len = gtk_tree_path_get_depth(treepath); if (len+tree_depth-1 >= MAX_NESTED_PRESET) { if (drop_pos == GTK_TREE_VIEW_DROP_INTO_OR_BEFORE) @@ -3847,11 +2056,21 @@ presets_drag_motion_cb( drop_pos = GTK_TREE_VIEW_DROP_AFTER; } for (ii = len+tree_depth-1; ii > MAX_NESTED_PRESET; ii--) - gtk_tree_path_up(path); - indices = gtk_tree_path_get_indices(path); - len = gtk_tree_path_get_depth(path); - dst_ptype = ghb_presets_get_type(presetsPlist, indices, len); - dst_folder = ghb_presets_get_folder(presetsPlist, indices, len); + gtk_tree_path_up(treepath); + path = ghb_tree_path_get_index(treepath); + + dst_preset = hb_preset_get(path); + free(path); + if (dst_preset != NULL) + { + dst_ptype = ghb_dict_get_int(dst_preset, "Type"); + dst_folder = ghb_dict_get_bool(dst_preset, "Folder"); + } + else + { + dst_ptype = PRESETS_CUSTOM; + dst_folder = FALSE; + } // Don't allow mixing custom presets in the builtins if (dst_ptype != PRESETS_CUSTOM) @@ -3869,179 +2088,188 @@ presets_drag_motion_cb( drop_pos = GTK_TREE_VIEW_DROP_AFTER; } - len = gtk_tree_path_get_depth(path); - gtk_tree_view_set_drag_dest_row(tv, path, drop_pos); - gtk_tree_path_free(path); + len = gtk_tree_path_get_depth(treepath); + gtk_tree_view_set_drag_dest_row(tv, treepath, drop_pos); + gtk_tree_path_free(treepath); gdk_drag_status(ctx, GDK_ACTION_MOVE, time); return TRUE; } G_MODULE_EXPORT void presets_drag_cb( - GtkTreeView *dstwidget, - GdkDragContext *dc, - gint x, gint y, - GtkSelectionData *selection_data, - guint info, guint t, + GtkTreeView *dst_widget, + GdkDragContext *dc, + gint x, + gint y, + GtkSelectionData *selection_data, + guint info, + guint t, signal_user_data_t *ud) { - GtkTreePath *path = NULL; - GtkTreeViewDropPosition drop_pos; - GtkTreeIter dstiter, srciter; - gint *dst_indices, dst_len, *src_indices, src_len; - gint src_ptype; - gboolean src_folder, dst_folder; + GtkTreePath *dst_treepath = NULL; + GtkTreeViewDropPosition drop_pos; + GtkTreeIter dst_iter, src_iter; + gint src_ptype; + gboolean src_folder, dst_folder; - GtkTreeModel *dstmodel = gtk_tree_view_get_model(dstwidget); + GtkTreeModel *dst_model = gtk_tree_view_get_model(dst_widget); - g_debug("preset_drag_cb ()"); // This doesn't work here for some reason... // gtk_tree_view_get_drag_dest_row(dstwidget, &path, &drop_pos); - gtk_tree_view_get_dest_row_at_pos (dstwidget, x, y, &path, &drop_pos); + gtk_tree_view_get_dest_row_at_pos(dst_widget, x, y, + &dst_treepath, &drop_pos); // This little hack is needed because attempting to drop after - // the last item gives us no path or drop_pos. - if (path == NULL) + // the last item gives us no dst_treepath or drop_pos. + if (dst_treepath == NULL) { gint n_children; - n_children = gtk_tree_model_iter_n_children(dstmodel, NULL); + n_children = gtk_tree_model_iter_n_children(dst_model, NULL); if (n_children) { drop_pos = GTK_TREE_VIEW_DROP_AFTER; - path = gtk_tree_path_new_from_indices(n_children-1, -1); + dst_treepath = gtk_tree_path_new_from_indices(n_children-1, -1); } else { drop_pos = GTK_TREE_VIEW_DROP_BEFORE; - path = gtk_tree_path_new_from_indices(0, -1); + dst_treepath = gtk_tree_path_new_from_indices(0, -1); } } - if (path) + if (dst_treepath) { - GtkTreeView *srcwidget; - GtkTreeModel *srcmodel; - GtkTreeSelection *select; - GtkTreePath *srcpath = NULL; - GhbValue *preset; - gint tree_depth, ii; - - srcwidget = GTK_TREE_VIEW(gtk_drag_get_source_widget(dc)); - select = gtk_tree_view_get_selection (srcwidget); - gtk_tree_selection_get_selected (select, &srcmodel, &srciter); - - srcpath = gtk_tree_model_get_path (srcmodel, &srciter); - src_indices = gtk_tree_path_get_indices(srcpath); - src_len = gtk_tree_path_get_depth(srcpath); - src_ptype = ghb_presets_get_type(presetsPlist, src_indices, src_len); - src_folder = ghb_presets_get_folder(presetsPlist, src_indices, src_len); - preset = ghb_value_dup( - presets_get_dict(presetsPlist, src_indices, src_len)); - gtk_tree_path_free(srcpath); + GtkTreeView *src_widget; + GtkTreeModel *src_model; + GtkTreeSelection *select; + gint tree_depth, ii; + hb_preset_index_t *dst_path, *src_path; + hb_value_t *src_preset; + + src_widget = GTK_TREE_VIEW(gtk_drag_get_source_widget(dc)); + select = gtk_tree_view_get_selection (src_widget); + gtk_tree_selection_get_selected(select, &src_model, &src_iter); + + src_path = ghb_tree_get_index(src_model, &src_iter); + src_ptype = preset_get_type(src_path); + src_folder = preset_is_folder(src_path); // Don't allow repositioning of builtin presets if (src_ptype != PRESETS_CUSTOM) + { + free(src_path); return; + } - tree_depth = preset_tree_depth(preset); + src_preset = hb_preset_get(src_path); + tree_depth = preset_tree_depth(src_preset); if (src_folder && tree_depth == 1) tree_depth = 2; - dst_len = gtk_tree_path_get_depth(path); - if (dst_len+tree_depth-1 >= MAX_NESTED_PRESET) + dst_path = ghb_tree_path_get_index(dst_treepath); + if (dst_path->depth + tree_depth - 1 >= MAX_NESTED_PRESET) { if (drop_pos == GTK_TREE_VIEW_DROP_INTO_OR_BEFORE) drop_pos = GTK_TREE_VIEW_DROP_BEFORE; - if (drop_pos == GTK_TREE_VIEW_DROP_INTO_OR_AFTER) + else if (drop_pos == GTK_TREE_VIEW_DROP_INTO_OR_AFTER) drop_pos = GTK_TREE_VIEW_DROP_AFTER; } - for (ii = dst_len+tree_depth-1; ii > MAX_NESTED_PRESET; ii--) - gtk_tree_path_up(path); - dst_indices = gtk_tree_path_get_indices(path); - dst_len = gtk_tree_path_get_depth(path); - dst_folder = ghb_presets_get_folder(presetsPlist, dst_indices, dst_len); + for (ii = dst_path->depth + tree_depth-1; ii > MAX_NESTED_PRESET; ii--) + { + gtk_tree_path_up(dst_treepath); + dst_path->depth--; + } + + dst_folder = preset_is_folder(dst_path); // Only allow *drop into* for folders if (!dst_folder) { if (drop_pos == GTK_TREE_VIEW_DROP_INTO_OR_BEFORE) drop_pos = GTK_TREE_VIEW_DROP_BEFORE; - if (drop_pos == GTK_TREE_VIEW_DROP_INTO_OR_AFTER) + else if (drop_pos == GTK_TREE_VIEW_DROP_INTO_OR_AFTER) drop_pos = GTK_TREE_VIEW_DROP_AFTER; } - if (gtk_tree_model_get_iter (dstmodel, &dstiter, path)) + free(dst_path); + if (gtk_tree_model_get_iter(dst_model, &dst_iter, dst_treepath)) { GtkTreeIter iter; - GtkTreePath *dstpath = NULL; + // Insert new empty row in UI preset list + // This logic determines the final position of the preset, + // i.e. before, after or inside the target entry. + // So the dst_path to move the preset to must be computed + // after moving the entry in the UI list switch (drop_pos) { case GTK_TREE_VIEW_DROP_BEFORE: - gtk_tree_store_insert_before(GTK_TREE_STORE (dstmodel), - &iter, NULL, &dstiter); + gtk_tree_store_insert_before(GTK_TREE_STORE(dst_model), + &iter, NULL, &dst_iter); break; case GTK_TREE_VIEW_DROP_INTO_OR_BEFORE: - gtk_tree_store_insert(GTK_TREE_STORE (dstmodel), - &iter, &dstiter, 0); + gtk_tree_store_insert(GTK_TREE_STORE(dst_model), + &iter, &dst_iter, 0); break; case GTK_TREE_VIEW_DROP_AFTER: - gtk_tree_store_insert_after(GTK_TREE_STORE (dstmodel), - &iter, NULL, &dstiter); + gtk_tree_store_insert_after(GTK_TREE_STORE(dst_model), + &iter, NULL, &dst_iter); break; case GTK_TREE_VIEW_DROP_INTO_OR_AFTER: - gtk_tree_store_insert_after(GTK_TREE_STORE (dstmodel), - &iter, &dstiter, 0); + gtk_tree_store_insert_after(GTK_TREE_STORE(dst_model), + &iter, &dst_iter, NULL); break; default: break; } - dstpath = gtk_tree_model_get_path (dstmodel, &iter); - dst_indices = gtk_tree_path_get_indices(dstpath); - dst_len = gtk_tree_path_get_depth(dstpath); - ghb_presets_insert(presetsPlist, preset, dst_indices, dst_len); - gtk_tree_path_free(dstpath); - - srcpath = gtk_tree_model_get_path (srcmodel, &srciter); - src_indices = gtk_tree_path_get_indices(srcpath); - src_len = gtk_tree_path_get_depth(srcpath); - ghb_presets_remove(presetsPlist, src_indices, src_len); - gtk_tree_path_free(srcpath); + // Move source preset at the desired location + dst_path = ghb_tree_get_index(dst_model, &iter); + hb_preset_move(src_path, dst_path); + free(dst_path); - gtk_tree_store_remove (GTK_TREE_STORE (srcmodel), &srciter); + // Remove the old entry in the UI list + gtk_tree_store_remove(GTK_TREE_STORE(src_model), &src_iter); - dstpath = gtk_tree_model_get_path (dstmodel, &iter); - dst_indices = gtk_tree_path_get_indices(dstpath); - dst_len = gtk_tree_path_get_depth(dstpath); - presets_list_update_item(ud, dst_indices, dst_len, TRUE); - gtk_tree_path_free(dstpath); + // UI elements were shuffled again. recompute dst_path + dst_path = ghb_tree_get_index(dst_model, &iter); + presets_list_update_item(ud, dst_path, TRUE); + select_preset2(ud->builder, dst_path); + free(dst_path); store_presets(); } - gtk_tree_path_free(path); + gtk_tree_path_free(dst_treepath); + free(src_path); } } void presets_row_expanded_cb( - GtkTreeView *treeview, - GtkTreeIter *iter, - GtkTreePath *path, + GtkTreeView *treeview, + GtkTreeIter *iter, + GtkTreePath *treepath, signal_user_data_t *ud) { - gint *indices, len; - gboolean expanded, folder; - GhbValue *dict; + hb_preset_index_t *path; + gboolean expanded; + GhbValue *dict; + + expanded = gtk_tree_view_row_expanded(treeview, treepath); + path = ghb_tree_path_get_index(treepath); + dict = hb_preset_get(path); + free(path); - expanded = gtk_tree_view_row_expanded(treeview, path); - indices = gtk_tree_path_get_indices(path); - len = gtk_tree_path_get_depth(path); - dict = presets_get_dict(presetsPlist, indices, len); - if (preset_folder_is_open(dict)) + // Sanity check + if (!ghb_dict_get_bool(dict, "Folder")) + { + g_warning("presets_row_expand_cb: Desync between presets and list"); + return; + } + if (ghb_dict_get_bool(dict, "FolderOpen")) { if (expanded) { @@ -4052,118 +2280,96 @@ presets_row_expanded_cb( { return; } - folder = ghb_presets_get_folder(presetsPlist, indices, len); - if (folder) - { - presets_set_folder_open(expanded, indices, len); - } - - // Collapsing parent folder collapses all children - if (!expanded) - { - GhbValue *presets = NULL; - gint *more_indices, count, ii; + ghb_dict_set_bool(dict, "FolderOpen", expanded); + store_presets(); +} - more_indices = g_malloc((len+1)*sizeof(gint)); - memcpy(more_indices, indices, len*sizeof(gint)); +char* +preset_get_fullname(hb_preset_index_t *path) +{ + int ii; + GString *gstr; + hb_preset_index_t *tmp; + GhbValue *dict; - presets = presets_get_folder(presetsPlist, indices, len); - count = ghb_array_len(presets); - for (ii = 0; ii < count; ii++) + gstr = g_string_new(""); + tmp = hb_preset_index_dup(path); + for (ii = 1; ii <= path->depth; ii++) + { + const char *name; + tmp->depth = ii; + dict = hb_preset_get(tmp); + if (dict == NULL) { - dict = ghb_array_get(presets, ii); - folder = ghb_preset_folder(dict); - if (folder) - { - more_indices[len] = ii; - presets_set_folder_open(expanded, more_indices, len+1); - } + break; + } + name = ghb_dict_get_string(dict, "PresetName"); + if (name != NULL) + { + g_string_append(gstr, "/"); + g_string_append(gstr, name); } - g_free(more_indices); } - store_presets(); + free(tmp); + char *str = g_string_free(gstr, FALSE); + return str; } +// Makes a copy of the preset and assigns "PresetFullName" which +// is use to look up the preset in the preset list should the need +// arrise, e.g. saving changes to the preset. GhbValue* ghb_get_current_preset(signal_user_data_t *ud) { - GtkTreeView *tv; - GtkTreeModel *tm; + GtkTreeView *tv; + GtkTreeModel *tm; GtkTreeSelection *ts; - GtkTreeIter ti; - GhbValue *preset = NULL; + GtkTreeIter ti; + GhbValue *preset = NULL; tv = GTK_TREE_VIEW(GHB_WIDGET(ud->builder, "presets_list")); ts = gtk_tree_view_get_selection(tv); if (gtk_tree_selection_get_selected(ts, &tm, &ti)) { - GtkTreePath *tp; - gint *indices, len; - - tp = gtk_tree_model_get_path(tm, &ti); - indices = gtk_tree_path_get_indices(tp); - len = gtk_tree_path_get_depth(tp); - preset = presets_get_dict(presetsPlist, indices, len); - gtk_tree_path_free(tp); - } - return preset; -} + hb_preset_index_t *path; -GhbValue* -ghb_get_current_preset_path(signal_user_data_t *ud) -{ - GtkTreeView *tv; - GtkTreeModel *tm; - GtkTreeSelection *ts; - GtkTreeIter ti; - GhbValue *path = NULL; + path = ghb_tree_get_index(tm, &ti); + preset = hb_preset_get(path); + if (preset != NULL) + { + char *fullname; - tv = GTK_TREE_VIEW(GHB_WIDGET(ud->builder, "presets_list")); - ts = gtk_tree_view_get_selection(tv); - if (gtk_tree_selection_get_selected(ts, &tm, &ti)) - { - GtkTreePath *tp; - gint *indices, len; - - tp = gtk_tree_model_get_path(tm, &ti); - indices = gtk_tree_path_get_indices(tp); - len = gtk_tree_path_get_depth(tp); - path = preset_path_from_indices(presetsPlist, indices, len); - gtk_tree_path_free(tp); + preset = hb_value_dup(preset); + fullname = preset_get_fullname(path); + ghb_dict_set_string(preset, "PresetFullName", fullname); + free(fullname); + } + free(path); } - return path; + return preset; } G_MODULE_EXPORT void presets_list_selection_changed_cb(GtkTreeSelection *selection, signal_user_data_t *ud) { - GtkTreeModel *store; - GtkTreeIter iter; - GtkWidget *widget; + GtkWidget *widget; + hb_preset_index_t *path; - g_debug("presets_list_selection_changed_cb ()"); widget = GHB_WIDGET (ud->builder, "presets_remove"); - if (gtk_tree_selection_get_selected(selection, &store, &iter)) + path = get_selected_path(ud); + if (path != NULL) { - GtkTreePath *treepath; - gint *indices, len; - gboolean folder; - - treepath = gtk_tree_model_get_path(store, &iter); - indices = gtk_tree_path_get_indices(treepath); - len = gtk_tree_path_get_depth(treepath); - - folder = ghb_presets_get_folder(presetsPlist, indices, len); - if (!folder && !ghb_dict_get_bool(ud->settings, "preset_reload")) + GhbValue *dict = hb_preset_get(path); + if (!ghb_dict_get_bool(dict, "Folder") && + !ghb_dict_get_bool(ud->settings, "preset_reload")) { - ghb_set_preset_settings_from_indices(ud, indices, len); - ghb_dict_set_bool(ud->settings, "preset_modified", FALSE); + ghb_preset_to_settings(ud->settings, dict); + char *fullname = preset_get_fullname(path); + ghb_dict_set_string(ud->settings, "PresetFullName", fullname); + free(fullname); ghb_set_current_title_settings(ud); - ghb_load_settings(ud); + ghb_load_post_settings(ud); } - ghb_dict_set_bool(ud->settings, "preset_reload", FALSE); - - gtk_tree_path_free(treepath); gtk_widget_set_sensitive(widget, TRUE); } else @@ -4176,26 +2382,28 @@ presets_list_selection_changed_cb(GtkTreeSelection *selection, signal_user_data_ void ghb_clear_presets_selection(signal_user_data_t *ud) { - GtkTreeView *treeview; + GtkTreeView *treeview; GtkTreeSelection *selection; if (ud->dont_clear_presets) return; - g_debug("ghb_clear_presets_selection()"); - treeview = GTK_TREE_VIEW(GHB_WIDGET(ud->builder, "presets_list")); + treeview = GTK_TREE_VIEW(GHB_WIDGET(ud->builder, "presets_list")); selection = gtk_tree_view_get_selection (treeview); gtk_tree_selection_unselect_all (selection); ghb_dict_set_bool(ud->settings, "preset_modified", TRUE); } G_MODULE_EXPORT void -presets_frame_size_allocate_cb(GtkWidget *widget, GtkAllocation *allocation, signal_user_data_t *ud) +presets_frame_size_allocate_cb( + GtkWidget *widget, + GtkAllocation *allocation, + signal_user_data_t *ud) { - GtkTreeView *treeview; + GtkTreeView *treeview; GtkTreeSelection *selection; - GtkTreeModel *store; - GtkTreeIter iter; + GtkTreeModel *store; + GtkTreeIter iter; - treeview = GTK_TREE_VIEW(GHB_WIDGET(ud->builder, "presets_list")); + treeview = GTK_TREE_VIEW(GHB_WIDGET(ud->builder, "presets_list")); selection = gtk_tree_view_get_selection(treeview); if (gtk_tree_selection_get_selected(selection, &store, &iter)) { @@ -4210,72 +2418,53 @@ presets_frame_size_allocate_cb(GtkWidget *widget, GtkAllocation *allocation, sig G_MODULE_EXPORT void presets_default_clicked_cb(GtkWidget *xwidget, signal_user_data_t *ud) { - GhbValue *preset; - gint *indices, len; - - g_debug("presets_default_clicked_cb ()"); - preset = get_selected_path(ud); - indices = ghb_preset_indices_from_path(presetsPlist, preset, &len); - if (indices) + hb_preset_index_t *path = get_selected_path(ud); + if (path != NULL) { - if (!ghb_presets_get_folder(presetsPlist, indices, len)) + hb_value_t *dict = hb_preset_get(path); + if (dict != NULL && !ghb_dict_get_bool(dict, "Folder")) { ghb_presets_list_clear_default(ud); - presets_set_default(indices, len); + ghb_dict_set_bool(dict, "Default", 1); ghb_presets_list_show_default(ud); + store_presets(); } - g_free(indices); + g_free(path); } - ghb_value_free(&preset); } G_MODULE_EXPORT void preset_edited_cb( GtkCellRendererText *cell, - gchar *path, - gchar *text, - signal_user_data_t *ud) + gchar *treepath_s, + gchar *text, + signal_user_data_t *ud) { - GtkTreePath *treepath; - GtkTreeStore *store; - GtkTreeView *treeview; - GtkTreeIter iter; - gint *indices, len, count; - GhbValue *dict; - GhbValue *preset, *dest; - - g_debug("preset_edited_cb ()"); - g_debug("path (%s)", path); - g_debug("text (%s)", text); - - preset = get_selected_path(ud); - dest = ghb_array_new(); - count = ghb_array_len(preset); - ghb_array_copy(dest, preset, count-1); - ghb_array_append(dest, ghb_string_value_new(text)); - indices = ghb_preset_indices_from_path(presetsPlist, dest, &len); - ghb_value_free(&dest); - if (indices != NULL) - { - // Already exists - g_free(indices); - ghb_value_free(&preset); - return; - } + GtkTreePath *treepath; + GtkTreeStore *store; + GtkTreeView *treeview; + GtkTreeIter iter; + GhbValue *dict; + hb_preset_index_t *path; treeview = GTK_TREE_VIEW(GHB_WIDGET(ud->builder, "presets_list")); - store = GTK_TREE_STORE(gtk_tree_view_get_model(treeview)); - treepath = gtk_tree_path_new_from_string (path); - indices = gtk_tree_path_get_indices(treepath); - len = gtk_tree_path_get_depth(treepath); - gtk_tree_model_get_iter(GTK_TREE_MODEL(store), &iter, treepath); - gtk_tree_store_set(store, &iter, 0, text, -1); + store = GTK_TREE_STORE(gtk_tree_view_get_model(treeview)); + treepath = gtk_tree_path_new_from_string(treepath_s); + path = ghb_tree_path_get_index(treepath); + if (path != NULL) + { + dict = hb_preset_get(path); + if (dict != NULL) + { + gtk_tree_model_get_iter(GTK_TREE_MODEL(store), &iter, treepath); + gtk_tree_store_set(store, &iter, 0, text, -1); - dict = presets_get_dict(presetsPlist, indices, len); - ghb_dict_set(dict, "PresetName", ghb_string_value_new(text)); - store_presets(); - gtk_tree_path_free (treepath); - ghb_value_free(&preset); + ghb_dict_set_string(dict, "PresetName", text); + store_presets(); + } + } + gtk_tree_path_free(treepath); + free(path); } G_MODULE_EXPORT void diff --git a/gtk/src/presets.h b/gtk/src/presets.h index d9fe4e92f..791900541 100644 --- a/gtk/src/presets.h +++ b/gtk/src/presets.h @@ -16,43 +16,32 @@ #if !defined(_GHB_PRESETS_H_) #define _GHB_PRESETS_H_ +#include "hb.h" #include "values.h" -void ghb_settings_save(signal_user_data_t *ud, const gchar *name); void ghb_presets_load(signal_user_data_t *ud); void ghb_update_from_preset(signal_user_data_t *ud, const gchar *key); void ghb_settings_init(GhbValue *settings, const char *name); void ghb_settings_close(); -void ghb_globals_to_ui(signal_user_data_t *ud); void ghb_prefs_load(signal_user_data_t *ud); -void ghb_prefs_to_ui(signal_user_data_t *ud); -void ghb_prefs_save(GhbValue *settings); void ghb_pref_save(GhbValue *settings, const gchar *key); void ghb_pref_set(GhbValue *settings, const gchar *key); void ghb_prefs_store(void); void ghb_save_queue(GhbValue *queue); -GhbValue* ghb_load_queue(); GhbValue* ghb_load_old_queue(int pid); -void ghb_remove_queue_file(void); void ghb_remove_old_queue_file(int pid); gchar* ghb_get_user_config_dir(gchar *subdir); void ghb_settings_to_ui(signal_user_data_t *ud, GhbValue *dict); void ghb_clear_presets_selection(signal_user_data_t *ud); -void ghb_select_preset(GtkBuilder *builder, const GhbValue *preset); +void ghb_select_preset(GtkBuilder *builder, const char *name); void ghb_select_default_preset(GtkBuilder *builder); -void ghb_presets_list_init(signal_user_data_t *ud, gint *indices, gint len); -GhbValue* ghb_parse_preset_path(const gchar *path); -gchar* ghb_preset_path_string(const GhbValue *path); -gboolean ghb_preset_is_custom(void); -gboolean ghb_lock_file(const gchar *name); +void ghb_presets_list_init(signal_user_data_t *ud, + const hb_preset_index_t *path); int ghb_find_pid_file(); -void ghb_unlink_pid_file(int pid); void ghb_write_pid_file(); GhbValue* ghb_get_current_preset(signal_user_data_t *ud); -GhbValue* ghb_get_current_preset_path(signal_user_data_t *ud); void ghb_preset_to_settings(GhbValue *settings, GhbValue *preset); void ghb_prefs_to_settings(GhbValue *settings); -void dump_preset_path(const gchar *msg, const GhbValue *path); GhbValue* ghb_read_settings_file(const gchar *path); void ghb_write_settings_file(const gchar *path, GhbValue *dict); diff --git a/gtk/src/queuehandler.c b/gtk/src/queuehandler.c index 876d49ec9..64421f8d9 100644 --- a/gtk/src/queuehandler.c +++ b/gtk/src/queuehandler.c @@ -168,10 +168,9 @@ add_to_queue_list(signal_user_data_t *ud, GhbValue *settings, GtkTreeIter *piter // Next line in the display // Preset: PresetName - gchar *preset; + const char *name; gboolean markers; gboolean preset_modified; - const GhbValue *path; const char *mux_id; const hb_container_t *mux; @@ -180,19 +179,17 @@ add_to_queue_list(signal_user_data_t *ud, GhbValue *settings, GtkTreeIter *piter mux = ghb_lookup_container_by_name(mux_id); preset_modified = ghb_dict_get_bool(settings, "preset_modified"); - path = ghb_dict_get_value(settings, "preset"); - preset = ghb_preset_path_string(path); + name = ghb_dict_get_string(settings, "PresetFullName"); markers = ghb_dict_get_bool(settings, "ChapterMarkers"); if (preset_modified) { - XPRINT(_("<b>Modified Preset Based On:</b> <small>%s</small>\n"), preset); + XPRINT(_("<b>Modified Preset Based On:</b> <small>%s</small>\n"), name); } else { - XPRINT(_("<b>Preset:</b> <small>%s</small>\n"), preset); + XPRINT(_("<b>Preset:</b> <small>%s</small>\n"), name); } - g_free(preset); // Next line in the display (Container type) // Format: XXX Container diff --git a/gtk/src/resources.c b/gtk/src/resources.c index 6683f1cd7..122a878d0 100644 --- a/gtk/src/resources.c +++ b/gtk/src/resources.c @@ -44,13 +44,6 @@ ghb_resource_init() ghb_dict_set(resources, "internal-defaults", val); gbytes = g_resource_lookup_data(data_res, - "/org/handbrake/data/standard_presets.json", 0, NULL); - data = g_bytes_get_data(gbytes, &data_size); - val = ghb_json_parse(data); - g_bytes_unref(gbytes); - ghb_dict_set(resources, "standard-presets", val); - - gbytes = g_resource_lookup_data(data_res, "/org/handbrake/data/widget.deps", 0, NULL); data = g_bytes_get_data(gbytes, &data_size); val = ghb_json_parse(data); diff --git a/gtk/src/standard_presets.json b/gtk/src/standard_presets.json deleted file mode 100644 index 41c7be767..000000000 --- a/gtk/src/standard_presets.json +++ /dev/null @@ -1,867 +0,0 @@ -[ - { - "ChildrenArray": [ - { - "AudioAllowAACPass": 1, - "AudioAllowAC3Pass": 1, - "AudioAllowDTSHDPass": 1, - "AudioAllowDTSPass": 1, - "AudioAllowMP3Pass": 1, - "AudioEncoderFallback": "AC3 (ffmpeg)", - "AudioList": [ - { - "AudioBitrate": "160", - "AudioEncoder": "AAC (avcodec)", - "AudioMixdown": "Dolby Pro Logic II", - "AudioSamplerate": "Auto", - "AudioTrack": 1, - "AudioTrackDRCSlider": 0.0, - "AudioTrackGainSlider": 0.0 - }, - { - "AudioBitrate": "160", - "AudioEncoder": "AC3 Passthru", - "AudioMixdown": "None", - "AudioSamplerate": "Auto", - "AudioTrack": 1, - "AudioTrackDRCSlider": 0.0, - "AudioTrackGainSlider": 0.0 - } - ], - "ChapterMarkers": 1, - "Default": 0, - "FileFormat": "MP4 file", - "Folder": false, - "Mp4HttpOptimize": 0, - "Mp4iPodCompatible": 0, - "PictureAutoCrop": 1, - "PictureBottomCrop": 0, - "PictureDeblock": 0, - "PictureDecomb": 0, - "PictureDecombCustom": "", - "PictureDecombDeinterlace": 1, - "PictureDeinterlace": 0, - "PictureDeinterlaceCustom": "", - "PictureDenoiseFilter": "off", - "PictureDenoiseCustom": "", - "PictureDetelecine": 0, - "PictureDetelecineCustom": "", - "PictureHeight": 576, - "PictureKeepRatio": 0, - "PictureLeftCrop": 0, - "PictureModulus": 2, - "PicturePAR": "loose", - "PictureRightCrop": 0, - "PictureTopCrop": 0, - "PictureWidth": 720, - "PresetDescription": "HandBrake's settings for compatibility with all Apple devices (including the iPod 6G and later). Includes Dolby Digital audio for surround sound.", - "PresetName": "Universal", - "Subtitles": "None", - "Type": 0, - "UsesPictureFilters": true, - "UsesPictureSettings": 1, - "VideoAvgBitrate": "2500", - "VideoEncoder": "H.264 (x264)", - "VideoFramerate": "30", - "VideoFramerateMode": "pfr", - "VideoGrayScale": 0, - "VideoQualitySlider": 20.0, - "VideoQualityType": 2, - "VideoTurboTwoPass": 0, - "VideoTwoPass": 0, - "VideoLevel": "3.0", - "VideoProfile": "baseline", - "x264Option": "", - "VideoOptionExtra": "", - "VideoPreset": "fast", - "VideoTune": "", - "x264UseAdvancedOptions": 0 - }, - { - "AudioAllowAACPass": 1, - "AudioAllowAC3Pass": 1, - "AudioAllowDTSHDPass": 1, - "AudioAllowDTSPass": 1, - "AudioAllowMP3Pass": 1, - "AudioEncoderFallback": "AC3 (ffmpeg)", - "AudioList": [ - { - "AudioBitrate": "160", - "AudioEncoder": "AAC (avcodec)", - "AudioMixdown": "Dolby Pro Logic II", - "AudioSamplerate": "Auto", - "AudioTrack": 1, - "AudioTrackDRCSlider": 0.0, - "AudioTrackGainSlider": 0.0 - } - ], - "ChapterMarkers": 1, - "Default": 0, - "FileFormat": "MP4 file", - "Folder": false, - "Mp4HttpOptimize": 0, - "Mp4iPodCompatible": 1, - "PictureAutoCrop": 1, - "PictureBottomCrop": 0, - "PictureDeblock": 0, - "PictureDecomb": 0, - "PictureDecombCustom": "", - "PictureDecombDeinterlace": 1, - "PictureDeinterlace": 0, - "PictureDeinterlaceCustom": "", - "PictureDenoiseFilter": "off", - "PictureDenoiseCustom": "", - "PictureDetelecine": 0, - "PictureDetelecineCustom": "", - "PictureHeight": 240, - "PictureKeepRatio": 1, - "PictureLeftCrop": 0, - "PictureModulus": 2, - "PicturePAR": "off", - "PictureRightCrop": 0, - "PictureTopCrop": 0, - "PictureWidth": 320, - "PresetDescription": "HandBrake's settings for playback on the iPod with Video (all generations).", - "PresetName": "iPod", - "Subtitles": "None", - "Type": 0, - "UsesPictureFilters": true, - "UsesPictureSettings": 1, - "VideoAvgBitrate": "2500", - "VideoEncoder": "H.264 (x264)", - "VideoFramerate": "30", - "VideoFramerateMode": "pfr", - "VideoGrayScale": 0, - "VideoQualitySlider": 22.0, - "VideoQualityType": 2, - "VideoTurboTwoPass": 0, - "VideoTwoPass": 0, - "VideoLevel": "1.3", - "VideoProfile": "baseline", - "x264Option": "", - "VideoOptionExtra": "", - "VideoPreset": "medium", - "VideoTune": "", - "x264UseAdvancedOptions": 0 - }, - { - "AudioAllowAACPass": 1, - "AudioAllowAC3Pass": 1, - "AudioAllowDTSHDPass": 1, - "AudioAllowDTSPass": 1, - "AudioAllowMP3Pass": 1, - "AudioEncoderFallback": "AC3 (ffmpeg)", - "AudioList": [ - { - "AudioBitrate": "160", - "AudioEncoder": "AAC (avcodec)", - "AudioMixdown": "Dolby Pro Logic II", - "AudioSamplerate": "Auto", - "AudioTrack": 1, - "AudioTrackDRCSlider": 0.0, - "AudioTrackGainSlider": 0.0 - } - ], - "ChapterMarkers": 1, - "Default": 0, - "FileFormat": "MP4 file", - "Folder": false, - "Mp4HttpOptimize": 0, - "Mp4iPodCompatible": 0, - "PictureAutoCrop": 1, - "PictureBottomCrop": 0, - "PictureDeblock": 0, - "PictureDecomb": 0, - "PictureDecombCustom": "", - "PictureDecombDeinterlace": 1, - "PictureDeinterlace": 0, - "PictureDeinterlaceCustom": "", - "PictureDenoiseFilter": "off", - "PictureDenoiseCustom": "", - "PictureDetelecine": 0, - "PictureDetelecineCustom": "", - "PictureHeight": 640, - "PictureKeepRatio": 0, - "PictureLeftCrop": 0, - "PictureModulus": 2, - "PicturePAR": "loose", - "PictureRightCrop": 0, - "PictureTopCrop": 0, - "PictureWidth": 960, - "PresetDescription": "HandBrake's settings for handheld iOS devices (iPhone 4, iPod touch 3G and later).", - "PresetName": "iPhone & iPod touch", - "Subtitles": "None", - "Type": 0, - "UsesPictureFilters": true, - "UsesPictureSettings": 1, - "VideoAvgBitrate": "2500", - "VideoEncoder": "H.264 (x264)", - "VideoFramerate": "30", - "VideoFramerateMode": "pfr", - "VideoGrayScale": 0, - "VideoQualitySlider": 22.0, - "VideoQualityType": 2, - "VideoTurboTwoPass": 0, - "VideoTwoPass": 0, - "VideoLevel": "3.1", - "VideoProfile": "high", - "x264Option": "", - "VideoOptionExtra": "", - "VideoPreset": "medium", - "VideoTune": "", - "x264UseAdvancedOptions": 0 - }, - { - "AudioAllowAACPass": 1, - "AudioAllowAC3Pass": 1, - "AudioAllowDTSHDPass": 1, - "AudioAllowDTSPass": 1, - "AudioAllowMP3Pass": 1, - "AudioEncoderFallback": "AC3 (ffmpeg)", - "AudioList": [ - { - "AudioBitrate": "160", - "AudioEncoder": "AAC (avcodec)", - "AudioMixdown": "Dolby Pro Logic II", - "AudioSamplerate": "Auto", - "AudioTrack": 1, - "AudioTrackDRCSlider": 0.0, - "AudioTrackGainSlider": 0.0 - } - ], - "ChapterMarkers": 1, - "Default": 0, - "FileFormat": "MP4 file", - "Folder": false, - "Mp4HttpOptimize": 0, - "Mp4iPodCompatible": 0, - "PictureAutoCrop": 1, - "PictureBottomCrop": 0, - "PictureDeblock": 0, - "PictureDecomb": 0, - "PictureDecombCustom": "", - "PictureDecombDeinterlace": 1, - "PictureDeinterlace": 0, - "PictureDeinterlaceCustom": "", - "PictureDenoiseFilter": "off", - "PictureDenoiseCustom": "", - "PictureDetelecine": 0, - "PictureDetelecineCustom": "", - "PictureHeight": 720, - "PictureKeepRatio": 0, - "PictureLeftCrop": 0, - "PictureModulus": 2, - "PicturePAR": "loose", - "PictureRightCrop": 0, - "PictureTopCrop": 0, - "PictureWidth": 1280, - "PresetDescription": "HandBrake's settings for playback on the iPad (all generations).", - "PresetName": "iPad", - "Subtitles": "None", - "Type": 0, - "UsesPictureFilters": true, - "UsesPictureSettings": 1, - "VideoAvgBitrate": "2500", - "VideoEncoder": "H.264 (x264)", - "VideoFramerate": "30", - "VideoFramerateMode": "pfr", - "VideoGrayScale": 0, - "VideoQualitySlider": 20.0, - "VideoQualityType": 2, - "VideoTurboTwoPass": 0, - "VideoTwoPass": 0, - "VideoLevel": "3.1", - "VideoProfile": "high", - "x264Option": "", - "VideoOptionExtra": "", - "VideoPreset": "medium", - "VideoTune": "", - "x264UseAdvancedOptions": 0 - }, - { - "AudioAllowAACPass": 1, - "AudioAllowAC3Pass": 1, - "AudioAllowDTSHDPass": 1, - "AudioAllowDTSPass": 1, - "AudioAllowMP3Pass": 1, - "AudioEncoderFallback": "AC3 (ffmpeg)", - "AudioList": [ - { - "AudioBitrate": "160", - "AudioEncoder": "AAC (avcodec)", - "AudioMixdown": "Dolby Pro Logic II", - "AudioSamplerate": "Auto", - "AudioTrack": 1, - "AudioTrackDRCSlider": 0.0, - "AudioTrackGainSlider": 0.0 - }, - { - "AudioBitrate": "160", - "AudioEncoder": "AC3 Passthru", - "AudioMixdown": "None", - "AudioSamplerate": "Auto", - "AudioTrack": 1, - "AudioTrackDRCSlider": 0.0, - "AudioTrackGainSlider": 0.0 - } - ], - "ChapterMarkers": 1, - "Default": 0, - "FileFormat": "MP4 file", - "Folder": false, - "Mp4HttpOptimize": 0, - "Mp4iPodCompatible": 0, - "PictureAutoCrop": 1, - "PictureBottomCrop": 0, - "PictureDeblock": 0, - "PictureDecomb": 0, - "PictureDecombCustom": "", - "PictureDecombDeinterlace": 1, - "PictureDeinterlace": 0, - "PictureDeinterlaceCustom": "", - "PictureDenoiseFilter": "off", - "PictureDenoiseCustom": "", - "PictureDetelecine": 0, - "PictureDetelecineCustom": "", - "PictureHeight": 720, - "PictureKeepRatio": 0, - "PictureLeftCrop": 0, - "PictureModulus": 2, - "PicturePAR": "loose", - "PictureRightCrop": 0, - "PictureTopCrop": 0, - "PictureWidth": 960, - "PresetDescription": "HandBrake's settings for the original AppleTV. Includes Dolby Digital audio for surround sound. Also compatible with iOS devices released since 2009.", - "PresetName": "AppleTV", - "Subtitles": "None", - "Type": 0, - "UsesPictureFilters": true, - "UsesPictureSettings": 1, - "VideoAvgBitrate": "2500", - "VideoEncoder": "H.264 (x264)", - "VideoFramerate": "30", - "VideoFramerateMode": "pfr", - "VideoGrayScale": 0, - "VideoQualitySlider": 20.0, - "VideoQualityType": 2, - "VideoTurboTwoPass": 0, - "VideoTwoPass": 0, - "VideoLevel": "3.1", - "VideoProfile": "high", - "x264Option": "", - "VideoOptionExtra": "qpmin=4:cabac=0:ref=2:b-pyramid=none:weightb=0:weightp=0:vbv-maxrate=9500:vbv-bufsize=9500", - "VideoPreset": "medium", - "VideoTune": "", - "x264UseAdvancedOptions": 0 - }, - { - "AudioAllowAACPass": 1, - "AudioAllowAC3Pass": 1, - "AudioAllowDTSHDPass": 1, - "AudioAllowDTSPass": 1, - "AudioAllowMP3Pass": 1, - "AudioEncoderFallback": "AC3 (ffmpeg)", - "AudioList": [ - { - "AudioBitrate": "160", - "AudioEncoder": "AAC (avcodec)", - "AudioMixdown": "Dolby Pro Logic II", - "AudioSamplerate": "Auto", - "AudioTrack": 1, - "AudioTrackDRCSlider": 0.0, - "AudioTrackGainSlider": 0.0 - }, - { - "AudioBitrate": "160", - "AudioEncoder": "AC3 Passthru", - "AudioMixdown": "None", - "AudioSamplerate": "Auto", - "AudioTrack": 1, - "AudioTrackDRCSlider": 0.0, - "AudioTrackGainSlider": 0.0 - } - ], - "ChapterMarkers": 1, - "Default": 0, - "FileFormat": "MP4 file", - "Folder": false, - "Mp4HttpOptimize": 0, - "Mp4iPodCompatible": 0, - "PictureAutoCrop": 1, - "PictureBottomCrop": 0, - "PictureDeblock": 0, - "PictureDecomb": 0, - "PictureDecombCustom": "", - "PictureDecombDeinterlace": 1, - "PictureDeinterlace": 0, - "PictureDeinterlaceCustom": "", - "PictureDenoiseFilter": "off", - "PictureDenoiseCustom": "", - "PictureDetelecine": 0, - "PictureDetelecineCustom": "", - "PictureHeight": 720, - "PictureKeepRatio": 0, - "PictureLeftCrop": 0, - "PictureModulus": 2, - "PicturePAR": "loose", - "PictureRightCrop": 0, - "PictureTopCrop": 0, - "PictureWidth": 1280, - "PresetDescription": "HandBrake's settings for the second-generation AppleTV. Includes Dolby Digital audio for surround sound. NOT compatible with the original AppleTV.", - "PresetName": "AppleTV 2", - "Subtitles": "None", - "Type": 0, - "UsesPictureFilters": true, - "UsesPictureSettings": 1, - "VideoAvgBitrate": "2500", - "VideoEncoder": "H.264 (x264)", - "VideoFramerate": "30", - "VideoFramerateMode": "pfr", - "VideoGrayScale": 0, - "VideoQualitySlider": 20.0, - "VideoQualityType": 2, - "VideoTurboTwoPass": 0, - "VideoTwoPass": 0, - "VideoLevel": "3.1", - "VideoProfile": "high", - "x264Option": "", - "VideoOptionExtra": "", - "VideoPreset": "medium", - "VideoTune": "", - "x264UseAdvancedOptions": 0 - }, - { - "AudioAllowAACPass": 1, - "AudioAllowAC3Pass": 1, - "AudioAllowDTSHDPass": 1, - "AudioAllowDTSPass": 1, - "AudioAllowMP3Pass": 1, - "AudioEncoderFallback": "AC3 (ffmpeg)", - "AudioList": [ - { - "AudioBitrate": "160", - "AudioEncoder": "AAC (avcodec)", - "AudioMixdown": "Dolby Pro Logic II", - "AudioSamplerate": "Auto", - "AudioTrack": 1, - "AudioTrackDRCSlider": 0.0, - "AudioTrackGainSlider": 0.0 - }, - { - "AudioBitrate": "160", - "AudioEncoder": "AC3 Passthru", - "AudioMixdown": "None", - "AudioSamplerate": "Auto", - "AudioTrack": 1, - "AudioTrackDRCSlider": 0.0, - "AudioTrackGainSlider": 0.0 - } - ], - "ChapterMarkers": 1, - "Default": 0, - "FileFormat": "MP4 file", - "Folder": false, - "Mp4HttpOptimize": 0, - "Mp4iPodCompatible": 0, - "PictureAutoCrop": 1, - "PictureBottomCrop": 0, - "PictureDeblock": 0, - "PictureDecomb": 3, - "PictureDecombCustom": "", - "PictureDecombDeinterlace": 1, - "PictureDeinterlace": 0, - "PictureDeinterlaceCustom": "", - "PictureDenoiseFilter": "off", - "PictureDenoiseCustom": "", - "PictureDetelecine": 0, - "PictureDetelecineCustom": "", - "PictureHeight": 1080, - "PictureKeepRatio": 0, - "PictureLeftCrop": 0, - "PictureModulus": 2, - "PicturePAR": "loose", - "PictureRightCrop": 0, - "PictureTopCrop": 0, - "PictureWidth": 1920, - "PresetDescription": "HandBrake's settings for the third-generation AppleTV. Includes Dolby Digital audio for surround sound. NOT compatible with the original AppleTV. May stutter on the second-generation AppleTV.", - "PresetName": "AppleTV 3", - "Subtitles": "None", - "Type": 0, - "UsesPictureFilters": true, - "UsesPictureSettings": 1, - "VideoAvgBitrate": "2500", - "VideoEncoder": "H.264 (x264)", - "VideoFramerate": "30", - "VideoFramerateMode": "pfr", - "VideoGrayScale": 0, - "VideoQualitySlider": 20.0, - "VideoQualityType": 2, - "VideoTurboTwoPass": 0, - "VideoTwoPass": 0, - "VideoLevel": "4.0", - "VideoProfile": "high", - "x264Option": "", - "VideoOptionExtra": "", - "VideoPreset": "medium", - "VideoTune": "", - "x264UseAdvancedOptions": 0 - }, - { - "AudioAllowAACPass": 1, - "AudioAllowAC3Pass": 1, - "AudioAllowDTSHDPass": 1, - "AudioAllowDTSPass": 1, - "AudioAllowMP3Pass": 1, - "AudioEncoderFallback": "AC3 (ffmpeg)", - "AudioList": [ - { - "AudioBitrate": "128", - "AudioEncoder": "AAC (avcodec)", - "AudioMixdown": "Dolby Pro Logic II", - "AudioSamplerate": "Auto", - "AudioTrack": 1, - "AudioTrackDRCSlider": 0.0, - "AudioTrackGainSlider": 0.0 - } - ], - "ChapterMarkers": 0, - "Default": 0, - "FileFormat": "MP4 file", - "Folder": false, - "Mp4HttpOptimize": 0, - "Mp4iPodCompatible": 0, - "PictureAutoCrop": 1, - "PictureBottomCrop": 0, - "PictureDeblock": 0, - "PictureDecomb": 0, - "PictureDecombCustom": "", - "PictureDecombDeinterlace": 1, - "PictureDeinterlace": 0, - "PictureDeinterlaceCustom": "", - "PictureDenoiseFilter": "off", - "PictureDenoiseCustom": "", - "PictureDetelecine": 0, - "PictureDetelecineCustom": "", - "PictureHeight": 576, - "PictureKeepRatio": 0, - "PictureLeftCrop": 0, - "PictureModulus": 2, - "PicturePAR": "loose", - "PictureRightCrop": 0, - "PictureTopCrop": 0, - "PictureWidth": 720, - "PresetDescription": "HandBrake's settings for midrange devices running Android 2.3 or later.", - "PresetName": "Android", - "Subtitles": "None", - "Type": 0, - "UsesPictureFilters": true, - "UsesPictureSettings": 1, - "VideoAvgBitrate": "2500", - "VideoEncoder": "H.264 (x264)", - "VideoFramerate": "30", - "VideoFramerateMode": "pfr", - "VideoGrayScale": 0, - "VideoQualitySlider": 22.0, - "VideoQualityType": 2, - "VideoTurboTwoPass": 0, - "VideoTwoPass": 0, - "VideoLevel": "3.0", - "VideoProfile": "main", - "x264Option": "", - "VideoOptionExtra": "", - "VideoPreset": "medium", - "VideoTune": "", - "x264UseAdvancedOptions": 0 - }, - { - "AudioAllowAACPass": 1, - "AudioAllowAC3Pass": 1, - "AudioAllowDTSHDPass": 1, - "AudioAllowDTSPass": 1, - "AudioAllowMP3Pass": 1, - "AudioEncoderFallback": "AC3 (ffmpeg)", - "AudioList": [ - { - "AudioBitrate": "128", - "AudioEncoder": "AAC (avcodec)", - "AudioMixdown": "Dolby Pro Logic II", - "AudioSamplerate": "Auto", - "AudioTrack": 1, - "AudioTrackDRCSlider": 0.0, - "AudioTrackGainSlider": 0.0 - } - ], - "ChapterMarkers": 0, - "Default": 0, - "FileFormat": "MP4 file", - "Folder": false, - "Mp4HttpOptimize": 0, - "Mp4iPodCompatible": 0, - "PictureAutoCrop": 1, - "PictureBottomCrop": 0, - "PictureDeblock": 0, - "PictureDecomb": 0, - "PictureDecombCustom": "", - "PictureDecombDeinterlace": 1, - "PictureDeinterlace": 0, - "PictureDeinterlaceCustom": "", - "PictureDenoiseFilter": "off", - "PictureDenoiseCustom": "", - "PictureDetelecine": 0, - "PictureDetelecineCustom": "", - "PictureHeight": 720, - "PictureKeepRatio": 0, - "PictureLeftCrop": 0, - "PictureModulus": 2, - "PicturePAR": "loose", - "PictureRightCrop": 0, - "PictureTopCrop": 0, - "PictureWidth": 1280, - "PresetDescription": "HandBrake's preset for tablets running Android 2.3 or later.", - "PresetName": "Android Tablet", - "Subtitles": "None", - "Type": 0, - "UsesPictureFilters": true, - "UsesPictureSettings": 1, - "VideoAvgBitrate": "2500", - "VideoEncoder": "H.264 (x264)", - "VideoFramerate": "30", - "VideoFramerateMode": "pfr", - "VideoGrayScale": 0, - "VideoQualitySlider": 22.0, - "VideoQualityType": 2, - "VideoTurboTwoPass": 0, - "VideoTwoPass": 0, - "VideoLevel": "3.1", - "VideoProfile": "main", - "x264Option": "", - "VideoOptionExtra": "", - "VideoPreset": "medium", - "VideoTune": "", - "x264UseAdvancedOptions": 0 - }, - { - "AudioAllowAACPass": 1, - "AudioAllowAC3Pass": 1, - "AudioAllowDTSHDPass": 1, - "AudioAllowDTSPass": 1, - "AudioAllowMP3Pass": 1, - "AudioEncoderFallback": "AC3 (ffmpeg)", - "AudioList": [ - { - "AudioBitrate": "128", - "AudioEncoder": "AAC (avcodec)", - "AudioMixdown": "Dolby Pro Logic II", - "AudioSamplerate": "Auto", - "AudioTrack": 1, - "AudioTrackDRCSlider": 0.0, - "AudioTrackGainSlider": 0.0 - } - ], - "ChapterMarkers": 0, - "Default": 0, - "FileFormat": "MP4 file", - "Folder": false, - "Mp4HttpOptimize": 0, - "Mp4iPodCompatible": 0, - "PictureAutoCrop": 1, - "PictureBottomCrop": 0, - "PictureDeblock": 0, - "PictureDecomb": 0, - "PictureDecombCustom": "", - "PictureDecombDeinterlace": 1, - "PictureDeinterlace": 0, - "PictureDeinterlaceCustom": "", - "PictureDenoiseFilter": "off", - "PictureDenoiseCustom": "", - "PictureDetelecine": 0, - "PictureDetelecineCustom": "", - "PictureHeight": 720, - "PictureKeepRatio": 1, - "PictureLeftCrop": 0, - "PictureModulus": 2, - "PicturePAR": "off", - "PictureRightCrop": 0, - "PictureTopCrop": 0, - "PictureWidth": 1280, - "PresetDescription": "HandBrake's preset for Windows Phone 8 devices", - "PresetName": "Windows Phone 8", - "Subtitles": "None", - "Type": 0, - "UsesPictureFilters": true, - "UsesPictureSettings": 1, - "VideoAvgBitrate": "2500", - "VideoEncoder": "H.264 (x264)", - "VideoFramerate": "30", - "VideoFramerateMode": "pfr", - "VideoGrayScale": 0, - "VideoQualitySlider": 22.0, - "VideoQualityType": 2, - "VideoTurboTwoPass": 0, - "VideoTwoPass": 0, - "VideoLevel": "3.1", - "VideoProfile": "main", - "x264Option": "", - "VideoOptionExtra": "", - "VideoPreset": "medium", - "VideoTune": "", - "x264UseAdvancedOptions": 0 - } - ], - "Default": 0, - "Folder": true, - "PresetName": "Devices", - "Type": 0 - }, - { - "ChildrenArray": [ - { - "AudioAllowAACPass": 1, - "AudioAllowAC3Pass": 1, - "AudioAllowDTSHDPass": 1, - "AudioAllowDTSPass": 1, - "AudioAllowMP3Pass": 1, - "AudioEncoderFallback": "AC3 (ffmpeg)", - "AudioList": [ - { - "AudioBitrate": "160", - "AudioEncoder": "AAC (avcodec)", - "AudioMixdown": "Dolby Pro Logic II", - "AudioSamplerate": "Auto", - "AudioTrack": 1, - "AudioTrackDRCSlider": 0.0, - "AudioTrackGainSlider": 0.0 - } - ], - "ChapterMarkers": 1, - "Default": 1, - "FileFormat": "MP4 file", - "Folder": false, - "Mp4HttpOptimize": 0, - "Mp4iPodCompatible": 0, - "PictureAutoCrop": 1, - "PictureBottomCrop": 0, - "PictureDeblock": 0, - "PictureDecomb": 0, - "PictureDecombCustom": "", - "PictureDecombDeinterlace": 1, - "PictureDeinterlace": 0, - "PictureDeinterlaceCustom": "", - "PictureDenoiseFilter": "off", - "PictureDenoiseCustom": "", - "PictureDetelecine": 0, - "PictureDetelecineCustom": "", - "PictureHeight": 0, - "PictureKeepRatio": 0, - "PictureLeftCrop": 0, - "PictureModulus": 2, - "PicturePAR": "loose", - "PictureRightCrop": 0, - "PictureTopCrop": 0, - "PictureWidth": 0, - "PresetDescription": "HandBrake's normal, default settings.", - "PresetName": "Normal", - "Subtitles": "None", - "Type": 0, - "UsesPictureFilters": true, - "UsesPictureSettings": 1, - "VideoAvgBitrate": "2500", - "VideoEncoder": "H.264 (x264)", - "VideoFramerate": "Same as source", - "VideoFramerateMode": "vfr", - "VideoGrayScale": 0, - "VideoQualitySlider": 20.0, - "VideoQualityType": 2, - "VideoTurboTwoPass": 0, - "VideoTwoPass": 0, - "VideoLevel": "4.0", - "VideoProfile": "main", - "x264Option": "", - "VideoOptionExtra": "", - "VideoPreset": "veryfast", - "VideoTune": "", - "x264UseAdvancedOptions": 0 - }, - { - "AudioAllowAACPass": 1, - "AudioAllowAC3Pass": 1, - "AudioAllowDTSHDPass": 1, - "AudioAllowDTSPass": 1, - "AudioAllowMP3Pass": 1, - "AudioEncoderFallback": "AC3 (ffmpeg)", - "AudioList": [ - { - "AudioBitrate": "160", - "AudioEncoder": "AAC (avcodec)", - "AudioMixdown": "Dolby Pro Logic II", - "AudioSamplerate": "Auto", - "AudioTrack": 1, - "AudioTrackDRCSlider": 0.0, - "AudioTrackGainSlider": 0.0 - }, - { - "AudioBitrate": "160", - "AudioEncoder": "AC3 Passthru", - "AudioMixdown": "None", - "AudioSamplerate": "Auto", - "AudioTrack": 1, - "AudioTrackDRCSlider": 0.0, - "AudioTrackGainSlider": 0.0 - } - ], - "ChapterMarkers": 1, - "Default": 0, - "FileFormat": "MP4 file", - "Folder": false, - "Mp4HttpOptimize": 0, - "Mp4iPodCompatible": 0, - "PictureAutoCrop": 1, - "PictureBottomCrop": 0, - "PictureDeblock": 0, - "PictureDecomb": 2, - "PictureDecombCustom": "", - "PictureDecombDeinterlace": 1, - "PictureDeinterlace": 0, - "PictureDeinterlaceCustom": "", - "PictureDenoiseFilter": "off", - "PictureDenoiseCustom": "", - "PictureDetelecine": 0, - "PictureDetelecineCustom": "", - "PictureHeight": 0, - "PictureKeepRatio": 0, - "PictureLeftCrop": 0, - "PictureModulus": 2, - "PicturePAR": "loose", - "PictureRightCrop": 0, - "PictureTopCrop": 0, - "PictureWidth": 0, - "PresetDescription": "HandBrake's general-purpose preset for High Profile H.264 video.", - "PresetName": "High Profile", - "Subtitles": "None", - "Type": 0, - "UsesPictureFilters": true, - "UsesPictureSettings": 1, - "VideoAvgBitrate": "2500", - "VideoEncoder": "H.264 (x264)", - "VideoFramerate": "Same as source", - "VideoFramerateMode": "vfr", - "VideoGrayScale": 0, - "VideoQualitySlider": 20.0, - "VideoQualityType": 2, - "VideoTurboTwoPass": 0, - "VideoTwoPass": 0, - "VideoLevel": "4.1", - "VideoProfile": "high", - "x264Option": "", - "VideoOptionExtra": "", - "VideoPreset": "medium", - "VideoTune": "", - "x264UseAdvancedOptions": 0 - } - ], - "Default": 0, - "Folder": true, - "PresetName": "Regular", - "Type": 0 - } -] diff --git a/gtk/src/values.c b/gtk/src/values.c index b413250cc..a1206d9d0 100644 --- a/gtk/src/values.c +++ b/gtk/src/values.c @@ -224,3 +224,32 @@ ghb_dict_get_string_xform(const GhbValue *dict, const gchar *key) return ghb_value_get_string_xform(value); } +void +ghb_dict_copy(GhbValue *dst, const GhbValue *src) +{ + GhbDictIter iter; + const char *key; + GhbValue *val, *dst_val; + + iter = ghb_dict_iter_init(src); + while (ghb_dict_iter_next(src, &iter, &key, &val)) + { + dst_val = ghb_dict_get(dst, key); + if (ghb_value_type(val) == GHB_DICT) + { + if (dst_val == NULL || ghb_value_type(dst_val) != GHB_DICT) + { + dst_val = ghb_value_dup(val); + ghb_dict_set(dst, key, dst_val); + } + else if (ghb_value_type(dst_val) == GHB_DICT) + { + ghb_dict_copy(dst_val, val); + } + } + else + { + ghb_dict_set(dst, key, ghb_value_dup(val)); + } + } +} diff --git a/gtk/src/values.h b/gtk/src/values.h index 87f7010cc..0f62bcc88 100644 --- a/gtk/src/values.h +++ b/gtk/src/values.h @@ -84,6 +84,8 @@ GhbValue* ghb_boolean_value(gboolean bval); void debug_show_value(GhbValue *gval); void debug_show_type(GhbType tp); +void ghb_dict_copy(GhbValue *dst, const GhbValue *src); + void ghb_dict_set_string(GhbValue *dict, const gchar *key, const gchar *sval); void ghb_dict_set_double(GhbValue *dict, const gchar *key, gdouble dval); void ghb_dict_set_int(GhbValue *dict, const gchar *key, gint64 ival); |