+ gtk_tree_model_foreach(GTK_TREE_MODEL(store), dump_model_entry, NULL);
+}
+#endif
+
+static GList *selected_dives;
+
+static void selection_cb(GtkTreeSelection *selection, GtkTreeModel *model)
+{
+ GtkTreeIter iter;
+ GtkTreePath *path;
+
+ int nr_selected = gtk_tree_selection_count_selected_rows(selection);
+
+ if (selected_dives) {
+ g_list_foreach (selected_dives, (GFunc) gtk_tree_path_free, NULL);
+ g_list_free (selected_dives);
+ }
+ selected_dives = gtk_tree_selection_get_selected_rows(selection, NULL);
+
+ switch (nr_selected) {
+ case 0: /* keep showing the last selected dive */
+ return;
+ case 1:
+ /* just pick that dive as selected */
+ amount_selected = 1;
+ path = g_list_nth_data(selected_dives, 0);
+ if (gtk_tree_model_get_iter(model, &iter, path)) {
+ gtk_tree_model_get(model, &iter, DIVE_INDEX, &selected_dive, -1);
+ /* a negative index means we picked a summary entry;
+ expand that entry and use first real child instead */
+ while (selected_dive < 0) {
+ GtkTreeIter parent;
+ GtkTreePath *tpath;
+ memcpy(&parent, &iter, sizeof(parent));
+ tpath = gtk_tree_model_get_path(model, &parent);
+ if (!gtk_tree_model_iter_children(model, &iter, &parent))
+ /* we should never have a parent without child */
+ return;
+ if(gtk_tree_view_row_expanded(GTK_TREE_VIEW(dive_list.tree_view), tpath))
+ gtk_tree_view_collapse_row(GTK_TREE_VIEW(dive_list.tree_view), tpath);
+ else
+ gtk_tree_view_expand_row(GTK_TREE_VIEW(dive_list.tree_view), tpath, FALSE);
+ gtk_tree_model_get(model, &iter, DIVE_INDEX, &selected_dive, -1);
+ }
+ repaint_dive();
+ }
+ return;
+ default: /* multiple selections - what now? At this point I
+ * don't want to change the selected dive unless
+ * there is exactly one dive selected; not sure this
+ * is the most intuitive solution.
+ * I do however want to keep around which dives have
+ * been selected */
+ amount_selected = g_list_length(selected_dives);
+ process_selected_dives(selected_dives, model);
+ repaint_dive();
+ return;
+ }