pause/resume/retry links
This commit is contained in:
@ -11,6 +11,8 @@ import com.muwire.core.InfoHash;
|
||||
import com.muwire.core.download.DownloadStartedEvent;
|
||||
import com.muwire.core.download.Downloader;
|
||||
import com.muwire.core.download.UIDownloadCancelledEvent;
|
||||
import com.muwire.core.download.UIDownloadPausedEvent;
|
||||
import com.muwire.core.download.UIDownloadResumedEvent;
|
||||
|
||||
public class DownloadManager {
|
||||
private final Core core;
|
||||
@ -42,5 +44,32 @@ public class DownloadManager {
|
||||
UIDownloadCancelledEvent event = new UIDownloadCancelledEvent();
|
||||
event.setDownloader(d);
|
||||
core.getEventBus().publish(event);
|
||||
delay();
|
||||
}
|
||||
|
||||
private static void delay() {
|
||||
try {
|
||||
Thread.sleep(100);
|
||||
} catch (InterruptedException e) {}
|
||||
}
|
||||
|
||||
void pause(InfoHash infoHash) {
|
||||
Downloader d = downloaders.get(infoHash);
|
||||
if (d == null)
|
||||
return;
|
||||
d.pause();
|
||||
UIDownloadPausedEvent event = new UIDownloadPausedEvent();
|
||||
core.getEventBus().publish(event);
|
||||
delay();
|
||||
}
|
||||
|
||||
void resume(InfoHash infoHash) {
|
||||
Downloader d = downloaders.get(infoHash);
|
||||
if (d == null)
|
||||
return;
|
||||
d.resume();
|
||||
UIDownloadResumedEvent event = new UIDownloadResumedEvent();
|
||||
core.getEventBus().publish(event);
|
||||
delay();
|
||||
}
|
||||
}
|
||||
|
@ -132,6 +132,18 @@ public class DownloadServlet extends HttpServlet {
|
||||
return;
|
||||
}
|
||||
downloadManager.cancel(infoHash);
|
||||
} else if (action.equals("pause")) {
|
||||
if (core == null) {
|
||||
resp.sendError(403, "Not initialized");
|
||||
return;
|
||||
}
|
||||
downloadManager.pause(infoHash);
|
||||
} else if (action.equals("resume")) {
|
||||
if (core == null) {
|
||||
resp.sendError(403, "Not initialized");
|
||||
return;
|
||||
}
|
||||
downloadManager.resume(infoHash);
|
||||
}
|
||||
// P-R-G
|
||||
resp.sendRedirect("/MuWire/Downloads");
|
||||
|
@ -48,6 +48,7 @@ public class Util {
|
||||
_x("Mark Neutral"),
|
||||
_x("Mark Trusted"),
|
||||
_x("Name"),
|
||||
_x("Pause"),
|
||||
_x("Progress"),
|
||||
_x("Query"),
|
||||
_x("Reason"),
|
||||
@ -55,6 +56,8 @@ public class Util {
|
||||
_x("Results"),
|
||||
_x("Results for {0}"),
|
||||
_x("Results from {0}"),
|
||||
_x("Resume"),
|
||||
_x("Retry"),
|
||||
_x("Save"),
|
||||
_x("Search"),
|
||||
_x("Sender"),
|
||||
|
@ -15,12 +15,13 @@ class Downloader {
|
||||
mapping.set("Speed", this.speed)
|
||||
mapping.set("ETA", this.ETA)
|
||||
mapping.set("Progress", this.progress)
|
||||
mapping.set("Cancel", this.getCancelBlock())
|
||||
return mapping
|
||||
}
|
||||
|
||||
getNameBlock() {
|
||||
return "<a href='#' onclick='window.updateDownloader(\"" + this.infoHash + "\");return false'>" + this.name + "</a>"
|
||||
var html = "<a href='#' onclick='window.updateDownloader(\"" + this.infoHash + "\");return false'>" + this.name + "</a>"
|
||||
html += "<div>" + this.getCancelBlock() + " " + this.getPauseResumeRetryBlock() + "</div>"
|
||||
return html
|
||||
}
|
||||
|
||||
getCancelBlock() {
|
||||
@ -31,11 +32,50 @@ class Downloader {
|
||||
var block = "<span id='download-" + this.infoHash + "'>" + link + "</span>"
|
||||
return block
|
||||
}
|
||||
|
||||
getPauseResumeRetryBlock() {
|
||||
if (this.state == "FINISHED" || this.state == "CANCELLED")
|
||||
return ""
|
||||
if (this.state == "FAILED") {
|
||||
var retryLink = new Link(_t("Retry"), "resumeDownload", [this.infoHash])
|
||||
return retryLink.render()
|
||||
} else if (this.state == "PAUSED") {
|
||||
var resumeLink = new Link(_t("Resume"), "resumeDownload", [this.infoHash])
|
||||
return resumeLink.render()
|
||||
} else {
|
||||
var pauseLink = new Link(_t("Pause"), "pauseDownload", [this.infoHash])
|
||||
return pauseLink.render()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var downloader = null;
|
||||
var downloaders = new Map()
|
||||
|
||||
function resumeDownload(infoHash) {
|
||||
var xmlhttp = new XMLHttpRequest()
|
||||
xmlhttp.onreadystatechange = function() {
|
||||
if (this.readyState == 4 && this.status == 200) {
|
||||
refreshDownloader()
|
||||
}
|
||||
}
|
||||
xmlhttp.open("POST", "/MuWire/Download", "true")
|
||||
xmlhttp.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
|
||||
xmlhttp.send(encodeURI("action=resume&infoHash=" + infoHash))
|
||||
}
|
||||
|
||||
function pauseDownload(infoHash) {
|
||||
var xmlhttp = new XMLHttpRequest()
|
||||
xmlhttp.onreadystatechange = function() {
|
||||
if (this.readyState == 4 && this.status == 200) {
|
||||
refreshDownloader()
|
||||
}
|
||||
}
|
||||
xmlhttp.open("POST", "/MuWire/Download", "true")
|
||||
xmlhttp.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
|
||||
xmlhttp.send(encodeURI("action=pause&infoHash=" + infoHash))
|
||||
}
|
||||
|
||||
function cancelDownload(infoHash) {
|
||||
var xmlhttp = new XMLHttpRequest();
|
||||
xmlhttp.onreadystatechange = function() {
|
||||
@ -78,7 +118,7 @@ function refreshDownloader() {
|
||||
newOrder = "ascending"
|
||||
else if (downloadsSortOrder == "ascending")
|
||||
newOrder = "descending"
|
||||
var table = new Table(["Name","State","Speed","ETA","Progress","Cancel"], "sortDownloads", downloadsSortKey, newOrder, null)
|
||||
var table = new Table(["Name","State","Speed","ETA","Progress"], "sortDownloads", downloadsSortKey, newOrder, null)
|
||||
|
||||
for(i = 0; i < downloaderList.length; i++) {
|
||||
table.addRow(downloaderList[i].getMapping())
|
||||
|
Reference in New Issue
Block a user