Import: control process_imported_dives() by flags

process_imported_dives() takes four boolean parameters. Replace these
by flags. This makes the function calls much more descriptive. Morover,
it becomes easier to add or remove flags.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
Berthold Stoeger 2019-01-13 22:53:57 +02:00 committed by Dirk Hohndel
parent ff9506b21b
commit 891fcbf520
14 changed files with 51 additions and 52 deletions

View file

@ -11,11 +11,9 @@ void addDive(dive *d, bool autogroup, bool newNumber)
execute(new AddDive(d, autogroup, newNumber));
}
void importDives(struct dive_table *dives, struct trip_table *trips,
bool prefer_imported, bool downloaded, bool merge_all_trips,
bool add_to_new_trip, const QString &source)
void importDives(struct dive_table *dives, struct trip_table *trips, int flags, const QString &source)
{
execute(new ImportDives(dives, trips, prefer_imported, downloaded, merge_all_trips, add_to_new_trip, source));
execute(new ImportDives(dives, trips, flags, source));
}
void deleteDive(const QVector<struct dive*> &divesToDelete)

View file

@ -21,9 +21,7 @@ void addDive(dive *d, bool autogroup, bool newNumber); // If d->dive_trip is nul
// distance are added to a trip. dive d is consumed (the structure is reset)!
// If newNumber is true, the dive is assigned a new number, depending on the
// insertion position.
void importDives(struct dive_table *dives, struct trip_table *trips,
bool prefer_imported, bool downloaded, bool merge_all_trips,
bool add_to_new_trip, const QString &source);
void importDives(struct dive_table *dives, struct trip_table *trips, int flags, const QString &source);
void deleteDive(const QVector<struct dive*> &divesToDelete);
void shiftTime(const QVector<dive *> &changedDives, int amount);
void renumberDives(const QVector<QPair<dive *, int>> &divesToRenumber);

View file

@ -552,17 +552,14 @@ void AddDive::undoit()
MainWindow::instance()->refreshDisplay(false);
}
ImportDives::ImportDives(struct dive_table *dives, struct trip_table *trips,
bool prefer_imported, bool downloaded, bool merge_all_trips,
bool add_to_new_trip, const QString &source)
ImportDives::ImportDives(struct dive_table *dives, struct trip_table *trips, int flags, const QString &source)
{
setText(tr("import %n dive(s) from %1", "", dives->nr).arg(source));
struct dive_table dives_to_add = { 0 };
struct dive_table dives_to_remove = { 0 };
struct trip_table trips_to_add = { 0 };
process_imported_dives(dives, trips, prefer_imported, downloaded, merge_all_trips,
add_to_new_trip, &dives_to_add, &dives_to_remove, &trips_to_add);
process_imported_dives(dives, trips, flags, &dives_to_add, &dives_to_remove, &trips_to_add);
// Add trips to the divesToAdd.trips structure
divesToAdd.trips.reserve(trips_to_add.nr);

View file

@ -98,9 +98,7 @@ private:
class ImportDives : public DiveListBase {
public:
// Note: dives and trips are consumed - after the call they will be empty.
ImportDives(struct dive_table *dives, struct trip_table *trips,
bool prefer_imported, bool downloaded, bool merge_all_trips,
bool add_to_new_trip, const QString &source);
ImportDives(struct dive_table *dives, struct trip_table *trips, int flags, const QString &source);
private:
void undoit() override;
void redoit() override;

View file

@ -1012,7 +1012,7 @@ void DiveLogImportDialog::on_buttonBox_accepted()
}
QString source = fileNames.size() == 1 ? fileNames[0] : tr("multiple files");
Command::importDives(&table, &trips, false, false, true, false, source);
Command::importDives(&table, &trips, IMPORT_MERGE_ALL_TRIPS, source);
}
TagDragDelegate::TagDragDelegate(QObject *parent) : QStyledItemDelegate(parent)

View file

@ -516,7 +516,12 @@ void DownloadFromDCWidget::on_ok_clicked()
if (table->nr > 0) {
auto data = thread.data();
Command::importDives(table, nullptr, preferDownloaded(), true, false, ui.createNewTrip->isChecked(), data->devName());
int flags = IMPORT_IS_DOWNLOADED;
if (preferDownloaded())
flags |= IMPORT_IS_DOWNLOADED;
if (ui.createNewTrip->isChecked())
flags |= IMPORT_ADD_TO_NEW_TRIP;
Command::importDives(table, nullptr, flags, data->devName());
}
if (ostcFirmwareCheck && currentState == DONE)

View file

@ -1716,7 +1716,7 @@ void MainWindow::importFiles(const QStringList fileNames)
parse_file(fileNamePtr.data(), &table, &trips);
}
QString source = fileNames.size() == 1 ? fileNames[0] : tr("multiple files");
Command::importDives(&table, &trips, false, false, true, false, source);
Command::importDives(&table, &trips, IMPORT_MERGE_ALL_TRIPS, source);
}
void MainWindow::loadFiles(const QStringList fileNames)

View file

@ -772,7 +772,7 @@ void DivelogsDeWebServices::buttonClicked(QAbstractButton *button)
struct dive_table table = { 0 };
struct trip_table trips = { 0 };
parse_file(QFile::encodeName(zipFile.fileName()), &table, &trips);
Command::importDives(&table, &trips, false, false, true, false, QStringLiteral("divelogs.de"));
Command::importDives(&table, &trips, IMPORT_MERGE_ALL_TRIPS, QStringLiteral("divelogs.de"));
/* store last entered user/pass in config */
QSettings s;