| 2336 | } |
| 2337 | |
| 2338 | G_MODULE_EXPORT void |
| 2339 | preset_export_action_cb(GSimpleAction *action, GVariant *param, |
| 2340 | signal_user_data_t *ud) |
| 2341 | { |
| 2342 | hb_preset_index_t *path; |
| 2343 | GtkWindow *hb_window; |
| 2344 | GtkFileChooser *chooser; |
| 2345 | const gchar *exportDir; |
| 2346 | gchar *filename; |
| 2347 | GhbValue *dict; |
| 2348 | char *preset_name; |
| 2349 | |
| 2350 | path = get_selected_path(ud); |
| 2351 | if (path == NULL || path->depth <= 0) |
| 2352 | { |
| 2353 | const gchar *name; |
| 2354 | char * new_name; |
| 2355 | |
| 2356 | free(path); |
| 2357 | dict = ghb_settings_to_preset(ud->settings); |
| 2358 | name = ghb_dict_get_string(dict, "PresetName"); |
| 2359 | new_name = g_strdup_printf("%s (modified)", name); |
| 2360 | ghb_dict_set_string(dict, "PresetName", new_name); |
| 2361 | free(new_name); |
| 2362 | } |
| 2363 | else |
| 2364 | { |
| 2365 | dict = hb_value_dup(hb_preset_get(path)); |
| 2366 | free(path); |
| 2367 | } |
| 2368 | |
| 2369 | if (dict == NULL) |
| 2370 | { |
| 2371 | return; |
| 2372 | } |
| 2373 | preset_name = g_strdup(ghb_dict_get_string(dict, "PresetName")); |
| 2374 | |
| 2375 | hb_window = GTK_WINDOW(ghb_builder_widget("hb_window")); |
| 2376 | chooser = ghb_file_chooser_new(_("Export Preset"), hb_window, |
| 2377 | GTK_FILE_CHOOSER_ACTION_SAVE, |
| 2378 | _("_Save"), |
| 2379 | _("_Cancel")); |
| 2380 | |
| 2381 | exportDir = ghb_dict_get_string(ud->prefs, "ExportDirectory"); |
| 2382 | if (exportDir == NULL || exportDir[0] == '\0') |
| 2383 | { |
| 2384 | exportDir = "."; |
| 2385 | } |
| 2386 | |
| 2387 | // Clean up preset name for use as a filename. Removing leading |
| 2388 | // and trailing whitespace and filename illegal characters. |
| 2389 | g_strstrip(preset_name); |
| 2390 | g_strdelimit(preset_name, GHB_UNSAFE_FILENAME_CHARS, '_'); |
| 2391 | filename = g_strdup_printf("%s.json", preset_name); |
| 2392 | ghb_file_chooser_set_initial_file(chooser, exportDir); |
| 2393 | gtk_file_chooser_set_current_name(chooser, filename); |
| 2394 | g_free(filename); |
| 2395 | g_free(preset_name); |
nothing calls this directly
no test coverage detected