From 1996681677dce69cda874d6b34bfb3698e2fd6f1 Mon Sep 17 00:00:00 2001 From: Zlatin Balevsky Date: Sat, 1 Jun 2019 13:44:46 +0100 Subject: [PATCH] incoming searches monitor --- .../com/muwire/gui/MainFrameModel.groovy | 21 +++++++++++++++ .../views/com/muwire/gui/MainFrameView.groovy | 26 ++++++++++++++----- 2 files changed, 41 insertions(+), 6 deletions(-) diff --git a/gui/griffon-app/models/com/muwire/gui/MainFrameModel.groovy b/gui/griffon-app/models/com/muwire/gui/MainFrameModel.groovy index d2f9a16b..3149bb3f 100644 --- a/gui/griffon-app/models/com/muwire/gui/MainFrameModel.groovy +++ b/gui/griffon-app/models/com/muwire/gui/MainFrameModel.groovy @@ -15,6 +15,7 @@ import com.muwire.core.download.DownloadStartedEvent 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.UIResultEvent import com.muwire.core.trust.TrustEvent import com.muwire.core.trust.TrustService @@ -42,6 +43,7 @@ class MainFrameModel { def uploads = [] def shared = [] def connectionList = [] + def searches = new LinkedList() @Observable int connections @Observable String me @@ -65,6 +67,7 @@ class MainFrameModel { core.eventBus.register(UploadEvent.class, this) core.eventBus.register(UploadFinishedEvent.class, this) core.eventBus.register(TrustEvent.class, this) + core.eventBus.register(QueryEvent.class, this) }) Timer timer = new Timer("download-pumper", true) timer.schedule({ @@ -153,4 +156,22 @@ class MainFrameModel { table.model.fireTableDataChanged() } } + + void onQueryEvent(QueryEvent e) { + StringBuilder sb = new StringBuilder() + e.searchEvent.searchTerms?.each { + sb.append(it) + sb.append(" ") + } + def search = sb.toString() + if (search.trim().size() == 0) + return + runInsideUIAsync { + searches.addFirst(search) + while(searches.size() > 200) + searches.removeLast() + JTable table = builder.getVariable("searches-table") + table.model.fireTableDataChanged() + } + } } \ 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 09d775c6..c72a5676 100644 --- a/gui/griffon-app/views/com/muwire/gui/MainFrameView.groovy +++ b/gui/griffon-app/views/com/muwire/gui/MainFrameView.groovy @@ -134,12 +134,26 @@ class MainFrameView { } } panel (constraints: "monitor window") { - borderLayout() - label("Connections", constraints : BorderLayout.NORTH) - scrollPane(constraints : BorderLayout.CENTER) { - table(id : "connections-table") { - tableModel(list : model.connectionList) { - closureColumn(header : "Destination", type: String, read : { row -> row.toBase32() }) + gridLayout(rows : 1, cols : 2) + panel { + borderLayout() + label("Connections", constraints : BorderLayout.NORTH) + scrollPane(constraints : BorderLayout.CENTER) { + table(id : "connections-table") { + tableModel(list : model.connectionList) { + closureColumn(header : "Destination", type: String, read : { row -> row.toBase32() }) + } + } + } + } + panel { + borderLayout() + label("Incoming searches", constraints : BorderLayout.NORTH) + scrollPane(constraints : BorderLayout.CENTER) { + table(id : "searches-table") { + tableModel(list : model.searches) { + closureColumn(header : "Keywords", type : String, read : { it }) + } } } }