+/* equipment.c */
+/* creates the UI for the equipment page -
+ * controlled through the following interfaces:
+ *
+ * void show_dive_equipment(struct dive *dive)
+ * void flush_dive_equipment_changes(struct dive *dive)
+ *
+ * called from gtk-ui:
+ * GtkWidget *equipment_widget(void)
+ */
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "dive.h"
#include "display.h"
+#include "display-gtk.h"
#include "divelist.h"
struct cylinder_widget {
int index, changed;
const char *name;
+ GtkWidget *hbox;
GtkComboBox *description;
GtkSpinButton *size, *pressure;
GtkWidget *o2, *gasmix_button;
}
void flush_dive_equipment_changes(struct dive *dive)
+{
+ /* We do nothing: we require the "Ok" button press */
+}
+
+static void apply_cb(GtkButton *button, gpointer data)
{
int i;
+ struct dive *dive = current_dive;
+
+ if (!dive)
+ return;
for (i = 0; i < MAX_CYLINDERS; i++)
record_cylinder_changes(dive->cylinder+i, gtk_cylinder+i);
+ mark_divelist_changed(TRUE);
+ flush_divelist(dive);
+}
+
+static void cancel_cb(GtkButton *button, gpointer data)
+{
+ struct dive *dive = current_dive;
+
+ if (!dive)
+ return;
+
+ show_dive_equipment(current_dive);
}
/*
gtk_widget_set_sensitive(cylinder->o2, state);
}
-static void cylinder_widget(GtkWidget *box, int nr, GtkListStore *model)
+static void cylinder_widget(int nr, GtkListStore *model)
{
struct cylinder_widget *cylinder;
GtkWidget *frame, *hbox, *hbox2;
cylinder->index = nr;
hbox = gtk_hbox_new(FALSE, 3);
- gtk_box_pack_start(GTK_BOX(box), hbox, FALSE, FALSE, 0);
+ cylinder->hbox = hbox;
snprintf(buffer, sizeof(buffer), "Cylinder %d", nr+1);
frame = gtk_frame_new(buffer);
GtkWidget *equipment_widget(void)
{
- GtkWidget *vbox;
+ int i;
+ GtkWidget *vbox, *hbox;
+ GtkWidget *apply, *cancel;
GtkListStore *model;
vbox = gtk_vbox_new(FALSE, 3);
model = create_tank_size_model();
- cylinder_widget(vbox, 0, model);
- cylinder_widget(vbox, 1, model);
+
+ /* Create all MAX_CYLINDER gtk widgets */
+ for (i = 0; i < MAX_CYLINDERS; i++)
+ cylinder_widget(i, model);
+
+ /* But only connect two of them right now to the frame vbox */
+ for (i = 0; i < 2; i++) {
+ struct cylinder_widget *cylinder = gtk_cylinder+i;
+ gtk_box_pack_start(GTK_BOX(vbox), cylinder->hbox, FALSE, TRUE, 0);
+ }
+
+ hbox = gtk_hbox_new(TRUE, 3);
+ gtk_box_pack_end(GTK_BOX(vbox), hbox, TRUE, FALSE, 0);
+
+ apply = gtk_button_new_from_stock(GTK_STOCK_APPLY);
+ cancel = gtk_button_new_from_stock(GTK_STOCK_CANCEL);
+ gtk_box_pack_start(GTK_BOX(hbox), apply, FALSE, FALSE, 0);
+ gtk_box_pack_start(GTK_BOX(hbox), cancel, FALSE, FALSE, 0);
+
+ g_signal_connect(apply, "clicked", G_CALLBACK(apply_cb), NULL);
+ g_signal_connect(cancel, "clicked", G_CALLBACK(cancel_cb), NULL);
return vbox;
}