Debian Codegraph @

src/backend/uploader/imgur/ImgurWrapper.h

raw symbols SCIP
1 /*
2 * Copyright (C) 2016 Damir Porobic <https://github.com/damirporobic>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18 *
19 */
20
21 #ifndef KSNIP_IMGURWRAPPER_H
22 #define KSNIP_IMGURWRAPPER_H
23
24 #include <QObject>
25 #include <QUrl>
26 #include <QUrlQuery>
27 #include <QNetworkReply>
28 #include <QDomDocument>
29 #include <QImage>
30 #include <QBuffer>
31
32 #include "ImgurResponse.h"
33
34 class ImgurWrapper : public QObject
35 {
36 Q_OBJECT
37 public:
38 explicit ImgurWrapper(const QString &imgurUrl, QObject *parent);
39 void startUpload(const QImage &image, const QString &title, const QString &description, const QByteArray &accessToken = nullptr) const;
40 void getAccessToken(const QByteArray &pin, const QByteArray &clientId, const QByteArray &clientSecret) const;
41 void refreshToken(const QByteArray &refreshToken, const QByteArray &clientId, const QByteArray &clientSecret) const;
42 QUrl pinRequestUrl(const QString &clientId) const;
43
44 signals:
45 void uploadFinished(const ImgurResponse &response) const;
46 void error(QNetworkReply::NetworkError networkError, const QString &message) const;
47 void tokenUpdated(const QString &accessToken, const QString &refreshToken, const QString &username) const;
48 void tokenRefreshRequired() const;
49
50 private:
51 QNetworkAccessManager *mAccessManager;
52 QByteArray mClientId;
53 QString mBaseImgurUrl;
54
55 void handleDataResponse(const QDomElement &element) const;
56 void handleTokenResponse(const QDomElement &element) const;
57
58 private slots:
59 void handleReply(QNetworkReply *reply);
60 };
61
62 #endif // KSNIP_IMGURWRAPPER_H