digiKam
ipfstalker.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 : 2012-02-12
7  * Description : a tool to export images to IPFS web service
8  *
9  * Copyright (C) 2018 by Amar Lakshya <amar dot lakshya at xaviers dot edu dot in>
10  * Copyright (C) 2018-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_IPFS_TALKER_H
25 #define DIGIKAM_IPFS_TALKER_H
26 
27 // Qt includes
28 
29 #include <QObject>
30 #include <QString>
31 #include <QTimerEvent>
32 
34 {
35 
37 {
38  IMG_UPLOAD, // Action: upload Result: image
39 };
40 
42 {
44 
45  struct
46  {
47  QString imgpath;
48  QString title;
49  QString description;
50  } upload;
51 };
52 
54 {
56 
57  struct IPFSImage
58  {
59  QString name;
60  QString url;
61  uint size;
62  } image;
63 };
64 
65 /* Main class, handles the client side of the globalupload.io API
66  */
67 class IpfsTalker : public QObject
68 {
69 Q_OBJECT
70 
71 public:
72 
73  explicit IpfsTalker(QObject* const parent = nullptr);
74  ~IpfsTalker() override;
75 
76  unsigned int workQueueLength();
77  void queueWork(const IpfsTalkerAction& action);
78  void cancelAllWork();
79 
80 Q_SIGNALS:
81 
82  /* Emitted on progress changes.
83  */
84  void progress(unsigned int percent, const IpfsTalkerAction& action);
85  void success(const IpfsTalkerResult& result);
86  void error(const QString& msg, const IpfsTalkerAction& action);
87 
88  /* Emitted when the status changes.
89  */
90  void busy(bool b);
91 
92 public Q_SLOTS:
93 
94  /* Connected to the current QNetworkReply.
95  */
96  void uploadProgress(qint64 sent, qint64 total);
97  void replyFinished();
98 
99 protected:
100 
101  void timerEvent(QTimerEvent* event) override;
102 
103 private:
104 
105  /* Starts m_work_timer if m_work_queue not empty.
106  */
107  void startWorkTimer();
108 
109  /* Stops m_work_timer if running.
110  */
111  void stopWorkTimer();
112 
113  /* Start working on the first item of m_work_queue
114  * by sending a request.
115  */
116  void doWork();
117 
118 private:
119 
120  class Private;
121  Private* const d;
122 };
123 
124 } // namespace DigikamGenericIpfsPlugin
125 
126 #endif // DIGIKAM_IPFS_TALKER_H
Definition: ipfstalker.h:68
void progress(unsigned int percent, const IpfsTalkerAction &action)
unsigned int workQueueLength()
Definition: ipfstalker.cpp:103
void success(const IpfsTalkerResult &result)
void queueWork(const IpfsTalkerAction &action)
Definition: ipfstalker.cpp:108
IpfsTalker(QObject *const parent=nullptr)
Definition: ipfstalker.cpp:87
void uploadProgress(qint64 sent, qint64 total)
Definition: ipfstalker.cpp:131
~IpfsTalker() override
Definition: ipfstalker.cpp:93
void timerEvent(QTimerEvent *event) override
Definition: ipfstalker.cpp:218
void replyFinished()
Definition: ipfstalker.cpp:139
void cancelAllWork()
Definition: ipfstalker.cpp:114
void error(const QString &msg, const IpfsTalkerAction &action)
Definition: ipfsimageslist.cpp:42
IpfsTalkerActionType
Definition: ipfstalker.h:37
QString title
Definition: ipfstalker.h:48
QString description
Definition: ipfstalker.h:49
struct DigikamGenericIpfsPlugin::IpfsTalkerAction::@6 upload
QString imgpath
Definition: ipfstalker.h:47
IpfsTalkerActionType type
Definition: ipfstalker.h:43
const IpfsTalkerAction * action
Definition: ipfstalker.h:55
struct DigikamGenericIpfsPlugin::IpfsTalkerResult::IPFSImage image