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

0001 /* ============================================================
0002  *
0003  * This file is a part of digiKam project
0004  * https://www.digikam.org
0005  *
0006  * Date        : 2014-09-30
0007  * Description : a tool to export items to Piwigo web service
0008  *
0009  * SPDX-FileCopyrightText: 2003-2005 by Renchi Raju <renchi dot raju at gmail dot com>
0010  * SPDX-FileCopyrightText: 2006      by Colin Guthrie <kde at colin dot guthr dot ie>
0011  * SPDX-FileCopyrightText: 2006-2024 by Gilles Caulier <caulier dot gilles at gmail dot com>
0012  * SPDX-FileCopyrightText: 2008      by Andrea Diamantini <adjam7 at gmail dot com>
0013  * SPDX-FileCopyrightText: 2010-2019 by Frederic Coiffier <frederic dot coiffier at free dot com>
0014  *
0015  * SPDX-License-Identifier: GPL-2.0-or-later
0016  *
0017  * ============================================================ */
0018 
0019 #ifndef DIGIKAM_PIWIGO_TALKER_H
0020 #define DIGIKAM_PIWIGO_TALKER_H
0021 
0022 // Qt includes
0023 
0024 #include <QObject>
0025 #include <QList>
0026 #include <QDateTime>
0027 #include <QTextStream>
0028 #include <QFile>
0029 #include <QUrl>
0030 #include <QNetworkReply>
0031 
0032 // Local includes
0033 
0034 #include "piwigoitem.h"
0035 #include "dinfointerface.h"
0036 
0037 using namespace Digikam;
0038 
0039 template <class T> class QList;
0040 
0041 namespace DigikamGenericPiwigoPlugin
0042 {
0043 
0044 class PiwigoTalker : public QObject
0045 {
0046     Q_OBJECT
0047 
0048 public:
0049 
0050     enum State
0051     {
0052         PG_LOGOUT = -1,
0053         PG_LOGIN  = 0,
0054         PG_GETVERSION,
0055         PG_LISTALBUMS,
0056         PG_CHECKPHOTOEXIST,
0057         PG_GETINFO,
0058         PG_SETINFO,
0059         PG_ADDPHOTOCHUNK,
0060         PG_ADDPHOTOSUMMARY
0061     };
0062 
0063     enum
0064     {
0065         CHUNK_MAX_SIZE = 512*1024,
0066         PIWIGO_VER_2_4 = 204
0067     };
0068 
0069 public:
0070 
0071     explicit PiwigoTalker(DInfoInterface* const iface,
0072                           QWidget* const parent);
0073     ~PiwigoTalker() override;
0074 
0075 public:
0076 
0077     bool loggedIn() const;
0078 
0079     void login(const QUrl& url, const QString& name, const QString& passwd);
0080     void listAlbums();
0081     void listPhotos(const QString& albumName);
0082 
0083 /* TODO Implement this function
0084     void createAlbum(const QString& parentAlbumName,
0085                      const QString& albumName,
0086                      const QString& albumTitle,
0087                      const QString& albumCaption);
0088 */
0089 
0090     bool addPhoto(int   albumId,
0091                   const QString& photoPath,
0092                   bool  rescale = false,
0093                   int   maxWidth = 1600,
0094                   int   maxHeight = 1600,
0095                   int   quality = 95);
0096 
0097     void cancel();
0098 
0099     static QString getAuthToken();
0100 
0101 Q_SIGNALS:
0102 
0103     void signalProgressInfo(const QString& msg);
0104     void signalError(const QString& msg);
0105     void signalLoginFailed(const QString& msg);
0106     void signalBusy(bool val);
0107     void signalAlbums(const QList<PiwigoAlbum>& albumList);
0108     void signalAddPhotoSucceeded();
0109     void signalAddPhotoFailed(const QString& msg);
0110 
0111 private:
0112 
0113     void parseResponseLogin(const QByteArray& data);
0114     void parseResponseGetVersion(const QByteArray& data);
0115     void parseResponseListAlbums(const QByteArray& data);
0116     void parseResponseDoesPhotoExist(const QByteArray& data);
0117     void parseResponseGetInfo(const QByteArray& data);
0118     void parseResponseSetInfo(const QByteArray& data);
0119 
0120     void addNextChunk();
0121     void parseResponseAddPhotoChunk(const QByteArray& data);
0122     void addPhotoSummary();
0123     void parseResponseAddPhotoSummary(const QByteArray& data);
0124 
0125     QByteArray computeMD5Sum(const QString& filepath);
0126     void deleteTemporaryFile();
0127 
0128 private Q_SLOTS:
0129 
0130     void slotFinished(QNetworkReply* reply);
0131 
0132 private:
0133 
0134     class Private;
0135     Private* const d;
0136 
0137     static QString s_authToken;
0138 };
0139 
0140 } // namespace DigikamGenericPiwigoPlugin
0141 
0142 #endif // PIWIGOTALKER_H