media: move addition of pictures out of create_picture()

If we want to make addition of pictures undoable, then create_picture()
must not add directly to the dive. Instead, return the dive to which the
picture should be added and let the caller perform the addition.

This means that the picture-test has to be adapted.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
Berthold Stoeger 2020-04-19 16:48:53 +02:00 committed by Dirk Hohndel
parent 0935513636
commit 74f03e3537
4 changed files with 45 additions and 25 deletions

View file

@ -11,6 +11,7 @@
#include "desktop-widgets/divepicturewidget.h"
#include "core/selection.h"
#include "core/divefilter.h"
#include "core/divesite.h" // for dive_site_table. TODO: remove once adding pictures is undoified
#include <unistd.h>
#include <QSettings>
#include <QKeyEvent>
@ -890,8 +891,16 @@ void DiveListView::matchImagesToDives(QStringList fileNames)
return;
updateLastImageTimeOffset(shiftDialog.amount());
for (const QString &fileName: fileNames)
create_picture(qPrintable(fileName), shiftDialog.amount(), shiftDialog.matchAll());
for (const QString &fileName: fileNames) {
struct dive *d;
picture *pic = create_picture(qPrintable(fileName), shiftDialog.amount(), shiftDialog.matchAll(), &d);
if (!pic)
continue;
add_picture(&d->pictures, *pic);
dive_set_geodata_from_picture(d, pic, &dive_site_table);
invalidate_dive_cache(d);
free(pic);
}
mark_divelist_changed(true);
copy_dive(current_dive, &displayed_dive);