/* virtual */ void XMLerLoadFileThread::run () { QFile xml( fileName() ); if ( !xml.exists() ) { emit error ( tr("File %1 does not exists.").arg( fileName() ) ); return; } /* QMap<QString, QString> info = getInformationFromFile(); */ QXmlSimpleReader reader; XMLerInputSource *source = new XMLerInputSource ( &xml ); /* connect source to slots in model */ connect ( source, SIGNAL(beginRead(qint64)), this, SLOT(on_beginProgress(qint64)) ); connect ( source, SIGNAL(readProgress(qint64)), this, SLOT(on_progress(qint64)) ); connect ( source, SIGNAL(endRead()), this, SLOT(on_endProgress()) ); reader.setContentHandler ( handler ); reader.setErrorHandler ( handler ); bool parseResult = reader.parse ( source, true ); /* FIXME: this is partial read */ if ( parseResult ) { bool partResult = parseResult; while ( partResult ) partResult = reader.parseContinue(); } if ( !parseResult ) { checkExceptionInHandler(); on_endProgress(); return; } /* set addition data (information) in document */ if ( handler->document() ) handler->document()->setFileName( fileName() ); /* CLEANIT if ( !info.isEmpty() ) { if ( info.contains ( "encoding" ) ) handler->document()->setCodec ( info.value ( "encoding" ) ); if ( info.contains ( "version" ) ) handler->document()->setVersion ( info.value ( "version" ) ); }*/ emit done ( handler->document() ); checkExceptionInHandler (); /* clean */ disconnect ( source, SIGNAL(beginRead(qint64)) ); disconnect ( source, SIGNAL(readProgress(qint64)) ); disconnect ( source, SIGNAL(endRead()) ); delete source; }
RideFile *QuarqFileReader::openRideFile(QFile &file, QStringList &errors, QList<RideFile*>*) const { (void) errors; RideFile *rideFile = new RideFile(); rideFile->setDeviceType("Quarq Qollector"); rideFile->setFileFormat("Quarq ANT+ Files (qla)"); rideFile->setRecIntSecs(1.0); QuarqParser handler(rideFile); QProcess *antProcess = getInterpreterProcess( installed_path ); assert(antProcess); QXmlInputSource source (antProcess); QXmlSimpleReader reader; reader.setContentHandler (&handler); // this could done be a loop to "save memory." file.open(QIODevice::ReadOnly); antProcess->write(file.readAll()); antProcess->closeWriteChannel(); antProcess->waitForFinished(-1); assert(QProcess::NormalExit == antProcess->exitStatus()); assert(0 == antProcess->exitCode()); reader.parse(source); reader.parseContinue(); QRegExp rideTime("^.*/(\\d\\d\\d\\d)_(\\d\\d)_(\\d\\d)_" "(\\d\\d)_(\\d\\d)_(\\d\\d)\\.qla$"); if (rideTime.indexIn(file.fileName()) >= 0) { QDateTime datetime(QDate(rideTime.cap(1).toInt(), rideTime.cap(2).toInt(), rideTime.cap(3).toInt()), QTime(rideTime.cap(4).toInt(), rideTime.cap(5).toInt(), rideTime.cap(6).toInt())); rideFile->setStartTime(datetime); } delete antProcess; return rideFile; }