From 96dfcf66c13723485b0df00f0d17035a2c3b9c68 Mon Sep 17 00:00:00 2001 From: John Stebbins Date: Fri, 22 Dec 2017 14:04:15 -0800 Subject: [PATCH] LinGui: add preset options inline menu --- gtk/src/ghb.m4 | 256 ++++++++++++++++++++++++++++++++++++++++++---- gtk/src/main.c | 3 + gtk/src/presets.c | 82 ++++++++++++++- 3 files changed, 317 insertions(+), 24 deletions(-) diff --git a/gtk/src/ghb.m4 b/gtk/src/ghb.m4 index d6cdd99db..7b8c3c74d 100644 --- a/gtk/src/ghb.m4 +++ b/gtk/src/ghb.m4 @@ -8,6 +8,48 @@ filter_output([ + +
+ + Set De_fault + app.preset-default + +
+
+ + _Save + app.preset-save + + + Save _As + app.preset-save-as + + + _Rename + app.preset-rename + + + _Delete + app.preset-remove + +
+
+ + _Import + app.preset-import + + + _Export + app.preset-export + +
+
+ + Reset _Built-in Presets + app.presets-reload + +
+
@@ -137,6 +179,15 @@ conjunction with the "Forced" option. app.preset-save-as + + + _Rename + True + False + True + app.preset-rename + + _Delete @@ -148,7 +199,7 @@ conjunction with the "Forced" option. - _Make Default + Set De_fault True False True @@ -156,26 +207,26 @@ conjunction with the "Forced" option. - - _Export + + _Import True False True - app.preset-export + app.preset-import - - _Import + + _Export True False True - app.preset-import + app.preset-export - _Reload Built-in Presets + Reset _Built-in Presets True False True @@ -949,6 +1000,15 @@ libx264 authors: app.preset-save-as + + + _Rename + True + False + True + app.preset-rename + + _Delete @@ -960,7 +1020,7 @@ libx264 authors: - _Make Default + Set De_fault True False True @@ -968,26 +1028,26 @@ libx264 authors: - - _Export + + _Import True False True - app.preset-export + app.preset-import - - _Import + + _Export True False True - app.preset-import + app.preset-export - _Reload Built-in Presets + Reset _Built-in Presets True False True @@ -1578,7 +1638,7 @@ This is often the feature title of a DVD. - True + False False 10 @@ -1594,7 +1654,7 @@ This is often the feature title of a DVD. Reload - True + False True Reload the encoding settings for the currently selected preset. Modifications will be discarded. @@ -1611,7 +1671,7 @@ This is often the feature title of a DVD. Save New Preset - True + False True Reload the encoding settings for the currently selected preset. Modifications will be discarded. @@ -1625,6 +1685,52 @@ This is often the feature title of a DVD. 4 + + + True + False + down + presets-mm + + + horizontal + True + False + + + True + False + 0 + Options + True + + + False + True + 0 + + + + + True + False + pan-down-symbolic + + + False + True + 1 + + + + + + + False + True + 5 + + 2 @@ -8405,6 +8511,118 @@ Uncheck this if you want to allow changing each title's settings independently.< preset_folder_ok + + hb_window + False + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + 5 + True + center-on-parent + dialog + + + + True + False + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + 2 + + + True + False + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + end + + + Cancel + gtk-cancel + True + True + True + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + + + False + False + 0 + + + + + OK + gtk-ok + True + True + True + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + + + False + False + 1 + + + + + False + True + end + 0 + + + + + horizontal + True + False + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + + + True + False + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + end + Preset Name: + + + False + True + 0 + + + + + True + True + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + 40 + True + 30 + True + False + False + + + + True + True + 1 + + + + + True + True + 1 + + + + + + preset_rename_cancel + preset_rename_ok + + hb_window False diff --git a/gtk/src/main.c b/gtk/src/main.c index 592a98029..f347af03d 100644 --- a/gtk/src/main.c +++ b/gtk/src/main.c @@ -865,6 +865,8 @@ preset_save_action_cb(GSimpleAction *action, GVariant *param, gpointer ud); G_MODULE_EXPORT void preset_save_as_action_cb(GSimpleAction *action, GVariant *param, gpointer ud); G_MODULE_EXPORT void +preset_rename_action_cb(GSimpleAction *action, GVariant *param, gpointer ud); +G_MODULE_EXPORT void preset_remove_action_cb(GSimpleAction *action, GVariant *param, gpointer ud); G_MODULE_EXPORT void preset_default_action_cb(GSimpleAction *action, GVariant *param, gpointer ud); @@ -909,6 +911,7 @@ static void map_actions(GApplication * app, signal_user_data_t * ud) NULL, "false", show_activity_action_cb }, { "preset-save", preset_save_action_cb }, { "preset-save-as", preset_save_as_action_cb }, + { "preset-rename", preset_rename_action_cb }, { "preset-remove", preset_remove_action_cb }, { "preset-default", preset_default_action_cb }, { "preset-export", preset_export_action_cb }, diff --git a/gtk/src/presets.c b/gtk/src/presets.c index 565de81e8..8da10ce5d 100644 --- a/gtk/src/presets.c +++ b/gtk/src/presets.c @@ -542,7 +542,8 @@ set_preset_menu_button_label(signal_user_data_t *ud, hb_preset_index_t *path) type = ghb_dict_get_int(dict, "Type"); fullname = preset_get_fullname(path, " > "); label = GTK_LABEL(GHB_WIDGET(ud->builder, "presets_menu_button_label")); - text = g_strdup_printf("%s%s", type ? "Custom" : "Official", fullname); + text = g_strdup_printf("%s%s", type == HB_PRESET_TYPE_CUSTOM ? + "Custom" : "Official", fullname); gtk_label_set_markup(label, text); free(fullname); free(text); @@ -585,6 +586,16 @@ select_preset2(signal_user_data_t *ud, hb_preset_index_t *path) gtk_tree_path_free(treepath); } set_preset_menu_button_label(ud, path); + + int type = preset_get_type(path); + GSimpleAction * action; + + action = G_SIMPLE_ACTION(g_action_map_lookup_action( + G_ACTION_MAP(ud->app), "preset-rename")); + g_simple_action_set_enabled(action, type == HB_PRESET_TYPE_CUSTOM); + action = G_SIMPLE_ACTION(g_action_map_lookup_action( + G_ACTION_MAP(ud->app), "preset-save")); + g_simple_action_set_enabled(action, type == HB_PRESET_TYPE_CUSTOM); } void @@ -1189,7 +1200,7 @@ ghb_presets_menu_init(signal_user_data_t *ud) continue; } - if (type == 0) + if (type == HB_PRESET_TYPE_OFFICIAL) { // Add folder name to list of official names official_names[kk++] = g_strdup(folder_name); @@ -1236,7 +1247,7 @@ ghb_presets_menu_init(signal_user_data_t *ud) free(preset_path); free(detail_action); } - if (type == 1 && + if (type == HB_PRESET_TYPE_CUSTOM && ghb_strv_contains((const char**)official_names, folder_name)) { menu_item_name = g_strdup_printf("My %s", folder_name); @@ -1251,7 +1262,9 @@ ghb_presets_menu_init(signal_user_data_t *ud) } g_string_free(folder_str, TRUE); } - g_menu_append_section(menu, type ? "Custom" : "Official", + g_menu_append_section(menu, + type == HB_PRESET_TYPE_CUSTOM ? + "Custom" : "Official", G_MENU_MODEL(section)); } g_free(path); @@ -2066,6 +2079,56 @@ preset_export_action_cb(GSimpleAction *action, GVariant *param, hb_value_free(&dict); } +G_MODULE_EXPORT void +preset_rename_action_cb(GSimpleAction *action, GVariant *param, + signal_user_data_t *ud) +{ + const gchar * name; + const gchar * fullname; + int type; + hb_preset_index_t * path; + GtkWidget * dialog; + GtkEntry * entry; + GhbValue * dict; + GtkResponseType response; + + name = ghb_dict_get_string(ud->settings, "PresetName"); + type = ghb_dict_get_int(ud->settings, "Type"); + fullname = ghb_dict_get_string(ud->settings, "PresetFullName"); + + if (type != HB_PRESET_TYPE_CUSTOM) + { + // Only allow renaming custom presets + return; + } + path = hb_preset_search_index(fullname, 0, type); + + dialog = GHB_WIDGET(ud->builder, "preset_rename_dialog"); + entry = GTK_ENTRY(GHB_WIDGET(ud->builder, "PresetReName")); + gtk_entry_set_text(entry, name); + + response = gtk_dialog_run(GTK_DIALOG(dialog)); + gtk_widget_hide(dialog); + if (response == GTK_RESPONSE_OK) + { + // save the new name + name = gtk_entry_get_text(entry); + dict = hb_preset_get(path); + if (dict != NULL) + { + ghb_dict_set_string(dict, "PresetName", name); + store_presets(); + } + + char * full = preset_get_fullname(path, "/"); + ghb_dict_set_string(ud->settings, "PresetFullName", full); + ghb_dict_set_string(ud->settings, "PresetName", name); + free(full); + ghb_presets_menu_reinit(ud); + set_preset_menu_button_label(ud, path); + } +} + static void preset_save_action(signal_user_data_t *ud, gboolean as) { const char * category = NULL; @@ -2121,7 +2184,7 @@ static void preset_save_action(signal_user_data_t *ud, gboolean as) { continue; } - if (ghb_dict_get_int(dict, "Type") == 1) + if (ghb_dict_get_int(dict, "Type") == HB_PRESET_TYPE_CUSTOM) { category = ghb_dict_get_string(dict, "PresetName"); break; @@ -2737,6 +2800,15 @@ presets_list_selection_changed_cb(GtkTreeSelection *selection, signal_user_data_ widget = GHB_WIDGET(ud->builder, "preset_save_new"); gtk_widget_set_visible(widget, FALSE); } + int type = preset_get_type(path); + GSimpleAction * action; + + action = G_SIMPLE_ACTION(g_action_map_lookup_action( + G_ACTION_MAP(ud->app), "preset-rename")); + g_simple_action_set_enabled(action, type == HB_PRESET_TYPE_CUSTOM); + action = G_SIMPLE_ACTION(g_action_map_lookup_action( + G_ACTION_MAP(ud->app), "preset-save")); + g_simple_action_set_enabled(action, type == HB_PRESET_TYPE_CUSTOM); free(path); } } -- 2.40.0