2 /* creates the UI for the equipment page -
3 * controlled through the following interfaces:
5 * void show_dive_equipment(struct dive *dive)
8 * GtkWidget *equipment_widget(void)
18 #include "display-gtk.h"
21 static GtkListStore *cylinder_model;
37 GtkWidget *edit, *add, *del;
40 struct cylinder_widget {
44 GtkComboBox *description;
45 GtkSpinButton *size, *pressure;
46 GtkWidget *start, *end, *pressure_button;
47 GtkWidget *o2, *he, *gasmix_button;
50 /* we want bar - so let's not use our unit functions */
51 static int convert_pressure(int mbar, double *p)
56 if (output_units.pressure == PSI) {
57 pressure = mbar_to_PSI(mbar);
60 pressure = mbar / 1000.0;
67 static int convert_volume_pressure(int ml, int mbar, double *v, double *p)
70 double volume, pressure;
74 if (output_units.volume == CUFT) {
75 volume = ml_to_cuft(ml);
76 volume *= bar_to_atm(mbar / 1000.0);
79 if (output_units.pressure == PSI) {
80 pressure = mbar_to_PSI(mbar);
83 pressure = mbar / 1000.0;
90 static void set_cylinder_type_spinbuttons(struct cylinder_widget *cylinder, int ml, int mbar)
92 double volume, pressure;
94 convert_volume_pressure(ml, mbar, &volume, &pressure);
95 gtk_spin_button_set_value(cylinder->size, volume);
96 gtk_spin_button_set_value(cylinder->pressure, pressure);
99 static void set_cylinder_pressure_spinbuttons(struct cylinder_widget *cylinder, cylinder_t *cyl)
102 unsigned int start, end;
105 start = cyl->start.mbar;
109 start = cyl->sample_start.mbar;
110 end = cyl->sample_end.mbar;
112 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(cylinder->pressure_button), set);
113 gtk_widget_set_sensitive(cylinder->start, set);
114 gtk_widget_set_sensitive(cylinder->end, set);
116 convert_pressure(start, &pressure);
117 gtk_spin_button_set_value(GTK_SPIN_BUTTON(cylinder->start), pressure);
118 convert_pressure(end, &pressure);
119 gtk_spin_button_set_value(GTK_SPIN_BUTTON(cylinder->end), pressure);
123 * The gtk_tree_model_foreach() interface is bad. It could have
124 * returned whether the callback ever returned true
126 static GtkTreeIter *found_match = NULL;
127 static GtkTreeIter match_iter;
129 static gboolean match_cylinder(GtkTreeModel *model,
136 const char *desc = data;
138 gtk_tree_model_get(model, iter, 0, &name, -1);
139 match = !strcmp(desc, name);
143 found_match = &match_iter;
148 static int get_active_cylinder(GtkComboBox *combo_box, GtkTreeIter *iter)
152 if (gtk_combo_box_get_active_iter(combo_box, iter))
155 desc = gtk_combo_box_get_active_text(combo_box);
158 gtk_tree_model_foreach(GTK_TREE_MODEL(cylinder_model), match_cylinder, (void *)desc);
164 *iter = *found_match;
165 gtk_combo_box_set_active_iter(combo_box, iter);
169 static void cylinder_cb(GtkComboBox *combo_box, gpointer data)
172 GtkTreeModel *model = gtk_combo_box_get_model(combo_box);
174 struct cylinder_widget *cylinder = data;
175 cylinder_t *cyl = current_dive->cylinder + cylinder->index;
177 /* Did the user set it to some non-standard value? */
178 if (!get_active_cylinder(combo_box, &iter)) {
179 cylinder->changed = 1;
184 * We get "change" signal callbacks just because we set
185 * the description by hand. Whatever. So ignore them if
188 if (!cylinder->changed && cyl->type.description) {
190 char *desc = gtk_combo_box_get_active_text(combo_box);
192 same = !strcmp(desc, cyl->type.description);
197 cylinder->changed = 1;
199 gtk_tree_model_get(model, &iter,
204 set_cylinder_type_spinbuttons(cylinder, ml, mbar);
207 static GtkTreeIter *add_cylinder_type(const char *desc, int ml, int mbar, GtkTreeIter *iter)
211 /* Don't even bother adding stuff without a size */
216 model = GTK_TREE_MODEL(cylinder_model);
217 gtk_tree_model_foreach(model, match_cylinder, (void *)desc);
220 GtkListStore *store = GTK_LIST_STORE(model);
222 gtk_list_store_append(store, iter);
223 gtk_list_store_set(store, iter,
234 * When adding a dive, we'll add all the pre-existing cylinder
235 * information from that dive to our cylinder model.
237 void add_cylinder_description(cylinder_type_t *type)
241 unsigned int size, workp;
243 desc = type->description;
246 size = type->size.mliter;
247 workp = type->workingpressure.mbar;
248 add_cylinder_type(desc, size, workp, &iter);
251 static void add_cylinder(struct cylinder_widget *cylinder, const char *desc, int ml, int mbar)
253 GtkTreeIter iter, *match;
255 cylinder->name = desc;
256 match = add_cylinder_type(desc, ml, mbar, &iter);
258 gtk_combo_box_set_active_iter(cylinder->description, match);
261 static void show_cylinder(cylinder_t *cyl, struct cylinder_widget *cylinder)
268 /* Don't show uninitialized cylinder widgets */
269 if (!cylinder->description)
272 desc = cyl->type.description;
275 ml = cyl->type.size.mliter;
276 mbar = cyl->type.workingpressure.mbar;
277 add_cylinder(cylinder, desc, ml, mbar);
279 set_cylinder_type_spinbuttons(cylinder,
280 cyl->type.size.mliter, cyl->type.workingpressure.mbar);
281 set_cylinder_pressure_spinbuttons(cylinder, cyl);
283 gasmix = cyl->gasmix.o2.permille || cyl->gasmix.he.permille;
284 gtk_widget_set_sensitive(cylinder->o2, gasmix);
285 gtk_widget_set_sensitive(cylinder->he, gasmix);
286 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(cylinder->gasmix_button), gasmix);
288 o2 = cyl->gasmix.o2.permille / 10.0;
289 he = cyl->gasmix.he.permille / 10.0;
292 gtk_spin_button_set_value(GTK_SPIN_BUTTON(cylinder->o2), o2);
293 gtk_spin_button_set_value(GTK_SPIN_BUTTON(cylinder->he), he);
296 int cylinder_none(cylinder_t *cyl)
298 return !cyl->type.size.mliter &&
299 !cyl->type.workingpressure.mbar &&
300 !cyl->type.description &&
301 !cyl->gasmix.o2.permille &&
302 !cyl->gasmix.he.permille &&
303 !cyl->sample_start.mbar &&
304 !cyl->sample_end.mbar &&
309 static void set_one_cylinder(int index, cylinder_t *cyl, GtkListStore *model, GtkTreeIter *iter)
311 unsigned int start, end;
313 start = cyl->start.mbar ? : cyl->sample_start.mbar;
314 end = cyl->end.mbar ? : cyl->sample_end.mbar;
315 gtk_list_store_set(model, iter,
316 CYL_DESC, cyl->type.description ? : "",
317 CYL_SIZE, cyl->type.size.mliter,
318 CYL_WORKP, cyl->type.workingpressure.mbar,
321 CYL_O2, cyl->gasmix.o2.permille,
322 CYL_HE, cyl->gasmix.he.permille,
326 void show_dive_equipment(struct dive *dive)
332 model = cylinder_list.model;
333 gtk_list_store_clear(model);
336 cylinder_t *cyl = &dive->cylinder[max-1];
338 if (!cylinder_none(cyl))
342 cylinder_list.max_index = max;
344 gtk_widget_set_sensitive(cylinder_list.edit, 0);
345 gtk_widget_set_sensitive(cylinder_list.del, 0);
346 gtk_widget_set_sensitive(cylinder_list.add, max < MAX_CYLINDERS);
348 for (i = 0; i < max; i++) {
349 cylinder_t *cyl = dive->cylinder+i;
351 gtk_list_store_append(model, &iter);
352 set_one_cylinder(i, cyl, model, &iter);
356 static GtkWidget *create_spinbutton(GtkWidget *vbox, const char *name, double min, double max, double incr)
358 GtkWidget *frame, *hbox, *button;
360 frame = gtk_frame_new(name);
361 gtk_box_pack_start(GTK_BOX(vbox), frame, TRUE, FALSE, 0);
363 hbox = gtk_hbox_new(FALSE, 3);
364 gtk_container_add(GTK_CONTAINER(frame), hbox);
366 button = gtk_spin_button_new_with_range(min, max, incr);
367 gtk_box_pack_start(GTK_BOX(hbox), button, TRUE, FALSE, 0);
369 gtk_spin_button_set_update_policy(GTK_SPIN_BUTTON(button), GTK_UPDATE_IF_VALID);
374 static void fill_cylinder_info(struct cylinder_widget *cylinder, cylinder_t *cyl, const char *desc,
375 double volume, double pressure, double start, double end, int o2, int he)
379 if (output_units.pressure == PSI) {
380 pressure = psi_to_bar(pressure);
381 start = psi_to_bar(start);
382 end = psi_to_bar(end);
385 if (pressure && output_units.volume == CUFT) {
386 volume = cuft_to_l(volume);
387 volume /= bar_to_atm(pressure);
390 ml = volume * 1000 + 0.5;
391 mbar = pressure * 1000 + 0.5;
393 /* Ignore obviously crazy He values */
397 /* We have a rule that normal air is all zeroes */
398 if (!he && o2 > 208 && o2 < 211)
401 cyl->type.description = desc;
402 cyl->type.size.mliter = ml;
403 cyl->type.workingpressure.mbar = mbar;
404 cyl->start.mbar = start * 1000 + 0.5;
405 cyl->end.mbar = end * 1000 + 0.5;
406 cyl->gasmix.o2.permille = o2;
407 cyl->gasmix.he.permille = he;
410 * Also, insert it into the model if it doesn't already exist
412 add_cylinder(cylinder, desc, ml, mbar);
415 static void record_cylinder_changes(cylinder_t *cyl, struct cylinder_widget *cylinder)
419 double volume, pressure, start, end;
422 /* Ignore uninitialized cylinder widgets */
423 box = cylinder->description;
427 desc = gtk_combo_box_get_active_text(box);
428 volume = gtk_spin_button_get_value(cylinder->size);
429 pressure = gtk_spin_button_get_value(cylinder->pressure);
430 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(cylinder->pressure_button))) {
431 start = gtk_spin_button_get_value(GTK_SPIN_BUTTON(cylinder->start));
432 end = gtk_spin_button_get_value(GTK_SPIN_BUTTON(cylinder->end));
436 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(cylinder->gasmix_button))) {
437 o2 = gtk_spin_button_get_value(GTK_SPIN_BUTTON(cylinder->o2))*10 + 0.5;
438 he = gtk_spin_button_get_value(GTK_SPIN_BUTTON(cylinder->he))*10 + 0.5;
443 fill_cylinder_info(cylinder, cyl, desc, volume, pressure, start, end, o2, he);
447 * We hardcode the most common standard cylinders,
448 * we should pick up any other names from the dive
451 static struct tank_info {
453 int size; /* cuft if < 1000, otherwise mliter */
454 int psi; /* If zero, size is in mliter */
456 /* Need an empty entry for the no-cylinder case */
459 /* Size-only metric cylinders */
463 /* Most common AL cylinders */
464 { "AL50", 50, 3000 },
465 { "AL63", 63, 3000 },
466 { "AL72", 72, 3000 },
467 { "AL80", 80, 3000 },
468 { "AL100", 100, 3300 },
470 /* Somewhat common LP steel cylinders */
471 { "LP85", 85, 2640 },
472 { "LP95", 95, 2640 },
473 { "LP108", 108, 2640 },
474 { "LP121", 121, 2640 },
476 /* Somewhat common HP steel cylinders */
477 { "HP65", 65, 3442 },
478 { "HP80", 80, 3442 },
479 { "HP100", 100, 3442 },
480 { "HP119", 119, 3442 },
481 { "HP130", 130, 3442 },
483 /* We'll fill in more from the dive log dynamically */
487 static void fill_tank_list(GtkListStore *store)
490 struct tank_info *info = tank_info;
493 int size = info->size;
495 int mbar = 0, ml = size;
497 /* Is it in cuft and psi? */
499 double bar = psi_to_bar(psi);
500 double airvolume = cuft_to_l(size) * 1000.0;
501 double atm = bar_to_atm(bar);
503 ml = airvolume / atm + 0.5;
504 mbar = bar*1000 + 0.5;
507 gtk_list_store_append(store, &iter);
508 gtk_list_store_set(store, &iter,
517 static void gasmix_cb(GtkToggleButton *button, gpointer data)
519 struct cylinder_widget *cylinder = data;
522 state = gtk_toggle_button_get_active(button);
523 gtk_widget_set_sensitive(cylinder->o2, state);
524 gtk_widget_set_sensitive(cylinder->he, state);
527 static void pressure_cb(GtkToggleButton *button, gpointer data)
529 struct cylinder_widget *cylinder = data;
532 state = gtk_toggle_button_get_active(button);
533 gtk_widget_set_sensitive(cylinder->start, state);
534 gtk_widget_set_sensitive(cylinder->end, state);
537 static gboolean completion_cb(GtkEntryCompletion *widget, GtkTreeModel *model, GtkTreeIter *iter, struct cylinder_widget *cylinder)
540 unsigned int ml, mbar;
542 gtk_tree_model_get(model, iter, CYL_DESC, &desc, CYL_SIZE, &ml, CYL_WORKP, &mbar, -1);
543 add_cylinder(cylinder, desc, ml, mbar);
547 static void cylinder_activate_cb(GtkComboBox *combo_box, gpointer data)
549 struct cylinder_widget *cylinder = data;
550 cylinder_cb(cylinder->description, data);
553 /* Return a frame containing a hbox inside a hbox */
554 static GtkWidget *frame_box(const char *title, GtkWidget *vbox)
556 GtkWidget *hbox, *frame;
558 hbox = gtk_hbox_new(FALSE, 10);
559 gtk_box_pack_start(GTK_BOX(vbox), hbox, TRUE, FALSE, 0);
561 frame = gtk_frame_new(title);
562 gtk_box_pack_start(GTK_BOX(hbox), frame, TRUE, FALSE, 0);
564 hbox = gtk_hbox_new(FALSE, 10);
565 gtk_container_add(GTK_CONTAINER(frame), hbox);
570 static GtkWidget *labeled_spinbutton(GtkWidget *box, const char *name, double min, double max, double incr)
572 GtkWidget *hbox, *label, *button;
574 hbox = gtk_hbox_new(FALSE, 0);
575 gtk_box_pack_start(GTK_BOX(box), hbox, TRUE, FALSE, 0);
577 label = gtk_label_new(name);
578 gtk_box_pack_start(GTK_BOX(hbox), label, TRUE, FALSE, 0);
580 button = gtk_spin_button_new_with_range(min, max, incr);
581 gtk_box_pack_start(GTK_BOX(hbox), button, TRUE, FALSE, 0);
583 gtk_spin_button_set_update_policy(GTK_SPIN_BUTTON(button), GTK_UPDATE_IF_VALID);
588 static void cylinder_widget(GtkWidget *vbox, struct cylinder_widget *cylinder, GtkListStore *model)
590 GtkWidget *frame, *hbox;
592 GtkEntryCompletion *completion;
596 * Cylinder type: description, size and
599 frame = gtk_frame_new("Cylinder");
601 hbox = gtk_hbox_new(FALSE, 3);
602 gtk_container_add(GTK_CONTAINER(frame), hbox);
604 widget = gtk_combo_box_entry_new_with_model(GTK_TREE_MODEL(model), 0);
605 gtk_box_pack_start(GTK_BOX(hbox), widget, FALSE, TRUE, 0);
607 cylinder->description = GTK_COMBO_BOX(widget);
608 g_signal_connect(widget, "changed", G_CALLBACK(cylinder_cb), cylinder);
610 entry = GTK_ENTRY(GTK_BIN(widget)->child);
611 g_signal_connect(entry, "activate", G_CALLBACK(cylinder_activate_cb), cylinder);
613 completion = gtk_entry_completion_new();
614 gtk_entry_completion_set_text_column(completion, 0);
615 gtk_entry_completion_set_model(completion, GTK_TREE_MODEL(model));
616 g_signal_connect(completion, "match-selected", G_CALLBACK(completion_cb), cylinder);
617 gtk_entry_set_completion(entry, completion);
619 hbox = gtk_hbox_new(FALSE, 3);
620 gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, TRUE, 0);
621 gtk_box_pack_start(GTK_BOX(hbox), frame, FALSE, TRUE, 0);
623 widget = create_spinbutton(hbox, "Size", 0, 300, 0.1);
624 cylinder->size = GTK_SPIN_BUTTON(widget);
626 widget = create_spinbutton(hbox, "Pressure", 0, 5000, 1);
627 cylinder->pressure = GTK_SPIN_BUTTON(widget);
630 * Cylinder start/end pressures
632 hbox = frame_box("Pressure", vbox);
634 widget = labeled_spinbutton(hbox, "Start", 0, 5000, 1);
635 cylinder->start = widget;
637 widget = labeled_spinbutton(hbox, "End", 0, 5000, 1);
638 cylinder->end = widget;
640 cylinder->pressure_button = gtk_check_button_new();
641 gtk_box_pack_start(GTK_BOX(hbox), cylinder->pressure_button, FALSE, FALSE, 3);
642 g_signal_connect(cylinder->pressure_button, "toggled", G_CALLBACK(pressure_cb), cylinder);
645 * Cylinder gas mix: Air, Nitrox or Trimix
647 hbox = frame_box("Gasmix", vbox);
649 widget = labeled_spinbutton(hbox, "O"UTF8_SUBSCRIPT_2 "%", 1, 100, 0.1);
650 cylinder->o2 = widget;
651 widget = labeled_spinbutton(hbox, "He%", 0, 100, 0.1);
652 cylinder->he = widget;
653 cylinder->gasmix_button = gtk_check_button_new();
654 gtk_box_pack_start(GTK_BOX(hbox), cylinder->gasmix_button, FALSE, FALSE, 3);
655 g_signal_connect(cylinder->gasmix_button, "toggled", G_CALLBACK(gasmix_cb), cylinder);
658 static int edit_cylinder_dialog(int index, cylinder_t *cyl)
661 GtkWidget *dialog, *vbox;
662 struct cylinder_widget cylinder;
665 cylinder.index = index;
666 cylinder.changed = 0;
671 *cyl = dive->cylinder[index];
673 dialog = gtk_dialog_new_with_buttons("Cylinder",
674 GTK_WINDOW(main_window),
675 GTK_DIALOG_DESTROY_WITH_PARENT,
676 GTK_STOCK_OK, GTK_RESPONSE_ACCEPT,
677 GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT,
680 vbox = gtk_dialog_get_content_area(GTK_DIALOG(dialog));
681 cylinder_widget(vbox, &cylinder, cylinder_model);
683 show_cylinder(cyl, &cylinder);
685 gtk_widget_show_all(dialog);
686 success = gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT;
688 record_cylinder_changes(cyl, &cylinder);
689 dive->cylinder[index] = *cyl;
690 mark_divelist_changed(TRUE);
691 update_cylinder_related_info(dive);
692 flush_divelist(dive);
695 gtk_widget_destroy(dialog);
700 static int get_model_index(GtkListStore *model, GtkTreeIter *iter)
705 path = gtk_tree_model_get_path(GTK_TREE_MODEL(model), iter);
706 p = gtk_tree_path_get_indices(path);
708 gtk_tree_path_free(path);
712 static void edit_cb(GtkButton *button, GtkTreeView *tree_view)
716 GtkListStore *model = cylinder_list.model;
717 GtkTreeSelection *selection;
720 selection = gtk_tree_view_get_selection(tree_view);
722 /* Nothing selected? This shouldn't happen, since the button should be inactive */
723 if (!gtk_tree_selection_get_selected(selection, NULL, &iter))
726 index = get_model_index(model, &iter);
727 if (!edit_cylinder_dialog(index, &cyl))
730 set_one_cylinder(index, &cyl, model, &iter);
734 static void add_cb(GtkButton *button, GtkTreeView *tree_view)
736 int index = cylinder_list.max_index;
738 GtkListStore *model = cylinder_list.model;
739 GtkTreeSelection *selection;
742 if (!edit_cylinder_dialog(index, &cyl))
745 gtk_list_store_append(model, &iter);
746 set_one_cylinder(index, &cyl, model, &iter);
748 selection = gtk_tree_view_get_selection(tree_view);
749 gtk_tree_selection_select_iter(selection, &iter);
751 cylinder_list.max_index++;
752 gtk_widget_set_sensitive(cylinder_list.add, cylinder_list.max_index < MAX_CYLINDERS);
755 static void del_cb(GtkButton *button, GtkTreeView *tree_view)
759 GtkListStore *model = cylinder_list.model;
760 GtkTreeSelection *selection;
764 selection = gtk_tree_view_get_selection(tree_view);
766 /* Nothing selected? This shouldn't happen, since the button should be inactive */
767 if (!gtk_tree_selection_get_selected(selection, NULL, &iter))
770 index = get_model_index(model, &iter);
775 cyl = dive->cylinder + index;
776 nr = cylinder_list.max_index - index - 1;
778 gtk_list_store_remove(model, &iter);
780 cylinder_list.max_index--;
781 memmove(cyl, cyl+1, nr*sizeof(*cyl));
782 memset(cyl+nr, 0, sizeof(*cyl));
784 mark_divelist_changed(TRUE);
785 flush_divelist(dive);
787 gtk_widget_set_sensitive(cylinder_list.edit, 0);
788 gtk_widget_set_sensitive(cylinder_list.del, 0);
789 gtk_widget_set_sensitive(cylinder_list.add, 1);
792 static GtkListStore *create_tank_size_model(void)
796 model = gtk_list_store_new(3,
797 G_TYPE_STRING, /* Tank name */
798 G_TYPE_INT, /* Tank size in mliter */
799 G_TYPE_INT, /* Tank working pressure in mbar */
802 fill_tank_list(model);
806 static void size_data_func(GtkTreeViewColumn *col,
807 GtkCellRenderer *renderer,
813 double size, pressure;
816 gtk_tree_model_get(model, iter, CYL_SIZE, &ml, CYL_WORKP, &mbar, -1);
817 convert_volume_pressure(ml, mbar, &size, &pressure);
819 snprintf(buffer, sizeof(buffer), "%.1f", size);
821 strcpy(buffer, "unkn");
822 g_object_set(renderer, "text", buffer, NULL);
825 static void pressure_data_func(GtkTreeViewColumn *col,
826 GtkCellRenderer *renderer,
831 int index = (long)data;
836 gtk_tree_model_get(model, iter, index, &mbar, -1);
837 decimals = convert_pressure(mbar, &pressure);
839 snprintf(buffer, sizeof(buffer), "%.*f", decimals, pressure);
842 g_object_set(renderer, "text", buffer, NULL);
845 static void percentage_data_func(GtkTreeViewColumn *col,
846 GtkCellRenderer *renderer,
851 int index = (long)data;
855 gtk_tree_model_get(model, iter, index, &permille, -1);
857 snprintf(buffer, sizeof(buffer), "%.1f%%", permille / 10.0);
860 g_object_set(renderer, "text", buffer, NULL);
863 static void selection_cb(GtkTreeSelection *selection, GtkTreeModel *model)
868 selected = gtk_tree_selection_get_selected(selection, NULL, &iter);
869 gtk_widget_set_sensitive(cylinder_list.edit, selected);
870 gtk_widget_set_sensitive(cylinder_list.del, selected);
873 static void row_activated_cb(GtkTreeView *tree_view,
875 GtkTreeViewColumn *column,
878 edit_cb(NULL, tree_view);
881 GtkWidget *cylinder_list_widget(void)
883 GtkListStore *model = cylinder_list.model;
884 GtkWidget *tree_view;
885 GtkTreeSelection *selection;
887 tree_view = gtk_tree_view_new_with_model(GTK_TREE_MODEL(model));
888 gtk_widget_set_can_focus(tree_view, FALSE);
890 g_signal_connect(tree_view, "row-activated", G_CALLBACK(row_activated_cb), model);
892 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(tree_view));
893 gtk_tree_selection_set_mode(GTK_TREE_SELECTION(selection), GTK_SELECTION_BROWSE);
894 g_signal_connect(selection, "changed", G_CALLBACK(selection_cb), model);
896 g_object_set(G_OBJECT(tree_view), "headers-visible", TRUE,
897 "enable-grid-lines", GTK_TREE_VIEW_GRID_LINES_BOTH,
900 tree_view_column(tree_view, CYL_DESC, "Type", NULL, ALIGN_LEFT | UNSORTABLE);
901 tree_view_column(tree_view, CYL_SIZE, "Size", size_data_func, ALIGN_RIGHT | UNSORTABLE);
902 tree_view_column(tree_view, CYL_WORKP, "MaxPress", pressure_data_func, ALIGN_RIGHT | UNSORTABLE);
903 tree_view_column(tree_view, CYL_STARTP, "Start", pressure_data_func, ALIGN_RIGHT | UNSORTABLE);
904 tree_view_column(tree_view, CYL_ENDP, "End", pressure_data_func, ALIGN_RIGHT | UNSORTABLE);
905 tree_view_column(tree_view, CYL_O2, "O" UTF8_SUBSCRIPT_2 "%", percentage_data_func, ALIGN_RIGHT | UNSORTABLE);
906 tree_view_column(tree_view, CYL_HE, "He%", percentage_data_func, ALIGN_RIGHT | UNSORTABLE);
910 static GtkWidget *cylinder_list_create(void)
914 model = gtk_list_store_new(CYL_COLUMNS,
915 G_TYPE_STRING, /* CYL_DESC: utf8 */
916 G_TYPE_INT, /* CYL_SIZE: mliter */
917 G_TYPE_INT, /* CYL_WORKP: mbar */
918 G_TYPE_INT, /* CYL_STARTP: mbar */
919 G_TYPE_INT, /* CYL_ENDP: mbar */
920 G_TYPE_INT, /* CYL_O2: permille */
921 G_TYPE_INT /* CYL_HE: permille */
923 cylinder_list.model = model;
924 return cylinder_list_widget();
927 GtkWidget *equipment_widget(void)
929 GtkWidget *vbox, *hbox, *frame, *framebox, *tree_view;
930 GtkWidget *add, *del, *edit;
932 vbox = gtk_vbox_new(FALSE, 3);
935 * We create the cylinder size model at startup, since
936 * we're going to share it across all cylinders and all
937 * dives. So if you add a new cylinder type in one dive,
938 * it will show up when you edit the cylinder types for
941 cylinder_model = create_tank_size_model();
943 tree_view = cylinder_list_create();
945 hbox = gtk_hbox_new(FALSE, 3);
946 gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 3);
948 frame = gtk_frame_new("Cylinders");
949 gtk_box_pack_start(GTK_BOX(hbox), frame, TRUE, FALSE, 3);
951 framebox = gtk_vbox_new(FALSE, 3);
952 gtk_container_add(GTK_CONTAINER(frame), framebox);
954 hbox = gtk_hbox_new(FALSE, 3);
955 gtk_box_pack_start(GTK_BOX(framebox), hbox, TRUE, FALSE, 3);
957 gtk_box_pack_start(GTK_BOX(hbox), tree_view, TRUE, FALSE, 3);
959 hbox = gtk_hbox_new(TRUE, 3);
960 gtk_box_pack_start(GTK_BOX(framebox), hbox, TRUE, FALSE, 3);
962 edit = gtk_button_new_from_stock(GTK_STOCK_EDIT);
963 add = gtk_button_new_from_stock(GTK_STOCK_ADD);
964 del = gtk_button_new_from_stock(GTK_STOCK_DELETE);
965 gtk_box_pack_start(GTK_BOX(hbox), edit, FALSE, FALSE, 0);
966 gtk_box_pack_start(GTK_BOX(hbox), add, FALSE, FALSE, 0);
967 gtk_box_pack_start(GTK_BOX(hbox), del, FALSE, FALSE, 0);
969 cylinder_list.edit = edit;
970 cylinder_list.add = add;
971 cylinder_list.del = del;
973 g_signal_connect(edit, "clicked", G_CALLBACK(edit_cb), tree_view);
974 g_signal_connect(add, "clicked", G_CALLBACK(add_cb), tree_view);
975 g_signal_connect(del, "clicked", G_CALLBACK(del_cb), tree_view);