11 static int cylinder_changed;
12 static GtkComboBox *cylinder_description;
13 static GtkSpinButton *cylinder_size, *cylinder_pressure, *nitrox_value;
15 static void cylinder_cb(GtkComboBox *combo_box, gpointer data)
18 GtkTreeModel *model = gtk_combo_box_get_model(combo_box);
19 GValue value1 = {0, }, value2 = {0,};
21 cylinder_t *cyl = current_dive->cylinder + 0;
23 /* Did the user set it to some non-standard value? */
24 if (!gtk_combo_box_get_active_iter(combo_box, &iter)) {
30 * We get "change" signal callbacks just because we set
31 * the description by hand. Whatever. So ignore them if
34 if (!cylinder_changed && cyl->type.description) {
36 char *desc = gtk_combo_box_get_active_text(combo_box);
38 same = !strcmp(desc, cyl->type.description);
45 gtk_tree_model_get_value(model, &iter, 1, &value1);
46 volume = g_value_get_int(&value1);
47 gtk_tree_model_get_value(model, &iter, 2, &value2);
48 pressure = g_value_get_int(&value2);
50 gtk_spin_button_set_value(cylinder_size,
52 gtk_spin_button_set_value(cylinder_pressure,
56 static gboolean match_cylinder(GtkTreeModel *model,
62 const char *desc = data;
65 gtk_tree_model_get_value(model, iter, 0, &value);
66 name = g_value_get_string(&value);
67 if (strcmp(desc, name))
69 gtk_combo_box_set_active_iter(cylinder_description, iter);
73 void show_dive_equipment(struct dive *dive)
75 cylinder_t *cyl = &dive->cylinder[0];
76 const char *desc = cyl->type.description;
77 GtkTreeModel *model = gtk_combo_box_get_model(cylinder_description);
81 gtk_tree_model_foreach(model, match_cylinder, (gpointer)desc);
82 gtk_spin_button_set_value(cylinder_size,
83 cyl->type.size.mliter / 1000.0);
84 gtk_spin_button_set_value(cylinder_pressure,
85 cyl->type.workingpressure.mbar / 1000.0);
86 o2 = cyl->gasmix.o2.permille / 10.0;
89 gtk_spin_button_set_value(nitrox_value, o2);
92 static GtkWidget *create_spinbutton(GtkWidget *vbox, const char *name, double min, double max, double incr)
94 GtkWidget *frame, *button;
96 frame = gtk_frame_new(name);
97 gtk_container_add(GTK_CONTAINER(vbox), frame);
99 button = gtk_spin_button_new_with_range(min, max, incr);
100 gtk_container_add(GTK_CONTAINER(frame), button);
102 gtk_spin_button_set_update_policy(GTK_SPIN_BUTTON(button), GTK_UPDATE_IF_VALID);
107 static void fill_cylinder_info(cylinder_t *cyl, const char *desc, int mliter, int mbar, int o2)
111 cyl->type.description = desc;
112 cyl->type.size.mliter = mliter;
113 cyl->type.workingpressure.mbar = mbar;
114 cyl->gasmix.o2.permille = o2;
117 static void record_cylinder_changes(struct dive *dive)
120 GtkComboBox *box = cylinder_description;
121 int volume, pressure, o2;
123 desc = gtk_combo_box_get_active_text(box);
124 volume = gtk_spin_button_get_value(cylinder_size) * 1000 + 0.5;
125 pressure = gtk_spin_button_get_value(cylinder_pressure) * 1000 + 0.5;
126 o2 = gtk_spin_button_get_value(nitrox_value)*10 + 0.5;
127 fill_cylinder_info(dive->cylinder+0, desc, volume, pressure, o2);
130 void flush_dive_equipment_changes(struct dive *dive)
132 record_cylinder_changes(dive);
135 /* We should take these from the dive list instead */
136 static struct tank_info {
138 int size; /* cuft or mliter depending on psi */
139 int psi; /* If zero, size is in mliter */
144 { "AL72", 72, 3000 },
145 { "AL80", 80, 3000 },
146 { "LP85", 85, 2400 },
147 { "LP95", 95, 2400 },
148 { "LP85+", 85, 2640 },
149 { "LP95+", 95, 2640 },
150 { "HP100", 100, 3442 },
151 { "HP119", 119, 3442 },
155 static void fill_tank_list(GtkListStore *store)
159 struct tank_info *info = tank_info;
162 int size = info->size;
164 int mbar = 0, ml = size;
166 /* Is it in cuft and psi? */
168 double bar = 0.0689475729 * psi;
169 double airvolume = 28316.8466 * size;
170 double atm = bar / 1.01325;
172 ml = airvolume / atm + 0.5;
173 mbar = bar*1000 + 0.5;
176 gtk_list_store_append(store, &iter);
177 gtk_list_store_set(store, &iter,
186 static void cylinder_widget(GtkWidget *box, int nr, GtkListStore *model)
188 GtkWidget *frame, *hbox;
192 snprintf(buffer, sizeof(buffer), "Cylinder %d", nr);
193 frame = gtk_frame_new(buffer);
194 gtk_box_pack_start(GTK_BOX(box), frame, FALSE, FALSE, 0);
196 hbox = gtk_hbox_new(TRUE, 3);
197 gtk_container_add(GTK_CONTAINER(frame), hbox);
199 frame = gtk_frame_new("Description");
200 gtk_box_pack_start(GTK_BOX(hbox), frame, FALSE, FALSE, 0);
202 widget = gtk_combo_box_entry_new_with_model(GTK_TREE_MODEL(model), 0);
203 gtk_container_add(GTK_CONTAINER(frame), widget);
205 cylinder_description = GTK_COMBO_BOX(widget);
206 g_signal_connect(widget, "changed", G_CALLBACK(cylinder_cb), NULL);
208 widget = create_spinbutton(hbox, "Size", 0, 200, 0.1);
209 cylinder_size = GTK_SPIN_BUTTON(widget);
211 widget = create_spinbutton(hbox, "Working Pressure", 0, 5000, 1);
212 cylinder_pressure = GTK_SPIN_BUTTON(widget);
214 widget = create_spinbutton(hbox, "Nitrox", 21, 100, 0.1);
215 nitrox_value = GTK_SPIN_BUTTON(widget);
216 gtk_spin_button_set_range(nitrox_value, 21.0, 100.0);
219 static GtkListStore *create_tank_size_model(void)
223 model = gtk_list_store_new(3,
224 G_TYPE_STRING, /* Tank name */
225 G_TYPE_INT, /* Tank size in mliter */
226 G_TYPE_INT, /* Tank working pressure in mbar */
229 fill_tank_list(model);
233 GtkWidget *equipment_widget(void)
238 vbox = gtk_vbox_new(FALSE, 3);
240 model = create_tank_size_model();
241 cylinder_widget(vbox, 0, model);