]> git.tdb.fi Git - ext/subsurface.git/commitdiff
First cut at working cylinder editing dialog
authorLinus Torvalds <torvalds@linux-foundation.org>
Sun, 2 Oct 2011 23:41:17 +0000 (16:41 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Sun, 2 Oct 2011 23:41:17 +0000 (16:41 -0700)
This currently only does the same old things we used to do (so still no
start/end pressure or trimix support), but despite that this is already
more flexible than the old model:

 - we can now add new cylinders, rather than just edit the information of
   the first two cylinders of the dive

 - because the cylinder editing is being done in a edit dialog, it is
   now much more reasonable to use multiple lines and expand all the
   things we can edit.

But to actually make this fully fledged, we'll need to add all the other
info to the cylinder edit dialog, and probably add a confirmation dialog
for the "delete cylinder" case too.

Oh, and right now deleting a cylinder doesn't mark the dive info changed.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
equipment.c

index 2bbd6511ecf647d9914dc67d69e07fc38d652a4a..7c70c6bf288129b80ff4247077cf258da13c7d1d 100644 (file)
@@ -50,8 +50,6 @@ struct cylinder_widget {
        GtkWidget *o2, *gasmix_button;
 };
 
-static struct cylinder_widget gtk_cylinder[MAX_CYLINDERS];
-
 static int convert_pressure(int mbar, double *p)
 {
        int decimals = 1;
@@ -219,6 +217,20 @@ static int cyl_nothing(cylinder_t *cyl)
                !cyl->end.mbar;
 }
 
+static void set_one_cylinder(int index, cylinder_t *cyl, GtkListStore *model, GtkTreeIter *iter)
+{
+       gtk_list_store_set(model, iter,
+               CYL_INDEX, index,
+               CYL_DESC, cyl->type.description ? : "",
+               CYL_SIZE, cyl->type.size.mliter,
+               CYL_WORKP, cyl->type.workingpressure.mbar,
+               CYL_STARTP, cyl->start.mbar,
+               CYL_ENDP, cyl->end.mbar,
+               CYL_O2, cyl->gasmix.o2.permille,
+               CYL_HE, cyl->gasmix.he.permille,
+               -1);
+}
+
 void show_dive_equipment(struct dive *dive)
 {
        int i, max;
@@ -245,16 +257,7 @@ void show_dive_equipment(struct dive *dive)
                cylinder_t *cyl = dive->cylinder+i;
 
                gtk_list_store_append(model, &iter);
-               gtk_list_store_set(model, &iter,
-                       CYL_INDEX, i,
-                       CYL_DESC, cyl->type.description ? : "",
-                       CYL_SIZE, cyl->type.size.mliter,
-                       CYL_WORKP, cyl->type.workingpressure.mbar,
-                       CYL_STARTP, cyl->start.mbar,
-                       CYL_ENDP, cyl->end.mbar,
-                       CYL_O2, cyl->gasmix.o2.permille,
-                       CYL_HE, cyl->gasmix.he.permille,
-                       -1);
+               set_one_cylinder(i, cyl, model, &iter);
        }
 }
 
@@ -330,30 +333,6 @@ 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);
-}
-
 /*
  * We hardcode the most common standard cylinders,
  * we should pick up any other names from the dive
@@ -473,8 +452,17 @@ static void cylinder_widget(GtkWidget *vbox, struct cylinder_widget *cylinder, G
 static void edit_cylinder_dialog(int index, GtkListStore *model, GtkTreeIter *iter)
 {
        int result;
-       struct cylinder_widget cyl;
-       GtkWidget *dialog, *frame, *vbox;
+       struct cylinder_widget cylinder;
+       GtkWidget *dialog, *vbox;
+       struct dive *dive;
+       cylinder_t *cyl;
+
+       dive = current_dive;
+       if (!dive)
+               return;
+       cyl = dive->cylinder + index;
+       cylinder.index = index;
+       cylinder.changed = 0;
 
        dialog = gtk_dialog_new_with_buttons("Cylinder",
                GTK_WINDOW(main_window),
@@ -484,12 +472,17 @@ static void edit_cylinder_dialog(int index, GtkListStore *model, GtkTreeIter *it
                NULL);
 
        vbox = gtk_dialog_get_content_area(GTK_DIALOG(dialog));
-       cylinder_widget(vbox, &cyl, cylinder_model);
+       cylinder_widget(vbox, &cylinder, cylinder_model);
+
+       show_cylinder(cyl, &cylinder);
 
        gtk_widget_show_all(dialog);
        result = gtk_dialog_run(GTK_DIALOG(dialog));
        if (result == GTK_RESPONSE_ACCEPT) {
-               /* Save it */
+               record_cylinder_changes(cyl, &cylinder);
+               set_one_cylinder(index, cyl, model, iter);
+               mark_divelist_changed(TRUE);
+               flush_divelist(dive);
        }
        gtk_widget_destroy(dialog);
 }