File indexing completed on 2024-05-12 16:59:42

0001 // SPDX-FileCopyrightText: 2007 Tobias Koenig <tokoe@kde.org>
0002 // SPDX-FileCopyrightText: 2021 Guo Yunhe <i@guoyunhe.me>
0003 // SPDX-License-Identifier: GPL-2.0-or-later
0004 
0005 #pragma once
0006 
0007 #include <QImage>
0008 #include <QObject>
0009 #include <QUrl>
0010 #include <QVariantList>
0011 
0012 #include <KIO/Job>
0013 #include <KPluginMetaData>
0014 
0015 #include "plasma_potd_export.h"
0016 
0017 class QDate;
0018 
0019 /**
0020  * This class is used to store wallpaper data.
0021  */
0022 struct PotdProviderData {
0023     QImage wallpaperImage;
0024     QString wallpaperLocalUrl;
0025     QUrl wallpaperRemoteUrl;
0026     QUrl wallpaperInfoUrl;
0027     QString wallpaperTitle;
0028     QString wallpaperAuthor;
0029 };
0030 Q_DECLARE_METATYPE(PotdProviderData)
0031 
0032 /**
0033  * This class is an interface for PoTD providers.
0034  */
0035 class PLASMA_POTD_EXPORT PotdProvider : public QObject
0036 {
0037     Q_OBJECT
0038 
0039 public:
0040     /**
0041      * Creates a new PoTD provider.
0042      *
0043      * @param parent The parent object.
0044      * @param data The metadata of the plugin
0045      * @param args The arguments.
0046      */
0047     explicit PotdProvider(QObject *parent, const KPluginMetaData &data, const QVariantList &args);
0048 
0049     /**
0050      * @deprecated Since 5.25. The constructor will be removed in Plasma 6.
0051      */
0052     PLASMA_POTD_DEPRECATED explicit PotdProvider(QObject *parent, const QVariantList &args);
0053 
0054     /**
0055      * Destroys the PoTD provider.
0056      */
0057     ~PotdProvider() override;
0058 
0059     /**
0060      * Returns the requested image.
0061      *
0062      * Note: This method returns only a valid image after the
0063      *       finished() signal has been emitted.
0064      */
0065     virtual QImage image() const;
0066 
0067     /**
0068      * Returns the identifier of the PoTD request (name + date).
0069      */
0070     virtual QString identifier() const;
0071 
0072     /**
0073      * Returns the remote URL of the image from the provider
0074      *
0075      * @note No @c virtual to keep binary compatibility.
0076      * @return the remote URL of the image, if any
0077      * @since 5.25
0078      */
0079     QUrl remoteUrl() const;
0080 
0081     /**
0082      * Returns the information URL of the image from the provider
0083      *
0084      * @return the information URL of the image, if any
0085      * @since 5.25
0086      */
0087     QUrl infoUrl() const;
0088 
0089     /**
0090      * Returns the title of the image from the provider, if any.
0091      *
0092      * @return the title of the image, if any
0093      * @since 5.25
0094      */
0095     QString title() const;
0096 
0097     /**
0098      * Returns the author of the image from the provider
0099      *
0100      * @return the title of the image, if any
0101      * @since 5.25
0102      */
0103     QString author() const;
0104 
0105     /**
0106      * @return the name of this provider (equiv to X-KDE-PlasmaPoTDProvider-Identifier)
0107      */
0108     QString name() const;
0109 
0110     /**
0111      * @return the date to load for this item, if any
0112      */
0113     QDate date() const;
0114 
0115     /**
0116      * @return if the date is fixed, or if it should always be "today"
0117      */
0118     bool isFixedDate() const;
0119 
0120     void refreshConfig();
0121     void loadConfig();
0122 
0123 Q_SIGNALS:
0124     /**
0125      * This signal is emitted whenever a request has been finished
0126      * successfully.
0127      *
0128      * @param provider The provider which emitted the signal.
0129      */
0130     void finished(PotdProvider *provider);
0131 
0132     /**
0133      * This signal is emitted whenever an error has occurred.
0134      *
0135      * @param provider The provider which emitted the signal.
0136      */
0137     void error(PotdProvider *provider);
0138 
0139     void configLoaded(QString apiKey, QString apiSecret);
0140 
0141 protected:
0142     PotdProviderData *potdProviderData() const;
0143 
0144 private:
0145     void configRequestFinished(KJob *job);
0146     void configWriteFinished(KJob *job);
0147 
0148     const QScopedPointer<class PotdProviderPrivate> d;
0149 
0150     QUrl configRemoteUrl;
0151     QUrl configLocalUrl;
0152     QString configLocalPath;
0153     bool refreshed = false;
0154 };