diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2011-09-13 13:25:06 -0700 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2011-09-13 13:25:06 -0700 |
commit | a92811351b82406184c354b948ff4b050ac579cc (patch) | |
tree | 65e3219d2e45df26b640e4b4e835e1dc76994fae /equipment.c | |
parent | a4c9cc110feeb71451614a8105657ed954fdced8 (diff) | |
download | subsurface-a92811351b82406184c354b948ff4b050ac579cc.tar.gz |
Make multiple cylinders actually work
This just always shows two cylinders, which is obviously bogus, but it's
a good test-case for the multi-cylinder case.
I need to figure out how to dynamically show the right number of
cylinders, but that also involves the notion of adding a cylinder in
order to fill out information that didn't use to exist.
That's lower priority - now the infrastructure seems to be there.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'equipment.c')
-rw-r--r-- | equipment.c | 38 |
1 files changed, 28 insertions, 10 deletions
diff --git a/equipment.c b/equipment.c index 1d3003bf2..023bebebb 100644 --- a/equipment.c +++ b/equipment.c @@ -121,17 +121,19 @@ static void add_cylinder(struct cylinder_widget *cylinder, const char *desc, int } } -void show_dive_equipment(struct dive *dive) +static void show_cylinder(cylinder_t *cyl, struct cylinder_widget *cylinder) { - cylinder_t *cyl = &dive->cylinder[0]; - const char *desc = cyl->type.description; - struct cylinder_widget *cylinder = >k_cylinder[0]; + const char *desc; int ml, mbar; double o2; + /* Don't show uninitialized cylinder widgets */ + if (!cylinder->description) + return; + + desc = cyl->type.description; if (!desc) desc = ""; - ml = cyl->type.size.mliter; mbar = cyl->type.workingpressure.mbar; add_cylinder(cylinder, desc, ml, mbar); @@ -145,6 +147,14 @@ void show_dive_equipment(struct dive *dive) gtk_spin_button_set_value(GTK_SPIN_BUTTON(cylinder->o2), o2); } +void show_dive_equipment(struct dive *dive) +{ + int i; + + for (i = 0; i < MAX_CYLINDERS; i++) + show_cylinder(dive->cylinder + i, gtk_cylinder+i); +} + static GtkWidget *create_spinbutton(GtkWidget *vbox, const char *name, double min, double max, double incr) { GtkWidget *frame, *hbox, *button; @@ -191,26 +201,33 @@ static void fill_cylinder_info(struct cylinder_widget *cylinder, cylinder_t *cyl add_cylinder(cylinder, desc, ml, mbar); } -static void record_cylinder_changes(struct dive *dive) +static void record_cylinder_changes(cylinder_t *cyl, struct cylinder_widget *cylinder) { const gchar *desc; - struct cylinder_widget *cylinder = >k_cylinder[0]; - GtkComboBox *box = cylinder->description; + GtkComboBox *box; double volume, pressure; int o2; + /* Ignore uninitialized cylinder widgets */ + box = cylinder->description; + if (!box) + return; + desc = gtk_combo_box_get_active_text(box); volume = gtk_spin_button_get_value(cylinder->size); pressure = gtk_spin_button_get_value(cylinder->pressure); o2 = gtk_spin_button_get_value(GTK_SPIN_BUTTON(cylinder->o2))*10 + 0.5; if (!gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(cylinder->gasmix_button))) o2 = 0; - fill_cylinder_info(cylinder, dive->cylinder+0, desc, volume, pressure, o2); + fill_cylinder_info(cylinder, cyl, desc, volume, pressure, o2); } void flush_dive_equipment_changes(struct dive *dive) { - record_cylinder_changes(dive); + int i; + + for (i = 0; i < MAX_CYLINDERS; i++) + record_cylinder_changes(dive->cylinder+i, gtk_cylinder+i); } /* @@ -358,6 +375,7 @@ GtkWidget *equipment_widget(void) model = create_tank_size_model(); cylinder_widget(vbox, 0, model); + cylinder_widget(vbox, 1, model); return vbox; } |