diff --git a/dataengines/potd/apodprovider.h b/dataengines/potd/apodprovider.h --- a/dataengines/potd/apodprovider.h +++ b/dataengines/potd/apodprovider.h @@ -23,6 +23,10 @@ #include "potdprovider.h" +#include + +class KJob; + /** * This class provides the image for APOD * "Astronomy Picture Of the Day" @@ -59,11 +63,11 @@ QImage image() const override; private: - class Private; - Private* const d; + void pageRequestFinished(KJob *job); + void imageRequestFinished(KJob *job); - Q_PRIVATE_SLOT( d, void pageRequestFinished( KJob* ) ) - Q_PRIVATE_SLOT( d, void imageRequestFinished( KJob* ) ) + private: + QImage mImage; }; #endif diff --git a/dataengines/potd/apodprovider.cpp b/dataengines/potd/apodprovider.cpp --- a/dataengines/potd/apodprovider.cpp +++ b/dataengines/potd/apodprovider.cpp @@ -21,32 +21,32 @@ #include "apodprovider.h" #include -#include #include -#include +#include +#include -class ApodProvider::Private +ApodProvider::ApodProvider(QObject *parent, const QVariantList &args) + : PotdProvider(parent, args) { - public: - Private( ApodProvider *parent ) - : mParent( parent ) - { - } + const QUrl url(QStringLiteral("http://antwrp.gsfc.nasa.gov/apod/")); + + KIO::StoredTransferJob *job = KIO::storedGet(url, KIO::NoReload, KIO::HideProgressInfo); + connect(job, &KIO::StoredTransferJob::finished, this, &ApodProvider::pageRequestFinished); +} - void pageRequestFinished( KJob* ); - void imageRequestFinished( KJob* ); - void parsePage(); +ApodProvider::~ApodProvider() = default; - ApodProvider *mParent; - QImage mImage; -}; +QImage ApodProvider::image() const +{ + return mImage; +} -void ApodProvider::Private::pageRequestFinished( KJob *_job ) +void ApodProvider::pageRequestFinished(KJob *_job) { KIO::StoredTransferJob *job = static_cast( _job ); if ( job->error() ) { - emit mParent->error( mParent ); + emit error(this); return; } @@ -59,43 +59,24 @@ const QString sub = exp.cap(1); const QUrl url(QLatin1String("http://antwrp.gsfc.nasa.gov/apod/") + sub); KIO::StoredTransferJob *imageJob = KIO::storedGet( url, KIO::NoReload, KIO::HideProgressInfo ); - mParent->connect( imageJob, SIGNAL(finished(KJob*)), SLOT(imageRequestFinished(KJob*)) ); + connect(imageJob, &KIO::StoredTransferJob::finished, this, &ApodProvider::imageRequestFinished); } else { - emit mParent->error( mParent ); + emit error(this); } } -void ApodProvider::Private::imageRequestFinished( KJob *_job ) +void ApodProvider::imageRequestFinished(KJob *_job) { KIO::StoredTransferJob *job = static_cast( _job ); if ( job->error() ) { - emit mParent->error( mParent ); + emit error(this); return; } mImage = QImage::fromData( job->data() ); - emit mParent->finished( mParent ); -} - -ApodProvider::ApodProvider( QObject *parent, const QVariantList &args ) - : PotdProvider( parent, args ), d( new Private( this ) ) -{ - QUrl url( QLatin1String( "http://antwrp.gsfc.nasa.gov/apod/" ) ); - KIO::StoredTransferJob *job = KIO::storedGet( url, KIO::NoReload, KIO::HideProgressInfo ); - connect( job, SIGNAL(finished(KJob*)), SLOT(pageRequestFinished(KJob*)) ); -} - -ApodProvider::~ApodProvider() -{ - delete d; -} - -QImage ApodProvider::image() const -{ - return d->mImage; + emit finished(this); } K_PLUGIN_FACTORY_WITH_JSON(ApodProviderFactory, "apodprovider.json", registerPlugin();) -#include "moc_apodprovider.cpp" #include "apodprovider.moc" diff --git a/dataengines/potd/bingprovider.h b/dataengines/potd/bingprovider.h --- a/dataengines/potd/bingprovider.h +++ b/dataengines/potd/bingprovider.h @@ -21,6 +21,10 @@ #define BINGPROVIDER_H #include "potdprovider.h" +// Qt +#include + +class KJob; /** * This class provides the image for the Bing's homepage @@ -53,12 +57,11 @@ QImage image() const override; private: - class Private; - Private* const d; + void pageRequestFinished(KJob *job); + void imageRequestFinished(KJob *job); - Q_PRIVATE_SLOT( d, void pageRequestFinished( KJob* ) ) - Q_PRIVATE_SLOT( d, void imageRequestFinished( KJob* ) ) + private: + QImage mImage; }; #endif - diff --git a/dataengines/potd/bingprovider.cpp b/dataengines/potd/bingprovider.cpp --- a/dataengines/potd/bingprovider.cpp +++ b/dataengines/potd/bingprovider.cpp @@ -19,35 +19,34 @@ #include "bingprovider.h" -#include -#include #include #include #include -#include +#include +#include -class BingProvider::Private +BingProvider::BingProvider(QObject* parent, const QVariantList& args) + : PotdProvider(parent, args) { -public: - Private(BingProvider* parent) - : mParent(parent) - { - } + const QUrl url(QStringLiteral("https://www.bing.com/HPImageArchive.aspx?format=js&idx=0&n=1")); - void pageRequestFinished(KJob*); - void imageRequestFinished(KJob*); - void parsePage(); + KIO::StoredTransferJob* job = KIO::storedGet(url, KIO::NoReload, KIO::HideProgressInfo); + connect(job, &KIO::StoredTransferJob::finished, this, &BingProvider::pageRequestFinished); +} - BingProvider* mParent; - QImage mImage; -}; +BingProvider::~BingProvider() = default; -void BingProvider::Private::pageRequestFinished(KJob* _job) +QImage BingProvider::image() const +{ + return mImage; +} + +void BingProvider::pageRequestFinished(KJob* _job) { KIO::StoredTransferJob* job = static_cast(_job); if (job->error()) { - emit mParent->error(mParent); + emit error(this); return; } @@ -70,47 +69,26 @@ } QUrl picUrl(QStringLiteral("https://www.bing.com/%1").arg(url.toString())); KIO::StoredTransferJob* imageJob = KIO::storedGet(picUrl, KIO::NoReload, KIO::HideProgressInfo); - mParent->connect(imageJob, SIGNAL(finished(KJob*)), SLOT(imageRequestFinished(KJob*))); + connect(imageJob, &KIO::StoredTransferJob::finished, this, &BingProvider::imageRequestFinished); return; } while (0); - emit mParent->error(mParent); + emit error(this); return; } -void BingProvider::Private::imageRequestFinished(KJob* _job) +void BingProvider::imageRequestFinished(KJob* _job) { KIO::StoredTransferJob* job = static_cast(_job); if (job->error()) { - emit mParent->error(mParent); + emit error(this); return; } QByteArray data = job->data(); mImage = QImage::fromData(data); - emit mParent->finished(mParent); -} - -BingProvider::BingProvider(QObject* parent, const QVariantList& args) - : PotdProvider(parent, args), d(new Private(this)) -{ - QUrl url(QStringLiteral("https://www.bing.com/HPImageArchive.aspx?format=js&idx=0&n=1")); - - KIO::StoredTransferJob* job = KIO::storedGet(url, KIO::NoReload, KIO::HideProgressInfo); - connect(job, SIGNAL(finished(KJob*)), SLOT(pageRequestFinished(KJob*))); -} - -BingProvider::~BingProvider() -{ - delete d; -} - -QImage BingProvider::image() const -{ - return d->mImage; + emit finished(this); } K_PLUGIN_FACTORY_WITH_JSON(BingProviderFactory, "bingprovider.json", registerPlugin();) #include "bingprovider.moc" -#include "moc_bingprovider.cpp" - diff --git a/dataengines/potd/cachedprovider.cpp b/dataengines/potd/cachedprovider.cpp --- a/dataengines/potd/cachedprovider.cpp +++ b/dataengines/potd/cachedprovider.cpp @@ -25,7 +25,7 @@ #include #include #include -#include +#include #include diff --git a/dataengines/potd/epodprovider.h b/dataengines/potd/epodprovider.h --- a/dataengines/potd/epodprovider.h +++ b/dataengines/potd/epodprovider.h @@ -22,6 +22,10 @@ #define EPODPROVIDER_H #include "potdprovider.h" +// Qt +#include + +class KJob; /** * This class provides the image for EPOD @@ -55,11 +59,11 @@ QImage image() const override; private: - class Private; - Private* const d; + void pageRequestFinished(KJob *job); + void imageRequestFinished(KJob *job); - Q_PRIVATE_SLOT( d, void pageRequestFinished( KJob* ) ) - Q_PRIVATE_SLOT( d, void imageRequestFinished( KJob* ) ) + private: + QImage mImage; }; #endif diff --git a/dataengines/potd/epodprovider.cpp b/dataengines/potd/epodprovider.cpp --- a/dataengines/potd/epodprovider.cpp +++ b/dataengines/potd/epodprovider.cpp @@ -21,32 +21,32 @@ #include "epodprovider.h" #include -#include #include -#include +#include +#include -class EpodProvider::Private +EpodProvider::EpodProvider( QObject *parent, const QVariantList &args ) + : PotdProvider(parent, args) { - public: - Private( EpodProvider *parent ) - : mParent( parent ) - { - } + const QUrl url(QStringLiteral("http://epod.usra.edu/blog/")); - void pageRequestFinished(KJob*); - void imageRequestFinished(KJob*); - void parsePage(); + KIO::StoredTransferJob *job = KIO::storedGet(url, KIO::NoReload, KIO::HideProgressInfo); + connect(job, &KIO::StoredTransferJob::finished, this, &EpodProvider::pageRequestFinished); +} - EpodProvider *mParent; - QImage mImage; -}; +EpodProvider::~EpodProvider() = default; + +QImage EpodProvider::image() const +{ + return mImage; +} -void EpodProvider::Private::pageRequestFinished(KJob *_job) +void EpodProvider::pageRequestFinished(KJob *_job) { KIO::StoredTransferJob *job = static_cast(_job); if ( job->error() ) { - emit mParent->error( mParent ); + emit error(this); return; } @@ -60,42 +60,22 @@ const QString sub = data.mid( pos-4, pattern.length()+6); const QUrl url(QStringLiteral("http://epod.usra.edu/.a/%1-pi").arg(sub)); KIO::StoredTransferJob *imageJob = KIO::storedGet( url, KIO::NoReload, KIO::HideProgressInfo ); - QObject::connect(imageJob, SIGNAL(finished(KJob*)), mParent, SLOT(imageRequestFinished(KJob*)) ); + connect(imageJob, &KIO::StoredTransferJob::finished, this, &EpodProvider::imageRequestFinished); } -void EpodProvider::Private::imageRequestFinished( KJob *_job) +void EpodProvider::imageRequestFinished(KJob *_job) { KIO::StoredTransferJob *job = static_cast(_job); if ( job->error() ) { - emit mParent->error( mParent ); + emit error(this); return; } // FIXME: this really should be done in a thread as this can block mImage = QImage::fromData( job->data() ); - emit mParent->finished( mParent ); -} - -EpodProvider::EpodProvider( QObject *parent, const QVariantList &args ) - : PotdProvider( parent, args ), d( new Private( this ) ) -{ - QUrl url( QLatin1String( "http://epod.usra.edu/blog/" ) ); - KIO::StoredTransferJob *job = KIO::storedGet( url, KIO::NoReload, KIO::HideProgressInfo ); - - connect( job, SIGNAL(finished(KJob*)), SLOT(pageRequestFinished(KJob*)) ); -} - -EpodProvider::~EpodProvider() -{ - delete d; -} - -QImage EpodProvider::image() const -{ - return d->mImage; + emit finished(this); } K_PLUGIN_FACTORY_WITH_JSON(EpodProviderFactory, "epodprovider.json", registerPlugin();) -#include "moc_epodprovider.cpp" #include "epodprovider.moc" diff --git a/dataengines/potd/flickrprovider.h b/dataengines/potd/flickrprovider.h --- a/dataengines/potd/flickrprovider.h +++ b/dataengines/potd/flickrprovider.h @@ -23,7 +23,12 @@ #define FLICKRPROVIDER_H #include "potdprovider.h" -#include +// Qt +#include +#include +#include + +class KJob; /** * This class grabs a random image from the flickr @@ -58,11 +63,18 @@ QImage image() const override; private: - class Private; - Private* const d; + void pageRequestFinished(KJob *job); + void imageRequestFinished(KJob *job); + + private: + QDate mActualDate; + QImage mImage; + + QXmlStreamReader xml; + + int mFailureNumber = 0; - Q_PRIVATE_SLOT( d, void pageRequestFinished( KJob* ) ) - Q_PRIVATE_SLOT( d, void imageRequestFinished( KJob* ) ) + QStringList m_photoList; }; #endif diff --git a/dataengines/potd/flickrprovider.cpp b/dataengines/potd/flickrprovider.cpp --- a/dataengines/potd/flickrprovider.cpp +++ b/dataengines/potd/flickrprovider.cpp @@ -21,59 +21,54 @@ #include "flickrprovider.h" -#include -#include -#include #include #include -#include +#include +#include #define FLICKR_API_KEY QStringLiteral("11829a470557ad8e10b02e80afacb3af") -class FlickrProvider::Private +static +QUrl buildUrl(const QDate &date) { - public: - Private( FlickrProvider *parent ) - : mParent( parent ) - { - qsrand(QTime(0,0,0).secsTo(QTime::currentTime())); - } + QUrl url(QLatin1String( "https://api.flickr.com/services/rest/")); + QUrlQuery urlQuery(url); + urlQuery.addQueryItem(QStringLiteral("api_key"), FLICKR_API_KEY); + urlQuery.addQueryItem(QStringLiteral("method"), QStringLiteral("flickr.interestingness.getList")); + urlQuery.addQueryItem(QStringLiteral("date"), date.toString(Qt::ISODate)); + // url_o might be either too small or too large. + urlQuery.addQueryItem(QStringLiteral("extras"), QStringLiteral("url_k,url_h,url_o")); + url.setQuery(urlQuery); + + return url; +} - QUrl buildUrl(const QDate &date) { - QUrl url(QLatin1String( "https://api.flickr.com/services/rest/")); - QUrlQuery urlQuery(url); - urlQuery.addQueryItem(QStringLiteral("api_key"), FLICKR_API_KEY); - urlQuery.addQueryItem(QStringLiteral("method"), QStringLiteral("flickr.interestingness.getList")); - urlQuery.addQueryItem(QStringLiteral("date"), date.toString(Qt::ISODate)); - // url_o might be either too small or too large. - urlQuery.addQueryItem(QStringLiteral("extras"), QStringLiteral("url_k,url_h,url_o")); - url.setQuery(urlQuery); - - return url; - } +FlickrProvider::FlickrProvider(QObject *parent, const QVariantList &args) + : PotdProvider(parent, args) +{ + qsrand(QTime(0,0,0).secsTo(QTime::currentTime())); - void pageRequestFinished( KJob* ); - void imageRequestFinished( KJob* ); - void parsePage(); + mActualDate = date(); - FlickrProvider *mParent; - QDate mActualDate; - QImage mImage; + const QUrl url = buildUrl(mActualDate); - QXmlStreamReader xml; + KIO::StoredTransferJob *job = KIO::storedGet(url, KIO::NoReload, KIO::HideProgressInfo); + connect(job, &KIO::StoredTransferJob::finished, this, &FlickrProvider::pageRequestFinished); +} - int mFailureNumber = 0; +FlickrProvider::~FlickrProvider() = default; - private: - QStringList m_photoList; -}; +QImage FlickrProvider::image() const +{ + return mImage; +} -void FlickrProvider::Private::pageRequestFinished( KJob *_job ) +void FlickrProvider::pageRequestFinished(KJob *_job) { KIO::StoredTransferJob *job = static_cast( _job ); if (job->error()) { - emit mParent->error( mParent ); + emit error(this); qDebug() << "pageRequestFinished error"; return; } @@ -100,11 +95,11 @@ mActualDate = mActualDate.addDays(-2); QUrl url = buildUrl(mActualDate); KIO::StoredTransferJob *pageJob = KIO::storedGet(url, KIO::NoReload, KIO::HideProgressInfo); - mParent->connect( pageJob, SIGNAL(finished(KJob*)), SLOT(pageRequestFinished(KJob*)) ); + connect(pageJob, &KIO::StoredTransferJob::finished, this, &FlickrProvider::pageRequestFinished); mFailureNumber++; return; } else { - emit mParent->error(mParent); + emit error(this); qDebug() << "pageRequestFinished error"; return; } @@ -149,45 +144,24 @@ if (m_photoList.begin() != m_photoList.end()) { QUrl url( m_photoList.at(qrand() % m_photoList.size()) ); KIO::StoredTransferJob *imageJob = KIO::storedGet(url, KIO::NoReload, KIO::HideProgressInfo); - mParent->connect( imageJob, SIGNAL(finished(KJob*)), SLOT(imageRequestFinished(KJob*)) ); + connect(imageJob, &KIO::StoredTransferJob::finished, this, &FlickrProvider::imageRequestFinished); } else { qDebug() << "empty list"; } } -void FlickrProvider::Private::imageRequestFinished( KJob *_job ) +void FlickrProvider::imageRequestFinished(KJob *_job) { KIO::StoredTransferJob *job = static_cast( _job ); if ( job->error() ) { - emit mParent->error( mParent ); + emit error(this); return; } mImage = QImage::fromData( job->data() ); - emit mParent->finished( mParent ); -} - -FlickrProvider::FlickrProvider( QObject *parent, const QVariantList &args ) - : PotdProvider( parent, args ), d( new Private( this ) ) -{ - d->mActualDate = date(); - - QUrl url = d->buildUrl(date()); - KIO::StoredTransferJob *job = KIO::storedGet( url, KIO::NoReload, KIO::HideProgressInfo ); - connect( job, SIGNAL(finished(KJob*)), SLOT(pageRequestFinished(KJob*)) ); -} - -FlickrProvider::~FlickrProvider() -{ - delete d; -} - -QImage FlickrProvider::image() const -{ - return d->mImage; + emit finished(this); } K_PLUGIN_FACTORY_WITH_JSON(FlickrProviderFactory, "flickrprovider.json", registerPlugin();) -#include "moc_flickrprovider.cpp" #include "flickrprovider.moc" diff --git a/dataengines/potd/natgeoprovider.h b/dataengines/potd/natgeoprovider.h --- a/dataengines/potd/natgeoprovider.h +++ b/dataengines/potd/natgeoprovider.h @@ -23,6 +23,11 @@ #define NATGEOPROVIDER_H #include "potdprovider.h" +// Qt +#include +#include + +class KJob; /** * This class provides the image for APOD @@ -60,8 +65,13 @@ QImage image() const override; private: - class Private; - Private* const d; + void pageRequestFinished(KJob *job); + void imageRequestFinished(KJob *job); + + private: + QImage mImage; + + QRegularExpression re; }; #endif diff --git a/dataengines/potd/natgeoprovider.cpp b/dataengines/potd/natgeoprovider.cpp --- a/dataengines/potd/natgeoprovider.cpp +++ b/dataengines/potd/natgeoprovider.cpp @@ -21,35 +21,33 @@ #include "natgeoprovider.h" -#include -#include -#include #include +#include #include -class NatGeoProvider::Private + +NatGeoProvider::NatGeoProvider(QObject *parent, const QVariantList &args) + : PotdProvider(parent, args) { - public: - Private( NatGeoProvider *parent ) - : mParent( parent ) - { - } + const QUrl url(QStringLiteral("http://www.nationalgeographic.com/photography/photo-of-the-day/")); - void pageRequestFinished( KJob* ); - void imageRequestFinished( KJob* ); + KIO::StoredTransferJob *job = KIO::storedGet(url, KIO::NoReload, KIO::HideProgressInfo); + connect(job, &KIO::StoredTransferJob::finished, this, &NatGeoProvider::pageRequestFinished); +} - NatGeoProvider *mParent; - QImage mImage; +NatGeoProvider::~NatGeoProvider() = default; - QRegularExpression re; -}; +QImage NatGeoProvider::image() const +{ + return mImage; +} -void NatGeoProvider::Private::pageRequestFinished( KJob* _job ) +void NatGeoProvider::pageRequestFinished(KJob* _job) { KIO::StoredTransferJob *job = static_cast( _job ); if (job->error()) { - emit mParent->error( mParent ); + emit error(this); return; } @@ -68,46 +66,24 @@ } if (url.isEmpty()) { - emit mParent->error( mParent ); + emit error(this); return; } KIO::StoredTransferJob *imageJob = KIO::storedGet( QUrl(url), KIO::NoReload, KIO::HideProgressInfo ); - mParent->connect( imageJob, &KIO::StoredTransferJob::finished, mParent, [this] (KJob *job) { - imageRequestFinished(job); - }); + connect(imageJob, &KIO::StoredTransferJob::finished, this, &NatGeoProvider::imageRequestFinished); } -void NatGeoProvider::Private::imageRequestFinished( KJob *_job ) +void NatGeoProvider::imageRequestFinished(KJob *_job) { KIO::StoredTransferJob *job = static_cast( _job ); if ( job->error() ) { - emit mParent->error( mParent ); + emit error(this); return; } mImage = QImage::fromData( job->data() ); - emit mParent->finished( mParent ); -} - -NatGeoProvider::NatGeoProvider( QObject *parent, const QVariantList &args ) - : PotdProvider( parent, args ), d( new Private( this ) ) -{ - const QUrl url( QLatin1String( "http://www.nationalgeographic.com/photography/photo-of-the-day/" ) ); - KIO::StoredTransferJob *job = KIO::storedGet( url, KIO::NoReload, KIO::HideProgressInfo ); - connect( job, &KIO::StoredTransferJob::finished, this, [this] (KJob *job) { - d->pageRequestFinished(job); - }); -} - -NatGeoProvider::~NatGeoProvider() -{ - delete d; -} - -QImage NatGeoProvider::image() const -{ - return d->mImage; + emit finished(this); } K_PLUGIN_FACTORY_WITH_JSON(NatGeoProviderFactory, "natgeoprovider.json", registerPlugin();) diff --git a/dataengines/potd/noaaprovider.h b/dataengines/potd/noaaprovider.h --- a/dataengines/potd/noaaprovider.h +++ b/dataengines/potd/noaaprovider.h @@ -23,6 +23,10 @@ #define NOAAPROVIDER_H #include "potdprovider.h" +// Qt +#include + +class KJob; /** * This class provides the image for NOAA Environmental Visualization Laboratory @@ -56,8 +60,11 @@ QImage image() const override; private: - class Private; - Private* const d; + void pageRequestFinished(KJob *job); + void imageRequestFinished(KJob *job); + + private: + QImage mImage; }; #endif diff --git a/dataengines/potd/noaaprovider.cpp b/dataengines/potd/noaaprovider.cpp --- a/dataengines/potd/noaaprovider.cpp +++ b/dataengines/potd/noaaprovider.cpp @@ -20,34 +20,34 @@ #include "noaaprovider.h" -#include -#include #include #include -#include +#include +#include -class NOAAProvider::Private + +NOAAProvider::NOAAProvider(QObject *parent, const QVariantList &args) + : PotdProvider(parent, args) { - public: - Private( NOAAProvider *parent ) - : mParent( parent ) - { - } + const QUrl url(QStringLiteral("http://www.nnvl.noaa.gov/imageoftheday.php")); - void pageRequestFinished( KJob* ); - void imageRequestFinished( KJob* ); - void parsePage(); + KIO::StoredTransferJob *job = KIO::storedGet(url, KIO::NoReload, KIO::HideProgressInfo); + connect(job, &KIO::StoredTransferJob::finished, this, &NOAAProvider::pageRequestFinished); +} - NOAAProvider *mParent; - QImage mImage; -}; +NOAAProvider::~NOAAProvider() = default; -void NOAAProvider::Private::pageRequestFinished( KJob* _job ) +QImage NOAAProvider::image() const +{ + return mImage; +} + +void NOAAProvider::pageRequestFinished(KJob* _job) { KIO::StoredTransferJob *job = static_cast( _job ); if (job->error()) { - emit mParent->error( mParent ); + emit error(this); return; } @@ -65,46 +65,24 @@ url = QLatin1String("http://www.nnvl.noaa.gov/") + result.captured(1); } if (url.isEmpty()) { - emit mParent->error( mParent ); + emit error(this); return; } KIO::StoredTransferJob *imageJob = KIO::storedGet( QUrl(url), KIO::NoReload, KIO::HideProgressInfo ); - mParent->connect( imageJob, &KIO::StoredTransferJob::finished, mParent, [this] (KJob* job) { - imageRequestFinished(job); - }); + connect(imageJob, &KIO::StoredTransferJob::finished, this, &NOAAProvider::imageRequestFinished); } -void NOAAProvider::Private::imageRequestFinished( KJob *_job ) +void NOAAProvider::imageRequestFinished(KJob *_job) { KIO::StoredTransferJob *job = static_cast( _job ); if ( job->error() ) { - emit mParent->error( mParent ); + emit error(this); return; } mImage = QImage::fromData( job->data() ); - emit mParent->finished( mParent ); -} - -NOAAProvider::NOAAProvider( QObject *parent, const QVariantList &args ) - : PotdProvider( parent, args ), d( new Private( this ) ) -{ - QUrl url( QLatin1String( "http://www.nnvl.noaa.gov/imageoftheday.php" ) ); - KIO::StoredTransferJob *job = KIO::storedGet( url, KIO::NoReload, KIO::HideProgressInfo ); - connect( job, &KIO::StoredTransferJob::finished, this, [this] (KJob *job) { - d->pageRequestFinished(job); - }); -} - -NOAAProvider::~NOAAProvider() -{ - delete d; -} - -QImage NOAAProvider::image() const -{ - return d->mImage; + emit finished(this); } K_PLUGIN_FACTORY_WITH_JSON(NOAAProviderFactory, "noaaprovider.json", registerPlugin();) diff --git a/dataengines/potd/potdprovider.h b/dataengines/potd/potdprovider.h --- a/dataengines/potd/potdprovider.h +++ b/dataengines/potd/potdprovider.h @@ -21,13 +21,12 @@ #define POTDPROVIDER_H #include -#include - -#include +#include #include "plasma_potd_export.h" class QImage; +class QDate; /** * This class is an interface for PoTD providers. diff --git a/dataengines/potd/potdprovider.cpp b/dataengines/potd/potdprovider.cpp --- a/dataengines/potd/potdprovider.cpp +++ b/dataengines/potd/potdprovider.cpp @@ -19,6 +19,10 @@ #include "potdprovider.h" +// Qt +#include + + class PotdProviderPrivate { public: diff --git a/dataengines/potd/wcpotdprovider.h b/dataengines/potd/wcpotdprovider.h --- a/dataengines/potd/wcpotdprovider.h +++ b/dataengines/potd/wcpotdprovider.h @@ -22,6 +22,10 @@ #define WCPOTDPROVIDER_H #include "potdprovider.h" +// Qt +#include + +class KJob; /** * This class provides the image for the "Wikimedia @@ -58,11 +62,11 @@ QImage image() const override; private: - class Private; - Private* const d; + void pageRequestFinished(KJob *job); + void imageRequestFinished(KJob *job); - Q_PRIVATE_SLOT( d, void pageRequestFinished( KJob* ) ) - Q_PRIVATE_SLOT( d, void imageRequestFinished( KJob* ) ) + private: + QImage mImage; }; #endif diff --git a/dataengines/potd/wcpotdprovider.cpp b/dataengines/potd/wcpotdprovider.cpp --- a/dataengines/potd/wcpotdprovider.cpp +++ b/dataengines/potd/wcpotdprovider.cpp @@ -27,29 +27,39 @@ #include #include -#include +#include +#include -class WcpotdProvider::Private + +WcpotdProvider::WcpotdProvider(QObject *parent, const QVariantList &args) + : PotdProvider(parent, args) { - public: - Private( WcpotdProvider *parent ) - : mParent( parent ) - { - } + QUrl url(QStringLiteral("https://commons.wikimedia.org/w/api.php")); + + QUrlQuery urlQuery(url); + urlQuery.addQueryItem(QStringLiteral("action"), QStringLiteral("parse")); + urlQuery.addQueryItem(QStringLiteral("text"), QStringLiteral("{{Potd}}")); + urlQuery.addQueryItem(QStringLiteral("contentmodel"), QStringLiteral("wikitext")); + urlQuery.addQueryItem(QStringLiteral("prop"), QStringLiteral("images")); + urlQuery.addQueryItem(QStringLiteral("format"), QStringLiteral("json")); + url.setQuery(urlQuery); - void pageRequestFinished( KJob* ); - void imageRequestFinished( KJob* ); - void parsePage(); + KIO::StoredTransferJob *job = KIO::storedGet(url, KIO::NoReload, KIO::HideProgressInfo); + connect(job, &KIO::StoredTransferJob::finished, this, &WcpotdProvider::pageRequestFinished); +} - WcpotdProvider *mParent; - QImage mImage; -}; +WcpotdProvider::~WcpotdProvider() = default; -void WcpotdProvider::Private::pageRequestFinished( KJob *_job ) +QImage WcpotdProvider::image() const +{ + return mImage; +} + +void WcpotdProvider::pageRequestFinished(KJob *_job) { KIO::StoredTransferJob *job = static_cast( _job ); if ( job->error() ) { - emit mParent->error( mParent ); + emit error(this); return; } @@ -63,54 +73,26 @@ if (!imageFile.isEmpty()) { const QUrl picUrl(QLatin1String("https://commons.wikimedia.org/wiki/Special:FilePath/") + imageFile); KIO::StoredTransferJob *imageJob = KIO::storedGet( picUrl, KIO::NoReload, KIO::HideProgressInfo ); - mParent->connect( imageJob, SIGNAL(finished(KJob*)), SLOT(imageRequestFinished(KJob*)) ); + connect(imageJob, &KIO::StoredTransferJob::finished, this, &WcpotdProvider::imageRequestFinished); return; } } - emit mParent->error(mParent); + emit error(this); } -void WcpotdProvider::Private::imageRequestFinished( KJob *_job ) +void WcpotdProvider::imageRequestFinished(KJob *_job) { KIO::StoredTransferJob *job = static_cast( _job ); if ( job->error() ) { - emit mParent->error( mParent ); + emit error(this); return; } QByteArray data = job->data(); mImage = QImage::fromData( data ); - emit mParent->finished( mParent ); -} - -WcpotdProvider::WcpotdProvider( QObject *parent, const QVariantList &args ) - : PotdProvider( parent, args ), d( new Private( this ) ) -{ - QUrl url(QStringLiteral("https://commons.wikimedia.org/w/api.php")); - - QUrlQuery urlQuery(url); - urlQuery.addQueryItem(QStringLiteral("action"), QStringLiteral("parse")); - urlQuery.addQueryItem(QStringLiteral("text"), QStringLiteral("{{Potd}}")); - urlQuery.addQueryItem(QStringLiteral("contentmodel"), QStringLiteral("wikitext")); - urlQuery.addQueryItem(QStringLiteral("prop"), QStringLiteral("images")); - urlQuery.addQueryItem(QStringLiteral("format"), QStringLiteral("json")); - url.setQuery(urlQuery); - - KIO::StoredTransferJob *job = KIO::storedGet( url, KIO::NoReload, KIO::HideProgressInfo ); - connect( job, SIGNAL(finished(KJob*)), SLOT(pageRequestFinished(KJob*)) ); -} - -WcpotdProvider::~WcpotdProvider() -{ - delete d; -} - -QImage WcpotdProvider::image() const -{ - return d->mImage; + emit finished(this); } K_PLUGIN_FACTORY_WITH_JSON(WcpotdProviderFactory, "wcpotdprovider.json", registerPlugin();) #include "wcpotdprovider.moc" -#include "moc_wcpotdprovider.cpp"