From 36d3467a644513e7d8c4c8a86a823926af74abc3 Mon Sep 17 00:00:00 2001 From: sawinglogz <3787776-sawinglogz@users.noreply.gitlab.com> Date: Tue, 21 Jan 2020 11:56:22 -0500 Subject: [PATCH] Refactor on_action_Import_Data_triggered into multiple functions. No change in behavior. --- oscar/mainwindow.cpp | 34 +++++++++++++++++++++++++--------- oscar/mainwindow.h | 2 ++ 2 files changed, 27 insertions(+), 9 deletions(-) diff --git a/oscar/mainwindow.cpp b/oscar/mainwindow.cpp index ce8a6e9b..f3695776 100644 --- a/oscar/mainwindow.cpp +++ b/oscar/mainwindow.cpp @@ -907,11 +907,22 @@ void MainWindow::on_action_Import_Data_triggered() ui->tabWidget->setCurrentWidget(welcome); QApplication::processEvents(); + QList datacards = selectCPAPDataCards(tr("Would you like to import from this location?")); + if (datacards.size() > 0) { + importCPAPDataCards(datacards); + } + + in_import=false; +} + + +QList MainWindow::selectCPAPDataCards(const QString & /*prompt*/) +{ QList datacards = detectCPAPCards(); if (importScanCancelled) { - in_import = false; - return; + datacards.clear(); + return datacards; } QListloaders = GetLoaders(MT_CPAP); @@ -948,8 +959,8 @@ void MainWindow::on_action_Import_Data_triggered() if (res == QMessageBox::Cancel) { // Give the communal progress bar back - in_import=false; - return; + datacards.clear(); + return datacards; } else if (res == QMessageBox::No) { //waitmsg->setText(tr("Please wait, launching file dialog...")); datacards.clear(); @@ -972,6 +983,7 @@ void MainWindow::on_action_Import_Data_triggered() if (p_profile->contains(STR_PREF_LastCPAPPath)) { folder = (*p_profile)[STR_PREF_LastCPAPPath].toString(); } else { + // TODO: Is a writable path really the best place to direct the user to find their SD card data? folder = QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation); } @@ -1006,9 +1018,8 @@ void MainWindow::on_action_Import_Data_triggered() //#endif if (w.exec() != QDialog::Accepted) { - in_import=false; - - return; + datacards.clear(); + return datacards; } @@ -1021,7 +1032,13 @@ void MainWindow::on_action_Import_Data_triggered() } } } + + return datacards; +} + +void MainWindow::importCPAPDataCards(const QList & datacards) +{ bool newdata = false; // QStringList goodlocations; @@ -1074,10 +1091,9 @@ void MainWindow::on_action_Import_Data_triggered() prog->close(); prog->deleteLater(); - in_import=false; - } + QMenu *MainWindow::CreateMenu(QString title) { QMenu *menu = new QMenu(title, ui->menubar); diff --git a/oscar/mainwindow.h b/oscar/mainwindow.h index db5f4da0..df663f6d 100644 --- a/oscar/mainwindow.h +++ b/oscar/mainwindow.h @@ -356,6 +356,8 @@ private: void importCPAPBackups(); void finishCPAPImport(); QList detectCPAPCards(); + QList selectCPAPDataCards(const QString & prompt); + void importCPAPDataCards(const QList & datacards); // QString getWelcomeHTML(); void FreeSessions();