diff options
| author | Mike Skec <skec@protonmail.ch> | 2021-01-09 15:55:52 +1100 |
|---|---|---|
| committer | Felix Queißner <felix@ib-queissner.de> | 2021-01-10 13:40:46 +0100 |
| commit | c635094a6bdfcf2f081eb3c0ed9a1454ae2933fb (patch) | |
| tree | b41aca9c2803ad3acbe89c027b340b15ac473eee /src/protocols | |
| parent | dd3e8716b276f9f1646338f8801ca9a2f688fc46 (diff) | |
| download | kristall-c635094a6bdfcf2f081eb3c0ed9a1454ae2933fb.tar.gz | |
status bar: show request status when loading pages
status text for loading HTTP/S is only a simple 'loading webpage'. The other protocols display more information
Diffstat (limited to 'src/protocols')
| -rw-r--r-- | src/protocols/fingerclient.cpp | 10 | ||||
| -rw-r--r-- | src/protocols/geminiclient.cpp | 14 | ||||
| -rw-r--r-- | src/protocols/gopherclient.cpp | 12 | ||||
| -rw-r--r-- | src/protocols/webclient.cpp | 6 |
4 files changed, 42 insertions, 0 deletions
diff --git a/src/protocols/fingerclient.cpp b/src/protocols/fingerclient.cpp index 83d5e1e..ee62ce1 100644 --- a/src/protocols/fingerclient.cpp +++ b/src/protocols/fingerclient.cpp @@ -1,5 +1,6 @@ #include "fingerclient.hpp" #include "ioutil.hpp" +#include "kristall.hpp" FingerClient::FingerClient() : ProtocolHandler(nullptr) { @@ -12,6 +13,11 @@ FingerClient::FingerClient() : ProtocolHandler(nullptr) #else connect(&socket, QOverload<QAbstractSocket::SocketError>::of(&QTcpSocket::error), this, &FingerClient::on_socketError); #endif + + connect(&socket, &QAbstractSocket::hostFound, this, [this]() { + emit this->requestStateChange(RequestState::HostFound); + }); + emit this->requestStateChange(RequestState::None); } FingerClient::~FingerClient() @@ -64,6 +70,8 @@ void FingerClient::on_connected() auto blob = (requested_user + "\r\n").toUtf8(); IoUtil::writeAll(socket, blob); + + emit this->requestStateChange(RequestState::Connected); } void FingerClient::on_readRead() @@ -80,6 +88,8 @@ void FingerClient::on_finished() was_cancelled = true; } body.clear(); + + emit this->requestStateChange(RequestState::None); } void FingerClient::on_socketError(QAbstractSocket::SocketError error_code) diff --git a/src/protocols/geminiclient.cpp b/src/protocols/geminiclient.cpp index 71bac3d..ee5ac27 100644 --- a/src/protocols/geminiclient.cpp +++ b/src/protocols/geminiclient.cpp @@ -19,6 +19,18 @@ GeminiClient::GeminiClient() : ProtocolHandler(nullptr) #else connect(&socket, QOverload<QAbstractSocket::SocketError>::of(&QTcpSocket::error), this, &GeminiClient::socketError); #endif + + // States + connect(&socket, &QAbstractSocket::hostFound, this, [this]() { + emit this->requestStateChange(RequestState::HostFound); + }); + connect(&socket, &QAbstractSocket::connected, this, [this]() { + emit this->requestStateChange(RequestState::Connected); + }); + connect(&socket, &QAbstractSocket::disconnected, this, [this]() { + emit this->requestStateChange(RequestState::None); + }); + emit this->requestStateChange(RequestState::None); } GeminiClient::~GeminiClient() @@ -45,6 +57,8 @@ bool GeminiClient::startRequest(const QUrl &url, RequestOptions options) return false; } + emit this->requestStateChange(RequestState::Started); + this->is_error_state = false; this->options = options; diff --git a/src/protocols/gopherclient.cpp b/src/protocols/gopherclient.cpp index ec0fa70..af2b141 100644 --- a/src/protocols/gopherclient.cpp +++ b/src/protocols/gopherclient.cpp @@ -1,5 +1,6 @@ #include "gopherclient.hpp" #include "ioutil.hpp" +#include "kristall.hpp" GopherClient::GopherClient(QObject *parent) : ProtocolHandler(parent) { @@ -12,6 +13,11 @@ GopherClient::GopherClient(QObject *parent) : ProtocolHandler(parent) #else connect(&socket, QOverload<QAbstractSocket::SocketError>::of(&QTcpSocket::error), this, &GopherClient::on_socketError); #endif + + connect(&socket, &QAbstractSocket::hostFound, this, [this]() { + emit this->requestStateChange(RequestState::HostFound); + }); + emit this->requestStateChange(RequestState::None); } GopherClient::~GopherClient() @@ -34,6 +40,8 @@ bool GopherClient::startRequest(const QUrl &url, RequestOptions options) if(url.scheme() != "gopher") return false; + emit this->requestStateChange(RequestState::Started); + // Second char on the URL path denotes the Gopher type // See https://tools.ietf.org/html/rfc4266 QString type = url.path().mid(1, 1); @@ -79,6 +87,8 @@ void GopherClient::on_connected() auto blob = (requested_url.path().mid(2) + "\r\n").toUtf8(); IoUtil::writeAll(socket, blob); + + emit this->requestStateChange(RequestState::Connected); } void GopherClient::on_readRead() @@ -107,6 +117,8 @@ void GopherClient::on_finished() was_cancelled = true; } body.clear(); + + emit this->requestStateChange(RequestState::None); } void GopherClient::on_socketError(QAbstractSocket::SocketError error_code) diff --git a/src/protocols/webclient.cpp b/src/protocols/webclient.cpp index e4a2036..58b3365 100644 --- a/src/protocols/webclient.cpp +++ b/src/protocols/webclient.cpp @@ -9,6 +9,8 @@ WebClient::WebClient() : current_reply(nullptr) { manager.setRedirectPolicy(QNetworkRequest::NoLessSafeRedirectPolicy); + + emit this->requestStateChange(RequestState::None); } WebClient::~WebClient() @@ -29,6 +31,8 @@ bool WebClient::startRequest(const QUrl &url, RequestOptions options) if(this->current_reply != nullptr) return true; + emit this->requestStateChange(RequestState::StartedWeb); + this->options = options; this->body.clear(); @@ -101,6 +105,8 @@ void WebClient::on_data() void WebClient::on_finished() { + emit this->requestStateChange(RequestState::None); + emit this->hostCertificateLoaded(this->current_reply->sslConfiguration().peerCertificate()); auto * const reply = this->current_reply; |
