Make the Ubuntu One settings page a bit more sane
This commit is contained in:
parent
1a3f6af1bd
commit
b31c646090
|
@ -25,7 +25,8 @@ static const char* kOAuthHeaderPrefix = "OAuth realm=\"\", ";
|
|||
|
||||
UbuntuOneAuthenticator::UbuntuOneAuthenticator(QObject* parent)
|
||||
: QObject(parent),
|
||||
network_(new NetworkAccessManager(this)) {
|
||||
network_(new NetworkAccessManager(this)),
|
||||
success_(false) {
|
||||
}
|
||||
|
||||
void UbuntuOneAuthenticator::StartAuthorisation(
|
||||
|
@ -65,6 +66,7 @@ void UbuntuOneAuthenticator::AuthorisationFinished(QNetworkReply* reply) {
|
|||
QVariant json = parser.parse(data, &ok);
|
||||
if (!ok) {
|
||||
qLog(Error) << "Failed to authenticate to Ubuntu One:" << parser.errorString();
|
||||
emit Finished();
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -135,5 +137,6 @@ void UbuntuOneAuthenticator::CopySSOTokens() {
|
|||
void UbuntuOneAuthenticator::CopySSOTokensFinished(QNetworkReply* reply) {
|
||||
reply->deleteLater();
|
||||
qLog(Debug) << reply->readAll();
|
||||
success_ = true;
|
||||
emit Finished();
|
||||
}
|
||||
|
|
|
@ -12,6 +12,7 @@ class UbuntuOneAuthenticator : public QObject {
|
|||
explicit UbuntuOneAuthenticator(QObject* parent = 0);
|
||||
void StartAuthorisation(const QString& email, const QString& password);
|
||||
|
||||
bool success() const { return success_; }
|
||||
QString consumer_key() const { return consumer_key_; }
|
||||
QString consumer_secret() const { return consumer_secret_; }
|
||||
QString token() const { return token_; }
|
||||
|
@ -37,6 +38,8 @@ class UbuntuOneAuthenticator : public QObject {
|
|||
private:
|
||||
NetworkAccessManager* network_;
|
||||
|
||||
bool success_;
|
||||
|
||||
QString consumer_key_;
|
||||
QString consumer_secret_;
|
||||
|
||||
|
|
|
@ -77,6 +77,9 @@ QByteArray UbuntuOneService::GenerateAuthorisationHeader() {
|
|||
void UbuntuOneService::AuthenticationFinished(
|
||||
UbuntuOneAuthenticator* authenticator) {
|
||||
authenticator->deleteLater();
|
||||
if (!authenticator->success()) {
|
||||
return;
|
||||
}
|
||||
|
||||
consumer_key_ = authenticator->consumer_key();
|
||||
consumer_secret_ = authenticator->consumer_secret();
|
||||
|
|
|
@ -9,16 +9,22 @@
|
|||
#include "internet/ubuntuoneauthenticator.h"
|
||||
#include "internet/ubuntuoneservice.h"
|
||||
|
||||
#include <QMessageBox>
|
||||
|
||||
UbuntuOneSettingsPage::UbuntuOneSettingsPage(SettingsDialog* parent)
|
||||
: SettingsPage(parent),
|
||||
ui_(new Ui::UbuntuOneSettingsPage),
|
||||
service_(dialog()->app()->internet_model()->Service<UbuntuOneService>()),
|
||||
authenticated_(false) {
|
||||
ui_->setupUi(this);
|
||||
ui_->login_state->AddCredentialGroup(ui_->login_container);
|
||||
connect(ui_->login_button, SIGNAL(clicked()), SLOT(LoginClicked()));
|
||||
|
||||
dialog()->installEventFilter(this);
|
||||
ui_->login_state->AddCredentialField(ui_->username);
|
||||
ui_->login_state->AddCredentialField(ui_->password);
|
||||
ui_->login_state->AddCredentialGroup(ui_->login_container);
|
||||
|
||||
connect(ui_->login_state, SIGNAL(LogoutClicked()), SLOT(LogoutClicked()));
|
||||
connect(ui_->login_state, SIGNAL(LoginClicked()), SLOT(LoginClicked()));
|
||||
connect(ui_->login_button, SIGNAL(clicked()), SLOT(LoginClicked()));
|
||||
}
|
||||
|
||||
void UbuntuOneSettingsPage::Load() {
|
||||
|
@ -33,18 +39,12 @@ void UbuntuOneSettingsPage::Load() {
|
|||
}
|
||||
|
||||
void UbuntuOneSettingsPage::Save() {
|
||||
QSettings s;
|
||||
s.beginGroup(UbuntuOneService::kSettingsGroup);
|
||||
|
||||
if (authenticated_) {
|
||||
s.setValue("user_email", ui_->username->text());
|
||||
}
|
||||
}
|
||||
|
||||
void UbuntuOneSettingsPage::LoginClicked() {
|
||||
ui_->login_button->setEnabled(false);
|
||||
QString username = ui_->username->text();
|
||||
QString password = ui_->password->text();
|
||||
const QString username = ui_->username->text();
|
||||
const QString password = ui_->password->text();
|
||||
ui_->password->clear();
|
||||
|
||||
UbuntuOneAuthenticator* authenticator = new UbuntuOneAuthenticator;
|
||||
authenticator->StartAuthorisation(username, password);
|
||||
|
@ -53,22 +53,34 @@ void UbuntuOneSettingsPage::LoginClicked() {
|
|||
NewClosure(authenticator, SIGNAL(Finished()),
|
||||
service_, SLOT(AuthenticationFinished(UbuntuOneAuthenticator*)),
|
||||
authenticator);
|
||||
|
||||
ui_->login_state->SetLoggedIn(LoginStateWidget::LoginInProgress);
|
||||
}
|
||||
|
||||
void UbuntuOneSettingsPage::LogoutClicked() {
|
||||
QSettings s;
|
||||
s.beginGroup(UbuntuOneService::kSettingsGroup);
|
||||
s.remove("user_email");
|
||||
s.remove("consumer_key");
|
||||
s.remove("consumer_secret");
|
||||
s.remove("token");
|
||||
s.remove("token_secret");
|
||||
|
||||
ui_->login_state->SetLoggedIn(LoginStateWidget::LoggedOut);
|
||||
}
|
||||
|
||||
void UbuntuOneSettingsPage::Connected(UbuntuOneAuthenticator* authenticator) {
|
||||
ui_->login_state->SetLoggedIn(LoginStateWidget::LoggedIn, ui_->username->text());
|
||||
authenticated_ = true;
|
||||
}
|
||||
|
||||
bool UbuntuOneSettingsPage::eventFilter(QObject* object, QEvent* event) {
|
||||
if (object == dialog() && event->type() == QEvent::Enter) {
|
||||
ui_->login_button->setEnabled(true);
|
||||
return false;
|
||||
if (!authenticator->success()) {
|
||||
ui_->login_state->SetLoggedIn(LoginStateWidget::LoggedOut);
|
||||
QMessageBox::warning(this, tr("Authentication failed"),
|
||||
tr("Your username or password was incorrect."));
|
||||
return;
|
||||
}
|
||||
|
||||
return SettingsPage::eventFilter(object, event);
|
||||
ui_->login_state->SetLoggedIn(LoginStateWidget::LoggedIn, ui_->username->text());
|
||||
authenticated_ = true;
|
||||
|
||||
QSettings s;
|
||||
s.beginGroup(UbuntuOneService::kSettingsGroup);
|
||||
s.setValue("user_email", ui_->username->text());
|
||||
}
|
||||
|
|
|
@ -15,9 +15,6 @@ class UbuntuOneSettingsPage : public SettingsPage {
|
|||
void Load();
|
||||
void Save();
|
||||
|
||||
// QObject
|
||||
bool eventFilter(QObject* object, QEvent* event);
|
||||
|
||||
private slots:
|
||||
void LoginClicked();
|
||||
void LogoutClicked();
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
<iconset resource="../../data/data.qrc">
|
||||
<normaloff>:/providers/ubuntuone.png</normaloff>:/providers/ubuntuone.png</iconset>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
|
@ -32,19 +32,23 @@
|
|||
<widget class="LoginStateWidget" name="login_state" native="true"/>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QWidget" name="login_container" native="true">
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<property name="leftMargin">
|
||||
<number>28</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<widget class="QGroupBox" name="login_container">
|
||||
<property name="title">
|
||||
<string>Account details</string>
|
||||
</property>
|
||||
<layout class="QFormLayout" name="formLayout">
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="label_2">
|
||||
<property name="text">
|
||||
<string>Ubuntu One username</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||
<item>
|
||||
<widget class="QLineEdit" name="username"/>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="login_button">
|
||||
<property name="text">
|
||||
|
@ -52,32 +56,32 @@
|
|||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLineEdit" name="username">
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLineEdit" name="password">
|
||||
<property name="echoMode">
|
||||
<enum>QLineEdit::Password</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="horizontalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="label_3">
|
||||
<property name="text">
|
||||
<string>Ubuntu One password</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QLineEdit" name="password">
|
||||
<property name="echoMode">
|
||||
<enum>QLineEdit::Password</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0" colspan="2">
|
||||
<widget class="QLabel" name="label_4">
|
||||
<property name="text">
|
||||
<string><a href="https://one.ubuntu.com/auth/login">Create a new account or reset your password</a></string>
|
||||
</property>
|
||||
<property name="openExternalLinks">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
|
@ -89,7 +93,7 @@
|
|||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>20</width>
|
||||
<height>357</height>
|
||||
<height>40</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
|
@ -104,6 +108,11 @@
|
|||
<container>1</container>
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
<tabstops>
|
||||
<tabstop>username</tabstop>
|
||||
<tabstop>password</tabstop>
|
||||
<tabstop>login_button</tabstop>
|
||||
</tabstops>
|
||||
<resources>
|
||||
<include location="../../data/data.qrc"/>
|
||||
</resources>
|
||||
|
|
Loading…
Reference in New Issue