Make ResMed & PRS1 importer check ignoreOlderSessions, make import progress dialog modal

This commit is contained in:
Mark Watkins 2018-05-07 11:30:42 +10:00
parent adf6f1917d
commit c4ac37d4ae
6 changed files with 42 additions and 13 deletions

View File

@ -431,6 +431,7 @@ int PRS1Loader::Open(const QString & dirpath)
c += OpenMachine(newpath + "/" + *sn); c += OpenMachine(newpath + "/" + *sn);
} }
} }
// Serial numbers that don't start with a letter.
for (sn = SerialNumbers.begin(); sn != SerialNumbers.end(); sn++) { for (sn = SerialNumbers.begin(); sn != SerialNumbers.end(); sn++) {
if (!(*sn)[0].isLetter()) { if (!(*sn)[0].isLetter()) {
c += OpenMachine(newpath + "/" + *sn); c += OpenMachine(newpath + "/" + *sn);
@ -632,6 +633,11 @@ int PRS1Loader::OpenMachine(const QString & path)
emit updateMessage(QObject::tr("Scanning Files...")); emit updateMessage(QObject::tr("Scanning Files..."));
QCoreApplication::processEvents(); QCoreApplication::processEvents();
QDateTime datetime;
QDateTime ignoreBefore = p_profile->session->ignoreOlderSessionsDate();
bool ignoreOldSessions = p_profile->session->ignoreOlderSessions();
// for each p0/p1/p2/etc... folder // for each p0/p1/p2/etc... folder
for (int p=0; p < size; ++p) { for (int p=0; p < size; ++p) {
dir.setPath(paths.at(p)); dir.setPath(paths.at(p));
@ -658,6 +664,14 @@ int PRS1Loader::OpenMachine(const QString & path)
continue; continue;
} }
if (ignoreOldSessions) {
datetime = QDateTime::fromTime_t(sid);
if (datetime < ignoreBefore) {
continue;
}
}
if (m->SessionExists(sid)) { if (m->SessionExists(sid)) {
// Skip already imported session // Skip already imported session
continue; continue;

View File

@ -118,6 +118,9 @@ void ResmedLoader::ParseSTR(Machine *mach, QMap<QDate, STRFile> & STRmap)
return; return;
} }
QDateTime ignoreBefore = p_profile->session->ignoreOlderSessionsDate();
bool ignoreOldSessions = p_profile->session->ignoreOlderSessions();
for (auto it=STRmap.begin(), end=STRmap.end(); it != end; ++it) { for (auto it=STRmap.begin(), end=STRmap.end(); it != end; ++it) {
STRFile & file = it.value(); STRFile & file = it.value();
QString & strfile = file.filename; QString & strfile = file.filename;
@ -144,6 +147,11 @@ void ResmedLoader::ParseSTR(Machine *mach, QMap<QDate, STRFile> & STRmap)
// For each data record, representing 1 day each // For each data record, representing 1 day each
for (int rec = 0; rec < size; ++rec, date = date.addDays(1)) { for (int rec = 0; rec < size; ++rec, date = date.addDays(1)) {
if (ignoreOldSessions) {
if (date < ignoreBefore.date()) {
continue;
}
}
auto rit = resdayList.find(date); auto rit = resdayList.find(date);
if (rit != resdayList.end()) { if (rit != resdayList.end()) {
@ -1441,6 +1449,8 @@ int ResmedLoader::scanFiles(Machine * mach, const QString & datalog_path)
int cnt = 0; int cnt = 0;
// Scan through all folders looking for EDF files, skip any already imported and peek inside to get durations // Scan through all folders looking for EDF files, skip any already imported and peek inside to get durations
QDateTime ignoreBefore = p_profile->session->ignoreOlderSessionsDate();
bool ignoreOldSessions = p_profile->session->ignoreOlderSessions();
qDebug() << "Starting EDF duration scan pass"; qDebug() << "Starting EDF duration scan pass";
for (int i=0; i < totalfiles; ++i) { for (int i=0; i < totalfiles; ++i) {
@ -1468,6 +1478,11 @@ int ResmedLoader::scanFiles(Machine * mach, const QString & datalog_path)
date = date.addDays(-1); date = date.addDays(-1);
} }
if (ignoreOldSessions) {
if (date < ignoreBefore.date())
continue;
}
// Chop off the .gz component if it exists, it's not needed at this stage // Chop off the .gz component if it exists, it's not needed at this stage
if (filename.endsWith(STR_ext_gz)) { if (filename.endsWith(STR_ext_gz)) {
filename.chop(3); filename.chop(3);

View File

@ -234,8 +234,6 @@ bool Machine::AddSession(Session *s)
return false; return false;
} }
updateChannels(s);
if (p_profile->session->ignoreOlderSessions()) { if (p_profile->session->ignoreOlderSessions()) {
qint64 ignorebefore = p_profile->session->ignoreOlderSessionsDate().toMSecsSinceEpoch(); qint64 ignorebefore = p_profile->session->ignoreOlderSessionsDate().toMSecsSinceEpoch();
if (s->last() < ignorebefore) { if (s->last() < ignorebefore) {
@ -244,6 +242,9 @@ bool Machine::AddSession(Session *s)
} }
} }
updateChannels(s);
if (s->session() > highest_sessionid) { if (s->session() > highest_sessionid) {
highest_sessionid = s->session(); highest_sessionid = s->session();
} }

View File

@ -219,10 +219,10 @@ void MachineLoader::runTasks(bool threaded)
ImportTask * task = m_tasklist.takeFirst(); ImportTask * task = m_tasklist.takeFirst();
task->run(); task->run();
if ((m_currenttask++ % 10)==0) { // update progress bar
qprogress->setValue(m_currenttask); m_currenttask++;
QApplication::processEvents(); qprogress->setValue(m_currenttask);
} QApplication::processEvents();
} }
} else { } else {
ImportTask * task = m_tasklist[0]; ImportTask * task = m_tasklist[0];
@ -239,10 +239,9 @@ void MachineLoader::runTasks(bool threaded)
task = m_tasklist[0]; task = m_tasklist[0];
// update progress bar // update progress bar
if ((m_currenttask++ % 10) == 0) { m_currenttask++;
qprogress->setValue(m_currenttask); qprogress->setValue(m_currenttask);
QApplication::processEvents(); QApplication::processEvents();
}
} else { } else {
// job list finished // job list finished
break; break;

View File

@ -9,7 +9,7 @@
#include "progressdialog.h" #include "progressdialog.h"
ProgressDialog::ProgressDialog(QWidget * parent): ProgressDialog::ProgressDialog(QWidget * parent):
QDialog(parent, Qt::Popup) QDialog(parent, Qt::Tool | Qt::FramelessWindowHint)
{ {
waitmsg = new QLabel(QObject::tr("PLease Wait...")); waitmsg = new QLabel(QObject::tr("PLease Wait..."));
hlayout = new QHBoxLayout; hlayout = new QHBoxLayout;

View File

@ -567,10 +567,10 @@ int MainWindow::importCPAP(ImportPath import, const QString &message)
QProgressBar *saveQprogress = qprogress; QProgressBar *saveQprogress = qprogress;
qprogress = progdlg->progress; qprogress = progdlg->progress;
progdlg->show(); progdlg->setWindowModality(Qt::ApplicationModal);
progdlg->open();
progdlg->setMessage(message); progdlg->setMessage(message);
import.loader->setParent(this);
connect(import.loader, SIGNAL(updateMessage(QString)), progdlg, SLOT(setMessage(QString))); connect(import.loader, SIGNAL(updateMessage(QString)), progdlg, SLOT(setMessage(QString)));
int c = import.loader->Open(import.path); int c = import.loader->Open(import.path);