gcompat: provide backwards compatible functions for older gtk versions
[fio.git] / goptions.c
index b8ebaf9a3252a72f3764c5904352c398028ac989..e74eb125c0f4fd87ab41d33b2695f102e899d7bb 100644 (file)
@@ -16,6 +16,8 @@ struct gopt {
        unsigned int opt_index;
        unsigned int opt_type;
        gulong sig_handler;
+       struct gopt_job_view *gjv;
+       struct flist_head changed_list;
 };
 
 struct gopt_combo {
@@ -58,15 +60,35 @@ struct gopt_str_multi {
        GtkWidget *checks[PARSE_MAX_VP];
 };
 
-static GtkWidget *gopt_widgets[FIO_MAX_OPTS];
+enum {
+       GOPT_COMBO_INT = 1,
+       GOPT_COMBO_STR,
+       GOPT_INT,
+       GOPT_BOOL,
+       GOPT_STR,
+       GOPT_STR_VAL,
+       GOPT_RANGE,
+       GOPT_STR_MULTI,
+};
 
 struct gopt_frame_widget {
        GtkWidget *vbox[2];
        unsigned int nr;
 };
-static struct gopt_frame_widget gopt_g_widgets[__FIO_OPT_G_NR];
 
-static GtkWidget *gopt_get_group_frame(GtkWidget *box, unsigned int groupmask)
+struct gopt_job_view {
+       struct flist_head list;
+       struct gopt_frame_widget g_widgets[__FIO_OPT_G_NR];
+       GtkWidget *widgets[FIO_MAX_OPTS];
+       GtkWidget *vboxes[__FIO_OPT_C_NR];
+       struct flist_head changed_list;
+       struct thread_options *o;
+};
+
+static GNode *gopt_dep_tree;
+
+static GtkWidget *gopt_get_group_frame(struct gopt_job_view *gjv,
+                                      GtkWidget *box, unsigned int groupmask)
 {
        unsigned int mask, group;
        struct opt_group *og;
@@ -82,7 +104,7 @@ static GtkWidget *gopt_get_group_frame(GtkWidget *box, unsigned int groupmask)
                return NULL;
 
        group = ffz(~groupmask);
-       gfw = &gopt_g_widgets[group];
+       gfw = &gjv->g_widgets[group];
        if (!gfw->vbox[0]) {
                frame = gtk_frame_new(og->name);
                gtk_box_pack_start(GTK_BOX(box), frame, FALSE, FALSE, 3);
@@ -102,33 +124,59 @@ static GtkWidget *gopt_get_group_frame(GtkWidget *box, unsigned int groupmask)
 /*
  * Mark children as invisible, if needed.
  */
-static void gopt_set_children_visible(struct fio_option *parent,
+static void gopt_set_children_visible(struct gopt_job_view *gjv,
+                                     struct fio_option *parent,
                                      gboolean visible)
 {
-       struct fio_option *o;
-       int i;
+       GNode *child, *node;
 
        if (parent->hide_on_set)
                visible = !visible;
 
-       /*
-        * This isn't super fast, but it should not be an issue. If it is, we
-        * can speed it up by caching the lookup at least. Or we can do it
-        * once, at init time.
-        */
-       for (i = 0; fio_options[i].name; i++) {
-               o = &fio_options[i];
-               if (!o->parent || !o->hide)
-                       continue;
+       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;
 
-               if (strcmp(parent->name, o->parent))
-                       continue;
+               /*
+                * Recurse into child, if it also has children
+                */
+               if (g_node_n_children(child))
+                       gopt_set_children_visible(gjv, o, visible);
 
-               if (gopt_widgets[i])
-                       gtk_widget_set_sensitive(gopt_widgets[i], visible);
+               if (gjv->widgets[g->opt_index])
+                       gtk_widget_set_sensitive(gjv->widgets[g->opt_index], visible);
+
+               child = g_node_next_sibling(child);
        }
 }
 
+static void gopt_mark_index(struct gopt_job_view *gjv, struct gopt *gopt,
+                           unsigned int idx, int type)
+{
+       INIT_FLIST_HEAD(&gopt->changed_list);
+       g_object_ref(G_OBJECT(gopt->box));
+
+       assert(!gjv->widgets[idx]);
+       gopt->opt_index = idx;
+       gopt->opt_type = type;
+       gopt->gjv = gjv;
+       gjv->widgets[idx] = gopt->box;
+}
+
+static void gopt_changed(struct gopt *gopt)
+{
+       struct gopt_job_view *gjv = gopt->gjv;
+
+       /*
+        * Add to changed list. This also prevents the option from being
+        * freed when the widget is destroyed.
+        */
+       if (flist_empty(&gopt->changed_list))
+               flist_add_tail(&gopt->changed_list, &gjv->changed_list);
+}
+
 static void gopt_str_changed(GtkEntry *entry, gpointer data)
 {
        struct gopt_str *s = (struct gopt_str *) data;
@@ -136,34 +184,32 @@ static void gopt_str_changed(GtkEntry *entry, gpointer data)
        const gchar *text;
        int set;
 
+       gopt_changed(&s->gopt);
+
        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;
+       gopt_set_children_visible(s->gopt.gjv, o, set);
 }
 
 static void gopt_str_destroy(GtkWidget *w, gpointer data)
 {
        struct gopt_str *s = (struct gopt_str *) data;
 
-       free(s);
+       if (flist_empty(&s->gopt.changed_list))
+               free(s);
+
        gtk_widget_destroy(w);
 }
 
-static struct gopt *gopt_new_str_store(struct fio_option *o, const char *text,
+static struct gopt *gopt_new_str_store(struct gopt_job_view *gjv,
+                                      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 = calloc(1, sizeof(*s));
 
        s->gopt.box = gtk_hbox_new(FALSE, 3);
        if (!o->lname)
@@ -172,20 +218,19 @@ static struct gopt *gopt_new_str_store(struct fio_option *o, const char *text,
                label = gtk_label_new(o->lname);
 
        s->entry = gtk_entry_new();
-       gopt_mark_index(&s->gopt, idx);
+       gopt_mark_index(gjv, &s->gopt, idx, GOPT_STR);
        if (text)
                gtk_entry_set_text(GTK_ENTRY(s->entry), text);
-       gtk_entry_set_editable(GTK_ENTRY(s->entry), 1);
+       gtk_editable_set_editable(GTK_EDITABLE(s->entry), 1);
 
        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);
+       s->gopt.sig_handler = g_signal_connect(G_OBJECT(s->entry), "changed", G_CALLBACK(gopt_str_changed), s);
+       g_signal_connect(G_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);
-       o->gui_data = s;
        return &s->gopt;
 }
 
@@ -193,26 +238,33 @@ 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;
 
-       printf("combo %s changed\n", o->name);
+       gopt_changed(&c->gopt);
+
+       index = gtk_combo_box_get_active(GTK_COMBO_BOX(c->combo));
+
+       gopt_set_children_visible(c->gopt.gjv, o, index);
 }
 
 static void gopt_combo_destroy(GtkWidget *w, gpointer data)
 {
        struct gopt_combo *c = (struct gopt_combo *) data;
 
-       free(c);
+       if (flist_empty(&c->gopt.changed_list))
+               free(c);
+
        gtk_widget_destroy(w);
 }
 
-static struct gopt_combo *__gopt_new_combo(struct fio_option *o,
-                                          unsigned int idx)
+static struct gopt_combo *__gopt_new_combo(struct gopt_job_view *gjv,
+                                          struct fio_option *o,
+                                          unsigned int idx, int type)
 {
        struct gopt_combo *c;
        GtkWidget *label;
 
-       c = malloc(sizeof(*c));
-       memset(c, 0, sizeof(*c));
+       c = calloc(1, sizeof(*c));
 
        c->gopt.box = gtk_hbox_new(FALSE, 3);
        if (!o->lname)
@@ -220,30 +272,30 @@ static struct gopt_combo *__gopt_new_combo(struct fio_option *o,
        else
                label = gtk_label_new(o->lname);
 
-       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);
+       c->combo = gtk_combo_box_text_new();
+       gopt_mark_index(gjv, &c->gopt, idx, type);
+       g_signal_connect(G_OBJECT(c->combo), "destroy", G_CALLBACK(gopt_combo_destroy), c);
 
        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);
 
-       o->gui_data = c;
        return c;
 }
 
-static struct gopt *gopt_new_combo_str(struct fio_option *o, const char *text,
+static struct gopt *gopt_new_combo_str(struct gopt_job_view *gjv,
+                                      struct fio_option *o, const char *text,
                                       unsigned int idx)
 {
        struct gopt_combo *c;
        struct value_pair *vp;
        int i, active = 0;
 
-       c = __gopt_new_combo(o, idx);
+       c = __gopt_new_combo(gjv, o, idx, GOPT_COMBO_STR);
 
        i = 0;
        vp = &o->posval[0];
        while (vp->ival) {
-               gtk_combo_box_append_text(GTK_COMBO_BOX(c->combo), vp->ival);
+               gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(c->combo), vp->ival);
                if (o->def && !strcmp(vp->ival, o->def))
                        active = i;
                if (text && !strcmp(vp->ival, text))
@@ -253,23 +305,24 @@ static struct gopt *gopt_new_combo_str(struct fio_option *o, const char *text,
        }
 
        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);
+       c->gopt.sig_handler = g_signal_connect(G_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 gopt_job_view *gjv,
+                                      struct fio_option *o, unsigned int *ip,
                                       unsigned int idx)
 {
        struct gopt_combo *c;
        struct value_pair *vp;
        int i, active = 0;
 
-       c = __gopt_new_combo(o, idx);
+       c = __gopt_new_combo(gjv, o, idx, GOPT_COMBO_INT);
 
        i = 0;
        vp = &o->posval[0];
        while (vp->ival) {
-               gtk_combo_box_append_text(GTK_COMBO_BOX(c->combo), vp->ival);
+               gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(c->combo), vp->ival);
                if (ip && vp->oval == *ip)
                        active = i;
                vp++;
@@ -277,21 +330,28 @@ static struct gopt *gopt_new_combo_int(struct fio_option *o, unsigned int *ip,
        }
 
        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);
+       c->gopt.sig_handler = g_signal_connect(G_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)
+static void gopt_str_multi_toggled(GtkToggleButton *button, gpointer data)
+{
+       struct gopt_str_multi *m = (struct gopt_str_multi *) data;
+
+       gopt_changed(&m->gopt);
+}
+
+static struct gopt *gopt_new_str_multi(struct gopt_job_view *gjv,
+                                      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 = calloc(1, sizeof(*m));
        m->gopt.box = gtk_hbox_new(FALSE, 3);
-       gopt_mark_index(&m->gopt, idx);
+       gopt_mark_index(gjv, &m->gopt, idx, GOPT_STR_MULTI);
 
        if (!o->lname)
                frame = gtk_frame_new(o->name);
@@ -308,7 +368,9 @@ static struct gopt *gopt_new_str_multi(struct fio_option *o, unsigned int idx)
                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);
+               g_signal_connect(G_OBJECT(m->checks[i]), "toggled", G_CALLBACK(gopt_str_multi_toggled), m);
                vp++;
+               i++;
        }
 
        return &m->gopt;
@@ -321,13 +383,16 @@ static void gopt_int_changed(GtkSpinButton *spin, gpointer data)
        GtkAdjustment *adj;
        int value, delta;
 
+       gopt_changed(&i->gopt);
+
        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_int *i_inv = o->inv_opt->gui_data;
+               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);
@@ -344,11 +409,14 @@ static void gopt_int_destroy(GtkWidget *w, gpointer data)
 {
        struct gopt_int *i = (struct gopt_int *) data;
 
-       free(i);
+       if (flist_empty(&i->gopt.changed_list))
+               free(i);
+
        gtk_widget_destroy(w);
 }
 
-static struct gopt_int *__gopt_new_int(struct fio_option *o,
+static struct gopt_int *__gopt_new_int(struct gopt_job_view *gjv,
+                                      struct fio_option *o,
                                       unsigned long long *p, unsigned int idx)
 {
        unsigned long long defval;
@@ -356,8 +424,7 @@ static struct gopt_int *__gopt_new_int(struct fio_option *o,
        guint maxval, interval;
        GtkWidget *label;
 
-       i = malloc(sizeof(*i));
-       memset(i, 0, sizeof(*i));
+       i = calloc(1, sizeof(*i));
        i->gopt.box = gtk_hbox_new(FALSE, 3);
        if (!o->lname)
                label = gtk_label_new(o->name);
@@ -383,7 +450,7 @@ static struct gopt_int *__gopt_new_int(struct fio_option *o,
                interval = o->interval;
 
        i->spin = gtk_spin_button_new_with_range(o->minval, maxval, interval);
-       gopt_mark_index(&i->gopt, idx);
+       gopt_mark_index(gjv, &i->gopt, idx, GOPT_INT);
        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;
@@ -393,11 +460,11 @@ static struct gopt_int *__gopt_new_int(struct fio_option *o,
        gtk_box_pack_start(GTK_BOX(i->gopt.box), i->spin, FALSE, FALSE, 0);
        gtk_box_pack_start(GTK_BOX(i->gopt.box), label, FALSE, FALSE, 0);
 
-       o->gui_data = i;
        return i;
 }
 
-static struct gopt *gopt_new_int(struct fio_option *o, unsigned int *ip,
+static struct gopt *gopt_new_int(struct gopt_job_view *gjv,
+                                struct fio_option *o, unsigned int *ip,
                                 unsigned int idx)
 {
        unsigned long long ullp;
@@ -405,19 +472,20 @@ static struct gopt *gopt_new_int(struct fio_option *o, unsigned int *ip,
 
        if (ip) {
                ullp = *ip;
-               i = __gopt_new_int(o, &ullp, idx);
+               i = __gopt_new_int(gjv, o, &ullp, idx);
        } else
-               i = __gopt_new_int(o, NULL, idx);
+               i = __gopt_new_int(gjv, o, NULL, idx);
 
        return &i->gopt;
 }
 
-static struct gopt *gopt_new_ullong(struct fio_option *o, unsigned long long *p,
+static struct gopt *gopt_new_ullong(struct gopt_job_view *gjv,
+                                   struct fio_option *o, unsigned long long *p,
                                    unsigned int idx)
 {
        struct gopt_int *i;
 
-       i = __gopt_new_int(o, p, idx);
+       i = __gopt_new_int(gjv, o, p, idx);
        return &i->gopt;
 }
 
@@ -427,10 +495,13 @@ static void gopt_bool_toggled(GtkToggleButton *button, gpointer data)
        struct fio_option *o = &fio_options[b->gopt.opt_index];
        gboolean set;
 
+       gopt_changed(&b->gopt);
+
        set = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(b->check));
 
        if (o->inv_opt) {
-               struct gopt_bool *b_inv = o->inv_opt->gui_data;
+               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);
 
@@ -439,26 +510,28 @@ static void gopt_bool_toggled(GtkToggleButton *button, gpointer data)
                g_signal_handler_unblock(G_OBJECT(b_inv->check), b_inv->gopt.sig_handler);
        }
 
-       gopt_set_children_visible(o, set);
+       gopt_set_children_visible(b->gopt.gjv, o, set);
 }
 
 static void gopt_bool_destroy(GtkWidget *w, gpointer data)
 {
        struct gopt_bool *b = (struct gopt_bool *) data;
 
-       free(b);
+       if (flist_empty(&b->gopt.changed_list))
+               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 gopt_job_view *gjv,
+                                 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 = calloc(1, sizeof(*b));
        b->gopt.box = gtk_hbox_new(FALSE, 3);
        if (!o->lname)
                label = gtk_label_new(o->name);
@@ -466,7 +539,7 @@ static struct gopt *gopt_new_bool(struct fio_option *o, unsigned int *val,
                label = gtk_label_new(o->lname);
 
        b->check = gtk_check_button_new();
-       gopt_mark_index(&b->gopt, idx);
+       gopt_mark_index(gjv, &b->gopt, idx, GOPT_BOOL);
        if (val)
                defstate = *val;
        else if (o->def && !strcmp(o->def, "1"))
@@ -481,7 +554,6 @@ static struct gopt *gopt_new_bool(struct fio_option *o, unsigned int *val,
 
        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);
-       o->gui_data = b;
        return &b->gopt;
 }
 
@@ -496,6 +568,8 @@ static void range_value_changed(GtkSpinButton *spin, gpointer data)
        int changed = -1, i;
        gint val, mval;
 
+       gopt_changed(&r->gopt);
+
        for (i = 0; i < GOPT_RANGE_SPIN; i++) {
                if (GTK_SPIN_BUTTON(r->spins[i]) == spin) {
                        changed = i;
@@ -529,11 +603,14 @@ static void gopt_range_destroy(GtkWidget *w, gpointer data)
 {
        struct gopt_range *r = (struct gopt_range *) data;
 
-       free(r);
+       if (flist_empty(&r->gopt.changed_list))
+               free(r);
+
        gtk_widget_destroy(w);
 }
 
-static struct gopt *gopt_new_int_range(struct fio_option *o, unsigned int **ip,
+static struct gopt *gopt_new_int_range(struct gopt_job_view *gjv,
+                                      struct fio_option *o, unsigned int **ip,
                                       unsigned int idx)
 {
        struct gopt_range *r;
@@ -542,10 +619,9 @@ static struct gopt *gopt_new_int_range(struct fio_option *o, unsigned int **ip,
        guint interval;
        int i;
 
-       r = malloc(sizeof(*r));
-       memset(r, 0, sizeof(*r));
+       r = calloc(1, sizeof(*r));
        r->gopt.box = gtk_hbox_new(FALSE, 3);
-       gopt_mark_index(&r->gopt, idx);
+       gopt_mark_index(gjv, &r->gopt, idx, GOPT_RANGE);
        if (!o->lname)
                label = gtk_label_new(o->name);
        else
@@ -581,7 +657,6 @@ static struct gopt *gopt_new_int_range(struct fio_option *o, unsigned int **ip,
 
        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);
-       o->gui_data = r;
        return &r->gopt;
 }
 
@@ -589,7 +664,9 @@ static void gopt_str_val_destroy(GtkWidget *w, gpointer data)
 {
        struct gopt_str_val *g = (struct gopt_str_val *) data;
 
-       free(g);
+       if (flist_empty(&g->gopt.changed_list))
+               free(g);
+
        gtk_widget_destroy(w);
 }
 
@@ -624,21 +701,30 @@ static void gopt_str_val_spin_wrapped(GtkSpinButton *spin, gpointer data)
        }
 }
 
-static struct gopt *gopt_new_str_val(struct fio_option *o,
+static void gopt_str_val_changed(GtkSpinButton *spin, gpointer data)
+{
+       struct gopt_str_val *g = (struct gopt_str_val *) data;
+
+       gopt_changed(&g->gopt);
+}
+
+static struct gopt *gopt_new_str_val(struct gopt_job_view *gjv,
+                                    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", "" };
+       unsigned long long val;
        GtkWidget *label;
        int i;
 
-       g = malloc(sizeof(*g));
-       memset(g, 0, sizeof(*g));
+       g = calloc(1, 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(gjv, &g->gopt, idx, GOPT_STR_VAL);
 
        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);
@@ -646,11 +732,12 @@ static struct gopt *gopt_new_str_val(struct fio_option *o,
        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_signal_connect(G_OBJECT(g->spin), "changed", G_CALLBACK(gopt_str_val_changed), g);
 
-       g->combo = gtk_combo_box_new_text();
+       g->combo = gtk_combo_box_text_new();
        i = 0;
        while (strlen(postfix[i])) {
-               gtk_combo_box_append_text(GTK_COMBO_BOX(g->combo), postfix[i]);
+               gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(g->combo), postfix[i]);
                i++;
        }
        g->maxindex = i - 1;
@@ -658,13 +745,33 @@ static struct gopt *gopt_new_str_val(struct fio_option *o,
        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);
 
+       /*
+        * Set the value
+        */
+       if (p) {
+               val = *p;
+               i = 0;
+               do {
+                       if (!val || (val % 1024))
+                               break;
+
+                       i++;
+                       val /= 1024;
+               } while (1);
+
+               gtk_spin_button_set_value(GTK_SPIN_BUTTON(g->spin), val);
+               gtk_combo_box_set_active(GTK_COMBO_BOX(g->combo), i);
+       }
+
+       g_signal_connect(G_OBJECT(g->combo), "changed", G_CALLBACK(gopt_str_val_changed), g);
+
        g_signal_connect(G_OBJECT(g->gopt.box), "destroy", G_CALLBACK(gopt_str_val_destroy), g);
-       o->gui_data = g;
        return &g->gopt;
 }
 
-static void gopt_add_option(GtkWidget *hbox, struct fio_option *o,
-                           unsigned int opt_index, struct thread_options *to)
+static void gopt_add_option(struct gopt_job_view *gjv, GtkWidget *hbox,
+                           struct fio_option *o, unsigned int opt_index,
+                           struct thread_options *to)
 {
        struct gopt *go = NULL;
 
@@ -675,7 +782,7 @@ static void gopt_add_option(GtkWidget *hbox, struct fio_option *o,
                if (o->off1)
                        ullp = td_var(to, o->off1);
 
-               go = gopt_new_str_val(o, ullp, opt_index);
+               go = gopt_new_str_val(gjv, o, ullp, opt_index);
                break;
                }
        case FIO_OPT_STR_VAL_TIME: {
@@ -684,7 +791,7 @@ static void gopt_add_option(GtkWidget *hbox, struct fio_option *o,
                if (o->off1)
                        ullp = td_var(to, o->off1);
 
-               go = gopt_new_ullong(o, ullp, opt_index);
+               go = gopt_new_ullong(gjv, o, ullp, opt_index);
                break;
                }
        case FIO_OPT_INT: {
@@ -693,7 +800,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, opt_index);
+               go = gopt_new_int(gjv, o, ip, opt_index);
                break;
                }
        case FIO_OPT_STR_SET:
@@ -703,7 +810,7 @@ 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, opt_index);
+               go = gopt_new_bool(gjv, o, ip, opt_index);
                break;
                }
        case FIO_OPT_STR: {
@@ -713,10 +820,10 @@ static void gopt_add_option(GtkWidget *hbox, struct fio_option *o,
                        if (o->off1)
                                ip = td_var(to, o->off1);
 
-                       go = gopt_new_combo_int(o, ip, opt_index);
+                       go = gopt_new_combo_int(gjv, o, ip, opt_index);
                } else {
                        /* TODO: usually ->cb, or unsigned int pointer */
-                       go = gopt_new_str_store(o, NULL, opt_index);
+                       go = gopt_new_str_store(gjv, o, NULL, opt_index);
                }
 
                break;
@@ -730,15 +837,15 @@ static void gopt_add_option(GtkWidget *hbox, struct fio_option *o,
                }
 
                if (!o->posval[0].ival) {
-                       go = gopt_new_str_store(o, text, opt_index);
+                       go = gopt_new_str_store(gjv, o, text, opt_index);
                        break;
                }
 
-               go = gopt_new_combo_str(o, text, opt_index);
+               go = gopt_new_combo_str(gjv, o, text, opt_index);
                break;
                }
        case FIO_OPT_STR_MULTI:
-               go = gopt_new_str_multi(o, opt_index);
+               go = gopt_new_str_multi(gjv, o, opt_index);
                break;
        case FIO_OPT_RANGE: {
                unsigned int *ip[4] = { td_var(to, o->off1),
@@ -746,7 +853,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, opt_index);
+               go = gopt_new_int_range(gjv, o, ip, opt_index);
                break;
                }
        /* still need to handle this one */
@@ -765,9 +872,9 @@ static void gopt_add_option(GtkWidget *hbox, struct fio_option *o,
                if (o->help)
                        gtk_widget_set_tooltip_text(go->box, o->help);
 
-               go->opt_type = o->type;
+               o->gui_data = go;
 
-               dest = gopt_get_group_frame(hbox, o->group);
+               dest = gopt_get_group_frame(gjv, hbox, o->group);
                if (!dest)
                        gtk_box_pack_start(GTK_BOX(hbox), go->box, FALSE, FALSE, 5);
                else
@@ -775,7 +882,8 @@ static void gopt_add_option(GtkWidget *hbox, struct fio_option *o,
        }
 }
 
-static void gopt_add_options(GtkWidget **vboxes, struct thread_options *to)
+static void gopt_add_options(struct gopt_job_view *gjv,
+                            struct thread_options *to)
 {
        GtkWidget *hbox = NULL;
        int i;
@@ -789,16 +897,16 @@ static void gopt_add_options(GtkWidget **vboxes, struct thread_options *to)
                struct opt_group *og;
 
                while ((og = opt_group_from_mask(&mask)) != NULL) {
-                       GtkWidget *vbox = vboxes[ffz(~og->mask)];
+                       GtkWidget *vbox = gjv->vboxes[ffz(~og->mask)];
 
                        hbox = gtk_hbox_new(FALSE, 3);
                        gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 5);
-                       gopt_add_option(hbox, o, i, to);
+                       gopt_add_option(gjv, hbox, o, i, to);
                }
        }
 }
 
-static GtkWidget *gopt_add_group_tab(GtkWidget *notebook, struct opt_group *og)
+static GtkWidget *gopt_add_tab(GtkWidget *notebook, const char *name)
 {
        GtkWidget *box, *vbox, *scroll;
 
@@ -810,12 +918,16 @@ static GtkWidget *gopt_add_group_tab(GtkWidget *notebook, struct opt_group *og)
        box = gtk_hbox_new(FALSE, 0);
        gtk_box_pack_start(GTK_BOX(vbox), box, FALSE, FALSE, 5);
        gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(scroll), vbox);
-       gtk_notebook_append_page(GTK_NOTEBOOK(notebook), scroll, gtk_label_new(og->name));
-
+       gtk_notebook_append_page(GTK_NOTEBOOK(notebook), scroll, gtk_label_new(name));
        return vbox;
 }
 
-static void gopt_add_group_tabs(GtkWidget *notebook, GtkWidget **vbox)
+static GtkWidget *gopt_add_group_tab(GtkWidget *notebook, struct opt_group *og)
+{
+       return gopt_add_tab(notebook, og->name);
+}
+
+static void gopt_add_group_tabs(GtkWidget *notebook, struct gopt_job_view *gjv)
 {
        struct opt_group *og;
        unsigned int i;
@@ -827,15 +939,245 @@ static void gopt_add_group_tabs(GtkWidget *notebook, GtkWidget **vbox)
                og = opt_group_from_mask(&mask);
                if (!og)
                        break;
-               vbox[i] = gopt_add_group_tab(notebook, og);
+               gjv->vboxes[i] = gopt_add_group_tab(notebook, og);
                i++;
        } while (1);
 }
 
-void gopt_get_options_window(GtkWidget *window, struct thread_options *o)
+static void gopt_handle_str_multi_changed(struct gopt_job_view *gjv,
+                                         struct gopt_str_multi *m,
+                                         struct fio_option *o)
 {
-       GtkWidget *dialog, *notebook;
-       GtkWidget *vboxes[__FIO_OPT_C_NR];
+       unsigned int *ip = td_var(gjv->o, o->off1);
+       struct value_pair *vp;
+       gboolean set;
+       guint val = 0;
+       int i;
+
+       i = 0;
+       vp = &o->posval[0];
+       while (vp->ival) {
+               if (!m->checks[i])
+                       break;
+               set = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(m->checks[i]));
+               if (set) {
+                       if (vp->or)
+                               val |= vp->oval;
+                       else
+                               val = vp->oval;
+               }
+               i++;
+               vp++;
+       }
+
+       if (o->off1)
+               *ip = val;
+}
+
+static void gopt_handle_range_changed(struct gopt_job_view *gjv,
+                                     struct gopt_range *r,
+                                     struct fio_option *o)
+{
+       unsigned int *ip[4] = { td_var(gjv->o, o->off1),
+                               td_var(gjv->o, o->off2),
+                               td_var(gjv->o, o->off3),
+                               td_var(gjv->o, o->off4) };
+       gint val;
+       int i;
+
+       for (i = 0; i < GOPT_RANGE_SPIN; i++) {
+               val = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(r->spins[i]));
+               *ip[i] = val;
+       }
+}
+
+static void gopt_handle_str_val_changed(struct gopt_job_view *gjv,
+                                       struct gopt_str_val *s,
+                                       struct fio_option *o)
+{
+       unsigned long long *ullp = td_var(gjv->o, o->off1);
+       GtkAdjustment *adj;
+       gint index;
+
+       if (!ullp)
+               return;
+
+       /*
+        * Numerical value
+        */
+       adj = gtk_spin_button_get_adjustment(GTK_SPIN_BUTTON(s->spin));
+       *ullp = gtk_adjustment_get_value(adj);
+
+       /*
+        * Multiplier
+        */
+       index = gtk_combo_box_get_active(GTK_COMBO_BOX(s->combo));
+       while (index--)
+               *ullp *= 1024ULL;
+}
+
+static void gopt_handle_str_changed(struct gopt_job_view *gjv,
+                                   struct gopt_str *s, struct fio_option *o)
+{
+       char **p = td_var(gjv->o, o->off1);
+
+       if (*p)
+               free(*p);
+
+       *p = strdup(gtk_entry_get_text(GTK_ENTRY(s->entry)));
+}
+
+static void gopt_handle_bool_changed(struct gopt_job_view *gjv,
+                                    struct gopt_bool *b, struct fio_option *o)
+{
+       unsigned int *ip = td_var(gjv->o, o->off1);
+       gboolean set;
+
+       set = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(b->check));
+       *ip = set;
+}
+
+static void gopt_handle_int_changed(struct gopt_job_view *gjv,
+                                   struct gopt_int *i, struct fio_option *o)
+{
+       unsigned int *ip = td_var(gjv->o, o->off1);
+       GtkAdjustment *adj;
+       guint val;
+
+       adj = gtk_spin_button_get_adjustment(GTK_SPIN_BUTTON(i->spin));
+       val = gtk_adjustment_get_value(adj);
+       *ip = val;
+}
+
+static void gopt_handle_combo_str_changed(struct gopt_job_view *gjv,
+                                         struct gopt_combo *c,
+                                         struct fio_option *o)
+{
+       char **p = td_var(gjv->o, o->off1);
+
+       if (*p)
+               free(*p);
+
+       *p = strdup(gtk_combo_box_text_get_active_text(GTK_COMBO_BOX_TEXT(c->combo)));
+}
+
+static void gopt_handle_combo_int_changed(struct gopt_job_view *gjv,
+                                         struct gopt_combo *c,
+                                         struct fio_option *o)
+{
+       unsigned int *ip = td_var(gjv->o, o->off1);
+       gint index;
+
+       index = gtk_combo_box_get_active(GTK_COMBO_BOX(c->combo));
+       *ip = o->posval[index].oval;
+}
+
+static void gopt_handle_changed(struct gopt *gopt)
+{
+       struct fio_option *o = &fio_options[gopt->opt_index];
+       struct gopt_job_view *gjv = gopt->gjv;
+       void *to_free = NULL;
+
+       switch (gopt->opt_type) {
+       case GOPT_COMBO_INT: {
+               struct gopt_combo *c;
+
+               c = container_of(gopt, struct gopt_combo, gopt);
+               gopt_handle_combo_int_changed(gjv, c, o);
+               to_free = c;
+               break;
+               }
+       case GOPT_COMBO_STR: {
+               struct gopt_combo *c;
+
+               c = container_of(gopt, struct gopt_combo, gopt);
+               gopt_handle_combo_str_changed(gjv, c, o);
+               to_free = c;
+               break;
+               }
+       case GOPT_INT: {
+               struct gopt_int *i;
+
+               i = container_of(gopt, struct gopt_int, gopt);
+               gopt_handle_int_changed(gjv, i, o);
+               to_free = i;
+               break;
+               }
+       case GOPT_BOOL: {
+               struct gopt_bool *b;
+
+               b = container_of(gopt, struct gopt_bool, gopt);
+               gopt_handle_bool_changed(gjv, b, o);
+               to_free = b;
+               break;
+               }
+       case GOPT_STR: {
+               struct gopt_str *s;
+
+               s = container_of(gopt, struct gopt_str, gopt);
+               gopt_handle_str_changed(gjv, s, o);
+               to_free = s;
+               break;
+               }
+       case GOPT_STR_VAL: {
+               struct gopt_str_val *s;
+
+               s = container_of(gopt, struct gopt_str_val, gopt);
+               gopt_handle_str_val_changed(gjv, s, o);
+               to_free = s;
+               break;
+               }
+       case GOPT_RANGE: {
+               struct gopt_range *r;
+
+               r = container_of(gopt, struct gopt_range, gopt);
+               gopt_handle_range_changed(gjv, r, o);
+               to_free = r;
+               break;
+               }
+       case GOPT_STR_MULTI: {
+               struct gopt_str_multi *m;
+
+               m = container_of(gopt, struct gopt_str_multi, gopt);
+               gopt_handle_str_multi_changed(gjv, m, o);
+               to_free = m;
+               break;
+               }
+       default:
+               log_err("gfio: bad option type %s/%d\n", gopt->opt_type);
+               return;
+       }
+
+       g_object_unref(G_OBJECT(gopt->box));
+       free(to_free);
+}
+
+static void gopt_handle_changed_options(struct gopt_job_view *gjv)
+{
+       struct gopt *gopt;
+
+       while (!flist_empty(&gjv->changed_list)) {
+               gopt = flist_entry(gjv->changed_list.next, struct gopt, changed_list);
+               flist_del(&gopt->changed_list);
+               gopt_handle_changed(gopt);
+       }
+}
+
+void gopt_get_options_window(GtkWidget *window, struct gfio_client *gc)
+{
+       GtkWidget *dialog, *notebook, *topnotebook, *vbox;
+       struct gfio_client_options *gco;
+       struct thread_options *o;
+       struct flist_head *entry;
+       struct gopt_job_view *gjv;
+       FLIST_HEAD(gjv_list);
+
+       /*
+        * Just choose the first item, we need to make each options
+        * entry the main notebook, with the below options view as
+        * a sub-notebook
+        */
+       assert(!flist_empty(&gc->o_list));
 
        dialog = gtk_dialog_new_with_buttons("Fio options",
                        GTK_WINDOW(window), GTK_DIALOG_DESTROY_WITH_PARENT,
@@ -844,20 +1186,89 @@ void gopt_get_options_window(GtkWidget *window, struct thread_options *o)
 
        gtk_widget_set_size_request(GTK_WIDGET(dialog), 1024, 768);
 
-       notebook = gtk_notebook_new();
-       gtk_notebook_set_scrollable(GTK_NOTEBOOK(notebook), 1);
-       gtk_notebook_popup_enable(GTK_NOTEBOOK(notebook));
-       gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox), notebook, TRUE, TRUE, 5);
-
-       gopt_add_group_tabs(notebook, vboxes);
-
-       gopt_add_options(vboxes, o);
+       topnotebook = gtk_notebook_new();
+       gtk_notebook_set_scrollable(GTK_NOTEBOOK(topnotebook), 1);
+       gtk_notebook_popup_enable(GTK_NOTEBOOK(topnotebook));
+       vbox = gtk_dialog_get_content_area(GTK_DIALOG(dialog));
+       gtk_box_pack_start(GTK_BOX(vbox), topnotebook, TRUE, TRUE, 5);
+
+       flist_for_each(entry, &gc->o_list) {
+               const char *name;
+
+               gco = flist_entry(entry, struct gfio_client_options, list);
+               o = &gco->o;
+               name = o->name;
+               if (!name || !strlen(name))
+                       name = "Default job";
+
+               vbox = gopt_add_tab(topnotebook, name);
+
+               notebook = gtk_notebook_new();
+               gtk_notebook_set_scrollable(GTK_NOTEBOOK(notebook), 1);
+               gtk_notebook_popup_enable(GTK_NOTEBOOK(notebook));
+               gtk_box_pack_start(GTK_BOX(vbox), notebook, TRUE, TRUE, 5);
+
+               gjv = calloc(1, sizeof(*gjv));
+               INIT_FLIST_HEAD(&gjv->list);
+               INIT_FLIST_HEAD(&gjv->changed_list);
+               gjv->o = o;
+               flist_add_tail(&gjv->list, &gjv_list);
+               gopt_add_group_tabs(notebook, gjv);
+               gopt_add_options(gjv, o);
+       }
 
        gtk_widget_show_all(dialog);
 
        gtk_dialog_run(GTK_DIALOG(dialog));
 
+       while (!flist_empty(&gjv_list)) {
+               gjv = flist_entry(gjv_list.next, struct gopt_job_view, list);
+
+               gopt_handle_changed_options(gjv);
+
+               flist_del(&gjv->list);
+               free(gjv);
+       }
+
        gtk_widget_destroy(dialog);
-       memset(gopt_widgets, 0, sizeof(gopt_widgets));
-       memset(gopt_g_widgets, 0, sizeof(gopt_g_widgets));
+}
+
+/*
+ * Build n-ary option dependency tree
+ */
+void gopt_init(void)
+{
+       int i;
+
+       gopt_dep_tree = g_node_new(NULL);
+
+       for (i = 0; fio_options[i].name; i++) {
+               struct fio_option *o = &fio_options[i];
+               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);
+       }
+}
+
+void gopt_exit(void)
+{
+       g_node_destroy(gopt_dep_tree);
+       gopt_dep_tree = NULL;
 }