From 2c5603092af9cdce1748870176c5f4cd49a87b8d Mon Sep 17 00:00:00 2001 From: LostDragonist Date: Fri, 6 Dec 2019 11:06:50 -0700 Subject: Add source game column to the download list --- src/downloadlist.cpp | 9 ++++++++- src/downloadlist.h | 1 + src/downloadlistsortproxy.cpp | 2 ++ src/downloadlistwidget.cpp | 1 + src/downloadmanager.cpp | 13 +++++++++++++ src/downloadmanager.h | 8 ++++++++ 6 files changed, 33 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/downloadlist.cpp b/src/downloadlist.cpp index 6957f270..99347a79 100644 --- a/src/downloadlist.cpp +++ b/src/downloadlist.cpp @@ -77,6 +77,7 @@ QVariant DownloadList::headerData(int section, Qt::Orientation orientation, int case COL_SIZE: return tr("Size"); case COL_STATUS: return tr("Status"); case COL_FILETIME: return tr("Filetime"); + case COL_SOURCEGAME: return tr("Source Game"); default: return QVariant(); } } else { @@ -118,10 +119,16 @@ QVariant DownloadList::data(const QModelIndex &index, int role) const if (m_Manager->isInfoIncomplete(index.row())) { return {}; } else { - const MOBase::ModRepositoryFileInfo *info = m_Manager->getFileInfo(index.row()); return QString("%1").arg(m_Manager->getModID(index.row())); } } + case COL_SOURCEGAME: { + if (m_Manager->isInfoIncomplete(index.row())) { + return {}; + } else { + return QString("%1").arg(m_Manager->getDisplayGameName(index.row())); + } + } case COL_SIZE: return MOBase::localizedByteSize(m_Manager->getFileSize(index.row())); case COL_FILETIME: return m_Manager->getFileTime(index.row()); case COL_STATUS: diff --git a/src/downloadlist.h b/src/downloadlist.h index 51ab4541..eb2bbc55 100644 --- a/src/downloadlist.h +++ b/src/downloadlist.h @@ -43,6 +43,7 @@ public: COL_MODNAME, COL_VERSION, COL_ID, + COL_SOURCEGAME, // number of columns COL_COUNT diff --git a/src/downloadlistsortproxy.cpp b/src/downloadlistsortproxy.cpp index a69993c0..6209a721 100644 --- a/src/downloadlistsortproxy.cpp +++ b/src/downloadlistsortproxy.cpp @@ -96,6 +96,8 @@ bool DownloadListSortProxy::lessThan(const QModelIndex &left, return m_Manager->getFileSize(left.row()) < m_Manager->getFileSize(right.row()); } else if (left.column() == DownloadList::COL_FILETIME) { return m_Manager->getFileTime(left.row()) < m_Manager->getFileTime(right.row()); + } else if (left.column() == DownloadList::COL_SOURCEGAME) { + return m_Manager->getDisplayGameName(left.row()) < m_Manager->getDisplayGameName(right.row()); } else { return leftIndex < rightIndex; } diff --git a/src/downloadlistwidget.cpp b/src/downloadlistwidget.cpp index 85d27831..ac37b0ee 100644 --- a/src/downloadlistwidget.cpp +++ b/src/downloadlistwidget.cpp @@ -135,6 +135,7 @@ void DownloadListWidget::setManager(DownloadManager *manager) header()->hideSection(DownloadList::COL_MODNAME); header()->hideSection(DownloadList::COL_VERSION); header()->hideSection(DownloadList::COL_ID); + header()->hideSection(DownloadList::COL_SOURCEGAME); } void DownloadListWidget::setSourceModel(DownloadList *sourceModel) diff --git a/src/downloadmanager.cpp b/src/downloadmanager.cpp index 361e7164..adfbc84d 100644 --- a/src/downloadmanager.cpp +++ b/src/downloadmanager.cpp @@ -1239,6 +1239,19 @@ int DownloadManager::getModID(int index) const return m_ActiveDownloads.at(index)->m_FileInfo->modID; } +QString DownloadManager::getDisplayGameName(int index) const +{ + if ((index < 0) || (index >= m_ActiveDownloads.size())) { + throw MyException(tr("mod id: invalid download index %1").arg(index)); + } + QString gameName = m_ActiveDownloads.at(index)->m_FileInfo->gameName; + IPluginGame* gamePlugin = m_OrganizerCore->getGame(gameName); + if (gamePlugin) { + gameName = gamePlugin->gameName(); + } + return gameName; +} + QString DownloadManager::getGameName(int index) const { if ((index < 0) || (index >= m_ActiveDownloads.size())) { diff --git a/src/downloadmanager.h b/src/downloadmanager.h index f2ad15f4..4fc61cad 100644 --- a/src/downloadmanager.h +++ b/src/downloadmanager.h @@ -312,6 +312,14 @@ public: **/ int getModID(int index) const; + /** + * @brief retrieve the displayable game name of the download specified by the index + * + * @param index index of the file to look up + * @return the displayable game name + **/ + QString getDisplayGameName(int index) const; + /** * @brief retrieve the game name of the downlaod specified by the index * -- cgit v1.3.1