diff --git a/oscar/SleepLib/loader_plugins/resmed_loader.cpp b/oscar/SleepLib/loader_plugins/resmed_loader.cpp index 131e38c5..78347c8b 100644 --- a/oscar/SleepLib/loader_plugins/resmed_loader.cpp +++ b/oscar/SleepLib/loader_plugins/resmed_loader.cpp @@ -335,8 +335,9 @@ int ResmedLoader::Open(const QString & dirpath) if ( mach ) { // we have seen this machine qDebug() << "We have seen this machime"; mach->setInfo( info ); // update info -// QDate lastDate = p_profile->LastDay(MT_CPAP); -// firstImportDay = lastDate.addDays(-1); + QDate lastDate = mach->LastDay(); // use the last day for this machine +// firstImportDay = lastDate.addDays(-1); // start the day before, to pick up partial days + firstImportDay = lastDate.addDays(1); // start the day after until we figure out the purge } else { // Starting from new beginnings - new or purged qDebug() << "New machine or just purged"; p_profile->forceResmedPrefs(); @@ -421,9 +422,9 @@ int ResmedLoader::Open(const QString & dirpath) QDate date = stredf->edfHdr.startdate_orig.date(); long int days = stredf->GetNumDataRecords(); qDebug() << importFile.section("/",-2,-1) << "starts at" << date << "for" << days << "ends" << date.addDays(days-1); - if (STRmap.contains(date)) { // Keep the longer of the two STR files + if (STRmap.contains(date)) { // Keep the longer of the two STR files - or newer if equal! qDebug() << importFile.section("/",-3,-1) << "overlaps" << STRmap[date].filename.section("/",-3,-1) << "for" << days << "ends" << date.addDays(days-1); - if (days > STRmap[date].days) { + if (days >= STRmap[date].days) { qDebug() << "Removing" << STRmap[date].filename.section("/",-3,-1) << "with" << STRmap[date].days; STRmap.remove(date); } else { @@ -1021,7 +1022,7 @@ bool ResmedLoader::ProcessSTRfiles(Machine *mach, QMap & STRmap, maskoff = str.lookupLabel("MaskOff"); } EDFSignal *maskeventcount = str.lookupLabel("Mask Events"); - if (!maskeventcount) { + if ( ! maskeventcount) { maskeventcount = str.lookupLabel("MaskEvents"); } if ( !maskon || !maskoff || !maskeventcount ) { @@ -1049,13 +1050,13 @@ bool ResmedLoader::ProcessSTRfiles(Machine *mach, QMap & STRmap, if (rit != resdayList.end()) { // Already seen this record.. should check if the data is the same, but meh. // At least check the maskeventcount to see if it changed... -// if ( maskeventcount* != rit...maskevents ) { -// qDebug() << "Maske events don't match, purge" << rit...date().toString; + if ( maskeventcount->dataArray[0] != rit.value().str.maskevents ) { + qDebug() << "Maske events don't match, purge" << rit.value().date.toString(); // purge... -// } -#ifdef SESSION_DEBUG + } +// #ifdef SESSION_DEBUG qDebug() << "Skipping" << date.toString() << "Already saw this one"; -#endif +// #endif continue; } diff --git a/oscar/SleepLib/machine.cpp b/oscar/SleepLib/machine.cpp index 9c128c27..09be5b59 100644 --- a/oscar/SleepLib/machine.cpp +++ b/oscar/SleepLib/machine.cpp @@ -186,7 +186,7 @@ bool Machine::loadSessionInfo() QHash::iterator s; QFile file(getDataPath() + "Sessions.info"); - if (!file.open(QFile::ReadOnly)) { + if ( ! file.open(QFile::ReadOnly)) { // No session.info file present, so let's create one... // But first check for legacy SESSION_ENABLED field in session settings @@ -391,7 +391,7 @@ bool Machine::AddSession(Session *s) return true; } - if (!firstsession) { + if ( ! firstsession) { if (firstday > date) { firstday = date; } if (lastday < date) { lastday = date; } @@ -687,7 +687,8 @@ bool Machine::Load(ProgressDialog *progress) mainwin->connect(loader(), SIGNAL(setProgressValue(int)), progress, SLOT(setProgressValue(int))); } - if (!LoadSummary(progress)) { + if ( ! LoadSummary(progress)) { + qDebug() << "Recreating the Summary index XML file"; // No XML index file, so assume upgrading, or it simply just got screwed up or deleted... progress->setMessage(QObject::tr("Scanning Files")); progress->setProgressValue(0); @@ -751,6 +752,7 @@ bool Machine::Load(ProgressDialog *progress) size = filelist.size(); progress->setMessage("Reading summary files"); + qDebug() << "Reading summary files (.000)"; progress->setProgressValue(0); QApplication::processEvents(); @@ -787,6 +789,7 @@ bool Machine::Load(ProgressDialog *progress) progress->setProgressValue(size); } progress->setMessage("Loading Session Info"); + qDebug() << "Loading Session Info"; QApplication::processEvents(); loadSessionInfo(); @@ -804,7 +807,9 @@ bool Machine::SaveSession(Session *sess) { QString path = getDataPath(); - if (sess->IsChanged() && sess->first() != 0) { sess->Store(path); } + if (sess->IsChanged() && sess->first() != 0) { + sess->Store(path); + } return true; } @@ -1004,7 +1009,7 @@ bool Machine::LoadSummary(ProgressDialog * progress) // } *****************************************************************/ Session * sess = it.value(); - if (!AddSession(sess)) { + if ( ! AddSession(sess)) { delete sess; } else { if (loadSummaries) { @@ -1018,6 +1023,7 @@ bool Machine::LoadSummary(ProgressDialog * progress) } } progress->setMessage(QObject::tr("Loading Summary Data")); + qDebug() << "Loading Summary Data"; QApplication::processEvents(); if (loader()) { diff --git a/oscar/SleepLib/profiles.cpp b/oscar/SleepLib/profiles.cpp index 41c40323..e9b58a21 100644 --- a/oscar/SleepLib/profiles.cpp +++ b/oscar/SleepLib/profiles.cpp @@ -630,7 +630,7 @@ void Profile::LoadMachineData(ProgressDialog *progress) if (loader) { if (mach->version() < loader->Version()) { - qDebug() << "LoadMachineData data format error, machine version" << mach->version() << "loader version" << loader->Version(); + qDebug() << "LoadMachineData" << mach->loaderName() << "data format error, machine version" << mach->version() << "loader version" << loader->Version(); progress->hide(); DataFormatError(mach); progress->show(); @@ -638,7 +638,7 @@ void Profile::LoadMachineData(ProgressDialog *progress) try { mach->Load(progress); } catch (OldDBVersion& e) { - qDebug() << "LoadMachineData mach->load failure, machine version" << mach->version() << "loader version" << loader->Version(); + qDebug() << "LoadMachineData" << mach->loaderName() << "load failure, machine version" << mach->version() << "loader version" << loader->Version(); Q_UNUSED(e) progress->hide(); DataFormatError(mach); diff --git a/oscar/SleepLib/session.cpp b/oscar/SleepLib/session.cpp index cff259f0..218cb9c1 100644 --- a/oscar/SleepLib/session.cpp +++ b/oscar/SleepLib/session.cpp @@ -119,13 +119,13 @@ bool Session::OpenEvents() QString filename = eventFile(); + qDebug() << "Loading" << s_machine->loaderName().toLocal8Bit().data() << "Events:" << filename.toLocal8Bit().data(); bool b = LoadEvents(filename); - if (!b) { -// qWarning() << "Error Loading Events" << filename; + if ( ! b) { + qWarning() << "Error Loading Events" << filename; return false; } -// qDebug() << "Loading" << s_machine->loaderName().toLocal8Bit().data() << "Events:" << filename.toLocal8Bit().data(); return s_events_loaded = true; } @@ -138,14 +138,14 @@ bool Session::Destroy() QString summaryfile = s_machine->getSummariesPath() + base + ".000"; QString eventfile = s_machine->getEventsPath() + base + ".001"; - if (!dir.remove(summaryfile)) { - // qDebug() << "Could not delete" << summaryfile; + if ( ! dir.remove(summaryfile)) { + qWarning() << "Could not delete" << summaryfile; } - if (!dir.remove(eventfile)) { - // qDebug() << "Could not delete" << eventfile; + if ( ! dir.remove(eventfile)) { + qWarning() << "Could not delete" << eventfile; } - return s_machine->unlinkSession(this); //!dir.exists(base + ".000") && !dir.exists(base + ".001"); + return s_machine->unlinkSession(this); } bool Session::Store(QString path) @@ -154,7 +154,7 @@ bool Session::Store(QString path) { QDir dir(path); - if (!dir.exists(path)) { + if ( ! dir.exists(path)) { dir.mkpath(path); } @@ -180,103 +180,104 @@ bool Session::Store(QString path) return a; } -/*QDataStream & operator<<(QDataStream & out, const Session & session) -{ - session.StoreSummaryData(out); - return out; -} -void Session::StoreSummaryData(QDataStream & out) const -{ - out << summary_version; - out << (quint32)s_session; - out << s_first; // Session Start Time - out << s_last; // Duration of sesion in seconds. - - out << settings; - out << m_cnt; - out << m_sum; - out << m_avg; - out << m_wavg; - - out << m_min; - out << m_max; - - out << m_physmin; - out << m_physmax; - - out << m_cph; - out << m_sph; - - out << m_firstchan; - out << m_lastchan; - - out << m_valuesummary; - out << m_timesummary; - - out << m_gain; - - out << m_availableChannels; - - out << m_timeAboveTheshold; - out << m_upperThreshold; - out << m_timeBelowTheshold; - out << m_lowerThreshold; - - out << s_summaryOnly; -} - -QDataStream & operator>>(QDataStream & in, Session & session) -{ - session.LoadSummaryData(in); - return in; -} - - -void Session::LoadSummaryData(QDataStream & in) -{ - quint16 version; - in >> version; - - quint32 t32; - in >> t32; // Sessionid; - s_session = t32; - - in >> s_first; // Start time - in >> s_last; // Duration - - in >> settings; - in >> m_cnt; - in >> m_sum; - in >> m_avg; - in >> m_wavg; - - in >> m_min; - in >> m_max; - - in >> m_physmin; - in >> m_physmax; - - in >> m_cph; - in >> m_sph; - in >> m_firstchan; - in >> m_lastchan; - - in >> m_valuesummary; - in >> m_timesummary; - - in >> m_gain; - - in >> m_availableChannels; - in >> m_timeAboveTheshold; - in >> m_upperThreshold; - in >> m_timeBelowTheshold; - in >> m_lowerThreshold; - - in >> s_summaryOnly; - - s_enabled = 1; -} */ +//QDataStream & operator<<(QDataStream & out, const Session & session) +//{ +// session.StoreSummaryData(out); +// return out; +//} +// +//void Session::StoreSummaryData(QDataStream & out) const +//{ +// out << summary_version; +// out << (quint32)s_session; +// out << s_first; // Session Start Time +// out << s_last; // Duration of sesion in seconds. +// +// out << settings; +// out << m_cnt; +// out << m_sum; +// out << m_avg; +// out << m_wavg; +// +// out << m_min; +// out << m_max; +// +// out << m_physmin; +// out << m_physmax; +// +// out << m_cph; +// out << m_sph; +// +// out << m_firstchan; +// out << m_lastchan; +// +// out << m_valuesummary; +// out << m_timesummary; +// +// out << m_gain; +// +// out << m_availableChannels; +// +// out << m_timeAboveTheshold; +// out << m_upperThreshold; +// out << m_timeBelowTheshold; +// out << m_lowerThreshold; +// +// out << s_summaryOnly; +//} +// +//QDataStream & operator>>(QDataStream & in, Session & session) +//{ +// session.LoadSummaryData(in); +// return in; +//} +// +// +//void Session::LoadSummaryData(QDataStream & in) +//{ +// quint16 version; +// in >> version; +// +// quint32 t32; +// in >> t32; // Sessionid; +// s_session = t32; +// +// in >> s_first; // Start time +// in >> s_last; // Duration +// +// in >> settings; +// in >> m_cnt; +// in >> m_sum; +// in >> m_avg; +// in >> m_wavg; +// +// in >> m_min; +// in >> m_max; +// +// in >> m_physmin; +// in >> m_physmax; +// +// in >> m_cph; +// in >> m_sph; +// in >> m_firstchan; +// in >> m_lastchan; +// +// in >> m_valuesummary; +// in >> m_timesummary; +// +// in >> m_gain; +// +// in >> m_availableChannels; +// in >> m_timeAboveTheshold; +// in >> m_upperThreshold; +// in >> m_timeBelowTheshold; +// in >> m_lowerThreshold; +// +// in >> s_summaryOnly; +// +// s_enabled = 1; +//} QDataStream & operator>>(QDataStream & in, SessionSlice & slice) { @@ -796,6 +797,7 @@ bool Session::StoreEvents() file.close(); return true; } + bool Session::LoadEvents(QString filename) { quint32 magicnum, machid, sessid; diff --git a/oscar/mainwindow.cpp b/oscar/mainwindow.cpp index c330304d..a18ce540 100644 --- a/oscar/mainwindow.cpp +++ b/oscar/mainwindow.cpp @@ -439,7 +439,8 @@ bool MainWindow::OpenProfile(QString profileName, bool skippassword) qDebug() << "Opening profile" << profileName; auto pit = Profiles::profiles.find(profileName); - if (pit == Profiles::profiles.end()) return false; + if (pit == Profiles::profiles.end()) + return false; Profile * prof = pit.value(); if (p_profile) { @@ -853,13 +854,6 @@ QList MainWindow::detectCPAPCards() QList detectedCards; importScanCancelled = false; QString lastpath = (*p_profile)[STR_PREF_LastCPAPPath].toString(); -// #if defined (Q_OS_LINUX) -// if (detectedCards.size() == 0) { -// qDebug() << "Skipping card detection on Linux"; -// return detectedCards; -// } -// #endif - QListloaders = GetLoaders(MT_CPAP); QTime time; @@ -1782,58 +1776,60 @@ void MainWindow::on_actionPurge_Current_Day_triggered() QList::iterator s; QList list; - QList sidlist; +//// QList sidlist; // obsolete, see below for (s = day->begin(); s != day->end(); ++s) { - list.push_back(*s); + list.append(*s); qDebug() << "Purging session ID:" << (*s)->session() << "["+QDateTime::fromTime_t((*s)->session()).toString()+"]"; qDebug() << "First Time:" << QDateTime::fromMSecsSinceEpoch((*s)->realFirst()).toString(); qDebug() << "Last Time:" << QDateTime::fromMSecsSinceEpoch((*s)->realLast()).toString(); - sidlist.push_back((*s)->session()); +//// sidlist.append((*s)->session()); } - QHash skipfiles; - // Read the already imported file list - - QFile impfile(cpap->getDataPath()+"/imported_files.csv"); - if (impfile.exists()) { - qDebug() << "Obsolet file exists" << impfile.fileName(); - if (impfile.open(QFile::ReadOnly)) { - QTextStream impstream(&impfile); - QString serial; - impstream >> serial; - if (cpap->serial() == serial) { - QString line, file, str; - SessionID sid; - bool ok; - do { - line = impstream.readLine(); - file = line.section(',',0,0); - str = line.section(',',1); - sid = str.toInt(&ok); - if (!sidlist.contains(sid)) { - skipfiles[file] = sid; - } - } while (!impstream.atEnd()); - } - } - impfile.close(); - // Delete the file - impfile.remove(); - - // Rewrite the file without the sessions being removed. - if (impfile.open(QFile::WriteOnly)) { - QTextStream out(&impfile); - out << cpap->serial(); - QHash::iterator skit; - QHash::iterator skit_end = skipfiles.end(); - for (skit = skipfiles.begin(); skit != skit_end; ++skit) { - QString a = QString("%1,%2\n").arg(skit.key()).arg(skit.value());; - out << a; - } - out.flush(); - } - impfile.close(); - } // end of obsolte file code +//////// The imported_files.csv has been removed from SH 1.1 ////////// +// QHash skipfiles; +// // Read the already imported file list +// +// QFile impfile(cpap->getDataPath()+"/imported_files.csv"); +// if (impfile.exists()) { +// qDebug() << "Obsolet file exists" << impfile.fileName(); +// if (impfile.open(QFile::ReadOnly)) { +// QTextStream impstream(&impfile); +// QString serial; +// impstream >> serial; +// if (cpap->serial() == serial) { +// QString line, file, str; +// SessionID sid; +// bool ok; +// do { +// line = impstream.readLine(); +// file = line.section(',',0,0); +// str = line.section(',',1); +// sid = str.toInt(&ok); +// if (!sidlist.contains(sid)) { +// skipfiles[file] = sid; +// } +// } while (!impstream.atEnd()); +// } +// } +// impfile.close(); +// // Delete the file +// impfile.remove(); +// +// // Rewrite the file without the sessions being removed. +// if (impfile.open(QFile::WriteOnly)) { +// QTextStream out(&impfile); +// out << cpap->serial(); +// QHash::iterator skit; +// QHash::iterator skit_end = skipfiles.end(); +// for (skit = skipfiles.begin(); skit != skit_end; ++skit) { +// QString a = QString("%1,%2\n").arg(skit.key()).arg(skit.value());; +// out << a; +// } +// out.flush(); +// } +// impfile.close(); +// } // end of obsolte file code +/////////////////////////////////////////////////////////////////////////////////////// QFile rxcache(p_profile->Get("{" + STR_GEN_DataFolder + "}/RXChanges.cache" )); rxcache.remove(); @@ -1845,7 +1841,7 @@ void MainWindow::on_actionPurge_Current_Day_triggered() for (int i = 0; i < list.size(); i++) { Session *sess = list.at(i); - sess->Destroy(); + sess->Destroy(); // remove the summary and event files delete sess; } @@ -2001,7 +1997,7 @@ void MainWindow::purgeMachine(Machine * mach) delete mach; // remove the directory unless it's got unexpected crap in it.. bool deleted = false; - if (!dir.rmdir(path)) { + if ( ! dir.rmdir(path)) { #ifdef Q_OS_WIN wchar_t* directoryPtr = (wchar_t*)path.utf16(); SetFileAttributes(directoryPtr, GetFileAttributes(directoryPtr) & ~FILE_ATTRIBUTE_READONLY); @@ -2017,13 +2013,13 @@ void MainWindow::purgeMachine(Machine * mach) deleted = true; } #else - qDebug() << "Couldn't remove directory" << path; + qWarning() << "Couldn't remove directory" << path; #endif } else { deleted = true; } - if (!deleted) { - qDebug() << "Leaving backup folder intact"; + if ( ! deleted) { + qWarning() << "Leaving backup folder intact"; } PopulatePurgeMenu();