summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/downloadmanager.cpp31
-rw-r--r--src/downloadmanager.h21
2 files changed, 46 insertions, 6 deletions
diff --git a/src/downloadmanager.cpp b/src/downloadmanager.cpp
index 3e6010db..5db0cbdf 100644
--- a/src/downloadmanager.cpp
+++ b/src/downloadmanager.cpp
@@ -694,6 +694,7 @@ void DownloadManager::removeFile(int index, bool deleteFile)
if(!download->m_Hidden)
metaSettings.setValue("removed", true);
}
+ m_DownloadRemoved(index);
endDisableDirWatcher();
}
@@ -1453,13 +1454,19 @@ void DownloadManager::setState(DownloadManager::DownloadInfo *info, DownloadMana
}
info->m_State = state;
switch (state) {
- case STATE_PAUSED:
+ case STATE_PAUSED: {
+ info->m_Reply->abort();
+ info->m_Output.close();
+ m_DownloadPaused(row);
+ } break;
case STATE_ERROR: {
info->m_Reply->abort();
info->m_Output.close();
+ m_DownloadFailed(row);
} break;
case STATE_CANCELED: {
info->m_Reply->abort();
+ m_DownloadFailed(row);
} break;
case STATE_FETCHINGMODINFO: {
m_RequestIDs.insert(m_NexusInterface->requestDescription(info->m_FileInfo->gameName, info->m_FileInfo->modID, this, info->m_DownloadID, QString()));
@@ -1473,7 +1480,7 @@ void DownloadManager::setState(DownloadManager::DownloadInfo *info, DownloadMana
} break;
case STATE_READY: {
createMetaFile(info);
- emit downloadComplete(row);
+ m_DownloadComplete(row);
} break;
default: /* NOP */ break;
}
@@ -1792,6 +1799,26 @@ QString DownloadManager::downloadPath(int id)
return getFilePath(id);
}
+bool DownloadManager::onDownloadComplete(const std::function<void(int)>& callback)
+{
+ return m_DownloadComplete.connect(callback).connected();
+}
+
+bool DownloadManager::onDownloadPaused(const std::function<void(int)>& callback)
+{
+ return m_DownloadPaused.connect(callback).connected();
+}
+
+bool DownloadManager::onDownloadFailed(const std::function<void(int)>& callback)
+{
+ return m_DownloadFailed.connect(callback).connected();
+}
+
+bool DownloadManager::onDownloadRemoved(const std::function<void(int)>& callback)
+{
+ return m_DownloadRemoved.connect(callback).connected();
+}
+
int DownloadManager::indexByName(const QString &fileName) const
{
for (int i = 0; i < m_ActiveDownloads.size(); ++i) {
diff --git a/src/downloadmanager.h b/src/downloadmanager.h
index 90def927..8a0d8eed 100644
--- a/src/downloadmanager.h
+++ b/src/downloadmanager.h
@@ -37,6 +37,7 @@ along with Mod Organizer. If not, see <http://www.gnu.org/licenses/>.
#include <QStringList>
#include <QFileSystemWatcher>
#include <QSettings>
+#include <boost/signals2.hpp>
namespace MOBase { class IPluginGame; }
@@ -126,6 +127,8 @@ private:
DownloadInfo() : m_TotalSize(0), m_ReQueried(false), m_Hidden(false), m_SpeedDiff(std::tuple<int,int,int,int,int>(0,0,0,0,0)), m_HasData(false) {}
};
+ using SignalDownloadCallback = boost::signals2::signal<void(int)>;
+
public:
/**
@@ -367,11 +370,16 @@ public:
*/
void refreshList();
- virtual int startDownloadURLs(const QStringList &urls);
+public: // IDownloadManager interface:
- virtual int startDownloadNexusFile(int modID, int fileID);
+ int startDownloadURLs(const QStringList &urls) override;
+ int startDownloadNexusFile(int modID, int fileID) override;
+ QString downloadPath(int id) override;
- virtual QString downloadPath(int id);
+ bool onDownloadComplete(const std::function<void(int)>& callback) override;
+ bool onDownloadPaused(const std::function<void(int)>& callback) override;
+ bool onDownloadFailed(const std::function<void(int)>& callback) override;
+ bool onDownloadRemoved(const std::function<void(int)>& callback) override;
/**
* @brief retrieve a download index from the filename
@@ -383,7 +391,7 @@ public:
void pauseAll();
-signals:
+Q_SIGNALS:
void aboutToUpdate();
@@ -556,6 +564,11 @@ private:
QFileSystemWatcher m_DirWatcher;
+ SignalDownloadCallback m_DownloadComplete;
+ SignalDownloadCallback m_DownloadPaused;
+ SignalDownloadCallback m_DownloadFailed;
+ SignalDownloadCallback m_DownloadRemoved;
+
//The dirWatcher is actually triggering off normal Mo operations such as deleting downloads or editing .meta files
//so it needs to be disabled during operations that are known to cause the creation or deletion of files in the Downloads folder.
//Notably using QSettings to edit a file creates a temporarily .lock file that causes the Watcher to trigger multiple listRefreshes freezing the ui.