| 2140 | } |
| 2141 | |
| 2142 | static void |
| 2143 | preset_import_response_cb (GtkFileChooser *chooser, GtkResponseType response, |
| 2144 | signal_user_data_t *ud) |
| 2145 | { |
| 2146 | GFile *file = gtk_file_chooser_get_file(chooser); |
| 2147 | if (response == GTK_RESPONSE_ACCEPT && file != NULL) |
| 2148 | { |
| 2149 | hb_preset_index_t *folder_path; |
| 2150 | char *filename = g_file_get_path(file); |
| 2151 | g_object_unref(file); |
| 2152 | // import the preset |
| 2153 | folder_path = preset_get_folder(ud, GHB_IMPORT_FOLDER, HB_PRESET_TYPE_CUSTOM); |
| 2154 | GhbValue *imported = hb_presets_read_file(filename); |
| 2155 | GhbValue *list = hb_dict_get(imported, "PresetList"); |
| 2156 | GhbValue *preset = ghb_value_dup(ghb_array_get(list, 0)); |
| 2157 | // Ensure imported presets have the right type and aren't set as default |
| 2158 | ghb_dict_set_bool(preset, "Default", FALSE); |
| 2159 | ghb_dict_set_int(preset, "Type", HB_PRESET_TYPE_CUSTOM); |
| 2160 | const char *preset_name = ghb_dict_get_string(preset, "PresetName"); |
| 2161 | |
| 2162 | preset_write_data *data = g_malloc0(sizeof(preset_write_data)); |
| 2163 | data->preset = preset; |
| 2164 | data->folder_path = folder_path; |
| 2165 | |
| 2166 | if (preset_exists(GHB_IMPORT_FOLDER, preset_name)) |
| 2167 | { |
| 2168 | GtkMessageDialog *overwrite_dialog; |
| 2169 | overwrite_dialog = ghb_question_dialog_new(NULL, GHB_ACTION_DESTRUCTIVE, |
| 2170 | _("Overwrite"), _("Cancel"), |
| 2171 | _("Overwrite Preset?"), |
| 2172 | _("The preset “%s” already exists. Do you want to overwrite it?"), |
| 2173 | preset_name); |
| 2174 | gtk_widget_set_visible(GTK_WIDGET(overwrite_dialog), TRUE); |
| 2175 | g_signal_connect(overwrite_dialog, "response", G_CALLBACK(preset_write_response), data); |
| 2176 | } |
| 2177 | else |
| 2178 | { |
| 2179 | // Skip overwrite confirmation dialog |
| 2180 | preset_write_response(NULL, GTK_RESPONSE_ACCEPT, data); |
| 2181 | } |
| 2182 | |
| 2183 | const char *exportDir = ghb_dict_get_string(ud->prefs, "ExportDirectory"); |
| 2184 | char *dir = g_path_get_dirname(filename); |
| 2185 | if (strcmp(dir, exportDir) != 0) |
| 2186 | { |
| 2187 | ghb_dict_set_string(ud->prefs, "ExportDirectory", dir); |
| 2188 | ghb_pref_save(ud->prefs, "ExportDirectory"); |
| 2189 | } |
| 2190 | g_free(filename); |
| 2191 | g_free(dir); |
| 2192 | hb_value_free(&imported); |
| 2193 | } |
| 2194 | ghb_file_chooser_destroy(chooser); |
| 2195 | } |
| 2196 | |
| 2197 | static void |
| 2198 | preset_write_response (GtkDialog *dialog, GtkResponseType response, |
nothing calls this directly
no test coverage detected