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

0001 /* ============================================================
0002  *
0003  * This file is a part of digiKam project
0004  * https://www.digikam.org
0005  *
0006  * Date        : 2011-04-12
0007  * Description : A tool to export items to Rajce web service
0008  *
0009  * SPDX-FileCopyrightText: 2011      by Lukas Krejci <krejci.l at centrum dot cz>
0010  * SPDX-FileCopyrightText: 2011-2024 by Gilles Caulier <caulier dot gilles at gmail dot com>
0011  *
0012  * SPDX-License-Identifier: GPL-2.0-or-later
0013  *
0014  * ============================================================ */
0015 
0016 #ifndef DIGIKAM_RAJCE_COMMAND_H
0017 #define DIGIKAM_RAJCE_COMMAND_H
0018 
0019 // Qt includes
0020 
0021 #include <QImage>
0022 #include <QObject>
0023 #include <QString>
0024 
0025 // Local includes
0026 
0027 #include "rajcesession.h"
0028 #include "rajcempform.h"
0029 
0030 class QXmlQuery;
0031 
0032 namespace DigikamGenericRajcePlugin
0033 {
0034 
0035 class RajceCommand : public QObject
0036 {
0037     Q_OBJECT
0038 
0039 public:
0040 
0041     explicit RajceCommand(const QString& name, RajceCommandType commandType);
0042     ~RajceCommand() override;
0043 
0044 public:
0045 
0046     void processResponse(const QString& response, RajceSession& state);
0047 
0048     QString            getXml()          const;
0049     RajceCommandType   commandType()     const;
0050     virtual QByteArray encode()          const;
0051     virtual QString    contentType()     const;
0052 
0053 protected:
0054 
0055     virtual void parseResponse(QXmlQuery& query, RajceSession& state) = 0;
0056     virtual void cleanUpOnError(RajceSession& state)                  = 0;
0057 
0058     // Allow modification in const methods for lazy init to be possible
0059     QMap<QString, QString>& parameters() const;
0060 
0061     // Aooend additional xml after the "parameters"
0062     virtual QString additionalXml()      const;
0063 
0064 private:
0065 
0066     bool parseErrorFromQuery(QXmlQuery& query, RajceSession& state);
0067 
0068 private:
0069 
0070     // Disable
0071     explicit RajceCommand(QObject*)              = delete;
0072     RajceCommand(const RajceCommand&)            = delete;
0073     RajceCommand& operator=(const RajceCommand&) = delete;
0074 
0075 private:
0076 
0077     class Private;
0078     Private* const d;
0079 };
0080 
0081 // -----------------------------------------------------------------------
0082 
0083 class LoginCommand : public RajceCommand
0084 {
0085     Q_OBJECT
0086 
0087 public:
0088 
0089     explicit LoginCommand(const QString& username, const QString& password);
0090 
0091 protected:
0092 
0093     void parseResponse(QXmlQuery& response, RajceSession& state) override;
0094     void cleanUpOnError(RajceSession& state)                     override;
0095 
0096 private:
0097 
0098     // Disable
0099     explicit LoginCommand(QObject*) = delete;
0100 };
0101 
0102 // -----------------------------------------------------------------------
0103 
0104 class OpenAlbumCommand : public RajceCommand
0105 {
0106     Q_OBJECT
0107 
0108 public:
0109 
0110     explicit OpenAlbumCommand(unsigned albumId, const RajceSession& state);
0111 
0112 protected:
0113 
0114     void parseResponse(QXmlQuery& response, RajceSession& state) override;
0115     void cleanUpOnError(RajceSession& state)                     override;
0116 
0117 private:
0118 
0119     // Disable
0120     explicit OpenAlbumCommand(QObject*) = delete;
0121 };
0122 
0123 // -----------------------------------------------------------------------
0124 
0125 class CreateAlbumCommand : public RajceCommand
0126 {
0127     Q_OBJECT
0128 
0129 public:
0130 
0131     explicit CreateAlbumCommand(const QString& name,
0132                                 const QString& description,
0133                                 bool  visible,
0134                                 const RajceSession& state);
0135 
0136 protected:
0137 
0138     void parseResponse(QXmlQuery& response, RajceSession& state) override;
0139     void cleanUpOnError(RajceSession& state)                     override;
0140 
0141 private:
0142 
0143     // Disable
0144     explicit CreateAlbumCommand(QObject*) = delete;
0145 };
0146 
0147 // -----------------------------------------------------------------------
0148 
0149 class CloseAlbumCommand : public RajceCommand
0150 {
0151     Q_OBJECT
0152 
0153 public:
0154 
0155     explicit CloseAlbumCommand(const RajceSession& state);
0156 
0157 protected:
0158 
0159     void parseResponse(QXmlQuery& response, RajceSession& state) override;
0160     void cleanUpOnError(RajceSession& state)                     override;
0161 
0162 private:
0163 
0164     // Disable
0165     explicit CloseAlbumCommand(QObject*) = delete;
0166 };
0167 
0168 // -----------------------------------------------------------------------
0169 
0170 class AlbumListCommand : public RajceCommand
0171 {
0172     Q_OBJECT
0173 
0174 public:
0175 
0176     explicit AlbumListCommand(const RajceSession&);
0177 
0178 protected:
0179 
0180     void parseResponse(QXmlQuery& response, RajceSession& state) override;
0181     void cleanUpOnError(RajceSession& state)                     override;
0182 
0183 private:
0184 
0185     // Disable
0186     explicit AlbumListCommand(QObject*) = delete;
0187 };
0188 
0189 // -----------------------------------------------------------------------
0190 
0191 class AddPhotoCommand : public RajceCommand
0192 {
0193     Q_OBJECT
0194 
0195 public:
0196 
0197     explicit AddPhotoCommand(const    QString& tmpDir,
0198                              const    QString& path,
0199                              unsigned dimension,
0200                              int      jpgQuality,
0201                              const    RajceSession& state);
0202     ~AddPhotoCommand() override;
0203 
0204 public:
0205 
0206     QByteArray encode()                                          const override;
0207     QString    contentType()                                     const override;
0208 
0209 protected:
0210 
0211     void    cleanUpOnError(RajceSession& state)                        override;
0212     void    parseResponse(QXmlQuery& query, RajceSession& state)       override;
0213     QString additionalXml()                                      const override;
0214 
0215 private:
0216 
0217     // Disable
0218     explicit AddPhotoCommand(QObject*) = delete;
0219 
0220 private:
0221 
0222     class Private;
0223     Private* const d;
0224 };
0225 
0226 } // namespace DigikamGenericRajcePlugin
0227 
0228 #endif // DIGIKAM_RAJCE_COMMAND_H