mirror of
https://invent.kde.org/network/falkon.git
synced 2024-11-11 01:22:10 +01:00
Bring back support for downloading files
All files are now automatically downloaded to the specified directory. Due to QtWebEngine API changes, it is not possible to ask user where to save the file.
This commit is contained in:
parent
6da67fc53d
commit
278b725571
|
@ -62,6 +62,7 @@
|
|||
#include <QDir>
|
||||
#include <QWebEngineProfile>
|
||||
#include <QStandardPaths>
|
||||
#include <QWebEngineDownloadItem>
|
||||
|
||||
#if defined(Q_OS_WIN) && !defined(Q_OS_OS2)
|
||||
#include "registerqappassociation.h"
|
||||
|
@ -237,6 +238,9 @@ MainApplication::MainApplication(int &argc, char** argv)
|
|||
setQuitOnLastWindowClosed(true);
|
||||
#endif
|
||||
|
||||
m_webProfile = isPrivate() ? new QWebEngineProfile(this) : QWebEngineProfile::defaultProfile();
|
||||
connect(m_webProfile, &QWebEngineProfile::downloadRequested, this, &MainApplication::downloadRequested);
|
||||
|
||||
QSettings::setDefaultFormat(QSettings::IniFormat);
|
||||
QDesktopServices::setUrlHandler("http", this, "addNewTab");
|
||||
QDesktopServices::setUrlHandler("ftp", this, "addNewTab");
|
||||
|
@ -577,11 +581,8 @@ DesktopNotificationsFactory* MainApplication::desktopNotifications()
|
|||
return m_desktopNotifications;
|
||||
}
|
||||
|
||||
QWebEngineProfile *MainApplication::webProfile()
|
||||
QWebEngineProfile *MainApplication::webProfile() const
|
||||
{
|
||||
if (!m_webProfile) {
|
||||
m_webProfile = m_isPrivate ? new QWebEngineProfile(this) : QWebEngineProfile::defaultProfile();
|
||||
}
|
||||
return m_webProfile;
|
||||
}
|
||||
|
||||
|
@ -836,6 +837,11 @@ void MainApplication::onFocusChanged()
|
|||
}
|
||||
}
|
||||
|
||||
void MainApplication::downloadRequested(QWebEngineDownloadItem *download)
|
||||
{
|
||||
downloadManager()->download(download);
|
||||
}
|
||||
|
||||
void MainApplication::loadSettings()
|
||||
{
|
||||
Settings settings;
|
||||
|
|
|
@ -29,6 +29,7 @@
|
|||
class QMenu;
|
||||
class QWebEngineProfile;
|
||||
class QNetworkAccessManager;
|
||||
class QWebEngineDownloadItem;
|
||||
|
||||
class History;
|
||||
class AutoFill;
|
||||
|
@ -98,7 +99,7 @@ public:
|
|||
SearchEnginesManager* searchEnginesManager();
|
||||
HTML5PermissionsManager* html5PermissionsManager();
|
||||
DesktopNotificationsFactory* desktopNotifications();
|
||||
QWebEngineProfile* webProfile();
|
||||
QWebEngineProfile* webProfile() const;
|
||||
|
||||
static MainApplication* instance();
|
||||
|
||||
|
@ -125,6 +126,8 @@ private slots:
|
|||
void windowDestroyed(QObject* window);
|
||||
void onFocusChanged();
|
||||
|
||||
void downloadRequested(QWebEngineDownloadItem *download);
|
||||
|
||||
private:
|
||||
enum PostLaunchAction {
|
||||
OpenDownloadManager,
|
||||
|
|
|
@ -36,6 +36,8 @@
|
|||
|
||||
#include <QStandardPaths>
|
||||
|
||||
#if QTWEBENGINE_DISABLED
|
||||
|
||||
DownloadFileHelper::DownloadFileHelper(const QString &lastDownloadPath, const QString &downloadPath, bool useNativeDialog)
|
||||
: QObject()
|
||||
, m_lastDownloadOption(DownloadManager::SaveFile)
|
||||
|
@ -324,3 +326,5 @@ DownloadFileHelper::~DownloadFileHelper()
|
|||
{
|
||||
delete m_iconProvider;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
@ -18,6 +18,8 @@
|
|||
#ifndef DOWNLOADFILEHELPER_H
|
||||
#define DOWNLOADFILEHELPER_H
|
||||
|
||||
#if QTWEBENGINE_DISABLED
|
||||
|
||||
#include <QObject>
|
||||
#include <QPixmap>
|
||||
#include <QUrl>
|
||||
|
@ -78,4 +80,6 @@ private:
|
|||
DownloadManager* m_manager;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
#endif // DOWNLOADFILEHELPER_H
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
#include "downloadmanager.h"
|
||||
#include "networkmanager.h"
|
||||
#include "qztools.h"
|
||||
#include "datapaths.h"
|
||||
#include "schemehandlers/ftpschemehandler.h"
|
||||
|
||||
#include <QMenu>
|
||||
|
@ -33,7 +34,9 @@
|
|||
#include <QTimer>
|
||||
#include <QFileInfo>
|
||||
#include <QMessageBox>
|
||||
#include <QFileIconProvider>
|
||||
#include <QDesktopServices>
|
||||
#include <QWebEngineDownloadItem>
|
||||
|
||||
#ifdef Q_OS_WIN
|
||||
#include "Shlwapi.h"
|
||||
|
@ -41,32 +44,24 @@
|
|||
|
||||
//#define DOWNMANAGER_DEBUG
|
||||
|
||||
DownloadItem::DownloadItem(QListWidgetItem* item, QNetworkReply* reply, const QString &path, const QString &fileName, const QPixmap &fileIcon, QTime* timer, bool openAfterFinishedDownload, const QUrl &downloadPage, DownloadManager* manager)
|
||||
DownloadItem::DownloadItem(QListWidgetItem *item, QWebEngineDownloadItem* downloadItem, const QString &path, const QString &fileName, DownloadManager* manager)
|
||||
: QWidget()
|
||||
, ui(new Ui::DownloadItem)
|
||||
, m_item(item)
|
||||
, m_reply(reply)
|
||||
, m_download(downloadItem)
|
||||
, m_ftpDownloader(0)
|
||||
, m_path(path)
|
||||
, m_fileName(fileName)
|
||||
, m_downTimer(timer)
|
||||
, m_downUrl(reply->url())
|
||||
, m_downloadPage(downloadPage)
|
||||
, m_downUrl(downloadItem->url())
|
||||
, m_validIcon(false)
|
||||
, m_downloading(false)
|
||||
, m_openAfterFinish(openAfterFinishedDownload)
|
||||
, m_downloadStopped(false)
|
||||
, m_received(0)
|
||||
, m_total(0)
|
||||
, m_received(downloadItem->receivedBytes())
|
||||
, m_total(downloadItem->totalBytes())
|
||||
{
|
||||
#ifdef DOWNMANAGER_DEBUG
|
||||
qDebug() << __FUNCTION__ << item << reply << path << fileName;
|
||||
#endif
|
||||
QString fullPath = path + fileName;
|
||||
if (QFile::exists(fullPath)) {
|
||||
QFile::remove(fullPath);
|
||||
}
|
||||
|
||||
m_outputFile.setFileName(fullPath);
|
||||
|
||||
ui->setupUi(this);
|
||||
setMaximumWidth(525);
|
||||
|
@ -74,7 +69,6 @@ DownloadItem::DownloadItem(QListWidgetItem* item, QNetworkReply* reply, const QS
|
|||
ui->button->setPixmap(QIcon::fromTheme(QSL("process-stop")).pixmap(20, 20));
|
||||
ui->fileName->setText(m_fileName);
|
||||
ui->downloadInfo->setText(tr("Remaining time unavailable"));
|
||||
ui->fileIcon->setPixmap(fileIcon);
|
||||
|
||||
setContextMenuPolicy(Qt::CustomContextMenu);
|
||||
connect(this, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(customContextMenuRequested(QPoint)));
|
||||
|
@ -84,61 +78,25 @@ DownloadItem::DownloadItem(QListWidgetItem* item, QNetworkReply* reply, const QS
|
|||
startDownloading();
|
||||
}
|
||||
|
||||
void DownloadItem::setTotalSize(qint64 total)
|
||||
{
|
||||
if (total > 0) {
|
||||
m_total = total;
|
||||
}
|
||||
}
|
||||
|
||||
void DownloadItem::startDownloading()
|
||||
{
|
||||
QUrl locationHeader = m_reply->header(QNetworkRequest::LocationHeader).toUrl();
|
||||
|
||||
bool hasFtpUrlInHeader = locationHeader.isValid() && (locationHeader.scheme() == "ftp");
|
||||
if (m_reply->url().scheme() == "ftp" || hasFtpUrlInHeader) {
|
||||
QUrl url = hasFtpUrlInHeader ? locationHeader : m_reply->url();
|
||||
m_reply->abort();
|
||||
m_reply->deleteLater();
|
||||
m_reply = 0;
|
||||
|
||||
startDownloadingFromFtp(url);
|
||||
return;
|
||||
}
|
||||
else if (locationHeader.isValid()) {
|
||||
m_reply->abort();
|
||||
m_reply->deleteLater();
|
||||
|
||||
m_reply = mApp->networkManager()->get(QNetworkRequest(locationHeader));
|
||||
}
|
||||
|
||||
m_reply->setParent(this);
|
||||
connect(m_reply, SIGNAL(finished()), this, SLOT(finished()));
|
||||
connect(m_reply, SIGNAL(readyRead()), this, SLOT(readyRead()));
|
||||
connect(m_reply, SIGNAL(downloadProgress(qint64,qint64)), this, SLOT(downloadProgress(qint64,qint64)));
|
||||
connect(m_reply, SIGNAL(error(QNetworkReply::NetworkError)), this, SLOT(error()));
|
||||
connect(m_reply, SIGNAL(metaDataChanged()), this, SLOT(metaDataChanged()));
|
||||
connect(m_download, &QWebEngineDownloadItem::finished, this, &DownloadItem::finished);
|
||||
connect(m_download, &QWebEngineDownloadItem::downloadProgress, this, &DownloadItem::downloadProgress);
|
||||
|
||||
m_downloading = true;
|
||||
m_timer.start(1000, this);
|
||||
readyRead();
|
||||
QTimer::singleShot(200, this, SLOT(updateDownload()));
|
||||
|
||||
if (m_reply->error() != QNetworkReply::NoError) {
|
||||
stop(false);
|
||||
error();
|
||||
}
|
||||
m_downTimer.start();
|
||||
updateDownloadInfo(0, m_download->receivedBytes(), m_download->totalBytes());
|
||||
}
|
||||
|
||||
void DownloadItem::startDownloadingFromFtp(const QUrl &url)
|
||||
{
|
||||
#if QTWEBENGINE_DISABLED
|
||||
if (!m_outputFile.isOpen() && !m_outputFile.open(QIODevice::WriteOnly)) {
|
||||
stop(false);
|
||||
ui->downloadInfo->setText(tr("Error: Cannot write to file!"));
|
||||
return;
|
||||
}
|
||||
|
||||
#if QTWEBENGINE_DISABLED
|
||||
m_ftpDownloader = new FtpDownloader(this);
|
||||
connect(m_ftpDownloader, SIGNAL(finished()), this, SLOT(finished()));
|
||||
connect(m_ftpDownloader, SIGNAL(dataTransferProgress(qint64,qint64)), this, SLOT(downloadProgress(qint64,qint64)));
|
||||
|
@ -147,7 +105,6 @@ void DownloadItem::startDownloadingFromFtp(const QUrl &url)
|
|||
|
||||
m_ftpDownloader->download(url, &m_outputFile);
|
||||
m_downloading = true;
|
||||
m_timer.start(1000, this);
|
||||
|
||||
QTimer::singleShot(200, this, SLOT(updateDownload()));
|
||||
|
||||
|
@ -157,6 +114,28 @@ void DownloadItem::startDownloadingFromFtp(const QUrl &url)
|
|||
#endif
|
||||
}
|
||||
|
||||
void DownloadItem::updateIcon()
|
||||
{
|
||||
if (m_validIcon)
|
||||
return;
|
||||
|
||||
// Copy the downloaded file to temp dir and get its icon
|
||||
QString tempFile = DataPaths::path(DataPaths::Temp) + QL1S("/download_") + m_fileName;
|
||||
QFile::copy(m_download->path() + QL1S(".download"), tempFile);
|
||||
QFileIconProvider iconProvider;
|
||||
QFileInfo info(tempFile);
|
||||
QIcon fileIcon = iconProvider.icon(info);
|
||||
QFile::remove(tempFile);
|
||||
|
||||
if (!fileIcon.isNull()) {
|
||||
ui->fileIcon->setPixmap(fileIcon.pixmap(30));
|
||||
m_validIcon = true;
|
||||
}
|
||||
else {
|
||||
ui->fileIcon->setPixmap(style()->standardIcon(QStyle::SP_FileIcon).pixmap(30));
|
||||
}
|
||||
}
|
||||
|
||||
void DownloadItem::parentResized(const QSize &size)
|
||||
{
|
||||
if (size.width() < 200) {
|
||||
|
@ -165,48 +144,42 @@ void DownloadItem::parentResized(const QSize &size)
|
|||
setMaximumWidth(size.width());
|
||||
}
|
||||
|
||||
void DownloadItem::metaDataChanged()
|
||||
{
|
||||
QUrl locationHeader = m_reply->header(QNetworkRequest::LocationHeader).toUrl();
|
||||
if (locationHeader.isValid()) {
|
||||
m_reply->close();
|
||||
m_reply->deleteLater();
|
||||
|
||||
m_reply = mApp->networkManager()->get(QNetworkRequest(locationHeader));
|
||||
startDownloading();
|
||||
}
|
||||
}
|
||||
|
||||
void DownloadItem::finished()
|
||||
{
|
||||
#ifdef DOWNMANAGER_DEBUG
|
||||
qDebug() << __FUNCTION__ << m_reply;
|
||||
#endif
|
||||
m_timer.stop();
|
||||
|
||||
QString host = m_reply->url().host();
|
||||
ui->downloadInfo->setText(tr("Done - %1 (%2)").arg(host, QDateTime::currentDateTime().toString(Qt::DefaultLocaleShortDate)));
|
||||
QString host = m_download->url().host();
|
||||
|
||||
switch (m_download->state()) {
|
||||
case QWebEngineDownloadItem::DownloadCompleted:
|
||||
ui->downloadInfo->setText(tr("Done - %1 (%2)").arg(host, QDateTime::currentDateTime().toString(Qt::DefaultLocaleShortDate)));
|
||||
break;
|
||||
|
||||
case QWebEngineDownloadItem::DownloadInterrupted:
|
||||
ui->downloadInfo->setText(tr("Error - %1").arg(host));
|
||||
break;
|
||||
|
||||
case QWebEngineDownloadItem::DownloadCancelled:
|
||||
ui->downloadInfo->setText(tr("Cancelled - %1").arg(host));
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
ui->progressBar->hide();
|
||||
ui->button->hide();
|
||||
ui->frame->hide();
|
||||
m_outputFile.close();
|
||||
|
||||
if (m_reply) {
|
||||
m_reply->deleteLater();
|
||||
}
|
||||
else {
|
||||
#if QTWEBENGINE_DISABLED
|
||||
m_ftpDownloader->deleteLater();
|
||||
#endif
|
||||
}
|
||||
|
||||
m_item->setSizeHint(sizeHint());
|
||||
m_downloading = false;
|
||||
|
||||
if (m_openAfterFinish) {
|
||||
openFile();
|
||||
}
|
||||
|
||||
emit downloadFinished(true);
|
||||
}
|
||||
|
||||
|
@ -223,19 +196,11 @@ void DownloadItem::downloadProgress(qint64 received, qint64 total)
|
|||
}
|
||||
ui->progressBar->setValue(currentValue);
|
||||
ui->progressBar->setMaximum(totalValue);
|
||||
m_currSpeed = received * 1000.0 / m_downTimer->elapsed();
|
||||
m_currSpeed = received * 1000.0 / m_downTimer.elapsed();
|
||||
m_received = received;
|
||||
m_total = total;
|
||||
}
|
||||
|
||||
void DownloadItem::timerEvent(QTimerEvent* event)
|
||||
{
|
||||
if (event->timerId() == m_timer.timerId()) {
|
||||
updateDownloadInfo(m_currSpeed, m_received, m_total);
|
||||
}
|
||||
else {
|
||||
QWidget::timerEvent(event);
|
||||
}
|
||||
updateDownloadInfo(m_currSpeed, m_received, m_total);
|
||||
}
|
||||
|
||||
int DownloadItem::progress()
|
||||
|
@ -311,9 +276,11 @@ void DownloadItem::updateDownloadInfo(double currSpeed, qint64 received, qint64
|
|||
else {
|
||||
ui->downloadInfo->setText(tr("Remaining %1 - %2 of %3 (%4)").arg(remTime, currSize, fileSize, speed));
|
||||
}
|
||||
|
||||
updateIcon();
|
||||
}
|
||||
|
||||
void DownloadItem::stop(bool askForDeleteFile)
|
||||
void DownloadItem::stop()
|
||||
{
|
||||
#ifdef DOWNMANAGER_DEBUG
|
||||
qDebug() << __FUNCTION__;
|
||||
|
@ -322,43 +289,19 @@ void DownloadItem::stop(bool askForDeleteFile)
|
|||
return;
|
||||
}
|
||||
m_downloadStopped = true;
|
||||
QString host;
|
||||
if (m_reply) {
|
||||
host = m_reply->url().host();
|
||||
}
|
||||
else if (m_ftpDownloader) {
|
||||
#if QTWEBENGINE_DISABLED
|
||||
host = m_ftpDownloader->url().host();
|
||||
host = m_ftpDownloader->url().host();
|
||||
m_ftpDownloader->abort();
|
||||
m_ftpDownloader->close();
|
||||
#endif
|
||||
}
|
||||
m_openAfterFinish = false;
|
||||
m_timer.stop();
|
||||
if (m_reply) {
|
||||
m_reply->abort();
|
||||
}
|
||||
else if (m_ftpDownloader) {
|
||||
#if QTWEBENGINE_DISABLED
|
||||
m_ftpDownloader->abort();
|
||||
m_ftpDownloader->close();
|
||||
#endif
|
||||
}
|
||||
QString outputfile = QFileInfo(m_outputFile).absoluteFilePath();
|
||||
m_outputFile.close();
|
||||
ui->downloadInfo->setText(tr("Cancelled - %1").arg(host));
|
||||
ui->progressBar->hide();
|
||||
ui->button->hide();
|
||||
m_item->setSizeHint(sizeHint());
|
||||
|
||||
ui->downloadInfo->setText(tr("Cancelled - %1").arg(m_download->url().host()));
|
||||
m_download->cancel();
|
||||
m_downloading = false;
|
||||
|
||||
emit downloadFinished(false);
|
||||
|
||||
if (askForDeleteFile) {
|
||||
QMessageBox::StandardButton button = QMessageBox::question(m_item->listWidget()->parentWidget(), tr("Delete file"), tr("Do you want to also delete dowloaded file?"), QMessageBox::Yes | QMessageBox::No);
|
||||
if (button == QMessageBox::Yes) {
|
||||
QFile::remove(outputfile);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void DownloadItem::mouseDoubleClickEvent(QMouseEvent* e)
|
||||
|
@ -374,7 +317,7 @@ void DownloadItem::customContextMenuRequested(const QPoint &pos)
|
|||
|
||||
menu.addAction(tr("Open Folder"), this, SLOT(openFolder()));
|
||||
menu.addSeparator();
|
||||
menu.addAction(tr("Go to Download Page"), this, SLOT(goToDownloadPage()))->setEnabled(!m_downloadPage.isEmpty());
|
||||
//menu.addAction(tr("Go to Download Page"), this, SLOT(goToDownloadPage()))->setEnabled(!m_downloadPage.isEmpty());
|
||||
menu.addAction(QIcon::fromTheme("edit-copy"), tr("Copy Download Link"), this, SLOT(copyDownloadLink()));
|
||||
menu.addSeparator();
|
||||
menu.addAction(QIcon::fromTheme("process-stop"), tr("Cancel downloading"), this, SLOT(stop()))->setEnabled(m_downloading);
|
||||
|
@ -388,6 +331,7 @@ void DownloadItem::customContextMenuRequested(const QPoint &pos)
|
|||
|
||||
void DownloadItem::goToDownloadPage()
|
||||
{
|
||||
#if QTWEBENGINE_DISABLED
|
||||
BrowserWindow* qz = mApp->getWindow();
|
||||
|
||||
if (qz) {
|
||||
|
@ -396,6 +340,7 @@ void DownloadItem::goToDownloadPage()
|
|||
else {
|
||||
mApp->createWindow(Qz::BW_NewWindow, m_downloadPage);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void DownloadItem::copyDownloadLink()
|
||||
|
@ -413,7 +358,7 @@ void DownloadItem::openFile()
|
|||
if (m_downloading) {
|
||||
return;
|
||||
}
|
||||
QFileInfo info(m_path + m_fileName);
|
||||
QFileInfo info(m_path, m_fileName);
|
||||
if (info.exists()) {
|
||||
QDesktopServices::openUrl(QUrl::fromLocalFile(info.absoluteFilePath()));
|
||||
}
|
||||
|
@ -425,7 +370,7 @@ void DownloadItem::openFile()
|
|||
void DownloadItem::openFolder()
|
||||
{
|
||||
#ifdef Q_OS_WIN
|
||||
QString winFileName = m_path + m_fileName;
|
||||
QString winFileName = QSL("%1/%2").arg(m_path, m_fileName);
|
||||
winFileName.replace(QLatin1Char('/'), "\\");
|
||||
QString shExArg = "/e,/select,\"" + winFileName + "\"";
|
||||
ShellExecute(NULL, NULL, TEXT("explorer.exe"), shExArg.toStdWString().c_str(), NULL, SW_SHOW);
|
||||
|
@ -434,63 +379,8 @@ void DownloadItem::openFolder()
|
|||
#endif
|
||||
}
|
||||
|
||||
void DownloadItem::readyRead()
|
||||
{
|
||||
#ifdef DOWNMANAGER_DEBUG
|
||||
qDebug() << __FUNCTION__ ;
|
||||
#endif
|
||||
if (!m_outputFile.isOpen() && !m_outputFile.open(QIODevice::WriteOnly)) {
|
||||
stop(false);
|
||||
ui->downloadInfo->setText(tr("Error: Cannot write to file!"));
|
||||
return;
|
||||
}
|
||||
m_outputFile.write(m_reply->readAll());
|
||||
}
|
||||
|
||||
void DownloadItem::error()
|
||||
{
|
||||
#ifdef DOWNMANAGER_DEBUG
|
||||
qDebug() << __FUNCTION__ << (m_reply ? m_reply->error() : m_ftpDownloader->error());
|
||||
#endif
|
||||
if (m_reply && m_reply->error() != QNetworkReply::NoError) {
|
||||
ui->downloadInfo->setText(tr("Error: ") + m_reply->errorString());
|
||||
}
|
||||
#if QTWEBENGINE_DISABLED
|
||||
else if (m_ftpDownloader && m_ftpDownloader->error() != QFtp::NoError) {
|
||||
stop(false);
|
||||
ui->downloadInfo->setText(tr("Error: ") + m_ftpDownloader->errorString());
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void DownloadItem::updateDownload()
|
||||
{
|
||||
#ifdef DOWNMANAGER_DEBUG
|
||||
qDebug() << __FUNCTION__ ;
|
||||
#endif
|
||||
// after caling stop() (from readyRead()) m_reply will be a dangling pointer,
|
||||
// thus it should be checked after m_outputFile.isOpen()
|
||||
#if QTWEBENGINE_DISABLED
|
||||
if (ui->progressBar->maximum() == 0 && m_outputFile.isOpen() &&
|
||||
((m_reply && m_reply->isFinished()) ||
|
||||
(m_ftpDownloader && m_ftpDownloader->isFinished())
|
||||
)
|
||||
) {
|
||||
downloadProgress(0, 0);
|
||||
finished();
|
||||
}
|
||||
#else
|
||||
if (ui->progressBar->maximum() == 0 && m_outputFile.isOpen() &&
|
||||
((m_reply && m_reply->isFinished()))) {
|
||||
downloadProgress(0, 0);
|
||||
finished();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
DownloadItem::~DownloadItem()
|
||||
{
|
||||
delete ui;
|
||||
delete m_item;
|
||||
delete m_downTimer;
|
||||
}
|
||||
|
|
|
@ -33,6 +33,7 @@ class DownloadItem;
|
|||
}
|
||||
|
||||
class QListWidgetItem;
|
||||
class QWebEngineDownloadItem;
|
||||
|
||||
class DownloadManager;
|
||||
class FtpDownloader;
|
||||
|
@ -42,7 +43,7 @@ class QUPZILLA_EXPORT DownloadItem : public QWidget
|
|||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit DownloadItem(QListWidgetItem* item, QNetworkReply* reply, const QString &path, const QString &fileName, const QPixmap &fileIcon, QTime* timer, bool openAfterFinishedDownload, const QUrl &downloadPage, DownloadManager* manager);
|
||||
explicit DownloadItem(QListWidgetItem* item, QWebEngineDownloadItem* downloadItem, const QString &path, const QString &fileName, DownloadManager* manager);
|
||||
bool isDownloading() { return m_downloading; }
|
||||
bool isCancelled();
|
||||
QTime remainingTime() { return m_remTime; }
|
||||
|
@ -50,8 +51,6 @@ public:
|
|||
int progress();
|
||||
~DownloadItem();
|
||||
|
||||
void setTotalSize(qint64 total);
|
||||
|
||||
static QString remaingTimeToString(QTime time);
|
||||
static QString currentSpeedToString(double speed);
|
||||
|
||||
|
@ -62,14 +61,10 @@ signals:
|
|||
private slots:
|
||||
void parentResized(const QSize &size);
|
||||
void finished();
|
||||
void metaDataChanged();
|
||||
void downloadProgress(qint64 received, qint64 total);
|
||||
void stop(bool askForDeleteFile = true);
|
||||
void stop();
|
||||
void openFile();
|
||||
void openFolder();
|
||||
void readyRead();
|
||||
void error();
|
||||
void updateDownload();
|
||||
void customContextMenuRequested(const QPoint &pos);
|
||||
void clear();
|
||||
|
||||
|
@ -80,25 +75,24 @@ private:
|
|||
void startDownloading();
|
||||
void startDownloadingFromFtp(const QUrl &url);
|
||||
|
||||
void timerEvent(QTimerEvent* event);
|
||||
void updateIcon();
|
||||
void updateDownloadInfo(double currSpeed, qint64 received, qint64 total);
|
||||
void mouseDoubleClickEvent(QMouseEvent* e);
|
||||
|
||||
Ui::DownloadItem* ui;
|
||||
|
||||
QListWidgetItem* m_item;
|
||||
QNetworkReply* m_reply;
|
||||
QWebEngineDownloadItem* m_download;
|
||||
FtpDownloader* m_ftpDownloader;
|
||||
QString m_path;
|
||||
QString m_fileName;
|
||||
QTime* m_downTimer;
|
||||
QTime m_downTimer;
|
||||
QTime m_remTime;
|
||||
QBasicTimer m_timer;
|
||||
QFile m_outputFile;
|
||||
QUrl m_downUrl;
|
||||
QUrl m_downloadPage;
|
||||
bool m_validIcon;
|
||||
|
||||
bool m_downloading;
|
||||
bool m_openAfterFinish;
|
||||
bool m_downloadStopped;
|
||||
double m_currSpeed;
|
||||
qint64 m_received;
|
||||
|
|
|
@ -27,6 +27,7 @@
|
|||
#include "desktopnotificationsfactory.h"
|
||||
#include "qztools.h"
|
||||
#include "webpage.h"
|
||||
#include "webview.h"
|
||||
#include "downloadfilehelper.h"
|
||||
#include "settings.h"
|
||||
|
||||
|
@ -34,6 +35,9 @@
|
|||
#include <QCloseEvent>
|
||||
#include <QDir>
|
||||
#include <QShortcut>
|
||||
#include <QStandardPaths>
|
||||
#include <QWebEngineHistory>
|
||||
#include <QWebEngineDownloadItem>
|
||||
|
||||
DownloadManager::DownloadManager(QWidget* parent)
|
||||
: QWidget(parent)
|
||||
|
@ -86,6 +90,10 @@ void DownloadManager::loadSettings()
|
|||
if (!m_externalArguments.contains(QLatin1String("%d"))) {
|
||||
m_externalArguments.append(QLatin1String(" %d"));
|
||||
}
|
||||
|
||||
if (m_downloadPath.isEmpty()) {
|
||||
m_downloadPath = QStandardPaths::writableLocation(QStandardPaths::DownloadLocation);
|
||||
}
|
||||
}
|
||||
|
||||
void DownloadManager::show()
|
||||
|
@ -206,54 +214,41 @@ void DownloadManager::clearList()
|
|||
qDeleteAll(items);
|
||||
}
|
||||
|
||||
void DownloadManager::download(const QNetworkRequest &request, const DownloadInfo &info)
|
||||
void DownloadManager::download(QWebEngineDownloadItem *downloadItem)
|
||||
{
|
||||
if (!info.page) {
|
||||
if (m_useExternalManager) {
|
||||
startExternalManager(downloadItem->url());
|
||||
downloadItem->cancel();
|
||||
return;
|
||||
}
|
||||
|
||||
// Clearing web page info from request
|
||||
QNetworkRequest req = request;
|
||||
req.setAttribute((QNetworkRequest::Attribute)(QNetworkRequest::User + 100), 0);
|
||||
|
||||
#if QTWEBENGINE_DISABLED
|
||||
handleUnsupportedContent(m_networkManager->get(req), info);
|
||||
#endif
|
||||
}
|
||||
|
||||
#if QTWEBENGINE_DISABLED
|
||||
void DownloadManager::handleUnsupportedContent(QNetworkReply* reply, const DownloadInfo &info)
|
||||
{
|
||||
if (!info.page || reply->url().scheme() == QLatin1String("qupzilla")) {
|
||||
return;
|
||||
// Get download page
|
||||
QUrl downloadPage;
|
||||
WebView* view = qobject_cast<WebView*>(info.page->view());
|
||||
if (!info.page->url().isEmpty()) {
|
||||
downloadPage = info.page->url();
|
||||
}
|
||||
else if (info.page->history()->canGoBack()) {
|
||||
downloadPage = info.page->history()->backItem().url();
|
||||
}
|
||||
// Close empty tab
|
||||
else if (view && info.page->history()->count() == 0) {
|
||||
view->closeView();
|
||||
}
|
||||
|
||||
// if (fromPageDownload && m_useExternalManager) {
|
||||
// startExternalManager(reply->url());
|
||||
// reply->abort();
|
||||
// reply->deleteLater();
|
||||
// return;
|
||||
// }
|
||||
|
||||
reply->setProperty("downReply", QVariant(true));
|
||||
|
||||
DownloadFileHelper* h = new DownloadFileHelper(m_lastDownloadPath, m_downloadPath, m_useNativeDialog);
|
||||
connect(h, SIGNAL(itemCreated(QListWidgetItem*,DownloadItem*)), this, SLOT(itemCreated(QListWidgetItem*,DownloadItem*)));
|
||||
|
||||
h->setLastDownloadOption(m_lastDownloadOption);
|
||||
h->setDownloadManager(this);
|
||||
h->setListWidget(ui->list);
|
||||
h->handleUnsupportedContent(reply, info);
|
||||
}
|
||||
#endif
|
||||
|
||||
void DownloadManager::itemCreated(QListWidgetItem* item, DownloadItem* downItem)
|
||||
{
|
||||
connect(downItem, SIGNAL(deleteItem(DownloadItem*)), this, SLOT(deleteItem(DownloadItem*)));
|
||||
connect(downItem, SIGNAL(downloadFinished(bool)), this, SLOT(downloadFinished(bool)));
|
||||
QString fileName = QFileInfo(downloadItem->path()).fileName();
|
||||
|
||||
ui->list->setItemWidget(item, downItem);
|
||||
item->setSizeHint(downItem->sizeHint());
|
||||
// Set download path and accept
|
||||
downloadItem->setPath(QzTools::ensureUniqueFilename(QSL("%1/%2").arg(m_downloadPath, fileName)));
|
||||
downloadItem->accept();
|
||||
|
||||
// Create download item
|
||||
QListWidgetItem* listItem = new QListWidgetItem(ui->list);
|
||||
DownloadItem* downItem = new DownloadItem(listItem, downloadItem, m_downloadPath, fileName, this);
|
||||
ui->list->setItemWidget(listItem, downItem);
|
||||
listItem->setSizeHint(downItem->sizeHint());
|
||||
downItem->show();
|
||||
|
||||
show();
|
||||
|
|
|
@ -28,11 +28,12 @@ namespace Ui
|
|||
class DownloadManager;
|
||||
}
|
||||
|
||||
class QUrl;
|
||||
class QNetworkReply;
|
||||
class QNetworkRequest;
|
||||
class QNetworkAccessManager;
|
||||
class QListWidgetItem;
|
||||
class QUrl;
|
||||
class QWebEngineDownloadItem;
|
||||
|
||||
class DownloadItem;
|
||||
class EcWin7;
|
||||
|
@ -64,11 +65,7 @@ public:
|
|||
|
||||
void loadSettings();
|
||||
|
||||
void download(const QNetworkRequest &request, const DownloadInfo &info);
|
||||
|
||||
#if QTWEBENGINE_DISABLED
|
||||
void handleUnsupportedContent(QNetworkReply* reply, const DownloadInfo &info);
|
||||
#endif
|
||||
void download(QWebEngineDownloadItem *downloadItem);
|
||||
|
||||
bool canClose();
|
||||
|
||||
|
@ -89,8 +86,6 @@ protected:
|
|||
private slots:
|
||||
void clearList();
|
||||
void deleteItem(DownloadItem* item);
|
||||
|
||||
void itemCreated(QListWidgetItem* item, DownloadItem* downItem);
|
||||
void downloadFinished(bool success);
|
||||
|
||||
signals:
|
||||
|
|
|
@ -99,7 +99,6 @@ WebPage::WebPage(QObject* parent)
|
|||
connect(this, SIGNAL(loadProgress(int)), this, SLOT(progress(int)));
|
||||
connect(this, SIGNAL(loadFinished(bool)), this, SLOT(finished()));
|
||||
connect(this, SIGNAL(printRequested(QWebFrame*)), this, SLOT(printFrame(QWebFrame*)));
|
||||
connect(this, SIGNAL(downloadRequested(QNetworkRequest)), this, SLOT(downloadRequested(QNetworkRequest)));
|
||||
|
||||
frameCreated(mainFrame());
|
||||
connect(this, SIGNAL(frameCreated(QWebFrame*)), this, SLOT(frameCreated(QWebFrame*)));
|
||||
|
@ -463,12 +462,6 @@ void WebPage::desktopServicesOpen(const QUrl &url)
|
|||
}
|
||||
}
|
||||
|
||||
void WebPage::downloadRequested(const QNetworkRequest &request)
|
||||
{
|
||||
DownloadManager* dManager = mApp->downloadManager();
|
||||
dManager->download(request, this);
|
||||
}
|
||||
|
||||
void WebPage::windowCloseRequested()
|
||||
{
|
||||
WebView* webView = qobject_cast<WebView*>(view());
|
||||
|
|
|
@ -25,8 +25,8 @@
|
|||
#include "qzcommon.h"
|
||||
#include "passwordmanager.h"
|
||||
|
||||
class QWebSecurityOrigin;
|
||||
class QEventLoop;
|
||||
class QWebEngineDownloadItem;
|
||||
|
||||
class BrowserWindow;
|
||||
class AdBlockRule;
|
||||
|
@ -100,7 +100,6 @@ private slots:
|
|||
void addJavaScriptObject();
|
||||
|
||||
void watchedFileChanged(const QString &file);
|
||||
void downloadRequested(const QNetworkRequest &request);
|
||||
void windowCloseRequested();
|
||||
void authentication(const QUrl &requestUrl, QAuthenticator* auth);
|
||||
void proxyAuthentication(const QUrl &requestUrl, QAuthenticator* auth, const QString &proxyHost);
|
||||
|
|
|
@ -564,6 +564,7 @@ void WebView::copyLinkToClipboard()
|
|||
|
||||
void WebView::savePageAs()
|
||||
{
|
||||
#if QTWEBENGINE_DISABLED
|
||||
if (url().isEmpty() || url().toString() == QLatin1String("about:blank")) {
|
||||
return;
|
||||
}
|
||||
|
@ -582,6 +583,7 @@ void WebView::savePageAs()
|
|||
|
||||
DownloadManager* dManager = mApp->downloadManager();
|
||||
dManager->download(request, info);
|
||||
#endif
|
||||
}
|
||||
|
||||
void WebView::openUrlInNewTab(const QUrl &url, Qz::NewTabPositionFlags position)
|
||||
|
@ -594,6 +596,7 @@ void WebView::openUrlInNewTab(const QUrl &url, Qz::NewTabPositionFlags position)
|
|||
|
||||
void WebView::downloadUrlToDisk()
|
||||
{
|
||||
#if QTWEBENGINE_DISABLED
|
||||
if (QAction* action = qobject_cast<QAction*>(sender())) {
|
||||
QNetworkRequest request(action->data().toUrl());
|
||||
|
||||
|
@ -606,6 +609,7 @@ void WebView::downloadUrlToDisk()
|
|||
DownloadManager* dManager = mApp->downloadManager();
|
||||
dManager->download(request, info);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void WebView::copyImageToClipboard()
|
||||
|
|
Loading…
Reference in New Issue
Block a user