diff options
author | David Robillard <d@drobilla.net> | 2024-09-29 19:16:36 -0400 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2024-10-12 11:10:39 -0400 |
commit | db7c58a3b770eb4688b2e1c6de4c39172fada6c3 (patch) | |
tree | b630342b9b3c2e79f41c892c1a917847117e72ca /src/jalv_gtk.c | |
parent | acb75fa0dfc17692a8824841161bb508a23bab91 (diff) | |
download | jalv-db7c58a3b770eb4688b2e1c6de4c39172fada6c3.tar.gz jalv-db7c58a3b770eb4688b2e1c6de4c39172fada6c3.tar.bz2 jalv-db7c58a3b770eb4688b2e1c6de4c39172fada6c3.zip |
Avoid casting away const
Diffstat (limited to 'src/jalv_gtk.c')
-rw-r--r-- | src/jalv_gtk.c | 35 |
1 files changed, 24 insertions, 11 deletions
diff --git a/src/jalv_gtk.c b/src/jalv_gtk.c index 1af37ef..fd2875c 100644 --- a/src/jalv_gtk.c +++ b/src/jalv_gtk.c @@ -305,10 +305,10 @@ typedef struct { } PresetMenu; static PresetMenu* -pset_menu_new(const char* label) +pset_menu_new(char* const label) { PresetMenu* menu = (PresetMenu*)malloc(sizeof(PresetMenu)); - menu->label = g_strdup(label); + menu->label = label; menu->item = GTK_MENU_ITEM(gtk_menu_item_new_with_label(menu->label)); menu->menu = GTK_MENU(gtk_menu_new()); menu->banks = NULL; @@ -338,22 +338,35 @@ menu_cmp(gconstpointer a, gconstpointer b, gpointer ZIX_UNUSED(data)) return strcmp(((const PresetMenu*)a)->label, ((const PresetMenu*)b)->label); } +static char* +get_label_string(Jalv* const jalv, const LilvNode* const node) +{ + LilvNode* const label_node = + lilv_world_get(jalv->world, node, jalv->nodes.rdfs_label, NULL); + + if (!label_node) { + return g_strdup(lilv_node_as_string(node)); + } + + char* const label = g_strdup(lilv_node_as_string(label_node)); + lilv_node_free(label_node); + return label; +} + static PresetMenu* get_bank_menu(Jalv* jalv, PresetMenu* menu, const LilvNode* bank) { - LilvNode* label = - lilv_world_get(jalv->world, bank, jalv->nodes.rdfs_label, NULL); - - const char* uri = lilv_node_as_string(bank); - const char* str = label ? lilv_node_as_string(label) : uri; - PresetMenu key = {NULL, (char*)str, NULL, NULL}; - GSequenceIter* i = g_sequence_lookup(menu->banks, &key, menu_cmp, NULL); + char* const label = get_label_string(jalv, bank); + PresetMenu key = {NULL, label, NULL, NULL}; + GSequenceIter* i = g_sequence_lookup(menu->banks, &key, menu_cmp, NULL); if (!i) { - PresetMenu* bank_menu = pset_menu_new(str); + PresetMenu* const bank_menu = pset_menu_new(label); gtk_menu_item_set_submenu(bank_menu->item, GTK_WIDGET(bank_menu->menu)); g_sequence_insert_sorted(menu->banks, bank_menu, menu_cmp, NULL); return bank_menu; } + + g_free(label); return (PresetMenu*)g_sequence_get(i); } @@ -1319,7 +1332,7 @@ static void on_row_activated(GtkTreeView* const tree_view, GtkTreePath* const path, GtkTreeViewColumn* const column, - const void* const user_data) + void* const user_data) { (void)tree_view; (void)path; |