mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
Core: split process_dives() in post-import and post-load versions
process_dives() is used to post-process the dive table after loading or importing. The first parameter states whether this was after load or import. Especially in the light of undo, load and import are fundamentally different things. Notably, that latter should be undo-able, whereas the former is not. Therefore, as a first step to make import undo-able, split the function in two versions and remove the first parameter. It turns out the the load-version is very light. It only sets the DC nicknames and sorts the dive-table. There seems to be no reason to merge dives. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
parent
0ae57cfe92
commit
35b8a4f404
12 changed files with 60 additions and 49 deletions
|
@ -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()
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -947,7 +947,7 @@ void DiveLogImportDialog::on_buttonBox_accepted()
|
|||
}
|
||||
}
|
||||
|
||||
process_dives(true, false);
|
||||
process_imported_dives(false);
|
||||
MainWindow::instance()->refreshDisplay();
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
||||
|
|
|
@ -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 */
|
||||
|
|
|
@ -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)));
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Add table
Reference in a new issue