summaryrefslogtreecommitdiff
path: root/plugins/converter
diff options
context:
space:
mode:
authorGravatar waker <wakeroid@gmail.com>2012-05-30 22:26:25 +0200
committerGravatar waker <wakeroid@gmail.com>2012-05-30 22:26:25 +0200
commit4c328e5564058757d993e109406baacfdcd97414 (patch)
treee66ae85cd6eeded9269b859b18343a2fbbcfbe04 /plugins/converter
parent8955786d3a4459ac67d9c26c7b5583b48cfb9772 (diff)
converter: implemented dsp preset plugin up/down button handlers
Diffstat (limited to 'plugins/converter')
-rw-r--r--plugins/converter/convgui.c79
1 files changed, 79 insertions, 0 deletions
diff --git a/plugins/converter/convgui.c b/plugins/converter/convgui.c
index 6e8cf1cc..670fa8eb 100644
--- a/plugins/converter/convgui.c
+++ b/plugins/converter/convgui.c
@@ -1020,11 +1020,78 @@ on_dsp_preset_plugin_configure_clicked (GtkButton *button,
current_dsp_context = NULL;
}
+static int
+listview_get_index (GtkWidget *list) {
+ GtkTreePath *path;
+ GtkTreeViewColumn *col;
+ gtk_tree_view_get_cursor (GTK_TREE_VIEW (list), &path, &col);
+ if (!path || !col) {
+ // nothing selected
+ return - 1;
+ }
+ int *indices = gtk_tree_path_get_indices (path);
+ int idx = *indices;
+ g_free (indices);
+ return idx;
+}
+
+static int
+swap_items (GtkWidget *list, int idx) {
+ ddb_dsp_context_t *prev = NULL;
+ ddb_dsp_context_t *p = current_ctx->current_dsp_preset->chain;
+
+ int n = idx;
+ while (n > 0 && p) {
+ prev = p;
+ p = p->next;
+ n--;
+ }
+
+ if (!p || !p->next) {
+ return -1;
+ }
+
+ ddb_dsp_context_t *moved = p->next;
+
+ if (!moved) {
+ return -1;
+ }
+
+ ddb_dsp_context_t *last = moved ? moved->next : NULL;
+
+ if (prev) {
+ p->next = last;
+ prev->next = moved;
+ moved->next = p;
+ }
+ else {
+ p->next = last;
+ current_ctx->current_dsp_preset->chain = moved;
+ moved->next = p;
+ }
+ GtkListStore *mdl = GTK_LIST_STORE (gtk_tree_view_get_model (GTK_TREE_VIEW(list)));
+ gtk_list_store_clear (mdl);
+ fill_dsp_preset_chain (mdl);
+ return 0;
+}
+
void
on_dsp_preset_plugin_up_clicked (GtkButton *button,
gpointer user_data)
{
+ GtkWidget *toplevel = gtk_widget_get_toplevel (GTK_WIDGET (button));
+ GtkWidget *list = lookup_widget (toplevel, "plugins");
+ int idx = listview_get_index (list);
+ if (idx <= 0) {
+ return;
+ }
+ if (-1 == swap_items (list, idx-1)) {
+ return;
+ }
+ GtkTreePath *path = gtk_tree_path_new_from_indices (idx-1, -1);
+ gtk_tree_view_set_cursor (GTK_TREE_VIEW (list), path, NULL, FALSE);
+ gtk_tree_path_free (path);
}
@@ -1032,7 +1099,19 @@ void
on_dsp_preset_plugin_down_clicked (GtkButton *button,
gpointer user_data)
{
+ GtkWidget *toplevel = gtk_widget_get_toplevel (GTK_WIDGET (button));
+ GtkWidget *list = lookup_widget (toplevel, "plugins");
+ int idx = listview_get_index (list);
+ if (idx == -1) {
+ return;
+ }
+ if (-1 == swap_items (list, idx)) {
+ return;
+ }
+ GtkTreePath *path = gtk_tree_path_new_from_indices (idx+1, -1);
+ gtk_tree_view_set_cursor (GTK_TREE_VIEW (list), path, NULL, FALSE);
+ gtk_tree_path_free (path);
}