+static void parseDelayClass(const QWebElement &element, StationScheduleItem &item)
+{
+ if (!element.isNull()) {
+ QWebElement image = element.findFirst("img");
+ if (!image.isNull()) {
+ int delayClass = 42;
+ QString imageName = image.attribute("src");
+ if (!imageName.isEmpty()) {
+ QRegExp delayClassRegexp("pallinoRit([0-9])\\.png");
+ int pos = delayClassRegexp.indexIn(imageName);
+ qDebug() << "regexp matched at pos:" << pos << "match:" << delayClassRegexp.cap(0);
+ delayClass = (pos >= 0) ? delayClassRegexp.cap(1).toInt() : 0;
+ }
+ item.setDelayClass(delayClass);
+ } else {
+ qDebug() << "img not found";
+ }
+ } else {
+ qDebug() << "div.bloccotreno not found";
+ }
+}
+
+static void parseDetailsUrl(const QWebElement &element, StationScheduleItem &item)
+{
+ if (!element.isNull()) {
+ QWebElement link = element.findFirst("a");
+ QString url = link.attribute("href");
+ item.setDetailsUrl(url);
+ } else {
+ qDebug() << "link not found";
+ }
+}
+
+static void parseTrain(const QString &text, StationScheduleItem &item)
+{
+ QRegExp filter("^(Per|Da) (.*)\\n"
+ "Delle ore (.*)\n"
+ "Binario Previsto: (.*)\n"
+ "Binario Reale: (.*)\n"
+ "(.*)$");
+ int pos = filter.indexIn(text);
+ if (pos >= 0) {
+ if (filter.cap(1) == "Per") {
+ item.setDepartureStation(filter.cap(2));
+ item.setDepartureTime(filter.cap(3));
+ } else {
+ item.setArrivalStation(filter.cap(2));
+ item.setArrivalTime(filter.cap(3));
+ }
+ item.setDelay(filter.cap(6));
+ } else {
+ qDebug() << "could not parse" << text;
+ }
+}
+