diff --git a/dataengines/potd/noaaprovider.cpp b/dataengines/potd/noaaprovider.cpp index 3f262f3da..f53fb2a96 100644 --- a/dataengines/potd/noaaprovider.cpp +++ b/dataengines/potd/noaaprovider.cpp @@ -1,121 +1,89 @@ /* * Copyright (C) 2007 Tobias Koenig * Copyright 2008 by Anne-Marie Mahfouf * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details * * You should have received a copy of the GNU Library General Public * License along with this program; if not, write to the * Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "noaaprovider.h" #include #include #include #include NOAAProvider::NOAAProvider(QObject *parent, const QVariantList &args) : PotdProvider(parent, args) { - const QUrl url(QStringLiteral("http://www.nesdis.noaa.gov/content/imagery-and-data")); + const QUrl url(QStringLiteral("https://www.nesdis.noaa.gov/content/imagery-and-data")); KIO::StoredTransferJob *job = KIO::storedGet(url, KIO::NoReload, KIO::HideProgressInfo); - connect(job, &KIO::StoredTransferJob::finished, this, &NOAAProvider::firstPageRequestFinished); + connect(job, &KIO::StoredTransferJob::finished, this, &NOAAProvider::pageRequestFinished); } NOAAProvider::~NOAAProvider() = default; QImage NOAAProvider::image() const { return mImage; } -void NOAAProvider::firstPageRequestFinished(KJob* _job) +void NOAAProvider::pageRequestFinished(KJob* _job) { KIO::StoredTransferJob *job = static_cast( _job ); if (job->error()) { emit error(this); return; } const QString data = QString::fromUtf8( job->data() ); // Using regular expression could be fragile in such case, but the HTML // NOAA page itself is not a valid XML file and unfortunately it could // not be parsed successfully till the content we want. And we do not want // to use heavy weight QtWebkit. So we use QRegularExpression to capture // the wanted url here. - QString url; - QRegularExpression re(QStringLiteral("href=\".*\\/content\\/(.*)\">\"Latest( _job ); - if (job->error()) { - emit error(this); - return; - } - - const QString data = QString::fromUtf8( job->data() ); - - // Using regular expression could be fragile in such case, but the HTML - // NOAA page itself is not a valid XML file and unfortunately it could - // not be parsed successfully till the content we want. And we do not want - // to use heavy weight QtWebkit. So we use QRegularExpression to capture - // the wanted url here. - QString url; - QRegularExpression re(QStringLiteral("a href='(.*)'>( _job ); if ( job->error() ) { emit error(this); return; } mImage = QImage::fromData( job->data() ); emit finished(this); } K_PLUGIN_CLASS_WITH_JSON(NOAAProvider, "noaaprovider.json") #include "noaaprovider.moc" diff --git a/dataengines/potd/noaaprovider.h b/dataengines/potd/noaaprovider.h index 015a8dcad..b9677e58f 100644 --- a/dataengines/potd/noaaprovider.h +++ b/dataengines/potd/noaaprovider.h @@ -1,71 +1,70 @@ /* * Copyright (C) 2007 Tobias Koenig * Copyright 2008 by Anne-Marie Mahfouf * Copyright 2016 Weng Xuetian * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details * * You should have received a copy of the GNU Library General Public * License along with this program; if not, write to the * Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef NOAAPROVIDER_H #define NOAAPROVIDER_H #include "potdprovider.h" // Qt #include class KJob; /** * This class provides the image for NOAA Environmental Visualization Laboratory * Image Of the Day * located at http://www.nesdis.noaa.gov/content/imagery-and-data. */ class NOAAProvider : public PotdProvider { Q_OBJECT public: /** * Creates a new NOAA provider. * * @param parent The parent object. * @param args The arguments. */ NOAAProvider( QObject *parent, const QVariantList &args ); /** * Destroys the NOAA provider. */ ~NOAAProvider() override; /** * Returns the requested image. * * Note: This method returns only a valid image after the * finished() signal has been emitted. */ QImage image() const override; private: - void firstPageRequestFinished(KJob *job); - void secondPageRequestFinished(KJob *job); + void pageRequestFinished(KJob *job); void imageRequestFinished(KJob *job); private: QImage mImage; }; #endif