From 11e816bdf62e65db82768b7d952d663d62f6d196 Mon Sep 17 00:00:00 2001 From: Martin Rotter Date: Mon, 2 Oct 2017 12:44:54 +0200 Subject: [PATCH] Do not store access token, prepare DB for Inoreader multi acc. --- src/network-web/oauth2service.cpp | 3 +- src/services/inoreader/definitions.h | 2 + .../gui/formeditinoreaderaccount.cpp | 30 ++- .../inoreader/gui/formeditinoreaderaccount.h | 3 +- .../inoreader/gui/formeditinoreaderaccount.ui | 172 +++++++++++------- .../inoreader/inoreaderentrypoint.cpp | 2 +- 6 files changed, 146 insertions(+), 66 deletions(-) diff --git a/src/network-web/oauth2service.cpp b/src/network-web/oauth2service.cpp index 8efddf6ac..1f5710811 100755 --- a/src/network-web/oauth2service.cpp +++ b/src/network-web/oauth2service.cpp @@ -43,6 +43,7 @@ #include "definitions/definitions.h" #include "gui/dialogs/oauthlogin.h" #include "miscellaneous/application.h" +#include "services/inoreader/definitions.h" #include #include @@ -53,7 +54,7 @@ OAuth2Service::OAuth2Service(QString authUrl, QString tokenUrl, QString clientId, QString clientSecret, QString scope, QObject* parent) : QObject(parent), m_tokensExpireIn(QDateTime()) { - m_redirectUri = QSL("http://localhost"); + m_redirectUri = QSL(INOREADER_OAUTH_CLI_REDIRECT); m_tokenGrantType = QSL("authorization_code"); m_tokenUrl = QUrl(tokenUrl); m_authUrl = authUrl; diff --git a/src/services/inoreader/definitions.h b/src/services/inoreader/definitions.h index 8dc9e4c51..ec4753935 100755 --- a/src/services/inoreader/definitions.h +++ b/src/services/inoreader/definitions.h @@ -22,6 +22,8 @@ #define INOREADER_OAUTH_SCOPE "read write" #define INOREADER_OAUTH_TOKEN_URL "https://www.inoreader.com/oauth2/token" #define INOREADER_OAUTH_AUTH_URL "https://www.inoreader.com/oauth2/auth" + +#define INOREADER_OAUTH_CLI_REDIRECT "http://localhost" #define INOREADER_OAUTH_CLI_ID "1000000604" #define INOREADER_OAUTH_CLI_KEY "gsStoZ3aAoQJCgQxoFSuXkWI7Sly87yK" diff --git a/src/services/inoreader/gui/formeditinoreaderaccount.cpp b/src/services/inoreader/gui/formeditinoreaderaccount.cpp index 86f8e0401..bdf8bcde4 100755 --- a/src/services/inoreader/gui/formeditinoreaderaccount.cpp +++ b/src/services/inoreader/gui/formeditinoreaderaccount.cpp @@ -28,17 +28,26 @@ FormEditInoreaderAccount::FormEditInoreaderAccount(QWidget* parent) : QDialog(parent), m_network(nullptr), m_editableRoot(nullptr) { m_ui.setupUi(this); + + GuiUtilities::setLabelAsNotice(*m_ui.m_lblAuthInfo, true); GuiUtilities::applyDialogProperties(*this, qApp->icons()->miscIcon(QSL("inoreader"))); + m_ui.m_lblTestResult->setStatus(WidgetWithStatus::StatusType::Information, tr("Not tested yet."), tr("Not tested yet.")); m_ui.m_lblTestResult->label()->setWordWrap(true); m_ui.m_txtUsername->lineEdit()->setPlaceholderText(tr("User-visible username")); - setTabOrder(m_ui.m_txtUsername->lineEdit(), m_ui.m_spinLimitMessages); + setTabOrder(m_ui.m_txtUsername->lineEdit(), m_ui.m_txtAppId); + setTabOrder(m_ui.m_txtAppId, m_ui.m_txtAppKey); + setTabOrder(m_ui.m_txtAppKey, m_ui.m_txtRedirectUrl); + setTabOrder(m_ui.m_txtRedirectUrl, m_ui.m_spinLimitMessages); setTabOrder(m_ui.m_spinLimitMessages, m_ui.m_btnTestSetup); setTabOrder(m_ui.m_btnTestSetup, m_ui.m_buttonBox); + connect(m_ui.m_txtAppId->lineEdit(), &BaseLineEdit::textChanged, this, &FormEditInoreaderAccount::checkOAuthValue); + connect(m_ui.m_txtAppKey->lineEdit(), &BaseLineEdit::textChanged, this, &FormEditInoreaderAccount::checkOAuthValue); + connect(m_ui.m_txtRedirectUrl->lineEdit(), &BaseLineEdit::textChanged, this, &FormEditInoreaderAccount::checkOAuthValue); connect(m_ui.m_txtUsername->lineEdit(), &BaseLineEdit::textChanged, this, &FormEditInoreaderAccount::checkUsername); connect(m_ui.m_btnTestSetup, &QPushButton::clicked, this, &FormEditInoreaderAccount::testSetup); connect(m_ui.m_buttonBox, &QDialogButtonBox::accepted, this, &FormEditInoreaderAccount::onClickedOk); @@ -130,9 +139,15 @@ void FormEditInoreaderAccount::unhookNetwork() { InoreaderServiceRoot* FormEditInoreaderAccount::execForCreate() { setWindowTitle(tr("Add new Inoreader account")); m_network = new InoreaderNetworkFactory(this); + + m_ui.m_txtAppId->lineEdit()->setText(INOREADER_OAUTH_CLI_ID); + m_ui.m_txtAppKey->lineEdit()->setText(INOREADER_OAUTH_CLI_KEY); + m_ui.m_txtRedirectUrl->lineEdit()->setText(INOREADER_OAUTH_CLI_REDIRECT); + hookNetwork(); exec(); unhookNetwork(); + return m_editableRoot; } @@ -147,3 +162,16 @@ void FormEditInoreaderAccount::execForEdit(InoreaderServiceRoot* existing_root) exec(); unhookNetwork(); } + +void FormEditInoreaderAccount::checkOAuthValue(const QString& value) { + LineEditWithStatus* line_edit = qobject_cast(sender()->parent()); + + if (line_edit != nullptr) { + if (value.isEmpty()) { + line_edit->setStatus(WidgetWithStatus::Error, tr("Empty value is entered.")); + } + else { + line_edit->setStatus(WidgetWithStatus::Ok, tr("Some value is entered.")); + } + } +} diff --git a/src/services/inoreader/gui/formeditinoreaderaccount.h b/src/services/inoreader/gui/formeditinoreaderaccount.h index c24bc79d6..c293cbc82 100755 --- a/src/services/inoreader/gui/formeditinoreaderaccount.h +++ b/src/services/inoreader/gui/formeditinoreaderaccount.h @@ -35,7 +35,7 @@ class FormEditInoreaderAccount : public QDialog { Q_OBJECT public: - explicit FormEditInoreaderAccount(QWidget* parent = 0); + explicit FormEditInoreaderAccount(QWidget* parent = nullptr); virtual ~FormEditInoreaderAccount(); InoreaderServiceRoot* execForCreate(); @@ -46,6 +46,7 @@ class FormEditInoreaderAccount : public QDialog { void testSetup(); void onClickedOk(); void onClickedCancel(); + void checkOAuthValue(const QString& value); void checkUsername(const QString& username); void onAuthFailed(); void onAuthError(const QString& error, const QString& detailed_description); diff --git a/src/services/inoreader/gui/formeditinoreaderaccount.ui b/src/services/inoreader/gui/formeditinoreaderaccount.ui index e99461d2e..1dc7a7c3a 100755 --- a/src/services/inoreader/gui/formeditinoreaderaccount.ui +++ b/src/services/inoreader/gui/formeditinoreaderaccount.ui @@ -2,79 +2,130 @@ FormEditInoreaderAccount + + + 0 + 0 + 542 + 363 + + Dialog - - - - - Username - - - - - + + + - + - Only download newest X messages per feed + Username - - - - 140 - 16777215 - - - - message(s) + + + + + + OAuth 2.0 settings + + + + + Application ID + + + + + + + + + + Application key + + + + + + + + + + Redirect URL + + + + + + + + + + These settings DO NOT have to be changed from their default values. Change these values only of you are advanced user and you know what you are doing! + + + true + + + + + + + + + + Only download newest X messages per feed + + + + + + + + 140 + 16777215 + + + + message(s) + + + + + + + + + + + &Login + + + + + + + + 0 + 1 + + + + Qt::RightToLeft + + + + + - - - - Qt::Vertical - - - - 20 - 120 - - - - - - - - - - &Login - - - - - - - - 0 - 1 - - - - Qt::RightToLeft - - - - - - + Qt::Horizontal @@ -84,9 +135,6 @@ - - - diff --git a/src/services/inoreader/inoreaderentrypoint.cpp b/src/services/inoreader/inoreaderentrypoint.cpp index 8f6ad0b8d..3cf65b58b 100755 --- a/src/services/inoreader/inoreaderentrypoint.cpp +++ b/src/services/inoreader/inoreaderentrypoint.cpp @@ -40,7 +40,7 @@ QList InoreaderEntryPoint::initializeSubtree() const { } bool InoreaderEntryPoint::isSingleInstanceService() const { - return true; + return false; } QString InoreaderEntryPoint::name() const {