add remove fct with aria2

This commit is contained in:
luddens 2019-04-29 17:29:42 +02:00 committed by Matthieu Gautier
parent ec8f1ffe9c
commit 491b6d655b
4 changed files with 20 additions and 0 deletions

View File

@ -56,6 +56,7 @@ class Download {
void updateStatus(bool follow=false); void updateStatus(bool follow=false);
void pauseDownload(); void pauseDownload();
void resumeDownload(); void resumeDownload();
void cancelDownload();
StatusResult getStatus() { return m_status; } StatusResult getStatus() { return m_status; }
std::string getDid() { return m_did; } std::string getDid() { return m_did; }
std::string getFollowedBy() { return m_followedBy; } std::string getFollowedBy() { return m_followedBy; }

View File

@ -233,4 +233,11 @@ void Aria2::unpause(const std::string& gid)
doRequest(methodCall); doRequest(methodCall);
} }
void Aria2::remove(const std::string& gid)
{
MethodCall methodCall("aria2.remove", m_secret);
methodCall.newParamValue().set(gid);
doRequest(methodCall);
}
} // end namespace kiwix } // end namespace kiwix

View File

@ -42,6 +42,7 @@ class Aria2
void shutdown(); void shutdown();
void pause(const std::string& gid); void pause(const std::string& gid);
void unpause(const std::string& gid); void unpause(const std::string& gid);
void remove(const std::string& gid);
}; };
}; //end namespace kiwix }; //end namespace kiwix

View File

@ -36,6 +36,8 @@ namespace kiwix
void Download::updateStatus(bool follow) void Download::updateStatus(bool follow)
{ {
if (m_status == Download::K_REMOVED)
return;
static std::vector<std::string> statusKey = {"status", "files", "totalLength", static std::vector<std::string> statusKey = {"status", "files", "totalLength",
"completedLength", "followedBy", "completedLength", "followedBy",
"downloadSpeed", "verifiedLength"}; "downloadSpeed", "verifiedLength"};
@ -111,6 +113,15 @@ void Download::pauseDownload()
updateStatus(true); updateStatus(true);
} }
void Download::cancelDownload()
{
if (!m_followedBy.empty())
mp_aria->remove(m_followedBy);
else
mp_aria->remove(m_did);
m_status = Download::K_REMOVED;
}
/* Constructor */ /* Constructor */
Downloader::Downloader() : Downloader::Downloader() :
mp_aria(new Aria2()) mp_aria(new Aria2())