mirror of
https://github.com/martinrotter/rssguard.git
synced 2025-02-05 11:47:53 +01:00
simple progress integration
This commit is contained in:
parent
c666ab062f
commit
5a055641f3
@ -16,6 +16,7 @@
|
|||||||
|
|
||||||
LiteHtmlViewer::LiteHtmlViewer(QWidget* parent) : QLiteHtmlWidget(parent) {
|
LiteHtmlViewer::LiteHtmlViewer(QWidget* parent) : QLiteHtmlWidget(parent) {
|
||||||
setResourceHandler([this](const QUrl& url) {
|
setResourceHandler([this](const QUrl& url) {
|
||||||
|
emit loadProgress(-1);
|
||||||
return handleResource(url);
|
return handleResource(url);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -30,19 +31,11 @@ void LiteHtmlViewer::bindToBrowser(WebBrowser* browser) {
|
|||||||
connect(this, &LiteHtmlViewer::linkHighlighted, browser, [browser](const QUrl& url) {
|
connect(this, &LiteHtmlViewer::linkHighlighted, browser, [browser](const QUrl& url) {
|
||||||
browser->onLinkHovered(url.toString());
|
browser->onLinkHovered(url.toString());
|
||||||
});
|
});
|
||||||
|
connect(this, &LiteHtmlViewer::titleChanged, browser, &WebBrowser::onTitleChanged);
|
||||||
// TODO: změna ikon, změna stavu akcí.
|
connect(this, &LiteHtmlViewer::urlChanged, browser, &WebBrowser::updateUrl);
|
||||||
|
connect(this, &LiteHtmlViewer::loadStarted, browser, &WebBrowser::onLoadingStarted);
|
||||||
/*
|
connect(this, &LiteHtmlViewer::loadProgress, browser, &WebBrowser::onLoadingProgress);
|
||||||
connect(this, &WebEngineViewer::urlChanged, browser, &WebBrowser::updateUrl);
|
connect(this, &LiteHtmlViewer::loadFinished, browser, &WebBrowser::onLoadingFinished);
|
||||||
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);
|
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void LiteHtmlViewer::findText(const QString& text, bool backwards) {
|
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) {
|
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(),
|
url.toString(),
|
||||||
5000,
|
5000,
|
||||||
{},
|
{},
|
||||||
output,
|
output,
|
||||||
QNetworkAccessManager::Operation::GetOperation);
|
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) {
|
void LiteHtmlViewer::setHtml(const QString& html, const QUrl& base_url) {
|
||||||
QLiteHtmlWidget::setUrl(base_url);
|
QLiteHtmlWidget::setUrl(base_url);
|
||||||
QLiteHtmlWidget::setHtml(html);
|
QLiteHtmlWidget::setHtml(html);
|
||||||
|
|
||||||
|
emit titleChanged(title());
|
||||||
|
emit urlChanged(base_url);
|
||||||
}
|
}
|
||||||
|
|
||||||
QString LiteHtmlViewer::html() const {
|
QString LiteHtmlViewer::html() const {
|
||||||
@ -151,6 +171,7 @@ void LiteHtmlViewer::loadMessages(const QList<Message>& messages, RootItem* root
|
|||||||
}
|
}
|
||||||
|
|
||||||
setHtml(msg_contents, QUrl::fromUserInput(base_url));
|
setHtml(msg_contents, QUrl::fromUserInput(base_url));
|
||||||
|
emit loadFinished(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
double LiteHtmlViewer::verticalScrollBarPosition() const {
|
double LiteHtmlViewer::verticalScrollBarPosition() const {
|
||||||
|
@ -35,6 +35,11 @@ class LiteHtmlViewer : public QLiteHtmlWidget, public WebViewer {
|
|||||||
|
|
||||||
signals:
|
signals:
|
||||||
void zoomFactorChanged();
|
void zoomFactorChanged();
|
||||||
|
void titleChanged(const QString& new_title);
|
||||||
|
void urlChanged(const QUrl& url);
|
||||||
|
void loadStarted();
|
||||||
|
void loadProgress(int progress);
|
||||||
|
void loadFinished(bool success);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void wheelEvent(QWheelEvent* event);
|
virtual void wheelEvent(QWheelEvent* event);
|
||||||
|
@ -270,7 +270,7 @@ void WebBrowser::initializeLayout() {
|
|||||||
m_toolBar->addWidget(m_txtLocation);
|
m_toolBar->addWidget(m_txtLocation);
|
||||||
|
|
||||||
m_loadingProgress = new QProgressBar(this);
|
m_loadingProgress = new QProgressBar(this);
|
||||||
m_loadingProgress->setFixedHeight(5);
|
m_loadingProgress->setFixedHeight(10);
|
||||||
m_loadingProgress->setMinimum(0);
|
m_loadingProgress->setMinimum(0);
|
||||||
m_loadingProgress->setTextVisible(false);
|
m_loadingProgress->setTextVisible(false);
|
||||||
m_loadingProgress->setMaximum(100);
|
m_loadingProgress->setMaximum(100);
|
||||||
@ -295,7 +295,8 @@ void WebBrowser::onLoadingStarted() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void WebBrowser::onLoadingProgress(int progress) {
|
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) {
|
void WebBrowser::onLoadingFinished(bool success) {
|
||||||
|
@ -40,8 +40,8 @@ class WebEngineViewer : public QWebEngineView, public WebViewer {
|
|||||||
virtual QString html() const;
|
virtual QString html() const;
|
||||||
virtual QUrl url() const;
|
virtual QUrl url() const;
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void zoomFactorChanged();
|
void zoomFactorChanged();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual QWebEngineView* createWindow(QWebEnginePage::WebWindowType type);
|
virtual QWebEngineView* createWindow(QWebEnginePage::WebWindowType type);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user