mirror of
https://github.com/martinrotter/rssguard.git
synced 2025-01-30 09:04:52 +01:00
refact
This commit is contained in:
parent
811d29f643
commit
01e79d7c5d
@ -95,6 +95,7 @@
|
||||
#define LOGSEC_INOREADER "inoreader: "
|
||||
#define LOGSEC_TTRSS "tt-rss: "
|
||||
#define LOGSEC_GMAIL "gmail: "
|
||||
#define LOGSEC_OAUTH "oauth: "
|
||||
|
||||
#define MAX_ZOOM_FACTOR 5.0f
|
||||
#define MIN_ZOOM_FACTOR 0.25f
|
||||
|
@ -123,6 +123,10 @@ void Downloader::finished() {
|
||||
request.setUrl(redirection_url);
|
||||
}
|
||||
|
||||
qWarningNN << LOGSEC_NETWORK
|
||||
<< "We are redirecting URL request to:"
|
||||
<< QUOTE_W_SPACE_DOT(request.url());
|
||||
|
||||
m_activeReply->deleteLater();
|
||||
m_activeReply = nullptr;
|
||||
|
||||
@ -175,6 +179,12 @@ void Downloader::progressInternal(qint64 bytes_received, qint64 bytes_total) {
|
||||
emit progress(bytes_received, bytes_total);
|
||||
}
|
||||
|
||||
void Downloader::setCustomPropsToReply(QNetworkReply* reply) {
|
||||
reply->setProperty("protected", m_targetProtected);
|
||||
reply->setProperty("username", m_targetUsername);
|
||||
reply->setProperty("password", m_targetPassword);
|
||||
}
|
||||
|
||||
QList<HttpResponse> Downloader::decodeMultipartAnswer(QNetworkReply* reply) {
|
||||
QByteArray data = reply->readAll();
|
||||
|
||||
@ -231,9 +241,7 @@ QList<HttpResponse> Downloader::decodeMultipartAnswer(QNetworkReply* reply) {
|
||||
void Downloader::runDeleteRequest(const QNetworkRequest& request) {
|
||||
m_timer->start();
|
||||
m_activeReply = m_downloadManager->deleteResource(request);
|
||||
m_activeReply->setProperty("protected", m_targetProtected);
|
||||
m_activeReply->setProperty("username", m_targetUsername);
|
||||
m_activeReply->setProperty("password", m_targetPassword);
|
||||
setCustomPropsToReply(m_activeReply);
|
||||
connect(m_activeReply, &QNetworkReply::downloadProgress, this, &Downloader::progressInternal);
|
||||
connect(m_activeReply, &QNetworkReply::finished, this, &Downloader::finished);
|
||||
}
|
||||
@ -241,9 +249,7 @@ void Downloader::runDeleteRequest(const QNetworkRequest& request) {
|
||||
void Downloader::runPutRequest(const QNetworkRequest& request, const QByteArray& data) {
|
||||
m_timer->start();
|
||||
m_activeReply = m_downloadManager->put(request, data);
|
||||
m_activeReply->setProperty("protected", m_targetProtected);
|
||||
m_activeReply->setProperty("username", m_targetUsername);
|
||||
m_activeReply->setProperty("password", m_targetPassword);
|
||||
setCustomPropsToReply(m_activeReply);
|
||||
connect(m_activeReply, &QNetworkReply::downloadProgress, this, &Downloader::progressInternal);
|
||||
connect(m_activeReply, &QNetworkReply::finished, this, &Downloader::finished);
|
||||
}
|
||||
@ -251,9 +257,7 @@ void Downloader::runPutRequest(const QNetworkRequest& request, const QByteArray&
|
||||
void Downloader::runPostRequest(const QNetworkRequest& request, QHttpMultiPart* multipart_data) {
|
||||
m_timer->start();
|
||||
m_activeReply = m_downloadManager->post(request, multipart_data);
|
||||
m_activeReply->setProperty("protected", m_targetProtected);
|
||||
m_activeReply->setProperty("username", m_targetUsername);
|
||||
m_activeReply->setProperty("password", m_targetPassword);
|
||||
setCustomPropsToReply(m_activeReply);
|
||||
connect(m_activeReply, &QNetworkReply::downloadProgress, this, &Downloader::progressInternal);
|
||||
connect(m_activeReply, &QNetworkReply::finished, this, &Downloader::finished);
|
||||
}
|
||||
@ -261,9 +265,7 @@ void Downloader::runPostRequest(const QNetworkRequest& request, QHttpMultiPart*
|
||||
void Downloader::runPostRequest(const QNetworkRequest& request, const QByteArray& data) {
|
||||
m_timer->start();
|
||||
m_activeReply = m_downloadManager->post(request, data);
|
||||
m_activeReply->setProperty("protected", m_targetProtected);
|
||||
m_activeReply->setProperty("username", m_targetUsername);
|
||||
m_activeReply->setProperty("password", m_targetPassword);
|
||||
setCustomPropsToReply(m_activeReply);
|
||||
connect(m_activeReply, &QNetworkReply::downloadProgress, this, &Downloader::progressInternal);
|
||||
connect(m_activeReply, &QNetworkReply::finished, this, &Downloader::finished);
|
||||
}
|
||||
@ -271,10 +273,7 @@ void Downloader::runPostRequest(const QNetworkRequest& request, const QByteArray
|
||||
void Downloader::runGetRequest(const QNetworkRequest& request) {
|
||||
m_timer->start();
|
||||
m_activeReply = m_downloadManager->get(request);
|
||||
m_activeReply->setProperty("protected", m_targetProtected);
|
||||
m_activeReply->setProperty("username", m_targetUsername);
|
||||
m_activeReply->setProperty("password", m_targetPassword);
|
||||
|
||||
setCustomPropsToReply(m_activeReply);
|
||||
connect(m_activeReply, &QNetworkReply::downloadProgress, this, &Downloader::progressInternal);
|
||||
connect(m_activeReply, &QNetworkReply::finished, this, &Downloader::finished);
|
||||
}
|
||||
|
@ -66,6 +66,7 @@ class Downloader : public QObject {
|
||||
void progressInternal(qint64 bytes_received, qint64 bytes_total);
|
||||
|
||||
private:
|
||||
void setCustomPropsToReply(QNetworkReply* reply);
|
||||
QList<HttpResponse> decodeMultipartAnswer(QNetworkReply* reply);
|
||||
void manipulateData(const QString& url, QNetworkAccessManager::Operation operation,
|
||||
const QByteArray& data, QHttpMultiPart* multipart_data,
|
||||
|
@ -440,7 +440,7 @@ DownloadManager::DownloadManager(QWidget* parent) : TabContent(parent), m_ui(new
|
||||
DownloadManager::~DownloadManager() {
|
||||
m_autoSaver->changeOccurred();
|
||||
m_autoSaver->saveIfNeccessary();
|
||||
qDebug("Destroying DownloadManager instance.");
|
||||
qDebugNN << LOGSEC_NETWORK << "Destroying DownloadManager instance.";
|
||||
}
|
||||
|
||||
int DownloadManager::activeDownloads() const {
|
||||
|
@ -112,11 +112,11 @@ void OAuth2Service::timerEvent(QTimerEvent* event) {
|
||||
|
||||
if (window_about_expire < QDateTime::currentDateTime()) {
|
||||
// We try to refresh access token, because it probably expires soon.
|
||||
qDebug("Refreshing automatically access token.");
|
||||
qDebugNN << LOGSEC_OAUTH << "Refreshing automatically access token.";
|
||||
refreshAccessToken();
|
||||
}
|
||||
else {
|
||||
qDebug("Access token is not expired yet.");
|
||||
qDebugNN << LOGSEC_OAUTH << "Access token is not expired yet.";
|
||||
}
|
||||
}
|
||||
|
||||
@ -145,6 +145,7 @@ void OAuth2Service::retrieveAccessToken(const QString& auth_code) {
|
||||
auth_code, m_tokenGrantType,
|
||||
m_redirectionHandler->listenAddressPort());
|
||||
|
||||
qDebugNN << LOGSEC_OAUTH << "Posting data for access token retrieval:" << QUOTE_W_SPACE_DOT(content);
|
||||
m_networkManager.post(networkRequest, content.toUtf8());
|
||||
}
|
||||
|
||||
@ -167,6 +168,7 @@ void OAuth2Service::refreshAccessToken(QString refresh_token) {
|
||||
tr("Refreshing login tokens for '%1'...").arg(m_tokenUrl.toString()),
|
||||
QSystemTrayIcon::MessageIcon::Information);
|
||||
|
||||
qDebugNN << LOGSEC_OAUTH << "Posting data for access token refreshing:" << QUOTE_W_SPACE_DOT(content);
|
||||
m_networkManager.post(networkRequest, content.toUtf8());
|
||||
}
|
||||
|
||||
@ -175,7 +177,7 @@ void OAuth2Service::tokenRequestFinished(QNetworkReply* network_reply) {
|
||||
QJsonDocument json_document = QJsonDocument::fromJson(repl);
|
||||
QJsonObject root_obj = json_document.object();
|
||||
|
||||
qDebug() << "Token response:" << json_document.toJson();
|
||||
qDebugNN << LOGSEC_OAUTH << "Token response:" << QUOTE_W_SPACE_DOT(json_document.toJson());
|
||||
|
||||
if (network_reply->error() != QNetworkReply::NetworkError::NoError) {
|
||||
emit tokensRetrieveError(QString(), NetworkFactory::networkErrorText(network_reply->error()));
|
||||
@ -200,7 +202,9 @@ void OAuth2Service::tokenRequestFinished(QNetworkReply* network_reply) {
|
||||
setRefreshToken(refresh_token);
|
||||
}
|
||||
|
||||
qDebug() << "Obtained refresh token" << refreshToken() << "- expires on date/time" << tokensExpireIn();
|
||||
qDebugNN << LOGSEC_OAUTH
|
||||
<< "Obtained refresh token" << QUOTE_W_SPACE(refreshToken())
|
||||
<< "- expires on date/time" << QUOTE_W_SPACE_DOT(tokensExpireIn());
|
||||
|
||||
emit tokensReceived(accessToken(), refreshToken(), expires);
|
||||
}
|
||||
@ -260,7 +264,8 @@ void OAuth2Service::setRefreshToken(const QString& refresh_token) {
|
||||
|
||||
bool OAuth2Service::login() {
|
||||
if (!m_redirectionHandler->isListening()) {
|
||||
qCritical("Cannot log-in because OAuth redirection handler is not listening.");
|
||||
qCriticalNN << LOGSEC_OAUTH
|
||||
<< "Cannot log-in because OAuth redirection handler is not listening.";
|
||||
return false;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user