diff --git a/gui/griffon-app/controllers/com/muwire/gui/BrowseController.groovy b/gui/griffon-app/controllers/com/muwire/gui/BrowseController.groovy index 3cd20b1d..19b97a40 100644 --- a/gui/griffon-app/controllers/com/muwire/gui/BrowseController.groovy +++ b/gui/griffon-app/controllers/com/muwire/gui/BrowseController.groovy @@ -7,6 +7,7 @@ import griffon.metadata.ArtifactProviderFor import javax.annotation.Nonnull import com.muwire.core.EventBus +import com.muwire.core.download.UIDownloadEvent import com.muwire.core.search.BrowseStatusEvent import com.muwire.core.search.UIBrowseEvent import com.muwire.core.search.UIResultEvent @@ -53,7 +54,25 @@ class BrowseController { @ControllerAction void download() { + def selectedResults = view.selectedResults() + if (selectedResults == null || selectedResults.isEmpty()) + return + selectedResults.removeAll { + !mvcGroup.parentGroup.parentGroup.model.canDownload(it.infohash) + } + selectedResults.each { result -> + def file = new File(application.context.get("muwire-settings").downloadLocation, result.name) + eventBus.publish(new UIDownloadEvent( + result : [result], + sources : [model.host.destination], + target : file, + sequential : mvcGroup.parentGroup.view.sequentialDownloadCheckbox.model.isSelected() + )) + } + + mvcGroup.parentGroup.parentGroup.view.showDownloadsWindow.call() + dismiss() } @ControllerAction diff --git a/gui/griffon-app/views/com/muwire/gui/BrowseView.groovy b/gui/griffon-app/views/com/muwire/gui/BrowseView.groovy index fae6ba64..bd2b4a62 100644 --- a/gui/griffon-app/views/com/muwire/gui/BrowseView.groovy +++ b/gui/griffon-app/views/com/muwire/gui/BrowseView.groovy @@ -10,6 +10,8 @@ import javax.swing.ListSelectionModel import javax.swing.SwingConstants import javax.swing.table.DefaultTableCellRenderer +import com.muwire.core.search.UIResultEvent + import java.awt.BorderLayout import java.awt.event.WindowAdapter import java.awt.event.WindowEvent @@ -111,4 +113,20 @@ class BrowseView { dialog.show() } + + def selectedResults() { + int [] rows = resultsTable.getSelectedRows() + if (rows.length == 0) + return null + if (lastSortEvent != null) { + for (int i = 0; i < rows.length; i ++) { + rows[i] = resultsTable.rowSorter.convertRowIndexToModel(rows[i]) + } + } + + List rv = new ArrayList<>() + for (Integer i : rows) + rv << model.results[i] + rv + } } \ No newline at end of file