Move ImportContext and ImportUI creation into main application.

Now all CPAP loaders have access to the unsupported/untested/brick signals
and CHECK_VALUE and UNEXPECTED_VALUE macros.

Also remove superfluous unsupported flag in MachineLoader.
This commit is contained in:
sawinglogz 2021-09-02 10:27:50 -04:00
parent 4c0677fca1
commit 08f4e2a5b7
7 changed files with 18 additions and 38 deletions

View File

@ -33,9 +33,9 @@ public:
// TODO: Isolate the Machine object from the loader rather than returning it.
virtual Machine* CreateMachineFromInfo(const MachineInfo & info) = 0;
protected:
void FlushUnexpectedMessages();
protected:
QMutex m_mutex;
QSet<QString> m_unexpectedMessages;
MachineInfo m_machineInfo;

View File

@ -733,24 +733,12 @@ int PRS1Loader::Open(const QString & selectedPath)
// open a unique device, instead of surprising the user.
int c = 0;
for (auto & machinePath : machines) {
#if 1
// TODO: Move this to the main application once all loaders support contexts and UI signals.
if (p_profile == nullptr) {
qWarning() << "PRS1Loader::Open() called without a valid p_profile object present";
if (m_ctx == nullptr) {
qWarning() << "PRS1Loader::Open() called without a valid m_ctx object present";
return 0;
}
ImportUI ui(p_profile);
ImportContext* ctx = new ProfileImportContext(p_profile);
SetContext(ctx);
connect(ctx, &ImportContext::importEncounteredUnexpectedData, &ui, &ImportUI::onUnexpectedData);
connect(this, &MachineLoader::deviceReportsUsageOnly, &ui, &ImportUI::onDeviceReportsUsageOnly);
connect(this, &MachineLoader::deviceIsUntested, &ui, &ImportUI::onDeviceIsUntested);
connect(this, &MachineLoader::deviceIsUnsupported, &ui, &ImportUI::onDeviceIsUnsupported);
#endif
c += OpenMachine(machinePath);
#if 1
delete ctx;
#endif
m_ctx->FlushUnexpectedMessages();
}
return c;
}
@ -780,6 +768,7 @@ int PRS1Loader::OpenMachine(const QString & path)
Machine *m = CreateMachineFromProperties(propertyfile);
if (m == nullptr) {
// Device is unsupported.
return -1;
}
@ -810,7 +799,7 @@ int PRS1Loader::OpenMachine(const QString & path)
finishAddingSessions();
return m->unsupported() ? -1 : tasks;
return tasks;
}
@ -2506,9 +2495,6 @@ void PRS1Import::ImportWaveforms()
void PRS1Import::run()
{
if (mach->unsupported())
return;
if (ParseSession()) {
SaveSessionToDatabase();
}

View File

@ -87,7 +87,6 @@ Machine::Machine(Profile *_profile, MachineID id) : profile(_profile)
{
day.clear();
highest_sessionid = 0;
m_unsupported = false;
m_suppressUntestedWarning = false;
// TODO: Have the machine write m_suppressUntestedWarning and m_previousUnexpected
// to XML (along with the current OSCAR version number) so that they persist across

View File

@ -177,8 +177,6 @@ class Machine
bool hasModifiedSessions();
bool unsupported() { return m_unsupported; }
void setUnsupported(bool b) { m_unsupported = b; }
bool warnOnUntested() { return m_suppressUntestedWarning == false; }
void suppressWarnOnUntested() { m_suppressUntestedWarning = true; }
QSet<QString> & previouslySeenUnexpectedData() { return m_previousUnexpected; }
@ -252,7 +250,6 @@ class Machine
// Public Data Members follow
MachineInfo info;
bool m_unsupported;
bool m_suppressUntestedWarning;
QSet<QString> m_previousUnexpected;

View File

@ -38,17 +38,6 @@ MachineLoader::~MachineLoader()
{
}
void MachineLoader::unsupported(Machine * m)
{
if (m == nullptr) {
qCritical("MachineLoader::unsupported(Machine *) called with null machine object");
return;
}
m->setUnsupported(true);
emit machineUnsupported(m);
}
void MachineLoader::addSession(Session * sess)
{
sessionMutex.lock();

View File

@ -82,8 +82,6 @@ class MachineLoader: public QObject
virtual void initChannels() {}
void unsupported(Machine * m);
void addSession(Session * sess);
inline MachineType type() { return m_type; }
@ -112,7 +110,6 @@ signals:
void setProgressMax(int max);
void setProgressValue(int val);
void updateMessage(QString);
void machineUnsupported(Machine *);
void deviceReportsUsageOnly(MachineInfo & info);
void deviceIsUntested(MachineInfo & info);

View File

@ -59,6 +59,7 @@
#include "checkupdates.h"
#include "SleepLib/calcs.h"
#include "SleepLib/progressdialog.h"
#include "SleepLib/importcontext.h"
#include "reports.h"
#include "statistics.h"
@ -721,8 +722,19 @@ int MainWindow::importCPAP(ImportPath import, const QString &message)
connect(import.loader, SIGNAL(setProgressValue(int)), progdlg, SLOT(setProgressValue(int)));
connect(progdlg, SIGNAL(abortClicked()), import.loader, SLOT(abortImport()));
ImportUI importui(p_profile);
ImportContext* ctx = new ProfileImportContext(p_profile);
import.loader->SetContext(ctx);
connect(ctx, &ImportContext::importEncounteredUnexpectedData, &importui, &ImportUI::onUnexpectedData);
connect(import.loader, &MachineLoader::deviceReportsUsageOnly, &importui, &ImportUI::onDeviceReportsUsageOnly);
connect(import.loader, &MachineLoader::deviceIsUntested, &importui, &ImportUI::onDeviceIsUntested);
connect(import.loader, &MachineLoader::deviceIsUnsupported, &importui, &ImportUI::onDeviceIsUnsupported);
int c = import.loader->Open(import.path);
import.loader->SetContext(nullptr);
delete ctx;
if (c > 0) {
Notify(tr("Imported %1 CPAP session(s) from\n\n%2").arg(c).arg(import.path), tr("Import Success"));
} else if (c == 0) {