Cleanups.
This commit is contained in:
parent
a6eaedb918
commit
d045e7ea72
@ -34,6 +34,7 @@
|
||||
#include "services/tt-rss/ttrssserviceroot.h"
|
||||
|
||||
#if defined(USE_WEBENGINE)
|
||||
#include "network-web/oauth2service.h"
|
||||
#include "services/inoreader/inoreaderfeed.h"
|
||||
#include "services/inoreader/inoreaderserviceroot.h"
|
||||
#include "services/inoreader/network/inoreadernetworkfactory.h"
|
||||
@ -1530,8 +1531,8 @@ QList<ServiceRoot*> DatabaseQueries::getInoreaderAccounts(QSqlDatabase db, bool*
|
||||
root->setId(query.value(0).toInt());
|
||||
root->setAccountId(query.value(0).toInt());
|
||||
root->network()->setUsername(query.value(1).toString());
|
||||
root->network()->setAccessToken(query.value(2).toString());
|
||||
root->network()->setRefreshToken(query.value(3).toString());
|
||||
root->network()->oauth()->setAccessToken(query.value(2).toString());
|
||||
root->network()->oauth()->setRefreshToken(query.value(3).toString());
|
||||
root->network()->setBatchSize(query.value(4).toInt());
|
||||
root->updateTitle();
|
||||
roots.append(root);
|
||||
|
@ -19,7 +19,6 @@
|
||||
#ifndef INOREADER_DEFINITIONS_H
|
||||
#define INOREADER_DEFINITIONS_H
|
||||
|
||||
#define INOREADER_OAUTH_PORT 12885
|
||||
#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"
|
||||
|
@ -109,11 +109,6 @@ void FormEditInoreaderAccount::hookNetwork() {
|
||||
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),
|
||||
|
@ -22,10 +22,12 @@
|
||||
#include "miscellaneous/application.h"
|
||||
#include "miscellaneous/databasequeries.h"
|
||||
#include "miscellaneous/iconfactory.h"
|
||||
#include "network-web/oauth2service.h"
|
||||
#include "services/abstract/recyclebin.h"
|
||||
#include "services/inoreader/gui/formeditinoreaderaccount.h"
|
||||
#include "services/inoreader/inoreaderentrypoint.h"
|
||||
#include "services/inoreader/network/inoreadernetworkfactory.h"
|
||||
#include "services/inoreader/network/inoreadernetworkfactory.h"
|
||||
|
||||
InoreaderServiceRoot::InoreaderServiceRoot(InoreaderNetworkFactory* network, RootItem* parent) : ServiceRoot(parent),
|
||||
m_serviceMenu(QList<QAction*>()), m_network(network) {
|
||||
@ -63,8 +65,8 @@ void InoreaderServiceRoot::saveAccountDataToDatabase() {
|
||||
QSqlDatabase database = qApp->database()->connection(metaObject()->className(), DatabaseFactory::FromSettings);
|
||||
|
||||
if (accountId() != NO_PARENT_CATEGORY) {
|
||||
if (DatabaseQueries::overwriteInoreaderAccount(database, m_network->userName(), m_network->accessToken(),
|
||||
m_network->refreshToken(), m_network->batchSize(),
|
||||
if (DatabaseQueries::overwriteInoreaderAccount(database, m_network->userName(), m_network->oauth()->accessToken(),
|
||||
m_network->oauth()->refreshToken(), m_network->batchSize(),
|
||||
accountId())) {
|
||||
updateTitle();
|
||||
itemChanged(QList<RootItem*>() << this);
|
||||
@ -76,8 +78,8 @@ void InoreaderServiceRoot::saveAccountDataToDatabase() {
|
||||
|
||||
if (saved) {
|
||||
if (DatabaseQueries::createInoreaderAccount(database, id_to_assign,
|
||||
m_network->userName(), m_network->accessToken(),
|
||||
m_network->refreshToken(), m_network->batchSize())) {
|
||||
m_network->userName(), m_network->oauth()->accessToken(),
|
||||
m_network->oauth()->refreshToken(), m_network->batchSize())) {
|
||||
setId(id_to_assign);
|
||||
setAccountId(id_to_assign);
|
||||
updateTitle();
|
||||
|
@ -23,6 +23,7 @@
|
||||
#include "gui/tabwidget.h"
|
||||
#include "miscellaneous/application.h"
|
||||
#include "network-web/networkfactory.h"
|
||||
#include "network-web/oauth2service.h"
|
||||
#include "network-web/silentnetworkaccessmanager.h"
|
||||
#include "network-web/webfactory.h"
|
||||
#include "services/abstract/category.h"
|
||||
@ -31,21 +32,21 @@
|
||||
#include <QJsonArray>
|
||||
#include <QJsonDocument>
|
||||
#include <QJsonObject>
|
||||
#include <QOAuth2AuthorizationCodeFlow>
|
||||
#include <QOAuthHttpServerReplyHandler>
|
||||
#include <QUrl>
|
||||
|
||||
#include "network-web/oauth2service.h"
|
||||
|
||||
InoreaderNetworkFactory::InoreaderNetworkFactory(QObject* parent) : QObject(parent),
|
||||
m_username(QString()), m_refreshToken(QString()), m_batchSize(INOREADER_DEFAULT_BATCH_SIZE),
|
||||
m_username(QString()), m_batchSize(INOREADER_DEFAULT_BATCH_SIZE),
|
||||
m_oauth2(new OAuth2Service(INOREADER_OAUTH_AUTH_URL, INOREADER_OAUTH_TOKEN_URL,
|
||||
INOREADER_OAUTH_CLI_ID, INOREADER_OAUTH_CLI_KEY, "read")) {
|
||||
INOREADER_OAUTH_CLI_ID, INOREADER_OAUTH_CLI_KEY, INOREADER_OAUTH_SCOPE)) {
|
||||
initializeOauth();
|
||||
}
|
||||
|
||||
OAuth2Service* InoreaderNetworkFactory::oauth() const {
|
||||
return m_oauth2;
|
||||
}
|
||||
|
||||
bool InoreaderNetworkFactory::isLoggedIn() const {
|
||||
return false;
|
||||
return !m_oauth2->refreshToken().isEmpty();
|
||||
}
|
||||
|
||||
QString InoreaderNetworkFactory::userName() const {
|
||||
@ -70,16 +71,6 @@ void InoreaderNetworkFactory::logInIfNeeded() {
|
||||
}
|
||||
}
|
||||
|
||||
void InoreaderNetworkFactory::tokensReceived(QVariantMap tokens) {
|
||||
qDebug() << "Inoreader: Tokens received:" << tokens;
|
||||
|
||||
if (tokens.contains(INOREADER_REFRESH_TOKEN_KEY)) {
|
||||
m_refreshToken = tokens.value(INOREADER_REFRESH_TOKEN_KEY).toString();
|
||||
}
|
||||
|
||||
emit tokensRefreshed();
|
||||
}
|
||||
|
||||
void InoreaderNetworkFactory::initializeOauth() {
|
||||
connect(m_oauth2, &OAuth2Service::tokenRetrieveError, [](QString error, QString error_description) {
|
||||
qApp->showGuiMessage("Authentication error - Inoreader", error_description, QSystemTrayIcon::Critical);
|
||||
@ -90,10 +81,6 @@ void InoreaderNetworkFactory::setUsername(const QString& username) {
|
||||
m_username = username;
|
||||
}
|
||||
|
||||
void InoreaderNetworkFactory::setRefreshToken(const QString& refreshToken) {
|
||||
m_refreshToken = refreshToken;
|
||||
}
|
||||
|
||||
// NOTE: oauth: https://developers.google.com/oauthplayground/#step3&scopes=read%20write&auth_code=497815bc3362aba9ad60c5ae3e01811fe2da4bb5&refresh_token=bacb9c36f82ba92667282d6175bb857a091e7f0c&access_token_field=094f92bc7aedbd27fbebc3efc9172b258be8944a&url=https%3A%2F%2Fwww.inoreader.com%2Freader%2Fapi%2F0%2Fsubscription%2Flist&content_type=application%2Fjson&http_method=GET&useDefaultOauthCred=unchecked&oauthEndpointSelect=Custom&oauthAuthEndpointValue=https%3A%2F%2Fwww.inoreader.com%2Foauth2%2Fauth%3Fstate%3Dtest&oauthTokenEndpointValue=https%3A%2F%2Fwww.inoreader.com%2Foauth2%2Ftoken&oauthClientId=1000000595&expires_in=3599&oauthClientSecret=_6pYUZgtNLWwSaB9pC1YOz6p4zwu3haL&access_token_issue_date=1506198338&for_access_token=094f92bc7aedbd27fbebc3efc9172b258be8944a&includeCredentials=checked&accessTokenType=bearer&autoRefreshToken=unchecked&accessType=offline&prompt=consent&response_type=code
|
||||
|
||||
RootItem* InoreaderNetworkFactory::feedsCategories(bool obtain_icons) {
|
||||
@ -157,62 +144,4 @@ RootItem* InoreaderNetworkFactory::feedsCategories(bool obtain_icons) {
|
||||
loop.exec();
|
||||
|
||||
return parent;
|
||||
|
||||
/*
|
||||
// Process categories first, then process feeds.
|
||||
foreach (const QJsonValue& cat, QJsonDocument::fromJson(m_contentCategories.toUtf8()).object()["folders"].toArray()) {
|
||||
QJsonObject item = cat.toObject();
|
||||
Category* category = new Category();
|
||||
|
||||
category->setTitle(item["name"].toString());
|
||||
category->setCustomId(item["id"].toInt());
|
||||
cats.insert(category->customId(), category);
|
||||
|
||||
// All categories in ownCloud are top-level.
|
||||
parent->appendChild(category);
|
||||
}*/
|
||||
|
||||
/*
|
||||
// We have categories added, now add all feeds.
|
||||
foreach (const QJsonValue& fed, QJsonDocument::fromJson(m_contentFeeds.toUtf8()).object()["feeds"].toArray()) {
|
||||
QJsonObject item = fed.toObject();
|
||||
OwnCloudFeed* feed = new OwnCloudFeed();
|
||||
|
||||
if (obtain_icons) {
|
||||
QString icon_path = item["faviconLink"].toString();
|
||||
|
||||
if (!icon_path.isEmpty()) {
|
||||
QByteArray icon_data;
|
||||
|
||||
if (NetworkFactory::performNetworkOperation(icon_path, DOWNLOAD_TIMEOUT,
|
||||
QByteArray(), QString(), icon_data,
|
||||
QNetworkAccessManager::GetOperation).first ==
|
||||
QNetworkReply::NoError) {
|
||||
// Icon downloaded, set it up.
|
||||
QPixmap icon_pixmap;
|
||||
|
||||
icon_pixmap.loadFromData(icon_data);
|
||||
feed->setIcon(QIcon(icon_pixmap));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
feed->setUrl(item["link"].toString());
|
||||
feed->setTitle(item["title"].toString());
|
||||
feed->setCustomId(item["id"].toInt());
|
||||
qDebug("Custom ID of next fetched Nextcloud feed is '%d'.", item["id"].toInt());
|
||||
cats.value(item["folderId"].toInt())->appendChild(feed);
|
||||
}*/
|
||||
}
|
||||
|
||||
void InoreaderNetworkFactory::setAccessToken(const QString& accessToken) {
|
||||
//m_oauth2->setToken(accessToken);
|
||||
}
|
||||
|
||||
QString InoreaderNetworkFactory::refreshToken() const {
|
||||
return m_refreshToken;
|
||||
}
|
||||
|
||||
QString InoreaderNetworkFactory::accessToken() const {
|
||||
return "a";// m_oauth2->token();
|
||||
}
|
||||
|
@ -32,6 +32,8 @@ class InoreaderNetworkFactory : public QObject {
|
||||
public:
|
||||
explicit InoreaderNetworkFactory(QObject* parent = nullptr);
|
||||
|
||||
OAuth2Service* oauth() const;
|
||||
|
||||
bool isLoggedIn() const;
|
||||
|
||||
QString userName() const;
|
||||
@ -41,11 +43,6 @@ class InoreaderNetworkFactory : public QObject {
|
||||
int batchSize() const;
|
||||
void setBatchSize(int batch_size);
|
||||
|
||||
QString accessToken() const;
|
||||
QString refreshToken() const;
|
||||
void setAccessToken(const QString& accessToken);
|
||||
void setRefreshToken(const QString& refreshToken);
|
||||
|
||||
// Returns tree of feeds/categories.
|
||||
// Top-level root of the tree is not needed here.
|
||||
// Returned items do not have primary IDs assigned.
|
||||
@ -57,18 +54,13 @@ class InoreaderNetworkFactory : public QObject {
|
||||
|
||||
signals:
|
||||
void accessGranted();
|
||||
void tokensRefreshed();
|
||||
void error(QString& description);
|
||||
|
||||
private slots:
|
||||
void tokensReceived(QVariantMap tokens);
|
||||
|
||||
private:
|
||||
void initializeOauth();
|
||||
|
||||
private:
|
||||
QString m_username;
|
||||
QString m_refreshToken;
|
||||
int m_batchSize;
|
||||
OAuth2Service* m_oauth2;
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user