aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Dirk Hohndel <dirk@hohndel.org>2014-06-09 09:38:50 -0700
committerGravatar Dirk Hohndel <dirk@hohndel.org>2014-06-09 09:38:50 -0700
commita26719c5419754b24a16b7c8163d236eae765a6d (patch)
tree6c735fa8d100686cd06c679584c3632b41347b00
parentb0983d9d13d2d967d52a0fbbc1052f7f6eca840a (diff)
downloadsubsurface-a26719c5419754b24a16b7c8163d236eae765a6d.tar.gz
Picture handling: switch to stronger typed offset
Also change the on file XML to be even easier to read by making it a duration as well (which gets us '32:34 min' instead of un-typed seconds). This is backwards compatible, it will happily read what was written with the previous commit). Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
-rw-r--r--dive.c4
-rw-r--r--dive.h2
-rw-r--r--parse-xml.c4
-rw-r--r--qt-ui/profile/profilewidget2.cpp4
-rw-r--r--save-xml.c4
5 files changed, 9 insertions, 9 deletions
diff --git a/dive.c b/dive.c
index 1c594db2e..68b811217 100644
--- a/dive.c
+++ b/dive.c
@@ -2290,7 +2290,7 @@ void dive_create_picture(struct dive *d, char *filename, int shift_time)
p->filename = filename;
picture_load_exif_data(p, &timestamp);
if (timestamp)
- p->offset = timestamp - d->when + shift_time;
+ p->offset.seconds = timestamp - d->when + shift_time;
dive_add_picture(d, p);
dive_set_geodata_from_picture(d, p);
}
@@ -2299,7 +2299,7 @@ void dive_add_picture(struct dive *d, struct picture *newpic)
{
struct picture **pic_ptr = &d->picture_list;
/* let's keep the list sorted by time */
- while( *pic_ptr && (*pic_ptr)->offset < newpic->offset )
+ while( *pic_ptr && (*pic_ptr)->offset.seconds < newpic->offset.seconds )
pic_ptr = &(*pic_ptr)->next;
newpic->next = *pic_ptr;
*pic_ptr = newpic;
diff --git a/dive.h b/dive.h
index 23278d4a3..be99bffb2 100644
--- a/dive.h
+++ b/dive.h
@@ -289,7 +289,7 @@ struct dive {
/* picture list and methods related to dive picture handling */
struct picture {
char *filename;
- int32_t offset;
+ duration_t offset;
degrees_t latitude;
degrees_t longitude;
struct picture *next;
diff --git a/parse-xml.c b/parse-xml.c
index 1fad25bbb..739115dcc 100644
--- a/parse-xml.c
+++ b/parse-xml.c
@@ -1084,7 +1084,7 @@ static void try_to_fill_dive(struct dive *dive, const char *name, char *buf)
if (MATCH("filename.picture", utf8_string, &cur_picture->filename))
return;
- if (MATCH("offset.picture", get_index, &cur_picture->offset))
+ if (MATCH("offset.picture", sampletime, &cur_picture->offset))
return;
if (MATCH("gps.picture", gps_picture_location, cur_picture))
return;
@@ -1295,7 +1295,7 @@ static void event_end(void)
if (cur_event.type == 123) {
struct picture *pic = alloc_picture();
pic->filename = strdup(cur_event.name);
- pic->offset = cur_event.time.seconds;
+ pic->offset = cur_event.time;
dive_add_picture(cur_dive, pic);
} else {
add_event(dc, cur_event.time.seconds,
diff --git a/qt-ui/profile/profilewidget2.cpp b/qt-ui/profile/profilewidget2.cpp
index c709e9389..f0a58a387 100644
--- a/qt-ui/profile/profilewidget2.cpp
+++ b/qt-ui/profile/profilewidget2.cpp
@@ -1307,13 +1307,13 @@ void ProfileWidget2::plotPictures()
struct picture *pic = (struct picture*) m->index(i,1).data(Qt::UserRole).value<void*>();
// it's a correct picture, but doesn't have a timestamp: only show on the widget near the
// information area.
- if (!pic->offset)
+ if (!pic->offset.seconds)
continue;
DivePictureItem *item = new DivePictureItem();
item->setPixmap(m->index(i,0).data(Qt::DecorationRole).value<QPixmap>());
// let's put the picture at the correct time, but at a fixed "depth" on the profile
// not sure this is ideal, but it seems to look right.
- x = timeAxis->posAtValue(pic->offset);
+ x = timeAxis->posAtValue(pic->offset.seconds);
if (i == 0)
y = 10;
else
diff --git a/save-xml.c b/save-xml.c
index 037fc45cb..4cebc3d61 100644
--- a/save-xml.c
+++ b/save-xml.c
@@ -333,8 +333,8 @@ static void save_picture(struct membuffer *b, struct picture *pic)
put_string(b, " <picture filename='");
put_string(b, pic->filename);
put_string(b, "'");
- if (pic->offset)
- put_format(b, " offset='%d'", pic->offset);
+ if (pic->offset.seconds)
+ put_format(b, " offset='%u:%02u min'", FRACTION(pic->offset.seconds, 60));
if (pic->latitude.udeg || pic->longitude.udeg) {
put_degrees(b, pic->latitude, " gps='", " ");
put_degrees(b, pic->longitude, "", "'");