diff options
| -rw-r--r-- | src/CMakeLists.txt | 1 | ||||
| -rw-r--r-- | src/datatab.h | 5 | ||||
| -rw-r--r-- | src/downloadstab.cpp | 88 | ||||
| -rw-r--r-- | src/downloadstab.h | 34 | ||||
| -rw-r--r-- | src/mainwindow.cpp | 94 | ||||
| -rw-r--r-- | src/mainwindow.h | 8 |
6 files changed, 143 insertions, 87 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 117528f8..fdbe8e38 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -99,6 +99,7 @@ add_filter(NAME src/loot GROUPS add_filter(NAME src/mainwindow GROUPS datatab + downloadstab iconfetcher filetree filetreeitem diff --git a/src/datatab.h b/src/datatab.h index a0f29a5f..32d788f6 100644 --- a/src/datatab.h +++ b/src/datatab.h @@ -1,3 +1,6 @@ +#ifndef MODORGANIZER_DATATAB_INCLUDED +#define MODORGANIZER_DATATAB_INCLUDED + #include "modinfodialogfwd.h" #include "modinfo.h" #include <filterwidget.h> @@ -58,3 +61,5 @@ private: void updateOptions(); void ensureFullyLoaded(); }; + +#endif // MODORGANIZER_DATATAB_INCLUDED diff --git a/src/downloadstab.cpp b/src/downloadstab.cpp new file mode 100644 index 00000000..a1a5a474 --- /dev/null +++ b/src/downloadstab.cpp @@ -0,0 +1,88 @@ +#include "downloadstab.h" +#include "downloadlist.h" +#include "downloadlistsortproxy.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); + + DownloadListSortProxy *sortProxy = new DownloadListSortProxy( + m_core.downloadManager(), ui.list); + + sortProxy->setSourceModel(sourceModel); + connect(ui.filter, SIGNAL(textChanged(QString)), sortProxy, SLOT(updateFilter(QString))); + connect(ui.filter, SIGNAL(textChanged(QString)), this, SLOT(downloadFilterChanged(QString))); + + ui.list->setSourceModel(sourceModel); + ui.list->setModel(sortProxy); + ui.list->setManager(m_core.downloadManager()); + ui.list->setItemDelegate(new DownloadProgressDelegate( + m_core.downloadManager(), sortProxy, ui.list)); + update(); + + 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, SIGNAL(resumeDownload(int)), this, SLOT(resumeDownload(int))); +} + +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); + }); +} + +void DownloadsTab::downloadFilterChanged(const QString &filter) +{ + if (!filter.isEmpty()) { + ui.list->setStyleSheet("QTreeView { border: 2px ridge #f00; }"); + } else { + ui.list->setStyleSheet(""); + } +} diff --git a/src/downloadstab.h b/src/downloadstab.h new file mode 100644 index 00000000..3ccdf5f4 --- /dev/null +++ b/src/downloadstab.h @@ -0,0 +1,34 @@ +#ifndef MODORGANIZER_DOWNLOADTAB_INCLUDED +#define MODORGANIZER_DOWNLOADTAB_INCLUDED + +namespace Ui { class MainWindow; } +class OrganizerCore; +class DownloadListWidget; + +class DownloadsTab : public QObject +{ + Q_OBJECT; + +public: + DownloadsTab(OrganizerCore& core, Ui::MainWindow* ui); + + void update(); + +private: + struct DownloadsTabUi + { + QPushButton* refresh; + DownloadListWidget* list; + QCheckBox* showHidden; + QLineEdit* filter; + }; + + OrganizerCore& m_core; + DownloadsTabUi ui; + + void refresh(); + void downloadFilterChanged(const QString &filter); + void resumeDownload(int downloadIndex); +}; + +#endif // MODORGANIZER_DOWNLOADTAB_INCLUDED diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 8d9857c1..8777c4ac 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -76,6 +76,7 @@ along with Mod Organizer. If not, see <http://www.gnu.org/licenses/>. #include "statusbar.h" #include "filterlist.h" #include "datatab.h" +#include "downloadstab.h" #include "instancemanagerdialog.h" #include <utility.h> #include <dataarchives.h> @@ -347,11 +348,11 @@ MainWindow::MainWindow(Settings &settings ui->bsaList->setLocalMoveOnly(true); ui->bsaList->setHeaderHidden(true); - initDownloadView(); - const bool pluginListAdjusted = settings.geometry().restoreState(ui->espList->header()); + + // data tab m_DataTab.reset(new DataTab(m_OrganizerCore, m_PluginContainer, this, ui)); m_DataTab->restoreState(settings); @@ -365,6 +366,11 @@ MainWindow::MainWindow(Settings &settings m_DataTab.get(), &DataTab::displayModInformation, [&](auto&& m, auto&& i, auto&& tab){ displayModInformation(m, i, tab); }); + + // downloads tab + m_DownloadsTab.reset(new DownloadsTab(m_OrganizerCore, ui)); + + // Hide stuff we do not need: IPluginGame const* game = m_OrganizerCore.managedGame(); if (!game->feature<GamePlugins>()) { @@ -1265,15 +1271,6 @@ void MainWindow::espFilterChanged(const QString &filter) updatePluginCount(); } -void MainWindow::downloadFilterChanged(const QString &filter) -{ - if (!filter.isEmpty()) { - ui->downloadView->setStyleSheet("QTreeView { border: 2px ridge #f00; }"); - } else { - ui->downloadView->setStyleSheet(""); - } -} - void MainWindow::expandModList(const QModelIndex &index) { QAbstractItemModel *model = ui->modList->model(); @@ -2310,11 +2307,6 @@ QMainWindow* MainWindow::mainWindow() return this; } -void MainWindow::on_btnRefreshDownloads_clicked() -{ - m_OrganizerCore.downloadManager()->refreshList(); -} - void MainWindow::on_tabWidget_currentChanged(int index) { QWidget* currentWidget = ui->tabWidget->widget(index); @@ -2856,13 +2848,6 @@ void MainWindow::backupMod_clicked() m_OrganizerCore.refresh(); } -void MainWindow::resumeDownload(int downloadIndex) -{ - m_OrganizerCore.loggedInAction(this, [this, downloadIndex] { - m_OrganizerCore.downloadManager()->resumeDownload(downloadIndex); - }); -} - void MainWindow::endorseMod(ModInfo::Ptr mod) { @@ -5161,7 +5146,7 @@ void MainWindow::on_actionSettings_triggered() } ui->statusBar->checkSettings(m_OrganizerCore.settings()); - updateDownloadView(); + m_DownloadsTab->update(); m_OrganizerCore.setLogLevel(settings.diagnostics().logLevel()); @@ -5184,7 +5169,7 @@ void MainWindow::onPluginRegistrationChanged() { updateModPageMenu(); scheduleCheckForProblems(); - updateDownloadView(); + m_DownloadsTab->update(); } void MainWindow::on_actionNexus_triggered() @@ -5240,7 +5225,9 @@ void MainWindow::languageChange(const QString &newLanguage) createHelpMenu(); - updateDownloadView(); + if (m_DownloadsTab) { + m_DownloadsTab->update(); + } QMenu *listOptionsMenu = new QMenu(ui->listOptionsBtn); initModListContextMenu(listOptionsMenu); @@ -5375,61 +5362,6 @@ void MainWindow::actionWontEndorseMO() } } -void MainWindow::initDownloadView() -{ - DownloadList *sourceModel = new DownloadList(m_OrganizerCore.downloadManager(), ui->downloadView); - DownloadListSortProxy *sortProxy = new DownloadListSortProxy(m_OrganizerCore.downloadManager(), ui->downloadView); - sortProxy->setSourceModel(sourceModel); - connect(ui->downloadFilterEdit, SIGNAL(textChanged(QString)), sortProxy, SLOT(updateFilter(QString))); - connect(ui->downloadFilterEdit, SIGNAL(textChanged(QString)), this, SLOT(downloadFilterChanged(QString))); - - ui->downloadView->setSourceModel(sourceModel); - ui->downloadView->setModel(sortProxy); - ui->downloadView->setManager(m_OrganizerCore.downloadManager()); - ui->downloadView->setItemDelegate(new DownloadProgressDelegate(m_OrganizerCore.downloadManager(), sortProxy, ui->downloadView)); - updateDownloadView(); - - connect(ui->downloadView, SIGNAL(installDownload(int)), &m_OrganizerCore, SLOT(installDownload(int))); - connect(ui->downloadView, SIGNAL(queryInfo(int)), m_OrganizerCore.downloadManager(), SLOT(queryInfo(int))); - connect(ui->downloadView, SIGNAL(queryInfoMd5(int)), m_OrganizerCore.downloadManager(), SLOT(queryInfoMd5(int))); - connect(ui->downloadView, SIGNAL(visitOnNexus(int)), m_OrganizerCore.downloadManager(), SLOT(visitOnNexus(int))); - connect(ui->downloadView, SIGNAL(openFile(int)), m_OrganizerCore.downloadManager(), SLOT(openFile(int))); - connect(ui->downloadView, SIGNAL(openMetaFile(int)), m_OrganizerCore.downloadManager(), SLOT(openMetaFile(int))); - connect(ui->downloadView, SIGNAL(openInDownloadsFolder(int)), m_OrganizerCore.downloadManager(), SLOT(openInDownloadsFolder(int))); - connect(ui->downloadView, SIGNAL(removeDownload(int, bool)), m_OrganizerCore.downloadManager(), SLOT(removeDownload(int, bool))); - connect(ui->downloadView, SIGNAL(restoreDownload(int)), m_OrganizerCore.downloadManager(), SLOT(restoreDownload(int))); - connect(ui->downloadView, SIGNAL(cancelDownload(int)), m_OrganizerCore.downloadManager(), SLOT(cancelDownload(int))); - connect(ui->downloadView, SIGNAL(pauseDownload(int)), m_OrganizerCore.downloadManager(), SLOT(pauseDownload(int))); - connect(ui->downloadView, SIGNAL(resumeDownload(int)), this, SLOT(resumeDownload(int))); -} - -void MainWindow::updateDownloadView() -{ - // this means downlaodTab initialization hasnt happened yet - if (ui->downloadView->model() == nullptr) { - return; - } - // set the view attribute and default row sizes - if (m_OrganizerCore.settings().interface().compactDownloads()) { - ui->downloadView->setProperty("downloadView", "compact"); - setStyleSheet("DownloadListWidget::item { padding: 4px 2px; }"); - } else { - ui->downloadView->setProperty("downloadView", "standard"); - setStyleSheet("DownloadListWidget::item { padding: 16px 4px; }"); - } - //setStyleSheet("DownloadListWidget::item:hover { padding: 0px; }"); - //setStyleSheet("DownloadListWidget::item:selected { padding: 0px; }"); - - // reapply global stylesheet on the widget level (!) to override the defaults - //ui->downloadView->setStyleSheet(styleSheet()); - - ui->downloadView->setMetaDisplay(m_OrganizerCore.settings().interface().metaDownloads()); - ui->downloadView->style()->unpolish(ui->downloadView); - ui->downloadView->style()->polish(ui->downloadView); - qobject_cast<DownloadListHeader*>(ui->downloadView->header())->customResizeSections(); - m_OrganizerCore.downloadManager()->refreshList(); -} - void MainWindow::modUpdateCheck(std::multimap<QString, int> IDs) { if (m_OrganizerCore.settings().network().offlineMode()) { diff --git a/src/mainwindow.h b/src/mainwindow.h index 7a1c683d..e4c7b851 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -39,6 +39,7 @@ class CategoryFactory; class OrganizerCore; class FilterList; class DataTab; +class DownloadsTab; class BrowserDialog; class PluginListSortProxy; @@ -234,9 +235,6 @@ private: bool populateMenuCategories(QMenu *menu, int targetID); - void initDownloadView(); - void updateDownloadView(); - // remove invalid category-references from mods void fixCategories(); @@ -298,6 +296,7 @@ private: std::unique_ptr<FilterList> m_Filters; std::unique_ptr<DataTab> m_DataTab; + std::unique_ptr<DownloadsTab> m_DownloadsTab; int m_OldProfileIndex; @@ -498,7 +497,6 @@ private slots: void hookUpWindowTutorials(); bool shouldStartTutorial() const; - void resumeDownload(int downloadIndex); void endorseMod(ModInfo::Ptr mod); void unendorseMod(ModInfo::Ptr mod); void trackMod(ModInfo::Ptr mod, bool doTrack); @@ -545,7 +543,6 @@ private slots: void modFilterActive(bool active); void espFilterChanged(const QString &filter); - void downloadFilterChanged(const QString &filter); void expandModList(const QModelIndex &index); @@ -602,7 +599,6 @@ private slots: // ui slots void on_centralWidget_customContextMenuRequested(const QPoint &pos); void on_bsaList_customContextMenuRequested(const QPoint &pos); void on_clearFiltersButton_clicked(); - void on_btnRefreshDownloads_clicked(); void on_executablesListBox_currentIndexChanged(int index); void on_modList_customContextMenuRequested(const QPoint &pos); void on_modList_doubleClicked(const QModelIndex &index); |
