]> git.tdb.fi Git - ext/subsurface.git/blob - equipment.c
First cut at working cylinder editing dialog
[ext/subsurface.git] / equipment.c
1 /* equipment.c */
2 /* creates the UI for the equipment page -
3  * controlled through the following interfaces:
4  *
5  * void show_dive_equipment(struct dive *dive)
6  * void flush_dive_equipment_changes(struct dive *dive)
7  *
8  * called from gtk-ui:
9  * GtkWidget *equipment_widget(void)
10  */
11 #include <stdio.h>
12 #include <string.h>
13 #include <stdlib.h>
14 #include <stdarg.h>
15 #include <time.h>
16
17 #include "dive.h"
18 #include "display.h"
19 #include "display-gtk.h"
20 #include "divelist.h"
21
22 GtkListStore *cylinder_model;
23
24 enum {
25         CYL_INDEX,
26         CYL_DESC,
27         CYL_SIZE,
28         CYL_WORKP,
29         CYL_STARTP,
30         CYL_ENDP,
31         CYL_O2,
32         CYL_HE,
33         CYL_COLUMNS
34 };
35
36 static struct {
37         int max_index;
38         GtkListStore *model;
39         GtkWidget *tree_view;
40         GtkWidget *edit, *add, *del;
41         GtkTreeViewColumn *desc, *size, *workp, *startp, *endp, *o2, *he;
42 } cylinder_list;
43
44 struct cylinder_widget {
45         int index, changed;
46         const char *name;
47         GtkWidget *hbox;
48         GtkComboBox *description;
49         GtkSpinButton *size, *pressure;
50         GtkWidget *o2, *gasmix_button;
51 };
52
53 static int convert_pressure(int mbar, double *p)
54 {
55         int decimals = 1;
56         double pressure;
57
58         pressure = mbar / 1000.0;
59         if (mbar) {
60                 if (output_units.pressure == PSI) {
61                         pressure *= 14.5037738; /* Bar to PSI */
62                         decimals = 0;
63                 }
64         }
65         *p = pressure;
66         return decimals;
67 }
68
69 static int convert_volume_pressure(int ml, int mbar, double *v, double *p)
70 {
71         int decimals = 1;
72         double volume, pressure;
73
74         volume = ml / 1000.0;
75         pressure = mbar / 1000.0;
76         if (mbar) {
77                 if (output_units.volume == CUFT) {
78                         volume /= 28.3168466;   /* Liters to cuft */
79                         volume *= pressure / 1.01325;
80                 }
81                 if (output_units.pressure == PSI) {
82                         pressure *= 14.5037738; /* Bar to PSI */
83                         decimals = 0;
84                 }
85         }
86         *v = volume;
87         *p = pressure;
88         return decimals;
89 }
90
91 static void set_cylinder_spinbuttons(struct cylinder_widget *cylinder, int ml, int mbar)
92 {
93         double volume, pressure;
94
95         convert_volume_pressure(ml, mbar, &volume, &pressure);
96         gtk_spin_button_set_value(cylinder->size, volume);
97         gtk_spin_button_set_value(cylinder->pressure, pressure);
98 }
99
100 static void cylinder_cb(GtkComboBox *combo_box, gpointer data)
101 {
102         GtkTreeIter iter;
103         GtkTreeModel *model = gtk_combo_box_get_model(combo_box);
104         GValue value1 = {0, }, value2 = {0,};
105         struct cylinder_widget *cylinder = data;
106         cylinder_t *cyl = current_dive->cylinder + cylinder->index;
107
108         /* Did the user set it to some non-standard value? */
109         if (!gtk_combo_box_get_active_iter(combo_box, &iter)) {
110                 cylinder->changed = 1;
111                 return;
112         }
113
114         /*
115          * We get "change" signal callbacks just because we set
116          * the description by hand. Whatever. So ignore them if
117          * they are no-ops.
118          */
119         if (!cylinder->changed && cyl->type.description) {
120                 int same;
121                 char *desc = gtk_combo_box_get_active_text(combo_box);
122
123                 same = !strcmp(desc, cyl->type.description);
124                 g_free(desc);
125                 if (same)
126                         return;
127         }
128         cylinder->changed = 1;
129
130         gtk_tree_model_get_value(model, &iter, 1, &value1);
131         gtk_tree_model_get_value(model, &iter, 2, &value2);
132
133         set_cylinder_spinbuttons(cylinder, g_value_get_int(&value1), g_value_get_int(&value2));
134 }
135
136 /*
137  * The gtk_tree_model_foreach() interface is bad. It could have
138  * returned whether the callback ever returned true
139  */
140 static int found_match = 0;
141
142 static gboolean match_cylinder(GtkTreeModel *model,
143                                 GtkTreePath *path,
144                                 GtkTreeIter *iter,
145                                 gpointer data)
146 {
147         const char *name;
148         struct cylinder_widget *cylinder = data;
149         GValue value = {0, };
150
151         gtk_tree_model_get_value(model, iter, 0, &value);
152         name = g_value_get_string(&value);
153         if (strcmp(cylinder->name, name))
154                 return FALSE;
155         gtk_combo_box_set_active_iter(cylinder->description, iter);
156         found_match = 1;
157         return TRUE;
158 }
159
160 static void add_cylinder(struct cylinder_widget *cylinder, const char *desc, int ml, int mbar)
161 {
162         GtkTreeModel *model;
163
164         found_match = 0;
165         model = gtk_combo_box_get_model(cylinder->description);
166         cylinder->name = desc;
167         gtk_tree_model_foreach(model, match_cylinder, cylinder);
168
169         if (!found_match) {
170                 GtkListStore *store = GTK_LIST_STORE(model);
171                 GtkTreeIter iter;
172
173                 gtk_list_store_append(store, &iter);
174                 gtk_list_store_set(store, &iter,
175                         0, desc,
176                         1, ml,
177                         2, mbar,
178                         -1);
179                 gtk_combo_box_set_active_iter(cylinder->description, &iter);
180         }
181 }
182
183 static void show_cylinder(cylinder_t *cyl, struct cylinder_widget *cylinder)
184 {
185         const char *desc;
186         int ml, mbar;
187         double o2;
188
189         /* Don't show uninitialized cylinder widgets */
190         if (!cylinder->description)
191                 return;
192
193         desc = cyl->type.description;
194         if (!desc)
195                 desc = "";
196         ml = cyl->type.size.mliter;
197         mbar = cyl->type.workingpressure.mbar;
198         add_cylinder(cylinder, desc, ml, mbar);
199
200         set_cylinder_spinbuttons(cylinder, cyl->type.size.mliter, cyl->type.workingpressure.mbar);
201         o2 = cyl->gasmix.o2.permille / 10.0;
202         gtk_widget_set_sensitive(cylinder->o2, !!o2);
203         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(cylinder->gasmix_button), !!o2);
204         if (!o2)
205                 o2 = 21.0;
206         gtk_spin_button_set_value(GTK_SPIN_BUTTON(cylinder->o2), o2);
207 }
208
209 static int cyl_nothing(cylinder_t *cyl)
210 {
211         return  !cyl->type.size.mliter &&
212                 !cyl->type.workingpressure.mbar &&
213                 !cyl->type.description &&
214                 !cyl->gasmix.o2.permille &&
215                 !cyl->gasmix.he.permille &&
216                 !cyl->start.mbar &&
217                 !cyl->end.mbar;
218 }
219
220 static void set_one_cylinder(int index, cylinder_t *cyl, GtkListStore *model, GtkTreeIter *iter)
221 {
222         gtk_list_store_set(model, iter,
223                 CYL_INDEX, index,
224                 CYL_DESC, cyl->type.description ? : "",
225                 CYL_SIZE, cyl->type.size.mliter,
226                 CYL_WORKP, cyl->type.workingpressure.mbar,
227                 CYL_STARTP, cyl->start.mbar,
228                 CYL_ENDP, cyl->end.mbar,
229                 CYL_O2, cyl->gasmix.o2.permille,
230                 CYL_HE, cyl->gasmix.he.permille,
231                 -1);
232 }
233
234 void show_dive_equipment(struct dive *dive)
235 {
236         int i, max;
237         GtkTreeIter iter;
238         GtkListStore *model;
239
240         model = cylinder_list.model;
241         gtk_list_store_clear(model);
242         max = MAX_CYLINDERS;
243         do {
244                 cylinder_t *cyl = &dive->cylinder[max-1];
245
246                 if (!cyl_nothing(cyl))
247                         break;
248         } while (--max);
249
250         cylinder_list.max_index = max;
251
252         gtk_widget_set_sensitive(cylinder_list.edit, 0);
253         gtk_widget_set_sensitive(cylinder_list.del, 0);
254         gtk_widget_set_sensitive(cylinder_list.add, max < MAX_CYLINDERS);
255
256         for (i = 0; i < max; i++) {
257                 cylinder_t *cyl = dive->cylinder+i;
258
259                 gtk_list_store_append(model, &iter);
260                 set_one_cylinder(i, cyl, model, &iter);
261         }
262 }
263
264 static GtkWidget *create_spinbutton(GtkWidget *vbox, const char *name, double min, double max, double incr)
265 {
266         GtkWidget *frame, *hbox, *button;
267
268         frame = gtk_frame_new(name);
269         gtk_box_pack_start(GTK_BOX(vbox), frame, FALSE, TRUE, 0);
270
271         hbox = gtk_hbox_new(FALSE, 3);
272         gtk_container_add(GTK_CONTAINER(frame), hbox);
273
274         button = gtk_spin_button_new_with_range(min, max, incr);
275         gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, TRUE, 0);
276
277         gtk_spin_button_set_update_policy(GTK_SPIN_BUTTON(button), GTK_UPDATE_IF_VALID);
278
279         return button;
280 }
281
282 static void fill_cylinder_info(struct cylinder_widget *cylinder, cylinder_t *cyl, const char *desc, double volume, double pressure, int o2)
283 {
284         int mbar, ml;
285
286         if (output_units.pressure == PSI)
287                 pressure /= 14.5037738;
288
289         if (pressure && output_units.volume == CUFT) {
290                 volume *= 28.3168466;   /* CUFT to liter */
291                 volume /= pressure / 1.01325;
292         }
293
294         ml = volume * 1000 + 0.5;
295         mbar = pressure * 1000 + 0.5;
296
297         if (o2 < 211)
298                 o2 = 0;
299         cyl->type.description = desc;
300         cyl->type.size.mliter = ml;
301         cyl->type.workingpressure.mbar = mbar;
302         cyl->gasmix.o2.permille = o2;
303
304         /*
305          * Also, insert it into the model if it doesn't already exist
306          */
307         add_cylinder(cylinder, desc, ml, mbar);
308 }
309
310 static void record_cylinder_changes(cylinder_t *cyl, struct cylinder_widget *cylinder)
311 {
312         const gchar *desc;
313         GtkComboBox *box;
314         double volume, pressure;
315         int o2;
316
317         /* Ignore uninitialized cylinder widgets */
318         box = cylinder->description;
319         if (!box)
320                 return;
321
322         desc = gtk_combo_box_get_active_text(box);
323         volume = gtk_spin_button_get_value(cylinder->size);
324         pressure = gtk_spin_button_get_value(cylinder->pressure);
325         o2 = gtk_spin_button_get_value(GTK_SPIN_BUTTON(cylinder->o2))*10 + 0.5;
326         if (!gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(cylinder->gasmix_button)))
327                 o2 = 0;
328         fill_cylinder_info(cylinder, cyl, desc, volume, pressure, o2);
329 }
330
331 void flush_dive_equipment_changes(struct dive *dive)
332 {
333         /* We do nothing: we require the "Ok" button press */
334 }
335
336 /*
337  * We hardcode the most common standard cylinders,
338  * we should pick up any other names from the dive
339  * logs directly.
340  */
341 static struct tank_info {
342         const char *name;
343         int size;       /* cuft if < 1000, otherwise mliter */
344         int psi;        /* If zero, size is in mliter */
345 } tank_info[100] = {
346         /* Need an empty entry for the no-cylinder case */
347         { "", 0, 0 },
348
349         /* Size-only metric cylinders */
350         { "10.0 l", 10000 },
351         { "11.1 l", 11100 },
352
353         /* Most common AL cylinders */
354         { "AL50",   50, 3000 },
355         { "AL63",   63, 3000 },
356         { "AL72",   72, 3000 },
357         { "AL80",   80, 3000 },
358         { "AL100", 100, 3300 },
359
360         /* Somewhat common LP steel cylinders */
361         { "LP85",   85, 2640 },
362         { "LP95",   95, 2640 },
363         { "LP108", 108, 2640 },
364         { "LP121", 121, 2640 },
365
366         /* Somewhat common HP steel cylinders */
367         { "HP65",   65, 3442 },
368         { "HP80",   80, 3442 },
369         { "HP100", 100, 3442 },
370         { "HP119", 119, 3442 },
371         { "HP130", 130, 3442 },
372
373         /* We'll fill in more from the dive log dynamically */
374         { NULL, }
375 };
376
377 static void fill_tank_list(GtkListStore *store)
378 {
379         GtkTreeIter iter;
380         struct tank_info *info = tank_info;
381
382         while (info->name) {
383                 int size = info->size;
384                 int psi = info->psi;
385                 int mbar = 0, ml = size;
386
387                 /* Is it in cuft and psi? */
388                 if (psi) {
389                         double bar = 0.0689475729 * psi;
390                         double airvolume = 28316.8466 * size;
391                         double atm = bar / 1.01325;
392
393                         ml = airvolume / atm + 0.5;
394                         mbar = bar*1000 + 0.5;
395                 }
396
397                 gtk_list_store_append(store, &iter);
398                 gtk_list_store_set(store, &iter,
399                         0, info->name,
400                         1, ml,
401                         2, mbar,
402                         -1);
403                 info++;
404         }
405 }
406
407 static void nitrox_cb(GtkToggleButton *button, gpointer data)
408 {
409         struct cylinder_widget *cylinder = data;
410         int state;
411
412         state = gtk_toggle_button_get_active(button);
413         gtk_widget_set_sensitive(cylinder->o2, state);
414 }
415
416 static void cylinder_widget(GtkWidget *vbox, struct cylinder_widget *cylinder, GtkListStore *model)
417 {
418         GtkWidget *frame, *hbox;
419         GtkWidget *widget;
420
421         frame = gtk_frame_new("Cylinder");
422
423         hbox = gtk_hbox_new(FALSE, 3);
424         gtk_container_add(GTK_CONTAINER(frame), hbox);
425
426         widget = gtk_combo_box_entry_new_with_model(GTK_TREE_MODEL(model), 0);
427         gtk_box_pack_start(GTK_BOX(hbox), widget, FALSE, TRUE, 0);
428
429         cylinder->description = GTK_COMBO_BOX(widget);
430         g_signal_connect(widget, "changed", G_CALLBACK(cylinder_cb), cylinder);
431
432         hbox = gtk_hbox_new(FALSE, 3);
433         gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, TRUE, 0);
434         gtk_box_pack_start(GTK_BOX(hbox), frame, FALSE, TRUE, 0);
435
436         widget = create_spinbutton(hbox, "Size", 0, 300, 0.1);
437         cylinder->size = GTK_SPIN_BUTTON(widget);
438
439         widget = create_spinbutton(hbox, "Pressure", 0, 5000, 1);
440         cylinder->pressure = GTK_SPIN_BUTTON(widget);
441
442         widget = create_spinbutton(hbox, "Nitrox", 21, 100, 0.1);
443         cylinder->o2 = widget;
444         cylinder->gasmix_button = gtk_check_button_new();
445         gtk_box_pack_start(GTK_BOX(gtk_widget_get_parent(cylinder->o2)),
446                 cylinder->gasmix_button, FALSE, FALSE, 3);
447         g_signal_connect(cylinder->gasmix_button, "toggled", G_CALLBACK(nitrox_cb), cylinder);
448
449         gtk_spin_button_set_range(GTK_SPIN_BUTTON(cylinder->o2), 21.0, 100.0);
450 }
451
452 static void edit_cylinder_dialog(int index, GtkListStore *model, GtkTreeIter *iter)
453 {
454         int result;
455         struct cylinder_widget cylinder;
456         GtkWidget *dialog, *vbox;
457         struct dive *dive;
458         cylinder_t *cyl;
459
460         dive = current_dive;
461         if (!dive)
462                 return;
463         cyl = dive->cylinder + index;
464         cylinder.index = index;
465         cylinder.changed = 0;
466
467         dialog = gtk_dialog_new_with_buttons("Cylinder",
468                 GTK_WINDOW(main_window),
469                 GTK_DIALOG_DESTROY_WITH_PARENT,
470                 GTK_STOCK_OK, GTK_RESPONSE_ACCEPT,
471                 GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT,
472                 NULL);
473
474         vbox = gtk_dialog_get_content_area(GTK_DIALOG(dialog));
475         cylinder_widget(vbox, &cylinder, cylinder_model);
476
477         show_cylinder(cyl, &cylinder);
478
479         gtk_widget_show_all(dialog);
480         result = gtk_dialog_run(GTK_DIALOG(dialog));
481         if (result == GTK_RESPONSE_ACCEPT) {
482                 record_cylinder_changes(cyl, &cylinder);
483                 set_one_cylinder(index, cyl, model, iter);
484                 mark_divelist_changed(TRUE);
485                 flush_divelist(dive);
486         }
487         gtk_widget_destroy(dialog);
488 }
489
490 static void edit_cb(GtkButton *button, gpointer data)
491 {
492         int index;
493         GtkTreeIter iter;
494         GtkListStore *model = cylinder_list.model;
495         GtkTreeSelection *selection;
496
497         selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(cylinder_list.tree_view));
498
499         /* Nothing selected? This shouldn't happen, since the button should be inactive */
500         if (!gtk_tree_selection_get_selected(selection, NULL, &iter))
501                 return;
502
503         gtk_tree_model_get(GTK_TREE_MODEL(model), &iter, CYL_INDEX, &index, -1);
504         edit_cylinder_dialog(index, model, &iter);
505 }
506
507 static void add_cb(GtkButton *button, gpointer data)
508 {
509         int index = cylinder_list.max_index;
510         GtkTreeIter iter;
511         GtkListStore *model = cylinder_list.model;
512         GtkTreeSelection *selection;
513
514         gtk_list_store_append(model, &iter);
515         gtk_list_store_set(model, &iter, CYL_INDEX, index, -1);
516
517         selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(cylinder_list.tree_view));
518         gtk_tree_selection_select_iter(selection, &iter);
519
520         edit_cylinder_dialog(index, model, &iter);
521         cylinder_list.max_index++;
522         gtk_widget_set_sensitive(cylinder_list.add, cylinder_list.max_index < MAX_CYLINDERS);
523 }
524
525 static void del_cb(GtkButton *button, gpointer data)
526 {
527         int index;
528         GtkTreeIter iter;
529         GtkListStore *model = cylinder_list.model;
530         GtkTreeSelection *selection;
531
532         selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(cylinder_list.tree_view));
533
534         /* Nothing selected? This shouldn't happen, since the button should be inactive */
535         if (!gtk_tree_selection_get_selected(selection, NULL, &iter))
536                 return;
537
538         gtk_tree_model_get(GTK_TREE_MODEL(model), &iter, CYL_INDEX, &index, -1);
539         if (gtk_list_store_remove(model, &iter)) {
540                 do {
541                         gtk_list_store_set(model, &iter, CYL_INDEX, index, -1);
542                         index++;
543                 } while (gtk_tree_model_iter_next(GTK_TREE_MODEL(model), &iter));
544         }
545
546         cylinder_list.max_index--;
547         gtk_widget_set_sensitive(cylinder_list.edit, 0);
548         gtk_widget_set_sensitive(cylinder_list.del, 0);
549         gtk_widget_set_sensitive(cylinder_list.add, 1);
550 }
551
552 static GtkListStore *create_tank_size_model(void)
553 {
554         GtkListStore *model;
555
556         model = gtk_list_store_new(3,
557                 G_TYPE_STRING,          /* Tank name */
558                 G_TYPE_INT,             /* Tank size in mliter */
559                 G_TYPE_INT,             /* Tank working pressure in mbar */
560                 -1);
561
562         fill_tank_list(model);
563         return model;
564 }
565
566 static void size_data_func(GtkTreeViewColumn *col,
567                            GtkCellRenderer *renderer,
568                            GtkTreeModel *model,
569                            GtkTreeIter *iter,
570                            gpointer data)
571 {
572         int ml, mbar;
573         double size, pressure;
574         char buffer[10];
575
576         gtk_tree_model_get(model, iter, CYL_SIZE, &ml, CYL_WORKP, &mbar, -1);
577         convert_volume_pressure(ml, mbar, &size, &pressure);
578         if (size)
579                 snprintf(buffer, sizeof(buffer), "%.1f", size);
580         else
581                 strcpy(buffer, "unkn");
582         g_object_set(renderer, "text", buffer, NULL);
583 }
584
585 static void pressure_data_func(GtkTreeViewColumn *col,
586                            GtkCellRenderer *renderer,
587                            GtkTreeModel *model,
588                            GtkTreeIter *iter,
589                            gpointer data)
590 {
591         int index = (long)data;
592         int mbar, decimals;
593         double pressure;
594         char buffer[10];
595
596         gtk_tree_model_get(model, iter, index, &mbar, -1);
597         decimals = convert_pressure(mbar, &pressure);
598         if (mbar)
599                 snprintf(buffer, sizeof(buffer), "%.*f", decimals, pressure);
600         else
601                 *buffer = 0;
602         g_object_set(renderer, "text", buffer, NULL);
603 }
604
605 static void percentage_data_func(GtkTreeViewColumn *col,
606                            GtkCellRenderer *renderer,
607                            GtkTreeModel *model,
608                            GtkTreeIter *iter,
609                            gpointer data)
610 {
611         int index = (long)data;
612         int permille;
613         char buffer[10];
614
615         gtk_tree_model_get(model, iter, index, &permille, -1);
616         if (permille)
617                 snprintf(buffer, sizeof(buffer), "%.1f%%", permille / 10.0);
618         else
619                 *buffer = 0;
620         g_object_set(renderer, "text", buffer, NULL);
621 }
622
623 static void selection_cb(GtkTreeSelection *selection, GtkTreeModel *model)
624 {
625         GtkTreeIter iter;
626         int selected;
627
628         selected = gtk_tree_selection_get_selected(selection, NULL, &iter);
629         gtk_widget_set_sensitive(cylinder_list.edit, selected);
630         gtk_widget_set_sensitive(cylinder_list.del, selected);
631 }
632
633 static GtkWidget *cylinder_list_create(void)
634 {
635         GtkWidget *tree_view;
636         GtkTreeSelection *selection;
637         GtkListStore *model;
638
639         model = gtk_list_store_new(CYL_COLUMNS,
640                 G_TYPE_INT,             /* CYL_INDEX */
641                 G_TYPE_STRING,          /* CYL_DESC: utf8 */
642                 G_TYPE_INT,             /* CYL_SIZE: mliter */
643                 G_TYPE_INT,             /* CYL_WORKP: mbar */
644                 G_TYPE_INT,             /* CYL_STARTP: mbar */
645                 G_TYPE_INT,             /* CYL_ENDP: mbar */
646                 G_TYPE_INT,             /* CYL_O2: permille */
647                 G_TYPE_INT              /* CYL_HE: permille */
648                 );
649         cylinder_list.model = model;
650         tree_view = gtk_tree_view_new_with_model(GTK_TREE_MODEL(model));
651
652         selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(tree_view));
653         gtk_tree_selection_set_mode(GTK_TREE_SELECTION(selection), GTK_SELECTION_BROWSE);
654         g_signal_connect(selection, "changed", G_CALLBACK(selection_cb), model);
655
656         tree_view_column(tree_view, CYL_INDEX, "Nr", NULL, PANGO_ALIGN_LEFT, TRUE);
657         cylinder_list.desc = tree_view_column(tree_view, CYL_DESC, "Type", NULL, PANGO_ALIGN_LEFT, TRUE);
658         cylinder_list.size = tree_view_column(tree_view, CYL_SIZE, "Size", size_data_func, PANGO_ALIGN_RIGHT, TRUE);
659         cylinder_list.workp = tree_view_column(tree_view, CYL_WORKP, "MaxPress", pressure_data_func, PANGO_ALIGN_RIGHT, TRUE);
660         cylinder_list.startp = tree_view_column(tree_view, CYL_STARTP, "Start", pressure_data_func, PANGO_ALIGN_RIGHT, TRUE);
661         cylinder_list.endp = tree_view_column(tree_view, CYL_ENDP, "End", pressure_data_func, PANGO_ALIGN_RIGHT, TRUE);
662         cylinder_list.o2 = tree_view_column(tree_view, CYL_O2, "O" UTF8_SUBSCRIPT_2 "%", percentage_data_func, PANGO_ALIGN_RIGHT, TRUE);
663         cylinder_list.he = tree_view_column(tree_view, CYL_HE, "He%", percentage_data_func, PANGO_ALIGN_RIGHT, TRUE);
664         return tree_view;
665 }
666
667 GtkWidget *equipment_widget(void)
668 {
669         GtkWidget *vbox, *hbox, *frame, *framebox;
670         GtkWidget *add, *del, *edit;
671
672         vbox = gtk_vbox_new(FALSE, 3);
673
674         /*
675          * We create the cylinder size model at startup, since
676          * we're going to share it across all cylinders and all
677          * dives. So if you add a new cylinder type in one dive,
678          * it will show up when you edit the cylinder types for
679          * another dive.
680          */
681         cylinder_model = create_tank_size_model();
682
683         cylinder_list.tree_view = cylinder_list_create();
684
685         hbox = gtk_hbox_new(FALSE, 3);
686         gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 3);
687
688         frame = gtk_frame_new("Cylinders");
689         gtk_box_pack_start(GTK_BOX(hbox), frame, TRUE, FALSE, 3);
690
691         framebox = gtk_vbox_new(FALSE, 3);
692         gtk_container_add(GTK_CONTAINER(frame), framebox);
693
694         hbox = gtk_hbox_new(FALSE, 3);
695         gtk_box_pack_start(GTK_BOX(framebox), hbox, TRUE, FALSE, 3);
696
697         gtk_box_pack_start(GTK_BOX(hbox), cylinder_list.tree_view, TRUE, FALSE, 3);
698
699         hbox = gtk_hbox_new(TRUE, 3);
700         gtk_box_pack_start(GTK_BOX(framebox), hbox, TRUE, FALSE, 3);
701
702         edit = gtk_button_new_from_stock(GTK_STOCK_EDIT);
703         add = gtk_button_new_from_stock(GTK_STOCK_ADD);
704         del = gtk_button_new_from_stock(GTK_STOCK_DELETE);
705         gtk_box_pack_start(GTK_BOX(hbox), edit, FALSE, FALSE, 0);
706         gtk_box_pack_start(GTK_BOX(hbox), add, FALSE, FALSE, 0);
707         gtk_box_pack_start(GTK_BOX(hbox), del, FALSE, FALSE, 0);
708
709         cylinder_list.edit = edit;
710         cylinder_list.add = add;
711         cylinder_list.del = del;
712
713         g_signal_connect(edit, "clicked", G_CALLBACK(edit_cb), NULL);
714         g_signal_connect(add, "clicked", G_CALLBACK(add_cb), NULL);
715         g_signal_connect(del, "clicked", G_CALLBACK(del_cb), NULL);
716
717         return vbox;
718 }