summaryrefslogtreecommitdiff
path: root/src/downloadstab.cpp
diff options
context:
space:
mode:
authorisanae <14251494+isanae@users.noreply.github.com>2020-12-28 06:23:44 -0500
committerGitHub <noreply@github.com>2020-12-28 06:23:44 -0500
commit4b059fa71f0d5043bfac8e48757c69b11a6168c6 (patch)
tree1f619884298e51bba99ec26bd41b8f2568119c01 /src/downloadstab.cpp
parent89bbdf22cde8d16d2d5e72999abf97b38ecd7b11 (diff)
parent9b3e91b53e769aec2622eb79509945c09fca8897 (diff)
Merge pull request #1332 from isanae/more-stuff
More stuff
Diffstat (limited to 'src/downloadstab.cpp')
-rw-r--r--src/downloadstab.cpp77
1 files changed, 77 insertions, 0 deletions
diff --git a/src/downloadstab.cpp b/src/downloadstab.cpp
new file mode 100644
index 00000000..a0602ede
--- /dev/null
+++ b/src/downloadstab.cpp
@@ -0,0 +1,77 @@
+#include "downloadstab.h"
+#include "downloadlist.h"
+#include "downloadlistwidget.h"
+#include "organizercore.h"
+#include "ui_mainwindow.h"
+
+DownloadsTab::DownloadsTab(OrganizerCore& core, Ui::MainWindow* mwui)
+ : m_core(core), ui{
+ mwui->btnRefreshDownloads, mwui->downloadView, mwui->showHiddenBox,
+ mwui->downloadFilterEdit}
+{
+ DownloadList *sourceModel = new DownloadList(
+ m_core.downloadManager(), 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.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(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)));
+ connect(ui.list, SIGNAL(cancelDownload(int)), m_core.downloadManager(), SLOT(cancelDownload(int)));
+ connect(ui.list, SIGNAL(pauseDownload(int)), m_core.downloadManager(), SLOT(pauseDownload(int)));
+ connect(ui.list, &DownloadListWidget::resumeDownload, [&](int i){ resumeDownload(i); });
+}
+
+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("DownloadListWidget::item { padding: 4px 2px; }");
+ } else {
+ ui.list->setProperty("downloadView", "standard");
+ ui.list->setStyleSheet("DownloadListWidget::item { padding: 16px 4px; }");
+ }
+
+ ui.list->setMetaDisplay(m_core.settings().interface().metaDownloads());
+ 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::resumeDownload(int downloadIndex)
+{
+ m_core.loggedInAction(ui.list, [this, downloadIndex] {
+ m_core.downloadManager()->resumeDownload(downloadIndex);
+ });
+}