From 5b0735bd687fb1095dfa5534726cd3badfb90532 Mon Sep 17 00:00:00 2001 From: Martin Rotter Date: Thu, 21 Sep 2017 11:41:27 +0200 Subject: [PATCH] Working "add" dialog. --- rssguard.pro | 9 +- src/gui/dialogs/formaddaccount.cpp | 2 +- .../gui/formeditinoreaderaccount.cpp | 67 +++++++++++++ .../inoreader/gui/formeditinoreaderaccount.h | 52 ++++++++++ .../inoreader/gui/formeditinoreaderaccount.ui | 99 +++++++++++++++++++ .../inoreader/inoreaderentrypoint.cpp | 10 +- src/services/inoreader/inoreaderentrypoint.h | 3 - .../network/inoreadernetworkfactory.cpp | 6 +- .../network/inoreadernetworkfactory.h | 4 + .../owncloud/gui/formeditowncloudaccount.cpp | 2 + .../owncloud/owncloudserviceentrypoint.cpp | 4 - .../owncloud/owncloudserviceentrypoint.h | 3 - .../standard/standardserviceentrypoint.cpp | 4 - .../standard/standardserviceentrypoint.h | 3 - .../tt-rss/ttrssserviceentrypoint.cpp | 11 +-- src/services/tt-rss/ttrssserviceentrypoint.h | 3 - 16 files changed, 243 insertions(+), 39 deletions(-) create mode 100755 src/services/inoreader/gui/formeditinoreaderaccount.cpp create mode 100755 src/services/inoreader/gui/formeditinoreaderaccount.h create mode 100755 src/services/inoreader/gui/formeditinoreaderaccount.ui diff --git a/rssguard.pro b/rssguard.pro index 3f1ba21be..9f81a30ff 100755 --- a/rssguard.pro +++ b/rssguard.pro @@ -335,7 +335,8 @@ HEADERS += src/core/feeddownloader.h \ src/services/inoreader/definitions.h \ src/services/inoreader/inoreaderentrypoint.h \ src/services/inoreader/network/inoreadernetworkfactory.h \ - src/services/inoreader/inoreaderserviceroot.h + src/services/inoreader/inoreaderserviceroot.h \ + src/services/inoreader/gui/formeditinoreaderaccount.h SOURCES += src/core/feeddownloader.cpp \ src/core/feedsmodel.cpp \ @@ -460,7 +461,8 @@ SOURCES += src/core/feeddownloader.cpp \ src/miscellaneous/externaltool.cpp \ src/services/inoreader/inoreaderentrypoint.cpp \ src/services/inoreader/network/inoreadernetworkfactory.cpp \ - src/services/inoreader/inoreaderserviceroot.cpp + src/services/inoreader/inoreaderserviceroot.cpp \ + src/services/inoreader/gui/formeditinoreaderaccount.cpp OBJECTIVE_SOURCES += src/miscellaneous/disablewindowtabbing.mm @@ -487,7 +489,8 @@ FORMS += src/gui/toolbareditor.ui \ src/gui/settings/settingsbrowsermail.ui \ src/gui/settings/settingsfeedsmessages.ui \ src/gui/settings/settingsdownloads.ui \ - src/services/tt-rss/gui/formeditttrssaccount.ui + src/services/tt-rss/gui/formeditttrssaccount.ui \ + src/services/inoreader/gui/formeditinoreaderaccount.ui equals(USE_WEBENGINE, true) { HEADERS += src/gui/locationlineedit.h \ diff --git a/src/gui/dialogs/formaddaccount.cpp b/src/gui/dialogs/formaddaccount.cpp index bac7de1cc..676da6a28 100755 --- a/src/gui/dialogs/formaddaccount.cpp +++ b/src/gui/dialogs/formaddaccount.cpp @@ -53,7 +53,7 @@ void FormAddAccount::addSelectedAccount() { m_model->addServiceAccount(new_root, true); } else { - qCritical("Cannot create new account."); + qWarning("Cannot create new account."); } } diff --git a/src/services/inoreader/gui/formeditinoreaderaccount.cpp b/src/services/inoreader/gui/formeditinoreaderaccount.cpp new file mode 100755 index 000000000..87174e264 --- /dev/null +++ b/src/services/inoreader/gui/formeditinoreaderaccount.cpp @@ -0,0 +1,67 @@ +// This file is part of RSS Guard. + +// +// Copyright (C) 2011-2017 by Martin Rotter +// +// RSS Guard is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// RSS Guard is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with RSS Guard. If not, see . + +#include "services/inoreader/gui/formeditinoreaderaccount.h" + +#include "gui/guiutilities.h" +#include "miscellaneous/application.h" +#include "miscellaneous/iconfactory.h" +#include "services/inoreader/inoreaderserviceroot.h" + +FormEditInoreaderAccount::FormEditInoreaderAccount(QWidget* parent) : QDialog(parent), m_editableRoot(nullptr) { + m_ui.setupUi(this); + 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); + + connect(m_ui.m_btnTestSetup, &QPushButton::clicked, this, &FormEditInoreaderAccount::testSetup); + 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::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.")); + }); +} + +FormEditInoreaderAccount::~FormEditInoreaderAccount() {} + +void FormEditInoreaderAccount::testSetup() { + if (m_network.isLoggedIn()) { + m_ui.m_lblTestResult->setStatus(WidgetWithStatus::StatusType::Information, + tr("Access granted successfully."), + tr("Access granted successfully.")); + } + else { + m_network.logIn(); + m_ui.m_lblTestResult->setStatus(WidgetWithStatus::StatusType::Progress, + tr("Requested access approval. Respond to it, please."), + tr("Access approval was requested via OAuth 2.0 protocol.")); + } +} + +InoreaderServiceRoot* FormEditInoreaderAccount::execForCreate() { + setWindowTitle(tr("Add new Inoreader account")); + exec(); + return m_editableRoot; +} diff --git a/src/services/inoreader/gui/formeditinoreaderaccount.h b/src/services/inoreader/gui/formeditinoreaderaccount.h new file mode 100755 index 000000000..8337b3d0c --- /dev/null +++ b/src/services/inoreader/gui/formeditinoreaderaccount.h @@ -0,0 +1,52 @@ +// This file is part of RSS Guard. + +// +// Copyright (C) 2011-2017 by Martin Rotter +// +// RSS Guard is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// RSS Guard is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with RSS Guard. If not, see . + +#ifndef FORMEDITINOREADERACCOUNT_H +#define FORMEDITINOREADERACCOUNT_H + +#include + +#include "ui_formeditinoreaderaccount.h" + +#include "services/inoreader/network/inoreadernetworkfactory.h" + +namespace Ui { + class FormEditInoreaderAccount; +} + +class InoreaderServiceRoot; + +class FormEditInoreaderAccount : public QDialog { + Q_OBJECT + + public: + explicit FormEditInoreaderAccount(QWidget* parent = 0); + virtual ~FormEditInoreaderAccount(); + + InoreaderServiceRoot* execForCreate(); + + private slots: + void testSetup(); + + private: + Ui::FormEditInoreaderAccount m_ui; + InoreaderNetworkFactory m_network; + InoreaderServiceRoot* m_editableRoot; +}; + +#endif // FORMEDITINOREADERACCOUNT_H diff --git a/src/services/inoreader/gui/formeditinoreaderaccount.ui b/src/services/inoreader/gui/formeditinoreaderaccount.ui new file mode 100755 index 000000000..879a6e9f9 --- /dev/null +++ b/src/services/inoreader/gui/formeditinoreaderaccount.ui @@ -0,0 +1,99 @@ + + + FormEditInoreaderAccount + + + + 0 + 0 + 400 + 157 + + + + Dialog + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + + &Test login + + + + + + + + 0 + 0 + + + + Qt::RightToLeft + + + + + + + + + + LabelWithStatus + QWidget +
labelwithstatus.h
+ 1 +
+
+ + m_btnTestSetup + + + + + m_buttonBox + accepted() + FormEditInoreaderAccount + accept() + + + 248 + 254 + + + 157 + 274 + + + + + m_buttonBox + rejected() + FormEditInoreaderAccount + reject() + + + 316 + 260 + + + 286 + 274 + + + + +
diff --git a/src/services/inoreader/inoreaderentrypoint.cpp b/src/services/inoreader/inoreaderentrypoint.cpp index c2e15e2d8..cae562d9f 100755 --- a/src/services/inoreader/inoreaderentrypoint.cpp +++ b/src/services/inoreader/inoreaderentrypoint.cpp @@ -23,14 +23,14 @@ #include "miscellaneous/databasequeries.h" #include "miscellaneous/iconfactory.h" #include "services/inoreader/definitions.h" +#include "services/inoreader/gui/formeditinoreaderaccount.h" +#include "services/inoreader/inoreaderserviceroot.h" #include "services/inoreader/network/inoreadernetworkfactory.h" -InoreaderEntryPoint::InoreaderEntryPoint() {} - -InoreaderEntryPoint::~InoreaderEntryPoint() {} - ServiceRoot* InoreaderEntryPoint::createNewRoot() const { - return nullptr; + FormEditInoreaderAccount form_acc(qApp->mainFormWidget()); + + return form_acc.execForCreate(); } QList InoreaderEntryPoint::initializeSubtree() const { diff --git a/src/services/inoreader/inoreaderentrypoint.h b/src/services/inoreader/inoreaderentrypoint.h index 0d2391c30..ad7b8e87f 100755 --- a/src/services/inoreader/inoreaderentrypoint.h +++ b/src/services/inoreader/inoreaderentrypoint.h @@ -23,9 +23,6 @@ class InoreaderEntryPoint : public ServiceEntryPoint { public: - explicit InoreaderEntryPoint(); - virtual ~InoreaderEntryPoint(); - ServiceRoot* createNewRoot() const; QList initializeSubtree() const; diff --git a/src/services/inoreader/network/inoreadernetworkfactory.cpp b/src/services/inoreader/network/inoreadernetworkfactory.cpp index 1fa38780e..38490dd91 100755 --- a/src/services/inoreader/network/inoreadernetworkfactory.cpp +++ b/src/services/inoreader/network/inoreadernetworkfactory.cpp @@ -76,12 +76,14 @@ void InoreaderNetworkFactory::initializeOauth() { }); connect(&m_oauth2, &QOAuth2AuthorizationCodeFlow::granted, [=]() { qDebug("Inoreader: Oauth2 granted."); + emit accessGranted(); }); - connect(&m_oauth2, &QOAuth2AuthorizationCodeFlow::error, [](const QString& error, const QString& error_description, const QUrl& uri) { - Q_UNUSED(error) + connect(&m_oauth2, &QOAuth2AuthorizationCodeFlow::error, [=](QString err, QString error_description, QUrl uri) { + Q_UNUSED(err) Q_UNUSED(uri) qCritical("Inoreader: We have error: '%s'.", qPrintable(error_description)); + emit error(error_description); }); connect(&m_oauth2, &QOAuth2AuthorizationCodeFlow::authorizeWithBrowser, [](const QUrl& url) { qApp->web()->openUrlInExternalBrowser(url.toString()); diff --git a/src/services/inoreader/network/inoreadernetworkfactory.h b/src/services/inoreader/network/inoreadernetworkfactory.h index c3297abf7..359214224 100755 --- a/src/services/inoreader/network/inoreadernetworkfactory.h +++ b/src/services/inoreader/network/inoreadernetworkfactory.h @@ -35,6 +35,10 @@ class InoreaderNetworkFactory : public QObject { void logIn(); void logInIfNeeded(); + signals: + void accessGranted(); + void error(QString& description); + private: void initializeOauth(); diff --git a/src/services/owncloud/gui/formeditowncloudaccount.cpp b/src/services/owncloud/gui/formeditowncloudaccount.cpp index 06c5ef6e1..5f14ecf21 100755 --- a/src/services/owncloud/gui/formeditowncloudaccount.cpp +++ b/src/services/owncloud/gui/formeditowncloudaccount.cpp @@ -95,12 +95,14 @@ OwnCloudServiceRoot* FormEditOwnCloudAccount::execForCreate() { void FormEditOwnCloudAccount::execForEdit(OwnCloudServiceRoot* existing_root) { setWindowTitle(tr("Edit existing ownCloud News account")); + m_editableRoot = existing_root; m_ui->m_txtUsername->lineEdit()->setText(existing_root->network()->authUsername()); m_ui->m_txtPassword->lineEdit()->setText(existing_root->network()->authPassword()); m_ui->m_txtUrl->lineEdit()->setText(existing_root->network()->url()); m_ui->m_checkServerSideUpdate->setChecked(existing_root->network()->forceServerSideUpdate()); m_ui->m_spinLimitMessages->setValue(existing_root->network()->batchSize()); + exec(); } diff --git a/src/services/owncloud/owncloudserviceentrypoint.cpp b/src/services/owncloud/owncloudserviceentrypoint.cpp index 2eb79b239..1a95cbfc6 100755 --- a/src/services/owncloud/owncloudserviceentrypoint.cpp +++ b/src/services/owncloud/owncloudserviceentrypoint.cpp @@ -26,10 +26,6 @@ #include "services/owncloud/gui/formeditowncloudaccount.h" #include "services/owncloud/owncloudserviceroot.h" -OwnCloudServiceEntryPoint::OwnCloudServiceEntryPoint() {} - -OwnCloudServiceEntryPoint::~OwnCloudServiceEntryPoint() {} - ServiceRoot* OwnCloudServiceEntryPoint::createNewRoot() const { FormEditOwnCloudAccount form_acc(qApp->mainFormWidget()); diff --git a/src/services/owncloud/owncloudserviceentrypoint.h b/src/services/owncloud/owncloudserviceentrypoint.h index 3f483577a..f0ed56ece 100755 --- a/src/services/owncloud/owncloudserviceentrypoint.h +++ b/src/services/owncloud/owncloudserviceentrypoint.h @@ -23,9 +23,6 @@ class OwnCloudServiceEntryPoint : public ServiceEntryPoint { public: - explicit OwnCloudServiceEntryPoint(); - virtual ~OwnCloudServiceEntryPoint(); - ServiceRoot* createNewRoot() const; QList initializeSubtree() const; diff --git a/src/services/standard/standardserviceentrypoint.cpp b/src/services/standard/standardserviceentrypoint.cpp index e74088a36..f1dd8a42c 100755 --- a/src/services/standard/standardserviceentrypoint.cpp +++ b/src/services/standard/standardserviceentrypoint.cpp @@ -23,10 +23,6 @@ #include "miscellaneous/databasequeries.h" #include "services/standard/standardserviceroot.h" -StandardServiceEntryPoint::StandardServiceEntryPoint() {} - -StandardServiceEntryPoint::~StandardServiceEntryPoint() {} - bool StandardServiceEntryPoint::isSingleInstanceService() const { return true; } diff --git a/src/services/standard/standardserviceentrypoint.h b/src/services/standard/standardserviceentrypoint.h index 923c0fe4e..981d106fe 100755 --- a/src/services/standard/standardserviceentrypoint.h +++ b/src/services/standard/standardserviceentrypoint.h @@ -23,9 +23,6 @@ class StandardServiceEntryPoint : public ServiceEntryPoint { public: - explicit StandardServiceEntryPoint(); - virtual ~StandardServiceEntryPoint(); - bool isSingleInstanceService() const; QString name() const; QString description() const; diff --git a/src/services/tt-rss/ttrssserviceentrypoint.cpp b/src/services/tt-rss/ttrssserviceentrypoint.cpp index 7cc7e41b6..3dca61085 100755 --- a/src/services/tt-rss/ttrssserviceentrypoint.cpp +++ b/src/services/tt-rss/ttrssserviceentrypoint.cpp @@ -25,12 +25,6 @@ #include "services/tt-rss/gui/formeditttrssaccount.h" #include "services/tt-rss/ttrssserviceroot.h" -#include - -TtRssServiceEntryPoint::TtRssServiceEntryPoint() {} - -TtRssServiceEntryPoint::~TtRssServiceEntryPoint() {} - bool TtRssServiceEntryPoint::isSingleInstanceService() const { return false; } @@ -59,8 +53,9 @@ QString TtRssServiceEntryPoint::code() const { } ServiceRoot* TtRssServiceEntryPoint::createNewRoot() const { - QScopedPointer form_acc(new FormEditTtRssAccount(qApp->mainFormWidget())); - return form_acc->execForCreate(); + FormEditTtRssAccount form_acc(qApp->mainFormWidget()); + + return form_acc.execForCreate(); } QList TtRssServiceEntryPoint::initializeSubtree() const { diff --git a/src/services/tt-rss/ttrssserviceentrypoint.h b/src/services/tt-rss/ttrssserviceentrypoint.h index cdc1c7f51..c8a2e0137 100755 --- a/src/services/tt-rss/ttrssserviceentrypoint.h +++ b/src/services/tt-rss/ttrssserviceentrypoint.h @@ -23,9 +23,6 @@ class TtRssServiceEntryPoint : public ServiceEntryPoint { public: - explicit TtRssServiceEntryPoint(); - virtual ~TtRssServiceEntryPoint(); - bool isSingleInstanceService() const; QString name() const; QString description() const;