fixed progress dialog, wip on search view

pull/24/head
Zlatin Balevsky 2019-10-24 07:49:15 +01:00
parent 224266b2dd
commit 877bf12a93
4 changed files with 200 additions and 7 deletions

View File

@ -28,6 +28,7 @@ import com.googlecode.lanterna.terminal.DefaultTerminalFactory
import com.googlecode.lanterna.terminal.Terminal
import com.muwire.core.Core
import com.muwire.core.MuWireSettings
import com.muwire.core.UILoadedEvent
class CliLanterna {
private static final String MW_VERSION = "0.5.3"
@ -110,8 +111,22 @@ class CliLanterna {
contentPanel.addComponent(connectButtonPanel, BorderLayout.Location.BOTTOM)
connectButtonPanel.setLayoutManager(new GridLayout(1))
Button connectButton = new Button("Connect", {
WaitingDialog waiting = new WaitingDialog("Connecting", "Please wait")
waiting.showDialog(textGUI, false)
CountDownLatch latch = new CountDownLatch(1)
Thread connector = new Thread({
core = new Core(props, home, MW_VERSION)
core.startServices()
latch.countDown()
})
connector.start()
while(latch.getCount() > 0) {
textGUI.updateScreen()
Thread.sleep(10)
}
waiting.close()
window.close()
} as Runnable)
welcomeNamePanel.addComponent(connectButton, GridLayout.createLayoutData(Alignment.CENTER, Alignment.CENTER))
@ -126,12 +141,11 @@ class CliLanterna {
System.exit(1)
}
window = new BasicWindow("MuWire " + MW_VERSION)
contentPanel = new Panel()
Label addStuff = new Label("Add stuff here")
contentPanel.addComponent(addStuff)
window.setComponent(contentPanel)
window = new MainWindowView("MuWire "+MW_VERSION, core, textGUI)
core.eventBus.publish(new UILoadedEvent())
textGUI.addWindowAndWait(window)
core.shutdown()
screen.stopScreen()
System.exit(0)
}
}

View File

@ -0,0 +1,92 @@
package com.muwire.clilanterna
import com.googlecode.lanterna.TerminalSize
import com.googlecode.lanterna.gui2.BasicWindow
import com.googlecode.lanterna.gui2.BorderLayout
import com.googlecode.lanterna.gui2.Button
import com.googlecode.lanterna.gui2.GridLayout
import com.googlecode.lanterna.gui2.GridLayout.Alignment
import com.googlecode.lanterna.gui2.Label
import com.googlecode.lanterna.gui2.Panel
import com.googlecode.lanterna.gui2.Panels
import com.googlecode.lanterna.gui2.TextGUI
import com.googlecode.lanterna.gui2.Window
import com.googlecode.lanterna.gui2.TextBox
import com.muwire.core.Core
class MainWindowView extends BasicWindow {
private final Core core
private final TextGUI textGUI
private final Label connectionCount
private final TextBox searchTextBox
public MainWindowView(String title, Core core, TextGUI textGUI) {
super(title);
this.core = core
this.textGUI = textGUI
setHints([Window.Hint.EXPANDED])
Panel contentPanel = new Panel()
setComponent(contentPanel)
BorderLayout borderLayout = new BorderLayout()
contentPanel.setLayoutManager(borderLayout)
Panel buttonsPanel = new Panel()
contentPanel.addComponent(buttonsPanel, BorderLayout.Location.TOP)
GridLayout gridLayout = new GridLayout(7)
buttonsPanel.setLayoutManager(gridLayout)
searchTextBox = new TextBox(new TerminalSize(40, 1))
Button searchButton = new Button("Search", { search() })
Button downloadsButton = new Button("Downloads", {println "downloads"})
Button uploadsButton = new Button("Uploads", {println "uploads"})
Button filesButton = new Button("Files", {println "files" })
Button trustButton = new Button("Trust", {println "trust"})
Button quitButton = new Button("Quit", {close()})
buttonsPanel.addComponent(searchTextBox, GridLayout.createLayoutData(Alignment.CENTER, Alignment.CENTER))
buttonsPanel.addComponent(searchButton, GridLayout.createLayoutData(Alignment.CENTER, Alignment.CENTER))
buttonsPanel.addComponent(downloadsButton, GridLayout.createLayoutData(Alignment.CENTER, Alignment.CENTER))
buttonsPanel.addComponent(uploadsButton, GridLayout.createLayoutData(Alignment.CENTER, Alignment.CENTER))
buttonsPanel.addComponent(filesButton, GridLayout.createLayoutData(Alignment.CENTER, Alignment.CENTER))
buttonsPanel.addComponent(trustButton, GridLayout.createLayoutData(Alignment.CENTER, Alignment.CENTER))
buttonsPanel.addComponent(quitButton, GridLayout.createLayoutData(Alignment.CENTER, Alignment.CENTER))
Panel bottomPanel = new Panel()
contentPanel.addComponent(bottomPanel, BorderLayout.Location.BOTTOM)
BorderLayout bottomLayout = new BorderLayout()
bottomPanel.setLayoutManager(bottomLayout)
Label persona = new Label(core.me.getHumanReadableName())
bottomPanel.addComponent(persona, BorderLayout.Location.LEFT)
Panel connectionsPanel = new Panel()
connectionsPanel.setLayoutManager(new GridLayout(2))
Label connections = new Label("Connections:")
connectionsPanel.addComponent(connections, GridLayout.createLayoutData(Alignment.CENTER, Alignment.CENTER))
connectionCount = new Label("0")
connectionsPanel.addComponent(connectionCount, GridLayout.createLayoutData(Alignment.CENTER, Alignment.CENTER))
bottomPanel.addComponent(connectionsPanel, BorderLayout.Location.RIGHT)
Button refreshButton = new Button("Refresh", {refresh()})
bottomPanel.addComponent(refreshButton, BorderLayout.Location.CENTER)
refreshButton.takeFocus()
}
private void refresh() {
connectionCount.setText(String.valueOf(core.connectionManager.connections.size()))
}
private void search() {
String query = searchTextBox.getText()
SearchModel model = new SearchModel(query, core)
textGUI.addWindowAndWait(new SearchView(model,core))
}
}

View File

@ -0,0 +1,48 @@
package com.muwire.clilanterna
import com.muwire.core.Core
import com.muwire.core.Persona
import com.muwire.core.SplitPattern
import com.muwire.core.search.QueryEvent
import com.muwire.core.search.SearchEvent
import com.muwire.core.search.UIResultBatchEvent
import com.muwire.core.search.UIResultEvent
import com.googlecode.lanterna.gui2.table.TableModel
class SearchModel {
private final String query
private final Core core
final TableModel model
SearchModel(String query, Core core) {
this.query = query
this.core = core
this.model = new TableModel("Sender","Results","Browse","Trust")
core.eventBus.register(UIResultBatchEvent.class, this)
def replaced = query.toLowerCase().trim().replaceAll(SplitPattern.SPLIT_PATTERN, " ")
def terms = replaced.split(" ")
def nonEmpty = []
terms.each { if (it.length() > 0) nonEmpty << it }
def searchEvent = new SearchEvent(searchTerms : nonEmpty, uuid : UUID.randomUUID(), oobInfohash: true,
searchComments : core.muOptions.searchComments, compressedResults : true)
boolean firstHop = core.muOptions.allowUntrusted || core.muOptions.searchExtraHop
core.eventBus.publish(new QueryEvent(searchEvent : searchEvent, firstHop : firstHop,
replyTo: core.me.destination, receivedOn: core.me.destination,
originator : core.me))
}
void unregister() {
core.eventBus.unregister(UIResultBatchEvent.class, this)
}
void onUIResultBatchEvent(UIResultBatchEvent e) {
Persona sender = e.results[0].sender
String browse = String.valueOf(e.results[0].browse)
String results = String.valueOf(e.results.length)
String trust = core.trustService.getLevel(sender.destination).toString()
model.addRow([sender.getHumanReadableName(), results, browse, trust])
}
}

View File

@ -0,0 +1,39 @@
package com.muwire.clilanterna
import com.googlecode.lanterna.gui2.BasicWindow
import com.googlecode.lanterna.gui2.Button
import com.googlecode.lanterna.gui2.Panel
import com.googlecode.lanterna.gui2.Window
import com.googlecode.lanterna.gui2.table.Table
import com.muwire.core.Core
class SearchView extends BasicWindow {
private final Core core
private final SearchModel model
private final Table table
SearchView(SearchModel model, Core core) {
super(model.query)
this.core = core
this.model = model
setHints([Window.Hint.EXPANDED])
Panel contentPanel = new Panel()
Button closeButton = new Button("Close", {
model.unregister()
close()
})
contentPanel.addComponent(closeButton)
table = new Table("Sender","Results","Browse","Trust")
table.setCellSelection(false)
table.setTableModel(model.model)
contentPanel.addComponent(table)
setComponent(contentPanel)
closeButton.takeFocus()
}
}