summaryrefslogtreecommitdiffstats
path: root/main.c
diff options
context:
space:
mode:
authorGravatar Dirk Hohndel <dirk@hohndel.org>2012-12-05 09:34:00 -0800
committerGravatar Dirk Hohndel <dirk@hohndel.org>2012-12-05 09:34:00 -0800
commit0141b69d0a64ae05dcf5380f2fb7d2dd0eb39efe (patch)
tree9ecb0d579383e00e7031d0c6f3a92c02ab422aaa /main.c
parent10e64f0e176cc31540b2c9a0ec9154dfdf1eb8a6 (diff)
downloadsubsurface-0141b69d0a64ae05dcf5380f2fb7d2dd0eb39efe.tar.gz
When starting with an empty data file and downloading dives, number them
We have been very careful not to mess with the numbering that a user may intend - but one obvious case where we should automatically number the dives appears to be the first time download from a dive computer. Right now all dives show up with number '0' and that's just really ugly and a bad experience for a first time user. With this change if a user starts with an empty data file and downloads dives from a computer for the first time, Subsurface will give them numbers starting with '1'. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'main.c')
-rw-r--r--main.c15
1 files changed, 11 insertions, 4 deletions
diff --git a/main.c b/main.c
index 1c4d33736..b8d5079cc 100644
--- a/main.c
+++ b/main.c
@@ -55,6 +55,10 @@ const char *monthname(int mon)
*
* But we only do it if:
*
+ * - there are no dives in the dive table
+ *
+ * OR
+ *
* - the last dive in the old dive table was numbered
*
* - all the new dives are strictly at the end (so the
@@ -79,7 +83,7 @@ static void try_to_renumber(struct dive *last, int preexisting)
* we're going to expect the user to do a manual
* renumbering.
*/
- if (get_dive(preexisting-1) != last)
+ if (preexisting && get_dive(preexisting-1) != last)
return;
/*
@@ -95,7 +99,10 @@ static void try_to_renumber(struct dive *last, int preexisting)
/*
* Ok, renumber..
*/
- nr = last->number;
+ if (last)
+ nr = last->number;
+ else
+ nr = 0;
for (i = preexisting; i < dive_table.nr; i++) {
struct dive *dive = get_dive(i);
dive->number = ++nr;
@@ -150,8 +157,8 @@ void report_dives(gboolean is_imported, gboolean prefer_imported)
dive_table.dives[i]->downloaded = FALSE;
if (is_imported) {
- /* Was the previous dive table state numbered? */
- if (last && last->number)
+ /* If there are dives in the table, are they numbered */
+ if (!last || last->number)
try_to_renumber(last, preexisting);
/* did we add dives to the dive table? */