| 2050 | } |
| 2051 | |
| 2052 | static void |
| 2053 | settings_save(signal_user_data_t *ud, const char * category, |
| 2054 | const char *name, const char * desc, gboolean set_def) |
| 2055 | { |
| 2056 | GhbValue * preset, * new_preset; |
| 2057 | hb_preset_index_t * folder_path, * path; |
| 2058 | char * fullname; |
| 2059 | |
| 2060 | folder_path = preset_get_folder(ud, category, HB_PRESET_TYPE_CUSTOM); |
| 2061 | if (!folder_path) return; |
| 2062 | |
| 2063 | new_preset = ghb_settings_to_preset(ud->settings); |
| 2064 | ghb_dict_set_int(new_preset, "Type", HB_PRESET_TYPE_CUSTOM); |
| 2065 | ghb_dict_set_string(new_preset, "PresetName", name); |
| 2066 | if (desc != NULL) |
| 2067 | ghb_dict_set_string(new_preset, "PresetDescription", desc); |
| 2068 | |
| 2069 | fullname = g_strdup_printf("/%s/%s", category, name); |
| 2070 | path = hb_preset_search_index(fullname, 0, HB_PRESET_TYPE_CUSTOM); |
| 2071 | preset = hb_preset_get(path); |
| 2072 | if (preset != NULL) |
| 2073 | { |
| 2074 | // Replacing an existing preset |
| 2075 | gboolean def = ghb_dict_get_bool(preset, "Default"); |
| 2076 | |
| 2077 | // If we are replacing the default preset, re-mark it as default |
| 2078 | ghb_dict_set_bool(new_preset, "Default", def); |
| 2079 | // Already exists, update its description |
| 2080 | if (hb_preset_set(path, new_preset) >= 0) |
| 2081 | { |
| 2082 | presets_list_update_item(ud, path, FALSE); |
| 2083 | } |
| 2084 | } |
| 2085 | else |
| 2086 | { |
| 2087 | // Check if the new preset is also the new default preset |
| 2088 | if (set_def) |
| 2089 | { |
| 2090 | ghb_dict_set_bool(new_preset, "Default", set_def); |
| 2091 | presets_list_clear_default(ud); |
| 2092 | hb_presets_clear_default(); |
| 2093 | } |
| 2094 | |
| 2095 | // Adding a new preset |
| 2096 | // Append to the folder |
| 2097 | int index = hb_preset_append(folder_path, new_preset); |
| 2098 | if (index >= 0) |
| 2099 | { |
| 2100 | folder_path->index[folder_path->depth++] = index; |
| 2101 | presets_list_append(ud, folder_path); |
| 2102 | } |
| 2103 | *path = *folder_path; |
| 2104 | } |
| 2105 | |
| 2106 | |
| 2107 | free(fullname); |
| 2108 | ghb_value_free(&new_preset); |
| 2109 |
no test coverage detected