gfio: fill default options on new job
[fio.git] / goptions.c
index 127f5d3272131982d2cb4433f6af4ccb106a0039..547d9cf98a88ca50831b4cd793edd37d0a49baa6 100644 (file)
@@ -24,6 +24,8 @@ struct gopt_combo {
 
 struct gopt_int {
        struct gopt gopt;
+       unsigned int lastval;
+       unsigned int in_change;
        GtkWidget *spin;
 };
 
@@ -44,6 +46,11 @@ struct gopt_range {
        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 {
@@ -155,6 +162,7 @@ static struct gopt *gopt_new_str_store(struct fio_option *o, const char *text, u
 
        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;
 }
 
@@ -186,6 +194,7 @@ static struct gopt_combo *__gopt_new_combo(struct fio_option *o, unsigned int id
        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;
 }
 
@@ -235,12 +244,68 @@ static struct gopt *gopt_new_combo_int(struct fio_option *o, unsigned int *ip, u
        return &combo->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));
+       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 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];
-
-       printf("int %s changed\n", o->name);
+       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_int *i_inv = o->inv_opt->gui_data;
+               int cur_val;
+
+               /*
+                * Don't recourse into notify changes. Is there a better
+                * way than this? We essentially want to block the update
+                * signal while we perform the below set_value().
+                */
+               if (i_inv->in_change)
+                       return;
+
+               i->in_change = 1;
+               cur_val = gtk_spin_button_get_value(GTK_SPIN_BUTTON(i_inv->spin));
+               cur_val -= delta;
+               gtk_spin_button_set_value(GTK_SPIN_BUTTON(i_inv->spin), cur_val);
+               i->in_change = 0;
+       }
 }
 
 static struct gopt_int *__gopt_new_int(struct fio_option *o, unsigned long long *p,
@@ -280,11 +345,13 @@ static struct gopt_int *__gopt_new_int(struct fio_option *o, unsigned long long
        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;
        g_signal_connect(G_OBJECT(i->spin), "value-changed", G_CALLBACK(gopt_int_changed), i);
 
        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;
 }
 
@@ -341,11 +408,15 @@ static struct gopt *gopt_new_bool(struct fio_option *o, unsigned int *val, unsig
        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);
        g_signal_connect(G_OBJECT(b->check), "toggled", G_CALLBACK(gopt_bool_toggled), 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);
+       o->gui_data = b;
        return &b->gopt;
 }
 
@@ -435,6 +506,7 @@ 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);
+       o->gui_data = r;
        return &r->gopt;
 }
 
@@ -474,12 +546,18 @@ static void gopt_add_option(GtkWidget *hbox, struct fio_option *o,
                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, opt_index);
                break;
                }
        case FIO_OPT_STR_STORE: {
@@ -499,7 +577,7 @@ static void gopt_add_option(GtkWidget *hbox, struct fio_option *o,
                break;
                }
        case FIO_OPT_STR_MULTI:
-               go = gopt_new_combo_str(o, NULL, opt_index);
+               go = gopt_new_str_multi(o, opt_index);
                break;
        case FIO_OPT_RANGE: {
                unsigned int *ip[4] = { td_var(to, o->off1),
@@ -541,6 +619,9 @@ static void gopt_add_options(GtkWidget **vboxes, struct thread_options *to)
        GtkWidget *hbox = NULL;
        int i;
 
+       /*
+        * First add all options
+        */
        for (i = 0; fio_options[i].name; i++) {
                struct fio_option *o = &fio_options[i];
                unsigned int mask = o->category;