only allow one download per infohash from gui
This commit is contained in:
@@ -118,8 +118,11 @@ class MainFrameController {
|
|||||||
void download() {
|
void download() {
|
||||||
def result = selectedResult()
|
def result = selectedResult()
|
||||||
if (result == null)
|
if (result == null)
|
||||||
return // TODO disable button
|
return
|
||||||
|
|
||||||
|
if (!model.canDownload(result.infohash))
|
||||||
|
return
|
||||||
|
|
||||||
def file = new File(application.context.get("muwire-settings").downloadLocation, result.name)
|
def file = new File(application.context.get("muwire-settings").downloadLocation, result.name)
|
||||||
|
|
||||||
def selected = builder.getVariable("result-tabs").getSelectedComponent()
|
def selected = builder.getVariable("result-tabs").getSelectedComponent()
|
||||||
@@ -150,6 +153,7 @@ class MainFrameController {
|
|||||||
void cancel() {
|
void cancel() {
|
||||||
def downloader = model.downloads[selectedDownload()].downloader
|
def downloader = model.downloads[selectedDownload()].downloader
|
||||||
downloader.cancel()
|
downloader.cancel()
|
||||||
|
model.downloadInfoHashes.remove(downloader.getInfoHash())
|
||||||
core.eventBus.publish(new UIDownloadCancelledEvent(downloader : downloader))
|
core.eventBus.publish(new UIDownloadCancelledEvent(downloader : downloader))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -60,11 +60,14 @@ class MainFrameModel {
|
|||||||
|
|
||||||
@Observable int connections
|
@Observable int connections
|
||||||
@Observable String me
|
@Observable String me
|
||||||
@Observable boolean searchButtonsEnabled
|
@Observable boolean downloadActionEnabled
|
||||||
|
@Observable boolean trustButtonsEnabled
|
||||||
@Observable boolean cancelButtonEnabled
|
@Observable boolean cancelButtonEnabled
|
||||||
@Observable boolean retryButtonEnabled
|
@Observable boolean retryButtonEnabled
|
||||||
|
|
||||||
private final Set<InfoHash> infoHashes = new HashSet<>()
|
private final Set<InfoHash> infoHashes = new HashSet<>()
|
||||||
|
|
||||||
|
private final Set<InfoHash> downloadInfoHashes = new HashSet<>()
|
||||||
|
|
||||||
volatile Core core
|
volatile Core core
|
||||||
|
|
||||||
@@ -171,6 +174,7 @@ class MainFrameModel {
|
|||||||
void onDownloadStartedEvent(DownloadStartedEvent e) {
|
void onDownloadStartedEvent(DownloadStartedEvent e) {
|
||||||
runInsideUIAsync {
|
runInsideUIAsync {
|
||||||
downloads << e
|
downloads << e
|
||||||
|
downloadInfoHashes.add(e.downloader.infoHash)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -340,4 +344,8 @@ class MainFrameModel {
|
|||||||
return destination == other.destination
|
return destination == other.destination
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
boolean canDownload(InfoHash hash) {
|
||||||
|
!downloadInfoHashes.contains(hash)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -105,9 +105,9 @@ class MainFrameView {
|
|||||||
borderLayout()
|
borderLayout()
|
||||||
tabbedPane(id : "result-tabs", constraints: BorderLayout.CENTER)
|
tabbedPane(id : "result-tabs", constraints: BorderLayout.CENTER)
|
||||||
panel(constraints : BorderLayout.SOUTH) {
|
panel(constraints : BorderLayout.SOUTH) {
|
||||||
button(text : "Download", enabled : bind {model.searchButtonsEnabled}, downloadAction)
|
button(text : "Download", enabled : bind {model.downloadActionEnabled}, downloadAction)
|
||||||
button(text : "Trust", enabled: bind {model.searchButtonsEnabled }, trustAction)
|
button(text : "Trust", enabled: bind {model.trustButtonsEnabled }, trustAction)
|
||||||
button(text : "Distrust", enabled : bind {model.searchButtonsEnabled}, distrustAction)
|
button(text : "Distrust", enabled : bind {model.trustButtonsEnabled}, distrustAction)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
panel (constraints : JSplitPane.BOTTOM) {
|
panel (constraints : JSplitPane.BOTTOM) {
|
||||||
|
|||||||
@@ -66,7 +66,11 @@ class SearchTabView {
|
|||||||
def selectionModel = resultsTable.getSelectionModel()
|
def selectionModel = resultsTable.getSelectionModel()
|
||||||
selectionModel.setSelectionMode(ListSelectionModel.SINGLE_SELECTION)
|
selectionModel.setSelectionMode(ListSelectionModel.SINGLE_SELECTION)
|
||||||
selectionModel.addListSelectionListener( {
|
selectionModel.addListSelectionListener( {
|
||||||
mvcGroup.parentGroup.model.searchButtonsEnabled = true
|
mvcGroup.parentGroup.model.trustButtonsEnabled = true
|
||||||
|
int row = resultsTable.getSelectedRow()
|
||||||
|
if (lastSortEvent != null)
|
||||||
|
row = resultsTable.rowSorter.convertRowIndexToModel(row)
|
||||||
|
mvcGroup.parentGroup.model.downloadActionEnabled = mvcGroup.parentGroup.model.canDownload(model.results[row].infohash)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -105,25 +109,18 @@ class SearchTabView {
|
|||||||
resultsTable.rowSorter.setSortsOnUpdates(true)
|
resultsTable.rowSorter.setSortsOnUpdates(true)
|
||||||
|
|
||||||
|
|
||||||
JPopupMenu menu = new JPopupMenu()
|
|
||||||
JMenuItem download = new JMenuItem("Download")
|
|
||||||
download.addActionListener({mvcGroup.parentGroup.controller.download()})
|
|
||||||
menu.add(download)
|
|
||||||
JMenuItem copyHashToClipboard = new JMenuItem("Copy hash to clipboard")
|
|
||||||
copyHashToClipboard.addActionListener({mvcGroup.view.copyHashToClipboard()})
|
|
||||||
menu.add(copyHashToClipboard)
|
|
||||||
resultsTable.addMouseListener(new MouseAdapter() {
|
resultsTable.addMouseListener(new MouseAdapter() {
|
||||||
@Override
|
@Override
|
||||||
public void mouseClicked(MouseEvent e) {
|
public void mouseClicked(MouseEvent e) {
|
||||||
if (e.button == MouseEvent.BUTTON3)
|
if (e.button == MouseEvent.BUTTON3)
|
||||||
showPopupMenu(menu, e)
|
showPopupMenu(e)
|
||||||
else if (e.button == MouseEvent.BUTTON1 && e.clickCount == 2)
|
else if (e.button == MouseEvent.BUTTON1 && e.clickCount == 2)
|
||||||
mvcGroup.parentGroup.controller.download()
|
mvcGroup.parentGroup.controller.download()
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public void mouseReleased(MouseEvent e) {
|
public void mouseReleased(MouseEvent e) {
|
||||||
if (e.button == MouseEvent.BUTTON3)
|
if (e.button == MouseEvent.BUTTON3)
|
||||||
showPopupMenu(menu, e)
|
showPopupMenu(e)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -135,8 +132,16 @@ class SearchTabView {
|
|||||||
mvcGroup.destroy()
|
mvcGroup.destroy()
|
||||||
}
|
}
|
||||||
|
|
||||||
def showPopupMenu(JPopupMenu menu, MouseEvent e) {
|
def showPopupMenu(MouseEvent e) {
|
||||||
println "showing popup menu"
|
JPopupMenu menu = new JPopupMenu()
|
||||||
|
if (mvcGroup.parentGroup.model.downloadActionEnabled) {
|
||||||
|
JMenuItem download = new JMenuItem("Download")
|
||||||
|
download.addActionListener({mvcGroup.parentGroup.controller.download()})
|
||||||
|
menu.add(download)
|
||||||
|
}
|
||||||
|
JMenuItem copyHashToClipboard = new JMenuItem("Copy hash to clipboard")
|
||||||
|
copyHashToClipboard.addActionListener({mvcGroup.view.copyHashToClipboard()})
|
||||||
|
menu.add(copyHashToClipboard)
|
||||||
menu.show(e.getComponent(), e.getX(), e.getY())
|
menu.show(e.getComponent(), e.getX(), e.getY())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user