gfio: add gerror.c for reporting errors
[fio.git] / goptions.c
index 9b6fca606859ca38284a8b35739b49083b6eecfc..49da0019d6d61a2bb14cf0fe3db83feb4ae34e20 100644 (file)
@@ -15,6 +15,7 @@ struct gopt {
        GtkWidget *box;
        unsigned int opt_index;
        unsigned int opt_type;
+       gulong sig_handler;
 };
 
 struct gopt_combo {
@@ -24,6 +25,7 @@ struct gopt_combo {
 
 struct gopt_int {
        struct gopt gopt;
+       unsigned int lastval;
        GtkWidget *spin;
 };
 
@@ -37,23 +39,142 @@ struct gopt_str {
        GtkWidget *entry;
 };
 
+struct gopt_str_val {
+       struct gopt gopt;
+       GtkWidget *spin;
+       GtkWidget *combo;
+       unsigned int maxindex;
+};
+
+#define GOPT_RANGE_SPIN        4
+
 struct gopt_range {
        struct gopt gopt;
-       GtkWidget *spins[4];
+       GtkWidget *spins[GOPT_RANGE_SPIN];
+};
+
+struct gopt_str_multi {
+       struct gopt gopt;
+       GtkWidget *checks[PARSE_MAX_VP];
+};
+
+static GtkWidget *gopt_widgets[FIO_MAX_OPTS];
+
+struct gopt_frame_widget {
+       GtkWidget *vbox[2];
+       unsigned int nr;
 };
+static struct gopt_frame_widget gopt_g_widgets[__FIO_OPT_G_NR];
+
+static GNode *gopt_dep_tree;
+
+static GtkWidget *gopt_get_group_frame(GtkWidget *box, unsigned int groupmask)
+{
+       unsigned int mask, group;
+       struct opt_group *og;
+       GtkWidget *frame, *hbox;
+       struct gopt_frame_widget *gfw;
+
+       if (!groupmask)
+               return 0;
+
+       mask = groupmask;
+       og = opt_group_cat_from_mask(&mask);
+       if (!og)
+               return NULL;
+
+       group = ffz(~groupmask);
+       gfw = &gopt_g_widgets[group];
+       if (!gfw->vbox[0]) {
+               frame = gtk_frame_new(og->name);
+               gtk_box_pack_start(GTK_BOX(box), frame, FALSE, FALSE, 3);
+               hbox = gtk_hbox_new(FALSE, 0);
+               gtk_container_add(GTK_CONTAINER(frame), hbox);
+               gfw->vbox[0] = gtk_vbox_new(TRUE, 5);
+               gfw->vbox[1] = gtk_vbox_new(TRUE, 5);
+               gtk_box_pack_start(GTK_BOX(hbox), gfw->vbox[0], TRUE, TRUE, 5);
+               gtk_box_pack_start(GTK_BOX(hbox), gfw->vbox[1], TRUE, TRUE, 5);
+       }
 
-static struct gopt *gopt_new_str_store(struct fio_option *o, const char *text)
+       hbox = gtk_hbox_new(FALSE, 3);
+       gtk_box_pack_start(GTK_BOX(gfw->vbox[gfw->nr++ & 1]), hbox, FALSE, FALSE, 5);
+       return hbox;
+}
+
+/*
+ * Mark children as invisible, if needed.
+ */
+static void gopt_set_children_visible(struct fio_option *parent,
+                                     gboolean visible)
+{
+       GNode *child, *node;
+
+       if (parent->hide_on_set)
+               visible = !visible;
+
+       node = g_node_find(gopt_dep_tree, G_IN_ORDER, G_TRAVERSE_ALL, parent);
+       child = g_node_first_child(node);
+       while (child) {
+               struct fio_option *o = child->data;
+               struct gopt *g = o->gui_data;
+
+               /*
+                * Recurse into child, if it also has children
+                */
+               if (g_node_n_children(child))
+                       gopt_set_children_visible(o, visible);
+
+               if (gopt_widgets[g->opt_index])
+                       gtk_widget_set_sensitive(gopt_widgets[g->opt_index], visible);
+
+               child = g_node_next_sibling(child);
+       }
+}
+
+static void gopt_str_changed(GtkEntry *entry, gpointer data)
+{
+       struct gopt_str *s = (struct gopt_str *) data;
+       struct fio_option *o = &fio_options[s->gopt.opt_index];
+       const gchar *text;
+       int set;
+
+       text = gtk_entry_get_text(GTK_ENTRY(s->entry));
+       set = strcmp(text, "") != 0;
+       gopt_set_children_visible(o, set);
+}
+
+static void gopt_mark_index(struct gopt *gopt, unsigned int idx)
+{
+       assert(!gopt_widgets[idx]);
+       gopt->opt_index = idx;
+       gopt_widgets[idx] = gopt->box;
+}
+
+static void gopt_str_destroy(GtkWidget *w, gpointer data)
+{
+       struct gopt_str *s = (struct gopt_str *) data;
+
+       free(s);
+       gtk_widget_destroy(w);
+}
+
+static struct gopt *gopt_new_str_store(struct fio_option *o, const char *text,
+                                      unsigned int idx)
 {
        struct gopt_str *s;
        GtkWidget *label;
 
        s = malloc(sizeof(*s));
+       memset(s, 0, sizeof(*s));
 
        s->gopt.box = gtk_hbox_new(FALSE, 3);
-       label = gtk_label_new(o->name);
-       gtk_box_pack_start(GTK_BOX(s->gopt.box), label, FALSE, FALSE, 0);
+       if (!o->lname)
+               label = gtk_label_new(o->name);
+       else
+               label = gtk_label_new(o->lname);
 
        s->entry = gtk_entry_new();
+       gopt_mark_index(&s->gopt, idx);
        if (text)
                gtk_entry_set_text(GTK_ENTRY(s->entry), text);
        gtk_entry_set_editable(GTK_ENTRY(s->entry), 1);
@@ -61,39 +182,70 @@ static struct gopt *gopt_new_str_store(struct fio_option *o, const char *text)
        if (o->def)
                gtk_entry_set_text(GTK_ENTRY(s->entry), o->def);
 
+       s->gopt.sig_handler = g_signal_connect(GTK_OBJECT(s->entry), "changed", G_CALLBACK(gopt_str_changed), s);
+       g_signal_connect(GTK_OBJECT(s->entry), "destroy", G_CALLBACK(gopt_str_destroy), s);
+
        gtk_box_pack_start(GTK_BOX(s->gopt.box), s->entry, FALSE, FALSE, 0);
+       gtk_box_pack_start(GTK_BOX(s->gopt.box), label, FALSE, FALSE, 0);
        return &s->gopt;
 }
 
-static struct gopt_combo *__gopt_new_combo(struct fio_option *o)
+static void gopt_combo_changed(GtkComboBox *box, gpointer data)
+{
+       struct gopt_combo *c = (struct gopt_combo *) data;
+       struct fio_option *o = &fio_options[c->gopt.opt_index];
+       unsigned int index;
+
+       index = gtk_combo_box_get_active(GTK_COMBO_BOX(c->combo));
+       gopt_set_children_visible(o, index);
+}
+
+static void gopt_combo_destroy(GtkWidget *w, gpointer data)
+{
+       struct gopt_combo *c = (struct gopt_combo *) data;
+
+       free(c);
+       gtk_widget_destroy(w);
+}
+
+static struct gopt_combo *__gopt_new_combo(struct fio_option *o,
+                                          unsigned int idx)
 {
-       struct gopt_combo *combo;
+       struct gopt_combo *c;
        GtkWidget *label;
 
-       combo = malloc(sizeof(*combo));
+       c = malloc(sizeof(*c));
+       memset(c, 0, sizeof(*c));
 
-       combo->gopt.box = gtk_hbox_new(FALSE, 3);
-       label = gtk_label_new(o->name);
-       gtk_box_pack_start(GTK_BOX(combo->gopt.box), label, FALSE, FALSE, 0);
+       c->gopt.box = gtk_hbox_new(FALSE, 3);
+       if (!o->lname)
+               label = gtk_label_new(o->name);
+       else
+               label = gtk_label_new(o->lname);
 
-       combo->combo = gtk_combo_box_new_text();
-       gtk_box_pack_start(GTK_BOX(combo->gopt.box), combo->combo, FALSE, FALSE, 0);
+       c->combo = gtk_combo_box_new_text();
+       gopt_mark_index(&c->gopt, idx);
+       g_signal_connect(GTK_OBJECT(c->combo), "destroy", G_CALLBACK(gopt_combo_destroy), c);
 
-       return combo;
+       gtk_box_pack_start(GTK_BOX(c->gopt.box), c->combo, FALSE, FALSE, 0);
+       gtk_box_pack_start(GTK_BOX(c->gopt.box), label, FALSE, FALSE, 0);
+
+       return c;
 }
 
-static struct gopt *gopt_new_combo_str(struct fio_option *o, const char *text)
+static struct gopt *gopt_new_combo_str(struct fio_option *o, const char *text,
+                                      unsigned int idx)
 {
-       struct gopt_combo *combo;
+       struct gopt_combo *c;
        struct value_pair *vp;
        int i, active = 0;
 
-       combo = __gopt_new_combo(o);
+       c = __gopt_new_combo(o, idx);
 
        i = 0;
        vp = &o->posval[0];
        while (vp->ival) {
-               gtk_combo_box_append_text(GTK_COMBO_BOX(combo->combo), vp->ival);
+               gtk_combo_box_append_text(GTK_COMBO_BOX(c->combo), vp->ival);
                if (o->def && !strcmp(vp->ival, o->def))
                        active = i;
                if (text && !strcmp(vp->ival, text))
@@ -102,43 +254,118 @@ static struct gopt *gopt_new_combo_str(struct fio_option *o, const char *text)
                i++;
        }
 
-       gtk_combo_box_set_active(GTK_COMBO_BOX(combo->combo), active);
-       return &combo->gopt;
+       gtk_combo_box_set_active(GTK_COMBO_BOX(c->combo), active);
+       c->gopt.sig_handler = g_signal_connect(GTK_OBJECT(c->combo), "changed", G_CALLBACK(gopt_combo_changed), c);
+       return &c->gopt;
 }
 
-static struct gopt *gopt_new_combo_int(struct fio_option *o, unsigned int *ip)
+static struct gopt *gopt_new_combo_int(struct fio_option *o, unsigned int *ip,
+                                      unsigned int idx)
 {
-       struct gopt_combo *combo;
+       struct gopt_combo *c;
        struct value_pair *vp;
        int i, active = 0;
 
-       combo = __gopt_new_combo(o);
+       c = __gopt_new_combo(o, idx);
 
        i = 0;
        vp = &o->posval[0];
        while (vp->ival) {
-               gtk_combo_box_append_text(GTK_COMBO_BOX(combo->combo), vp->ival);
+               gtk_combo_box_append_text(GTK_COMBO_BOX(c->combo), vp->ival);
                if (ip && vp->oval == *ip)
                        active = i;
                vp++;
                i++;
        }
 
-       gtk_combo_box_set_active(GTK_COMBO_BOX(combo->combo), active);
-       return &combo->gopt;
+       gtk_combo_box_set_active(GTK_COMBO_BOX(c->combo), active);
+       c->gopt.sig_handler = g_signal_connect(GTK_OBJECT(c->combo), "changed", G_CALLBACK(gopt_combo_changed), c);
+       return &c->gopt;
+}
+
+static struct gopt *gopt_new_str_multi(struct fio_option *o, unsigned int idx)
+{
+       struct gopt_str_multi *m;
+       struct value_pair *vp;
+       GtkWidget *frame, *hbox;
+       int i;
+
+       m = malloc(sizeof(*m));
+       memset(m, 0, sizeof(*m));
+       m->gopt.box = gtk_hbox_new(FALSE, 3);
+       gopt_mark_index(&m->gopt, idx);
+
+       if (!o->lname)
+               frame = gtk_frame_new(o->name);
+       else
+               frame = gtk_frame_new(o->lname);
+       gtk_box_pack_start(GTK_BOX(m->gopt.box), frame, FALSE, FALSE, 3);
+
+       hbox = gtk_hbox_new(FALSE, 3);
+       gtk_container_add(GTK_CONTAINER(frame), hbox);
+
+       i = 0;
+       vp = &o->posval[0];
+       while (vp->ival) {
+               m->checks[i] = gtk_check_button_new_with_label(vp->ival);
+               gtk_widget_set_tooltip_text(m->checks[i], vp->help);
+               gtk_box_pack_start(GTK_BOX(hbox), m->checks[i], FALSE, FALSE, 3);
+               vp++;
+       }
+
+       return &m->gopt;
 }
 
-static struct gopt *__gopt_new_int(struct fio_option *o, unsigned long long *p)
+static void gopt_int_changed(GtkSpinButton *spin, gpointer data)
+{
+       struct gopt_int *i = (struct gopt_int *) data;
+       struct fio_option *o = &fio_options[i->gopt.opt_index];
+       GtkAdjustment *adj;
+       int value, delta;
+
+       adj = gtk_spin_button_get_adjustment(spin);
+       value = gtk_adjustment_get_value(adj);
+       delta = value - i->lastval;
+       i->lastval = value;
+
+       if (o->inv_opt) {
+               struct gopt *b_inv = o->inv_opt->gui_data;
+               struct gopt_int *i_inv = container_of(b_inv, struct gopt_int, gopt);
+               int cur_val;
+
+               assert(o->type == o->inv_opt->type);
+
+               cur_val = gtk_spin_button_get_value(GTK_SPIN_BUTTON(i_inv->spin));
+               cur_val -= delta;
+               g_signal_handler_block(G_OBJECT(i_inv->spin), i_inv->gopt.sig_handler);
+               gtk_spin_button_set_value(GTK_SPIN_BUTTON(i_inv->spin), cur_val);
+               g_signal_handler_unblock(G_OBJECT(i_inv->spin), i_inv->gopt.sig_handler);
+       }
+}
+
+static void gopt_int_destroy(GtkWidget *w, gpointer data)
+{
+       struct gopt_int *i = (struct gopt_int *) data;
+
+       free(i);
+       gtk_widget_destroy(w);
+}
+
+static struct gopt_int *__gopt_new_int(struct fio_option *o,
+                                      unsigned long long *p, unsigned int idx)
 {
        unsigned long long defval;
        struct gopt_int *i;
-       guint maxval;
+       guint maxval, interval;
        GtkWidget *label;
 
        i = malloc(sizeof(*i));
+       memset(i, 0, sizeof(*i));
        i->gopt.box = gtk_hbox_new(FALSE, 3);
-       label = gtk_label_new(o->name);
-       gtk_box_pack_start(GTK_BOX(i->gopt.box), label, FALSE, FALSE, 0);
+       if (!o->lname)
+               label = gtk_label_new(o->name);
+       else
+               label = gtk_label_new(o->lname);
 
        maxval = o->maxval;
        if (!maxval)
@@ -154,65 +381,177 @@ static struct gopt *__gopt_new_int(struct fio_option *o, unsigned long long *p)
                defval = val;
        }
 
-       i->spin = gtk_spin_button_new_with_range(o->minval, maxval, 1.0);
+       interval = 1.0;
+       if (o->interval)
+               interval = o->interval;
+
+       i->spin = gtk_spin_button_new_with_range(o->minval, maxval, interval);
+       gopt_mark_index(&i->gopt, idx);
        gtk_spin_button_set_update_policy(GTK_SPIN_BUTTON(i->spin), GTK_UPDATE_IF_VALID);
        gtk_spin_button_set_value(GTK_SPIN_BUTTON(i->spin), defval);
+       i->lastval = defval;
+       i->gopt.sig_handler = g_signal_connect(G_OBJECT(i->spin), "value-changed", G_CALLBACK(gopt_int_changed), i);
+       g_signal_connect(G_OBJECT(i->spin), "destroy", G_CALLBACK(gopt_int_destroy), i);
 
        gtk_box_pack_start(GTK_BOX(i->gopt.box), i->spin, FALSE, FALSE, 0);
-       return &i->gopt;
+       gtk_box_pack_start(GTK_BOX(i->gopt.box), label, FALSE, FALSE, 0);
+
+       return i;
 }
 
-static struct gopt *gopt_new_int(struct fio_option *o, unsigned int *ip)
+static struct gopt *gopt_new_int(struct fio_option *o, unsigned int *ip,
+                                unsigned int idx)
 {
        unsigned long long ullp;
+       struct gopt_int *i;
 
        if (ip) {
                ullp = *ip;
-               return __gopt_new_int(o, &ullp);
+               i = __gopt_new_int(o, &ullp, idx);
+       } else
+               i = __gopt_new_int(o, NULL, idx);
+
+       return &i->gopt;
+}
+
+static struct gopt *gopt_new_ullong(struct fio_option *o, unsigned long long *p,
+                                   unsigned int idx)
+{
+       struct gopt_int *i;
+
+       i = __gopt_new_int(o, p, idx);
+       return &i->gopt;
+}
+
+static void gopt_bool_toggled(GtkToggleButton *button, gpointer data)
+{
+       struct gopt_bool *b = (struct gopt_bool *) data;
+       struct fio_option *o = &fio_options[b->gopt.opt_index];
+       gboolean set;
+
+       set = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(b->check));
+
+       if (o->inv_opt) {
+               struct gopt *g_inv = o->inv_opt->gui_data;
+               struct gopt_bool *b_inv = container_of(g_inv, struct gopt_bool, gopt);
+
+               assert(o->type == o->inv_opt->type);
+
+               g_signal_handler_block(G_OBJECT(b_inv->check), b_inv->gopt.sig_handler);
+               gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(b_inv->check), !set);
+               g_signal_handler_unblock(G_OBJECT(b_inv->check), b_inv->gopt.sig_handler);
        }
 
-       return __gopt_new_int(o, NULL);
+       gopt_set_children_visible(o, set);
 }
 
-static struct gopt *gopt_new_ullong(struct fio_option *o, unsigned long long *p)
+static void gopt_bool_destroy(GtkWidget *w, gpointer data)
 {
-       return __gopt_new_int(o, p);
+       struct gopt_bool *b = (struct gopt_bool *) data;
+
+       free(b);
+       gtk_widget_destroy(w);
 }
 
-static struct gopt *gopt_new_bool(struct fio_option *o, unsigned int *val)
+static struct gopt *gopt_new_bool(struct fio_option *o, unsigned int *val,
+                                 unsigned int idx)
 {
        struct gopt_bool *b;
        GtkWidget *label;
        int defstate = 0;
 
        b = malloc(sizeof(*b));
+       memset(b, 0, sizeof(*b));
        b->gopt.box = gtk_hbox_new(FALSE, 3);
-       label = gtk_label_new(o->name);
-       gtk_box_pack_start(GTK_BOX(b->gopt.box), label, FALSE, FALSE, 0);
+       if (!o->lname)
+               label = gtk_label_new(o->name);
+       else
+               label = gtk_label_new(o->lname);
 
        b->check = gtk_check_button_new();
+       gopt_mark_index(&b->gopt, idx);
        if (val)
                defstate = *val;
        else if (o->def && !strcmp(o->def, "1"))
                defstate = 1;
 
+       if (o->neg)
+               defstate = !defstate;
+
        gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(b->check), defstate);
+       b->gopt.sig_handler = g_signal_connect(G_OBJECT(b->check), "toggled", G_CALLBACK(gopt_bool_toggled), b);
+       g_signal_connect(G_OBJECT(b->check), "destroy", G_CALLBACK(gopt_bool_destroy), b);
 
        gtk_box_pack_start(GTK_BOX(b->gopt.box), b->check, FALSE, FALSE, 0);
+       gtk_box_pack_start(GTK_BOX(b->gopt.box), label, FALSE, FALSE, 0);
        return &b->gopt;
 }
 
-static struct gopt *gopt_new_int_range(struct fio_option *o, unsigned int **ip)
+/*
+ * These are paired 0/1 and 2/3. 0/2 are min values, 1/3 are max values.
+ * If the max is made smaller than min, adjust min down.
+ * If the min is made larger than max, adjust the max.
+ */
+static void range_value_changed(GtkSpinButton *spin, gpointer data)
+{
+       struct gopt_range *r = (struct gopt_range *) data;
+       int changed = -1, i;
+       gint val, mval;
+
+       for (i = 0; i < GOPT_RANGE_SPIN; i++) {
+               if (GTK_SPIN_BUTTON(r->spins[i]) == spin) {
+                       changed = i;
+                       break;
+               }
+       }
+
+       assert(changed != -1);
+
+       /*
+        * Min changed
+        */
+       if (changed == 0 || changed == 2) {
+               GtkWidget *mspin = r->spins[changed + 1];
+
+               val = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(r->spins[changed]));
+               mval = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(mspin));
+               if (val > mval)
+                       gtk_spin_button_set_value(GTK_SPIN_BUTTON(mspin), val);
+       } else {
+               GtkWidget *mspin = r->spins[changed - 1];
+
+               val = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(r->spins[changed]));
+               mval = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(mspin));
+               if (val < mval)
+                       gtk_spin_button_set_value(GTK_SPIN_BUTTON(mspin), val);
+       }
+}
+
+static void gopt_range_destroy(GtkWidget *w, gpointer data)
+{
+       struct gopt_range *r = (struct gopt_range *) data;
+
+       free(r);
+       gtk_widget_destroy(w);
+}
+
+static struct gopt *gopt_new_int_range(struct fio_option *o, unsigned int **ip,
+                                      unsigned int idx)
 {
        struct gopt_range *r;
        gint maxval, defval;
        GtkWidget *label;
+       guint interval;
        int i;
 
        r = malloc(sizeof(*r));
+       memset(r, 0, sizeof(*r));
        r->gopt.box = gtk_hbox_new(FALSE, 3);
-       label = gtk_label_new(o->name);
-       gtk_box_pack_start(GTK_BOX(r->gopt.box), label, FALSE, FALSE, 0);
+       gopt_mark_index(&r->gopt, idx);
+       if (!o->lname)
+               label = gtk_label_new(o->name);
+       else
+               label = gtk_label_new(o->lname);
 
        maxval = o->maxval;
        if (!maxval)
@@ -226,8 +565,12 @@ static struct gopt *gopt_new_int_range(struct fio_option *o, unsigned int **ip)
                defval = val;
        }
 
-       for (i = 0; i < 4; i++) {
-               r->spins[i] = gtk_spin_button_new_with_range(o->minval, maxval, 512);
+       interval = 1.0;
+       if (o->interval)
+               interval = o->interval;
+
+       for (i = 0; i < GOPT_RANGE_SPIN; i++) {
+               r->spins[i] = gtk_spin_button_new_with_range(o->minval, maxval, interval);
                gtk_spin_button_set_update_policy(GTK_SPIN_BUTTON(r->spins[i]), GTK_UPDATE_IF_VALID);
                if (ip)
                        gtk_spin_button_set_value(GTK_SPIN_BUTTON(r->spins[i]), *ip[i]);
@@ -235,25 +578,114 @@ static struct gopt *gopt_new_int_range(struct fio_option *o, unsigned int **ip)
                        gtk_spin_button_set_value(GTK_SPIN_BUTTON(r->spins[i]), defval);
 
                gtk_box_pack_start(GTK_BOX(r->gopt.box), r->spins[i], FALSE, FALSE, 0);
+               g_signal_connect(G_OBJECT(r->spins[i]), "value-changed", G_CALLBACK(range_value_changed), r);
        }
 
+       gtk_box_pack_start(GTK_BOX(r->gopt.box), label, FALSE, FALSE, 0);
+       g_signal_connect(G_OBJECT(r->gopt.box), "destroy", G_CALLBACK(gopt_range_destroy), r);
        return &r->gopt;
 }
 
+static void gopt_str_val_destroy(GtkWidget *w, gpointer data)
+{
+       struct gopt_str_val *g = (struct gopt_str_val *) data;
+
+       free(g);
+       gtk_widget_destroy(w);
+}
+
+static void gopt_str_val_spin_wrapped(GtkSpinButton *spin, gpointer data)
+{
+       struct gopt_str_val *g = (struct gopt_str_val *) data;
+       unsigned int val;
+       GtkAdjustment *adj;
+       gint index;
+
+       adj = gtk_spin_button_get_adjustment(spin);
+       val = gtk_adjustment_get_value(adj);
+
+       /*
+        * Can't rely on exact value, as fast changes increment >= 1
+        */
+       if (!val) {
+               index = gtk_combo_box_get_active(GTK_COMBO_BOX(g->combo));
+               if (index + 1 <= g->maxindex) {
+                       val = 1;
+                       gtk_combo_box_set_active(GTK_COMBO_BOX(g->combo), ++index);
+               } else
+                       val = 1023;
+               gtk_spin_button_set_value(spin, val);
+       } else {
+               index = gtk_combo_box_get_active(GTK_COMBO_BOX(g->combo));
+               if (index) {
+                       gtk_combo_box_set_active(GTK_COMBO_BOX(g->combo), --index);
+                       gtk_spin_button_set_value(spin, 1023);
+               } else
+                       gtk_spin_button_set_value(spin, 0);
+       }
+}
+
+static struct gopt *gopt_new_str_val(struct fio_option *o,
+                                    unsigned long long *p, unsigned int idx)
+{
+       struct gopt_str_val *g;
+       const gchar *postfix[] = { "B", "KB", "MB", "GB", "PB", "TB", "" };
+       GtkWidget *label;
+       int i;
+
+       g = malloc(sizeof(*g));
+       memset(g, 0, sizeof(*g));
+       g->gopt.box = gtk_hbox_new(FALSE, 3);
+       if (!o->lname)
+               label = gtk_label_new(o->name);
+       else
+               label = gtk_label_new(o->lname);
+       gopt_mark_index(&g->gopt, idx);
+
+       g->spin = gtk_spin_button_new_with_range(0.0, 1023.0, 1.0);
+       gtk_spin_button_set_update_policy(GTK_SPIN_BUTTON(g->spin), GTK_UPDATE_IF_VALID);
+       gtk_spin_button_set_value(GTK_SPIN_BUTTON(g->spin), 0);
+       gtk_spin_button_set_wrap(GTK_SPIN_BUTTON(g->spin), 1);
+       gtk_box_pack_start(GTK_BOX(g->gopt.box), g->spin, FALSE, FALSE, 0);
+       g_signal_connect(G_OBJECT(g->spin), "wrapped", G_CALLBACK(gopt_str_val_spin_wrapped), g);
+
+       g->combo = gtk_combo_box_new_text();
+       i = 0;
+       while (strlen(postfix[i])) {
+               gtk_combo_box_append_text(GTK_COMBO_BOX(g->combo), postfix[i]);
+               i++;
+       }
+       g->maxindex = i - 1;
+       gtk_combo_box_set_active(GTK_COMBO_BOX(g->combo), 0);
+       gtk_box_pack_start(GTK_BOX(g->gopt.box), g->combo, FALSE, FALSE, 0);
+       gtk_box_pack_start(GTK_BOX(g->gopt.box), label, FALSE, FALSE, 3);
+
+       g_signal_connect(G_OBJECT(g->gopt.box), "destroy", G_CALLBACK(gopt_str_val_destroy), g);
+       return &g->gopt;
+}
+
 static void gopt_add_option(GtkWidget *hbox, struct fio_option *o,
                            unsigned int opt_index, struct thread_options *to)
 {
        struct gopt *go = NULL;
 
        switch (o->type) {
-       case FIO_OPT_STR_VAL:
+       case FIO_OPT_STR_VAL: {
+               unsigned long long *ullp = NULL;
+
+               if (o->off1)
+                       ullp = td_var(to, o->off1);
+
+               go = gopt_new_str_val(o, ullp, opt_index);
+               break;
+               }
        case FIO_OPT_STR_VAL_TIME: {
                unsigned long long *ullp = NULL;
 
                if (o->off1)
                        ullp = td_var(to, o->off1);
 
-               go = gopt_new_ullong(o, ullp);
+               go = gopt_new_ullong(o, ullp, opt_index);
                break;
                }
        case FIO_OPT_INT: {
@@ -262,7 +694,7 @@ static void gopt_add_option(GtkWidget *hbox, struct fio_option *o,
                if (o->off1)
                        ip = td_var(to, o->off1);
 
-               go = gopt_new_int(o, ip);
+               go = gopt_new_int(o, ip, opt_index);
                break;
                }
        case FIO_OPT_STR_SET:
@@ -272,36 +704,42 @@ static void gopt_add_option(GtkWidget *hbox, struct fio_option *o,
                if (o->off1)
                        ip = td_var(to, o->off1);
 
-               go = gopt_new_bool(o, ip);
+               go = gopt_new_bool(o, ip, opt_index);
                break;
                }
        case FIO_OPT_STR: {
-               unsigned int *ip = NULL;
+               if (o->posval[0].ival) {
+                       unsigned int *ip = NULL;
 
-               if (o->off1)
-                       ip = td_var(to, o->off1);
+                       if (o->off1)
+                               ip = td_var(to, o->off1);
+
+                       go = gopt_new_combo_int(o, ip, opt_index);
+               } else {
+                       /* TODO: usually ->cb, or unsigned int pointer */
+                       go = gopt_new_str_store(o, NULL, opt_index);
+               }
 
-               go = gopt_new_combo_int(o, ip);
                break;
                }
        case FIO_OPT_STR_STORE: {
                char *text = NULL;
 
-               if (o->off1 && !o->cb) {
+               if (o->off1) {
                        char **p = td_var(to, o->off1);
                        text = *p;
                }
 
                if (!o->posval[0].ival) {
-                       go = gopt_new_str_store(o, text);
+                       go = gopt_new_str_store(o, text, opt_index);
                        break;
                }
 
-               go = gopt_new_combo_str(o, text);
+               go = gopt_new_combo_str(o, text, opt_index);
                break;
                }
        case FIO_OPT_STR_MULTI:
-               go = gopt_new_combo_str(o, NULL);
+               go = gopt_new_str_multi(o, opt_index);
                break;
        case FIO_OPT_RANGE: {
                unsigned int *ip[4] = { td_var(to, o->off1),
@@ -309,7 +747,7 @@ static void gopt_add_option(GtkWidget *hbox, struct fio_option *o,
                                        td_var(to, o->off3),
                                        td_var(to, o->off4) };
 
-               go = gopt_new_int_range(o, ip);
+               go = gopt_new_int_range(o, ip, opt_index);
                break;
                }
        /* still need to handle this one */
@@ -323,12 +761,19 @@ static void gopt_add_option(GtkWidget *hbox, struct fio_option *o,
        }
 
        if (go) {
+               GtkWidget *dest;
+
                if (o->help)
                        gtk_widget_set_tooltip_text(go->box, o->help);
-       
-               gtk_box_pack_start(GTK_BOX(hbox), go->box, FALSE, FALSE, 5);
-               go->opt_index = opt_index;
+
                go->opt_type = o->type;
+               o->gui_data = go;
+
+               dest = gopt_get_group_frame(hbox, o->group);
+               if (!dest)
+                       gtk_box_pack_start(GTK_BOX(hbox), go->box, FALSE, FALSE, 5);
+               else
+                       gtk_box_pack_start(GTK_BOX(dest), go->box, FALSE, FALSE, 5);
        }
 }
 
@@ -337,10 +782,35 @@ static void gopt_add_options(GtkWidget **vboxes, struct thread_options *to)
        GtkWidget *hbox = NULL;
        int i;
 
+       gopt_dep_tree = g_node_new(NULL);
+
+       /*
+        * First add all options
+        */
        for (i = 0; fio_options[i].name; i++) {
                struct fio_option *o = &fio_options[i];
                unsigned int mask = o->category;
                struct opt_group *og;
+               GNode *node, *nparent;
+
+               /*
+                * Insert node with either the root parent, or an
+                * option parent.
+                */
+               node = g_node_new(o);
+               nparent = gopt_dep_tree;
+               if (o->parent) {
+                       struct fio_option *parent;
+
+                       parent = fio_option_find(o->parent);
+                       nparent = g_node_find(gopt_dep_tree, G_IN_ORDER, G_TRAVERSE_ALL, parent);
+                       if (!nparent) {
+                               log_err("fio: did not find parent %s for opt %s\n", o->name, o->parent);
+                               nparent = gopt_dep_tree;
+                       }
+               }
+
+               g_node_insert(nparent, -1, node);
 
                while ((og = opt_group_from_mask(&mask)) != NULL) {
                        GtkWidget *vbox = vboxes[ffz(~og->mask)];
@@ -372,8 +842,9 @@ static GtkWidget *gopt_add_group_tab(GtkWidget *notebook, struct opt_group *og)
 static void gopt_add_group_tabs(GtkWidget *notebook, GtkWidget **vbox)
 {
        struct opt_group *og;
-       unsigned int i = 0;
+       unsigned int i;
 
+       i = 0;
        do {
                unsigned int mask = (1U << i);
 
@@ -388,7 +859,7 @@ static void gopt_add_group_tabs(GtkWidget *notebook, GtkWidget **vbox)
 void gopt_get_options_window(GtkWidget *window, struct thread_options *o)
 {
        GtkWidget *dialog, *notebook;
-       GtkWidget *vboxes[__FIO_OPT_G_NR];
+       GtkWidget *vboxes[__FIO_OPT_C_NR];
 
        dialog = gtk_dialog_new_with_buttons("Fio options",
                        GTK_WINDOW(window), GTK_DIALOG_DESTROY_WITH_PARENT,
@@ -411,4 +882,9 @@ void gopt_get_options_window(GtkWidget *window, struct thread_options *o)
        gtk_dialog_run(GTK_DIALOG(dialog));
 
        gtk_widget_destroy(dialog);
+
+       g_node_destroy(gopt_dep_tree);
+       gopt_dep_tree = NULL;
+       memset(gopt_widgets, 0, sizeof(gopt_widgets));
+       memset(gopt_g_widgets, 0, sizeof(gopt_g_widgets));
 }