From deae9a397746d9cf3438ee5b417d8e22487f6917 Mon Sep 17 00:00:00 2001 From: Zlatin Balevsky Date: Fri, 31 May 2019 05:26:04 +0100 Subject: [PATCH] hook up downloads to the table --- .../com/muwire/gui/MainFrameController.groovy | 15 ++++++++++++++- .../models/com/muwire/gui/MainFrameModel.groovy | 8 ++++++++ .../views/com/muwire/gui/MainFrameView.groovy | 2 +- 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/gui/griffon-app/controllers/com/muwire/gui/MainFrameController.groovy b/gui/griffon-app/controllers/com/muwire/gui/MainFrameController.groovy index 0e6539b1..b4fc9539 100644 --- a/gui/griffon-app/controllers/com/muwire/gui/MainFrameController.groovy +++ b/gui/griffon-app/controllers/com/muwire/gui/MainFrameController.groovy @@ -9,6 +9,8 @@ import javax.annotation.Nonnull import javax.inject.Inject import com.muwire.core.Core +import com.muwire.core.download.DownloadStartedEvent +import com.muwire.core.download.UIDownloadEvent import com.muwire.core.search.QueryEvent import com.muwire.core.search.SearchEvent @@ -31,7 +33,18 @@ class MainFrameController { replyTo: core.me.destination, receivedOn: core.me.destination)) } + @ControllerAction + void download() { + def resultsTable = builder.getVariable("results-table") + int row = resultsTable.getSelectedRow() + def result = model.results[row] + def file = new File(System.getProperty("user.home"), result.name) // TODO: move elsewhere + core.eventBus.publish(new UIDownloadEvent(result : result, target : file)) + } + void mvcGroupInit(Map args) { - application.addPropertyChangeListener("core", {e-> core = e.getNewValue()}) + application.addPropertyChangeListener("core", {e-> + core = e.getNewValue() + }) } } \ No newline at end of file diff --git a/gui/griffon-app/models/com/muwire/gui/MainFrameModel.groovy b/gui/griffon-app/models/com/muwire/gui/MainFrameModel.groovy index 56e99f3d..bf56a627 100644 --- a/gui/griffon-app/models/com/muwire/gui/MainFrameModel.groovy +++ b/gui/griffon-app/models/com/muwire/gui/MainFrameModel.groovy @@ -5,6 +5,7 @@ import javax.inject.Inject import javax.swing.JTable import com.muwire.core.Core +import com.muwire.core.download.DownloadStartedEvent import com.muwire.core.search.UIResultEvent import griffon.core.GriffonApplication @@ -31,6 +32,7 @@ class MainFrameModel { coreInitialized = (e.getNewValue() != null) core = e.getNewValue() core.eventBus.register(UIResultEvent.class, this) + core.eventBus.register(DownloadStartedEvent.class, this) }) Timer timer = new Timer("download-pumper", true) timer.schedule({ @@ -47,4 +49,10 @@ class MainFrameModel { table.model.fireTableDataChanged() } } + + void onDownloadStartedEvent(DownloadStartedEvent e) { + runInsideUIAsync { + downloads << e + } + } } \ No newline at end of file diff --git a/gui/griffon-app/views/com/muwire/gui/MainFrameView.groovy b/gui/griffon-app/views/com/muwire/gui/MainFrameView.groovy index c31a8616..75f3aff1 100644 --- a/gui/griffon-app/views/com/muwire/gui/MainFrameView.groovy +++ b/gui/griffon-app/views/com/muwire/gui/MainFrameView.groovy @@ -73,7 +73,7 @@ class MainFrameView { } } panel(constraints : BorderLayout.SOUTH) { - button(text : "Download") + button(text : "Download", downloadAction) button(text : "Trust") button(text : "Distrust") }