Warning, file /plasma/kdeplasma-addons/applets/comic/engine/comicprovider.h was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 /*
0002  *   SPDX-FileCopyrightText: 2007 Tobias Koenig <tokoe@kde.org>
0003  *   SPDX-FileCopyrightText: 2022 Alexander Lohnau <alexander.lohnau@gmx.de>
0004  *
0005  *   SPDX-License-Identifier: LGPL-2.0-only
0006  */
0007 
0008 #ifndef COMICPROVIDER_H
0009 #define COMICPROVIDER_H
0010 
0011 #include <KPluginMetaData>
0012 #include <QDate>
0013 #include <QObject>
0014 
0015 #include "types.h"
0016 
0017 class QImage;
0018 class QUrl;
0019 
0020 /**
0021  * This class is an interface for comic providers.
0022  */
0023 class ComicProvider : public QObject
0024 {
0025     Q_OBJECT
0026 
0027 public:
0028     enum RequestType {
0029         Page = 0,
0030         Image,
0031         User,
0032     };
0033 
0034     /**
0035      * Creates a new comic provider.
0036      *
0037      * @param parent The parent object.
0038      * @param args Arguments passed by the plugin loader.
0039      */
0040     ComicProvider(QObject *parent, const KPluginMetaData &data, IdentifierType type, const QVariant &identifier);
0041 
0042     /**
0043      * Destroys the comic provider.
0044      */
0045     ~ComicProvider() override;
0046 
0047     /**
0048      * Returns the type of identifier that is used by this
0049      * comic provider.
0050      */
0051     virtual IdentifierType identifierType() const = 0;
0052 
0053     /**
0054      * Returns the url of the website where the comic of that particular date resides.
0055      */
0056     virtual QUrl websiteUrl() const = 0;
0057 
0058     /**
0059      * Returns the direct url to the comic, if the comic strip is a combination of multiple
0060      * images, then this should return the url to one part of it
0061      * @note the image url is automatically set by requestPage with the ComicProvider::Image id
0062      * @see requestPage
0063      */
0064     virtual QUrl imageUrl() const;
0065 
0066     /**
0067      * Returns the url of the website where the comic has a shop.
0068      */
0069     virtual QUrl shopUrl() const;
0070 
0071     /**
0072      * Returns the requested image.
0073      *
0074      * Note: This method returns only a valid image after the
0075      *       finished() signal has been emitted.
0076      */
0077     virtual QImage image() const = 0;
0078 
0079     /**
0080      * Returns the identifier of the comic request.
0081      */
0082     virtual QString identifier() const = 0;
0083 
0084     /**
0085      * Returns the identifier of the next comic (default: date of next day).
0086      */
0087     virtual QString nextIdentifier() const;
0088 
0089     /**
0090      * Returns the identifier of the previous comic (default: date of previous day
0091      * as long).
0092      */
0093     virtual QString previousIdentifier() const;
0094 
0095     /**
0096      * Returns the identifier of the first strip.
0097      */
0098     virtual QString firstStripIdentifier() const;
0099 
0100     /**
0101      * Returns the author of the comic.
0102      */
0103     virtual QString comicAuthor() const;
0104 
0105     /**
0106      * Returns the title of the strip.
0107      */
0108     virtual QString stripTitle() const;
0109 
0110     /**
0111      * Returns additionalText of the comic.
0112      */
0113     virtual QString additionalText() const;
0114 
0115     /**
0116      * Returns the identifier for the comic
0117      */
0118     virtual QString pluginName() const;
0119 
0120     /**
0121      * Returns the name for the comic
0122      */
0123     virtual QString name() const;
0124 
0125     /**
0126      * Returns whether the comic is leftToRight or not
0127      */
0128     virtual bool isLeftToRight() const;
0129 
0130     /**
0131      * Returns whether the comic is topToBottom or not
0132      */
0133     virtual bool isTopToBottom() const;
0134 
0135     /**
0136      * Returns the plugin info for the comic
0137      */
0138     KPluginMetaData description() const;
0139 
0140     /**
0141      * Set whether this request is for the current comic (only used internally).
0142      */
0143     void setIsCurrent(bool value);
0144 
0145     /**
0146      * Returns whether this request is for the current comic (only used internally).
0147      */
0148     bool isCurrent() const;
0149 
0150 Q_SIGNALS:
0151     /**
0152      * This signal is emitted whenever a request has been finished
0153      * successfully.
0154      *
0155      * @param provider The provider which emitted the signal.
0156      */
0157     void finished(ComicProvider *provider);
0158 
0159     /**
0160      * This signal is emitted whenever an error has occurred.
0161      *
0162      * @param provider The provider which emitted the signal.
0163      */
0164     void error(ComicProvider *provider);
0165 
0166 protected:
0167     /**
0168      * Returns the date identifier that was requested by the applet.
0169      */
0170     QDate requestedDate() const;
0171 
0172     /**
0173      * Returns the numeric identifier that was requested by the applet.
0174      */
0175     int requestedNumber() const;
0176 
0177     /**
0178      * Returns the string identifier that was requested by the applet.
0179      */
0180     QString requestedString() const;
0181 
0182     /**
0183      * @internal
0184      *
0185      * Returns the comic name of the string identifier that was requested by the applet.
0186      */
0187     QString requestedComicName() const;
0188 
0189     /**
0190      * Returns the date of the first available comic strip.
0191      */
0192     QDate firstStripDate() const;
0193 
0194     /**
0195      * Sets the date of the first available comic strip.
0196      */
0197     void setFirstStripDate(const QDate &date);
0198 
0199     /**
0200      * Returns the number of the first available comic strip (default: 1).
0201      */
0202     int firstStripNumber() const;
0203 
0204     /**
0205      * Sets the number of the first available comic strip.
0206      */
0207     void setFirstStripNumber(int number);
0208 
0209     /**
0210      * Sets the name of the comic author.
0211      */
0212     void setComicAuthor(const QString &author);
0213 
0214     typedef QMap<QString, QString> MetaInfos;
0215 
0216     /**
0217      * This method should be used by all comic providers to request
0218      * websites or images from the web. It encapsulates the HTTP
0219      * handling and calls pageRetrieved() or pageError() on success or error.
0220      *
0221      * @param url The url to access.
0222      * @param id A unique id that identifies this request.
0223      * @param infos A list of meta information passed to http.
0224      */
0225     void requestPage(const QUrl &url, int id, const MetaInfos &infos = MetaInfos());
0226 
0227     /**
0228      * This method can be used to find the place url points to, when finished
0229      * urlRetrieved() is called, either with the original url or a redirected url
0230      * @param url to check for redirections
0231      * @param id A unique id that identifies this request.
0232      * @param infos A list of meta information passed to KIO.
0233      */
0234     void requestRedirectedUrl(const QUrl &url, int id, const MetaInfos &infos = MetaInfos());
0235 
0236     /**
0237      * This method is called whenever a request done by requestPage() was successful.
0238      *
0239      * @param id The unique identifier of that request.
0240      * @param data The data of the fetched object.
0241      */
0242     virtual void pageRetrieved(int id, const QByteArray &data);
0243 
0244     /**
0245      * This method is called whenever a request done by requestPage() has failed.
0246      *
0247      * @param id The unique identifier of that request.
0248      * @param message The error message.
0249      */
0250     virtual void pageError(int id, const QString &message);
0251 
0252     /**
0253      * This method is called whenever a request by requestRedirectedUrl() was done
0254      * @param id The unique identifier of that request.
0255      * @param newUrl The redirected Url
0256      */
0257     virtual void redirected(int id, const QUrl &newUrl);
0258 
0259 private:
0260     class Private;
0261     Private *const d;
0262 };
0263 
0264 #endif