diff --git a/core/src/main/groovy/com/muwire/core/connection/ConnectionAcceptor.groovy b/core/src/main/groovy/com/muwire/core/connection/ConnectionAcceptor.groovy index be3a3f82..0b686af9 100644 --- a/core/src/main/groovy/com/muwire/core/connection/ConnectionAcceptor.groovy +++ b/core/src/main/groovy/com/muwire/core/connection/ConnectionAcceptor.groovy @@ -17,6 +17,8 @@ import com.muwire.core.upload.UploadManager import com.muwire.core.search.InvalidSearchResultException import com.muwire.core.search.ResultsParser import com.muwire.core.search.SearchManager +import com.muwire.core.search.UIResultBatchEvent +import com.muwire.core.search.UIResultEvent import com.muwire.core.search.UnexpectedResultsException import groovy.json.JsonOutput @@ -225,13 +227,15 @@ class ConnectionAcceptor { if (sender.destination != e.getDestination()) throw new IOException("Sender destination mismatch expected $e.getDestination(), got $sender.destination") int nResults = dis.readUnsignedShort() + UIResultEvent[] results = new UIResultEvent[nResults] for (int i = 0; i < nResults; i++) { int jsonSize = dis.readUnsignedShort() byte [] payload = new byte[jsonSize] dis.readFully(payload) def json = slurper.parse(payload) - eventBus.publish(ResultsParser.parse(sender, resultsUUID, json)) + results[i] = ResultsParser.parse(sender, resultsUUID, json) } + eventBus.publish(new UIResultBatchEvent(uuid: resultsUUID, results: results)) } catch (IOException | UnexpectedResultsException | InvalidSearchResultException bad) { log.log(Level.WARNING, "failed to process POST", bad) } finally { diff --git a/core/src/main/groovy/com/muwire/core/search/UIResultBatchEvent.groovy b/core/src/main/groovy/com/muwire/core/search/UIResultBatchEvent.groovy new file mode 100644 index 00000000..3f22921b --- /dev/null +++ b/core/src/main/groovy/com/muwire/core/search/UIResultBatchEvent.groovy @@ -0,0 +1,8 @@ +package com.muwire.core.search + +import com.muwire.core.Event + +class UIResultBatchEvent extends Event { + UUID uuid + UIResultEvent[] results +} diff --git a/gui/griffon-app/models/com/muwire/gui/MainFrameModel.groovy b/gui/griffon-app/models/com/muwire/gui/MainFrameModel.groovy index 3d6a9d4c..e16513a5 100644 --- a/gui/griffon-app/models/com/muwire/gui/MainFrameModel.groovy +++ b/gui/griffon-app/models/com/muwire/gui/MainFrameModel.groovy @@ -20,6 +20,7 @@ import com.muwire.core.files.FileHashedEvent import com.muwire.core.files.FileLoadedEvent import com.muwire.core.files.FileSharedEvent import com.muwire.core.search.QueryEvent +import com.muwire.core.search.UIResultBatchEvent import com.muwire.core.search.UIResultEvent import com.muwire.core.trust.TrustEvent import com.muwire.core.trust.TrustService @@ -115,6 +116,7 @@ class MainFrameModel { core = e.getNewValue() me = core.me.getHumanReadableName() core.eventBus.register(UIResultEvent.class, this) + core.eventBus.register(UIResultBatchEvent.class, this) core.eventBus.register(DownloadStartedEvent.class, this) core.eventBus.register(ConnectionEvent.class, this) core.eventBus.register(DisconnectionEvent.class, this) @@ -161,6 +163,11 @@ class MainFrameModel { resultsGroup?.model.handleResult(e) } + void onUIResultBatchEvent(UIResultBatchEvent e) { + MVCGroup resultsGroup = results.get(e.uuid) + resultsGroup?.model.handleResultBatch(e.results) + } + void onDownloadStartedEvent(DownloadStartedEvent e) { runInsideUIAsync { downloads << e diff --git a/gui/griffon-app/models/com/muwire/gui/SearchTabModel.groovy b/gui/griffon-app/models/com/muwire/gui/SearchTabModel.groovy index 06e1edef..75f5c5e2 100644 --- a/gui/griffon-app/models/com/muwire/gui/SearchTabModel.groovy +++ b/gui/griffon-app/models/com/muwire/gui/SearchTabModel.groovy @@ -52,4 +52,22 @@ class SearchTabModel { table.model.fireTableDataChanged() } } + + void handleResultBatch(UIResultEvent[] batch) { + runInsideUIAsync { + batch.each { + if (uiSettings.excludeLocalResult && e.sender == core.me) + return + def bucket = hashBucket.get(it.infohash) + if (bucket == null) { + bucket = [] + hashBucket[it.infohash] = bucket + } + bucket << it + results << it + } + JTable table = builder.getVariable("results-table") + table.model.fireTableDataChanged() + } + } } \ No newline at end of file