diff options
| author | LostDragonist <lost.dragonist@gmail.com> | 2019-05-03 21:32:33 -0500 |
|---|---|---|
| committer | LostDragonist <lost.dragonist@gmail.com> | 2019-05-03 21:32:33 -0500 |
| commit | 179a73857125ee604f42b0d5c2d765183c86d2c7 (patch) | |
| tree | b9b3f9d62bd5640de839d150a53ab8ef119dab9c /src/downloadlist.cpp | |
| parent | e2b799bd6b5cfd51969fefd1dab5e5b1b7e5f81c (diff) | |
| parent | 907c5468424b48774f5da2a6b5f96f26590987b0 (diff) | |
Merge pull request #695 from ModOrganizer2/Develop
Stage for Release 2.2.0
Diffstat (limited to 'src/downloadlist.cpp')
| -rw-r--r-- | src/downloadlist.cpp | 104 |
1 files changed, 88 insertions, 16 deletions
diff --git a/src/downloadlist.cpp b/src/downloadlist.cpp index 1e31973d..dd72abbd 100644 --- a/src/downloadlist.cpp +++ b/src/downloadlist.cpp @@ -20,6 +20,8 @@ along with Mod Organizer. If not, see <http://www.gnu.org/licenses/>. #include "downloadlist.h"
#include "downloadmanager.h"
#include <QEvent>
+#include <QColor>
+#include <QIcon>
#include <QSortFilterProxyModel>
@@ -31,6 +33,11 @@ DownloadList::DownloadList(DownloadManager *manager, QObject *parent) connect(m_Manager, SIGNAL(aboutToUpdate()), this, SLOT(aboutToUpdate()));
}
+void DownloadList::setMetaDisplay(bool metaDisplay)
+{
+ m_MetaDisplay = metaDisplay;
+}
+
int DownloadList::rowCount(const QModelIndex&) const
{
@@ -62,36 +69,86 @@ QVariant DownloadList::headerData(int section, Qt::Orientation orientation, int (orientation == Qt::Horizontal)) {
switch (section) {
case COL_NAME: return tr("Name");
- case COL_FILETIME: return tr("Filetime");
case COL_SIZE: return tr("Size");
- default: return tr("Done");
+ case COL_STATUS: return tr("Status");
+ case COL_FILETIME: return tr("Filetime");
+ default: return QVariant();
}
} else {
return QAbstractItemModel::headerData(section, orientation, role);
}
}
-
QVariant DownloadList::data(const QModelIndex &index, int role) const
{
+ bool pendingDownload = index.row() >= m_Manager->numTotalDownloads();
if (role == Qt::DisplayRole) {
- return index.row();
+ if (pendingDownload) {
+ std::tuple<QString, int, int> 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");
+ }
+ } else {
+ switch (index.column()) {
+ case COL_NAME: return m_MetaDisplay ? m_Manager->getDisplayName(index.row()) : m_Manager->getFileName(index.row());
+ case COL_SIZE: return sizeFormat(m_Manager->getFileSize(index.row()));
+ case COL_FILETIME: return m_Manager->getFileTime(index.row());
+ case COL_STATUS:
+ switch (m_Manager->getState(index.row())) {
+ // STATE_DOWNLOADING handled by DownloadProgressDelegate
+ case DownloadManager::STATE_STARTED: return tr("Started");
+ 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");
+ case DownloadManager::STATE_FETCHINGFILEINFO: return tr("Fetching Info");
+ case DownloadManager::STATE_FETCHINGMODINFO_MD5: return tr("Fetching Info");
+ case DownloadManager::STATE_READY: return tr("Downloaded");
+ case DownloadManager::STATE_INSTALLED: return tr("Installed");
+ case DownloadManager::STATE_UNINSTALLED: return tr("Uninstalled");
+ }
+ }
+ }
+ } else if (role == Qt::ForegroundRole && index.column() == COL_STATUS) {
+ if (pendingDownload) {
+ return QColor(Qt::darkBlue);
+ } else {
+ DownloadManager::DownloadState state = m_Manager->getState(index.row());
+ if (state == DownloadManager::STATE_READY)
+ return QColor(Qt::darkGreen);
+ else if (state == DownloadManager::STATE_UNINSTALLED)
+ return QColor(Qt::darkYellow);
+ else if (state == DownloadManager::STATE_PAUSED)
+ return QColor(Qt::darkRed);
+ }
} 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.");
} else {
const MOBase::ModRepositoryFileInfo *info = m_Manager->getFileInfo(index.row());
- return QString("%1 (ID %2) %3<br><span>%4</span>").arg(info->modName).arg(m_Manager->getModID(index.row())).arg(info->version.canonicalString()).arg(info->description);
+ return QString("%1 (ID %2) %3<br><span>%4</span>").arg(info->modName).arg(m_Manager->getModID(index.row())).arg(info->version.canonicalString()).arg(info->description.chopped(4096));
}
return text;
- } else {
- return tr("pending download");
}
- } else {
- return QVariant();
+ } 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_NAME)
+ return QVariant(Qt::AlignVCenter | Qt::AlignLeft);
+ else
+ return QVariant(Qt::AlignVCenter | Qt::AlignRight);
}
+ return QVariant();
}
@@ -103,13 +160,28 @@ void DownloadList::aboutToUpdate() void DownloadList::update(int row)
{
- if (row < 0) {
+ if (row < 0)
emit endResetModel();
- } else if (row < this->rowCount()) {
-#pragma message("updating only the one column is a hack")
- emit dataChanged(this->index(row, 2, QModelIndex()), this->index(row, 2, QModelIndex()));
- } else {
+ else if (row < this->rowCount())
+ emit dataChanged(this->index(row, 0, QModelIndex()), this->index(row, this->columnCount(QModelIndex())-1, QModelIndex()));
+ else
qCritical("invalid row %d in download list, update failed", row);
- }
}
+QString DownloadList::sizeFormat(quint64 size) const
+{
+ qreal calc = size;
+ QStringList list;
+ list << "MB" << "GB" << "TB";
+
+ QStringListIterator i(list);
+ QString unit("KB");
+
+ calc /= 1024.0;
+ while (calc >= 1024.0 && i.hasNext()) {
+ unit = i.next();
+ calc /= 1024.0;
+ }
+
+ return QString().setNum(calc, 'f', 2) + " " + unit;
+}
|
