retry implemented

This commit is contained in:
Zlatin Balevsky
2019-06-01 18:30:30 +01:00
parent 98ea8154a5
commit 13b3f0f63b
4 changed files with 21 additions and 4 deletions

View File

@ -28,10 +28,14 @@ public class DownloadManager {
public void onUIDownloadEvent(UIDownloadEvent e) {
def downloader = new Downloader(e.target, e.result.size,
def downloader = new Downloader(this, e.target, e.result.size,
e.result.infohash, e.result.pieceSize, connector, e.result.sender.destination,
incompletes)
executor.execute({downloader.download()} as Runnable)
eventBus.publish(new DownloadStartedEvent(downloader : downloader))
}
void resume(Downloader downloader) {
executor.execute({downloader.download() as Runnable})
}
}

View File

@ -14,7 +14,8 @@ import net.i2p.data.Destination
@Log
public class Downloader {
public enum DownloadState { CONNECTING, DOWNLOADING, FAILED, CANCELLED, FINISHED }
private final DownloadManager downloadManager
private final File file
private final Pieces pieces
private final long length
@ -31,8 +32,10 @@ public class Downloader {
private volatile boolean cancelled
private volatile Thread downloadThread
public Downloader(File file, long length, InfoHash infoHash, int pieceSizePow2, I2PConnector connector, Destination destination,
public Downloader(DownloadManager downloadManager, File file, long length, InfoHash infoHash,
int pieceSizePow2, I2PConnector connector, Destination destination,
File incompletes) {
this.downloadManager = downloadManager
this.file = file
this.infoHash = infoHash
this.length = length
@ -112,4 +115,8 @@ public class Downloader {
cancelled = true
downloadThread?.interrupt()
}
public void resume() {
downloadManager.resume(this)
}
}

View File

@ -90,6 +90,12 @@ class MainFrameController {
downloader.cancel()
}
@ControllerAction
void resume() {
def downloader = selectedDownload()
downloader.resume()
}
void mvcGroupInit(Map<String, String> args) {
application.addPropertyChangeListener("core", {e->
core = e.getNewValue()

View File

@ -99,7 +99,7 @@ class MainFrameView {
}
panel (constraints : BorderLayout.SOUTH) {
button(text: "Cancel", enabled : bind {model.cancelButtonEnabled }, cancelAction )
button("Retry", enabled : bind {model.retryButtonEnabled})
button(text: "Retry", enabled : bind {model.retryButtonEnabled}, resumeAction)
}
}
}