mirror of
https://github.com/subsurface/subsurface.git
synced 2024-11-28 05:00:20 +00:00
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 <junkins@foghead.com>
This commit is contained in:
parent
704ff9f82e
commit
98b3a326bd
6 changed files with 61 additions and 1 deletions
|
@ -1,3 +1,4 @@
|
||||||
|
- Desktop: Add import dive site menu option and site selection dialog
|
||||||
- Core: fix bug in get_distance() to correctly compute spherical distance
|
- Core: fix bug in get_distance() to correctly compute spherical distance
|
||||||
- Desktop: For videos, add save data export as subtitle file
|
- Desktop: For videos, add save data export as subtitle file
|
||||||
- Desktop: make dive sites 1st class citizens with their own dive site table
|
- Desktop: make dive sites 1st class citizens with their own dive site table
|
||||||
|
|
|
@ -1292,7 +1292,7 @@ void clear_table(struct dive_table *table)
|
||||||
table->nr = 0;
|
table->nr = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void clear_trip_table(struct trip_table *table)
|
void clear_trip_table(struct trip_table *table)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < table->nr; i++)
|
for (int i = 0; i < table->nr; i++)
|
||||||
free_trip(table->trips[i]);
|
free_trip(table->trips[i]);
|
||||||
|
|
|
@ -69,6 +69,7 @@ void report_datafile_version(int version);
|
||||||
int get_dive_id_closest_to(timestamp_t when);
|
int get_dive_id_closest_to(timestamp_t when);
|
||||||
void clear_dive_file_data();
|
void clear_dive_file_data();
|
||||||
void clear_table(struct dive_table *table);
|
void clear_table(struct dive_table *table);
|
||||||
|
void clear_trip_table(struct trip_table *table);
|
||||||
|
|
||||||
typedef enum {PO2VAL, SINGLE_EXP, SINGLE_SLOPE, DAILY_EXP, DAILY_SLOPE, NO_COLUMNS} cns_table_headers;
|
typedef enum {PO2VAL, SINGLE_EXP, SINGLE_SLOPE, DAILY_EXP, DAILY_SLOPE, NO_COLUMNS} cns_table_headers;
|
||||||
|
|
||||||
|
|
|
@ -43,6 +43,7 @@
|
||||||
#include "desktop-widgets/divelistview.h"
|
#include "desktop-widgets/divelistview.h"
|
||||||
#include "desktop-widgets/divelogexportdialog.h"
|
#include "desktop-widgets/divelogexportdialog.h"
|
||||||
#include "desktop-widgets/divelogimportdialog.h"
|
#include "desktop-widgets/divelogimportdialog.h"
|
||||||
|
#include "desktop-widgets/divesiteimportdialog.h"
|
||||||
#include "desktop-widgets/diveplanner.h"
|
#include "desktop-widgets/diveplanner.h"
|
||||||
#include "desktop-widgets/downloadfromdivecomputer.h"
|
#include "desktop-widgets/downloadfromdivecomputer.h"
|
||||||
#include "desktop-widgets/findmovedimagesdialog.h"
|
#include "desktop-widgets/findmovedimagesdialog.h"
|
||||||
|
@ -1338,6 +1339,18 @@ QString MainWindow::filter_import()
|
||||||
return f;
|
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()
|
bool MainWindow::askSaveChanges()
|
||||||
{
|
{
|
||||||
QMessageBox response(this);
|
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()
|
void MainWindow::editCurrentDive()
|
||||||
{
|
{
|
||||||
if (!current_dive)
|
if (!current_dive)
|
||||||
|
|
|
@ -139,6 +139,7 @@ slots:
|
||||||
void initialUiSetup();
|
void initialUiSetup();
|
||||||
|
|
||||||
void on_actionImportDiveLog_triggered();
|
void on_actionImportDiveLog_triggered();
|
||||||
|
void on_actionImportDiveSites_triggered();
|
||||||
|
|
||||||
/* TODO: Move those slots below to it's own class */
|
/* TODO: Move those slots below to it's own class */
|
||||||
void on_actionExport_triggered();
|
void on_actionExport_triggered();
|
||||||
|
@ -192,6 +193,7 @@ private:
|
||||||
CurrentState stateBeforeEdit;
|
CurrentState stateBeforeEdit;
|
||||||
QString filter_open();
|
QString filter_open();
|
||||||
QString filter_import();
|
QString filter_import();
|
||||||
|
QString filter_import_dive_sites();
|
||||||
static MainWindow *m_Instance;
|
static MainWindow *m_Instance;
|
||||||
QString displayedFilename(QString fullFilename);
|
QString displayedFilename(QString fullFilename);
|
||||||
bool askSaveChanges();
|
bool askSaveChanges();
|
||||||
|
|
|
@ -130,6 +130,7 @@
|
||||||
</property>
|
</property>
|
||||||
<addaction name="actionDownloadDC"/>
|
<addaction name="actionDownloadDC"/>
|
||||||
<addaction name="actionImportDiveLog"/>
|
<addaction name="actionImportDiveLog"/>
|
||||||
|
<addaction name="actionImportDiveSites"/>
|
||||||
<addaction name="actionDivelogs_de"/>
|
<addaction name="actionDivelogs_de"/>
|
||||||
</widget>
|
</widget>
|
||||||
<widget class="QMenu" name="menu_Edit">
|
<widget class="QMenu" name="menu_Edit">
|
||||||
|
@ -381,6 +382,17 @@
|
||||||
<string notr="true">Ctrl+I</string>
|
<string notr="true">Ctrl+I</string>
|
||||||
</property>
|
</property>
|
||||||
</action>
|
</action>
|
||||||
|
<action name="actionImportDiveSites">
|
||||||
|
<property name="text">
|
||||||
|
<string>&Import dive sites</string>
|
||||||
|
</property>
|
||||||
|
<property name="toolTip">
|
||||||
|
<string>Import dive sites from other users</string>
|
||||||
|
</property>
|
||||||
|
<property name="shortcut">
|
||||||
|
<string notr="true">Ctrl+J</string>
|
||||||
|
</property>
|
||||||
|
</action>
|
||||||
<action name="actionDivelogs_de">
|
<action name="actionDivelogs_de">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Import &from divelogs.de</string>
|
<string>Import &from divelogs.de</string>
|
||||||
|
|
Loading…
Reference in a new issue