From 4d40e8d18c789e71af403997fa1b10e8dd7168e1 Mon Sep 17 00:00:00 2001 From: Krzysztof Starecki Date: Sun, 30 Dec 2018 16:22:35 +0100 Subject: Fix adding new downloads, add missing download progress states --- src/downloadlist.cpp | 71 +++++++++++++++++++++++++++++---------- src/downloadlistsortproxy.cpp | 4 +-- src/downloadlistwidgetcompact.cpp | 1 - 3 files changed, 55 insertions(+), 21 deletions(-) (limited to 'src') diff --git a/src/downloadlist.cpp b/src/downloadlist.cpp index a44850cb..178e4083 100644 --- a/src/downloadlist.cpp +++ b/src/downloadlist.cpp @@ -64,7 +64,7 @@ QVariant DownloadList::headerData(int section, Qt::Orientation orientation, int case COL_NAME : return tr("Name"); case COL_SIZE : return tr("Size"); case COL_STATUS : return tr("Status"); - default : return "-"; + default : return QVariant(); } } else { return QAbstractItemModel::headerData(section, orientation, role); @@ -73,26 +73,63 @@ QVariant DownloadList::headerData(int section, Qt::Orientation orientation, int QVariant DownloadList::data(const QModelIndex &index, int role) const { + bool pendingDownload = index.row() >= m_Manager->numTotalDownloads(); if (role == Qt::DisplayRole) { - if (index.column() == COL_NAME) { - return m_Manager->getFileName(index.row()); - } else if (index.column() == COL_SIZE) { - return sizeFormat(m_Manager->getFileSize(index.row())); - } else if (index.column() == COL_STATUS) { - DownloadManager::DownloadState state = m_Manager->getState(index.row()); - switch (state) { - case DownloadManager::STATE_INSTALLED : return tr("Installed"); - case DownloadManager::STATE_UNINSTALLED : return tr("Uninstalled"); - case DownloadManager::STATE_READY : return tr("Downloaded"); - case DownloadManager::STATE_DOWNLOADING : return m_Manager->getProgress(index.row()).second; - case DownloadManager::STATE_PAUSED : return tr("Paused"); - default : return state; + if (pendingDownload) { + std::tuple nexusids = m_Manager->getPendingDownload(index.row() - m_Manager->numTotalDownloads()); + switch (index.column()) { + case COL_NAME: + return tr("< game %1 mod %2 file %3 >").arg(std::get<0>(nexusids)).arg(std::get<1>(nexusids)).arg(std::get<2>(nexusids)); + case COL_SIZE: + return tr("Unknown"); + case COL_STATUS: + return tr("Pending"); + default: + return QVariant(); } } else { - return index.row(); + switch (index.column()) { + case COL_NAME: + return m_Manager->getFileName(index.row()); + case COL_SIZE: + return sizeFormat(m_Manager->getFileSize(index.row())); + case COL_STATUS: + switch (m_Manager->getState(index.row())) { + case DownloadManager::STATE_STARTED: + return tr("Started"); + case DownloadManager::STATE_DOWNLOADING: + return m_Manager->getProgress(index.row()).second; + case DownloadManager::STATE_CANCELING: + return tr("Canceling"); + case DownloadManager::STATE_PAUSING: + return tr("Pausing"); + case DownloadManager::STATE_CANCELED: + return tr("Canceled"); + case DownloadManager::STATE_PAUSED: + return tr("Paused"); + case DownloadManager::STATE_ERROR: + return tr("Error"); + case DownloadManager::STATE_FETCHINGMODINFO: + return tr("Fetching Info 1"); + case DownloadManager::STATE_FETCHINGFILEINFO: + return tr("Fetching Info 2"); + case DownloadManager::STATE_READY: + return tr("Downloaded"); + case DownloadManager::STATE_INSTALLED: + return tr("Installed"); + case DownloadManager::STATE_UNINSTALLED: + return tr("Uninstalled"); + default: + return QVariant(); + } + default: + return QVariant(); + } } } else if (role == Qt::ToolTipRole) { - if (index.row() < m_Manager->numTotalDownloads()) { + if (pendingDownload) { + return tr("pending download"); + } else { QString text = m_Manager->getFileName(index.row()) + "\n"; if (m_Manager->isInfoIncomplete(index.row())) { text += tr("Information missing, please select \"Query Info\" from the context menu to re-retrieve."); @@ -101,8 +138,6 @@ QVariant DownloadList::data(const QModelIndex &index, int role) const return QString("%1 (ID %2) %3
%4").arg(info->modName).arg(m_Manager->getModID(index.row())).arg(info->version.canonicalString()).arg(info->description); } return text; - } else { - return tr("pending download"); } } else { return QVariant(); diff --git a/src/downloadlistsortproxy.cpp b/src/downloadlistsortproxy.cpp index 1a2606c9..5e455529 100644 --- a/src/downloadlistsortproxy.cpp +++ b/src/downloadlistsortproxy.cpp @@ -37,8 +37,8 @@ void DownloadListSortProxy::updateFilter(const QString &filter) bool DownloadListSortProxy::lessThan(const QModelIndex &left, const QModelIndex &right) const { - int leftIndex = left.data().toInt(); - int rightIndex = right.data().toInt(); + int leftIndex = left.row(); + int rightIndex = right.row(); if ((leftIndex < m_Manager->numTotalDownloads()) && (rightIndex < m_Manager->numTotalDownloads())) { if (left.column() == DownloadList::COL_NAME) { diff --git a/src/downloadlistwidgetcompact.cpp b/src/downloadlistwidgetcompact.cpp index b534b95b..e033c202 100644 --- a/src/downloadlistwidgetcompact.cpp +++ b/src/downloadlistwidgetcompact.cpp @@ -124,7 +124,6 @@ void DownloadListWidgetCompactDelegate::paintRegularDownload(int downloadIndex) name.append("..."); } m_NameLabel->setText(name); - DownloadManager::DownloadState state = m_Manager->getState(downloadIndex); if (m_SizeLabel != nullptr) { -- cgit v1.3.1