+ EventTypes::EventFromFileList fileEvents;
+ //return fileEvents;
+
+ QSet<uint> recordsToReturnSet(QSet<uint>::fromList(recordsToReturn));
+
+ uint lineNumber(0);
+ uint recordNumber(0);
+ eventFile.seek(0);
+
+ // Read the first line
+ QTextStream stream(&eventFile);
+ QString firstLineContent(stream.readLine());
+ QStringList firstLineValues(QString(firstLineContent).split(m_Delimiter));
+ if(firstLineValues.count() != m_NumColumnsPerRecord)
+ throw new std::runtime_error(QString("Unexpected number of columns (%1, expected %2) on line %3 of %4")
+ .arg(firstLineValues.count())
+ .arg(m_NumColumnsPerRecord)
+ .arg(lineNumber)
+ .arg(eventFile.fileName()).toStdString());
+ ++lineNumber;
+
+ // Read the main body of the file
+ while(!stream.atEnd())
+ {
+ QStringList lineValues(QString(stream.readLine()).split(m_Delimiter));
+ ++lineNumber;
+ // Make sure we have enough columns (i.e. handle newlines in values)
+ while(lineValues.count() < m_NumColumnsPerRecord)
+ {
+ lineValues.append(QString(stream.readLine()).split(m_Delimiter));
+ ++lineNumber;
+ }
+
+ if(recordsToReturnSet.count() == 0 || recordsToReturnSet.contains(recordNumber))
+ {
+ bool bOK(false);
+ int eType(lineValues.at(m_HeadingIndices.value("etype")).toUInt(&bOK));
+ // We're only interested in phone calls
+ if(bOK && eType == 0)
+ {
+ qDebug() << "Parsing event from line #" << lineNumber << ". Values: " << lineValues;
+
+ QDateTime eTime(QDateTime::fromString(lineValues.at(m_HeadingIndices.value("etime")), "dd/MM/yyyy h:mm:ss ap"));
+ Settings::eDirection direction(lineValues.at(m_HeadingIndices.value("direction")) == "0"
+ ? Settings::INCOMING
+ : Settings::OUTGOING);
+
+ // We only care about the requested directions...
+ if(CurrentSettings().ShouldProcess(direction, EventTypes::EVENT_TYPE_CALL))
+ {
+ int duration(lineValues.at(m_HeadingIndices.value("duration")).toInt(&bOK));
+ if(!bOK)
+ {
+ qDebug() << QString("Unable to parse '%1' as a duration. Skipping record.")
+ .arg(lineValues.at(m_HeadingIndices.value("duration")));
+ continue;
+ }
+ QString number(ExtractString(lineValues.at(m_HeadingIndices.value("number"))));
+ // TODO: Not currently used...but almost certainly contains SIP call data
+ QString data(ExtractString(lineValues.at(m_HeadingIndices.value("data"))));
+
+ if(number.trimmed().length() == 0)
+ {
+ qDebug() << "Empty tel!";
+ }
+
+ QSharedPointer<EventTypes::iEvent> newEvent(new PhoneCall(
+ CurrentSettings(),
+ direction,
+ eTime,
+ number,
+ duration));
+ fileEvents.append(EventTypes::EventFromFile(newEvent, recordNumber));
+ }
+ }
+ }
+
+ ++recordNumber;
+ }
+
+ qDebug() << QString("File pos: %1, bAvail: %2, canReadLine: %3").arg(eventFile.pos()).arg(eventFile.bytesAvailable()).arg(eventFile.canReadLine());
+ qDebug() << fileEvents.count() << " events loaded from file";
+ return fileEvents;