From 9cdabb51d12bd3fb28969fa10b1afbe553a80576 Mon Sep 17 00:00:00 2001 From: Zlatin Balevsky Date: Fri, 25 Oct 2019 22:51:26 +0100 Subject: [PATCH] count shared files in dashboard --- .../muwire/clilanterna/MainWindowView.groovy | 42 ++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) diff --git a/cli-lanterna/src/main/groovy/com/muwire/clilanterna/MainWindowView.groovy b/cli-lanterna/src/main/groovy/com/muwire/clilanterna/MainWindowView.groovy index 24e8f6e7..b2111d0e 100644 --- a/cli-lanterna/src/main/groovy/com/muwire/clilanterna/MainWindowView.groovy +++ b/cli-lanterna/src/main/groovy/com/muwire/clilanterna/MainWindowView.groovy @@ -17,7 +17,12 @@ import com.googlecode.lanterna.gui2.Window import com.googlecode.lanterna.screen.Screen import com.googlecode.lanterna.gui2.TextBox import com.muwire.core.Core +import com.muwire.core.DownloadedFile import com.muwire.core.connection.ConnectionEvent +import com.muwire.core.files.FileDownloadedEvent +import com.muwire.core.files.FileHashedEvent +import com.muwire.core.files.FileLoadedEvent +import com.muwire.core.files.FileUnsharedEvent import com.muwire.core.hostcache.HostDiscoveredEvent class MainWindowView extends BasicWindow { @@ -35,6 +40,7 @@ class MainWindowView extends BasicWindow { private final Label connectionCount, incoming, outgoing private final Label known, failing, hopeless + private final Label sharedFiles public MainWindowView(String title, Core core, TextGUI textGUI, Screen screen) { super(title); @@ -112,7 +118,9 @@ class MainWindowView extends BasicWindow { outgoing = new Label("0") known = new Label("0") failing = new Label("0") - hopeless = new Label("0") + hopeless = new Label("0") + sharedFiles = new Label("0") + statusPanel.with { addComponent(new Label("Incoming Connections: "), layoutData) addComponent(incoming, layoutData) @@ -124,6 +132,8 @@ class MainWindowView extends BasicWindow { addComponent(failing, layoutData) addComponent(new Label("Hopeless Hosts: "), layoutData) addComponent(hopeless, layoutData) + addComponent(new Label("Shared Files: "), layoutData) + addComponent(sharedFiles, layoutData) } refreshStats() @@ -131,6 +141,10 @@ class MainWindowView extends BasicWindow { searchButton.takeFocus() core.eventBus.register(ConnectionEvent.class, this) core.eventBus.register(HostDiscoveredEvent.class, this) + core.eventBus.register(FileLoadedEvent.class, this) + core.eventBus.register(FileHashedEvent.class, this) + core.eventBus.register(FileUnsharedEvent.class, this) + core.eventBus.register(FileDownloadedEvent.class, this) } void onConnectionEvent(ConnectionEvent e) { @@ -146,6 +160,30 @@ class MainWindowView extends BasicWindow { } } + void onFileLoadedEvent(FileLoadedEvent e) { + textGUI.getGUIThread().invokeLater { + refreshStats() + } + } + + void onFileHashedEvent(FileHashedEvent e) { + textGUI.getGUIThread().invokeLater { + refreshStats() + } + } + + void onFileUnsharedEvent(FileUnsharedEvent e) { + textGUI.getGUIThread().invokeLater { + refreshStats() + } + } + + void onFileDownloadedEvent(FileDownloadedEvent e) { + textGUI.getGUIThread().invokeLater { + refreshStats() + } + } + private TerminalSize sizeForTables() { TerminalSize full = screen.getTerminalSize() return new TerminalSize(full.getColumns(), full.getRows() - 10) @@ -186,11 +224,13 @@ class MainWindowView extends BasicWindow { int knownHosts = core.hostCache.hosts.size() int failingHosts = core.hostCache.countFailingHosts() int hopelessHosts = core.hostCache.countHopelessHosts() + int shared = core.fileManager.fileToSharedFile.size() incoming.setText(String.valueOf(inCon)) outgoing.setText(String.valueOf(outCon)) known.setText(String.valueOf(knownHosts)) failing.setText(String.valueOf(failingHosts)) hopeless.setText(String.valueOf(hopelessHosts)) + sharedFiles.setText(String.valueOf(shared)) } }