Work on inoreader account editing.
This commit is contained in:
parent
88eb55cb0e
commit
3e74e54b8c
4 changed files with 32 additions and 24 deletions
|
@ -25,7 +25,7 @@
|
||||||
#include "services/inoreader/inoreaderserviceroot.h"
|
#include "services/inoreader/inoreaderserviceroot.h"
|
||||||
|
|
||||||
FormEditInoreaderAccount::FormEditInoreaderAccount(QWidget* parent) : QDialog(parent),
|
FormEditInoreaderAccount::FormEditInoreaderAccount(QWidget* parent) : QDialog(parent),
|
||||||
m_network(new InoreaderNetworkFactory(this)), m_editableRoot(nullptr) {
|
m_network(nullptr), m_editableRoot(nullptr) {
|
||||||
m_ui.setupUi(this);
|
m_ui.setupUi(this);
|
||||||
GuiUtilities::applyDialogProperties(*this, qApp->icons()->miscIcon(QSL("inoreader")));
|
GuiUtilities::applyDialogProperties(*this, qApp->icons()->miscIcon(QSL("inoreader")));
|
||||||
m_ui.m_lblTestResult->setStatus(WidgetWithStatus::StatusType::Information,
|
m_ui.m_lblTestResult->setStatus(WidgetWithStatus::StatusType::Information,
|
||||||
|
@ -57,21 +57,6 @@ FormEditInoreaderAccount::FormEditInoreaderAccount(QWidget* parent) : QDialog(pa
|
||||||
connect(m_ui.m_btnTestSetup, &QPushButton::clicked, this, &FormEditInoreaderAccount::testSetup);
|
connect(m_ui.m_btnTestSetup, &QPushButton::clicked, this, &FormEditInoreaderAccount::testSetup);
|
||||||
connect(m_ui.m_buttonBox, &QDialogButtonBox::accepted, this, &FormEditInoreaderAccount::onClickedOk);
|
connect(m_ui.m_buttonBox, &QDialogButtonBox::accepted, this, &FormEditInoreaderAccount::onClickedOk);
|
||||||
connect(m_ui.m_buttonBox, &QDialogButtonBox::rejected, this, &FormEditInoreaderAccount::onClickedCancel);
|
connect(m_ui.m_buttonBox, &QDialogButtonBox::rejected, this, &FormEditInoreaderAccount::onClickedCancel);
|
||||||
connect(m_network, &InoreaderNetworkFactory::accessGranted, [this]() {
|
|
||||||
m_ui.m_lblTestResult->setStatus(WidgetWithStatus::StatusType::Ok,
|
|
||||||
tr("Tested successfully. You may be prompted to login once more."),
|
|
||||||
tr("Your access was approved."));
|
|
||||||
});
|
|
||||||
connect(m_network, &InoreaderNetworkFactory::tokensRefreshed, [this]() {
|
|
||||||
m_ui.m_lblTestResult->setStatus(WidgetWithStatus::StatusType::Ok,
|
|
||||||
tr("Access tokens refreshed, it seems okay."),
|
|
||||||
tr("Your access was approved."));
|
|
||||||
});
|
|
||||||
connect(m_network, &InoreaderNetworkFactory::error, [this](const QString& err) {
|
|
||||||
m_ui.m_lblTestResult->setStatus(WidgetWithStatus::StatusType::Error,
|
|
||||||
tr("There is error. %1").arg(err),
|
|
||||||
tr("There was error during testing."));
|
|
||||||
});
|
|
||||||
|
|
||||||
m_ui.m_spinLimitMessages->setValue(INOREADER_DEFAULT_BATCH_SIZE);
|
m_ui.m_spinLimitMessages->setValue(INOREADER_DEFAULT_BATCH_SIZE);
|
||||||
m_ui.m_spinLimitMessages->setMinimum(INOREADER_UNLIMITED_BATCH_SIZE);
|
m_ui.m_spinLimitMessages->setMinimum(INOREADER_UNLIMITED_BATCH_SIZE);
|
||||||
|
@ -118,9 +103,31 @@ void FormEditInoreaderAccount::onClickedCancel() {
|
||||||
reject();
|
reject();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void FormEditInoreaderAccount::hookNetwork() {
|
||||||
|
connect(m_network, &InoreaderNetworkFactory::accessGranted, [this]() {
|
||||||
|
m_ui.m_lblTestResult->setStatus(WidgetWithStatus::StatusType::Ok,
|
||||||
|
tr("Tested successfully. You may be prompted to login once more."),
|
||||||
|
tr("Your access was approved."));
|
||||||
|
});
|
||||||
|
connect(m_network, &InoreaderNetworkFactory::tokensRefreshed, [this]() {
|
||||||
|
m_ui.m_lblTestResult->setStatus(WidgetWithStatus::StatusType::Ok,
|
||||||
|
tr("Access tokens refreshed, it seems okay."),
|
||||||
|
tr("Your access was approved."));
|
||||||
|
});
|
||||||
|
connect(m_network, &InoreaderNetworkFactory::error, [this](const QString& err) {
|
||||||
|
m_ui.m_lblTestResult->setStatus(WidgetWithStatus::StatusType::Error,
|
||||||
|
tr("There is error. %1").arg(err),
|
||||||
|
tr("There was error during testing."));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
InoreaderServiceRoot* FormEditInoreaderAccount::execForCreate() {
|
InoreaderServiceRoot* FormEditInoreaderAccount::execForCreate() {
|
||||||
setWindowTitle(tr("Add new Inoreader account"));
|
setWindowTitle(tr("Add new Inoreader account"));
|
||||||
exec();
|
exec();
|
||||||
|
|
||||||
|
m_network = new InoreaderNetworkFactory(this);
|
||||||
|
hookNetwork();
|
||||||
|
|
||||||
return m_editableRoot;
|
return m_editableRoot;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -129,5 +136,8 @@ void FormEditInoreaderAccount::execForEdit(InoreaderServiceRoot* existing_root)
|
||||||
m_editableRoot = existing_root;
|
m_editableRoot = existing_root;
|
||||||
m_ui.m_txtUsername->lineEdit()->setText(existing_root->network()->userName());
|
m_ui.m_txtUsername->lineEdit()->setText(existing_root->network()->userName());
|
||||||
m_ui.m_spinLimitMessages->setValue(existing_root->network()->batchSize());
|
m_ui.m_spinLimitMessages->setValue(existing_root->network()->batchSize());
|
||||||
|
|
||||||
|
m_network = existing_root->network();
|
||||||
|
hookNetwork();
|
||||||
exec();
|
exec();
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,6 +48,8 @@ class FormEditInoreaderAccount : public QDialog {
|
||||||
void onClickedCancel();
|
void onClickedCancel();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
void hookNetwork();
|
||||||
|
|
||||||
Ui::FormEditInoreaderAccount m_ui;
|
Ui::FormEditInoreaderAccount m_ui;
|
||||||
InoreaderNetworkFactory* m_network;
|
InoreaderNetworkFactory* m_network;
|
||||||
InoreaderServiceRoot* m_editableRoot;
|
InoreaderServiceRoot* m_editableRoot;
|
||||||
|
|
|
@ -69,10 +69,6 @@ void InoreaderNetworkFactory::logInIfNeeded() {
|
||||||
void InoreaderNetworkFactory::tokensReceived(QVariantMap tokens) {
|
void InoreaderNetworkFactory::tokensReceived(QVariantMap tokens) {
|
||||||
qDebug() << "Inoreader: Tokens received:" << tokens;
|
qDebug() << "Inoreader: Tokens received:" << tokens;
|
||||||
|
|
||||||
if (tokens.contains(INOREADER_ACCESS_TOKEN_KEY)) {
|
|
||||||
m_accessToken = tokens.value(INOREADER_ACCESS_TOKEN_KEY).toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (tokens.contains(INOREADER_REFRESH_TOKEN_KEY)) {
|
if (tokens.contains(INOREADER_REFRESH_TOKEN_KEY)) {
|
||||||
m_refreshToken = tokens.value(INOREADER_REFRESH_TOKEN_KEY).toString();
|
m_refreshToken = tokens.value(INOREADER_REFRESH_TOKEN_KEY).toString();
|
||||||
}
|
}
|
||||||
|
@ -114,7 +110,8 @@ void InoreaderNetworkFactory::initializeOauth() {
|
||||||
Q_UNUSED(uri)
|
Q_UNUSED(uri)
|
||||||
|
|
||||||
qCritical("Inoreader: We have error: '%s'.", qPrintable(error_description));
|
qCritical("Inoreader: We have error: '%s'.", qPrintable(error_description));
|
||||||
m_accessToken = m_refreshToken = QString();
|
setRefreshToken(QString());
|
||||||
|
setAccessToken(QString());
|
||||||
emit error(error_description);
|
emit error(error_description);
|
||||||
});
|
});
|
||||||
connect(m_oauth2, &QOAuth2AuthorizationCodeFlow::authorizeWithBrowser, [](const QUrl& url) {
|
connect(m_oauth2, &QOAuth2AuthorizationCodeFlow::authorizeWithBrowser, [](const QUrl& url) {
|
||||||
|
@ -131,7 +128,7 @@ void InoreaderNetworkFactory::setRefreshToken(const QString& refreshToken) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void InoreaderNetworkFactory::setAccessToken(const QString& accessToken) {
|
void InoreaderNetworkFactory::setAccessToken(const QString& accessToken) {
|
||||||
m_accessToken = accessToken;
|
m_oauth2->setToken(accessToken);
|
||||||
}
|
}
|
||||||
|
|
||||||
QString InoreaderNetworkFactory::refreshToken() const {
|
QString InoreaderNetworkFactory::refreshToken() const {
|
||||||
|
@ -139,5 +136,5 @@ QString InoreaderNetworkFactory::refreshToken() const {
|
||||||
}
|
}
|
||||||
|
|
||||||
QString InoreaderNetworkFactory::accessToken() const {
|
QString InoreaderNetworkFactory::accessToken() const {
|
||||||
return m_accessToken;
|
return m_oauth2->token();
|
||||||
}
|
}
|
||||||
|
|
|
@ -61,7 +61,6 @@ class InoreaderNetworkFactory : public QObject {
|
||||||
private:
|
private:
|
||||||
int m_batchSize;
|
int m_batchSize;
|
||||||
QString m_username;
|
QString m_username;
|
||||||
QString m_accessToken;
|
|
||||||
QString m_refreshToken;
|
QString m_refreshToken;
|
||||||
QOAuth2AuthorizationCodeFlow* m_oauth2;
|
QOAuth2AuthorizationCodeFlow* m_oauth2;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Reference in a new issue