From: Luciano Montanaro Date: Sat, 4 Feb 2012 21:02:30 +0000 (+0100) Subject: Handle error pages in the schedule model X-Git-Tag: tags/0.5.0~7 X-Git-Url: http://vcs.maemo.org/git/?a=commitdiff_plain;h=04b756ee66455287cbcfcff058a4f4ff556ce4e8;p=quandoparte Handle error pages in the schedule model --- diff --git a/application/stationschedulemodel.cpp b/application/stationschedulemodel.cpp index 6f13b79..7343b30 100644 --- a/application/stationschedulemodel.cpp +++ b/application/stationschedulemodel.cpp @@ -212,6 +212,20 @@ void StationScheduleModel::parse(const QByteArray &htmlReply, const QUrl &baseUr page.mainFrame()->setContent(htmlReply, "text/html", baseUrl); QWebElement doc = page.mainFrame()->documentElement(); + // Check if the page is reporting an error before parsing it + QWebElement errorElement = doc.findFirst("span.errore"); + if (!errorElement.isNull()) { + m_departureSchedules.clear(); + m_arrivalSchedules.clear(); + QString errorText = errorElement.toPlainText().trimmed(); + if (errorText == "localita' non trovata") { + setError(tr("Unknown station")); + } else { + setError(tr("Unknown error")); + } + qDebug() << "error:" << error(); + return; + } // Find the first div QWebElement current = doc.findFirst("div");