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