Trust List actions

This commit is contained in:
Zlatin Balevsky
2019-10-25 08:48:07 +01:00
parent 7bf0373b80
commit 45fcb2209e

View File

@ -9,6 +9,7 @@ import com.googlecode.lanterna.gui2.Panel
import com.googlecode.lanterna.gui2.TextGUI
import com.googlecode.lanterna.gui2.Window
import com.googlecode.lanterna.gui2.dialogs.MessageDialog
import com.googlecode.lanterna.gui2.dialogs.MessageDialogBuilder
import com.googlecode.lanterna.gui2.dialogs.MessageDialogButton
import com.googlecode.lanterna.gui2.GridLayout.Alignment
import com.googlecode.lanterna.gui2.Label
@ -17,6 +18,7 @@ import com.muwire.core.Core
import com.muwire.core.Persona
import com.muwire.core.trust.TrustEvent
import com.muwire.core.trust.TrustLevel
import com.muwire.core.trust.TrustSubscriptionEvent
class TrustView extends BasicWindow {
private final TrustModel model
@ -83,12 +85,21 @@ class TrustView extends BasicWindow {
def row = model.modelTrusted.getRow(selectedRow)
Persona persona = row[0].persona
Window prompt = new BasicWindow("Change trust for "+persona.getHumanReadableName())
Window prompt = new BasicWindow("Change Trust For "+persona.getHumanReadableName())
prompt.setHints([Window.Hint.CENTERED])
Panel contentPanel = new Panel()
contentPanel.setLayoutManager(new GridLayout(3))
contentPanel.setLayoutManager(new GridLayout(4))
LayoutData layoutData = GridLayout.createLayoutData(Alignment.CENTER, Alignment.CENTER)
Button subscribe = new Button("Subscribe", {
core.muOptions.trustSubscriptions.add(persona)
saveMuSettings()
core.eventBus.publish(new TrustSubscriptionEvent(persona : persona, subscribe : true))
MessageDialog.showMessageDialog(textGUI, "Subscribed", "Subscribed from trust list of " + persona.getHumanReadableName(),
MessageDialogButton.OK)
model.refreshModels()
})
Button markNeutral = new Button("Mark Neutral", {
core.eventBus.publish(new TrustEvent(persona : persona, level : TrustLevel.NEUTRAL))
MessageDialog.showMessageDialog(textGUI, "Marked Neutral", persona.getHumanReadableName() + "has been marked neutral",
@ -100,7 +111,8 @@ class TrustView extends BasicWindow {
MessageDialogButton.OK)
})
Button closeButton = new Button("Close", {prompt.close()})
contentPanel.with {
contentPanel.with {
addComponent(subscribe, layoutData)
addComponent(markNeutral, layoutData)
addComponent(markDistrusted, layoutData)
addComponent(closeButton, layoutData)
@ -114,7 +126,7 @@ class TrustView extends BasicWindow {
def row = model.modelDistrusted.getRow(selectedRow)
Persona persona = row[0].persona
Window prompt = new BasicWindow("Change trust for "+persona.getHumanReadableName())
Window prompt = new BasicWindow("Change Trust For "+persona.getHumanReadableName())
prompt.setHints([Window.Hint.CENTERED])
Panel contentPanel = new Panel()
contentPanel.setLayoutManager(new GridLayout(3))
@ -141,6 +153,44 @@ class TrustView extends BasicWindow {
}
private void trustListActions() {
int selectedRow = subscriptions.getSelectedRow()
def row = model.modelSubscriptions.getRow(selectedRow)
Persona persona = row[0].trustList.persona
Window prompt = new BasicWindow("Trust List Actions")
prompt.setHints([Window.Hint.CENTERED])
Panel contentPanel = new Panel()
contentPanel.setLayoutManager(new GridLayout(4))
LayoutData layoutData = GridLayout.createLayoutData(Alignment.CENTER, Alignment.CENTER)
Button reviewButton = new Button("Review",{}) // TODO
Button updateButton = new Button("Update",{
core.eventBus.publish(new TrustSubscriptionEvent(persona : persona, subscribe : true))
MessageDialog.showMessageDialog(textGUI, "Updating...", "Trust list will update soon", MessageDialogButton.OK)
})
Button unsubscribeButton = new Button("Unsubscribe", {
core.muOptions.trustSubscriptions.remove(persona)
saveMuSettings()
core.eventBus.publish(new TrustSubscriptionEvent(persona : persona, subscribe : false))
MessageDialog.showMessageDialog(textGUI, "Unsubscribed", "Unsubscribed from trust list of " + persona.getHumanReadableName(),
MessageDialogButton.OK)
model.refreshModels()
})
Button closeButton = new Button("Close", {prompt.close()})
contentPanel.with {
addComponent(reviewButton, layoutData)
addComponent(updateButton, layoutData)
addComponent(unsubscribeButton, layoutData)
addComponent(closeButton, layoutData)
}
prompt.setComponent(contentPanel)
textGUI.addWindowAndWait(prompt)
}
private void saveMuSettings() {
File settingsFile = new File(core.home,"MuWire.properties")
settingsFile.withOutputStream { core.muOptions.write(it) }
}
}