implement downloading from browse window
This commit is contained in:
@@ -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
|
||||
|
@@ -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<UIResultEvent> rv = new ArrayList<>()
|
||||
for (Integer i : rows)
|
||||
rv << model.results[i]
|
||||
rv
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user