1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119
|
/* ============================================================
*
* This file is a part of KDE project
*
*
* Date : 2015-06-21
* Description : a kipi plugin to export images to Google-Drive web service
*
* Copyright (C) 2015 by Shourya Singh Gupta <shouryasgupta at gmail dot com>
*
* This program is free software; you can redistribute it
* and/or modify it under the terms of the GNU General
* Public License as published by the Free Software Foundation;
* either version 2, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* ============================================================ */
#ifndef AUTHORIZE_H
#define AUTHORIZE_H
// Qt includes
#include <QList>
#include <QString>
#include <QObject>
#include <QStringList>
#include <QDialog>
#include <QNetworkReply>
#include <QNetworkAccessManager>
namespace KIPIGoogleServicesPlugin
{
class Authorize : public QObject
{
Q_OBJECT
public:
Authorize(QWidget* const parent, const QString& scope);
~Authorize();
Q_SIGNALS:
void signalBusy(bool val);
void signalAccessTokenFailed(int errCode, const QString& errMsg);
void signalAccessTokenObtained();
void signalTextBoxEmpty();
void signalRefreshTokenObtained(const QString& msg);
private Q_SLOTS:
void slotAuthFinished(QNetworkReply* reply);
void slotAccept();
void slotReject();
public:
void doOAuth();
void getAccessToken();
void getAccessTokenFromRefreshToken(const QString& msg);
bool authenticated();
QString getValue(const QString&, const QString&);
QStringList getParams(const QString&, const QStringList&, const QString&);
QString getToken(const QString&, const QString&, const QString&);
int getTokenEnd(const QString&, int);
private:
void parseResponseAccessToken(const QByteArray& data);
void parseResponseRefreshToken(const QByteArray& data);
private:
enum Auth_State
{
GD_ACCESSTOKEN=0,
GD_REFRESHTOKEN
};
protected:
QWidget* m_parent;
QString m_scope;
QString m_redirect_uri;
QString m_response_type;
QString m_client_id;
QString m_client_secret;
QString m_access_token;
QString m_refresh_token;
QString m_code;
QString m_token_uri;
QString m_bearer_access_token;
QByteArray m_buffer;
QNetworkReply* m_reply;
Auth_State m_Authstate;
int m_continuePos;
private:
QDialog* m_window;
QNetworkAccessManager* m_netMngr;
};
} // namespace KIPIGoogleServicesPlugin
#endif /* AUTHORIZE_H */
|