]> git.tdb.fi Git - ext/subsurface.git/commitdiff
Make sure SAC and OTU get recalculated after cylinder info was changed
authorDirk Hohndel <dirk@hohndel.org>
Sun, 13 Nov 2011 17:29:07 +0000 (15:29 -0200)
committerDirk Hohndel <dirk@hohndel.org>
Sun, 13 Nov 2011 17:29:07 +0000 (15:29 -0200)
Also fixed minor coding style issues (prevent useless code from being
executed).

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
divelist.c
divelist.h
equipment.c

index eb8f231432a99f33f40a8ca0341aee8a66b14148..bf853ec0e49fce534853c3b59e98abb0d9a314a1 100644 (file)
@@ -335,6 +335,14 @@ static int calculate_sac(struct dive *dive)
        return sac * 1000;
 }
 
+void update_cylinder_related_info(struct dive *dive)
+{
+       if(dive != NULL) {
+               dive->sac = calculate_sac(dive);
+               dive->otu = calculate_otu(dive);
+       }
+}
+
 static void get_string(char **str, const char *s)
 {
        int len;
@@ -452,8 +460,7 @@ static void fill_dive_list(void)
        for (i = 0; i < dive_table.nr; i++) {
                struct dive *dive = dive_table.dives[i];
 
-               dive->otu = calculate_otu(dive);
-               dive->sac = calculate_sac(dive);
+               update_cylinder_related_info(dive);
                gtk_list_store_append(store, &iter);
                gtk_list_store_set(store, &iter,
                        DIVE_INDEX, i,
index 2635b75419829012e291ef597f6f7efd962dc10f..c170941dbb236e75f3d8bd2ae426e292d037704e 100644 (file)
@@ -7,7 +7,7 @@ extern void dive_list_update_dives(void);
 extern void update_dive_list_col_visibility(void);
 extern void update_dive_list_units(void);
 extern void flush_divelist(struct dive *);
-
+extern void update_cylinder_related_info(struct dive *);
 extern void mark_divelist_changed(int);
 extern int unsaved_changes(void);
 #endif
index 19abbe67294c7c6fea26f9b708c7bf3a95a761fe..dbe1f0f137be5f769608c5e4d21dfe58dd917c59 100644 (file)
@@ -416,12 +416,14 @@ static void record_cylinder_changes(cylinder_t *cyl, struct cylinder_widget *cyl
        desc = gtk_combo_box_get_active_text(box);
        volume = gtk_spin_button_get_value(cylinder->size);
        pressure = gtk_spin_button_get_value(cylinder->pressure);
-       start = gtk_spin_button_get_value(GTK_SPIN_BUTTON(cylinder->start));
-       end = gtk_spin_button_get_value(GTK_SPIN_BUTTON(cylinder->end));
-       if (!gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(cylinder->pressure_button)))
+       if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(cylinder->pressure_button))) {
+               start = gtk_spin_button_get_value(GTK_SPIN_BUTTON(cylinder->start));
+               end = gtk_spin_button_get_value(GTK_SPIN_BUTTON(cylinder->end));
+       } else
                start = end = 0;
-       o2 = gtk_spin_button_get_value(GTK_SPIN_BUTTON(cylinder->o2))*10 + 0.5;
-       if (!gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(cylinder->gasmix_button)))
+       if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(cylinder->gasmix_button)))
+               o2 = gtk_spin_button_get_value(GTK_SPIN_BUTTON(cylinder->o2))*10 + 0.5;
+       else
                o2 = 0;
        fill_cylinder_info(cylinder, cyl, desc, volume, pressure, start, end, o2);
 }
@@ -643,6 +645,7 @@ static int edit_cylinder_dialog(int index, cylinder_t *cyl)
                record_cylinder_changes(cyl, &cylinder);
                dive->cylinder[index] = *cyl;
                mark_divelist_changed(TRUE);
+               update_cylinder_related_info(dive);
                flush_divelist(dive);
        }