summaryrefslogtreecommitdiff
path: root/src/downloadmanager.cpp
diff options
context:
space:
mode:
authorAl12rs <gabriel.cortesi@outlook.com>2018-05-17 00:01:54 +0200
committerAl12rs <gabriel.cortesi@outlook.com>2018-05-17 00:03:10 +0200
commit8731159bfbaa34c431343b4e415590ae079a24bb (patch)
tree05ad6d57458c5c98d7b8d01364a1e5e5e09e6f53 /src/downloadmanager.cpp
parent1c6543454ef4d3b84e2ce1f6928b6c99005eee29 (diff)
Huge performace improvements for downloads tab by disabling the dirWatcher triggered refreshes.
Avoid app freezes caused by stacked refresh calls. Added chack to see if a download is alerady hidden before trying to hide it. Made sure to refresh Download tab where it was othwerwise relying in the dirwatcher to refresh.
Diffstat (limited to 'src/downloadmanager.cpp')
-rw-r--r--src/downloadmanager.cpp50
1 files changed, 30 insertions, 20 deletions
diff --git a/src/downloadmanager.cpp b/src/downloadmanager.cpp
index ea8253be..6cd86ece 100644
--- a/src/downloadmanager.cpp
+++ b/src/downloadmanager.cpp
@@ -54,6 +54,7 @@ using namespace MOBase;
static const char UNFINISHED[] = ".unfinished";
unsigned int DownloadManager::DownloadInfo::s_NextDownloadID = 1U;
+int DownloadManager::m_DirWatcherDisabler = 0;
DownloadManager::DownloadInfo *DownloadManager::DownloadInfo::createNew(const ModRepositoryFileInfo *fileInfo, const QStringList &URLs)
@@ -142,6 +143,25 @@ DownloadManager::DownloadInfo *DownloadManager::DownloadInfo::createFromMeta(con
return info;
}
+void DownloadManager::startDisableDirWatcher()
+{
+ DownloadManager::m_DirWatcherDisabler++;
+}
+
+
+void DownloadManager::endDisableDirWatcher()
+{
+ if (DownloadManager::m_DirWatcherDisabler > 0)
+ {
+ if (DownloadManager::m_DirWatcherDisabler == 1)
+ QCoreApplication::processEvents();
+ DownloadManager::m_DirWatcherDisabler--;
+ }
+ else {
+ DownloadManager::m_DirWatcherDisabler = 0;
+ }
+}
+
void DownloadManager::DownloadInfo::setName(QString newName, bool renameFile)
{
QString oldMetaFileName = QString("%1.meta").arg(m_FileName);
@@ -180,7 +200,7 @@ QString DownloadManager::DownloadInfo::currentURL()
DownloadManager::DownloadManager(NexusInterface *nexusInterface, QObject *parent)
- : IDownloadManager(parent), m_NexusInterface(nexusInterface), m_DirWatcher(), m_DirWatcherDisabler(0), m_ShowHidden(false),
+ : IDownloadManager(parent), m_NexusInterface(nexusInterface), m_DirWatcher(), m_ShowHidden(false),
m_DateExpression("/Date\\((\\d+)\\)/")
{
connect(&m_DirWatcher, SIGNAL(directoryChanged(QString)), this, SLOT(directoryChanged(QString)));
@@ -280,20 +300,7 @@ void DownloadManager::setPluginContainer(PluginContainer *pluginContainer)
}
-void DownloadManager::startDisableDirWatcher()
-{
- m_DirWatcherDisabler++;
-}
-
-void DownloadManager::endDisableDirWatcher()
-{
- QCoreApplication::processEvents();
- if (m_DirWatcherDisabler > 0)
- m_DirWatcherDisabler--;
- else
- m_DirWatcherDisabler = 0;
-}
@@ -359,9 +366,9 @@ void DownloadManager::refreshList()
}
}
- if (m_ActiveDownloads.size() != downloadsBefore) {
+ //if (m_ActiveDownloads.size() != downloadsBefore) {
qDebug("downloads after refresh: %d", m_ActiveDownloads.size());
- }
+ //}
emit update(-1);
//let watcher trigger refreshes again
@@ -597,9 +604,10 @@ void DownloadManager::removeFile(int index, bool deleteFile)
}
} else {
QSettings metaSettings(filePath.append(".meta"), QSettings::IniFormat);
- metaSettings.setValue("removed", true);
+ if(!download->m_Hidden)
+ metaSettings.setValue("removed", true);
}
-
+
endDisableDirWatcher();
}
@@ -682,6 +690,7 @@ void DownloadManager::removeDownload(int index, bool deleteFile)
} else {
if (index >= m_ActiveDownloads.size()) {
reportError(tr("remove: invalid download index %1").arg(index));
+ //emit update(-1);
endDisableDirWatcher();
return;
}
@@ -690,11 +699,12 @@ void DownloadManager::removeDownload(int index, bool deleteFile)
delete m_ActiveDownloads.at(index);
m_ActiveDownloads.erase(m_ActiveDownloads.begin() + index);
}
- endDisableDirWatcher();
emit update(-1);
+ endDisableDirWatcher();
} catch (const std::exception &e) {
qCritical("failed to remove download: %s", e.what());
}
+ refreshList();
}
@@ -1710,7 +1720,7 @@ void DownloadManager::metaDataChanged()
void DownloadManager::directoryChanged(const QString&)
{
- if(m_DirWatcherDisabler==0)
+ if(DownloadManager::m_DirWatcherDisabler==0)
refreshList();
}