+ gtk_box_pack_start(GTK_BOX(hbox), cylinder->gasmix_button, FALSE, FALSE, 3);
+ g_signal_connect(cylinder->gasmix_button, "toggled", G_CALLBACK(gasmix_cb), cylinder);
+}
+
+static gboolean weight_completion_cb(GtkEntryCompletion *widget, GtkTreeModel *model, GtkTreeIter *iter, struct ws_widget *ws_widget)
+{
+ const char *desc;
+ unsigned int weight;
+
+ gtk_tree_model_get(model, iter, WS_DESC, &desc, WS_WEIGHT, &weight, -1);
+ add_weightsystem(ws_widget, desc, weight);
+ return TRUE;
+}
+
+static void weight_activate_cb(GtkComboBox *combo_box, gpointer data)
+{
+ struct ws_widget *ws_widget = data;
+ weight_cb(ws_widget->description, data);
+}
+
+static void ws_widget(GtkWidget *vbox, struct ws_widget *ws_widget, GtkListStore *model)
+{
+ GtkWidget *frame, *hbox;
+ GtkEntryCompletion *completion;
+ GtkWidget *widget;
+ GtkEntry *entry;
+
+ /*
+ * weight_system: description and weight
+ */
+ frame = gtk_frame_new("Weight");
+
+ hbox = gtk_hbox_new(FALSE, 3);
+ gtk_container_add(GTK_CONTAINER(frame), hbox);
+
+ widget = gtk_combo_box_entry_new_with_model(GTK_TREE_MODEL(model), 0);
+ gtk_box_pack_start(GTK_BOX(hbox), widget, FALSE, TRUE, 0);
+
+ ws_widget->description = GTK_COMBO_BOX(widget);
+ g_signal_connect(widget, "changed", G_CALLBACK(weight_cb), ws_widget);
+
+ entry = GTK_ENTRY(GTK_BIN(widget)->child);
+ g_signal_connect(entry, "activate", G_CALLBACK(weight_activate_cb), ws_widget);
+
+ completion = gtk_entry_completion_new();
+ gtk_entry_completion_set_text_column(completion, 0);
+ gtk_entry_completion_set_model(completion, GTK_TREE_MODEL(model));
+ g_signal_connect(completion, "match-selected", G_CALLBACK(weight_completion_cb), ws_widget);
+ gtk_entry_set_completion(entry, completion);
+
+ hbox = gtk_hbox_new(FALSE, 3);
+ gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, TRUE, 0);
+ gtk_box_pack_start(GTK_BOX(hbox), frame, FALSE, TRUE, 0);
+
+ if ( output_units.weight == KG)
+ widget = create_spinbutton(hbox, "kg", 0, 50, 0.5);
+ else
+ widget = create_spinbutton(hbox, "lbs", 0, 110, 1);
+ ws_widget->weight = GTK_SPIN_BUTTON(widget);
+}
+
+static int edit_cylinder_dialog(int index, cylinder_t *cyl)
+{
+ int success;
+ GtkWidget *dialog, *vbox;
+ struct cylinder_widget cylinder;
+ struct dive *dive;
+
+ cylinder.index = index;
+ cylinder.changed = 0;
+
+ dive = current_dive;
+ if (!dive)
+ return 0;
+ *cyl = dive->cylinder[index];
+
+ dialog = gtk_dialog_new_with_buttons("Cylinder",
+ GTK_WINDOW(main_window),
+ GTK_DIALOG_DESTROY_WITH_PARENT,
+ GTK_STOCK_OK, GTK_RESPONSE_ACCEPT,
+ GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT,
+ NULL);
+
+ vbox = gtk_dialog_get_content_area(GTK_DIALOG(dialog));
+ cylinder_widget(vbox, &cylinder, cylinder_model);
+
+ show_cylinder(cyl, &cylinder);
+
+ gtk_widget_show_all(dialog);
+ success = gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT;
+ if (success) {
+ record_cylinder_changes(cyl, &cylinder);
+ dive->cylinder[index] = *cyl;
+ mark_divelist_changed(TRUE);
+ update_cylinder_related_info(dive);
+ flush_divelist(dive);
+ }
+
+ gtk_widget_destroy(dialog);
+
+ return success;
+}
+
+static int edit_weightsystem_dialog(int index, weightsystem_t *ws)
+{
+ int success;
+ GtkWidget *dialog, *vbox;
+ struct ws_widget weightsystem_widget;
+ struct dive *dive;
+
+ weightsystem_widget.index = index;
+ weightsystem_widget.changed = 0;
+
+ dive = current_dive;
+ if (!dive)
+ return 0;
+ *ws = dive->weightsystem[index];
+
+ dialog = gtk_dialog_new_with_buttons("Weight System",
+ GTK_WINDOW(main_window),
+ GTK_DIALOG_DESTROY_WITH_PARENT,
+ GTK_STOCK_OK, GTK_RESPONSE_ACCEPT,
+ GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT,
+ NULL);
+
+ vbox = gtk_dialog_get_content_area(GTK_DIALOG(dialog));
+ ws_widget(vbox, &weightsystem_widget, weightsystem_model);
+
+ show_weightsystem(ws, &weightsystem_widget);
+
+ gtk_widget_show_all(dialog);
+ success = gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT;
+ if (success) {
+ record_weightsystem_changes(ws, &weightsystem_widget);
+ dive->weightsystem[index] = *ws;
+ mark_divelist_changed(TRUE);
+ flush_divelist(dive);
+ }
+
+ gtk_widget_destroy(dialog);