summaryrefslogtreecommitdiff
path: root/src/downloadmanager.cpp
diff options
context:
space:
mode:
authorJeremy Rimpo <jeremy.rimpo@servermonkey.com>2023-09-23 19:00:41 -0500
committerJeremy Rimpo <jeremy.rimpo@servermonkey.com>2023-09-23 19:00:41 -0500
commite22331fa0305d8a0a2b8b6d37203dac1ed3524e9 (patch)
tree3231affb718494c342fc6197bae2b784fde9fd21 /src/downloadmanager.cpp
parent31a85a3db5fcb34b36dc6ed6f56a351a5dcb319a (diff)
Restructure category refresh action
- Remove plugins class - Route signals to run Nexus API call from MainWindow - Pass Dialog instance to route response data - Revert CategoryFactory::instance to return reference
Diffstat (limited to 'src/downloadmanager.cpp')
-rw-r--r--src/downloadmanager.cpp37
1 files changed, 20 insertions, 17 deletions
diff --git a/src/downloadmanager.cpp b/src/downloadmanager.cpp
index 3c9e776e..d7a72c0b 100644
--- a/src/downloadmanager.cpp
+++ b/src/downloadmanager.cpp
@@ -153,6 +153,20 @@ DownloadManager::DownloadInfo::createFromMeta(const QString& filePath, bool show
return info;
}
+ScopedDisableDirWatcher::ScopedDisableDirWatcher(DownloadManager* downloadManager)
+{
+ m_downloadManager = downloadManager;
+ m_downloadManager->startDisableDirWatcher();
+ log::debug("Scoped Disable DirWatcher: Started");
+}
+
+ScopedDisableDirWatcher::~ScopedDisableDirWatcher()
+{
+ m_downloadManager->endDisableDirWatcher();
+ m_downloadManager = nullptr;
+ log::debug("Scoped Disable DirWatcher: Stopped");
+}
+
void DownloadManager::startDisableDirWatcher()
{
DownloadManager::m_DirWatcherDisabler++;
@@ -317,10 +331,9 @@ void DownloadManager::refreshList()
{
TimeThis tt("DownloadManager::refreshList()");
+ // avoid triggering other refreshes
+ ScopedDisableDirWatcher scopedDirWatcher(this);
try {
- // avoid triggering other refreshes
- startDisableDirWatcher();
-
int downloadsBefore = m_ActiveDownloads.size();
// remove finished downloads
@@ -419,10 +432,7 @@ void DownloadManager::refreshList()
log::debug("saw {} downloads", m_ActiveDownloads.size());
- emit update(-1);
-
- // let watcher trigger refreshes again
- endDisableDirWatcher();
+ emit update(-1);
} catch (const std::bad_alloc&) {
reportError(tr("Memory allocation error (in refreshing directory)."));
@@ -758,7 +768,7 @@ void DownloadManager::addNXMDownload(const QString& url)
void DownloadManager::removeFile(int index, bool deleteFile)
{
// Avoid triggering refreshes from DirWatcher
- startDisableDirWatcher();
+ ScopedDisableDirWatcher scopedDirWatcher(this);
if (index >= m_ActiveDownloads.size()) {
throw MyException(tr("remove: invalid download index %1").arg(index));
@@ -770,7 +780,6 @@ void DownloadManager::removeFile(int index, bool deleteFile)
(download->m_State == STATE_DOWNLOADING)) {
// shouldn't have been possible
log::error("tried to remove active download");
- endDisableDirWatcher();
return;
}
@@ -781,7 +790,6 @@ void DownloadManager::removeFile(int index, bool deleteFile)
if (deleteFile) {
if (!shellDelete(QStringList(filePath), true)) {
reportError(tr("failed to delete %1").arg(filePath));
- endDisableDirWatcher();
return;
}
@@ -795,8 +803,6 @@ void DownloadManager::removeFile(int index, bool deleteFile)
metaSettings.setValue("removed", true);
}
m_DownloadRemoved(index);
-
- endDisableDirWatcher();
}
class LessThanWrapper
@@ -1449,15 +1455,13 @@ void DownloadManager::markInstalled(int index)
}
// Avoid triggering refreshes from DirWatcher
- startDisableDirWatcher();
+ ScopedDisableDirWatcher scopedDirWatcher(this);
DownloadInfo* info = m_ActiveDownloads.at(index);
QSettings metaFile(info->m_Output.fileName() + ".meta", QSettings::IniFormat);
metaFile.setValue("installed", true);
metaFile.setValue("uninstalled", false);
- endDisableDirWatcher();
-
setState(m_ActiveDownloads.at(index), STATE_INSTALLED);
}
@@ -1686,7 +1690,7 @@ void DownloadManager::downloadReadyRead()
void DownloadManager::createMetaFile(DownloadInfo* info)
{
// Avoid triggering refreshes from DirWatcher
- startDisableDirWatcher();
+ ScopedDisableDirWatcher scopedDirWatcher(this);
QSettings metaFile(QString("%1.meta").arg(info->m_Output.fileName()),
QSettings::IniFormat);
@@ -1710,7 +1714,6 @@ void DownloadManager::createMetaFile(DownloadInfo* info)
(info->m_State == DownloadManager::STATE_ERROR));
metaFile.setValue("removed", info->m_Hidden);
- endDisableDirWatcher();
// slightly hackish...
for (int i = 0; i < m_ActiveDownloads.size(); ++i) {
if (m_ActiveDownloads[i] == info) {