aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMike Skec <skec@protonmail.ch>2021-01-09 15:55:52 +1100
committerFelix Queißner <felix@ib-queissner.de>2021-01-10 13:40:46 +0100
commitc635094a6bdfcf2f081eb3c0ed9a1454ae2933fb (patch)
treeb41aca9c2803ad3acbe89c027b340b15ac473eee /src
parentdd3e8716b276f9f1646338f8801ca9a2f688fc46 (diff)
downloadkristall-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')
-rw-r--r--src/browsertab.cpp7
-rw-r--r--src/browsertab.hpp3
-rw-r--r--src/kristall.hpp10
-rw-r--r--src/mainwindow.cpp57
-rw-r--r--src/mainwindow.hpp9
-rw-r--r--src/protocolhandler.hpp5
-rw-r--r--src/protocols/fingerclient.cpp10
-rw-r--r--src/protocols/geminiclient.cpp14
-rw-r--r--src/protocols/gopherclient.cpp12
-rw-r--r--src/protocols/webclient.cpp6
10 files changed, 131 insertions, 2 deletions
diff --git a/src/browsertab.cpp b/src/browsertab.cpp
index 0bb1133..faae7dd 100644
--- a/src/browsertab.cpp
+++ b/src/browsertab.cpp
@@ -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);
diff --git a/src/browsertab.hpp b/src/browsertab.hpp
index 9b0d662..27add74 100644
--- a/src/browsertab.hpp
+++ b/src/browsertab.hpp
@@ -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
diff --git a/src/kristall.hpp b/src/kristall.hpp
index 2be1065..8df86a6 100644
--- a/src/kristall.hpp
+++ b/src/kristall.hpp
@@ -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 {
diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp
index 26f49ec..0bc4d90 100644
--- a/src/mainwindow.cpp
+++ b/src/mainwindow.cpp
@@ -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();
diff --git a/src/mainwindow.hpp b/src/mainwindow.hpp
index 8b092f3..7602ac5 100644
--- a/src/mainwindow.hpp
+++ b/src/mainwindow.hpp
@@ -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
diff --git a/src/protocolhandler.hpp b/src/protocolhandler.hpp
index bdc1cd3..8e2c1e8 100644
--- a/src/protocolhandler.hpp
+++ b/src/protocolhandler.hpp
@@ -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);
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;