mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
Use the divetrip index to look up divelist trip entries
We used to look up dive trips by their date, but these days we always create a dynamic index for a dive trip when we insert it into the divelist model, so we can use that to unambiguously match up dive trips with the dive model entries. That means that we don't get confused if we have two trips with the exact same time, which happens when you load all the test-dives, for example. Reported-by: Miika Turkia <miika.turkia@gmail.com> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
parent
8facc61e8f
commit
cb490b7abf
1 changed files with 22 additions and 34 deletions
56
divelist.c
56
divelist.c
|
@ -1029,27 +1029,20 @@ static void dump_trip_list(void)
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* this finds a trip that starts at precisely the time given */
|
static dive_trip_t *find_trip_by_idx(int idx)
|
||||||
static dive_trip_t *find_trip_by_time(timestamp_t when)
|
|
||||||
{
|
{
|
||||||
dive_trip_t *trip = dive_trip_list;
|
dive_trip_t *trip = dive_trip_list;
|
||||||
|
|
||||||
while (trip && trip->when < when)
|
if (!idx)
|
||||||
|
return NULL;
|
||||||
|
if (idx < 0)
|
||||||
|
idx = -idx;
|
||||||
|
|
||||||
|
while (trip) {
|
||||||
|
if (trip->index == idx)
|
||||||
|
return trip;
|
||||||
trip = trip->next;
|
trip = trip->next;
|
||||||
if (trip && trip->when == when) {
|
|
||||||
#ifdef DEBUG_TRIP
|
|
||||||
struct tm tm;
|
|
||||||
utc_mkdate(trip->when, &tm);
|
|
||||||
printf("found trip %p @ %04d-%02d-%02d %02d:%02d:%02d\n",
|
|
||||||
trip,
|
|
||||||
tm.tm_year+1900, tm.tm_mon+1, tm.tm_mday,
|
|
||||||
tm.tm_hour, tm.tm_min, tm.tm_sec);
|
|
||||||
#endif
|
|
||||||
return trip;
|
|
||||||
}
|
}
|
||||||
#ifdef DEBUG_TRIP
|
|
||||||
printf("no matching trip\n");
|
|
||||||
#endif
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1382,7 +1375,7 @@ static gint dive_nr_sort(GtkTreeModel *model,
|
||||||
|
|
||||||
if (idx_a < 0) {
|
if (idx_a < 0) {
|
||||||
a = NULL;
|
a = NULL;
|
||||||
tripa = find_trip_by_time(when_a);
|
tripa = find_trip_by_idx(idx_a);
|
||||||
} else {
|
} else {
|
||||||
a = get_dive(idx_a);
|
a = get_dive(idx_a);
|
||||||
if (a)
|
if (a)
|
||||||
|
@ -1391,7 +1384,7 @@ static gint dive_nr_sort(GtkTreeModel *model,
|
||||||
|
|
||||||
if (idx_b < 0) {
|
if (idx_b < 0) {
|
||||||
b = NULL;
|
b = NULL;
|
||||||
tripb = find_trip_by_time(when_b);
|
tripb = find_trip_by_idx(idx_b);
|
||||||
} else {
|
} else {
|
||||||
b = get_dive(idx_b);
|
b = get_dive(idx_b);
|
||||||
if (b)
|
if (b)
|
||||||
|
@ -1521,13 +1514,13 @@ void add_dive_cb(GtkWidget *menuitem, gpointer data)
|
||||||
|
|
||||||
static void edit_trip_cb(GtkWidget *menuitem, GtkTreePath *path)
|
static void edit_trip_cb(GtkWidget *menuitem, GtkTreePath *path)
|
||||||
{
|
{
|
||||||
|
int idx;
|
||||||
GtkTreeIter iter;
|
GtkTreeIter iter;
|
||||||
timestamp_t when;
|
|
||||||
dive_trip_t *dive_trip;
|
dive_trip_t *dive_trip;
|
||||||
|
|
||||||
gtk_tree_model_get_iter(MODEL(dive_list), &iter, path);
|
gtk_tree_model_get_iter(MODEL(dive_list), &iter, path);
|
||||||
gtk_tree_model_get(MODEL(dive_list), &iter, DIVE_DATE, &when, -1);
|
gtk_tree_model_get(MODEL(dive_list), &iter, DIVE_INDEX, &idx, -1);
|
||||||
dive_trip = find_trip_by_time(when);
|
dive_trip = find_trip_by_idx(idx);
|
||||||
if (edit_trip(dive_trip))
|
if (edit_trip(dive_trip))
|
||||||
gtk_tree_store_set(STORE(dive_list), &iter, DIVE_LOCATION, dive_trip->location, -1);
|
gtk_tree_store_set(STORE(dive_list), &iter, DIVE_LOCATION, dive_trip->location, -1);
|
||||||
}
|
}
|
||||||
|
@ -2176,16 +2169,14 @@ void remember_tree_state()
|
||||||
return;
|
return;
|
||||||
do {
|
do {
|
||||||
int idx;
|
int idx;
|
||||||
timestamp_t when;
|
|
||||||
GtkTreePath *path;
|
GtkTreePath *path;
|
||||||
|
|
||||||
gtk_tree_model_get(TREEMODEL(dive_list), &iter,
|
gtk_tree_model_get(TREEMODEL(dive_list), &iter, DIVE_INDEX, &idx, -1);
|
||||||
DIVE_INDEX, &idx, DIVE_DATE, &when, -1);
|
|
||||||
if (idx >= 0)
|
if (idx >= 0)
|
||||||
continue;
|
continue;
|
||||||
path = gtk_tree_model_get_path(TREEMODEL(dive_list), &iter);
|
path = gtk_tree_model_get_path(TREEMODEL(dive_list), &iter);
|
||||||
if (gtk_tree_view_row_expanded(GTK_TREE_VIEW(dive_list.tree_view), path)) {
|
if (gtk_tree_view_row_expanded(GTK_TREE_VIEW(dive_list.tree_view), path)) {
|
||||||
trip = find_trip_by_time(when);
|
trip = find_trip_by_idx(idx);
|
||||||
if (trip)
|
if (trip)
|
||||||
trip->expanded = TRUE;
|
trip->expanded = TRUE;
|
||||||
}
|
}
|
||||||
|
@ -2196,15 +2187,14 @@ void remember_tree_state()
|
||||||
static gboolean restore_node_state(GtkTreeModel *model, GtkTreePath *path, GtkTreeIter *iter, gpointer data)
|
static gboolean restore_node_state(GtkTreeModel *model, GtkTreePath *path, GtkTreeIter *iter, gpointer data)
|
||||||
{
|
{
|
||||||
int idx;
|
int idx;
|
||||||
timestamp_t when;
|
|
||||||
struct dive *dive;
|
struct dive *dive;
|
||||||
dive_trip_t *trip;
|
dive_trip_t *trip;
|
||||||
GtkTreeView *tree_view = GTK_TREE_VIEW(dive_list.tree_view);
|
GtkTreeView *tree_view = GTK_TREE_VIEW(dive_list.tree_view);
|
||||||
GtkTreeSelection *selection = gtk_tree_view_get_selection(tree_view);
|
GtkTreeSelection *selection = gtk_tree_view_get_selection(tree_view);
|
||||||
|
|
||||||
gtk_tree_model_get(model, iter, DIVE_INDEX, &idx, DIVE_DATE, &when, -1);
|
gtk_tree_model_get(model, iter, DIVE_INDEX, &idx, -1);
|
||||||
if (idx < 0) {
|
if (idx < 0) {
|
||||||
trip = find_trip_by_time(when);
|
trip = find_trip_by_idx(idx);
|
||||||
if (trip && trip->expanded)
|
if (trip && trip->expanded)
|
||||||
gtk_tree_view_expand_row(tree_view, path, FALSE);
|
gtk_tree_view_expand_row(tree_view, path, FALSE);
|
||||||
if (trip && trip->selected)
|
if (trip && trip->selected)
|
||||||
|
@ -2700,17 +2690,16 @@ static gboolean modify_selection_cb(GtkTreeSelection *selection, GtkTreeModel *m
|
||||||
GtkTreePath *path, gboolean was_selected, gpointer userdata)
|
GtkTreePath *path, gboolean was_selected, gpointer userdata)
|
||||||
{
|
{
|
||||||
int idx;
|
int idx;
|
||||||
timestamp_t when;
|
|
||||||
GtkTreeIter iter;
|
GtkTreeIter iter;
|
||||||
|
|
||||||
if (!was_selected)
|
if (!was_selected)
|
||||||
return TRUE;
|
return TRUE;
|
||||||
gtk_tree_model_get_iter(model, &iter, path);
|
gtk_tree_model_get_iter(model, &iter, path);
|
||||||
gtk_tree_model_get(model, &iter, DIVE_INDEX, &idx, DIVE_DATE, &when, -1);
|
gtk_tree_model_get(model, &iter, DIVE_INDEX, &idx, -1);
|
||||||
if (idx < 0) {
|
if (idx < 0) {
|
||||||
int i;
|
int i;
|
||||||
struct dive *dive;
|
struct dive *dive;
|
||||||
dive_trip_t *trip = find_trip_by_time(when);
|
dive_trip_t *trip = find_trip_by_idx(idx);
|
||||||
if (!trip)
|
if (!trip)
|
||||||
return TRUE;
|
return TRUE;
|
||||||
|
|
||||||
|
@ -2733,13 +2722,12 @@ static gboolean modify_selection_cb(GtkTreeSelection *selection, GtkTreeModel *m
|
||||||
static void entry_selected(GtkTreeModel *model, GtkTreePath *path, GtkTreeIter *iter, gpointer data)
|
static void entry_selected(GtkTreeModel *model, GtkTreePath *path, GtkTreeIter *iter, gpointer data)
|
||||||
{
|
{
|
||||||
int idx;
|
int idx;
|
||||||
timestamp_t when;
|
|
||||||
|
|
||||||
gtk_tree_model_get(model, iter, DIVE_INDEX, &idx, DIVE_DATE, &when, -1);
|
gtk_tree_model_get(model, iter, DIVE_INDEX, &idx, -1);
|
||||||
if (idx < 0) {
|
if (idx < 0) {
|
||||||
int i;
|
int i;
|
||||||
struct dive *dive;
|
struct dive *dive;
|
||||||
dive_trip_t *trip = find_trip_by_time(when);
|
dive_trip_t *trip = find_trip_by_idx(idx);
|
||||||
|
|
||||||
if (!trip)
|
if (!trip)
|
||||||
return;
|
return;
|
||||||
|
|
Loading…
Add table
Reference in a new issue