-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdialogoauthsetup.cpp
96 lines (65 loc) · 2.43 KB
/
dialogoauthsetup.cpp
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
#include "dialogoauthsetup.h"
#include "ui_dialogoauthsetup.h"
dialogOauthSetup::dialogOauthSetup(QWidget *parent) :
QDialog(parent),
ui(new Ui::dialogOauthSetup)
{
ui->setupUi(this);
this->ui->lineEditOAuthToken->setText(genericHelper::getOAuthAccessToken());
tw = new TwitchApi(this, genericHelper::getOAuthAccessToken());
QObject::connect(tw, SIGNAL(twitchReady(const QJsonDocument)), this, SLOT(successPopup(const QJsonDocument)));
QObject::connect(tw, SIGNAL(networkError(QString)), this, SLOT(errorPopup(QString)));
}
void dialogOauthSetup::errorPopup(QString message) {
QMessageBox::warning(this, tr("twitcher"),
message,
QMessageBox::Ok
);
}
void dialogOauthSetup::successPopup(const QJsonDocument message) {
int ret = QMessageBox::information(this, tr("twitcher"),
message.toJson(),
QMessageBox::Ok
);
QJsonObject jsonObject = message.object();
genericHelper::setUsername(jsonObject["name"].toString());
emit valueChanged( );
}
dialogOauthSetup::~dialogOauthSetup()
{
delete ui;
}
void dialogOauthSetup::setDialogShown()
{
dialogShown = true;
}
bool dialogOauthSetup::getDialogShown()
{
return dialogShown;
}
void dialogOauthSetup::on_pushButtonAuthorizeOnTwitch_clicked()
{
QString link = "https://api.twitch.tv/kraken/oauth2/authorize?response_type=token&client_id=XXXXXXXXXXXXX&redirect_uri=http://oauth.abyle.org/&scope=channel_editor+user_read+chat_login+channel_read";
QDesktopServices::openUrl(QUrl(link));
}
void dialogOauthSetup::on_pushButtonSave_clicked()
{
genericHelper::setOAuthAccessToken(this->ui->lineEditOAuthToken->text());
tw->setOAuthAccessToken(this->ui->lineEditOAuthToken->text());
tw->getUser();
QMessageBox::information(this, tr("twitcher"),
tr("Saved."),
QMessageBox::Ok
);
emit valueChanged( );
}
void dialogOauthSetup::on_pushButtonTestOAuth_clicked()
{
tw->setOAuthAccessToken(this->ui->lineEditOAuthToken->text());
tw->getUser();
}
void dialogOauthSetup::on_pushButtonREvoke_clicked()
{
QString link = "http://www.twitch.tv/settings/applications";
QDesktopServices::openUrl(QUrl(link));
}