count shared files in dashboard

pull/24/head
Zlatin Balevsky 2019-10-25 22:51:26 +01:00
parent 45f0736a5e
commit 9cdabb51d1
1 changed files with 41 additions and 1 deletions

View File

@ -17,7 +17,12 @@ import com.googlecode.lanterna.gui2.Window
import com.googlecode.lanterna.screen.Screen import com.googlecode.lanterna.screen.Screen
import com.googlecode.lanterna.gui2.TextBox import com.googlecode.lanterna.gui2.TextBox
import com.muwire.core.Core import com.muwire.core.Core
import com.muwire.core.DownloadedFile
import com.muwire.core.connection.ConnectionEvent 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 import com.muwire.core.hostcache.HostDiscoveredEvent
class MainWindowView extends BasicWindow { class MainWindowView extends BasicWindow {
@ -35,6 +40,7 @@ class MainWindowView extends BasicWindow {
private final Label connectionCount, incoming, outgoing private final Label connectionCount, incoming, outgoing
private final Label known, failing, hopeless private final Label known, failing, hopeless
private final Label sharedFiles
public MainWindowView(String title, Core core, TextGUI textGUI, Screen screen) { public MainWindowView(String title, Core core, TextGUI textGUI, Screen screen) {
super(title); super(title);
@ -113,6 +119,8 @@ class MainWindowView extends BasicWindow {
known = new Label("0") known = new Label("0")
failing = new Label("0") failing = new Label("0")
hopeless = new Label("0") hopeless = new Label("0")
sharedFiles = new Label("0")
statusPanel.with { statusPanel.with {
addComponent(new Label("Incoming Connections: "), layoutData) addComponent(new Label("Incoming Connections: "), layoutData)
addComponent(incoming, layoutData) addComponent(incoming, layoutData)
@ -124,6 +132,8 @@ class MainWindowView extends BasicWindow {
addComponent(failing, layoutData) addComponent(failing, layoutData)
addComponent(new Label("Hopeless Hosts: "), layoutData) addComponent(new Label("Hopeless Hosts: "), layoutData)
addComponent(hopeless, layoutData) addComponent(hopeless, layoutData)
addComponent(new Label("Shared Files: "), layoutData)
addComponent(sharedFiles, layoutData)
} }
refreshStats() refreshStats()
@ -131,6 +141,10 @@ class MainWindowView extends BasicWindow {
searchButton.takeFocus() searchButton.takeFocus()
core.eventBus.register(ConnectionEvent.class, this) core.eventBus.register(ConnectionEvent.class, this)
core.eventBus.register(HostDiscoveredEvent.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) { 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() { private TerminalSize sizeForTables() {
TerminalSize full = screen.getTerminalSize() TerminalSize full = screen.getTerminalSize()
return new TerminalSize(full.getColumns(), full.getRows() - 10) return new TerminalSize(full.getColumns(), full.getRows() - 10)
@ -186,11 +224,13 @@ class MainWindowView extends BasicWindow {
int knownHosts = core.hostCache.hosts.size() int knownHosts = core.hostCache.hosts.size()
int failingHosts = core.hostCache.countFailingHosts() int failingHosts = core.hostCache.countFailingHosts()
int hopelessHosts = core.hostCache.countHopelessHosts() int hopelessHosts = core.hostCache.countHopelessHosts()
int shared = core.fileManager.fileToSharedFile.size()
incoming.setText(String.valueOf(inCon)) incoming.setText(String.valueOf(inCon))
outgoing.setText(String.valueOf(outCon)) outgoing.setText(String.valueOf(outCon))
known.setText(String.valueOf(knownHosts)) known.setText(String.valueOf(knownHosts))
failing.setText(String.valueOf(failingHosts)) failing.setText(String.valueOf(failingHosts))
hopeless.setText(String.valueOf(hopelessHosts)) hopeless.setText(String.valueOf(hopelessHosts))
sharedFiles.setText(String.valueOf(shared))
} }
} }