digiKam
piwigotalker.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 : 2014-09-30
7  * Description : a tool to export items to Piwigo web service
8  *
9  * Copyright (C) 2003-2005 by Renchi Raju <renchi dot raju at gmail dot com>
10  * Copyright (C) 2006 by Colin Guthrie <kde at colin dot guthr dot ie>
11  * Copyright (C) 2006-2022 by Gilles Caulier <caulier dot gilles at gmail dot com>
12  * Copyright (C) 2008 by Andrea Diamantini <adjam7 at gmail dot com>
13  * Copyright (C) 2010-2019 by Frederic Coiffier <frederic dot coiffier at free dot com>
14  *
15  * This program is free software; you can redistribute it
16  * and/or modify it under the terms of the GNU General
17  * Public License as published by the Free Software Foundation;
18  * either version 2, or (at your option) any later version.
19  *
20  * This program is distributed in the hope that it will be useful,
21  * but WITHOUT ANY WARRANTY; without even the implied warranty of
22  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23  * GNU General Public License for more details.
24  *
25  * ============================================================ */
26 
27 #ifndef DIGIKAM_PIWIGO_TALKER_H
28 #define DIGIKAM_PIWIGO_TALKER_H
29 
30 // Qt includes
31 
32 #include <QObject>
33 #include <QList>
34 #include <QDateTime>
35 #include <QTextStream>
36 #include <QFile>
37 #include <QUrl>
38 #include <QNetworkReply>
39 #include <QNetworkAccessManager>
40 
41 // Local includes
42 
43 #include "piwigoitem.h"
44 #include "dinfointerface.h"
45 
46 using namespace Digikam;
47 
48 template <class T> class QList;
49 
51 {
52 
53 class PiwigoTalker : public QObject
54 {
55  Q_OBJECT
56 
57 public:
58 
59  enum State
60  {
61  GE_LOGOUT = -1,
62  GE_LOGIN = 0,
69  GE_ADDPHOTOSUMMARY
70  };
71 
72  enum
73  {
74  CHUNK_MAX_SIZE = 512*1024,
75  PIWIGO_VER_2_4 = 204
76  };
77 
78 public:
79 
80  explicit PiwigoTalker(DInfoInterface* const iface,
81  QWidget* const parent);
82  ~PiwigoTalker() override;
83 
84 public:
85 
86  bool loggedIn() const;
87 
88  void login(const QUrl& url, const QString& name, const QString& passwd);
89  void listAlbums();
90  void listPhotos(const QString& albumName);
91 
92 /* TODO Implement this function
93  void createAlbum(const QString& parentAlbumName,
94  const QString& albumName,
95  const QString& albumTitle,
96  const QString& albumCaption);
97 */
98 
99  bool addPhoto(int albumId,
100  const QString& photoPath,
101  bool rescale = false,
102  int maxWidth = 1600,
103  int maxHeight = 1600,
104  int quality = 95);
105 
106  void cancel();
107 
108  static QString getAuthToken();
109 
110 Q_SIGNALS:
111 
112  void signalProgressInfo(const QString& msg);
113  void signalError(const QString& msg);
114  void signalLoginFailed(const QString& msg);
115  void signalBusy(bool val);
116  void signalAlbums(const QList<PiwigoAlbum>& albumList);
118  void signalAddPhotoFailed(const QString& msg);
119 
120 private:
121 
122  void parseResponseLogin(const QByteArray& data);
123  void parseResponseGetVersion(const QByteArray& data);
124  void parseResponseListAlbums(const QByteArray& data);
125  void parseResponseDoesPhotoExist(const QByteArray& data);
126  void parseResponseGetInfo(const QByteArray& data);
127  void parseResponseSetInfo(const QByteArray& data);
128 
129  void addNextChunk();
130  void parseResponseAddPhotoChunk(const QByteArray& data);
131  void addPhotoSummary();
132  void parseResponseAddPhotoSummary(const QByteArray& data);
133 
134  QByteArray computeMD5Sum(const QString& filepath);
135  void deleteTemporaryFile();
136 
137 private Q_SLOTS:
138 
139  void slotFinished(QNetworkReply* reply);
140 
141 private:
142 
143  class Private;
144  Private* const d;
145 
146  static QString s_authToken;
147 };
148 
149 } // namespace DigikamGenericPiwigoPlugin
150 
151 #endif // PIWIGOTALKER_H
Definition: piwigotalker.h:54
State
Definition: piwigotalker.h:60
@ GE_GETVERSION
Definition: piwigotalker.h:63
@ GE_LISTALBUMS
Definition: piwigotalker.h:64
@ GE_SETINFO
Definition: piwigotalker.h:67
@ GE_CHECKPHOTOEXIST
Definition: piwigotalker.h:65
@ GE_GETINFO
Definition: piwigotalker.h:66
@ GE_ADDPHOTOCHUNK
Definition: piwigotalker.h:68
void signalProgressInfo(const QString &msg)
void signalAlbums(const QList< PiwigoAlbum > &albumList)
void signalLoginFailed(const QString &msg)
void signalError(const QString &msg)
void signalAddPhotoFailed(const QString &msg)
void listPhotos(const QString &albumName)
Definition: dinfointerface.h:56
Definition: piwigotalker.h:48
Definition: piwigoitem.h:35
Definition: datefolderview.cpp:43