summaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
Diffstat (limited to 'core')
-rw-r--r--core/divelist.c40
-rw-r--r--core/divelist.h3
-rw-r--r--core/import-csv.c2
3 files changed, 28 insertions, 17 deletions
diff --git a/core/divelist.c b/core/divelist.c
index 1906d002a..62af3120c 100644
--- a/core/divelist.c
+++ b/core/divelist.c
@@ -3,6 +3,8 @@
/* core logic for the dive list -
* accessed through the following interfaces:
*
+ * void process_loaded_dives();
+ * void process_imported_dives(bool prefer_imported);
* dive_trip_t *dive_trip_list;
* unsigned int amount_selected;
* void dump_selection(void)
@@ -1259,17 +1261,32 @@ static void try_to_renumber(struct dive *last, int preexisting)
}
}
-void process_dives(bool is_imported, bool prefer_imported)
+void process_loaded_dives()
+{
+ int i;
+ struct dive *dive;
+
+ /* Register dive computer nick names */
+ for_each_dive(i, dive)
+ set_dc_nickname(dive);
+
+ sort_table(&dive_table);
+}
+
+void process_imported_dives(bool prefer_imported)
{
int i;
int preexisting = dive_table.preexisting;
- bool did_merge = false;
struct dive *last;
+ /* If no dives were imported, don't bother doing anything */
+ if (preexisting >= dive_table.nr)
+ return;
+
/* check if we need a nickname for the divecomputer for newly downloaded dives;
* since we know they all came from the same divecomputer we just check for the
* first one */
- if (preexisting < dive_table.nr && dive_table.dives[preexisting]->downloaded)
+ if (dive_table.dives[preexisting]->downloaded)
set_dc_nickname(dive_table.dives[preexisting]);
else
/* they aren't downloaded, so record / check all new ones */
@@ -1315,24 +1332,17 @@ void process_dives(bool is_imported, bool prefer_imported)
delete_single_dive(i + 1);
// keep the id or the first dive for the merged dive
merged->id = id;
-
- /* this means the table was changed */
- did_merge = true;
}
+
/* make sure no dives are still marked as downloaded */
for (i = 1; i < dive_table.nr; i++)
dive_table.dives[i]->downloaded = false;
- if (is_imported) {
- /* If there are dives in the table, are they numbered */
- if (!last || last->number)
- try_to_renumber(last, preexisting);
+ /* If there are dives in the table, are they numbered */
+ if (!last || last->number)
+ try_to_renumber(last, preexisting);
- /* did we add dives or divecomputers to the dive table? */
- if (did_merge || preexisting < dive_table.nr) {
- mark_divelist_changed(true);
- }
- }
+ mark_divelist_changed(true);
}
void set_dive_nr_for_current_dive()
diff --git a/core/divelist.h b/core/divelist.h
index 5467f10ae..937909d2b 100644
--- a/core/divelist.h
+++ b/core/divelist.h
@@ -18,7 +18,8 @@ extern void remove_autogen_trips(void);
extern int init_decompression(struct deco_state *ds, struct dive *dive);
/* divelist core logic functions */
-extern void process_dives(bool imported, bool prefer_imported);
+extern void process_loaded_dives();
+extern void process_imported_dives(bool prefer_imported);
extern char *get_dive_gas_string(struct dive *dive);
struct dive **grow_dive_table(struct dive_table *table);
diff --git a/core/import-csv.c b/core/import-csv.c
index 898dfdbd0..8d6c229fd 100644
--- a/core/import-csv.c
+++ b/core/import-csv.c
@@ -135,7 +135,7 @@ static int parse_dan_format(const char *filename, char **params, int pnr)
*/
if (end_ptr)
- process_dives(true, false);
+ process_imported_dives(false);
mem_csv.buffer = malloc(mem.size + 1);
mem_csv.size = mem.size;