From 5dacd60bbb34a7fe2b29a2c9a7c2914f904e495d Mon Sep 17 00:00:00 2001 From: Zlatin Balevsky Date: Fri, 14 Jun 2019 13:11:20 +0100 Subject: [PATCH] hook up cleaning up of cancelled/finished downloads --- .../models/com/muwire/gui/MainFrameModel.groovy | 17 +++++++++++++++++ .../views/com/muwire/gui/MainFrameView.groovy | 4 +++- gui/src/main/resources/trust.html | 7 ------- 3 files changed, 20 insertions(+), 8 deletions(-) delete mode 100644 gui/src/main/resources/trust.html diff --git a/gui/griffon-app/models/com/muwire/gui/MainFrameModel.groovy b/gui/griffon-app/models/com/muwire/gui/MainFrameModel.groovy index 27235eae..c91ca934 100644 --- a/gui/griffon-app/models/com/muwire/gui/MainFrameModel.groovy +++ b/gui/griffon-app/models/com/muwire/gui/MainFrameModel.groovy @@ -79,11 +79,28 @@ class MainFrameModel { void mvcGroupInit(Map args) { + UISettings uiSettings = application.context.get("ui-settings") + Timer timer = new Timer("download-pumper", true) timer.schedule({ runInsideUIAsync { if (!mvcGroup.alive) return + + // remove cancelled or finished downloads + def toRemove = [] + downloads.each { + if (uiSettings.clearCancelledDownloads && + it.downloader.getCurrentState() == Downloader.DownloadState.CANCELLED) + toRemove << it + if (uiSettings.clearFinishedDownloads && + it.downloader.getCurrentState() == Downloader.DownloadState.FINISHED) + toRemove << it + } + toRemove.each { + downloads.remove(it) + } + builder.getVariable("uploads-table")?.model.fireTableDataChanged() updateTablePreservingSelection("downloads-table") diff --git a/gui/griffon-app/views/com/muwire/gui/MainFrameView.groovy b/gui/griffon-app/views/com/muwire/gui/MainFrameView.groovy index 1fc2a180..f9ad3c58 100644 --- a/gui/griffon-app/views/com/muwire/gui/MainFrameView.groovy +++ b/gui/griffon-app/views/com/muwire/gui/MainFrameView.groovy @@ -266,7 +266,9 @@ class MainFrameView { selectionModel.setSelectionMode(ListSelectionModel.SINGLE_SELECTION) selectionModel.addListSelectionListener({ int selectedRow = selectedDownloaderRow() - def downloader = model.downloads[selectedRow].downloader + def downloader = model.downloads[selectedRow]?.downloader + if (downloader == null) + return switch(downloader.getCurrentState()) { case Downloader.DownloadState.CONNECTING : case Downloader.DownloadState.DOWNLOADING : diff --git a/gui/src/main/resources/trust.html b/gui/src/main/resources/trust.html deleted file mode 100644 index d72ee6ba..00000000 --- a/gui/src/main/resources/trust.html +++ /dev/null @@ -1,7 +0,0 @@ - -Some html goes here - -