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 void convert_volume_pressure(int ml, int mbar, double *v, double *p)
69 double volume, pressure;
73 if (output_units.volume == CUFT) {
74 volume = ml_to_cuft(ml);
75 volume *= bar_to_atm(mbar / 1000.0);
78 if (output_units.pressure == PSI) {
79 pressure = mbar_to_PSI(mbar);
81 pressure = mbar / 1000.0;
87 static void set_cylinder_type_spinbuttons(struct cylinder_widget *cylinder, int ml, int mbar)
89 double volume, pressure;
91 convert_volume_pressure(ml, mbar, &volume, &pressure);
92 gtk_spin_button_set_value(cylinder->size, volume);
93 gtk_spin_button_set_value(cylinder->pressure, pressure);
96 static void set_cylinder_pressure_spinbuttons(struct cylinder_widget *cylinder, cylinder_t *cyl)
99 unsigned int start, end;
102 start = cyl->start.mbar;
106 start = cyl->sample_start.mbar;
107 end = cyl->sample_end.mbar;
109 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(cylinder->pressure_button), set);
110 gtk_widget_set_sensitive(cylinder->start, set);
111 gtk_widget_set_sensitive(cylinder->end, set);
113 convert_pressure(start, &pressure);
114 gtk_spin_button_set_value(GTK_SPIN_BUTTON(cylinder->start), pressure);
115 convert_pressure(end, &pressure);
116 gtk_spin_button_set_value(GTK_SPIN_BUTTON(cylinder->end), pressure);
120 * The gtk_tree_model_foreach() interface is bad. It could have
121 * returned whether the callback ever returned true
123 static GtkTreeIter *found_match = NULL;
124 static GtkTreeIter match_iter;
126 static gboolean match_cylinder(GtkTreeModel *model,
133 const char *desc = data;
135 gtk_tree_model_get(model, iter, 0, &name, -1);
136 match = !strcmp(desc, name);
140 found_match = &match_iter;
145 static int get_active_cylinder(GtkComboBox *combo_box, GtkTreeIter *iter)
149 if (gtk_combo_box_get_active_iter(combo_box, iter))
152 desc = gtk_combo_box_get_active_text(combo_box);
155 gtk_tree_model_foreach(GTK_TREE_MODEL(cylinder_model), match_cylinder, (void *)desc);
161 *iter = *found_match;
162 gtk_combo_box_set_active_iter(combo_box, iter);
166 static void cylinder_cb(GtkComboBox *combo_box, gpointer data)
169 GtkTreeModel *model = gtk_combo_box_get_model(combo_box);
171 struct cylinder_widget *cylinder = data;
172 cylinder_t *cyl = current_dive->cylinder + cylinder->index;
174 /* Did the user set it to some non-standard value? */
175 if (!get_active_cylinder(combo_box, &iter)) {
176 cylinder->changed = 1;
181 * We get "change" signal callbacks just because we set
182 * the description by hand. Whatever. So ignore them if
185 if (!cylinder->changed && cyl->type.description) {
187 char *desc = gtk_combo_box_get_active_text(combo_box);
189 same = !strcmp(desc, cyl->type.description);
194 cylinder->changed = 1;
196 gtk_tree_model_get(model, &iter,
201 set_cylinder_type_spinbuttons(cylinder, ml, mbar);
204 static GtkTreeIter *add_cylinder_type(const char *desc, int ml, int mbar, GtkTreeIter *iter)
208 /* Don't even bother adding stuff without a size */
213 model = GTK_TREE_MODEL(cylinder_model);
214 gtk_tree_model_foreach(model, match_cylinder, (void *)desc);
217 GtkListStore *store = GTK_LIST_STORE(model);
219 gtk_list_store_append(store, iter);
220 gtk_list_store_set(store, iter,
231 * When adding a dive, we'll add all the pre-existing cylinder
232 * information from that dive to our cylinder model.
234 void add_cylinder_description(cylinder_type_t *type)
238 unsigned int size, workp;
240 desc = type->description;
243 size = type->size.mliter;
244 workp = type->workingpressure.mbar;
245 add_cylinder_type(desc, size, workp, &iter);
248 static void add_cylinder(struct cylinder_widget *cylinder, const char *desc, int ml, int mbar)
250 GtkTreeIter iter, *match;
252 cylinder->name = desc;
253 match = add_cylinder_type(desc, ml, mbar, &iter);
255 gtk_combo_box_set_active_iter(cylinder->description, match);
258 static void show_cylinder(cylinder_t *cyl, struct cylinder_widget *cylinder)
265 /* Don't show uninitialized cylinder widgets */
266 if (!cylinder->description)
269 desc = cyl->type.description;
272 ml = cyl->type.size.mliter;
273 mbar = cyl->type.workingpressure.mbar;
274 add_cylinder(cylinder, desc, ml, mbar);
276 set_cylinder_type_spinbuttons(cylinder,
277 cyl->type.size.mliter, cyl->type.workingpressure.mbar);
278 set_cylinder_pressure_spinbuttons(cylinder, cyl);
280 gasmix = cyl->gasmix.o2.permille || cyl->gasmix.he.permille;
281 gtk_widget_set_sensitive(cylinder->o2, gasmix);
282 gtk_widget_set_sensitive(cylinder->he, gasmix);
283 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(cylinder->gasmix_button), gasmix);
285 o2 = cyl->gasmix.o2.permille / 10.0;
286 he = cyl->gasmix.he.permille / 10.0;
289 gtk_spin_button_set_value(GTK_SPIN_BUTTON(cylinder->o2), o2);
290 gtk_spin_button_set_value(GTK_SPIN_BUTTON(cylinder->he), he);
293 int cylinder_none(cylinder_t *cyl)
295 return !cyl->type.size.mliter &&
296 !cyl->type.workingpressure.mbar &&
297 !cyl->type.description &&
298 !cyl->gasmix.o2.permille &&
299 !cyl->gasmix.he.permille &&
300 !cyl->sample_start.mbar &&
301 !cyl->sample_end.mbar &&
306 static void set_one_cylinder(int index, cylinder_t *cyl, GtkListStore *model, GtkTreeIter *iter)
308 unsigned int start, end;
310 start = cyl->start.mbar ? : cyl->sample_start.mbar;
311 end = cyl->end.mbar ? : cyl->sample_end.mbar;
312 gtk_list_store_set(model, iter,
313 CYL_DESC, cyl->type.description ? : "",
314 CYL_SIZE, cyl->type.size.mliter,
315 CYL_WORKP, cyl->type.workingpressure.mbar,
318 CYL_O2, cyl->gasmix.o2.permille,
319 CYL_HE, cyl->gasmix.he.permille,
323 void show_dive_equipment(struct dive *dive)
329 model = cylinder_list.model;
330 gtk_list_store_clear(model);
333 cylinder_t *cyl = &dive->cylinder[max-1];
335 if (!cylinder_none(cyl))
339 cylinder_list.max_index = max;
341 gtk_widget_set_sensitive(cylinder_list.edit, 0);
342 gtk_widget_set_sensitive(cylinder_list.del, 0);
343 gtk_widget_set_sensitive(cylinder_list.add, max < MAX_CYLINDERS);
345 for (i = 0; i < max; i++) {
346 cylinder_t *cyl = dive->cylinder+i;
348 gtk_list_store_append(model, &iter);
349 set_one_cylinder(i, cyl, model, &iter);
353 static GtkWidget *create_spinbutton(GtkWidget *vbox, const char *name, double min, double max, double incr)
355 GtkWidget *frame, *hbox, *button;
357 frame = gtk_frame_new(name);
358 gtk_box_pack_start(GTK_BOX(vbox), frame, TRUE, FALSE, 0);
360 hbox = gtk_hbox_new(FALSE, 3);
361 gtk_container_add(GTK_CONTAINER(frame), hbox);
363 button = gtk_spin_button_new_with_range(min, max, incr);
364 gtk_box_pack_start(GTK_BOX(hbox), button, TRUE, FALSE, 0);
366 gtk_spin_button_set_update_policy(GTK_SPIN_BUTTON(button), GTK_UPDATE_IF_VALID);
371 static void fill_cylinder_info(struct cylinder_widget *cylinder, cylinder_t *cyl, const char *desc,
372 double volume, double pressure, double start, double end, int o2, int he)
376 if (output_units.pressure == PSI) {
377 pressure = psi_to_bar(pressure);
378 start = psi_to_bar(start);
379 end = psi_to_bar(end);
382 if (pressure && output_units.volume == CUFT) {
383 volume = cuft_to_l(volume);
384 volume /= bar_to_atm(pressure);
387 ml = volume * 1000 + 0.5;
388 mbar = pressure * 1000 + 0.5;
390 /* Ignore obviously crazy He values */
394 /* We have a rule that normal air is all zeroes */
395 if (!he && o2 > 208 && o2 < 211)
398 cyl->type.description = desc;
399 cyl->type.size.mliter = ml;
400 cyl->type.workingpressure.mbar = mbar;
401 cyl->start.mbar = start * 1000 + 0.5;
402 cyl->end.mbar = end * 1000 + 0.5;
403 cyl->gasmix.o2.permille = o2;
404 cyl->gasmix.he.permille = he;
407 * Also, insert it into the model if it doesn't already exist
409 add_cylinder(cylinder, desc, ml, mbar);
412 static void record_cylinder_changes(cylinder_t *cyl, struct cylinder_widget *cylinder)
416 double volume, pressure, start, end;
419 /* Ignore uninitialized cylinder widgets */
420 box = cylinder->description;
424 desc = gtk_combo_box_get_active_text(box);
425 volume = gtk_spin_button_get_value(cylinder->size);
426 pressure = gtk_spin_button_get_value(cylinder->pressure);
427 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(cylinder->pressure_button))) {
428 start = gtk_spin_button_get_value(GTK_SPIN_BUTTON(cylinder->start));
429 end = gtk_spin_button_get_value(GTK_SPIN_BUTTON(cylinder->end));
433 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(cylinder->gasmix_button))) {
434 o2 = gtk_spin_button_get_value(GTK_SPIN_BUTTON(cylinder->o2))*10 + 0.5;
435 he = gtk_spin_button_get_value(GTK_SPIN_BUTTON(cylinder->he))*10 + 0.5;
440 fill_cylinder_info(cylinder, cyl, desc, volume, pressure, start, end, o2, he);
444 * We hardcode the most common standard cylinders,
445 * we should pick up any other names from the dive
448 static struct tank_info {
450 int cuft, ml, psi, bar;
452 /* Need an empty entry for the no-cylinder case */
455 /* Size-only metric cylinders */
456 { "10.0 l", .ml = 10000 },
457 { "11.1 l", .ml = 11100 },
459 /* Most common AL cylinders */
460 { "AL50", .cuft = 50, .psi = 3000 },
461 { "AL63", .cuft = 63, .psi = 3000 },
462 { "AL72", .cuft = 72, .psi = 3000 },
463 { "AL80", .cuft = 80, .psi = 3000 },
464 { "AL100", .cuft = 100, .psi = 3300 },
466 /* Somewhat common LP steel cylinders */
467 { "LP85", .cuft = 85, 2640 },
468 { "LP95", .cuft = 95, 2640 },
469 { "LP108", .cuft = 108, 2640 },
470 { "LP121", .cuft = 121, 2640 },
472 /* Somewhat common HP steel cylinders */
473 { "HP65", .cuft = 65, .psi = 3442 },
474 { "HP80", .cuft = 80, .psi = 3442 },
475 { "HP100", .cuft = 100, .psi = 3442 },
476 { "HP119", .cuft = 119, .psi = 3442 },
477 { "HP130", .cuft = 130, .psi = 3442 },
479 /* Common European steel cylinders */
480 { "10L 300 bar", .ml = 10000, .bar = 300 },
481 { "12L 200 bar", .ml = 12000, .bar = 200 },
482 { "12L 232 bar", .ml = 12000, .bar = 232 },
483 { "12L 300 bar", .ml = 12000, .bar = 300 },
484 { "15L 200 bar", .ml = 15000, .bar = 200 },
485 { "15L 232 bar", .ml = 15000, .bar = 232 },
486 { "D7 300 bar", .ml = 14000, .bar = 300 },
487 { "D8.5 232 bar", .ml = 17000, .bar = 232 },
488 { "D12 232 bar", .ml = 24000, .bar = 232 },
490 /* We'll fill in more from the dive log dynamically */
494 static void fill_tank_list(GtkListStore *store)
497 struct tank_info *info = tank_info;
501 int cuft = info->cuft;
504 double bar = info->bar;
506 /* Is it in cuft and psi? */
508 bar = psi_to_bar(psi);
511 double airvolume = cuft_to_l(cuft) * 1000.0;
512 double atm = bar_to_atm(bar);
514 ml = airvolume / atm + 0.5;
518 mbar = bar * 1000 + 0.5;
520 gtk_list_store_append(store, &iter);
521 gtk_list_store_set(store, &iter,
530 static void gasmix_cb(GtkToggleButton *button, gpointer data)
532 struct cylinder_widget *cylinder = data;
535 state = gtk_toggle_button_get_active(button);
536 gtk_widget_set_sensitive(cylinder->o2, state);
537 gtk_widget_set_sensitive(cylinder->he, state);
540 static void pressure_cb(GtkToggleButton *button, gpointer data)
542 struct cylinder_widget *cylinder = data;
545 state = gtk_toggle_button_get_active(button);
546 gtk_widget_set_sensitive(cylinder->start, state);
547 gtk_widget_set_sensitive(cylinder->end, state);
550 static gboolean completion_cb(GtkEntryCompletion *widget, GtkTreeModel *model, GtkTreeIter *iter, struct cylinder_widget *cylinder)
553 unsigned int ml, mbar;
555 gtk_tree_model_get(model, iter, CYL_DESC, &desc, CYL_SIZE, &ml, CYL_WORKP, &mbar, -1);
556 add_cylinder(cylinder, desc, ml, mbar);
560 static void cylinder_activate_cb(GtkComboBox *combo_box, gpointer data)
562 struct cylinder_widget *cylinder = data;
563 cylinder_cb(cylinder->description, data);
566 /* Return a frame containing a hbox inside a hbox */
567 static GtkWidget *frame_box(const char *title, GtkWidget *vbox)
569 GtkWidget *hbox, *frame;
571 hbox = gtk_hbox_new(FALSE, 10);
572 gtk_box_pack_start(GTK_BOX(vbox), hbox, TRUE, FALSE, 0);
574 frame = gtk_frame_new(title);
575 gtk_box_pack_start(GTK_BOX(hbox), frame, TRUE, FALSE, 0);
577 hbox = gtk_hbox_new(FALSE, 10);
578 gtk_container_add(GTK_CONTAINER(frame), hbox);
583 static GtkWidget *labeled_spinbutton(GtkWidget *box, const char *name, double min, double max, double incr)
585 GtkWidget *hbox, *label, *button;
587 hbox = gtk_hbox_new(FALSE, 0);
588 gtk_box_pack_start(GTK_BOX(box), hbox, TRUE, FALSE, 0);
590 label = gtk_label_new(name);
591 gtk_box_pack_start(GTK_BOX(hbox), label, TRUE, FALSE, 0);
593 button = gtk_spin_button_new_with_range(min, max, incr);
594 gtk_box_pack_start(GTK_BOX(hbox), button, TRUE, FALSE, 0);
596 gtk_spin_button_set_update_policy(GTK_SPIN_BUTTON(button), GTK_UPDATE_IF_VALID);
601 static void cylinder_widget(GtkWidget *vbox, struct cylinder_widget *cylinder, GtkListStore *model)
603 GtkWidget *frame, *hbox;
605 GtkEntryCompletion *completion;
609 * Cylinder type: description, size and
612 frame = gtk_frame_new("Cylinder");
614 hbox = gtk_hbox_new(FALSE, 3);
615 gtk_container_add(GTK_CONTAINER(frame), hbox);
617 widget = gtk_combo_box_entry_new_with_model(GTK_TREE_MODEL(model), 0);
618 gtk_box_pack_start(GTK_BOX(hbox), widget, FALSE, TRUE, 0);
620 cylinder->description = GTK_COMBO_BOX(widget);
621 g_signal_connect(widget, "changed", G_CALLBACK(cylinder_cb), cylinder);
623 entry = GTK_ENTRY(GTK_BIN(widget)->child);
624 g_signal_connect(entry, "activate", G_CALLBACK(cylinder_activate_cb), cylinder);
626 completion = gtk_entry_completion_new();
627 gtk_entry_completion_set_text_column(completion, 0);
628 gtk_entry_completion_set_model(completion, GTK_TREE_MODEL(model));
629 g_signal_connect(completion, "match-selected", G_CALLBACK(completion_cb), cylinder);
630 gtk_entry_set_completion(entry, completion);
632 hbox = gtk_hbox_new(FALSE, 3);
633 gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, TRUE, 0);
634 gtk_box_pack_start(GTK_BOX(hbox), frame, FALSE, TRUE, 0);
636 widget = create_spinbutton(hbox, "Size", 0, 300, 0.1);
637 cylinder->size = GTK_SPIN_BUTTON(widget);
639 widget = create_spinbutton(hbox, "Pressure", 0, 5000, 1);
640 cylinder->pressure = GTK_SPIN_BUTTON(widget);
643 * Cylinder start/end pressures
645 hbox = frame_box("Pressure", vbox);
647 widget = labeled_spinbutton(hbox, "Start", 0, 5000, 1);
648 cylinder->start = widget;
650 widget = labeled_spinbutton(hbox, "End", 0, 5000, 1);
651 cylinder->end = widget;
653 cylinder->pressure_button = gtk_check_button_new();
654 gtk_box_pack_start(GTK_BOX(hbox), cylinder->pressure_button, FALSE, FALSE, 3);
655 g_signal_connect(cylinder->pressure_button, "toggled", G_CALLBACK(pressure_cb), cylinder);
658 * Cylinder gas mix: Air, Nitrox or Trimix
660 hbox = frame_box("Gasmix", vbox);
662 widget = labeled_spinbutton(hbox, "O"UTF8_SUBSCRIPT_2 "%", 1, 100, 0.1);
663 cylinder->o2 = widget;
664 widget = labeled_spinbutton(hbox, "He%", 0, 100, 0.1);
665 cylinder->he = widget;
666 cylinder->gasmix_button = gtk_check_button_new();
667 gtk_box_pack_start(GTK_BOX(hbox), cylinder->gasmix_button, FALSE, FALSE, 3);
668 g_signal_connect(cylinder->gasmix_button, "toggled", G_CALLBACK(gasmix_cb), cylinder);
671 static int edit_cylinder_dialog(int index, cylinder_t *cyl)
674 GtkWidget *dialog, *vbox;
675 struct cylinder_widget cylinder;
678 cylinder.index = index;
679 cylinder.changed = 0;
684 *cyl = dive->cylinder[index];
686 dialog = gtk_dialog_new_with_buttons("Cylinder",
687 GTK_WINDOW(main_window),
688 GTK_DIALOG_DESTROY_WITH_PARENT,
689 GTK_STOCK_OK, GTK_RESPONSE_ACCEPT,
690 GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT,
693 vbox = gtk_dialog_get_content_area(GTK_DIALOG(dialog));
694 cylinder_widget(vbox, &cylinder, cylinder_model);
696 show_cylinder(cyl, &cylinder);
698 gtk_widget_show_all(dialog);
699 success = gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT;
701 record_cylinder_changes(cyl, &cylinder);
702 dive->cylinder[index] = *cyl;
703 mark_divelist_changed(TRUE);
704 update_cylinder_related_info(dive);
705 flush_divelist(dive);
708 gtk_widget_destroy(dialog);
713 static int get_model_index(GtkListStore *model, GtkTreeIter *iter)
718 path = gtk_tree_model_get_path(GTK_TREE_MODEL(model), iter);
719 p = gtk_tree_path_get_indices(path);
721 gtk_tree_path_free(path);
725 static void edit_cb(GtkButton *button, GtkTreeView *tree_view)
729 GtkListStore *model = cylinder_list.model;
730 GtkTreeSelection *selection;
733 selection = gtk_tree_view_get_selection(tree_view);
735 /* Nothing selected? This shouldn't happen, since the button should be inactive */
736 if (!gtk_tree_selection_get_selected(selection, NULL, &iter))
739 index = get_model_index(model, &iter);
740 if (!edit_cylinder_dialog(index, &cyl))
743 set_one_cylinder(index, &cyl, model, &iter);
747 static void add_cb(GtkButton *button, GtkTreeView *tree_view)
749 int index = cylinder_list.max_index;
751 GtkListStore *model = cylinder_list.model;
752 GtkTreeSelection *selection;
755 if (!edit_cylinder_dialog(index, &cyl))
758 gtk_list_store_append(model, &iter);
759 set_one_cylinder(index, &cyl, model, &iter);
761 selection = gtk_tree_view_get_selection(tree_view);
762 gtk_tree_selection_select_iter(selection, &iter);
764 cylinder_list.max_index++;
765 gtk_widget_set_sensitive(cylinder_list.add, cylinder_list.max_index < MAX_CYLINDERS);
768 static void del_cb(GtkButton *button, GtkTreeView *tree_view)
772 GtkListStore *model = cylinder_list.model;
773 GtkTreeSelection *selection;
777 selection = gtk_tree_view_get_selection(tree_view);
779 /* Nothing selected? This shouldn't happen, since the button should be inactive */
780 if (!gtk_tree_selection_get_selected(selection, NULL, &iter))
783 index = get_model_index(model, &iter);
788 cyl = dive->cylinder + index;
789 nr = cylinder_list.max_index - index - 1;
791 gtk_list_store_remove(model, &iter);
793 cylinder_list.max_index--;
794 memmove(cyl, cyl+1, nr*sizeof(*cyl));
795 memset(cyl+nr, 0, sizeof(*cyl));
797 mark_divelist_changed(TRUE);
798 flush_divelist(dive);
800 gtk_widget_set_sensitive(cylinder_list.edit, 0);
801 gtk_widget_set_sensitive(cylinder_list.del, 0);
802 gtk_widget_set_sensitive(cylinder_list.add, 1);
805 static GtkListStore *create_tank_size_model(void)
809 model = gtk_list_store_new(3,
810 G_TYPE_STRING, /* Tank name */
811 G_TYPE_INT, /* Tank size in mliter */
812 G_TYPE_INT, /* Tank working pressure in mbar */
815 fill_tank_list(model);
819 static void size_data_func(GtkTreeViewColumn *col,
820 GtkCellRenderer *renderer,
826 double size, pressure;
829 gtk_tree_model_get(model, iter, CYL_SIZE, &ml, CYL_WORKP, &mbar, -1);
830 convert_volume_pressure(ml, mbar, &size, &pressure);
832 snprintf(buffer, sizeof(buffer), "%.1f", size);
834 strcpy(buffer, "unkn");
835 g_object_set(renderer, "text", buffer, NULL);
838 static void pressure_data_func(GtkTreeViewColumn *col,
839 GtkCellRenderer *renderer,
844 int index = (long)data;
849 gtk_tree_model_get(model, iter, index, &mbar, -1);
850 decimals = convert_pressure(mbar, &pressure);
852 snprintf(buffer, sizeof(buffer), "%.*f", decimals, pressure);
855 g_object_set(renderer, "text", buffer, NULL);
858 static void percentage_data_func(GtkTreeViewColumn *col,
859 GtkCellRenderer *renderer,
864 int index = (long)data;
868 gtk_tree_model_get(model, iter, index, &permille, -1);
870 snprintf(buffer, sizeof(buffer), "%.1f%%", permille / 10.0);
873 g_object_set(renderer, "text", buffer, NULL);
876 static void selection_cb(GtkTreeSelection *selection, GtkTreeModel *model)
881 selected = gtk_tree_selection_get_selected(selection, NULL, &iter);
882 gtk_widget_set_sensitive(cylinder_list.edit, selected);
883 gtk_widget_set_sensitive(cylinder_list.del, selected);
886 static void row_activated_cb(GtkTreeView *tree_view,
888 GtkTreeViewColumn *column,
891 edit_cb(NULL, tree_view);
894 GtkWidget *cylinder_list_widget(void)
896 GtkListStore *model = cylinder_list.model;
897 GtkWidget *tree_view;
898 GtkTreeSelection *selection;
900 tree_view = gtk_tree_view_new_with_model(GTK_TREE_MODEL(model));
901 gtk_widget_set_can_focus(tree_view, FALSE);
903 g_signal_connect(tree_view, "row-activated", G_CALLBACK(row_activated_cb), model);
905 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(tree_view));
906 gtk_tree_selection_set_mode(GTK_TREE_SELECTION(selection), GTK_SELECTION_BROWSE);
907 g_signal_connect(selection, "changed", G_CALLBACK(selection_cb), model);
909 g_object_set(G_OBJECT(tree_view), "headers-visible", TRUE,
910 "enable-grid-lines", GTK_TREE_VIEW_GRID_LINES_BOTH,
913 tree_view_column(tree_view, CYL_DESC, "Type", NULL, ALIGN_LEFT | UNSORTABLE);
914 tree_view_column(tree_view, CYL_SIZE, "Size", size_data_func, ALIGN_RIGHT | UNSORTABLE);
915 tree_view_column(tree_view, CYL_WORKP, "MaxPress", pressure_data_func, ALIGN_RIGHT | UNSORTABLE);
916 tree_view_column(tree_view, CYL_STARTP, "Start", pressure_data_func, ALIGN_RIGHT | UNSORTABLE);
917 tree_view_column(tree_view, CYL_ENDP, "End", pressure_data_func, ALIGN_RIGHT | UNSORTABLE);
918 tree_view_column(tree_view, CYL_O2, "O" UTF8_SUBSCRIPT_2 "%", percentage_data_func, ALIGN_RIGHT | UNSORTABLE);
919 tree_view_column(tree_view, CYL_HE, "He%", percentage_data_func, ALIGN_RIGHT | UNSORTABLE);
923 static GtkWidget *cylinder_list_create(void)
927 model = gtk_list_store_new(CYL_COLUMNS,
928 G_TYPE_STRING, /* CYL_DESC: utf8 */
929 G_TYPE_INT, /* CYL_SIZE: mliter */
930 G_TYPE_INT, /* CYL_WORKP: mbar */
931 G_TYPE_INT, /* CYL_STARTP: mbar */
932 G_TYPE_INT, /* CYL_ENDP: mbar */
933 G_TYPE_INT, /* CYL_O2: permille */
934 G_TYPE_INT /* CYL_HE: permille */
936 cylinder_list.model = model;
937 return cylinder_list_widget();
940 GtkWidget *equipment_widget(void)
942 GtkWidget *vbox, *hbox, *frame, *framebox, *tree_view;
943 GtkWidget *add, *del, *edit;
945 vbox = gtk_vbox_new(FALSE, 3);
948 * We create the cylinder size model at startup, since
949 * we're going to share it across all cylinders and all
950 * dives. So if you add a new cylinder type in one dive,
951 * it will show up when you edit the cylinder types for
954 cylinder_model = create_tank_size_model();
956 tree_view = cylinder_list_create();
958 hbox = gtk_hbox_new(FALSE, 3);
959 gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 3);
961 frame = gtk_frame_new("Cylinders");
962 gtk_box_pack_start(GTK_BOX(hbox), frame, TRUE, FALSE, 3);
964 framebox = gtk_vbox_new(FALSE, 3);
965 gtk_container_add(GTK_CONTAINER(frame), framebox);
967 hbox = gtk_hbox_new(FALSE, 3);
968 gtk_box_pack_start(GTK_BOX(framebox), hbox, TRUE, FALSE, 3);
970 gtk_box_pack_start(GTK_BOX(hbox), tree_view, TRUE, FALSE, 3);
972 hbox = gtk_hbox_new(TRUE, 3);
973 gtk_box_pack_start(GTK_BOX(framebox), hbox, TRUE, FALSE, 3);
975 edit = gtk_button_new_from_stock(GTK_STOCK_EDIT);
976 add = gtk_button_new_from_stock(GTK_STOCK_ADD);
977 del = gtk_button_new_from_stock(GTK_STOCK_DELETE);
978 gtk_box_pack_start(GTK_BOX(hbox), edit, FALSE, FALSE, 0);
979 gtk_box_pack_start(GTK_BOX(hbox), add, FALSE, FALSE, 0);
980 gtk_box_pack_start(GTK_BOX(hbox), del, FALSE, FALSE, 0);
982 cylinder_list.edit = edit;
983 cylinder_list.add = add;
984 cylinder_list.del = del;
986 g_signal_connect(edit, "clicked", G_CALLBACK(edit_cb), tree_view);
987 g_signal_connect(add, "clicked", G_CALLBACK(add_cb), tree_view);
988 g_signal_connect(del, "clicked", G_CALLBACK(del_cb), tree_view);