aboutsummaryrefslogtreecommitdiffstats
path: root/core/dive.c
diff options
context:
space:
mode:
authorGravatar Berthold Stoeger <bstoeger@mail.tuwien.ac.at>2020-04-19 17:01:58 +0200
committerGravatar Dirk Hohndel <dirk@hohndel.org>2020-05-06 13:58:09 -0700
commit6ae2d36e381b4f676eb9d8c0e06245989ef16383 (patch)
tree169e0b4119fc9c549a32528952215cd78a64221d /core/dive.c
parent74f03e3537ee530000d4b11013bb12de91cb21dd (diff)
downloadsubsurface-6ae2d36e381b4f676eb9d8c0e06245989ef16383.tar.gz
core: move picture-related function from dive.c to picture.c
Move the two functions create_picture() and picture_check_valid_time() from dive.c to picture.c. This might be somewhat questionable, as these functions are not purely picture related, but check the nearest selected dives, etc. However, dive.c is so huge, that slimming it down can't hurt. Moreover, getting the nearest selected dive is more divelist- than dive functionality anyway. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'core/dive.c')
-rw-r--r--core/dive.c86
1 files changed, 0 insertions, 86 deletions
diff --git a/core/dive.c b/core/dive.c
index 5ac008e8f..d5ffc162b 100644
--- a/core/dive.c
+++ b/core/dive.c
@@ -14,7 +14,6 @@
#include "divesite.h"
#include "errorhelper.h"
#include "qthelper.h"
-#include "metadata.h"
#include "membuffer.h"
#include "picture.h"
#include "tag.h"
@@ -3498,64 +3497,6 @@ void set_git_prefs(const char *prefs)
git_prefs.pp_graphs.po2 = 1;
}
-/* Return distance of timestamp to time of dive. Result is always positive, 0 means during dive. */
-static timestamp_t time_from_dive(const struct dive *d, timestamp_t timestamp)
-{
- timestamp_t end_time = dive_endtime(d);
- if (timestamp < d->when)
- return d->when - timestamp;
- else if (timestamp > end_time)
- return timestamp - end_time;
- else
- return 0;
-}
-
-// only add pictures that have timestamps between 30 minutes before the dive and
-// 30 minutes after the dive ends
-#define D30MIN (30 * 60)
-static bool dive_check_picture_time(const struct dive *d, timestamp_t timestamp)
-{
- return time_from_dive(d, timestamp) < D30MIN;
-}
-
-/* Return dive closest selected dive to given timestamp or NULL if no dives are selected. */
-static struct dive *nearest_selected_dive(timestamp_t timestamp)
-{
- struct dive *d, *res = NULL;
- int i;
- timestamp_t offset, min = 0;
-
- for_each_dive(i, d) {
- if (!d->selected)
- continue;
- offset = time_from_dive(d, timestamp);
- if (!res || offset < min) {
- res = d;
- min = offset;
- }
-
- /* We suppose that dives are sorted chronologically. Thus
- * if the offset starts to increase, we can end. This ignores
- * pathological cases such as overlapping dives. In such a
- * case the user will have to add pictures manually.
- */
- if (offset == 0 || offset > min)
- break;
- }
- return res;
-}
-
-bool picture_check_valid_time(timestamp_t timestamp, int shift_time)
-{
- int i;
- struct dive *dive;
-
- for_each_dive (i, dive)
- if (dive->selected && dive_check_picture_time(dive, timestamp + shift_time))
- return true;
- return false;
-}
-
void dive_set_geodata_from_picture(struct dive *dive, struct picture *picture, struct dive_site_table *table)
{
struct dive_site *ds = dive->dive_site;
@@ -3570,33 +3511,6 @@ void dive_set_geodata_from_picture(struct dive *dive, struct picture *picture, s
}
}
-/* Creates a picture and indicates the dive to which this picture should be added.
- * The caller is responsible for actually adding the picture to the dive.
- * If no appropriate dive was found, no picture is created and NULL is returned.
- */
-struct picture *create_picture(const char *filename, int shift_time, bool match_all, struct dive **dive)
-{
- struct metadata metadata;
- timestamp_t timestamp;
-
- get_metadata(filename, &metadata);
- timestamp = metadata.timestamp + shift_time;
- *dive = nearest_selected_dive(timestamp);
-
- if (!*dive)
- return NULL;
- if (get_picture_idx(&(*dive)->pictures, filename) >= 0)
- return NULL;
- if (!match_all && !dive_check_picture_time(*dive, timestamp))
- return NULL;
-
- struct picture *picture = malloc(sizeof(struct picture));
- picture->filename = strdup(filename);
- picture->offset.seconds = metadata.timestamp - (*dive)->when + shift_time;
- picture->location = metadata.location;
- return picture;
-}
-
/* clones a dive and moves given dive computer to front */
struct dive *make_first_dc(const struct dive *d, int dc_number)
{