File indexing completed on 2025-01-05 03:53:37

0001 /* ============================================================
0002  *
0003  * This file is a part of digiKam project
0004  * https://www.digikam.org
0005  *
0006  * Date        : 2011-03-22
0007  * Description : a Iface C++ interface
0008  *
0009  * SPDX-FileCopyrightText: 2011-2024 by Gilles Caulier <caulier dot gilles at gmail dot com>
0010  * SPDX-FileCopyrightText: 2011      by Hormiere Guillaume <hormiere dot guillaume at gmail dot com>
0011  * SPDX-FileCopyrightText: 2011      by Manuel Campomanes <campomanes dot manuel at gmail dot com>
0012  *
0013  * SPDX-License-Identifier: GPL-2.0-or-later
0014  *
0015  * ============================================================ */
0016 
0017 #ifndef DIGIKAM_MEDIAWIKI_QUERYREVISION_H
0018 #define DIGIKAM_MEDIAWIKI_QUERYREVISION_H
0019 
0020 // Qt includes
0021 
0022 #include <QDateTime>
0023 #include <QList>
0024 #include <QString>
0025 
0026 // Local includes
0027 
0028 #include "mediawiki_job.h"
0029 #include "mediawiki_revision.h"
0030 
0031 namespace MediaWiki
0032 {
0033 
0034 class Iface;
0035 class QueryRevisionPrivate;
0036 
0037 /**
0038  * @brief QueryRevision job.
0039  *
0040  * Uses for fetch a revision information about one pages of the wiki.
0041  */
0042 class QueryRevision : public Job
0043 {
0044     Q_OBJECT
0045     Q_DECLARE_PRIVATE(QueryRevision)
0046 
0047 public:
0048 
0049     /**
0050      * @brief Direction to list revisions.
0051      */
0052     enum Direction
0053     {
0054         /**
0055          * @brief List newest revisions first.
0056          */
0057         Older,
0058 
0059         /**
0060          * @brief List oldest revisions first.
0061          */
0062         Newer
0063     };
0064 
0065     /**
0066      * @brief Tokens can get for each revision.
0067      */
0068     enum Token
0069     {
0070         /**
0071          * @brief Rollback token.
0072          */
0073         Rollback
0074     };
0075 
0076     /**
0077      * @brief Indicates all possible error conditions found during the processing of the job.
0078      */
0079     enum
0080     {
0081         /**
0082          * @brief The revids= parameter may not be used with the list options (limit, startid, endid, dirNewer, start, end).
0083          */
0084         WrongRevisionId = Job::UserDefinedError + 1,
0085 
0086         /**
0087          * @brief titles, pageids or a generator was used to supply multiple pages, but the limit, startid, endid, dirNewer, user, excludeuser, start and end parameters may only be used on a single page.
0088          */
0089         MultiPagesNotAllowed,
0090 
0091         /**
0092          * @brief The current user is not allowed to read title.
0093          */
0094         TitleAccessDenied,
0095 
0096         /**
0097          * @brief start and startid or end and endid or user and excludeuser cannot be used together
0098          */
0099         TooManyParams,
0100 
0101         /**
0102          * @brief There is no section in rrevid
0103          */
0104         SectionNotFound
0105     };
0106 
0107     /**
0108      * @brief Property.
0109      */
0110     enum Property
0111     {
0112         Ids         = 0x01,
0113         Flags       = 0x02,
0114         Timestamp   = 0x04,
0115         User        = 0x08,
0116         Comment     = 0x10,
0117         Size        = 0x20,
0118         Content     = 0x40
0119     };
0120     Q_DECLARE_FLAGS(Properties, Property)
0121 
0122 public:
0123 
0124     /**
0125      * @brief Constructs a Revision job.
0126      * @param MediaWiki the MediaWiki concerned by the job
0127      * @param parent the QObject parent
0128      */
0129     explicit QueryRevision(Iface& MediaWiki, QObject* const parent = nullptr);
0130 
0131     /**
0132      * @brief Destroys the QueryRevision job.
0133      */
0134     ~QueryRevision() override;
0135 
0136     /**
0137      * @brief Starts the job asynchronously.
0138      */
0139     void start() override;
0140 
0141     /**
0142      * @brief Set the page id.
0143      * @param pageId the page id
0144      */
0145     void setPageId(unsigned int pageId);
0146 
0147     /**
0148      * @param Set the revision id.
0149      * @param revisionId the revision id
0150      */
0151     void setRevisionId(unsigned int revisionId);
0152 
0153     /**
0154      * @brief Set the page name.
0155      * @param pageName the page name
0156      */
0157     void setPageName(const QString& pageName);
0158 
0159     /**
0160      * @brief Which properties to get for each revision.
0161      * @param properties the properties to get for each revision
0162      */
0163     void setProperties(Properties properties);
0164 
0165     /**
0166      * @brief Set the maximum number of revisions to return.
0167      * @param limit the maximum number of revisions to return
0168      */
0169     void setLimit(int limit);
0170 
0171     /**
0172      * @brief Set the revision ID to start listing from.
0173      * @param startId the revision ID to start listing from
0174      */
0175     void setStartId(int startId);
0176 
0177     /**
0178      * @brief Set the revision ID to stop listing at.
0179      * @param endId the revision ID to stop listing at
0180      */
0181     void setEndId(int endId);
0182 
0183     /**
0184      * @brief Set the timestamp to start listing from.
0185      * @param start the timestamp to start listing from
0186      */
0187     void setStartTimestamp(const QDateTime& start);
0188 
0189     /**
0190      * @brief Set the timestamp to end listing at.
0191      * @param end the timestamp to end listing at
0192      */
0193     void setEndTimestamp(const QDateTime& end);
0194 
0195     /**
0196      * @brief Set the user.
0197      *
0198      * Do list revisions made by this user.
0199      *
0200      * @param user the user
0201      */
0202     void setUser(const QString& user);
0203 
0204     /**
0205      * @brief Set the user to exclude.
0206      *
0207      * Do not list revisions made by this user
0208      *
0209      * @param excludeUser the user to exclude
0210      */
0211     void setExcludeUser(const QString& excludeUser);
0212 
0213     /**
0214      * @brief Set the direction to list revisions.
0215      * @param direction the direction to list revisions
0216      */
0217     void setDirection(QueryRevision::Direction direction);
0218 
0219     /**
0220      * @brief Set XML generation to parse tree for revision content.
0221      * @param generateXML if true set XML generation to parse tree for revision content
0222      */
0223     void setGenerateXML(bool generateXML);
0224 
0225     /**
0226      * @brief Set the section.
0227      *
0228      * If the property content is set, only retrieve the contents of this section.
0229      *
0230      * @param section the section
0231      */
0232     void setSection(int section);
0233 
0234     /**
0235      * @brief Set the token to get for each revision.
0236      * @param token the token to get for each revision
0237      */
0238     void setToken(QueryRevision::Token token);
0239 
0240     /**
0241      * @brief Set expand templates.
0242      *
0243      * Only if the property content is set.
0244      *
0245      * @param expandTemplates if true set expand templates
0246      */
0247     void setExpandTemplates(bool expandTemplates);
0248 
0249 Q_SIGNALS:
0250 
0251     /**
0252      * @brief Provides a list of all user groups.
0253      * @param revision list of all user groups
0254      */
0255     void revision(const QList<Revision>& revision);
0256 
0257 private Q_SLOTS:
0258 
0259     void doWorkSendRequest();
0260     void doWorkProcessReply();
0261 };
0262 
0263 Q_DECLARE_OPERATORS_FOR_FLAGS(QueryRevision::Properties)
0264 
0265 } // namespace MediaWiki
0266 
0267 #endif // DIGIKAM_MEDIAWIKI_QUERYREVISION_H