Skip to content

Commit

Permalink
Merge pull request #454 from Modorganizer2/Develop
Browse files Browse the repository at this point in the history
Release 2.1.4
  • Loading branch information
LePresidente authored Aug 2, 2018
2 parents 886fb10 + 1ea4358 commit 9a3a15b
Show file tree
Hide file tree
Showing 42 changed files with 2,211 additions and 1,206 deletions.
3 changes: 2 additions & 1 deletion src/downloadlist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ int DownloadList::rowCount(const QModelIndex&) const

int DownloadList::columnCount(const QModelIndex&) const
{
return 3;
return 4;
}


Expand All @@ -63,6 +63,7 @@ QVariant DownloadList::headerData(int section, Qt::Orientation orientation, int
switch (section) {
case COL_NAME: return tr("Name");
case COL_FILETIME: return tr("Filetime");
case COL_SIZE: return tr("Size");
default: return tr("Done");
}
} else {
Expand Down
3 changes: 2 additions & 1 deletion src/downloadlist.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ class DownloadList : public QAbstractTableModel
enum EColumn {
COL_NAME = 0,
COL_FILETIME,
COL_STATUS
COL_STATUS,
COL_SIZE
};

public:
Expand Down
2 changes: 2 additions & 0 deletions src/downloadlistsortproxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ bool DownloadListSortProxy::lessThan(const QModelIndex &left,
return m_Manager->getFileTime(leftIndex) < m_Manager->getFileTime(rightIndex);
} else if (left.column() == DownloadList::COL_STATUS) {
return m_Manager->getState(leftIndex) < m_Manager->getState(rightIndex);
} else if(left.column() == DownloadList::COL_SIZE){
return m_Manager->getFileSize(leftIndex) < m_Manager->getFileSize(rightIndex);
} else {
return leftIndex < rightIndex;
}
Expand Down
105 changes: 89 additions & 16 deletions src/downloadlistwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,30 @@ void DownloadListWidgetDelegate::drawCache(QPainter *painter, const QStyleOption
{
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 DownloadListWidgetDelegate::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 DownloadListWidgetDelegate::paintPendingDownload(int downloadIndex) const
{
std::tuple<QString, int, int> nexusids = m_Manager->getPendingDownload(downloadIndex);
Expand All @@ -106,9 +125,9 @@ void DownloadListWidgetDelegate::paintRegularDownload(int downloadIndex) const
name.append("...");
}
m_NameLabel->setText(name);
m_SizeLabel->setText(QString::number(m_Manager->getFileSize(downloadIndex) / 1024));
m_SizeLabel->setText(sizeFormat(m_Manager->getFileSize(downloadIndex) ));
DownloadManager::DownloadState state = m_Manager->getState(downloadIndex);
if ((state == DownloadManager::STATE_PAUSED) || (state == DownloadManager::STATE_ERROR)) {
if ((state == DownloadManager::STATE_PAUSED) || (state == DownloadManager::STATE_ERROR) || (state == DownloadManager::STATE_PAUSING)) {
QPalette labelPalette;
m_InstallLabel->setVisible(true);
m_Progress->setVisible(false);
Expand Down Expand Up @@ -174,7 +193,7 @@ void DownloadListWidgetDelegate::paint(QPainter *painter, const QStyleOptionView
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()));

int downloadIndex = index.data().toInt();

Expand Down Expand Up @@ -226,7 +245,11 @@ void DownloadListWidgetDelegate::issueQueryInfo()

void DownloadListWidgetDelegate::issueDelete()
{
emit removeDownload(m_ContextRow, true);
if (QMessageBox::question(nullptr, tr("Delete Files?"),
tr("This will permanently delete the selected download."),
QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes) {
emit removeDownload(m_ContextRow, true);
}
}

void DownloadListWidgetDelegate::issueRemoveFromView()
Expand All @@ -236,7 +259,22 @@ void DownloadListWidgetDelegate::issueRemoveFromView()

void DownloadListWidgetDelegate::issueRestoreToView()
{
emit restoreDownload(m_ContextRow);
emit restoreDownload(m_ContextRow);
}

void DownloadListWidgetDelegate::issueRestoreToViewAll()
{
emit restoreDownload(-1);
}

void DownloadListWidgetDelegate::issueVisitOnNexus()
{
emit visitOnNexus(m_ContextRow);
}

void DownloadListWidgetDelegate::issueOpenInDownloadsFolder()
{
emit openInDownloadsFolder(m_ContextRow);
}

void DownloadListWidgetDelegate::issueCancel()
Expand All @@ -256,7 +294,7 @@ void DownloadListWidgetDelegate::issueResume()

void DownloadListWidgetDelegate::issueDeleteAll()
{
if (QMessageBox::question(nullptr, tr("Are you sure?"),
if (QMessageBox::question(nullptr, tr("Delete Files?"),
tr("This will remove all finished downloads from this list and from disk."),
QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes) {
emit removeDownload(-1, true);
Expand All @@ -265,13 +303,22 @@ void DownloadListWidgetDelegate::issueDeleteAll()

void DownloadListWidgetDelegate::issueDeleteCompleted()
{
if (QMessageBox::question(nullptr, tr("Are you sure?"),
if (QMessageBox::question(nullptr, tr("Delete Files?"),
tr("This will remove all installed downloads from this list and from disk."),
QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes) {
emit removeDownload(-2, true);
}
}

void DownloadListWidgetDelegate::issueDeleteUninstalled()
{
if (QMessageBox::question(nullptr, tr("Delete Files?"),
tr("This will remove all uninstalled downloads from this list and from disk."),
QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes) {
emit removeDownload(-3, true);
}
}

void DownloadListWidgetDelegate::issueRemoveFromViewAll()
{
if (QMessageBox::question(nullptr, tr("Are you sure?"),
Expand All @@ -290,6 +337,15 @@ void DownloadListWidgetDelegate::issueRemoveFromViewCompleted()
}
}

void DownloadListWidgetDelegate::issueRemoveFromViewUninstalled()
{
if (QMessageBox::question(nullptr, tr("Are you sure?"),
tr("This will remove all uninstalled downloads from this list (but NOT from disk)."),
QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes) {
emit removeDownload(-3, false);
}
}

bool DownloadListWidgetDelegate::editorEvent(QEvent *event, QAbstractItemModel *model,
const QStyleOptionViewItem &option, const QModelIndex &index)
{
Expand All @@ -298,7 +354,7 @@ bool DownloadListWidgetDelegate::editorEvent(QEvent *event, QAbstractItemModel *
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;
Expand All @@ -315,7 +371,14 @@ bool DownloadListWidgetDelegate::editorEvent(QEvent *event, QAbstractItemModel *
menu.addAction(tr("Install"), this, SLOT(issueInstall()));
if (m_Manager->isInfoIncomplete(m_ContextRow)) {
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()));
Expand All @@ -325,20 +388,30 @@ bool DownloadListWidgetDelegate::editorEvent(QEvent *event, QAbstractItemModel *
} 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("Remove"), this, SLOT(issueDelete()));
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("Delete"), 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 All..."), this, SLOT(issueRemoveFromViewAll()));
}

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();
Expand Down
9 changes: 9 additions & 0 deletions src/downloadlistwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,18 @@ class DownloadListWidgetDelegate : public QItemDelegate
void cancelDownload(int index);
void pauseDownload(int index);
void resumeDownload(int index);
void visitOnNexus(int index);
void openInDownloadsFolder(int index);

protected:

QString sizeFormat(quint64 size) const;
bool editorEvent(QEvent *event, QAbstractItemModel *model,
const QStyleOptionViewItem &option, const QModelIndex &index);

private:


void drawCache(QPainter *painter, const QStyleOptionViewItem &option, const QPixmap &cache) const;

private slots:
Expand All @@ -87,13 +91,18 @@ private slots:
void issueDelete();
void issueRemoveFromView();
void issueRestoreToView();
void issueRestoreToViewAll();
void issueVisitOnNexus();
void issueOpenInDownloadsFolder();
void issueCancel();
void issuePause();
void issueResume();
void issueDeleteAll();
void issueDeleteCompleted();
void issueDeleteUninstalled();
void issueRemoveFromViewAll();
void issueRemoveFromViewCompleted();
void issueRemoveFromViewUninstalled();
void issueQueryInfo();

void stateChanged(int row, DownloadManager::DownloadState);
Expand Down
3 changes: 3 additions & 0 deletions src/downloadlistwidget.ui
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@
<widget class="QLabel" name="label_2">
<property name="text">
<string notr="true">KB</string>
</property>
<property name="visible">
<bool>false</bool>
</property>
</widget>
</item>
Expand Down
Loading

0 comments on commit 9a3a15b

Please sign in to comment.