diff options
author | David Robillard <d@drobilla.net> | 2012-04-11 21:19:30 +0000 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2012-04-11 21:19:30 +0000 |
commit | d0c8bc8d6a7edd97d31723f26426eee95a89ef99 (patch) | |
tree | 660b81965163a20f4191da09191a2c690d33b4b1 /src/jalv_gtk2.c | |
parent | 2ac525df826f4dadfc3358cd75c3aa8b03ad548d (diff) | |
download | jalv-d0c8bc8d6a7edd97d31723f26426eee95a89ef99.tar.gz jalv-d0c8bc8d6a7edd97d31723f26426eee95a89ef99.tar.bz2 jalv-d0c8bc8d6a7edd97d31723f26426eee95a89ef99.zip |
Simpler preset saving.
git-svn-id: http://svn.drobilla.net/lad/trunk/jalv@4166 a436a847-0d15-0410-975c-d299462d15a1
Diffstat (limited to 'src/jalv_gtk2.c')
-rw-r--r-- | src/jalv_gtk2.c | 73 |
1 files changed, 42 insertions, 31 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)); |