nextcloud proxy support, provide fallback icon in msg list if no feed icon is available

This commit is contained in:
Martin Rotter 2021-01-26 08:21:11 +01:00
parent 4082ce7469
commit 5131881c3f
12 changed files with 135 additions and 67 deletions

View File

@ -30,7 +30,7 @@
<url type="donation">https://martinrotter.github.io/donate/</url>
<content_rating type="oars-1.1" />
<releases>
<release version="3.8.4" date="2021-01-25"/>
<release version="3.8.4" date="2021-01-26"/>
</releases>
<content_rating type="oars-1.0">
<content_attribute id="violence-cartoon">none</content_attribute>

View File

@ -339,7 +339,12 @@ QVariant MessagesModel::data(const QModelIndex& idx, int role) const {
QString feed_custom_id = dta.toString();
auto acc = m_selectedItem->getParentServiceRoot()->feedIconForMessage(feed_custom_id);
return acc;
if (acc.isNull()) {
return qApp->icons()->fromTheme(QSL("application-rss+xml"));
}
else {
return acc;
}
}
else {
QModelIndex idx_read = index(idx.row(), MSG_DB_READ_INDEX);

View File

@ -14,8 +14,6 @@
#include <QTextDocument>
#include <QTimer>
NetworkFactory::NetworkFactory() = default;
QStringList NetworkFactory::extractFeedLinksFromHtmlPage(const QUrl& url, const QString& html) {
QStringList feeds;
QRegularExpression rx(FEED_REGEX_MATCHER, QRegularExpression::PatternOption::CaseInsensitiveOption);

View File

@ -20,9 +20,7 @@ class NetworkFactory {
Q_DECLARE_TR_FUNCTIONS(NetworkFactory)
private:
// Constructor.
explicit NetworkFactory();
explicit NetworkFactory() = default;
public:
static QStringList extractFeedLinksFromHtmlPage(const QUrl& url, const QString& html);

View File

@ -15,6 +15,8 @@ FormEditOwnCloudAccount::FormEditOwnCloudAccount(QWidget* parent)
insertCustomTab(m_details, tr("Server setup"), 0);
activateTab(0);
connect(m_details->m_ui.m_btnTestSetup, &QPushButton::clicked, this, &FormEditOwnCloudAccount::performTest);
m_details->m_ui.m_txtUrl->setFocus();
}
@ -49,3 +51,7 @@ void FormEditOwnCloudAccount::setEditableAccount(ServiceRoot* editable_account)
m_details->m_ui.m_checkServerSideUpdate->setChecked(existing_root->network()->forceServerSideUpdate());
m_details->m_ui.m_spinLimitMessages->setValue(existing_root->network()->batchSize());
}
void FormEditOwnCloudAccount::performTest() {
m_details->performTest(m_proxyDetails->proxy());
}

View File

@ -20,6 +20,9 @@ class FormEditOwnCloudAccount : public FormAccountDetails {
protected:
virtual void setEditableAccount(ServiceRoot* editable_account);
private slots:
void performTest();
private:
OwnCloudAccountDetails* m_details;
};

View File

@ -40,7 +40,6 @@ OwnCloudAccountDetails::OwnCloudAccountDetails(QWidget* parent) : QWidget(parent
connect(m_ui.m_txtPassword->lineEdit(), &BaseLineEdit::textChanged, this, &OwnCloudAccountDetails::onPasswordChanged);
connect(m_ui.m_txtUsername->lineEdit(), &BaseLineEdit::textChanged, this, &OwnCloudAccountDetails::onUsernameChanged);
connect(m_ui.m_txtUrl->lineEdit(), &BaseLineEdit::textChanged, this, &OwnCloudAccountDetails::onUrlChanged);
connect(m_ui.m_btnTestSetup, &QPushButton::clicked, this, &OwnCloudAccountDetails::performTest);
setTabOrder(m_ui.m_txtUrl->lineEdit(), m_ui.m_checkDownloadOnlyUnreadMessages);
setTabOrder(m_ui.m_checkDownloadOnlyUnreadMessages, m_ui.m_checkServerSideUpdate);
@ -60,7 +59,7 @@ void OwnCloudAccountDetails::displayPassword(bool display) {
m_ui.m_txtPassword->lineEdit()->setEchoMode(display ? QLineEdit::Normal : QLineEdit::Password);
}
void OwnCloudAccountDetails::performTest() {
void OwnCloudAccountDetails::performTest(const QNetworkProxy& custom_proxy) {
OwnCloudNetworkFactory factory;
factory.setAuthUsername(m_ui.m_txtUsername->lineEdit()->text());
@ -68,7 +67,7 @@ void OwnCloudAccountDetails::performTest() {
factory.setUrl(m_ui.m_txtUrl->lineEdit()->text());
factory.setForceServerSideUpdate(m_ui.m_checkServerSideUpdate->isChecked());
OwnCloudStatusResponse result = factory.status();
OwnCloudStatusResponse result = factory.status(custom_proxy);
if (result.networkError() != QNetworkReply::NetworkError::NoError) {
m_ui.m_lblTestResult->setStatus(WidgetWithStatus::StatusType::Error,

View File

@ -7,6 +7,8 @@
#include "ui_owncloudaccountdetails.h"
#include <QNetworkProxy>
class OwnCloudAccountDetails : public QWidget {
Q_OBJECT
@ -17,7 +19,7 @@ class OwnCloudAccountDetails : public QWidget {
private slots:
void displayPassword(bool display);
void performTest();
void performTest(const QNetworkProxy& custom_proxy);
void onUsernameChanged();
void onPasswordChanged();
void onUrlChanged();

View File

@ -19,10 +19,9 @@
OwnCloudNetworkFactory::OwnCloudNetworkFactory()
: m_url(QString()), m_fixedUrl(QString()), m_downloadOnlyUnreadMessages(false), m_forceServerSideUpdate(false),
m_authUsername(QString()), m_authPassword(QString()), m_batchSize(OWNCLOUD_UNLIMITED_BATCH_SIZE), m_urlUser(QString()), m_urlStatus(
QString()),
m_urlFolders(QString()), m_urlFeeds(QString()), m_urlMessages(QString()), m_urlFeedsUpdate(QString()),
m_urlDeleteFeed(QString()), m_urlRenameFeed(QString()) {}
m_authUsername(QString()), m_authPassword(QString()), m_batchSize(OWNCLOUD_UNLIMITED_BATCH_SIZE), m_urlUser(QString()),
m_urlStatus(QString()), m_urlFolders(QString()), m_urlFeeds(QString()), m_urlMessages(QString()),
m_urlFeedsUpdate(QString()), m_urlDeleteFeed(QString()), m_urlRenameFeed(QString()) {}
OwnCloudNetworkFactory::~OwnCloudNetworkFactory() = default;
@ -75,7 +74,7 @@ void OwnCloudNetworkFactory::setAuthPassword(const QString& auth_password) {
m_authPassword = auth_password;
}
OwnCloudStatusResponse OwnCloudNetworkFactory::status() {
OwnCloudStatusResponse OwnCloudNetworkFactory::status(const QNetworkProxy& custom_proxy) {
QByteArray result_raw;
QList<QPair<QByteArray, QByteArray>> headers;
@ -85,9 +84,14 @@ OwnCloudStatusResponse OwnCloudNetworkFactory::status() {
NetworkResult network_reply = NetworkFactory::performNetworkOperation(m_urlStatus,
qApp->settings()->value(GROUP(Feeds),
SETTING(Feeds::UpdateTimeout)).toInt(),
QByteArray(), result_raw,
QByteArray(),
result_raw,
QNetworkAccessManager::Operation::GetOperation,
headers);
headers,
false,
{},
{},
custom_proxy);
OwnCloudStatusResponse status_response(network_reply.first, QString::fromUtf8(result_raw));
qDebugNN << LOGSEC_NEXTCLOUD
@ -102,7 +106,7 @@ OwnCloudStatusResponse OwnCloudNetworkFactory::status() {
return status_response;
}
OwnCloudGetFeedsCategoriesResponse OwnCloudNetworkFactory::feedsCategories() {
OwnCloudGetFeedsCategoriesResponse OwnCloudNetworkFactory::feedsCategories(const QNetworkProxy& custom_proxy) {
QByteArray result_raw;
QList<QPair<QByteArray, QByteArray>> headers;
@ -112,9 +116,14 @@ OwnCloudGetFeedsCategoriesResponse OwnCloudNetworkFactory::feedsCategories() {
NetworkResult network_reply = NetworkFactory::performNetworkOperation(m_urlFolders,
qApp->settings()->value(GROUP(Feeds),
SETTING(Feeds::UpdateTimeout)).toInt(),
QByteArray(), result_raw,
QByteArray(),
result_raw,
QNetworkAccessManager::Operation::GetOperation,
headers);
headers,
false,
{},
{},
custom_proxy);
if (network_reply.first != QNetworkReply::NoError) {
qCriticalNN << LOGSEC_NEXTCLOUD
@ -129,9 +138,14 @@ OwnCloudGetFeedsCategoriesResponse OwnCloudNetworkFactory::feedsCategories() {
network_reply = NetworkFactory::performNetworkOperation(m_urlFeeds,
qApp->settings()->value(GROUP(Feeds),
SETTING(Feeds::UpdateTimeout)).toInt(),
QByteArray(), result_raw,
QByteArray(),
result_raw,
QNetworkAccessManager::Operation::GetOperation,
headers);
headers,
false,
{},
{},
custom_proxy);
if (network_reply.first != QNetworkReply::NoError) {
qCriticalNN << LOGSEC_NEXTCLOUD
@ -145,7 +159,7 @@ OwnCloudGetFeedsCategoriesResponse OwnCloudNetworkFactory::feedsCategories() {
return OwnCloudGetFeedsCategoriesResponse(network_reply.first, content_categories, content_feeds);
}
bool OwnCloudNetworkFactory::deleteFeed(const QString& feed_id) {
bool OwnCloudNetworkFactory::deleteFeed(const QString& feed_id, const QNetworkProxy& custom_proxy) {
QString final_url = m_urlDeleteFeed.arg(feed_id);
QByteArray raw_output;
QList<QPair<QByteArray, QByteArray>> headers;
@ -159,7 +173,11 @@ bool OwnCloudNetworkFactory::deleteFeed(const QString& feed_id) {
QByteArray(),
raw_output,
QNetworkAccessManager::Operation::DeleteOperation,
headers);
headers,
false,
{},
{},
custom_proxy);
if (network_reply.first != QNetworkReply::NoError) {
qCriticalNN << LOGSEC_NEXTCLOUD
@ -172,12 +190,12 @@ bool OwnCloudNetworkFactory::deleteFeed(const QString& feed_id) {
}
}
bool OwnCloudNetworkFactory::createFeed(const QString& url, int parent_id) {
bool OwnCloudNetworkFactory::createFeed(const QString& url, int parent_id, const QNetworkProxy& custom_proxy) {
QJsonObject json;
json["url"] = url;
auto nextcloud_version = status().version();
auto nextcloud_version = status(custom_proxy).version();
if (SystemFactory::isVersionEqualOrNewer(nextcloud_version, QSL("15.1.0"))) {
json["folderId"] = parent_id == 0 ? QJsonValue(QJsonValue::Type::Null) : parent_id;
@ -198,7 +216,11 @@ bool OwnCloudNetworkFactory::createFeed(const QString& url, int parent_id) {
QJsonDocument(json).toJson(QJsonDocument::JsonFormat::Compact),
result_raw,
QNetworkAccessManager::Operation::PostOperation,
headers);
headers,
false,
{},
{},
custom_proxy);
if (network_reply.first != QNetworkReply::NoError) {
qCriticalNN << LOGSEC_NEXTCLOUD
@ -211,7 +233,9 @@ bool OwnCloudNetworkFactory::createFeed(const QString& url, int parent_id) {
}
}
bool OwnCloudNetworkFactory::renameFeed(const QString& new_name, const QString& custom_feed_id) {
bool OwnCloudNetworkFactory::renameFeed(const QString& new_name,
const QString& custom_feed_id,
const QNetworkProxy& custom_proxy) {
QString final_url = m_urlRenameFeed.arg(custom_feed_id);
QByteArray result_raw;
QJsonObject json;
@ -229,7 +253,11 @@ bool OwnCloudNetworkFactory::renameFeed(const QString& new_name, const QString&
QJsonDocument(json).toJson(QJsonDocument::JsonFormat::Compact),
result_raw,
QNetworkAccessManager::PutOperation,
headers);
headers,
false,
{},
{},
custom_proxy);
if (network_reply.first != QNetworkReply::NetworkError::NoError) {
qCriticalNN << LOGSEC_NEXTCLOUD
@ -242,9 +270,9 @@ bool OwnCloudNetworkFactory::renameFeed(const QString& new_name, const QString&
}
}
OwnCloudGetMessagesResponse OwnCloudNetworkFactory::getMessages(int feed_id) {
OwnCloudGetMessagesResponse OwnCloudNetworkFactory::getMessages(int feed_id, const QNetworkProxy& custom_proxy) {
if (forceServerSideUpdate()) {
triggerFeedUpdate(feed_id);
triggerFeedUpdate(feed_id, custom_proxy);
}
QString final_url = m_urlMessages.arg(QString::number(feed_id),
@ -260,9 +288,14 @@ OwnCloudGetMessagesResponse OwnCloudNetworkFactory::getMessages(int feed_id) {
NetworkResult network_reply = NetworkFactory::performNetworkOperation(final_url,
qApp->settings()->value(GROUP(Feeds),
SETTING(Feeds::UpdateTimeout)).toInt(),
QByteArray(), result_raw,
QByteArray(),
result_raw,
QNetworkAccessManager::Operation::GetOperation,
headers);
headers,
false,
{},
{},
custom_proxy);
OwnCloudGetMessagesResponse msgs_response(network_reply.first, QString::fromUtf8(result_raw));
if (network_reply.first != QNetworkReply::NoError) {
@ -274,7 +307,7 @@ OwnCloudGetMessagesResponse OwnCloudNetworkFactory::getMessages(int feed_id) {
return msgs_response;
}
QNetworkReply::NetworkError OwnCloudNetworkFactory::triggerFeedUpdate(int feed_id) {
QNetworkReply::NetworkError OwnCloudNetworkFactory::triggerFeedUpdate(int feed_id, const QNetworkProxy& custom_proxy) {
// Now, we can trigger the update.
QByteArray raw_output;
QList<QPair<QByteArray, QByteArray>> headers;
@ -286,9 +319,14 @@ QNetworkReply::NetworkError OwnCloudNetworkFactory::triggerFeedUpdate(int feed_i
QString::number(feed_id)),
qApp->settings()->value(GROUP(Feeds),
SETTING(Feeds::UpdateTimeout)).toInt(),
QByteArray(), raw_output,
QByteArray(),
raw_output,
QNetworkAccessManager::Operation::GetOperation,
headers);
headers,
false,
{},
{},
custom_proxy);
if (network_reply.first != QNetworkReply::NetworkError::NoError) {
qCriticalNN << LOGSEC_NEXTCLOUD
@ -299,7 +337,9 @@ QNetworkReply::NetworkError OwnCloudNetworkFactory::triggerFeedUpdate(int feed_i
return network_reply.first;
}
NetworkResult OwnCloudNetworkFactory::markMessagesRead(RootItem::ReadStatus status, const QStringList& custom_ids) {
NetworkResult OwnCloudNetworkFactory::markMessagesRead(RootItem::ReadStatus status,
const QStringList& custom_ids,
const QNetworkProxy& custom_proxy) {
QJsonObject json;
QJsonArray ids;
QString final_url;
@ -330,12 +370,17 @@ NetworkResult OwnCloudNetworkFactory::markMessagesRead(RootItem::ReadStatus stat
QJsonDocument(json).toJson(QJsonDocument::JsonFormat::Compact),
output,
QNetworkAccessManager::Operation::PutOperation,
headers);
headers,
false,
{},
{},
custom_proxy);
}
NetworkResult OwnCloudNetworkFactory::markMessagesStarred(RootItem::Importance importance,
const QStringList& feed_ids,
const QStringList& guid_hashes) {
const QStringList& guid_hashes,
const QNetworkProxy& custom_proxy) {
QJsonObject json;
QJsonArray ids;
QString final_url;
@ -370,7 +415,11 @@ NetworkResult OwnCloudNetworkFactory::markMessagesStarred(RootItem::Importance i
QJsonDocument(json).toJson(QJsonDocument::JsonFormat::Compact),
output,
QNetworkAccessManager::Operation::PutOperation,
headers);
headers,
false,
{},
{},
custom_proxy);
}
int OwnCloudNetworkFactory::batchSize() const {

View File

@ -79,27 +79,6 @@ class OwnCloudNetworkFactory {
QString authPassword() const;
void setAuthPassword(const QString& auth_password);
// Operations.
// Get version info.
OwnCloudStatusResponse status();
// Get feeds & categories (used for sync-in).
OwnCloudGetFeedsCategoriesResponse feedsCategories();
// Feed operations.
bool deleteFeed(const QString& feed_id);
bool createFeed(const QString& url, int parent_id);
bool renameFeed(const QString& new_name, const QString& custom_feed_id);
// Get messages for given feed.
OwnCloudGetMessagesResponse getMessages(int feed_id);
// Misc methods.
QNetworkReply::NetworkError triggerFeedUpdate(int feed_id);
NetworkResult markMessagesRead(RootItem::ReadStatus status, const QStringList& custom_ids);
NetworkResult markMessagesStarred(RootItem::Importance importance, const QStringList& feed_ids, const QStringList& guid_hashes);
// Gets/sets the amount of messages to obtain during single feed update.
int batchSize() const;
void setBatchSize(int batch_size);
@ -107,6 +86,34 @@ class OwnCloudNetworkFactory {
bool downloadOnlyUnreadMessages() const;
void setDownloadOnlyUnreadMessages(bool dowload_only_unread_messages);
// Operations.
// Get version info.
OwnCloudStatusResponse status(const QNetworkProxy& custom_proxy);
// Get feeds & categories (used for sync-in).
OwnCloudGetFeedsCategoriesResponse feedsCategories(const QNetworkProxy& custom_proxy);
// Feed operations.
bool deleteFeed(const QString& feed_id, const QNetworkProxy& custom_proxy);
bool createFeed(const QString& url, int parent_id, const QNetworkProxy& custom_proxy);
bool renameFeed(const QString& new_name, const QString& custom_feed_id, const QNetworkProxy& custom_proxy);
// Get messages for given feed.
OwnCloudGetMessagesResponse getMessages(int feed_id, const QNetworkProxy& custom_proxy);
// Misc methods.
QNetworkReply::NetworkError triggerFeedUpdate(int feed_id, const QNetworkProxy& custom_proxy);
NetworkResult markMessagesRead(RootItem::ReadStatus status,
const QStringList& custom_ids,
const QNetworkProxy& custom_proxy);
NetworkResult markMessagesStarred(RootItem::Importance importance,
const QStringList& feed_ids,
const QStringList& guid_hashes,
const QNetworkProxy& custom_proxy);
private:
QString m_url;
QString m_fixedUrl;

View File

@ -20,7 +20,7 @@ bool OwnCloudFeed::canBeDeleted() const {
}
bool OwnCloudFeed::deleteViaGui() {
if (serviceRoot()->network()->deleteFeed(customId()) && removeItself()) {
if (serviceRoot()->network()->deleteFeed(customId(), getParentServiceRoot()->networkProxy()) && removeItself()) {
serviceRoot()->requestItemRemoval(this);
return true;
}
@ -40,7 +40,8 @@ OwnCloudServiceRoot* OwnCloudFeed::serviceRoot() const {
}
QList<Message> OwnCloudFeed::obtainNewMessages(bool* error_during_obtaining) {
OwnCloudGetMessagesResponse messages = serviceRoot()->network()->getMessages(customNumericId());
OwnCloudGetMessagesResponse messages = serviceRoot()->network()->getMessages(customNumericId(),
getParentServiceRoot()->networkProxy());
if (messages.networkError() != QNetworkReply::NetworkError::NoError) {
setStatus(Feed::Status::NetworkError);

View File

@ -91,7 +91,7 @@ void OwnCloudServiceRoot::saveAllCachedData(bool ignore_errors) {
QStringList ids = i.value();
if (!ids.isEmpty()) {
auto res = network()->markMessagesRead(key, ids);
auto res = network()->markMessagesRead(key, ids, networkProxy());
if (!ignore_errors && res.first != QNetworkReply::NetworkError::NoError) {
addMessageStatesToCache(ids, key);
@ -115,7 +115,7 @@ void OwnCloudServiceRoot::saveAllCachedData(bool ignore_errors) {
guid_hashes.append(msg.m_customHash);
}
auto res = network()->markMessagesStarred(key, feed_ids, guid_hashes);
auto res = network()->markMessagesStarred(key, feed_ids, guid_hashes, networkProxy());
if (!ignore_errors && res.first != QNetworkReply::NetworkError::NoError) {
addMessageStatesToCache(messages, key);
@ -152,7 +152,7 @@ void OwnCloudServiceRoot::saveAccountDataToDatabase(bool creating_new) {
}
RootItem* OwnCloudServiceRoot::obtainNewTreeForSyncIn() const {
OwnCloudGetFeedsCategoriesResponse feed_cats_response = m_network->feedsCategories();
OwnCloudGetFeedsCategoriesResponse feed_cats_response = m_network->feedsCategories(networkProxy());
if (feed_cats_response.networkError() == QNetworkReply::NetworkError::NoError) {
return feed_cats_response.feedsCategories(true);