diff options
-rw-r--r-- | core/divelist.c | 40 | ||||
-rw-r--r-- | core/divelist.h | 3 | ||||
-rw-r--r-- | core/import-csv.c | 2 | ||||
-rw-r--r-- | desktop-widgets/divelogimportdialog.cpp | 2 | ||||
-rw-r--r-- | desktop-widgets/downloadfromdivecomputer.cpp | 4 | ||||
-rw-r--r-- | desktop-widgets/mainwindow.cpp | 10 | ||||
-rw-r--r-- | desktop-widgets/subsurfacewebservices.cpp | 2 | ||||
-rw-r--r-- | mobile-widgets/qmlmanager.cpp | 6 | ||||
-rw-r--r-- | qt-models/diveimportedmodel.cpp | 2 | ||||
-rw-r--r-- | tests/testgitstorage.cpp | 24 | ||||
-rw-r--r-- | tests/testmerge.cpp | 8 | ||||
-rw-r--r-- | tests/testrenumber.cpp | 6 |
12 files changed, 60 insertions, 49 deletions
diff --git a/core/divelist.c b/core/divelist.c index 1906d002a..62af3120c 100644 --- a/core/divelist.c +++ b/core/divelist.c @@ -3,6 +3,8 @@ /* core logic for the dive list - * accessed through the following interfaces: * + * void process_loaded_dives(); + * void process_imported_dives(bool prefer_imported); * dive_trip_t *dive_trip_list; * unsigned int amount_selected; * void dump_selection(void) @@ -1259,17 +1261,32 @@ static void try_to_renumber(struct dive *last, int preexisting) } } -void process_dives(bool is_imported, bool prefer_imported) +void process_loaded_dives() +{ + int i; + struct dive *dive; + + /* Register dive computer nick names */ + for_each_dive(i, dive) + set_dc_nickname(dive); + + sort_table(&dive_table); +} + +void process_imported_dives(bool prefer_imported) { int i; int preexisting = dive_table.preexisting; - bool did_merge = false; struct dive *last; + /* If no dives were imported, don't bother doing anything */ + if (preexisting >= dive_table.nr) + return; + /* 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 * first one */ - if (preexisting < dive_table.nr && dive_table.dives[preexisting]->downloaded) + if (dive_table.dives[preexisting]->downloaded) set_dc_nickname(dive_table.dives[preexisting]); else /* they aren't downloaded, so record / check all new ones */ @@ -1315,24 +1332,17 @@ void process_dives(bool is_imported, bool prefer_imported) delete_single_dive(i + 1); // keep the id or the first dive for the merged dive merged->id = id; - - /* this means the table was changed */ - did_merge = true; } + /* make sure no dives are still marked as downloaded */ for (i = 1; i < dive_table.nr; i++) dive_table.dives[i]->downloaded = false; - if (is_imported) { - /* If there are dives in the table, are they numbered */ - if (!last || last->number) - try_to_renumber(last, preexisting); + /* If there are dives in the table, are they numbered */ + if (!last || last->number) + try_to_renumber(last, preexisting); - /* did we add dives or divecomputers to the dive table? */ - if (did_merge || preexisting < dive_table.nr) { - mark_divelist_changed(true); - } - } + mark_divelist_changed(true); } void set_dive_nr_for_current_dive() diff --git a/core/divelist.h b/core/divelist.h index 5467f10ae..937909d2b 100644 --- a/core/divelist.h +++ b/core/divelist.h @@ -18,7 +18,8 @@ extern void remove_autogen_trips(void); extern int init_decompression(struct deco_state *ds, struct dive *dive); /* divelist core logic functions */ -extern void process_dives(bool imported, bool prefer_imported); +extern void process_loaded_dives(); +extern void process_imported_dives(bool prefer_imported); extern char *get_dive_gas_string(struct dive *dive); struct dive **grow_dive_table(struct dive_table *table); diff --git a/core/import-csv.c b/core/import-csv.c index 898dfdbd0..8d6c229fd 100644 --- a/core/import-csv.c +++ b/core/import-csv.c @@ -135,7 +135,7 @@ static int parse_dan_format(const char *filename, char **params, int pnr) */ if (end_ptr) - process_dives(true, false); + process_imported_dives(false); mem_csv.buffer = malloc(mem.size + 1); mem_csv.size = mem.size; diff --git a/desktop-widgets/divelogimportdialog.cpp b/desktop-widgets/divelogimportdialog.cpp index edb93b9fd..967330277 100644 --- a/desktop-widgets/divelogimportdialog.cpp +++ b/desktop-widgets/divelogimportdialog.cpp @@ -947,7 +947,7 @@ void DiveLogImportDialog::on_buttonBox_accepted() } } - process_dives(true, false); + process_imported_dives(false); MainWindow::instance()->refreshDisplay(); } diff --git a/desktop-widgets/downloadfromdivecomputer.cpp b/desktop-widgets/downloadfromdivecomputer.cpp index c34b9a824..c040575fc 100644 --- a/desktop-widgets/downloadfromdivecomputer.cpp +++ b/desktop-widgets/downloadfromdivecomputer.cpp @@ -499,8 +499,8 @@ void DownloadFromDCWidget::on_ok_clicked() dive = get_dive(dive_table.nr - 1); if (dive != NULL) { uniqId = get_dive(dive_table.nr - 1)->id; - process_dives(true, preferDownloaded()); - // after process_dives does any merging or resorting needed, we need + process_imported_dives(preferDownloaded()); + // 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 MainWindow::instance()->recreateDiveList(); idx = get_idx_by_uniq_id(uniqId); diff --git a/desktop-widgets/mainwindow.cpp b/desktop-widgets/mainwindow.cpp index af22991a2..e4583a58e 100644 --- a/desktop-widgets/mainwindow.cpp +++ b/desktop-widgets/mainwindow.cpp @@ -616,7 +616,7 @@ void MainWindow::on_actionCloudstorageopen_triggered() QByteArray fileNamePtr = QFile::encodeName(filename); if (!parse_file(fileNamePtr.data(), &dive_table)) setCurrentFile(fileNamePtr.data()); - process_dives(false, false); + process_loaded_dives(); hideProgressBar(); refreshDisplay(); } @@ -1737,7 +1737,7 @@ void MainWindow::importFiles(const QStringList fileNames) fileNamePtr = QFile::encodeName(fileNames.at(i)); parse_file(fileNamePtr.data(), &dive_table); } - process_dives(true, false); + process_imported_dives(false); refreshDisplay(); } @@ -1767,7 +1767,7 @@ void MainWindow::importTxtFiles(const QStringList fileNames) DiveLogImportDialog *diveLogImport = new DiveLogImportDialog(csvFiles, this); diveLogImport->show(); } - process_dives(true, false); + process_imported_dives(false); refreshDisplay(); } @@ -1789,7 +1789,7 @@ void MainWindow::loadFiles(const QStringList fileNames) } hideProgressBar(); updateRecentFiles(); - process_dives(false, false); + process_loaded_dives(); refreshDisplay(); @@ -1827,7 +1827,7 @@ void MainWindow::on_actionImportDiveLog_triggered() if (csvFiles.size()) { DiveLogImportDialog *diveLogImport = new DiveLogImportDialog(csvFiles, this); diveLogImport->show(); - process_dives(true, false); + process_imported_dives(false); refreshDisplay(); } diff --git a/desktop-widgets/subsurfacewebservices.cpp b/desktop-widgets/subsurfacewebservices.cpp index 0d4d62bac..2dd39bffd 100644 --- a/desktop-widgets/subsurfacewebservices.cpp +++ b/desktop-widgets/subsurfacewebservices.cpp @@ -768,7 +768,7 @@ void DivelogsDeWebServices::buttonClicked(QAbstractButton *button) } /* parse file and import dives */ parse_file(QFile::encodeName(zipFile.fileName()), &dive_table); - process_dives(true, false); + process_imported_dives(false); MainWindow::instance()->refreshDisplay(); /* store last entered user/pass in config */ diff --git a/mobile-widgets/qmlmanager.cpp b/mobile-widgets/qmlmanager.cpp index aa9cf3d75..7df920478 100644 --- a/mobile-widgets/qmlmanager.cpp +++ b/mobile-widgets/qmlmanager.cpp @@ -288,7 +288,7 @@ void QMLManager::openLocalThenRemote(QString url) qPrefTechnicalDetails::set_show_ccr_setpoint(git_prefs.show_ccr_setpoint); qPrefTechnicalDetails::set_show_ccr_sensors(git_prefs.show_ccr_sensors); qPrefPartialPressureGas::set_po2(git_prefs.pp_graphs.po2); - process_dives(false, false); + process_loaded_dives(); DiveListModel::instance()->clear(); DiveListModel::instance()->addAllDives(); appendTextToLog(QStringLiteral("%1 dives loaded from cache").arg(dive_table.nr)); @@ -326,7 +326,7 @@ void QMLManager::mergeLocalRepo() { char *filename = NOCLOUD_LOCALSTORAGE; parse_file(filename, &dive_table); - process_dives(true, false); + process_imported_dives(false); } void QMLManager::copyAppLogToClipboard() @@ -735,7 +735,7 @@ void QMLManager::consumeFinishedLoad(timestamp_t currentDiveTimestamp) prefs.show_ccr_sensors = git_prefs.show_ccr_sensors; prefs.pp_graphs.po2 = git_prefs.pp_graphs.po2; DiveListModel::instance()->clear(); - process_dives(false, false); + process_loaded_dives(); DiveListModel::instance()->addAllDives(); if (currentDiveTimestamp) setUpdateSelectedDive(dlSortModel->getIdxForId(get_dive_id_closest_to(currentDiveTimestamp))); diff --git a/qt-models/diveimportedmodel.cpp b/qt-models/diveimportedmodel.cpp index d8d486a13..48d9a1dcd 100644 --- a/qt-models/diveimportedmodel.cpp +++ b/qt-models/diveimportedmodel.cpp @@ -177,7 +177,7 @@ void DiveImportedModel::recordDives() diveTable->dives[i] = NULL; } diveTable->nr = 0; - process_dives(true, true); + process_imported_dives(true); if (autogroup) autogroup_dives(); } diff --git a/tests/testgitstorage.cpp b/tests/testgitstorage.cpp index 5184aeb2a..f9e3e2d6c 100644 --- a/tests/testgitstorage.cpp +++ b/tests/testgitstorage.cpp @@ -137,9 +137,9 @@ void TestGitStorage::testGitStorageCloudOfflineSync() // read the local repo from the previous test and add dive 10 QCOMPARE(parse_file(qPrintable(localCacheRepo), &dive_table), 0); QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/test10.xml", &dive_table), 0); - // calling process_dive() sorts the table, but calling it with - // is_imported == true causes it to try to update the window title... let's not do that - process_dives(false, false); + // calling process_loaded_dives() sorts the table, but calling process_imported_dives() + // causes it to try to update the window title... let's not do that + process_loaded_dives(); // now save only to the local cache but not to the remote server QCOMPARE(save_dives(qPrintable(localCacheRepo)), 0); QCOMPARE(save_dives("./SampleDivesV3plus10local.ssrf"), 0); @@ -186,14 +186,14 @@ void TestGitStorage::testGitStorageCloudMerge() QString localCacheRepoSave = localCacheDir + "save[ssrftest@hohndel.org]"; QCOMPARE(parse_file(qPrintable(localCacheRepoSave), &dive_table), 0); QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/test11.xml", &dive_table), 0); - process_dives(false, false); + process_loaded_dives(); QCOMPARE(save_dives(qPrintable(localCacheRepoSave)), 0); clear_dive_file_data(); // now we open the cloud storage repo and add a different dive to it QCOMPARE(parse_file(qPrintable(cloudTestRepo), &dive_table), 0); QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/test12.xml", &dive_table), 0); - process_dives(false, false); + process_loaded_dives(); QCOMPARE(save_dives(qPrintable(cloudTestRepo)), 0); clear_dive_file_data(); @@ -208,9 +208,9 @@ void TestGitStorage::testGitStorageCloudMerge() clear_dive_file_data(); QCOMPARE(parse_file("./SampleDivesV3plus10local.ssrf", &dive_table), 0); QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/test11.xml", &dive_table), 0); - process_dives(false, false); + process_loaded_dives(); QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/test12.xml", &dive_table), 0); - process_dives(false, false); + process_loaded_dives(); QCOMPARE(save_dives("./SampleDivesV3plus10-11-12.ssrf"), 0); QFile org("./SampleDivesV3plus10-11-12-merged.ssrf"); org.open(QFile::ReadOnly); @@ -232,7 +232,7 @@ void TestGitStorage::testGitStorageCloudMerge2() QString localCacheDir(get_local_dir("https://cloud.subsurface-divelog.org/git/ssrftest@hohndel.org", "ssrftest@hohndel.org")); QString localCacheRepo = localCacheDir + "[ssrftest@hohndel.org]"; QCOMPARE(parse_file(qPrintable(localCacheRepo), &dive_table), 0); - process_dives(false, false); + process_loaded_dives(); struct dive *dive = get_dive(1); delete_single_dive(1); QCOMPARE(save_dives("./SampleDivesMinus1.ssrf"), 0); @@ -248,7 +248,7 @@ void TestGitStorage::testGitStorageCloudMerge2() } // now we open the cloud storage repo and modify that first dive QCOMPARE(parse_file(qPrintable(cloudTestRepo), &dive_table), 0); - process_dives(false, false); + process_loaded_dives(); dive = get_dive(1); QVERIFY(dive != NULL); free(dive->notes); @@ -288,7 +288,7 @@ void TestGitStorage::testGitStorageCloudMerge3() QString localCacheDir(get_local_dir("https://cloud.subsurface-divelog.org/git/ssrftest@hohndel.org", "ssrftest@hohndel.org")); QString localCacheRepo = localCacheDir + "[ssrftest@hohndel.org]"; QCOMPARE(parse_file(qPrintable(cloudTestRepo), &dive_table), 0); - process_dives(false, false); + process_loaded_dives(); struct dive *dive = get_dive(0); QVERIFY(dive != 0); dive->notes = strdup("Create multi line dive notes\nLine 2\nLine 3\nLine 4\nLine 5\nThat should be enough"); @@ -300,7 +300,7 @@ void TestGitStorage::testGitStorageCloudMerge3() clear_dive_file_data(); QCOMPARE(parse_file(qPrintable(localCacheRepo), &dive_table), 0); - process_dives(false, false); + process_loaded_dives(); dive = get_dive(0); dive->notes = strdup("Create multi line dive notes\nDifferent line 2 and removed 3-5\n\nThat should be enough"); dive = get_dive(1); @@ -319,7 +319,7 @@ void TestGitStorage::testGitStorageCloudMerge3() } // now we open the cloud storage repo and modify those first dive notes differently QCOMPARE(parse_file(qPrintable(cloudTestRepo), &dive_table), 0); - process_dives(false, false); + process_loaded_dives(); dive = get_dive(0); dive->notes = strdup("Completely different dive notes\nBut also multi line"); dive = get_dive(1); diff --git a/tests/testmerge.cpp b/tests/testmerge.cpp index b102e239f..50bfd6e50 100644 --- a/tests/testmerge.cpp +++ b/tests/testmerge.cpp @@ -22,9 +22,9 @@ void TestMerge::testMergeEmpty() * check that we correctly merge mixed cylinder dives */ QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/test47.xml", &dive_table), 0); - process_dives(true, false); + process_imported_dives(false); QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/test48.xml", &dive_table), 0); - process_dives(true, false); + process_imported_dives(false); QCOMPARE(save_dives("./testmerge47+48.ssrf"), 0); QFile org(SUBSURFACE_TEST_DATA "/dives/test47+48.xml"); org.open(QFile::ReadOnly); @@ -45,9 +45,9 @@ void TestMerge::testMergeBackwards() * check that we correctly merge mixed cylinder dives */ QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/test48.xml", &dive_table), 0); - process_dives(true, false); + process_imported_dives(false); QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/test47.xml", &dive_table), 0); - process_dives(true, false); + process_imported_dives(false); QCOMPARE(save_dives("./testmerge47+48.ssrf"), 0); QFile org(SUBSURFACE_TEST_DATA "/dives/test47+48.xml"); org.open(QFile::ReadOnly); diff --git a/tests/testrenumber.cpp b/tests/testrenumber.cpp index f6a628083..54d689004 100644 --- a/tests/testrenumber.cpp +++ b/tests/testrenumber.cpp @@ -8,14 +8,14 @@ void TestRenumber::setup() { QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/test47.xml", &dive_table), 0); - process_dives(false, false); + process_loaded_dives(); dive_table.preexisting = dive_table.nr; } void TestRenumber::testMerge() { QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/test47b.xml", &dive_table), 0); - process_dives(true, false); + process_imported_dives(false); QCOMPARE(dive_table.nr, 1); QCOMPARE(unsaved_changes(), 1); mark_divelist_changed(false); @@ -25,7 +25,7 @@ void TestRenumber::testMerge() void TestRenumber::testMergeAndAppend() { QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/test47c.xml", &dive_table), 0); - process_dives(true, false); + process_imported_dives(false); QCOMPARE(dive_table.nr, 2); QCOMPARE(unsaved_changes(), 1); struct dive *d = get_dive(1); |