Merge pull request #6490 from jbroadus/gpodder-login-cleanup
Gpodder login cleanup.
This commit is contained in:
commit
4ec427c097
|
@ -103,9 +103,8 @@ void GPodderSync::ReloadSettings() {
|
|||
}
|
||||
}
|
||||
|
||||
QNetworkReply* GPodderSync::Login(const QString& username,
|
||||
const QString& password,
|
||||
const QString& device_name) {
|
||||
void GPodderSync::Login(const QString& username, const QString& password,
|
||||
const QString& device_name) {
|
||||
api_.reset(new mygpo::ApiRequest(username, password, network_));
|
||||
|
||||
QNetworkReply* reply = api_->renameDevice(
|
||||
|
@ -114,7 +113,6 @@ QNetworkReply* GPodderSync::Login(const QString& username,
|
|||
NewClosure(reply, SIGNAL(finished()), this,
|
||||
SLOT(LoginFinished(QNetworkReply*, QString, QString)), reply,
|
||||
username, password);
|
||||
return reply;
|
||||
}
|
||||
|
||||
void GPodderSync::LoginFinished(QNetworkReply* reply, const QString& username,
|
||||
|
@ -131,8 +129,10 @@ void GPodderSync::LoginFinished(QNetworkReply* reply, const QString& username,
|
|||
s.setValue("gpodder_password", password);
|
||||
|
||||
DoInitialSync();
|
||||
emit LoginSuccess();
|
||||
} else {
|
||||
api_.reset();
|
||||
emit LoginFailure(reply->errorString());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -59,15 +59,18 @@ class GPodderSync : public QObject {
|
|||
bool is_logged_in() const;
|
||||
|
||||
// Tries to login using the given username and password. Also sets the
|
||||
// device name and type on gpodder.net. You do NOT need to deleteLater()
|
||||
// the QNetworkReply returned from this function.
|
||||
// device name and type on gpodder.net.
|
||||
// If login succeeds the username and password will be saved in QSettings.
|
||||
QNetworkReply* Login(const QString& username, const QString& password,
|
||||
const QString& device_name);
|
||||
void Login(const QString& username, const QString& password,
|
||||
const QString& device_name);
|
||||
|
||||
// Clears any saved username and password from QSettings.
|
||||
void Logout();
|
||||
|
||||
signals:
|
||||
void LoginSuccess();
|
||||
void LoginFailure(const QString& error);
|
||||
|
||||
public slots:
|
||||
void GetUpdatesNow();
|
||||
|
||||
|
|
|
@ -21,11 +21,9 @@
|
|||
#include "ui_podcastsettingspage.h"
|
||||
|
||||
#include <QFileDialog>
|
||||
#include <QNetworkReply>
|
||||
#include <QSettings>
|
||||
|
||||
#include "core/application.h"
|
||||
#include "core/closure.h"
|
||||
#include "core/timeconstants.h"
|
||||
#include "gpoddersync.h"
|
||||
#include "library/librarydirectorymodel.h"
|
||||
|
@ -47,6 +45,11 @@ PodcastSettingsPage::PodcastSettingsPage(SettingsDialog* dialog)
|
|||
connect(ui_->download_dir_browse, SIGNAL(clicked()),
|
||||
SLOT(DownloadDirBrowse()));
|
||||
|
||||
GPodderSync* gsync = dialog->app()->gpodder_sync();
|
||||
connect(gsync, SIGNAL(LoginSuccess()), SLOT(GpodderLoginSuccess()));
|
||||
connect(gsync, SIGNAL(LoginFailure(const QString&)),
|
||||
SLOT(GpodderLoginFailure(const QString&)));
|
||||
|
||||
ui_->login_state->AddCredentialField(ui_->username);
|
||||
ui_->login_state->AddCredentialField(ui_->device_name);
|
||||
ui_->login_state->AddCredentialField(ui_->password);
|
||||
|
@ -112,24 +115,21 @@ void PodcastSettingsPage::Save() {
|
|||
void PodcastSettingsPage::LoginClicked() {
|
||||
ui_->login_state->SetLoggedIn(LoginStateWidget::LoginInProgress);
|
||||
|
||||
QNetworkReply* reply = dialog()->app()->gpodder_sync()->Login(
|
||||
dialog()->app()->gpodder_sync()->Login(
|
||||
ui_->username->text(), ui_->password->text(), ui_->device_name->text());
|
||||
|
||||
NewClosure(reply, SIGNAL(finished()), this,
|
||||
SLOT(LoginFinished(QNetworkReply*)), reply);
|
||||
}
|
||||
|
||||
void PodcastSettingsPage::LoginFinished(QNetworkReply* reply) {
|
||||
const bool success = reply->error() == QNetworkReply::NoError;
|
||||
ui_->login_state->SetLoggedIn(
|
||||
success ? LoginStateWidget::LoggedIn : LoginStateWidget::LoggedOut,
|
||||
ui_->username->text());
|
||||
void PodcastSettingsPage::GpodderLoginSuccess() {
|
||||
ui_->login_state->SetLoggedIn(LoginStateWidget::LoggedIn,
|
||||
ui_->username->text());
|
||||
ui_->login_state->SetAccountTypeVisible(false);
|
||||
}
|
||||
|
||||
ui_->login_state->SetAccountTypeVisible(!success);
|
||||
if (!success) {
|
||||
ui_->login_state->SetAccountTypeText(tr("Login failed") + ": " +
|
||||
reply->errorString());
|
||||
}
|
||||
void PodcastSettingsPage::GpodderLoginFailure(const QString& error) {
|
||||
ui_->login_state->SetLoggedIn(LoginStateWidget::LoggedOut,
|
||||
ui_->username->text());
|
||||
ui_->login_state->SetAccountTypeVisible(true);
|
||||
ui_->login_state->SetAccountTypeText(tr("Login failed") + ": " + error);
|
||||
}
|
||||
|
||||
void PodcastSettingsPage::LogoutClicked() {
|
||||
|
|
|
@ -24,8 +24,6 @@
|
|||
|
||||
class Ui_PodcastSettingsPage;
|
||||
|
||||
class QNetworkReply;
|
||||
|
||||
class PodcastSettingsPage : public SettingsPage {
|
||||
Q_OBJECT
|
||||
|
||||
|
@ -40,9 +38,11 @@ class PodcastSettingsPage : public SettingsPage {
|
|||
|
||||
private slots:
|
||||
void LoginClicked();
|
||||
void LoginFinished(QNetworkReply* reply);
|
||||
void LogoutClicked();
|
||||
|
||||
void GpodderLoginSuccess();
|
||||
void GpodderLoginFailure(const QString& error);
|
||||
|
||||
void DownloadDirBrowse();
|
||||
|
||||
private:
|
||||
|
|
Loading…
Reference in New Issue