From 186f26b71e4597e9999a3d946b0d9497255fc986 Mon Sep 17 00:00:00 2001 From: Al12rs Date: Mon, 21 May 2018 01:27:13 +0200 Subject: Added un-hide all option to downlods tab. Improved performace when hiding/unhiding. There is still room for improvement for hiding but it requires refactoring the function --- src/downloadmanager.cpp | 40 ++++++++++++++++++++++++++++------------ 1 file changed, 28 insertions(+), 12 deletions(-) (limited to 'src/downloadmanager.cpp') diff --git a/src/downloadmanager.cpp b/src/downloadmanager.cpp index 6cd86ece..93a46d78 100644 --- a/src/downloadmanager.cpp +++ b/src/downloadmanager.cpp @@ -645,22 +645,38 @@ void DownloadManager::refreshAlphabeticalTranslation() void DownloadManager::restoreDownload(int index) { - if ((index < 0) || (index >= m_ActiveDownloads.size())) { - throw MyException(tr("restore: invalid download index: %1").arg(index)); - } - DownloadInfo *download = m_ActiveDownloads.at(index); - download->m_Hidden = false; + if (index < 0) { + DownloadState minState = STATE_READY ; + index = 0; - QString filePath = m_OutputDirectory + "/" + download->m_FileName; + for (QVector::const_iterator iter = m_ActiveDownloads.begin(); iter != m_ActiveDownloads.end(); ++iter ) { + + if ((*iter)->m_State >= minState) { + restoreDownload(index); + } + index++; + } + } + else { + if (index >= m_ActiveDownloads.size()) { + throw MyException(tr("restore: invalid download index: %1").arg(index)); + } - //avoid dirWatcher triggering refreshes - startDisableDirWatcher(); + DownloadInfo *download = m_ActiveDownloads.at(index); + if (download->m_Hidden) { + download->m_Hidden = false; - QSettings metaSettings(filePath.append(".meta"), QSettings::IniFormat); - metaSettings.setValue("removed", false); + QString filePath = m_OutputDirectory + "/" + download->m_FileName; - endDisableDirWatcher(); + //avoid dirWatcher triggering refreshes + startDisableDirWatcher(); + QSettings metaSettings(filePath.append(".meta"), QSettings::IniFormat); + metaSettings.setValue("removed", false); + + endDisableDirWatcher(); + } + } } @@ -680,7 +696,7 @@ void DownloadManager::removeDownload(int index, bool deleteFile) removeFile(index, deleteFile); delete *iter; iter = m_ActiveDownloads.erase(iter); - QCoreApplication::processEvents(); + //QCoreApplication::processEvents(); } else { ++iter; -- cgit v1.3.1