From f44663d795b5ba4adb9b11474f21337de12a9af5 Mon Sep 17 00:00:00 2001 From: isanae <14251494+isanae@users.noreply.github.com> Date: Wed, 10 Jul 2019 21:43:31 -0400 Subject: handle context menu on pending downloads --- src/downloadlistwidget.cpp | 69 ++++++++++++++++++++++++++-------------------- 1 file changed, 39 insertions(+), 30 deletions(-) (limited to 'src/downloadlistwidget.cpp') diff --git a/src/downloadlistwidget.cpp b/src/downloadlistwidget.cpp index c75ecdd2..e2a6f321 100644 --- a/src/downloadlistwidget.cpp +++ b/src/downloadlistwidget.cpp @@ -201,40 +201,49 @@ void DownloadListWidget::onCustomContextMenu(const QPoint &point) QModelIndex index = indexAt(point); bool hidden = false; - if (index.row() >= 0) { - m_ContextRow = qobject_cast(model())->mapToSource(index).row(); - DownloadManager::DownloadState state = m_Manager->getState(m_ContextRow); - hidden = m_Manager->isHidden(m_ContextRow); - - if (state >= DownloadManager::STATE_READY) { - menu.addAction(tr("Install"), this, SLOT(issueInstall())); - if (m_Manager->isInfoIncomplete(m_ContextRow)) - menu.addAction(tr("Query Info"), this, SLOT(issueQueryInfoMd5())); - else - menu.addAction(tr("Visit on Nexus"), this, SLOT(issueVisitOnNexus())); - menu.addAction(tr("Open File"), this, SLOT(issueOpenFile())); - menu.addAction(tr("Show in Folder"), this, SLOT(issueOpenInDownloadsFolder())); + try + { + if (index.row() >= 0) { + m_ContextRow = qobject_cast(model())->mapToSource(index).row(); + DownloadManager::DownloadState state = m_Manager->getState(m_ContextRow); + + hidden = m_Manager->isHidden(m_ContextRow); + + if (state >= DownloadManager::STATE_READY) { + menu.addAction(tr("Install"), this, SLOT(issueInstall())); + if (m_Manager->isInfoIncomplete(m_ContextRow)) + menu.addAction(tr("Query Info"), this, SLOT(issueQueryInfoMd5())); + else + menu.addAction(tr("Visit on Nexus"), this, SLOT(issueVisitOnNexus())); + menu.addAction(tr("Open File"), this, SLOT(issueOpenFile())); + menu.addAction(tr("Show in Folder"), this, SLOT(issueOpenInDownloadsFolder())); - menu.addSeparator(); + menu.addSeparator(); - menu.addAction(tr("Delete"), this, SLOT(issueDelete())); - if (hidden) - menu.addAction(tr("Un-Hide"), this, SLOT(issueRestoreToView())); - else - menu.addAction(tr("Hide"), this, SLOT(issueRemoveFromView())); - } else if (state == DownloadManager::STATE_DOWNLOADING) { - menu.addAction(tr("Cancel"), this, SLOT(issueCancel())); - menu.addAction(tr("Pause"), this, SLOT(issuePause())); - 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.addAction(tr("Delete"), this, SLOT(issueDelete())); + if (hidden) + menu.addAction(tr("Un-Hide"), this, SLOT(issueRestoreToView())); + else + menu.addAction(tr("Hide"), this, SLOT(issueRemoveFromView())); + } else if (state == DownloadManager::STATE_DOWNLOADING) { + menu.addAction(tr("Cancel"), this, SLOT(issueCancel())); + menu.addAction(tr("Pause"), this, SLOT(issuePause())); + 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.addSeparator(); + } + } catch(std::exception&) + { + // this happens when the download index is not found, ignore it and don't + // display download-specific actions } + menu.addAction(tr("Delete Installed Downloads..."), this, SLOT(issueDeleteCompleted())); menu.addAction(tr("Delete Uninstalled Downloads..."), this, SLOT(issueDeleteUninstalled())); menu.addAction(tr("Delete All Downloads..."), this, SLOT(issueDeleteAll())); -- cgit v1.3.1