Import: pass "downloaded" parameter to process_imported_dives()

process_imported_dives() is more efficient for downloaded than for
imported (from a file) dives, because it checks only the divecomputer
of the first dive.

This condition is checked via the "downloaded" flag of the first
dive. Instead, pass an argument to process_imported_dives().

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
Berthold Stoeger 2018-10-03 21:45:50 +02:00 committed by Dirk Hohndel
parent e5dca8228e
commit 6dc1dcaea5
10 changed files with 20 additions and 16 deletions

View file

@ -1339,10 +1339,13 @@ static bool try_to_merge_into(struct dive *dive_to_add, int idx, bool prefer_imp
* Add imported dive to global dive table. Overlapping dives will * Add imported dive to global dive table. Overlapping dives will
* be merged if possible. If prefer_imported is true, data of the * be merged if possible. If prefer_imported is true, data of the
* new dives are prioritized in such a case. * new dives are prioritized in such a case.
* If downloaded is true, only the divecomputer of the first dive
* will be considered, as it is assumed that all dives come from
* the same computer.
* Note: the dives in import_table are consumed! On return import_table * Note: the dives in import_table are consumed! On return import_table
* has size 0. * has size 0.
*/ */
void process_imported_dives(struct dive_table *import_table, bool prefer_imported) void process_imported_dives(struct dive_table *import_table, bool prefer_imported, bool downloaded)
{ {
int i, j; int i, j;
struct dive *old_dive, *merged; struct dive *old_dive, *merged;
@ -1356,7 +1359,7 @@ void process_imported_dives(struct dive_table *import_table, bool prefer_importe
/* check if we need a nickname for the divecomputer for newly downloaded dives; /* check if we need a nickname for the divecomputer for newly downloaded dives;
* since we know they all came from the same divecomputer we just check for the * since we know they all came from the same divecomputer we just check for the
* first one */ * first one */
if (import_table->dives[0]->downloaded) if (downloaded)
set_dc_nickname(import_table->dives[0]); set_dc_nickname(import_table->dives[0]);
else else
/* they aren't downloaded, so record / check all new ones */ /* they aren't downloaded, so record / check all new ones */

View file

@ -19,7 +19,7 @@ extern int init_decompression(struct deco_state *ds, struct dive *dive);
/* divelist core logic functions */ /* divelist core logic functions */
extern void process_loaded_dives(); extern void process_loaded_dives();
extern void process_imported_dives(struct dive_table *import_table, bool prefer_imported); extern void process_imported_dives(struct dive_table *import_table, bool prefer_imported, bool downloaded);
extern char *get_dive_gas_string(struct dive *dive); extern char *get_dive_gas_string(struct dive *dive);
struct dive **grow_dive_table(struct dive_table *table); struct dive **grow_dive_table(struct dive_table *table);

View file

@ -1007,7 +1007,7 @@ void DiveLogImportDialog::on_buttonBox_accepted()
} }
} }
process_imported_dives(&table, false); process_imported_dives(&table, false, false);
MainWindow::instance()->refreshDisplay(); MainWindow::instance()->refreshDisplay();
} }

View file

@ -506,7 +506,7 @@ void DownloadFromDCWidget::on_ok_clicked()
// remember the last downloaded dive (on most dive computers this will be the chronologically // remember the last downloaded dive (on most dive computers this will be the chronologically
// first new dive) and select it again after processing all the dives // first new dive) and select it again after processing all the dives
int uniqId = downloadTable.dives[downloadTable.nr - 1]->id; int uniqId = downloadTable.dives[downloadTable.nr - 1]->id;
process_imported_dives(&downloadTable, preferDownloaded()); process_imported_dives(&downloadTable, preferDownloaded(), true);
// after process_imported_dives does any merging or resorting needed, we need // after process_imported_dives does any merging or resorting needed, we need
// to recreate the model for the dive list so we can select the newest dive // to recreate the model for the dive list so we can select the newest dive
MainWindow::instance()->recreateDiveList(); MainWindow::instance()->recreateDiveList();

View file

@ -1739,7 +1739,7 @@ void MainWindow::importFiles(const QStringList fileNames)
fileNamePtr = QFile::encodeName(fileNames.at(i)); fileNamePtr = QFile::encodeName(fileNames.at(i));
parse_file(fileNamePtr.data(), &table); parse_file(fileNamePtr.data(), &table);
} }
process_imported_dives(&table, false); process_imported_dives(&table, false, false);
refreshDisplay(); refreshDisplay();
} }

View file

@ -769,7 +769,7 @@ void DivelogsDeWebServices::buttonClicked(QAbstractButton *button)
/* parse file and import dives */ /* parse file and import dives */
struct dive_table table = { 0 }; struct dive_table table = { 0 };
parse_file(QFile::encodeName(zipFile.fileName()), &table); parse_file(QFile::encodeName(zipFile.fileName()), &table);
process_imported_dives(&table, false); process_imported_dives(&table, false, false);
MainWindow::instance()->refreshDisplay(); MainWindow::instance()->refreshDisplay();
/* store last entered user/pass in config */ /* store last entered user/pass in config */

View file

@ -325,8 +325,9 @@ void QMLManager::updateAllGlobalLists()
void QMLManager::mergeLocalRepo() void QMLManager::mergeLocalRepo()
{ {
char *filename = NOCLOUD_LOCALSTORAGE; char *filename = NOCLOUD_LOCALSTORAGE;
parse_file(filename, &dive_table); struct dive_table table = { 0 };
process_imported_dives(false); parse_file(filename, &table);
process_imported_dives(&table, false, false);
} }
void QMLManager::copyAppLogToClipboard() void QMLManager::copyAppLogToClipboard()

View file

@ -173,7 +173,7 @@ void DiveImportedModel::recordDives()
delete_dive_from_table(&downloadTable, j); delete_dive_from_table(&downloadTable, j);
} }
process_imported_dives(diveTable, true); process_imported_dives(diveTable, true, true);
if (autogroup) if (autogroup)
autogroup_dives(); autogroup_dives();
} }

View file

@ -23,9 +23,9 @@ void TestMerge::testMergeEmpty()
*/ */
struct dive_table table = { 0 }; struct dive_table table = { 0 };
QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/test47.xml", &table), 0); QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/test47.xml", &table), 0);
process_imported_dives(&table, false); process_imported_dives(&table, false, false);
QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/test48.xml", &table), 0); QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/test48.xml", &table), 0);
process_imported_dives(&table, false); process_imported_dives(&table, false, false);
QCOMPARE(save_dives("./testmerge47+48.ssrf"), 0); QCOMPARE(save_dives("./testmerge47+48.ssrf"), 0);
QFile org(SUBSURFACE_TEST_DATA "/dives/test47+48.xml"); QFile org(SUBSURFACE_TEST_DATA "/dives/test47+48.xml");
org.open(QFile::ReadOnly); org.open(QFile::ReadOnly);
@ -47,9 +47,9 @@ void TestMerge::testMergeBackwards()
*/ */
struct dive_table table = { 0 }; struct dive_table table = { 0 };
QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/test48.xml", &table), 0); QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/test48.xml", &table), 0);
process_imported_dives(&table, false); process_imported_dives(&table, false, false);
QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/test47.xml", &table), 0); QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/test47.xml", &table), 0);
process_imported_dives(&table, false); process_imported_dives(&table, false, false);
QCOMPARE(save_dives("./testmerge47+48.ssrf"), 0); QCOMPARE(save_dives("./testmerge47+48.ssrf"), 0);
QFile org(SUBSURFACE_TEST_DATA "/dives/test47+48.xml"); QFile org(SUBSURFACE_TEST_DATA "/dives/test47+48.xml");
org.open(QFile::ReadOnly); org.open(QFile::ReadOnly);

View file

@ -15,7 +15,7 @@ void TestRenumber::testMerge()
{ {
struct dive_table table = { 0 }; struct dive_table table = { 0 };
QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/test47b.xml", &table), 0); QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/test47b.xml", &table), 0);
process_imported_dives(&table, false); process_imported_dives(&table, false, false);
QCOMPARE(dive_table.nr, 1); QCOMPARE(dive_table.nr, 1);
QCOMPARE(unsaved_changes(), 1); QCOMPARE(unsaved_changes(), 1);
mark_divelist_changed(false); mark_divelist_changed(false);
@ -25,7 +25,7 @@ void TestRenumber::testMergeAndAppend()
{ {
struct dive_table table = { 0 }; struct dive_table table = { 0 };
QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/test47c.xml", &table), 0); QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/test47c.xml", &table), 0);
process_imported_dives(&table, false); process_imported_dives(&table, false, false);
QCOMPARE(dive_table.nr, 2); QCOMPARE(dive_table.nr, 2);
QCOMPARE(unsaved_changes(), 1); QCOMPARE(unsaved_changes(), 1);
struct dive *d = get_dive(1); struct dive *d = get_dive(1);