blob: 2d752879856d0f81f0a7c21a4ad93311955c0003 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
|
#include "downloadmanagerwidget.h"
#include "downloadwidget.h"
#include <QFileDialog>
#include <QStandardPaths>
#include <QWebEngineDownloadItem>
DownloadManagerWidget::DownloadManagerWidget(QWidget *parent)
: QWidget(parent), m_numDownloads(0) {
setupUi(this);
}
void DownloadManagerWidget::downloadRequested(
QWebEngineDownloadItem *download) {
Q_ASSERT(download &&
download->state() == QWebEngineDownloadItem::DownloadRequested);
QString path =
settings
.value("defaultDownloadLocation",
QStandardPaths::writableLocation(
QStandardPaths::DownloadLocation) +
QDir::separator() + QApplication::applicationName())
.toString();
QDir d;
d.mkpath(path);
download->setDownloadFileName(path + QDir::separator() +
download->downloadFileName());
download->accept();
add(new DownloadWidget(download));
show();
}
void DownloadManagerWidget::add(DownloadWidget *downloadWidget) {
connect(downloadWidget, &DownloadWidget::removeClicked, this,
&DownloadManagerWidget::remove);
m_itemsLayout->insertWidget(0, downloadWidget, 0, Qt::AlignTop);
if (m_numDownloads++ == 0)
m_zeroItemsLabel->hide();
}
void DownloadManagerWidget::remove(DownloadWidget *downloadWidget) {
m_itemsLayout->removeWidget(downloadWidget);
downloadWidget->deleteLater();
if (--m_numDownloads == 0)
m_zeroItemsLabel->show();
}
void DownloadManagerWidget::on_open_download_dir_clicked() {
utils::desktopOpenUrl(settings
.value("defaultDownloadLocation",
QStandardPaths::writableLocation(
QStandardPaths::DownloadLocation) +
QDir::separator() +
QApplication::applicationName())
.toString());
}
|