digiKam
vkontakte_jobs.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 : 2011-02-19
7  * Description : a tool to export images to VKontakte web service
8  *
9  * Copyright (C) 2011-2015 by Alexander Potashev <aspotashev at gmail dot com>
10  * Copyright (C) 2011-2022 by Gilles Caulier <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_VKONTAKTE_JOBS_H
25 #define DIGIKAM_VKONTAKTE_JOBS_H
26 
27 // Qt includes
28 
29 #include <QPointer>
30 
31 // KDE includes
32 
33 #include <KJob>
34 
35 namespace Vkontakte
36 {
37 
38 typedef QPair<QString, QString> QueryItem;
39 
40 class KJobWithSubjob : public KJob
41 {
42  Q_OBJECT
43 
44 public:
45 
46  explicit KJobWithSubjob(QObject* const parent = nullptr);
47 
48 protected:
49 
53  bool doKill() override;
54 
58  QPointer<KJob> m_job;
59 };
60 
61 // ------------------------------------------------------------
62 
63 class KJobWithSubjobs : public KJob
64 {
65  Q_OBJECT
66 
67 public:
68 
69  explicit KJobWithSubjobs(QObject* const parent = nullptr);
70 
71 protected:
72 
76  bool doKill() override;
77 
81  QList<KJob*> m_jobs;
82 };
83 
84 // ------------------------------------------------------------
85 
89 class VkontakteJob : public KJobWithSubjob
90 {
91  Q_OBJECT
92 
93 public:
94 
95  enum JobErrorType
96  {
97  AuthenticationProblem = KJob::UserDefinedError + 42
98  };
99 
100 public:
101 
109  VkontakteJob(const QString& accessToken, const QString& method, bool httpPost = false);
110 
111  void start() override;
112 
113 protected:
114 
118  void addQueryItem(const QString& key, const QString& value);
119 
120 private:
121 
129  bool handleError(const QJsonValue& data);
130 
131  virtual void handleData(const QJsonValue& data) = 0;
132 
136  virtual void prepareQueryItems() {}
137 
138  // TODO: cache url in a member variable
139  KJob* createHttpJob();
140 
141 private Q_SLOTS:
142 
143  void jobFinished(KJob* kjob);
144  void slotRetry();
145 
146 private:
147 
148  QString m_accessToken;
149  QString m_method;
150  bool m_httpPost;
151  QList<QueryItem> m_queryItems;
152 
153 private:
154 
155  // Disable
156  explicit VkontakteJob(QObject*) = delete;
157 };
158 
159 } // namespace Vkontakte
160 
161 #endif // DIGIKAM_VKONTAKTE_JOBS_H
qulonglong value
Definition: itemviewutilities.cpp:592