Changeset View
Changeset View
Standalone View
Standalone View
dataengines/potd/noaaprovider.cpp
Show First 20 Lines • Show All 52 Lines • ▼ Show 20 Line(s) | 46 | { | |||
---|---|---|---|---|---|
53 | const QString data = QString::fromUtf8( job->data() ); | 53 | const QString data = QString::fromUtf8( job->data() ); | ||
54 | 54 | | |||
55 | // Using regular expression could be fragile in such case, but the HTML | 55 | // Using regular expression could be fragile in such case, but the HTML | ||
56 | // NOAA page itself is not a valid XML file and unfortunately it could | 56 | // NOAA page itself is not a valid XML file and unfortunately it could | ||
57 | // not be parsed successfully till the content we want. And we do not want | 57 | // not be parsed successfully till the content we want. And we do not want | ||
58 | // to use heavy weight QtWebkit. So we use QRegularExpression to capture | 58 | // to use heavy weight QtWebkit. So we use QRegularExpression to capture | ||
59 | // the wanted url here. | 59 | // the wanted url here. | ||
60 | QString url; | 60 | QString url; | ||
61 | QRegularExpression re(QStringLiteral("href=\"(.*)\"><img alt=\"Latest Image of the Day"), QRegularExpression::MultilineOption); | 61 | QRegularExpression re(QStringLiteral("href=\".*\\/content\\/(.*)\"><img alt=\"Latest Image of the Day"), QRegularExpression::MultilineOption); | ||
62 | auto result = re.match(data); | 62 | auto result = re.match(data); | ||
63 | if (result.hasMatch()) | 63 | if (result.hasMatch()) | ||
64 | { | 64 | { | ||
65 | url = result.captured(1); | 65 | url = QStringLiteral("http://www.nesdis.noaa.gov/content/") + result.captured(1); | ||
66 | } | 66 | } | ||
67 | if (url.isEmpty()) | 67 | if (url.isEmpty()) | ||
68 | { | 68 | { | ||
69 | emit error(this); | 69 | emit error(this); | ||
70 | return; | 70 | return; | ||
71 | } | 71 | } | ||
72 | 72 | | |||
73 | job = KIO::storedGet(QUrl(url), KIO::NoReload, KIO::HideProgressInfo); | 73 | job = KIO::storedGet(QUrl(url), KIO::NoReload, KIO::HideProgressInfo); | ||
▲ Show 20 Lines • Show All 48 Lines • Show Last 20 Lines |