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
This commit is contained in:
Mike Skec 2021-01-09 15:55:52 +11:00 committed by Felix Queißner
parent dd3e8716b2
commit c635094a6b
10 changed files with 131 additions and 2 deletions

View File

@ -520,6 +520,9 @@ void BrowserTab::on_requestComplete(const QByteArray &ref_data, const MimeType &
emit this->fileLoaded(this->current_stats);
this->updateMouseCursor(false);
emit this->requestStateChanged(RequestState::None);
this->request_state = RequestState::None;
}
void BrowserTab::renderPage(const QByteArray &data, const MimeType &mime)
@ -1355,6 +1358,10 @@ void BrowserTab::addProtocolHandler(std::unique_ptr<ProtocolHandler> &&handler)
connect(handler.get(), &ProtocolHandler::requestProgress, this, &BrowserTab::on_requestProgress);
connect(handler.get(), &ProtocolHandler::requestComplete, this,
qOverload<QByteArray const &, QString const &>(&BrowserTab::on_requestComplete));
connect(handler.get(), &ProtocolHandler::requestStateChange, this, [this](RequestState state) {
emit this->requestStateChanged(state);
this->request_state = state;
});
connect(handler.get(), &ProtocolHandler::redirected, this, &BrowserTab::on_redirected);
connect(handler.get(), &ProtocolHandler::inputRequired, this, &BrowserTab::on_inputRequired);
connect(handler.get(), &ProtocolHandler::networkError, this, &BrowserTab::on_networkError);

View File

@ -105,6 +105,7 @@ signals:
void titleChanged(QString const & title);
void locationChanged(QUrl const & url);
void fileLoaded(DocumentStats const & stats);
void requestStateChanged(RequestState state);
private slots:
void on_url_bar_returnPressed();
@ -228,6 +229,8 @@ public:
bool no_url_style = false;
bool was_read_from_cache = false;
RequestState request_state;
};
#endif // BROWSERTAB_HPP

View File

@ -26,6 +26,16 @@ enum class UIDensity : int
classic = 1
};
enum class RequestState : int
{
None = 0,
Started = 1,
HostFound = 2,
Connected = 3,
StartedWeb = 255,
};
struct GenericSettings
{
enum TextDisplay {

View File

@ -105,6 +105,7 @@ BrowserTab * MainWindow::addEmptyTab(bool focus_new, bool load_default)
connect(tab, &BrowserTab::titleChanged, this, &MainWindow::on_tab_titleChanged);
connect(tab, &BrowserTab::fileLoaded, this, &MainWindow::on_tab_fileLoaded);
connect(tab, &BrowserTab::requestStateChanged, this, &MainWindow::on_tab_requestStateChanged);
int index = this->ui->browser_tabs->addTab(tab, "Page");
@ -147,11 +148,47 @@ void MainWindow::setUrlPreview(const QUrl &url)
if(str.length() > 300) {
str = str.mid(0, 300) + "...";
}
this->previewing_url = true;
this->url_status->setText(str);
return;
}
else {
this->url_status->setText("");
this->previewing_url = false;
this->url_status->setText(this->request_status);
}
void MainWindow::setRequestState(RequestState state)
{
switch (state)
{
case RequestState::Started:
{
this->request_status = "Looking up...";
} break;
case RequestState::StartedWeb:
{
this->request_status = "Loading webpage...";
} break;
case RequestState::HostFound:
{
this->request_status = "Connecting...";
} break;
case RequestState::Connected:
{
this->request_status = "Downloading...";
} break;
default:
{
this->request_status = "";
} break;
}
if (!this->previewing_url)
this->url_status->setText(this->request_status);
}
void MainWindow::viewPageSource()
@ -247,15 +284,19 @@ void MainWindow::on_browser_tabs_currentChanged(int index)
{
tab->refreshFavButton();
}
this->setRequestState(tab->request_state);
} else {
this->ui->outline_view->setModel(nullptr);
this->ui->history_view->setModel(nullptr);
this->setFileStatus(DocumentStats { });
this->setRequestState(RequestState::None);
}
} else {
this->ui->outline_view->setModel(nullptr);
this->ui->history_view->setModel(nullptr);
this->setFileStatus(DocumentStats { });
this->setRequestState(RequestState::None);
}
updateWindowTitle();
}
@ -487,6 +528,18 @@ void MainWindow::on_tab_fileLoaded(DocumentStats const & stats)
}
}
void MainWindow::on_tab_requestStateChanged(RequestState state)
{
auto * tab = qobject_cast<BrowserTab*>(sender());
if(tab != nullptr) {
int index = this->ui->browser_tabs->indexOf(tab);
assert(index >= 0);
if(index == this->ui->browser_tabs->currentIndex()) {
setRequestState(state);
}
}
}
void MainWindow::on_focus_inputbar()
{
BrowserTab * tab = this->curTab();

View File

@ -20,6 +20,8 @@ class BrowserTab;
enum class UIDensity : int;
enum class RequestState : int;
class MainWindow : public QMainWindow
{
Q_OBJECT
@ -96,6 +98,8 @@ private: // slots
void on_tab_fileLoaded(DocumentStats const & stats);
void on_tab_requestStateChanged(RequestState state);
void on_tab_titleChanged(QString const & title);
void on_tab_locationChanged(QUrl const & url);
@ -106,6 +110,8 @@ private: // slots
private:
void setFileStatus(DocumentStats const & stats);
void setRequestState(RequestState state);
public:
QApplication * application;
@ -117,5 +123,8 @@ private:
QLabel * file_cached;
QLabel * file_mime;
QLabel * load_time;
QString request_status;
bool previewing_url = false;
};
#endif // MAINWINDOW_HPP

View File

@ -6,6 +6,8 @@
#include <QObject>
#include <QAbstractSocket>
enum class RequestState : int;
class ProtocolHandler : public QObject
{
Q_OBJECT
@ -50,6 +52,9 @@ signals:
//! The request completed with the given data and mime type
void requestComplete(QByteArray const & data, QString const & mime);
//! The state of the request has changed
void requestStateChange(RequestState state);
//! Server redirected us to another URL
void redirected(QUrl const & uri, bool is_permanent);

View File

@ -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)

View File

@ -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;

View File

@ -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)

View File

@ -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;