Merge pull request #6490 from jbroadus/gpodder-login-cleanup

Gpodder login cleanup.
This commit is contained in:
John Maguire 2020-01-02 17:03:28 +00:00 committed by GitHub
commit 4ec427c097
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 30 additions and 27 deletions

View File

@ -103,9 +103,8 @@ void GPodderSync::ReloadSettings() {
} }
} }
QNetworkReply* GPodderSync::Login(const QString& username, void GPodderSync::Login(const QString& username, const QString& password,
const QString& password, const QString& device_name) {
const QString& device_name) {
api_.reset(new mygpo::ApiRequest(username, password, network_)); api_.reset(new mygpo::ApiRequest(username, password, network_));
QNetworkReply* reply = api_->renameDevice( QNetworkReply* reply = api_->renameDevice(
@ -114,7 +113,6 @@ QNetworkReply* GPodderSync::Login(const QString& username,
NewClosure(reply, SIGNAL(finished()), this, NewClosure(reply, SIGNAL(finished()), this,
SLOT(LoginFinished(QNetworkReply*, QString, QString)), reply, SLOT(LoginFinished(QNetworkReply*, QString, QString)), reply,
username, password); username, password);
return reply;
} }
void GPodderSync::LoginFinished(QNetworkReply* reply, const QString& username, 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); s.setValue("gpodder_password", password);
DoInitialSync(); DoInitialSync();
emit LoginSuccess();
} else { } else {
api_.reset(); api_.reset();
emit LoginFailure(reply->errorString());
} }
} }

View File

@ -59,15 +59,18 @@ class GPodderSync : public QObject {
bool is_logged_in() const; bool is_logged_in() const;
// Tries to login using the given username and password. Also sets the // 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() // device name and type on gpodder.net.
// the QNetworkReply returned from this function.
// If login succeeds the username and password will be saved in QSettings. // If login succeeds the username and password will be saved in QSettings.
QNetworkReply* Login(const QString& username, const QString& password, void Login(const QString& username, const QString& password,
const QString& device_name); const QString& device_name);
// Clears any saved username and password from QSettings. // Clears any saved username and password from QSettings.
void Logout(); void Logout();
signals:
void LoginSuccess();
void LoginFailure(const QString& error);
public slots: public slots:
void GetUpdatesNow(); void GetUpdatesNow();

View File

@ -21,11 +21,9 @@
#include "ui_podcastsettingspage.h" #include "ui_podcastsettingspage.h"
#include <QFileDialog> #include <QFileDialog>
#include <QNetworkReply>
#include <QSettings> #include <QSettings>
#include "core/application.h" #include "core/application.h"
#include "core/closure.h"
#include "core/timeconstants.h" #include "core/timeconstants.h"
#include "gpoddersync.h" #include "gpoddersync.h"
#include "library/librarydirectorymodel.h" #include "library/librarydirectorymodel.h"
@ -47,6 +45,11 @@ PodcastSettingsPage::PodcastSettingsPage(SettingsDialog* dialog)
connect(ui_->download_dir_browse, SIGNAL(clicked()), connect(ui_->download_dir_browse, SIGNAL(clicked()),
SLOT(DownloadDirBrowse())); 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_->username);
ui_->login_state->AddCredentialField(ui_->device_name); ui_->login_state->AddCredentialField(ui_->device_name);
ui_->login_state->AddCredentialField(ui_->password); ui_->login_state->AddCredentialField(ui_->password);
@ -112,24 +115,21 @@ void PodcastSettingsPage::Save() {
void PodcastSettingsPage::LoginClicked() { void PodcastSettingsPage::LoginClicked() {
ui_->login_state->SetLoggedIn(LoginStateWidget::LoginInProgress); 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()); ui_->username->text(), ui_->password->text(), ui_->device_name->text());
NewClosure(reply, SIGNAL(finished()), this,
SLOT(LoginFinished(QNetworkReply*)), reply);
} }
void PodcastSettingsPage::LoginFinished(QNetworkReply* reply) { void PodcastSettingsPage::GpodderLoginSuccess() {
const bool success = reply->error() == QNetworkReply::NoError; ui_->login_state->SetLoggedIn(LoginStateWidget::LoggedIn,
ui_->login_state->SetLoggedIn( ui_->username->text());
success ? LoginStateWidget::LoggedIn : LoginStateWidget::LoggedOut, ui_->login_state->SetAccountTypeVisible(false);
ui_->username->text()); }
ui_->login_state->SetAccountTypeVisible(!success); void PodcastSettingsPage::GpodderLoginFailure(const QString& error) {
if (!success) { ui_->login_state->SetLoggedIn(LoginStateWidget::LoggedOut,
ui_->login_state->SetAccountTypeText(tr("Login failed") + ": " + ui_->username->text());
reply->errorString()); ui_->login_state->SetAccountTypeVisible(true);
} ui_->login_state->SetAccountTypeText(tr("Login failed") + ": " + error);
} }
void PodcastSettingsPage::LogoutClicked() { void PodcastSettingsPage::LogoutClicked() {

View File

@ -24,8 +24,6 @@
class Ui_PodcastSettingsPage; class Ui_PodcastSettingsPage;
class QNetworkReply;
class PodcastSettingsPage : public SettingsPage { class PodcastSettingsPage : public SettingsPage {
Q_OBJECT Q_OBJECT
@ -40,9 +38,11 @@ class PodcastSettingsPage : public SettingsPage {
private slots: private slots:
void LoginClicked(); void LoginClicked();
void LoginFinished(QNetworkReply* reply);
void LogoutClicked(); void LogoutClicked();
void GpodderLoginSuccess();
void GpodderLoginFailure(const QString& error);
void DownloadDirBrowse(); void DownloadDirBrowse();
private: private: