fix build work on feedly
This commit is contained in:
parent
c6c84daaed
commit
6f21368e19
@ -1 +1 @@
|
|||||||
Subproject commit 47f4125753452eff8800dbd6600c5a05540b15d9
|
Subproject commit 9c10723bfbaf6cb85107d6ee16e0324e9e487749
|
11
src/librssguard/exceptions/networkexception.cpp
Normal file
11
src/librssguard/exceptions/networkexception.cpp
Normal 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;
|
||||||
|
}
|
20
src/librssguard/exceptions/networkexception.h
Normal file
20
src/librssguard/exceptions/networkexception.h
Normal 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
|
@ -50,6 +50,7 @@ HEADERS += core/feeddownloader.h \
|
|||||||
exceptions/applicationexception.h \
|
exceptions/applicationexception.h \
|
||||||
exceptions/filteringexception.h \
|
exceptions/filteringexception.h \
|
||||||
exceptions/ioexception.h \
|
exceptions/ioexception.h \
|
||||||
|
exceptions/networkexception.h \
|
||||||
exceptions/scriptexception.h \
|
exceptions/scriptexception.h \
|
||||||
gui/baselineedit.h \
|
gui/baselineedit.h \
|
||||||
gui/basetoolbar.h \
|
gui/basetoolbar.h \
|
||||||
@ -229,6 +230,7 @@ SOURCES += core/feeddownloader.cpp \
|
|||||||
exceptions/applicationexception.cpp \
|
exceptions/applicationexception.cpp \
|
||||||
exceptions/filteringexception.cpp \
|
exceptions/filteringexception.cpp \
|
||||||
exceptions/ioexception.cpp \
|
exceptions/ioexception.cpp \
|
||||||
|
exceptions/networkexception.cpp \
|
||||||
exceptions/scriptexception.cpp \
|
exceptions/scriptexception.cpp \
|
||||||
gui/baselineedit.cpp \
|
gui/baselineedit.cpp \
|
||||||
gui/basetoolbar.cpp \
|
gui/basetoolbar.cpp \
|
||||||
|
@ -1846,12 +1846,12 @@ bool DatabaseQueries::overwriteOwnCloudAccount(const QSqlDatabase& db, const QSt
|
|||||||
|
|
||||||
bool DatabaseQueries::createFeedlyAccount(const QSqlDatabase& db, const QString& username,
|
bool DatabaseQueries::createFeedlyAccount(const QSqlDatabase& db, const QString& username,
|
||||||
const QString& developer_access_token, const QString& refresh_token,
|
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);
|
QSqlQuery q(db);
|
||||||
|
|
||||||
q.prepare("INSERT INTO FeedlyAccounts (id, username, developer_access_token, refresh_token, msg_limit) "
|
q.prepare("INSERT INTO FeedlyAccounts (id, username, developer_access_token, refresh_token, msg_limit) "
|
||||||
"VALUES (: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(":username"), username);
|
||||||
q.bindValue(QSL(":developer_access_token"), developer_access_token);
|
q.bindValue(QSL(":developer_access_token"), developer_access_token);
|
||||||
q.bindValue(QSL(":refresh_token"), refresh_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,
|
bool DatabaseQueries::overwriteFeedlyAccount(const QSqlDatabase& db, const QString& username,
|
||||||
const QString& developer_access_token, const QString& refresh_token,
|
const QString& developer_access_token, const QString& refresh_token,
|
||||||
int batch_size, int id_to_assign) {
|
int batch_size, int account_id) {
|
||||||
return {};
|
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,
|
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->setAccountId(query.value(0).toInt());
|
||||||
root->network()->setUsername(query.value(1).toString());
|
root->network()->setUsername(query.value(1).toString());
|
||||||
root->network()->setDeveloperAccessToken(query.value(2).toString());
|
root->network()->setDeveloperAccessToken(query.value(2).toString());
|
||||||
|
|
||||||
|
#if defined (FEEDLY_OFFICIAL_SUPPORT)
|
||||||
root->network()->oauth()->setRefreshToken(query.value(3).toString());
|
root->network()->oauth()->setRefreshToken(query.value(3).toString());
|
||||||
|
#endif
|
||||||
|
|
||||||
root->network()->setBatchSize(query.value(4).toInt());
|
root->network()->setBatchSize(query.value(4).toInt());
|
||||||
root->updateTitle();
|
root->updateTitle();
|
||||||
|
|
||||||
|
@ -159,13 +159,13 @@ class DatabaseQueries {
|
|||||||
const QString& developer_access_token,
|
const QString& developer_access_token,
|
||||||
const QString& refresh_token,
|
const QString& refresh_token,
|
||||||
int batch_size,
|
int batch_size,
|
||||||
int id_to_assign);
|
int account_id);
|
||||||
static bool overwriteFeedlyAccount(const QSqlDatabase& db,
|
static bool overwriteFeedlyAccount(const QSqlDatabase& db,
|
||||||
const QString& username,
|
const QString& username,
|
||||||
const QString& developer_access_token,
|
const QString& developer_access_token,
|
||||||
const QString& refresh_token,
|
const QString& refresh_token,
|
||||||
int batch_size,
|
int batch_size,
|
||||||
int id_to_assign);
|
int account_id);
|
||||||
|
|
||||||
// Greader account.
|
// Greader account.
|
||||||
static bool deleteGreaderAccount(const QSqlDatabase& db, int account_id);
|
static bool deleteGreaderAccount(const QSqlDatabase& db, int account_id);
|
||||||
|
@ -9,7 +9,7 @@
|
|||||||
#define FEEDLY_API_REDIRECT_URI_PORT 8080
|
#define FEEDLY_API_REDIRECT_URI_PORT 8080
|
||||||
#define FEEDLY_API_SCOPE "https://cloud.feedly.com/subscriptions"
|
#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/"
|
#define FEEDLY_API_URL_BASE "https://sandbox7.feedly.com/v3/"
|
||||||
#else
|
#else
|
||||||
#define FEEDLY_API_URL_BASE "https://cloud.feedly.com/v3/"
|
#define FEEDLY_API_URL_BASE "https://cloud.feedly.com/v3/"
|
||||||
|
@ -3,10 +3,10 @@
|
|||||||
#include "services/feedly/feedlynetwork.h"
|
#include "services/feedly/feedlynetwork.h"
|
||||||
|
|
||||||
#include "3rd-party/boolinq/boolinq.h"
|
#include "3rd-party/boolinq/boolinq.h"
|
||||||
|
#include "exceptions/networkexception.h"
|
||||||
#include "miscellaneous/application.h"
|
#include "miscellaneous/application.h"
|
||||||
#include "network-web/networkfactory.h"
|
|
||||||
|
|
||||||
#include "miscellaneous/databasequeries.h"
|
#include "miscellaneous/databasequeries.h"
|
||||||
|
#include "network-web/networkfactory.h"
|
||||||
#include "network-web/webfactory.h"
|
#include "network-web/webfactory.h"
|
||||||
#include "services/abstract/category.h"
|
#include "services/abstract/category.h"
|
||||||
#include "services/abstract/label.h"
|
#include "services/abstract/label.h"
|
||||||
@ -44,34 +44,45 @@ FeedlyNetwork::FeedlyNetwork(QObject* parent)
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
QString FeedlyNetwork::profile(const QNetworkProxy& network_proxy) {
|
RootItem* FeedlyNetwork::personalCollections(bool obtain_icons, const QNetworkProxy& proxy) {
|
||||||
QString bear = bearer();
|
QString bear = bearer();
|
||||||
|
|
||||||
if (bear.isEmpty()) {
|
if (bear.isEmpty()) {
|
||||||
qCriticalNN << LOGSEC_FEEDLY
|
qCriticalNN << LOGSEC_FEEDLY << "Cannot obtain personal collections, because bearer is empty.";
|
||||||
<< "Cannot obtain profile information, because bearer is empty.";
|
throw NetworkException(QNetworkReply::NetworkError::AuthenticationRequiredError);
|
||||||
return {};
|
|
||||||
}
|
}
|
||||||
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,
|
QVariantHash FeedlyNetwork::profile(const QNetworkProxy& network_proxy) {
|
||||||
// not via "m_service" field.
|
QString bear = bearer();
|
||||||
auto result = NetworkFactory::performNetworkOperation(target_url,
|
|
||||||
timeout,
|
|
||||||
{},
|
|
||||||
output_msgs,
|
|
||||||
QNetworkAccessManager::Operation::GetOperation,
|
|
||||||
{ bearerHeader(bear) },
|
|
||||||
false,
|
|
||||||
{},
|
|
||||||
{},
|
|
||||||
network_proxy);
|
|
||||||
|
|
||||||
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 {
|
QString FeedlyNetwork::username() const {
|
||||||
|
@ -21,7 +21,7 @@ class FeedlyNetwork : public QObject {
|
|||||||
explicit FeedlyNetwork(QObject* parent = nullptr);
|
explicit FeedlyNetwork(QObject* parent = nullptr);
|
||||||
|
|
||||||
// API operations.
|
// API operations.
|
||||||
QString profile(const QNetworkProxy& network_proxy);
|
QVariantHash profile(const QNetworkProxy& network_proxy);
|
||||||
|
|
||||||
// Getters and setters.
|
// Getters and setters.
|
||||||
QString username() const;
|
QString username() const;
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
#include "services/feedly/gui/feedlyaccountdetails.h"
|
#include "services/feedly/gui/feedlyaccountdetails.h"
|
||||||
|
|
||||||
#include "definitions/definitions.h"
|
#include "definitions/definitions.h"
|
||||||
|
#include "exceptions/networkexception.h"
|
||||||
#include "gui/guiutilities.h"
|
#include "gui/guiutilities.h"
|
||||||
#include "miscellaneous/application.h"
|
#include "miscellaneous/application.h"
|
||||||
#include "miscellaneous/systemfactory.h"
|
#include "miscellaneous/systemfactory.h"
|
||||||
@ -14,6 +15,8 @@
|
|||||||
#include "network-web/oauth2service.h"
|
#include "network-web/oauth2service.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include <QVariantHash>
|
||||||
|
|
||||||
FeedlyAccountDetails::FeedlyAccountDetails(QWidget* parent) : QWidget(parent) {
|
FeedlyAccountDetails::FeedlyAccountDetails(QWidget* parent) : QWidget(parent) {
|
||||||
#if defined (FEEDLY_OFFICIAL_SUPPORT)
|
#if defined (FEEDLY_OFFICIAL_SUPPORT)
|
||||||
m_oauth = new OAuth2Service(QSL(FEEDLY_API_URL_BASE) + FEEDLY_API_URL_AUTH,
|
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.setUsername(m_ui.m_txtUsername->lineEdit()->text());
|
||||||
factory.setDeveloperAccessToken(m_ui.m_txtDeveloperAccessToken->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,
|
m_ui.m_lblTestResult->setStatus(WidgetWithStatus::StatusType::Ok,
|
||||||
tr("Login was successful."),
|
tr("Login was successful."),
|
||||||
tr("Access granted."));
|
tr("Access granted."));
|
||||||
}
|
}
|
||||||
else {
|
catch (const NetworkException& ex) {
|
||||||
m_ui.m_lblTestResult->setStatus(WidgetWithStatus::StatusType::Error,
|
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."));
|
tr("Some problems."));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user