diff --git a/dataengines/potd/apodprovider.h b/dataengines/potd/apodprovider.h index 3cd83b122..94c2d47d5 100644 --- a/dataengines/potd/apodprovider.h +++ b/dataengines/potd/apodprovider.h @@ -1,73 +1,73 @@ /* * 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. */ #ifndef APODPROVIDER_H #define APODPROVIDER_H #include "potdprovider.h" #include class KJob; /** * This class provides the image for APOD * "Astronomy Picture Of the Day" - * located at http://antwrp.gsfc.nasa.gov/apod. + * located at https://antwrp.gsfc.nasa.gov/apod. * Direct link to the picture of the day page is - * http://antwrp.gsfc.nasa.gov/apod/apYYMMDD.html + * https://antwrp.gsfc.nasa.gov/apod/apYYMMDD.html * where YY is the year last 2 digits, * MM is the month and DD the day, in 2 digits. */ class ApodProvider : public PotdProvider { Q_OBJECT public: /** * Creates a new APOD provider. * * @param parent The parent object. * @param args The arguments. */ explicit ApodProvider( QObject *parent, const QVariantList &args ); /** * Destroys the APOD provider. */ ~ApodProvider() 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 pageRequestFinished(KJob *job); void imageRequestFinished(KJob *job); private: QImage mImage; }; #endif diff --git a/dataengines/potd/bingprovider.h b/dataengines/potd/bingprovider.h index 1678008d0..22947b70c 100644 --- a/dataengines/potd/bingprovider.h +++ b/dataengines/potd/bingprovider.h @@ -1,67 +1,67 @@ /* * Copyright 2017 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 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 BINGPROVIDER_H #define BINGPROVIDER_H #include "potdprovider.h" // Qt #include class KJob; /** * This class provides the image for the Bing's homepage - * url is obtained from http://www.bing.com/HPImageArchive.aspx?format=js&idx=0&n=1 + * url is obtained from https://www.bing.com/HPImageArchive.aspx?format=js&idx=0&n=1 */ class BingProvider : public PotdProvider { Q_OBJECT public: /** * Creates a new Bing provider. * * @param parent The parent object. * @param args The arguments. */ BingProvider( QObject *parent, const QVariantList &args ); /** * Destroys the Bing provider. */ ~BingProvider() 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 pageRequestFinished(KJob *job); void imageRequestFinished(KJob *job); private: QImage mImage; }; #endif diff --git a/dataengines/potd/epodprovider.cpp b/dataengines/potd/epodprovider.cpp index 0450be163..6078ecdba 100644 --- a/dataengines/potd/epodprovider.cpp +++ b/dataengines/potd/epodprovider.cpp @@ -1,81 +1,81 @@ /* * 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 "epodprovider.h" #include #include #include #include EpodProvider::EpodProvider( QObject *parent, const QVariantList &args ) : PotdProvider(parent, args) { - const QUrl url(QStringLiteral("http://epod.usra.edu/blog/")); + const QUrl url(QStringLiteral("https://epod.usra.edu/blog/")); KIO::StoredTransferJob *job = KIO::storedGet(url, KIO::NoReload, KIO::HideProgressInfo); connect(job, &KIO::StoredTransferJob::finished, this, &EpodProvider::pageRequestFinished); } EpodProvider::~EpodProvider() = default; QImage EpodProvider::image() const { return mImage; } void EpodProvider::pageRequestFinished(KJob *_job) { KIO::StoredTransferJob *job = static_cast(_job); if ( job->error() ) { emit error(this); return; } const QString data = QString::fromUtf8( job->data() ); const QString pattern = QStringLiteral("://epod.usra.edu/.a/*-pi"); QRegExp exp( pattern ); exp.setPatternSyntax(QRegExp::Wildcard); int pos = exp.indexIn( data ) + pattern.length(); const QString sub = data.mid( pos-4, pattern.length()+10); - const QUrl url(QStringLiteral("http://epod.usra.edu/.a/%1-pi").arg(sub)); + const QUrl url(QStringLiteral("https://epod.usra.edu/.a/%1-pi").arg(sub)); KIO::StoredTransferJob *imageJob = KIO::storedGet( url, KIO::NoReload, KIO::HideProgressInfo ); connect(imageJob, &KIO::StoredTransferJob::finished, this, &EpodProvider::imageRequestFinished); } void EpodProvider::imageRequestFinished(KJob *_job) { KIO::StoredTransferJob *job = static_cast(_job); if ( job->error() ) { emit error(this); return; } // FIXME: this really should be done in a thread as this can block mImage = QImage::fromData( job->data() ); emit finished(this); } K_PLUGIN_CLASS_WITH_JSON(EpodProvider, "epodprovider.json") #include "epodprovider.moc" diff --git a/dataengines/potd/epodprovider.h b/dataengines/potd/epodprovider.h index 17e67d8bb..6eb77b3c1 100644 --- a/dataengines/potd/epodprovider.h +++ b/dataengines/potd/epodprovider.h @@ -1,69 +1,69 @@ /* * 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. */ #ifndef EPODPROVIDER_H #define EPODPROVIDER_H #include "potdprovider.h" // Qt #include class KJob; /** * This class provides the image for EPOD * "Earth Science Picture Of the Day" - * located at http://epod.usra.edu/. + * located at https://epod.usra.edu/. */ class EpodProvider : public PotdProvider { Q_OBJECT public: /** * Creates a new EPOD provider. * * @param parent The parent object. * @param args The arguments. */ EpodProvider( QObject *parent, const QVariantList &args ); /** * Destroys the EPOD provider. */ ~EpodProvider() 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 pageRequestFinished(KJob *job); void imageRequestFinished(KJob *job); private: QImage mImage; }; #endif diff --git a/dataengines/potd/natgeoprovider.cpp b/dataengines/potd/natgeoprovider.cpp index c15d34015..5a51c0c1f 100644 --- a/dataengines/potd/natgeoprovider.cpp +++ b/dataengines/potd/natgeoprovider.cpp @@ -1,91 +1,91 @@ /* * Copyright 2007 Tobias Koenig * Copyright 2008 Anne-Marie Mahfouf * Copyright 2013 Aaron Seigo * * 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 "natgeoprovider.h" #include #include #include NatGeoProvider::NatGeoProvider(QObject *parent, const QVariantList &args) : PotdProvider(parent, args) { - const QUrl url(QStringLiteral("http://www.nationalgeographic.com/photography/photo-of-the-day/")); + const QUrl url(QStringLiteral("https://www.nationalgeographic.com/photography/photo-of-the-day/")); KIO::StoredTransferJob *job = KIO::storedGet(url, KIO::NoReload, KIO::HideProgressInfo); connect(job, &KIO::StoredTransferJob::finished, this, &NatGeoProvider::pageRequestFinished); } NatGeoProvider::~NatGeoProvider() = default; QImage NatGeoProvider::image() const { return mImage; } void NatGeoProvider::pageRequestFinished(KJob* _job) { KIO::StoredTransferJob *job = static_cast( _job ); if (job->error()) { emit error(this); return; } const QString data = QString::fromUtf8( job->data() ); const QStringList lines = data.split(QLatin1Char('\n')); QString url; re.setPattern(QStringLiteral("^$")); for (int i = 0; i < lines.size(); i++) { QRegularExpressionMatch match = re.match(lines.at(i)); if (match.hasMatch()) { url = match.captured(1); } } if (url.isEmpty()) { emit error(this); return; } KIO::StoredTransferJob *imageJob = KIO::storedGet( QUrl(url), KIO::NoReload, KIO::HideProgressInfo ); connect(imageJob, &KIO::StoredTransferJob::finished, this, &NatGeoProvider::imageRequestFinished); } void NatGeoProvider::imageRequestFinished(KJob *_job) { KIO::StoredTransferJob *job = static_cast( _job ); if ( job->error() ) { emit error(this); return; } mImage = QImage::fromData( job->data() ); emit finished(this); } K_PLUGIN_CLASS_WITH_JSON(NatGeoProvider, "natgeoprovider.json") #include "natgeoprovider.moc" diff --git a/dataengines/potd/noaaprovider.h b/dataengines/potd/noaaprovider.h index b9677e58f..1371f49b0 100644 --- a/dataengines/potd/noaaprovider.h +++ b/dataengines/potd/noaaprovider.h @@ -1,70 +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 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. + * located at https://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 pageRequestFinished(KJob *job); void imageRequestFinished(KJob *job); private: QImage mImage; }; #endif diff --git a/runners/mediawiki/mediawiki.cpp b/runners/mediawiki/mediawiki.cpp index fafc139db..87a1782ac 100644 --- a/runners/mediawiki/mediawiki.cpp +++ b/runners/mediawiki/mediawiki.cpp @@ -1,246 +1,246 @@ /* * Copyright 2009 by Richard Moore * Copyright 2009 by Sebastian K?gler * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Library General Public License as * published by the Free Software Foundation; either version 2, 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 "mediawiki.h" // KF #include // Qt #include #include #include #include #include #include enum State { StateApiChanged, StateApiUpdating, StateReady }; struct MediaWikiPrivate { int state; QList results; QUrl apiUrl; QUrl baseUrl; QNetworkAccessManager *manager; int maxItems; QNetworkReply *reply; int timeout; QUrl query; QByteArray userAgent; }; MediaWiki::MediaWiki( QObject *parent ) : QObject( parent ), d( new MediaWikiPrivate ) { d->state = StateApiChanged; // should be overwritten by the user d->apiUrl = QUrl(QStringLiteral("https://en.wikipedia.org/w/api.php")); //FIXME: at the moment KIO doesn't seem to work in threads d->manager = new QNetworkAccessManager( this ); d->manager->setRedirectPolicy(QNetworkRequest::NoLessSafeRedirectPolicy); //d->manager = new KIO::AccessManager( this ); d->maxItems = 10; d->timeout = 30 * 1000; // 30 second d->reply = nullptr; d->userAgent = QByteArray("KDE Plasma Silk; MediaWikiRunner; 1.0"); connect(d->manager, &QNetworkAccessManager::finished, this, &MediaWiki::onNetworkRequestFinished); } MediaWiki::~MediaWiki() { delete d; } QList MediaWiki::results() const { return d->results; } int MediaWiki::maxItems() const { return d->maxItems; } void MediaWiki::setMaxItems( int limit ) { d->maxItems = limit; } QUrl MediaWiki::apiUrl() const { return d->apiUrl; } void MediaWiki::setApiUrl( const QUrl &url ) { if ( d->apiUrl == url ) return; d->apiUrl = url; d->state = StateApiChanged; } int MediaWiki::timeout() const { return d->timeout; } void MediaWiki::setTimeout( int millis ) { d->timeout = millis; } void MediaWiki::abort() { if ( !d->reply ) return; d->reply->abort(); d->reply = nullptr; } void MediaWiki::search( const QString &searchTerm ) { QUrl url = d->apiUrl; QUrlQuery urlQuery(url); urlQuery.addQueryItem(QStringLiteral("action"), QStringLiteral("query")); urlQuery.addQueryItem(QStringLiteral("format"), QStringLiteral("xml")); urlQuery.addQueryItem(QStringLiteral("list"), QStringLiteral("search")); urlQuery.addQueryItem(QStringLiteral("srsearch"), searchTerm ); urlQuery.addQueryItem(QStringLiteral("srlimit"), QString::number(d->maxItems)); url.setQuery(urlQuery); qDebug() << "Constructed search URL" << url; if ( d->state == StateReady ) { QNetworkRequest req(url); req.setRawHeader( QByteArray("User-Agent"), d->userAgent ); qDebug() << "mediawiki User-Agent" << req.rawHeader(QByteArray("UserAgent")); d->reply = d->manager->get( req ); QTimer::singleShot( d->timeout, this, SLOT(abort()) ); } else if ( d->state == StateApiChanged ) { d->query = url; findBase(); } } void MediaWiki::findBase() { - // http://en.wikipedia.org/w/api.php?action=query&meta=siteinfo + // https://en.wikipedia.org/w/api.php?action=query&meta=siteinfo QUrl url = d->apiUrl; QUrlQuery urlQuery(url); urlQuery.addQueryItem(QStringLiteral("action"), QStringLiteral("query")); urlQuery.addQueryItem(QStringLiteral("format"), QStringLiteral("xml")); urlQuery.addQueryItem(QStringLiteral("meta"), QStringLiteral("siteinfo")); url.setQuery(urlQuery); qDebug() << "Constructed base query URL" << url; QNetworkRequest req(url); req.setRawHeader( QByteArray("User-Agent"), d->userAgent ); d->reply = d->manager->get( req ); d->state = StateApiUpdating; } void MediaWiki::onNetworkRequestFinished(QNetworkReply *reply) { if ( reply->error() != QNetworkReply::NoError ) { qDebug() << "Request failed, " << reply->errorString(); reply->deleteLater(); d->reply = nullptr; emit finished(false); return; } qDebug() << "Request succeeded" << d->apiUrl; if ( d->state == StateApiUpdating ) { bool ok = processBaseResult( reply ); Q_UNUSED ( ok ); reply->deleteLater(); reply= nullptr; d->state = StateReady; QNetworkRequest req(d->query); req.setRawHeader( QByteArray("User-Agent"), d->userAgent ); d->reply = d->manager->get( req ); QTimer::singleShot( d->timeout, this, SLOT(abort()) ); } else { bool ok = processSearchResult( reply ); emit finished( ok ); d->reply->deleteLater(); d->reply = nullptr; } } bool MediaWiki::processBaseResult( QIODevice *source ) { QXmlStreamReader reader( source ); while ( !reader.atEnd() ) { QXmlStreamReader::TokenType tokenType = reader.readNext(); // qDebug() << "Token" << int(tokenType); if ( tokenType == QXmlStreamReader::StartElement ) { if (reader.name() == QLatin1String("general")) { QXmlStreamAttributes attrs = reader.attributes(); d->baseUrl = QUrl(attrs.value(QStringLiteral("base")).toString()); return true; } } else if ( tokenType == QXmlStreamReader::Invalid ) return false; } return true; } bool MediaWiki::processSearchResult( QIODevice *source ) { d->results.clear(); QXmlStreamReader reader( source ); while ( !reader.atEnd() ) { QXmlStreamReader::TokenType tokenType = reader.readNext(); // qDebug() << "Token" << int(tokenType); if ( tokenType == QXmlStreamReader::StartElement ) { if (reader.name() == QLatin1String("p")) { QXmlStreamAttributes attrs = reader.attributes(); Result r; r.title = attrs.value(QStringLiteral("title")).toString(); r.url = d->baseUrl.resolved(QUrl(r.title)); qDebug() << "Got result: url=" << r.url << "title=" << r.title; d->results.prepend( r ); } } else if ( tokenType == QXmlStreamReader::Invalid ) { return false; } } return true; } diff --git a/runners/mediawiki/mediawiki.h b/runners/mediawiki/mediawiki.h index 5093066fd..1bce66848 100644 --- a/runners/mediawiki/mediawiki.h +++ b/runners/mediawiki/mediawiki.h @@ -1,142 +1,142 @@ /* * Copyright 2009 by Richard Moore * Copyright 2009 by Sebastian K?gler * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Library General Public License as * published by the Free Software Foundation; either version 2, 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 MEDIAWIKI_H #define MEDIAWIKI_H // Qt #include #include #include class QNetworkReply; class QIODevice; /** * Searches MediaWiki based wikis like wikipedia and techbase. * * @author Richard Moore, rich@kde.org */ class MediaWiki : public QObject { Q_OBJECT public: /** * Contains information about a single match from the search. */ class Result { public: Result() { } Result( const Result &r ) { this->title = r.title; this->url = r.url; } Result &operator= (const Result &other) { this->title = other.title; this->url = other.url; return *this; } /** The page title of the match. */ QString title; /** The URL of the page containing the match. */ QUrl url; }; /** * Create a media wiki querying object with the specified parent. The querying - * object can be used for multple queries, though only one can be performed at + * object can be used for multiple queries, though only one can be performed at * a time. * @param parent The parent object */ explicit MediaWiki(QObject *parent = nullptr); ~MediaWiki() override; /** * @returns a list of matches. */ QList results() const; /** @returns the currently specified maximum number of results to return. */ int maxItems() const; /** Sets the maximum number of results to return. * - * @param limit Maximumber number of results to retrieve + * @param limit Maximum number number of results to retrieve */ void setMaxItems( int limit ); /** @returns the currently specified API URL. */ QUrl apiUrl() const; /** * Sets the URL at which the wikis API page can be found. For example, wikipedia - * has the API file at http://en.wikipedia.org/w/api.php whilst techbase has the + * has the API file at https://en.wikipedia.org/w/api.php whilst techbase has the * - * @param url The URL of the api.php file, for example http://techbase.kde.org/api.php + * @param url The URL of the api.php file, for example https://techbase.kde.org/api.php */ void setApiUrl( const QUrl &url ); /** @returns the currently specified timeout in milliseconds. */ int timeout() const; /** * Sets timeout in milliseconds. Once the specified time has elapsed, the current * query is aborted. * * @param millis Query timeout in milliseconds */ void setTimeout( int millis ); Q_SIGNALS: /** * Emitted when a search has been completed. * @param success true if the search was completed successfully. */ void finished( bool success ); public Q_SLOTS: /** * Search the wiki for the specified search term. */ void search( const QString &searchTerm ); /** * Aborts the currently running request. */ void abort(); private Q_SLOTS: void onNetworkRequestFinished(QNetworkReply *reply); private: void findBase(); bool processBaseResult( QIODevice *source ); bool processSearchResult( QIODevice *source ); struct MediaWikiPrivate * const d; }; #endif // MEDIAWIKI_H