Improve Features

Support downloading files from website directly;
Show DSpinner before webpage loading progress finished.
This commit is contained in:
2020-11-28 04:14:04 +08:00
parent 9c8b2fdd94
commit 4a753259d3
12 changed files with 166 additions and 152 deletions

View File

@@ -1,22 +1,49 @@
#include "webenginepage.h"
#include <QWebEngineSettings>
#include <QDir>
#include <QDebug>
WebEnginePage::WebEnginePage(QObject *parent) : QWebEnginePage(parent)
WebEnginePage::WebEnginePage(QObject *parent)
: QWebEnginePage(parent)
, m_profile(this->profile())
, process(new QProcess)
{
connect(m_profile, &QWebEngineProfile::downloadRequested, this, &WebEnginePage::on_download);
}
QWebEnginePage *WebEnginePage::createWindow(QWebEnginePage::WebWindowType type)
{
Q_UNUSED(type)
WebEnginePage *page = new WebEnginePage();
connect(page, &QWebEnginePage::urlChanged, this, &WebEnginePage::onUrlChanged);
connect(page, &QWebEnginePage::urlChanged, this, &WebEnginePage::on_urlChanged);
return page;
}
void WebEnginePage::onUrlChanged(const QUrl url)
void WebEnginePage::on_urlChanged(const QUrl url)
{
setUrl(url);
sender()->deleteLater();
}
void WebEnginePage::on_download(QWebEngineDownloadItem *item)
{
connect(item, &QWebEngineDownloadItem::downloadProgress, this, &WebEnginePage::on_downloadProgress);
connect(item, &QWebEngineDownloadItem::finished, this, &WebEnginePage::on_downloadFinished);
// 无法指定下载位置,原因未知;默认位置为 ~/Downloads
// item->setPath(QDir::homePath() + "/Downloads/");
item->accept();
process->start(QString("notify-send -a spark-webapp-runtime -t 5000 \"%1\"").arg(tr("Start downloading...")));
}
void WebEnginePage::on_downloadProgress(qint64 bytesReceived, qint64 bytesTotal)
{
qDebug() << "Download Progress:\tbytesReceived: " << bytesReceived << "\tbytesTotal: " << bytesTotal;
}
void WebEnginePage::on_downloadFinished()
{
process->start(QString("notify-send -a spark-webapp-runtime -t 5000 \"%1\"").arg(tr("Download finished!")));
}