From 850213b968b8e2ed8fd45b5cfedd1e779a0bdf81 Mon Sep 17 00:00:00 2001 From: Mark Liversedge Date: Fri, 25 Sep 2009 21:18:56 +0100 Subject: [PATCH] report errors up from WkoRideFile --- src/RideImportWizard.cpp | 13 +++++++++++-- src/WkoRideFile.cpp | 19 +++++++++++-------- src/WkoRideFile.h | 4 ++-- 3 files changed, 24 insertions(+), 12 deletions(-) diff --git a/src/RideImportWizard.cpp b/src/RideImportWizard.cpp index 78d45e4bc..13f37a403 100644 --- a/src/RideImportWizard.cpp +++ b/src/RideImportWizard.cpp @@ -264,7 +264,7 @@ RideImportWizard::process() // does the status say Queued? if (!tableWidget->item(i,5)->text().startsWith(tr("Error"))) { - QStringList errors; + QStringList errors; QFile thisfile(filenames[i]); tableWidget->item(i,5)->setText(tr("Parsing...")); @@ -301,6 +301,7 @@ RideImportWizard::process() tableWidget->item(i,2)->setTextAlignment(Qt::AlignRight); // put in the middle // show duration by looking at last data point + if (ride->dataPoints().last() != NULL) { int secs = ride->dataPoints().last()->secs; QChar zero = QLatin1Char ( '0' ); QString time = QString("%1:%2:%3").arg(secs/3600,2,10,zero) @@ -315,9 +316,17 @@ RideImportWizard::process() tableWidget->item(i,4)->setText(dist); tableWidget->item(i,4)->setTextAlignment(Qt::AlignRight); // put in the middle + } else { + + tableWidget->item(i,3)->setText(tr("00:00:00")); // duration + tableWidget->item(i,3)->setTextAlignment(Qt::AlignHCenter); // put in the middle + tableWidget->item(i,4)->setText(tr("0 km")); + tableWidget->item(i,4)->setTextAlignment(Qt::AlignRight); // put in the middle + } + } else { // nope - can't handle this file - tableWidget->item(i,5)->setText(tr("Error - cannot parse")); + tableWidget->item(i,5)->setText(tr("Error - ") + errors.join(tr(" "))); } } progressBar->setValue(progressBar->value()+1); diff --git a/src/WkoRideFile.cpp b/src/WkoRideFile.cpp index 4908f1e83..3fbe3ed0c 100644 --- a/src/WkoRideFile.cpp +++ b/src/WkoRideFile.cpp @@ -110,10 +110,10 @@ RideFile *WkoFileReader::openRideFile(QFile &file, QStringList &errors) const RideFile *rideFile = new RideFile; // read header data and store details into rideFile structure - rawdata = WkoParseHeaderData(headerdata, rideFile); + rawdata = WkoParseHeaderData(headerdata, rideFile, errors); // Parse raw data (which calls rideFile->appendPoint() with each sample - if (rawdata) footerdata = WkoParseRawData(rawdata, rideFile); + if (rawdata) footerdata = WkoParseRawData(rawdata, rideFile, errors); else return NULL; if (footerdata) return (RideFile *)rideFile; @@ -127,7 +127,7 @@ RideFile *WkoFileReader::openRideFile(QFile &file, QStringList &errors) const * WkoParseRawData() - read through all the raw data adding record points and return * a pointer to the footer record **************************************************************************************/ -WKO_UCHAR *WkoParseRawData(WKO_UCHAR *fb, RideFile *rideFile) +WKO_UCHAR *WkoParseRawData(WKO_UCHAR *fb, RideFile *rideFile, QStringList &errors) { WKO_ULONG WKO_xormasks[32]; // xormasks used all over double cad, hr, km, kph, nm, watts, alt, interval; @@ -162,7 +162,7 @@ WKO_UCHAR *WkoParseRawData(WKO_UCHAR *fb, RideFile *rideFile) for (i=0; WKO_GRAPHS[i] != '\0'; i++) { WKO_nullval[i] = nullvals(WKO_GRAPHS[i]); // setup nullvalue if ((WKO_graphbits[i] = bitsize(WKO_GRAPHS[i], WKO_device)) == 0) { // setup & check field size - fprintf(stderr, "ERROR: Unknown channel '%c' for WKO_device %x.\n", WKO_GRAPHS[i], WKO_device); + errors << ("Unknown channel " + WKO_GRAPHS[i]); return (NULL); } } @@ -179,6 +179,10 @@ WKO_UCHAR *WkoParseRawData(WKO_UCHAR *fb, RideFile *rideFile) records = us; } + if (records == 0) { + errors << ("Workout is empty."); + return NULL; + } /* how much data is there? */ fb += doshort(fb, &us); if (us == 0xffff) { @@ -207,7 +211,6 @@ WKO_UCHAR *WkoParseRawData(WKO_UCHAR *fb, RideFile *rideFile) * RUN THROUGH EACH RAW DATA RECORD *==============================================================================*/ rdist=rtime=0; - if (!records) return NULL; while (records) { unsigned int marker; @@ -429,7 +432,7 @@ WKO_UCHAR *WkoParseRawData(WKO_UCHAR *fb, RideFile *rideFile) * WkoParseHeadeData() - read through file and land on the raw data * *********************************************************************/ -WKO_UCHAR *WkoParseHeaderData(WKO_UCHAR *fb, RideFile *rideFile) +WKO_UCHAR *WkoParseHeaderData(WKO_UCHAR *fb, RideFile *rideFile, QStringList &errors) { unsigned long julian, sincemidnight; WKO_UCHAR *goal, *notes, *code; // save location of WKO metadata @@ -930,7 +933,7 @@ next: } } else { - fprintf(stderr, "ERROR: unrecognised segment %x at %x aborting file\n", num, p-fb); + errors << ("Unrecognised segment"); return NULL; } } @@ -938,7 +941,7 @@ next: breakout: if (WKO_GRAPHS[0] == '\0') { - fprintf(stderr, "ERROR: file contains no GRAPHS\n"); + errors << ("File contains no GRAPHS"); return (WKO_UCHAR *)NULL; } else { /* PHEW! We're on the raw data, out job here is done */ diff --git a/src/WkoRideFile.h b/src/WkoRideFile.h index 050fd2da0..6e5071f74 100644 --- a/src/WkoRideFile.h +++ b/src/WkoRideFile.h @@ -43,8 +43,8 @@ struct WkoFileReader : public RideFileReader { typedef std::auto_ptr QDataStreamPtr; -WKO_UCHAR *WkoParseHeaderData(WKO_UCHAR *data, RideFile *rideFile) ; -WKO_UCHAR *WkoParseRawData(WKO_UCHAR *data, RideFile *rideFile) ; +WKO_UCHAR *WkoParseHeaderData(WKO_UCHAR *data, RideFile *rideFile, QStringList &errors) ; +WKO_UCHAR *WkoParseRawData(WKO_UCHAR *data, RideFile *rideFile, QStringList &errors) ; // Some Globals -- try and remove them as I refactor code from the original WKO2CSV source QString WKO_HOMEDIR;