From a1e011da4d9131df482db2f67d3006cca24e6ac7 Mon Sep 17 00:00:00 2001 From: kappa44 <6469032-kappa44@users.noreply.gitlab.com> Date: Mon, 22 Feb 2021 09:30:24 +1100 Subject: [PATCH] Support multi-file imports for Somnopose --- oscar/mainwindow.cpp | 40 +++++++++++++++++++++++++++++++++++----- 1 file changed, 35 insertions(+), 5 deletions(-) diff --git a/oscar/mainwindow.cpp b/oscar/mainwindow.cpp index 0393f405..390fed99 100644 --- a/oscar/mainwindow.cpp +++ b/oscar/mainwindow.cpp @@ -2394,16 +2394,46 @@ void MainWindow::on_actionImport_Somnopose_Data_triggered() w.setNameFilters(QStringList("Somnopause CSV File (*.csv)")); SomnoposeLoader somno; + // Display progress if we have more than 1 file to load... + ProgressDialog progress(this); if (w.exec() == QFileDialog::Accepted) { - QString filename = w.selectedFiles()[0]; + int i, skipped = 0; + int size = w.selectedFiles().size(); + if (size > 1) { + progress.setMessage(QObject::tr("Importing Sessions...")); + progress.setProgressMax(size); + progress.setProgressValue(0); + progress.setWindowModality(Qt::ApplicationModal); + progress.open(); + QCoreApplication::processEvents(); + } + for (i=0; i < size; i++) { + QString filename = w.selectedFiles()[i]; - if (!somno.OpenFile(filename)) { - Notify(tr("There was a problem opening Somnopose Data File: ") + filename); - return; + int res = somno.OpenFile(filename); + if (!res) { + if (i == 0) { + Notify(tr("There was a problem opening Somnopose Data File: ") + filename); + return; + } else { + Notify(tr("Somnopause Data Import of %1 file(s) complete").arg(i) + "\n\n" + + tr("There was a problem opening Somnopose Data File: ") + filename, + tr("Somnopose Import Partial Success")); + break; + } + } + if (res < 0) { + // Should we report on skipped count? + skipped++; + } + progress.setProgressValue(i+1); + QCoreApplication::processEvents(); } - Notify(tr("Somnopause Data Import complete")); + if (i == size) { + Notify(tr("Somnopause Data Import complete")); + } PopulatePurgeMenu(); if (overview) overview->ReloadGraphs(); if (welcome) welcome->refreshPage();