summaryrefslogtreecommitdiff
path: root/src/downloadmanager.cpp
diff options
context:
space:
mode:
authorTannin <devnull@localhost>2014-01-04 15:57:14 +0100
committerTannin <devnull@localhost>2014-01-04 15:57:14 +0100
commit4dc3538a7d14dd0f1aaa2e6c172745b63e251c86 (patch)
tree2242c92482306c5710b00dfb212cce11456e776d /src/downloadmanager.cpp
parent14ac234daf1680b0685f6bea3e74aa09dfcf38ef (diff)
- nxmhandler will now ask before registering itself
- downloads from nexus are now displayed before file information is retrieved - logging from the ui is now a bit more informative - download list now scrolls to bottom automatically
Diffstat (limited to 'src/downloadmanager.cpp')
-rw-r--r--src/downloadmanager.cpp49
1 files changed, 45 insertions, 4 deletions
diff --git a/src/downloadmanager.cpp b/src/downloadmanager.cpp
index 48484d24..61c5113c 100644
--- a/src/downloadmanager.cpp
+++ b/src/downloadmanager.cpp
@@ -323,6 +323,7 @@ bool DownloadManager::addDownload(QNetworkReply *reply, const QStringList &URLs,
(QMessageBox::question(NULL, tr("Download again?"), tr("A file with the same name has already been downloaded. "
"Do you want to download it again? The new file will receive a different name."),
QMessageBox::Yes | QMessageBox::No) == QMessageBox::No)) {
+ removePending(modID, fileID);
delete newDownload;
return false;
}
@@ -331,11 +332,24 @@ bool DownloadManager::addDownload(QNetworkReply *reply, const QStringList &URLs,
startDownload(reply, newDownload, false);
- emit update(-1);
+// emit update(-1);
return true;
}
+void DownloadManager::removePending(int modID, int fileID)
+{
+ emit aboutToUpdate();
+ for (auto iter = m_PendingDownloads.begin(); iter != m_PendingDownloads.end(); ++iter) {
+ if ((iter->first == modID) && (iter->second == fileID)) {
+ m_PendingDownloads.erase(iter);
+ break;
+ }
+ }
+ emit update(-1);
+}
+
+
void DownloadManager::startDownload(QNetworkReply *reply, DownloadInfo *newDownload, bool resume)
{
newDownload->m_Reply = reply;
@@ -365,11 +379,14 @@ void DownloadManager::startDownload(QNetworkReply *reply, DownloadInfo *newDownl
if (!resume) {
newDownload->m_PreResumeSize = newDownload->m_Output.size();
+ removePending(newDownload->m_ModID, newDownload->m_FileID);
+
emit aboutToUpdate();
m_ActiveDownloads.append(newDownload);
emit update(-1);
+ emit downloadAdded();
}
}
@@ -379,14 +396,21 @@ void DownloadManager::addNXMDownload(const QString &url)
NXMUrl nxmInfo(url);
QString managedGame = ToQString(MOShared::GameInfo::instance().getGameShortName());
-
+ qDebug("add nxm download", qPrintable(url));
if (nxmInfo.game().compare(managedGame, Qt::CaseInsensitive) != 0) {
+ qDebug("download requested for wrong game (game: %s, url: %s)", qPrintable(managedGame), qPrintable(nxmInfo.game()));
QMessageBox::information(NULL, 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(managedGame), QMessageBox::Ok);
return;
}
- m_RequestIDs.insert(m_NexusInterface->requestFileInfo(nxmInfo.getModId(), nxmInfo.getFileId(), this, QVariant()));
+ emit aboutToUpdate();
+
+ m_PendingDownloads.append(std::make_pair(nxmInfo.modId(), nxmInfo.fileId()));
+
+ emit update(-1);
+ emit downloadAdded();
+ m_RequestIDs.insert(m_NexusInterface->requestFileInfo(nxmInfo.modId(), nxmInfo.fileId(), this, QVariant()));
}
@@ -628,6 +652,19 @@ int DownloadManager::numTotalDownloads() const
return m_ActiveDownloads.size();
}
+int DownloadManager::numPendingDownloads() const
+{
+ return m_PendingDownloads.size();
+}
+
+std::pair<int, int> DownloadManager::getPendingDownload(int index)
+{
+ if ((index < 0) || (index >= m_PendingDownloads.size())) {
+ throw MyException(tr("invalid index"));
+ }
+
+ return m_PendingDownloads.at(index);
+}
QString DownloadManager::getFilePath(int index) const
{
@@ -1025,8 +1062,8 @@ void DownloadManager::nxmFileInfoAvailable(int modID, int fileID, QVariant userD
NexusInfo info;
QVariantMap result = resultData.toMap();
-
info.m_Name = result["name"].toString();
+ qDebug("file info received for %s", qPrintable(info.m_Name));
info.m_Version = result["version"].toString();
if (info.m_Version.isEmpty()) {
info.m_Version = info.m_NewestVersion;
@@ -1121,9 +1158,12 @@ void DownloadManager::nxmDownloadURLsAvailable(int modID, int fileID, QVariant u
m_RequestIDs.erase(idIter);
}
+ qDebug("download urls received (modid %d, fileid %d)", modID, fileID);
+
NexusInfo info = userData.value<NexusInfo>();
QVariantList resultList = resultData.toList();
if (resultList.length() == 0) {
+ removePending(modID, fileID);
emit showMessage(tr("No download server available. Please try again later."));
return;
}
@@ -1282,3 +1322,4 @@ void DownloadManager::directoryChanged(const QString&)
{
refreshList();
}
+