aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/jalv_gtk2.c73
-rw-r--r--src/jalv_internal.h3
-rw-r--r--src/state.c8
3 files changed, 49 insertions, 35 deletions
diff --git a/src/jalv_gtk2.c b/src/jalv_gtk2.c
index d6829b5..178e14a 100644
--- a/src/jalv_gtk2.c
+++ b/src/jalv_gtk2.c
@@ -98,6 +98,21 @@ typedef struct {
LilvNode* preset;
} PresetRecord;
+char*
+symbolify(const char* in)
+{
+ const size_t len = strlen(in);
+ char* out = calloc(len + 1, 1);
+ for (size_t i = 0; i < len; ++i) {
+ if (g_ascii_isalnum(in[i])) {
+ out[i] = in[i];
+ } else {
+ out[i] = '_';
+ }
+ }
+ return out;
+}
+
static void
on_save_preset_activate(GtkWidget* widget, void* ptr)
{
@@ -106,7 +121,7 @@ on_save_preset_activate(GtkWidget* widget, void* ptr)
GtkWidget* dialog = gtk_file_chooser_dialog_new(
"Save Preset",
jalv->window,
- GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER,
+ GTK_FILE_CHOOSER_ACTION_SAVE,
GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT,
GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT,
NULL);
@@ -115,41 +130,37 @@ on_save_preset_activate(GtkWidget* widget, void* ptr)
gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(dialog), dot_lv2);
free(dot_lv2);
- GtkWidget* content = gtk_dialog_get_content_area(GTK_DIALOG(dialog));
- GtkTable* table = GTK_TABLE(gtk_table_new(2, 2, FALSE));
- GtkWidget* label_label = gtk_label_new("Label:");
- GtkWidget* uri_label = gtk_label_new("URI:");
- GtkWidget* label_entry = gtk_entry_new();
- GtkWidget* uri_entry = gtk_entry_new();
- gtk_misc_set_alignment(GTK_MISC(label_label), 1.0, 0.5);
- gtk_misc_set_alignment(GTK_MISC(uri_label), 1.0, 0.5);
- gtk_table_attach(table, label_label,
- 0, 1, 0, 1, GTK_SHRINK, GTK_SHRINK, 6, 12);
- gtk_table_attach(table, label_entry,
- 1, 2, 0, 1,
- GTK_FILL|GTK_EXPAND, GTK_FILL|GTK_EXPAND, 6, 6);
- gtk_table_attach(table, uri_label,
- 0, 1, 1, 2,
- GTK_SHRINK, GTK_SHRINK, 6, 12);
- gtk_table_attach(table, uri_entry,
- 1, 2, 1, 2,
- GTK_FILL|GTK_EXPAND, GTK_FILL|GTK_EXPAND, 6, 6);
- gtk_box_pack_start(GTK_BOX(content), GTK_WIDGET(table), FALSE, FALSE, 6);
+ GtkWidget* content = gtk_dialog_get_content_area(GTK_DIALOG(dialog));
+ GtkBox* box = GTK_BOX(gtk_hbox_new(FALSE, 8));
+ GtkWidget* uri_label = gtk_label_new("URI (Optional):");
+ GtkWidget* uri_entry = gtk_entry_new();
+
+ gtk_box_pack_start(box, uri_label, FALSE, TRUE, 2);
+ gtk_box_pack_start(box, uri_entry, TRUE, TRUE, 2);
+ gtk_box_pack_start(GTK_BOX(content), GTK_WIDGET(box), FALSE, FALSE, 6);
gtk_widget_show_all(GTK_WIDGET(dialog));
- gtk_entry_set_activates_default(GTK_ENTRY(label_entry), TRUE);
gtk_entry_set_activates_default(GTK_ENTRY(uri_entry), TRUE);
gtk_dialog_set_default_response(GTK_DIALOG(dialog), GTK_RESPONSE_ACCEPT);
if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) {
- const char* path = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog));
- const char* label = gtk_entry_get_text(GTK_ENTRY(label_entry));
- const char* uri = gtk_entry_get_text(GTK_ENTRY(uri_entry));
- char* l = ((strlen(label) > 0)
- ? g_strdup(label)
- : g_path_get_basename(path));
-
- jalv_save_preset(jalv, path, (strlen(uri) ? uri : NULL), l);
- free(l);
+ const char* path = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog));
+ const char* uri = gtk_entry_get_text(GTK_ENTRY(uri_entry));
+
+ char* dirname = g_path_get_dirname(path);
+ char* basename = g_path_get_basename(path);
+ char* sym = symbolify(basename);
+ char* bundle = g_strjoin(NULL, sym, ".lv2", NULL);
+ char* file = g_strjoin(NULL, sym, ".ttl", NULL);
+ char* dir = g_build_filename(dirname, bundle, NULL);
+
+ jalv_save_preset(jalv, dir, (strlen(uri) ? uri : NULL), basename, file);
+
+ g_free(dir);
+ g_free(file);
+ g_free(bundle);
+ free(sym);
+ g_free(basename);
+ g_free(dirname);
}
gtk_widget_destroy(GTK_WIDGET(dialog));
diff --git a/src/jalv_internal.h b/src/jalv_internal.h
index 631994d..06114f2 100644
--- a/src/jalv_internal.h
+++ b/src/jalv_internal.h
@@ -229,7 +229,8 @@ int
jalv_save_preset(Jalv* jalv,
const char* dir,
const char* uri,
- const char* label);
+ const char* label,
+ const char* filename);
void
jalv_save(Jalv* jalv, const char* dir);
diff --git a/src/state.c b/src/state.c
index a75ef3b..1d94fe8 100644
--- a/src/state.c
+++ b/src/state.c
@@ -192,7 +192,8 @@ int
jalv_save_preset(Jalv* jalv,
const char* dir,
const char* uri,
- const char* label)
+ const char* label,
+ const char* filename)
{
LilvState* const state = lilv_state_new_from_instance(
jalv->plugin, jalv->instance, &jalv->map,
@@ -204,8 +205,9 @@ jalv_save_preset(Jalv* jalv,
lilv_state_set_label(state, label);
}
- int ret = lilv_state_save(jalv->world, &jalv->map, &jalv->unmap, state,
- uri, dir, "state.ttl");
+ int ret = lilv_state_save(
+ jalv->world, &jalv->map, &jalv->unmap, state, uri, dir, filename);
+
lilv_state_free(state);
return ret;