Allow images to be added via the web

This adds a new divelist context menu entry which asks for a URL. The file
is retrieved and if it is an image it is added to the cache and the url
is associated to dives as with local files.

NB this currently only works with URLs pointing directly to images. But it
should not be too hard to add the possibility to add a direction via an html
file and its image tags.

To test: open dives/test43.xml and delete the image and then add the URL
http://euve10195.vserver.de/~robert/wreck.jpg

Signed-off-by: Robert C. Helling <helling@atdotde.de>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Robert C. Helling 2015-04-24 17:10:55 +02:00 committed by Dirk Hohndel
parent 98ae7b1f86
commit 757c4aab20
9 changed files with 219 additions and 26 deletions

8
dive.c
View file

@ -2885,7 +2885,7 @@ static bool new_picture_for_dive(struct dive *d, char *filename)
// only add pictures that have timestamps between 30 minutes before the dive and
// 30 minutes after the dive ends
#define D30MIN (30 * 60)
bool dive_check_picture_time(struct dive *d, char *filename, int shift_time, timestamp_t timestamp)
bool dive_check_picture_time(struct dive *d, int shift_time, timestamp_t timestamp)
{
offset_t offset;
if (timestamp) {
@ -2905,7 +2905,7 @@ bool picture_check_valid(char *filename, int shift_time)
timestamp_t timestamp = picture_get_timestamp(filename);
for_each_dive (i, dive)
if (dive->selected && dive_check_picture_time(dive, filename, shift_time, timestamp))
if (dive->selected && dive_check_picture_time(dive, shift_time, timestamp))
return true;
return false;
}
@ -2915,11 +2915,11 @@ void dive_create_picture(struct dive *dive, char *filename, int shift_time)
timestamp_t timestamp = picture_get_timestamp(filename);
if (!new_picture_for_dive(dive, filename))
return;
if (!dive_check_picture_time(dive, filename, shift_time, timestamp))
if (!dive_check_picture_time(dive, shift_time, timestamp))
return;
struct picture *picture = alloc_picture();
picture->filename = filename;
picture->filename = strdup(filename);
picture->offset.seconds = timestamp - dive->when + shift_time;
picture_load_exif_data(picture);