]> git.tdb.fi Git - ext/subsurface.git/blobdiff - equipment.c
Fixed another memory leak
[ext/subsurface.git] / equipment.c
index abfb0e7b5979bba41b9af71b1d5391d610ed4359..165b9d77cdab94326341e214fb15c54cdf1b9866 100644 (file)
@@ -308,13 +308,15 @@ static GtkTreeIter *add_weightsystem_type(const char *desc, int weight, GtkTreeI
        model = GTK_TREE_MODEL(weightsystem_model);
        gtk_tree_model_foreach(model, match_desc, (void *)desc);
 
-       if (!found_match) {
-               GtkListStore *store = GTK_LIST_STORE(model);
-
-               gtk_list_store_append(store, iter);
-               gtk_list_store_set(store, iter,
-                       0, desc,
-                       1, weight,
+       if (found_match) {
+               gtk_list_store_set(GTK_LIST_STORE(model), found_match,
+                               WS_WEIGHT, weight,
+                               -1);
+       } else if (desc && desc[0]) {
+               gtk_list_store_append(GTK_LIST_STORE(model), iter);
+               gtk_list_store_set(GTK_LIST_STORE(model), iter,
+                       WS_DESC, desc,
+                       WS_WEIGHT, weight,
                        -1);
                return iter;
        }
@@ -623,6 +625,7 @@ static void record_weightsystem_changes(weightsystem_t *ws, struct ws_widget *we
        GtkComboBox *box;
        int grams;
        double value;
+       GtkTreeIter iter;
 
        /* Ignore uninitialized cylinder widgets */
        box = weightsystem_widget->description;
@@ -638,6 +641,7 @@ static void record_weightsystem_changes(weightsystem_t *ws, struct ws_widget *we
                grams = value * 1000;
        ws->weight.grams = grams;
        ws->description = desc;
+       add_weightsystem_type(desc, grams, &iter);
 }
 
 /*
@@ -664,10 +668,10 @@ static struct tank_info {
        { "AL100", .cuft = 100, .psi = 3300 },
 
        /* Somewhat common LP steel cylinders */
-       { "LP85",  .cuft =  85, 2640 },
-       { "LP95",  .cuft =  95, 2640 },
-       { "LP108", .cuft = 108, 2640 },
-       { "LP121", .cuft = 121, 2640 },
+       { "LP85",  .cuft =  85, .psi = 2640 },
+       { "LP95",  .cuft =  95, .psi = 2640 },
+       { "LP108", .cuft = 108, .psi = 2640 },
+       { "LP121", .cuft = 121, .psi = 2640 },
 
        /* Somewhat common HP steel cylinders */
        { "HP65",  .cuft =  65, .psi = 3442 },
@@ -696,23 +700,29 @@ static void fill_tank_list(GtkListStore *store)
        GtkTreeIter iter;
        struct tank_info *info = tank_info;
 
-       while (info->name) {
+       for (info = tank_info ; info->name; info++) {
                int ml = info->ml;
                int cuft = info->cuft;
                int psi = info->psi;
                int mbar;
                double bar = info->bar;
 
+               if (psi && bar)
+                       goto bad_tank_info;
+               if (ml && cuft)
+                       goto bad_tank_info;
+               if (cuft && !psi)
+                       goto bad_tank_info;
+
                /* Is it in cuft and psi? */
-               if (psi) {
+               if (psi)
                        bar = psi_to_bar(psi);
 
-                       if (cuft) {
-                               double airvolume = cuft_to_l(cuft) * 1000.0;
-                               double atm = bar_to_atm(bar);
+               if (cuft) {
+                       double airvolume = cuft_to_l(cuft) * 1000.0;
+                       double atm = bar_to_atm(bar);
 
-                               ml = airvolume / atm + 0.5;
-                       }
+                       ml = airvolume / atm + 0.5;
                }
 
                mbar = bar * 1000 + 0.5;
@@ -723,7 +733,10 @@ static void fill_tank_list(GtkListStore *store)
                        1, ml,
                        2, mbar,
                        -1);
-               info++;
+               continue;
+
+bad_tank_info:
+               fprintf(stderr, "Bad tank info for '%s'\n", info->name);
        }
 }
 
@@ -735,8 +748,6 @@ static struct ws_info {
        const char *name;
        int grams;
 } ws_info[100] = {
-       /* Need an empty entry for the no weight system case */
-       { "", },
        { "integrated", 0 },
        { "belt", 0 },
        { "ankle", 0 },
@@ -1334,6 +1345,14 @@ static void row_activated_cb(GtkTreeView *tree_view,
        edit_cb(NULL, tree_view);
 }
 
+static void ws_row_activated_cb(GtkTreeView *tree_view,
+                       GtkTreePath *path,
+                       GtkTreeViewColumn *column,
+                       GtkTreeModel *model)
+{
+       ws_edit_cb(NULL, tree_view);
+}
+
 GtkWidget *cylinder_list_widget(void)
 {
        GtkListStore *model = cylinder_list.model;
@@ -1371,7 +1390,7 @@ GtkWidget *weightsystem_list_widget(void)
 
        tree_view = gtk_tree_view_new_with_model(GTK_TREE_MODEL(model));
        gtk_widget_set_can_focus(tree_view, FALSE);
-       g_signal_connect(tree_view, "row-activated", G_CALLBACK(row_activated_cb), model);
+       g_signal_connect(tree_view, "row-activated", G_CALLBACK(ws_row_activated_cb), model);
 
        selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(tree_view));
        gtk_tree_selection_set_mode(GTK_TREE_SELECTION(selection), GTK_SELECTION_BROWSE);