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

0001 /* ============================================================
0002  *
0003  * This file is a part of digiKam project
0004  * https://www.digikam.org
0005  *
0006  * Date        : 2012-02-02
0007  * Description : a tool to export items to ImageShack web service
0008  *
0009  * SPDX-FileCopyrightText: 2012      by Dodon Victor <dodonvictor at gmail dot com>
0010  * SPDX-FileCopyrightText: 2013-2018 by Caulier Gilles <caulier dot gilles at gmail dot com>
0011  *
0012  * SPDX-License-Identifier: GPL-2.0-or-later
0013  *
0014  * ============================================================ */
0015 
0016 #ifndef DIGIKAM_IMAGE_SHACK_TALKER_H
0017 #define DIGIKAM_IMAGE_SHACK_TALKER_H
0018 
0019 // Qt includes
0020 
0021 #include <QObject>
0022 #include <QString>
0023 #include <QMap>
0024 #include <QNetworkReply>
0025 
0026 class QDomElement;
0027 class QByteArray;
0028 
0029 namespace DigikamGenericImageShackPlugin
0030 {
0031 
0032 class ImageShackSession;
0033 
0034 class ImageShackTalker : public QObject
0035 {
0036     Q_OBJECT
0037 
0038 public:
0039 
0040     explicit ImageShackTalker(ImageShackSession* const session);
0041     ~ImageShackTalker()                                                           override;
0042 
0043 public:
0044 
0045     void authenticate();
0046     void cancelLogIn();
0047     void cancel();
0048     void getGalleries();
0049 
0050     void uploadItem(const QString& path, const QMap<QString, QString>& opts);
0051     void uploadItemToGallery(const QString& path,
0052                              const QString& gallery,
0053                              const QMap<QString, QString>& opts);
0054 
0055 Q_SIGNALS:
0056 
0057     void signalBusy(bool busy);
0058     void signalJobInProgress(int step,
0059                              int maxStep = 0,
0060                              const QString& label = QString());
0061     void signalLoginDone(int errCode,  const QString& errMsg);
0062     void signalGetGalleriesDone(int errCode, const QString& errMsg);
0063 
0064     void signalAddPhotoDone(int errCode, const QString& errMsg);
0065     void signalUpdateGalleries(const QStringList& gTexts,
0066                                const QStringList& gNames);
0067 
0068 private Q_SLOTS:
0069 
0070     void slotFinished(QNetworkReply* reply);
0071 
0072 private:
0073 
0074     QString getCallString(QMap<QString, QString>& args)                     const;
0075     void    checkRegistrationCodeDone(int errCode, const QString& errMsg);
0076     void    parseAccessToken(const QByteArray& data);
0077     void    parseGetGalleries(const QByteArray& data);
0078     void    authenticationDone(int errCode, const QString& errMsg);
0079 
0080     void    logOut();
0081 
0082     int     parseErrorResponse(const QDomElement& elem, QString& errMsg)    const;
0083 
0084     void    parseUploadPhotoDone(const QByteArray& data);
0085     void    parseAddPhotoToGalleryDone(const QByteArray& data);
0086 
0087     QString mimeType(const QString& path)                                   const;
0088 
0089 private:
0090 
0091     // Disable
0092     explicit ImageShackTalker(QObject*) = delete;
0093 
0094 private:
0095 
0096     class Private;
0097     Private* const d;
0098 };
0099 
0100 } // namespace DigikamGenericImageShackPlugin
0101 
0102 #endif // DIGIKAM_IMAGE_SHACK_TALKER_H