From ec8dbcbf280bf6b542e9087d562e51757d205299 Mon Sep 17 00:00:00 2001 From: Krzysztof Starecki Date: Sun, 30 Dec 2018 14:54:28 +0100 Subject: Port context menus to new downloadlist --- src/downloadmanager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/downloadmanager.cpp') diff --git a/src/downloadmanager.cpp b/src/downloadmanager.cpp index f1cbf109..9f07b030 100644 --- a/src/downloadmanager.cpp +++ b/src/downloadmanager.cpp @@ -1853,4 +1853,4 @@ void DownloadManager::writeData(DownloadInfo *info) "Canceling download \"%2\"...").arg(ret).arg(fileName)); } } -} \ No newline at end of file +} -- cgit v1.3.1 From c11ff7e2db09514304cef35a650aa3fbef27dd16 Mon Sep 17 00:00:00 2001 From: Krzysztof Starecki Date: Sun, 30 Dec 2018 22:13:15 +0100 Subject: Add icon for incomplete download info, add download progress delegate --- src/downloadlist.cpp | 5 +++++ src/downloadlist.h | 1 - src/downloadlistwidget.cpp | 26 ++++++++++++++++++++++++++ src/downloadlistwidget.h | 18 ++++++++++++++++++ src/downloadmanager.cpp | 6 +++--- src/mainwindow.cpp | 7 ++++--- src/mainwindow.h | 2 +- 7 files changed, 57 insertions(+), 8 deletions(-) (limited to 'src/downloadmanager.cpp') diff --git a/src/downloadlist.cpp b/src/downloadlist.cpp index d78e97f9..09f6968c 100644 --- a/src/downloadlist.cpp +++ b/src/downloadlist.cpp @@ -21,6 +21,7 @@ along with Mod Organizer. If not, see . #include "downloadmanager.h" #include #include +#include #include @@ -147,6 +148,10 @@ QVariant DownloadList::data(const QModelIndex &index, int role) const } return text; } + } else if (role == Qt::DecorationRole && index.column() == COL_NAME) { + if (!pendingDownload && m_Manager->getState(index.row()) >= DownloadManager::STATE_READY + && m_Manager->isInfoIncomplete(index.row())) + return QIcon(":/MO/gui/warning_16"); } else if (role == Qt::TextAlignmentRole) { if (index.column() == COL_SIZE) return Qt::AlignVCenter | Qt::AlignRight; diff --git a/src/downloadlist.h b/src/downloadlist.h index d7764763..3b33fc40 100644 --- a/src/downloadlist.h +++ b/src/downloadlist.h @@ -23,7 +23,6 @@ along with Mod Organizer. If not, see . #include #include - class DownloadManager; diff --git a/src/downloadlistwidget.cpp b/src/downloadlistwidget.cpp index 9cf8e097..6a85c317 100644 --- a/src/downloadlistwidget.cpp +++ b/src/downloadlistwidget.cpp @@ -17,13 +17,39 @@ You should have received a copy of the GNU General Public License along with Mod Organizer. If not, see . */ +#include "downloadlist.h" #include "downloadlistwidget.h" #include #include #include #include #include +#include +void DownloadProgressDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const +{ + QModelIndex sourceIndex = m_SortProxy->mapToSource(index); + if (sourceIndex.column() == DownloadList::COL_STATUS && sourceIndex.row() < m_Manager->numTotalDownloads() + && m_Manager->getState(sourceIndex.row()) == DownloadManager::STATE_DOWNLOADING) { + bool pendingDownload = sourceIndex.row() >= m_Manager->numTotalDownloads(); + QStyleOptionProgressBar progressBarOption; + progressBarOption.state = QStyle::State_Enabled; + progressBarOption.direction = QApplication::layoutDirection(); + progressBarOption.rect = option.rect; + progressBarOption.fontMetrics = QApplication::fontMetrics(); + progressBarOption.minimum = 0; + progressBarOption.maximum = 100; + progressBarOption.textAlignment = Qt::AlignCenter; + progressBarOption.textVisible = true; + progressBarOption.progress = m_Manager->getProgress(sourceIndex.row()).first; + progressBarOption.text = m_Manager->getProgress(sourceIndex.row()).second; + + QApplication::style()->drawControl(QStyle::CE_ProgressBar, + &progressBarOption, painter); + } else { + QStyledItemDelegate::paint(painter, option, index); + } +} DownloadListWidget::DownloadListWidget(QWidget *parent) : QTreeView(parent) diff --git a/src/downloadlistwidget.h b/src/downloadlistwidget.h index 0c17de87..c19e4473 100644 --- a/src/downloadlistwidget.h +++ b/src/downloadlistwidget.h @@ -21,11 +21,14 @@ along with Mod Organizer. If not, see . #define DOWNLOADLISTWIDGET_H #include "downloadmanager.h" +#include "downloadlistsortproxy.h" #include #include #include #include #include +#include + namespace Ui { class DownloadListWidget; @@ -33,6 +36,21 @@ namespace Ui { class DownloadManager; +class DownloadProgressDelegate : public QStyledItemDelegate +{ + Q_OBJECT + +public: + DownloadProgressDelegate(DownloadManager *manager, DownloadListSortProxy *sortProxy, QWidget *parent = 0) : QStyledItemDelegate(parent), m_Manager(manager), m_SortProxy(sortProxy) {} + + void paint(QPainter *painter, const QStyleOptionViewItem &option, + const QModelIndex &index) const override; + +private: + DownloadManager *m_Manager; + DownloadListSortProxy *m_SortProxy; +}; + class DownloadListWidget : public QTreeView { Q_OBJECT diff --git a/src/downloadmanager.cpp b/src/downloadmanager.cpp index 9f07b030..b94b5864 100644 --- a/src/downloadmanager.cpp +++ b/src/downloadmanager.cpp @@ -64,7 +64,7 @@ DownloadManager::DownloadInfo *DownloadManager::DownloadInfo::createNew(const Mo info->m_DownloadID = s_NextDownloadID++; info->m_StartTime.start(); info->m_PreResumeSize = 0LL; - info->m_Progress = std::make_pair(0, " 0.0 Bytes/s "); + info->m_Progress = std::make_pair(0, "0.0 B/s "); info->m_ResumePos = 0; info->m_FileInfo = new ModRepositoryFileInfo(*fileInfo); info->m_Urls = URLs; @@ -1338,7 +1338,7 @@ void DownloadManager::downloadProgress(qint64 bytesReceived, qint64 bytesTotal) QString unit; if (speed < 1000) { - unit = "Bytes/s"; + unit = "B/s"; } else if (speed < 1000*1024) { speed /= 1024; @@ -1349,7 +1349,7 @@ void DownloadManager::downloadProgress(qint64 bytesReceived, qint64 bytesTotal) unit = "MB/s"; } - info->m_Progress.second = QString::fromLatin1("%1% - %2 %3").arg(info->m_Progress.first).arg(speed, 8, 'f', 1,' ').arg(unit, -8, ' '); + info->m_Progress.second = QString::fromLatin1("%1% - %2 %3").arg(info->m_Progress.first).arg(QString::number(speed, 'f', 1)).arg(unit); TaskProgressManager::instance().updateProgress(info->m_TaskProgressId, bytesReceived, bytesTotal); emit update(index); diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index b2876e33..4f60ae16 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -319,6 +319,7 @@ MainWindow::MainWindow(QSettings &initSettings //ui->bsaList->setLocalMoveOnly(true); + initDownloadView(); bool pluginListAdjusted = registerWidgetState(ui->espList->objectName(), ui->espList->header(), "plugin_list_state"); registerWidgetState(ui->dataTree->objectName(), ui->dataTree->header()); registerWidgetState(ui->downloadView->objectName(), @@ -340,8 +341,6 @@ MainWindow::MainWindow(QSettings &initSettings ui->openFolderMenu->setMenu(openFolderMenu()); - initDownloadList(); - ui->savegameList->installEventFilter(this); ui->savegameList->setMouseTracking(true); @@ -5145,15 +5144,17 @@ void MainWindow::on_actionEndorseMO_triggered() } -void MainWindow::initDownloadList() +void MainWindow::initDownloadView() { DownloadListSortProxy *sortProxy = new DownloadListSortProxy(m_OrganizerCore.downloadManager(), ui->downloadView); sortProxy->setSourceModel(new DownloadList(m_OrganizerCore.downloadManager(), ui->downloadView)); connect(ui->downloadFilterEdit, SIGNAL(textChanged(QString)), sortProxy, SLOT(updateFilter(QString))); connect(ui->downloadFilterEdit, SIGNAL(textChanged(QString)), this, SLOT(downloadFilterChanged(QString))); + ui->downloadView->setObjectName("downloadView"); ui->downloadView->setModel(sortProxy); ui->downloadView->setManager(m_OrganizerCore.downloadManager()); + ui->downloadView->setItemDelegate(new DownloadProgressDelegate(m_OrganizerCore.downloadManager(), sortProxy, ui->downloadView)); ui->downloadView->setUniformRowHeights(true); ui->downloadView->header()->setStretchLastSection(false); ui->downloadView->header()->setSectionResizeMode(QHeaderView::Interactive); diff --git a/src/mainwindow.h b/src/mainwindow.h index 93f2ed5f..13a66a8e 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -246,7 +246,7 @@ private: bool populateMenuCategories(QMenu *menu, int targetID); - void initDownloadList(); + void initDownloadView(); // remove invalid category-references from mods void fixCategories(); -- cgit v1.3.1 From 79a2f8477b02c506ff8ae18367d3739aa17307ad Mon Sep 17 00:00:00 2001 From: Krzysztof Starecki Date: Mon, 31 Dec 2018 22:45:04 +0100 Subject: Fix bug with hiding installed downloads --- src/downloadmanager.cpp | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) (limited to 'src/downloadmanager.cpp') diff --git a/src/downloadmanager.cpp b/src/downloadmanager.cpp index b94b5864..509323c9 100644 --- a/src/downloadmanager.cpp +++ b/src/downloadmanager.cpp @@ -700,22 +700,18 @@ void DownloadManager::removeDownload(int index, bool deleteFile) emit aboutToUpdate(); if (index < 0) { - DownloadState minState; - if (index == -3) { - minState = STATE_UNINSTALLED; - } - else - minState = index == -1 ? STATE_READY : STATE_INSTALLED; + bool removeAll = (index == -1); + DownloadState removeState = (index == -2 ? STATE_INSTALLED : STATE_UNINSTALLED); index = 0; - for (QVector::iterator iter = m_ActiveDownloads.begin(); iter != m_ActiveDownloads.end();) { - if ((*iter)->m_State >= minState) { + for (QVector::iterator iter = m_ActiveDownloads.begin(); iter != m_ActiveDownloads.end();) { + DownloadState downloadState = (*iter)->m_State; + if ((removeAll && (downloadState >= STATE_READY)) || + (removeState == downloadState)) { removeFile(index, deleteFile); delete *iter; iter = m_ActiveDownloads.erase(iter); - //QCoreApplication::processEvents(); - } - else { + } else { ++iter; ++index; } -- cgit v1.3.1 From 44d42cb26dca902d744a994a91279ca45c79d75f Mon Sep 17 00:00:00 2001 From: Krzysztof Starecki Date: Tue, 1 Jan 2019 01:10:46 +0100 Subject: Change redownload dialog to display the filename --- src/downloadmanager.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/downloadmanager.cpp') diff --git a/src/downloadmanager.cpp b/src/downloadmanager.cpp index 509323c9..8c4e0b56 100644 --- a/src/downloadmanager.cpp +++ b/src/downloadmanager.cpp @@ -499,8 +499,8 @@ void DownloadManager::startDownload(QNetworkReply *reply, DownloadInfo *newDownl if (QFile::exists(m_OutputDirectory + "/" + newDownload->m_FileName)) { setState(newDownload, STATE_PAUSING); QCoreApplication::processEvents(); - if (QMessageBox::question(nullptr, tr("Download again?"), tr("A file with the same name has already been downloaded. " - "Do you want to download it again? The new file will receive a different name."), + if (QMessageBox::question(nullptr, tr("Download again?"), tr("A file with the same name \"%1\" has already been downloaded. " + "Do you want to download it again? The new file will receive a different name.").arg(newDownload->m_FileName), QMessageBox::Yes | QMessageBox::No) == QMessageBox::No) { if (reply->isFinished()) setState(newDownload, STATE_CANCELED); -- cgit v1.3.1 From 63b21894160bf10675b36a4519afccdef6567900 Mon Sep 17 00:00:00 2001 From: Krzysztof Starecki Date: Tue, 1 Jan 2019 15:29:50 +0100 Subject: Remove unused import, fix accidental indent --- src/downloadlist.h | 1 - src/downloadmanager.cpp | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) (limited to 'src/downloadmanager.cpp') diff --git a/src/downloadlist.h b/src/downloadlist.h index 2c32a397..bf0cdc37 100644 --- a/src/downloadlist.h +++ b/src/downloadlist.h @@ -21,7 +21,6 @@ along with Mod Organizer. If not, see . #define DOWNLOADLIST_H #include -#include class DownloadManager; diff --git a/src/downloadmanager.cpp b/src/downloadmanager.cpp index 8c4e0b56..2784a8ce 100644 --- a/src/downloadmanager.cpp +++ b/src/downloadmanager.cpp @@ -711,7 +711,7 @@ void DownloadManager::removeDownload(int index, bool deleteFile) removeFile(index, deleteFile); delete *iter; iter = m_ActiveDownloads.erase(iter); - } else { + } else { ++iter; ++index; } -- cgit v1.3.1