From: Linus Torvalds Date: Thu, 16 Aug 2012 17:46:30 +0000 (-0700) Subject: Merge branch 'tree2' of git://git.hohndel.org/subsurface X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=9b72217f79f29313d30c87c55f533cc606da6a8f;p=ext%2Fsubsurface.git Merge branch 'tree2' of git://git.hohndel.org/subsurface Pull dive-trip grouping from Dirk Hohndel: "This turned into an updated pull request for the tree2 branch where I implemented the date based grouping - but is actually a very different topic: this adds the ability to edit multiple dives (and fixes some issues with the dive editing overall). The reason for that is that it reuses some of the infrastructure that I implemented in the tree2 branch for tracking the selected dives. More details in the commit messages." * 'tree2' of git://git.hohndel.org/subsurface: Switch from date based to dive trip based grouping Redo dive editing Fix selecting and unselecting summary items Apply sort functions to the correct model, don't select summary entries Maintain selected rows when switching between list model and tree model Create duplicate list model so sorting by columns works again Improve tree model implementation Allow date based grouping --- 9b72217f79f29313d30c87c55f533cc606da6a8f diff --cc divelist.c index 36c5883,5b4ef0a..a85ac7c --- a/divelist.c +++ b/divelist.c @@@ -24,9 -24,9 +24,9 @@@ 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; }; @@@ -535,39 -638,42 +672,55 @@@ static void get_cylinder(struct dive *d 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, @@@ -653,10 -806,21 +858,23 @@@ static void fill_dive_list(void 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); } @@@ -789,7 -1079,21 +1135,23 @@@ GtkWidget *dive_list_create(void { 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 */ diff --cc info.c index a28e793,842a150..1c7b6a9 --- a/info.c +++ b/info.c @@@ -392,12 -380,15 +394,16 @@@ static void dive_info_widget(GtkWidget 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);