save
This commit is contained in:
parent
a9fe39df92
commit
2a1289e70a
@ -1 +1 @@
|
||||
Subproject commit 47f4125753452eff8800dbd6600c5a05540b15d9
|
||||
Subproject commit 9c10723bfbaf6cb85107d6ee16e0324e9e487749
|
@ -2,6 +2,9 @@
|
||||
|
||||
#include "services/greader/greadernetwork.h"
|
||||
|
||||
#include "miscellaneous/application.h"
|
||||
#include "network-web/networkfactory.h"
|
||||
|
||||
GreaderNetwork::GreaderNetwork(QObject* parent)
|
||||
: QObject(parent), m_service(GreaderServiceRoot::Service::FreshRss) {}
|
||||
|
||||
@ -9,8 +12,28 @@ QList<Message> GreaderNetwork::messages(ServiceRoot* root, const QString& stream
|
||||
return {};
|
||||
}
|
||||
|
||||
NetworkResult GreaderNetwork::status(const QNetworkProxy& custom_proxy) const {
|
||||
return NetworkResult(QNetworkReply::NetworkError::NoError, {});
|
||||
QNetworkReply::NetworkError GreaderNetwork::clientLogin(const QNetworkProxy& proxy) {
|
||||
QString full_url = generateFullUrl(Operations::ClientLogin);
|
||||
auto timeout = qApp->settings()->value(GROUP(Feeds), SETTING(Feeds::UpdateTimeout)).toInt();
|
||||
QByteArray output;
|
||||
auto network_result = NetworkFactory::performNetworkOperation(full_url,
|
||||
timeout,
|
||||
{},
|
||||
output,
|
||||
QNetworkAccessManager::Operation::GetOperation,
|
||||
{},
|
||||
false,
|
||||
{},
|
||||
{},
|
||||
proxy);
|
||||
|
||||
if (network_result.first == QNetworkReply::NetworkError::NoError) {
|
||||
// Save credentials.
|
||||
auto lines = QString::fromUtf8(output).replace(QSL("\r"), QString()).split('\n');
|
||||
int a = 5;
|
||||
}
|
||||
|
||||
return network_result.first;
|
||||
}
|
||||
|
||||
GreaderServiceRoot::Service GreaderNetwork::service() const {
|
||||
@ -68,3 +91,19 @@ int GreaderNetwork::batchSize() const {
|
||||
void GreaderNetwork::setBatchSize(int batch_size) {
|
||||
m_batchSize = batch_size;
|
||||
}
|
||||
|
||||
QString GreaderNetwork::sanitizedBaseUrl() const {
|
||||
if (m_baseUrl.endsWith('/')) {
|
||||
return m_baseUrl;
|
||||
}
|
||||
else {
|
||||
return m_baseUrl + QL1C('/');
|
||||
}
|
||||
}
|
||||
|
||||
QString GreaderNetwork::generateFullUrl(GreaderNetwork::Operations operation) const {
|
||||
switch (operation) {
|
||||
case Operations::ClientLogin:
|
||||
return sanitizedBaseUrl() + QSL("accounts/ClientLogin?Email=%1&Passwd=%2").arg(username(), password());
|
||||
}
|
||||
}
|
||||
|
@ -13,12 +13,17 @@ class GreaderNetwork : public QObject {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
enum class Operations {
|
||||
ClientLogin
|
||||
};
|
||||
|
||||
explicit GreaderNetwork(QObject* parent = nullptr);
|
||||
|
||||
// Network operations.
|
||||
QList<Message> messages(ServiceRoot* root, const QString& stream_id, Feed::Status& error);
|
||||
|
||||
NetworkResult status(const QNetworkProxy& custom_proxy) const;
|
||||
// Performs client login, if successful, then saves SID, LSID and Auth.
|
||||
QNetworkReply::NetworkError clientLogin(const QNetworkProxy& proxy);
|
||||
|
||||
// Metadata.
|
||||
GreaderServiceRoot::Service service() const;
|
||||
@ -38,6 +43,10 @@ class GreaderNetwork : public QObject {
|
||||
int batchSize() const;
|
||||
void setBatchSize(int batch_size);
|
||||
|
||||
private:
|
||||
QString sanitizedBaseUrl() const;
|
||||
QString generateFullUrl(Operations operation) const;
|
||||
|
||||
private:
|
||||
GreaderServiceRoot::Service m_service;
|
||||
QString m_username;
|
||||
|
@ -76,18 +76,19 @@ void GreaderAccountDetails::performTest(const QNetworkProxy& custom_proxy) {
|
||||
factory.setUsername(m_ui.m_txtUsername->lineEdit()->text());
|
||||
factory.setPassword(m_ui.m_txtPassword->lineEdit()->text());
|
||||
factory.setBaseUrl(m_ui.m_txtUrl->lineEdit()->text());
|
||||
factory.setService(service());
|
||||
|
||||
NetworkResult result = factory.status(custom_proxy);
|
||||
auto result = factory.clientLogin(custom_proxy);
|
||||
|
||||
if (result.first != QNetworkReply::NetworkError::NoError) {
|
||||
if (result != QNetworkReply::NetworkError::NoError) {
|
||||
m_ui.m_lblTestResult->setStatus(WidgetWithStatus::StatusType::Error,
|
||||
tr("Network error: '%1'.").arg(NetworkFactory::networkErrorText(result.first)),
|
||||
tr("Network error: '%1'.").arg(NetworkFactory::networkErrorText(result)),
|
||||
tr("Network error, have you entered correct Nextcloud endpoint and password?"));
|
||||
}
|
||||
else {
|
||||
m_ui.m_lblTestResult->setStatus(WidgetWithStatus::StatusType::Error,
|
||||
tr("Unspecified error, did you enter correct URL?"),
|
||||
tr("Unspecified error, did you enter correct URL?"));
|
||||
m_ui.m_lblTestResult->setStatus(WidgetWithStatus::StatusType::Ok,
|
||||
tr("You are good to go!"),
|
||||
tr("Yeah."));
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user