-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathDropBoxAuthDialog.cpp
72 lines (64 loc) · 2.03 KB
/
DropBoxAuthDialog.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
#include "DropBoxAuthDialog.h"
#include "ui_DropBoxAuthDialog.h"
#include <QDebug>
#include <QUrl>
#include <QDesktopServices>
#include <QMessageBox>
#include <QClipboard>
#include "dropbox/endpoint/DropboxWebAuth.h"
#include "dropbox/DropboxClient.h"
DropBoxAuthDialog::DropBoxAuthDialog(QString workingPath, QWidget *parent) :
QDialog(parent),
ui(new Ui::DropBoxAuthDialog),
m_workingPath(workingPath)
{
ui->setupUi(this);
if( m_appInfo.readFromFile( m_workingPath + "app.info" ) )
{
ui->lineEditAppKey->setText( m_appInfo.getKey() );
ui->lineEditAppSecret->setText( m_appInfo.getSecret() );
}
}
DropBoxAuthDialog::~DropBoxAuthDialog()
{
delete ui;
}
void DropBoxAuthDialog::on_pushButtonGetToken_clicked()
{
m_appInfo.setKeySecret( ui->lineEditAppKey->text(), ui->lineEditAppSecret->text() );
m_appInfo.storeToFile( m_workingPath + "app.info" );
m_url = DropboxWebAuth::getCodeAuthorizeUrl( m_appInfo );
QDesktopServices::openUrl( QUrl( m_url ) );
ui->lineEditAuthCode->setEnabled( true );
ui->pushButtonPaste->setEnabled( true );
}
void DropBoxAuthDialog::on_lineEditAuthCode_textChanged(const QString &arg1)
{
ui->pushButtonOk->setEnabled( arg1.size() > 0 );
}
void DropBoxAuthDialog::on_pushButtonOk_clicked()
{
try
{
DropboxAuthInfo authInfo = DropboxWebAuth::getTokenFromCode( m_appInfo, ui->lineEditAuthCode->text() );
m_token = authInfo.getAccessToken();
/*if( !authInfo.storeToFile( m_workingPath + "token.info" ) )
{
QMessageBox::critical( this, tr( "Dropbox Authentication" ), tr( "Error, failed to store access token to file." ) );
reject();
return;
}*/
}
catch(DropboxException& e)
{
QMessageBox::critical( this, tr( "Dropbox Authentication" ), tr( "Exception: " ) + e.what() );
reject();
return;
}
accept();
return;
}
void DropBoxAuthDialog::on_pushButtonPaste_clicked()
{
ui->lineEditAuthCode->setText( QGuiApplication::clipboard()->text() );
}