summaryrefslogtreecommitdiffstats
path: root/core/divesite.c
diff options
context:
space:
mode:
authorGravatar Berthold Stoeger <bstoeger@mail.tuwien.ac.at>2020-03-17 21:26:57 +0100
committerGravatar Dirk Hohndel <dirk@hohndel.org>2020-03-17 14:05:24 -0700
commit4bd217299a9a7977d151431e15479fe16b7fbb30 (patch)
treeceace0a2af7719727d17df0a8707a805ff1f7078 /core/divesite.c
parentccd024f0ee4c1e8ba66605eacc40db101ee72dc4 (diff)
downloadsubsurface-4bd217299a9a7977d151431e15479fe16b7fbb30.tar.gz
mobile/edit: don't add dive site twice to table
When editing a dive on mobile we might have to create a new dive site. That site is added to the global dive site table in the undo command. However, the code in QMLManager created the dive site with create_dive_site*() functions, which already adds it to the table. The undo command then added the dive site again leading to a hang of the application. To solve this problem, create new alloc_dive_site*() functions that do the same as create_dive_site*() but do not add it to the table. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'core/divesite.c')
-rw-r--r--core/divesite.c23
1 files changed, 17 insertions, 6 deletions
diff --git a/core/divesite.c b/core/divesite.c
index 0ed4eb2ca..654ca45dd 100644
--- a/core/divesite.c
+++ b/core/divesite.c
@@ -171,6 +171,21 @@ struct dive_site *alloc_dive_site()
return ds;
}
+struct dive_site *alloc_dive_site_with_name(const char *name)
+{
+ struct dive_site *ds = alloc_dive_site();
+ ds->name = copy_string(name);
+ return ds;
+}
+
+struct dive_site *alloc_dive_site_with_gps(const char *name, const location_t *loc)
+{
+ struct dive_site *ds = alloc_dive_site_with_name(name);
+ ds->location = *loc;
+
+ return ds;
+}
+
/* when parsing, dive sites are identified by uuid */
struct dive_site *alloc_or_get_dive_site(uint32_t uuid, struct dive_site_table *ds_table)
{
@@ -231,8 +246,7 @@ void delete_dive_site(struct dive_site *ds, struct dive_site_table *ds_table)
/* allocate a new site and add it to the table */
struct dive_site *create_dive_site(const char *name, struct dive_site_table *ds_table)
{
- struct dive_site *ds = alloc_dive_site();
- ds->name = copy_string(name);
+ struct dive_site *ds = alloc_dive_site_with_name(name);
add_dive_site_to_table(ds, ds_table);
return ds;
}
@@ -240,11 +254,8 @@ struct dive_site *create_dive_site(const char *name, struct dive_site_table *ds_
/* same as before, but with GPS data */
struct dive_site *create_dive_site_with_gps(const char *name, const location_t *loc, struct dive_site_table *ds_table)
{
- struct dive_site *ds = alloc_dive_site();
- ds->name = copy_string(name);
- ds->location = *loc;
+ struct dive_site *ds = alloc_dive_site_with_gps(name, loc);
add_dive_site_to_table(ds, ds_table);
-
return ds;
}