From: Luciano Montanaro Date: Wed, 9 Nov 2011 00:01:16 +0000 (+0100) Subject: Start of a proper station schedule parsing. X-Git-Tag: tags/0.4.81~46 X-Git-Url: https://vcs.maemo.org/git/?a=commitdiff_plain;h=8f6b51ef2393fe07b41df73e8146e5313d0eefa8;p=quandoparte Start of a proper station schedule parsing. --- diff --git a/application/resources/harmattan/qml/StationPage.qml b/application/resources/harmattan/qml/StationPage.qml index 2916622..e84f11f 100644 --- a/application/resources/harmattan/qml/StationPage.qml +++ b/application/resources/harmattan/qml/StationPage.qml @@ -52,11 +52,12 @@ Page { } Item { id: view - anchors { - top: info.bottom; - bottom: parent.bottom; - } - width: parent.width + anchors.top: info.bottom + anchors.bottom: tools.top + x: 16 + y: 16 + width: parent.width - 32 + height: parent.height ListView { id: stationScheduleView @@ -66,7 +67,7 @@ Page { model: schedule delegate: Item { id: listItem - height: 48 + height: 192 width: parent.width BorderImage { id: background @@ -83,7 +84,7 @@ Page { Label { id: mainText - text: Private.highlightSearch(model.display, UiConstants.AccentColor) + text: model.display font.bold: true } } diff --git a/application/stationlistmodel.cpp b/application/stationlistmodel.cpp index b1b3c52..d0d12a8 100644 --- a/application/stationlistmodel.cpp +++ b/application/stationlistmodel.cpp @@ -43,6 +43,7 @@ bool StationListModel::load(const QString &filename) qDebug() << "loading file:" << fi.absoluteFilePath(); + emit layoutAboutToBeChanged(); if (!file.open(QFile::ReadOnly | QFile::Text)) { qDebug() << "cannot open file:" << filename; return false; diff --git a/application/stationschedulemodel.cpp b/application/stationschedulemodel.cpp index b39ebf6..34021be 100644 --- a/application/stationschedulemodel.cpp +++ b/application/stationschedulemodel.cpp @@ -24,6 +24,9 @@ Boston, MA 02110-1301, USA. #include "dataprovider.h" #include +#include +#include +#include StationScheduleModel::StationScheduleModel(const QString &name, QObject *parent) : QStringListModel(parent), @@ -55,6 +58,57 @@ void StationScheduleModel::parse(const QByteArray &htmlReply, const QUrl &baseUr qDebug() << "--- start of query result --- cut here ------"; qDebug() << QString::fromUtf8(htmlReply.constData()); qDebug() << "--- end of query result ----- cut here ------"; + + emit layoutAboutToBeChanged(); + QWebPage page; + page.mainFrame()->setContent(htmlReply, "text/html", baseUrl); + QWebElement doc = page.mainFrame()->documentElement(); + + // Find the first div + QWebElement current = doc.findFirst("div"); + + QStringList departures, arrivals; + qDebug() << "skipping to the departures"; + // Skip to the first div of class corpocentrale, which contains the first + // departure-related contents + while (!current.classes().contains("corpocentrale")) { + current = current.nextSibling(); + qDebug() << "skipping to the next element"; + if (current.isNull()) + break; + } + // Mark every div as a departure class element; the next corpocentrale + // marks the start of the arrivals section + qDebug() << "marking departures"; + do { + if (current.classes().contains("bloccorisultato")) { + departures << current.toPlainText(); + } + current.addClass("departures"); + current = current.nextSibling(); + qDebug() << "marking as departures"; + if (current.isNull()) + break; + } while (!current.classes().contains("corpocentrale")); + + // Mark everything as an arrival, until reaching the footer + while (!current.classes().contains("footer")) { + if (current.classes().contains("bloccorisultato")) { + arrivals << current.toPlainText(); + } + current.addClass("arrivals"); + current = current.nextSibling(); + qDebug() << "marking as arrival"; + if (current.isNull()) + break; + } + + setStringList(departures); + qDebug() << "departures list contain:"; + qDebug() << departures; + qDebug() << "arrivals list contain:"; + qDebug() << arrivals; + emit layoutChanged(); } void StationScheduleModel::fetch(const QString &name) diff --git a/application/stationschedulemodel.h b/application/stationschedulemodel.h index 0758b2f..957364c 100644 --- a/application/stationschedulemodel.h +++ b/application/stationschedulemodel.h @@ -48,6 +48,8 @@ private slots: private: QString m_name; + QStringList departures; + QStringList arrivals; }; #endif // STATIONSCHEDULEMODEL_H