summaryrefslogtreecommitdiff
path: root/plugins/gtkui/pluginconf.c
diff options
context:
space:
mode:
authorGravatar waker <wakeroid@gmail.com>2010-12-27 17:46:53 +0100
committerGravatar waker <wakeroid@gmail.com>2010-12-27 17:46:53 +0100
commit8990244b8aff1ed931bc49a419b9d729887702c1 (patch)
treed60ef6738d94d578a63464c3fe734d8ceb004d47 /plugins/gtkui/pluginconf.c
parent105a5af47b396941781adf422511b2b7e899f56a (diff)
improved gui script:
added support for spinbtn and combobox changed API to allow generic use (e.g. for dsp plugins) dsp set/get_param are now using strings instead of floats dsp plugins are now using gui script fixed many errors in converter and its gui supereq set/get_param now uses dBs instead of amplitude
Diffstat (limited to 'plugins/gtkui/pluginconf.c')
-rw-r--r--plugins/gtkui/pluginconf.c288
1 files changed, 234 insertions, 54 deletions
diff --git a/plugins/gtkui/pluginconf.c b/plugins/gtkui/pluginconf.c
index 601f72e8..b024bcf8 100644
--- a/plugins/gtkui/pluginconf.c
+++ b/plugins/gtkui/pluginconf.c
@@ -30,6 +30,7 @@
#include "gtkui.h"
#include "parser.h"
#include "support.h"
+#include "pluginconf.h"
//#define trace(...) { fprintf (stderr, __VA_ARGS__); }
#define trace(fmt,...)
@@ -65,14 +66,14 @@ on_prop_browse_file (GtkButton *button, gpointer user_data) {
}
}
-static void apply_conf (GtkWidget *w, DB_plugin_t *p) {
+static void apply_conf (GtkWidget *w, pluginconf_t *conf) {
// parse script
char token[MAX_TOKEN];
- const char *script = p->configdialog;
+ const char *script = conf->layout;
parser_line = 1;
while (script = gettoken (script, token)) {
if (strcmp (token, "property")) {
- fprintf (stderr, "invalid token while loading plugin %s config dialog: %s at line %d\n", p->name, token, parser_line);
+ fprintf (stderr, "invalid token while loading plugin %s config dialog: %s at line %d\n", conf->title, token, parser_line);
break;
}
char labeltext[MAX_TOKEN];
@@ -85,8 +86,34 @@ static void apply_conf (GtkWidget *w, DB_plugin_t *p) {
if (!script) {
break;
}
+
+ // skip containers
+ if (!strncmp (type, "hbox[", 5) || !strncmp (type, "vbox[", 5)) {
+ // skip to ;
+ char semicolon[MAX_TOKEN];
+ while (script = gettoken_warn_eof (script, semicolon)) {
+ if (!strcmp (semicolon, ";")) {
+ break;
+ }
+ }
+ continue;
+ }
+
+ // ignore layout options
char key[MAX_TOKEN];
- script = gettoken_warn_eof (script, key);
+ const char *skiptokens[] = { "vert", NULL };
+ for (;;) {
+ script = gettoken_warn_eof (script, key);
+ int i = 0;
+ for (i = 0; skiptokens[i]; i++) {
+ if (!strcmp (key, skiptokens[i])) {
+ break;
+ }
+ }
+ if (!skiptokens[i]) {
+ break;
+ }
+ }
if (!script) {
break;
}
@@ -95,36 +122,63 @@ static void apply_conf (GtkWidget *w, DB_plugin_t *p) {
if (!script) {
break;
}
- script = gettoken_warn_eof (script, token);
- if (!script) {
- break;
- }
- if (strcmp (token, ";")) {
- fprintf (stderr, "expected `;' while loading plugin %s config dialog: %s at line %d\n", p->name, token, parser_line);
- break;
- }
// fetch data
GtkWidget *widget = lookup_widget (w, key);
if (widget) {
if (!strcmp (type, "entry") || !strcmp (type, "password")) {
- deadbeef->conf_set_str (key, gtk_entry_get_text (GTK_ENTRY (widget)));
+ conf->set_param (key, gtk_entry_get_text (GTK_ENTRY (widget)));
}
else if (!strcmp (type, "file")) {
if (deadbeef->conf_get_int ("gtkui.pluginconf.use_filechooser_button", 0)) {
// filechooser
- deadbeef->conf_set_str (key, gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (widget)));
+ conf->set_param (key, gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (widget)));
}
else {
- deadbeef->conf_set_str (key, gtk_entry_get_text (GTK_ENTRY (widget)));
+ conf->set_param (key, gtk_entry_get_text (GTK_ENTRY (widget)));
}
}
else if (!strcmp (type, "checkbox")) {
- deadbeef->conf_set_int (key, gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget)));
+ conf->set_param (key, gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget)) ? "1" : "0");
+ }
+ else if (!strncmp (type, "hscale[", 7) || !strncmp (type, "vscale[", 7)) {
+ char s[20];
+ snprintf (s, sizeof (s), "%f", gtk_range_get_value (GTK_RANGE (widget)));
+ conf->set_param (key, s);
}
- else if (!strncmp (type, "hscale[", 7)) {
- deadbeef->conf_set_float (key, gtk_range_get_value (GTK_RANGE (widget)));
+ else if (!strncmp (type, "spinbtn[", 8)) {
+ char s[20];
+ snprintf (s, sizeof (s), "%f", (float)gtk_spin_button_get_value (GTK_SPIN_BUTTON (widget)));
+ conf->set_param (key, s);
}
+ else if (!strncmp (type, "select[", 7)) {
+ int n;
+ if (1 != sscanf (type+6, "[%d]", &n)) {
+ break;
+ }
+ for (int i = 0; i < n; i++) {
+ char value[MAX_TOKEN];
+ script = gettoken_warn_eof (script, value);
+ if (!script) {
+ break;
+ }
+ }
+ if (!script) {
+ break;
+ }
+ char s[20];
+ snprintf (s, sizeof (s), "%d", gtk_combo_box_get_active (GTK_COMBO_BOX (widget)));
+ conf->set_param (key, s);
+ }
+ }
+
+ script = gettoken_warn_eof (script, token);
+ if (!script) {
+ break;
+ }
+ if (strcmp (token, ";")) {
+ fprintf (stderr, "expected `;' while loading plugin %s config dialog: %s at line %d\n", conf->title, token, parser_line);
+ break;
}
}
deadbeef->sendmessage (M_CONFIGCHANGED, 0, 0, 0);
@@ -136,10 +190,10 @@ prop_changed (GtkWidget *editable, gpointer user_data) {
}
void
-plugin_configure (GtkWidget *parentwin, DB_plugin_t *p) {
+plugin_configure (GtkWidget *parentwin, pluginconf_t *conf) {
// create window
char title[200];
- snprintf (title, sizeof (title), _("Setup %s"), p->name);
+ snprintf (title, sizeof (title), _("Configure %s"), conf->title);
GtkWidget *win = gtk_dialog_new_with_buttons (title, GTK_WINDOW (parentwin), GTK_DIALOG_MODAL, GTK_STOCK_APPLY, GTK_RESPONSE_APPLY, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, GTK_STOCK_OK, GTK_RESPONSE_OK, NULL);
gtk_dialog_set_default_response (GTK_DIALOG (win), GTK_RESPONSE_OK);
gtk_window_set_type_hint (GTK_WINDOW (win), GDK_WINDOW_TYPE_HINT_DIALOG);
@@ -148,9 +202,13 @@ plugin_configure (GtkWidget *parentwin, DB_plugin_t *p) {
gtk_window_set_title (GTK_WINDOW (win), title);
gtk_window_set_modal (GTK_WINDOW (win), TRUE);
gtk_window_set_transient_for (GTK_WINDOW (win), GTK_WINDOW (parentwin));
- GtkWidget *vbox;
- vbox = GTK_DIALOG (win)->vbox;
- gtk_box_set_spacing (GTK_BOX (vbox), 8);
+
+ GtkWidget *widgets[100] = {NULL};
+ int pack[100] = {0};
+ int ncurr = 0;
+
+ widgets[ncurr] = GTK_DIALOG (win)->vbox;
+ gtk_box_set_spacing (GTK_BOX (widgets[ncurr]), 8);
GtkWidget *action_area = GTK_DIALOG (win)->action_area;
gtk_widget_show (action_area);
gtk_button_box_set_layout (GTK_BUTTON_BOX (action_area), GTK_BUTTONBOX_END);
@@ -158,11 +216,11 @@ plugin_configure (GtkWidget *parentwin, DB_plugin_t *p) {
// parse script
char token[MAX_TOKEN];
- const char *script = p->configdialog;
+ const char *script = conf->layout;
parser_line = 1;
while (script = gettoken (script, token)) {
if (strcmp (token, "property")) {
- fprintf (stderr, "invalid token while loading plugin %s config dialog: %s at line %d\n", p->name, token, parser_line);
+ fprintf (stderr, "invalid token while loading plugin %s config dialog: %s at line %d\n", conf->title, token, parser_line);
break;
}
char labeltext[MAX_TOKEN];
@@ -170,34 +228,100 @@ plugin_configure (GtkWidget *parentwin, DB_plugin_t *p) {
if (!script) {
break;
}
+
+ if (ncurr > 0) {
+ pack[ncurr]--;
+ if (pack[ncurr] < 0) {
+ ncurr--;
+ }
+ }
+
char type[MAX_TOKEN];
script = gettoken_warn_eof (script, type);
if (!script) {
break;
}
+
+ if (!strncmp (type, "hbox[", 5) || !strncmp (type, "vbox[", 5)) {
+ ncurr++;
+ int n = 0;
+ if (1 != sscanf (type+4, "[%d]", &n)) {
+ break;
+ }
+ pack[ncurr] = n;
+
+ int vert = 0;
+ int hmg = FALSE;
+ int fill = FALSE;
+ int expand = FALSE;
+ int border = 0;
+ int spacing = 8;
+ int height = 100;
+
+ char param[MAX_TOKEN];
+ for (;;) {
+ script = gettoken_warn_eof (script, param);
+ if (!script) {
+ break;
+ }
+ if (!strcmp (param, ";")) {
+ break;
+ }
+ else if (!strcmp (param, "hmg")) {
+ hmg = TRUE;
+ }
+ else if (!strcmp (param, "fill")) {
+ fill = TRUE;
+ }
+ else if (!strcmp (param, "expand")) {
+ expand = TRUE;
+ }
+ else if (!strncmp (param, "border=", 7)) {
+ border = atoi (param+7);
+ }
+ else if (!strncmp (param, "spacing=", 8)) {
+ spacing = atoi (param+8);
+ }
+ else if (!strncmp (param, "height=", 7)) {
+ height = atoi (param+7);
+ }
+ }
+
+ widgets[ncurr] = vert ? gtk_vbox_new (TRUE, spacing) : gtk_hbox_new (TRUE, spacing);
+ gtk_widget_set_size_request (widgets[ncurr], -1, height);
+ gtk_widget_show (widgets[ncurr]);
+ gtk_box_pack_start (GTK_BOX(widgets[ncurr-1]), widgets[ncurr], fill, expand, border);
+ continue;
+ }
+
+ int vertical = 0;
+
char key[MAX_TOKEN];
- script = gettoken_warn_eof (script, key);
- if (!script) {
- break;
+ for (;;) {
+ script = gettoken_warn_eof (script, key);
+ if (!script) {
+ break;
+ }
+ if (!strcmp (key, "vert")) {
+ vertical = 1;
+ }
+ else {
+ break;
+ }
}
+
char def[MAX_TOKEN];
script = gettoken_warn_eof (script, def);
if (!script) {
break;
}
- script = gettoken_warn_eof (script, token);
- if (!script) {
- break;
- }
- if (strcmp (token, ";")) {
- fprintf (stderr, "expected `;' while loading plugin %s config dialog: %s at line %d\n", p->name, token, parser_line);
- break;
- }
// add to dialog
GtkWidget *label = NULL;
GtkWidget *prop = NULL;
GtkWidget *cont = NULL;
+ char value[1000];
+ conf->get_param (key, value, sizeof (value), def);
if (!strcmp (type, "entry") || !strcmp (type, "password")) {
label = gtk_label_new (_(labeltext));
gtk_widget_show (label);
@@ -205,13 +329,17 @@ plugin_configure (GtkWidget *parentwin, DB_plugin_t *p) {
gtk_entry_set_activates_default (GTK_ENTRY (prop), TRUE);
g_signal_connect (G_OBJECT (prop), "changed", G_CALLBACK (prop_changed), win);
gtk_widget_show (prop);
- gtk_entry_set_text (GTK_ENTRY (prop), deadbeef->conf_get_str (key, def));
+ gtk_entry_set_text (GTK_ENTRY (prop), value);
+
+ if (!strcmp (type, "password")) {
+ gtk_entry_set_visibility (GTK_ENTRY (prop), FALSE);
+ }
}
else if (!strcmp (type, "checkbox")) {
prop = gtk_check_button_new_with_label (_(labeltext));
g_signal_connect (G_OBJECT (prop), "toggled", G_CALLBACK (prop_changed), win);
gtk_widget_show (prop);
- int val = deadbeef->conf_get_int (key, atoi (def));
+ int val = atoi (value);
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (prop), val);
}
else if (!strcmp (type, "file")) {
@@ -220,7 +348,7 @@ plugin_configure (GtkWidget *parentwin, DB_plugin_t *p) {
if (deadbeef->conf_get_int ("gtkui.pluginconf.use_filechooser_button", 0)) {
prop = gtk_file_chooser_button_new (_(labeltext), GTK_FILE_CHOOSER_ACTION_OPEN);
gtk_widget_show (prop);
- gtk_file_chooser_set_filename (GTK_FILE_CHOOSER (prop), deadbeef->conf_get_str (key, def));
+ gtk_file_chooser_set_filename (GTK_FILE_CHOOSER (prop), value);
g_signal_connect (G_OBJECT (prop), "file-set", G_CALLBACK (prop_changed), win);
}
else {
@@ -231,7 +359,7 @@ plugin_configure (GtkWidget *parentwin, DB_plugin_t *p) {
g_signal_connect (G_OBJECT (prop), "changed", G_CALLBACK (prop_changed), win);
gtk_widget_show (prop);
gtk_editable_set_editable (GTK_EDITABLE (prop), FALSE);
- gtk_entry_set_text (GTK_ENTRY (prop), deadbeef->conf_get_str (key, def));
+ gtk_entry_set_text (GTK_ENTRY (prop), value);
gtk_box_pack_start (GTK_BOX (cont), prop, TRUE, TRUE, 0);
GtkWidget *btn = gtk_button_new_with_label ("…");
gtk_widget_show (btn);
@@ -239,36 +367,88 @@ plugin_configure (GtkWidget *parentwin, DB_plugin_t *p) {
g_signal_connect (G_OBJECT (btn), "clicked", G_CALLBACK (on_prop_browse_file), prop);
}
}
- else if (!strncmp (type, "hscale[", 7)) {
+ else if (!strncmp (type, "select[", 7)) {
+ int n;
+ if (1 != sscanf (type+6, "[%d]", &n)) {
+ break;
+ }
+
+ label = gtk_label_new (_(labeltext));
+ gtk_widget_show (label);
+
+ prop = gtk_combo_box_new_text ();
+ gtk_widget_show (prop);
+
+ for (int i = 0; i < n; i++) {
+ char entry[MAX_TOKEN];
+ script = gettoken_warn_eof (script, entry);
+ if (!script) {
+ break;
+ }
+
+ gtk_combo_box_append_text (GTK_COMBO_BOX (prop), entry);
+ }
+ if (!script) {
+ break;
+ }
+ gtk_combo_box_set_active (GTK_COMBO_BOX (prop), atoi (value));
+ g_signal_connect ((gpointer) prop, "changed",
+ G_CALLBACK (prop_changed),
+ win);
+ }
+ else if (!strncmp (type, "hscale[", 7) || !strncmp (type, "vscale[", 7) || !strncmp (type, "spinbtn[", 8)) {
float min, max, step;
- if (3 != sscanf (type+6, "[%f,%f,%f]", &min, &max, &step)) {
- min = 0;
- max = 100;
- step = 1;
+ const char *args;
+ if (type[0] == 's') {
+ args = type + 7;
+ }
+ else {
+ args = type + 6;
}
+ if (3 != sscanf (args, "[%f,%f,%f]", &min, &max, &step)) {
+ break;
+ }
+ int invert = 0;
if (min >= max) {
float tmp = min;
min = max;
max = tmp;
- break;
+ invert = 1;
}
if (step <= 0) {
step = 1;
}
- prop = gtk_hscale_new_with_range (min, max, step);
+ if (type[0] == 's') {
+ prop = gtk_spin_button_new_with_range (min, max, step);
+ gtk_spin_button_set_value (GTK_SPIN_BUTTON (prop), atof (value));
+ }
+ else {
+ prop = type[0] == 'h' ? gtk_hscale_new_with_range (min, max, step) : gtk_vscale_new_with_range (min, max, step);
+ if (invert) {
+ gtk_range_set_inverted (GTK_RANGE (prop), TRUE);
+ }
+ gtk_range_set_value (GTK_RANGE (prop), (gdouble)atof (value));
+ gtk_scale_set_value_pos (GTK_SCALE (prop), GTK_POS_RIGHT);
+ }
label = gtk_label_new (_(labeltext));
gtk_widget_show (label);
g_signal_connect (G_OBJECT (prop), "value-changed", G_CALLBACK (prop_changed), win);
gtk_widget_show (prop);
- gtk_range_set_value (GTK_RANGE (prop), (gdouble)deadbeef->conf_get_float (key, (float)*def));
- gtk_scale_set_value_pos (GTK_SCALE (prop), GTK_POS_RIGHT);
}
- if (!strcmp (type, "password")) {
- gtk_entry_set_visibility (GTK_ENTRY (prop), FALSE);
+
+ script = gettoken_warn_eof (script, token);
+ if (!script) {
+ break;
+ }
+ if (strcmp (token, ";")) {
+ fprintf (stderr, "expected `;' while loading plugin %s config dialog: %s at line %d\n", conf->title, token, parser_line);
+ break;
}
+
+
if (label && prop) {
GtkWidget *hbox = NULL;
- hbox = gtk_hbox_new (FALSE, 8);
+ hbox = vertical ? gtk_vbox_new (FALSE, 8) : gtk_hbox_new (FALSE, 8);
gtk_widget_show (hbox);
gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
gtk_box_pack_start (GTK_BOX (hbox), cont ? cont : prop, TRUE, TRUE, 0);
@@ -281,7 +461,7 @@ plugin_configure (GtkWidget *parentwin, DB_plugin_t *p) {
g_object_set_data (G_OBJECT (win), key, prop);
}
if (cont) {
- gtk_box_pack_start (GTK_BOX (vbox), cont, FALSE, FALSE, 0);
+ gtk_box_pack_start (GTK_BOX (widgets[ncurr]), cont, FALSE, FALSE, 0);
}
}
@@ -290,7 +470,7 @@ plugin_configure (GtkWidget *parentwin, DB_plugin_t *p) {
gtk_dialog_set_response_sensitive (GTK_DIALOG (win), GTK_RESPONSE_APPLY, FALSE);
response = gtk_dialog_run (GTK_DIALOG (win));
if (response == GTK_RESPONSE_APPLY || response == GTK_RESPONSE_OK) {
- apply_conf (win, p);
+ apply_conf (win, conf);
}
} while (response == GTK_RESPONSE_APPLY);
gtk_widget_destroy (win);