Improve Features

Support run in Fullscreen mode;
Suppport "save as" when downloading files.
This commit is contained in:
2020-11-29 02:59:26 +08:00
parent 4a753259d3
commit 4b3cc4276d
9 changed files with 234 additions and 67 deletions

View File

@@ -3,18 +3,19 @@
#include <QDir>
#include <QDebug>
#include <DMessageManager>
DWIDGET_USE_NAMESPACE
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();
WebEnginePage *page = new WebEnginePage;
connect(page, &QWebEnginePage::urlChanged, this, &WebEnginePage::on_urlChanged);
return page;
}
@@ -24,26 +25,3 @@ 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!")));
}