digiKam
imgurtalker.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 : 2016-05-27
7  * Description : Implementation of v3 of the Imgur API
8  *
9  * Copyright (C) 2016 by Fabian Vogt <fabian at ritter dash vogt dot de>
10  * Copyright (C) 2016-2020 by Caulier Gilles <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_IMGUR_TALKER_H
25 #define DIGIKAM_IMGUR_TALKER_H
26 
27 // C++ includes
28 
29 #include <atomic>
30 #include <queue>
31 
32 // Qt includes
33 
34 #include <QString>
35 #include <QFile>
36 #include <QUrl>
37 
38 // Local includes
39 
40 #include "o2.h"
41 
43 {
44 
46 {
47  ACCT_INFO,
48  IMG_UPLOAD,
50 };
51 
53 {
55 
56  struct
57  {
58  QString imgpath;
59  QString title;
60  QString description;
61  }
63 
64  struct
65  {
66  QString username;
67  }
69 };
70 
72 {
74 
75  struct ImgurImage
76  {
77  QString name;
78  QString title;
79  QString hash;
80  QString deletehash;
81  QString url;
82  QString description;
83  qulonglong datetime;
84  QString type;
85  bool animated;
86  uint width;
87  uint height;
88  uint size;
89  uint views;
90  qulonglong bandwidth;
91  }
93 
94  struct ImgurAccount
95  {
96  QString username;
97  }
99 };
100 
101 // ----------------------------------------------------------------
102 
106 class ImgurTalker : public QObject
107 {
108 Q_OBJECT
109 
110 public:
111 
112  explicit ImgurTalker(QObject* const parent = nullptr);
113  ~ImgurTalker() override;
114 
115 public:
116 
120  O2& getAuth();
121 
122  unsigned int workQueueLength();
123  void queueWork(const ImgurTalkerAction& action);
124  void cancelAllWork();
125 
126  static QUrl urlForDeletehash(const QString& deletehash);
127 
128 Q_SIGNALS:
129 
133  void signalAuthorized(bool success, const QString& username);
134  void signalAuthError(const QString& msg);
135 
140  void signalRequestPin(const QUrl& url);
141 
145  void signalProgress(unsigned int percent, const ImgurTalkerAction& action);
146  void signalSuccess(const ImgurTalkerResult& result);
147  void signalError(const QString& msg, const ImgurTalkerAction& action);
148 
152  void signalBusy(bool b);
153 
154 public Q_SLOTS:
155 
159  void slotOauthAuthorized();
160 
164  void slotOauthRequestPin(const QUrl& url);
165 
169  void slotOauthFailed();
170 
174  void slotUploadProgress(qint64 sent, qint64 total);
175  void slotReplyFinished();
176 
177 protected:
178 
179  void timerEvent(QTimerEvent* event) override;
180 
181 private:
182 
186  void startWorkTimer();
187 
191  void stopWorkTimer();
192 
196  void addAuthToken(QNetworkRequest* request);
197 
201  void addAnonToken(QNetworkRequest* request);
202 
207  void doWork();
208 
209 private:
210 
211  class Private;
212  Private* const d;
213 };
214 
215 } // namespace DigikamGenericImgUrPlugin
216 
217 #endif // DIGIKAM_IMGUR_TALKER_H
Definition: imgurtalker.h:107
void slotUploadProgress(qint64 sent, qint64 total)
Definition: imgurtalker.cpp:199
void slotOauthFailed()
Definition: imgurtalker.cpp:193
void signalRequestPin(const QUrl &url)
void queueWork(const ImgurTalkerAction &action)
Definition: imgurtalker.cpp:142
void timerEvent(QTimerEvent *event) override
Definition: imgurtalker.cpp:303
void signalAuthError(const QString &msg)
unsigned int workQueueLength()
Definition: imgurtalker.cpp:137
O2 & getAuth()
Definition: imgurtalker.cpp:132
static QUrl urlForDeletehash(const QString &deletehash)
Definition: imgurtalker.cpp:165
void slotOauthRequestPin(const QUrl &url)
Definition: imgurtalker.cpp:187
void signalSuccess(const ImgurTalkerResult &result)
void cancelAllWork()
Definition: imgurtalker.cpp:148
void signalError(const QString &msg, const ImgurTalkerAction &action)
void signalProgress(unsigned int percent, const ImgurTalkerAction &action)
ImgurTalker(QObject *const parent=nullptr)
Definition: imgurtalker.cpp:94
void signalAuthorized(bool success, const QString &username)
void slotReplyFinished()
Definition: imgurtalker.cpp:209
void slotOauthAuthorized()
Definition: imgurtalker.cpp:170
~ImgurTalker() override
Definition: imgurtalker.cpp:122
Definition: imgurimageslist.cpp:47
ImgurTalkerActionType
Definition: imgurtalker.h:46
@ IMG_UPLOAD
Action: upload Result : image.
@ ACCT_INFO
Action: account Result : account.
@ ANON_IMG_UPLOAD
Action: upload Result : image.
QString title
Definition: imgurtalker.h:59
struct DigikamGenericImgUrPlugin::ImgurTalkerAction::@1 upload
QString imgpath
Definition: imgurtalker.h:58
ImgurTalkerActionType type
Definition: imgurtalker.h:54
struct DigikamGenericImgUrPlugin::ImgurTalkerAction::@2 account
QString username
Definition: imgurtalker.h:66
QString description
Definition: imgurtalker.h:60
qulonglong bandwidth
Definition: imgurtalker.h:90
qulonglong datetime
Definition: imgurtalker.h:83
QString deletehash
Definition: imgurtalker.h:80
QString description
Definition: imgurtalker.h:82
struct DigikamGenericImgUrPlugin::ImgurTalkerResult::ImgurImage image
const ImgurTalkerAction * action
Definition: imgurtalker.h:73
struct DigikamGenericImgUrPlugin::ImgurTalkerResult::ImgurAccount account