summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/downloadmanager.cpp31
-rw-r--r--src/downloadmanager.h4
-rw-r--r--src/organizercore.cpp1
3 files changed, 28 insertions, 8 deletions
diff --git a/src/downloadmanager.cpp b/src/downloadmanager.cpp
index 3143a22e..361e7164 100644
--- a/src/downloadmanager.cpp
+++ b/src/downloadmanager.cpp
@@ -200,8 +200,9 @@ QString DownloadManager::DownloadInfo::currentURL()
}
-DownloadManager::DownloadManager(NexusInterface *nexusInterface, QObject *parent)
- : IDownloadManager(parent), m_NexusInterface(nexusInterface), m_DirWatcher(), m_ShowHidden(false)
+DownloadManager::DownloadManager(NexusInterface *nexusInterface, QObject *parent) :
+ IDownloadManager(parent), m_NexusInterface(nexusInterface), m_DirWatcher(), m_ShowHidden(false),
+ m_ParentWidget(nullptr)
{
m_OrganizerCore = dynamic_cast<OrganizerCore*>(parent);
connect(&m_DirWatcher, SIGNAL(directoryChanged(QString)), this, SLOT(directoryChanged(QString)));
@@ -219,6 +220,10 @@ DownloadManager::~DownloadManager()
m_ActiveDownloads.clear();
}
+void DownloadManager::setParentWidget(QWidget* w)
+{
+ m_ParentWidget = w;
+}
bool DownloadManager::downloadsInProgress()
{
@@ -501,7 +506,7 @@ void DownloadManager::startDownload(QNetworkReply *reply, DownloadInfo *newDownl
if (QFile::exists(m_OutputDirectory + "/" + newDownload->m_FileName)) {
setState(newDownload, STATE_PAUSING);
QCoreApplication::processEvents();
- if (QMessageBox::question(nullptr, tr("Download again?"), tr("A file with the same name \"%1\" has already been downloaded. "
+ if (QMessageBox::question(m_ParentWidget, tr("Download again?"), tr("A file with the same name \"%1\" has already been downloaded. "
"Do you want to download it again? The new file will receive a different name.").arg(newDownload->m_FileName),
QMessageBox::Yes | QMessageBox::No) == QMessageBox::No) {
if (reply->isFinished())
@@ -513,7 +518,7 @@ void DownloadManager::startDownload(QNetworkReply *reply, DownloadInfo *newDownl
newDownload->setName(getDownloadFileName(newDownload->m_FileName, true), true);
endDisableDirWatcher();
if (newDownload->m_State == STATE_PAUSED)
- resumeDownload(indexByName(newDownload->m_FileName));
+ resumeDownload(indexByInfo(newDownload));
else
setState(newDownload, STATE_DOWNLOADING);
}
@@ -527,7 +532,7 @@ void DownloadManager::startDownload(QNetworkReply *reply, DownloadInfo *newDownl
newDownload->m_State != STATE_READY &&
newDownload->m_State != STATE_FETCHINGMODINFO &&
reply->isFinished()) {
- downloadFinished(indexByName(newDownload->m_FileName));
+ downloadFinished(indexByInfo(newDownload));
return;
}
} else
@@ -556,7 +561,7 @@ void DownloadManager::addNXMDownload(const QString &url)
log::debug("add nxm download: {}", url);
if (foundGame == nullptr) {
log::debug("download requested for wrong game (game: {}, url: {})", m_ManagedGame->gameShortName(), nxmInfo.game());
- QMessageBox::information(nullptr, tr("Wrong Game"), tr("The download link is for a mod for \"%1\" but this instance of MO "
+ QMessageBox::information(m_ParentWidget, tr("Wrong Game"), tr("The download link is for a mod for \"%1\" but this instance of MO "
"has been set up for \"%2\".").arg(nxmInfo.game()).arg(m_ManagedGame->gameShortName()), QMessageBox::Ok);
return;
}
@@ -571,7 +576,7 @@ void DownloadManager::addNXMDownload(const QString &url)
"download requested is already queued (mod: {}, file: {})",
nxmInfo.modId(), nxmInfo.fileId());
- QMessageBox::information(nullptr, tr("Already Queued"), infoStr, QMessageBox::Ok);
+ QMessageBox::information(m_ParentWidget, tr("Already Queued"), infoStr, QMessageBox::Ok);
return;
}
}
@@ -615,7 +620,7 @@ void DownloadManager::addNXMDownload(const QString &url)
}
log::debug("{}", debugStr);
- QMessageBox::information(nullptr, tr("Already Started"), infoStr, QMessageBox::Ok);
+ QMessageBox::information(m_ParentWidget, tr("Already Started"), infoStr, QMessageBox::Ok);
return;
}
}
@@ -1738,6 +1743,16 @@ int DownloadManager::indexByName(const QString &fileName) const
return -1;
}
+int DownloadManager::indexByInfo(const DownloadInfo* info) const
+{
+ for (int i = 0; i < m_ActiveDownloads.size(); ++i) {
+ if (m_ActiveDownloads[i] == info) {
+ return i;
+ }
+ }
+ return -1;
+}
+
void DownloadManager::nxmDownloadURLsAvailable(QString gameName, int modID, int fileID, QVariant userData, QVariant resultData, int requestID)
{
std::set<int>::iterator idIter = m_RequestIDs.find(requestID);
diff --git a/src/downloadmanager.h b/src/downloadmanager.h
index bed1b3cc..f2ad15f4 100644
--- a/src/downloadmanager.h
+++ b/src/downloadmanager.h
@@ -137,6 +137,8 @@ public:
~DownloadManager();
+ void setParentWidget(QWidget* w);
+
/**
* @brief determine if a download is currently in progress
*
@@ -368,6 +370,7 @@ public:
* @return index of that download or -1 if it wasn't found
*/
int indexByName(const QString &fileName) const;
+ int indexByInfo(const DownloadInfo* info) const;
void pauseAll();
@@ -529,6 +532,7 @@ private:
NexusInterface *m_NexusInterface;
OrganizerCore *m_OrganizerCore;
+ QWidget* m_ParentWidget;
QVector<std::tuple<QString, int, int>> m_PendingDownloads;
diff --git a/src/organizercore.cpp b/src/organizercore.cpp
index c585ba09..55cb82ff 100644
--- a/src/organizercore.cpp
+++ b/src/organizercore.cpp
@@ -251,6 +251,7 @@ void OrganizerCore::setUserInterface(IUserInterface* ui)
m_InstallationManager.setParentWidget(w);
m_Updater.setUserInterface(w);
m_UILocker.setUserInterface(w);
+ m_DownloadManager.setParentWidget(w);
checkForUpdates();
}