Cleaned up add acc dialog.

This commit is contained in:
Martin Rotter 2017-09-21 10:22:18 +02:00
parent 843795fd88
commit 45ea9a68be
15 changed files with 54 additions and 190 deletions

@ -1 +1 @@
Subproject commit d44aacc99fdc997648c924f0d5444566164f142e
Subproject commit e9833a2e45d8d3241f662d3a03ed19d3446386ce

View File

@ -19,6 +19,7 @@
#include "gui/dialogs/formaddaccount.h"
#include "core/feedsmodel.h"
#include "gui/guiutilities.h"
#include "miscellaneous/application.h"
#include "miscellaneous/iconfactory.h"
#include "services/standard/standardserviceentrypoint.h"
@ -31,11 +32,11 @@ FormAddAccount::FormAddAccount(const QList<ServiceEntryPoint*>& entry_points, Fe
m_ui->setupUi(this);
// Set flags and attributes.
setWindowFlags(Qt::MSWindowsFixedSizeDialogHint | Qt::Dialog | Qt::WindowSystemMenuHint);
setWindowIcon(qApp->icons()->fromTheme(QSL("document-new")));
GuiUtilities::applyDialogProperties(*this, qApp->icons()->fromTheme(QSL("document-new")));
connect(m_ui->m_listEntryPoints, &QListWidget::itemDoubleClicked, this, &FormAddAccount::addSelectedAccount);
connect(m_ui->m_buttonBox, &QDialogButtonBox::accepted, this, &FormAddAccount::addSelectedAccount);
connect(m_ui->m_listEntryPoints, &QListWidget::itemSelectionChanged, this, &FormAddAccount::displayActiveEntryPointDetails);
loadEntryPoints();
}
@ -56,15 +57,6 @@ void FormAddAccount::addSelectedAccount() {
}
}
void FormAddAccount::displayActiveEntryPointDetails() {
const ServiceEntryPoint* point = selectedEntryPoint();
m_ui->m_txtAuthor->setText(point->author());
m_ui->m_txtDescription->setText(point->description());
m_ui->m_txtName->setText(point->name());
m_ui->m_txtVersion->setText(point->version());
}
ServiceEntryPoint* FormAddAccount::selectedEntryPoint() const {
return m_entryPoints.at(m_ui->m_listEntryPoints->currentRow());
}
@ -78,6 +70,9 @@ void FormAddAccount::loadEntryPoints() {
item->setFlags(Qt::NoItemFlags);
item->setToolTip(tr("This account can be added only once."));
}
else {
item->setToolTip(entry_point->description());
}
}
m_ui->m_listEntryPoints->setCurrentRow(m_entryPoints.size() - 1);

View File

@ -35,7 +35,6 @@ class FormAddAccount : public QDialog {
private slots:
void addSelectedAccount();
void displayActiveEntryPointDetails();
private:
ServiceEntryPoint* selectedEntryPoint() const;

View File

@ -6,15 +6,25 @@
<rect>
<x>0</x>
<y>0</y>
<width>685</width>
<width>338</width>
<height>300</height>
</rect>
</property>
<property name="windowTitle">
<string>Add new account</string>
</property>
<layout class="QFormLayout" name="formLayout">
<item row="0" column="0">
<layout class="QFormLayout" name="formLayout_2">
<item row="1" column="0" colspan="2">
<widget class="QDialogButtonBox" name="m_buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
<item row="0" column="0" colspan="2">
<widget class="QListWidget" name="m_listEntryPoints">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
@ -33,95 +43,11 @@
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QGroupBox" name="m_grpEntryPointDetails">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>1</verstretch>
</sizepolicy>
</property>
<property name="title">
<string>Details</string>
</property>
<layout class="QFormLayout" name="formLayout_2">
<item row="0" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>Name</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLineEdit" name="m_txtName">
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Version</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QLineEdit" name="m_txtVersion">
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_3">
<property name="text">
<string>Author</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QLineEdit" name="m_txtAuthor">
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="label_4">
<property name="text">
<string>Description</string>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QTextEdit" name="m_txtDescription">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>1</verstretch>
</sizepolicy>
</property>
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item row="1" column="0" colspan="2">
<widget class="QDialogButtonBox" name="m_buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
</layout>
</widget>
<tabstops>
<tabstop>m_listEntryPoints</tabstop>
</tabstops>
<resources/>
<connections>
<connection>

View File

@ -29,14 +29,8 @@ class FeedsModel;
// TOP LEVEL class which provides basic information about the "service"
class ServiceEntryPoint {
public:
// Constructors.
virtual ~ServiceEntryPoint();
/////////////////////////////////////////
// /* Members to override.
/////////////////////////////////////////
// Creates new service root item, which is ready to be added
// into the model. This method can for example display
// some kind of first-time configuration dialog inside itself
@ -65,18 +59,11 @@ class ServiceEntryPoint {
// Human readable service description, for example "Services which offers TT-RSS integration.".
virtual QString description() const = 0;
// Version of the service, using of semantic versioning is recommended.
virtual QString version() const = 0;
// Author of the service.
virtual QString author() const = 0;
// Icon of the service.
virtual QIcon icon() const = 0;
/////////////////////////////////////////
// Members to override. */
/////////////////////////////////////////
};
#endif // SERVICE_H

View File

@ -23,6 +23,7 @@
#include "miscellaneous/databasequeries.h"
#include "miscellaneous/iconfactory.h"
#include "services/inoreader/definitions.h"
#include "services/inoreader/network/inoreadernetworkfactory.h"
InoreaderEntryPoint::InoreaderEntryPoint() {}
@ -37,7 +38,7 @@ QList<ServiceRoot*> InoreaderEntryPoint::initializeSubtree() const {
}
bool InoreaderEntryPoint::isSingleInstanceService() const {
return false;
return true;
}
QString InoreaderEntryPoint::name() const {
@ -52,10 +53,6 @@ QString InoreaderEntryPoint::description() const {
return QObject::tr("This is integration of Inoreader.");
}
QString InoreaderEntryPoint::version() const {
return APP_VERSION;
}
QString InoreaderEntryPoint::author() const {
return APP_AUTHOR;
}

View File

@ -33,7 +33,6 @@ class InoreaderEntryPoint : public ServiceEntryPoint {
QString name() const;
QString code() const;
QString description() const;
QString version() const;
QString author() const;
QIcon icon() const;
};

View File

@ -38,8 +38,19 @@ bool InoreaderNetworkFactory::isLoggedIn() const {
}
void InoreaderNetworkFactory::logIn() {
if (!m_oauth2.expirationAt().isNull() && m_oauth2.expirationAt() <= QDateTime::currentDateTime()) {
m_oauth2.refreshAccessToken();
}
else {
m_oauth2.grant();
}
}
void InoreaderNetworkFactory::logInIfNeeded() {
if (!isLoggedIn()) {
logIn();
}
}
void InoreaderNetworkFactory::initializeOauth() {
auto oauth_reply_handler = new QOAuthHttpServerReplyHandler(INOREADER_OAUTH_PORT, this);
@ -52,63 +63,27 @@ void InoreaderNetworkFactory::initializeOauth() {
m_oauth2.setClientIdentifier(INOREADER_OAUTH_CLI_ID);
m_oauth2.setClientIdentifierSharedKey(INOREADER_OAUTH_CLI_KEY);
m_oauth2.setContentType(QAbstractOAuth::ContentType::Json);
m_oauth2.setNetworkAccessManager(new SilentNetworkAccessManager(this));
m_oauth2.setNetworkAccessManager(SilentNetworkAccessManager::instance());
m_oauth2.setReplyHandler(oauth_reply_handler);
m_oauth2.setUserAgent(APP_USERAGENT);
m_oauth2.setScope(INOREADER_OAUTH_SCOPE);
connect(&m_oauth2, &QOAuth2AuthorizationCodeFlow::statusChanged, [=](QAbstractOAuth::Status status) {});
m_oauth2.setModifyParametersFunction([&](QAbstractOAuth::Stage stage, QVariantMap* parameters) {});
connect(&m_oauth2, &QOAuth2AuthorizationCodeFlow::granted, [=]() {
int a = 5;
connect(&m_oauth2, &QOAuth2AuthorizationCodeFlow::statusChanged, [=](QAbstractOAuth::Status status) {
qDebug("Inoreader: Status changed to '%d'.", (int)status);
});
m_oauth2.setModifyParametersFunction([&](QAbstractOAuth::Stage stage, QVariantMap* parameters) {
qDebug() << "Inoreader: Set modify parameters for stage" << (int)stage << "called: \n" << parameters;
});
connect(&m_oauth2, &QOAuth2AuthorizationCodeFlow::granted, [=]() {
qDebug("Inoreader: Oauth2 granted.");
});
connect(&m_oauth2, &QOAuth2AuthorizationCodeFlow::error, [](const QString& error, const QString& error_description, const QUrl& uri) {
Q_UNUSED(error)
Q_UNUSED(uri)
qCritical("Inoreader: We have error: '%s'.", qPrintable(error_description));
});
connect(&m_oauth2, &QOAuth2AuthorizationCodeFlow::error, [](const QString& error, const QString& errorDescription, const QUrl& uri) {});
connect(&m_oauth2, &QOAuth2AuthorizationCodeFlow::authorizeWithBrowser, [](const QUrl& url) {
qApp->web()->openUrlInExternalBrowser(url.toString());
});
}
/*
QOAuth2AuthorizationCodeFlow* oauth2 = new QOAuth2AuthorizationCodeFlow("1000000604",
QUrl("https://www.inoreader.com/oauth2/auth"),
QUrl("https://www.inoreader.com/oauth2/token"),
new SilentNetworkAccessManager(),
this);
auto replyHandler = new QOAuthHttpServerReplyHandler(8080, this);
replyHandler->setCallbackPath("");
oauth2->setReplyHandler(replyHandler);
oauth2->setClientIdentifierSharedKey("gsStoZ3aAoQJCgQxoFSuXkWI7Sly87yK");
oauth2->setContentType(QAbstractOAuth::ContentType::Json);
oauth2->setScope("read write");
connect(oauth2, &QOAuth2AuthorizationCodeFlow::statusChanged, [=](
QAbstractOAuth::Status status) {
if (status == QAbstractOAuth::Status::Granted) {
int a = 5;
}
});
oauth2->setModifyParametersFunction([&](QAbstractOAuth::Stage stage, QVariantMap* parameters) {
if (stage == QAbstractOAuth::Stage::RequestingAuthorization) {
int b = 6;
}
});
connect(oauth2, &QOAuth2AuthorizationCodeFlow::granted, [ = ] {
int c = 45;
auto* reply = oauth2->get(QUrl("https://www.inoreader.com/reader/api/0/subscription/list"));
connect(reply, &QNetworkReply::finished, [=]() {
const auto json = reply->readAll();
const auto document = QJsonDocument::fromJson(json);
});
});
connect(oauth2, &QOAuth2AuthorizationCodeFlow::error, [](const QString& error, const QString& errorDescription, const QUrl& uri) {
int d = 5;
});
connect(oauth2, &QOAuth2AuthorizationCodeFlow::authorizeWithBrowser, &QDesktopServices::openUrl);
oauth2->grant();
*/

View File

@ -33,6 +33,7 @@ class InoreaderNetworkFactory : public QObject {
public slots:
void logIn();
void logInIfNeeded();
private:
void initializeOauth();

View File

@ -59,10 +59,6 @@ QString OwnCloudServiceEntryPoint::description() const {
.arg(API_VERSION);
}
QString OwnCloudServiceEntryPoint::version() const {
return APP_VERSION;
}
QString OwnCloudServiceEntryPoint::author() const {
return APP_AUTHOR;
}

View File

@ -33,7 +33,6 @@ class OwnCloudServiceEntryPoint : public ServiceEntryPoint {
QString name() const;
QString code() const;
QString description() const;
QString version() const;
QString author() const;
QIcon icon() const;
};

View File

@ -39,10 +39,6 @@ QString StandardServiceEntryPoint::description() const {
return QObject::tr("This service offers integration with standard online RSS/RDF/ATOM feeds and podcasts.");
}
QString StandardServiceEntryPoint::version() const {
return APP_VERSION;
}
QString StandardServiceEntryPoint::author() const {
return APP_AUTHOR;
}

View File

@ -29,7 +29,6 @@ class StandardServiceEntryPoint : public ServiceEntryPoint {
bool isSingleInstanceService() const;
QString name() const;
QString description() const;
QString version() const;
QString author() const;
QIcon icon() const;
QString code() const;

View File

@ -46,10 +46,6 @@ QString TtRssServiceEntryPoint::description() const {
"desktop application as possible.\n\nAt least API level %1 is required.").arg(MINIMAL_API_LEVEL);
}
QString TtRssServiceEntryPoint::version() const {
return APP_VERSION;
}
QString TtRssServiceEntryPoint::author() const {
return APP_AUTHOR;
}

View File

@ -29,7 +29,6 @@ class TtRssServiceEntryPoint : public ServiceEntryPoint {
bool isSingleInstanceService() const;
QString name() const;
QString description() const;
QString version() const;
QString author() const;
QIcon icon() const;
QString code() const;