mirror of
https://github.com/martinrotter/rssguard.git
synced 2025-01-26 15:34:59 +01:00
simple progress integration
This commit is contained in:
parent
c666ab062f
commit
5a055641f3
@ -16,6 +16,7 @@
|
||||
|
||||
LiteHtmlViewer::LiteHtmlViewer(QWidget* parent) : QLiteHtmlWidget(parent) {
|
||||
setResourceHandler([this](const QUrl& url) {
|
||||
emit loadProgress(-1);
|
||||
return handleResource(url);
|
||||
});
|
||||
}
|
||||
@ -30,19 +31,11 @@ void LiteHtmlViewer::bindToBrowser(WebBrowser* browser) {
|
||||
connect(this, &LiteHtmlViewer::linkHighlighted, browser, [browser](const QUrl& url) {
|
||||
browser->onLinkHovered(url.toString());
|
||||
});
|
||||
|
||||
// TODO: změna ikon, změna stavu akcí.
|
||||
|
||||
/*
|
||||
connect(this, &WebEngineViewer::urlChanged, browser, &WebBrowser::updateUrl);
|
||||
connect(this, &WebEngineViewer::loadStarted, browser, &WebBrowser::onLoadingStarted);
|
||||
connect(this, &WebEngineViewer::loadProgress, browser, &WebBrowser::onLoadingProgress);
|
||||
connect(this, &WebEngineViewer::loadFinished, browser, &WebBrowser::onLoadingFinished);
|
||||
connect(this, &WebEngineViewer::titleChanged, browser, &WebBrowser::onTitleChanged);
|
||||
connect(this, &WebEngineViewer::iconChanged, browser, &WebBrowser::onIconChanged);
|
||||
|
||||
connect(page(), &WebEnginePage::windowCloseRequested, browser, &WebBrowser::closeRequested);
|
||||
*/
|
||||
connect(this, &LiteHtmlViewer::titleChanged, browser, &WebBrowser::onTitleChanged);
|
||||
connect(this, &LiteHtmlViewer::urlChanged, browser, &WebBrowser::updateUrl);
|
||||
connect(this, &LiteHtmlViewer::loadStarted, browser, &WebBrowser::onLoadingStarted);
|
||||
connect(this, &LiteHtmlViewer::loadProgress, browser, &WebBrowser::onLoadingProgress);
|
||||
connect(this, &LiteHtmlViewer::loadFinished, browser, &WebBrowser::onLoadingFinished);
|
||||
}
|
||||
|
||||
void LiteHtmlViewer::findText(const QString& text, bool backwards) {
|
||||
@ -52,21 +45,48 @@ void LiteHtmlViewer::findText(const QString& text, bool backwards) {
|
||||
}
|
||||
|
||||
void LiteHtmlViewer::setUrl(const QUrl& url) {
|
||||
QByteArray output;
|
||||
emit loadStarted();
|
||||
AdblockRequestInfo block_request(url);
|
||||
|
||||
NetworkFactory::performNetworkOperation(
|
||||
if (url.path().endsWith(QSL("css"))) {
|
||||
block_request.setResourceType(QSL("stylesheet"));
|
||||
}
|
||||
else {
|
||||
block_request.setResourceType(QSL("image"));
|
||||
}
|
||||
|
||||
if (qApp->web()->adBlock()->block(block_request).m_blocked) {
|
||||
qWarningNN << LOGSEC_ADBLOCK << "Blocked request:" << QUOTE_W_SPACE_DOT(block_request.requestUrl().toString());
|
||||
return;
|
||||
}
|
||||
|
||||
QByteArray output;
|
||||
auto net_res = NetworkFactory::performNetworkOperation(
|
||||
url.toString(),
|
||||
5000,
|
||||
{},
|
||||
output,
|
||||
QNetworkAccessManager::Operation::GetOperation);
|
||||
QString html_str;
|
||||
|
||||
setHtml(QString::fromUtf8(output), url);
|
||||
if (net_res.m_networkError != QNetworkReply::NetworkError::NoError) {
|
||||
html_str = "Error!";
|
||||
}
|
||||
else {
|
||||
html_str = QString::fromUtf8(output);
|
||||
}
|
||||
|
||||
setHtml(html_str, url);
|
||||
|
||||
emit loadFinished(net_res.m_networkError == QNetworkReply::NetworkError::NoError);
|
||||
}
|
||||
|
||||
void LiteHtmlViewer::setHtml(const QString& html, const QUrl& base_url) {
|
||||
QLiteHtmlWidget::setUrl(base_url);
|
||||
QLiteHtmlWidget::setHtml(html);
|
||||
|
||||
emit titleChanged(title());
|
||||
emit urlChanged(base_url);
|
||||
}
|
||||
|
||||
QString LiteHtmlViewer::html() const {
|
||||
@ -151,6 +171,7 @@ void LiteHtmlViewer::loadMessages(const QList<Message>& messages, RootItem* root
|
||||
}
|
||||
|
||||
setHtml(msg_contents, QUrl::fromUserInput(base_url));
|
||||
emit loadFinished(true);
|
||||
}
|
||||
|
||||
double LiteHtmlViewer::verticalScrollBarPosition() const {
|
||||
|
@ -35,6 +35,11 @@ class LiteHtmlViewer : public QLiteHtmlWidget, public WebViewer {
|
||||
|
||||
signals:
|
||||
void zoomFactorChanged();
|
||||
void titleChanged(const QString& new_title);
|
||||
void urlChanged(const QUrl& url);
|
||||
void loadStarted();
|
||||
void loadProgress(int progress);
|
||||
void loadFinished(bool success);
|
||||
|
||||
protected:
|
||||
virtual void wheelEvent(QWheelEvent* event);
|
||||
|
@ -270,7 +270,7 @@ void WebBrowser::initializeLayout() {
|
||||
m_toolBar->addWidget(m_txtLocation);
|
||||
|
||||
m_loadingProgress = new QProgressBar(this);
|
||||
m_loadingProgress->setFixedHeight(5);
|
||||
m_loadingProgress->setFixedHeight(10);
|
||||
m_loadingProgress->setMinimum(0);
|
||||
m_loadingProgress->setTextVisible(false);
|
||||
m_loadingProgress->setMaximum(100);
|
||||
@ -295,7 +295,8 @@ void WebBrowser::onLoadingStarted() {
|
||||
}
|
||||
|
||||
void WebBrowser::onLoadingProgress(int progress) {
|
||||
m_loadingProgress->setValue(progress);
|
||||
m_loadingProgress->setMaximum(progress < 0 ? 0 : 100);
|
||||
m_loadingProgress->setValue(progress < 0 ? 0 : progress);
|
||||
}
|
||||
|
||||
void WebBrowser::onLoadingFinished(bool success) {
|
||||
|
@ -40,8 +40,8 @@ class WebEngineViewer : public QWebEngineView, public WebViewer {
|
||||
virtual QString html() const;
|
||||
virtual QUrl url() const;
|
||||
|
||||
signals:
|
||||
void zoomFactorChanged();
|
||||
signals:
|
||||
void zoomFactorChanged();
|
||||
|
||||
protected:
|
||||
virtual QWebEngineView* createWindow(QWebEnginePage::WebWindowType type);
|
||||
|
Loading…
Reference in New Issue
Block a user