]> git.tdb.fi Git - ext/subsurface.git/commitdiff
Update the divelist when dive info changes
authorLinus Torvalds <torvalds@linux-foundation.org>
Mon, 19 Sep 2011 23:41:56 +0000 (16:41 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Mon, 19 Sep 2011 23:41:56 +0000 (16:41 -0700)
This flushes the dive changes to the dive list, the way the old dive
info frame would update as you update dive fields.

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

index d215fd23651c6e2737e0b671cfe97d5de22cd5e6..9c1510664d496bb4237188770e6460a027737893 100644 (file)
@@ -232,23 +232,14 @@ static void get_sac(struct dive *dive, int *val, char **str)
        *str = strdup(buffer);
 }
 
-static gboolean set_one_dive(GtkTreeModel *model,
-                            GtkTreePath *path,
-                            GtkTreeIter *iter,
-                            gpointer data)
+static void fill_one_dive(struct dive *dive,
+                         GtkTreeModel *model,
+                         GtkTreeIter *iter)
 {
-       GValue value = {0, };
-       struct dive *dive;
        int date, depth, duration, temp, nitrox, sac;
        char *datestr, *depthstr, *durationstr, *tempstr, *nitroxstr, *sacstr;
        char *location;
 
-       /* Get the dive number */
-       gtk_tree_model_get_value(model, iter, DIVE_INDEX, &value);
-       dive = get_dive(g_value_get_int(&value));
-       if (!dive)
-               return TRUE;
-
        get_date(dive, &date, &datestr);
        get_depth(dive, &depth, &depthstr);
        get_duration(dive, &duration, &durationstr);
@@ -273,8 +264,33 @@ static gboolean set_one_dive(GtkTreeModel *model,
                DIVE_SACSTR, sacstr,
                DIVE_SAC, sac,
                -1);
+}
+
+static gboolean set_one_dive(GtkTreeModel *model,
+                            GtkTreePath *path,
+                            GtkTreeIter *iter,
+                            gpointer data)
+{
+       GValue value = {0, };
+       struct dive *dive;
+
+       /* Get the dive number */
+       gtk_tree_model_get_value(model, iter, DIVE_INDEX, &value);
+       dive = get_dive(g_value_get_int(&value));
+       if (!dive)
+               return TRUE;
+       if (data && dive != data)
+               return FALSE;
+
+       fill_one_dive(dive, model, iter);
+       return dive == data;
+}
+
+void flush_divelist(struct DiveList *dive_list, struct dive *dive)
+{
+       GtkTreeModel *model = GTK_TREE_MODEL(dive_list->model);
 
-       return FALSE;
+       gtk_tree_model_foreach(model, set_one_dive, dive);
 }
 
 void update_dive_list_units(struct DiveList *dive_list)
index e0ab1137cc105627b681a28df57f62a4eb71581d..46598b14ffbac0c1715b188ca7851dd5bb5877a6 100644 (file)
@@ -11,9 +11,12 @@ struct DiveList {
        GtkTreeViewColumn *temperature, *nitrox, *sac;
 };
 
+struct dive;
+
 extern struct DiveList dive_list;
 extern struct DiveList dive_list_create(void);
 extern void dive_list_update_dives(struct DiveList);
 extern void update_dive_list_units(struct DiveList *);
+extern void flush_divelist(struct DiveList *, struct dive *);
 
 #endif
diff --git a/main.c b/main.c
index 7c7ec8c3e350ecd97af4a76d17f2a4b248ba6c81..f91663276f799a55b0f4167c54f1e7f72f6308ac 100644 (file)
--- a/main.c
+++ b/main.c
@@ -98,6 +98,7 @@ void update_dive(struct dive *new_dive)
        if (old_dive) {
                flush_dive_info_changes(old_dive);
                flush_dive_equipment_changes(old_dive);
+               flush_divelist(&dive_list, old_dive);
        }
        if (new_dive) {
                show_dive_info(new_dive);