From 98b3a326bd952c616843694821a48e0c029db699 Mon Sep 17 00:00:00 2001 From: Doug Junkins Date: Sat, 4 May 2019 20:46:42 -0700 Subject: Add "Import dive sites" menu to mainwindow Adds "Import->Import dive sites" menu to mainwindow.cpp and adds the on_actionImportDiveSites_triggered() method to prompt for the filename to import from. The files are parsed and then any dive and trip data is cleared before opening a dialog box to select which sites are to be imported. Signed-off-by: Doug Junkins --- desktop-widgets/mainwindow.cpp | 44 ++++++++++++++++++++++++++++++++++++++++++ desktop-widgets/mainwindow.h | 2 ++ desktop-widgets/mainwindow.ui | 12 ++++++++++++ 3 files changed, 58 insertions(+) (limited to 'desktop-widgets') diff --git a/desktop-widgets/mainwindow.cpp b/desktop-widgets/mainwindow.cpp index 9ff6808c5..18571e3b8 100644 --- a/desktop-widgets/mainwindow.cpp +++ b/desktop-widgets/mainwindow.cpp @@ -43,6 +43,7 @@ #include "desktop-widgets/divelistview.h" #include "desktop-widgets/divelogexportdialog.h" #include "desktop-widgets/divelogimportdialog.h" +#include "desktop-widgets/divesiteimportdialog.h" #include "desktop-widgets/diveplanner.h" #include "desktop-widgets/downloadfromdivecomputer.h" #include "desktop-widgets/findmovedimagesdialog.h" @@ -1338,6 +1339,18 @@ QString MainWindow::filter_import() return f; } +QString MainWindow::filter_import_dive_sites() +{ + QString f = tr("Dive site files") + + " (*.ssrf" + " *.xml" + ");;"; + + f += tr("All files") + " (*.*)"; + + return f; +} + bool MainWindow::askSaveChanges() { QMessageBox response(this); @@ -1748,6 +1761,37 @@ void MainWindow::on_actionImportDiveLog_triggered() } } +void MainWindow::on_actionImportDiveSites_triggered() +{ + QStringList fileNames = QFileDialog::getOpenFileNames(this, tr("Open dive site file"), lastUsedDir(), filter_import_dive_sites()); + + if (fileNames.isEmpty()) + return; + updateLastUsedDir(QFileInfo(fileNames[0]).dir().path()); + + struct dive_table table = { 0 }; + struct trip_table trips = { 0 }; + struct dive_site_table sites = { 0 }; + + for (const QString &s: fileNames) { + QByteArray fileNamePtr = QFile::encodeName(s); + parse_file(fileNamePtr.data(), &table, &trips, &sites); + } + // The imported dive sites still have pointers to imported dives - remove them + for (int i = 0; i < sites.nr; ++i) + sites.dive_sites[i]->dives.nr = 0; + + // Now we can clear the imported dives and trips. + clear_table(&table); + clear_trip_table(&trips); + + QString source = fileNames.size() == 1 ? fileNames[0] : tr("multiple files"); + + // sites table will be cleared by DivesiteImportDialog constructor + DivesiteImportDialog divesiteImport(sites, source, this); + divesiteImport.exec(); +} + void MainWindow::editCurrentDive() { if (!current_dive) diff --git a/desktop-widgets/mainwindow.h b/desktop-widgets/mainwindow.h index 252a95b98..805900a74 100644 --- a/desktop-widgets/mainwindow.h +++ b/desktop-widgets/mainwindow.h @@ -139,6 +139,7 @@ slots: void initialUiSetup(); void on_actionImportDiveLog_triggered(); + void on_actionImportDiveSites_triggered(); /* TODO: Move those slots below to it's own class */ void on_actionExport_triggered(); @@ -192,6 +193,7 @@ private: CurrentState stateBeforeEdit; QString filter_open(); QString filter_import(); + QString filter_import_dive_sites(); static MainWindow *m_Instance; QString displayedFilename(QString fullFilename); bool askSaveChanges(); diff --git a/desktop-widgets/mainwindow.ui b/desktop-widgets/mainwindow.ui index 3548280e8..07886b18e 100644 --- a/desktop-widgets/mainwindow.ui +++ b/desktop-widgets/mainwindow.ui @@ -130,6 +130,7 @@ + @@ -381,6 +382,17 @@ Ctrl+I + + + &Import dive sites + + + Import dive sites from other users + + + Ctrl+J + + Import &from divelogs.de -- cgit v1.2.3-70-g09d2