summaryrefslogtreecommitdiff
path: root/src/downloadlistwidgetcompact.cpp
diff options
context:
space:
mode:
authorBrian Munro <brian.alexander.munro@gmail.com>2018-08-02 09:15:12 +0200
committerGitHub <noreply@github.com>2018-08-02 09:15:12 +0200
commit9a3a15b1f6339589be97e2546b7d532d30abc292 (patch)
tree2776d6834b92fdc95b5b26ab43e9e743e10c1128 /src/downloadlistwidgetcompact.cpp
parent886fb10288baf4f52af2ad812a1c2121e138a16e (diff)
parent1ea43586d8eb304d8e91bf7f1480d7e4db5ef05f (diff)
Merge pull request #454 from Modorganizer2/Develop
Release 2.1.4
Diffstat (limited to 'src/downloadlistwidgetcompact.cpp')
-rw-r--r--src/downloadlistwidgetcompact.cpp97
1 files changed, 83 insertions, 14 deletions
diff --git a/src/downloadlistwidgetcompact.cpp b/src/downloadlistwidgetcompact.cpp
index 898d400a..663a224e 100644
--- a/src/downloadlistwidgetcompact.cpp
+++ b/src/downloadlistwidgetcompact.cpp
@@ -81,18 +81,35 @@ void DownloadListWidgetCompactDelegate::drawCache(QPainter *painter, const QStyl
{
QRect rect = option.rect;
rect.setLeft(0);
- rect.setWidth(m_View->columnWidth(0) + m_View->columnWidth(1) + m_View->columnWidth(2));
+ rect.setWidth(m_View->columnWidth(0) + m_View->columnWidth(1) + m_View->columnWidth(2) + m_View->columnWidth(3));
painter->drawPixmap(rect, cache);
}
+QString DownloadListWidgetCompactDelegate::sizeFormat(quint64 size) const
+{
+ qreal calc = size;
+ QStringList list;
+ list << "KB" << "MB" << "GB" << "TB";
+
+ QStringListIterator i(list);
+ QString unit("byte(s)");
+
+ while (calc >= 1024.0 && i.hasNext())
+ {
+ unit = i.next();
+ calc /= 1024.0;
+ }
+
+ return QString().setNum(calc, 'f', 2) + " " + unit;
+}
void DownloadListWidgetCompactDelegate::paintPendingDownload(int downloadIndex) const
{
std::tuple<QString, int, int> nexusids = m_Manager->getPendingDownload(downloadIndex);
m_NameLabel->setText(tr("< game %1 mod %2 file %3 >").arg(std::get<0>(nexusids)).arg(std::get<1>(nexusids)).arg(std::get<2>(nexusids)));
- if (m_SizeLabel != nullptr) {
- m_SizeLabel->setText("???");
- }
+ //if (m_SizeLabel != nullptr) {
+ // m_SizeLabel->setText("???");
+ //}
m_DoneLabel->setVisible(true);
m_DoneLabel->setText(tr("Pending"));
m_Progress->setVisible(false);
@@ -110,11 +127,15 @@ void DownloadListWidgetCompactDelegate::paintRegularDownload(int downloadIndex)
DownloadManager::DownloadState state = m_Manager->getState(downloadIndex);
- if ((m_SizeLabel != nullptr) && (state >= DownloadManager::STATE_READY)) {
- m_SizeLabel->setText(QString::number(m_Manager->getFileSize(downloadIndex) / 1048576));
+ if (m_SizeLabel != nullptr) {
+ m_SizeLabel->setText(sizeFormat(m_Manager->getFileSize(downloadIndex)) + " ");
+ m_SizeLabel->setVisible(true);
}
+ //else {
+ // m_SizeLabel->setVisible(false);
+ //}
- if ((state == DownloadManager::STATE_PAUSED) || (state == DownloadManager::STATE_ERROR)) {
+ if ((state == DownloadManager::STATE_PAUSED) || (state == DownloadManager::STATE_ERROR) || (state == DownloadManager::STATE_PAUSING)) {
m_DoneLabel->setVisible(true);
m_Progress->setVisible(false);
m_DoneLabel->setText(QString("%1<img src=\":/MO/gui/inactive\">").arg(tr("Paused")));
@@ -153,7 +174,7 @@ void DownloadListWidgetCompactDelegate::paint(QPainter *painter, const QStyleOpt
return;
}
- m_ItemWidget->resize(QSize(m_View->columnWidth(0) + m_View->columnWidth(1) + m_View->columnWidth(2), option.rect.height()));
+ m_ItemWidget->resize(QSize(m_View->columnWidth(0) + m_View->columnWidth(1) + m_View->columnWidth(2) + m_View->columnWidth(3), option.rect.height()));
if (index.row() % 2 == 1) {
m_ItemWidget->setBackgroundRole(QPalette::AlternateBase);
} else {
@@ -209,7 +230,11 @@ void DownloadListWidgetCompactDelegate::issueQueryInfo()
void DownloadListWidgetCompactDelegate::issueDelete()
{
- emit removeDownload(m_ContextIndex.row(), true);
+ if (QMessageBox::question(nullptr, tr("Are you sure?"),
+ tr("This will permanently delete the selected download."),
+ QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes) {
+ emit removeDownload(m_ContextIndex.row(), true);
+ }
}
void DownloadListWidgetCompactDelegate::issueRemoveFromView()
@@ -217,11 +242,27 @@ void DownloadListWidgetCompactDelegate::issueRemoveFromView()
emit removeDownload(m_ContextIndex.row(), false);
}
+void DownloadListWidgetCompactDelegate::issueVisitOnNexus()
+{
+ emit visitOnNexus(m_ContextIndex.row());
+}
+
+void DownloadListWidgetCompactDelegate::issueOpenInDownloadsFolder()
+{
+ emit openInDownloadsFolder(m_ContextIndex.row());
+}
+
void DownloadListWidgetCompactDelegate::issueRestoreToView()
{
- emit restoreDownload(m_ContextIndex.row());
+ emit restoreDownload(m_ContextIndex.row());
}
+void DownloadListWidgetCompactDelegate::issueRestoreToViewAll()
+{
+ emit restoreDownload(-1);
+}
+
+
void DownloadListWidgetCompactDelegate::issueCancel()
{
emit cancelDownload(m_ContextIndex.row());
@@ -255,6 +296,15 @@ void DownloadListWidgetCompactDelegate::issueDeleteCompleted()
}
}
+void DownloadListWidgetCompactDelegate::issueDeleteUninstalled()
+{
+ if (QMessageBox::question(nullptr, tr("Are you sure?"),
+ tr("This will remove all uninstalled downloads from this list and from disk."),
+ QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes) {
+ emit removeDownload(-3, true);
+ }
+}
+
void DownloadListWidgetCompactDelegate::issueRemoveFromViewAll()
{
if (QMessageBox::question(nullptr, tr("Are you sure?"),
@@ -273,6 +323,15 @@ void DownloadListWidgetCompactDelegate::issueRemoveFromViewCompleted()
}
}
+void DownloadListWidgetCompactDelegate::issueRemoveFromViewUninstalled()
+{
+ if (QMessageBox::question(nullptr, tr("Are you sure?"),
+ tr("This will permanently remove all uninstalled downloads from this list (but NOT from disk)."),
+ QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes) {
+ emit removeDownload(-3, false);
+ }
+}
+
bool DownloadListWidgetCompactDelegate::editorEvent(QEvent *event, QAbstractItemModel *model,
const QStyleOptionViewItem &option, const QModelIndex &index)
@@ -282,7 +341,7 @@ bool DownloadListWidgetCompactDelegate::editorEvent(QEvent *event, QAbstractItem
QModelIndex sourceIndex = qobject_cast<QSortFilterProxyModel*>(model)->mapToSource(index);
if (m_Manager->getState(sourceIndex.row()) >= DownloadManager::STATE_READY) {
emit installDownload(sourceIndex.row());
- } else if (m_Manager->getState(sourceIndex.row()) >= DownloadManager::STATE_PAUSED) {
+ } else if ((m_Manager->getState(sourceIndex.row()) >= DownloadManager::STATE_PAUSED) || (m_Manager->getState(sourceIndex.row()) == DownloadManager::STATE_PAUSING)) {
emit resumeDownload(sourceIndex.row());
}
return true;
@@ -299,7 +358,11 @@ bool DownloadListWidgetCompactDelegate::editorEvent(QEvent *event, QAbstractItem
menu.addAction(tr("Install"), this, SLOT(issueInstall()));
if (m_Manager->isInfoIncomplete(m_ContextIndex.row())) {
menu.addAction(tr("Query Info"), this, SLOT(issueQueryInfo()));
+ }else {
+ menu.addAction(tr("Visit on Nexus"), this, SLOT(issueVisitOnNexus()));
}
+ menu.addAction(tr("Show in Folder"), this, SLOT(issueOpenInDownloadsFolder()));
+ menu.addSeparator();
menu.addAction(tr("Delete"), this, SLOT(issueDelete()));
if (hidden) {
menu.addAction(tr("Un-Hide"), this, SLOT(issueRestoreToView()));
@@ -309,20 +372,27 @@ bool DownloadListWidgetCompactDelegate::editorEvent(QEvent *event, QAbstractItem
} else if (state == DownloadManager::STATE_DOWNLOADING){
menu.addAction(tr("Cancel"), this, SLOT(issueCancel()));
menu.addAction(tr("Pause"), this, SLOT(issuePause()));
- } else if ((state == DownloadManager::STATE_PAUSED) || (state == DownloadManager::STATE_ERROR)) {
+ menu.addAction(tr("Show in Folder"), this, SLOT(issueOpenInDownloadsFolder()));
+ } else if ((state == DownloadManager::STATE_PAUSED) || (state == DownloadManager::STATE_ERROR) || (state == DownloadManager::STATE_PAUSING)) {
menu.addAction(tr("Remove"), this, SLOT(issueDelete()));
menu.addAction(tr("Resume"), this, SLOT(issueResume()));
+ menu.addAction(tr("Show in Folder"), this, SLOT(issueOpenInDownloadsFolder()));
}
-
menu.addSeparator();
}
menu.addAction(tr("Delete Installed..."), this, SLOT(issueDeleteCompleted()));
+ menu.addAction(tr("Delete Uninstalled..."), this, SLOT(issueDeleteUninstalled()));
menu.addAction(tr("Delete All..."), this, SLOT(issueDeleteAll()));
if (!hidden) {
menu.addSeparator();
menu.addAction(tr("Hide Installed..."), this, SLOT(issueRemoveFromViewCompleted()));
+ menu.addAction(tr("Hide Uninstalled..."), this, SLOT(issueRemoveFromViewUninstalled()));
menu.addAction(tr("Hide All..."), this, SLOT(issueRemoveFromViewAll()));
}
+ if (hidden) {
+ menu.addSeparator();
+ menu.addAction(tr("Un-Hide All..."), this, SLOT(issueRestoreToViewAll()));
+ }
menu.exec(mouseEvent->globalPos());
event->accept();
@@ -335,4 +405,3 @@ bool DownloadListWidgetCompactDelegate::editorEvent(QEvent *event, QAbstractItem
return QItemDelegate::editorEvent(event, model, option, index);
}
-