fix build work on feedly

This commit is contained in:
Martin Rotter 2021-02-12 20:37:27 +01:00
parent c6c84daaed
commit 6f21368e19
10 changed files with 105 additions and 35 deletions

@ -1 +1 @@
Subproject commit 47f4125753452eff8800dbd6600c5a05540b15d9
Subproject commit 9c10723bfbaf6cb85107d6ee16e0324e9e487749

View File

@ -0,0 +1,11 @@
// For license of this file, see <project-root-folder>/LICENSE.md.
#include "exceptions/networkexception.h"
#include "network-web/networkfactory.h"
NetworkException::NetworkException(QNetworkReply::NetworkError error) : ApplicationException(NetworkFactory::networkErrorText(error)) {}
QNetworkReply::NetworkError NetworkException::networkError() const {
return m_networkError;
}

View File

@ -0,0 +1,20 @@
// For license of this file, see <project-root-folder>/LICENSE.md.
#ifndef NETWORKEXCEPTION_H
#define NETWORKEXCEPTION_H
#include "exceptions/applicationexception.h"
#include <QNetworkReply>
class NetworkException : public ApplicationException {
public:
explicit NetworkException(QNetworkReply::NetworkError error);
QNetworkReply::NetworkError networkError() const;
private:
QNetworkReply::NetworkError m_networkError;
};
#endif // NETWORKEXCEPTION_H

View File

@ -50,6 +50,7 @@ HEADERS += core/feeddownloader.h \
exceptions/applicationexception.h \
exceptions/filteringexception.h \
exceptions/ioexception.h \
exceptions/networkexception.h \
exceptions/scriptexception.h \
gui/baselineedit.h \
gui/basetoolbar.h \
@ -229,6 +230,7 @@ SOURCES += core/feeddownloader.cpp \
exceptions/applicationexception.cpp \
exceptions/filteringexception.cpp \
exceptions/ioexception.cpp \
exceptions/networkexception.cpp \
exceptions/scriptexception.cpp \
gui/baselineedit.cpp \
gui/basetoolbar.cpp \

View File

@ -1846,12 +1846,12 @@ bool DatabaseQueries::overwriteOwnCloudAccount(const QSqlDatabase& db, const QSt
bool DatabaseQueries::createFeedlyAccount(const QSqlDatabase& db, const QString& username,
const QString& developer_access_token, const QString& refresh_token,
int batch_size, int id_to_assign) {
int batch_size, int account_id) {
QSqlQuery q(db);
q.prepare("INSERT INTO FeedlyAccounts (id, username, developer_access_token, refresh_token, msg_limit) "
"VALUES (:id, :username, :developer_access_token, :refresh_token, :msg_limit);");
q.bindValue(QSL(":id"), id_to_assign);
q.bindValue(QSL(":id"), account_id);
q.bindValue(QSL(":username"), username);
q.bindValue(QSL(":developer_access_token"), developer_access_token);
q.bindValue(QSL(":refresh_token"), refresh_token);
@ -1870,8 +1870,26 @@ bool DatabaseQueries::createFeedlyAccount(const QSqlDatabase& db, const QString&
bool DatabaseQueries::overwriteFeedlyAccount(const QSqlDatabase& db, const QString& username,
const QString& developer_access_token, const QString& refresh_token,
int batch_size, int id_to_assign) {
return {};
int batch_size, int account_id) {
QSqlQuery query(db);
query.prepare("UPDATE FeedlyAccounts "
"SET username = :username, developer_access_token = :developer_access_token, "
"refresh_token = :refresh_token, msg_limit = :msg_limit "
"WHERE id = :id;");
query.bindValue(QSL(":id"), account_id);
query.bindValue(QSL(":username"), username);
query.bindValue(QSL(":developer_access_token"), developer_access_token);
query.bindValue(QSL(":refresh_token"), refresh_token);
query.bindValue(QSL(":msg_limit"), batch_size <= 0 ? FEEDLY_UNLIMITED_BATCH_SIZE : batch_size);
if (query.exec()) {
return true;
}
else {
qCriticalNN << LOGSEC_FEEDLY << "Updating account failed:" << QUOTE_W_SPACE_DOT(query.lastError().text());
return false;
}
}
bool DatabaseQueries::createGreaderAccount(const QSqlDatabase& db, int id_to_assign, const QString& username,
@ -2604,7 +2622,11 @@ QList<ServiceRoot*> DatabaseQueries::getFeedlyAccounts(const QSqlDatabase& db, b
root->setAccountId(query.value(0).toInt());
root->network()->setUsername(query.value(1).toString());
root->network()->setDeveloperAccessToken(query.value(2).toString());
#if defined (FEEDLY_OFFICIAL_SUPPORT)
root->network()->oauth()->setRefreshToken(query.value(3).toString());
#endif
root->network()->setBatchSize(query.value(4).toInt());
root->updateTitle();

View File

@ -159,13 +159,13 @@ class DatabaseQueries {
const QString& developer_access_token,
const QString& refresh_token,
int batch_size,
int id_to_assign);
int account_id);
static bool overwriteFeedlyAccount(const QSqlDatabase& db,
const QString& username,
const QString& developer_access_token,
const QString& refresh_token,
int batch_size,
int id_to_assign);
int account_id);
// Greader account.
static bool deleteGreaderAccount(const QSqlDatabase& db, int account_id);

View File

@ -9,7 +9,7 @@
#define FEEDLY_API_REDIRECT_URI_PORT 8080
#define FEEDLY_API_SCOPE "https://cloud.feedly.com/subscriptions"
#if defined(DEBUG)
#if defined(NDEBUG)
#define FEEDLY_API_URL_BASE "https://sandbox7.feedly.com/v3/"
#else
#define FEEDLY_API_URL_BASE "https://cloud.feedly.com/v3/"

View File

@ -3,10 +3,10 @@
#include "services/feedly/feedlynetwork.h"
#include "3rd-party/boolinq/boolinq.h"
#include "exceptions/networkexception.h"
#include "miscellaneous/application.h"
#include "network-web/networkfactory.h"
#include "miscellaneous/databasequeries.h"
#include "network-web/networkfactory.h"
#include "network-web/webfactory.h"
#include "services/abstract/category.h"
#include "services/abstract/label.h"
@ -44,34 +44,45 @@ FeedlyNetwork::FeedlyNetwork(QObject* parent)
#endif
}
QString FeedlyNetwork::profile(const QNetworkProxy& network_proxy) {
RootItem* FeedlyNetwork::personalCollections(bool obtain_icons, const QNetworkProxy& proxy) {
QString bear = bearer();
if (bear.isEmpty()) {
qCriticalNN << LOGSEC_FEEDLY
<< "Cannot obtain profile information, because bearer is empty.";
return {};
qCriticalNN << LOGSEC_FEEDLY << "Cannot obtain personal collections, because bearer is empty.";
throw NetworkException(QNetworkReply::NetworkError::AuthenticationRequiredError);
}
else {
QString target_url = fullUrl(Service::Profile);
int timeout = qApp->settings()->value(GROUP(Feeds), SETTING(Feeds::UpdateTimeout)).toInt();
QByteArray output_msgs;
}
// This method uses proxy via parameter,
// not via "m_service" field.
auto result = NetworkFactory::performNetworkOperation(target_url,
timeout,
{},
output_msgs,
QNetworkAccessManager::Operation::GetOperation,
{ bearerHeader(bear) },
false,
{},
{},
network_proxy);
QVariantHash FeedlyNetwork::profile(const QNetworkProxy& network_proxy) {
QString bear = bearer();
return output_msgs;
if (bear.isEmpty()) {
qCriticalNN << LOGSEC_FEEDLY << "Cannot obtain profile information, because bearer is empty.";
throw NetworkException(QNetworkReply::NetworkError::AuthenticationRequiredError);
}
QString target_url = fullUrl(Service::Profile);
int timeout = qApp->settings()->value(GROUP(Feeds), SETTING(Feeds::UpdateTimeout)).toInt();
QByteArray output_msgs;
// This method uses proxy via parameter,
// not via "m_service" field.
auto result = NetworkFactory::performNetworkOperation(target_url,
timeout,
{},
output_msgs,
QNetworkAccessManager::Operation::GetOperation,
{ bearerHeader(bear) },
false,
{},
{},
network_proxy);
if (result.first != QNetworkReply::NetworkError::NoError) {
throw NetworkException(result.first);
}
return QJsonDocument::fromJson(output_msgs).object().toVariantHash();
}
QString FeedlyNetwork::username() const {

View File

@ -21,7 +21,7 @@ class FeedlyNetwork : public QObject {
explicit FeedlyNetwork(QObject* parent = nullptr);
// API operations.
QString profile(const QNetworkProxy& network_proxy);
QVariantHash profile(const QNetworkProxy& network_proxy);
// Getters and setters.
QString username() const;

View File

@ -3,6 +3,7 @@
#include "services/feedly/gui/feedlyaccountdetails.h"
#include "definitions/definitions.h"
#include "exceptions/networkexception.h"
#include "gui/guiutilities.h"
#include "miscellaneous/application.h"
#include "miscellaneous/systemfactory.h"
@ -14,6 +15,8 @@
#include "network-web/oauth2service.h"
#endif
#include <QVariantHash>
FeedlyAccountDetails::FeedlyAccountDetails(QWidget* parent) : QWidget(parent) {
#if defined (FEEDLY_OFFICIAL_SUPPORT)
m_oauth = new OAuth2Service(QSL(FEEDLY_API_URL_BASE) + FEEDLY_API_URL_AUTH,
@ -131,14 +134,15 @@ void FeedlyAccountDetails::performTest(const QNetworkProxy& custom_proxy) {
factory.setUsername(m_ui.m_txtUsername->lineEdit()->text());
factory.setDeveloperAccessToken(m_ui.m_txtDeveloperAccessToken->lineEdit()->text());
if (!factory.profile(custom_proxy).isEmpty()) {
try {
m_ui.m_txtUsername->lineEdit()->setText(factory.profile(custom_proxy)["email"].toString());
m_ui.m_lblTestResult->setStatus(WidgetWithStatus::StatusType::Ok,
tr("Login was successful."),
tr("Access granted."));
}
else {
catch (const NetworkException& ex) {
m_ui.m_lblTestResult->setStatus(WidgetWithStatus::StatusType::Error,
tr("Make sure your \"development access token\" is correct and your internet works."),
tr("Error: '%1'").arg(ex.message()),
tr("Some problems."));
}
}