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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
|
#include "downloadstab.h"
#include "downloadlist.h"
#include "downloadlistview.h"
#include "organizercore.h"
#include "ui_mainwindow.h"
DownloadsTab::DownloadsTab(OrganizerCore& core, Ui::MainWindow* mwui)
: m_core(core),
ui{mwui->btnRefreshDownloads, mwui->btnQueryDownloadsInfo, mwui->downloadView,
mwui->showHiddenBox, mwui->downloadFilterEdit}
{
DownloadList* sourceModel = new DownloadList(m_core, ui.list);
ui.list->setModel(sourceModel);
ui.list->setManager(m_core.downloadManager());
ui.list->setItemDelegate(
new DownloadProgressDelegate(m_core.downloadManager(), ui.list));
update();
m_filter.setEdit(ui.filter);
m_filter.setList(ui.list);
m_filter.setSortPredicate([sourceModel](auto&& left, auto&& right) {
return sourceModel->lessThanPredicate(left, right);
});
connect(ui.refresh, &QPushButton::clicked, [&] {
refresh();
});
connect(ui.queryInfos, &QPushButton::clicked, [&] {
queryInfos();
});
connect(ui.list, SIGNAL(installDownload(int)), &m_core, SLOT(installDownload(int)));
connect(ui.list, SIGNAL(queryInfo(int)), m_core.downloadManager(),
SLOT(queryInfo(int)));
connect(ui.list, SIGNAL(queryInfoMd5(int)), m_core.downloadManager(),
SLOT(queryInfoMd5(int)));
connect(ui.list, SIGNAL(visitOnNexus(int)), m_core.downloadManager(),
SLOT(visitOnNexus(int)));
connect(ui.list, SIGNAL(visitUploaderProfile(int)), m_core.downloadManager(),
SLOT(visitUploaderProfile(int)));
connect(ui.list, SIGNAL(openFile(int)), m_core.downloadManager(),
SLOT(openFile(int)));
connect(ui.list, SIGNAL(openMetaFile(int)), m_core.downloadManager(),
SLOT(openMetaFile(int)));
connect(ui.list, SIGNAL(openInDownloadsFolder(int)), m_core.downloadManager(),
SLOT(openInDownloadsFolder(int)));
connect(ui.list, SIGNAL(removeDownload(int, bool)), m_core.downloadManager(),
SLOT(removeDownload(int, bool)));
connect(ui.list, SIGNAL(restoreDownload(int)), m_core.downloadManager(),
SLOT(restoreDownload(int)));
// The view reports actions by row; translate to DownloadID at the boundary.
connect(ui.list, &DownloadListView::cancelDownload, this, [this](int row) {
auto* dm = m_core.downloadManager();
dm->cancelDownload(dm->downloadIDAtRow(row));
});
connect(ui.list, &DownloadListView::pauseDownload, this, [this](int row) {
auto* dm = m_core.downloadManager();
dm->pauseDownload(dm->downloadIDAtRow(row));
});
connect(ui.list, &DownloadListView::resumeDownload, this, [this](int row) {
resumeDownload(row);
});
}
void DownloadsTab::update()
{
// this means downloadTab initialization hasn't happened yet
if (ui.list->model() == nullptr) {
return;
}
// set the view attribute and default row sizes
if (m_core.settings().interface().compactDownloads()) {
ui.list->setProperty("downloadView", "compact");
ui.list->setStyleSheet("DownloadListView::item { padding: 4px 2px; }");
} else {
ui.list->setProperty("downloadView", "standard");
ui.list->setStyleSheet("DownloadListView::item { padding: 16px 4px; }");
}
ui.list->style()->unpolish(ui.list);
ui.list->style()->polish(ui.list);
qobject_cast<DownloadListHeader*>(ui.list->header())->customResizeSections();
m_core.downloadManager()->refreshList();
}
void DownloadsTab::refresh()
{
m_core.downloadManager()->refreshList();
}
void DownloadsTab::queryInfos()
{
if (m_core.settings().network().offlineMode()) {
if (QMessageBox::warning(nullptr, tr("Query Metadata"),
tr("Cannot query metadata while offline mode is enabled. "
"Do you want to disable offline mode?"),
QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes) {
m_core.settings().network().setOfflineMode(false);
} else {
return;
}
}
m_core.downloadManager()->queryDownloadListInfo();
}
void DownloadsTab::resumeDownload(int downloadIndex)
{
m_core.loggedInAction(ui.list, [this, downloadIndex] {
auto* dm = m_core.downloadManager();
dm->resumeDownload(dm->downloadIDAtRow(downloadIndex));
});
}
|