digiKam
rajcecommand.h
Go to the documentation of this file.
1 /* ============================================================
2  *
3  * This file is a part of digiKam project
4  * https://www.digikam.org
5  *
6  * Date : 2011-04-12
7  * Description : A tool to export items to Rajce web service
8  *
9  * Copyright (C) 2011 by Lukas Krejci <krejci.l at centrum dot cz>
10  * Copyright (C) 2011-2022 by Gilles Caulier <caulier dot gilles at gmail dot com>
11  *
12  * This program is free software; you can redistribute it
13  * and/or modify it under the terms of the GNU General
14  * Public License as published by the Free Software Foundation;
15  * either version 2, or (at your option) any later version.
16  *
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20  * GNU General Public License for more details.
21  *
22  * ============================================================ */
23 
24 #ifndef DIGIKAM_RAJCE_COMMAND_H
25 #define DIGIKAM_RAJCE_COMMAND_H
26 
27 // Qt includes
28 
29 #include <QImage>
30 #include <QObject>
31 #include <QString>
32 
33 // Local includes
34 
35 #include "rajcesession.h"
36 #include "rajcempform.h"
37 
38 class QXmlQuery;
39 
41 {
42 
43 class RajceCommand : public QObject
44 {
45  Q_OBJECT
46 
47 public:
48 
49  explicit RajceCommand(const QString& name, RajceCommandType commandType);
50  ~RajceCommand() override;
51 
52 public:
53 
54  void processResponse(const QString& response, RajceSession& state);
55 
56  QString getXml() const;
58  virtual QByteArray encode() const;
59  virtual QString contentType() const;
60 
61 protected:
62 
63  virtual void parseResponse(QXmlQuery& query, RajceSession& state) = 0;
64  virtual void cleanUpOnError(RajceSession& state) = 0;
65 
66  // Allow modification in const methods for lazy init to be possible
67  QMap<QString, QString>& parameters() const;
68 
69  // Aooend additional xml after the "parameters"
70  virtual QString additionalXml() const;
71 
72 private:
73 
74  bool parseErrorFromQuery(QXmlQuery& query, RajceSession& state);
75 
76 private:
77 
78  // Disable
79  explicit RajceCommand(QObject*) = delete;
80  RajceCommand(const RajceCommand&) = delete;
81  RajceCommand& operator=(const RajceCommand&) = delete;
82 
83 private:
84 
85  class Private;
86  Private* const d;
87 };
88 
89 // -----------------------------------------------------------------------
90 
91 class LoginCommand : public RajceCommand
92 {
93  Q_OBJECT
94 
95 public:
96 
97  explicit LoginCommand(const QString& username, const QString& password);
98 
99 protected:
100 
101  void parseResponse(QXmlQuery& response, RajceSession& state) override;
102  void cleanUpOnError(RajceSession& state) override;
103 
104 private:
105 
106  // Disable
107  explicit LoginCommand(QObject*) = delete;
108 };
109 
110 // -----------------------------------------------------------------------
111 
113 {
114  Q_OBJECT
115 
116 public:
117 
118  explicit OpenAlbumCommand(unsigned albumId, const RajceSession& state);
119 
120 protected:
121 
122  void parseResponse(QXmlQuery& response, RajceSession& state) override;
123  void cleanUpOnError(RajceSession& state) override;
124 
125 private:
126 
127  // Disable
128  explicit OpenAlbumCommand(QObject*) = delete;
129 };
130 
131 // -----------------------------------------------------------------------
132 
134 {
135  Q_OBJECT
136 
137 public:
138 
139  explicit CreateAlbumCommand(const QString& name,
140  const QString& description,
141  bool visible,
142  const RajceSession& state);
143 
144 protected:
145 
146  void parseResponse(QXmlQuery& response, RajceSession& state) override;
147  void cleanUpOnError(RajceSession& state) override;
148 
149 private:
150 
151  // Disable
152  explicit CreateAlbumCommand(QObject*) = delete;
153 };
154 
155 // -----------------------------------------------------------------------
156 
158 {
159  Q_OBJECT
160 
161 public:
162 
163  explicit CloseAlbumCommand(const RajceSession& state);
164 
165 protected:
166 
167  void parseResponse(QXmlQuery& response, RajceSession& state) override;
168  void cleanUpOnError(RajceSession& state) override;
169 
170 private:
171 
172  // Disable
173  explicit CloseAlbumCommand(QObject*) = delete;
174 };
175 
176 // -----------------------------------------------------------------------
177 
179 {
180  Q_OBJECT
181 
182 public:
183 
184  explicit AlbumListCommand(const RajceSession&);
185 
186 protected:
187 
188  void parseResponse(QXmlQuery& response, RajceSession& state) override;
189  void cleanUpOnError(RajceSession& state) override;
190 
191 private:
192 
193  // Disable
194  explicit AlbumListCommand(QObject*) = delete;
195 };
196 
197 // -----------------------------------------------------------------------
198 
200 {
201  Q_OBJECT
202 
203 public:
204 
205  explicit AddPhotoCommand(const QString& tmpDir,
206  const QString& path,
207  unsigned dimension,
208  int jpgQuality,
209  const RajceSession& state);
210  ~AddPhotoCommand() override;
211 
212 public:
213 
214  QByteArray encode() const override;
215  QString contentType() const override;
216 
217 protected:
218 
219  void cleanUpOnError(RajceSession& state) override;
220  void parseResponse(QXmlQuery& query, RajceSession& state) override;
221  QString additionalXml() const override;
222 
223 private:
224 
225  // Disable
226  explicit AddPhotoCommand(QObject*) = delete;
227 
228 private:
229 
230  class Private;
231  Private* const d;
232 };
233 
234 } // namespace DigikamGenericRajcePlugin
235 
236 #endif // DIGIKAM_RAJCE_COMMAND_H
Definition: rajcecommand.h:200
QString contentType() const override
Definition: rajcecommand.cpp:562
~AddPhotoCommand() override
Definition: rajcecommand.cpp:496
QByteArray encode() const override
Definition: rajcecommand.cpp:567
void parseResponse(QXmlQuery &query, RajceSession &state) override
Definition: rajcecommand.cpp:506
AddPhotoCommand(const QString &tmpDir, const QString &path, unsigned dimension, int jpgQuality, const RajceSession &state)
Definition: rajcecommand.cpp:463
QString additionalXml() const override
Definition: rajcecommand.cpp:510
void cleanUpOnError(RajceSession &state) override
Definition: rajcecommand.cpp:502
Definition: rajcecommand.h:179
AlbumListCommand(const RajceSession &)
Definition: rajcecommand.cpp:345
void parseResponse(QXmlQuery &response, RajceSession &state) override
Definition: rajcecommand.cpp:351
void cleanUpOnError(RajceSession &state) override
Definition: rajcecommand.cpp:431
Definition: rajcecommand.h:158
CloseAlbumCommand(const RajceSession &state)
Definition: rajcecommand.cpp:336
void parseResponse(QXmlQuery &response, RajceSession &state) override
Definition: rajcecommand.cpp:326
void cleanUpOnError(RajceSession &state) override
Definition: rajcecommand.cpp:330
Definition: rajcecommand.h:134
CreateAlbumCommand(const QString &name, const QString &description, bool visible, const RajceSession &state)
Definition: rajcecommand.cpp:306
void cleanUpOnError(RajceSession &state) override
Definition: rajcecommand.cpp:322
void parseResponse(QXmlQuery &response, RajceSession &state) override
Definition: rajcecommand.cpp:318
Definition: rajcecommand.h:92
void parseResponse(QXmlQuery &response, RajceSession &state) override
Definition: rajcecommand.cpp:265
LoginCommand(const QString &username, const QString &password)
Definition: rajcecommand.cpp:257
void cleanUpOnError(RajceSession &state) override
Definition: rajcecommand.cpp:292
Definition: rajcecommand.h:113
void parseResponse(QXmlQuery &response, RajceSession &state) override
Definition: rajcecommand.cpp:238
void cleanUpOnError(RajceSession &state) override
Definition: rajcecommand.cpp:250
OpenAlbumCommand(unsigned albumId, const RajceSession &state)
Definition: rajcecommand.cpp:231
Definition: rajcecommand.h:44
virtual QString contentType() const
Definition: rajcecommand.cpp:219
virtual QString additionalXml() const
Definition: rajcecommand.cpp:206
virtual void cleanUpOnError(RajceSession &state)=0
virtual QByteArray encode() const
Definition: rajcecommand.cpp:211
QString getXml() const
Definition: rajcecommand.cpp:147
~RajceCommand() override
Definition: rajcecommand.cpp:137
void processResponse(const QString &response, RajceSession &state)
Definition: rajcecommand.cpp:189
QMap< QString, QString > & parameters() const
Definition: rajcecommand.cpp:142
RajceCommandType commandType() const
Definition: rajcecommand.cpp:224
RajceCommand(const QString &name, RajceCommandType commandType)
Definition: rajcecommand.cpp:129
virtual void parseResponse(QXmlQuery &query, RajceSession &state)=0
Definition: rajcesession.h:78
Definition: rajcealbum.h:35
RajceCommandType
Definition: rajcesession.h:40