X-Git-Url: http://git.maemo.org/git/?p=qwerkisync;a=blobdiff_plain;f=EventParsers%2FCSVSymbianEventLogParser.cpp;h=43142f1f4df7549493c90ef6bb1cf18f1dbefd38;hp=926a247b9f3908dbf4359c20d0e74aca5d1ace02;hb=f3569fd45504745ccde6944c0dc25c17c0b92dd5;hpb=48aa85b627d1367979cf57878ceceecf028e05f2 diff --git a/EventParsers/CSVSymbianEventLogParser.cpp b/EventParsers/CSVSymbianEventLogParser.cpp index 926a247..43142f1 100644 --- a/EventParsers/CSVSymbianEventLogParser.cpp +++ b/EventParsers/CSVSymbianEventLogParser.cpp @@ -29,11 +29,12 @@ #include using namespace EventParsers; +using EventTypes::PhoneCall; class SortByValueDesc { public: - inline bool operator()(const QPair &a, const QPair &b) const + inline bool operator()(const QPair &a, const QPair &b) const { return b.second < a.second; } @@ -50,30 +51,32 @@ iEventParser *CSVSymbianEventLogParser::IsValid(const Settings ¤tSettings, { qDebug() << "Checking if a CSV call log file..."; - QByteArray firstLineContent(eventFile.readLine()); + QTextStream stream(&eventFile); + + QString firstLineContent(stream.readLine()); eventFile.seek(0); if(firstLineContent.length() > 0) { // Count the non-alphanumeric characters used - QHash counts; - foreach(char c, firstLineContent) + QHash counts; + foreach(const QChar c, firstLineContent) ++counts[c]; - QList > orderedCounts; + QList > orderedCounts; orderedCounts.reserve(counts.size()); - foreach(char c, counts.keys()) + foreach(const QChar c, counts.keys()) if(!QChar(c).isLetterOrNumber()) - orderedCounts.append(QPair(c, counts.value(c))); + orderedCounts.append(QPair(c, counts.value(c))); qSort(orderedCounts.begin(), orderedCounts.end(), SortByValueDesc()); // Work around Q_FOREACH macro limitation when dealing with // multi-typed templates (comma issue) - typedef QPair bodge; + typedef QPair bodge; foreach(bodge count, orderedCounts) qDebug() << count.first << " = " << count.second; - char delim; + QChar delim; // No-one would be mad enough to use quotation marks or apostrophes // as their delimiter,but just in case, check the second most // frequent character is present thr right number of times for @@ -123,7 +126,7 @@ iEventParser *CSVSymbianEventLogParser::IsValid(const Settings ¤tSettings, return NULL; } -CSVSymbianEventLogParser::CSVSymbianEventLogParser(const Settings &settings, const QString &filename, const char delimiter, const int numColumnsPerRecord, const ColumnIndicesHash &headingIndices) +CSVSymbianEventLogParser::CSVSymbianEventLogParser(const Settings &settings, const QString &filename, const QChar delimiter, const int numColumnsPerRecord, const ColumnIndicesHash &headingIndices) : m_Settings(settings), m_Delimiter(delimiter), m_NumColumnsPerRecord(numColumnsPerRecord), m_HeadingIndices(headingIndices) { } @@ -141,25 +144,26 @@ EventTypes::EventFromFileList CSVSymbianEventLogParser::ParseFile(QFile &eventFi eventFile.seek(0); // Read the first line - QByteArray firstLineContent(eventFile.readLine()); + 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()); + .arg(m_NumColumnsPerRecord) + .arg(lineNumber) + .arg(eventFile.fileName()).toStdString()); ++lineNumber; // Read the main body of the file - while(!eventFile.atEnd()) + while(!stream.atEnd()) { - QStringList lineValues(QString(eventFile.readLine()).split(m_Delimiter)); + 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(eventFile.readLine()).split(m_Delimiter)); + lineValues.append(QString(stream.readLine()).split(m_Delimiter)); ++lineNumber; } @@ -172,27 +176,38 @@ EventTypes::EventFromFileList CSVSymbianEventLogParser::ParseFile(QFile &eventFi { qDebug() << "Parsing event from line #" << lineNumber << ". Values: " << lineValues; - QDateTime eTime(QDateTime::fromString(lineValues.at(m_HeadingIndices.value("etime")), "dd/MM/yyyy hh:mm:ss")); - int duration(lineValues.at(m_HeadingIndices.value("duration")).toInt(&bOK)); - if(!bOK) + 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)) { - qDebug() << QString("Unable to parse '%1' as a duration. Skipping record.") - .arg(lineValues.at(m_HeadingIndices.value("duration"))); - continue; + 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 newEvent(new PhoneCall( + CurrentSettings(), + direction, + eTime, + number, + duration)); + fileEvents.append(EventTypes::EventFromFile(newEvent, recordNumber)); } - QString number(ExtractString(lineValues.at(m_HeadingIndices.value("number")))); - QString data(ExtractString(lineValues.at(m_HeadingIndices.value("data")))); - - QSharedPointer newEvent(new EventTypes::PhoneCall( - CurrentSettings(), - direction, - eTime, - number, - duration)); - fileEvents.append(EventTypes::EventFromFile(newEvent, recordNumber)); } }