]> git.tdb.fi Git - ext/subsurface.git/blob - equipment.c
Add the ability to add new cylinders
[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(int nr, GtkListStore *model)
438 {
439         struct cylinder_widget *cylinder;
440         GtkWidget *frame, *hbox, *hbox2;
441         GtkWidget *widget;
442         char buffer[80];
443
444         cylinder = gtk_cylinder + nr;
445         cylinder->index = nr;
446
447         hbox = gtk_hbox_new(FALSE, 3);
448         cylinder->hbox = hbox;
449
450         snprintf(buffer, sizeof(buffer), "Cylinder %d", nr+1);
451         frame = gtk_frame_new(buffer);
452         gtk_box_pack_start(GTK_BOX(hbox), frame, FALSE, TRUE, 0);
453
454         hbox2 = gtk_hbox_new(FALSE, 3);
455         gtk_container_add(GTK_CONTAINER(frame), hbox2);
456
457         widget = gtk_combo_box_entry_new_with_model(GTK_TREE_MODEL(model), 0);
458         gtk_box_pack_start(GTK_BOX(hbox2), widget, FALSE, TRUE, 0);
459
460         cylinder->description = GTK_COMBO_BOX(widget);
461         g_signal_connect(widget, "changed", G_CALLBACK(cylinder_cb), cylinder);
462
463         widget = create_spinbutton(hbox, "Size", 0, 300, 0.1);
464         cylinder->size = GTK_SPIN_BUTTON(widget);
465
466         widget = create_spinbutton(hbox, "Pressure", 0, 5000, 1);
467         cylinder->pressure = GTK_SPIN_BUTTON(widget);
468
469         widget = create_spinbutton(hbox, "Nitrox", 21, 100, 0.1);
470         cylinder->o2 = widget;
471         cylinder->gasmix_button = gtk_check_button_new();
472         gtk_box_pack_start(GTK_BOX(gtk_widget_get_parent(cylinder->o2)),
473                 cylinder->gasmix_button, FALSE, FALSE, 3);
474         g_signal_connect(cylinder->gasmix_button, "toggled", G_CALLBACK(nitrox_cb), cylinder);
475
476         gtk_spin_button_set_range(GTK_SPIN_BUTTON(cylinder->o2), 21.0, 100.0);
477 }
478
479 static void edit_dive_dialog(int index, GtkListStore *model, GtkTreeIter *iter)
480 {
481 }
482
483 static void edit_cb(GtkButton *button, gpointer data)
484 {
485         int index;
486         GtkTreeIter iter;
487         GtkListStore *model = cylinder_list.model;
488         GtkTreeSelection *selection;
489
490         selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(cylinder_list.tree_view));
491
492         /* Nothing selected? This shouldn't happen, since the button should be inactive */
493         if (!gtk_tree_selection_get_selected(selection, NULL, &iter))
494                 return;
495
496         gtk_tree_model_get(GTK_TREE_MODEL(model), &iter, CYL_INDEX, &index, -1);
497         edit_dive_dialog(index, model, &iter);
498 }
499
500 static void add_cb(GtkButton *button, gpointer data)
501 {
502         int index = cylinder_list.max_index;
503         GtkTreeIter iter;
504         GtkListStore *model = cylinder_list.model;
505
506         gtk_list_store_append(model, &iter);
507         edit_dive_dialog(index, model, &iter);
508         cylinder_list.max_index++;
509         gtk_widget_set_sensitive(cylinder_list.add, cylinder_list.max_index < MAX_CYLINDERS);
510 }
511
512 static void del_cb(GtkButton *button, gpointer data)
513 {
514 }
515
516 static GtkListStore *create_tank_size_model(void)
517 {
518         GtkListStore *model;
519
520         model = gtk_list_store_new(3,
521                 G_TYPE_STRING,          /* Tank name */
522                 G_TYPE_INT,             /* Tank size in mliter */
523                 G_TYPE_INT,             /* Tank working pressure in mbar */
524                 -1);
525
526         fill_tank_list(model);
527         return model;
528 }
529
530 static void size_data_func(GtkTreeViewColumn *col,
531                            GtkCellRenderer *renderer,
532                            GtkTreeModel *model,
533                            GtkTreeIter *iter,
534                            gpointer data)
535 {
536         int ml, mbar;
537         double size, pressure;
538         char buffer[10];
539
540         gtk_tree_model_get(model, iter, CYL_SIZE, &ml, CYL_WORKP, &mbar, -1);
541         convert_volume_pressure(ml, mbar, &size, &pressure);
542         if (size)
543                 snprintf(buffer, sizeof(buffer), "%.1f", size);
544         else
545                 strcpy(buffer, "unkn");
546         g_object_set(renderer, "text", buffer, NULL);
547 }
548
549 static void pressure_data_func(GtkTreeViewColumn *col,
550                            GtkCellRenderer *renderer,
551                            GtkTreeModel *model,
552                            GtkTreeIter *iter,
553                            gpointer data)
554 {
555         int index = (long)data;
556         int mbar, decimals;
557         double pressure;
558         char buffer[10];
559
560         gtk_tree_model_get(model, iter, index, &mbar, -1);
561         decimals = convert_pressure(mbar, &pressure);
562         if (mbar)
563                 snprintf(buffer, sizeof(buffer), "%.*f", decimals, pressure);
564         else
565                 *buffer = 0;
566         g_object_set(renderer, "text", buffer, NULL);
567 }
568
569 static void percentage_data_func(GtkTreeViewColumn *col,
570                            GtkCellRenderer *renderer,
571                            GtkTreeModel *model,
572                            GtkTreeIter *iter,
573                            gpointer data)
574 {
575         int index = (long)data;
576         int permille;
577         char buffer[10];
578
579         gtk_tree_model_get(model, iter, index, &permille, -1);
580         if (permille)
581                 snprintf(buffer, sizeof(buffer), "%.1f%%", permille / 10.0);
582         else
583                 *buffer = 0;
584         g_object_set(renderer, "text", buffer, NULL);
585 }
586
587 static void selection_cb(GtkTreeSelection *selection, GtkTreeModel *model)
588 {
589         GtkTreeIter iter;
590         int selected;
591
592         selected = gtk_tree_selection_get_selected(selection, NULL, &iter);
593         gtk_widget_set_sensitive(cylinder_list.edit, selected);
594         gtk_widget_set_sensitive(cylinder_list.del, selected);
595 }
596
597 static GtkWidget *cylinder_list_create(void)
598 {
599         GtkWidget *tree_view;
600         GtkTreeSelection *selection;
601         GtkListStore *model;
602
603         model = gtk_list_store_new(CYL_COLUMNS,
604                 G_TYPE_INT,             /* CYL_INDEX */
605                 G_TYPE_STRING,          /* CYL_DESC: utf8 */
606                 G_TYPE_INT,             /* CYL_SIZE: mliter */
607                 G_TYPE_INT,             /* CYL_WORKP: mbar */
608                 G_TYPE_INT,             /* CYL_STARTP: mbar */
609                 G_TYPE_INT,             /* CYL_ENDP: mbar */
610                 G_TYPE_INT,             /* CYL_O2: permille */
611                 G_TYPE_INT              /* CYL_HE: permille */
612                 );
613         cylinder_list.model = model;
614         tree_view = gtk_tree_view_new_with_model(GTK_TREE_MODEL(model));
615
616         selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(tree_view));
617         gtk_tree_selection_set_mode(GTK_TREE_SELECTION(selection), GTK_SELECTION_BROWSE);
618         g_signal_connect(selection, "changed", G_CALLBACK(selection_cb), model);
619
620         cylinder_list.desc = tree_view_column(tree_view, CYL_DESC, "Type", NULL, PANGO_ALIGN_LEFT, TRUE);
621         cylinder_list.size = tree_view_column(tree_view, CYL_SIZE, "Size", size_data_func, PANGO_ALIGN_RIGHT, TRUE);
622         cylinder_list.workp = tree_view_column(tree_view, CYL_WORKP, "MaxPress", pressure_data_func, PANGO_ALIGN_RIGHT, TRUE);
623         cylinder_list.startp = tree_view_column(tree_view, CYL_STARTP, "Start", pressure_data_func, PANGO_ALIGN_RIGHT, TRUE);
624         cylinder_list.endp = tree_view_column(tree_view, CYL_ENDP, "End", pressure_data_func, PANGO_ALIGN_RIGHT, TRUE);
625         cylinder_list.o2 = tree_view_column(tree_view, CYL_O2, "O" UTF8_SUBSCRIPT_2 "%", percentage_data_func, PANGO_ALIGN_RIGHT, TRUE);
626         cylinder_list.he = tree_view_column(tree_view, CYL_HE, "He%", percentage_data_func, PANGO_ALIGN_RIGHT, TRUE);
627         return tree_view;
628 }
629
630 GtkWidget *equipment_widget(void)
631 {
632         GtkWidget *vbox, *hbox, *frame, *framebox;
633         GtkWidget *add, *del, *edit;
634
635         vbox = gtk_vbox_new(FALSE, 3);
636
637         /*
638          * We create the cylinder size model at startup, since
639          * we're going to share it across all cylinders and all
640          * dives. So if you add a new cylinder type in one dive,
641          * it will show up when you edit the cylinder types for
642          * another dive.
643          */
644         cylinder_model = create_tank_size_model();
645
646         cylinder_list.tree_view = cylinder_list_create();
647
648         hbox = gtk_hbox_new(FALSE, 3);
649         gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 3);
650
651         frame = gtk_frame_new("Cylinders");
652         gtk_box_pack_start(GTK_BOX(hbox), frame, TRUE, FALSE, 3);
653
654         framebox = gtk_vbox_new(FALSE, 3);
655         gtk_container_add(GTK_CONTAINER(frame), framebox);
656
657         hbox = gtk_hbox_new(FALSE, 3);
658         gtk_box_pack_start(GTK_BOX(framebox), hbox, TRUE, FALSE, 3);
659
660         gtk_box_pack_start(GTK_BOX(hbox), cylinder_list.tree_view, TRUE, FALSE, 3);
661
662         hbox = gtk_hbox_new(TRUE, 3);
663         gtk_box_pack_start(GTK_BOX(framebox), hbox, TRUE, FALSE, 3);
664
665         edit = gtk_button_new_from_stock(GTK_STOCK_EDIT);
666         add = gtk_button_new_from_stock(GTK_STOCK_ADD);
667         del = gtk_button_new_from_stock(GTK_STOCK_DELETE);
668         gtk_box_pack_start(GTK_BOX(hbox), edit, FALSE, FALSE, 0);
669         gtk_box_pack_start(GTK_BOX(hbox), add, FALSE, FALSE, 0);
670         gtk_box_pack_start(GTK_BOX(hbox), del, FALSE, FALSE, 0);
671
672         cylinder_list.edit = edit;
673         cylinder_list.add = add;
674         cylinder_list.del = del;
675
676         g_signal_connect(edit, "clicked", G_CALLBACK(edit_cb), NULL);
677         g_signal_connect(add, "clicked", G_CALLBACK(add_cb), NULL);
678         g_signal_connect(del, "clicked", G_CALLBACK(del_cb), NULL);
679
680         return vbox;
681 }