Added support for acc proxy to standard acc.
This commit is contained in:
parent
15eadf188e
commit
8e95f8a5ec
13 changed files with 87 additions and 23 deletions
|
@ -21,9 +21,9 @@ void BaseNetworkAccessManager::loadSettings() {
|
||||||
SETTING(Proxy::Type)).
|
SETTING(Proxy::Type)).
|
||||||
toInt());
|
toInt());
|
||||||
|
|
||||||
if (selected_proxy_type == QNetworkProxy::NoProxy) {
|
if (selected_proxy_type == QNetworkProxy::ProxyType::NoProxy) {
|
||||||
// No extra setting is needed, set new proxy and exit this method.
|
// No extra setting is needed, set new proxy and exit this method.
|
||||||
setProxy(QNetworkProxy::NoProxy);
|
setProxy(QNetworkProxy::ProxyType::NoProxy);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
setProxy(QNetworkProxy::applicationProxy());
|
setProxy(QNetworkProxy::applicationProxy());
|
||||||
|
|
|
@ -10,8 +10,6 @@ class BaseNetworkAccessManager : public QNetworkAccessManager {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
// Constructors and desctructors.
|
|
||||||
explicit BaseNetworkAccessManager(QObject* parent = nullptr);
|
explicit BaseNetworkAccessManager(QObject* parent = nullptr);
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
|
|
|
@ -282,6 +282,12 @@ QVariant Downloader::lastContentType() const {
|
||||||
return m_lastContentType;
|
return m_lastContentType;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Downloader::setProxy(const QNetworkProxy& proxy) {
|
||||||
|
qWarningNN << LOGSEC_NETWORK << "Setting custom proxy:" << QUOTE_W_SPACE_DOT(proxy.hostName());
|
||||||
|
|
||||||
|
m_downloadManager->setProxy(proxy);
|
||||||
|
}
|
||||||
|
|
||||||
void Downloader::cancel() {
|
void Downloader::cancel() {
|
||||||
if (m_activeReply != nullptr) {
|
if (m_activeReply != nullptr) {
|
||||||
// Download action timed-out, too slow connection or target is not reachable.
|
// Download action timed-out, too slow connection or target is not reachable.
|
||||||
|
|
|
@ -9,6 +9,7 @@
|
||||||
#include "network-web/httpresponse.h"
|
#include "network-web/httpresponse.h"
|
||||||
|
|
||||||
#include <QHttpMultiPart>
|
#include <QHttpMultiPart>
|
||||||
|
#include <QNetworkProxy>
|
||||||
#include <QNetworkReply>
|
#include <QNetworkReply>
|
||||||
#include <QSslError>
|
#include <QSslError>
|
||||||
|
|
||||||
|
@ -28,6 +29,8 @@ class Downloader : public QObject {
|
||||||
QList<HttpResponse> lastOutputMultipartData() const;
|
QList<HttpResponse> lastOutputMultipartData() const;
|
||||||
QVariant lastContentType() const;
|
QVariant lastContentType() const;
|
||||||
|
|
||||||
|
void setProxy(const QNetworkProxy& proxy);
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void cancel();
|
void cancel();
|
||||||
|
|
||||||
|
|
|
@ -208,7 +208,8 @@ NetworkResult NetworkFactory::performNetworkOperation(const QString& url, int ti
|
||||||
QByteArray& output, QNetworkAccessManager::Operation operation,
|
QByteArray& output, QNetworkAccessManager::Operation operation,
|
||||||
QList<QPair<QByteArray, QByteArray>> additional_headers,
|
QList<QPair<QByteArray, QByteArray>> additional_headers,
|
||||||
bool protected_contents,
|
bool protected_contents,
|
||||||
const QString& username, const QString& password) {
|
const QString& username, const QString& password,
|
||||||
|
const QNetworkProxy& custom_proxy) {
|
||||||
Downloader downloader;
|
Downloader downloader;
|
||||||
QEventLoop loop;
|
QEventLoop loop;
|
||||||
NetworkResult result;
|
NetworkResult result;
|
||||||
|
@ -222,6 +223,10 @@ NetworkResult NetworkFactory::performNetworkOperation(const QString& url, int ti
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (custom_proxy.type() != QNetworkProxy::ProxyType::DefaultProxy) {
|
||||||
|
downloader.setProxy(custom_proxy);
|
||||||
|
}
|
||||||
|
|
||||||
downloader.manipulateData(url, operation, input_data, timeout, protected_contents, username, password);
|
downloader.manipulateData(url, operation, input_data, timeout, protected_contents, username, password);
|
||||||
loop.exec();
|
loop.exec();
|
||||||
|
|
||||||
|
@ -239,7 +244,8 @@ NetworkResult NetworkFactory::performNetworkOperation(const QString& url,
|
||||||
QList<QPair<QByteArray, QByteArray>> additional_headers,
|
QList<QPair<QByteArray, QByteArray>> additional_headers,
|
||||||
bool protected_contents,
|
bool protected_contents,
|
||||||
const QString& username,
|
const QString& username,
|
||||||
const QString& password) {
|
const QString& password,
|
||||||
|
const QNetworkProxy& custom_proxy) {
|
||||||
Downloader downloader;
|
Downloader downloader;
|
||||||
QEventLoop loop;
|
QEventLoop loop;
|
||||||
NetworkResult result;
|
NetworkResult result;
|
||||||
|
@ -253,6 +259,10 @@ NetworkResult NetworkFactory::performNetworkOperation(const QString& url,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (custom_proxy.type() != QNetworkProxy::ProxyType::DefaultProxy) {
|
||||||
|
downloader.setProxy(custom_proxy);
|
||||||
|
}
|
||||||
|
|
||||||
downloader.manipulateData(url, operation, input_data, timeout, protected_contents, username, password);
|
downloader.manipulateData(url, operation, input_data, timeout, protected_contents, username, password);
|
||||||
loop.exec();
|
loop.exec();
|
||||||
|
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
|
|
||||||
#include <QCoreApplication>
|
#include <QCoreApplication>
|
||||||
#include <QHttpPart>
|
#include <QHttpPart>
|
||||||
|
#include <QNetworkProxy>
|
||||||
#include <QNetworkReply>
|
#include <QNetworkReply>
|
||||||
#include <QPair>
|
#include <QPair>
|
||||||
#include <QVariant>
|
#include <QVariant>
|
||||||
|
@ -50,7 +51,8 @@ class NetworkFactory {
|
||||||
QByteArray>> additional_headers = QList<QPair<QByteArray, QByteArray>>(),
|
QByteArray>> additional_headers = QList<QPair<QByteArray, QByteArray>>(),
|
||||||
bool protected_contents = false,
|
bool protected_contents = false,
|
||||||
const QString& username = QString(),
|
const QString& username = QString(),
|
||||||
const QString& password = QString());
|
const QString& password = QString(),
|
||||||
|
const QNetworkProxy& custom_proxy = QNetworkProxy::ProxyType::DefaultProxy);
|
||||||
static NetworkResult performNetworkOperation(const QString& url, int timeout,
|
static NetworkResult performNetworkOperation(const QString& url, int timeout,
|
||||||
QHttpMultiPart* input_data,
|
QHttpMultiPart* input_data,
|
||||||
QList<HttpResponse>& output,
|
QList<HttpResponse>& output,
|
||||||
|
@ -59,7 +61,8 @@ class NetworkFactory {
|
||||||
QByteArray>> additional_headers = QList<QPair<QByteArray, QByteArray>>(),
|
QByteArray>> additional_headers = QList<QPair<QByteArray, QByteArray>>(),
|
||||||
bool protected_contents = false,
|
bool protected_contents = false,
|
||||||
const QString& username = QString(),
|
const QString& username = QString(),
|
||||||
const QString& password = QString());
|
const QString& password = QString(),
|
||||||
|
const QNetworkProxy& custom_proxy = QNetworkProxy::ProxyType::DefaultProxy);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // NETWORKFACTORY_H
|
#endif // NETWORKFACTORY_H
|
||||||
|
|
|
@ -14,7 +14,7 @@
|
||||||
<string>Form</string>
|
<string>Form</string>
|
||||||
</property>
|
</property>
|
||||||
<layout class="QFormLayout" name="formLayout">
|
<layout class="QFormLayout" name="formLayout">
|
||||||
<item row="0" column="0">
|
<item row="0" column="0" colspan="2">
|
||||||
<widget class="QGroupBox" name="m_gbAuthentication">
|
<widget class="QGroupBox" name="m_gbAuthentication">
|
||||||
<property name="toolTip">
|
<property name="toolTip">
|
||||||
<string>Some feeds require authentication, including GMail feeds. BASIC, NTLM-2 and DIGEST-MD5 authentication schemes are supported.</string>
|
<string>Some feeds require authentication, including GMail feeds. BASIC, NTLM-2 and DIGEST-MD5 authentication schemes are supported.</string>
|
||||||
|
|
|
@ -16,6 +16,8 @@ FormAccountDetails::FormAccountDetails(const QIcon& icon, QWidget* parent)
|
||||||
? qApp->icons()->fromTheme(QSL("emblem-system"))
|
? qApp->icons()->fromTheme(QSL("emblem-system"))
|
||||||
: icon);
|
: icon);
|
||||||
createConnections();
|
createConnections();
|
||||||
|
|
||||||
|
m_proxyDetails->setProxy(QNetworkProxy());
|
||||||
}
|
}
|
||||||
|
|
||||||
void FormAccountDetails::insertCustomTab(QWidget* custom_tab, const QString& title, int index) {
|
void FormAccountDetails::insertCustomTab(QWidget* custom_tab, const QString& title, int index) {
|
||||||
|
|
|
@ -78,8 +78,12 @@ StandardFeedDetails::StandardFeedDetails(QWidget* parent) : QWidget(parent) {
|
||||||
onUrlChanged(QString());
|
onUrlChanged(QString());
|
||||||
}
|
}
|
||||||
|
|
||||||
void StandardFeedDetails::guessIconOnly(const QString& url, const QString& username, const QString& password) {
|
void StandardFeedDetails::guessIconOnly(const QString& url, const QString& username,
|
||||||
QPair<StandardFeed*, QNetworkReply::NetworkError> result = StandardFeed::guessFeed(url, username, password);
|
const QString& password, const QNetworkProxy& custom_proxy) {
|
||||||
|
QPair<StandardFeed*, QNetworkReply::NetworkError> result = StandardFeed::guessFeed(url,
|
||||||
|
username,
|
||||||
|
password,
|
||||||
|
custom_proxy);
|
||||||
|
|
||||||
if (result.first != nullptr) {
|
if (result.first != nullptr) {
|
||||||
// Icon or whole feed was guessed.
|
// Icon or whole feed was guessed.
|
||||||
|
@ -107,8 +111,12 @@ void StandardFeedDetails::guessIconOnly(const QString& url, const QString& usern
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void StandardFeedDetails::guessFeed(const QString& url, const QString& username, const QString& password) {
|
void StandardFeedDetails::guessFeed(const QString& url, const QString& username,
|
||||||
QPair<StandardFeed*, QNetworkReply::NetworkError> result = StandardFeed::guessFeed(url, username, password);
|
const QString& password, const QNetworkProxy& custom_proxy) {
|
||||||
|
QPair<StandardFeed*, QNetworkReply::NetworkError> result = StandardFeed::guessFeed(url,
|
||||||
|
username,
|
||||||
|
password,
|
||||||
|
custom_proxy);
|
||||||
|
|
||||||
if (result.first != nullptr) {
|
if (result.first != nullptr) {
|
||||||
// Icon or whole feed was guessed.
|
// Icon or whole feed was guessed.
|
||||||
|
|
|
@ -7,6 +7,8 @@
|
||||||
|
|
||||||
#include "ui_standardfeeddetails.h"
|
#include "ui_standardfeeddetails.h"
|
||||||
|
|
||||||
|
#include <QNetworkProxy>
|
||||||
|
|
||||||
class Category;
|
class Category;
|
||||||
class RootItem;
|
class RootItem;
|
||||||
class StandardFeed;
|
class StandardFeed;
|
||||||
|
@ -20,8 +22,14 @@ class StandardFeedDetails : public QWidget {
|
||||||
explicit StandardFeedDetails(QWidget* parent = nullptr);
|
explicit StandardFeedDetails(QWidget* parent = nullptr);
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void guessIconOnly(const QString& url, const QString& username, const QString& password);
|
void guessIconOnly(const QString& url,
|
||||||
void guessFeed(const QString& url, const QString& username, const QString& password);
|
const QString& username,
|
||||||
|
const QString& password,
|
||||||
|
const QNetworkProxy& custom_proxy = QNetworkProxy::ProxyType::DefaultProxy);
|
||||||
|
void guessFeed(const QString& url,
|
||||||
|
const QString& username,
|
||||||
|
const QString& password,
|
||||||
|
const QNetworkProxy& custom_proxy = QNetworkProxy::ProxyType::DefaultProxy);
|
||||||
|
|
||||||
void onTitleChanged(const QString& new_title);
|
void onTitleChanged(const QString& new_title);
|
||||||
void onDescriptionChanged(const QString& new_description);
|
void onDescriptionChanged(const QString& new_description);
|
||||||
|
|
|
@ -111,7 +111,10 @@ QString StandardFeed::typeToString(StandardFeed::Type type) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void StandardFeed::fetchMetadataForItself() {
|
void StandardFeed::fetchMetadataForItself() {
|
||||||
QPair<StandardFeed*, QNetworkReply::NetworkError> metadata = guessFeed(url(), username(), password());
|
QPair<StandardFeed*, QNetworkReply::NetworkError> metadata = guessFeed(url(),
|
||||||
|
username(),
|
||||||
|
password(),
|
||||||
|
getParentServiceRoot()->networkProxy());
|
||||||
|
|
||||||
if (metadata.first != nullptr && metadata.second == QNetworkReply::NetworkError::NoError) {
|
if (metadata.first != nullptr && metadata.second == QNetworkReply::NetworkError::NoError) {
|
||||||
// Some properties are not updated when new metadata are fetched.
|
// Some properties are not updated when new metadata are fetched.
|
||||||
|
@ -138,7 +141,8 @@ void StandardFeed::fetchMetadataForItself() {
|
||||||
|
|
||||||
QPair<StandardFeed*, QNetworkReply::NetworkError> StandardFeed::guessFeed(const QString& url,
|
QPair<StandardFeed*, QNetworkReply::NetworkError> StandardFeed::guessFeed(const QString& url,
|
||||||
const QString& username,
|
const QString& username,
|
||||||
const QString& password) {
|
const QString& password,
|
||||||
|
const QNetworkProxy& custom_proxy) {
|
||||||
QPair<StandardFeed*, QNetworkReply::NetworkError> result;
|
QPair<StandardFeed*, QNetworkReply::NetworkError> result;
|
||||||
|
|
||||||
result.first = nullptr;
|
result.first = nullptr;
|
||||||
|
@ -146,14 +150,17 @@ QPair<StandardFeed*, QNetworkReply::NetworkError> StandardFeed::guessFeed(const
|
||||||
QList<QPair<QByteArray, QByteArray>> headers;
|
QList<QPair<QByteArray, QByteArray>> headers;
|
||||||
|
|
||||||
headers << NetworkFactory::generateBasicAuthHeader(username, password);
|
headers << NetworkFactory::generateBasicAuthHeader(username, password);
|
||||||
|
|
||||||
NetworkResult network_result = NetworkFactory::performNetworkOperation(url,
|
NetworkResult network_result = NetworkFactory::performNetworkOperation(url,
|
||||||
qApp->settings()->value(GROUP(Feeds),
|
qApp->settings()->value(GROUP(Feeds),
|
||||||
SETTING(Feeds::UpdateTimeout)).toInt(),
|
SETTING(Feeds::UpdateTimeout)).toInt(),
|
||||||
QByteArray(),
|
QByteArray(),
|
||||||
feed_contents,
|
feed_contents,
|
||||||
QNetworkAccessManager::GetOperation,
|
QNetworkAccessManager::GetOperation,
|
||||||
headers);
|
headers,
|
||||||
|
false,
|
||||||
|
{},
|
||||||
|
{},
|
||||||
|
custom_proxy);
|
||||||
|
|
||||||
result.second = network_result.first;
|
result.second = network_result.first;
|
||||||
|
|
||||||
|
@ -430,7 +437,11 @@ QList<Message> StandardFeed::obtainNewMessages(bool* error_during_obtaining) {
|
||||||
QByteArray(),
|
QByteArray(),
|
||||||
feed_contents,
|
feed_contents,
|
||||||
QNetworkAccessManager::GetOperation,
|
QNetworkAccessManager::GetOperation,
|
||||||
headers).first;
|
headers,
|
||||||
|
false,
|
||||||
|
{},
|
||||||
|
{},
|
||||||
|
getParentServiceRoot()->networkProxy()).first;
|
||||||
|
|
||||||
if (m_networkError != QNetworkReply::NoError) {
|
if (m_networkError != QNetworkReply::NoError) {
|
||||||
qWarningNN << LOGSEC_CORE
|
qWarningNN << LOGSEC_CORE
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
#include <QCoreApplication>
|
#include <QCoreApplication>
|
||||||
#include <QDateTime>
|
#include <QDateTime>
|
||||||
#include <QMetaType>
|
#include <QMetaType>
|
||||||
|
#include <QNetworkProxy>
|
||||||
#include <QNetworkReply>
|
#include <QNetworkReply>
|
||||||
#include <QPair>
|
#include <QPair>
|
||||||
#include <QSqlRecord>
|
#include <QSqlRecord>
|
||||||
|
@ -72,7 +73,8 @@ class StandardFeed : public Feed {
|
||||||
// or NULL feed.
|
// or NULL feed.
|
||||||
static QPair<StandardFeed*, QNetworkReply::NetworkError> guessFeed(const QString& url,
|
static QPair<StandardFeed*, QNetworkReply::NetworkError> guessFeed(const QString& url,
|
||||||
const QString& username = QString(),
|
const QString& username = QString(),
|
||||||
const QString& password = QString());
|
const QString& password = QString(),
|
||||||
|
const QNetworkProxy& custom_proxy = QNetworkProxy::ProxyType::DefaultProxy);
|
||||||
|
|
||||||
// Converts particular feed type to string.
|
// Converts particular feed type to string.
|
||||||
static QString typeToString(Type type);
|
static QString typeToString(Type type);
|
||||||
|
|
|
@ -152,6 +152,12 @@ void FeedsImportExportModel::importAsOPML20(const QByteArray& data, bool fetch_m
|
||||||
int completed = 0, total = 0, succeded = 0, failed = 0;
|
int completed = 0, total = 0, succeded = 0, failed = 0;
|
||||||
auto* root_item = new StandardServiceRoot();
|
auto* root_item = new StandardServiceRoot();
|
||||||
QStack<RootItem*> model_items;
|
QStack<RootItem*> model_items;
|
||||||
|
QNetworkProxy custom_proxy;
|
||||||
|
|
||||||
|
if (sourceModel()->rootItem() != nullptr &&
|
||||||
|
sourceModel()->rootItem()->getParentServiceRoot() != nullptr) {
|
||||||
|
custom_proxy = sourceModel()->rootItem()->getParentServiceRoot()->networkProxy();
|
||||||
|
}
|
||||||
|
|
||||||
model_items.push(root_item);
|
model_items.push(root_item);
|
||||||
QStack<QDomElement> elements_to_process;
|
QStack<QDomElement> elements_to_process;
|
||||||
|
@ -182,7 +188,7 @@ void FeedsImportExportModel::importAsOPML20(const QByteArray& data, bool fetch_m
|
||||||
QPair<StandardFeed*, QNetworkReply::NetworkError> guessed;
|
QPair<StandardFeed*, QNetworkReply::NetworkError> guessed;
|
||||||
|
|
||||||
if (fetch_metadata_online &&
|
if (fetch_metadata_online &&
|
||||||
(guessed = StandardFeed::guessFeed(feed_url)).second == QNetworkReply::NoError) {
|
(guessed = StandardFeed::guessFeed(feed_url, {}, {}, custom_proxy)).second == QNetworkReply::NoError) {
|
||||||
// We should obtain fresh metadata from online feed source.
|
// We should obtain fresh metadata from online feed source.
|
||||||
guessed.first->setUrl(feed_url);
|
guessed.first->setUrl(feed_url);
|
||||||
active_model_item->appendChild(guessed.first);
|
active_model_item->appendChild(guessed.first);
|
||||||
|
@ -287,6 +293,13 @@ void FeedsImportExportModel::importAsTxtURLPerLine(const QByteArray& data, bool
|
||||||
emit layoutChanged();
|
emit layoutChanged();
|
||||||
int completed = 0, succeded = 0, failed = 0;
|
int completed = 0, succeded = 0, failed = 0;
|
||||||
auto* root_item = new StandardServiceRoot();
|
auto* root_item = new StandardServiceRoot();
|
||||||
|
QNetworkProxy custom_proxy;
|
||||||
|
|
||||||
|
if (sourceModel()->rootItem() != nullptr &&
|
||||||
|
sourceModel()->rootItem()->getParentServiceRoot() != nullptr) {
|
||||||
|
custom_proxy = sourceModel()->rootItem()->getParentServiceRoot()->networkProxy();
|
||||||
|
}
|
||||||
|
|
||||||
QList<QByteArray> urls = data.split('\n');
|
QList<QByteArray> urls = data.split('\n');
|
||||||
|
|
||||||
for (const QByteArray& url : urls) {
|
for (const QByteArray& url : urls) {
|
||||||
|
@ -294,7 +307,7 @@ void FeedsImportExportModel::importAsTxtURLPerLine(const QByteArray& data, bool
|
||||||
QPair<StandardFeed*, QNetworkReply::NetworkError> guessed;
|
QPair<StandardFeed*, QNetworkReply::NetworkError> guessed;
|
||||||
|
|
||||||
if (fetch_metadata_online &&
|
if (fetch_metadata_online &&
|
||||||
(guessed = StandardFeed::guessFeed(url)).second == QNetworkReply::NoError) {
|
(guessed = StandardFeed::guessFeed(url, {}, {}, custom_proxy)).second == QNetworkReply::NoError) {
|
||||||
guessed.first->setUrl(url);
|
guessed.first->setUrl(url);
|
||||||
root_item->appendChild(guessed.first);
|
root_item->appendChild(guessed.first);
|
||||||
succeded++;
|
succeded++;
|
||||||
|
|
Loading…
Add table
Reference in a new issue