X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=equipment.c;h=b9b9259b5a8cd0631816842e95d513e14d1066e3;hb=9cf8d98711dff888f5bfa8efd52ca7b8cf8bfa07;hp=1d3003bf25efdc9b1992a2e438b0911056dba7b3;hpb=a4c9cc110feeb71451614a8105657ed954fdced8;p=ext%2Fsubsurface.git diff --git a/equipment.c b/equipment.c index 1d3003b..b9b9259 100644 --- a/equipment.c +++ b/equipment.c @@ -11,6 +11,7 @@ struct cylinder_widget { int index, changed; const char *name; + GtkWidget *hbox; GtkComboBox *description; GtkSpinButton *size, *pressure; GtkWidget *o2, *gasmix_button; @@ -121,17 +122,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 +148,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 +202,53 @@ 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); + /* We do nothing: we require the "Ok" button press */ +} + +static void apply_cb(GtkButton *button, gpointer data) +{ + int i; + struct dive *dive = current_dive; + + if (!dive) + return; + + for (i = 0; i < MAX_CYLINDERS; i++) + record_cylinder_changes(dive->cylinder+i, gtk_cylinder+i); + flush_divelist(dive); +} + +static void cancel_cb(GtkButton *button, gpointer data) +{ + struct dive *dive = current_dive; + + if (!dive) + return; + + show_dive_equipment(current_dive); } /* @@ -293,7 +331,7 @@ static void nitrox_cb(GtkToggleButton *button, gpointer data) gtk_widget_set_sensitive(cylinder->o2, state); } -static void cylinder_widget(GtkWidget *box, int nr, GtkListStore *model) +static void cylinder_widget(int nr, GtkListStore *model) { struct cylinder_widget *cylinder; GtkWidget *frame, *hbox, *hbox2; @@ -304,7 +342,7 @@ static void cylinder_widget(GtkWidget *box, int nr, GtkListStore *model) cylinder->index = nr; hbox = gtk_hbox_new(FALSE, 3); - gtk_box_pack_start(GTK_BOX(box), hbox, FALSE, FALSE, 0); + cylinder->hbox = hbox; snprintf(buffer, sizeof(buffer), "Cylinder %d", nr+1); frame = gtk_frame_new(buffer); @@ -351,13 +389,35 @@ static GtkListStore *create_tank_size_model(void) GtkWidget *equipment_widget(void) { - GtkWidget *vbox; + int i; + GtkWidget *vbox, *hbox; + GtkWidget *apply, *cancel; GtkListStore *model; vbox = gtk_vbox_new(FALSE, 3); model = create_tank_size_model(); - cylinder_widget(vbox, 0, model); + + /* Create all MAX_CYLINDER gtk widgets */ + for (i = 0; i < MAX_CYLINDERS; i++) + cylinder_widget(i, model); + + /* But only connect two of them right now to the frame vbox */ + for (i = 0; i < 2; i++) { + struct cylinder_widget *cylinder = gtk_cylinder+i; + gtk_box_pack_start(GTK_BOX(vbox), cylinder->hbox, FALSE, TRUE, 0); + } + + hbox = gtk_hbox_new(TRUE, 3); + gtk_box_pack_end(GTK_BOX(vbox), hbox, TRUE, FALSE, 0); + + apply = gtk_button_new_from_stock(GTK_STOCK_APPLY); + cancel = gtk_button_new_from_stock(GTK_STOCK_CANCEL); + gtk_box_pack_start(GTK_BOX(hbox), apply, FALSE, FALSE, 0); + gtk_box_pack_start(GTK_BOX(hbox), cancel, FALSE, FALSE, 0); + + g_signal_connect(apply, "clicked", G_CALLBACK(apply_cb), NULL); + g_signal_connect(cancel, "clicked", G_CALLBACK(cancel_cb), NULL); return vbox; }