11 static int cylinder_changed;
12 static GtkComboBox *cylinder_description;
13 static GtkSpinButton *cylinder_size, *cylinder_pressure;
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,};
23 if (!gtk_combo_box_get_active_iter(combo_box, &iter))
26 gtk_tree_model_get_value(model, &iter, 1, &value1);
27 volume = g_value_get_int(&value1);
28 gtk_tree_model_get_value(model, &iter, 2, &value2);
29 pressure = g_value_get_int(&value2);
31 gtk_spin_button_set_value(cylinder_size,
33 gtk_spin_button_set_value(cylinder_pressure,
37 static gboolean match_cylinder(GtkTreeModel *model,
43 const char *desc = data;
46 gtk_tree_model_get_value(model, iter, 0, &value);
47 name = g_value_get_string(&value);
48 if (strcmp(desc, name))
50 gtk_combo_box_set_active_iter(cylinder_description, iter);
54 void show_dive_equipment(struct dive *dive)
56 cylinder_type_t *type = &dive->cylinder[0].type;
57 const char *desc = type->description;
58 GtkTreeModel *model = gtk_combo_box_get_model(cylinder_description);
61 gtk_tree_model_foreach(model, match_cylinder, (gpointer)desc);
62 gtk_spin_button_set_value(cylinder_size,
63 type->size.mliter / 1000.0);
64 gtk_spin_button_set_value(cylinder_pressure,
65 type->workingpressure.mbar / 1000.0);
68 static GtkWidget *create_spinbutton(GtkWidget *vbox, const char *name)
70 GtkWidget *frame, *button;
72 frame = gtk_frame_new(name);
73 gtk_container_add(GTK_CONTAINER(vbox), frame);
75 button = gtk_spin_button_new_with_range( 0.0, 3500.0, 0.1);
76 gtk_container_add(GTK_CONTAINER(frame), button);
81 static void fill_cylinder_info(cylinder_t *cyl, const char *desc, int mliter, int mbar)
84 * The code is currently too broken to actually set anything,
85 * so just print what we would set
87 printf("Set cylinder to '%s': %.1f liter at %.1f bar working pressure\n",
88 desc, mliter / 1000.0, mbar / 1000.);
90 cyl->type.description = desc;
91 cyl->type.size.mliter = mliter;
92 cyl->type.workingpressure.mbar = mbar;
96 static void record_cylinder_changes(struct dive *dive)
99 GtkComboBox *box = cylinder_description;
100 gdouble volume, pressure;
102 desc = gtk_combo_box_get_active_text(box);
103 volume = gtk_spin_button_get_value(cylinder_size);
104 pressure = gtk_spin_button_get_value(cylinder_pressure);
106 fill_cylinder_info(dive->cylinder+0,
107 desc, volume * 1000, pressure * 1000);
110 void flush_dive_equipment_changes(struct dive *dive)
112 if (cylinder_changed) {
113 cylinder_changed = 0;
114 record_cylinder_changes(dive);
118 /* We should take these from the dive list instead */
119 static struct tank_info {
121 int size; /* cuft or mliter depending on psi */
122 int psi; /* If zero, size is in mliter */
127 { "AL72", 72, 3000 },
128 { "AL80", 80, 3000 },
129 { "LP85", 85, 2400 },
130 { "LP95", 95, 2400 },
131 { "LP85+", 85, 2640 },
132 { "LP95+", 95, 2640 },
133 { "HP100", 100, 3442 },
134 { "HP119", 119, 3442 },
138 static void fill_tank_list(GtkListStore *store)
142 struct tank_info *info = tank_info;
145 int size = info->size;
147 int mbar = 0, ml = size;
149 /* Is it in cuft and psi? */
151 double bar = 0.0689475729 * psi;
152 double airvolume = 28316.8466 * size;
153 double atm = bar / 1.01325;
155 ml = airvolume / atm + 0.5;
156 mbar = bar*1000 + 0.5;
159 gtk_list_store_append(store, &iter);
160 gtk_list_store_set(store, &iter,
169 static void cylinder_widget(GtkWidget *box, int nr, GtkListStore *model)
171 GtkWidget *frame, *hbox;
172 GtkWidget *description, *size, *pressure;
175 snprintf(buffer, sizeof(buffer), "Cylinder %d", nr);
176 frame = gtk_frame_new(buffer);
177 gtk_box_pack_start(GTK_BOX(box), frame, FALSE, FALSE, 0);
179 hbox = gtk_hbox_new(TRUE, 3);
180 gtk_container_add(GTK_CONTAINER(frame), hbox);
182 frame = gtk_frame_new("Description");
183 gtk_box_pack_start(GTK_BOX(hbox), frame, FALSE, FALSE, 0);
185 description = gtk_combo_box_entry_new_with_model(GTK_TREE_MODEL(model), 0);
186 gtk_container_add(GTK_CONTAINER(frame), description);
188 cylinder_description = GTK_COMBO_BOX(description);
189 g_signal_connect(description, "changed", G_CALLBACK(cylinder_cb), description);
191 size = create_spinbutton(hbox, "Size");
192 cylinder_size = GTK_SPIN_BUTTON(size);
194 pressure = create_spinbutton(hbox, "Working Pressure");
195 cylinder_pressure = GTK_SPIN_BUTTON(pressure);
198 static GtkListStore *create_tank_size_model(void)
202 model = gtk_list_store_new(3,
203 G_TYPE_STRING, /* Tank name */
204 G_TYPE_INT, /* Tank size in mliter */
205 G_TYPE_INT, /* Tank working pressure in mbar */
208 fill_tank_list(model);
212 GtkWidget *equipment_widget(void)
217 vbox = gtk_vbox_new(FALSE, 3);
219 model = create_tank_size_model();
220 cylinder_widget(vbox, 0, model);