diff --git a/sleepyhead/SleepLib/loader_plugins/prs1_loader.cpp b/sleepyhead/SleepLib/loader_plugins/prs1_loader.cpp index 18971014..883b1074 100644 --- a/sleepyhead/SleepLib/loader_plugins/prs1_loader.cpp +++ b/sleepyhead/SleepLib/loader_plugins/prs1_loader.cpp @@ -513,6 +513,9 @@ int PRS1Loader::OpenMachine(const QString & path) return 0; } + emit updateMessage(QObject::tr("Getting Ready...")); + QCoreApplication::processEvents(); + dir.setFilter(QDir::NoDotAndDotDot | QDir::Dirs | QDir::Files | QDir::Hidden | QDir::NoSymLinks); dir.setSorting(QDir::Name); QFileInfoList flist = dir.entryInfoList(); @@ -626,6 +629,9 @@ int PRS1Loader::OpenMachine(const QString & path) PRS1Import * task = nullptr; // Note, I have observed p0/p1/etc folders containing duplicates session files (in Robin Sanders data.) + emit updateMessage(QObject::tr("Scanning Files...")); + QCoreApplication::processEvents(); + // for each p0/p1/p2/etc... folder for (int p=0; p < size; ++p) { dir.setPath(paths.at(p)); @@ -738,7 +744,14 @@ int PRS1Loader::OpenMachine(const QString & path) int tasks = countTasks(); unknownCodes.clear(); + emit updateMessage(QObject::tr("Importing Sessions...")); + QCoreApplication::processEvents(); + runTasks(AppSetting->multithreading()); + + emit updateMessage(QObject::tr("Finishing up...")); + QCoreApplication::processEvents(); + finishAddingSessions(); if (unknownCodes.size() > 0) { diff --git a/sleepyhead/SleepLib/loader_plugins/resmed_loader.cpp b/sleepyhead/SleepLib/loader_plugins/resmed_loader.cpp index 7c170a61..14b04334 100644 --- a/sleepyhead/SleepLib/loader_plugins/resmed_loader.cpp +++ b/sleepyhead/SleepLib/loader_plugins/resmed_loader.cpp @@ -2301,6 +2301,9 @@ int ResmedLoader::Open(const QString & dirpath) } MachineInfo info = newInfo(); + emit updateMessage(QObject::tr("Parsing Identification File")); + QApplication::processEvents(); + // Parse # entries into idmap. while (!f.atEnd()) { line = f.readLine().trimmed(); @@ -2397,7 +2400,11 @@ int ResmedLoader::Open(const QString & dirpath) resdayList.clear(); + emit updateMessage(QObject::tr("Locating STR.edf File(s)...")); + QCoreApplication::processEvents(); + // List all STR.edf backups and tag on latest for processing + QMap STRmap; QDir dir; @@ -2528,6 +2535,9 @@ int ResmedLoader::Open(const QString & dirpath) /////////////////////////////////////////////////////////////////////////////////// // Build a Date map of all records in STR.edf files, populating ResDayList /////////////////////////////////////////////////////////////////////////////////// + emit updateMessage(QObject::tr("Processing STR.edf File(s)...")); + QApplication::processEvents(); + ParseSTR(mach, STRmap); // We are done with the Parsed STR EDF objects, so delete them @@ -2567,11 +2577,17 @@ int ResmedLoader::Open(const QString & dirpath) QFile impfile(mach->getDataPath()+"/imported_files.csv"); if (impfile.exists()) impfile.remove(); + emit updateMessage(QObject::tr("Searching for EDF Files...")); + QApplication::processEvents(); + scanFiles(mach, newpath); // Now at this point we have resdayList populated with processable summary and EDF files data // that can be processed in threads.. + emit updateMessage(QObject::tr("Queing Import Jobs...")); + QApplication::processEvents(); + for (auto rdi=resdayList.begin(), rend=resdayList.end(); rdi != rend; rdi++) { QDate date = rdi.key(); @@ -2619,6 +2635,7 @@ int ResmedLoader::Open(const QString & dirpath) } sessionCount = 0; + emit updateMessage(QObject::tr("Importing Sessions...")); runTasks(); int num_new_sessions = sessionCount; @@ -2627,6 +2644,8 @@ int ResmedLoader::Open(const QString & dirpath) // Now look for any new summary data that can be extracted from STR.edf records //////////////////////////////////////////////////////////////////////////////////// + emit updateMessage(QObject::tr("Finishing Up...")); + QApplication::processEvents(); //int size = m->sessionlist.size(); //int cnt=0; diff --git a/sleepyhead/SleepLib/loader_plugins/resmed_loader.h b/sleepyhead/SleepLib/loader_plugins/resmed_loader.h index 7097483c..a3d1de2e 100644 --- a/sleepyhead/SleepLib/loader_plugins/resmed_loader.h +++ b/sleepyhead/SleepLib/loader_plugins/resmed_loader.h @@ -375,6 +375,7 @@ protected: */ class ResmedLoader : public CPAPLoader { + Q_OBJECT friend class ResmedImport; friend class ResmedImportStage2; public: diff --git a/sleepyhead/SleepLib/machine.cpp b/sleepyhead/SleepLib/machine.cpp index b07c7487..c27b9dd3 100644 --- a/sleepyhead/SleepLib/machine.cpp +++ b/sleepyhead/SleepLib/machine.cpp @@ -606,12 +606,14 @@ bool Machine::Load() QPixmap image = getPixmap().scaled(64,64); popup->setPixmap(image); - popup->setMessage(QObject::tr("Loading %1 data...").arg(info.brand)); + popup->setMessage(QObject::tr("Loading %1 data for %2...").arg(info.brand).arg(p_profile->user->userName())); popup->show(); - QProgressBar * progress = popup->progress; + QProgressBar * saveQProgress = qprogress; - if (!LoadSummary(progress)) { + qprogress = popup->progress; + + if (!LoadSummary(qprogress)) { // No XML index file, so assume upgrading, or it simply just got screwed up or deleted... QTime time; time.start(); @@ -631,17 +633,15 @@ bool Machine::Load() QStringList filelist = dir.entryList(); int size = filelist.size(); - if (progress) { - progress->setMinimum(0); - progress->setMaximum(0); - progress->setValue(0); + if (qprogress) { + qprogress->setMinimum(0); + qprogress->setValue(0); QApplication::processEvents(); } - for (int i=0; i < size; i++) { - QString filename = filelist.at(i); - QFile::copy(path+filename, summarypath+filename); - QFile::remove(path+filename); + // Legacy crap.. Summary and Event stuff used to be in one big pile in the machine folder root + for (auto & filename : filelist) { + QFile::rename(path+filename, summarypath+filename); } // Copy old Event files to folder @@ -654,14 +654,13 @@ bool Machine::Load() if (!dir.exists(eventpath)) dir.mkpath(eventpath); for (int i=0; i< size; i++) { if ((i % 50) == 0) { // This is slow.. :-/ - if (progress) { progress->setValue((float(i) / float(size) * 100.0)); } + if (qprogress) { qprogress->setValue((float(i) / float(size) * 100.0)); } QApplication::processEvents(); } QString filename = filelist.at(i); - QFile::copy(path+filename, eventpath+filename); - QFile::remove(path+filename); + QFile::rename(path+filename, eventpath+filename); } } @@ -675,10 +674,10 @@ bool Machine::Load() filelist = dir.entryList(); size = filelist.size(); - if (progress) { - progress->setMinimum(0); - progress->setMaximum(size); - progress->setValue(0); + if (qprogress) { + qprogress->setMinimum(0); + qprogress->setMaximum(size); + qprogress->setValue(0); QApplication::processEvents(); } @@ -689,7 +688,7 @@ bool Machine::Load() for (int i=0; i < size; i++) { if ((i % 50) == 0) { // This is slow.. :-/ - if (progress) { progress->setValue(i); } + if (qprogress) { qprogress->setValue(i); } QApplication::processEvents(); } @@ -713,15 +712,17 @@ bool Machine::Load() SaveSummary(); qDebug() << "Loaded" << info.model << "data in" << time.elapsed() << "ms"; - if (progress) { progress->setValue(size); } + if (qprogress) { qprogress->setValue(size); } } else { - if (progress) { progress->setValue(100); } + if (qprogress) { qprogress->setValue(100); } } loadSessionInfo(); QApplication::processEvents(); popup->hide(); delete popup; + qprogress = saveQProgress; + return true; } @@ -893,16 +894,15 @@ void Machine::runTasks() return; QThreadPool * threadpool = QThreadPool::globalInstance(); - // int m_totaltasks=m_tasklist.size(); + int m_totaltasks=m_tasklist.size(); int m_currenttask=0; + qprogress->setMaximum(m_totaltasks); while (!m_tasklist.isEmpty()) { if (threadpool->tryStart(m_tasklist.at(0))) { m_tasklist.pop_front(); - // float f = float(m_currenttask) / float(m_totaltasks) * 100.0; - // qprogress->setValue(f); - m_currenttask++; + qprogress->setValue(m_currenttask++); + QApplication::processEvents(); } - //QApplication::processEvents(); } QThreadPool::globalInstance()->waitForDone(-1); diff --git a/sleepyhead/SleepLib/machine_loader.h b/sleepyhead/SleepLib/machine_loader.h index 73b53902..175730f6 100644 --- a/sleepyhead/SleepLib/machine_loader.h +++ b/sleepyhead/SleepLib/machine_loader.h @@ -109,6 +109,7 @@ class MachineLoader: public QObject signals: void updateProgress(int cnt, int total); + void updateMessage(QString); void machineUnsupported(Machine *); protected: @@ -151,6 +152,7 @@ public: virtual ChannelID HumidifierLevel() { return CPAP_HumidSetting; } virtual ChannelID CPAPModeChannel() { return CPAP_Mode; } virtual void initChannels() {} + }; struct ImportPath diff --git a/sleepyhead/SleepLib/progressdialog.cpp b/sleepyhead/SleepLib/progressdialog.cpp index 3902cb27..be624a1f 100644 --- a/sleepyhead/SleepLib/progressdialog.cpp +++ b/sleepyhead/SleepLib/progressdialog.cpp @@ -1,4 +1,4 @@ -/* SleepLib Progress Dialog Header +/* SleepLib Progress Dialog Header * * Copyright (c) 2011-2018 Mark Watkins * @@ -9,7 +9,7 @@ #include "progressdialog.h" ProgressDialog::ProgressDialog(QWidget * parent): - QDialog(parent, Qt::SplashScreen) + QDialog(parent, Qt::Popup) { waitmsg = new QLabel(QObject::tr("PLease Wait...")); hlayout = new QHBoxLayout; @@ -36,3 +36,7 @@ void ProgressDialog::doUpdateProgress(int cnt, int total) progress->setValue(cnt); } + +void ProgressDialog::setMessage(QString msg) { + waitmsg->setText(msg); update(); +} diff --git a/sleepyhead/SleepLib/progressdialog.h b/sleepyhead/SleepLib/progressdialog.h index a3e6a2d6..d2ec5f5b 100644 --- a/sleepyhead/SleepLib/progressdialog.h +++ b/sleepyhead/SleepLib/progressdialog.h @@ -1,4 +1,4 @@ -/* SleepLib Progress Dialog Header +/* SleepLib Progress Dialog Header * * Copyright (C) 2011-2018 Mark Watkins * @@ -16,14 +16,15 @@ #include class ProgressDialog:public QDialog { +Q_OBJECT public: explicit ProgressDialog(QWidget * parent); virtual ~ProgressDialog(); - void setMessage(QString msg) { waitmsg->setText(msg); } void setPixmap(QPixmap &pixmap) { imglabel->setPixmap(pixmap); } QProgressBar * progress; public slots: + void setMessage(QString msg); void doUpdateProgress(int cnt, int total); protected: diff --git a/sleepyhead/mainwindow.cpp b/sleepyhead/mainwindow.cpp index bf615964..72fe8b8c 100644 --- a/sleepyhead/mainwindow.cpp +++ b/sleepyhead/mainwindow.cpp @@ -463,13 +463,12 @@ void MainWindow::OpenProfile(QString profileName) p_profile->p_preferences[STR_PREF_ReimportBackup]=false; } - p_profile->LoadMachineData(); - QList loaders = GetLoaders(); for (int i=0; iLoadMachineData(); ui->statStartDate->setDate(p_profile->FirstDay()); ui->statEndDate->setDate(p_profile->LastDay()); @@ -536,7 +535,9 @@ void MainWindow::CloseProfile() void MainWindow::Startup() { - + for (auto & loader : GetLoaders()) { + loader->setParent(this); + } QString lastProfile = AppSetting->profileName(); if (Profiles::profiles.contains(lastProfile) && AppSetting->autoOpenLastUsed()) { @@ -557,27 +558,21 @@ int MainWindow::importCPAP(ImportPath import, const QString &message) return 0; } - QDialog * popup = new QDialog(this); - QLabel * waitmsg = new QLabel(message); - QHBoxLayout *hlayout = new QHBoxLayout; - - QLabel * imglabel = new QLabel(popup); + ProgressDialog * progdlg = new ProgressDialog(this); QPixmap image = import.loader->getPixmap(import.loader->PeekInfo(import.path).series); -// QPixmap image(getCPAPPixmap(import.loader->loaderName())); image = image.scaled(64,64); - imglabel->setPixmap(image); + progdlg->setPixmap(image); + QProgressBar *saveQprogress = qprogress; + qprogress = progdlg->progress; - QVBoxLayout * vlayout = new QVBoxLayout; - popup->setLayout(vlayout); - vlayout->addLayout(hlayout); - hlayout->addWidget(imglabel); - hlayout->addWidget(waitmsg,1,Qt::AlignCenter); - vlayout->addWidget(qprogress,1); + progdlg->show(); + progdlg->setMessage(message); + + import.loader->setParent(this); + connect(import.loader, SIGNAL(updateMessage(QString)), progdlg, SLOT(setMessage(QString))); - qprogress->setVisible(true); - popup->show(); int c = import.loader->Open(import.path); if (c > 0) { @@ -587,17 +582,17 @@ int MainWindow::importCPAP(ImportPath import, const QString &message) } else { Notify(tr("Couldn't find any valid Machine Data at\n\n%1").arg(import.path),tr("Import Problem")); } + disconnect(import.loader, SIGNAL(updateMessage(QString)), progdlg, SLOT(setMessage(QString))); - popup->hide(); - vlayout->removeWidget(qprogress); - ui->statusbar->insertWidget(1,qprogress,1); - qprogress->setVisible(false); + progdlg->hide(); + + delete progdlg; - delete popup; if (AppSetting->openTabAfterImport()>0) { ui->tabWidget->setCurrentIndex(AppSetting->openTabAfterImport()); } + qprogress=saveQprogress; return c; }