summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Miika Turkia <miika.turkia@gmail.com>2014-01-07 22:01:28 +0200
committerGravatar Dirk Hohndel <dirk@hohndel.org>2014-01-08 05:54:20 +0800
commit88fdf1b138afaead559456d1734eae88b4778f83 (patch)
tree11fa840c47e78f8cf0691674fd7c32f97be5b38b
parent58f6a01a220bcdc25de2aac84a4eb5e49562d739 (diff)
downloadsubsurface-88fdf1b138afaead559456d1734eae88b4778f83.tar.gz
Show import dialog only when needed for CSV config
We do not need any import dialog when importing normal XML based divelogs. With this they are imported directly after file selection dialog. However, when CSV files are detected in the import list, the configuration dialog is displayed and applied for them. (CSV files are detected by file extension.) Signed-off-by: Miika Turkia <miika.turkia@gmail.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
-rw-r--r--qt-ui/divelogimportdialog.cpp60
-rw-r--r--qt-ui/divelogimportdialog.h8
-rw-r--r--qt-ui/divelogimportdialog.ui111
-rw-r--r--qt-ui/mainwindow.cpp22
4 files changed, 46 insertions, 155 deletions
diff --git a/qt-ui/divelogimportdialog.cpp b/qt-ui/divelogimportdialog.cpp
index 129dbd9d0..e5814795d 100644
--- a/qt-ui/divelogimportdialog.cpp
+++ b/qt-ui/divelogimportdialog.cpp
@@ -11,12 +11,13 @@ const DiveLogImportDialog::CSVAppConfig DiveLogImportDialog::CSVApps[CSVAPPS] =
{NULL,}
};
-DiveLogImportDialog::DiveLogImportDialog(QWidget *parent) :
+DiveLogImportDialog::DiveLogImportDialog(QStringList *fn, QWidget *parent) :
QDialog(parent),
selector(true),
ui(new Ui::DiveLogImportDialog)
{
ui->setupUi(this);
+ fileNames = *fn;
for (int i = 0; !CSVApps[i].name.isNull(); ++i)
ui->knownImports->addItem(CSVApps[i].name);
@@ -24,7 +25,6 @@ DiveLogImportDialog::DiveLogImportDialog(QWidget *parent) :
ui->CSVSeparator->addItem("Tab");
ui->CSVSeparator->addItem(",");
ui->knownImports->setCurrentIndex(1);
- ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false);
connect(ui->CSVDepth, SIGNAL(valueChanged(int)), this, SLOT(unknownImports(int)));
connect(ui->CSVTime, SIGNAL(valueChanged(int)), this, SLOT(unknownImports(int)));
@@ -48,30 +48,8 @@ void DiveLogImportDialog::on_buttonBox_accepted()
{
char *error = NULL;
- if (ui->tabWidget->currentIndex() == 0) {
- QStringList fileNames = ui->DiveLogFile->text().split(";");
-
- /*
- if (ui->ImportAdvanced->isChecked()) {
- for (int i = 0; i < fileNames.size(); ++i) {
- parse_xml_file_units(fileNames.at(i).toUtf8().data(),
- ui->XMLImportFormat->currentIndex(), ui->XMLImportUnits->currentIndex(),
- &error);
- }
- if (error != NULL) {
-
- mainWindow()->showError(error);
- free(error);
- error = NULL;
- }
- } else {
- */
- mainWindow()->importFiles(fileNames);
- return;
- //}
-
- } else {
- parse_csv_file(ui->CSVFile->text().toUtf8().data(), ui->CSVTime->value() - 1,
+ for (int i = 0; i < fileNames.size(); ++i) {
+ parse_csv_file(fileNames[i].toUtf8().data(), ui->CSVTime->value() - 1,
ui->CSVDepth->value() - 1, VALUE_IF_CHECKED(CSVTemperature),
VALUE_IF_CHECKED(CSVpo2),
VALUE_IF_CHECKED(CSVcns),
@@ -89,13 +67,6 @@ void DiveLogImportDialog::on_buttonBox_accepted()
mainWindow()->refreshDisplay();
}
-void DiveLogImportDialog::on_CSVFileSelector_clicked()
-{
- QString filename = QFileDialog::getOpenFileName(this, tr("Open CSV Log File"), ".", tr("CSV Files (*.csv);;All Files(*)"));
- ui->CSVFile->setText(filename);
- ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(!filename.isEmpty());
-}
-
#define SET_VALUE_AND_CHECKBOX(CSV, BOX, VAL) ({\
ui->CSV->blockSignals(true);\
ui->CSV->setValue(VAL);\
@@ -134,26 +105,3 @@ void DiveLogImportDialog::unknownImports()
{
ui->knownImports->setCurrentIndex(0);
}
-
-void DiveLogImportDialog::on_CSVFile_textEdited()
-{
- ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(!ui->CSVFile->text().isEmpty());
-}
-
-void DiveLogImportDialog::on_DiveLogFileSelector_clicked()
-{
- QStringList fileNames = QFileDialog::getOpenFileNames(this, tr("Open Dive Log File"), ".", tr("XML Files (*.xml);;UDDF/UDCF Files(*.uddf *.udcf);;All Files(*)"));
- ui->DiveLogFile->setText(fileNames.join(";"));
- if (fileNames.size())
- ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(true);
- else
- ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false);
-}
-
-void DiveLogImportDialog::on_DiveLogFile_editingFinished()
-{
- if (ui->DiveLogFile->text().size())
- ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(true);
- else
- ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false);
-}
diff --git a/qt-ui/divelogimportdialog.h b/qt-ui/divelogimportdialog.h
index 9ecf32410..d8cedab6a 100644
--- a/qt-ui/divelogimportdialog.h
+++ b/qt-ui/divelogimportdialog.h
@@ -15,24 +15,20 @@ class DiveLogImportDialog : public QDialog
Q_OBJECT
public:
- explicit DiveLogImportDialog(QWidget *parent = 0);
+ explicit DiveLogImportDialog(QStringList *fn, QWidget *parent = 0);
~DiveLogImportDialog();
private slots:
void on_buttonBox_accepted();
- void on_CSVFileSelector_clicked();
void on_knownImports_currentIndexChanged(int index);
- void on_CSVFile_textEdited();
void unknownImports(int);
void unknownImports(bool);
- void on_DiveLogFileSelector_clicked();
- void on_DiveLogFile_editingFinished();
-
private:
void unknownImports();
bool selector;
+ QStringList fileNames;
Ui::DiveLogImportDialog *ui;
struct CSVAppConfig {
diff --git a/qt-ui/divelogimportdialog.ui b/qt-ui/divelogimportdialog.ui
index ac2315636..36f62de54 100644
--- a/qt-ui/divelogimportdialog.ui
+++ b/qt-ui/divelogimportdialog.ui
@@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>515</width>
- <height>440</height>
+ <height>370</height>
</rect>
</property>
<property name="windowTitle">
@@ -33,7 +33,7 @@
<enum>QFrame::NoFrame</enum>
</property>
<property name="text">
- <string>Import Dive Log File</string>
+ <string>Import CSV Dive Log Files</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
@@ -45,82 +45,15 @@
<property name="currentIndex">
<number>0</number>
</property>
- <widget class="QWidget" name="tab_2">
- <attribute name="title">
- <string>DiveLog</string>
- </attribute>
- <widget class="QGroupBox" name="groupBox_8">
- <property name="geometry">
- <rect>
- <x>10</x>
- <y>10</y>
- <width>441</width>
- <height>65</height>
- </rect>
- </property>
- <property name="sizePolicy">
- <sizepolicy hsizetype="Expanding" vsizetype="Preferred">
- <horstretch>0</horstretch>
- <verstretch>0</verstretch>
- </sizepolicy>
- </property>
- <property name="title">
- <string>Import File</string>
- </property>
- <layout class="QHBoxLayout" name="horizontalLayout_8">
- <item>
- <widget class="QLineEdit" name="DiveLogFile"/>
- </item>
- <item>
- <widget class="QToolButton" name="DiveLogFileSelector">
- <property name="text">
- <string>...</string>
- </property>
- </widget>
- </item>
- </layout>
- </widget>
- </widget>
<widget class="QWidget" name="tab">
<attribute name="title">
- <string>CSV</string>
+ <string>CSV options</string>
</attribute>
- <widget class="QGroupBox" name="groupBox">
- <property name="geometry">
- <rect>
- <x>10</x>
- <y>10</y>
- <width>441</width>
- <height>65</height>
- </rect>
- </property>
- <property name="sizePolicy">
- <sizepolicy hsizetype="Expanding" vsizetype="Preferred">
- <horstretch>0</horstretch>
- <verstretch>0</verstretch>
- </sizepolicy>
- </property>
- <property name="title">
- <string>Import File</string>
- </property>
- <layout class="QHBoxLayout" name="horizontalLayout">
- <item>
- <widget class="QLineEdit" name="CSVFile"/>
- </item>
- <item>
- <widget class="QToolButton" name="CSVFileSelector">
- <property name="text">
- <string>...</string>
- </property>
- </widget>
- </item>
- </layout>
- </widget>
<widget class="QGroupBox" name="groupBox_2">
<property name="geometry">
<rect>
<x>210</x>
- <y>88</y>
+ <y>10</y>
<width>281</width>
<height>65</height>
</rect>
@@ -138,7 +71,7 @@
<property name="geometry">
<rect>
<x>210</x>
- <y>159</y>
+ <y>80</y>
<width>281</width>
<height>65</height>
</rect>
@@ -165,8 +98,8 @@
<widget class="QGroupBox" name="groupBox_3">
<property name="geometry">
<rect>
- <x>16</x>
- <y>88</y>
+ <x>10</x>
+ <y>10</y>
<width>185</width>
<height>246</height>
</rect>
@@ -183,14 +116,14 @@
<layout class="QGridLayout" name="gridLayout">
<item row="3" column="1">
<widget class="QSpinBox" name="CSVpo2">
- <property name="minimum">
- <number>1</number>
- </property>
<property name="enabled">
<bool>false</bool>
</property>
+ <property name="minimum">
+ <number>1</number>
+ </property>
<property name="value">
- <number>0</number>
+ <number>1</number>
</property>
</widget>
</item>
@@ -206,12 +139,12 @@
</item>
<item row="2" column="1">
<widget class="QSpinBox" name="CSVTemperature">
- <property name="minimum">
- <number>1</number>
- </property>
<property name="enabled">
<bool>false</bool>
</property>
+ <property name="minimum">
+ <number>1</number>
+ </property>
</widget>
</item>
<item row="1" column="0">
@@ -223,14 +156,14 @@
</item>
<item row="5" column="1">
<widget class="QSpinBox" name="CSVstopdepth">
- <property name="minimum">
- <number>1</number>
- </property>
<property name="enabled">
<bool>false</bool>
</property>
+ <property name="minimum">
+ <number>1</number>
+ </property>
<property name="value">
- <number>0</number>
+ <number>1</number>
</property>
</widget>
</item>
@@ -274,14 +207,14 @@
</item>
<item row="4" column="1">
<widget class="QSpinBox" name="CSVcns">
- <property name="minimum">
- <number>1</number>
- </property>
<property name="enabled">
<bool>false</bool>
</property>
+ <property name="minimum">
+ <number>1</number>
+ </property>
<property name="value">
- <number>0</number>
+ <number>1</number>
</property>
</widget>
</item>
diff --git a/qt-ui/mainwindow.cpp b/qt-ui/mainwindow.cpp
index c6e05faa4..cf97ca1f0 100644
--- a/qt-ui/mainwindow.cpp
+++ b/qt-ui/mainwindow.cpp
@@ -857,10 +857,24 @@ void MainWindow::loadFiles(const QStringList fileNames)
void MainWindow::on_actionImportDiveLog_triggered()
{
- DiveLogImportDialog *diveLogImport = new DiveLogImportDialog();
- diveLogImport->show();
- process_dives(TRUE, FALSE);
- refreshDisplay();
+ QStringList fileNames = QFileDialog::getOpenFileNames(this, tr("Open Dive Log File"), lastUsedDir(), tr("Dive Log Files (*.xml *.uddf *.udcf *.csv *.jlb *.dld *.sde *.db);;XML Files (*.xml);;UDDF/UDCF Files(*.uddf *.udcf);;JDiveLog Files(*.jlb);;Suunto Files(*.sde *.db);;CSV Files(*.csv);;All Files(*)"));
+
+ if (fileNames.isEmpty())
+ return;
+ updateLastUsedDir(QFileInfo(fileNames[0]).dir().path());
+
+ QStringList logFiles = fileNames.filter( QRegExp("^.*\\.(?!csv)", Qt::CaseInsensitive) ) ;
+ QStringList csvFiles = fileNames.filter(".csv", Qt::CaseInsensitive);
+ if (logFiles.size()) {
+ importFiles(logFiles);
+ }
+
+ if (csvFiles.size()) {
+ DiveLogImportDialog *diveLogImport = new DiveLogImportDialog(&csvFiles);
+ diveLogImport->show();
+ process_dives(TRUE, FALSE);
+ refreshDisplay();
+ }
}
void MainWindow::editCurrentDive()