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

0001 /* ============================================================
0002  *
0003  * This file is a part of digiKam project
0004  * https://www.digikam.org
0005  *
0006  * Date        : 2008-12-01
0007  * Description : a tool to export images to Smugmug web service
0008  *
0009  * SPDX-FileCopyrightText: 2008-2009 by Luka Renko <lure at kubuntu dot org>
0010  * SPDX-FileCopyrightText: 2008-2024 by Gilles Caulier <caulier dot gilles at gmail dot com>
0011  * SPDX-FileCopyrightText: 2018      by Thanh Trung Dinh <dinhthanhtrung1996 at gmail dot com>
0012  *
0013  * SPDX-License-Identifier: GPL-2.0-or-later
0014  *
0015  * ============================================================ */
0016 
0017 #ifndef DIGIKAM_SMUG_TALKER_H
0018 #define DIGIKAM_SMUG_TALKER_H
0019 
0020 // Qt includes
0021 
0022 #include <QList>
0023 #include <QString>
0024 #include <QObject>
0025 
0026 // local includes
0027 
0028 #include "smugitem.h"
0029 #include "dinfointerface.h"
0030 
0031 // OAuth2 library includes
0032 
0033 #if defined(Q_CC_CLANG)
0034 #   pragma clang diagnostic push
0035 #   pragma clang diagnostic ignored "-Wextra-semi"
0036 #endif
0037 
0038 #include "o0globals.h"
0039 #include "o1smugmug.h"
0040 #include "o1requestor.h"
0041 
0042 #if defined(Q_CC_CLANG)
0043 #   pragma clang diagnostic pop
0044 #endif
0045 
0046 class QNetworkReply;
0047 
0048 using namespace Digikam;
0049 
0050 namespace DigikamGenericSmugPlugin
0051 {
0052 
0053 class SmugTalker : public QObject
0054 {
0055     Q_OBJECT
0056 
0057 public:
0058 
0059     explicit SmugTalker(DInfoInterface* const iface, QWidget* const parent);
0060     ~SmugTalker() override;
0061 
0062 public:
0063 
0064     SmugUser getUser() const;
0065 
0066     bool    loggedIn() const;
0067     void    cancel();
0068 
0069     void    link();
0070     void    unlink();
0071     void    removeUserAccount(const QString& userName);
0072     void    login();
0073     void    getLoginedUser();
0074     void    logout();
0075 
0076     void    listAlbums(const QString& nickName = QString());
0077     void    listPhotos(qint64 albumID,
0078                        const QString& albumKey,
0079                        const QString& albumPassword = QString(),
0080                        const QString& sitePassword = QString());
0081     void    listAlbumTmpl();
0082 
0083 /*  Categories are deprecated in API v2
0084     void    listCategories();
0085     void    listSubCategories(qint64 categoryID);
0086 */
0087 
0088     void    createAlbum(const SmugAlbum& album);
0089 
0090     bool    addPhoto(const QString& imgPath,
0091                      qint64 albumID,
0092                      const QString& albumKey,
0093                      const QString& caption);
0094 
0095     void    getPhoto(const QString& imgPath);
0096 
0097     QString createAlbumName(const QString& word);
0098 
0099     QString createAlbumUrl(const QString& name);
0100 
0101 Q_SIGNALS:
0102 
0103     void signalBusy(bool val);
0104     void signalLinkingSucceeded();
0105     void signalLoginProgress(int step,
0106                             int maxStep = 0,
0107                             const QString& label = QString());
0108     void signalLoginDone(int errCode, const QString& errMsg);
0109 
0110     void signalAddPhotoDone(int errCode, const QString& errMsg);
0111 
0112     void signalGetPhotoDone(int errCode, const QString& errMsg,
0113                             const QByteArray& photoData);
0114     void signalCreateAlbumDone(int errCode, const QString& errMsg, qint64 newAlbumID,
0115                                const QString& newAlbumKey);
0116     void signalListAlbumsDone(int errCode, const QString& errMsg,
0117                               const QList <SmugAlbum>& albumsList);
0118     void signalListPhotosDone(int errCode, const QString& errMsg,
0119                               const QList <SmugPhoto>& photosList);
0120     void signalListAlbumTmplDone(int errCode, const QString& errMsg,
0121                                  const QList <SmugAlbumTmpl>& albumTList);
0122 
0123 /* Categories deprecated in API v2
0124 
0125     void signalListCategoriesDone(int errCode, const QString& errMsg,
0126                                   const QList <SmugCategory>& categoriesList);
0127     void signalListSubCategoriesDone(int errCode, const QString& errMsg,
0128                                      const QList <SmugCategory>& categoriesList);
0129 */
0130 
0131 private:
0132 
0133     QString htmlToText(const QString& htmlText) const;
0134     QString errorToText(int errCode, const QString& errMsg) const;
0135     void parseResponseLogin(const QByteArray& data);
0136 
0137 //     void parseResponseLogout(const QByteArray& data);
0138 
0139     void parseResponseAddPhoto(const QByteArray& data);
0140     void parseResponseCreateAlbum(const QByteArray& data);
0141     void parseResponseListAlbums(const QByteArray& data);
0142     void parseResponseListPhotos(const QByteArray& data);
0143     void parseResponseListAlbumTmpl(const QByteArray& data);
0144 
0145 /*  Categories deprecated in API v2
0146 
0147     void parseResponseListCategories(const QByteArray& data);
0148     void parseResponseListSubCategories(const QByteArray& data);
0149 */
0150 
0151 private Q_SLOTS:
0152 
0153     void slotFinished(QNetworkReply* reply);
0154     void slotLinkingFailed();
0155     void slotLinkingSucceeded();
0156     void slotOpenBrowser(const QUrl& url);
0157     void slotCloseBrowser();
0158 
0159 private:
0160 
0161     class Private;
0162     Private* const d;
0163 };
0164 
0165 } // namespace DigikamGenericSmugPlugin
0166 
0167 #endif // DIGIKAM_SMUG_TALKER_H