struct DiveList {
GtkWidget *tree_view;
GtkWidget *container_widget;
- GtkListStore *model;
+ GtkTreeStore *model, *listmodel, *treemodel;
GtkTreeViewColumn *nr, *date, *stars, *depth, *duration, *location;
- GtkTreeViewColumn *temperature, *cylinder, *nitrox, *sac, *otu;
+ GtkTreeViewColumn *temperature, *cylinder, *totalweight, *suit, *nitrox, *sac, *otu;
int changed;
};
get_string(str, dive->cylinder[0].type.description);
}
+static void get_suit(struct dive *dive, char **str)
+{
+ get_string(str, dive->suit);
+}
+
/*
* Set up anything that could have changed due to editing
- * of dive information
+ * of dive information; we need to do this for both models,
+ * so we simply call set_one_dive again with the non-current model
*/
+ /* forward declaration for recursion */
+ 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)
{
- char *location, *cylinder;
+ char *location, *cylinder, *suit;
+ GtkTreeStore *othermodel;
get_cylinder(dive, &cylinder);
get_location(dive, &location);
+ get_suit(dive, &suit);
- gtk_list_store_set(GTK_LIST_STORE(model), iter,
+ gtk_tree_store_set(GTK_TREE_STORE(model), iter,
DIVE_NR, dive->number,
DIVE_LOCATION, location,
DIVE_CYLINDER, cylinder,
DIVE_RATING, dive->rating,
DIVE_SAC, dive->sac,
DIVE_OTU, dive->otu,
+ DIVE_TOTALWEIGHT, total_weight(dive),
+ DIVE_SUIT, suit,
-1);
+
+ free(location);
+ free(cylinder);
+ free(suit);
++
+ if (model == GTK_TREE_MODEL(dive_list.treemodel))
+ othermodel = dive_list.listmodel;
+ else
+ othermodel = dive_list.treemodel;
+ if (othermodel != dive_list.model)
+ /* recursive call */
+ gtk_tree_model_foreach(GTK_TREE_MODEL(othermodel), set_one_dive, dive);
}
static gboolean set_one_dive(GtkTreeModel *model,
DIVE_DATE, dive->when,
DIVE_DEPTH, dive->maxdepth,
DIVE_DURATION, dive->duration.seconds,
- DIVE_LOCATION, "location",
+ DIVE_LOCATION, dive->location,
+ DIVE_RATING, dive->rating,
+ DIVE_TEMPERATURE, dive->watertemp.mkelvin,
+ DIVE_SAC, 0,
+ -1);
+ gtk_tree_store_append(liststore, &iter, NULL);
+ gtk_tree_store_set(liststore, &iter,
+ DIVE_INDEX, i,
+ DIVE_NR, dive->number,
+ DIVE_DATE, dive->when,
+ DIVE_DEPTH, dive->maxdepth,
+ DIVE_DURATION, dive->duration.seconds,
+ DIVE_LOCATION, dive->location,
+ DIVE_RATING, dive->rating,
DIVE_TEMPERATURE, dive->watertemp.mkelvin,
+ DIVE_TOTALWEIGHT, 0,
+ DIVE_SUIT, dive->suit,
DIVE_SAC, 0,
-1);
}
{
GtkTreeSelection *selection;
- dive_list.model = gtk_list_store_new(DIVELIST_COLUMNS,
+ dive_list.listmodel = gtk_tree_store_new(DIVELIST_COLUMNS,
+ G_TYPE_INT, /* index */
+ G_TYPE_INT, /* nr */
+ G_TYPE_INT, /* Date */
+ G_TYPE_INT, /* Star rating */
+ G_TYPE_INT, /* Depth */
+ G_TYPE_INT, /* Duration */
+ G_TYPE_INT, /* Temperature */
++ G_TYPE_INT, /* Total weight */
++ G_TYPE_STRING, /* Suit */
+ G_TYPE_STRING, /* Cylinder */
+ G_TYPE_INT, /* Nitrox */
+ G_TYPE_INT, /* SAC */
+ G_TYPE_INT, /* OTU */
+ G_TYPE_STRING /* Location */
+ );
+ dive_list.treemodel = gtk_tree_store_new(DIVELIST_COLUMNS,
G_TYPE_INT, /* index */
G_TYPE_INT, /* nr */
G_TYPE_INT, /* Date */
gtk_box_pack_start(GTK_BOX(box), hbox, FALSE, TRUE, 0);
info->rating = text_entry(hbox, "Rating", star_list, star_strings[dive->rating]);
+ info->suit = text_entry(hbox, "Suit", suit_list, dive->suit);
- info->notes = text_view(box, "Notes", READ_WRITE);
- if (dive->notes && *dive->notes)
- gtk_text_buffer_set_text(gtk_text_view_get_buffer(info->notes), dive->notes, -1);
-
+ /* only show notes if editing a single dive */
+ if (multi) {
+ info->notes = NULL;
+ } else {
+ info->notes = text_view(box, "Notes", READ_WRITE);
+ if (dive->notes && *dive->notes)
+ gtk_text_buffer_set_text(gtk_text_view_get_buffer(info->notes), dive->notes, -1);
+ }
hbox = gtk_hbox_new(FALSE, 3);
gtk_box_pack_start(GTK_BOX(box), hbox, FALSE, TRUE, 0);